@codexhost/cli-darwin-x64 0.22.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 (59) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +3117 -274
  4. package/app/console-web.js +15645 -4413
  5. package/app/desktop-controller.mjs +14057 -969
  6. package/app/host-runtime.mjs +11518 -8277
  7. package/app/plugins/antigravity/plugin.mjs +2030 -678
  8. package/app/plugins/claude-code/plugin.mjs +2116 -929
  9. package/app/plugins/codebuddy/plugin.mjs +1247 -353
  10. package/app/plugins/codex-usage/plugin.mjs +786 -163
  11. package/app/plugins/copilot/plugin.mjs +938 -296
  12. package/app/plugins/cursor-cli/plugin.mjs +1021 -232
  13. package/app/plugins/deepseek-harness/plugin.mjs +1552 -664
  14. package/app/plugins/devin/plugin.mjs +826 -185
  15. package/app/plugins/grok/plugin.mjs +1083 -424
  16. package/app/plugins/hermes/plugin.mjs +961 -338
  17. package/app/plugins/kimi-code/plugin.mjs +854 -237
  18. package/app/plugins/kiro-cli/plugin.mjs +821 -184
  19. package/app/plugins/omp/plugin.mjs +1316 -633
  20. package/app/plugins/opencode/plugin.mjs +1293 -606
  21. package/app/plugins/pi/plugin.mjs +1540 -867
  22. package/app/plugins/qoder/plugin.mjs +961 -332
  23. package/app/plugins/qoder-cn/plugin.mjs +961 -332
  24. package/app/plugins/qwen-code/plugin.mjs +937 -321
  25. package/app/plugins/workbuddy/plugin.mjs +1311 -370
  26. package/app/plugins/zcode/plugin.mjs +1516 -423
  27. package/app/renderer-extension.js +21297 -9060
  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 +6753 -31616
  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 +14 -14
  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 +94 -91
  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-browser/client.js +1 -1
  44. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  45. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-right/client.js +1 -1
  46. package/app/web/plugins/deepseek-ai__dsh-client-ui-theme/client.js +1 -1
  47. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +79 -79
  48. package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +3 -3
  49. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +7 -7
  50. package/app/web/sw.js +8 -1
  51. package/app/web-modules/licenses/werift-NOTICES.txt +123 -0
  52. package/app/web-modules/licenses/werift-libwebrtc-NOTICES.txt +58 -0
  53. package/app/web-modules/server.mjs +40416 -11283
  54. package/bin/codexhost +0 -0
  55. package/libexec/codexhost-shim +0 -0
  56. package/libexec/codexhost-updater +0 -0
  57. package/package.json +1 -1
  58. package/app/web/assets/index-CN4a4sj0.js +0 -201
  59. package/app/web/assets/index-DJW4bmyx.css +0 -1
@@ -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,
@@ -15055,6 +15055,9 @@ var threadPermissionModeSelectParamsSchema = external_exports.object({
15055
15055
  permissionModeId: harnessPermissionModeIdSchema
15056
15056
  }).strict();
15057
15057
 
15058
+ // ../../shared-contracts/dist/harness-route-limit.js
15059
+ var HARNESS_TRANSPORT_MODEL_ID_MAX_LENGTH = 8192;
15060
+
15058
15061
  // ../../shared-contracts/dist/thread-usage.js
15059
15062
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
15060
15063
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
@@ -15087,7 +15090,7 @@ var composerIndicatorsSchema = external_exports.array(external_exports.object({
15087
15090
  expiresAtUnix: nonNegativeSafeIntegerSchema,
15088
15091
  label: indicatorTextSchema(256).optional(),
15089
15092
  tooltip: indicatorTextSchema(1024).optional()
15090
- }).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, {
15091
15094
  message: "Composer indicator IDs must be unique"
15092
15095
  });
15093
15096
  var threadUsageSnapshotSchema = external_exports.object({
@@ -15113,6 +15116,7 @@ var threadUsageSnapshotSchema = external_exports.object({
15113
15116
  planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
15114
15117
  sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
15115
15118
  timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
15119
+ latestRequestTimeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
15116
15120
  costSource: external_exports.enum(["publicPrice", "native"]).optional(),
15117
15121
  unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
15118
15122
  }).strict().superRefine((usage, context) => {
@@ -15210,6 +15214,13 @@ var accountCreditsSnapshotSchema = external_exports.object({
15210
15214
  productUsage: external_exports.array(accountCreditsProductUsageSchema).min(1).optional(),
15211
15215
  resetCredits: accountResetCreditsSchema.optional()
15212
15216
  }).strict();
15217
+ var accountBalanceSnapshotSchema = external_exports.object({
15218
+ amount: external_exports.number().finite().nonnegative(),
15219
+ /** ISO 4217 code as reported by the Provider, for example `CNY`. */
15220
+ currency: external_exports.string().trim().min(1).max(8),
15221
+ /** Native label when the Harness exposes several Billing Sources. */
15222
+ label: external_exports.string().trim().min(1).max(128).optional()
15223
+ }).strict();
15213
15224
  var threadUsageInspectionParamsSchema = external_exports.object({
15214
15225
  threadId: hostThreadIdSchema,
15215
15226
  refresh: external_exports.literal("exact").optional()
@@ -15218,7 +15229,10 @@ var threadUsageInspectionSchema = external_exports.object({
15218
15229
  threadId: hostThreadIdSchema,
15219
15230
  usage: threadUsageSnapshotSchema.nullable(),
15220
15231
  accountCredits: accountCreditsSnapshotSchema.optional(),
15221
- /** Whether this source can provide cached account quota independently of usage. */
15232
+ /** Prepaid funds for the Thread's Billing Source; shown only when no percentage quota exists. */
15233
+ accountBalance: accountBalanceSnapshotSchema.optional(),
15234
+ /** Whether this source can provide cached account quota (credits or a prepaid balance)
15235
+ * independently of usage. */
15222
15236
  accountCreditsSupported: external_exports.boolean().optional()
15223
15237
  }).strict();
15224
15238
 
@@ -15230,10 +15244,15 @@ var THREAD_OWNERSHIP_LIST_MAX_LENGTH = 100;
15230
15244
  var nonBlankTextSchema2 = external_exports.string().refine((value) => value.trim().length > 0, {
15231
15245
  message: "Value must not be empty or whitespace"
15232
15246
  });
15233
- 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"]);
15234
15249
  var harnessModelRefSchema = external_exports.object({
15235
- id: harnessModelRefIdSchema
15250
+ id: harnessModelRefIdSchema,
15251
+ serviceTier: harnessModelServiceTierSchema.optional()
15236
15252
  }).strict();
15253
+ function sameHarnessModelRef(left, right) {
15254
+ return left?.id === right?.id && left?.serviceTier === right?.serviceTier;
15255
+ }
15237
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();
15238
15257
  var harnessResolvedModelLabelSchema = nonBlankTextSchema2.max(HARNESS_MODEL_LABEL_MAX_LENGTH);
15239
15258
  var harnessThinkingOptionSchema = external_exports.object({
@@ -15247,7 +15266,15 @@ var harnessModelSchema = external_exports.object({
15247
15266
  /** Optional opaque selection for this same Model with priority processing enabled. */
15248
15267
  fastModel: harnessModelRefSchema.optional(),
15249
15268
  supportedThinkingOptionIds: external_exports.array(harnessThinkingOptionIdSchema).optional()
15250
- }).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
+ }
15251
15278
  var harnessThinkingOptionsSchema = external_exports.array(harnessThinkingOptionSchema).superRefine((options, context) => {
15252
15279
  const ids = /* @__PURE__ */ new Set();
15253
15280
  for (const [index, option] of options.entries()) {
@@ -15267,26 +15294,26 @@ var harnessModelCatalogSchema = external_exports.object({
15267
15294
  thinkingOptions: harnessThinkingOptionsSchema,
15268
15295
  defaultThinkingOptionId: harnessThinkingOptionIdSchema.optional()
15269
15296
  }).strict().superRefine((catalog, context) => {
15270
- const refs = /* @__PURE__ */ new Set();
15271
- const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
15297
+ const refs = [];
15298
+ const thinkingIds = new Set(catalog.thinkingOptions.map(({ id: id2 }) => id2));
15272
15299
  for (const [index, model2] of catalog.models.entries()) {
15273
- if (refs.has(model2.ref.id)) {
15300
+ if (refs.some((ref) => sameHarnessModelRef(ref, model2.ref))) {
15274
15301
  context.addIssue({
15275
15302
  code: "custom",
15276
15303
  message: "Model Catalog refs must be unique",
15277
15304
  path: ["models", index, "ref", "id"]
15278
15305
  });
15279
15306
  }
15280
- refs.add(model2.ref.id);
15307
+ refs.push(model2.ref);
15281
15308
  if (model2.fastModel) {
15282
- 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))) {
15283
15310
  context.addIssue({
15284
15311
  code: "custom",
15285
15312
  message: "Fast Model refs must be distinct and unique",
15286
15313
  path: ["models", index, "fastModel"]
15287
15314
  });
15288
15315
  }
15289
- refs.add(model2.fastModel.id);
15316
+ refs.push(model2.fastModel);
15290
15317
  }
15291
15318
  const supportedThinkingIds = /* @__PURE__ */ new Set();
15292
15319
  for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
@@ -15307,7 +15334,7 @@ var harnessModelCatalogSchema = external_exports.object({
15307
15334
  }
15308
15335
  }
15309
15336
  }
15310
- if (catalog.defaultModel && !refs.has(catalog.defaultModel.id)) {
15337
+ if (catalog.defaultModel && !catalogModelForRef(catalog, catalog.defaultModel)) {
15311
15338
  context.addIssue({
15312
15339
  code: "custom",
15313
15340
  message: "Default Model must exist in the Model Catalog",
@@ -15347,7 +15374,12 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
15347
15374
  observe: external_exports.boolean()
15348
15375
  }).strict().optional(),
15349
15376
  /** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
15350
- 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()
15351
15383
  }).strict();
15352
15384
  var harnessConfigurationStateSchema = external_exports.object({
15353
15385
  effectiveModel: harnessModelRefSchema.optional(),
@@ -15356,7 +15388,7 @@ var harnessConfigurationStateSchema = external_exports.object({
15356
15388
  availableThinkingOptions: harnessThinkingOptionsSchema.optional(),
15357
15389
  effectivePermissionModeId: harnessPermissionModeIdSchema.optional()
15358
15390
  }).strict().superRefine((state, context) => {
15359
- 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)) {
15360
15392
  context.addIssue({
15361
15393
  code: "custom",
15362
15394
  message: "Effective Thinking option must be currently available",
@@ -15396,7 +15428,8 @@ var harnessInspectParamsSchema = external_exports.object({
15396
15428
  cwd: nonBlankTextSchema2.max(16384).optional(),
15397
15429
  refresh: external_exports.boolean().optional(),
15398
15430
  /** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
15399
- purpose: external_exports.literal("availability").optional()
15431
+ purpose: external_exports.literal("availability").optional(),
15432
+ credentialAccess: external_exports.enum(["allow", "retry"]).optional()
15400
15433
  }).strict();
15401
15434
  var harnessWebUiOpenParamsSchema = external_exports.object({
15402
15435
  harnessId: harnessIdSchema
@@ -15427,7 +15460,7 @@ var codexThreadInspectionSchema = external_exports.object({
15427
15460
  var externalThreadInspectionSchema = external_exports.object({
15428
15461
  owner: external_exports.literal("external"),
15429
15462
  harnessId: nonBlankTextSchema2.max(256),
15430
- transportModelId: nonBlankTextSchema2.max(1024),
15463
+ transportModelId: nonBlankTextSchema2.max(HARNESS_TRANSPORT_MODEL_ID_MAX_LENGTH),
15431
15464
  effectiveModel: harnessModelRefSchema.optional(),
15432
15465
  resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15433
15466
  effectiveThinkingOptionId: harnessThinkingOptionIdSchema.optional(),
@@ -15509,13 +15542,635 @@ var threadSteeringInspectResultSchema = external_exports.object({
15509
15542
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
15510
15543
  }).strict();
15511
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()
15777
+ });
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 })
15942
+ ]);
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") })
15948
+ ]);
15949
+ var hostExtensionInstallationSchema = external_exports.strictObject({
15950
+ ...active,
15951
+ manifest: hostExtensionManifestV2Schema,
15952
+ installedAt: external_exports.iso.datetime(),
15953
+ source: hostExtensionProvenanceSchema.optional()
15954
+ });
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
+ })
15974
+ ]);
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
16029
+ });
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
+ };
16089
+
15512
16090
  // ../../shared-contracts/dist/thread-archive-confirm.js
16091
+ var THREAD_ARCHIVE_CONFIRM_METHOD = "codexhost/thread/archive/confirm";
15513
16092
  var threadArchiveConfirmParamsSchema = external_exports.object({ threadId: hostThreadIdSchema }).strict();
15514
16093
  var threadArchiveConfirmResultSchema = external_exports.object({ confirmed: external_exports.boolean() }).strict();
15515
16094
 
15516
16095
  // ../../shared-contracts/dist/client-channel.js
15517
16096
  var CLIENT_CHANNEL_VERSION = 1;
15518
16097
  var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
16098
+ var CLIENT_CHANNEL_METHODS = [
16099
+ "codexhost/skills/list",
16100
+ "codexhost/voice/status",
16101
+ "codexhost/voice/transcribe",
16102
+ "codexhost/harness/display-settings/get",
16103
+ "codexhost/harness/display-settings/set",
16104
+ "codexhost/harness/display-settings/capabilities",
16105
+ "codexhost/harness/preferences/get",
16106
+ "codexhost/harness/preferences/patch",
16107
+ "thread/list",
16108
+ "codexhost/thread/catalog/read",
16109
+ "thread/read",
16110
+ "thread/resume",
16111
+ "thread/fork",
16112
+ "thread/turns/list",
16113
+ "thread/revert",
16114
+ "thread/items/list",
16115
+ "thread/start",
16116
+ "thread/name/set",
16117
+ "codexhost/thread/title/generate",
16118
+ "thread/archive",
16119
+ THREAD_ARCHIVE_CONFIRM_METHOD,
16120
+ "thread/unarchive",
16121
+ "turn/start",
16122
+ "turn/interrupt",
16123
+ "turn/steer",
16124
+ "thread/queue/list",
16125
+ "thread/queue/add",
16126
+ "thread/queue/update",
16127
+ "thread/queue/delete",
16128
+ "thread/queue/reorder",
16129
+ "thread/queue/start",
16130
+ "codexhost/thread/queue/send-now",
16131
+ "codexhost/workspace/read",
16132
+ "codexhost/thread/tree/read",
16133
+ "codexhost/thread/pins/list",
16134
+ "codexhost/thread/pins/set",
16135
+ "codexhost/harness/plugins/list",
16136
+ "codexhost/harness/inspect",
16137
+ "codexhost/thread/inspect",
16138
+ "codexhost/thread/usage/inspect",
16139
+ "codexhost/thread/ownership/list",
16140
+ "codexhost/thread/model/select",
16141
+ "codexhost/thread/thinking/select",
16142
+ "codexhost/thread/permission-mode/select",
16143
+ "codexhost/thread/commands/inspect",
16144
+ "codexhost/harness/commands/inspect",
16145
+ "codexhost/thread/command/execute",
16146
+ "codexhost/thread/fork",
16147
+ "codexhost/harness/session-import/sources",
16148
+ "codexhost/harness/session-import/list",
16149
+ "codexhost/harness/session-import/import",
16150
+ // Host settings shared across Desktop and Web.
16151
+ ...HOST_EXTENSION_MANAGEMENT_METHODS,
16152
+ "codexhost/harness/installation",
16153
+ "codexhost/harness/installation/start",
16154
+ "codexhost/harness/installation/status",
16155
+ "codexhost/harness/launch-settings/get",
16156
+ "codexhost/harness/launch-settings/set",
16157
+ "codexhost/harness/web-ui/open",
16158
+ "codexhost/harness/accounts/sources",
16159
+ "codexhost/harness/accounts/list",
16160
+ "codexhost/harness/accounts/inspect",
16161
+ "codexhost/harness/credential-imports",
16162
+ "codexhost/account/list",
16163
+ "codexhost/account/refresh",
16164
+ "codexhost/account/usage/inspect",
16165
+ "codexhost/usage/model-prices/get",
16166
+ "codexhost/usage/model-prices/set",
16167
+ "codexhost/usage/model-prices/default",
16168
+ "codexhost/usage/statistics/get",
16169
+ "codexhost/update/check",
16170
+ "codexhost/update/start",
16171
+ "codexhost/update/status",
16172
+ "codexhost/sessions/loaded/list"
16173
+ ];
15519
16174
  var clientThreadPinsSchema = external_exports.object({ threadIds: external_exports.array(external_exports.string().min(1)) }).strict();
15520
16175
  var clientThreadPinParamsSchema = external_exports.object({ threadId: external_exports.string().min(1).max(1024), pinned: external_exports.boolean() }).strict();
15521
16176
  var clientThreadTreeReadParamsSchema = external_exports.object({}).strict();
@@ -15554,6 +16209,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
15554
16209
  cursor: clientChannelCursorSchema,
15555
16210
  revision: external_exports.number().int().nonnegative()
15556
16211
  }),
16212
+ external_exports.object({
16213
+ type: external_exports.literal("extensions-changed"),
16214
+ cursor: clientChannelCursorSchema,
16215
+ revision: hostExtensionRevisionSchema
16216
+ }),
15557
16217
  external_exports.object({
15558
16218
  type: external_exports.literal("hello"),
15559
16219
  version: external_exports.literal(1),
@@ -15729,6 +16389,29 @@ var threadCatalogReadResultSchema = external_exports.object({
15729
16389
  officialCursor: external_exports.object({ live: external_exports.string().nullable(), archived: external_exports.string().nullable().optional() }).strict().optional()
15730
16390
  }).strict();
15731
16391
 
16392
+ // ../../shared-contracts/dist/thread-tree-watch.js
16393
+ var THREAD_TREE_MAX_NODES = 5e3;
16394
+ var threadTreeStatusSchema = external_exports.enum(["running", "waiting", "idle", "unknown"]);
16395
+ var threadTreeNodeSchema = external_exports.strictObject({
16396
+ harnessId: harnessIdSchema,
16397
+ title: external_exports.string().optional(),
16398
+ status: threadTreeStatusSchema,
16399
+ archived: external_exports.boolean()
16400
+ });
16401
+ var threadTreeSnapshotSchema = external_exports.strictObject({
16402
+ revision: external_exports.int().nonnegative(),
16403
+ parents: external_exports.record(hostThreadIdSchema, hostThreadIdSchema),
16404
+ nodes: external_exports.record(hostThreadIdSchema, threadTreeNodeSchema),
16405
+ truncated: external_exports.boolean()
16406
+ }).refine((snapshot) => Object.keys(snapshot.nodes).length <= THREAD_TREE_MAX_NODES, "Too many Thread tree nodes").refine(({ parents, nodes }) => Object.entries(parents).every(([child, parent]) => Object.hasOwn(nodes, child) && Object.hasOwn(nodes, parent)), "Missing Thread tree node");
16407
+ var subscriptionId = external_exports.string().min(1).max(128);
16408
+ var threadTreeWatchParamsSchema = external_exports.strictObject({});
16409
+ var threadTreeUnwatchParamsSchema = external_exports.strictObject({ subscriptionId });
16410
+ var threadTreeUnwatchResultSchema = external_exports.strictObject({});
16411
+ var threadTreeWatchResultSchema = threadTreeUnwatchParamsSchema.extend({
16412
+ snapshot: threadTreeSnapshotSchema
16413
+ });
16414
+
15732
16415
  // ../../shared-contracts/dist/voice.js
15733
16416
  var VOICE_AUDIO_MAX_BYTES = 10 * 1024 * 1024;
15734
16417
  var voiceAudioMimeTypeSchema = external_exports.string().regex(/^audio\/[a-z0-9.+-]+(?:\s*;[^\r\n]*)?$/i);
@@ -15967,7 +16650,7 @@ var DEFAULT_IDLE_RELEASE_SETTINGS = Object.freeze({
15967
16650
 
15968
16651
  // ../../shared-contracts/dist/harness-preferences.js
15969
16652
  var harnessPreferenceScopeSchema = external_exports.string().regex(/^external$/u);
15970
- var preferenceHarnessKey = harnessIdSchema.transform((id) => String(id));
16653
+ var preferenceHarnessKey = harnessIdSchema.transform((id2) => String(id2));
15971
16654
  var harnessDefaultConfigurationSchema = external_exports.strictObject({
15972
16655
  model: harnessModelRefSchema.optional(),
15973
16656
  thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
@@ -15977,11 +16660,19 @@ var newThreadDefaultsSchema = external_exports.strictObject({
15977
16660
  lastHarness: harnessIdSchema.optional(),
15978
16661
  byHarness: external_exports.record(preferenceHarnessKey, harnessDefaultConfigurationSchema)
15979
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
+ });
15980
16670
  var modelId = external_exports.string().min(1).max(1024);
15981
16671
  var harnessPreferenceValuesSchema = external_exports.strictObject({
15982
16672
  idleRelease: idleReleaseSettingsSchema.optional(),
15983
16673
  favorites: external_exports.record(preferenceHarnessKey, external_exports.array(modelId).max(2048)).default({}),
15984
- newThread: newThreadDefaultsSchema.optional()
16674
+ newThread: newThreadDefaultsSchema.optional(),
16675
+ delegation: delegationDefaultsSchema.optional()
15985
16676
  });
15986
16677
  var harnessPreferenceSnapshotSchema = external_exports.strictObject({
15987
16678
  scope: harnessPreferenceScopeSchema,
@@ -16009,6 +16700,11 @@ var harnessPreferenceOperationSchema = external_exports.discriminatedUnion("kind
16009
16700
  lastHarness: harnessIdSchema.optional(),
16010
16701
  harnessId: harnessIdSchema.optional(),
16011
16702
  configuration: harnessDefaultConfigurationSchema.optional()
16703
+ }),
16704
+ external_exports.strictObject({
16705
+ kind: external_exports.literal("delegation"),
16706
+ harnessId: harnessIdSchema,
16707
+ configuration: harnessDelegationDefaultSchema.nullable()
16012
16708
  })
16013
16709
  ]);
16014
16710
  var harnessPreferencePatchSchema = external_exports.strictObject({
@@ -16359,13 +17055,6 @@ var threadManualCompactionStartedSchema = external_exports.strictObject({
16359
17055
  });
16360
17056
 
16361
17057
  // ../../shared-contracts/dist/harness-accounts.js
16362
- var accountBalanceSnapshotSchema = external_exports.object({
16363
- amount: external_exports.number().finite().nonnegative(),
16364
- /** ISO 4217 code as reported by the Provider, for example `CNY`. */
16365
- currency: external_exports.string().trim().min(1).max(8),
16366
- /** Native label when the Harness exposes several Billing Sources. */
16367
- label: external_exports.string().trim().min(1).max(128).optional()
16368
- }).strict();
16369
17058
  var harnessAccountSnapshotObject = external_exports.object({
16370
17059
  email: external_exports.string().trim().min(1).max(320).optional(),
16371
17060
  label: external_exports.string().trim().min(1).max(256).optional(),
@@ -16399,76 +17088,6 @@ var harnessAccountListResultSchema = external_exports.object({
16399
17088
  accounts: external_exports.array(requireReportedQuota(harnessAccountSnapshotObject.extend(harnessAccountIdentityShape))).max(128)
16400
17089
  }).strict();
16401
17090
 
16402
- // ../../shared-contracts/dist/harness-plugins.js
16403
- var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
16404
- var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
16405
- var HARNESS_PLUGIN_LIMIT = 128;
16406
- var installedHarnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).pipe(harnessIdSchema);
16407
- var harnessPluginIdSchema = installedHarnessPluginIdSchema.refine((id) => id !== "codex", "The official Codex identity is reserved");
16408
- var relativeResourceSchema = 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");
16409
- var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
16410
- var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
16411
- var harnessInstallationGuideSchema = external_exports.object({
16412
- commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
16413
- before: localizedTextSchema.optional(),
16414
- after: localizedTextSchema.optional(),
16415
- downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
16416
- }).strict();
16417
- var pluginPresentationShape = {
16418
- id: installedHarnessPluginIdSchema,
16419
- name: external_exports.string().trim().min(1).max(128),
16420
- version: external_exports.string().min(1).max(128),
16421
- /** Capability-only plugin; omitted for existing session-capable plugins. */
16422
- kind: external_exports.literal("usage").optional(),
16423
- /** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
16424
- iconStyle: external_exports.object({
16425
- vector: external_exports.object({
16426
- viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
16427
- color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
16428
- paths: external_exports.array(external_exports.object({
16429
- d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
16430
- fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
16431
- fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
16432
- }).strict()).min(1).max(32)
16433
- }).strict().optional(),
16434
- background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
16435
- borderRadius: external_exports.number().min(0).max(50).optional(),
16436
- paddingRatio: external_exports.number().min(0).max(0.25).optional()
16437
- }).strict().optional(),
16438
- installation: harnessInstallationGuideSchema.optional(),
16439
- notice: localizedTextSchema.optional(),
16440
- /** The factory accepts a persisted local entrypoint through its construction context. */
16441
- launchCommand: external_exports.literal(true).optional(),
16442
- links: external_exports.object({
16443
- website: documentationUrlSchema.optional(),
16444
- documentation: documentationUrlSchema.optional(),
16445
- installation: documentationUrlSchema.optional()
16446
- }).strict().optional()
16447
- };
16448
- var harnessPluginManifestSchema = external_exports.object({
16449
- manifestVersion: external_exports.literal(1),
16450
- ...pluginPresentationShape,
16451
- adapterApiVersion: external_exports.number().int().positive(),
16452
- entry: relativeResourceSchema,
16453
- icon: relativeResourceSchema.optional()
16454
- }).strict();
16455
- 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);
16456
- var harnessPluginDescriptorSchema = external_exports.object({
16457
- ...pluginPresentationShape,
16458
- icon: harnessPluginIconSchema.optional()
16459
- }).strict();
16460
- var harnessPluginListParamsSchema = external_exports.object({}).strict();
16461
- var harnessPluginListResultSchema = external_exports.object({
16462
- plugins: external_exports.array(harnessPluginDescriptorSchema.extend({ id: harnessPluginIdSchema })).max(HARNESS_PLUGIN_LIMIT)
16463
- }).strict();
16464
- var harnessPluginConfigurationSchema = external_exports.object({
16465
- version: external_exports.literal(1),
16466
- enabled: external_exports.array(installedHarnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
16467
- }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
16468
- message: "Enabled plugin IDs must be unique",
16469
- path: ["enabled"]
16470
- });
16471
-
16472
17091
  // ../../shared-contracts/dist/harness-route.js
16473
17092
  var harnessPluginRouteSchema = external_exports.object({
16474
17093
  harnessId: harnessPluginIdSchema,
@@ -16909,9 +17528,12 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
16909
17528
  ...thread,
16910
17529
  epoch: identity,
16911
17530
  modelId: identity.optional(),
17531
+ serviceTier: harnessModelServiceTierSchema.optional(),
16912
17532
  thinkingOptionId: identity.optional(),
16913
17533
  permissionModeId: identity.optional()
16914
- }).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
+ }),
16915
17537
  external_exports.strictObject({
16916
17538
  kind: external_exports.literal("prompt"),
16917
17539
  ...thread,
@@ -16961,7 +17583,7 @@ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action
16961
17583
  external_exports.strictObject({ action: external_exports.literal("catalog") }),
16962
17584
  external_exports.strictObject({
16963
17585
  action: external_exports.literal("read-thread"),
16964
- hostId: hostId.refine((id) => id !== "local"),
17586
+ hostId: hostId.refine((id2) => id2 !== "local"),
16965
17587
  input: delegationReadParamsSchema
16966
17588
  }),
16967
17589
  external_exports.strictObject({
@@ -16975,7 +17597,7 @@ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action
16975
17597
  external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
16976
17598
  external_exports.strictObject({
16977
17599
  action: external_exports.literal("update"),
16978
- hostId: hostId.refine((id) => id !== "local"),
17600
+ hostId: hostId.refine((id2) => id2 !== "local"),
16979
17601
  version: remoteUpdateParamsSchema.shape.version
16980
17602
  })
16981
17603
  ]);
@@ -17039,7 +17661,7 @@ function invalidRequest(message3) {
17039
17661
  return { code: "invalidRequest", message: message3, retryable: false };
17040
17662
  }
17041
17663
  function validateHostApprovalResponse(interaction, response) {
17042
- 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");
17043
17665
  }
17044
17666
 
17045
17667
  // ../../harness-adapter/dist/question.js
@@ -17047,7 +17669,7 @@ function invalidRequest2(message3) {
17047
17669
  return { code: "invalidRequest", message: message3, retryable: false };
17048
17670
  }
17049
17671
  function validateHostQuestionResponse(interaction, response) {
17050
- const questionIds = new Set(interaction.questions.map(({ id }) => id));
17672
+ const questionIds = new Set(interaction.questions.map(({ id: id2 }) => id2));
17051
17673
  if (response.cancelled) {
17052
17674
  return Object.keys(response.answers).length === 0 ? null : invalidRequest2("Cancelled Question Response must not contain answers");
17053
17675
  }
@@ -17078,6 +17700,21 @@ function validateHostQuestionResponse(interaction, response) {
17078
17700
  return null;
17079
17701
  }
17080
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
+
17081
17718
  // ../../harness-adapter/dist/output-channel.js
17082
17719
  var HarnessOutputChannel = class {
17083
17720
  outputs;
@@ -17150,7 +17787,8 @@ var tokenFields = [
17150
17787
  var safeIntegerFields = [
17151
17788
  "planFiveHourResetsAtUnix",
17152
17789
  "planSevenDayResetsAtUnix",
17153
- "timeToFirstOutputMs"
17790
+ "timeToFirstOutputMs",
17791
+ "latestRequestTimeToFirstOutputMs"
17154
17792
  ];
17155
17793
  var percentFields = [
17156
17794
  "cacheHitRatePercent",
@@ -17413,7 +18051,7 @@ function isExcludedLiveCommand(name, extra = {}) {
17413
18051
  function liveHarnessCommandPrompt(catalog, idPrefix, commandId, argumentText) {
17414
18052
  if (!commandId.startsWith(idPrefix))
17415
18053
  return null;
17416
- const descriptor = catalog.commands.find(({ id }) => id === commandId);
18054
+ const descriptor = catalog.commands.find(({ id: id2 }) => id2 === commandId);
17417
18055
  if (!descriptor)
17418
18056
  return null;
17419
18057
  const text = typeof argumentText === "string" ? argumentText.trim() : "";
@@ -17423,7 +18061,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17423
18061
  if (!live)
17424
18062
  return builtIns;
17425
18063
  const invocations = new Set(builtIns.commands.map(({ invocation }) => invocation));
17426
- const ids = new Set(builtIns.commands.map(({ id }) => id));
18064
+ const ids = new Set(builtIns.commands.map(({ id: id2 }) => id2));
17427
18065
  const dynamic = [];
17428
18066
  for (const command of live) {
17429
18067
  const name = command.name.trim().replace(/^\//u, "");
@@ -17432,12 +18070,12 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17432
18070
  if (isExcludedLiveCommand(name, exclusions))
17433
18071
  continue;
17434
18072
  const invocation = `/${name}`;
17435
- const id = `${idPrefix}${name.replace(/[^A-Za-z0-9._:-]/gu, "-")}`.slice(0, 128);
17436
- 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))
17437
18075
  continue;
17438
18076
  const description = command.description?.trim().slice(0, 512);
17439
18077
  const parsed = harnessCommandDescriptorSchema.safeParse({
17440
- id,
18078
+ id: id2,
17441
18079
  invocation,
17442
18080
  label: name.slice(0, 128),
17443
18081
  ...description ? { description } : {},
@@ -17446,7 +18084,7 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17446
18084
  if (!parsed.success)
17447
18085
  continue;
17448
18086
  invocations.add(invocation);
17449
- ids.add(id);
18087
+ ids.add(id2);
17450
18088
  dynamic.push(parsed.data);
17451
18089
  }
17452
18090
  return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
@@ -17976,7 +18614,7 @@ var OMP_DRAFT_THINKING_OPTION_IDS = [
17976
18614
  "high",
17977
18615
  "xhigh",
17978
18616
  "max"
17979
- ].map((id) => harnessThinkingOptionIdSchema.parse(id));
18617
+ ].map((id2) => harnessThinkingOptionIdSchema.parse(id2));
17980
18618
  var OMP_THINKING_LABELS = {
17981
18619
  off: "Off",
17982
18620
  minimal: "Minimal",
@@ -17993,52 +18631,76 @@ function assertNativePart(value, name) {
17993
18631
  if (value.trim().length === 0)
17994
18632
  throw new Error(`Omp ${name} must not be empty`);
17995
18633
  }
17996
- 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)) {
17997
18644
  assertNativePart(model2.provider, "Model provider");
17998
18645
  assertNativePart(model2.id, "Model id");
17999
- const encoded = Buffer.from(JSON.stringify([model2.provider, model2.id]), "utf8").toString("base64url");
18000
- return harnessModelRefSchema.parse({ id: `${OMP_MODEL_REF_PREFIX}${encoded}` });
18646
+ return harnessModelRefSchema.parse({ id: id2 });
18001
18647
  }
18002
- function decodeOmpModelRef(ref) {
18003
- const parsedRef = harnessModelRefSchema.parse(ref);
18004
- if (!parsedRef.id.startsWith(OMP_MODEL_REF_PREFIX)) {
18005
- 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");
18006
18665
  }
18007
- const encoded = parsedRef.id.slice(OMP_MODEL_REF_PREFIX.length);
18008
- 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;
18009
18672
  try {
18010
- 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"));
18011
18674
  } catch {
18012
- throw new Error("Omp Model Ref is malformed");
18013
- }
18014
- if (!Array.isArray(decoded) || decoded.length !== 2 || typeof decoded[0] !== "string" || typeof decoded[1] !== "string") {
18015
- throw new Error("Omp Model Ref has an invalid native identity");
18016
- }
18017
- const native = { provider: decoded[0], id: decoded[1] };
18018
- assertNativePart(native.provider, "Model provider");
18019
- assertNativePart(native.id, "Model id");
18020
- if (encodeOmpModelRef(native).id !== parsedRef.id) {
18021
- throw new Error("Omp Model Ref is not canonical");
18675
+ return void 0;
18022
18676
  }
18023
- 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;
18024
18685
  }
18025
18686
  function sameOmpModel(left, right) {
18026
18687
  return left === null ? right === null : right !== null && left.provider === right.provider && left.id === right.id;
18027
18688
  }
18028
- function fallbackThinkingLabel(id) {
18029
- const label = id.split(/[._~-]+/u).filter((part) => part.length > 0).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
18030
- 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;
18031
18692
  }
18032
18693
  function normalizeOmpThinkingOptions(levels) {
18033
- return levels.map((id) => harnessThinkingOptionSchema.parse({
18034
- id,
18035
- 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)
18036
18697
  }));
18037
18698
  }
18038
18699
  function normalizeOmpModelCatalog(nativeModels, effectiveModel, thinkingLevels, effectiveThinkingOptionId) {
18700
+ const index = createOmpModelIndex(nativeModels);
18039
18701
  const byRef = /* @__PURE__ */ new Map();
18040
18702
  for (const native of nativeModels) {
18041
- const ref = encodeOmpModelRef(native);
18703
+ const ref = index.ref(native);
18042
18704
  const existing = byRef.get(ref.id);
18043
18705
  if (existing) {
18044
18706
  if (existing.reasoning !== native.reasoning) {
@@ -18049,12 +18711,12 @@ function normalizeOmpModelCatalog(nativeModels, effectiveModel, thinkingLevels,
18049
18711
  byRef.set(ref.id, {
18050
18712
  model: {
18051
18713
  ref,
18052
- label: `${native.provider} / ${native.id}`
18714
+ label: modelLabel(native)
18053
18715
  },
18054
18716
  reasoning: native.reasoning
18055
18717
  });
18056
18718
  }
18057
- const defaultModel = effectiveModel ? encodeOmpModelRef(effectiveModel) : void 0;
18719
+ const defaultModel = effectiveModel ? index.ref(effectiveModel) : void 0;
18058
18720
  if (defaultModel && !byRef.has(defaultModel.id)) {
18059
18721
  throw new Error("Omp effective Model is absent from the available Model catalog");
18060
18722
  }
@@ -18065,13 +18727,13 @@ function normalizeOmpModelCatalog(nativeModels, effectiveModel, thinkingLevels,
18065
18727
  throw new Error("Omp did not report an effective Thinking option");
18066
18728
  }
18067
18729
  const thinkingOptions = thinkingLevels ? normalizeOmpThinkingOptions(OMP_DRAFT_THINKING_OPTION_IDS) : [];
18068
- const allThinkingOptionIds = thinkingOptions.map(({ id }) => id);
18069
- 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;
18070
18732
  const models = [...byRef.values()].map(({ model: model2, reasoning }) => ({
18071
18733
  ...model2,
18072
18734
  supportedThinkingOptionIds: reasoning ? allThinkingOptionIds : offThinkingOptionId ? [offThinkingOptionId] : []
18073
18735
  })).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
18074
- const defaultThinkingOptionId = thinkingOptions.find(({ id }) => id === effectiveThinkingOptionId)?.id;
18736
+ const defaultThinkingOptionId = thinkingOptions.find(({ id: id2 }) => id2 === effectiveThinkingOptionId)?.id;
18075
18737
  return harnessModelCatalogSchema.parse({
18076
18738
  models,
18077
18739
  ...defaultModel ? { defaultModel } : {},
@@ -18284,25 +18946,30 @@ function modelChange(entry) {
18284
18946
  return entry.type === "model_change" && typeof entry.provider === "string" && typeof entry.modelId === "string" ? { provider: entry.provider, id: entry.modelId } : null;
18285
18947
  }
18286
18948
  function mapOmpSnapshot(history, state) {
18287
- const active = activeOmpEntries(history);
18949
+ const active2 = activeOmpEntries(history);
18288
18950
  const turns = [];
18951
+ const models = createOmpModelIndex([
18952
+ ...state.models ?? [],
18953
+ ...state.model ? [state.model] : [],
18954
+ ...active2.map(modelChange).filter((model2) => model2 !== null)
18955
+ ]);
18289
18956
  let effectiveModel = state.model;
18290
- for (let index = 0; index < active.length; ) {
18291
- const model2 = modelChange(active[index]);
18957
+ for (let index = 0; index < active2.length; ) {
18958
+ const model2 = modelChange(active2[index]);
18292
18959
  if (model2) {
18293
18960
  effectiveModel = model2;
18294
18961
  index += 1;
18295
18962
  continue;
18296
18963
  }
18297
- const user = active[index];
18964
+ const user = active2[index];
18298
18965
  if (messageRole(user) !== "user") {
18299
18966
  index += 1;
18300
18967
  continue;
18301
18968
  }
18302
18969
  let end = index + 1;
18303
- while (end < active.length && messageRole(active[end]) !== "user")
18970
+ while (end < active2.length && messageRole(active2[end]) !== "user")
18304
18971
  end += 1;
18305
- const entries = active.slice(index, end);
18972
+ const entries = active2.slice(index, end);
18306
18973
  const outcome = assistantOutcome(entries);
18307
18974
  const userText = textContent(message(user)?.content);
18308
18975
  const nativeTurnRef = nativeTurnRefSchema.parse({
@@ -18323,7 +18990,7 @@ function mapOmpSnapshot(history, state) {
18323
18990
  input: [{ type: "text", text: userText }],
18324
18991
  items: snapshotItems(entries, outcome),
18325
18992
  outcome,
18326
- ...effectiveModel ? { model: encodeOmpModelRef(effectiveModel) } : {}
18993
+ ...effectiveModel ? { model: models.ref(effectiveModel) } : {}
18327
18994
  });
18328
18995
  for (const entry of entries) {
18329
18996
  const changed = modelChange(entry);
@@ -18340,8 +19007,8 @@ function resolveOmpLastTurnBoundary(history) {
18340
19007
  return last ? { lastUserEntryId: last.id, sourceTurnCount: users.length } : null;
18341
19008
  }
18342
19009
  function resolveOmpForkBoundary(history, checkpointId) {
18343
- const active = activeOmpEntries(history);
18344
- const users = active.filter((entry) => messageRole(entry) === "user");
19010
+ const active2 = activeOmpEntries(history);
19011
+ const users = active2.filter((entry) => messageRole(entry) === "user");
18345
19012
  const targetTurnIndex = users.findIndex((entry) => entry.id === checkpointId);
18346
19013
  if (targetTurnIndex < 0)
18347
19014
  throw new Error("Omp Checkpoint is not on the active branch");
@@ -18504,7 +19171,7 @@ function createOmpUsageStatistics(environment) {
18504
19171
  return Object.freeze({
18505
19172
  // <project>/<session>.jsonl and its subagents' and advisor's in <session>/
18506
19173
  listSources: (signal) => jsonlUsageSources(ompSessionImportDirectory(environment).directory, 4, signal),
18507
- readSource: (id, signal) => readOmpUsage(id, signal)
19174
+ readSource: (id2, signal) => readOmpUsage(id2, signal)
18508
19175
  });
18509
19176
  }
18510
19177
 
@@ -18789,8 +19456,8 @@ var OmpRpcUnsupportedCommandError = class extends Error {
18789
19456
  this.name = "OmpRpcUnsupportedCommandError";
18790
19457
  }
18791
19458
  };
18792
- function hasTurnCompletion(active) {
18793
- return active.terminalEnd || active.localResult !== null && !active.sawAgentStart;
19459
+ function hasTurnCompletion(active2) {
19460
+ return active2.terminalEnd || active2.localResult !== null && !active2.sawAgentStart;
18794
19461
  }
18795
19462
  var textDecoder = new TextDecoder("utf-8", { fatal: true });
18796
19463
  function isRecord8(value) {
@@ -19174,9 +19841,9 @@ var OmpRpcSession = class {
19174
19841
  const branchId = role === "user" ? branchEntryIds?.[userIndex] : void 0;
19175
19842
  if (branchId)
19176
19843
  userIndex += 1;
19177
- const id = branchId ?? (isRecord8(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
19178
- const entry = { id, parentId, type: "message", message: nativeMessage };
19179
- 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;
19180
19847
  return entry;
19181
19848
  });
19182
19849
  return { entries, leafId: parentId };
@@ -19379,9 +20046,9 @@ var OmpRpcSession = class {
19379
20046
  return this.#resolveInteraction(response, "cancelled" in response ? "cancelled" : "responded");
19380
20047
  }
19381
20048
  async #resolveInteraction(response, reason) {
19382
- const active = this.#activeTurn;
19383
- const pending = active?.interactions.get(response.requestId);
19384
- 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) {
19385
20052
  throw new Error("Omp RPC interaction is not pending");
19386
20053
  }
19387
20054
  if ("value" in response && !["select", "input", "editor"].includes(pending.request.method)) {
@@ -19396,12 +20063,12 @@ var OmpRpcSession = class {
19396
20063
  cancelled: true,
19397
20064
  ...reason === "expired" ? { timedOut: true } : {}
19398
20065
  } : "confirmed" in response ? { type: "extension_ui_response", id: response.requestId, confirmed: response.confirmed } : { type: "extension_ui_response", id: response.requestId, value: response.value };
19399
- if (!active.interactions.delete(response.requestId)) {
20066
+ if (!active2.interactions.delete(response.requestId)) {
19400
20067
  throw new Error("Omp RPC interaction is not pending");
19401
20068
  }
19402
20069
  if (pending.timeout)
19403
20070
  clearTimeout(pending.timeout);
19404
- active.onEvent({ type: "interaction.closed", requestId: response.requestId, reason });
20071
+ active2.onEvent({ type: "interaction.closed", requestId: response.requestId, reason });
19405
20072
  try {
19406
20073
  await this.#write(frame);
19407
20074
  } catch (error51) {
@@ -19411,37 +20078,37 @@ var OmpRpcSession = class {
19411
20078
  }
19412
20079
  }
19413
20080
  abort() {
19414
- const active = this.#activeTurn;
19415
- if (!active || this.#closed || this.#failed) {
20081
+ const active2 = this.#activeTurn;
20082
+ if (!active2 || this.#closed || this.#failed) {
19416
20083
  return Promise.reject(new Error("Omp RPC Session has no cancellable Turn"));
19417
20084
  }
19418
- if (active.abortPromise)
19419
- return active.abortPromise;
19420
- active.cancellation = "requesting";
19421
- active.cancellationTimeout = setTimeout(() => {
19422
- 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"));
19423
20090
  }, this.#options.cancelTimeoutMs);
19424
20091
  const aborting = this.#send("abort", {}).then(async () => {
19425
- if (this.#activeTurn !== active)
20092
+ if (this.#activeTurn !== active2)
19426
20093
  return;
19427
- active.cancellation = "accepted";
19428
- await this.#confirmCancelledTurn(active);
20094
+ active2.cancellation = "accepted";
20095
+ await this.#confirmCancelledTurn(active2);
19429
20096
  }).catch((error51) => {
19430
- if (this.#activeTurn !== active)
20097
+ if (this.#activeTurn !== active2)
19431
20098
  throw error51;
19432
20099
  const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC Abort failed: ${message2(error51)}`);
19433
- this.#terminateFailedCancellation(active, fault);
20100
+ this.#terminateFailedCancellation(active2, fault);
19434
20101
  throw fault;
19435
20102
  });
19436
- active.abortPromise = aborting;
20103
+ active2.abortPromise = aborting;
19437
20104
  return aborting;
19438
20105
  }
19439
- #terminateFailedCancellation(active, fault) {
19440
- if (this.#activeTurn !== active)
20106
+ #terminateFailedCancellation(active2, fault) {
20107
+ if (this.#activeTurn !== active2)
19441
20108
  return;
19442
- if (active.cancellationTimeout)
19443
- clearTimeout(active.cancellationTimeout);
19444
- active.cancellationTimeout = null;
20109
+ if (active2.cancellationTimeout)
20110
+ clearTimeout(active2.cancellationTimeout);
20111
+ active2.cancellationTimeout = null;
19445
20112
  this.#fail(fault);
19446
20113
  void this.close().catch(() => void 0);
19447
20114
  }
@@ -19544,9 +20211,9 @@ var OmpRpcSession = class {
19544
20211
  this.#compactionTimeout = null;
19545
20212
  const compactionTurn = this.#compactionTurn;
19546
20213
  this.#compactionTurn = null;
19547
- for (const [id, pending] of this.#pending) {
20214
+ for (const [id2, pending] of this.#pending) {
19548
20215
  if (pending.command === "prompt" || pending.command === "compact") {
19549
- this.#armCommandTimeout(id, pending);
20216
+ this.#armCommandTimeout(id2, pending);
19550
20217
  }
19551
20218
  }
19552
20219
  const outcome = value.aborted === true ? "cancelled" : isRecord8(value.result) ? "succeeded" : "failed";
@@ -19565,59 +20232,59 @@ var OmpRpcSession = class {
19565
20232
  });
19566
20233
  return;
19567
20234
  }
19568
- const active = this.#activeTurn;
19569
- if (this.#handleSubagentFrame(active, value))
20235
+ const active2 = this.#activeTurn;
20236
+ if (this.#handleSubagentFrame(active2, value))
19570
20237
  return;
19571
20238
  this.#observeUsage(value);
19572
- if (value.type === "agent_start" && active) {
19573
- active.terminalEnd = false;
19574
- active.sawAgentStart = true;
20239
+ if (value.type === "agent_start" && active2) {
20240
+ active2.terminalEnd = false;
20241
+ active2.sawAgentStart = true;
19575
20242
  }
19576
- if ((value.type === "session_settled" || value.type === "agent_start") && active?.cancellation === "accepted") {
19577
- void this.#confirmCancelledTurn(active);
20243
+ if ((value.type === "session_settled" || value.type === "agent_start") && active2?.cancellation === "accepted") {
20244
+ void this.#confirmCancelledTurn(active2);
19578
20245
  return;
19579
20246
  }
19580
20247
  if (value.type === "session_settled") {
19581
- if (active && hasTurnCompletion(active)) {
19582
- active.settledNotice = true;
19583
- void this.#confirmSettledTurn(active);
20248
+ if (active2 && hasTurnCompletion(active2)) {
20249
+ active2.settledNotice = true;
20250
+ void this.#confirmSettledTurn(active2);
19584
20251
  }
19585
20252
  return;
19586
20253
  }
19587
- if (!active) {
20254
+ if (!active2) {
19588
20255
  if (value.type === "extension_ui_request" && this.#isBlockingInteraction(value)) {
19589
20256
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC requested blocking Extension UI outside an active Turn"));
19590
20257
  }
19591
20258
  return;
19592
20259
  }
19593
20260
  if (value.type === "command_output") {
19594
- if (active.settlement !== "pending")
20261
+ if (active2.settlement !== "pending")
19595
20262
  return;
19596
20263
  if (typeof value.text !== "string") {
19597
20264
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned invalid command output");
19598
20265
  }
19599
- active.text += value.text;
19600
- 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 });
19601
20268
  return;
19602
20269
  }
19603
20270
  if (value.type === "prompt_result") {
19604
- if (value.id !== active.promptId || value.agentInvoked !== false)
20271
+ if (value.id !== active2.promptId || value.agentInvoked !== false)
19605
20272
  return;
19606
20273
  if (value.status === "completed" || value.status === "aborted") {
19607
- this.#settleLocalTurn(active, { cancelled: value.status === "aborted" });
20274
+ this.#settleLocalTurn(active2, { cancelled: value.status === "aborted" });
19608
20275
  } else if (value.status === "error" && isRecord8(value.error) && typeof value.error.message === "string") {
19609
- this.#settleLocalTurn(active, { cancelled: false, error: value.error.message });
20276
+ this.#settleLocalTurn(active2, { cancelled: false, error: value.error.message });
19610
20277
  } else {
19611
20278
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid local prompt result");
19612
20279
  }
19613
20280
  return;
19614
20281
  }
19615
20282
  if (value.type === "extension_ui_request") {
19616
- this.#startInteraction(active, value);
20283
+ this.#startInteraction(active2, value);
19617
20284
  return;
19618
20285
  }
19619
20286
  if (value.type === "message_start" && assistantText(value.message) !== null) {
19620
- this.#startAssistantMessage(active, value.message);
20287
+ this.#startAssistantMessage(active2, value.message);
19621
20288
  return;
19622
20289
  }
19623
20290
  if (value.type === "message_update" && isRecord8(value.assistantMessageEvent)) {
@@ -19627,39 +20294,39 @@ var OmpRpcSession = class {
19627
20294
  const isText = eventType === "text_delta" || eventType === "text" || eventType === "content_block_delta";
19628
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;
19629
20296
  if (isThinking && delta !== null && delta.length > 0) {
19630
- const messageId = this.#ensureAssistantMessage(active, value.message);
19631
- active.reasoningMessageOpen = true;
19632
- active.sawStreamedMessageReasoning = true;
19633
- 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 });
19634
20301
  } else if (isText && delta !== null && delta.length > 0) {
19635
- const messageId = this.#ensureAssistantMessage(active, value.message);
19636
- active.text += delta;
19637
- active.sawStreamedMessageText = true;
19638
- 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 });
19639
20306
  } else if (event.type === "error") {
19640
- this.#ensureAssistantMessage(active, value.message);
19641
- 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");
19642
20309
  }
19643
20310
  return;
19644
20311
  }
19645
20312
  if (value.type === "message_end") {
19646
- this.#finalizeAssistantMessage(active, value.message);
20313
+ this.#finalizeAssistantMessage(active2, value.message);
19647
20314
  return;
19648
20315
  }
19649
20316
  if (value.type === "turn_end") {
19650
- this.#finalizeAssistantMessage(active, value.message);
20317
+ this.#finalizeAssistantMessage(active2, value.message);
19651
20318
  return;
19652
20319
  }
19653
20320
  if (value.type === "tool_execution_start") {
19654
- this.#startTool(active, value);
20321
+ this.#startTool(active2, value);
19655
20322
  return;
19656
20323
  }
19657
20324
  if (value.type === "tool_execution_update") {
19658
- this.#updateTool(active, value);
20325
+ this.#updateTool(active2, value);
19659
20326
  return;
19660
20327
  }
19661
20328
  if (value.type === "tool_execution_end") {
19662
- this.#completeTool(active, value);
20329
+ this.#completeTool(active2, value);
19663
20330
  return;
19664
20331
  }
19665
20332
  if (value.type === "agent_end" && Array.isArray(value.messages)) {
@@ -19667,18 +20334,18 @@ var OmpRpcSession = class {
19667
20334
  const message3 = value.messages[index];
19668
20335
  if (!isRecord8(message3) || message3.role !== "assistant")
19669
20336
  continue;
19670
- this.#finalizeAssistantMessage(active, message3);
20337
+ this.#finalizeAssistantMessage(active2, message3);
19671
20338
  break;
19672
20339
  }
19673
20340
  }
19674
20341
  if (value.type === "agent_end" && value.isTerminal !== false) {
19675
- active.terminalEnd = true;
19676
- if (active.cancellation !== "none") {
19677
- if (active.cancellation === "accepted")
19678
- void this.#confirmCancelledTurn(active);
20342
+ active2.terminalEnd = true;
20343
+ if (active2.cancellation !== "none") {
20344
+ if (active2.cancellation === "accepted")
20345
+ void this.#confirmCancelledTurn(active2);
19679
20346
  return;
19680
20347
  }
19681
- void this.#confirmSettledTurn(active);
20348
+ void this.#confirmSettledTurn(active2);
19682
20349
  }
19683
20350
  }
19684
20351
  /** Every finished assistant message is one model request, with or without an active Turn. */
@@ -19720,7 +20387,7 @@ var OmpRpcSession = class {
19720
20387
  });
19721
20388
  }
19722
20389
  }
19723
- #handleSubagentFrame(active, value) {
20390
+ #handleSubagentFrame(active2, value) {
19724
20391
  if (value.type !== "subagent_lifecycle" && value.type !== "subagent_progress" && value.type !== "subagent_event") {
19725
20392
  return false;
19726
20393
  }
@@ -19732,7 +20399,7 @@ var OmpRpcSession = class {
19732
20399
  }
19733
20400
  const nativeSubagentId = nativeIdValue;
19734
20401
  const callId = nativeSubagentId;
19735
- const emit = active?.onEvent ?? this.#options.onSubagentEvent;
20402
+ const emit = active2?.onEvent ?? this.#options.onSubagentEvent;
19736
20403
  if (value.type === "subagent_event") {
19737
20404
  emit?.({ type: "subagent.transcript.changed", callId, nativeSubagentId });
19738
20405
  return true;
@@ -19790,14 +20457,14 @@ var OmpRpcSession = class {
19790
20457
  #isBlockingInteraction(value) {
19791
20458
  return ["select", "confirm", "input", "editor"].includes(String(value.method));
19792
20459
  }
19793
- #startInteraction(active, value) {
20460
+ #startInteraction(active2, value) {
19794
20461
  if (!this.#isBlockingInteraction(value))
19795
20462
  return;
19796
20463
  const requestId = value.id;
19797
20464
  const method = value.method;
19798
20465
  const title = value.title;
19799
20466
  const timeoutMs = value.timeout;
19800
- 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)) {
19801
20468
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Interaction request");
19802
20469
  }
19803
20470
  let request;
@@ -19857,7 +20524,7 @@ var OmpRpcSession = class {
19857
20524
  const pending = { request, timeout: null };
19858
20525
  if (request.timeoutMs !== void 0) {
19859
20526
  pending.timeout = setTimeout(() => {
19860
- if (this.#activeTurn !== active || !active.interactions.has(requestId))
20527
+ if (this.#activeTurn !== active2 || !active2.interactions.has(requestId))
19861
20528
  return;
19862
20529
  void this.#resolveInteraction({ requestId, cancelled: true }, "expired").catch((error51) => {
19863
20530
  if (this.#closed || this.#failed)
@@ -19866,20 +20533,20 @@ var OmpRpcSession = class {
19866
20533
  });
19867
20534
  }, request.timeoutMs);
19868
20535
  }
19869
- active.interactions.set(requestId, pending);
19870
- active.onEvent({ type: "interaction.requested", request });
20536
+ active2.interactions.set(requestId, pending);
20537
+ active2.onEvent({ type: "interaction.requested", request });
19871
20538
  }
19872
20539
  #handleResponse(value) {
19873
- const id = value.id;
19874
- if (typeof id !== "string") {
20540
+ const id2 = value.id;
20541
+ if (typeof id2 !== "string") {
19875
20542
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response has no id"));
19876
20543
  return;
19877
20544
  }
19878
- const pending = this.#pending.get(id);
19879
- const active = this.#activeTurn;
20545
+ const pending = this.#pending.get(id2);
20546
+ const active2 = this.#activeTurn;
19880
20547
  if (!pending) {
19881
- if (active?.promptId === id && value.command === "prompt" && value.success === false) {
19882
- 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");
19883
20550
  return;
19884
20551
  }
19885
20552
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC response id is not pending"));
@@ -19887,10 +20554,10 @@ var OmpRpcSession = class {
19887
20554
  }
19888
20555
  if (pending.timeout)
19889
20556
  clearTimeout(pending.timeout);
19890
- this.#pending.delete(id);
20557
+ this.#pending.delete(id2);
19891
20558
  if (value.success === true) {
19892
- if (pending.command === "prompt" && active?.promptId === id && isRecord8(value.data) && value.data.agentInvoked === false) {
19893
- 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 });
19894
20561
  }
19895
20562
  pending.resolve(value);
19896
20563
  } else {
@@ -19904,50 +20571,50 @@ var OmpRpcSession = class {
19904
20571
  }
19905
20572
  }
19906
20573
  }
19907
- #startTool(active, value) {
20574
+ #startTool(active2, value) {
19908
20575
  const callId = value.toolCallId;
19909
20576
  const toolName = value.toolName;
19910
20577
  const argumentsResult = jsonValueSchema.safeParse(value.args);
19911
- 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)) {
19912
20579
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool start");
19913
20580
  }
19914
- active.sawTool = true;
19915
- active.tools.set(callId, toolName);
19916
- active.onEvent({
20581
+ active2.sawTool = true;
20582
+ active2.tools.set(callId, toolName);
20583
+ active2.onEvent({
19917
20584
  type: "tool.started",
19918
20585
  callId,
19919
20586
  toolName,
19920
20587
  arguments: argumentsResult.data
19921
20588
  });
19922
20589
  }
19923
- #updateTool(active, value) {
20590
+ #updateTool(active2, value) {
19924
20591
  const callId = value.toolCallId;
19925
20592
  if (typeof callId !== "string" || callId.length === 0) {
19926
20593
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
19927
20594
  }
19928
- if (!active.tools.has(callId))
20595
+ if (!active2.tools.has(callId))
19929
20596
  return;
19930
20597
  const outputResult = jsonValueSchema.safeParse(value.partialResult ?? null);
19931
20598
  if (!outputResult.success) {
19932
20599
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool update");
19933
20600
  }
19934
- active.onEvent({ type: "tool.updated", callId, output: outputResult.data });
20601
+ active2.onEvent({ type: "tool.updated", callId, output: outputResult.data });
19935
20602
  }
19936
- #completeTool(active, value) {
20603
+ #completeTool(active2, value) {
19937
20604
  const callId = value.toolCallId;
19938
20605
  const toolName = value.toolName;
19939
20606
  if (typeof callId !== "string" || callId.length === 0) {
19940
20607
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool end");
19941
20608
  }
19942
- const expectedName = active.tools.get(callId);
20609
+ const expectedName = active2.tools.get(callId);
19943
20610
  if (expectedName === void 0)
19944
20611
  return;
19945
20612
  const result = jsonValueSchema.safeParse(value.result);
19946
20613
  if (typeof toolName !== "string" || expectedName !== toolName || value.isError !== void 0 && typeof value.isError !== "boolean" || !result.success) {
19947
20614
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Tool end");
19948
20615
  }
19949
- active.tools.delete(callId);
19950
- active.onEvent({
20616
+ active2.tools.delete(callId);
20617
+ active2.onEvent({
19951
20618
  type: "tool.completed",
19952
20619
  callId,
19953
20620
  toolName,
@@ -19955,40 +20622,40 @@ var OmpRpcSession = class {
19955
20622
  isError: value.isError === true
19956
20623
  });
19957
20624
  }
19958
- async #confirmCancelledTurn(active) {
19959
- 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)
19960
20627
  return;
19961
- active.cancellationChecking = true;
19962
- if (active.cancellationRecheck)
19963
- clearTimeout(active.cancellationRecheck);
19964
- active.cancellationRecheck = null;
20628
+ active2.cancellationChecking = true;
20629
+ if (active2.cancellationRecheck)
20630
+ clearTimeout(active2.cancellationRecheck);
20631
+ active2.cancellationRecheck = null;
19965
20632
  try {
19966
20633
  let response = await this.#send("get_state", {});
19967
- if (this.#activeTurn !== active)
20634
+ if (this.#activeTurn !== active2)
19968
20635
  return;
19969
20636
  if (parseSessionStreaming(response)) {
19970
20637
  await this.#send("abort", {});
19971
- if (this.#activeTurn !== active)
20638
+ if (this.#activeTurn !== active2)
19972
20639
  return;
19973
20640
  response = await this.#send("get_state", {});
19974
20641
  }
19975
20642
  let state = parseSessionState(response);
19976
- if (this.#activeTurn !== active || active.cancellation !== "accepted")
20643
+ if (this.#activeTurn !== active2 || active2.cancellation !== "accepted")
19977
20644
  return;
19978
20645
  const data = sessionStateData(response);
19979
- 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) {
19980
20647
  await this.verifySessionCwd(this.#options.cwd);
19981
- if (this.#activeTurn !== active)
20648
+ if (this.#activeTurn !== active2)
19982
20649
  return;
19983
- active.cancellationReloaded = true;
20650
+ active2.cancellationReloaded = true;
19984
20651
  const reset = await this.#send("new_session", {});
19985
- if (this.#activeTurn !== active)
20652
+ if (this.#activeTurn !== active2)
19986
20653
  return;
19987
20654
  if (!isRecord8(reset.data) || reset.data.cancelled !== false) {
19988
20655
  throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reset was refused");
19989
20656
  }
19990
20657
  const reloaded = await this.#send("switch_session", { sessionPath: state.sessionFile });
19991
- if (this.#activeTurn !== active)
20658
+ if (this.#activeTurn !== active2)
19992
20659
  return;
19993
20660
  if (!isRecord8(reloaded.data) || reloaded.data.cancelled !== false) {
19994
20661
  throw new OmpRpcFaultError("unavailable", "Omp cancelled Session reload was refused");
@@ -20014,157 +20681,157 @@ var OmpRpcSession = class {
20014
20681
  throw new OmpRpcFaultError("protocolError", "Omp cancelled Session reload changed its identity or configuration");
20015
20682
  }
20016
20683
  }
20017
- if (!sessionSettled(response, active.terminalEnd)) {
20018
- active.settlement = "pending";
20019
- active.cancellationRecheck = setTimeout(() => {
20020
- active.cancellationRecheck = null;
20021
- 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);
20022
20689
  }, 250);
20023
20690
  return;
20024
20691
  }
20025
20692
  this.#state = state;
20026
- active.settlement = "confirmed";
20027
- this.#finishSettledTurn(active);
20693
+ active2.settlement = "confirmed";
20694
+ this.#finishSettledTurn(active2);
20028
20695
  } catch (error51) {
20029
- if (this.#activeTurn !== active)
20696
+ if (this.#activeTurn !== active2)
20030
20697
  return;
20031
20698
  const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC cancelled Turn state could not be confirmed: ${message2(error51)}`);
20032
- this.#terminateFailedCancellation(active, fault);
20699
+ this.#terminateFailedCancellation(active2, fault);
20033
20700
  } finally {
20034
- active.cancellationChecking = false;
20701
+ active2.cancellationChecking = false;
20035
20702
  }
20036
20703
  }
20037
- #settleLocalTurn(active, result) {
20038
- if (this.#activeTurn !== active || active.settlement !== "pending")
20704
+ #settleLocalTurn(active2, result) {
20705
+ if (this.#activeTurn !== active2 || active2.settlement !== "pending")
20039
20706
  return;
20040
- active.localResult = result;
20041
- void this.#confirmSettledTurn(active);
20707
+ active2.localResult = result;
20708
+ void this.#confirmSettledTurn(active2);
20042
20709
  }
20043
- async #confirmSettledTurn(active) {
20044
- 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))
20045
20712
  return;
20046
- if (active.settlementRecheck)
20047
- clearTimeout(active.settlementRecheck);
20048
- active.settlementRecheck = null;
20049
- active.settlement = "confirming";
20713
+ if (active2.settlementRecheck)
20714
+ clearTimeout(active2.settlementRecheck);
20715
+ active2.settlementRecheck = null;
20716
+ active2.settlement = "confirming";
20050
20717
  try {
20051
20718
  const response = await this.#send("get_state", {});
20052
20719
  const state = parseSessionState(response);
20053
- if (this.#activeTurn !== active)
20720
+ if (this.#activeTurn !== active2)
20054
20721
  return;
20055
- if (active.cancellation !== "none") {
20056
- active.settlement = "pending";
20057
- if (active.cancellation === "accepted")
20058
- void this.#confirmCancelledTurn(active);
20722
+ if (active2.cancellation !== "none") {
20723
+ active2.settlement = "pending";
20724
+ if (active2.cancellation === "accepted")
20725
+ void this.#confirmCancelledTurn(active2);
20059
20726
  return;
20060
20727
  }
20061
- if (!hasTurnCompletion(active)) {
20062
- active.settlement = "pending";
20063
- active.settledNotice = false;
20728
+ if (!hasTurnCompletion(active2)) {
20729
+ active2.settlement = "pending";
20730
+ active2.settledNotice = false;
20064
20731
  return;
20065
20732
  }
20066
- if (!sessionSettled(response, hasTurnCompletion(active))) {
20067
- active.settlement = "pending";
20068
- if (active.settledNotice) {
20069
- active.settledNotice = false;
20070
- active.settlementRecheck = setTimeout(() => {
20071
- active.settlementRecheck = null;
20072
- 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);
20073
20740
  }, 50);
20074
20741
  }
20075
20742
  return;
20076
20743
  }
20077
20744
  this.#state = state;
20078
- active.settlement = "confirmed";
20079
- this.#finishSettledTurn(active);
20745
+ active2.settlement = "confirmed";
20746
+ this.#finishSettledTurn(active2);
20080
20747
  } catch (error51) {
20081
- if (this.#activeTurn !== active)
20748
+ if (this.#activeTurn !== active2)
20082
20749
  return;
20083
20750
  const fault = error51 instanceof OmpRpcFaultError ? error51 : new OmpRpcFaultError("protocolError", `Omp RPC stable Turn state could not be confirmed: ${message2(error51)}`);
20084
20751
  this.#fail(fault);
20085
20752
  }
20086
20753
  }
20087
- #finishSettledTurn(active) {
20088
- if (this.#activeTurn !== active || active.settlement !== "confirmed" || active.cancellation === "requesting") {
20754
+ #finishSettledTurn(active2) {
20755
+ if (this.#activeTurn !== active2 || active2.settlement !== "confirmed" || active2.cancellation === "requesting") {
20089
20756
  return;
20090
20757
  }
20091
- if (active.settlementRecheck)
20092
- clearTimeout(active.settlementRecheck);
20093
- active.settlementRecheck = null;
20094
- if (active.cancellationTimeout)
20095
- clearTimeout(active.cancellationTimeout);
20096
- active.cancellationTimeout = null;
20097
- if (active.cancellationRecheck)
20098
- clearTimeout(active.cancellationRecheck);
20099
- active.cancellationRecheck = null;
20100
- this.#closeInteractions(active, active.cancellation === "accepted" ? "cancelled" : "superseded");
20101
- 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) {
20102
20769
  this.#fail(new OmpRpcFaultError("protocolError", "Omp RPC settled with active Tool executions"));
20103
20770
  return;
20104
20771
  }
20105
20772
  this.#activeTurn = null;
20106
- if (active.localResult) {
20107
- active.resolve({
20108
- text: active.text,
20773
+ if (active2.localResult) {
20774
+ active2.resolve({
20775
+ text: active2.text,
20109
20776
  agentInvoked: false,
20110
- ...active.localResult,
20111
- cancelled: active.localResult.cancelled || active.cancellation === "accepted"
20777
+ ...active2.localResult,
20778
+ cancelled: active2.localResult.cancelled || active2.cancellation === "accepted"
20112
20779
  });
20113
- } else if (active.cancellation === "accepted") {
20114
- active.resolve({ text: active.text, cancelled: true, agentInvoked: true });
20115
- } else if (active.failure) {
20116
- active.reject(active.failure);
20117
- } else if (active.text.trim().length === 0 && !active.sawTool) {
20118
- 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"));
20119
20786
  } else {
20120
- active.resolve({ text: active.text, cancelled: false, agentInvoked: true });
20787
+ active2.resolve({ text: active2.text, cancelled: false, agentInvoked: true });
20121
20788
  }
20122
20789
  }
20123
- #startAssistantMessage(active, value) {
20124
- if (active.assistantMessageId !== null && active.reasoningMessageOpen) {
20125
- 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 });
20126
20793
  }
20127
20794
  const messageId = assistantMessageId(value) ?? randomUUID();
20128
- active.assistantMessageId = messageId;
20129
- active.sawStreamedMessageText = false;
20130
- active.sawStreamedMessageReasoning = false;
20131
- active.reasoningMessageOpen = false;
20795
+ active2.assistantMessageId = messageId;
20796
+ active2.sawStreamedMessageText = false;
20797
+ active2.sawStreamedMessageReasoning = false;
20798
+ active2.reasoningMessageOpen = false;
20132
20799
  return messageId;
20133
20800
  }
20134
- #ensureAssistantMessage(active, value) {
20135
- return active.assistantMessageId ?? this.#startAssistantMessage(active, value);
20801
+ #ensureAssistantMessage(active2, value) {
20802
+ return active2.assistantMessageId ?? this.#startAssistantMessage(active2, value);
20136
20803
  }
20137
- #finalizeAssistantMessage(active, value) {
20804
+ #finalizeAssistantMessage(active2, value) {
20138
20805
  const finalText = assistantText(value);
20139
20806
  const finalReasoning = assistantReasoning(value);
20140
20807
  const failure = assistantFailure(value);
20141
20808
  const cacheHitRatePercent = optionalOmpCacheHitRatePercent(value);
20142
20809
  if (finalText === null || finalReasoning === null || failure === void 0)
20143
20810
  return;
20144
- 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) {
20145
20812
  return;
20146
20813
  }
20147
- active.failure = failure;
20814
+ active2.failure = failure;
20148
20815
  this.#latestCacheHitRatePercent = cacheHitRatePercent;
20149
- const messageId = this.#ensureAssistantMessage(active, value);
20150
- if (!active.sawStreamedMessageReasoning && finalReasoning.length > 0) {
20151
- active.reasoningMessageOpen = true;
20152
- active.onEvent({ type: "reasoning.delta", messageId, delta: finalReasoning });
20153
- }
20154
- if (active.reasoningMessageOpen && active.failure === null) {
20155
- active.onEvent({ type: "reasoning.completed", messageId });
20156
- }
20157
- if (!active.sawStreamedMessageText && finalText.length > 0) {
20158
- active.text += finalText;
20159
- active.onEvent({ type: "text.delta", messageId, delta: finalText });
20160
- }
20161
- active.assistantMessageId = null;
20162
- active.sawStreamedMessageText = false;
20163
- active.sawStreamedMessageReasoning = false;
20164
- active.reasoningMessageOpen = false;
20165
- active.lastFinalizedMessageText = finalText;
20166
- active.lastFinalizedMessageReasoning = finalReasoning;
20167
- 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 });
20168
20835
  }
20169
20836
  #write(value) {
20170
20837
  const child = this.#child;
@@ -20177,7 +20844,7 @@ var OmpRpcSession = class {
20177
20844
  child.stdin.write(frame, (error51) => error51 ? reject(error51) : resolve());
20178
20845
  });
20179
20846
  }
20180
- #send(type, payload, id = `codexhost-${randomUUID()}`, onResponse) {
20847
+ #send(type, payload, id2 = `codexhost-${randomUUID()}`, onResponse) {
20181
20848
  const child = this.#child;
20182
20849
  if (!child?.stdin.writable || this.#closed || this.#failed) {
20183
20850
  return Promise.reject(new Error("Omp RPC stdin is unavailable"));
@@ -20192,31 +20859,31 @@ var OmpRpcSession = class {
20192
20859
  reject,
20193
20860
  timeout: null
20194
20861
  };
20195
- this.#pending.set(id, pending);
20196
- this.#armCommandTimeout(id, pending);
20197
- 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 })}
20198
20865
  `, "utf8");
20199
20866
  child.stdin.write(frame, (error51) => {
20200
20867
  if (error51) {
20201
20868
  if (pending.timeout)
20202
20869
  clearTimeout(pending.timeout);
20203
- this.#pending.delete(id);
20870
+ this.#pending.delete(id2);
20204
20871
  reject(error51);
20205
20872
  }
20206
20873
  });
20207
20874
  });
20208
20875
  }
20209
- #armCommandTimeout(id, pending) {
20210
- 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) {
20211
20878
  return;
20212
20879
  }
20213
20880
  pending.timeout = setTimeout(() => {
20214
- if (this.#pending.get(id) !== pending)
20881
+ if (this.#pending.get(id2) !== pending)
20215
20882
  return;
20216
20883
  pending.timeout = null;
20217
20884
  const error51 = new Error(`Omp RPC '${pending.command}' command timed out`);
20218
20885
  if (pending.command !== "prompt") {
20219
- this.#pending.delete(id);
20886
+ this.#pending.delete(id2);
20220
20887
  pending.reject(error51);
20221
20888
  return;
20222
20889
  }
@@ -20243,27 +20910,27 @@ var OmpRpcSession = class {
20243
20910
  this.#rejectAll(finalFault);
20244
20911
  this.#options.onFault?.(finalFault);
20245
20912
  }
20246
- #closeInteractions(active, reason) {
20247
- for (const [requestId, pending] of active.interactions) {
20248
- active.interactions.delete(requestId);
20913
+ #closeInteractions(active2, reason) {
20914
+ for (const [requestId, pending] of active2.interactions) {
20915
+ active2.interactions.delete(requestId);
20249
20916
  if (pending.timeout)
20250
20917
  clearTimeout(pending.timeout);
20251
- active.onEvent({ type: "interaction.closed", requestId, reason });
20918
+ active2.onEvent({ type: "interaction.closed", requestId, reason });
20252
20919
  }
20253
20920
  }
20254
20921
  #rejectActiveTurn(error51) {
20255
- const active = this.#activeTurn;
20256
- if (!active)
20922
+ const active2 = this.#activeTurn;
20923
+ if (!active2)
20257
20924
  return;
20258
- if (active.settlementRecheck)
20259
- clearTimeout(active.settlementRecheck);
20260
- if (active.cancellationTimeout)
20261
- clearTimeout(active.cancellationTimeout);
20262
- if (active.cancellationRecheck)
20263
- clearTimeout(active.cancellationRecheck);
20264
- 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");
20265
20932
  this.#activeTurn = null;
20266
- active.reject(error51);
20933
+ active2.reject(error51);
20267
20934
  }
20268
20935
  #rejectAll(error51) {
20269
20936
  if (this.#compactionTimeout)
@@ -21048,10 +21715,10 @@ var OmpSubagentLifecycle = class {
21048
21715
  return subagent;
21049
21716
  }
21050
21717
  update(turnId, event) {
21051
- const active = this.#delegations.get(event.callId);
21052
- if (!active)
21718
+ const active2 = this.#delegations.get(event.callId);
21719
+ if (!active2)
21053
21720
  return void 0;
21054
- const current = active.item.subagents[0];
21721
+ const current = active2.item.subagents[0];
21055
21722
  if (!current)
21056
21723
  throw new Error("Omp Subagent delegation has no Agent state");
21057
21724
  const subagent = {
@@ -21062,21 +21729,21 @@ var OmpSubagentLifecycle = class {
21062
21729
  ...event.resultSummary ? { resultSummary: event.resultSummary } : {},
21063
21730
  ...event.nativeSubagentId ? { nativeSubagentId: event.nativeSubagentId } : {}
21064
21731
  };
21065
- active.item = { ...active.item, subagents: [subagent] };
21732
+ active2.item = { ...active2.item, subagents: [subagent] };
21066
21733
  this.#emit({
21067
21734
  type: "item.updated",
21068
21735
  turnId,
21069
- itemId: active.item.itemId,
21070
- update: { type: "subagents.replace", subagents: active.item.subagents }
21736
+ itemId: active2.item.itemId,
21737
+ update: { type: "subagents.replace", subagents: active2.item.subagents }
21071
21738
  });
21072
21739
  return subagent;
21073
21740
  }
21074
21741
  complete(turnId, event, cancellationRequested) {
21075
- const active = this.#delegations.get(event.callId);
21076
- if (!active)
21742
+ const active2 = this.#delegations.get(event.callId);
21743
+ if (!active2)
21077
21744
  throw new Error("Omp Subagent completion references an unknown delegation");
21078
21745
  this.#delegations.delete(event.callId);
21079
- const current = active.item.subagents[0];
21746
+ const current = active2.item.subagents[0];
21080
21747
  if (!current)
21081
21748
  throw new Error("Omp Subagent delegation has no Agent state");
21082
21749
  const subagent = {
@@ -21085,7 +21752,7 @@ var OmpSubagentLifecycle = class {
21085
21752
  ...event.resultSummary ? { resultSummary: event.resultSummary } : {},
21086
21753
  ...event.nativeSubagentId ? { nativeSubagentId: event.nativeSubagentId } : {}
21087
21754
  };
21088
- const item = { ...active.item, subagents: [subagent] };
21755
+ const item = { ...active2.item, subagents: [subagent] };
21089
21756
  this.#emit({
21090
21757
  type: "item.updated",
21091
21758
  turnId,
@@ -21097,13 +21764,13 @@ var OmpSubagentLifecycle = class {
21097
21764
  return subagent;
21098
21765
  }
21099
21766
  finalize(turnId, outcome) {
21100
- for (const [callId, active] of this.#delegations) {
21767
+ for (const [callId, active2] of this.#delegations) {
21101
21768
  this.#delegations.delete(callId);
21102
- const current = active.item.subagents[0];
21769
+ const current = active2.item.subagents[0];
21103
21770
  if (!current)
21104
21771
  continue;
21105
21772
  const status = outcome.status === "succeeded" ? current.status : outcome.status === "cancelled" ? "interrupted" : "failed";
21106
- const item = { ...active.item, subagents: [{ ...current, status }] };
21773
+ const item = { ...active2.item, subagents: [{ ...current, status }] };
21107
21774
  this.#emit({ type: "item.completed", turnId, snapshot: { item, outcome } });
21108
21775
  }
21109
21776
  }
@@ -21194,12 +21861,9 @@ function nativeModelFromState(state) {
21194
21861
  }
21195
21862
  return { provider: state.provider, id: state.modelId };
21196
21863
  }
21197
- function effectiveModelFromState(state) {
21864
+ function harnessStateFromOmp(state, thinkingLevels, index, permissionModeId) {
21198
21865
  const model2 = nativeModelFromState(state);
21199
- return model2 ? encodeOmpModelRef(model2) : void 0;
21200
- }
21201
- function harnessStateFromOmp(state, thinkingLevels, permissionModeId) {
21202
- const effectiveModel = effectiveModelFromState(state);
21866
+ const effectiveModel = model2 ? index.ref(model2) : void 0;
21203
21867
  const availableThinkingOptions = thinkingLevels ? normalizeOmpThinkingOptions(thinkingLevels) : void 0;
21204
21868
  if (availableThinkingOptions && (!state.thinkingLevel || !thinkingLevels?.includes(state.thinkingLevel))) {
21205
21869
  throw new OmpRpcFaultError("protocolError", "Omp effective Thinking level is absent from its available levels");
@@ -21420,10 +22084,10 @@ function fileChangeFromPatch(patch, cwd) {
21420
22084
  return [{ path: displayed.path, kind, unifiedDiff: patch }];
21421
22085
  }
21422
22086
  function synthesizeFileChange(kind, args, cwd) {
21423
- const filePath = nestedToolString(args, ["path", "file_path", "filePath", "file"]);
21424
- if (!filePath)
22087
+ const filePath2 = nestedToolString(args, ["path", "file_path", "filePath", "file"]);
22088
+ if (!filePath2)
21425
22089
  return null;
21426
- const displayed = displayPath(filePath, cwd);
22090
+ const displayed = displayPath(filePath2, cwd);
21427
22091
  if (!displayed)
21428
22092
  return null;
21429
22093
  if (kind === "write") {
@@ -21500,6 +22164,7 @@ var OmpHarnessSession = class {
21500
22164
  #requestedModel;
21501
22165
  #requestedThinkingOptionId;
21502
22166
  #toolOutputLimit;
22167
+ #modelIndex;
21503
22168
  #permissionMode;
21504
22169
  #permissionModeId;
21505
22170
  #acceptingTurn = false;
@@ -21541,7 +22206,8 @@ var OmpHarnessSession = class {
21541
22206
  execute: (command) => this.#executeHarnessCommand(command)
21542
22207
  };
21543
22208
  this.#transport = options.startedTransport ?? null;
21544
- 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 };
21545
22211
  this.initialUsage = options.initialUsage ?? null;
21546
22212
  this.#usage = this.initialUsage;
21547
22213
  this.#state = this.initialState;
@@ -21612,7 +22278,7 @@ var OmpHarnessSession = class {
21612
22278
  }
21613
22279
  #subagentConfiguration() {
21614
22280
  const state = this.#state;
21615
- const model2 = state.effectiveModel ? decodeOmpModelRef(state.effectiveModel).id : void 0;
22281
+ const model2 = this.#transport?.state.modelId;
21616
22282
  return {
21617
22283
  ...model2 ? { model: model2 } : {},
21618
22284
  ...state.effectiveThinkingOptionId ? { reasoningEffort: state.effectiveThinkingOptionId } : {}
@@ -21660,7 +22326,8 @@ var OmpHarnessSession = class {
21660
22326
  value: {
21661
22327
  ...mapOmpSnapshot(history, {
21662
22328
  sessionId: transport.state.sessionId,
21663
- model: nativeModelForHistory(transport.state)
22329
+ model: nativeModelForHistory(transport.state),
22330
+ models: this.#modelIndex.models
21664
22331
  }),
21665
22332
  state: this.#state
21666
22333
  }
@@ -21740,7 +22407,7 @@ var OmpHarnessSession = class {
21740
22407
  itemId: this.#newItemId(),
21741
22408
  text: ""
21742
22409
  };
21743
- const active = {
22410
+ const active2 = {
21744
22411
  command,
21745
22412
  agentItem: item,
21746
22413
  agentMessageId: null,
@@ -21762,23 +22429,23 @@ var OmpHarnessSession = class {
21762
22429
  completion,
21763
22430
  resolveCompletion
21764
22431
  };
21765
- this.#active = active;
22432
+ this.#active = active2;
21766
22433
  this.#event({ type: "turn.started", turnId: command.turnId });
21767
22434
  this.#event({ type: "item.started", turnId: command.turnId, item });
21768
- 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) => {
21769
22436
  if (!result.agentInvoked) {
21770
- 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);
21771
22438
  return;
21772
22439
  }
21773
22440
  try {
21774
- const identity2 = await this.#completedTurnIdentity(active, transport);
21775
- this.#completeTurn(active, result.cancelled ? {
22441
+ const identity2 = await this.#completedTurnIdentity(active2, transport);
22442
+ this.#completeTurn(active2, result.cancelled ? {
21776
22443
  status: "cancelled",
21777
22444
  reason: "Cancelled by user",
21778
22445
  checkpoint: identity2.checkpoint
21779
22446
  } : { status: "succeeded", checkpoint: identity2.checkpoint }, result.text, identity2.nativeTurnRef);
21780
22447
  } catch (error51) {
21781
- this.#completeTurn(active, {
22448
+ this.#completeTurn(active2, {
21782
22449
  status: "failed",
21783
22450
  error: normalizedError(error51, "protocolError")
21784
22451
  });
@@ -21786,10 +22453,10 @@ var OmpHarnessSession = class {
21786
22453
  }).catch(async (error51) => {
21787
22454
  let identity2;
21788
22455
  try {
21789
- identity2 = await this.#completedTurnIdentity(active, transport);
22456
+ identity2 = await this.#completedTurnIdentity(active2, transport);
21790
22457
  } catch {
21791
22458
  }
21792
- this.#completeTurn(active, {
22459
+ this.#completeTurn(active2, {
21793
22460
  status: "failed",
21794
22461
  error: normalizedError(error51, "nativeFailure"),
21795
22462
  ...identity2 ? { checkpoint: identity2.checkpoint } : {}
@@ -21824,15 +22491,17 @@ var OmpHarnessSession = class {
21824
22491
  error: invalidState("Omp Model selection requires a started Native Session")
21825
22492
  };
21826
22493
  }
21827
- let requested;
21828
- try {
21829
- requested = decodeOmpModelRef(command.model);
21830
- } catch (error51) {
21831
- return { ok: false, error: normalizedError(error51, "invalidRequest") };
21832
- }
21833
22494
  const previousModel = this.#state.effectiveModel;
21834
22495
  this.#configuring = true;
21835
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
+ }
21836
22505
  let state;
21837
22506
  let thinkingLevels;
21838
22507
  try {
@@ -21848,8 +22517,7 @@ var OmpHarnessSession = class {
21848
22517
  return { ok: false, error: normalizedError(error51, "nativeFailure") };
21849
22518
  }
21850
22519
  const actual = nativeModelFromState(state);
21851
- const nextModel = effectiveModelFromState(state);
21852
- if (previousModel?.id !== nextModel?.id) {
22520
+ if (previousModel?.id !== this.#state.effectiveModel?.id) {
21853
22521
  this.#invalidateUsage();
21854
22522
  void this.#refreshUsage();
21855
22523
  }
@@ -22032,9 +22700,9 @@ var OmpHarnessSession = class {
22032
22700
  }
22033
22701
  }
22034
22702
  async #respond(command) {
22035
- const active = this.#active;
22036
- const pending = active?.interactions.get(command.interactionId);
22037
- if (!active || !pending) {
22703
+ const active2 = this.#active;
22704
+ const pending = active2?.interactions.get(command.interactionId);
22705
+ if (!active2 || !pending) {
22038
22706
  return {
22039
22707
  ok: false,
22040
22708
  error: invalidState("Omp Interaction Response must reference a pending Interaction")
@@ -22107,8 +22775,8 @@ var OmpHarnessSession = class {
22107
22775
  }
22108
22776
  }
22109
22777
  #canSteerActiveTurn() {
22110
- const active = this.#active;
22111
- 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);
22112
22780
  }
22113
22781
  async #steer(command) {
22114
22782
  const text = command.input.map((input) => input.text).join("\n");
@@ -22122,17 +22790,17 @@ var OmpHarnessSession = class {
22122
22790
  }
22123
22791
  };
22124
22792
  }
22125
- const active = this.#active;
22793
+ const active2 = this.#active;
22126
22794
  const transport = this.#transport;
22127
- if (!active || !transport || active.command.turnId !== command.turnId || !this.#canSteerActiveTurn()) {
22795
+ if (!active2 || !transport || active2.command.turnId !== command.turnId || !this.#canSteerActiveTurn()) {
22128
22796
  return { ok: false, error: invalidState("Omp Turn is not accepting native input") };
22129
22797
  }
22130
22798
  let accepted;
22131
22799
  try {
22132
22800
  accepted = transport.steer(text).then(() => {
22133
- active.acceptedSteerCount += 1;
22801
+ active2.acceptedSteerCount += 1;
22134
22802
  });
22135
- active.pendingSteers.add(accepted);
22803
+ active2.pendingSteers.add(accepted);
22136
22804
  await accepted;
22137
22805
  return { ok: true, value: { accepted: true } };
22138
22806
  } catch (error51) {
@@ -22140,34 +22808,34 @@ var OmpHarnessSession = class {
22140
22808
  return { ok: false, error: invalidState(error51.message) };
22141
22809
  }
22142
22810
  if (error51 instanceof OmpRpcSteerTargetEndedError)
22143
- active.steerFailure = error51;
22811
+ active2.steerFailure = error51;
22144
22812
  throw error51;
22145
22813
  } finally {
22146
22814
  if (accepted)
22147
- active.pendingSteers.delete(accepted);
22815
+ active2.pendingSteers.delete(accepted);
22148
22816
  }
22149
22817
  }
22150
22818
  async #cancel(command) {
22151
- const active = this.#active;
22152
- if (!active || active.command.turnId !== command.turnId) {
22819
+ const active2 = this.#active;
22820
+ if (!active2 || active2.command.turnId !== command.turnId) {
22153
22821
  return {
22154
22822
  ok: false,
22155
22823
  error: invalidState("Omp Turn Cancel must reference the active Turn")
22156
22824
  };
22157
22825
  }
22158
- if (active.cancellationRequested) {
22826
+ if (active2.cancellationRequested) {
22159
22827
  return { ok: true, value: { cancellationRequested: true } };
22160
22828
  }
22161
22829
  const transport = this.#transport;
22162
22830
  if (!transport)
22163
22831
  return { ok: false, error: invalidState("Omp transport is unavailable") };
22164
- active.cancellationRequested = true;
22832
+ active2.cancellationRequested = true;
22165
22833
  try {
22166
22834
  await transport.abort();
22167
22835
  return { ok: true, value: { cancellationRequested: true } };
22168
22836
  } catch (error51) {
22169
22837
  const normalized = normalizedError(error51, "nativeFailure");
22170
- if (this.#active === active) {
22838
+ if (this.#active === active2) {
22171
22839
  this.#fault(new OmpAdapterFaultError(normalized));
22172
22840
  void transport.close().catch(() => void 0);
22173
22841
  }
@@ -22251,7 +22919,7 @@ var OmpHarnessSession = class {
22251
22919
  const completion = new Promise((resolve) => {
22252
22920
  resolveCompletion = resolve;
22253
22921
  });
22254
- const active = {
22922
+ const active2 = {
22255
22923
  command: turnCommand,
22256
22924
  agentItem: null,
22257
22925
  agentMessageId: null,
@@ -22273,18 +22941,18 @@ var OmpHarnessSession = class {
22273
22941
  completion,
22274
22942
  resolveCompletion
22275
22943
  };
22276
- this.#active = active;
22944
+ this.#active = active2;
22277
22945
  this.#event({ type: "turn.started", turnId: command.turnId });
22278
- void transport.compact(customInstructions, (event) => this.#handleTurnEvent(active, event)).then((result) => {
22946
+ void transport.compact(customInstructions, (event) => this.#handleTurnEvent(active2, event)).then((result) => {
22279
22947
  if (result.outcome === "succeeded") {
22280
- this.#completeTurn(active, { status: "succeeded" });
22948
+ this.#completeTurn(active2, { status: "succeeded" });
22281
22949
  } else if (result.outcome === "cancelled") {
22282
- this.#completeTurn(active, {
22950
+ this.#completeTurn(active2, {
22283
22951
  status: "cancelled",
22284
22952
  reason: "Context compaction was cancelled"
22285
22953
  });
22286
22954
  } else {
22287
- this.#completeTurn(active, {
22955
+ this.#completeTurn(active2, {
22288
22956
  status: "failed",
22289
22957
  error: {
22290
22958
  code: "nativeFailure",
@@ -22294,7 +22962,7 @@ var OmpHarnessSession = class {
22294
22962
  });
22295
22963
  }
22296
22964
  }).catch((error51) => {
22297
- this.#completeTurn(active, {
22965
+ this.#completeTurn(active2, {
22298
22966
  status: "failed",
22299
22967
  error: normalizedError(error51, "nativeFailure")
22300
22968
  });
@@ -22320,9 +22988,11 @@ var OmpHarnessSession = class {
22320
22988
  if (this.#phase !== "open")
22321
22989
  throw new Error("Omp Session closed during startup");
22322
22990
  let state = transport.state;
22991
+ const models = await transport.getAvailableModels();
22992
+ this.#modelIndex = createOmpModelIndex(models);
22323
22993
  let thinkingLevels = await transport.getAvailableThinkingLevels();
22324
22994
  if (this.#requestedModel) {
22325
- const requested = decodeOmpModelRef(this.#requestedModel);
22995
+ const requested = resolveOmpModelRef(this.#requestedModel, this.#modelIndex);
22326
22996
  const current = nativeModelFromState(state);
22327
22997
  if (!sameOmpModel(current, requested))
22328
22998
  state = await transport.selectModel(requested);
@@ -22335,7 +23005,7 @@ var OmpHarnessSession = class {
22335
23005
  if (this.#requestedThinkingOptionId) {
22336
23006
  if (!thinkingLevels) {
22337
23007
  const current = nativeModelFromState(state);
22338
- 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));
22339
23009
  if (!thinkingAlreadyOff) {
22340
23010
  throw new OmpAdapterFaultError({
22341
23011
  code: "unsupported",
@@ -22367,7 +23037,7 @@ var OmpHarnessSession = class {
22367
23037
  return starting;
22368
23038
  }
22369
23039
  #publishTransportState(state, thinkingLevels) {
22370
- this.#state = harnessStateFromOmp(state, thinkingLevels, this.#permissionModeId);
23040
+ this.#state = harnessStateFromOmp(state, thinkingLevels, this.#modelIndex, this.#permissionModeId);
22371
23041
  this.#event({ type: "session.state.changed", state: this.#state });
22372
23042
  }
22373
23043
  #invalidateUsage() {
@@ -22403,50 +23073,50 @@ var OmpHarnessSession = class {
22403
23073
  ...observedForTurnId ? { observedForTurnId } : {}
22404
23074
  });
22405
23075
  }
22406
- #handleTurnEvent(active, event) {
22407
- 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")
22408
23078
  return;
22409
23079
  switch (event.type) {
22410
23080
  case "text.delta":
22411
- this.#activateAgentMessage(active, event.messageId);
22412
- this.#appendText(active, event.delta);
23081
+ this.#activateAgentMessage(active2, event.messageId);
23082
+ this.#appendText(active2, event.delta);
22413
23083
  return;
22414
23084
  case "reasoning.delta":
22415
- this.#activateAgentMessage(active, event.messageId);
22416
- this.#appendReasoning(active, event.delta);
23085
+ this.#activateAgentMessage(active2, event.messageId);
23086
+ this.#appendReasoning(active2, event.delta);
22417
23087
  return;
22418
23088
  case "reasoning.completed":
22419
- this.#completeReasoning(active, { status: "succeeded" });
23089
+ this.#completeReasoning(active2, { status: "succeeded" });
22420
23090
  return;
22421
23091
  case "message.completed":
22422
- void this.#refreshUsage(active.command.turnId);
23092
+ void this.#refreshUsage(active2.command.turnId);
22423
23093
  return;
22424
23094
  case "compaction.started":
22425
- this.#startCompaction(active);
23095
+ this.#startCompaction(active2);
22426
23096
  return;
22427
23097
  case "compaction.completed":
22428
- this.#completeCompaction(active, event);
23098
+ this.#completeCompaction(active2, event);
22429
23099
  return;
22430
23100
  case "interaction.requested":
22431
- this.#startInteraction(active, event.request);
23101
+ this.#startInteraction(active2, event.request);
22432
23102
  return;
22433
23103
  case "interaction.closed":
22434
- this.#closeInteraction(active, event.requestId, event.reason);
23104
+ this.#closeInteraction(active2, event.requestId, event.reason);
22435
23105
  return;
22436
23106
  case "tool.started":
22437
- this.#completeReasoning(active, { status: "succeeded" });
22438
- this.#completeAgentItem(active, { status: "succeeded" }, false);
22439
- this.#startTool(active, event);
23107
+ this.#completeReasoning(active2, { status: "succeeded" });
23108
+ this.#completeAgentItem(active2, { status: "succeeded" }, false);
23109
+ this.#startTool(active2, event);
22440
23110
  return;
22441
23111
  case "tool.updated":
22442
- this.#updateTool(active, event);
23112
+ this.#updateTool(active2, event);
22443
23113
  return;
22444
23114
  case "tool.completed":
22445
- this.#completeTool(active, event);
23115
+ this.#completeTool(active2, event);
22446
23116
  return;
22447
23117
  case "subagent.started":
22448
23118
  {
22449
- const subagent = active.subagents.start(active.command.turnId, event);
23119
+ const subagent = active2.subagents.start(active2.command.turnId, event);
22450
23120
  this.#event({
22451
23121
  type: "subagent.state.changed",
22452
23122
  nativeSubagentId: subagent.nativeSubagentId ?? subagent.subagentId,
@@ -22456,7 +23126,7 @@ var OmpHarnessSession = class {
22456
23126
  return;
22457
23127
  case "subagent.updated":
22458
23128
  {
22459
- const subagent = active.subagents.update(active.command.turnId, event);
23129
+ const subagent = active2.subagents.update(active2.command.turnId, event);
22460
23130
  if (subagent) {
22461
23131
  this.#event({
22462
23132
  type: "subagent.state.changed",
@@ -22469,7 +23139,7 @@ var OmpHarnessSession = class {
22469
23139
  return;
22470
23140
  case "subagent.completed":
22471
23141
  {
22472
- const subagent = active.subagents.complete(active.command.turnId, event, active.cancellationRequested);
23142
+ const subagent = active2.subagents.complete(active2.command.turnId, event, active2.cancellationRequested);
22473
23143
  this.#event({
22474
23144
  type: "subagent.state.changed",
22475
23145
  nativeSubagentId: subagent.nativeSubagentId ?? subagent.subagentId,
@@ -22485,8 +23155,8 @@ var OmpHarnessSession = class {
22485
23155
  });
22486
23156
  }
22487
23157
  }
22488
- #startInteraction(active, request) {
22489
- if (active.interactionByNativeId.has(request.requestId)) {
23158
+ #startInteraction(active2, request) {
23159
+ if (active2.interactionByNativeId.has(request.requestId)) {
22490
23160
  throw new Error("Omp Interaction started more than once");
22491
23161
  }
22492
23162
  const interactionId = hostInteractionIdSchema.parse(randomUUID2());
@@ -22495,7 +23165,7 @@ var OmpHarnessSession = class {
22495
23165
  interaction = {
22496
23166
  type: "approval",
22497
23167
  interactionId,
22498
- turnId: active.command.turnId,
23168
+ turnId: active2.command.turnId,
22499
23169
  title: request.title,
22500
23170
  subject: { type: "nativeAction" },
22501
23171
  actions: [
@@ -22538,49 +23208,49 @@ var OmpHarnessSession = class {
22538
23208
  ...request.method === "input" && request.placeholder ? { placeholder: request.placeholder } : {},
22539
23209
  ...request.method === "editor" && request.prefill ? { prefill: request.prefill } : {}
22540
23210
  };
22541
- 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;
22542
23212
  interaction = {
22543
23213
  type: "question",
22544
23214
  interactionId,
22545
- turnId: active.command.turnId,
23215
+ turnId: active2.command.turnId,
22546
23216
  ...associatedTool ? { itemId: associatedTool.item.itemId } : {},
22547
23217
  title: "OMP",
22548
23218
  questions: [question],
22549
23219
  ...request.timeoutMs !== void 0 ? { expiresAt: new Date(Date.now() + request.timeoutMs).toISOString() } : {}
22550
23220
  };
22551
23221
  }
22552
- active.interactions.set(interactionId, { interaction, nativeRequest: request });
22553
- active.interactionByNativeId.set(request.requestId, interactionId);
23222
+ active2.interactions.set(interactionId, { interaction, nativeRequest: request });
23223
+ active2.interactionByNativeId.set(request.requestId, interactionId);
22554
23224
  this.#channel.emit({ kind: "interaction", interaction });
22555
23225
  }
22556
- #closeInteraction(active, nativeRequestId, reason) {
22557
- const interactionId = active.interactionByNativeId.get(nativeRequestId);
23226
+ #closeInteraction(active2, nativeRequestId, reason) {
23227
+ const interactionId = active2.interactionByNativeId.get(nativeRequestId);
22558
23228
  if (!interactionId)
22559
23229
  throw new Error("Omp Interaction close references an unknown request");
22560
- active.interactionByNativeId.delete(nativeRequestId);
22561
- active.interactions.delete(interactionId);
23230
+ active2.interactionByNativeId.delete(nativeRequestId);
23231
+ active2.interactions.delete(interactionId);
22562
23232
  this.#event({
22563
23233
  type: "interaction.closed",
22564
23234
  interactionId,
22565
- turnId: active.command.turnId,
23235
+ turnId: active2.command.turnId,
22566
23236
  reason
22567
23237
  });
22568
23238
  }
22569
- #startCompaction(active) {
22570
- if (active.compactionItem)
23239
+ #startCompaction(active2) {
23240
+ if (active2.compactionItem)
22571
23241
  throw new Error("Omp Compaction started more than once");
22572
23242
  const item = {
22573
23243
  type: "contextCompaction",
22574
23244
  itemId: this.#newItemId()
22575
23245
  };
22576
- active.compactionItem = item;
22577
- 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 });
22578
23248
  }
22579
- #completeCompaction(active, event) {
22580
- const item = active.compactionItem;
23249
+ #completeCompaction(active2, event) {
23250
+ const item = active2.compactionItem;
22581
23251
  if (!item)
22582
23252
  throw new Error("Omp Compaction completed without starting");
22583
- active.compactionItem = null;
23253
+ active2.compactionItem = null;
22584
23254
  const outcome = event.outcome === "succeeded" ? { status: "succeeded" } : event.outcome === "cancelled" ? { status: "cancelled", reason: "Context compaction was cancelled" } : {
22585
23255
  status: "failed",
22586
23256
  error: {
@@ -22589,87 +23259,87 @@ var OmpHarnessSession = class {
22589
23259
  retryable: true
22590
23260
  }
22591
23261
  };
22592
- this.#completeItem(active, item, outcome);
23262
+ this.#completeItem(active2, item, outcome);
22593
23263
  if (event.outcome === "succeeded")
22594
- void this.#refreshUsage(active.command.turnId);
23264
+ void this.#refreshUsage(active2.command.turnId);
22595
23265
  }
22596
- #activateAgentMessage(active, messageId) {
22597
- if (active.agentMessageId === messageId)
23266
+ #activateAgentMessage(active2, messageId) {
23267
+ if (active2.agentMessageId === messageId)
22598
23268
  return;
22599
- if (active.agentMessageId !== null) {
22600
- this.#completeReasoning(active, { status: "succeeded" });
22601
- this.#completeAgentItem(active, { status: "succeeded" }, false);
23269
+ if (active2.agentMessageId !== null) {
23270
+ this.#completeReasoning(active2, { status: "succeeded" });
23271
+ this.#completeAgentItem(active2, { status: "succeeded" }, false);
22602
23272
  }
22603
- if (!active.agentItem) {
22604
- active.agentItem = {
23273
+ if (!active2.agentItem) {
23274
+ active2.agentItem = {
22605
23275
  type: "agentMessage",
22606
23276
  itemId: this.#newItemId(),
22607
23277
  text: ""
22608
23278
  };
22609
23279
  this.#event({
22610
23280
  type: "item.started",
22611
- turnId: active.command.turnId,
22612
- item: active.agentItem
23281
+ turnId: active2.command.turnId,
23282
+ item: active2.agentItem
22613
23283
  });
22614
23284
  }
22615
- active.agentMessageId = messageId;
22616
- active.sawAssistantMessage = true;
23285
+ active2.agentMessageId = messageId;
23286
+ active2.sawAssistantMessage = true;
22617
23287
  }
22618
- #appendText(active, text) {
22619
- if (active.agentMessageId === null || !active.agentItem) {
23288
+ #appendText(active2, text) {
23289
+ if (active2.agentMessageId === null || !active2.agentItem) {
22620
23290
  throw new Error("Omp Assistant text arrived outside an active message");
22621
23291
  }
22622
- active.agentItem = { ...active.agentItem, text: active.agentItem.text + text };
23292
+ active2.agentItem = { ...active2.agentItem, text: active2.agentItem.text + text };
22623
23293
  this.#event({
22624
23294
  type: "item.updated",
22625
- turnId: active.command.turnId,
22626
- itemId: active.agentItem.itemId,
23295
+ turnId: active2.command.turnId,
23296
+ itemId: active2.agentItem.itemId,
22627
23297
  update: { type: "text.append", text }
22628
23298
  });
22629
23299
  }
22630
- #completeAgentItem(active, outcome, completeEmpty) {
22631
- active.agentMessageId = null;
22632
- const item = active.agentItem;
23300
+ #completeAgentItem(active2, outcome, completeEmpty) {
23301
+ active2.agentMessageId = null;
23302
+ const item = active2.agentItem;
22633
23303
  if (!item || !completeEmpty && item.text.length === 0)
22634
23304
  return;
22635
- active.agentItem = null;
22636
- this.#completeItem(active, item, outcome);
23305
+ active2.agentItem = null;
23306
+ this.#completeItem(active2, item, outcome);
22637
23307
  }
22638
- #appendReasoning(active, text) {
23308
+ #appendReasoning(active2, text) {
22639
23309
  if (text.length === 0)
22640
23310
  return;
22641
- if (!active.reasoningItem) {
22642
- active.reasoningItem = {
23311
+ if (!active2.reasoningItem) {
23312
+ active2.reasoningItem = {
22643
23313
  type: "reasoning",
22644
23314
  itemId: this.#newItemId(),
22645
23315
  text: ""
22646
23316
  };
22647
23317
  this.#event({
22648
23318
  type: "item.started",
22649
- turnId: active.command.turnId,
22650
- item: active.reasoningItem
23319
+ turnId: active2.command.turnId,
23320
+ item: active2.reasoningItem
22651
23321
  });
22652
23322
  }
22653
- active.reasoningItem = {
22654
- ...active.reasoningItem,
22655
- text: active.reasoningItem.text + text
23323
+ active2.reasoningItem = {
23324
+ ...active2.reasoningItem,
23325
+ text: active2.reasoningItem.text + text
22656
23326
  };
22657
23327
  this.#event({
22658
23328
  type: "item.updated",
22659
- turnId: active.command.turnId,
22660
- itemId: active.reasoningItem.itemId,
23329
+ turnId: active2.command.turnId,
23330
+ itemId: active2.reasoningItem.itemId,
22661
23331
  update: { type: "text.append", text }
22662
23332
  });
22663
23333
  }
22664
- #completeReasoning(active, outcome) {
22665
- const item = active.reasoningItem;
23334
+ #completeReasoning(active2, outcome) {
23335
+ const item = active2.reasoningItem;
22666
23336
  if (!item)
22667
23337
  return;
22668
- active.reasoningItem = null;
22669
- this.#completeItem(active, item, outcome);
23338
+ active2.reasoningItem = null;
23339
+ this.#completeItem(active2, item, outcome);
22670
23340
  }
22671
- #startTool(active, event) {
22672
- if (active.tools.has(event.callId))
23341
+ #startTool(active2, event) {
23342
+ if (active2.tools.has(event.callId))
22673
23343
  throw new Error("Omp Tool started more than once");
22674
23344
  const item = projectOmpToolItem({
22675
23345
  itemId: this.#newItemId(),
@@ -22677,16 +23347,16 @@ var OmpHarnessSession = class {
22677
23347
  arguments: event.arguments,
22678
23348
  cwd: stringField2(event.arguments, "cwd") ?? this.#cwd
22679
23349
  });
22680
- active.tools.set(event.callId, {
23350
+ active2.tools.set(event.callId, {
22681
23351
  item,
22682
23352
  nativeName: event.toolName,
22683
23353
  arguments: event.arguments,
22684
23354
  startedAtMs: Date.now()
22685
23355
  });
22686
- this.#event({ type: "item.started", turnId: active.command.turnId, item });
23356
+ this.#event({ type: "item.started", turnId: active2.command.turnId, item });
22687
23357
  }
22688
- #updateTool(active, event) {
22689
- const tool = active.tools.get(event.callId);
23358
+ #updateTool(active2, event) {
23359
+ const tool = active2.tools.get(event.callId);
22690
23360
  if (!tool)
22691
23361
  throw new Error("Omp Tool update references an unknown Tool Call");
22692
23362
  const output = boundedOutput(event.output, this.#toolOutputLimit);
@@ -22704,19 +23374,19 @@ var OmpHarnessSession = class {
22704
23374
  if (delta.length > 0) {
22705
23375
  this.#event({
22706
23376
  type: "item.updated",
22707
- turnId: active.command.turnId,
23377
+ turnId: active2.command.turnId,
22708
23378
  itemId: tool.item.itemId,
22709
23379
  update: { type: "output.append", text: delta }
22710
23380
  });
22711
23381
  }
22712
23382
  }
22713
23383
  }
22714
- #completeTool(active, event) {
22715
- const tool = active.tools.get(event.callId);
23384
+ #completeTool(active2, event) {
23385
+ const tool = active2.tools.get(event.callId);
22716
23386
  if (!tool || tool.nativeName !== event.toolName) {
22717
23387
  throw new Error("Omp Tool completion references an unknown Tool Call");
22718
23388
  }
22719
- active.tools.delete(event.callId);
23389
+ active2.tools.delete(event.callId);
22720
23390
  const durationMs = Math.max(0, Date.now() - tool.startedAtMs);
22721
23391
  const output = boundedOutput(event.result, this.#toolOutputLimit);
22722
23392
  const exitCode = numberField(event.result, "exitCode");
@@ -22729,8 +23399,8 @@ var OmpHarnessSession = class {
22729
23399
  ...exitCode !== void 0 ? { exitCode } : {},
22730
23400
  durationMs
22731
23401
  };
22732
- const outcome = active.cancellationRequested ? { status: "cancelled", reason: "Cancelled by user" } : event.isError ? { status: "failed", error: toolFailure(event.toolName) } : { status: "succeeded" };
22733
- 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);
22734
23404
  if (!event.isError) {
22735
23405
  try {
22736
23406
  const kind = fileMutatingKind(event.toolName);
@@ -22746,30 +23416,30 @@ var OmpHarnessSession = class {
22746
23416
  sourceItemIds: [tool.item.itemId],
22747
23417
  changes
22748
23418
  };
22749
- this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
22750
- 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" });
22751
23421
  }
22752
23422
  } catch {
22753
23423
  }
22754
23424
  }
22755
23425
  }
22756
- #completeItem(active, item, outcome) {
23426
+ #completeItem(active2, item, outcome) {
22757
23427
  this.#event({
22758
23428
  type: "item.completed",
22759
- turnId: active.command.turnId,
23429
+ turnId: active2.command.turnId,
22760
23430
  snapshot: { item, outcome }
22761
23431
  });
22762
23432
  }
22763
- async #completedTurnIdentity(active, transport) {
22764
- active.acceptingSteers = false;
22765
- await Promise.allSettled([...active.pendingSteers]);
22766
- 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();
22767
23437
  const snapshot = mapOmpSnapshot(history, {
22768
23438
  sessionId: transport.state.sessionId,
22769
23439
  model: nativeModelForHistory(transport.state)
22770
23440
  });
22771
- const created = snapshot.turns.filter((turn2) => !active.beforeNativeTurnKeys.has(turn2.nativeTurnRef.nativeTurnKey));
22772
- const expected = 1 + active.acceptedSteerCount;
23441
+ const created = snapshot.turns.filter((turn2) => !active2.beforeNativeTurnKeys.has(turn2.nativeTurnRef.nativeTurnKey));
23442
+ const expected = 1 + active2.acceptedSteerCount;
22773
23443
  if (created.length !== expected) {
22774
23444
  const countText = expected === 1 ? "one" : `${expected}`;
22775
23445
  throw new Error(`Omp Turn persisted ${created.length} new User Entries; exactly ${countText} is required`);
@@ -22779,49 +23449,49 @@ var OmpHarnessSession = class {
22779
23449
  throw new Error("Omp Turn has no terminal Checkpoint identity");
22780
23450
  return { nativeTurnRef: turn.nativeTurnRef, checkpoint: turn.checkpoint };
22781
23451
  }
22782
- #completeTurn(active, outcome, finalText, nativeTurnRef, ephemeral) {
22783
- if (this.#active !== active)
23452
+ #completeTurn(active2, outcome, finalText, nativeTurnRef, ephemeral) {
23453
+ if (this.#active !== active2)
22784
23454
  return;
22785
23455
  this.#active = null;
22786
23456
  const itemOutcome2 = outcome.status === "failed" ? { status: "failed", error: outcome.error } : outcome.status === "cancelled" ? { status: "cancelled", ...outcome.reason ? { reason: outcome.reason } : {} } : { status: "succeeded" };
22787
- this.#completeReasoning(active, itemOutcome2);
22788
- if (active.compactionItem) {
22789
- this.#completeItem(active, active.compactionItem, itemOutcome2);
22790
- active.compactionItem = null;
23457
+ this.#completeReasoning(active2, itemOutcome2);
23458
+ if (active2.compactionItem) {
23459
+ this.#completeItem(active2, active2.compactionItem, itemOutcome2);
23460
+ active2.compactionItem = null;
22791
23461
  }
22792
- for (const interactionId of active.interactions.keys()) {
23462
+ for (const interactionId of active2.interactions.keys()) {
22793
23463
  this.#event({
22794
23464
  type: "interaction.closed",
22795
23465
  interactionId,
22796
- turnId: active.command.turnId,
23466
+ turnId: active2.command.turnId,
22797
23467
  reason: outcome.status === "cancelled" ? "cancelled" : "superseded"
22798
23468
  });
22799
23469
  }
22800
- active.interactions.clear();
22801
- active.interactionByNativeId.clear();
22802
- for (const tool of active.tools.values())
22803
- this.#completeItem(active, tool.item, itemOutcome2);
22804
- active.tools.clear();
22805
- active.subagents.finalize(active.command.turnId, itemOutcome2);
22806
- if (!active.sawAssistantMessage && finalText !== void 0 && active.agentItem) {
22807
- 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 };
22808
23478
  }
22809
- this.#completeAgentItem(active, itemOutcome2, true);
23479
+ this.#completeAgentItem(active2, itemOutcome2, true);
22810
23480
  this.#event({
22811
23481
  type: "turn.completed",
22812
- turnId: active.command.turnId,
23482
+ turnId: active2.command.turnId,
22813
23483
  outcome,
22814
23484
  ...nativeTurnRef ? { nativeTurnRef } : {},
22815
23485
  ...ephemeral ? { ephemeral } : {}
22816
23486
  });
22817
- active.resolveCompletion();
22818
- if (active.steerFailure) {
22819
- this.#fault(active.steerFailure);
23487
+ active2.resolveCompletion();
23488
+ if (active2.steerFailure) {
23489
+ this.#fault(active2.steerFailure);
22820
23490
  return;
22821
23491
  }
22822
23492
  queueMicrotask(() => {
22823
23493
  if (this.#phase === "open")
22824
- void this.#refreshUsage(active.command.turnId);
23494
+ void this.#refreshUsage(active2.command.turnId);
22825
23495
  });
22826
23496
  }
22827
23497
  #fault(error51) {
@@ -22842,11 +23512,11 @@ var OmpHarnessSession = class {
22842
23512
  if (!wasFaulted)
22843
23513
  this.#phase = "closing";
22844
23514
  const transport = this.#transport ?? (this.#starting ? await this.#starting.catch(() => null) : null);
22845
- const active = this.#active;
22846
- if (transport && active) {
22847
- active.cancellationRequested = true;
23515
+ const active2 = this.#active;
23516
+ if (transport && active2) {
23517
+ active2.cancellationRequested = true;
22848
23518
  await transport.abort().catch(() => void 0);
22849
- await Promise.race([active.completion, delay(this.#closeTimeoutMs)]);
23519
+ await Promise.race([active2.completion, delay(this.#closeTimeoutMs)]);
22850
23520
  }
22851
23521
  try {
22852
23522
  if (transport)
@@ -22873,6 +23543,7 @@ var OmpHarnessSession = class {
22873
23543
  }
22874
23544
  };
22875
23545
  var OmpAdapter = class {
23546
+ normalizeStoredModelRef = normalizeStoredOmpModelRef;
22876
23547
  commandCatalog = ompCommandCatalog;
22877
23548
  liveCommandCatalog = true;
22878
23549
  harnessId = ompHarnessId2;
@@ -22956,16 +23627,25 @@ var OmpAdapter = class {
22956
23627
  if (this.#closePromise)
22957
23628
  return closedInspection();
22958
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
+ }
22959
23641
  const inFlight = this.#inspectionInFlight.get(cwd);
22960
23642
  if (inFlight)
22961
23643
  return inFlight;
22962
- if (!input.refresh) {
22963
- const cached2 = this.#inspectionCache.get(cwd);
22964
- if (cached2)
22965
- return cached2;
22966
- }
23644
+ const cached2 = this.#inspectionCache.get(cwd);
23645
+ if (cached2)
23646
+ return cached2;
22967
23647
  if (input.purpose === "availability")
22968
- return this.#inspectAvailability(cwd, input.refresh);
23648
+ return this.#inspectAvailability(cwd);
22969
23649
  return this.#startFullInspection(cwd);
22970
23650
  }
22971
23651
  /**
@@ -22975,9 +23655,7 @@ var OmpAdapter = class {
22975
23655
  * update `#thinkingSelectionSupported`. When the list cannot answer, a full inspection answers
22976
23656
  * instead, reusing one that is in flight or finished meanwhile.
22977
23657
  */
22978
- async #inspectAvailability(cwd, refresh = false) {
22979
- if (refresh)
22980
- this.#inspectionCache.delete(cwd);
23658
+ async #inspectAvailability(cwd) {
22981
23659
  let pending = this.#availabilityInFlight.get(cwd);
22982
23660
  if (!pending) {
22983
23661
  const listing = this.#listAvailability(cwd);
@@ -22996,8 +23674,10 @@ var OmpAdapter = class {
22996
23674
  }
22997
23675
  #startFullInspection(cwd) {
22998
23676
  const inspection = this.#inspectCwd(cwd).then((result) => {
22999
- if (result.status === "ready")
23677
+ if (result.status === "ready" && this.#inspectionInFlight.get(cwd) === inspection) {
23000
23678
  this.#inspectionCache.set(cwd, result);
23679
+ this.#thinkingSelectionSupported = result.capabilities.configuration.selectThinkingOption;
23680
+ }
23001
23681
  return result;
23002
23682
  });
23003
23683
  this.#inspectionInFlight.set(cwd, inspection);
@@ -23076,7 +23756,6 @@ var OmpAdapter = class {
23076
23756
  const models = await transport.getAvailableModels();
23077
23757
  stage = "capabilities";
23078
23758
  const thinkingLevels = await transport.getAvailableThinkingLevels();
23079
- this.#thinkingSelectionSupported = thinkingLevels !== null;
23080
23759
  const catalog = normalizeOmpModelCatalog(models, nativeModelFromState(transport.state), thinkingLevels, transport.state.thinkingLevel);
23081
23760
  await transport.close();
23082
23761
  return {
@@ -23129,10 +23808,12 @@ var OmpAdapter = class {
23129
23808
  return { ok: false, error: normalizedError(error51, "invalidRequest") };
23130
23809
  }
23131
23810
  if (input.model) {
23132
- try {
23133
- decodeOmpModelRef(input.model);
23134
- } catch (error51) {
23135
- 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
+ };
23136
23817
  }
23137
23818
  }
23138
23819
  const thinkingOptionId = input.thinkingOptionId ? harnessThinkingOptionIdSchema.safeParse(input.thinkingOptionId) : null;
@@ -23249,6 +23930,7 @@ var OmpAdapter = class {
23249
23930
  usageHistory,
23250
23931
  ...input.environment ? { environment: input.environment } : {},
23251
23932
  startedTransport: transport,
23933
+ startedModels: await transport.getAvailableModels(),
23252
23934
  startedThinkingLevels,
23253
23935
  initialUsage,
23254
23936
  supportsThinkingSelection: startedThinkingLevels !== null,
@@ -23285,6 +23967,7 @@ var OmpAdapter = class {
23285
23967
  permissionMode: options.permissionMode,
23286
23968
  permissionModeId: options.permissionModeId,
23287
23969
  ...options.startedTransport ? { startedTransport: options.startedTransport } : {},
23970
+ ...options.startedModels ? { startedModels: options.startedModels } : {},
23288
23971
  ...options.startedThinkingLevels !== void 0 ? { startedThinkingLevels: options.startedThinkingLevels } : {},
23289
23972
  ...options.initialUsage !== void 0 ? { initialUsage: options.initialUsage } : {},
23290
23973
  ...options.usageHistory ? { usageHistory: options.usageHistory } : {}