@liberseek/boft-cli-win32-arm64 0.6.1 → 0.6.3

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.
@@ -5002,6 +5002,9 @@ function parseModelProviderAuth(source) {
5002
5002
  const tables = tomlProviderTableNames(providerId);
5003
5003
  let currentTable = "";
5004
5004
  let name;
5005
+ let baseUrl;
5006
+ let bearerToken;
5007
+ let envKey;
5005
5008
  let requiresOpenAiAuth;
5006
5009
  let hasLocalApiCredential = false;
5007
5010
  for (const rawLine of source.split(/\r?\n/u)) {
@@ -5018,14 +5021,23 @@ function parseModelProviderAuth(source) {
5018
5021
  const key = assignment[1] ?? "";
5019
5022
  const value2 = tomlUnquote(assignment[2] ?? "");
5020
5023
  if (key === "name" && value2) name = value2;
5024
+ if (key === "base_url" && value2) baseUrl = value2;
5021
5025
  if (key === "requires_openai_auth") requiresOpenAiAuth = tomlBoolean(value2);
5022
- if ((key === "experimental_bearer_token" || key === "env_key") && value2.trim().length > 0) {
5026
+ if (key === "experimental_bearer_token" && value2.trim().length > 0) {
5027
+ bearerToken = value2.trim();
5028
+ hasLocalApiCredential = true;
5029
+ }
5030
+ if (key === "env_key" && value2.trim().length > 0) {
5031
+ envKey = value2.trim();
5023
5032
  hasLocalApiCredential = true;
5024
5033
  }
5025
5034
  }
5026
5035
  return {
5027
5036
  id: providerId,
5028
5037
  ...name ? { name } : {},
5038
+ ...baseUrl ? { baseUrl } : {},
5039
+ ...bearerToken ? { bearerToken } : {},
5040
+ ...envKey ? { envKey } : {},
5029
5041
  requiresOpenAiAuth: requiresOpenAiAuth ?? providerId === "openai",
5030
5042
  hasLocalApiCredential
5031
5043
  };
@@ -5069,6 +5081,24 @@ async function readOptionalUtf8(file2) {
5069
5081
  throw error51;
5070
5082
  }
5071
5083
  }
5084
+ function authJsonApiKey(authJson) {
5085
+ if (!authJson) return void 0;
5086
+ try {
5087
+ const auth = JSON.parse(authJson);
5088
+ return typeof auth.api_key === "string" && auth.api_key.trim() ? auth.api_key.trim() : void 0;
5089
+ } catch {
5090
+ return void 0;
5091
+ }
5092
+ }
5093
+ function inspectCodexApiUsageSource(input) {
5094
+ const provider = parseModelProviderAuth(input.configToml);
5095
+ const baseUrl = provider?.baseUrl?.trim();
5096
+ if (!baseUrl) return null;
5097
+ const env = input.env ?? process.env;
5098
+ const apiKey = provider?.bearerToken?.trim() || authJsonApiKey(input.authJson) || (provider?.envKey ? env[provider.envKey]?.trim() : void 0);
5099
+ if (!apiKey) return null;
5100
+ return { baseUrl, apiKey };
5101
+ }
5072
5102
  async function inspectCodexHomeAuth(codexHome) {
5073
5103
  const root = path4.resolve(codexHome);
5074
5104
  const [configToml, authJson] = await Promise.all([
@@ -5080,6 +5110,87 @@ async function inspectCodexHomeAuth(codexHome) {
5080
5110
  ...authJson ? { authJson } : {}
5081
5111
  });
5082
5112
  }
5113
+ async function inspectCodexHomeApiUsageSource(codexHome, env = process.env) {
5114
+ const root = path4.resolve(codexHome);
5115
+ const [configToml, authJson] = await Promise.all([
5116
+ readOptionalUtf8(path4.join(root, "config.toml")),
5117
+ readOptionalUtf8(path4.join(root, "auth.json"))
5118
+ ]);
5119
+ return inspectCodexApiUsageSource({
5120
+ ...configToml ? { configToml } : {},
5121
+ ...authJson ? { authJson } : {},
5122
+ env
5123
+ });
5124
+ }
5125
+
5126
+ // packages/host-runtime/src/account/codex-api-usage.ts
5127
+ var REQUEST_TIMEOUT_MS = 15e3;
5128
+ function isRecord(value2) {
5129
+ return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
5130
+ }
5131
+ function finiteNumber(value2) {
5132
+ if (typeof value2 === "number" && Number.isFinite(value2)) return value2;
5133
+ if (typeof value2 === "string" && value2.trim()) {
5134
+ const parsed = Number(value2);
5135
+ if (Number.isFinite(parsed)) return parsed;
5136
+ }
5137
+ return void 0;
5138
+ }
5139
+ function text(value2) {
5140
+ return typeof value2 === "string" && value2.trim() ? value2.trim() : void 0;
5141
+ }
5142
+ function boolean(value2) {
5143
+ return typeof value2 === "boolean" ? value2 : void 0;
5144
+ }
5145
+ function codexApiUsageUrl(baseUrl) {
5146
+ const trimmed = baseUrl.trim().replace(/\/+$/u, "");
5147
+ if (!trimmed) throw new Error("Codex API usage base URL is empty");
5148
+ const withPath = /\/v1$/iu.test(trimmed) ? `${trimmed}/usage` : `${trimmed}/v1/usage`;
5149
+ const parsed = new URL(withPath);
5150
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
5151
+ throw new Error("Codex API usage URL must be http or https");
5152
+ }
5153
+ return parsed.toString();
5154
+ }
5155
+ function extractCodexApiUsage(response) {
5156
+ if (!isRecord(response)) return null;
5157
+ const quota = isRecord(response.quota) ? response.quota : void 0;
5158
+ const remaining = finiteNumber(response.remaining) ?? finiteNumber(quota?.remaining) ?? finiteNumber(response.balance);
5159
+ if (remaining === void 0) return null;
5160
+ const isValid = boolean(response.is_active) ?? boolean(response.isValid) ?? true;
5161
+ if (!isValid) throw new Error("Codex API usage is inactive");
5162
+ return {
5163
+ remaining,
5164
+ unit: text(response.unit) ?? text(quota?.unit) ?? "USD"
5165
+ };
5166
+ }
5167
+ function projectCodexApiUsageToCredits(usage) {
5168
+ return {
5169
+ remaining: usage.remaining,
5170
+ unit: usage.unit,
5171
+ periodType: "unknown"
5172
+ };
5173
+ }
5174
+ async function inspectCodexApiAccountCredits(codexHome, input = {}) {
5175
+ const source = input.source === void 0 ? await inspectCodexHomeApiUsageSource(codexHome, input.env) : input.source;
5176
+ if (!source) return null;
5177
+ const fetchImpl = input.fetch ?? fetch;
5178
+ const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
5179
+ const signal = input.signal ? AbortSignal.any([input.signal, timeout]) : timeout;
5180
+ const response = await fetchImpl(codexApiUsageUrl(source.baseUrl), {
5181
+ method: "GET",
5182
+ headers: {
5183
+ Accept: "application/json",
5184
+ Authorization: `Bearer ${source.apiKey}`
5185
+ },
5186
+ signal
5187
+ });
5188
+ if (!response.ok) {
5189
+ throw new Error(`Codex API usage request failed (${response.status})`);
5190
+ }
5191
+ const usage = extractCodexApiUsage(await response.json());
5192
+ return usage ? projectCodexApiUsageToCredits(usage) : null;
5193
+ }
5083
5194
 
5084
5195
  // node_modules/zod/v4/classic/external.js
5085
5196
  var external_exports = {};
@@ -5174,7 +5285,7 @@ __export(external_exports, {
5174
5285
  base64: () => base642,
5175
5286
  base64url: () => base64url2,
5176
5287
  bigint: () => bigint2,
5177
- boolean: () => boolean2,
5288
+ boolean: () => boolean3,
5178
5289
  catch: () => _catch2,
5179
5290
  check: () => check,
5180
5291
  cidrv4: () => cidrv42,
@@ -6609,7 +6720,7 @@ __export(regexes_exports, {
6609
6720
  base64: () => base64,
6610
6721
  base64url: () => base64url,
6611
6722
  bigint: () => bigint,
6612
- boolean: () => boolean,
6723
+ boolean: () => boolean2,
6613
6724
  browserEmail: () => browserEmail,
6614
6725
  cidrv4: () => cidrv4,
6615
6726
  cidrv6: () => cidrv6,
@@ -6734,7 +6845,7 @@ var string = (params) => {
6734
6845
  var bigint = /^-?\d+n?$/;
6735
6846
  var integer = /^-?\d+$/;
6736
6847
  var number = /^-?\d+(?:\.\d+)?$/;
6737
- var boolean = /^(?:true|false)$/i;
6848
+ var boolean2 = /^(?:true|false)$/i;
6738
6849
  var _null = /^null$/i;
6739
6850
  var _undefined = /^undefined$/i;
6740
6851
  var lowercase = /^[^A-Z]*$/;
@@ -7820,7 +7931,7 @@ var $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumberFormat", (inst, d
7820
7931
  });
7821
7932
  var $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
7822
7933
  $ZodType.init(inst, def);
7823
- inst._zod.pattern = boolean;
7934
+ inst._zod.pattern = boolean2;
7824
7935
  inst._zod.parse = (payload, _ctx) => {
7825
7936
  if (def.coerce)
7826
7937
  try {
@@ -12719,8 +12830,8 @@ function ko_default() {
12719
12830
  }
12720
12831
 
12721
12832
  // node_modules/zod/v4/locales/lt.js
12722
- var capitalizeFirstCharacter = (text) => {
12723
- return text.charAt(0).toUpperCase() + text.slice(1);
12833
+ var capitalizeFirstCharacter = (text2) => {
12834
+ return text2.charAt(0).toUpperCase() + text2.slice(1);
12724
12835
  };
12725
12836
  function getUnitTypeFromNumber(number4) {
12726
12837
  const abs = Math.abs(number4);
@@ -17551,7 +17662,7 @@ __export(schemas_exports2, {
17551
17662
  base64: () => base642,
17552
17663
  base64url: () => base64url2,
17553
17664
  bigint: () => bigint2,
17554
- boolean: () => boolean2,
17665
+ boolean: () => boolean3,
17555
17666
  catch: () => _catch2,
17556
17667
  check: () => check,
17557
17668
  cidrv4: () => cidrv42,
@@ -18294,7 +18405,7 @@ var ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
18294
18405
  ZodType.init(inst, def);
18295
18406
  inst._zod.processJSONSchema = (ctx, json2, params) => booleanProcessor(inst, ctx, json2, params);
18296
18407
  });
18297
- function boolean2(params) {
18408
+ function boolean3(params) {
18298
18409
  return _boolean(ZodBoolean, params);
18299
18410
  }
18300
18411
  var ZodBigInt = /* @__PURE__ */ $constructor("ZodBigInt", (inst, def) => {
@@ -19049,7 +19160,7 @@ var stringbool = (...args) => _stringbool({
19049
19160
  }, ...args);
19050
19161
  function json(params) {
19051
19162
  const jsonSchema = lazy(() => {
19052
- return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record2(string2(), jsonSchema)]);
19163
+ return union([string2(params), number2(), boolean3(), _null3(), array(jsonSchema), record2(string2(), jsonSchema)]);
19053
19164
  });
19054
19165
  return jsonSchema;
19055
19166
  }
@@ -19571,7 +19682,7 @@ function fromJSONSchema(schema, params) {
19571
19682
  var coerce_exports = {};
19572
19683
  __export(coerce_exports, {
19573
19684
  bigint: () => bigint3,
19574
- boolean: () => boolean3,
19685
+ boolean: () => boolean4,
19575
19686
  date: () => date4,
19576
19687
  number: () => number3,
19577
19688
  string: () => string3
@@ -19582,7 +19693,7 @@ function string3(params) {
19582
19693
  function number3(params) {
19583
19694
  return _coercedNumber(ZodNumber, params);
19584
19695
  }
19585
- function boolean3(params) {
19696
+ function boolean4(params) {
19586
19697
  return _coercedBoolean(ZodBoolean, params);
19587
19698
  }
19588
19699
  function bigint3(params) {
@@ -19621,6 +19732,8 @@ var threadUsageSnapshotSchema = external_exports.object({
19621
19732
  reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
19622
19733
  totalTokens: nonNegativeSafeIntegerSchema.optional(),
19623
19734
  totalCostUsd: finiteNonNegativeNumberSchema.optional(),
19735
+ totalCredits: finiteNonNegativeNumberSchema.optional(),
19736
+ contextUsagePercent: finiteNonNegativeNumberSchema.optional(),
19624
19737
  cacheHitRatePercent: cacheHitRatePercentSchema.optional(),
19625
19738
  contextWindowTokens: nonNegativeSafeIntegerSchema.optional(),
19626
19739
  contextUsedTokens: nonNegativeSafeIntegerSchema.optional(),
@@ -19677,12 +19790,28 @@ var accountResetCreditsSchema = external_exports.object({
19677
19790
  var accountCreditsSnapshotSchema = external_exports.object({
19678
19791
  /** Native label when the primary limit is scoped to a model or product group. */
19679
19792
  label: external_exports.string().min(1).optional(),
19680
- usedPercent: usagePercentSchema,
19793
+ usedPercent: usagePercentSchema.optional(),
19794
+ remaining: external_exports.number().finite().optional(),
19795
+ unit: external_exports.string().trim().min(1).max(32).optional(),
19681
19796
  resetsAt: external_exports.string().min(1).optional(),
19682
19797
  periodType: external_exports.enum(["weekly", "monthly", "five_hour", "seven_day", "unknown"]),
19683
19798
  productUsage: external_exports.array(accountCreditsProductUsageSchema).min(1).optional(),
19684
19799
  resetCredits: accountResetCreditsSchema.optional()
19685
- }).strict();
19800
+ }).strict().superRefine((credits, context) => {
19801
+ if (credits.usedPercent === void 0 && credits.remaining === void 0) {
19802
+ context.addIssue({
19803
+ code: "custom",
19804
+ message: "Account credits must include usedPercent or remaining"
19805
+ });
19806
+ }
19807
+ if (credits.remaining !== void 0 && !credits.unit) {
19808
+ context.addIssue({
19809
+ code: "custom",
19810
+ message: "Account remaining credits require a unit",
19811
+ path: ["unit"]
19812
+ });
19813
+ }
19814
+ });
19686
19815
  var threadUsageInspectionParamsSchema = external_exports.object({
19687
19816
  threadId: hostThreadIdSchema,
19688
19817
  refresh: external_exports.literal("exact").optional()
@@ -20540,13 +20669,15 @@ var usageFields = /* @__PURE__ */ new Set([
20540
20669
  ...tokenFields,
20541
20670
  ...safeIntegerFields,
20542
20671
  ...percentFields,
20543
- "totalCostUsd"
20672
+ "totalCostUsd",
20673
+ "totalCredits",
20674
+ "contextUsagePercent"
20544
20675
  ]);
20545
- function isRecord(value2) {
20676
+ function isRecord2(value2) {
20546
20677
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
20547
20678
  }
20548
20679
  function parseHostUsage(value2) {
20549
- if (!isRecord(value2))
20680
+ if (!isRecord2(value2))
20550
20681
  throw new Error("Harness Usage must be an object");
20551
20682
  const keys = Object.keys(value2);
20552
20683
  if (keys.length === 0)
@@ -20574,6 +20705,12 @@ function parseHostUsage(value2) {
20574
20705
  if (value2.totalCostUsd !== void 0 && (typeof value2.totalCostUsd !== "number" || !Number.isFinite(value2.totalCostUsd) || value2.totalCostUsd < 0)) {
20575
20706
  throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
20576
20707
  }
20708
+ for (const field of ["totalCredits", "contextUsagePercent"]) {
20709
+ const candidate = value2[field];
20710
+ if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
20711
+ throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
20712
+ }
20713
+ }
20577
20714
  for (const field of percentFields) {
20578
20715
  const candidate = value2[field];
20579
20716
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
@@ -21142,6 +21279,9 @@ var MappingStore = class {
21142
21279
  async setTitle(hostThreadId, title) {
21143
21280
  return this.#update(hostThreadId, (current) => ({ ...current, title }));
21144
21281
  }
21282
+ async setCwd(hostThreadId, cwd) {
21283
+ return this.#update(hostThreadId, (current) => current.cwd === cwd ? null : { ...current, cwd });
21284
+ }
21145
21285
  async setTransportModelId(hostThreadId, transportModelId) {
21146
21286
  return this.#update(hostThreadId, (current) => current.transportModelId === transportModelId ? null : { ...current, transportModelId });
21147
21287
  }
@@ -21448,24 +21588,24 @@ var TITLE_MAX_LENGTH = 150;
21448
21588
  var DESCRIPTION_MAX_LENGTH = 500;
21449
21589
  var SERVER_NAME_MAX_LENGTH = 80;
21450
21590
  var ELLIPSIS = "…";
21451
- function isRecord2(value2) {
21591
+ function isRecord3(value2) {
21452
21592
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
21453
21593
  }
21454
21594
  function boundedText(value2, field, maxLength) {
21455
- const text = value2.trim();
21456
- if (text.length === 0 || text.length > maxLength) {
21595
+ const text2 = value2.trim();
21596
+ if (text2.length === 0 || text2.length > maxLength) {
21457
21597
  throw new Error(`Host Approval ${field} must contain 1 to ${maxLength} characters`);
21458
21598
  }
21459
- return text;
21599
+ return text2;
21460
21600
  }
21461
21601
  function clampedText(value2, field, maxLength) {
21462
- const text = value2.trim();
21463
- if (text.length === 0) {
21602
+ const text2 = value2.trim();
21603
+ if (text2.length === 0) {
21464
21604
  throw new Error(`Host Approval ${field} must contain at least 1 character`);
21465
21605
  }
21466
- const characters = [...text];
21606
+ const characters = [...text2];
21467
21607
  if (characters.length <= maxLength)
21468
- return text;
21608
+ return text2;
21469
21609
  return `${characters.slice(0, maxLength - 1).join("").trimEnd()}${ELLIPSIS}`;
21470
21610
  }
21471
21611
  function actionsForEffect(interaction, effect) {
@@ -21502,7 +21642,7 @@ function responseError(message) {
21502
21642
  function responsePersist(value2) {
21503
21643
  if (value2 === void 0 || value2 === null)
21504
21644
  return null;
21505
- if (!isRecord2(value2) || Object.keys(value2).length !== 1 || value2.persist !== "session" && value2.persist !== "always") {
21645
+ if (!isRecord3(value2) || Object.keys(value2).length !== 1 || value2.persist !== "session" && value2.persist !== "always") {
21506
21646
  throw responseError("contains malformed persist metadata");
21507
21647
  }
21508
21648
  return value2.persist;
@@ -21513,9 +21653,16 @@ function projectCodexApprovalRequest(input) {
21513
21653
  throw new Error("Host Approval subject is unsupported");
21514
21654
  }
21515
21655
  validateActions(interaction);
21516
- const allow = requiredActionForEffect(interaction, "allowOnce");
21656
+ if (new Set(interaction.actions.map(({ effect }) => effect)).size !== interaction.actions.length) {
21657
+ return projectApprovalChoices(input);
21658
+ }
21659
+ const allowOnce = optionalActionForEffect(interaction, "allowOnce");
21517
21660
  const allowForSession = optionalActionForEffect(interaction, "allowForSession");
21518
21661
  const allowAlways = optionalActionForEffect(interaction, "allowAlways");
21662
+ const allow = allowOnce ?? allowForSession ?? allowAlways;
21663
+ if (!allow) {
21664
+ throw new Error("Host Approval must declare an allowOnce, allowForSession, or allowAlways action");
21665
+ }
21519
21666
  const deny = requiredActionForEffect(interaction, "deny");
21520
21667
  const serverName = boundedText(input.serverName, "server name", SERVER_NAME_MAX_LENGTH);
21521
21668
  const title = clampedText(interaction.title, "title", TITLE_MAX_LENGTH);
@@ -21545,7 +21692,7 @@ function projectCodexApprovalRequest(input) {
21545
21692
  },
21546
21693
  denyResponse,
21547
21694
  parseResponse(result) {
21548
- if (!isRecord2(result) || typeof result.action !== "string") {
21695
+ if (!isRecord3(result) || typeof result.action !== "string") {
21549
21696
  throw responseError("missing action");
21550
21697
  }
21551
21698
  if (Object.keys(result).some((key) => key !== "action" && key !== "content" && key !== "_meta")) {
@@ -21553,7 +21700,7 @@ function projectCodexApprovalRequest(input) {
21553
21700
  }
21554
21701
  const selectedPersist = responsePersist(result._meta);
21555
21702
  if (result.action === "accept") {
21556
- if ("content" in result && (!isRecord2(result.content) || Object.keys(result.content).length !== 0)) {
21703
+ if ("content" in result && (!isRecord3(result.content) || Object.keys(result.content).length !== 0)) {
21557
21704
  throw responseError("contains non-empty accepted content");
21558
21705
  }
21559
21706
  if (selectedPersist === "session") {
@@ -21578,9 +21725,66 @@ function projectCodexApprovalRequest(input) {
21578
21725
  }
21579
21726
  };
21580
21727
  }
21728
+ function projectApprovalChoices(input) {
21729
+ const { interaction } = input;
21730
+ const allow = actionsForEffect(interaction, "allowOnce")[0];
21731
+ const deny = actionsForEffect(interaction, "deny")[0];
21732
+ if (!allow || !deny)
21733
+ throw new Error("Host Approval must declare allowOnce and deny actions");
21734
+ const denyResponse = { type: "approval", actionId: deny.id };
21735
+ return {
21736
+ request: {
21737
+ method: "mcpServer/elicitation/request",
21738
+ params: {
21739
+ serverName: boundedText(input.serverName, "server name", SERVER_NAME_MAX_LENGTH),
21740
+ threadId: input.threadId,
21741
+ turnId: interaction.turnId,
21742
+ mode: "form",
21743
+ message: [
21744
+ clampedText(interaction.title, "title", TITLE_MAX_LENGTH),
21745
+ ...interaction.description ? [interaction.description] : []
21746
+ ].join("\n\n"),
21747
+ requestedSchema: {
21748
+ type: "object",
21749
+ properties: {
21750
+ actionId: {
21751
+ type: "string",
21752
+ title: "Approval",
21753
+ oneOf: interaction.actions.map(({ id: id2, label }) => ({ const: id2, title: label })),
21754
+ default: allow.id
21755
+ }
21756
+ },
21757
+ required: ["actionId"]
21758
+ }
21759
+ }
21760
+ },
21761
+ denyResponse,
21762
+ parseResponse(result) {
21763
+ if (!isRecord3(result) || typeof result.action !== "string")
21764
+ throw responseError("missing action");
21765
+ if (Object.keys(result).some((key) => !["action", "content", "_meta"].includes(key))) {
21766
+ throw responseError("contains unreviewed fields");
21767
+ }
21768
+ if (result._meta !== void 0 && result._meta !== null) {
21769
+ throw responseError("contains unexpected persist metadata");
21770
+ }
21771
+ if (result.action === "decline" || result.action === "cancel") {
21772
+ if (result.content !== void 0 && result.content !== null) {
21773
+ throw responseError("contains fields incompatible with denial");
21774
+ }
21775
+ return denyResponse;
21776
+ }
21777
+ const content = result.content;
21778
+ if (result.action !== "accept" || !isRecord3(content) || Object.keys(content).length !== 1 || !interaction.actions.some(({ id: id2 }) => id2 === content.actionId)) {
21779
+ throw responseError("contains an undeclared approval choice");
21780
+ }
21781
+ return { type: "approval", actionId: content.actionId };
21782
+ }
21783
+ };
21784
+ }
21581
21785
 
21582
21786
  // packages/protocol-core/dist/codex-question.js
21583
- function isRecord3(value2) {
21787
+ function isRecord4(value2) {
21584
21788
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
21585
21789
  }
21586
21790
  function responseError2(message) {
@@ -21649,7 +21853,7 @@ function projectCodexQuestionRequest(input) {
21649
21853
  }
21650
21854
  },
21651
21855
  parseResponse(result) {
21652
- if (!isRecord3(result) || !isRecord3(result.answers)) {
21856
+ if (!isRecord4(result) || !isRecord4(result.answers)) {
21653
21857
  throw responseError2("missing answers object");
21654
21858
  }
21655
21859
  const rawAnswers = result.answers;
@@ -21662,7 +21866,7 @@ function projectCodexQuestionRequest(input) {
21662
21866
  const question = interaction.questions.find(({ id: id2 }) => id2 === questionId);
21663
21867
  if (!question)
21664
21868
  throw responseError2("contains an unknown Question ID");
21665
- if (!isRecord3(answerValue) || !Array.isArray(answerValue.answers)) {
21869
+ if (!isRecord4(answerValue) || !Array.isArray(answerValue.answers)) {
21666
21870
  throw responseError2("answer entry has no answers array");
21667
21871
  }
21668
21872
  const values = answerValue.answers;
@@ -21747,7 +21951,7 @@ function projectCodexThreadUsage(input) {
21747
21951
  }
21748
21952
 
21749
21953
  // packages/protocol-core/dist/codex-native-usage.js
21750
- function isRecord4(value2) {
21954
+ function isRecord5(value2) {
21751
21955
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
21752
21956
  }
21753
21957
  function nonNegativeSafeInteger(value2) {
@@ -21777,20 +21981,20 @@ function addBreakdown(target, source) {
21777
21981
  }
21778
21982
  }
21779
21983
  function observeCodexTokenUsage(value2) {
21780
- if (!isRecord4(value2) || value2.method !== "thread/tokenUsage/updated")
21984
+ if (!isRecord5(value2) || value2.method !== "thread/tokenUsage/updated")
21781
21985
  return null;
21782
21986
  const params = value2.params;
21783
- if (!isRecord4(params))
21987
+ if (!isRecord5(params))
21784
21988
  return null;
21785
21989
  const threadId3 = hostThreadIdSchema.safeParse(params.threadId);
21786
21990
  const turnId = hostTurnIdSchema.safeParse(params.turnId);
21787
21991
  if (!threadId3.success || !turnId.success)
21788
21992
  return null;
21789
21993
  const tokenUsage = params.tokenUsage;
21790
- if (!isRecord4(tokenUsage))
21994
+ if (!isRecord5(tokenUsage))
21791
21995
  return null;
21792
- const total = isRecord4(tokenUsage.total) ? tokenUsage.total : void 0;
21793
- const last = isRecord4(tokenUsage.last) ? tokenUsage.last : void 0;
21996
+ const total = isRecord5(tokenUsage.total) ? tokenUsage.total : void 0;
21997
+ const last = isRecord5(tokenUsage.last) ? tokenUsage.last : void 0;
21794
21998
  const usage = {};
21795
21999
  addBreakdown(usage, total);
21796
22000
  const contextUsedTokens = nonNegativeSafeInteger(last?.totalTokens);
@@ -21815,7 +22019,7 @@ function observeCodexTokenUsage(value2) {
21815
22019
  }
21816
22020
  }
21817
22021
  function parseRateLimitWindow(value2) {
21818
- if (!isRecord4(value2))
22022
+ if (!isRecord5(value2))
21819
22023
  return null;
21820
22024
  const usedPercent = finitePercent(value2.usedPercent);
21821
22025
  const windowDurationMins = nonNegativeSafeInteger(value2.windowDurationMins);
@@ -21826,7 +22030,7 @@ function parseRateLimitWindow(value2) {
21826
22030
  return { usedPercent, windowDurationMins, ...resetsAt !== void 0 ? { resetsAt } : {} };
21827
22031
  }
21828
22032
  function parseRateLimitCandidate(value2, options2 = {}) {
21829
- if (!isRecord4(value2))
22033
+ if (!isRecord5(value2))
21830
22034
  return null;
21831
22035
  if (options2.genericOnly && value2.limitId !== void 0 && value2.limitId !== null && value2.limitId !== "codex") {
21832
22036
  return null;
@@ -21836,16 +22040,16 @@ function parseRateLimitCandidate(value2, options2 = {}) {
21836
22040
  return primary || secondary ? { primary, secondary } : null;
21837
22041
  }
21838
22042
  function rateLimitCandidates(value2) {
21839
- if (!isRecord4(value2))
22043
+ if (!isRecord5(value2))
21840
22044
  return [];
21841
- const result = isRecord4(value2.result) ? value2.result : value2;
21842
- if (!isRecord4(result))
22045
+ const result = isRecord5(value2.result) ? value2.result : value2;
22046
+ if (!isRecord5(result))
21843
22047
  return [];
21844
22048
  const candidates = [];
21845
22049
  const base = parseRateLimitCandidate(result.rateLimits, { genericOnly: true });
21846
22050
  if (base)
21847
22051
  candidates.push(base);
21848
- const notificationParams = isRecord4(value2.params) ? value2.params : void 0;
22052
+ const notificationParams = isRecord5(value2.params) ? value2.params : void 0;
21849
22053
  const notificationSnapshot = parseRateLimitCandidate(notificationParams?.rateLimits, {
21850
22054
  genericOnly: true
21851
22055
  });
@@ -21889,14 +22093,14 @@ function parseAvailableCount(value2) {
21889
22093
  return void 0;
21890
22094
  }
21891
22095
  function rateLimitResetCreditsSummary(value2) {
21892
- if (!isRecord4(value2))
22096
+ if (!isRecord5(value2))
21893
22097
  return null;
21894
- const result = isRecord4(value2.result) ? value2.result : value2;
21895
- const fromResult = isRecord4(result) && isRecord4(result.rateLimitResetCredits) ? result.rateLimitResetCredits : null;
22098
+ const result = isRecord5(value2.result) ? value2.result : value2;
22099
+ const fromResult = isRecord5(result) && isRecord5(result.rateLimitResetCredits) ? result.rateLimitResetCredits : null;
21896
22100
  if (fromResult)
21897
22101
  return fromResult;
21898
- const params = isRecord4(value2.params) ? value2.params : void 0;
21899
- return isRecord4(params?.rateLimitResetCredits) ? params.rateLimitResetCredits : null;
22102
+ const params = isRecord5(value2.params) ? value2.params : void 0;
22103
+ return isRecord5(params?.rateLimitResetCredits) ? params.rateLimitResetCredits : null;
21900
22104
  }
21901
22105
  function observeCodexRateLimitResetCredits(value2) {
21902
22106
  const summary = rateLimitResetCreditsSummary(value2);
@@ -21908,7 +22112,7 @@ function observeCodexRateLimitResetCredits(value2) {
21908
22112
  const expiresAtUnix = [];
21909
22113
  if (Array.isArray(summary.credits)) {
21910
22114
  for (const credit of summary.credits) {
21911
- if (!isRecord4(credit))
22115
+ if (!isRecord5(credit))
21912
22116
  continue;
21913
22117
  if (credit.status !== void 0 && credit.status !== "available")
21914
22118
  continue;
@@ -21977,11 +22181,11 @@ function itemStatus(outcome) {
21977
22181
  return "inProgress";
21978
22182
  return outcome.status === "succeeded" ? "completed" : "failed";
21979
22183
  }
21980
- function isRecord5(value2) {
22184
+ function isRecord6(value2) {
21981
22185
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
21982
22186
  }
21983
22187
  function nestedString(value2, keys) {
21984
- if (!isRecord5(value2))
22188
+ if (!isRecord6(value2))
21985
22189
  return void 0;
21986
22190
  for (const key of keys) {
21987
22191
  const field = value2[key];
@@ -21998,8 +22202,8 @@ function nestedString(value2, keys) {
21998
22202
  function toolOutputText(item) {
21999
22203
  if (!item.output)
22000
22204
  return null;
22001
- const text = item.output.content.filter((content) => content.type === "text").map(({ text: text2 }) => text2).join("");
22002
- return text.length > 0 ? text : null;
22205
+ const text2 = item.output.content.filter((content) => content.type === "text").map(({ text: text3 }) => text3).join("");
22206
+ return text2.length > 0 ? text2 : null;
22003
22207
  }
22004
22208
  function toolCommandLine(toolName, args) {
22005
22209
  const lower = toolName.toLowerCase().replaceAll(/[_-]/g, "");
@@ -22153,8 +22357,8 @@ function planFromTodoValue(value2) {
22153
22357
  if (value2 && typeof value2 === "object" && "content" in value2 && Array.isArray(value2.content)) {
22154
22358
  const output = value2;
22155
22359
  if (output) {
22156
- const text = output.content.flatMap((entry) => entry.type === "text" ? [entry.text] : []).join("\n");
22157
- const fromText = planFromChecklistText(text);
22360
+ const text2 = output.content.flatMap((entry) => entry.type === "text" ? [entry.text] : []).join("\n");
22361
+ const fromText = planFromChecklistText(text2);
22158
22362
  if (fromText)
22159
22363
  return fromText;
22160
22364
  }
@@ -22162,7 +22366,7 @@ function planFromTodoValue(value2) {
22162
22366
  const record3 = unwrapToolRecord(value2);
22163
22367
  if (!record3)
22164
22368
  return planFromChecklistText(typeof value2 === "string" ? value2 : null);
22165
- if (isRecord5(record3.TodosUpdated)) {
22369
+ if (isRecord6(record3.TodosUpdated)) {
22166
22370
  const nested = planFromTodoValue(record3.TodosUpdated);
22167
22371
  if (nested)
22168
22372
  return nested;
@@ -22177,7 +22381,7 @@ function planFromTodoValue(value2) {
22177
22381
  plan.push({ step: entry.trim(), status: "pending" });
22178
22382
  continue;
22179
22383
  }
22180
- if (!isRecord5(entry))
22384
+ if (!isRecord6(entry))
22181
22385
  continue;
22182
22386
  const step = nestedString(entry, ["content", "step", "text", "title", "description", "task"]);
22183
22387
  if (!step)
@@ -22232,7 +22436,7 @@ function unwrapToolRecord(value2) {
22232
22436
  }
22233
22437
  if (Array.isArray(value2))
22234
22438
  return { todos: value2 };
22235
- if (!isRecord5(value2))
22439
+ if (!isRecord6(value2))
22236
22440
  return null;
22237
22441
  for (const wrapper of ["input", "arguments", "params"]) {
22238
22442
  if (value2[wrapper] === void 0)
@@ -22290,7 +22494,7 @@ function projectItem(item, outcome, defaultCwd, includeCommandOutput = true, sen
22290
22494
  id: item.itemId,
22291
22495
  type: "agentMessage",
22292
22496
  text: item.text,
22293
- phase: null,
22497
+ phase: item.phase ?? null,
22294
22498
  memoryCitation: null,
22295
22499
  durationMs: item.durationMs ?? null
22296
22500
  };
@@ -22714,10 +22918,10 @@ var CodexTurnProjector = class {
22714
22918
  });
22715
22919
  } else if (event.update.type === "output.replace") {
22716
22920
  if (next.type === "toolExecution" && toolCommandLine(next.toolName, next.arguments)) {
22717
- const text = toolOutputText(next);
22718
- if (text) {
22921
+ const text2 = toolOutputText(next);
22922
+ if (text2) {
22719
22923
  const previousText = previous.type === "toolExecution" ? toolOutputText(previous) ?? "" : "";
22720
- const delta = text.startsWith(previousText) ? text.slice(previousText.length) : text;
22924
+ const delta = text2.startsWith(previousText) ? text2.slice(previousText.length) : text2;
22721
22925
  if (delta.length > 0) {
22722
22926
  projected.streamedCommandOutput = true;
22723
22927
  messages.push({
@@ -23041,7 +23245,7 @@ var CodexTurnProjector = class {
23041
23245
  };
23042
23246
 
23043
23247
  // packages/protocol-core/dist/thread-fork.js
23044
- function isRecord6(value2) {
23248
+ function isRecord7(value2) {
23045
23249
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
23046
23250
  }
23047
23251
  function optionalText(params, name, options2 = {}) {
@@ -23064,7 +23268,7 @@ function optionalBoolean(params, name) {
23064
23268
  function decodeThreadForkRequest(request) {
23065
23269
  if (request.method !== "thread/fork")
23066
23270
  return null;
23067
- if (!isRecord6(request.params))
23271
+ if (!isRecord7(request.params))
23068
23272
  throw new Error("thread/fork params must be an object");
23069
23273
  const params = request.params;
23070
23274
  const threadId3 = optionalText(params, "threadId");
@@ -23100,7 +23304,7 @@ function decodeThreadForkRequest(request) {
23100
23304
  function decodeThreadRevertRequest(request) {
23101
23305
  if (request.method !== "thread/revert")
23102
23306
  return null;
23103
- if (!isRecord6(request.params))
23307
+ if (!isRecord7(request.params))
23104
23308
  throw new Error("thread/revert params must be an object");
23105
23309
  const { threadId: threadId3, beforeTurnId } = request.params;
23106
23310
  if (typeof threadId3 !== "string" || threadId3.length === 0) {
@@ -23114,7 +23318,7 @@ function decodeThreadRevertRequest(request) {
23114
23318
  function decodeThreadRollbackRequest(request) {
23115
23319
  if (request.method !== "thread/rollback")
23116
23320
  return null;
23117
- if (!isRecord6(request.params))
23321
+ if (!isRecord7(request.params))
23118
23322
  throw new Error("thread/rollback params must be an object");
23119
23323
  const { threadId: threadId3, numTurns } = request.params;
23120
23324
  if (typeof threadId3 !== "string" || threadId3.length === 0) {
@@ -23211,13 +23415,13 @@ var THREAD_SOURCE_KINDS = /* @__PURE__ */ new Set([
23211
23415
  "subAgentOther",
23212
23416
  "unknown"
23213
23417
  ]);
23214
- function isRecord7(value2) {
23418
+ function isRecord8(value2) {
23215
23419
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
23216
23420
  }
23217
23421
  function paramsObject(request, method) {
23218
23422
  if (request.params === void 0 && method === "thread/list")
23219
23423
  return {};
23220
- if (!isRecord7(request.params))
23424
+ if (!isRecord8(request.params))
23221
23425
  throw new Error(`${method} params must be an object`);
23222
23426
  return request.params;
23223
23427
  }
@@ -23289,7 +23493,7 @@ function cursorPayload(value2) {
23289
23493
  };
23290
23494
  }
23291
23495
  function parseCursorPayload(value2) {
23292
- if (!isRecord7(value2) || value2.formatVersion !== 1)
23496
+ if (!isRecord8(value2) || value2.formatVersion !== 1)
23293
23497
  throw new Error("Host cursor is invalid");
23294
23498
  const { queryFingerprint: fingerprint, sortDirection: sortDirection2, officialCursor, officialDone } = value2;
23295
23499
  const { externalAnchor: externalAnchor2, externalDone } = value2;
@@ -23298,7 +23502,7 @@ function parseCursorPayload(value2) {
23298
23502
  }
23299
23503
  let anchor = null;
23300
23504
  if (externalAnchor2 !== null) {
23301
- if (!isRecord7(externalAnchor2) || !Number.isSafeInteger(externalAnchor2.timestamp) || typeof externalAnchor2.threadId !== "string" || externalAnchor2.threadId.length === 0) {
23505
+ if (!isRecord8(externalAnchor2) || !Number.isSafeInteger(externalAnchor2.timestamp) || typeof externalAnchor2.threadId !== "string" || externalAnchor2.threadId.length === 0) {
23302
23506
  throw new Error("Host cursor is invalid");
23303
23507
  }
23304
23508
  anchor = {
@@ -23418,7 +23622,7 @@ function decodeThreadMetadataUpdateRequest(request) {
23418
23622
  if (params.gitInfo === null) {
23419
23623
  gitInfo = null;
23420
23624
  } else if (params.gitInfo !== void 0) {
23421
- if (!isRecord7(params.gitInfo)) {
23625
+ if (!isRecord8(params.gitInfo)) {
23422
23626
  throw new Error("thread/metadata/update params.gitInfo must be an object or null");
23423
23627
  }
23424
23628
  gitInfo = {};
@@ -23446,7 +23650,7 @@ function optionalCursor(value2, name) {
23446
23650
  return value2;
23447
23651
  }
23448
23652
  function decodeOfficialThreadListPage(value2) {
23449
- if (!isRecord7(value2) || !Array.isArray(value2.data) || value2.data.some((row) => !isRecord7(row))) {
23653
+ if (!isRecord8(value2) || !Array.isArray(value2.data) || value2.data.some((row) => !isRecord8(row))) {
23450
23654
  throw new Error("Official thread/list response is invalid");
23451
23655
  }
23452
23656
  return {
@@ -24178,6 +24382,9 @@ var ExternalThreadRepository = class {
24178
24382
  setTitle(hostThreadId, title) {
24179
24383
  return this.store.setTitle(hostThreadId, title);
24180
24384
  }
24385
+ setCwd(hostThreadId, cwd) {
24386
+ return this.store.setCwd(hostThreadId, cwd);
24387
+ }
24181
24388
  setTransportModelId(hostThreadId, transportModelId) {
24182
24389
  return this.store.setTransportModelId(hostThreadId, transportModelId);
24183
24390
  }
@@ -24685,8 +24892,25 @@ var HarnessSessionImporter = class {
24685
24892
  return { ok: false, error: fixedError(-32081, "Session mappings could not be read") };
24686
24893
  }
24687
24894
  const existing = this.#mappedRecord(records, nativeSessionId);
24688
- if (existing) return importedThread(existing);
24689
24895
  const capability = this.#capability;
24896
+ if (existing) {
24897
+ if (!capability?.resolveCandidate) return importedThread(existing);
24898
+ try {
24899
+ const resolved = await capability.resolveCandidate(nativeSessionId);
24900
+ if (!resolved.ok) return importedThread(existing);
24901
+ const metadata2 = harnessSessionImportCandidateSchema.safeParse(resolved.value.candidate);
24902
+ const ref2 = nativeSessionRefSchema.safeParse(resolved.value.nativeRef);
24903
+ if (!metadata2.success || !ref2.success || ref2.data.harnessId !== this.#harnessId || ref2.data.nativeSessionId !== nativeSessionId || metadata2.data.nativeSessionId !== nativeSessionId || metadata2.data.cwd === existing.cwd) {
24904
+ return importedThread(existing);
24905
+ }
24906
+ return importedThread(
24907
+ await this.#repository.setCwd(existing.hostThreadId, metadata2.data.cwd)
24908
+ );
24909
+ } catch (error51) {
24910
+ this.#diagnose(error51);
24911
+ return importedThread(existing);
24912
+ }
24913
+ }
24690
24914
  if (!capability?.resolveCandidate) return { ok: false, error: this.#unavailable() };
24691
24915
  let source;
24692
24916
  try {
@@ -24872,10 +25096,10 @@ function serializeCursor(anchor, includeAnchor) {
24872
25096
  return JSON.stringify({ anchor, includeAnchor });
24873
25097
  }
24874
25098
  function parseCursor(value2) {
24875
- const text = optionalText2(value2, "cursor");
24876
- if (text === null) return null;
25099
+ const text2 = optionalText2(value2, "cursor");
25100
+ if (text2 === null) return null;
24877
25101
  try {
24878
- const parsed = JSON.parse(text);
25102
+ const parsed = JSON.parse(text2);
24879
25103
  if (typeof parsed === "object" && parsed !== null && typeof parsed.anchor === "string" && parsed.anchor.length > 0 && typeof parsed.includeAnchor === "boolean") {
24880
25104
  return { anchor: parsed.anchor, includeAnchor: parsed.includeAnchor };
24881
25105
  }
@@ -25738,8 +25962,8 @@ function parseInput(params) {
25738
25962
  )) {
25739
25963
  throw new ExternalSteerError(-32602, "External steering requires text input");
25740
25964
  }
25741
- const text = params.input.map((item) => item.text).join("\n");
25742
- if (!text.trim())
25965
+ const text2 = params.input.map((item) => item.text).join("\n");
25966
+ if (!text2.trim())
25743
25967
  throw new ExternalSteerError(-32602, "External steering input must not be empty");
25744
25968
  const clientUserMessageId = params.clientUserMessageId;
25745
25969
  if (clientUserMessageId != null && (typeof clientUserMessageId !== "string" || !clientUserMessageId.trim())) {
@@ -25747,7 +25971,7 @@ function parseInput(params) {
25747
25971
  }
25748
25972
  return {
25749
25973
  expectedTurnId: params.expectedTurnId,
25750
- text,
25974
+ text: text2,
25751
25975
  ...typeof clientUserMessageId === "string" ? { clientUserMessageId } : {}
25752
25976
  };
25753
25977
  }
@@ -25893,7 +26117,7 @@ import { createHash as createHash3 } from "node:crypto";
25893
26117
  var CURSOR_PREFIX = "codexhost:thread-messages:v1:";
25894
26118
  var DEFAULT_MESSAGE_LIMIT = 25;
25895
26119
  var MAX_MESSAGE_LIMIT = 100;
25896
- function isRecord8(value2) {
26120
+ function isRecord9(value2) {
25897
26121
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
25898
26122
  }
25899
26123
  function stringValue(value2) {
@@ -25902,12 +26126,12 @@ function stringValue(value2) {
25902
26126
  function textFromUserItem(item) {
25903
26127
  if (!Array.isArray(item.content)) return "";
25904
26128
  return item.content.flatMap(
25905
- (part) => isRecord8(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []
26129
+ (part) => isRecord9(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []
25906
26130
  ).join("\n");
25907
26131
  }
25908
26132
  function threadStatus(value2, running) {
25909
26133
  if (running) return "running";
25910
- if (isRecord8(value2)) {
26134
+ if (isRecord9(value2)) {
25911
26135
  if (value2.type === "active") return "running";
25912
26136
  }
25913
26137
  return "completed";
@@ -25924,15 +26148,15 @@ function allVisibleMessages(turns) {
25924
26148
  const turnId = stringValue(turn.id);
25925
26149
  if (!turnId || !Array.isArray(turn.items)) continue;
25926
26150
  const agentItems = turn.items.filter(
25927
- (item) => isRecord8(item) && item.type === "agentMessage"
26151
+ (item) => isRecord9(item) && item.type === "agentMessage"
25928
26152
  );
25929
26153
  for (const item of turn.items) {
25930
- if (!isRecord8(item)) continue;
26154
+ if (!isRecord9(item)) continue;
25931
26155
  const id2 = stringValue(item.id);
25932
26156
  if (!id2) continue;
25933
26157
  if (item.type === "userMessage") {
25934
- const text = textFromUserItem(item);
25935
- if (text) messages.push({ id: id2, turnId, role: "user", text });
26158
+ const text2 = textFromUserItem(item);
26159
+ if (text2) messages.push({ id: id2, turnId, role: "user", text: text2 });
25936
26160
  } else if (item.type === "agentMessage" && typeof item.text === "string" && item.text) {
25937
26161
  const itemIndex = agentItems.indexOf(item);
25938
26162
  const phase = item.phase === "commentary" || item.phase === "final" ? item.phase : turn.status === "inProgress" || itemIndex < agentItems.length - 1 ? "commentary" : "final";
@@ -25999,10 +26223,10 @@ function projectDelegationThreadSnapshot(input) {
25999
26223
  const status = input.running ? "running" : latestTurnStatus === "failed" || latestTurnStatus === "interrupted" ? latestTurnStatus : threadStatus(input.thread.status, input.running);
26000
26224
  const latestTurnMessages = latestTurnId ? visible.filter((message) => message.turnId === latestTurnId && message.role === "agent") : [];
26001
26225
  const final = latestTurnMessages.filter((message) => message.phase === "final").at(-1);
26002
- const progress = latestTurnMessages.filter((message) => message.phase !== "final").map(({ id: id2, turnId, text }) => ({ id: id2, turnId, text }));
26226
+ const progress = latestTurnMessages.filter((message) => message.phase !== "final").map(({ id: id2, turnId, text: text2 }) => ({ id: id2, turnId, text: text2 }));
26003
26227
  const result = input.running ? { availability: "pending" } : final ? { availability: "available", text: final.text } : {
26004
26228
  availability: "unavailable",
26005
- ...isRecord8(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
26229
+ ...isRecord9(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
26006
26230
  };
26007
26231
  const offset = options2.view === "messages" ? decodeCursor(input.threadId, options2.cursor) : visible.length;
26008
26232
  const page = options2.view === "messages" ? visible.slice(offset, offset + options2.limit) : void 0;
@@ -27157,7 +27381,7 @@ import { mkdir as mkdir6 } from "node:fs/promises";
27157
27381
  import { randomUUID as randomUUID7 } from "node:crypto";
27158
27382
  var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
27159
27383
  var MAX_RETIRED_IDS = 1024;
27160
- function isRecord9(value2) {
27384
+ function isRecord10(value2) {
27161
27385
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
27162
27386
  }
27163
27387
  var OfficialRequestBroker = class {
@@ -27200,7 +27424,7 @@ var OfficialRequestBroker = class {
27200
27424
  });
27201
27425
  }
27202
27426
  handle(value2) {
27203
- if (!isRecord9(value2) || typeof value2.id !== "string") return false;
27427
+ if (!isRecord10(value2) || typeof value2.id !== "string") return false;
27204
27428
  const pending = this.#pending.get(value2.id);
27205
27429
  if (!pending) return this.#retired.has(value2.id);
27206
27430
  clearTimeout(pending.timeout);
@@ -27791,11 +28015,11 @@ async function aggregateOfficialAccountThreadListPage(input) {
27791
28015
  }
27792
28016
 
27793
28017
  // packages/host-runtime/src/route-observation.ts
27794
- function isRecord10(value2) {
28018
+ function isRecord11(value2) {
27795
28019
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
27796
28020
  }
27797
28021
  function classifyThreadPurpose(request) {
27798
- return isRecord10(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
28022
+ return isRecord11(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
27799
28023
  }
27800
28024
  var RequestRouteObservationTracker = class {
27801
28025
  #nextCreateOrdinal = 0;
@@ -27820,13 +28044,13 @@ var RequestRouteObservationTracker = class {
27820
28044
  this.#createByThreadId.set(threadId3, tracked);
27821
28045
  }
27822
28046
  bindOfficialResponse(response) {
27823
- if (!isRecord10(response) || !("id" in response)) return;
28047
+ if (!isRecord11(response) || !("id" in response)) return;
27824
28048
  const tracked = this.#pendingByRequestId.get(response.id);
27825
28049
  if (!tracked) return;
27826
28050
  this.#pendingByRequestId.delete(response.id);
27827
28051
  const result = response.result;
27828
- const thread = isRecord10(result) ? result.thread : null;
27829
- if (isRecord10(thread) && typeof thread.id === "string") {
28052
+ const thread = isRecord11(result) ? result.thread : null;
28053
+ if (isRecord11(thread) && typeof thread.id === "string") {
27830
28054
  this.#createByThreadId.set(thread.id, tracked);
27831
28055
  }
27832
28056
  }
@@ -27869,11 +28093,11 @@ var OfficialThreadListError = class extends Error {
27869
28093
  }
27870
28094
  rpcError;
27871
28095
  };
27872
- function isRecord11(value2) {
28096
+ function isRecord12(value2) {
27873
28097
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
27874
28098
  }
27875
28099
  function officialThreadListPageFromResponse(response) {
27876
- if (isRecord11(response.error)) {
28100
+ if (isRecord12(response.error)) {
27877
28101
  if (!Number.isSafeInteger(response.error.code) || typeof response.error.message !== "string") {
27878
28102
  throw new Error("Official thread/list error response is invalid");
27879
28103
  }
@@ -27886,7 +28110,11 @@ function opposite(direction) {
27886
28110
  return direction === "asc" ? "desc" : "asc";
27887
28111
  }
27888
28112
  function officialParams(query, cursor, limit) {
27889
- return { ...query.params, cursor, limit };
28113
+ const params = { ...query.params, cursor, limit };
28114
+ if (Array.isArray(params.modelProviders) && params.modelProviders.length === 0) {
28115
+ delete params.modelProviders;
28116
+ }
28117
+ return params;
27890
28118
  }
27891
28119
  function cursorValue(input) {
27892
28120
  return encodeHostThreadListCursor({
@@ -28038,14 +28266,14 @@ var THREAD_USAGE_UPDATED_METHOD = "codexhost/thread/usage/updated";
28038
28266
  function delay3(milliseconds) {
28039
28267
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
28040
28268
  }
28041
- function isRecord12(value2) {
28269
+ function isRecord13(value2) {
28042
28270
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
28043
28271
  }
28044
28272
  function isCreditsAdapter(adapter) {
28045
28273
  return typeof adapter.credits === "function";
28046
28274
  }
28047
28275
  function projectAccountCredits(value2) {
28048
- if (!isRecord12(value2)) return null;
28276
+ if (!isRecord13(value2)) return null;
28049
28277
  const rest = { ...value2 };
28050
28278
  delete rest.fetchedAt;
28051
28279
  const parsed = accountCreditsSnapshotSchema.safeParse(rest);
@@ -28165,14 +28393,14 @@ function classifyCreateRequestRoute(request, defaultAgent) {
28165
28393
  };
28166
28394
  }
28167
28395
  function requestObject(request) {
28168
- if (!isRecord12(request.params)) throw new Error(`${request.method} params must be an object`);
28396
+ if (!isRecord13(request.params)) throw new Error(`${request.method} params must be an object`);
28169
28397
  return request.params;
28170
28398
  }
28171
28399
  function requestText(params) {
28172
28400
  if (!Array.isArray(params.input)) throw new Error("turn/start input must be an array");
28173
- const text = params.input.filter((item) => isRecord12(item) && item.type === "text").map((item) => item.text).filter((value2) => typeof value2 === "string").join("\n");
28174
- if (!text) throw new Error("turn/start must contain text input");
28175
- return text;
28401
+ const text2 = params.input.filter((item) => isRecord13(item) && item.type === "text").map((item) => item.text).filter((value2) => typeof value2 === "string").join("\n");
28402
+ if (!text2) throw new Error("turn/start must contain text input");
28403
+ return text2;
28176
28404
  }
28177
28405
  function sandboxResult(params) {
28178
28406
  const sandbox = params.sandbox;
@@ -28310,7 +28538,7 @@ var AppServerHost = class {
28310
28538
  externalRuntime: this.#externalRuntime,
28311
28539
  repository: this.#repository,
28312
28540
  registerExternalThread: (input) => this.#registerExternalThread(input),
28313
- startExternalTurn: (thread, text, turnId) => this.#startDelegatedExternalTurn(thread, text, turnId),
28541
+ startExternalTurn: (thread, text2, turnId) => this.#startDelegatedExternalTurn(thread, text2, turnId),
28314
28542
  notifyThreadStarted: (thread) => this.#notifyExternalThreadStarted(thread),
28315
28543
  inspectOfficial: (input) => this.#inspectOfficialDelegationTarget(input),
28316
28544
  readOfficial: (input) => this.#readOfficialDelegationThread(input),
@@ -28455,12 +28683,12 @@ var AppServerHost = class {
28455
28683
  for (const resolve of waiters) resolve();
28456
28684
  }
28457
28685
  #observeOfficialTurnStartResponse(value2) {
28458
- if (!isRecord12(value2) || !("id" in value2)) return;
28686
+ if (!isRecord13(value2) || !("id" in value2)) return;
28459
28687
  const threadId3 = this.#pendingOfficialTurnStarts.get(value2.id);
28460
28688
  if (!threadId3) return;
28461
28689
  this.#pendingOfficialTurnStarts.delete(value2.id);
28462
- const result = isRecord12(value2.result) ? value2.result : null;
28463
- const turn = result && isRecord12(result.turn) ? result.turn : null;
28690
+ const result = isRecord13(value2.result) ? value2.result : null;
28691
+ const turn = result && isRecord13(result.turn) ? result.turn : null;
28464
28692
  if (turn && typeof turn.id === "string") {
28465
28693
  this.#activeOfficialTurns.set(threadId3, turn.id);
28466
28694
  }
@@ -28474,7 +28702,7 @@ var AppServerHost = class {
28474
28702
  async #forwardDesktop() {
28475
28703
  for await (const frame of readLfFrames(this.#options.desktopInput)) {
28476
28704
  const parsed = parseJsonFrame(frame);
28477
- if (isRecord12(parsed) && parsed.method === "initialized" && !("id" in parsed)) {
28705
+ if (isRecord13(parsed) && parsed.method === "initialized" && !("id" in parsed)) {
28478
28706
  continue;
28479
28707
  }
28480
28708
  if (await this.#handleDesktopApprovalResponse(parsed)) continue;
@@ -28685,7 +28913,7 @@ var AppServerHost = class {
28685
28913
  continue;
28686
28914
  }
28687
28915
  if (request.method === "thread/fork") {
28688
- const params = isRecord12(request.params) ? request.params : {};
28916
+ const params = isRecord13(request.params) ? request.params : {};
28689
28917
  const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
28690
28918
  if (resolution.kind === "error") {
28691
28919
  await this.#writer.json(
@@ -28708,7 +28936,7 @@ var AppServerHost = class {
28708
28936
  }
28709
28937
  }
28710
28938
  if (request.method === "thread/revert") {
28711
- const params = isRecord12(request.params) ? request.params : {};
28939
+ const params = isRecord13(request.params) ? request.params : {};
28712
28940
  const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
28713
28941
  if (resolution.kind === "error") {
28714
28942
  await this.#writer.json(
@@ -28731,7 +28959,7 @@ var AppServerHost = class {
28731
28959
  }
28732
28960
  }
28733
28961
  if (request.method === "thread/rollback") {
28734
- const params = isRecord12(request.params) ? request.params : {};
28962
+ const params = isRecord13(request.params) ? request.params : {};
28735
28963
  const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
28736
28964
  if (resolution.kind === "error") {
28737
28965
  await this.#writer.json(
@@ -28883,7 +29111,7 @@ var AppServerHost = class {
28883
29111
  continue;
28884
29112
  }
28885
29113
  }
28886
- if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) && isRecord12(request.params) && typeof request.params.threadId === "string") {
29114
+ if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) && isRecord13(request.params) && typeof request.params.threadId === "string") {
28887
29115
  const location = await this.#locateExternalThread(request.params.threadId);
28888
29116
  if (await this.#writeResolutionError(request, location)) continue;
28889
29117
  if (location.kind === "external") {
@@ -28901,7 +29129,7 @@ var AppServerHost = class {
28901
29129
  await this.#codexRuntimePool.close();
28902
29130
  }
28903
29131
  async #forwardOfficialNonRequest(value2, frame) {
28904
- const response = isRecord12(value2) ? value2 : null;
29132
+ const response = isRecord13(value2) ? value2 : null;
28905
29133
  const request = response && (typeof response.id === "string" || typeof response.id === "number") ? this.#officialServerRequestAccounts.get(response.id) : null;
28906
29134
  if (request && response) {
28907
29135
  this.#officialServerRequestAccounts.delete(response.id);
@@ -28915,7 +29143,7 @@ var AppServerHost = class {
28915
29143
  }
28916
29144
  async #forwardOfficialRequest(request, frame) {
28917
29145
  try {
28918
- const params = isRecord12(request.params) ? request.params : null;
29146
+ const params = isRecord13(request.params) ? request.params : null;
28919
29147
  const requestedAccountId = request.method === "thread/start" && typeof params?.__codexhostAccountId === "string" ? params.__codexhostAccountId : null;
28920
29148
  const threadId3 = params && typeof params.threadId === "string" ? params.threadId : null;
28921
29149
  const loginId = params && typeof params.loginId === "string" ? params.loginId : null;
@@ -28966,7 +29194,7 @@ var AppServerHost = class {
28966
29194
  const parsed = input.value;
28967
29195
  this.#observeOfficialTurnStartResponse(parsed);
28968
29196
  let forwarded = parsed;
28969
- if (isRecord12(parsed) && typeof parsed.method === "string" && "id" in parsed) {
29197
+ if (isRecord13(parsed) && typeof parsed.method === "string" && "id" in parsed) {
28970
29198
  const originalId = parsed.id;
28971
29199
  if (typeof originalId === "string" || typeof originalId === "number") {
28972
29200
  const forwardedId = `codexhost:official:${++this.#nextOfficialServerRequestId}`;
@@ -28977,12 +29205,12 @@ var AppServerHost = class {
28977
29205
  forwarded = { ...parsed, id: forwardedId };
28978
29206
  }
28979
29207
  }
28980
- if (isRecord12(parsed) && !("method" in parsed) && "id" in parsed) {
29208
+ if (isRecord13(parsed) && !("method" in parsed) && "id" in parsed) {
28981
29209
  const requestKey = this.#officialRequestKey(input.accountId, parsed.id);
28982
29210
  const loginAccountId = this.#pendingOfficialLoginStarts.get(requestKey);
28983
29211
  if (loginAccountId) {
28984
29212
  this.#pendingOfficialLoginStarts.delete(requestKey);
28985
- const result = isRecord12(parsed.result) ? parsed.result : null;
29213
+ const result = isRecord13(parsed.result) ? parsed.result : null;
28986
29214
  const loginId = result && typeof result.loginId === "string" ? result.loginId : null;
28987
29215
  if (result && loginId) {
28988
29216
  this.#officialLoginSessions.set(this.#loginSessionKey(loginAccountId, loginId), {
@@ -28996,8 +29224,8 @@ var AppServerHost = class {
28996
29224
  const pending = this.#pendingOfficialThreadBindings.get(requestKey);
28997
29225
  if (pending) {
28998
29226
  this.#pendingOfficialThreadBindings.delete(requestKey);
28999
- const result = isRecord12(parsed.result) ? parsed.result : null;
29000
- const thread = result && isRecord12(result.thread) ? result.thread : null;
29227
+ const result = isRecord13(parsed.result) ? parsed.result : null;
29228
+ const thread = result && isRecord13(result.thread) ? result.thread : null;
29001
29229
  const threadId3 = thread && typeof thread.id === "string" ? thread.id : null;
29002
29230
  if (threadId3) {
29003
29231
  try {
@@ -29012,7 +29240,7 @@ var AppServerHost = class {
29012
29240
  }
29013
29241
  }
29014
29242
  }
29015
- if (isRecord12(parsed) && parsed.method === "account/login/completed" && isRecord12(parsed.params)) {
29243
+ if (isRecord13(parsed) && parsed.method === "account/login/completed" && isRecord13(parsed.params)) {
29016
29244
  const notificationLoginId = typeof parsed.params.loginId === "string" ? parsed.params.loginId : null;
29017
29245
  const accountSessions = notificationLoginId ? [] : [...this.#officialLoginSessions.values()].filter(
29018
29246
  (candidate) => candidate.accountId === input.accountId
@@ -29036,7 +29264,7 @@ var AppServerHost = class {
29036
29264
  }
29037
29265
  return;
29038
29266
  }
29039
- const accountScopedNotification = isRecord12(parsed) && typeof parsed.method === "string" && (parsed.method === "account/updated" || parsed.method.startsWith("account/rateLimits/"));
29267
+ const accountScopedNotification = isRecord13(parsed) && typeof parsed.method === "string" && (parsed.method === "account/updated" || parsed.method.startsWith("account/rateLimits/"));
29040
29268
  if (accountScopedNotification) {
29041
29269
  if (parsed.method === "account/updated") this.#resetOfficialUsageState(input.accountId);
29042
29270
  }
@@ -29072,8 +29300,19 @@ var AppServerHost = class {
29072
29300
  try {
29073
29301
  if (request.method === "codexhost/account/usage/inspect") {
29074
29302
  const { accountId } = codexAccountUsageParamsSchema.parse(requestObject(request));
29075
- if (!await this.#accountRepository.get(accountId))
29076
- throw new Error("Unknown Codex Account");
29303
+ const account = await this.#accountRepository.get(accountId);
29304
+ if (!account) throw new Error("Unknown Codex Account");
29305
+ const auth = await inspectCodexHomeAuth(account.codexHome);
29306
+ if (auth.kind === "api") {
29307
+ const accountCredits2 = await inspectCodexApiAccountCredits(account.codexHome);
29308
+ const result2 = codexAccountUsageResultSchema.parse({
29309
+ accountId,
29310
+ usage: null,
29311
+ ...accountCredits2 ? { accountCredits: accountCredits2 } : {}
29312
+ });
29313
+ await this.#writer.json(rpcEnvelope(request, { result: jsonValueSchema.parse(result2) }));
29314
+ return;
29315
+ }
29077
29316
  await this.#refreshOfficialRateLimits(accountId);
29078
29317
  const usage = this.#officialRateLimits.get(accountId);
29079
29318
  const accountCredits = this.#officialAccountCredits(accountId);
@@ -29093,11 +29332,11 @@ var AppServerHost = class {
29093
29332
  const response2 = await runtime.request("account/rateLimitResetCredit/consume", {
29094
29333
  idempotencyKey: params2.idempotencyKey ?? randomUUID8()
29095
29334
  });
29096
- if (isRecord12(response2.error)) {
29335
+ if (isRecord13(response2.error)) {
29097
29336
  await this.#writer.json(rpcEnvelope(request, { error: response2.error }));
29098
29337
  return;
29099
29338
  }
29100
- const result = isRecord12(response2.result) ? response2.result : null;
29339
+ const result = isRecord13(response2.result) ? response2.result : null;
29101
29340
  const outcome = codexAccountResetCreditConsumeOutcomeSchema.safeParse(result?.outcome);
29102
29341
  if (!outcome.success) throw new Error("Official reset-credit consume response is invalid");
29103
29342
  this.#officialRateLimits.reset(params2.accountId);
@@ -29199,11 +29438,11 @@ var AppServerHost = class {
29199
29438
  const response2 = await runtime.request("account/login/start", {
29200
29439
  type: "chatgptDeviceCode"
29201
29440
  });
29202
- if (isRecord12(response2.error)) {
29441
+ if (isRecord13(response2.error)) {
29203
29442
  await this.#writer.json(rpcEnvelope(request, { error: response2.error }));
29204
29443
  return;
29205
29444
  }
29206
- const result = isRecord12(response2.result) ? response2.result : null;
29445
+ const result = isRecord13(response2.result) ? response2.result : null;
29207
29446
  if (!result || result.type !== "chatgptDeviceCode" || typeof result.loginId !== "string" || typeof result.verificationUrl !== "string" || typeof result.userCode !== "string") {
29208
29447
  throw new Error("Official account/login/start response is invalid");
29209
29448
  }
@@ -29232,7 +29471,7 @@ var AppServerHost = class {
29232
29471
  return;
29233
29472
  }
29234
29473
  const response = await (await this.#codexRuntimePool.get(session.accountId)).request("account/login/cancel", { loginId: params.loginId });
29235
- if (isRecord12(response.error)) {
29474
+ if (isRecord13(response.error)) {
29236
29475
  await this.#writer.json(rpcEnvelope(request, { error: response.error }));
29237
29476
  return;
29238
29477
  }
@@ -29264,8 +29503,8 @@ var AppServerHost = class {
29264
29503
  for (const account of await this.#accountRepository.list()) {
29265
29504
  try {
29266
29505
  const response = await (await this.#codexRuntimePool.get(account.accountId)).request("account/read", { refreshToken: false });
29267
- const result = isRecord12(response.result) ? response.result : null;
29268
- const officialAccount = result && isRecord12(result.account) ? result.account : null;
29506
+ const result = isRecord13(response.result) ? response.result : null;
29507
+ const officialAccount = result && isRecord13(result.account) ? result.account : null;
29269
29508
  if (!officialAccount) continue;
29270
29509
  const email3 = typeof officialAccount.email === "string" ? officialAccount.email.trim() : "";
29271
29510
  const parsedPlanType = codexAccountPlanTypeSchema.safeParse(officialAccount.planType);
@@ -29300,10 +29539,10 @@ var AppServerHost = class {
29300
29539
  return this.#uniqueLoginSession(loginId)?.accountId;
29301
29540
  }
29302
29541
  async #observeOfficialTurnLifecycle(value2) {
29303
- if (!isRecord12(value2) || !isRecord12(value2.params)) return;
29542
+ if (!isRecord13(value2) || !isRecord13(value2.params)) return;
29304
29543
  const params = value2.params;
29305
29544
  if (value2.method === "turn/started" && typeof params.threadId === "string") {
29306
- const turn = isRecord12(params.turn) ? params.turn : null;
29545
+ const turn = isRecord13(params.turn) ? params.turn : null;
29307
29546
  if (turn && typeof turn.id === "string") {
29308
29547
  this.#forgetPendingOfficialTurnStarts(params.threadId);
29309
29548
  this.#activeOfficialTurns.set(params.threadId, turn.id);
@@ -29316,7 +29555,7 @@ var AppServerHost = class {
29316
29555
  const delegation = await this.#repository.getDelegationByChild(
29317
29556
  hostThreadIdSchema.parse(params.threadId)
29318
29557
  );
29319
- const turn = isRecord12(params.turn) ? params.turn : null;
29558
+ const turn = isRecord13(params.turn) ? params.turn : null;
29320
29559
  const status = turn?.status === "failed" ? "failed" : turn?.status === "interrupted" || turn?.status === "cancelled" ? "interrupted" : "completed";
29321
29560
  if (this.#pendingOfficialDelegationThreads.has(params.threadId)) {
29322
29561
  this.#pendingOfficialTerminalStatuses.set(params.threadId, status);
@@ -29346,21 +29585,21 @@ var AppServerHost = class {
29346
29585
  }
29347
29586
  async #inspectOfficialDelegationTarget(input) {
29348
29587
  const response = await this.#requestOfficial("model/list", {});
29349
- if (isRecord12(response.error)) {
29588
+ if (isRecord13(response.error)) {
29350
29589
  throw new DelegationControlError(
29351
29590
  "DELEGATION_FAILED",
29352
29591
  typeof response.error.message === "string" ? response.error.message : "Official Model catalog could not be read"
29353
29592
  );
29354
29593
  }
29355
- const result = isRecord12(response.result) ? response.result : null;
29594
+ const result = isRecord13(response.result) ? response.result : null;
29356
29595
  const data = result && Array.isArray(result.data) ? result.data : [];
29357
29596
  const thinkingById = /* @__PURE__ */ new Map();
29358
29597
  const models = data.flatMap((candidate) => {
29359
- if (!isRecord12(candidate) || typeof candidate.model !== "string" || !candidate.model.trim()) {
29598
+ if (!isRecord13(candidate) || typeof candidate.model !== "string" || !candidate.model.trim()) {
29360
29599
  return [];
29361
29600
  }
29362
29601
  const supportedThinkingOptionIds = Array.isArray(candidate.supportedReasoningEfforts) ? candidate.supportedReasoningEfforts.flatMap((option) => {
29363
- if (!isRecord12(option) || typeof option.reasoningEffort !== "string" || !option.reasoningEffort.trim()) {
29602
+ if (!isRecord13(option) || typeof option.reasoningEffort !== "string" || !option.reasoningEffort.trim()) {
29364
29603
  return [];
29365
29604
  }
29366
29605
  const id2 = harnessThinkingOptionIdSchema.safeParse(option.reasoningEffort);
@@ -29380,9 +29619,9 @@ var AppServerHost = class {
29380
29619
  ];
29381
29620
  });
29382
29621
  const defaultEntry = data.find(
29383
- (candidate) => isRecord12(candidate) && candidate.isDefault === true
29622
+ (candidate) => isRecord13(candidate) && candidate.isDefault === true
29384
29623
  );
29385
- const defaultModel = isRecord12(defaultEntry) && typeof defaultEntry.model === "string" ? encodeOfficialCodexModelRef(defaultEntry.model) : void 0;
29624
+ const defaultModel = isRecord13(defaultEntry) && typeof defaultEntry.model === "string" ? encodeOfficialCodexModelRef(defaultEntry.model) : void 0;
29386
29625
  return {
29387
29626
  harnessId: input.harnessId,
29388
29627
  inspection: {
@@ -29489,8 +29728,8 @@ var AppServerHost = class {
29489
29728
  ephemeral: false,
29490
29729
  historyMode: "paginated"
29491
29730
  });
29492
- const startedResult = isRecord12(started.result) ? started.result : null;
29493
- const thread = startedResult && isRecord12(startedResult.thread) ? startedResult.thread : null;
29731
+ const startedResult = isRecord13(started.result) ? started.result : null;
29732
+ const thread = startedResult && isRecord13(startedResult.thread) ? startedResult.thread : null;
29494
29733
  const threadId3 = thread && typeof thread.id === "string" ? thread.id : null;
29495
29734
  if (!threadId3) throw new Error("Official thread/start returned no Thread identity");
29496
29735
  await this.#codexRuntimePool.bindThread(threadId3, activeRuntime.account.accountId);
@@ -29503,8 +29742,8 @@ var AppServerHost = class {
29503
29742
  ...nativeModelId ? { model: nativeModelId } : {},
29504
29743
  ...input.thinkingOptionId ? { effort: input.thinkingOptionId } : {}
29505
29744
  });
29506
- const turnResult = isRecord12(turn.result) ? turn.result : null;
29507
- const turnValue = turnResult && isRecord12(turnResult.turn) ? turnResult.turn : null;
29745
+ const turnResult = isRecord13(turn.result) ? turn.result : null;
29746
+ const turnValue = turnResult && isRecord13(turnResult.turn) ? turnResult.turn : null;
29508
29747
  const parsedTurnId = turnValue && typeof turnValue.id === "string" ? turnValue.id : null;
29509
29748
  if (!parsedTurnId) throw new Error("Official turn/start returned no Turn identity");
29510
29749
  turnId = parsedTurnId;
@@ -29573,27 +29812,27 @@ var AppServerHost = class {
29573
29812
  threadId: input.threadId,
29574
29813
  includeTurns: true
29575
29814
  });
29576
- if (isRecord12(current.error) || !isRecord12(current.result)) {
29815
+ if (isRecord13(current.error) || !isRecord13(current.result)) {
29577
29816
  throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
29578
29817
  }
29579
- const currentThread = isRecord12(current.result.thread) ? current.result.thread : null;
29818
+ const currentThread = isRecord13(current.result.thread) ? current.result.thread : null;
29580
29819
  const currentTurns = currentThread && Array.isArray(currentThread.turns) ? currentThread.turns : [];
29581
29820
  const latestTurn = currentTurns.at(-1);
29582
- if (currentThread && isRecord12(currentThread.status) && currentThread.status.type === "active" || isRecord12(latestTurn) && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
29821
+ if (currentThread && isRecord13(currentThread.status) && currentThread.status.type === "active" || isRecord13(latestTurn) && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
29583
29822
  throw new DelegationControlError("THREAD_BUSY", "Thread already has an active Turn");
29584
29823
  }
29585
29824
  const response = await this.#requestOfficial("turn/start", {
29586
29825
  threadId: input.threadId,
29587
29826
  input: [{ type: "text", text: input.message }]
29588
29827
  });
29589
- if (isRecord12(response.error)) {
29828
+ if (isRecord13(response.error)) {
29590
29829
  throw new DelegationControlError(
29591
29830
  "DELEGATION_FAILED",
29592
29831
  typeof response.error.message === "string" ? response.error.message : "Turn start failed"
29593
29832
  );
29594
29833
  }
29595
- const result = isRecord12(response.result) ? response.result : null;
29596
- const turn = result && isRecord12(result.turn) ? result.turn : null;
29834
+ const result = isRecord13(response.result) ? response.result : null;
29835
+ const turn = result && isRecord13(result.turn) ? result.turn : null;
29597
29836
  const turnId = turn && typeof turn.id === "string" ? turn.id : null;
29598
29837
  if (!turnId) throw new Error("Official turn/start returned no Turn identity");
29599
29838
  this.#activeOfficialTurns.set(input.threadId, turnId);
@@ -29615,13 +29854,13 @@ var AppServerHost = class {
29615
29854
  threadId: input.threadId,
29616
29855
  includeTurns: true
29617
29856
  });
29618
- if (isRecord12(current.error) || !isRecord12(current.result)) {
29857
+ if (isRecord13(current.error) || !isRecord13(current.result)) {
29619
29858
  throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
29620
29859
  }
29621
- const currentThread = isRecord12(current.result.thread) ? current.result.thread : null;
29860
+ const currentThread = isRecord13(current.result.thread) ? current.result.thread : null;
29622
29861
  const currentTurns = currentThread && Array.isArray(currentThread.turns) ? currentThread.turns : [];
29623
29862
  const latestTurn = currentTurns.at(-1);
29624
- if (isRecord12(latestTurn) && typeof latestTurn.id === "string" && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
29863
+ if (isRecord13(latestTurn) && typeof latestTurn.id === "string" && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
29625
29864
  turnId = latestTurn.id;
29626
29865
  this.#activeOfficialTurns.set(input.threadId, turnId);
29627
29866
  } else {
@@ -29632,7 +29871,7 @@ var AppServerHost = class {
29632
29871
  threadId: input.threadId,
29633
29872
  turnId
29634
29873
  });
29635
- if (isRecord12(response.error)) {
29874
+ if (isRecord13(response.error)) {
29636
29875
  throw new DelegationControlError(
29637
29876
  "DELEGATION_FAILED",
29638
29877
  typeof response.error.message === "string" ? response.error.message : "Turn cancel failed"
@@ -29645,18 +29884,18 @@ var AppServerHost = class {
29645
29884
  threadId: input.threadId,
29646
29885
  includeTurns: true
29647
29886
  });
29648
- if (isRecord12(response.error)) {
29887
+ if (isRecord13(response.error)) {
29649
29888
  throw new DelegationControlError(
29650
29889
  "THREAD_NOT_FOUND",
29651
29890
  typeof response.error.message === "string" ? response.error.message : "Official Thread was not found"
29652
29891
  );
29653
29892
  }
29654
- const result = isRecord12(response.result) ? response.result : null;
29655
- const thread = result && isRecord12(result.thread) ? result.thread : null;
29893
+ const result = isRecord13(response.result) ? response.result : null;
29894
+ const thread = result && isRecord13(result.thread) ? result.thread : null;
29656
29895
  if (!thread)
29657
29896
  throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
29658
- const turns = Array.isArray(thread.turns) ? thread.turns.filter((turn) => isRecord12(turn)) : [];
29659
- const running = this.#activeOfficialTurns.has(input.threadId) || isRecord12(thread.status) && thread.status.type === "active";
29897
+ const turns = Array.isArray(thread.turns) ? thread.turns.filter((turn) => isRecord13(turn)) : [];
29898
+ const running = this.#activeOfficialTurns.has(input.threadId) || isRecord13(thread.status) && thread.status.type === "active";
29660
29899
  const snapshot = projectDelegationThreadSnapshot({
29661
29900
  threadId: input.threadId,
29662
29901
  harnessId: "codex",
@@ -29715,7 +29954,7 @@ var AppServerHost = class {
29715
29954
  threads: result.data.flatMap((entry) => {
29716
29955
  if (typeof entry.id !== "string") return [];
29717
29956
  const record3 = records.find((candidate) => candidate.hostThreadId === entry.id);
29718
- const status = isRecord12(entry.status) && entry.status.type === "active" ? "running" : "completed";
29957
+ const status = isRecord13(entry.status) && entry.status.type === "active" ? "running" : "completed";
29719
29958
  return [
29720
29959
  {
29721
29960
  threadId: entry.id,
@@ -30860,10 +31099,10 @@ var AppServerHost = class {
30860
31099
  ...typeof params.serviceTier === "string" ? { serviceTier: params.serviceTier } : {}
30861
31100
  });
30862
31101
  try {
30863
- if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !isRecord12(params.initialTurnsPage)) {
31102
+ if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !isRecord13(params.initialTurnsPage)) {
30864
31103
  throw new ExternalHistoryRequestError("initialTurnsPage must be an object");
30865
31104
  }
30866
- const initialPageParams = isRecord12(params.initialTurnsPage) ? params.initialTurnsPage : null;
31105
+ const initialPageParams = isRecord13(params.initialTurnsPage) ? params.initialTurnsPage : null;
30867
31106
  const initialTurnsPage = initialPageParams ? listExternalTurns(turns, initialPageParams) : null;
30868
31107
  const paginated = thread.record.historyMode === "paginated";
30869
31108
  const turnsBackwardsCursor = paginated ? listExternalTurns(turns, { limit: 1, itemsView: "notLoaded" }).backwardsCursor : null;
@@ -30893,7 +31132,7 @@ var AppServerHost = class {
30893
31132
  const active = thread.projectedTurns.get(thread.activeTurnId);
30894
31133
  return active ? [...thread.turns, active.projector.pendingTurn()] : thread.turns;
30895
31134
  }
30896
- async #startDelegatedExternalTurn(thread, text, requestedTurnId) {
31135
+ async #startDelegatedExternalTurn(thread, text2, requestedTurnId) {
30897
31136
  if (thread.running || this.#externalSteering.hasPending(thread.id)) {
30898
31137
  throw new Error("External Thread already has an active Turn");
30899
31138
  }
@@ -30904,7 +31143,7 @@ var AppServerHost = class {
30904
31143
  turnId,
30905
31144
  cwd: thread.cwd,
30906
31145
  startedAtMs: Date.now(),
30907
- initialInput: [{ type: "text", text }]
31146
+ initialInput: [{ type: "text", text: text2 }]
30908
31147
  })
30909
31148
  };
30910
31149
  thread.running = true;
@@ -30917,7 +31156,7 @@ var AppServerHost = class {
30917
31156
  const result = await thread.session.execute({
30918
31157
  type: "turn.start",
30919
31158
  turnId,
30920
- input: [{ type: "text", text }]
31159
+ input: [{ type: "text", text: text2 }]
30921
31160
  });
30922
31161
  if (!result.ok) {
30923
31162
  thread.running = false;
@@ -30951,14 +31190,14 @@ var AppServerHost = class {
30951
31190
  return;
30952
31191
  }
30953
31192
  }
30954
- let text;
31193
+ let text2;
30955
31194
  try {
30956
- text = requestText(params);
31195
+ text2 = requestText(params);
30957
31196
  } catch (error51) {
30958
31197
  await this.#writer.json(rpcError(request, -32602, errorMessage3(error51)));
30959
31198
  return;
30960
31199
  }
30961
- const commandCandidate = text.trimStart();
31200
+ const commandCandidate = text2.trimStart();
30962
31201
  if (thread.session.commands && /^\/[^\s/]+(?:\s|$)/u.test(commandCandidate)) {
30963
31202
  const commandText = commandCandidate.trimEnd();
30964
31203
  this.#pendingExternalCommandRequests.add(thread.id);
@@ -31004,7 +31243,7 @@ var AppServerHost = class {
31004
31243
  return;
31005
31244
  }
31006
31245
  try {
31007
- const started = await this.#beginExternalTurn(thread, text);
31246
+ const started = await this.#beginExternalTurn(thread, text2);
31008
31247
  try {
31009
31248
  await this.#writer.json(rpcEnvelope(request, { result: { turn: started.turn } }));
31010
31249
  } finally {
@@ -31025,7 +31264,7 @@ var AppServerHost = class {
31025
31264
  const started = await this.#externalSteering.run(
31026
31265
  thread,
31027
31266
  requestObject(request),
31028
- (text) => this.#beginExternalTurn(thread, text)
31267
+ (text2) => this.#beginExternalTurn(thread, text2)
31029
31268
  );
31030
31269
  try {
31031
31270
  await this.#writer.json(rpcEnvelope(request, { result: { turnId: started.turnId } }));
@@ -31044,7 +31283,7 @@ var AppServerHost = class {
31044
31283
  this.#signalActiveWorkChanged();
31045
31284
  }
31046
31285
  }
31047
- async #beginExternalTurn(thread, text) {
31286
+ async #beginExternalTurn(thread, text2) {
31048
31287
  if (this.#closeRequested || this.#externalRuntime.get(thread.id) !== thread) {
31049
31288
  throw new ExternalSteerError(-32073, "External Thread is no longer available");
31050
31289
  }
@@ -31070,7 +31309,7 @@ var AppServerHost = class {
31070
31309
  const result = await thread.session.execute({
31071
31310
  type: "turn.start",
31072
31311
  turnId,
31073
- input: [{ type: "text", text }]
31312
+ input: [{ type: "text", text: text2 }]
31074
31313
  });
31075
31314
  if (!result.ok) throw new ExternalSteerError(-32073, result.error.message);
31076
31315
  return { turnId, turn: projection.projector.pendingTurn(), gate };
@@ -31103,17 +31342,15 @@ var AppServerHost = class {
31103
31342
  resolve: cancellationGate.resolve
31104
31343
  };
31105
31344
  thread.responseGates.set(turnId, gate);
31106
- const result = await thread.session.execute({ type: "turn.cancel", turnId });
31107
- if (!result.ok) {
31108
- try {
31109
- await this.#writer.json(rpcError(request, -32074, result.error.message));
31110
- } finally {
31111
- gate.resolve();
31112
- }
31113
- return;
31345
+ let response;
31346
+ try {
31347
+ const result = await thread.session.execute({ type: "turn.cancel", turnId });
31348
+ response = result.ok ? rpcEnvelope(request, { result: {} }) : rpcError(request, -32074, result.error.message);
31349
+ } catch (error51) {
31350
+ response = rpcError(request, -32074, errorMessage3(error51));
31114
31351
  }
31115
31352
  try {
31116
- await this.#writer.json(rpcEnvelope(request, { result: {} }));
31353
+ await this.#writer.json(response);
31117
31354
  } finally {
31118
31355
  gate.resolve();
31119
31356
  }
@@ -31413,12 +31650,14 @@ var AppServerHost = class {
31413
31650
  await this.#repository.setDelegationStatus(delegation.delegationId, status);
31414
31651
  }
31415
31652
  }
31416
- for (const message of result.messages) await this.#writer.json(message);
31417
31653
  if (event.type === "turn.completed") {
31418
31654
  await this.#setThreadStatus(
31419
31655
  thread,
31420
31656
  this.#hasRunningSubagents(thread.id) ? { type: "active", activeFlags: [] } : { type: "idle" }
31421
31657
  );
31658
+ }
31659
+ for (const message of result.messages) await this.#writer.json(message);
31660
+ if (event.type === "turn.completed") {
31422
31661
  this.#externalSteering.terminal(thread.id, event.turnId, event.outcome);
31423
31662
  }
31424
31663
  }
@@ -31473,7 +31712,7 @@ var AppServerHost = class {
31473
31712
  const previousItems = new Map(
31474
31713
  child.turns.flatMap(
31475
31714
  (turn) => Array.isArray(turn.items) ? turn.items.flatMap(
31476
- (item) => isRecord12(item) && typeof item.id === "string" ? [[item.id, JSON.stringify(item)]] : []
31715
+ (item) => isRecord13(item) && typeof item.id === "string" ? [[item.id, JSON.stringify(item)]] : []
31477
31716
  ) : []
31478
31717
  )
31479
31718
  );
@@ -31486,7 +31725,7 @@ var AppServerHost = class {
31486
31725
  for (const turn of child.turns) {
31487
31726
  if (typeof turn.id !== "string" || !Array.isArray(turn.items)) continue;
31488
31727
  const changedItems = turn.items.filter(
31489
- (item) => isRecord12(item) && typeof item.id === "string" && previousItems.get(item.id) !== JSON.stringify(item)
31728
+ (item) => isRecord13(item) && typeof item.id === "string" && previousItems.get(item.id) !== JSON.stringify(item)
31490
31729
  );
31491
31730
  if (changedItems.length > 0) {
31492
31731
  await this.#writer.json({
@@ -31618,7 +31857,7 @@ var AppServerHost = class {
31618
31857
  }
31619
31858
  }
31620
31859
  async #handleDesktopApprovalResponse(value2) {
31621
- if (!isRecord12(value2) || !isHostApprovalRequestId(value2.id)) return false;
31860
+ if (!isRecord13(value2) || !isHostApprovalRequestId(value2.id)) return false;
31622
31861
  const pending = this.#pendingDesktopApprovals.get(value2.id);
31623
31862
  if (!pending) return true;
31624
31863
  this.#pendingDesktopApprovals.delete(value2.id);
@@ -31740,7 +31979,7 @@ var AppServerHost = class {
31740
31979
  }
31741
31980
  }
31742
31981
  async #handleDesktopQuestionResponse(value2) {
31743
- if (!isRecord12(value2) || !isHostQuestionRequestId(value2.id)) return false;
31982
+ if (!isRecord13(value2) || !isHostQuestionRequestId(value2.id)) return false;
31744
31983
  const pending = this.#pendingDesktopQuestions.get(value2.id);
31745
31984
  if (!pending) return true;
31746
31985
  this.#pendingDesktopQuestions.delete(value2.id);
@@ -31936,9 +32175,11 @@ var DelegationControlRegistry = class {
31936
32175
  );
31937
32176
  }
31938
32177
  if (registrations.length === 1) return registrations[0];
31939
- throw new DelegationControlError("THREAD_NOT_FOUND", "Thread was not found", {
31940
- matchingRuntimeCount: 0
31941
- });
32178
+ throw new DelegationControlError(
32179
+ "PARENT_THREAD_AMBIGUOUS",
32180
+ "Thread is not owned by exactly one active Host Runtime session",
32181
+ { matchingRuntimeCount: 0 }
32182
+ );
31942
32183
  }
31943
32184
  #compareThreads(left, right, sort) {
31944
32185
  const field = sort.startsWith("created") ? "createdAt" : "updatedAt";
@@ -32155,6 +32396,7 @@ import path15 from "node:path";
32155
32396
  var SKILL_VERSION = 5;
32156
32397
  var SKILL_RELATIVE_PATH = path15.join("skills", "codexhost-delegation", "SKILL.md");
32157
32398
  var PREVIOUS_MANAGED_DIGESTS = [
32399
+ "aff258622dc8ff321f32b15620d081e578cb9c9ed1134d6a57f35ca8e7762c0a",
32158
32400
  "ba509f57e5448e796b3dfdd5031dcb08672eded50b61c0a54de84cfa02c49dd3",
32159
32401
  "d3ddf6db9bc5c5df825479c885bbbf0ca08da66f7057a12e02e1fdf57525149e",
32160
32402
  "15eb63519ff867e1536c97188a0c43738d7a49d38d4d6adeb7a1036726e7246d",
@@ -32164,12 +32406,12 @@ var CODEXHOST_DELEGATION_SKILL = `---
32164
32406
  name: codexhost-delegation
32165
32407
  version: ${SKILL_VERSION}
32166
32408
  description: >
32167
- Delegate work to another coding agent. Use when the user explicitly asks
32168
- Claude Code, Pi, Codex/OpenAI, OMP, Grok, another agent, or an agent mentioned
32169
- as @<agent> to independently review, investigate, implement, test, or verify
32170
- something. Do not use when the user is merely discussing, comparing, or
32171
- configuring agents, choosing a Model or Provider, or asking the current agent
32172
- to role-play as another agent.
32409
+ Delegate tasks to other coding agents, or read and follow up on existing
32410
+ external agent sessions. Use when the user asks another agent (including
32411
+ @agent) to independently perform a task, or asks to view a specified external
32412
+ session's content, progress, or results, send follow-up messages, wait, or
32413
+ cancel a task. Not for recapping the current conversation, discussing or
32414
+ configuring agents, or role-playing.
32173
32415
  ---
32174
32416
 
32175
32417
  # Execute the task
@@ -32194,9 +32436,14 @@ When the user asks for a specific Model or Thinking level, inspect the target
32194
32436
  Harness first and use the exact opaque IDs returned by the authoritative CLI.
32195
32437
  When they do not specify either setting, omit it so the target keeps its default.
32196
32438
 
32197
- Create an independent child session and submit the requested task.
32439
+ For a new delegation, create an independent child session and submit the
32440
+ requested task. For an existing external session, resolve the target from the
32441
+ user-provided session link, identifier, or context and operate on that Thread
32442
+ directly; it need not have been created by the current assistant. If the target
32443
+ is ambiguous, ask the user to identify it. Keep requests to view or summarize a
32444
+ session read-only.
32198
32445
 
32199
- After starting the task, choose the appropriate next action based on the
32446
+ For a new or existing task, choose the appropriate next action based on the
32200
32447
  user’s request and the task:
32201
32448
 
32202
32449
  - send a follow-up message to the same Thread;
@@ -32206,10 +32453,11 @@ user’s request and the task:
32206
32453
  - check it again later;
32207
32454
  - leave it running in the background.
32208
32455
 
32209
- When the result is needed, explicitly read the child Thread. Report only the
32456
+ When the result is needed, explicitly read the target Thread. Report only the
32210
32457
  visible result returned by that Thread.
32211
32458
 
32212
- Provide the user with the necessary tracking information, including:
32459
+ Provide the user with the necessary tracking information available from the
32460
+ CLI; omit unavailable fields rather than inventing them:
32213
32461
 
32214
32462
  - target agent;
32215
32463
  - \`delegationId\`;
@@ -34905,10 +35153,13 @@ async function runRemoteHostCli(input) {
34905
35153
  var HARNESS_BROKER_PROTOCOL_VERSION = 1;
34906
35154
  var HARNESS_BROKER_MAX_FRAME_BYTES = 8 * 1024 * 1024;
34907
35155
  var HARNESS_BROKER_MAX_PENDING_REQUESTS = 32;
35156
+ var HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE = 100;
34908
35157
  var harnessBrokerMethodSchema = external_exports.enum([
34909
35158
  "adapter.inspect",
34910
35159
  "adapter.inspectAccount",
34911
35160
  "adapter.open",
35161
+ "adapter.sessionImport.list",
35162
+ "adapter.sessionImport.resolve",
34912
35163
  "adapter.subagent.readSnapshot",
34913
35164
  "session.readSnapshot",
34914
35165
  "session.refreshUsage",
@@ -35064,6 +35315,27 @@ var brokerOpenInputSchema = external_exports.discriminatedUnion("kind", [
35064
35315
  rollbackSchema
35065
35316
  ]);
35066
35317
  var brokerInspectInputSchema = external_exports.object({ cwd: cwdSchema.optional(), refresh: external_exports.boolean().optional() }).strict();
35318
+ var brokerSessionImportListParamsSchema = external_exports.object({
35319
+ offset: external_exports.number().int().nonnegative().safe(),
35320
+ limit: external_exports.number().int().min(1).max(HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE)
35321
+ }).strict();
35322
+ var brokerSessionImportResolveParamsSchema = external_exports.object({ nativeSessionId: harnessSessionImportIdSchema }).strict();
35323
+ var brokerSessionImportCandidatesSchema = external_exports.array(harnessSessionImportCandidateSchema);
35324
+ var brokerSessionImportPageSchema = external_exports.object({
35325
+ candidates: external_exports.array(harnessSessionImportCandidateSchema).max(HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE),
35326
+ total: external_exports.number().int().nonnegative().safe()
35327
+ }).strict();
35328
+ var brokerSessionImportSourceSchema = external_exports.object({
35329
+ candidate: harnessSessionImportCandidateSchema,
35330
+ nativeRef: nativeSessionRefSchema
35331
+ }).strict().superRefine((source, context) => {
35332
+ if (source.nativeRef.harnessId !== "claude-code" || source.nativeRef.nativeSessionId !== source.candidate.nativeSessionId) {
35333
+ context.addIssue({
35334
+ code: "custom",
35335
+ message: "Claude Session import source identity does not match"
35336
+ });
35337
+ }
35338
+ });
35067
35339
  var textInputSchema = external_exports.object({ type: external_exports.literal("text"), text: external_exports.string().max(4e6) }).strict();
35068
35340
  var turnStartSchema = external_exports.object({
35069
35341
  type: external_exports.literal("turn.start"),
@@ -35562,6 +35834,50 @@ async function startHarnessBrokerServer(input) {
35562
35834
  return { ok: false, error: harnessError("Claude subagents are unavailable", false) };
35563
35835
  return subagents.readSnapshot(subagentReadSnapshotSchema.parse(request.params));
35564
35836
  }
35837
+ if (request.method === "adapter.sessionImport.list") {
35838
+ const { limit, offset } = brokerSessionImportListParamsSchema.parse(request.params);
35839
+ const sessionImport = input.adapter.sessionImport;
35840
+ if (!sessionImport?.resolveCandidate) {
35841
+ return {
35842
+ ok: false,
35843
+ error: harnessError("Claude Session import is unavailable", false)
35844
+ };
35845
+ }
35846
+ if (offset === 0) {
35847
+ const result = await sessionImport.listCandidates();
35848
+ if (!result.ok)
35849
+ return result;
35850
+ state.sessionImportCandidates = result.value.map((candidate) => harnessSessionImportCandidateSchema.parse(candidate));
35851
+ }
35852
+ const candidates = state.sessionImportCandidates;
35853
+ if (!candidates) {
35854
+ return {
35855
+ ok: false,
35856
+ error: {
35857
+ code: "invalidState",
35858
+ message: "Claude Session import page snapshot is unavailable",
35859
+ retryable: true,
35860
+ stage: "harnessBroker.sessionImport"
35861
+ }
35862
+ };
35863
+ }
35864
+ const page = candidates.slice(offset, offset + limit);
35865
+ const total = candidates.length;
35866
+ if (offset + page.length >= total)
35867
+ delete state.sessionImportCandidates;
35868
+ return { ok: true, value: { candidates: page, total } };
35869
+ }
35870
+ if (request.method === "adapter.sessionImport.resolve") {
35871
+ const { nativeSessionId } = brokerSessionImportResolveParamsSchema.parse(request.params);
35872
+ const resolveCandidate = input.adapter.sessionImport?.resolveCandidate;
35873
+ if (!resolveCandidate) {
35874
+ return {
35875
+ ok: false,
35876
+ error: harnessError("Claude Session import is unavailable", false)
35877
+ };
35878
+ }
35879
+ return resolveCandidate(nativeSessionId);
35880
+ }
35565
35881
  if (request.method === "adapter.open") {
35566
35882
  const openInput = brokerOpenInputSchema.parse(request.params);
35567
35883
  const sourceRef = openInput.kind === "create" ? void 0 : openInput.kind === "resume" ? openInput.nativeRef : openInput.sourceRef;