@codexhost/cli-darwin-x64 0.23.0 → 0.24.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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +1565 -1805
  4. package/app/console-web.js +5786 -1600
  5. package/app/desktop-controller.mjs +13104 -2842
  6. package/app/host-runtime.mjs +50518 -51753
  7. package/app/plugins/antigravity/plugin.mjs +1932 -1148
  8. package/app/plugins/claude-code/plugin.mjs +1676 -1218
  9. package/app/plugins/codebuddy/plugin.mjs +1266 -850
  10. package/app/plugins/codex-usage/plugin.mjs +916 -737
  11. package/app/plugins/copilot/plugin.mjs +838 -640
  12. package/app/plugins/cursor-cli/plugin.mjs +1058 -747
  13. package/app/plugins/deepseek-harness/plugin.mjs +1302 -1070
  14. package/app/plugins/devin/plugin.mjs +949 -752
  15. package/app/plugins/grok/plugin.mjs +1132 -964
  16. package/app/plugins/hermes/plugin.mjs +1084 -905
  17. package/app/plugins/kimi-code/plugin.mjs +977 -804
  18. package/app/plugins/kiro-cli/plugin.mjs +951 -758
  19. package/app/plugins/omp/plugin.mjs +1408 -1169
  20. package/app/plugins/opencode/plugin.mjs +1385 -1142
  21. package/app/plugins/pi/plugin.mjs +1515 -1287
  22. package/app/plugins/qoder/plugin.mjs +861 -676
  23. package/app/plugins/qoder-cn/plugin.mjs +861 -676
  24. package/app/plugins/qwen-code/plugin.mjs +1060 -888
  25. package/app/plugins/workbuddy/plugin.mjs +1272 -856
  26. package/app/plugins/zcode/plugin.mjs +1529 -880
  27. package/app/renderer-extension.js +11568 -7827
  28. package/app/web/assets/index-CTCFIQbU.css +1 -0
  29. package/app/web/assets/index-IvFk9KT-.js +203 -0
  30. package/app/web/codexhost-settings.js +4472 -36194
  31. package/app/web/index.html +2 -2
  32. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
  33. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +69 -69
  34. package/app/web/plugins/deepseek-ai__dsh-client-ui-approval/client.js +1 -1
  35. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +74 -74
  36. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +75 -64
  37. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +19 -16
  38. package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
  39. package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
  40. package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +2 -2
  41. package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
  42. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +2 -2
  43. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  44. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-right/client.js +1 -1
  45. package/app/web/plugins/deepseek-ai__dsh-client-ui-theme/client.js +1 -1
  46. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +18 -18
  47. package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +3 -3
  48. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +7 -7
  49. package/app/web/sw.js +8 -1
  50. package/app/web-modules/server.mjs +2682 -5540
  51. package/bin/codexhost +0 -0
  52. package/libexec/codexhost-shim +0 -0
  53. package/libexec/codexhost-updater +0 -0
  54. package/package.json +1 -1
  55. package/app/web/assets/index-DJW4bmyx.css +0 -1
  56. package/app/web/assets/index-Dyh1KzAB.js +0 -201
@@ -32,10 +32,10 @@ function executableExtensions(command, platform, environment) {
32
32
  return [""];
33
33
  return (environmentValue(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean);
34
34
  }
35
- function isExecutableFile(filePath, platform) {
35
+ function isExecutableFile(filePath2, platform) {
36
36
  try {
37
- fs.accessSync(filePath, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
38
- return fs.statSync(filePath).isFile();
37
+ fs.accessSync(filePath2, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
38
+ return fs.statSync(filePath2).isFile();
39
39
  } catch {
40
40
  return false;
41
41
  }
@@ -1661,8 +1661,8 @@ function cleanEnum(obj) {
1661
1661
  return Number.isNaN(Number.parseInt(k, 10));
1662
1662
  }).map((el) => el[1]);
1663
1663
  }
1664
- function base64ToUint8Array(base643) {
1665
- const binaryString = atob(base643);
1664
+ function base64ToUint8Array(base644) {
1665
+ const binaryString = atob(base644);
1666
1666
  const bytes = new Uint8Array(binaryString.length);
1667
1667
  for (let i = 0; i < binaryString.length; i++) {
1668
1668
  bytes[i] = binaryString.charCodeAt(i);
@@ -1677,9 +1677,9 @@ function uint8ArrayToBase64(bytes) {
1677
1677
  return btoa(binaryString);
1678
1678
  }
1679
1679
  function base64urlToUint8Array(base64url3) {
1680
- const base643 = base64url3.replace(/-/g, "+").replace(/_/g, "/");
1681
- const padding = "=".repeat((4 - base643.length % 4) % 4);
1682
- return base64ToUint8Array(base643 + padding);
1680
+ const base644 = base64url3.replace(/-/g, "+").replace(/_/g, "/");
1681
+ const padding = "=".repeat((4 - base644.length % 4) % 4);
1682
+ return base64ToUint8Array(base644 + padding);
1683
1683
  }
1684
1684
  function uint8ArrayToBase64url(bytes) {
1685
1685
  return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
@@ -3045,8 +3045,8 @@ var $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
3045
3045
  function isValidBase64URL(data) {
3046
3046
  if (!base64url.test(data))
3047
3047
  return false;
3048
- const base643 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
3049
- const padded = base643.padEnd(Math.ceil(base643.length / 4) * 4, "=");
3048
+ const base644 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
3049
+ const padded = base644.padEnd(Math.ceil(base644.length / 4) * 4, "=");
3050
3050
  return isValidBase64(padded);
3051
3051
  }
3052
3052
  var $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
@@ -3500,42 +3500,42 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
3500
3500
  }
3501
3501
  doc.write(`const newResult = {};`);
3502
3502
  for (const key of normalized.keys) {
3503
- const id = ids[key];
3503
+ const id2 = ids[key];
3504
3504
  const k = esc(key);
3505
3505
  const schema = shape[key];
3506
3506
  const isOptionalIn = schema?._zod?.optin === "optional";
3507
3507
  const isOptionalOut = schema?._zod?.optout === "optional";
3508
- doc.write(`const ${id} = ${parseStr(key)};`);
3508
+ doc.write(`const ${id2} = ${parseStr(key)};`);
3509
3509
  if (isOptionalIn && isOptionalOut) {
3510
3510
  doc.write(`
3511
- if (${id}.issues.length) {
3511
+ if (${id2}.issues.length) {
3512
3512
  if (${k} in input) {
3513
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
3513
+ payload.issues = payload.issues.concat(${id2}.issues.map(iss => ({
3514
3514
  ...iss,
3515
3515
  path: iss.path ? [${k}, ...iss.path] : [${k}]
3516
3516
  })));
3517
3517
  }
3518
3518
  }
3519
3519
 
3520
- if (${id}.value === undefined) {
3520
+ if (${id2}.value === undefined) {
3521
3521
  if (${k} in input) {
3522
3522
  newResult[${k}] = undefined;
3523
3523
  }
3524
3524
  } else {
3525
- newResult[${k}] = ${id}.value;
3525
+ newResult[${k}] = ${id2}.value;
3526
3526
  }
3527
3527
 
3528
3528
  `);
3529
3529
  } else if (!isOptionalIn) {
3530
3530
  doc.write(`
3531
- const ${id}_present = ${k} in input;
3532
- if (${id}.issues.length) {
3533
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
3531
+ const ${id2}_present = ${k} in input;
3532
+ if (${id2}.issues.length) {
3533
+ payload.issues = payload.issues.concat(${id2}.issues.map(iss => ({
3534
3534
  ...iss,
3535
3535
  path: iss.path ? [${k}, ...iss.path] : [${k}]
3536
3536
  })));
3537
3537
  }
3538
- if (!${id}_present && !${id}.issues.length) {
3538
+ if (!${id2}_present && !${id2}.issues.length) {
3539
3539
  payload.issues.push({
3540
3540
  code: "invalid_type",
3541
3541
  expected: "nonoptional",
@@ -3544,30 +3544,30 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
3544
3544
  });
3545
3545
  }
3546
3546
 
3547
- if (${id}_present) {
3548
- if (${id}.value === undefined) {
3547
+ if (${id2}_present) {
3548
+ if (${id2}.value === undefined) {
3549
3549
  newResult[${k}] = undefined;
3550
3550
  } else {
3551
- newResult[${k}] = ${id}.value;
3551
+ newResult[${k}] = ${id2}.value;
3552
3552
  }
3553
3553
  }
3554
3554
 
3555
3555
  `);
3556
3556
  } else {
3557
3557
  doc.write(`
3558
- if (${id}.issues.length) {
3559
- payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
3558
+ if (${id2}.issues.length) {
3559
+ payload.issues = payload.issues.concat(${id2}.issues.map(iss => ({
3560
3560
  ...iss,
3561
3561
  path: iss.path ? [${k}, ...iss.path] : [${k}]
3562
3562
  })));
3563
3563
  }
3564
3564
 
3565
- if (${id}.value === undefined) {
3565
+ if (${id2}.value === undefined) {
3566
3566
  if (${k} in input) {
3567
3567
  newResult[${k}] = undefined;
3568
3568
  }
3569
3569
  } else {
3570
- newResult[${k}] = ${id}.value;
3570
+ newResult[${k}] = ${id2}.value;
3571
3571
  }
3572
3572
 
3573
3573
  `);
@@ -11899,26 +11899,26 @@ function extractDefs(ctx, schema) {
11899
11899
  throw new Error("Unprocessed schema. This is a bug in Zod.");
11900
11900
  const idToSchema = /* @__PURE__ */ new Map();
11901
11901
  for (const entry of ctx.seen.entries()) {
11902
- const id = ctx.metadataRegistry.get(entry[0])?.id;
11903
- if (id) {
11904
- const existing = idToSchema.get(id);
11902
+ const id2 = ctx.metadataRegistry.get(entry[0])?.id;
11903
+ if (id2) {
11904
+ const existing = idToSchema.get(id2);
11905
11905
  if (existing && existing !== entry[0]) {
11906
- throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
11906
+ throw new Error(`Duplicate schema id "${id2}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
11907
11907
  }
11908
- idToSchema.set(id, entry[0]);
11908
+ idToSchema.set(id2, entry[0]);
11909
11909
  }
11910
11910
  }
11911
11911
  const makeURI = (entry) => {
11912
11912
  const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
11913
11913
  if (ctx.external) {
11914
11914
  const externalId = ctx.external.registry.get(entry[0])?.id;
11915
- const uriGenerator = ctx.external.uri ?? ((id2) => id2);
11915
+ const uriGenerator = ctx.external.uri ?? ((id3) => id3);
11916
11916
  if (externalId) {
11917
11917
  return { ref: uriGenerator(externalId) };
11918
11918
  }
11919
- const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
11920
- entry[1].defId = id;
11921
- return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
11919
+ const id2 = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
11920
+ entry[1].defId = id2;
11921
+ return { defId: id2, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id2}` };
11922
11922
  }
11923
11923
  if (entry[1] === root) {
11924
11924
  return { ref: "#" };
@@ -11966,8 +11966,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
11966
11966
  continue;
11967
11967
  }
11968
11968
  }
11969
- const id = ctx.metadataRegistry.get(entry[0])?.id;
11970
- if (id) {
11969
+ const id2 = ctx.metadataRegistry.get(entry[0])?.id;
11970
+ if (id2) {
11971
11971
  extractToDef(entry);
11972
11972
  continue;
11973
11973
  }
@@ -12063,10 +12063,10 @@ function finalize(ctx, schema) {
12063
12063
  } else {
12064
12064
  }
12065
12065
  if (ctx.external?.uri) {
12066
- const id = ctx.external.registry.get(schema)?.id;
12067
- if (!id)
12066
+ const id2 = ctx.external.registry.get(schema)?.id;
12067
+ if (!id2)
12068
12068
  throw new Error("Schema is missing an `id` property");
12069
- result.$id = ctx.external.uri(id);
12069
+ result.$id = ctx.external.uri(id2);
12070
12070
  }
12071
12071
  Object.assign(result, root.def ?? root.schema);
12072
12072
  const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
@@ -12226,9 +12226,9 @@ var numberProcessor = (schema, ctx, _json, _params) => {
12226
12226
  json2.type = "number";
12227
12227
  const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
12228
12228
  const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
12229
- const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
12229
+ const legacy2 = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
12230
12230
  if (exMin) {
12231
- if (legacy) {
12231
+ if (legacy2) {
12232
12232
  json2.minimum = exclusiveMinimum;
12233
12233
  json2.exclusiveMinimum = true;
12234
12234
  } else {
@@ -12238,7 +12238,7 @@ var numberProcessor = (schema, ctx, _json, _params) => {
12238
12238
  json2.minimum = minimum;
12239
12239
  }
12240
12240
  if (exMax) {
12241
- if (legacy) {
12241
+ if (legacy2) {
12242
12242
  json2.maximum = exclusiveMaximum;
12243
12243
  json2.exclusiveMaximum = true;
12244
12244
  } else {
@@ -13100,7 +13100,7 @@ var safeDecodeAsync2 = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
13100
13100
 
13101
13101
  // ../../../node_modules/zod/v4/classic/schemas.js
13102
13102
  var _installedGroups = /* @__PURE__ */ new WeakMap();
13103
- function _installLazyMethods(inst, group, methods) {
13103
+ function _installLazyMethods(inst, group, methods2) {
13104
13104
  const proto = Object.getPrototypeOf(inst);
13105
13105
  let installed = _installedGroups.get(proto);
13106
13106
  if (!installed) {
@@ -13110,8 +13110,8 @@ function _installLazyMethods(inst, group, methods) {
13110
13110
  if (installed.has(group))
13111
13111
  return;
13112
13112
  installed.add(group);
13113
- for (const key in methods) {
13114
- const fn = methods[key];
13113
+ for (const key in methods2) {
13114
+ const fn = methods2[key];
13115
13115
  Object.defineProperty(proto, key, {
13116
13116
  configurable: true,
13117
13117
  enumerable: false,
@@ -14922,87 +14922,6 @@ function date4(params) {
14922
14922
  // ../../../node_modules/zod/v4/classic/external.js
14923
14923
  config(en_default());
14924
14924
 
14925
- // ../../shared-contracts/dist/ids.js
14926
- var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
14927
- message: "Identifier must not be empty or whitespace"
14928
- });
14929
- var harnessIdSchema = opaqueIdSchema.brand();
14930
- var hostThreadIdSchema = opaqueIdSchema.brand();
14931
- var hostTurnIdSchema = opaqueIdSchema.brand();
14932
- var hostItemIdSchema = opaqueIdSchema.brand();
14933
- var hostInteractionIdSchema = opaqueIdSchema.brand();
14934
-
14935
- // ../../shared-contracts/dist/harness-plugins.js
14936
- var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
14937
- var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
14938
- var HARNESS_PLUGIN_LIMIT = 128;
14939
- var installedPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u);
14940
- var installedHarnessPluginIdSchema = installedPluginIdSchema.pipe(harnessIdSchema);
14941
- var harnessPluginIdSchema = installedHarnessPluginIdSchema.refine((id) => id !== "codex", "The official Codex identity is reserved");
14942
- var pluginRelativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
14943
- var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
14944
- var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
14945
- var harnessInstallationGuideSchema = external_exports.object({
14946
- commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
14947
- before: localizedTextSchema.optional(),
14948
- after: localizedTextSchema.optional(),
14949
- downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
14950
- }).strict();
14951
- var pluginPresentationShape = {
14952
- id: installedHarnessPluginIdSchema,
14953
- name: external_exports.string().trim().min(1).max(128),
14954
- version: external_exports.string().min(1).max(128),
14955
- /** Capability-only plugin; omitted for existing session-capable plugins. */
14956
- kind: external_exports.literal("usage").optional(),
14957
- /** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
14958
- iconStyle: external_exports.object({
14959
- vector: external_exports.object({
14960
- viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
14961
- color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
14962
- paths: external_exports.array(external_exports.object({
14963
- d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
14964
- fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
14965
- fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
14966
- }).strict()).min(1).max(32)
14967
- }).strict().optional(),
14968
- background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
14969
- borderRadius: external_exports.number().min(0).max(50).optional(),
14970
- paddingRatio: external_exports.number().min(0).max(0.25).optional()
14971
- }).strict().optional(),
14972
- installation: harnessInstallationGuideSchema.optional(),
14973
- notice: localizedTextSchema.optional(),
14974
- /** The factory accepts a persisted local entrypoint through its construction context. */
14975
- launchCommand: external_exports.literal(true).optional(),
14976
- links: external_exports.object({
14977
- website: documentationUrlSchema.optional(),
14978
- documentation: documentationUrlSchema.optional(),
14979
- installation: documentationUrlSchema.optional()
14980
- }).strict().optional()
14981
- };
14982
- var harnessPluginManifestSchema = external_exports.object({
14983
- manifestVersion: external_exports.literal(1),
14984
- ...pluginPresentationShape,
14985
- adapterApiVersion: external_exports.number().int().positive(),
14986
- entry: pluginRelativeResourceSchema,
14987
- icon: pluginRelativeResourceSchema.optional()
14988
- }).strict();
14989
- var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
14990
- var harnessPluginDescriptorSchema = external_exports.object({
14991
- ...pluginPresentationShape,
14992
- icon: harnessPluginIconSchema.optional()
14993
- }).strict();
14994
- var harnessPluginListParamsSchema = external_exports.object({}).strict();
14995
- var harnessPluginListResultSchema = external_exports.object({
14996
- plugins: external_exports.array(harnessPluginDescriptorSchema.extend({ id: harnessPluginIdSchema })).max(HARNESS_PLUGIN_LIMIT)
14997
- }).strict();
14998
- var harnessPluginConfigurationSchema = external_exports.object({
14999
- version: external_exports.literal(1),
15000
- enabled: external_exports.array(installedHarnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
15001
- }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
15002
- message: "Enabled plugin IDs must be unique",
15003
- path: ["enabled"]
15004
- });
15005
-
15006
14925
  // ../../shared-contracts/dist/json-value.js
15007
14926
  function rejectExplicitUndefined(keys) {
15008
14927
  return (value, context) => {
@@ -15062,403 +14981,73 @@ var jsonValueSchema = nonCircularSchema.pipe(recursiveJsonValueSchema);
15062
14981
  var jsonArraySchema = nonCircularSchema.pipe(external_exports.array(recursiveJsonValueSchema));
15063
14982
  var jsonObjectSchema = nonCircularSchema.pipe(external_exports.record(external_exports.string(), recursiveJsonValueSchema));
15064
14983
 
15065
- // ../../shared-contracts/dist/desktop-extensions.js
15066
- var DESKTOP_EXTENSION_API_VERSION = 1;
15067
- var DESKTOP_EXTENSION_LIMIT = 64;
15068
- var DESKTOP_EXTENSION_ZIP_MAX_BYTES = 64 * 1024 * 1024;
15069
- var DESKTOP_EXTENSION_ZIP_MAX_BASE64_LENGTH = 4 * Math.ceil(DESKTOP_EXTENSION_ZIP_MAX_BYTES / 3);
15070
- var DESKTOP_EXTENSION_MANIFEST_MAX_BYTES = 128 * 1024;
15071
- var DESKTOP_EXTENSION_SCRIPT_MAX_BYTES = 2 * 1024 * 1024;
15072
- var DESKTOP_EXTENSION_STYLE_MAX_BYTES = 256 * 1024;
15073
- var DESKTOP_EXTENSION_ICON_MAX_BYTES = 128 * 1024;
15074
- var DESKTOP_EXTENSION_SCREENSHOT_LIMIT = 4;
15075
- var DESKTOP_EXTENSION_SCREENSHOT_MAX_BYTES = 512 * 1024;
15076
- var DESKTOP_EXTENSION_LIST_SCREENSHOTS_MAX_BYTES = 8 * 1024 * 1024;
15077
- var DESKTOP_EXTENSION_SNAPSHOT_MAX_BYTES = 8 * 1024 * 1024;
15078
- var DESKTOP_EXTENSION_ASSET_MAX_BYTES = 16 * 1024 * 1024;
15079
- var DESKTOP_EXTENSION_SETTINGS_MAX_BYTES = 1024 * 1024;
15080
- var desktopExtensionIdSchema = installedPluginIdSchema;
15081
- var desktopExtensionSlotSchema = external_exports.enum([
15082
- "sidebar.thread-layout",
15083
- "sidebar.thread-badge",
15084
- "appearance.theme"
15085
- ]);
15086
- var desktopExtensionCategorySchema = external_exports.enum([
15087
- "appearance",
15088
- "interface",
15089
- "workflow",
15090
- "analytics",
15091
- "integrations",
15092
- "tools"
15093
- ]);
15094
- var extensionName = external_exports.string().trim().min(1).max(128);
15095
- function desktopExtensionScreenshotMimeType(resource) {
15096
- switch (resource.match(/\.([^./]+)$/u)?.[1]?.toLowerCase()) {
15097
- case "png":
15098
- return "image/png";
15099
- case "jpg":
15100
- case "jpeg":
15101
- return "image/jpeg";
15102
- case "webp":
15103
- return "image/webp";
15104
- default:
15105
- return void 0;
14984
+ // ../../shared-contracts/dist/errors.js
14985
+ var codexhostErrorSchema = external_exports.strictObject({
14986
+ code: external_exports.string().min(1),
14987
+ message: external_exports.string().min(1),
14988
+ retryable: external_exports.boolean(),
14989
+ diagnostic: external_exports.string().min(1).optional(),
14990
+ stage: external_exports.string().min(1).optional(),
14991
+ durationMs: external_exports.number().int().nonnegative().optional(),
14992
+ stderrTail: external_exports.string().min(1).optional()
14993
+ }).superRefine(rejectExplicitUndefined(["diagnostic", "stage", "durationMs", "stderrTail"]));
14994
+
14995
+ // ../../shared-contracts/dist/harness-presentation.js
14996
+ var localeSchema = external_exports.string().max(64).regex(/^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u);
14997
+ var displayText = (maximum) => external_exports.string().min(1).max(maximum).refine((text) => text.trim().length > 0);
14998
+ var harnessLocalizationsSchema = external_exports.record(localeSchema, external_exports.object({
14999
+ label: displayText(256).optional(),
15000
+ description: displayText(1024).optional()
15001
+ }).strict()).refine((entries) => Object.keys(entries).length <= 16, "Too many locales");
15002
+ var harnessLocalizedTextSchema = external_exports.record(localeSchema, displayText(4096)).refine((entries) => typeof entries.en === "string", "English fallback is required").refine((entries) => Object.keys(entries).length <= 16, "Too many locales");
15003
+
15004
+ // ../../shared-contracts/dist/ids.js
15005
+ var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
15006
+ message: "Identifier must not be empty or whitespace"
15007
+ });
15008
+ var harnessIdSchema = opaqueIdSchema.brand();
15009
+ var hostThreadIdSchema = opaqueIdSchema.brand();
15010
+ var hostTurnIdSchema = opaqueIdSchema.brand();
15011
+ var hostItemIdSchema = opaqueIdSchema.brand();
15012
+ var hostInteractionIdSchema = opaqueIdSchema.brand();
15013
+
15014
+ // ../../shared-contracts/dist/harness-permission-modes.js
15015
+ var HARNESS_PERMISSION_MODE_ID_MAX_LENGTH = 128;
15016
+ var HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH = 256;
15017
+ var HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH = 1024;
15018
+ var HARNESS_PERMISSION_MODE_CATALOG_MAX_LENGTH = 32;
15019
+ var nonBlankTextSchema = external_exports.string().refine((value) => value.trim().length > 0, {
15020
+ message: "Value must not be empty or whitespace"
15021
+ });
15022
+ var harnessPermissionModeIdSchema = nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~:-]+$/u, "Permission Mode ID must use transport-safe characters").brand();
15023
+ var harnessPermissionModeSchema = external_exports.object({
15024
+ id: harnessPermissionModeIdSchema,
15025
+ label: nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH),
15026
+ description: nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH).optional(),
15027
+ dangerous: external_exports.boolean().optional(),
15028
+ localizations: harnessLocalizationsSchema.optional()
15029
+ }).strict();
15030
+ var harnessPermissionModeCatalogSchema = external_exports.object({
15031
+ modes: external_exports.array(harnessPermissionModeSchema).min(1).max(HARNESS_PERMISSION_MODE_CATALOG_MAX_LENGTH),
15032
+ defaultModeId: harnessPermissionModeIdSchema
15033
+ }).strict().superRefine((catalog, context) => {
15034
+ const ids = /* @__PURE__ */ new Set();
15035
+ for (const [index, mode] of catalog.modes.entries()) {
15036
+ if (ids.has(mode.id)) {
15037
+ context.addIssue({
15038
+ code: "custom",
15039
+ message: "Permission Mode IDs must be unique",
15040
+ path: ["modes", index, "id"]
15041
+ });
15042
+ }
15043
+ ids.add(mode.id);
15106
15044
  }
15107
- }
15108
- function desktopExtensionAssetMimeType(resource) {
15109
- switch (resource.match(/\.([^./]+)$/u)?.[1]?.toLowerCase()) {
15110
- case "gif":
15111
- return "image/gif";
15112
- case "svg":
15113
- return "image/svg+xml";
15114
- case "woff2":
15115
- return "font/woff2";
15116
- case "json":
15117
- return "application/json";
15118
- case "css":
15119
- return "text/css";
15120
- default:
15121
- return desktopExtensionScreenshotMimeType(resource);
15122
- }
15123
- }
15124
- var hasPortableSegments = (resource) => resource.split("/").every((segment) => !/[. ]$/u.test(segment));
15125
- var desktopExtensionAssetPathSchema = pluginRelativeResourceSchema.refine((resource) => hasPortableSegments(resource) && desktopExtensionAssetMimeType(resource) !== void 0, "Expected a relative Desktop extension asset path with a supported suffix");
15126
- var imagePathSchema = pluginRelativeResourceSchema.refine((resource) => desktopExtensionScreenshotMimeType(resource) !== void 0 && hasPortableSegments(resource), "Images must be relative .png, .jpg, .jpeg, or .webp paths with no segments ending in a dot or space");
15127
- var desktopExtensionHttpUrlSchema = external_exports.string().trim().max(2048).regex(/^https?:\/\/[^/?#\\\s]+/iu, "Expected an HTTP(S) URL").pipe(external_exports.url({ protocol: /^https?$/u })).refine((value) => {
15128
- const { username, password } = new URL(value);
15129
- return !username && !password && !/[\\\s]/u.test(value);
15130
- }, "URL must not contain credentials, backslashes, or whitespace");
15131
- function localizedText(text) {
15132
- return external_exports.strictObject({ en: text, "zh-CN": text });
15133
- }
15134
- var desktopExtensionLocalizedTextSchema = localizedText(external_exports.string().trim().min(1));
15135
- var categoriesSchema = external_exports.array(desktopExtensionCategorySchema).max(desktopExtensionCategorySchema.options.length).refine((categories) => new Set(categories).size === categories.length, "Duplicate categories");
15136
- var slotsSchema = external_exports.array(desktopExtensionSlotSchema).max(desktopExtensionSlotSchema.options.length).refine((slots) => new Set(slots).size === slots.length, "Duplicate slots");
15137
- var settingField = {
15138
- key: external_exports.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/u),
15139
- label: desktopExtensionLocalizedTextSchema,
15140
- description: desktopExtensionLocalizedTextSchema.optional()
15141
- };
15142
- var numericSetting = {
15143
- ...settingField,
15144
- step: external_exports.number().positive().optional(),
15145
- default: external_exports.number().optional()
15146
- };
15147
- var settingOption = external_exports.strictObject({
15148
- value: external_exports.string(),
15149
- label: desktopExtensionLocalizedTextSchema
15150
- });
15151
- var desktopExtensionSettingFieldSchema = external_exports.discriminatedUnion("type", [
15152
- external_exports.strictObject({
15153
- ...settingField,
15154
- type: external_exports.literal("boolean"),
15155
- default: external_exports.boolean().optional()
15156
- }),
15157
- external_exports.strictObject({
15158
- ...settingField,
15159
- type: external_exports.literal("string"),
15160
- placeholder: desktopExtensionLocalizedTextSchema.optional(),
15161
- default: external_exports.string().optional()
15162
- }),
15163
- external_exports.strictObject({
15164
- ...numericSetting,
15165
- type: external_exports.literal("number"),
15166
- min: external_exports.number().optional(),
15167
- max: external_exports.number().optional()
15168
- }),
15169
- external_exports.strictObject({
15170
- ...numericSetting,
15171
- type: external_exports.literal("range"),
15172
- min: external_exports.number(),
15173
- max: external_exports.number()
15174
- }),
15175
- external_exports.strictObject({
15176
- ...settingField,
15177
- type: external_exports.literal("select"),
15178
- options: external_exports.array(settingOption).min(1),
15179
- default: external_exports.string().optional()
15180
- })
15181
- ]).superRefine((field2, ctx) => {
15182
- const issue2 = (path9, message3) => ctx.addIssue({ code: "custom", path: [path9], message: message3 });
15183
- if (field2.type === "number" || field2.type === "range") {
15184
- const { min = -Infinity, max = Infinity, default: value } = field2;
15185
- if (min > max)
15186
- issue2("max", "Must be at least min");
15187
- if (value !== void 0 && (value < min || value > max))
15188
- issue2("default", "Must be within min and max");
15189
- } else if (field2.type === "select") {
15190
- const values = new Set(field2.options.map(({ value }) => value));
15191
- if (values.size !== field2.options.length)
15192
- issue2("options", "Duplicate option values");
15193
- if (field2.default !== void 0 && !values.has(field2.default))
15194
- issue2("default", "Must match an option value");
15195
- }
15196
- });
15197
- var manifestHeader = external_exports.object({
15198
- manifestVersion: external_exports.int().positive(),
15199
- id: desktopExtensionIdSchema,
15200
- name: external_exports.union([extensionName, localizedText(extensionName)]),
15201
- version: external_exports.string().min(1).max(128),
15202
- desktopApi: external_exports.int().positive()
15203
- }).passthrough();
15204
- var desktopExtensionManifestSchema = manifestHeader.extend({
15205
- manifestVersion: external_exports.literal(1),
15206
- desktopApi: external_exports.literal(DESKTOP_EXTENSION_API_VERSION),
15207
- description: external_exports.strictObject({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).optional(),
15208
- author: external_exports.string().trim().min(1).max(128).optional(),
15209
- repository: desktopExtensionHttpUrlSchema.optional(),
15210
- details: external_exports.strictObject({ en: external_exports.string().max(16384), "zh-CN": external_exports.string().max(16384).optional() }).optional(),
15211
- icon: imagePathSchema.optional(),
15212
- screenshots: external_exports.array(imagePathSchema).max(DESKTOP_EXTENSION_SCREENSHOT_LIMIT).refine((screenshots) => new Set(screenshots).size === screenshots.length, "Duplicate screenshots").optional(),
15213
- desktop: external_exports.strictObject({
15214
- script: pluginRelativeResourceSchema,
15215
- style: pluginRelativeResourceSchema.optional()
15216
- }).optional(),
15217
- backend: external_exports.strictObject({ script: pluginRelativeResourceSchema.refine(hasPortableSegments) }).optional(),
15218
- slots: slotsSchema.default(() => []),
15219
- settingsSchema: external_exports.array(desktopExtensionSettingFieldSchema).max(32).refine((fields) => new Set(fields.map(({ key }) => key)).size === fields.length, "Duplicate setting keys").optional(),
15220
- categories: categoriesSchema.optional()
15221
- }).strict().refine((manifest) => manifest.desktop !== void 0 || manifest.backend !== void 0, "Expected at least one desktop or backend entry");
15222
- var desktopExtensionConfigurationSchema = external_exports.strictObject({
15223
- version: external_exports.literal(1),
15224
- revision: external_exports.int().nonnegative(),
15225
- enabled: external_exports.array(desktopExtensionIdSchema).max(DESKTOP_EXTENSION_LIMIT).refine((ids) => new Set(ids).size === ids.length, "Duplicate extension IDs"),
15226
- reloadToken: external_exports.uuid().optional()
15227
- });
15228
- var desktopExtensionHashSchema = external_exports.string().regex(/^[a-f0-9]{64}$/u);
15229
- var desktopExtensionStatusSchema = external_exports.strictObject({
15230
- state: external_exports.enum([
15231
- "running",
15232
- "disabled",
15233
- "invalid",
15234
- "incompatible",
15235
- "conflict",
15236
- "failed",
15237
- "waiting"
15238
- ]),
15239
- hash: desktopExtensionHashSchema.optional(),
15240
- error: external_exports.string().optional(),
15241
- conflictWith: desktopExtensionIdSchema.optional()
15242
- });
15243
- var desktopExtensionsDiagnosticSchema = external_exports.strictObject({
15244
- controllerPid: external_exports.int().positive(),
15245
- targetId: external_exports.string().nullable(),
15246
- updatedAt: external_exports.iso.datetime(),
15247
- handledReloadToken: external_exports.uuid().optional(),
15248
- extensions: external_exports.record(external_exports.string(), desktopExtensionStatusSchema)
15249
- });
15250
- var desktopExtensionTrustTierSchema = external_exports.enum(["official", "community"]);
15251
- function isGitHubDesktopExtensionZipballUrl(url2) {
15252
- return url2.origin === "https://api.github.com" && /^\/repos\/[\w-]+\/[\w.-]+\/zipball(?:\/[^/]+)?\/?$/u.test(url2.pathname);
15253
- }
15254
- var desktopExtensionZipUrlSchema = desktopExtensionHttpUrlSchema.refine((input) => {
15255
- const url2 = new URL(input);
15256
- return /\.zip$/iu.test(url2.pathname) || isGitHubDesktopExtensionZipballUrl(url2) || url2.origin === "https://github.com" && /^\/[\w-]+\/[\w.-]+\/zipball(?:\/.+)?\/?$/u.test(url2.pathname) || url2.origin === "https://codeload.github.com" && /^\/[\w-]+\/[\w.-]+\/(?:zip|zipball|legacy\.zip)\/.+$/u.test(url2.pathname);
15257
- }, "Expected a .zip download URL or a GitHub zipball URL");
15258
- var desktopExtensionCatalogEntrySchema = external_exports.strictObject({
15259
- id: desktopExtensionIdSchema,
15260
- version: external_exports.string().trim().min(1).max(128),
15261
- name: desktopExtensionLocalizedTextSchema.extend({ en: extensionName, "zh-CN": extensionName }),
15262
- description: localizedText(external_exports.string().trim().min(1).max(4096)),
15263
- details: localizedText(external_exports.string().trim().min(1).max(16384)).optional(),
15264
- author: external_exports.string().trim().min(1).max(128),
15265
- repository: desktopExtensionHttpUrlSchema,
15266
- stars: external_exports.number().int().min(0).optional(),
15267
- downloads: external_exports.number().int().min(0).optional(),
15268
- categories: categoriesSchema.optional(),
15269
- trustTier: desktopExtensionTrustTierSchema.default("community"),
15270
- icon: desktopExtensionHttpUrlSchema.optional(),
15271
- screenshots: external_exports.array(desktopExtensionHttpUrlSchema).max(DESKTOP_EXTENSION_SCREENSHOT_LIMIT).optional(),
15272
- downloadUrl: desktopExtensionZipUrlSchema,
15273
- sha256: desktopExtensionHashSchema,
15274
- slots: slotsSchema.optional(),
15275
- publishedAt: external_exports.string().optional(),
15276
- updatedAt: external_exports.string().optional(),
15277
- minCodexHostVersion: external_exports.string().optional()
15278
- });
15279
- var desktopExtensionCatalogSchema = external_exports.strictObject({
15280
- schemaVersion: external_exports.literal(1),
15281
- generatedAt: external_exports.string(),
15282
- extensions: external_exports.array(desktopExtensionCatalogEntrySchema).refine((entries) => new Set(entries.map(({ id }) => id)).size === entries.length, "Duplicate extension IDs")
15283
- });
15284
- var DESKTOP_EXTENSIONS_ASSET_METHOD = "codexhost/desktop/extensions/asset";
15285
- var DESKTOP_EXTENSIONS_SETTINGS_GET_METHOD = "codexhost/desktop/extensions/settings/get";
15286
- var DESKTOP_EXTENSIONS_SETTINGS_SET_METHOD = "codexhost/desktop/extensions/settings/set";
15287
- var DESKTOP_EXTENSIONS_BACKEND_INVOKE_METHOD = "codexhost/desktop/extensions/backend/invoke";
15288
- var extensionIdParams = { id: desktopExtensionIdSchema };
15289
- var desktopExtensionsAssetParamsSchema = external_exports.strictObject({
15290
- ...extensionIdParams,
15291
- path: desktopExtensionAssetPathSchema
15292
- });
15293
- var desktopExtensionsAssetResultSchema = external_exports.strictObject({
15294
- mimeType: external_exports.string(),
15295
- dataUrl: external_exports.string()
15296
- });
15297
- var desktopExtensionsSettingsGetParamsSchema = external_exports.strictObject(extensionIdParams);
15298
- var desktopExtensionsSettingsSetParamsSchema = external_exports.strictObject({
15299
- ...extensionIdParams,
15300
- values: jsonObjectSchema
15301
- });
15302
- var desktopExtensionsSettingsResultSchema = external_exports.strictObject({ values: jsonObjectSchema });
15303
- var desktopExtensionBackendMethodSchema = external_exports.string().trim().min(1).max(128);
15304
- var desktopExtensionsBackendInvokeParamsSchema = external_exports.strictObject({
15305
- ...extensionIdParams,
15306
- method: desktopExtensionBackendMethodSchema,
15307
- params: jsonValueSchema.optional()
15308
- });
15309
- var desktopExtensionsBackendInvokeResultSchema = external_exports.strictObject({
15310
- result: jsonValueSchema
15311
- });
15312
-
15313
- // ../../shared-contracts/dist/desktop-extension-management.js
15314
- var DESKTOP_EXTENSIONS_LIST_METHOD = "codexhost/desktop/extensions/list";
15315
- var DESKTOP_EXTENSIONS_ENABLE_METHOD = "codexhost/desktop/extensions/enable";
15316
- var DESKTOP_EXTENSIONS_DISABLE_METHOD = "codexhost/desktop/extensions/disable";
15317
- var DESKTOP_EXTENSIONS_CATALOG_METHOD = "codexhost/desktop/extensions/catalog";
15318
- var DESKTOP_EXTENSIONS_INSTALL_METHOD = "codexhost/desktop/extensions/install";
15319
- var DESKTOP_EXTENSIONS_UNINSTALL_METHOD = "codexhost/desktop/extensions/uninstall";
15320
- var DESKTOP_EXTENSIONS_RECOVER_METHOD = "codexhost/desktop/extensions/disable-all-and-reload";
15321
- var DESKTOP_EXTENSION_MANAGEMENT_METHODS = [
15322
- DESKTOP_EXTENSIONS_LIST_METHOD,
15323
- DESKTOP_EXTENSIONS_ENABLE_METHOD,
15324
- DESKTOP_EXTENSIONS_DISABLE_METHOD,
15325
- DESKTOP_EXTENSIONS_RECOVER_METHOD,
15326
- DESKTOP_EXTENSIONS_CATALOG_METHOD,
15327
- DESKTOP_EXTENSIONS_INSTALL_METHOD,
15328
- DESKTOP_EXTENSIONS_UNINSTALL_METHOD,
15329
- DESKTOP_EXTENSIONS_ASSET_METHOD,
15330
- DESKTOP_EXTENSIONS_SETTINGS_GET_METHOD,
15331
- DESKTOP_EXTENSIONS_SETTINGS_SET_METHOD,
15332
- DESKTOP_EXTENSIONS_BACKEND_INVOKE_METHOD
15333
- ];
15334
- var revisionSchema = external_exports.int().nonnegative();
15335
- var desktopExtensionsListParamsSchema = external_exports.strictObject({});
15336
- var desktopExtensionSelectionParamsSchema = external_exports.strictObject({
15337
- id: desktopExtensionIdSchema,
15338
- expectedRevision: revisionSchema
15339
- });
15340
- var desktopExtensionsRecoveryParamsSchema = external_exports.strictObject({
15341
- expectedRevision: revisionSchema.optional()
15342
- });
15343
- var rasterDataUrlSchema = (maxBytes) => external_exports.string().max("data:image/jpeg;base64,".length + 4 * Math.ceil(maxBytes / 3)).regex(/^data:image\/(?:png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/u);
15344
- var desktopExtensionListItemSchema = external_exports.strictObject({
15345
- // An invalid discovery can have a directory name that isn't a valid extension ID.
15346
- id: external_exports.string().min(1),
15347
- manifest: desktopExtensionManifestSchema.optional(),
15348
- iconDataUrl: rasterDataUrlSchema(DESKTOP_EXTENSION_ICON_MAX_BYTES).optional(),
15349
- screenshotDataUrls: external_exports.array(rasterDataUrlSchema(DESKTOP_EXTENSION_SCREENSHOT_MAX_BYTES)).max(DESKTOP_EXTENSION_SCREENSHOT_LIMIT).optional(),
15350
- enabled: external_exports.boolean(),
15351
- status: desktopExtensionStatusSchema
15352
- });
15353
- var desktopExtensionsListResultSchema = external_exports.strictObject({
15354
- configuration: desktopExtensionConfigurationSchema,
15355
- desktopConnected: external_exports.boolean(),
15356
- diagnostics: external_exports.array(external_exports.string()),
15357
- extensions: external_exports.array(desktopExtensionListItemSchema)
15358
- });
15359
- var desktopExtensionsCatalogParamsSchema = external_exports.strictObject({
15360
- forceRefresh: external_exports.boolean().optional()
15361
- });
15362
- var desktopExtensionsCatalogResultSchema = external_exports.strictObject({
15363
- catalogUrl: external_exports.string(),
15364
- source: external_exports.enum(["remote", "fallback"]),
15365
- fetchedAt: external_exports.string(),
15366
- cached: external_exports.boolean(),
15367
- extensions: desktopExtensionCatalogSchema.shape.extensions,
15368
- error: external_exports.string().optional()
15369
- });
15370
- var desktopExtensionsInstallParamsSchema = external_exports.strictObject({
15371
- source: external_exports.discriminatedUnion("type", [
15372
- external_exports.strictObject({ type: external_exports.literal("catalog"), id: desktopExtensionIdSchema }),
15373
- external_exports.strictObject({
15374
- type: external_exports.literal("url"),
15375
- url: desktopExtensionHttpUrlSchema,
15376
- expectedSha256: desktopExtensionHashSchema.optional()
15377
- }),
15378
- external_exports.strictObject({
15379
- type: external_exports.literal("zip-base64"),
15380
- fileName: external_exports.string().trim().min(1).max(255),
15381
- contentBase64: external_exports.string().min(4).max(DESKTOP_EXTENSION_ZIP_MAX_BASE64_LENGTH).refine((value) => value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/u.test(value), "Expected standard padded base64")
15382
- })
15383
- ])
15384
- });
15385
- var desktopExtensionsInstallResultSchema = external_exports.strictObject({
15386
- extensionId: desktopExtensionIdSchema,
15387
- version: external_exports.string().min(1),
15388
- replaced: external_exports.boolean(),
15389
- installedPath: external_exports.string(),
15390
- list: desktopExtensionsListResultSchema
15391
- });
15392
- var desktopExtensionsUninstallParamsSchema = external_exports.strictObject({
15393
- id: desktopExtensionIdSchema
15394
- });
15395
- var desktopExtensionsUninstallResultSchema = external_exports.strictObject({
15396
- removedId: desktopExtensionIdSchema,
15397
- list: desktopExtensionsListResultSchema
15398
- });
15399
- var desktopExtensionMutationResultSchema = external_exports.discriminatedUnion("state", [
15400
- external_exports.strictObject({ state: external_exports.literal("saved"), configuration: desktopExtensionConfigurationSchema }),
15401
- external_exports.strictObject({ state: external_exports.literal("slot-conflict"), conflictWith: desktopExtensionIdSchema }),
15402
- external_exports.strictObject({ state: external_exports.literal("revision-conflict"), revision: revisionSchema })
15403
- ]);
15404
-
15405
- // ../../shared-contracts/dist/errors.js
15406
- var codexhostErrorSchema = external_exports.strictObject({
15407
- code: external_exports.string().min(1),
15408
- message: external_exports.string().min(1),
15409
- retryable: external_exports.boolean(),
15410
- diagnostic: external_exports.string().min(1).optional(),
15411
- stage: external_exports.string().min(1).optional(),
15412
- durationMs: external_exports.number().int().nonnegative().optional(),
15413
- stderrTail: external_exports.string().min(1).optional()
15414
- }).superRefine(rejectExplicitUndefined(["diagnostic", "stage", "durationMs", "stderrTail"]));
15415
-
15416
- // ../../shared-contracts/dist/harness-presentation.js
15417
- var localeSchema = external_exports.string().max(64).regex(/^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u);
15418
- var displayText = (maximum) => external_exports.string().min(1).max(maximum).refine((text) => text.trim().length > 0);
15419
- var harnessLocalizationsSchema = external_exports.record(localeSchema, external_exports.object({
15420
- label: displayText(256).optional(),
15421
- description: displayText(1024).optional()
15422
- }).strict()).refine((entries) => Object.keys(entries).length <= 16, "Too many locales");
15423
- var harnessLocalizedTextSchema = external_exports.record(localeSchema, displayText(4096)).refine((entries) => typeof entries.en === "string", "English fallback is required").refine((entries) => Object.keys(entries).length <= 16, "Too many locales");
15424
-
15425
- // ../../shared-contracts/dist/harness-permission-modes.js
15426
- var HARNESS_PERMISSION_MODE_ID_MAX_LENGTH = 128;
15427
- var HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH = 256;
15428
- var HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH = 1024;
15429
- var HARNESS_PERMISSION_MODE_CATALOG_MAX_LENGTH = 32;
15430
- var nonBlankTextSchema = external_exports.string().refine((value) => value.trim().length > 0, {
15431
- message: "Value must not be empty or whitespace"
15432
- });
15433
- var harnessPermissionModeIdSchema = nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~:-]+$/u, "Permission Mode ID must use transport-safe characters").brand();
15434
- var harnessPermissionModeSchema = external_exports.object({
15435
- id: harnessPermissionModeIdSchema,
15436
- label: nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH),
15437
- description: nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH).optional(),
15438
- dangerous: external_exports.boolean().optional(),
15439
- localizations: harnessLocalizationsSchema.optional()
15440
- }).strict();
15441
- var harnessPermissionModeCatalogSchema = external_exports.object({
15442
- modes: external_exports.array(harnessPermissionModeSchema).min(1).max(HARNESS_PERMISSION_MODE_CATALOG_MAX_LENGTH),
15443
- defaultModeId: harnessPermissionModeIdSchema
15444
- }).strict().superRefine((catalog, context) => {
15445
- const ids = /* @__PURE__ */ new Set();
15446
- for (const [index, mode] of catalog.modes.entries()) {
15447
- if (ids.has(mode.id)) {
15448
- context.addIssue({
15449
- code: "custom",
15450
- message: "Permission Mode IDs must be unique",
15451
- path: ["modes", index, "id"]
15452
- });
15453
- }
15454
- ids.add(mode.id);
15455
- }
15456
- if (!ids.has(catalog.defaultModeId)) {
15457
- context.addIssue({
15458
- code: "custom",
15459
- message: "Default Permission Mode must exist in the catalog",
15460
- path: ["defaultModeId"]
15461
- });
15045
+ if (!ids.has(catalog.defaultModeId)) {
15046
+ context.addIssue({
15047
+ code: "custom",
15048
+ message: "Default Permission Mode must exist in the catalog",
15049
+ path: ["defaultModeId"]
15050
+ });
15462
15051
  }
15463
15052
  });
15464
15053
  var threadPermissionModeSelectParamsSchema = external_exports.object({
@@ -15466,6 +15055,9 @@ var threadPermissionModeSelectParamsSchema = external_exports.object({
15466
15055
  permissionModeId: harnessPermissionModeIdSchema
15467
15056
  }).strict();
15468
15057
 
15058
+ // ../../shared-contracts/dist/harness-route-limit.js
15059
+ var HARNESS_TRANSPORT_MODEL_ID_MAX_LENGTH = 8192;
15060
+
15469
15061
  // ../../shared-contracts/dist/thread-usage.js
15470
15062
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
15471
15063
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
@@ -15498,7 +15090,7 @@ var composerIndicatorsSchema = external_exports.array(external_exports.object({
15498
15090
  expiresAtUnix: nonNegativeSafeIntegerSchema,
15499
15091
  label: indicatorTextSchema(256).optional(),
15500
15092
  tooltip: indicatorTextSchema(1024).optional()
15501
- }).strict()).max(2).refine((entries) => new Set(entries.map(({ id }) => id)).size === entries.length, {
15093
+ }).strict()).max(2).refine((entries) => new Set(entries.map(({ id: id2 }) => id2)).size === entries.length, {
15502
15094
  message: "Composer indicator IDs must be unique"
15503
15095
  });
15504
15096
  var threadUsageSnapshotSchema = external_exports.object({
@@ -15524,6 +15116,7 @@ var threadUsageSnapshotSchema = external_exports.object({
15524
15116
  planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
15525
15117
  sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
15526
15118
  timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
15119
+ latestRequestTimeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
15527
15120
  costSource: external_exports.enum(["publicPrice", "native"]).optional(),
15528
15121
  unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
15529
15122
  }).strict().superRefine((usage, context) => {
@@ -15651,10 +15244,15 @@ var THREAD_OWNERSHIP_LIST_MAX_LENGTH = 100;
15651
15244
  var nonBlankTextSchema2 = external_exports.string().refine((value) => value.trim().length > 0, {
15652
15245
  message: "Value must not be empty or whitespace"
15653
15246
  });
15654
- var harnessModelRefIdSchema = nonBlankTextSchema2.max(HARNESS_MODEL_REF_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Model Ref must use transport-safe opaque characters").brand();
15247
+ var harnessModelRefIdSchema = external_exports.string().min(1).max(HARNESS_MODEL_REF_MAX_LENGTH).refine((id2) => !new RegExp("\\p{Cc}", "u").test(id2), "Model Ref must not contain control characters").brand();
15248
+ var harnessModelServiceTierSchema = external_exports.enum(["priority", "ultrafast"]);
15655
15249
  var harnessModelRefSchema = external_exports.object({
15656
- id: harnessModelRefIdSchema
15250
+ id: harnessModelRefIdSchema,
15251
+ serviceTier: harnessModelServiceTierSchema.optional()
15657
15252
  }).strict();
15253
+ function sameHarnessModelRef(left, right) {
15254
+ return left?.id === right?.id && left?.serviceTier === right?.serviceTier;
15255
+ }
15658
15256
  var harnessThinkingOptionIdSchema = nonBlankTextSchema2.max(HARNESS_THINKING_OPTION_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Thinking option ID must use transport-safe characters").brand();
15659
15257
  var harnessResolvedModelLabelSchema = nonBlankTextSchema2.max(HARNESS_MODEL_LABEL_MAX_LENGTH);
15660
15258
  var harnessThinkingOptionSchema = external_exports.object({
@@ -15668,7 +15266,15 @@ var harnessModelSchema = external_exports.object({
15668
15266
  /** Optional opaque selection for this same Model with priority processing enabled. */
15669
15267
  fastModel: harnessModelRefSchema.optional(),
15670
15268
  supportedThinkingOptionIds: external_exports.array(harnessThinkingOptionIdSchema).optional()
15671
- }).strict();
15269
+ }).strict().refine((model2) => model2.fastModel?.serviceTier === void 0 || model2.fastModel.id === model2.ref.id, {
15270
+ path: ["fastModel", "id"],
15271
+ message: "A tiered Fast Model must share the base Model ID"
15272
+ });
15273
+ function catalogModelForRef(catalog, ref) {
15274
+ if (!ref)
15275
+ return void 0;
15276
+ return catalog?.models.find((model2) => sameHarnessModelRef(model2.ref, ref) || sameHarnessModelRef(model2.fastModel, ref));
15277
+ }
15672
15278
  var harnessThinkingOptionsSchema = external_exports.array(harnessThinkingOptionSchema).superRefine((options, context) => {
15673
15279
  const ids = /* @__PURE__ */ new Set();
15674
15280
  for (const [index, option] of options.entries()) {
@@ -15688,26 +15294,26 @@ var harnessModelCatalogSchema = external_exports.object({
15688
15294
  thinkingOptions: harnessThinkingOptionsSchema,
15689
15295
  defaultThinkingOptionId: harnessThinkingOptionIdSchema.optional()
15690
15296
  }).strict().superRefine((catalog, context) => {
15691
- const refs = /* @__PURE__ */ new Set();
15692
- const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
15297
+ const refs = [];
15298
+ const thinkingIds = new Set(catalog.thinkingOptions.map(({ id: id2 }) => id2));
15693
15299
  for (const [index, model2] of catalog.models.entries()) {
15694
- if (refs.has(model2.ref.id)) {
15300
+ if (refs.some((ref) => sameHarnessModelRef(ref, model2.ref))) {
15695
15301
  context.addIssue({
15696
15302
  code: "custom",
15697
15303
  message: "Model Catalog refs must be unique",
15698
15304
  path: ["models", index, "ref", "id"]
15699
15305
  });
15700
15306
  }
15701
- refs.add(model2.ref.id);
15307
+ refs.push(model2.ref);
15702
15308
  if (model2.fastModel) {
15703
- if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
15309
+ if (refs.some((ref) => sameHarnessModelRef(ref, model2.fastModel))) {
15704
15310
  context.addIssue({
15705
15311
  code: "custom",
15706
15312
  message: "Fast Model refs must be distinct and unique",
15707
15313
  path: ["models", index, "fastModel"]
15708
15314
  });
15709
15315
  }
15710
- refs.add(model2.fastModel.id);
15316
+ refs.push(model2.fastModel);
15711
15317
  }
15712
15318
  const supportedThinkingIds = /* @__PURE__ */ new Set();
15713
15319
  for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
@@ -15728,7 +15334,7 @@ var harnessModelCatalogSchema = external_exports.object({
15728
15334
  }
15729
15335
  }
15730
15336
  }
15731
- if (catalog.defaultModel && !refs.has(catalog.defaultModel.id)) {
15337
+ if (catalog.defaultModel && !catalogModelForRef(catalog, catalog.defaultModel)) {
15732
15338
  context.addIssue({
15733
15339
  code: "custom",
15734
15340
  message: "Default Model must exist in the Model Catalog",
@@ -15768,7 +15374,12 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
15768
15374
  observe: external_exports.boolean()
15769
15375
  }).strict().optional(),
15770
15376
  /** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
15771
- steer: external_exports.boolean().optional()
15377
+ steer: external_exports.boolean().optional(),
15378
+ /**
15379
+ * True when the native plan (task list) outlives the Turn that changed it, so a reopened
15380
+ * Thread gets its latest plan again. Otherwise a plan stays with the Turn that made it.
15381
+ */
15382
+ persistentPlan: external_exports.boolean().optional()
15772
15383
  }).strict();
15773
15384
  var harnessConfigurationStateSchema = external_exports.object({
15774
15385
  effectiveModel: harnessModelRefSchema.optional(),
@@ -15777,7 +15388,7 @@ var harnessConfigurationStateSchema = external_exports.object({
15777
15388
  availableThinkingOptions: harnessThinkingOptionsSchema.optional(),
15778
15389
  effectivePermissionModeId: harnessPermissionModeIdSchema.optional()
15779
15390
  }).strict().superRefine((state, context) => {
15780
- if (state.effectiveThinkingOptionId && state.availableThinkingOptions && !state.availableThinkingOptions.some(({ id }) => id === state.effectiveThinkingOptionId)) {
15391
+ if (state.effectiveThinkingOptionId && state.availableThinkingOptions && !state.availableThinkingOptions.some(({ id: id2 }) => id2 === state.effectiveThinkingOptionId)) {
15781
15392
  context.addIssue({
15782
15393
  code: "custom",
15783
15394
  message: "Effective Thinking option must be currently available",
@@ -15785,150 +15396,696 @@ var harnessConfigurationStateSchema = external_exports.object({
15785
15396
  });
15786
15397
  }
15787
15398
  });
15788
- var harnessWebUiCapabilitySchema = external_exports.object({
15789
- open: external_exports.literal(true)
15790
- }).strict();
15791
- var readyHarnessInspectionSchema = external_exports.object({
15792
- status: external_exports.literal("ready"),
15793
- catalog: harnessModelCatalogSchema,
15794
- permissionModes: harnessPermissionModeCatalogSchema.optional(),
15795
- capabilities: harnessSessionCapabilitiesSchema,
15796
- webUi: harnessWebUiCapabilitySchema.optional()
15797
- }).strict().superRefine((inspection, context) => {
15798
- const selectable = inspection.capabilities.configuration.selectPermissionMode;
15799
- if (selectable !== Boolean(inspection.permissionModes)) {
15800
- context.addIssue({
15801
- code: "custom",
15802
- message: "Permission Mode catalog and capability must agree",
15803
- path: selectable ? ["permissionModes"] : ["capabilities", "configuration", "selectPermissionMode"]
15804
- });
15805
- }
15399
+ var harnessWebUiCapabilitySchema = external_exports.object({
15400
+ open: external_exports.literal(true)
15401
+ }).strict();
15402
+ var readyHarnessInspectionSchema = external_exports.object({
15403
+ status: external_exports.literal("ready"),
15404
+ catalog: harnessModelCatalogSchema,
15405
+ permissionModes: harnessPermissionModeCatalogSchema.optional(),
15406
+ capabilities: harnessSessionCapabilitiesSchema,
15407
+ webUi: harnessWebUiCapabilitySchema.optional()
15408
+ }).strict().superRefine((inspection, context) => {
15409
+ const selectable = inspection.capabilities.configuration.selectPermissionMode;
15410
+ if (selectable !== Boolean(inspection.permissionModes)) {
15411
+ context.addIssue({
15412
+ code: "custom",
15413
+ message: "Permission Mode catalog and capability must agree",
15414
+ path: selectable ? ["permissionModes"] : ["capabilities", "configuration", "selectPermissionMode"]
15415
+ });
15416
+ }
15417
+ });
15418
+ var failedHarnessInspectionSchema = external_exports.object({
15419
+ status: external_exports.enum(["notInstalled", "unavailable", "error"]),
15420
+ error: codexhostErrorSchema
15421
+ }).strict();
15422
+ var harnessInspectionSchema = external_exports.union([
15423
+ readyHarnessInspectionSchema,
15424
+ failedHarnessInspectionSchema
15425
+ ]);
15426
+ var harnessInspectParamsSchema = external_exports.object({
15427
+ harnessId: harnessIdSchema,
15428
+ cwd: nonBlankTextSchema2.max(16384).optional(),
15429
+ refresh: external_exports.boolean().optional(),
15430
+ /** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
15431
+ purpose: external_exports.literal("availability").optional(),
15432
+ credentialAccess: external_exports.enum(["allow", "retry"]).optional()
15433
+ }).strict();
15434
+ var harnessWebUiOpenParamsSchema = external_exports.object({
15435
+ harnessId: harnessIdSchema
15436
+ }).strict();
15437
+ var harnessWebUiOpenResultSchema = external_exports.object({}).strict();
15438
+ var threadModelSelectParamsSchema = external_exports.object({
15439
+ threadId: hostThreadIdSchema,
15440
+ model: harnessModelRefSchema
15441
+ }).strict();
15442
+ var threadThinkingSelectParamsSchema = external_exports.object({
15443
+ threadId: hostThreadIdSchema,
15444
+ thinkingOptionId: harnessThinkingOptionIdSchema
15445
+ }).strict();
15446
+ var threadInspectionParamsSchema = external_exports.object({
15447
+ threadId: hostThreadIdSchema,
15448
+ includeReferenceCapability: external_exports.boolean().optional()
15449
+ }).strict();
15450
+ var codexThreadInspectionSchema = external_exports.object({
15451
+ owner: external_exports.literal("codex"),
15452
+ locked: external_exports.boolean(),
15453
+ effectiveModel: harnessModelRefSchema.optional(),
15454
+ resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15455
+ effectiveThinkingOptionId: harnessThinkingOptionIdSchema.optional(),
15456
+ effectivePermissionModeId: harnessPermissionModeIdSchema.optional(),
15457
+ history: harnessHistoryCapabilitiesSchema.optional(),
15458
+ supportsThreadReferences: external_exports.literal(true).optional()
15459
+ }).strict();
15460
+ var externalThreadInspectionSchema = external_exports.object({
15461
+ owner: external_exports.literal("external"),
15462
+ harnessId: nonBlankTextSchema2.max(256),
15463
+ transportModelId: nonBlankTextSchema2.max(HARNESS_TRANSPORT_MODEL_ID_MAX_LENGTH),
15464
+ effectiveModel: harnessModelRefSchema.optional(),
15465
+ resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15466
+ effectiveThinkingOptionId: harnessThinkingOptionIdSchema.optional(),
15467
+ availableThinkingOptions: harnessThinkingOptionsSchema.optional(),
15468
+ effectivePermissionModeId: harnessPermissionModeIdSchema.optional(),
15469
+ history: harnessHistoryCapabilitiesSchema,
15470
+ usage: threadUsageSnapshotSchema.optional(),
15471
+ locked: external_exports.literal(true)
15472
+ }).strict();
15473
+ var threadInspectionSchema = external_exports.discriminatedUnion("owner", [
15474
+ codexThreadInspectionSchema,
15475
+ externalThreadInspectionSchema
15476
+ ]);
15477
+ var threadOwnershipListParamsSchema = external_exports.object({
15478
+ threadIds: external_exports.array(hostThreadIdSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
15479
+ }).strict().superRefine(({ threadIds }, context) => {
15480
+ const seen = /* @__PURE__ */ new Set();
15481
+ for (const [index, threadId] of threadIds.entries()) {
15482
+ if (seen.has(threadId)) {
15483
+ context.addIssue({
15484
+ code: "custom",
15485
+ message: "Thread ownership-list IDs must be unique",
15486
+ path: ["threadIds", index]
15487
+ });
15488
+ }
15489
+ seen.add(threadId);
15490
+ }
15491
+ });
15492
+ var codexThreadOwnershipSchema = external_exports.object({
15493
+ threadId: hostThreadIdSchema,
15494
+ owner: external_exports.literal("codex")
15495
+ }).strict();
15496
+ var externalThreadOwnershipSchema = external_exports.object({
15497
+ threadId: hostThreadIdSchema,
15498
+ owner: external_exports.literal("external"),
15499
+ harnessId: external_exports.string().max(256).pipe(harnessIdSchema)
15500
+ }).strict();
15501
+ var threadOwnershipSchema = external_exports.discriminatedUnion("owner", [
15502
+ codexThreadOwnershipSchema,
15503
+ externalThreadOwnershipSchema
15504
+ ]);
15505
+ var threadOwnershipListResultSchema = external_exports.object({
15506
+ threads: external_exports.array(threadOwnershipSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
15507
+ }).strict().superRefine(({ threads }, context) => {
15508
+ const seen = /* @__PURE__ */ new Set();
15509
+ for (const [index, thread2] of threads.entries()) {
15510
+ if (seen.has(thread2.threadId)) {
15511
+ context.addIssue({
15512
+ code: "custom",
15513
+ message: "Thread ownership-list results must be unique",
15514
+ path: ["threads", index, "threadId"]
15515
+ });
15516
+ }
15517
+ seen.add(thread2.threadId);
15518
+ }
15519
+ });
15520
+ var threadSteeringInspectParamsSchema = external_exports.object({
15521
+ threadId: hostThreadIdSchema,
15522
+ /** The text about to be steered; a Harness command always stops and restarts. */
15523
+ text: external_exports.string().optional()
15524
+ }).strict();
15525
+ var threadSteeringContextSchema = external_exports.object({
15526
+ kind: external_exports.literal("application"),
15527
+ value: external_exports.string().transform((text, context) => {
15528
+ try {
15529
+ return JSON.parse(text);
15530
+ } catch {
15531
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15532
+ return external_exports.NEVER;
15533
+ }
15534
+ }).pipe(external_exports.object({
15535
+ expectedTurnId: hostTurnIdSchema,
15536
+ clientUserMessageId: external_exports.string().min(1),
15537
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15538
+ }).strict())
15539
+ }).strict().transform((context) => context.value);
15540
+ var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15541
+ var threadSteeringInspectResultSchema = external_exports.object({
15542
+ delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
15543
+ }).strict();
15544
+
15545
+ // ../../shared-contracts/dist/harness-plugins.js
15546
+ var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15547
+ var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
15548
+ var HARNESS_PLUGIN_LIMIT = 128;
15549
+ var installedPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u);
15550
+ var installedHarnessPluginIdSchema = installedPluginIdSchema.pipe(harnessIdSchema);
15551
+ var harnessPluginIdSchema = installedHarnessPluginIdSchema.refine((id2) => id2 !== "codex", "The official Codex identity is reserved");
15552
+ var pluginRelativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
15553
+ var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
15554
+ var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
15555
+ var harnessInstallationGuideSchema = external_exports.object({
15556
+ commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
15557
+ before: localizedTextSchema.optional(),
15558
+ after: localizedTextSchema.optional(),
15559
+ downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
15560
+ }).strict();
15561
+ var pluginPresentationShape = {
15562
+ id: installedHarnessPluginIdSchema,
15563
+ name: external_exports.string().trim().min(1).max(128),
15564
+ version: external_exports.string().min(1).max(128),
15565
+ /** Capability-only plugin; omitted for existing session-capable plugins. */
15566
+ kind: external_exports.literal("usage").optional(),
15567
+ /** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
15568
+ iconStyle: external_exports.object({
15569
+ vector: external_exports.object({
15570
+ viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
15571
+ color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
15572
+ paths: external_exports.array(external_exports.object({
15573
+ d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
15574
+ fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
15575
+ fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
15576
+ }).strict()).min(1).max(32)
15577
+ }).strict().optional(),
15578
+ background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
15579
+ borderRadius: external_exports.number().min(0).max(50).optional(),
15580
+ paddingRatio: external_exports.number().min(0).max(0.25).optional()
15581
+ }).strict().optional(),
15582
+ installation: harnessInstallationGuideSchema.optional(),
15583
+ notice: localizedTextSchema.optional(),
15584
+ /** The factory accepts a persisted local entrypoint through its construction context. */
15585
+ launchCommand: external_exports.literal(true).optional(),
15586
+ links: external_exports.object({
15587
+ website: documentationUrlSchema.optional(),
15588
+ documentation: documentationUrlSchema.optional(),
15589
+ installation: documentationUrlSchema.optional()
15590
+ }).strict().optional()
15591
+ };
15592
+ var harnessPluginManifestSchema = external_exports.object({
15593
+ manifestVersion: external_exports.literal(1),
15594
+ ...pluginPresentationShape,
15595
+ adapterApiVersion: external_exports.number().int().positive(),
15596
+ entry: pluginRelativeResourceSchema,
15597
+ icon: pluginRelativeResourceSchema.optional()
15598
+ }).strict();
15599
+ var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
15600
+ var harnessPluginDescriptorSchema = external_exports.object({
15601
+ ...pluginPresentationShape,
15602
+ icon: harnessPluginIconSchema.optional()
15603
+ }).strict();
15604
+ var harnessPluginListParamsSchema = external_exports.object({}).strict();
15605
+ var harnessPluginListResultSchema = external_exports.object({
15606
+ plugins: external_exports.array(harnessPluginDescriptorSchema.extend({ id: harnessPluginIdSchema })).max(HARNESS_PLUGIN_LIMIT)
15607
+ }).strict();
15608
+ var harnessPluginConfigurationSchema = external_exports.object({
15609
+ version: external_exports.literal(1),
15610
+ enabled: external_exports.array(installedHarnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
15611
+ }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
15612
+ message: "Enabled plugin IDs must be unique",
15613
+ path: ["enabled"]
15614
+ });
15615
+
15616
+ // ../../shared-contracts/dist/desktop-extensions.js
15617
+ var DESKTOP_EXTENSION_API_VERSION = 1;
15618
+ var DESKTOP_EXTENSION_LIMIT = 64;
15619
+ var DESKTOP_EXTENSION_ZIP_MAX_BYTES = 64 * 1024 * 1024;
15620
+ var DESKTOP_EXTENSION_MANIFEST_MAX_BYTES = 128 * 1024;
15621
+ var DESKTOP_EXTENSION_SCRIPT_MAX_BYTES = 2 * 1024 * 1024;
15622
+ var DESKTOP_EXTENSION_STYLE_MAX_BYTES = 256 * 1024;
15623
+ var DESKTOP_EXTENSION_ICON_MAX_BYTES = 128 * 1024;
15624
+ var DESKTOP_EXTENSION_SCREENSHOT_LIMIT = 4;
15625
+ var DESKTOP_EXTENSION_SCREENSHOT_MAX_BYTES = 512 * 1024;
15626
+ var DESKTOP_EXTENSION_LIST_SCREENSHOTS_MAX_BYTES = 8 * 1024 * 1024;
15627
+ var DESKTOP_EXTENSION_SNAPSHOT_MAX_BYTES = 8 * 1024 * 1024;
15628
+ var DESKTOP_EXTENSION_ASSET_MAX_BYTES = 16 * 1024 * 1024;
15629
+ var DESKTOP_EXTENSION_SETTINGS_MAX_BYTES = 1024 * 1024;
15630
+ var desktopExtensionIdSchema = installedPluginIdSchema;
15631
+ var desktopExtensionSlotSchema = external_exports.enum([
15632
+ "sidebar.thread-layout",
15633
+ "sidebar.thread-badge",
15634
+ "appearance.theme"
15635
+ ]);
15636
+ var desktopExtensionCategorySchema = external_exports.enum([
15637
+ "appearance",
15638
+ "interface",
15639
+ "workflow",
15640
+ "analytics",
15641
+ "integrations",
15642
+ "tools"
15643
+ ]);
15644
+ var extensionName = external_exports.string().trim().min(1).max(128);
15645
+ function desktopExtensionScreenshotMimeType(resource) {
15646
+ switch (resource.match(/\.([^./]+)$/u)?.[1]?.toLowerCase()) {
15647
+ case "png":
15648
+ return "image/png";
15649
+ case "jpg":
15650
+ case "jpeg":
15651
+ return "image/jpeg";
15652
+ case "webp":
15653
+ return "image/webp";
15654
+ default:
15655
+ return void 0;
15656
+ }
15657
+ }
15658
+ var hasPortableSegments = (resource) => resource.split("/").every((segment) => !/[. ]$/u.test(segment));
15659
+ var imagePathSchema = pluginRelativeResourceSchema.refine((resource) => desktopExtensionScreenshotMimeType(resource) !== void 0 && hasPortableSegments(resource), "Images must be relative .png, .jpg, .jpeg, or .webp paths with no segments ending in a dot or space");
15660
+ var desktopExtensionHttpUrlSchema = external_exports.string().trim().max(2048).regex(/^https?:\/\/[^/?#\\\s]+/iu, "Expected an HTTP(S) URL").pipe(external_exports.url({ protocol: /^https?$/u })).refine((value) => {
15661
+ const { username, password } = new URL(value);
15662
+ return !username && !password && !/[\\\s]/u.test(value);
15663
+ }, "URL must not contain credentials, backslashes, or whitespace");
15664
+ function localizedText(text) {
15665
+ return external_exports.strictObject({ en: text, "zh-CN": text });
15666
+ }
15667
+ var desktopExtensionLocalizedTextSchema = localizedText(external_exports.string().trim().min(1));
15668
+ var categoriesSchema = external_exports.array(desktopExtensionCategorySchema).max(desktopExtensionCategorySchema.options.length).refine((categories) => new Set(categories).size === categories.length, "Duplicate categories");
15669
+ var slotsSchema = external_exports.array(desktopExtensionSlotSchema).max(desktopExtensionSlotSchema.options.length).refine((slots) => new Set(slots).size === slots.length, "Duplicate slots");
15670
+ var settingField = {
15671
+ key: external_exports.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/u),
15672
+ label: desktopExtensionLocalizedTextSchema,
15673
+ description: desktopExtensionLocalizedTextSchema.optional()
15674
+ };
15675
+ var numericSetting = {
15676
+ ...settingField,
15677
+ step: external_exports.number().positive().optional(),
15678
+ default: external_exports.number().optional()
15679
+ };
15680
+ var settingOption = external_exports.strictObject({
15681
+ value: external_exports.string(),
15682
+ label: desktopExtensionLocalizedTextSchema
15683
+ });
15684
+ var desktopExtensionSettingFieldSchema = external_exports.discriminatedUnion("type", [
15685
+ external_exports.strictObject({
15686
+ ...settingField,
15687
+ type: external_exports.literal("boolean"),
15688
+ default: external_exports.boolean().optional()
15689
+ }),
15690
+ external_exports.strictObject({
15691
+ ...settingField,
15692
+ type: external_exports.literal("string"),
15693
+ placeholder: desktopExtensionLocalizedTextSchema.optional(),
15694
+ default: external_exports.string().optional()
15695
+ }),
15696
+ external_exports.strictObject({
15697
+ ...numericSetting,
15698
+ type: external_exports.literal("number"),
15699
+ min: external_exports.number().optional(),
15700
+ max: external_exports.number().optional()
15701
+ }),
15702
+ external_exports.strictObject({
15703
+ ...numericSetting,
15704
+ type: external_exports.literal("range"),
15705
+ min: external_exports.number(),
15706
+ max: external_exports.number()
15707
+ }),
15708
+ external_exports.strictObject({
15709
+ ...settingField,
15710
+ type: external_exports.literal("select"),
15711
+ options: external_exports.array(settingOption).min(1),
15712
+ default: external_exports.string().optional()
15713
+ })
15714
+ ]).superRefine((field2, ctx) => {
15715
+ const issue2 = (path9, message3) => ctx.addIssue({ code: "custom", path: [path9], message: message3 });
15716
+ if (field2.type === "number" || field2.type === "range") {
15717
+ const { min = -Infinity, max = Infinity, default: value } = field2;
15718
+ if (min > max)
15719
+ issue2("max", "Must be at least min");
15720
+ if (value !== void 0 && (value < min || value > max))
15721
+ issue2("default", "Must be within min and max");
15722
+ } else if (field2.type === "select") {
15723
+ const values = new Set(field2.options.map(({ value }) => value));
15724
+ if (values.size !== field2.options.length)
15725
+ issue2("options", "Duplicate option values");
15726
+ if (field2.default !== void 0 && !values.has(field2.default))
15727
+ issue2("default", "Must match an option value");
15728
+ }
15729
+ });
15730
+ var manifestHeader = external_exports.object({
15731
+ manifestVersion: external_exports.int().positive(),
15732
+ id: desktopExtensionIdSchema,
15733
+ name: external_exports.union([extensionName, localizedText(extensionName)]),
15734
+ version: external_exports.string().min(1).max(128),
15735
+ desktopApi: external_exports.int().positive()
15736
+ }).passthrough();
15737
+ var desktopExtensionManifestSchema = manifestHeader.extend({
15738
+ manifestVersion: external_exports.literal(1),
15739
+ desktopApi: external_exports.literal(DESKTOP_EXTENSION_API_VERSION),
15740
+ description: external_exports.strictObject({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).optional(),
15741
+ author: external_exports.string().trim().min(1).max(128).optional(),
15742
+ repository: desktopExtensionHttpUrlSchema.optional(),
15743
+ details: external_exports.strictObject({ en: external_exports.string().max(16384), "zh-CN": external_exports.string().max(16384).optional() }).optional(),
15744
+ icon: imagePathSchema.optional(),
15745
+ screenshots: external_exports.array(imagePathSchema).max(DESKTOP_EXTENSION_SCREENSHOT_LIMIT).refine((screenshots) => new Set(screenshots).size === screenshots.length, "Duplicate screenshots").optional(),
15746
+ desktop: external_exports.strictObject({
15747
+ script: pluginRelativeResourceSchema,
15748
+ style: pluginRelativeResourceSchema.optional()
15749
+ }).optional(),
15750
+ backend: external_exports.strictObject({ script: pluginRelativeResourceSchema.refine(hasPortableSegments) }).optional(),
15751
+ slots: slotsSchema.default(() => []),
15752
+ settingsSchema: external_exports.array(desktopExtensionSettingFieldSchema).max(32).refine((fields) => new Set(fields.map(({ key }) => key)).size === fields.length, "Duplicate setting keys").optional(),
15753
+ categories: categoriesSchema.optional()
15754
+ }).strict().refine((manifest) => manifest.desktop !== void 0 || manifest.backend !== void 0, "Expected at least one desktop or backend entry");
15755
+ var desktopExtensionHashSchema = external_exports.string().regex(/^[a-f0-9]{64}$/u);
15756
+ var desktopExtensionStatusSchema = external_exports.strictObject({
15757
+ state: external_exports.enum([
15758
+ "running",
15759
+ "disabled",
15760
+ "invalid",
15761
+ "incompatible",
15762
+ "conflict",
15763
+ "failed",
15764
+ "waiting"
15765
+ ]),
15766
+ hash: desktopExtensionHashSchema.optional(),
15767
+ error: external_exports.string().optional(),
15768
+ conflictWith: desktopExtensionIdSchema.optional()
15769
+ });
15770
+ var desktopExtensionsDiagnosticSchema = external_exports.strictObject({
15771
+ controllerPid: external_exports.int().positive(),
15772
+ targetId: external_exports.string().nullable(),
15773
+ updatedAt: external_exports.iso.datetime(),
15774
+ handledReloadToken: external_exports.uuid().optional(),
15775
+ extensions: external_exports.record(external_exports.string(), desktopExtensionStatusSchema),
15776
+ surfaces: external_exports.record(external_exports.string(), desktopExtensionStatusSchema).optional()
15806
15777
  });
15807
- var failedHarnessInspectionSchema = external_exports.object({
15808
- status: external_exports.enum(["notInstalled", "unavailable", "error"]),
15809
- error: codexhostErrorSchema
15810
- }).strict();
15811
- var harnessInspectionSchema = external_exports.union([
15812
- readyHarnessInspectionSchema,
15813
- failedHarnessInspectionSchema
15778
+ var desktopExtensionTrustTierSchema = external_exports.enum(["official", "community"]);
15779
+ function isGitHubDesktopExtensionZipballUrl(url2) {
15780
+ return url2.origin === "https://api.github.com" && /^\/repos\/[\w-]+\/[\w.-]+\/zipball(?:\/[^/]+)?\/?$/u.test(url2.pathname);
15781
+ }
15782
+ var desktopExtensionZipUrlSchema = desktopExtensionHttpUrlSchema.refine((input) => {
15783
+ const url2 = new URL(input);
15784
+ return /\.zip$/iu.test(url2.pathname) || isGitHubDesktopExtensionZipballUrl(url2) || url2.origin === "https://github.com" && /^\/[\w-]+\/[\w.-]+\/zipball(?:\/.+)?\/?$/u.test(url2.pathname) || url2.origin === "https://codeload.github.com" && /^\/[\w-]+\/[\w.-]+\/(?:zip|zipball|legacy\.zip)\/.+$/u.test(url2.pathname);
15785
+ }, "Expected a .zip download URL or a GitHub zipball URL");
15786
+ var desktopExtensionCatalogEntrySchema = external_exports.strictObject({
15787
+ id: desktopExtensionIdSchema,
15788
+ version: external_exports.string().trim().min(1).max(128),
15789
+ name: desktopExtensionLocalizedTextSchema.extend({ en: extensionName, "zh-CN": extensionName }),
15790
+ description: localizedText(external_exports.string().trim().min(1).max(4096)),
15791
+ details: localizedText(external_exports.string().trim().min(1).max(16384)).optional(),
15792
+ author: external_exports.string().trim().min(1).max(128),
15793
+ repository: desktopExtensionHttpUrlSchema,
15794
+ stars: external_exports.number().int().min(0).optional(),
15795
+ downloads: external_exports.number().int().min(0).optional(),
15796
+ categories: categoriesSchema.optional(),
15797
+ trustTier: desktopExtensionTrustTierSchema.default("community"),
15798
+ icon: desktopExtensionHttpUrlSchema.optional(),
15799
+ screenshots: external_exports.array(desktopExtensionHttpUrlSchema).max(DESKTOP_EXTENSION_SCREENSHOT_LIMIT).optional(),
15800
+ downloadUrl: desktopExtensionZipUrlSchema,
15801
+ sha256: desktopExtensionHashSchema,
15802
+ slots: slotsSchema.optional(),
15803
+ publishedAt: external_exports.string().optional(),
15804
+ updatedAt: external_exports.string().optional(),
15805
+ minCodexHostVersion: external_exports.string().optional()
15806
+ });
15807
+ var desktopExtensionCatalogSchema = external_exports.strictObject({
15808
+ schemaVersion: external_exports.literal(1),
15809
+ generatedAt: external_exports.string(),
15810
+ extensions: external_exports.array(desktopExtensionCatalogEntrySchema).refine((entries) => new Set(entries.map(({ id: id2 }) => id2)).size === entries.length, "Duplicate extension IDs")
15811
+ });
15812
+ var desktopExtensionBackendMethodSchema = external_exports.string().trim().min(1).max(128);
15813
+
15814
+ // ../../shared-contracts/dist/host-extensions.js
15815
+ var reservedName = /^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³]) *(?:\.|$)/iu;
15816
+ var HOST_EXTENSION_PAGE_API_VERSION = 1;
15817
+ var hostExtensionIdSchema = desktopExtensionIdSchema.refine((id2) => !reservedName.test(id2), "Reserved extension ID");
15818
+ var hostExtensionTargetSchema = external_exports.enum(["desktop", "web"]);
15819
+ var hostExtensionDigestSchema = desktopExtensionHashSchema;
15820
+ var hostExtensionActivationIdSchema = external_exports.uuid();
15821
+ var hostExtensionResourcePathSchema = pluginRelativeResourceSchema.refine((resource) => !/[\x00-\x1f\x7f<>"|*]/u.test(resource) && resource.split("/").every((part) => !/[. ]$/u.test(part) && !reservedName.test(part)), "Expected a portable relative resource path").refine((path9) => path9.split("/").length <= 32, "Extension resources may be at most 32 segments deep");
15822
+ var legacy = desktopExtensionManifestSchema.shape;
15823
+ var localized = (max, min = 0) => external_exports.strictObject({
15824
+ en: external_exports.string().trim().min(min).max(max),
15825
+ "zh-CN": external_exports.string().trim().min(min).max(max)
15826
+ });
15827
+ var resourceWithSuffix = (suffix) => hostExtensionResourcePathSchema.refine((path9) => path9.endsWith(suffix), `Expected a ${suffix} file`);
15828
+ var moduleEntry = resourceWithSuffix(".mjs");
15829
+ var style = resourceWithSuffix(".css").optional();
15830
+ var hostExtensionCanonicalPath = (path9) => path9.normalize("NFC").toLowerCase();
15831
+ var hostExtensionManifestV2Schema = external_exports.strictObject({
15832
+ manifestVersion: external_exports.literal(2),
15833
+ id: hostExtensionIdSchema,
15834
+ name: localized(128, 1),
15835
+ version: external_exports.string().trim().min(1).max(128),
15836
+ description: localized(4096),
15837
+ details: localized(16384).optional(),
15838
+ author: legacy.author,
15839
+ repository: legacy.repository,
15840
+ icon: legacy.icon.refine((path9) => path9 === void 0 || hostExtensionResourcePathSchema.safeParse(path9).success),
15841
+ screenshots: legacy.screenshots.refine((paths) => paths === void 0 || paths.every((path9) => hostExtensionResourcePathSchema.safeParse(path9).success)),
15842
+ categories: legacy.categories,
15843
+ settingsSchema: legacy.settingsSchema,
15844
+ slots: legacy.slots.removeDefault().optional(),
15845
+ page: external_exports.strictObject({
15846
+ apiVersion: external_exports.literal(HOST_EXTENSION_PAGE_API_VERSION),
15847
+ entry: moduleEntry,
15848
+ style,
15849
+ title: localized(128, 1).optional()
15850
+ }).optional(),
15851
+ widget: external_exports.strictObject({
15852
+ apiVersion: external_exports.literal(HOST_EXTENSION_PAGE_API_VERSION),
15853
+ entry: moduleEntry,
15854
+ style
15855
+ }).optional(),
15856
+ desktop: external_exports.strictObject({ apiVersion: external_exports.literal(1), script: resourceWithSuffix(".js"), style }).optional(),
15857
+ web: external_exports.strictObject({ apiVersion: external_exports.literal(1), entry: moduleEntry.optional(), style }).refine(({ entry, style: style2 }) => entry !== void 0 || style2 !== void 0, "Expected a Web entry or style").optional(),
15858
+ backend: external_exports.strictObject({ apiVersion: external_exports.literal(1), entry: moduleEntry }).optional()
15859
+ }).refine(({ page, widget, desktop, web, backend }) => Boolean(page || widget || desktop || web || backend), "Expected at least one page, widget, desktop, web, or backend entry").refine(({ page, widget, web, backend }) => !backend || [page?.entry, widget?.entry, web?.entry].every((entry) => entry === void 0 || hostExtensionCanonicalPath(entry) !== hostExtensionCanonicalPath(backend.entry)), { path: ["backend", "entry"], message: "A backend entry cannot also be a frontend entry" });
15860
+ function targetsForCapabilities({ hasPage, hasWidget, hasDesktop, hasWeb, hasBackend }) {
15861
+ if (hasPage || hasWidget || hasBackend && !hasDesktop && !hasWeb)
15862
+ return ["desktop", "web"];
15863
+ const targets = [];
15864
+ if (hasDesktop)
15865
+ targets.push("desktop");
15866
+ if (hasWeb)
15867
+ targets.push("web");
15868
+ return targets;
15869
+ }
15870
+ var hostExtensionBackendMethodSchema = desktopExtensionBackendMethodSchema;
15871
+
15872
+ // ../../shared-contracts/dist/host-extension-management.js
15873
+ var HOST_EXTENSION_ZIP_MAX_BYTES = DESKTOP_EXTENSION_ZIP_MAX_BYTES;
15874
+ var hostExtensionRevisionSchema = external_exports.int().nonnegative();
15875
+ var hostExtensionConfigurationSchema = external_exports.strictObject({
15876
+ revision: hostExtensionRevisionSchema,
15877
+ enabled: external_exports.array(hostExtensionIdSchema).max(DESKTOP_EXTENSION_LIMIT).refine((ids) => new Set(ids).size === ids.length, "Duplicate extension IDs")
15878
+ });
15879
+ var { downloadUrl, ...catalogMetadata } = desktopExtensionCatalogEntrySchema.shape;
15880
+ var hostExtensionCatalogEntrySchema = external_exports.object({
15881
+ ...catalogMetadata,
15882
+ id: hostExtensionIdSchema,
15883
+ format: external_exports.literal("codexhost"),
15884
+ targets: external_exports.array(hostExtensionTargetSchema).min(1).max(2).refine((targets) => new Set(targets).size === targets.length, "Duplicate targets"),
15885
+ apis: external_exports.strictObject({
15886
+ page: external_exports.int().positive().optional(),
15887
+ widget: external_exports.int().positive().optional(),
15888
+ desktop: external_exports.int().positive().optional(),
15889
+ web: external_exports.int().positive().optional(),
15890
+ backend: external_exports.int().positive().optional()
15891
+ }),
15892
+ downloadUrl: downloadUrl.refine((url2) => url2.startsWith("https://"), "Expected HTTPS")
15893
+ }).refine(({ targets, apis }) => {
15894
+ const derived = targetsForCapabilities({
15895
+ hasPage: Boolean(apis.page),
15896
+ hasWidget: Boolean(apis.widget),
15897
+ hasDesktop: Boolean(apis.desktop),
15898
+ hasWeb: Boolean(apis.web),
15899
+ hasBackend: Boolean(apis.backend)
15900
+ });
15901
+ return targets.length === derived.length && derived.every((target2) => targets.includes(target2));
15902
+ }, "Catalog targets must match the declared APIs");
15903
+ var hostExtensionCatalogSchema = external_exports.object({
15904
+ schemaVersion: external_exports.literal(2),
15905
+ generatedAt: external_exports.string().min(1),
15906
+ extensions: external_exports.array(hostExtensionCatalogEntrySchema).max(1e4).refine((entries) => new Set(entries.map(({ id: id2 }) => id2)).size === entries.length, "Duplicate extension IDs")
15907
+ });
15908
+ var hostExtensionsCatalogResultSchema = hostExtensionCatalogSchema.extend({
15909
+ catalogUrl: desktopExtensionHttpUrlSchema,
15910
+ fetchedAt: external_exports.iso.datetime(),
15911
+ cached: external_exports.boolean()
15912
+ });
15913
+ var id = { id: hostExtensionIdSchema };
15914
+ var active = {
15915
+ ...id,
15916
+ activationId: hostExtensionActivationIdSchema,
15917
+ digest: hostExtensionDigestSchema
15918
+ };
15919
+ var optionalActivation = { ...id, activationId: active.activationId.optional() };
15920
+ var filePath = external_exports.string().min(1).max(4096).refine((path9) => /^(?:\/|[a-z]:[/\\])/iu.test(path9) && !path9.includes("\0") && !path9.split(/[/\\]/u).some((part) => part === "." || part === ".."), "Expected an absolute local path without dot segments");
15921
+ var gitRef = external_exports.string().min(1).max(256).refine((ref) => ref.split("/").every((part) => part && /^[a-z0-9_.-]+$/iu.test(part) && part !== "." && part !== ".."), "Invalid GitHub ref");
15922
+ function base643(maxBytes) {
15923
+ return external_exports.string().max(4 * Math.ceil(maxBytes / 3)).refine((value) => {
15924
+ const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
15925
+ return value.length % 4 === 0 && value.length * 3 / 4 - padding <= maxBytes && /^[A-Za-z0-9+/]*={0,2}$/u.test(value);
15926
+ }, "Expected bounded standard padded base64");
15927
+ }
15928
+ var hostExtensionGitHubSourceSchema = external_exports.strictObject({
15929
+ type: external_exports.literal("github"),
15930
+ repository: external_exports.string().max(150).regex(/^[a-z0-9-]+\/[a-z0-9_-][a-z0-9_.-]*$/iu),
15931
+ ref: gitRef.optional(),
15932
+ tag: gitRef.optional(),
15933
+ asset: external_exports.string().max(255).regex(/^[a-z0-9_.-]+\.zip$/iu).optional(),
15934
+ subpath: hostExtensionResourcePathSchema.optional()
15935
+ }).refine(({ ref, tag, asset }) => !ref || !tag && !asset, "Use either a zipball ref or a release tag/asset");
15936
+ var hostExtensionInstallSourceSchema = external_exports.union([
15937
+ external_exports.strictObject({ type: external_exports.literal("catalog"), ...id }),
15938
+ hostExtensionGitHubSourceSchema,
15939
+ external_exports.strictObject({ type: external_exports.literal("zip"), base64: base643(HOST_EXTENSION_ZIP_MAX_BYTES).min(4) }),
15940
+ external_exports.strictObject({ type: external_exports.literal("zip"), localZipPath: filePath }),
15941
+ external_exports.strictObject({ type: external_exports.literal("localDir"), localDir: filePath })
15814
15942
  ]);
15815
- var harnessInspectParamsSchema = external_exports.object({
15816
- harnessId: harnessIdSchema,
15817
- cwd: nonBlankTextSchema2.max(16384).optional(),
15818
- refresh: external_exports.boolean().optional(),
15819
- /** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
15820
- purpose: external_exports.literal("availability").optional()
15821
- }).strict();
15822
- var harnessWebUiOpenParamsSchema = external_exports.object({
15823
- harnessId: harnessIdSchema
15824
- }).strict();
15825
- var harnessWebUiOpenResultSchema = external_exports.object({}).strict();
15826
- var threadModelSelectParamsSchema = external_exports.object({
15827
- threadId: hostThreadIdSchema,
15828
- model: harnessModelRefSchema
15829
- }).strict();
15830
- var threadThinkingSelectParamsSchema = external_exports.object({
15831
- threadId: hostThreadIdSchema,
15832
- thinkingOptionId: harnessThinkingOptionIdSchema
15833
- }).strict();
15834
- var threadInspectionParamsSchema = external_exports.object({
15835
- threadId: hostThreadIdSchema,
15836
- includeReferenceCapability: external_exports.boolean().optional()
15837
- }).strict();
15838
- var codexThreadInspectionSchema = external_exports.object({
15839
- owner: external_exports.literal("codex"),
15840
- locked: external_exports.boolean(),
15841
- effectiveModel: harnessModelRefSchema.optional(),
15842
- resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15843
- effectiveThinkingOptionId: harnessThinkingOptionIdSchema.optional(),
15844
- effectivePermissionModeId: harnessPermissionModeIdSchema.optional(),
15845
- history: harnessHistoryCapabilitiesSchema.optional(),
15846
- supportsThreadReferences: external_exports.literal(true).optional()
15847
- }).strict();
15848
- var externalThreadInspectionSchema = external_exports.object({
15849
- owner: external_exports.literal("external"),
15850
- harnessId: nonBlankTextSchema2.max(256),
15851
- transportModelId: nonBlankTextSchema2.max(1024),
15852
- effectiveModel: harnessModelRefSchema.optional(),
15853
- resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15854
- effectiveThinkingOptionId: harnessThinkingOptionIdSchema.optional(),
15855
- availableThinkingOptions: harnessThinkingOptionsSchema.optional(),
15856
- effectivePermissionModeId: harnessPermissionModeIdSchema.optional(),
15857
- history: harnessHistoryCapabilitiesSchema,
15858
- usage: threadUsageSnapshotSchema.optional(),
15859
- locked: external_exports.literal(true)
15860
- }).strict();
15861
- var threadInspectionSchema = external_exports.discriminatedUnion("owner", [
15862
- codexThreadInspectionSchema,
15863
- externalThreadInspectionSchema
15943
+ var hostExtensionProvenanceSchema = external_exports.discriminatedUnion("type", [
15944
+ external_exports.strictObject({ type: external_exports.literal("catalog"), ...id }),
15945
+ hostExtensionGitHubSourceSchema,
15946
+ external_exports.strictObject({ type: external_exports.literal("zip") }),
15947
+ external_exports.strictObject({ type: external_exports.literal("localDir") })
15864
15948
  ]);
15865
- var threadOwnershipListParamsSchema = external_exports.object({
15866
- threadIds: external_exports.array(hostThreadIdSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
15867
- }).strict().superRefine(({ threadIds }, context) => {
15868
- const seen = /* @__PURE__ */ new Set();
15869
- for (const [index, threadId] of threadIds.entries()) {
15870
- if (seen.has(threadId)) {
15871
- context.addIssue({
15872
- code: "custom",
15873
- message: "Thread ownership-list IDs must be unique",
15874
- path: ["threadIds", index]
15875
- });
15876
- }
15877
- seen.add(threadId);
15878
- }
15949
+ var hostExtensionInstallationSchema = external_exports.strictObject({
15950
+ ...active,
15951
+ manifest: hostExtensionManifestV2Schema,
15952
+ installedAt: external_exports.iso.datetime(),
15953
+ source: hostExtensionProvenanceSchema.optional()
15879
15954
  });
15880
- var codexThreadOwnershipSchema = external_exports.object({
15881
- threadId: hostThreadIdSchema,
15882
- owner: external_exports.literal("codex")
15883
- }).strict();
15884
- var externalThreadOwnershipSchema = external_exports.object({
15885
- threadId: hostThreadIdSchema,
15886
- owner: external_exports.literal("external"),
15887
- harnessId: external_exports.string().max(256).pipe(harnessIdSchema)
15888
- }).strict();
15889
- var threadOwnershipSchema = external_exports.discriminatedUnion("owner", [
15890
- codexThreadOwnershipSchema,
15891
- externalThreadOwnershipSchema
15955
+ var rasterDataUrlSchema = (maxBytes) => external_exports.string().max("data:image/jpeg;base64,".length + 4 * Math.ceil(maxBytes / 3)).regex(/^data:image\/(?:png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/u);
15956
+ var desktopConflict = { desktopConflictWith: hostExtensionIdSchema.optional() };
15957
+ var backendState = external_exports.enum(["none", "inactive", "starting", "running", "failed"]);
15958
+ var hostExtensionListItemSchema = external_exports.discriminatedUnion("state", [
15959
+ hostExtensionInstallationSchema.extend({
15960
+ state: external_exports.literal("valid"),
15961
+ enabled: external_exports.boolean(),
15962
+ ...desktopConflict,
15963
+ iconDataUrl: rasterDataUrlSchema(DESKTOP_EXTENSION_ICON_MAX_BYTES).optional(),
15964
+ screenshotDataUrls: external_exports.array(rasterDataUrlSchema(DESKTOP_EXTENSION_SCREENSHOT_MAX_BYTES)).max(DESKTOP_EXTENSION_SCREENSHOT_LIMIT).optional(),
15965
+ backendState: backendState.optional(),
15966
+ backendError: external_exports.string().optional()
15967
+ }),
15968
+ external_exports.strictObject({
15969
+ state: external_exports.enum(["invalid", "incompatible"]),
15970
+ id: external_exports.string().min(1),
15971
+ enabled: external_exports.boolean(),
15972
+ error: external_exports.string()
15973
+ })
15892
15974
  ]);
15893
- var threadOwnershipListResultSchema = external_exports.object({
15894
- threads: external_exports.array(threadOwnershipSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
15895
- }).strict().superRefine(({ threads }, context) => {
15896
- const seen = /* @__PURE__ */ new Set();
15897
- for (const [index, thread2] of threads.entries()) {
15898
- if (seen.has(thread2.threadId)) {
15899
- context.addIssue({
15900
- code: "custom",
15901
- message: "Thread ownership-list results must be unique",
15902
- path: ["threads", index, "threadId"]
15903
- });
15904
- }
15905
- seen.add(thread2.threadId);
15906
- }
15975
+ var hostExtensionsListResultSchema = external_exports.strictObject({
15976
+ revision: hostExtensionRevisionSchema,
15977
+ configuration: hostExtensionConfigurationSchema,
15978
+ diagnostics: external_exports.array(external_exports.string()),
15979
+ extensions: external_exports.array(hostExtensionListItemSchema)
15980
+ });
15981
+ var hostExtensionRuntimeEntrySchema = hostExtensionInstallationSchema.extend({
15982
+ ...desktopConflict,
15983
+ settingsRevision: hostExtensionRevisionSchema
15984
+ });
15985
+ var hostExtensionsSnapshotResultSchema = external_exports.strictObject({
15986
+ /** The Host publishes this revision in extensions-changed, independent of enabled.json's revision. */
15987
+ revision: hostExtensionRevisionSchema,
15988
+ // Enabled, valid activations only. A Desktop conflict does not hide other capabilities.
15989
+ extensions: external_exports.array(hostExtensionRuntimeEntrySchema).max(DESKTOP_EXTENSION_LIMIT)
15990
+ });
15991
+ var HOST_EXTENSIONS_RPC = {
15992
+ list: "codexhost/extensions/list",
15993
+ snapshot: "codexhost/extensions/snapshot",
15994
+ catalog: "codexhost/extensions/catalog",
15995
+ install: "codexhost/extensions/install",
15996
+ update: "codexhost/extensions/update",
15997
+ enable: "codexhost/extensions/enable",
15998
+ disable: "codexhost/extensions/disable",
15999
+ uninstall: "codexhost/extensions/uninstall",
16000
+ recover: "codexhost/extensions/recover",
16001
+ asset: "codexhost/extensions/asset",
16002
+ settingsGet: "codexhost/extensions/settings/get",
16003
+ settingsSet: "codexhost/extensions/settings/set",
16004
+ backendInvoke: "codexhost/extensions/backend/invoke"
16005
+ };
16006
+ var HOST_EXTENSION_MANAGEMENT_METHODS = Object.freeze(Object.values(HOST_EXTENSIONS_RPC));
16007
+ var methods = new Set(HOST_EXTENSION_MANAGEMENT_METHODS);
16008
+ var noParams = external_exports.strictObject({});
16009
+ var expectedRevision = { expectedRevision: hostExtensionRevisionSchema };
16010
+ var selection = external_exports.strictObject({ ...id, ...expectedRevision });
16011
+ var installationResult = hostExtensionInstallationSchema.extend({ replaced: external_exports.boolean() });
16012
+ var mutationResult = external_exports.discriminatedUnion("state", [
16013
+ external_exports.strictObject({ state: external_exports.literal("saved"), configuration: hostExtensionConfigurationSchema }),
16014
+ external_exports.strictObject({ state: external_exports.literal("revision-conflict"), revision: hostExtensionRevisionSchema })
16015
+ ]);
16016
+ var hostExtensionsAssetParamsSchema = external_exports.strictObject({
16017
+ ...optionalActivation,
16018
+ digest: active.digest.optional(),
16019
+ path: hostExtensionResourcePathSchema
16020
+ });
16021
+ var hostExtensionsAssetResultSchema = external_exports.strictObject({
16022
+ mimeType: external_exports.string().min(1),
16023
+ base64: base643(DESKTOP_EXTENSION_ASSET_MAX_BYTES),
16024
+ digest: active.digest
16025
+ });
16026
+ var hostExtensionSettingsSchema = external_exports.strictObject({
16027
+ settingsRevision: hostExtensionRevisionSchema,
16028
+ values: jsonObjectSchema
15907
16029
  });
15908
- var threadSteeringInspectParamsSchema = external_exports.object({
15909
- threadId: hostThreadIdSchema,
15910
- /** The text about to be steered; a Harness command always stops and restarts. */
15911
- text: external_exports.string().optional()
15912
- }).strict();
15913
- var threadSteeringContextSchema = external_exports.object({
15914
- kind: external_exports.literal("application"),
15915
- value: external_exports.string().transform((text, context) => {
15916
- try {
15917
- return JSON.parse(text);
15918
- } catch {
15919
- context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15920
- return external_exports.NEVER;
15921
- }
15922
- }).pipe(external_exports.object({
15923
- expectedTurnId: hostTurnIdSchema,
15924
- clientUserMessageId: external_exports.string().min(1),
15925
- delivery: external_exports.enum(["newTurn", "activeTurn"])
15926
- }).strict())
15927
- }).strict().transform((context) => context.value);
15928
- var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15929
- var threadSteeringInspectResultSchema = external_exports.object({
15930
- delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
15931
- }).strict();
16030
+ var hostExtensionsRpcSchemas = {
16031
+ [HOST_EXTENSIONS_RPC.list]: { params: noParams, result: hostExtensionsListResultSchema },
16032
+ [HOST_EXTENSIONS_RPC.snapshot]: { params: noParams, result: hostExtensionsSnapshotResultSchema },
16033
+ [HOST_EXTENSIONS_RPC.catalog]: {
16034
+ params: external_exports.strictObject({ forceRefresh: external_exports.boolean().optional() }),
16035
+ result: hostExtensionsCatalogResultSchema
16036
+ },
16037
+ [HOST_EXTENSIONS_RPC.install]: {
16038
+ params: external_exports.strictObject({ source: hostExtensionInstallSourceSchema }),
16039
+ result: installationResult
16040
+ },
16041
+ [HOST_EXTENSIONS_RPC.update]: {
16042
+ params: external_exports.strictObject({
16043
+ ...id,
16044
+ expectedDigest: active.digest,
16045
+ expectedActivationId: active.activationId.optional(),
16046
+ source: hostExtensionInstallSourceSchema.optional()
16047
+ }),
16048
+ result: installationResult
16049
+ },
16050
+ [HOST_EXTENSIONS_RPC.enable]: { params: selection, result: mutationResult },
16051
+ [HOST_EXTENSIONS_RPC.disable]: { params: selection, result: mutationResult },
16052
+ [HOST_EXTENSIONS_RPC.uninstall]: {
16053
+ params: external_exports.strictObject({
16054
+ ...id,
16055
+ removeData: external_exports.boolean().optional(),
16056
+ expectedDigest: active.digest.optional()
16057
+ }),
16058
+ result: external_exports.strictObject({ ...id, removed: external_exports.boolean() })
16059
+ },
16060
+ [HOST_EXTENSIONS_RPC.recover]: {
16061
+ params: external_exports.strictObject({ expectedRevision: expectedRevision.expectedRevision.optional() }),
16062
+ result: mutationResult
16063
+ },
16064
+ [HOST_EXTENSIONS_RPC.asset]: {
16065
+ params: hostExtensionsAssetParamsSchema,
16066
+ result: hostExtensionsAssetResultSchema
16067
+ },
16068
+ [HOST_EXTENSIONS_RPC.settingsGet]: {
16069
+ params: external_exports.strictObject(optionalActivation),
16070
+ result: hostExtensionSettingsSchema
16071
+ },
16072
+ [HOST_EXTENSIONS_RPC.settingsSet]: {
16073
+ params: external_exports.strictObject({
16074
+ ...optionalActivation,
16075
+ expectedSettingsRevision: hostExtensionRevisionSchema,
16076
+ values: jsonObjectSchema
16077
+ }),
16078
+ result: hostExtensionSettingsSchema
16079
+ },
16080
+ [HOST_EXTENSIONS_RPC.backendInvoke]: {
16081
+ params: external_exports.strictObject({
16082
+ ...optionalActivation,
16083
+ method: hostExtensionBackendMethodSchema,
16084
+ params: jsonValueSchema.optional()
16085
+ }),
16086
+ result: external_exports.strictObject({ result: jsonValueSchema })
16087
+ }
16088
+ };
15932
16089
 
15933
16090
  // ../../shared-contracts/dist/thread-archive-confirm.js
15934
16091
  var THREAD_ARCHIVE_CONFIRM_METHOD = "codexhost/thread/archive/confirm";
@@ -15991,7 +16148,7 @@ var CLIENT_CHANNEL_METHODS = [
15991
16148
  "codexhost/harness/session-import/list",
15992
16149
  "codexhost/harness/session-import/import",
15993
16150
  // Host settings shared across Desktop and Web.
15994
- ...DESKTOP_EXTENSION_MANAGEMENT_METHODS,
16151
+ ...HOST_EXTENSION_MANAGEMENT_METHODS,
15995
16152
  "codexhost/harness/installation",
15996
16153
  "codexhost/harness/installation/start",
15997
16154
  "codexhost/harness/installation/status",
@@ -16052,6 +16209,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
16052
16209
  cursor: clientChannelCursorSchema,
16053
16210
  revision: external_exports.number().int().nonnegative()
16054
16211
  }),
16212
+ external_exports.object({
16213
+ type: external_exports.literal("extensions-changed"),
16214
+ cursor: clientChannelCursorSchema,
16215
+ revision: hostExtensionRevisionSchema
16216
+ }),
16055
16217
  external_exports.object({
16056
16218
  type: external_exports.literal("hello"),
16057
16219
  version: external_exports.literal(1),
@@ -16488,7 +16650,7 @@ var DEFAULT_IDLE_RELEASE_SETTINGS = Object.freeze({
16488
16650
 
16489
16651
  // ../../shared-contracts/dist/harness-preferences.js
16490
16652
  var harnessPreferenceScopeSchema = external_exports.string().regex(/^external$/u);
16491
- var preferenceHarnessKey = harnessIdSchema.transform((id) => String(id));
16653
+ var preferenceHarnessKey = harnessIdSchema.transform((id2) => String(id2));
16492
16654
  var harnessDefaultConfigurationSchema = external_exports.strictObject({
16493
16655
  model: harnessModelRefSchema.optional(),
16494
16656
  thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
@@ -16498,11 +16660,19 @@ var newThreadDefaultsSchema = external_exports.strictObject({
16498
16660
  lastHarness: harnessIdSchema.optional(),
16499
16661
  byHarness: external_exports.record(preferenceHarnessKey, harnessDefaultConfigurationSchema)
16500
16662
  });
16663
+ var harnessDelegationDefaultSchema = external_exports.strictObject({
16664
+ model: harnessModelRefSchema.optional(),
16665
+ thinkingOptionId: harnessThinkingOptionIdSchema.optional()
16666
+ }).refine((value) => Boolean(value.model || value.thinkingOptionId), "A delegation default must contain a Model or Thinking option");
16667
+ var delegationDefaultsSchema = external_exports.strictObject({
16668
+ byHarness: external_exports.record(preferenceHarnessKey, harnessDelegationDefaultSchema)
16669
+ });
16501
16670
  var modelId = external_exports.string().min(1).max(1024);
16502
16671
  var harnessPreferenceValuesSchema = external_exports.strictObject({
16503
16672
  idleRelease: idleReleaseSettingsSchema.optional(),
16504
16673
  favorites: external_exports.record(preferenceHarnessKey, external_exports.array(modelId).max(2048)).default({}),
16505
- newThread: newThreadDefaultsSchema.optional()
16674
+ newThread: newThreadDefaultsSchema.optional(),
16675
+ delegation: delegationDefaultsSchema.optional()
16506
16676
  });
16507
16677
  var harnessPreferenceSnapshotSchema = external_exports.strictObject({
16508
16678
  scope: harnessPreferenceScopeSchema,
@@ -16530,6 +16700,11 @@ var harnessPreferenceOperationSchema = external_exports.discriminatedUnion("kind
16530
16700
  lastHarness: harnessIdSchema.optional(),
16531
16701
  harnessId: harnessIdSchema.optional(),
16532
16702
  configuration: harnessDefaultConfigurationSchema.optional()
16703
+ }),
16704
+ external_exports.strictObject({
16705
+ kind: external_exports.literal("delegation"),
16706
+ harnessId: harnessIdSchema,
16707
+ configuration: harnessDelegationDefaultSchema.nullable()
16533
16708
  })
16534
16709
  ]);
16535
16710
  var harnessPreferencePatchSchema = external_exports.strictObject({
@@ -17353,9 +17528,12 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
17353
17528
  ...thread,
17354
17529
  epoch: identity,
17355
17530
  modelId: identity.optional(),
17531
+ serviceTier: harnessModelServiceTierSchema.optional(),
17356
17532
  thinkingOptionId: identity.optional(),
17357
17533
  permissionModeId: identity.optional()
17358
- }).refine((value) => [value.modelId, value.thinkingOptionId, value.permissionModeId].filter((v) => v !== void 0).length === 1, "Select exactly one remote setting"),
17534
+ }).refine((value) => [value.modelId, value.thinkingOptionId, value.permissionModeId].filter((v) => v !== void 0).length === 1, "Select exactly one remote setting").refine((value) => value.serviceTier === void 0 || value.modelId !== void 0, {
17535
+ message: "A service tier requires a Model ID"
17536
+ }),
17359
17537
  external_exports.strictObject({
17360
17538
  kind: external_exports.literal("prompt"),
17361
17539
  ...thread,
@@ -17405,7 +17583,7 @@ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action
17405
17583
  external_exports.strictObject({ action: external_exports.literal("catalog") }),
17406
17584
  external_exports.strictObject({
17407
17585
  action: external_exports.literal("read-thread"),
17408
- hostId: hostId.refine((id) => id !== "local"),
17586
+ hostId: hostId.refine((id2) => id2 !== "local"),
17409
17587
  input: delegationReadParamsSchema
17410
17588
  }),
17411
17589
  external_exports.strictObject({
@@ -17419,7 +17597,7 @@ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action
17419
17597
  external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
17420
17598
  external_exports.strictObject({
17421
17599
  action: external_exports.literal("update"),
17422
- hostId: hostId.refine((id) => id !== "local"),
17600
+ hostId: hostId.refine((id2) => id2 !== "local"),
17423
17601
  version: remoteUpdateParamsSchema.shape.version
17424
17602
  })
17425
17603
  ]);
@@ -17483,7 +17661,7 @@ function invalidRequest(message3) {
17483
17661
  return { code: "invalidRequest", message: message3, retryable: false };
17484
17662
  }
17485
17663
  function validateHostApprovalResponse(interaction, response) {
17486
- return interaction.actions.some(({ id }) => id === response.actionId) ? null : invalidRequest("Approval Response contains an undeclared action ID");
17664
+ return interaction.actions.some(({ id: id2 }) => id2 === response.actionId) ? null : invalidRequest("Approval Response contains an undeclared action ID");
17487
17665
  }
17488
17666
 
17489
17667
  // ../../harness-adapter/dist/question.js
@@ -17491,7 +17669,7 @@ function invalidRequest2(message3) {
17491
17669
  return { code: "invalidRequest", message: message3, retryable: false };
17492
17670
  }
17493
17671
  function validateHostQuestionResponse(interaction, response) {
17494
- const questionIds = new Set(interaction.questions.map(({ id }) => id));
17672
+ const questionIds = new Set(interaction.questions.map(({ id: id2 }) => id2));
17495
17673
  if (response.cancelled) {
17496
17674
  return Object.keys(response.answers).length === 0 ? null : invalidRequest2("Cancelled Question Response must not contain answers");
17497
17675
  }
@@ -17522,6 +17700,21 @@ function validateHostQuestionResponse(interaction, response) {
17522
17700
  return null;
17523
17701
  }
17524
17702
 
17703
+ // ../../harness-adapter/dist/composite-model-ref.js
17704
+ function compositeModelRefIds(entries, fallbackId) {
17705
+ const counts = /* @__PURE__ */ new Map();
17706
+ for (const entry of entries) {
17707
+ const id2 = `${entry.provider}/${entry.model}`;
17708
+ counts.set(id2, (counts.get(id2) ?? 0) + 1);
17709
+ }
17710
+ const ids = /* @__PURE__ */ new Map();
17711
+ for (const entry of entries) {
17712
+ const id2 = `${entry.provider}/${entry.model}`;
17713
+ ids.set(counts.get(id2) === 1 ? id2 : fallbackId(entry), entry);
17714
+ }
17715
+ return ids;
17716
+ }
17717
+
17525
17718
  // ../../harness-adapter/dist/output-channel.js
17526
17719
  var HarnessOutputChannel = class {
17527
17720
  outputs;
@@ -17594,7 +17787,8 @@ var tokenFields = [
17594
17787
  var safeIntegerFields = [
17595
17788
  "planFiveHourResetsAtUnix",
17596
17789
  "planSevenDayResetsAtUnix",
17597
- "timeToFirstOutputMs"
17790
+ "timeToFirstOutputMs",
17791
+ "latestRequestTimeToFirstOutputMs"
17598
17792
  ];
17599
17793
  var percentFields = [
17600
17794
  "cacheHitRatePercent",
@@ -17857,7 +18051,7 @@ function isExcludedLiveCommand(name, extra = {}) {
17857
18051
  function liveHarnessCommandPrompt(catalog, idPrefix, commandId, argumentText) {
17858
18052
  if (!commandId.startsWith(idPrefix))
17859
18053
  return null;
17860
- const descriptor = catalog.commands.find(({ id }) => id === commandId);
18054
+ const descriptor = catalog.commands.find(({ id: id2 }) => id2 === commandId);
17861
18055
  if (!descriptor)
17862
18056
  return null;
17863
18057
  const text = typeof argumentText === "string" ? argumentText.trim() : "";
@@ -17867,7 +18061,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17867
18061
  if (!live)
17868
18062
  return builtIns;
17869
18063
  const invocations = new Set(builtIns.commands.map(({ invocation }) => invocation));
17870
- const ids = new Set(builtIns.commands.map(({ id }) => id));
18064
+ const ids = new Set(builtIns.commands.map(({ id: id2 }) => id2));
17871
18065
  const dynamic = [];
17872
18066
  for (const command of live) {
17873
18067
  const name = command.name.trim().replace(/^\//u, "");
@@ -17876,12 +18070,12 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17876
18070
  if (isExcludedLiveCommand(name, exclusions))
17877
18071
  continue;
17878
18072
  const invocation = `/${name}`;
17879
- const id = `${idPrefix}${name.replace(/[^A-Za-z0-9._:-]/gu, "-")}`.slice(0, 128);
17880
- if (invocations.has(invocation) || ids.has(id))
18073
+ const id2 = `${idPrefix}${name.replace(/[^A-Za-z0-9._:-]/gu, "-")}`.slice(0, 128);
18074
+ if (invocations.has(invocation) || ids.has(id2))
17881
18075
  continue;
17882
18076
  const description = command.description?.trim().slice(0, 512);
17883
18077
  const parsed = harnessCommandDescriptorSchema.safeParse({
17884
- id,
18078
+ id: id2,
17885
18079
  invocation,
17886
18080
  label: name.slice(0, 128),
17887
18081
  ...description ? { description } : {},
@@ -17890,7 +18084,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17890
18084
  if (!parsed.success)
17891
18085
  continue;
17892
18086
  invocations.add(invocation);
17893
- ids.add(id);
18087
+ ids.add(id2);
17894
18088
  dynamic.push(parsed.data);
17895
18089
  }
17896
18090
  return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
@@ -18420,7 +18614,7 @@ var OMP_DRAFT_THINKING_OPTION_IDS = [
18420
18614
  "high",
18421
18615
  "xhigh",
18422
18616
  "max"
18423
- ].map((id) => harnessThinkingOptionIdSchema.parse(id));
18617
+ ].map((id2) => harnessThinkingOptionIdSchema.parse(id2));
18424
18618
  var OMP_THINKING_LABELS = {
18425
18619
  off: "Off",
18426
18620
  minimal: "Minimal",
@@ -18437,52 +18631,76 @@ function assertNativePart(value, name) {
18437
18631
  if (value.trim().length === 0)
18438
18632
  throw new Error(`Omp ${name} must not be empty`);
18439
18633
  }
18440
- function encodeOmpModelRef(model2) {
18634
+ function readableId({ provider, id: id2 }) {
18635
+ return `${provider}/${id2}`;
18636
+ }
18637
+ function modelLabel({ provider, id: id2 }) {
18638
+ return `${provider} / ${id2}`;
18639
+ }
18640
+ function encodedId({ provider, id: id2 }) {
18641
+ return `${OMP_MODEL_REF_PREFIX}${Buffer.from(JSON.stringify([provider, id2])).toString("base64url")}`;
18642
+ }
18643
+ function encodeOmpModelRef(model2, id2 = readableId(model2)) {
18441
18644
  assertNativePart(model2.provider, "Model provider");
18442
18645
  assertNativePart(model2.id, "Model id");
18443
- const encoded = Buffer.from(JSON.stringify([model2.provider, model2.id]), "utf8").toString("base64url");
18444
- return harnessModelRefSchema.parse({ id: `${OMP_MODEL_REF_PREFIX}${encoded}` });
18646
+ return harnessModelRefSchema.parse({ id: id2 });
18445
18647
  }
18446
- function decodeOmpModelRef(ref) {
18447
- const parsedRef = harnessModelRefSchema.parse(ref);
18448
- if (!parsedRef.id.startsWith(OMP_MODEL_REF_PREFIX)) {
18449
- throw new Error("Model Ref does not belong to OmpAdapter");
18648
+ function createOmpModelIndex(models) {
18649
+ const entries = new Map(models.map(({ provider, id: id2 }) => [JSON.stringify([provider, id2]), { provider, model: id2, id: id2 }]));
18650
+ const byId = compositeModelRefIds([...entries.values()], (entry) => encodedId(entry));
18651
+ const idsByPair = new Map([...byId].map(([id2, entry]) => [JSON.stringify([entry.provider, entry.model]), id2]));
18652
+ return {
18653
+ models,
18654
+ byId,
18655
+ ref: (model2) => {
18656
+ const id2 = idsByPair.get(JSON.stringify([model2.provider, model2.id]));
18657
+ return encodeOmpModelRef(model2, id2 ?? (byId.has(readableId(model2)) ? encodedId(model2) : readableId(model2)));
18658
+ }
18659
+ };
18660
+ }
18661
+ function resolveOmpModelRef(ref, index) {
18662
+ const model2 = index.byId.get(ref.id);
18663
+ if (!model2 || ref.serviceTier) {
18664
+ throw new Error("Model Ref is not in the current Omp Model catalog");
18450
18665
  }
18451
- const encoded = parsedRef.id.slice(OMP_MODEL_REF_PREFIX.length);
18452
- let decoded;
18666
+ return { provider: model2.provider, id: model2.id };
18667
+ }
18668
+ function normalizeStoredOmpModelRef(ref, catalog) {
18669
+ if (!ref.id.startsWith(OMP_MODEL_REF_PREFIX) || ref.serviceTier)
18670
+ return void 0;
18671
+ let tuple2;
18453
18672
  try {
18454
- decoded = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
18673
+ tuple2 = JSON.parse(Buffer.from(ref.id.slice(OMP_MODEL_REF_PREFIX.length), "base64url").toString("utf8"));
18455
18674
  } catch {
18456
- throw new Error("Omp Model Ref is malformed");
18457
- }
18458
- if (!Array.isArray(decoded) || decoded.length !== 2 || typeof decoded[0] !== "string" || typeof decoded[1] !== "string") {
18459
- throw new Error("Omp Model Ref has an invalid native identity");
18460
- }
18461
- const native = { provider: decoded[0], id: decoded[1] };
18462
- assertNativePart(native.provider, "Model provider");
18463
- assertNativePart(native.id, "Model id");
18464
- if (encodeOmpModelRef(native).id !== parsedRef.id) {
18465
- throw new Error("Omp Model Ref is not canonical");
18675
+ return void 0;
18466
18676
  }
18467
- return native;
18677
+ if (!Array.isArray(tuple2) || tuple2.length !== 2 || typeof tuple2[0] !== "string" || typeof tuple2[1] !== "string")
18678
+ return void 0;
18679
+ const native = { provider: tuple2[0], id: tuple2[1] };
18680
+ const encoded = encodedId(native);
18681
+ if (encoded !== ref.id)
18682
+ return void 0;
18683
+ const readable = readableId(native);
18684
+ return catalog.models.find(({ ref: ref2, label }) => ref2.id === encoded || ref2.id === readable && label === modelLabel(native))?.ref;
18468
18685
  }
18469
18686
  function sameOmpModel(left, right) {
18470
18687
  return left === null ? right === null : right !== null && left.provider === right.provider && left.id === right.id;
18471
18688
  }
18472
- function fallbackThinkingLabel(id) {
18473
- const label = id.split(/[._~-]+/u).filter((part) => part.length > 0).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
18474
- return label || id;
18689
+ function fallbackThinkingLabel(id2) {
18690
+ const label = id2.split(/[._~-]+/u).filter((part) => part.length > 0).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
18691
+ return label || id2;
18475
18692
  }
18476
18693
  function normalizeOmpThinkingOptions(levels) {
18477
- return levels.map((id) => harnessThinkingOptionSchema.parse({
18478
- id,
18479
- label: OMP_THINKING_LABELS[id] ?? fallbackThinkingLabel(id)
18694
+ return levels.map((id2) => harnessThinkingOptionSchema.parse({
18695
+ id: id2,
18696
+ label: OMP_THINKING_LABELS[id2] ?? fallbackThinkingLabel(id2)
18480
18697
  }));
18481
18698
  }
18482
18699
  function normalizeOmpModelCatalog(nativeModels, effectiveModel, thinkingLevels, effectiveThinkingOptionId) {
18700
+ const index = createOmpModelIndex(nativeModels);
18483
18701
  const byRef = /* @__PURE__ */ new Map();
18484
18702
  for (const native of nativeModels) {
18485
- const ref = encodeOmpModelRef(native);
18703
+ const ref = index.ref(native);
18486
18704
  const existing = byRef.get(ref.id);
18487
18705
  if (existing) {
18488
18706
  if (existing.reasoning !== native.reasoning) {
@@ -18493,12 +18711,12 @@ function normalizeOmpModelCatalog(nativeModels, effectiveModel, thinkingLevels,
18493
18711
  byRef.set(ref.id, {
18494
18712
  model: {
18495
18713
  ref,
18496
- label: `${native.provider} / ${native.id}`
18714
+ label: modelLabel(native)
18497
18715
  },
18498
18716
  reasoning: native.reasoning
18499
18717
  });
18500
18718
  }
18501
- const defaultModel = effectiveModel ? encodeOmpModelRef(effectiveModel) : void 0;
18719
+ const defaultModel = effectiveModel ? index.ref(effectiveModel) : void 0;
18502
18720
  if (defaultModel && !byRef.has(defaultModel.id)) {
18503
18721
  throw new Error("Omp effective Model is absent from the available Model catalog");
18504
18722
  }
@@ -18509,13 +18727,13 @@ function normalizeOmpModelCatalog(nativeModels, effectiveModel, thinkingLevels,
18509
18727
  throw new Error("Omp did not report an effective Thinking option");
18510
18728
  }
18511
18729
  const thinkingOptions = thinkingLevels ? normalizeOmpThinkingOptions(OMP_DRAFT_THINKING_OPTION_IDS) : [];
18512
- const allThinkingOptionIds = thinkingOptions.map(({ id }) => id);
18513
- const offThinkingOptionId = thinkingOptions.find(({ id }) => id === "off")?.id;
18730
+ const allThinkingOptionIds = thinkingOptions.map(({ id: id2 }) => id2);
18731
+ const offThinkingOptionId = thinkingOptions.find(({ id: id2 }) => id2 === "off")?.id;
18514
18732
  const models = [...byRef.values()].map(({ model: model2, reasoning }) => ({
18515
18733
  ...model2,
18516
18734
  supportedThinkingOptionIds: reasoning ? allThinkingOptionIds : offThinkingOptionId ? [offThinkingOptionId] : []
18517
18735
  })).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
18518
- const defaultThinkingOptionId = thinkingOptions.find(({ id }) => id === effectiveThinkingOptionId)?.id;
18736
+ const defaultThinkingOptionId = thinkingOptions.find(({ id: id2 }) => id2 === effectiveThinkingOptionId)?.id;
18519
18737
  return harnessModelCatalogSchema.parse({
18520
18738
  models,
18521
18739
  ...defaultModel ? { defaultModel } : {},
@@ -18728,25 +18946,30 @@ function modelChange(entry) {
18728
18946
  return entry.type === "model_change" && typeof entry.provider === "string" && typeof entry.modelId === "string" ? { provider: entry.provider, id: entry.modelId } : null;
18729
18947
  }
18730
18948
  function mapOmpSnapshot(history, state) {
18731
- const active = activeOmpEntries(history);
18949
+ const active2 = activeOmpEntries(history);
18732
18950
  const turns = [];
18951
+ const models = createOmpModelIndex([
18952
+ ...state.models ?? [],
18953
+ ...state.model ? [state.model] : [],
18954
+ ...active2.map(modelChange).filter((model2) => model2 !== null)
18955
+ ]);
18733
18956
  let effectiveModel = state.model;
18734
- for (let index = 0; index < active.length; ) {
18735
- const model2 = modelChange(active[index]);
18957
+ for (let index = 0; index < active2.length; ) {
18958
+ const model2 = modelChange(active2[index]);
18736
18959
  if (model2) {
18737
18960
  effectiveModel = model2;
18738
18961
  index += 1;
18739
18962
  continue;
18740
18963
  }
18741
- const user = active[index];
18964
+ const user = active2[index];
18742
18965
  if (messageRole(user) !== "user") {
18743
18966
  index += 1;
18744
18967
  continue;
18745
18968
  }
18746
18969
  let end = index + 1;
18747
- while (end < active.length && messageRole(active[end]) !== "user")
18970
+ while (end < active2.length && messageRole(active2[end]) !== "user")
18748
18971
  end += 1;
18749
- const entries = active.slice(index, end);
18972
+ const entries = active2.slice(index, end);
18750
18973
  const outcome = assistantOutcome(entries);
18751
18974
  const userText = textContent(message(user)?.content);
18752
18975
  const nativeTurnRef = nativeTurnRefSchema.parse({
@@ -18767,7 +18990,7 @@ function mapOmpSnapshot(history, state) {
18767
18990
  input: [{ type: "text", text: userText }],
18768
18991
  items: snapshotItems(entries, outcome),
18769
18992
  outcome,
18770
- ...effectiveModel ? { model: encodeOmpModelRef(effectiveModel) } : {}
18993
+ ...effectiveModel ? { model: models.ref(effectiveModel) } : {}
18771
18994
  });
18772
18995
  for (const entry of entries) {
18773
18996
  const changed = modelChange(entry);
@@ -18784,8 +19007,8 @@ function resolveOmpLastTurnBoundary(history) {
18784
19007
  return last ? { lastUserEntryId: last.id, sourceTurnCount: users.length } : null;
18785
19008
  }
18786
19009
  function resolveOmpForkBoundary(history, checkpointId) {
18787
- const active = activeOmpEntries(history);
18788
- const users = active.filter((entry) => messageRole(entry) === "user");
19010
+ const active2 = activeOmpEntries(history);
19011
+ const users = active2.filter((entry) => messageRole(entry) === "user");
18789
19012
  const targetTurnIndex = users.findIndex((entry) => entry.id === checkpointId);
18790
19013
  if (targetTurnIndex < 0)
18791
19014
  throw new Error("Omp Checkpoint is not on the active branch");
@@ -18948,7 +19171,7 @@ function createOmpUsageStatistics(environment) {
18948
19171
  return Object.freeze({
18949
19172
  // <project>/<session>.jsonl and its subagents' and advisor's in <session>/
18950
19173
  listSources: (signal) => jsonlUsageSources(ompSessionImportDirectory(environment).directory, 4, signal),
18951
- readSource: (id, signal) => readOmpUsage(id, signal)
19174
+ readSource: (id2, signal) => readOmpUsage(id2, signal)
18952
19175
  });
18953
19176
  }
18954
19177
 
@@ -19233,8 +19456,8 @@ var OmpRpcUnsupportedCommandError = class extends Error {
19233
19456
  this.name = "OmpRpcUnsupportedCommandError";
19234
19457
  }
19235
19458
  };
19236
- function hasTurnCompletion(active) {
19237
- return active.terminalEnd || active.localResult !== null && !active.sawAgentStart;
19459
+ function hasTurnCompletion(active2) {
19460
+ return active2.terminalEnd || active2.localResult !== null && !active2.sawAgentStart;
19238
19461
  }
19239
19462
  var textDecoder = new TextDecoder("utf-8", { fatal: true });
19240
19463
  function isRecord8(value) {
@@ -19618,9 +19841,9 @@ var OmpRpcSession = class {
19618
19841
  const branchId = role === "user" ? branchEntryIds?.[userIndex] : void 0;
19619
19842
  if (branchId)
19620
19843
  userIndex += 1;
19621
- const id = branchId ?? (isRecord8(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
19622
- const entry = { id, parentId, type: "message", message: nativeMessage };
19623
- parentId = id;
19844
+ const id2 = branchId ?? (isRecord8(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
19845
+ const entry = { id: id2, parentId, type: "message", message: nativeMessage };
19846
+ parentId = id2;
19624
19847
  return entry;
19625
19848
  });
19626
19849
  return { entries, leafId: parentId };
@@ -19823,9 +20046,9 @@ var OmpRpcSession = class {
19823
20046
  return this.#resolveInteraction(response, "cancelled" in response ? "cancelled" : "responded");
19824
20047
  }
19825
20048
  async #resolveInteraction(response, reason) {
19826
- const active = this.#activeTurn;
19827
- const pending = active?.interactions.get(response.requestId);
19828
- if (!active || !pending || this.#closed || this.#failed) {
20049
+ const active2 = this.#activeTurn;
20050
+ const pending = active2?.interactions.get(response.requestId);
20051
+ if (!active2 || !pending || this.#closed || this.#failed) {
19829
20052
  throw new Error("Omp RPC interaction is not pending");
19830
20053
  }
19831
20054
  if ("value" in response && !["select", "input", "editor"].includes(pending.request.method)) {
@@ -19840,12 +20063,12 @@ var OmpRpcSession = class {
19840
20063
  cancelled: true,
19841
20064
  ...reason === "expired" ? { timedOut: true } : {}
19842
20065
  } : "confirmed" in response ? { type: "extension_ui_response", id: response.requestId, confirmed: response.confirmed } : { type: "extension_ui_response", id: response.requestId, value: response.value };
19843
- if (!active.interactions.delete(response.requestId)) {
20066
+ if (!active2.interactions.delete(response.requestId)) {
19844
20067
  throw new Error("Omp RPC interaction is not pending");
19845
20068
  }
19846
20069
  if (pending.timeout)
19847
20070
  clearTimeout(pending.timeout);
19848
- active.onEvent({ type: "interaction.closed", requestId: response.requestId, reason });
20071
+ active2.onEvent({ type: "interaction.closed", requestId: response.requestId, reason });
19849
20072
  try {
19850
20073
  await this.#write(frame);
19851
20074
  } catch (error51) {
@@ -19855,37 +20078,37 @@ var OmpRpcSession = class {
19855
20078
  }
19856
20079
  }
19857
20080
  abort() {
19858
- const active = this.#activeTurn;
19859
- if (!active || this.#closed || this.#failed) {
20081
+ const active2 = this.#activeTurn;
20082
+ if (!active2 || this.#closed || this.#failed) {
19860
20083
  return Promise.reject(new Error("Omp RPC Session has no cancellable Turn"));
19861
20084
  }
19862
- if (active.abortPromise)
19863
- return active.abortPromise;
19864
- active.cancellation = "requesting";
19865
- active.cancellationTimeout = setTimeout(() => {
19866
- this.#terminateFailedCancellation(active, new OmpRpcFaultError("protocolError", "Omp Turn cancellation did not settle within its bound"));
20085
+ if (active2.abortPromise)
20086
+ return active2.abortPromise;
20087
+ active2.cancellation = "requesting";
20088
+ active2.cancellationTimeout = setTimeout(() => {
20089
+ this.#terminateFailedCancellation(active2, new OmpRpcFaultError("protocolError", "Omp Turn cancellation did not settle within its bound"));
19867
20090
  }, this.#options.cancelTimeoutMs);
19868
20091
  const aborting = this.#send("abort", {}).then(async () => {
19869
- if (this.#activeTurn !== active)
20092
+ if (this.#activeTurn !== active2)
19870
20093
  return;
19871
- active.cancellation = "accepted";
19872
- await this.#confirmCancelledTurn(active);
20094
+ active2.cancellation = "accepted";
20095
+ await this.#confirmCancelledTurn(active2);
19873
20096
  }).catch((error51) => {
19874
- if (this.#activeTurn !== active)
20097
+ if (this.#activeTurn !== active2)
19875
20098
  throw error51;
19876
20099
  const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC Abort failed: ${message2(error51)}`);
19877
- this.#terminateFailedCancellation(active, fault);
20100
+ this.#terminateFailedCancellation(active2, fault);
19878
20101
  throw fault;
19879
20102
  });
19880
- active.abortPromise = aborting;
20103
+ active2.abortPromise = aborting;
19881
20104
  return aborting;
19882
20105
  }
19883
- #terminateFailedCancellation(active, fault) {
19884
- if (this.#activeTurn !== active)
20106
+ #terminateFailedCancellation(active2, fault) {
20107
+ if (this.#activeTurn !== active2)
19885
20108
  return;
19886
- if (active.cancellationTimeout)
19887
- clearTimeout(active.cancellationTimeout);
19888
- active.cancellationTimeout = null;
20109
+ if (active2.cancellationTimeout)
20110
+ clearTimeout(active2.cancellationTimeout);
20111
+ active2.cancellationTimeout = null;
19889
20112
  this.#fail(fault);
19890
20113
  void this.close().catch(() => void 0);
19891
20114
  }
@@ -19988,9 +20211,9 @@ var OmpRpcSession = class {
19988
20211
  this.#compactionTimeout = null;
19989
20212
  const compactionTurn = this.#compactionTurn;
19990
20213
  this.#compactionTurn = null;
19991
- for (const [id, pending] of this.#pending) {
20214
+ for (const [id2, pending] of this.#pending) {
19992
20215
  if (pending.command === "prompt" || pending.command === "compact") {
19993
- this.#armCommandTimeout(id, pending);
20216
+ this.#armCommandTimeout(id2, pending);
19994
20217
  }
19995
20218
  }
19996
20219
  const outcome = value.aborted === true ? "cancelled" : isRecord8(value.result) ? "succeeded" : "failed";
@@ -20009,59 +20232,59 @@ var OmpRpcSession = class {
20009
20232
  });
20010
20233
  return;
20011
20234
  }
20012
- const active = this.#activeTurn;
20013
- if (this.#handleSubagentFrame(active, value))
20235
+ const active2 = this.#activeTurn;
20236
+ if (this.#handleSubagentFrame(active2, value))
20014
20237
  return;
20015
20238
  this.#observeUsage(value);
20016
- if (value.type === "agent_start" && active) {
20017
- active.terminalEnd = false;
20018
- active.sawAgentStart = true;
20239
+ if (value.type === "agent_start" && active2) {
20240
+ active2.terminalEnd = false;
20241
+ active2.sawAgentStart = true;
20019
20242
  }
20020
- if ((value.type === "session_settled" || value.type === "agent_start") && active?.cancellation === "accepted") {
20021
- void this.#confirmCancelledTurn(active);
20243
+ if ((value.type === "session_settled" || value.type === "agent_start") && active2?.cancellation === "accepted") {
20244
+ void this.#confirmCancelledTurn(active2);
20022
20245
  return;
20023
20246
  }
20024
20247
  if (value.type === "session_settled") {
20025
- if (active && hasTurnCompletion(active)) {
20026
- active.settledNotice = true;
20027
- void this.#confirmSettledTurn(active);
20248
+ if (active2 && hasTurnCompletion(active2)) {
20249
+ active2.settledNotice = true;
20250
+ void this.#confirmSettledTurn(active2);
20028
20251
  }
20029
20252
  return;
20030
20253
  }
20031
- if (!active) {
20254
+ if (!active2) {
20032
20255
  if (value.type === "extension_ui_request" && this.#isBlockingInteraction(value)) {
20033
20256
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC requested blocking Extension UI outside an active Turn"));
20034
20257
  }
20035
20258
  return;
20036
20259
  }
20037
20260
  if (value.type === "command_output") {
20038
- if (active.settlement !== "pending")
20261
+ if (active2.settlement !== "pending")
20039
20262
  return;
20040
20263
  if (typeof value.text !== "string") {
20041
20264
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned invalid command output");
20042
20265
  }
20043
- active.text += value.text;
20044
- active.onEvent({ type: "text.delta", messageId: active.promptId, delta: value.text });
20266
+ active2.text += value.text;
20267
+ active2.onEvent({ type: "text.delta", messageId: active2.promptId, delta: value.text });
20045
20268
  return;
20046
20269
  }
20047
20270
  if (value.type === "prompt_result") {
20048
- if (value.id !== active.promptId || value.agentInvoked !== false)
20271
+ if (value.id !== active2.promptId || value.agentInvoked !== false)
20049
20272
  return;
20050
20273
  if (value.status === "completed" || value.status === "aborted") {
20051
- this.#settleLocalTurn(active, { cancelled: value.status === "aborted" });
20274
+ this.#settleLocalTurn(active2, { cancelled: value.status === "aborted" });
20052
20275
  } else if (value.status === "error" && isRecord8(value.error) && typeof value.error.message === "string") {
20053
- this.#settleLocalTurn(active, { cancelled: false, error: value.error.message });
20276
+ this.#settleLocalTurn(active2, { cancelled: false, error: value.error.message });
20054
20277
  } else {
20055
20278
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid local prompt result");
20056
20279
  }
20057
20280
  return;
20058
20281
  }
20059
20282
  if (value.type === "extension_ui_request") {
20060
- this.#startInteraction(active, value);
20283
+ this.#startInteraction(active2, value);
20061
20284
  return;
20062
20285
  }
20063
20286
  if (value.type === "message_start" && assistantText(value.message) !== null) {
20064
- this.#startAssistantMessage(active, value.message);
20287
+ this.#startAssistantMessage(active2, value.message);
20065
20288
  return;
20066
20289
  }
20067
20290
  if (value.type === "message_update" && isRecord8(value.assistantMessageEvent)) {
@@ -20071,39 +20294,39 @@ var OmpRpcSession = class {
20071
20294
  const isText = eventType === "text_delta" || eventType === "text" || eventType === "content_block_delta";
20072
20295
  const delta = typeof event.delta === "string" ? event.delta : typeof event.thinking === "string" ? event.thinking : typeof event.reasoning === "string" ? event.reasoning : typeof event.text === "string" ? event.text : isRecord8(event.delta) && typeof event.delta.thinking === "string" ? event.delta.thinking : isRecord8(event.delta) && typeof event.delta.text === "string" ? event.delta.text : null;
20073
20296
  if (isThinking && delta !== null && delta.length > 0) {
20074
- const messageId = this.#ensureAssistantMessage(active, value.message);
20075
- active.reasoningMessageOpen = true;
20076
- active.sawStreamedMessageReasoning = true;
20077
- active.onEvent({ type: "reasoning.delta", messageId, delta });
20297
+ const messageId = this.#ensureAssistantMessage(active2, value.message);
20298
+ active2.reasoningMessageOpen = true;
20299
+ active2.sawStreamedMessageReasoning = true;
20300
+ active2.onEvent({ type: "reasoning.delta", messageId, delta });
20078
20301
  } else if (isText && delta !== null && delta.length > 0) {
20079
- const messageId = this.#ensureAssistantMessage(active, value.message);
20080
- active.text += delta;
20081
- active.sawStreamedMessageText = true;
20082
- active.onEvent({ type: "text.delta", messageId, delta });
20302
+ const messageId = this.#ensureAssistantMessage(active2, value.message);
20303
+ active2.text += delta;
20304
+ active2.sawStreamedMessageText = true;
20305
+ active2.onEvent({ type: "text.delta", messageId, delta });
20083
20306
  } else if (event.type === "error") {
20084
- this.#ensureAssistantMessage(active, value.message);
20085
- active.failure = assistantFailure(event.error) ?? assistantFailure(value.message) ?? new Error("Omp assistant message failed");
20307
+ this.#ensureAssistantMessage(active2, value.message);
20308
+ active2.failure = assistantFailure(event.error) ?? assistantFailure(value.message) ?? new Error("Omp assistant message failed");
20086
20309
  }
20087
20310
  return;
20088
20311
  }
20089
20312
  if (value.type === "message_end") {
20090
- this.#finalizeAssistantMessage(active, value.message);
20313
+ this.#finalizeAssistantMessage(active2, value.message);
20091
20314
  return;
20092
20315
  }
20093
20316
  if (value.type === "turn_end") {
20094
- this.#finalizeAssistantMessage(active, value.message);
20317
+ this.#finalizeAssistantMessage(active2, value.message);
20095
20318
  return;
20096
20319
  }
20097
20320
  if (value.type === "tool_execution_start") {
20098
- this.#startTool(active, value);
20321
+ this.#startTool(active2, value);
20099
20322
  return;
20100
20323
  }
20101
20324
  if (value.type === "tool_execution_update") {
20102
- this.#updateTool(active, value);
20325
+ this.#updateTool(active2, value);
20103
20326
  return;
20104
20327
  }
20105
20328
  if (value.type === "tool_execution_end") {
20106
- this.#completeTool(active, value);
20329
+ this.#completeTool(active2, value);
20107
20330
  return;
20108
20331
  }
20109
20332
  if (value.type === "agent_end" && Array.isArray(value.messages)) {
@@ -20111,18 +20334,18 @@ var OmpRpcSession = class {
20111
20334
  const message3 = value.messages[index];
20112
20335
  if (!isRecord8(message3) || message3.role !== "assistant")
20113
20336
  continue;
20114
- this.#finalizeAssistantMessage(active, message3);
20337
+ this.#finalizeAssistantMessage(active2, message3);
20115
20338
  break;
20116
20339
  }
20117
20340
  }
20118
20341
  if (value.type === "agent_end" && value.isTerminal !== false) {
20119
- active.terminalEnd = true;
20120
- if (active.cancellation !== "none") {
20121
- if (active.cancellation === "accepted")
20122
- void this.#confirmCancelledTurn(active);
20342
+ active2.terminalEnd = true;
20343
+ if (active2.cancellation !== "none") {
20344
+ if (active2.cancellation === "accepted")
20345
+ void this.#confirmCancelledTurn(active2);
20123
20346
  return;
20124
20347
  }
20125
- void this.#confirmSettledTurn(active);
20348
+ void this.#confirmSettledTurn(active2);
20126
20349
  }
20127
20350
  }
20128
20351
  /** Every finished assistant message is one model request, with or without an active Turn. */
@@ -20164,7 +20387,7 @@ var OmpRpcSession = class {
20164
20387
  });
20165
20388
  }
20166
20389
  }
20167
- #handleSubagentFrame(active, value) {
20390
+ #handleSubagentFrame(active2, value) {
20168
20391
  if (value.type !== "subagent_lifecycle" && value.type !== "subagent_progress" && value.type !== "subagent_event") {
20169
20392
  return false;
20170
20393
  }
@@ -20176,7 +20399,7 @@ var OmpRpcSession = class {
20176
20399
  }
20177
20400
  const nativeSubagentId = nativeIdValue;
20178
20401
  const callId = nativeSubagentId;
20179
- const emit = active?.onEvent ?? this.#options.onSubagentEvent;
20402
+ const emit = active2?.onEvent ?? this.#options.onSubagentEvent;
20180
20403
  if (value.type === "subagent_event") {
20181
20404
  emit?.({ type: "subagent.transcript.changed", callId, nativeSubagentId });
20182
20405
  return true;
@@ -20234,14 +20457,14 @@ var OmpRpcSession = class {
20234
20457
  #isBlockingInteraction(value) {
20235
20458
  return ["select", "confirm", "input", "editor"].includes(String(value.method));
20236
20459
  }
20237
- #startInteraction(active, value) {
20460
+ #startInteraction(active2, value) {
20238
20461
  if (!this.#isBlockingInteraction(value))
20239
20462
  return;
20240
20463
  const requestId = value.id;
20241
20464
  const method = value.method;
20242
20465
  const title = value.title;
20243
20466
  const timeoutMs = value.timeout;
20244
- if (typeof requestId !== "string" || requestId.length === 0 || typeof method !== "string" || typeof title !== "string" || title.length === 0 || timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs < 0) || active.interactions.has(requestId)) {
20467
+ if (typeof requestId !== "string" || requestId.length === 0 || typeof method !== "string" || typeof title !== "string" || title.length === 0 || timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs < 0) || active2.interactions.has(requestId)) {
20245
20468
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Interaction request");
20246
20469
  }
20247
20470
  let request;
@@ -20301,7 +20524,7 @@ var OmpRpcSession = class {
20301
20524
  const pending = { request, timeout: null };
20302
20525
  if (request.timeoutMs !== void 0) {
20303
20526
  pending.timeout = setTimeout(() => {
20304
- if (this.#activeTurn !== active || !active.interactions.has(requestId))
20527
+ if (this.#activeTurn !== active2 || !active2.interactions.has(requestId))
20305
20528
  return;
20306
20529
  void this.#resolveInteraction({ requestId, cancelled: true }, "expired").catch((error51) => {
20307
20530
  if (this.#closed || this.#failed)
@@ -20310,20 +20533,20 @@ var OmpRpcSession = class {
20310
20533
  });
20311
20534
  }, request.timeoutMs);
20312
20535
  }
20313
- active.interactions.set(requestId, pending);
20314
- active.onEvent({ type: "interaction.requested", request });
20536
+ active2.interactions.set(requestId, pending);
20537
+ active2.onEvent({ type: "interaction.requested", request });
20315
20538
  }
20316
20539
  #handleResponse(value) {
20317
- const id = value.id;
20318
- if (typeof id !== "string") {
20540
+ const id2 = value.id;
20541
+ if (typeof id2 !== "string") {
20319
20542
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response has no id"));
20320
20543
  return;
20321
20544
  }
20322
- const pending = this.#pending.get(id);
20323
- const active = this.#activeTurn;
20545
+ const pending = this.#pending.get(id2);
20546
+ const active2 = this.#activeTurn;
20324
20547
  if (!pending) {
20325
- if (active?.promptId === id && value.command === "prompt" && value.success === false) {
20326
- active.failure = new Error(typeof value.error === "string" ? value.error : "Omp RPC command failed");
20548
+ if (active2?.promptId === id2 && value.command === "prompt" && value.success === false) {
20549
+ active2.failure = new Error(typeof value.error === "string" ? value.error : "Omp RPC command failed");
20327
20550
  return;
20328
20551
  }
20329
20552
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response id is not pending"));
@@ -20331,10 +20554,10 @@ var OmpRpcSession = class {
20331
20554
  }
20332
20555
  if (pending.timeout)
20333
20556
  clearTimeout(pending.timeout);
20334
- this.#pending.delete(id);
20557
+ this.#pending.delete(id2);
20335
20558
  if (value.success === true) {
20336
- if (pending.command === "prompt" && active?.promptId === id && isRecord8(value.data) && value.data.agentInvoked === false) {
20337
- this.#settleLocalTurn(active, { cancelled: false });
20559
+ if (pending.command === "prompt" && active2?.promptId === id2 && isRecord8(value.data) && value.data.agentInvoked === false) {
20560
+ this.#settleLocalTurn(active2, { cancelled: false });
20338
20561
  }
20339
20562
  pending.resolve(value);
20340
20563
  } else {
@@ -20348,50 +20571,50 @@ var OmpRpcSession = class {
20348
20571
  }
20349
20572
  }
20350
20573
  }
20351
- #startTool(active, value) {
20574
+ #startTool(active2, value) {
20352
20575
  const callId = value.toolCallId;
20353
20576
  const toolName = value.toolName;
20354
20577
  const argumentsResult = jsonValueSchema.safeParse(value.args);
20355
- if (typeof callId !== "string" || callId.length === 0 || typeof toolName !== "string" || toolName.length === 0 || !argumentsResult.success || active.tools.has(callId)) {
20578
+ if (typeof callId !== "string" || callId.length === 0 || typeof toolName !== "string" || toolName.length === 0 || !argumentsResult.success || active2.tools.has(callId)) {
20356
20579
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool start");
20357
20580
  }
20358
- active.sawTool = true;
20359
- active.tools.set(callId, toolName);
20360
- active.onEvent({
20581
+ active2.sawTool = true;
20582
+ active2.tools.set(callId, toolName);
20583
+ active2.onEvent({
20361
20584
  type: "tool.started",
20362
20585
  callId,
20363
20586
  toolName,
20364
20587
  arguments: argumentsResult.data
20365
20588
  });
20366
20589
  }
20367
- #updateTool(active, value) {
20590
+ #updateTool(active2, value) {
20368
20591
  const callId = value.toolCallId;
20369
20592
  if (typeof callId !== "string" || callId.length === 0) {
20370
20593
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
20371
20594
  }
20372
- if (!active.tools.has(callId))
20595
+ if (!active2.tools.has(callId))
20373
20596
  return;
20374
20597
  const outputResult = jsonValueSchema.safeParse(value.partialResult ?? null);
20375
20598
  if (!outputResult.success) {
20376
20599
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
20377
20600
  }
20378
- active.onEvent({ type: "tool.updated", callId, output: outputResult.data });
20601
+ active2.onEvent({ type: "tool.updated", callId, output: outputResult.data });
20379
20602
  }
20380
- #completeTool(active, value) {
20603
+ #completeTool(active2, value) {
20381
20604
  const callId = value.toolCallId;
20382
20605
  const toolName = value.toolName;
20383
20606
  if (typeof callId !== "string" || callId.length === 0) {
20384
20607
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool end");
20385
20608
  }
20386
- const expectedName = active.tools.get(callId);
20609
+ const expectedName = active2.tools.get(callId);
20387
20610
  if (expectedName === void 0)
20388
20611
  return;
20389
20612
  const result = jsonValueSchema.safeParse(value.result);
20390
20613
  if (typeof toolName !== "string" || expectedName !== toolName || value.isError !== void 0 && typeof value.isError !== "boolean" || !result.success) {
20391
20614
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool end");
20392
20615
  }
20393
- active.tools.delete(callId);
20394
- active.onEvent({
20616
+ active2.tools.delete(callId);
20617
+ active2.onEvent({
20395
20618
  type: "tool.completed",
20396
20619
  callId,
20397
20620
  toolName,
@@ -20399,40 +20622,40 @@ var OmpRpcSession = class {
20399
20622
  isError: value.isError === true
20400
20623
  });
20401
20624
  }
20402
- async #confirmCancelledTurn(active) {
20403
- if (this.#activeTurn !== active || active.cancellation !== "accepted" || active.settlement === "confirming" || active.cancellationChecking)
20625
+ async #confirmCancelledTurn(active2) {
20626
+ if (this.#activeTurn !== active2 || active2.cancellation !== "accepted" || active2.settlement === "confirming" || active2.cancellationChecking)
20404
20627
  return;
20405
- active.cancellationChecking = true;
20406
- if (active.cancellationRecheck)
20407
- clearTimeout(active.cancellationRecheck);
20408
- active.cancellationRecheck = null;
20628
+ active2.cancellationChecking = true;
20629
+ if (active2.cancellationRecheck)
20630
+ clearTimeout(active2.cancellationRecheck);
20631
+ active2.cancellationRecheck = null;
20409
20632
  try {
20410
20633
  let response = await this.#send("get_state", {});
20411
- if (this.#activeTurn !== active)
20634
+ if (this.#activeTurn !== active2)
20412
20635
  return;
20413
20636
  if (parseSessionStreaming(response)) {
20414
20637
  await this.#send("abort", {});
20415
- if (this.#activeTurn !== active)
20638
+ if (this.#activeTurn !== active2)
20416
20639
  return;
20417
20640
  response = await this.#send("get_state", {});
20418
20641
  }
20419
20642
  let state = parseSessionState(response);
20420
- if (this.#activeTurn !== active || active.cancellation !== "accepted")
20643
+ if (this.#activeTurn !== active2 || active2.cancellation !== "accepted")
20421
20644
  return;
20422
20645
  const data = sessionStateData(response);
20423
- if (!active.cancellationReloaded && state.sessionFile && state.sessionId === this.state.sessionId && state.sessionFile === this.state.sessionFile && data.isStreaming === false && data.isCompacting === false && data.queuedMessageCount === 0 && data.hasPendingAsyncWork === true && active.tools.size === 0) {
20646
+ if (!active2.cancellationReloaded && state.sessionFile && state.sessionId === this.state.sessionId && state.sessionFile === this.state.sessionFile && data.isStreaming === false && data.isCompacting === false && data.queuedMessageCount === 0 && data.hasPendingAsyncWork === true && active2.tools.size === 0) {
20424
20647
  await this.verifySessionCwd(this.#options.cwd);
20425
- if (this.#activeTurn !== active)
20648
+ if (this.#activeTurn !== active2)
20426
20649
  return;
20427
- active.cancellationReloaded = true;
20650
+ active2.cancellationReloaded = true;
20428
20651
  const reset = await this.#send("new_session", {});
20429
- if (this.#activeTurn !== active)
20652
+ if (this.#activeTurn !== active2)
20430
20653
  return;
20431
20654
  if (!isRecord8(reset.data) || reset.data.cancelled !== false) {
20432
20655
  throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reset was refused");
20433
20656
  }
20434
20657
  const reloaded = await this.#send("switch_session", { sessionPath: state.sessionFile });
20435
- if (this.#activeTurn !== active)
20658
+ if (this.#activeTurn !== active2)
20436
20659
  return;
20437
20660
  if (!isRecord8(reloaded.data) || reloaded.data.cancelled !== false) {
20438
20661
  throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reload was refused");
@@ -20458,157 +20681,157 @@ var OmpRpcSession = class {
20458
20681
  throw new OmpRpcFaultError("protocolError", "Omp cancelled Session reload changed its identity or configuration");
20459
20682
  }
20460
20683
  }
20461
- if (!sessionSettled(response, active.terminalEnd)) {
20462
- active.settlement = "pending";
20463
- active.cancellationRecheck = setTimeout(() => {
20464
- active.cancellationRecheck = null;
20465
- void this.#confirmCancelledTurn(active);
20684
+ if (!sessionSettled(response, active2.terminalEnd)) {
20685
+ active2.settlement = "pending";
20686
+ active2.cancellationRecheck = setTimeout(() => {
20687
+ active2.cancellationRecheck = null;
20688
+ void this.#confirmCancelledTurn(active2);
20466
20689
  }, 250);
20467
20690
  return;
20468
20691
  }
20469
20692
  this.#state = state;
20470
- active.settlement = "confirmed";
20471
- this.#finishSettledTurn(active);
20693
+ active2.settlement = "confirmed";
20694
+ this.#finishSettledTurn(active2);
20472
20695
  } catch (error51) {
20473
- if (this.#activeTurn !== active)
20696
+ if (this.#activeTurn !== active2)
20474
20697
  return;
20475
20698
  const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC cancelled Turn state could not be confirmed: ${message2(error51)}`);
20476
- this.#terminateFailedCancellation(active, fault);
20699
+ this.#terminateFailedCancellation(active2, fault);
20477
20700
  } finally {
20478
- active.cancellationChecking = false;
20701
+ active2.cancellationChecking = false;
20479
20702
  }
20480
20703
  }
20481
- #settleLocalTurn(active, result) {
20482
- if (this.#activeTurn !== active || active.settlement !== "pending")
20704
+ #settleLocalTurn(active2, result) {
20705
+ if (this.#activeTurn !== active2 || active2.settlement !== "pending")
20483
20706
  return;
20484
- active.localResult = result;
20485
- void this.#confirmSettledTurn(active);
20707
+ active2.localResult = result;
20708
+ void this.#confirmSettledTurn(active2);
20486
20709
  }
20487
- async #confirmSettledTurn(active) {
20488
- if (this.#activeTurn !== active || active.settlement !== "pending" || active.cancellation !== "none" || !hasTurnCompletion(active))
20710
+ async #confirmSettledTurn(active2) {
20711
+ if (this.#activeTurn !== active2 || active2.settlement !== "pending" || active2.cancellation !== "none" || !hasTurnCompletion(active2))
20489
20712
  return;
20490
- if (active.settlementRecheck)
20491
- clearTimeout(active.settlementRecheck);
20492
- active.settlementRecheck = null;
20493
- active.settlement = "confirming";
20713
+ if (active2.settlementRecheck)
20714
+ clearTimeout(active2.settlementRecheck);
20715
+ active2.settlementRecheck = null;
20716
+ active2.settlement = "confirming";
20494
20717
  try {
20495
20718
  const response = await this.#send("get_state", {});
20496
20719
  const state = parseSessionState(response);
20497
- if (this.#activeTurn !== active)
20720
+ if (this.#activeTurn !== active2)
20498
20721
  return;
20499
- if (active.cancellation !== "none") {
20500
- active.settlement = "pending";
20501
- if (active.cancellation === "accepted")
20502
- void this.#confirmCancelledTurn(active);
20722
+ if (active2.cancellation !== "none") {
20723
+ active2.settlement = "pending";
20724
+ if (active2.cancellation === "accepted")
20725
+ void this.#confirmCancelledTurn(active2);
20503
20726
  return;
20504
20727
  }
20505
- if (!hasTurnCompletion(active)) {
20506
- active.settlement = "pending";
20507
- active.settledNotice = false;
20728
+ if (!hasTurnCompletion(active2)) {
20729
+ active2.settlement = "pending";
20730
+ active2.settledNotice = false;
20508
20731
  return;
20509
20732
  }
20510
- if (!sessionSettled(response, hasTurnCompletion(active))) {
20511
- active.settlement = "pending";
20512
- if (active.settledNotice) {
20513
- active.settledNotice = false;
20514
- active.settlementRecheck = setTimeout(() => {
20515
- active.settlementRecheck = null;
20516
- void this.#confirmSettledTurn(active);
20733
+ if (!sessionSettled(response, hasTurnCompletion(active2))) {
20734
+ active2.settlement = "pending";
20735
+ if (active2.settledNotice) {
20736
+ active2.settledNotice = false;
20737
+ active2.settlementRecheck = setTimeout(() => {
20738
+ active2.settlementRecheck = null;
20739
+ void this.#confirmSettledTurn(active2);
20517
20740
  }, 50);
20518
20741
  }
20519
20742
  return;
20520
20743
  }
20521
20744
  this.#state = state;
20522
- active.settlement = "confirmed";
20523
- this.#finishSettledTurn(active);
20745
+ active2.settlement = "confirmed";
20746
+ this.#finishSettledTurn(active2);
20524
20747
  } catch (error51) {
20525
- if (this.#activeTurn !== active)
20748
+ if (this.#activeTurn !== active2)
20526
20749
  return;
20527
20750
  const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC stable Turn state could not be confirmed: ${message2(error51)}`);
20528
20751
  this.#fail(fault);
20529
20752
  }
20530
20753
  }
20531
- #finishSettledTurn(active) {
20532
- if (this.#activeTurn !== active || active.settlement !== "confirmed" || active.cancellation === "requesting") {
20754
+ #finishSettledTurn(active2) {
20755
+ if (this.#activeTurn !== active2 || active2.settlement !== "confirmed" || active2.cancellation === "requesting") {
20533
20756
  return;
20534
20757
  }
20535
- if (active.settlementRecheck)
20536
- clearTimeout(active.settlementRecheck);
20537
- active.settlementRecheck = null;
20538
- if (active.cancellationTimeout)
20539
- clearTimeout(active.cancellationTimeout);
20540
- active.cancellationTimeout = null;
20541
- if (active.cancellationRecheck)
20542
- clearTimeout(active.cancellationRecheck);
20543
- active.cancellationRecheck = null;
20544
- this.#closeInteractions(active, active.cancellation === "accepted" ? "cancelled" : "superseded");
20545
- if (active.tools.size > 0) {
20758
+ if (active2.settlementRecheck)
20759
+ clearTimeout(active2.settlementRecheck);
20760
+ active2.settlementRecheck = null;
20761
+ if (active2.cancellationTimeout)
20762
+ clearTimeout(active2.cancellationTimeout);
20763
+ active2.cancellationTimeout = null;
20764
+ if (active2.cancellationRecheck)
20765
+ clearTimeout(active2.cancellationRecheck);
20766
+ active2.cancellationRecheck = null;
20767
+ this.#closeInteractions(active2, active2.cancellation === "accepted" ? "cancelled" : "superseded");
20768
+ if (active2.tools.size > 0) {
20546
20769
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC settled with active Tool executions"));
20547
20770
  return;
20548
20771
  }
20549
20772
  this.#activeTurn = null;
20550
- if (active.localResult) {
20551
- active.resolve({
20552
- text: active.text,
20773
+ if (active2.localResult) {
20774
+ active2.resolve({
20775
+ text: active2.text,
20553
20776
  agentInvoked: false,
20554
- ...active.localResult,
20555
- cancelled: active.localResult.cancelled || active.cancellation === "accepted"
20777
+ ...active2.localResult,
20778
+ cancelled: active2.localResult.cancelled || active2.cancellation === "accepted"
20556
20779
  });
20557
- } else if (active.cancellation === "accepted") {
20558
- active.resolve({ text: active.text, cancelled: true, agentInvoked: true });
20559
- } else if (active.failure) {
20560
- active.reject(active.failure);
20561
- } else if (active.text.trim().length === 0 && !active.sawTool) {
20562
- active.reject(new Error("Omp RPC settled without displayable output"));
20780
+ } else if (active2.cancellation === "accepted") {
20781
+ active2.resolve({ text: active2.text, cancelled: true, agentInvoked: true });
20782
+ } else if (active2.failure) {
20783
+ active2.reject(active2.failure);
20784
+ } else if (active2.text.trim().length === 0 && !active2.sawTool) {
20785
+ active2.reject(new Error("Omp RPC settled without displayable output"));
20563
20786
  } else {
20564
- active.resolve({ text: active.text, cancelled: false, agentInvoked: true });
20787
+ active2.resolve({ text: active2.text, cancelled: false, agentInvoked: true });
20565
20788
  }
20566
20789
  }
20567
- #startAssistantMessage(active, value) {
20568
- if (active.assistantMessageId !== null && active.reasoningMessageOpen) {
20569
- active.onEvent({ type: "reasoning.completed", messageId: active.assistantMessageId });
20790
+ #startAssistantMessage(active2, value) {
20791
+ if (active2.assistantMessageId !== null && active2.reasoningMessageOpen) {
20792
+ active2.onEvent({ type: "reasoning.completed", messageId: active2.assistantMessageId });
20570
20793
  }
20571
20794
  const messageId = assistantMessageId(value) ?? randomUUID();
20572
- active.assistantMessageId = messageId;
20573
- active.sawStreamedMessageText = false;
20574
- active.sawStreamedMessageReasoning = false;
20575
- active.reasoningMessageOpen = false;
20795
+ active2.assistantMessageId = messageId;
20796
+ active2.sawStreamedMessageText = false;
20797
+ active2.sawStreamedMessageReasoning = false;
20798
+ active2.reasoningMessageOpen = false;
20576
20799
  return messageId;
20577
20800
  }
20578
- #ensureAssistantMessage(active, value) {
20579
- return active.assistantMessageId ?? this.#startAssistantMessage(active, value);
20801
+ #ensureAssistantMessage(active2, value) {
20802
+ return active2.assistantMessageId ?? this.#startAssistantMessage(active2, value);
20580
20803
  }
20581
- #finalizeAssistantMessage(active, value) {
20804
+ #finalizeAssistantMessage(active2, value) {
20582
20805
  const finalText = assistantText(value);
20583
20806
  const finalReasoning = assistantReasoning(value);
20584
20807
  const failure = assistantFailure(value);
20585
20808
  const cacheHitRatePercent = optionalOmpCacheHitRatePercent(value);
20586
20809
  if (finalText === null || finalReasoning === null || failure === void 0)
20587
20810
  return;
20588
- if (active.assistantMessageId === null && finalText === active.lastFinalizedMessageText && finalReasoning === active.lastFinalizedMessageReasoning && !active.sawStreamedMessageText && !active.sawStreamedMessageReasoning) {
20811
+ if (active2.assistantMessageId === null && finalText === active2.lastFinalizedMessageText && finalReasoning === active2.lastFinalizedMessageReasoning && !active2.sawStreamedMessageText && !active2.sawStreamedMessageReasoning) {
20589
20812
  return;
20590
20813
  }
20591
- active.failure = failure;
20814
+ active2.failure = failure;
20592
20815
  this.#latestCacheHitRatePercent = cacheHitRatePercent;
20593
- const messageId = this.#ensureAssistantMessage(active, value);
20594
- if (!active.sawStreamedMessageReasoning && finalReasoning.length > 0) {
20595
- active.reasoningMessageOpen = true;
20596
- active.onEvent({ type: "reasoning.delta", messageId, delta: finalReasoning });
20597
- }
20598
- if (active.reasoningMessageOpen && active.failure === null) {
20599
- active.onEvent({ type: "reasoning.completed", messageId });
20600
- }
20601
- if (!active.sawStreamedMessageText && finalText.length > 0) {
20602
- active.text += finalText;
20603
- active.onEvent({ type: "text.delta", messageId, delta: finalText });
20604
- }
20605
- active.assistantMessageId = null;
20606
- active.sawStreamedMessageText = false;
20607
- active.sawStreamedMessageReasoning = false;
20608
- active.reasoningMessageOpen = false;
20609
- active.lastFinalizedMessageText = finalText;
20610
- active.lastFinalizedMessageReasoning = finalReasoning;
20611
- active.onEvent({ type: "message.completed", messageId });
20816
+ const messageId = this.#ensureAssistantMessage(active2, value);
20817
+ if (!active2.sawStreamedMessageReasoning && finalReasoning.length > 0) {
20818
+ active2.reasoningMessageOpen = true;
20819
+ active2.onEvent({ type: "reasoning.delta", messageId, delta: finalReasoning });
20820
+ }
20821
+ if (active2.reasoningMessageOpen && active2.failure === null) {
20822
+ active2.onEvent({ type: "reasoning.completed", messageId });
20823
+ }
20824
+ if (!active2.sawStreamedMessageText && finalText.length > 0) {
20825
+ active2.text += finalText;
20826
+ active2.onEvent({ type: "text.delta", messageId, delta: finalText });
20827
+ }
20828
+ active2.assistantMessageId = null;
20829
+ active2.sawStreamedMessageText = false;
20830
+ active2.sawStreamedMessageReasoning = false;
20831
+ active2.reasoningMessageOpen = false;
20832
+ active2.lastFinalizedMessageText = finalText;
20833
+ active2.lastFinalizedMessageReasoning = finalReasoning;
20834
+ active2.onEvent({ type: "message.completed", messageId });
20612
20835
  }
20613
20836
  #write(value) {
20614
20837
  const child = this.#child;
@@ -20621,7 +20844,7 @@ var OmpRpcSession = class {
20621
20844
  child.stdin.write(frame, (error51) => error51 ? reject(error51) : resolve());
20622
20845
  });
20623
20846
  }
20624
- #send(type, payload, id = `codexhost-${randomUUID()}`, onResponse) {
20847
+ #send(type, payload, id2 = `codexhost-${randomUUID()}`, onResponse) {
20625
20848
  const child = this.#child;
20626
20849
  if (!child?.stdin.writable || this.#closed || this.#failed) {
20627
20850
  return Promise.reject(new Error("Omp RPC stdin is unavailable"));
@@ -20636,31 +20859,31 @@ var OmpRpcSession = class {
20636
20859
  reject,
20637
20860
  timeout: null
20638
20861
  };
20639
- this.#pending.set(id, pending);
20640
- this.#armCommandTimeout(id, pending);
20641
- const frame = Buffer.from(`${JSON.stringify({ id, type, ...payload })}
20862
+ this.#pending.set(id2, pending);
20863
+ this.#armCommandTimeout(id2, pending);
20864
+ const frame = Buffer.from(`${JSON.stringify({ id: id2, type, ...payload })}
20642
20865
  `, "utf8");
20643
20866
  child.stdin.write(frame, (error51) => {
20644
20867
  if (error51) {
20645
20868
  if (pending.timeout)
20646
20869
  clearTimeout(pending.timeout);
20647
- this.#pending.delete(id);
20870
+ this.#pending.delete(id2);
20648
20871
  reject(error51);
20649
20872
  }
20650
20873
  });
20651
20874
  });
20652
20875
  }
20653
- #armCommandTimeout(id, pending) {
20654
- if (pending.timeout || this.#pending.get(id) !== pending || (pending.command === "prompt" || pending.command === "compact") && this.#compactionActive) {
20876
+ #armCommandTimeout(id2, pending) {
20877
+ if (pending.timeout || this.#pending.get(id2) !== pending || (pending.command === "prompt" || pending.command === "compact") && this.#compactionActive) {
20655
20878
  return;
20656
20879
  }
20657
20880
  pending.timeout = setTimeout(() => {
20658
- if (this.#pending.get(id) !== pending)
20881
+ if (this.#pending.get(id2) !== pending)
20659
20882
  return;
20660
20883
  pending.timeout = null;
20661
20884
  const error51 = new Error(`Omp RPC '${pending.command}' command timed out`);
20662
20885
  if (pending.command !== "prompt") {
20663
- this.#pending.delete(id);
20886
+ this.#pending.delete(id2);
20664
20887
  pending.reject(error51);
20665
20888
  return;
20666
20889
  }
@@ -20687,27 +20910,27 @@ var OmpRpcSession = class {
20687
20910
  this.#rejectAll(finalFault);
20688
20911
  this.#options.onFault?.(finalFault);
20689
20912
  }
20690
- #closeInteractions(active, reason) {
20691
- for (const [requestId, pending] of active.interactions) {
20692
- active.interactions.delete(requestId);
20913
+ #closeInteractions(active2, reason) {
20914
+ for (const [requestId, pending] of active2.interactions) {
20915
+ active2.interactions.delete(requestId);
20693
20916
  if (pending.timeout)
20694
20917
  clearTimeout(pending.timeout);
20695
- active.onEvent({ type: "interaction.closed", requestId, reason });
20918
+ active2.onEvent({ type: "interaction.closed", requestId, reason });
20696
20919
  }
20697
20920
  }
20698
20921
  #rejectActiveTurn(error51) {
20699
- const active = this.#activeTurn;
20700
- if (!active)
20922
+ const active2 = this.#activeTurn;
20923
+ if (!active2)
20701
20924
  return;
20702
- if (active.settlementRecheck)
20703
- clearTimeout(active.settlementRecheck);
20704
- if (active.cancellationTimeout)
20705
- clearTimeout(active.cancellationTimeout);
20706
- if (active.cancellationRecheck)
20707
- clearTimeout(active.cancellationRecheck);
20708
- this.#closeInteractions(active, "cancelled");
20925
+ if (active2.settlementRecheck)
20926
+ clearTimeout(active2.settlementRecheck);
20927
+ if (active2.cancellationTimeout)
20928
+ clearTimeout(active2.cancellationTimeout);
20929
+ if (active2.cancellationRecheck)
20930
+ clearTimeout(active2.cancellationRecheck);
20931
+ this.#closeInteractions(active2, "cancelled");
20709
20932
  this.#activeTurn = null;
20710
- active.reject(error51);
20933
+ active2.reject(error51);
20711
20934
  }
20712
20935
  #rejectAll(error51) {
20713
20936
  if (this.#compactionTimeout)
@@ -21492,10 +21715,10 @@ var OmpSubagentLifecycle = class {
21492
21715
  return subagent;
21493
21716
  }
21494
21717
  update(turnId, event) {
21495
- const active = this.#delegations.get(event.callId);
21496
- if (!active)
21718
+ const active2 = this.#delegations.get(event.callId);
21719
+ if (!active2)
21497
21720
  return void 0;
21498
- const current = active.item.subagents[0];
21721
+ const current = active2.item.subagents[0];
21499
21722
  if (!current)
21500
21723
  throw new Error("Omp Subagent delegation has no Agent state");
21501
21724
  const subagent = {
@@ -21506,21 +21729,21 @@ var OmpSubagentLifecycle = class {
21506
21729
  ...event.resultSummary ? { resultSummary: event.resultSummary } : {},
21507
21730
  ...event.nativeSubagentId ? { nativeSubagentId: event.nativeSubagentId } : {}
21508
21731
  };
21509
- active.item = { ...active.item, subagents: [subagent] };
21732
+ active2.item = { ...active2.item, subagents: [subagent] };
21510
21733
  this.#emit({
21511
21734
  type: "item.updated",
21512
21735
  turnId,
21513
- itemId: active.item.itemId,
21514
- update: { type: "subagents.replace", subagents: active.item.subagents }
21736
+ itemId: active2.item.itemId,
21737
+ update: { type: "subagents.replace", subagents: active2.item.subagents }
21515
21738
  });
21516
21739
  return subagent;
21517
21740
  }
21518
21741
  complete(turnId, event, cancellationRequested) {
21519
- const active = this.#delegations.get(event.callId);
21520
- if (!active)
21742
+ const active2 = this.#delegations.get(event.callId);
21743
+ if (!active2)
21521
21744
  throw new Error("Omp Subagent completion references an unknown delegation");
21522
21745
  this.#delegations.delete(event.callId);
21523
- const current = active.item.subagents[0];
21746
+ const current = active2.item.subagents[0];
21524
21747
  if (!current)
21525
21748
  throw new Error("Omp Subagent delegation has no Agent state");
21526
21749
  const subagent = {
@@ -21529,7 +21752,7 @@ var OmpSubagentLifecycle = class {
21529
21752
  ...event.resultSummary ? { resultSummary: event.resultSummary } : {},
21530
21753
  ...event.nativeSubagentId ? { nativeSubagentId: event.nativeSubagentId } : {}
21531
21754
  };
21532
- const item = { ...active.item, subagents: [subagent] };
21755
+ const item = { ...active2.item, subagents: [subagent] };
21533
21756
  this.#emit({
21534
21757
  type: "item.updated",
21535
21758
  turnId,
@@ -21541,13 +21764,13 @@ var OmpSubagentLifecycle = class {
21541
21764
  return subagent;
21542
21765
  }
21543
21766
  finalize(turnId, outcome) {
21544
- for (const [callId, active] of this.#delegations) {
21767
+ for (const [callId, active2] of this.#delegations) {
21545
21768
  this.#delegations.delete(callId);
21546
- const current = active.item.subagents[0];
21769
+ const current = active2.item.subagents[0];
21547
21770
  if (!current)
21548
21771
  continue;
21549
21772
  const status = outcome.status === "succeeded" ? current.status : outcome.status === "cancelled" ? "interrupted" : "failed";
21550
- const item = { ...active.item, subagents: [{ ...current, status }] };
21773
+ const item = { ...active2.item, subagents: [{ ...current, status }] };
21551
21774
  this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
21552
21775
  }
21553
21776
  }
@@ -21638,12 +21861,9 @@ function nativeModelFromState(state) {
21638
21861
  }
21639
21862
  return { provider: state.provider, id: state.modelId };
21640
21863
  }
21641
- function effectiveModelFromState(state) {
21864
+ function harnessStateFromOmp(state, thinkingLevels, index, permissionModeId) {
21642
21865
  const model2 = nativeModelFromState(state);
21643
- return model2 ? encodeOmpModelRef(model2) : void 0;
21644
- }
21645
- function harnessStateFromOmp(state, thinkingLevels, permissionModeId) {
21646
- const effectiveModel = effectiveModelFromState(state);
21866
+ const effectiveModel = model2 ? index.ref(model2) : void 0;
21647
21867
  const availableThinkingOptions = thinkingLevels ? normalizeOmpThinkingOptions(thinkingLevels) : void 0;
21648
21868
  if (availableThinkingOptions && (!state.thinkingLevel || !thinkingLevels?.includes(state.thinkingLevel))) {
21649
21869
  throw new OmpRpcFaultError("protocolError", "Omp effective Thinking level is absent from its available levels");
@@ -21864,10 +22084,10 @@ function fileChangeFromPatch(patch, cwd) {
21864
22084
  return [{ path: displayed.path, kind, unifiedDiff: patch }];
21865
22085
  }
21866
22086
  function synthesizeFileChange(kind, args, cwd) {
21867
- const filePath = nestedToolString(args, ["path", "file_path", "filePath", "file"]);
21868
- if (!filePath)
22087
+ const filePath2 = nestedToolString(args, ["path", "file_path", "filePath", "file"]);
22088
+ if (!filePath2)
21869
22089
  return null;
21870
- const displayed = displayPath(filePath, cwd);
22090
+ const displayed = displayPath(filePath2, cwd);
21871
22091
  if (!displayed)
21872
22092
  return null;
21873
22093
  if (kind === "write") {
@@ -21944,6 +22164,7 @@ var OmpHarnessSession = class {
21944
22164
  #requestedModel;
21945
22165
  #requestedThinkingOptionId;
21946
22166
  #toolOutputLimit;
22167
+ #modelIndex;
21947
22168
  #permissionMode;
21948
22169
  #permissionModeId;
21949
22170
  #acceptingTurn = false;
@@ -21985,7 +22206,8 @@ var OmpHarnessSession = class {
21985
22206
  execute: (command) => this.#executeHarnessCommand(command)
21986
22207
  };
21987
22208
  this.#transport = options.startedTransport ?? null;
21988
- this.initialState = options.startedTransport ? harnessStateFromOmp(options.startedTransport.state, options.startedThinkingLevels ?? null, this.#permissionModeId) : { effectivePermissionModeId: this.#permissionModeId };
22209
+ this.#modelIndex = createOmpModelIndex(options.startedModels ?? []);
22210
+ this.initialState = options.startedTransport ? harnessStateFromOmp(options.startedTransport.state, options.startedThinkingLevels ?? null, this.#modelIndex, this.#permissionModeId) : { effectivePermissionModeId: this.#permissionModeId };
21989
22211
  this.initialUsage = options.initialUsage ?? null;
21990
22212
  this.#usage = this.initialUsage;
21991
22213
  this.#state = this.initialState;
@@ -22056,7 +22278,7 @@ var OmpHarnessSession = class {
22056
22278
  }
22057
22279
  #subagentConfiguration() {
22058
22280
  const state = this.#state;
22059
- const model2 = state.effectiveModel ? decodeOmpModelRef(state.effectiveModel).id : void 0;
22281
+ const model2 = this.#transport?.state.modelId;
22060
22282
  return {
22061
22283
  ...model2 ? { model: model2 } : {},
22062
22284
  ...state.effectiveThinkingOptionId ? { reasoningEffort: state.effectiveThinkingOptionId } : {}
@@ -22104,7 +22326,8 @@ var OmpHarnessSession = class {
22104
22326
  value: {
22105
22327
  ...mapOmpSnapshot(history, {
22106
22328
  sessionId: transport.state.sessionId,
22107
- model: nativeModelForHistory(transport.state)
22329
+ model: nativeModelForHistory(transport.state),
22330
+ models: this.#modelIndex.models
22108
22331
  }),
22109
22332
  state: this.#state
22110
22333
  }
@@ -22184,7 +22407,7 @@ var OmpHarnessSession = class {
22184
22407
  itemId: this.#newItemId(),
22185
22408
  text: ""
22186
22409
  };
22187
- const active = {
22410
+ const active2 = {
22188
22411
  command,
22189
22412
  agentItem: item,
22190
22413
  agentMessageId: null,
@@ -22206,23 +22429,23 @@ var OmpHarnessSession = class {
22206
22429
  completion,
22207
22430
  resolveCompletion
22208
22431
  };
22209
- this.#active = active;
22432
+ this.#active = active2;
22210
22433
  this.#event({ type: "turn.started", turnId: command.turnId });
22211
22434
  this.#event({ type: "item.started", turnId: command.turnId, item });
22212
- void transport.runTurn(text, (event) => this.#handleTurnEvent(active, event)).then(async (result) => {
22435
+ void transport.runTurn(text, (event) => this.#handleTurnEvent(active2, event)).then(async (result) => {
22213
22436
  if (!result.agentInvoked) {
22214
- this.#completeTurn(active, result.error !== void 0 ? { status: "failed", error: normalizedError(result.error, "nativeFailure") } : result.cancelled ? { status: "cancelled", reason: "Cancelled by user" } : { status: "succeeded" }, result.text, void 0, true);
22437
+ this.#completeTurn(active2, result.error !== void 0 ? { status: "failed", error: normalizedError(result.error, "nativeFailure") } : result.cancelled ? { status: "cancelled", reason: "Cancelled by user" } : { status: "succeeded" }, result.text, void 0, true);
22215
22438
  return;
22216
22439
  }
22217
22440
  try {
22218
- const identity2 = await this.#completedTurnIdentity(active, transport);
22219
- this.#completeTurn(active, result.cancelled ? {
22441
+ const identity2 = await this.#completedTurnIdentity(active2, transport);
22442
+ this.#completeTurn(active2, result.cancelled ? {
22220
22443
  status: "cancelled",
22221
22444
  reason: "Cancelled by user",
22222
22445
  checkpoint: identity2.checkpoint
22223
22446
  } : { status: "succeeded", checkpoint: identity2.checkpoint }, result.text, identity2.nativeTurnRef);
22224
22447
  } catch (error51) {
22225
- this.#completeTurn(active, {
22448
+ this.#completeTurn(active2, {
22226
22449
  status: "failed",
22227
22450
  error: normalizedError(error51, "protocolError")
22228
22451
  });
@@ -22230,10 +22453,10 @@ var OmpHarnessSession = class {
22230
22453
  }).catch(async (error51) => {
22231
22454
  let identity2;
22232
22455
  try {
22233
- identity2 = await this.#completedTurnIdentity(active, transport);
22456
+ identity2 = await this.#completedTurnIdentity(active2, transport);
22234
22457
  } catch {
22235
22458
  }
22236
- this.#completeTurn(active, {
22459
+ this.#completeTurn(active2, {
22237
22460
  status: "failed",
22238
22461
  error: normalizedError(error51, "nativeFailure"),
22239
22462
  ...identity2 ? { checkpoint: identity2.checkpoint } : {}
@@ -22268,15 +22491,17 @@ var OmpHarnessSession = class {
22268
22491
  error: invalidState("Omp Model selection requires a started Native Session")
22269
22492
  };
22270
22493
  }
22271
- let requested;
22272
- try {
22273
- requested = decodeOmpModelRef(command.model);
22274
- } catch (error51) {
22275
- return { ok: false, error: normalizedError(error51, "invalidRequest") };
22276
- }
22277
22494
  const previousModel = this.#state.effectiveModel;
22278
22495
  this.#configuring = true;
22279
22496
  try {
22497
+ let requested;
22498
+ try {
22499
+ const index = createOmpModelIndex(await transport.getAvailableModels());
22500
+ requested = resolveOmpModelRef(harnessModelRefSchema.parse(command.model), index);
22501
+ this.#modelIndex = index;
22502
+ } catch (error51) {
22503
+ return { ok: false, error: normalizedError(error51, "invalidRequest") };
22504
+ }
22280
22505
  let state;
22281
22506
  let thinkingLevels;
22282
22507
  try {
@@ -22292,8 +22517,7 @@ var OmpHarnessSession = class {
22292
22517
  return { ok: false, error: normalizedError(error51, "nativeFailure") };
22293
22518
  }
22294
22519
  const actual = nativeModelFromState(state);
22295
- const nextModel = effectiveModelFromState(state);
22296
- if (previousModel?.id !== nextModel?.id) {
22520
+ if (previousModel?.id !== this.#state.effectiveModel?.id) {
22297
22521
  this.#invalidateUsage();
22298
22522
  void this.#refreshUsage();
22299
22523
  }
@@ -22476,9 +22700,9 @@ var OmpHarnessSession = class {
22476
22700
  }
22477
22701
  }
22478
22702
  async #respond(command) {
22479
- const active = this.#active;
22480
- const pending = active?.interactions.get(command.interactionId);
22481
- if (!active || !pending) {
22703
+ const active2 = this.#active;
22704
+ const pending = active2?.interactions.get(command.interactionId);
22705
+ if (!active2 || !pending) {
22482
22706
  return {
22483
22707
  ok: false,
22484
22708
  error: invalidState("Omp Interaction Response must reference a pending Interaction")
@@ -22551,8 +22775,8 @@ var OmpHarnessSession = class {
22551
22775
  }
22552
22776
  }
22553
22777
  #canSteerActiveTurn() {
22554
- const active = this.#active;
22555
- return Boolean(this.#phase === "open" && active && !active.cancellationRequested && active.acceptingSteers && active.tools.size > 0 && this.#transport);
22778
+ const active2 = this.#active;
22779
+ return Boolean(this.#phase === "open" && active2 && !active2.cancellationRequested && active2.acceptingSteers && active2.tools.size > 0 && this.#transport);
22556
22780
  }
22557
22781
  async #steer(command) {
22558
22782
  const text = command.input.map((input) => input.text).join("\n");
@@ -22566,17 +22790,17 @@ var OmpHarnessSession = class {
22566
22790
  }
22567
22791
  };
22568
22792
  }
22569
- const active = this.#active;
22793
+ const active2 = this.#active;
22570
22794
  const transport = this.#transport;
22571
- if (!active || !transport || active.command.turnId !== command.turnId || !this.#canSteerActiveTurn()) {
22795
+ if (!active2 || !transport || active2.command.turnId !== command.turnId || !this.#canSteerActiveTurn()) {
22572
22796
  return { ok: false, error: invalidState("Omp Turn is not accepting native input") };
22573
22797
  }
22574
22798
  let accepted;
22575
22799
  try {
22576
22800
  accepted = transport.steer(text).then(() => {
22577
- active.acceptedSteerCount += 1;
22801
+ active2.acceptedSteerCount += 1;
22578
22802
  });
22579
- active.pendingSteers.add(accepted);
22803
+ active2.pendingSteers.add(accepted);
22580
22804
  await accepted;
22581
22805
  return { ok: true, value: { accepted: true } };
22582
22806
  } catch (error51) {
@@ -22584,34 +22808,34 @@ var OmpHarnessSession = class {
22584
22808
  return { ok: false, error: invalidState(error51.message) };
22585
22809
  }
22586
22810
  if (error51 instanceof OmpRpcSteerTargetEndedError)
22587
- active.steerFailure = error51;
22811
+ active2.steerFailure = error51;
22588
22812
  throw error51;
22589
22813
  } finally {
22590
22814
  if (accepted)
22591
- active.pendingSteers.delete(accepted);
22815
+ active2.pendingSteers.delete(accepted);
22592
22816
  }
22593
22817
  }
22594
22818
  async #cancel(command) {
22595
- const active = this.#active;
22596
- if (!active || active.command.turnId !== command.turnId) {
22819
+ const active2 = this.#active;
22820
+ if (!active2 || active2.command.turnId !== command.turnId) {
22597
22821
  return {
22598
22822
  ok: false,
22599
22823
  error: invalidState("Omp Turn Cancel must reference the active Turn")
22600
22824
  };
22601
22825
  }
22602
- if (active.cancellationRequested) {
22826
+ if (active2.cancellationRequested) {
22603
22827
  return { ok: true, value: { cancellationRequested: true } };
22604
22828
  }
22605
22829
  const transport = this.#transport;
22606
22830
  if (!transport)
22607
22831
  return { ok: false, error: invalidState("Omp transport is unavailable") };
22608
- active.cancellationRequested = true;
22832
+ active2.cancellationRequested = true;
22609
22833
  try {
22610
22834
  await transport.abort();
22611
22835
  return { ok: true, value: { cancellationRequested: true } };
22612
22836
  } catch (error51) {
22613
22837
  const normalized = normalizedError(error51, "nativeFailure");
22614
- if (this.#active === active) {
22838
+ if (this.#active === active2) {
22615
22839
  this.#fault(new OmpAdapterFaultError(normalized));
22616
22840
  void transport.close().catch(() => void 0);
22617
22841
  }
@@ -22695,7 +22919,7 @@ var OmpHarnessSession = class {
22695
22919
  const completion = new Promise((resolve) => {
22696
22920
  resolveCompletion = resolve;
22697
22921
  });
22698
- const active = {
22922
+ const active2 = {
22699
22923
  command: turnCommand,
22700
22924
  agentItem: null,
22701
22925
  agentMessageId: null,
@@ -22717,18 +22941,18 @@ var OmpHarnessSession = class {
22717
22941
  completion,
22718
22942
  resolveCompletion
22719
22943
  };
22720
- this.#active = active;
22944
+ this.#active = active2;
22721
22945
  this.#event({ type: "turn.started", turnId: command.turnId });
22722
- void transport.compact(customInstructions, (event) => this.#handleTurnEvent(active, event)).then((result) => {
22946
+ void transport.compact(customInstructions, (event) => this.#handleTurnEvent(active2, event)).then((result) => {
22723
22947
  if (result.outcome === "succeeded") {
22724
- this.#completeTurn(active, { status: "succeeded" });
22948
+ this.#completeTurn(active2, { status: "succeeded" });
22725
22949
  } else if (result.outcome === "cancelled") {
22726
- this.#completeTurn(active, {
22950
+ this.#completeTurn(active2, {
22727
22951
  status: "cancelled",
22728
22952
  reason: "Context compaction was cancelled"
22729
22953
  });
22730
22954
  } else {
22731
- this.#completeTurn(active, {
22955
+ this.#completeTurn(active2, {
22732
22956
  status: "failed",
22733
22957
  error: {
22734
22958
  code: "nativeFailure",
@@ -22738,7 +22962,7 @@ var OmpHarnessSession = class {
22738
22962
  });
22739
22963
  }
22740
22964
  }).catch((error51) => {
22741
- this.#completeTurn(active, {
22965
+ this.#completeTurn(active2, {
22742
22966
  status: "failed",
22743
22967
  error: normalizedError(error51, "nativeFailure")
22744
22968
  });
@@ -22764,9 +22988,11 @@ var OmpHarnessSession = class {
22764
22988
  if (this.#phase !== "open")
22765
22989
  throw new Error("Omp Session closed during startup");
22766
22990
  let state = transport.state;
22991
+ const models = await transport.getAvailableModels();
22992
+ this.#modelIndex = createOmpModelIndex(models);
22767
22993
  let thinkingLevels = await transport.getAvailableThinkingLevels();
22768
22994
  if (this.#requestedModel) {
22769
- const requested = decodeOmpModelRef(this.#requestedModel);
22995
+ const requested = resolveOmpModelRef(this.#requestedModel, this.#modelIndex);
22770
22996
  const current = nativeModelFromState(state);
22771
22997
  if (!sameOmpModel(current, requested))
22772
22998
  state = await transport.selectModel(requested);
@@ -22779,7 +23005,7 @@ var OmpHarnessSession = class {
22779
23005
  if (this.#requestedThinkingOptionId) {
22780
23006
  if (!thinkingLevels) {
22781
23007
  const current = nativeModelFromState(state);
22782
- const thinkingAlreadyOff = this.#requestedThinkingOptionId === "off" && (state.thinkingLevel === "off" || current !== null && (await transport.getAvailableModels()).some((model2) => sameOmpModel(model2, current) && model2.reasoning === false));
23008
+ const thinkingAlreadyOff = this.#requestedThinkingOptionId === "off" && (state.thinkingLevel === "off" || current !== null && models.some((model2) => sameOmpModel(model2, current) && model2.reasoning === false));
22783
23009
  if (!thinkingAlreadyOff) {
22784
23010
  throw new OmpAdapterFaultError({
22785
23011
  code: "unsupported",
@@ -22811,7 +23037,7 @@ var OmpHarnessSession = class {
22811
23037
  return starting;
22812
23038
  }
22813
23039
  #publishTransportState(state, thinkingLevels) {
22814
- this.#state = harnessStateFromOmp(state, thinkingLevels, this.#permissionModeId);
23040
+ this.#state = harnessStateFromOmp(state, thinkingLevels, this.#modelIndex, this.#permissionModeId);
22815
23041
  this.#event({ type: "session.state.changed", state: this.#state });
22816
23042
  }
22817
23043
  #invalidateUsage() {
@@ -22847,50 +23073,50 @@ var OmpHarnessSession = class {
22847
23073
  ...observedForTurnId ? { observedForTurnId } : {}
22848
23074
  });
22849
23075
  }
22850
- #handleTurnEvent(active, event) {
22851
- if (this.#active !== active || this.#phase === "closed" || this.#phase === "faulted")
23076
+ #handleTurnEvent(active2, event) {
23077
+ if (this.#active !== active2 || this.#phase === "closed" || this.#phase === "faulted")
22852
23078
  return;
22853
23079
  switch (event.type) {
22854
23080
  case "text.delta":
22855
- this.#activateAgentMessage(active, event.messageId);
22856
- this.#appendText(active, event.delta);
23081
+ this.#activateAgentMessage(active2, event.messageId);
23082
+ this.#appendText(active2, event.delta);
22857
23083
  return;
22858
23084
  case "reasoning.delta":
22859
- this.#activateAgentMessage(active, event.messageId);
22860
- this.#appendReasoning(active, event.delta);
23085
+ this.#activateAgentMessage(active2, event.messageId);
23086
+ this.#appendReasoning(active2, event.delta);
22861
23087
  return;
22862
23088
  case "reasoning.completed":
22863
- this.#completeReasoning(active, { status: "succeeded" });
23089
+ this.#completeReasoning(active2, { status: "succeeded" });
22864
23090
  return;
22865
23091
  case "message.completed":
22866
- void this.#refreshUsage(active.command.turnId);
23092
+ void this.#refreshUsage(active2.command.turnId);
22867
23093
  return;
22868
23094
  case "compaction.started":
22869
- this.#startCompaction(active);
23095
+ this.#startCompaction(active2);
22870
23096
  return;
22871
23097
  case "compaction.completed":
22872
- this.#completeCompaction(active, event);
23098
+ this.#completeCompaction(active2, event);
22873
23099
  return;
22874
23100
  case "interaction.requested":
22875
- this.#startInteraction(active, event.request);
23101
+ this.#startInteraction(active2, event.request);
22876
23102
  return;
22877
23103
  case "interaction.closed":
22878
- this.#closeInteraction(active, event.requestId, event.reason);
23104
+ this.#closeInteraction(active2, event.requestId, event.reason);
22879
23105
  return;
22880
23106
  case "tool.started":
22881
- this.#completeReasoning(active, { status: "succeeded" });
22882
- this.#completeAgentItem(active, { status: "succeeded" }, false);
22883
- this.#startTool(active, event);
23107
+ this.#completeReasoning(active2, { status: "succeeded" });
23108
+ this.#completeAgentItem(active2, { status: "succeeded" }, false);
23109
+ this.#startTool(active2, event);
22884
23110
  return;
22885
23111
  case "tool.updated":
22886
- this.#updateTool(active, event);
23112
+ this.#updateTool(active2, event);
22887
23113
  return;
22888
23114
  case "tool.completed":
22889
- this.#completeTool(active, event);
23115
+ this.#completeTool(active2, event);
22890
23116
  return;
22891
23117
  case "subagent.started":
22892
23118
  {
22893
- const subagent = active.subagents.start(active.command.turnId, event);
23119
+ const subagent = active2.subagents.start(active2.command.turnId, event);
22894
23120
  this.#event({
22895
23121
  type: "subagent.state.changed",
22896
23122
  nativeSubagentId: subagent.nativeSubagentId ?? subagent.subagentId,
@@ -22900,7 +23126,7 @@ var OmpHarnessSession = class {
22900
23126
  return;
22901
23127
  case "subagent.updated":
22902
23128
  {
22903
- const subagent = active.subagents.update(active.command.turnId, event);
23129
+ const subagent = active2.subagents.update(active2.command.turnId, event);
22904
23130
  if (subagent) {
22905
23131
  this.#event({
22906
23132
  type: "subagent.state.changed",
@@ -22913,7 +23139,7 @@ var OmpHarnessSession = class {
22913
23139
  return;
22914
23140
  case "subagent.completed":
22915
23141
  {
22916
- const subagent = active.subagents.complete(active.command.turnId, event, active.cancellationRequested);
23142
+ const subagent = active2.subagents.complete(active2.command.turnId, event, active2.cancellationRequested);
22917
23143
  this.#event({
22918
23144
  type: "subagent.state.changed",
22919
23145
  nativeSubagentId: subagent.nativeSubagentId ?? subagent.subagentId,
@@ -22929,8 +23155,8 @@ var OmpHarnessSession = class {
22929
23155
  });
22930
23156
  }
22931
23157
  }
22932
- #startInteraction(active, request) {
22933
- if (active.interactionByNativeId.has(request.requestId)) {
23158
+ #startInteraction(active2, request) {
23159
+ if (active2.interactionByNativeId.has(request.requestId)) {
22934
23160
  throw new Error("Omp Interaction started more than once");
22935
23161
  }
22936
23162
  const interactionId = hostInteractionIdSchema.parse(randomUUID2());
@@ -22939,7 +23165,7 @@ var OmpHarnessSession = class {
22939
23165
  interaction = {
22940
23166
  type: "approval",
22941
23167
  interactionId,
22942
- turnId: active.command.turnId,
23168
+ turnId: active2.command.turnId,
22943
23169
  title: request.title,
22944
23170
  subject: { type: "nativeAction" },
22945
23171
  actions: [
@@ -22982,49 +23208,49 @@ var OmpHarnessSession = class {
22982
23208
  ...request.method === "input" && request.placeholder ? { placeholder: request.placeholder } : {},
22983
23209
  ...request.method === "editor" && request.prefill ? { prefill: request.prefill } : {}
22984
23210
  };
22985
- const associatedTool = active.tools.size === 1 ? [...active.tools.values()][0] : void 0;
23211
+ const associatedTool = active2.tools.size === 1 ? [...active2.tools.values()][0] : void 0;
22986
23212
  interaction = {
22987
23213
  type: "question",
22988
23214
  interactionId,
22989
- turnId: active.command.turnId,
23215
+ turnId: active2.command.turnId,
22990
23216
  ...associatedTool ? { itemId: associatedTool.item.itemId } : {},
22991
23217
  title: "OMP",
22992
23218
  questions: [question],
22993
23219
  ...request.timeoutMs !== void 0 ? { expiresAt: new Date(Date.now() + request.timeoutMs).toISOString() } : {}
22994
23220
  };
22995
23221
  }
22996
- active.interactions.set(interactionId, { interaction, nativeRequest: request });
22997
- active.interactionByNativeId.set(request.requestId, interactionId);
23222
+ active2.interactions.set(interactionId, { interaction, nativeRequest: request });
23223
+ active2.interactionByNativeId.set(request.requestId, interactionId);
22998
23224
  this.#channel.emit({ kind: "interaction", interaction });
22999
23225
  }
23000
- #closeInteraction(active, nativeRequestId, reason) {
23001
- const interactionId = active.interactionByNativeId.get(nativeRequestId);
23226
+ #closeInteraction(active2, nativeRequestId, reason) {
23227
+ const interactionId = active2.interactionByNativeId.get(nativeRequestId);
23002
23228
  if (!interactionId)
23003
23229
  throw new Error("Omp Interaction close references an unknown request");
23004
- active.interactionByNativeId.delete(nativeRequestId);
23005
- active.interactions.delete(interactionId);
23230
+ active2.interactionByNativeId.delete(nativeRequestId);
23231
+ active2.interactions.delete(interactionId);
23006
23232
  this.#event({
23007
23233
  type: "interaction.closed",
23008
23234
  interactionId,
23009
- turnId: active.command.turnId,
23235
+ turnId: active2.command.turnId,
23010
23236
  reason
23011
23237
  });
23012
23238
  }
23013
- #startCompaction(active) {
23014
- if (active.compactionItem)
23239
+ #startCompaction(active2) {
23240
+ if (active2.compactionItem)
23015
23241
  throw new Error("Omp Compaction started more than once");
23016
23242
  const item = {
23017
23243
  type: "contextCompaction",
23018
23244
  itemId: this.#newItemId()
23019
23245
  };
23020
- active.compactionItem = item;
23021
- this.#event({ type: "item.started", turnId: active.command.turnId, item });
23246
+ active2.compactionItem = item;
23247
+ this.#event({ type: "item.started", turnId: active2.command.turnId, item });
23022
23248
  }
23023
- #completeCompaction(active, event) {
23024
- const item = active.compactionItem;
23249
+ #completeCompaction(active2, event) {
23250
+ const item = active2.compactionItem;
23025
23251
  if (!item)
23026
23252
  throw new Error("Omp Compaction completed without starting");
23027
- active.compactionItem = null;
23253
+ active2.compactionItem = null;
23028
23254
  const outcome = event.outcome === "succeeded" ? { status: "succeeded" } : event.outcome === "cancelled" ? { status: "cancelled", reason: "Context compaction was cancelled" } : {
23029
23255
  status: "failed",
23030
23256
  error: {
@@ -23033,87 +23259,87 @@ var OmpHarnessSession = class {
23033
23259
  retryable: true
23034
23260
  }
23035
23261
  };
23036
- this.#completeItem(active, item, outcome);
23262
+ this.#completeItem(active2, item, outcome);
23037
23263
  if (event.outcome === "succeeded")
23038
- void this.#refreshUsage(active.command.turnId);
23264
+ void this.#refreshUsage(active2.command.turnId);
23039
23265
  }
23040
- #activateAgentMessage(active, messageId) {
23041
- if (active.agentMessageId === messageId)
23266
+ #activateAgentMessage(active2, messageId) {
23267
+ if (active2.agentMessageId === messageId)
23042
23268
  return;
23043
- if (active.agentMessageId !== null) {
23044
- this.#completeReasoning(active, { status: "succeeded" });
23045
- this.#completeAgentItem(active, { status: "succeeded" }, false);
23269
+ if (active2.agentMessageId !== null) {
23270
+ this.#completeReasoning(active2, { status: "succeeded" });
23271
+ this.#completeAgentItem(active2, { status: "succeeded" }, false);
23046
23272
  }
23047
- if (!active.agentItem) {
23048
- active.agentItem = {
23273
+ if (!active2.agentItem) {
23274
+ active2.agentItem = {
23049
23275
  type: "agentMessage",
23050
23276
  itemId: this.#newItemId(),
23051
23277
  text: ""
23052
23278
  };
23053
23279
  this.#event({
23054
23280
  type: "item.started",
23055
- turnId: active.command.turnId,
23056
- item: active.agentItem
23281
+ turnId: active2.command.turnId,
23282
+ item: active2.agentItem
23057
23283
  });
23058
23284
  }
23059
- active.agentMessageId = messageId;
23060
- active.sawAssistantMessage = true;
23285
+ active2.agentMessageId = messageId;
23286
+ active2.sawAssistantMessage = true;
23061
23287
  }
23062
- #appendText(active, text) {
23063
- if (active.agentMessageId === null || !active.agentItem) {
23288
+ #appendText(active2, text) {
23289
+ if (active2.agentMessageId === null || !active2.agentItem) {
23064
23290
  throw new Error("Omp Assistant text arrived outside an active message");
23065
23291
  }
23066
- active.agentItem = { ...active.agentItem, text: active.agentItem.text + text };
23292
+ active2.agentItem = { ...active2.agentItem, text: active2.agentItem.text + text };
23067
23293
  this.#event({
23068
23294
  type: "item.updated",
23069
- turnId: active.command.turnId,
23070
- itemId: active.agentItem.itemId,
23295
+ turnId: active2.command.turnId,
23296
+ itemId: active2.agentItem.itemId,
23071
23297
  update: { type: "text.append", text }
23072
23298
  });
23073
23299
  }
23074
- #completeAgentItem(active, outcome, completeEmpty) {
23075
- active.agentMessageId = null;
23076
- const item = active.agentItem;
23300
+ #completeAgentItem(active2, outcome, completeEmpty) {
23301
+ active2.agentMessageId = null;
23302
+ const item = active2.agentItem;
23077
23303
  if (!item || !completeEmpty && item.text.length === 0)
23078
23304
  return;
23079
- active.agentItem = null;
23080
- this.#completeItem(active, item, outcome);
23305
+ active2.agentItem = null;
23306
+ this.#completeItem(active2, item, outcome);
23081
23307
  }
23082
- #appendReasoning(active, text) {
23308
+ #appendReasoning(active2, text) {
23083
23309
  if (text.length === 0)
23084
23310
  return;
23085
- if (!active.reasoningItem) {
23086
- active.reasoningItem = {
23311
+ if (!active2.reasoningItem) {
23312
+ active2.reasoningItem = {
23087
23313
  type: "reasoning",
23088
23314
  itemId: this.#newItemId(),
23089
23315
  text: ""
23090
23316
  };
23091
23317
  this.#event({
23092
23318
  type: "item.started",
23093
- turnId: active.command.turnId,
23094
- item: active.reasoningItem
23319
+ turnId: active2.command.turnId,
23320
+ item: active2.reasoningItem
23095
23321
  });
23096
23322
  }
23097
- active.reasoningItem = {
23098
- ...active.reasoningItem,
23099
- text: active.reasoningItem.text + text
23323
+ active2.reasoningItem = {
23324
+ ...active2.reasoningItem,
23325
+ text: active2.reasoningItem.text + text
23100
23326
  };
23101
23327
  this.#event({
23102
23328
  type: "item.updated",
23103
- turnId: active.command.turnId,
23104
- itemId: active.reasoningItem.itemId,
23329
+ turnId: active2.command.turnId,
23330
+ itemId: active2.reasoningItem.itemId,
23105
23331
  update: { type: "text.append", text }
23106
23332
  });
23107
23333
  }
23108
- #completeReasoning(active, outcome) {
23109
- const item = active.reasoningItem;
23334
+ #completeReasoning(active2, outcome) {
23335
+ const item = active2.reasoningItem;
23110
23336
  if (!item)
23111
23337
  return;
23112
- active.reasoningItem = null;
23113
- this.#completeItem(active, item, outcome);
23338
+ active2.reasoningItem = null;
23339
+ this.#completeItem(active2, item, outcome);
23114
23340
  }
23115
- #startTool(active, event) {
23116
- if (active.tools.has(event.callId))
23341
+ #startTool(active2, event) {
23342
+ if (active2.tools.has(event.callId))
23117
23343
  throw new Error("Omp Tool started more than once");
23118
23344
  const item = projectOmpToolItem({
23119
23345
  itemId: this.#newItemId(),
@@ -23121,16 +23347,16 @@ var OmpHarnessSession = class {
23121
23347
  arguments: event.arguments,
23122
23348
  cwd: stringField2(event.arguments, "cwd") ?? this.#cwd
23123
23349
  });
23124
- active.tools.set(event.callId, {
23350
+ active2.tools.set(event.callId, {
23125
23351
  item,
23126
23352
  nativeName: event.toolName,
23127
23353
  arguments: event.arguments,
23128
23354
  startedAtMs: Date.now()
23129
23355
  });
23130
- this.#event({ type: "item.started", turnId: active.command.turnId, item });
23356
+ this.#event({ type: "item.started", turnId: active2.command.turnId, item });
23131
23357
  }
23132
- #updateTool(active, event) {
23133
- const tool = active.tools.get(event.callId);
23358
+ #updateTool(active2, event) {
23359
+ const tool = active2.tools.get(event.callId);
23134
23360
  if (!tool)
23135
23361
  throw new Error("Omp Tool update references an unknown Tool Call");
23136
23362
  const output = boundedOutput(event.output, this.#toolOutputLimit);
@@ -23148,19 +23374,19 @@ var OmpHarnessSession = class {
23148
23374
  if (delta.length > 0) {
23149
23375
  this.#event({
23150
23376
  type: "item.updated",
23151
- turnId: active.command.turnId,
23377
+ turnId: active2.command.turnId,
23152
23378
  itemId: tool.item.itemId,
23153
23379
  update: { type: "output.append", text: delta }
23154
23380
  });
23155
23381
  }
23156
23382
  }
23157
23383
  }
23158
- #completeTool(active, event) {
23159
- const tool = active.tools.get(event.callId);
23384
+ #completeTool(active2, event) {
23385
+ const tool = active2.tools.get(event.callId);
23160
23386
  if (!tool || tool.nativeName !== event.toolName) {
23161
23387
  throw new Error("Omp Tool completion references an unknown Tool Call");
23162
23388
  }
23163
- active.tools.delete(event.callId);
23389
+ active2.tools.delete(event.callId);
23164
23390
  const durationMs = Math.max(0, Date.now() - tool.startedAtMs);
23165
23391
  const output = boundedOutput(event.result, this.#toolOutputLimit);
23166
23392
  const exitCode = numberField(event.result, "exitCode");
@@ -23173,8 +23399,8 @@ var OmpHarnessSession = class {
23173
23399
  ...exitCode !== void 0 ? { exitCode } : {},
23174
23400
  durationMs
23175
23401
  };
23176
- const outcome = active.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : event.isError ? { status: "failed", error: toolFailure(event.toolName) } : { status: "succeeded" };
23177
- this.#completeItem(active, tool.item, outcome);
23402
+ const outcome = active2.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : event.isError ? { status: "failed", error: toolFailure(event.toolName) } : { status: "succeeded" };
23403
+ this.#completeItem(active2, tool.item, outcome);
23178
23404
  if (!event.isError) {
23179
23405
  try {
23180
23406
  const kind = fileMutatingKind(event.toolName);
@@ -23190,30 +23416,30 @@ var OmpHarnessSession = class {
23190
23416
  sourceItemIds: [tool.item.itemId],
23191
23417
  changes
23192
23418
  };
23193
- this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
23194
- this.#completeItem(active, fileItem, { status: "succeeded" });
23419
+ this.#event({ type: "item.started", turnId: active2.command.turnId, item: fileItem });
23420
+ this.#completeItem(active2, fileItem, { status: "succeeded" });
23195
23421
  }
23196
23422
  } catch {
23197
23423
  }
23198
23424
  }
23199
23425
  }
23200
- #completeItem(active, item, outcome) {
23426
+ #completeItem(active2, item, outcome) {
23201
23427
  this.#event({
23202
23428
  type: "item.completed",
23203
- turnId: active.command.turnId,
23429
+ turnId: active2.command.turnId,
23204
23430
  snapshot: { item, outcome }
23205
23431
  });
23206
23432
  }
23207
- async #completedTurnIdentity(active, transport) {
23208
- active.acceptingSteers = false;
23209
- await Promise.allSettled([...active.pendingSteers]);
23210
- const history = active.steerFailure?.history ?? await transport.getEntries();
23433
+ async #completedTurnIdentity(active2, transport) {
23434
+ active2.acceptingSteers = false;
23435
+ await Promise.allSettled([...active2.pendingSteers]);
23436
+ const history = active2.steerFailure?.history ?? await transport.getEntries();
23211
23437
  const snapshot = mapOmpSnapshot(history, {
23212
23438
  sessionId: transport.state.sessionId,
23213
23439
  model: nativeModelForHistory(transport.state)
23214
23440
  });
23215
- const created = snapshot.turns.filter((turn2) => !active.beforeNativeTurnKeys.has(turn2.nativeTurnRef.nativeTurnKey));
23216
- const expected = 1 + active.acceptedSteerCount;
23441
+ const created = snapshot.turns.filter((turn2) => !active2.beforeNativeTurnKeys.has(turn2.nativeTurnRef.nativeTurnKey));
23442
+ const expected = 1 + active2.acceptedSteerCount;
23217
23443
  if (created.length !== expected) {
23218
23444
  const countText = expected === 1 ? "one" : `${expected}`;
23219
23445
  throw new Error(`Omp Turn persisted ${created.length} new User Entries; exactly ${countText} is required`);
@@ -23223,49 +23449,49 @@ var OmpHarnessSession = class {
23223
23449
  throw new Error("Omp Turn has no terminal Checkpoint identity");
23224
23450
  return { nativeTurnRef: turn.nativeTurnRef, checkpoint: turn.checkpoint };
23225
23451
  }
23226
- #completeTurn(active, outcome, finalText, nativeTurnRef, ephemeral) {
23227
- if (this.#active !== active)
23452
+ #completeTurn(active2, outcome, finalText, nativeTurnRef, ephemeral) {
23453
+ if (this.#active !== active2)
23228
23454
  return;
23229
23455
  this.#active = null;
23230
23456
  const itemOutcome2 = outcome.status === "failed" ? { status: "failed", error: outcome.error } : outcome.status === "cancelled" ? { status: "cancelled", ...outcome.reason ? { reason: outcome.reason } : {} } : { status: "succeeded" };
23231
- this.#completeReasoning(active, itemOutcome2);
23232
- if (active.compactionItem) {
23233
- this.#completeItem(active, active.compactionItem, itemOutcome2);
23234
- active.compactionItem = null;
23457
+ this.#completeReasoning(active2, itemOutcome2);
23458
+ if (active2.compactionItem) {
23459
+ this.#completeItem(active2, active2.compactionItem, itemOutcome2);
23460
+ active2.compactionItem = null;
23235
23461
  }
23236
- for (const interactionId of active.interactions.keys()) {
23462
+ for (const interactionId of active2.interactions.keys()) {
23237
23463
  this.#event({
23238
23464
  type: "interaction.closed",
23239
23465
  interactionId,
23240
- turnId: active.command.turnId,
23466
+ turnId: active2.command.turnId,
23241
23467
  reason: outcome.status === "cancelled" ? "cancelled" : "superseded"
23242
23468
  });
23243
23469
  }
23244
- active.interactions.clear();
23245
- active.interactionByNativeId.clear();
23246
- for (const tool of active.tools.values())
23247
- this.#completeItem(active, tool.item, itemOutcome2);
23248
- active.tools.clear();
23249
- active.subagents.finalize(active.command.turnId, itemOutcome2);
23250
- if (!active.sawAssistantMessage && finalText !== void 0 && active.agentItem) {
23251
- active.agentItem = { ...active.agentItem, text: finalText };
23470
+ active2.interactions.clear();
23471
+ active2.interactionByNativeId.clear();
23472
+ for (const tool of active2.tools.values())
23473
+ this.#completeItem(active2, tool.item, itemOutcome2);
23474
+ active2.tools.clear();
23475
+ active2.subagents.finalize(active2.command.turnId, itemOutcome2);
23476
+ if (!active2.sawAssistantMessage && finalText !== void 0 && active2.agentItem) {
23477
+ active2.agentItem = { ...active2.agentItem, text: finalText };
23252
23478
  }
23253
- this.#completeAgentItem(active, itemOutcome2, true);
23479
+ this.#completeAgentItem(active2, itemOutcome2, true);
23254
23480
  this.#event({
23255
23481
  type: "turn.completed",
23256
- turnId: active.command.turnId,
23482
+ turnId: active2.command.turnId,
23257
23483
  outcome,
23258
23484
  ...nativeTurnRef ? { nativeTurnRef } : {},
23259
23485
  ...ephemeral ? { ephemeral } : {}
23260
23486
  });
23261
- active.resolveCompletion();
23262
- if (active.steerFailure) {
23263
- this.#fault(active.steerFailure);
23487
+ active2.resolveCompletion();
23488
+ if (active2.steerFailure) {
23489
+ this.#fault(active2.steerFailure);
23264
23490
  return;
23265
23491
  }
23266
23492
  queueMicrotask(() => {
23267
23493
  if (this.#phase === "open")
23268
- void this.#refreshUsage(active.command.turnId);
23494
+ void this.#refreshUsage(active2.command.turnId);
23269
23495
  });
23270
23496
  }
23271
23497
  #fault(error51) {
@@ -23286,11 +23512,11 @@ var OmpHarnessSession = class {
23286
23512
  if (!wasFaulted)
23287
23513
  this.#phase = "closing";
23288
23514
  const transport = this.#transport ?? (this.#starting ? await this.#starting.catch(() => null) : null);
23289
- const active = this.#active;
23290
- if (transport && active) {
23291
- active.cancellationRequested = true;
23515
+ const active2 = this.#active;
23516
+ if (transport && active2) {
23517
+ active2.cancellationRequested = true;
23292
23518
  await transport.abort().catch(() => void 0);
23293
- await Promise.race([active.completion, delay(this.#closeTimeoutMs)]);
23519
+ await Promise.race([active2.completion, delay(this.#closeTimeoutMs)]);
23294
23520
  }
23295
23521
  try {
23296
23522
  if (transport)
@@ -23317,6 +23543,7 @@ var OmpHarnessSession = class {
23317
23543
  }
23318
23544
  };
23319
23545
  var OmpAdapter = class {
23546
+ normalizeStoredModelRef = normalizeStoredOmpModelRef;
23320
23547
  commandCatalog = ompCommandCatalog;
23321
23548
  liveCommandCatalog = true;
23322
23549
  harnessId = ompHarnessId2;
@@ -23400,16 +23627,25 @@ var OmpAdapter = class {
23400
23627
  if (this.#closePromise)
23401
23628
  return closedInspection();
23402
23629
  const cwd = input.cwd ?? process.cwd();
23630
+ if (input.refresh) {
23631
+ const catalog = input.purpose === "availability" ? void 0 : this.#inspectionInFlight.get(cwd);
23632
+ const availability = input.purpose === "availability" ? this.#availabilityInFlight.get(cwd) : void 0;
23633
+ this.#inspectionCache.clear();
23634
+ this.#inspectionInFlight.clear();
23635
+ this.#availabilityInFlight.clear();
23636
+ if (catalog)
23637
+ this.#inspectionInFlight.set(cwd, catalog);
23638
+ if (availability)
23639
+ this.#availabilityInFlight.set(cwd, availability);
23640
+ }
23403
23641
  const inFlight = this.#inspectionInFlight.get(cwd);
23404
23642
  if (inFlight)
23405
23643
  return inFlight;
23406
- if (!input.refresh) {
23407
- const cached2 = this.#inspectionCache.get(cwd);
23408
- if (cached2)
23409
- return cached2;
23410
- }
23644
+ const cached2 = this.#inspectionCache.get(cwd);
23645
+ if (cached2)
23646
+ return cached2;
23411
23647
  if (input.purpose === "availability")
23412
- return this.#inspectAvailability(cwd, input.refresh);
23648
+ return this.#inspectAvailability(cwd);
23413
23649
  return this.#startFullInspection(cwd);
23414
23650
  }
23415
23651
  /**
@@ -23419,9 +23655,7 @@ var OmpAdapter = class {
23419
23655
  * update `#thinkingSelectionSupported`. When the list cannot answer, a full inspection answers
23420
23656
  * instead, reusing one that is in flight or finished meanwhile.
23421
23657
  */
23422
- async #inspectAvailability(cwd, refresh = false) {
23423
- if (refresh)
23424
- this.#inspectionCache.delete(cwd);
23658
+ async #inspectAvailability(cwd) {
23425
23659
  let pending = this.#availabilityInFlight.get(cwd);
23426
23660
  if (!pending) {
23427
23661
  const listing = this.#listAvailability(cwd);
@@ -23440,8 +23674,10 @@ var OmpAdapter = class {
23440
23674
  }
23441
23675
  #startFullInspection(cwd) {
23442
23676
  const inspection = this.#inspectCwd(cwd).then((result) => {
23443
- if (result.status === "ready")
23677
+ if (result.status === "ready" && this.#inspectionInFlight.get(cwd) === inspection) {
23444
23678
  this.#inspectionCache.set(cwd, result);
23679
+ this.#thinkingSelectionSupported = result.capabilities.configuration.selectThinkingOption;
23680
+ }
23445
23681
  return result;
23446
23682
  });
23447
23683
  this.#inspectionInFlight.set(cwd, inspection);
@@ -23520,7 +23756,6 @@ var OmpAdapter = class {
23520
23756
  const models = await transport.getAvailableModels();
23521
23757
  stage = "capabilities";
23522
23758
  const thinkingLevels = await transport.getAvailableThinkingLevels();
23523
- this.#thinkingSelectionSupported = thinkingLevels !== null;
23524
23759
  const catalog = normalizeOmpModelCatalog(models, nativeModelFromState(transport.state), thinkingLevels, transport.state.thinkingLevel);
23525
23760
  await transport.close();
23526
23761
  return {
@@ -23573,10 +23808,12 @@ var OmpAdapter = class {
23573
23808
  return { ok: false, error: normalizedError(error51, "invalidRequest") };
23574
23809
  }
23575
23810
  if (input.model) {
23576
- try {
23577
- decodeOmpModelRef(input.model);
23578
- } catch (error51) {
23579
- return { ok: false, error: normalizedError(error51, "invalidRequest") };
23811
+ const parsed = harnessModelRefSchema.safeParse(input.model);
23812
+ if (!parsed.success || parsed.data.serviceTier) {
23813
+ return {
23814
+ ok: false,
23815
+ error: { code: "invalidRequest", message: "Invalid Omp Model Ref", retryable: false }
23816
+ };
23580
23817
  }
23581
23818
  }
23582
23819
  const thinkingOptionId = input.thinkingOptionId ? harnessThinkingOptionIdSchema.safeParse(input.thinkingOptionId) : null;
@@ -23693,6 +23930,7 @@ var OmpAdapter = class {
23693
23930
  usageHistory,
23694
23931
  ...input.environment ? { environment: input.environment } : {},
23695
23932
  startedTransport: transport,
23933
+ startedModels: await transport.getAvailableModels(),
23696
23934
  startedThinkingLevels,
23697
23935
  initialUsage,
23698
23936
  supportsThinkingSelection: startedThinkingLevels !== null,
@@ -23729,6 +23967,7 @@ var OmpAdapter = class {
23729
23967
  permissionMode: options.permissionMode,
23730
23968
  permissionModeId: options.permissionModeId,
23731
23969
  ...options.startedTransport ? { startedTransport: options.startedTransport } : {},
23970
+ ...options.startedModels ? { startedModels: options.startedModels } : {},
23732
23971
  ...options.startedThinkingLevels !== void 0 ? { startedThinkingLevels: options.startedThinkingLevels } : {},
23733
23972
  ...options.initialUsage !== void 0 ? { initialUsage: options.initialUsage } : {},
23734
23973
  ...options.usageHistory ? { usageHistory: options.usageHistory } : {}