@liberseek/boft-cli-win32-arm64 0.8.3 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +117 -13
  4. package/app/console-web.js +713 -129
  5. package/app/desktop-controller.mjs +713 -42
  6. package/app/host-runtime.mjs +2535 -855
  7. package/app/plugins/antigravity/plugin.mjs +437 -67
  8. package/app/plugins/claude-code/plugin.mjs +758 -248
  9. package/app/plugins/codebuddy/plugin.mjs +348 -156
  10. package/app/plugins/codex-usage/plugin.mjs +258 -106
  11. package/app/plugins/copilot/assets/icon.png +0 -0
  12. package/app/plugins/copilot/manifest.json +26 -0
  13. package/app/plugins/copilot/plugin.mjs +34651 -0
  14. package/app/plugins/cursor-cli/plugin.mjs +20905 -44961
  15. package/app/plugins/deepseek-harness/plugin.mjs +195 -53
  16. package/app/plugins/enabled.json +1 -0
  17. package/app/plugins/grok/plugin.mjs +584 -138
  18. package/app/plugins/hermes/plugin.mjs +134 -13
  19. package/app/plugins/kimi-code/plugin.mjs +145 -26
  20. package/app/plugins/kiro-cli/plugin.mjs +145 -26
  21. package/app/plugins/muse/plugin.mjs +132 -14
  22. package/app/plugins/omp/plugin.mjs +2245 -2040
  23. package/app/plugins/opencode/plugin.mjs +196 -72
  24. package/app/plugins/pi/plugin.mjs +2643 -2309
  25. package/app/plugins/qoder/plugin.mjs +162 -40
  26. package/app/plugins/qoder-cn/plugin.mjs +162 -40
  27. package/app/plugins/workbuddy/plugin.mjs +609 -180
  28. package/app/plugins/zcode/plugin.mjs +192 -44
  29. package/app/renderer-extension.js +3405 -429
  30. package/bin/boft.exe +0 -0
  31. package/libexec/boft-node-repl.exe +0 -0
  32. package/libexec/boft-shim.exe +0 -0
  33. package/libexec/boft-updater.exe +0 -0
  34. package/package.json +1 -1
@@ -3308,10 +3308,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
3308
3308
  const shape = def.shape;
3309
3309
  const propValues = {};
3310
3310
  for (const key in shape) {
3311
- const field = shape[key]._zod;
3312
- if (field.values) {
3311
+ const field2 = shape[key]._zod;
3312
+ if (field2.values) {
3313
3313
  propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
3314
- for (const v of field.values)
3314
+ for (const v of field2.values)
3315
3315
  propValues[key].add(v);
3316
3316
  }
3317
3317
  }
@@ -14931,10 +14931,19 @@ var model = external_exports.string().min(1).max(512);
14931
14931
  var project = external_exports.string().min(1).max(4096);
14932
14932
  var usageStatisticsParamsSchema = external_exports.strictObject({
14933
14933
  range: external_exports.enum(USAGE_STATISTICS_RANGES),
14934
+ /** Display timezone for ranges, dates and hourly buckets; omitted means the Host's local zone. */
14935
+ timeZone: external_exports.string().min(1).max(128).refine((value) => {
14936
+ try {
14937
+ new Intl.DateTimeFormat("en", { timeZone: value });
14938
+ return true;
14939
+ } catch {
14940
+ return false;
14941
+ }
14942
+ }, "Unsupported usage statistics timezone").optional(),
14934
14943
  harness: harness.optional(),
14935
14944
  model: model.nullable().optional(),
14936
14945
  project: project.nullable().optional(),
14937
- /** One local date inside the range. */
14946
+ /** One date in the query timezone inside the range. */
14938
14947
  date: localDate.optional()
14939
14948
  });
14940
14949
  var usageStatisticsTotalsSchema = external_exports.strictObject({
@@ -14943,6 +14952,8 @@ var usageStatisticsTotalsSchema = external_exports.strictObject({
14943
14952
  cachedInputTokens: count,
14944
14953
  cacheWriteInputTokens: count,
14945
14954
  cacheKnownInputTokens: count,
14955
+ cacheHitCachedInputTokens: count,
14956
+ cacheHitInputTokens: count,
14946
14957
  outputTokens: count,
14947
14958
  reasoningOutputTokens: count,
14948
14959
  /** USD at the public price, summed over the priced requests only. */
@@ -14970,7 +14981,7 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
14970
14981
  });
14971
14982
  var usageStatisticsResultSchema = external_exports.strictObject({
14972
14983
  range: external_exports.enum(USAGE_STATISTICS_RANGES),
14973
- /** First local date of the range; null for all time. */
14984
+ /** First date in the query timezone (Host local when omitted); null for all time. */
14974
14985
  from: localDate.nullable(),
14975
14986
  to: localDate,
14976
14987
  /** The filters these figures apply, echoed so a late answer to older filters is recognised. */
@@ -15010,7 +15021,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
15010
15021
  totals: usageStatisticsTotalsSchema,
15011
15022
  /** Each date and Harness of the range: every filter except the day. */
15012
15023
  daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
15013
- /** Local weekday (0 = Sunday) and hour, all filters applied. */
15024
+ /** Weekday (0 = Sunday) and hour in the query timezone, all filters applied. */
15014
15025
  hourly: external_exports.array(external_exports.strictObject({
15015
15026
  weekday: external_exports.number().int().min(0).max(6),
15016
15027
  hour: external_exports.number().int().min(0).max(23),
@@ -15050,6 +15061,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
15050
15061
  var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
15051
15062
  var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
15052
15063
 
15064
+ // packages/shared-contracts/dist/thread-questions.js
15065
+ var field = external_exports.discriminatedUnion("type", [
15066
+ external_exports.object({
15067
+ id: external_exports.string().min(1),
15068
+ type: external_exports.literal("choice"),
15069
+ prompt: external_exports.string(),
15070
+ options: external_exports.array(external_exports.object({
15071
+ value: external_exports.string().min(1),
15072
+ label: external_exports.string(),
15073
+ description: external_exports.string().optional()
15074
+ })).min(1),
15075
+ multiple: external_exports.boolean(),
15076
+ allowOther: external_exports.boolean(),
15077
+ optional: external_exports.boolean()
15078
+ }),
15079
+ external_exports.object({
15080
+ id: external_exports.string().min(1),
15081
+ type: external_exports.literal("text"),
15082
+ prompt: external_exports.string(),
15083
+ multiline: external_exports.boolean(),
15084
+ secret: external_exports.literal(false),
15085
+ optional: external_exports.boolean(),
15086
+ placeholder: external_exports.string().optional(),
15087
+ prefill: external_exports.string().optional()
15088
+ })
15089
+ ]);
15090
+ var threadQuestionSchema = external_exports.object({
15091
+ interactionId: external_exports.string().min(1),
15092
+ turnId: external_exports.string().min(1),
15093
+ title: external_exports.string().optional(),
15094
+ questions: external_exports.array(field).min(1)
15095
+ }).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
15096
+ message: "Shared cards require at least one multi-select question"
15097
+ });
15098
+ var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
15099
+ var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
15100
+ var threadQuestionRespondParamsSchema = external_exports.strictObject({
15101
+ threadId: external_exports.string().min(1),
15102
+ turnId: external_exports.string().min(1),
15103
+ interactionId: external_exports.string().min(1),
15104
+ answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
15105
+ cancelled: external_exports.boolean().default(false)
15106
+ });
15107
+ var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
15108
+
15053
15109
  // packages/shared-contracts/dist/harness-plugins.js
15054
15110
  var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15055
15111
  var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
@@ -15152,6 +15208,8 @@ var CONSOLE_HOST_METHODS = Object.freeze([
15152
15208
  "codexhost/harness/display-settings/set",
15153
15209
  "codexhost/harness/inspect",
15154
15210
  "codexhost/harness/installation",
15211
+ "codexhost/harness/installation/start",
15212
+ "codexhost/harness/installation/status",
15155
15213
  "codexhost/harness/launch-settings/get",
15156
15214
  "codexhost/harness/launch-settings/set",
15157
15215
  HARNESS_LONG_CONTEXT_GET_METHOD,
@@ -15229,7 +15287,18 @@ var threadManualCompactionStartedSchema = external_exports.strictObject({
15229
15287
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
15230
15288
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
15231
15289
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
15290
+ var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
15291
+ var composerIndicatorsSchema = external_exports.array(external_exports.object({
15292
+ kind: external_exports.literal("countdown"),
15293
+ id: external_exports.string().min(1).max(64),
15294
+ expiresAtUnix: nonNegativeSafeIntegerSchema,
15295
+ label: indicatorTextSchema(256).optional(),
15296
+ tooltip: indicatorTextSchema(1024).optional()
15297
+ }).strict()).max(2).refine((entries) => new Set(entries.map(({ id }) => id)).size === entries.length, {
15298
+ message: "Composer indicator IDs must be unique"
15299
+ });
15232
15300
  var threadUsageSnapshotSchema = external_exports.object({
15301
+ composerIndicators: composerIndicatorsSchema.optional(),
15233
15302
  inputTokens: nonNegativeSafeIntegerSchema.optional(),
15234
15303
  cachedInputTokens: nonNegativeSafeIntegerSchema.optional(),
15235
15304
  cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
@@ -15655,7 +15724,9 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
15655
15724
  }).strict().optional(),
15656
15725
  input: external_exports.object({
15657
15726
  image: external_exports.boolean()
15658
- }).strict().optional()
15727
+ }).strict().optional(),
15728
+ /** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
15729
+ steer: external_exports.boolean().optional()
15659
15730
  }).strict();
15660
15731
  var harnessConfigurationStateSchema = external_exports.object({
15661
15732
  effectiveModel: harnessModelRefSchema.optional(),
@@ -15702,7 +15773,9 @@ var harnessInspectionSchema = external_exports.union([
15702
15773
  var harnessInspectParamsSchema = external_exports.object({
15703
15774
  harnessId: harnessIdSchema,
15704
15775
  cwd: nonBlankTextSchema2.max(16384).optional(),
15705
- refresh: external_exports.boolean().optional()
15776
+ refresh: external_exports.boolean().optional(),
15777
+ /** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
15778
+ purpose: external_exports.literal("availability").optional()
15706
15779
  }).strict();
15707
15780
  var harnessWebUiOpenParamsSchema = external_exports.object({
15708
15781
  harnessId: harnessIdSchema
@@ -15787,13 +15860,25 @@ var threadOwnershipListResultSchema = external_exports.object({
15787
15860
  seen.add(thread.threadId);
15788
15861
  }
15789
15862
  });
15863
+ var threadSteeringInspectParamsSchema = external_exports.object({
15864
+ threadId: hostThreadIdSchema,
15865
+ /** The text about to be steered; a Harness command always stops and restarts. */
15866
+ text: external_exports.string().optional()
15867
+ }).strict();
15868
+ var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15869
+ var threadSteeringInspectResultSchema = external_exports.object({
15870
+ delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
15871
+ }).strict();
15790
15872
 
15791
15873
  // packages/shared-contracts/dist/harness-route.js
15792
15874
  var harnessPluginRouteSchema = external_exports.object({
15793
15875
  harnessId: harnessPluginIdSchema,
15794
15876
  model: harnessModelRefSchema.optional(),
15795
15877
  thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
15796
- permissionModeId: harnessPermissionModeIdSchema.optional()
15878
+ permissionModeId: harnessPermissionModeIdSchema.optional(),
15879
+ /** A draft prewarm create: stays unsubmitted until the user's first Turn.
15880
+ * Desktop forwards only the Model of a main-process prewarm to thread/start. */
15881
+ prewarm: external_exports.literal(true).optional()
15797
15882
  }).strict();
15798
15883
 
15799
15884
  // packages/shared-contracts/dist/harness-launch-settings.js
@@ -15819,6 +15904,10 @@ var harnessInstallationStateSchema = external_exports.object({
15819
15904
  latestVersion: external_exports.string().min(1).max(128),
15820
15905
  updateAvailable: external_exports.boolean(),
15821
15906
  canUpdate: external_exports.boolean(),
15907
+ /** Defaults to CLI; some Harnesses ship only inside a desktop application. */
15908
+ versionKind: external_exports.enum(["cli", "application"]).optional(),
15909
+ /** Official download opened by the user; does not imply an automatic installation. */
15910
+ manualUpdateUrl: external_exports.url().max(2048).refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Manual updates require a credential-free HTTPS URL").optional(),
15822
15911
  // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
15823
15912
  message: external_exports.string().max(2048).optional(),
15824
15913
  messageCode: external_exports.string().min(1).max(128).optional(),
@@ -15826,6 +15915,20 @@ var harnessInstallationStateSchema = external_exports.object({
15826
15915
  notice: harnessLocalizedTextSchema.optional(),
15827
15916
  latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
15828
15917
  }).strict();
15918
+ var harnessInstallationTaskParamsSchema = external_exports.object({ taskId: external_exports.string().uuid() }).strict();
15919
+ var harnessInstallationTaskSchema = external_exports.discriminatedUnion("status", [
15920
+ external_exports.object({ taskId: external_exports.string().uuid(), status: external_exports.literal("running") }).strict(),
15921
+ external_exports.object({
15922
+ taskId: external_exports.string().uuid(),
15923
+ status: external_exports.literal("succeeded"),
15924
+ result: harnessInstallationStateSchema
15925
+ }).strict(),
15926
+ external_exports.object({
15927
+ taskId: external_exports.string().uuid(),
15928
+ status: external_exports.literal("failed"),
15929
+ error: external_exports.object({ code: external_exports.number().int(), message: external_exports.string().min(1).max(2048) }).strict()
15930
+ }).strict()
15931
+ ]);
15829
15932
 
15830
15933
  // packages/shared-contracts/dist/codex-accounts.js
15831
15934
  var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
@@ -16651,8 +16754,99 @@ function retainRendererHostResponses(client, hostId2, target) {
16651
16754
  };
16652
16755
  }
16653
16756
 
16757
+ // packages/desktop-control/src/renderer-prewarm-consumption.ts
16758
+ function isolateRendererPrewarmConsumption(manager, discardExternal) {
16759
+ const record3 = (value) => value !== null && typeof value === "object";
16760
+ if (!record3(manager) || !record3(manager.threadCreation)) return null;
16761
+ const creation = manager.threadCreation;
16762
+ const originalStart = manager.startConversation;
16763
+ const original = creation.createConversation;
16764
+ const params = creation.params;
16765
+ if (typeof originalStart !== "function" || typeof original !== "function" || !record3(params))
16766
+ return null;
16767
+ const prototype = Object.getPrototypeOf(creation);
16768
+ if (!record3(prototype) || typeof prototype.constructor !== "function") return null;
16769
+ if (Object.keys(creation).some((key) => key !== "params" && typeof creation[key] !== "function") || /#[A-Za-z_$]/u.test(Function.prototype.toString.call(prototype.constructor)))
16770
+ return null;
16771
+ const pool = params.prewarmedThreadManager;
16772
+ if (!record3(pool) || typeof pool.hasPrewarmedThread !== "function" || typeof pool.consumePrewarmedThread !== "function" || typeof pool.deletePrewarmedThread !== "function")
16773
+ return null;
16774
+ const consume = pool.consumePrewarmedThread;
16775
+ const hasPrewarm = pool.hasPrewarmedThread;
16776
+ const draftModels = /* @__PURE__ */ new Map();
16777
+ const draftIdentity = /* @__PURE__ */ Symbol("codexhost draft creation");
16778
+ const external = (model2) => typeof model2 === "string" && model2.startsWith("codexhost/");
16779
+ const routedStart = function(input, options, ...args) {
16780
+ const draftId = record3(options) ? options.clientThreadId : null;
16781
+ const mode = record3(input) && record3(input.collaborationMode) ? input.collaborationMode : null;
16782
+ const origin = mode ? Reflect.get(mode, draftIdentity) : void 0;
16783
+ if (mode && record3(mode.settings) && external(mode.settings.model))
16784
+ return originalStart.call(this, input, options, ...args);
16785
+ const model2 = (typeof draftId === "string" ? draftModels.get(draftId) : void 0) ?? (typeof origin === "string" ? draftModels.get(origin) : void 0);
16786
+ if (!model2) return originalStart.call(this, input, options, ...args);
16787
+ if (!record3(input) || !record3(input.collaborationMode) || !record3(input.collaborationMode.settings))
16788
+ throw new Error("External draft creation is missing its native Model settings");
16789
+ const routed = {
16790
+ ...input,
16791
+ collaborationMode: {
16792
+ ...input.collaborationMode,
16793
+ settings: { ...input.collaborationMode.settings, model: model2 }
16794
+ }
16795
+ };
16796
+ return originalStart.call(this, routed, options, ...args);
16797
+ };
16798
+ const wrapped = function(input, ...args) {
16799
+ const mode = record3(input) && record3(input.collaborationMode) ? input.collaborationMode : null;
16800
+ const expected = mode && record3(mode.settings) ? mode.settings.model : null;
16801
+ const scopedPool = Object.create(pool);
16802
+ scopedPool.hasPrewarmedThread = (...parameters) => hasPrewarm.apply(pool, parameters);
16803
+ scopedPool.consumePrewarmedThread = async (...consumeArgs) => {
16804
+ const warmed = await consume.apply(pool, consumeArgs);
16805
+ if (!record3(warmed) || !record3(warmed.response)) return warmed;
16806
+ const response = warmed.response;
16807
+ if (!external(expected) && !external(response.model)) return warmed;
16808
+ if (external(expected) && expected === response.model) return warmed;
16809
+ if (record3(response.thread) && typeof response.thread.id === "string") {
16810
+ const threadId = response.thread.id;
16811
+ if (external(response.model)) discardExternal(threadId);
16812
+ else
16813
+ void Promise.resolve().then(() => pool.deletePrewarmedThread(threadId)).catch(() => void 0);
16814
+ }
16815
+ return null;
16816
+ };
16817
+ const invocation = Object.create(creation);
16818
+ invocation.params = { ...params, prewarmedThreadManager: scopedPool };
16819
+ return original.call(invocation, input, ...args);
16820
+ };
16821
+ creation.createConversation = wrapped;
16822
+ manager.startConversation = routedStart;
16823
+ return {
16824
+ selectDraft(draftId, model2, creationModes = []) {
16825
+ if (draftId === void 0) {
16826
+ if (model2 === null) draftModels.clear();
16827
+ } else if (model2 === null) draftModels.delete(draftId);
16828
+ else {
16829
+ if (!draftId.startsWith("client-new-thread:") || !external(model2))
16830
+ throw new Error("External draft route is missing its client Thread identity");
16831
+ draftModels.set(draftId, model2);
16832
+ for (const mode of creationModes)
16833
+ Object.defineProperty(mode, draftIdentity, {
16834
+ configurable: true,
16835
+ enumerable: true,
16836
+ value: draftId
16837
+ });
16838
+ }
16839
+ },
16840
+ dispose() {
16841
+ draftModels.clear();
16842
+ if (manager.startConversation === routedStart) manager.startConversation = originalStart;
16843
+ if (creation.createConversation === wrapped) creation.createConversation = original;
16844
+ }
16845
+ };
16846
+ }
16847
+
16654
16848
  // packages/desktop-control/src/renderer-draft-prewarm-runtime.ts
16655
- function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses) {
16849
+ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses, isolateConsumption = isolateRendererPrewarmConsumption) {
16656
16850
  let disposed = false;
16657
16851
  const originalSend = bridge.sendRequest;
16658
16852
  const originalPrewarm = bridge.prewarmThreadStart;
@@ -17033,26 +17227,16 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17033
17227
  if (threadId && knownOfficialThreadIds.has(threadId)) return false;
17034
17228
  return selectedModel !== null && (method.startsWith("thread/") || method.startsWith("turn/") || method.startsWith("review/"));
17035
17229
  };
17036
- const routeThreadStart = (parameters) => {
17037
- if (!isRecord3(parameters) || parameters.ephemeral === true) {
17038
- return parameters;
17039
- }
17040
- return {
17041
- ...parameters,
17042
- ...selectedModel === null ? {} : { model: selectedModel }
17043
- };
17044
- };
17045
17230
  const routedSend = (method, parameters, options) => {
17046
17231
  if (method === "turn/start" || method === "thread/resume" || method === "codexhost/thread/command/execute") {
17047
17232
  const threadId = threadIdFromParameters(parameters);
17048
17233
  if (threadId) externalPrewarms.delete(threadId);
17049
17234
  }
17050
- const routedParameters = method === "thread/start" ? routeThreadStart(parameters) : parameters;
17051
17235
  const sendBridged = () => initializeBridge().then(
17052
- () => enqueueBridgeRequest(method, routedParameters, options)
17236
+ () => enqueueBridgeRequest(method, parameters, options)
17053
17237
  );
17054
- const sendDirect = () => options === void 0 ? originalSend.call(bridge, method, routedParameters) : originalSend.call(bridge, method, routedParameters, options);
17055
- const unresolvedThreadId = shouldResolveThreadOwnership(method, routedParameters);
17238
+ const sendDirect = () => options === void 0 ? originalSend.call(bridge, method, parameters) : originalSend.call(bridge, method, parameters, options);
17239
+ const unresolvedThreadId = shouldResolveThreadOwnership(method, parameters);
17056
17240
  if (unresolvedThreadId) {
17057
17241
  return resolveThreadOwnership(unresolvedThreadId).then(
17058
17242
  (owner) => owner === "external" ? sendBridged() : sendDirect(),
@@ -17068,7 +17252,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17068
17252
  }
17069
17253
  );
17070
17254
  }
17071
- return shouldUseBridge(method, routedParameters) ? sendBridged() : sendDirect();
17255
+ return shouldUseBridge(method, parameters) ? sendBridged() : sendDirect();
17072
17256
  };
17073
17257
  const publishDraftWorkspace = (parameters) => {
17074
17258
  if (!isRecord3(parameters) || parameters.ephemeral === true) return;
@@ -17098,10 +17282,10 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17098
17282
  const discardExternalPrewarms = () => {
17099
17283
  for (const threadId of externalPrewarms) discardExternalPrewarm(threadId);
17100
17284
  };
17285
+ const restoreConsumption = isolateConsumption(manager, discardExternalPrewarm);
17101
17286
  const routedPrewarm = (parameters, options) => {
17102
- const routed = routeThreadStart(parameters);
17103
- const external = isRecord3(routed) && routed.ephemeral !== true && typeof routed.model === "string" && routed.model.startsWith("codexhost/");
17104
- const routedParameters = external ? { ...routed, codexhostPrewarm: true } : routed;
17287
+ const external = isRecord3(parameters) && parameters.ephemeral !== true && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
17288
+ const routedParameters = external ? { ...parameters, codexhostPrewarm: true } : parameters;
17105
17289
  const generation = prewarmGeneration;
17106
17290
  publishDraftWorkspace(routedParameters);
17107
17291
  const pending = shouldUseBridge("thread/start", routedParameters) ? routedSend("thread/start", routedParameters, options) : options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
@@ -17154,6 +17338,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17154
17338
  const policy = Object.freeze({
17155
17339
  state: "ready",
17156
17340
  hostId: hostId2,
17341
+ scopedCreation: restoreConsumption !== null,
17157
17342
  owns(candidateManager, candidate, candidateHostId, candidatePrewarmedThreadManager, requiresCurrentManager) {
17158
17343
  return !disposed && candidateManager === manager && candidate === bridge && candidateHostId === hostId2 && candidatePrewarmedThreadManager === prewarmedThreadManager && requiresCurrentManager === !!isCurrentManager;
17159
17344
  },
@@ -17162,12 +17347,13 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17162
17347
  throw new Error("Renderer request manager is retired");
17163
17348
  return manager;
17164
17349
  },
17165
- select(model2) {
17350
+ select(model2, draftId, creationModes) {
17166
17351
  if (disposed || isCurrentManager && !isCurrentManager())
17167
17352
  throw new Error("Renderer request manager is retired");
17168
17353
  if (model2 !== null && (typeof model2 !== "string" || !model2.startsWith("codexhost/"))) {
17169
17354
  throw new Error("Draft route Model must be a codexhost transport carrier");
17170
17355
  }
17356
+ restoreConsumption?.selectDraft(draftId, model2, creationModes);
17171
17357
  if (selectedModel === model2) return false;
17172
17358
  selectedModel = model2;
17173
17359
  prewarmGeneration += 1;
@@ -17188,6 +17374,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17188
17374
  disposed = true;
17189
17375
  prewarmGeneration += 1;
17190
17376
  retireResponses();
17377
+ restoreConsumption?.dispose();
17191
17378
  if (bridge.sendRequest === routedSend) bridge.sendRequest = originalSend;
17192
17379
  if (bridge.prewarmThreadStart === routedPrewarm) {
17193
17380
  bridge.prewarmThreadStart = originalPrewarm;
@@ -17224,19 +17411,23 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
17224
17411
 
17225
17412
  // packages/desktop-control/src/renderer-host-discovery.ts
17226
17413
  function requestManagerFromHookState(value, hostId2) {
17227
- const record2 = (candidate) => typeof candidate === "object" && candidate !== null;
17414
+ const record3 = (candidate) => typeof candidate === "object" && candidate !== null;
17228
17415
  const manager = (candidate) => {
17229
- if (!record2(candidate) || !record2(candidate.requestClient) || !record2(candidate.prewarmedThreadManager))
17416
+ if (!record3(candidate) || !record3(candidate.requestClient) || !record3(candidate.prewarmedThreadManager))
17230
17417
  return null;
17231
17418
  const bridge = candidate.requestClient;
17232
17419
  return typeof candidate.sendRequest === "function" && typeof bridge.sendRequest === "function" && typeof bridge.prewarmThreadStart === "function" && typeof bridge.enqueueRequest === "function" && typeof candidate.prewarmedThreadManager.discardAllPrewarmedThreads === "function" ? candidate : null;
17233
17420
  };
17234
- if (!record2(value)) return null;
17421
+ if (!record3(value)) return null;
17235
17422
  const direct = manager(value) ?? manager(value.manager);
17236
17423
  if (direct) return direct;
17237
- if (!hostId2 || typeof value.addManager !== "function" || typeof value.getForHostId !== "function" || typeof value.waitForManagerForHostId !== "function")
17424
+ if (!hostId2 || typeof value.addManager !== "function" || typeof value.getForHostId !== "function")
17238
17425
  return null;
17239
- return manager(value.getForHostId(hostId2));
17426
+ try {
17427
+ return manager(value.getForHostId(hostId2));
17428
+ } catch {
17429
+ return null;
17430
+ }
17240
17431
  }
17241
17432
  function discoverRendererHosts(root, ancestors = committedReactAncestors, managerFrom = requestManagerFromHookState) {
17242
17433
  const editors = [
@@ -17271,7 +17462,7 @@ function discoverRendererHosts(root, ancestors = committedReactAncestors, manage
17271
17462
  const value = hook.memoizedState;
17272
17463
  const manager = managerFrom(value);
17273
17464
  if (manager) managers.add(manager);
17274
- if (value && typeof value === "object" && "addManager" in value && typeof value.addManager === "function" && "getForHostId" in value && typeof value.getForHostId === "function" && "waitForManagerForHostId" in value && typeof value.waitForManagerForHostId === "function") {
17465
+ if (value && typeof value === "object" && "addManager" in value && typeof value.addManager === "function" && "getForHostId" in value && typeof value.getForHostId === "function") {
17275
17466
  registries.add(value);
17276
17467
  }
17277
17468
  hook = hook.next && typeof hook.next === "object" ? hook.next : null;
@@ -17286,7 +17477,13 @@ function discoverRendererHosts(root, ancestors = committedReactAncestors, manage
17286
17477
  }
17287
17478
  function resolveRendererHostManager(discovery, hostId2, managerFrom = requestManagerFromHookState) {
17288
17479
  if (!hostId2) return null;
17289
- const candidates = discovery.registries.length ? discovery.registries.map((registry2) => managerFrom(registry2.getForHostId(hostId2))) : discovery.managers;
17480
+ const candidates = discovery.registries.length ? discovery.registries.flatMap((registry2) => {
17481
+ try {
17482
+ return [managerFrom(registry2.getForHostId(hostId2))];
17483
+ } catch {
17484
+ return [];
17485
+ }
17486
+ }) : discovery.managers;
17290
17487
  const matching = new Set(
17291
17488
  candidates.filter(
17292
17489
  (manager) => manager && (manager.getHostId?.() ?? manager.requestClient.hostId) === hostId2 && (manager.requestClient.hostId === void 0 || manager.requestClient.hostId === hostId2)
@@ -17431,6 +17628,335 @@ function installRendererHostRouting(root, target, discover, resolve, createPolic
17431
17628
  return routing;
17432
17629
  }
17433
17630
 
17631
+ // packages/desktop-control/src/renderer-host-rpc-discovery.ts
17632
+ function findRendererAppScopeStore(root) {
17633
+ const MAX_VISITED_FIBERS = 5e4;
17634
+ const record3 = (value) => typeof value === "object" && value !== null;
17635
+ const container = root.getElementById?.("root");
17636
+ if (!record3(container)) return null;
17637
+ const key = Object.getOwnPropertyNames(container).find(
17638
+ (name) => name.startsWith("__reactContainer$")
17639
+ );
17640
+ const first = key ? container[key] : null;
17641
+ if (!record3(first)) return null;
17642
+ const isScopeHandle = (value) => record3(value) && record3(value.node) && "chain" in value && "scope" in value && typeof value.get === "function" && typeof value.set === "function" && typeof value.watch === "function";
17643
+ const stack = [first];
17644
+ const seen = /* @__PURE__ */ new Set();
17645
+ while (stack.length && seen.size < MAX_VISITED_FIBERS) {
17646
+ const fiber = stack.pop();
17647
+ if (seen.has(fiber)) continue;
17648
+ seen.add(fiber);
17649
+ let hook = fiber.memoizedState;
17650
+ for (let index = 0; record3(hook) && "next" in hook && index < 150; index += 1) {
17651
+ const state = hook.memoizedState;
17652
+ const handle = record3(state) ? state.current : null;
17653
+ if (isScopeHandle(handle)) {
17654
+ let node = handle.node;
17655
+ const nodes = /* @__PURE__ */ new Set();
17656
+ while (record3(node.parent) && !nodes.has(node.parent)) {
17657
+ nodes.add(node);
17658
+ node = node.parent;
17659
+ }
17660
+ const bindings = node.familyBindings;
17661
+ return record3(bindings) && typeof bindings.get === "function" && typeof bindings.entries === "function" ? node : null;
17662
+ }
17663
+ hook = hook.next;
17664
+ }
17665
+ if (record3(fiber.sibling)) stack.push(fiber.sibling);
17666
+ if (record3(fiber.child)) stack.push(fiber.child);
17667
+ }
17668
+ return null;
17669
+ }
17670
+ function findRendererHostRpcFamily(store) {
17671
+ const record3 = (value) => typeof value === "object" && value !== null;
17672
+ const families = /* @__PURE__ */ new Set();
17673
+ for (const [definition, members] of store.familyBindings) {
17674
+ if (!record3(definition) || definition.kind !== "signal-family") continue;
17675
+ if (!record3(members) || typeof members.get !== "function") continue;
17676
+ for (const [hostId2, member] of members) {
17677
+ if (typeof hostId2 !== "string" || !record3(member)) continue;
17678
+ const signal = member.value;
17679
+ if (!record3(signal) || typeof signal.get !== "function") continue;
17680
+ let value;
17681
+ try {
17682
+ value = signal.get();
17683
+ } catch {
17684
+ continue;
17685
+ }
17686
+ if (record3(value) && Object.keys(value).length === 2 && typeof value.status === "string" && record3(value.client) && value.client.hostId === hostId2 && "rpc" in value.client) {
17687
+ families.add(members);
17688
+ break;
17689
+ }
17690
+ }
17691
+ }
17692
+ if (families.size !== 1) return null;
17693
+ return { store, family: families.values().next().value };
17694
+ }
17695
+ function resolveRendererHostRpc(discovery, hostId2) {
17696
+ const record3 = (value2) => typeof value2 === "object" && value2 !== null;
17697
+ const signal = discovery.family.get(hostId2)?.value;
17698
+ if (!record3(signal) || typeof signal.get !== "function") return null;
17699
+ let value;
17700
+ try {
17701
+ value = signal.get();
17702
+ } catch {
17703
+ return null;
17704
+ }
17705
+ if (!record3(value) || value.status !== "ready" || !record3(value.client) || value.client.hostId !== hostId2)
17706
+ return null;
17707
+ const rpc = value.client.rpc;
17708
+ return typeof rpc === "function" || record3(rpc) ? rpc : null;
17709
+ }
17710
+ function rendererHostRpcHostIds(discovery) {
17711
+ return [...discovery.family.keys()].filter(
17712
+ (hostId2) => typeof hostId2 === "string"
17713
+ );
17714
+ }
17715
+
17716
+ // packages/desktop-control/src/renderer-host-rpc-routing.ts
17717
+ function installRendererHostRpcRouting(root, target, dependencies) {
17718
+ const existing = target.__codexhostHostRoutingV1;
17719
+ if (existing) return existing;
17720
+ let disposed = false;
17721
+ let discovery = null;
17722
+ const routes = /* @__PURE__ */ new Map();
17723
+ const read = () => {
17724
+ if (disposed) return null;
17725
+ if (!discovery) {
17726
+ const store = dependencies.findStore(root);
17727
+ discovery = store ? dependencies.findFamily(store) : null;
17728
+ }
17729
+ return discovery;
17730
+ };
17731
+ if (!read()) return null;
17732
+ const isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
17733
+ const externalDrafts = /* @__PURE__ */ new Map();
17734
+ const selectedModels = /* @__PURE__ */ new Map();
17735
+ const prewarmCarrier = (carrier) => {
17736
+ const prefix = "codexhost/plugin-v1@";
17737
+ if (!carrier.startsWith(prefix)) return null;
17738
+ try {
17739
+ const json2 = carrier.slice(prefix.length).replace(/[a-f0-9]{2}/gu, (byte) => String.fromCharCode(Number.parseInt(byte, 16)));
17740
+ const route = JSON.parse(json2);
17741
+ if (!isRecord3(route)) return null;
17742
+ const payload = [...JSON.stringify({ ...route, prewarm: true })].map((character) => character.charCodeAt(0).toString(16).padStart(2, "0")).join("");
17743
+ return `${prefix}${payload}`;
17744
+ } catch {
17745
+ return null;
17746
+ }
17747
+ };
17748
+ const publishDraftWorkspace = (hostId2, cwd) => {
17749
+ if (typeof cwd !== "string" || cwd.length === 0) return;
17750
+ const drafts = isRecord3(target.__codexhostDraftWorkspacesV1) ? target.__codexhostDraftWorkspacesV1 : {};
17751
+ if (drafts[hostId2] === cwd) return;
17752
+ drafts[hostId2] = cwd;
17753
+ Object.defineProperty(target, "__codexhostDraftWorkspacesV1", {
17754
+ configurable: true,
17755
+ value: drafts
17756
+ });
17757
+ if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
17758
+ target.dispatchEvent(
17759
+ new CustomEvent("codexhost:draft-workspace", { detail: { hostId: hostId2, cwd } })
17760
+ );
17761
+ }
17762
+ };
17763
+ const routeCreationCall = (message) => {
17764
+ if (!Array.isArray(message) || message.length !== 2 || message[0] !== "push") return message;
17765
+ const expression = message[1];
17766
+ if (!Array.isArray(expression) || expression.length !== 4 || expression[0] !== "pipeline")
17767
+ return message;
17768
+ const [, importId, path3, args] = expression;
17769
+ if (!Array.isArray(path3) || path3.length !== 1 || !Array.isArray(args)) return message;
17770
+ const [input, options] = args;
17771
+ if (!isRecord3(input) || !isRecord3(input.collaborationMode)) return message;
17772
+ const settings = input.collaborationMode.settings;
17773
+ if (!isRecord3(settings)) return message;
17774
+ let model2 = null;
17775
+ if (path3[0] === "startConversation") {
17776
+ const draftId = isRecord3(options) ? options.clientThreadId : null;
17777
+ model2 = typeof draftId === "string" ? externalDrafts.get(draftId)?.model ?? null : null;
17778
+ } else if (path3[0] === "prewarmConversation") {
17779
+ if (input.ephemeral !== true) publishDraftWorkspace("local", input.cwd);
17780
+ const selected = selectedModels.get("local");
17781
+ model2 = selected ? prewarmCarrier(selected) : null;
17782
+ }
17783
+ if (!model2) return message;
17784
+ return [
17785
+ "push",
17786
+ [
17787
+ "pipeline",
17788
+ importId,
17789
+ path3,
17790
+ [
17791
+ {
17792
+ ...input,
17793
+ collaborationMode: { ...input.collaborationMode, settings: { ...settings, model: model2 } }
17794
+ },
17795
+ ...args.slice(1)
17796
+ ]
17797
+ ]
17798
+ ];
17799
+ };
17800
+ const port = dependencies.portPrototype;
17801
+ const originalPostMessage = port.postMessage;
17802
+ const postMessage = function(message, ...rest) {
17803
+ let routed = message;
17804
+ try {
17805
+ routed = disposed ? message : routeCreationCall(message);
17806
+ } catch {
17807
+ routed = message;
17808
+ }
17809
+ return originalPostMessage.call(this, routed, ...rest);
17810
+ };
17811
+ port.postMessage = postMessage;
17812
+ const createRoute = (hostId2, rpc) => {
17813
+ let retired = false;
17814
+ const isCurrent = () => !retired && !disposed && routes.get(hostId2)?.rpc === rpc;
17815
+ const manager = Object.freeze({
17816
+ kind: "main-process-rpc",
17817
+ getHostId: () => hostId2,
17818
+ sendRequest(method, params, options) {
17819
+ if (!isCurrent())
17820
+ return Promise.reject(new Error(`Renderer request manager is retired for ${hostId2}`));
17821
+ return options === void 0 ? rpc.sendRequest(method, params) : rpc.sendRequest(method, params, options);
17822
+ },
17823
+ // The main process broadcasts every app-server notification to its windows,
17824
+ // including codexhost methods Desktop's own notification table drops.
17825
+ addNotificationCallback(methods, listener) {
17826
+ const accepted = new Set(typeof methods === "string" ? [methods] : methods);
17827
+ const onMessage = (event) => {
17828
+ const { source, data } = event;
17829
+ if (source != null && source !== target) return;
17830
+ if (!isRecord3(data) || data.type !== "mcp-notification" || data.hostId !== hostId2 || typeof data.method !== "string" || !accepted.has(data.method) || !isCurrent())
17831
+ return;
17832
+ listener({ method: data.method, params: data.params });
17833
+ };
17834
+ target.addEventListener?.("message", onMessage);
17835
+ return () => target.removeEventListener?.("message", onMessage);
17836
+ }
17837
+ });
17838
+ const clearDrafts = () => {
17839
+ for (const [draftId, draft] of externalDrafts) {
17840
+ if (draft.owner === policy) externalDrafts.delete(draftId);
17841
+ }
17842
+ };
17843
+ const clear = () => isCurrent() ? Promise.resolve(rpc.clearPrewarmedThreads()).then(() => void 0) : Promise.reject(new Error("Renderer request manager is retired"));
17844
+ const policy = Object.freeze({
17845
+ state: "ready",
17846
+ hostId: hostId2,
17847
+ scopedCreation: true,
17848
+ requestTarget: () => {
17849
+ if (!isCurrent()) throw new Error("Renderer request manager is retired");
17850
+ return manager;
17851
+ },
17852
+ select(model2, draftId) {
17853
+ if (!isCurrent()) throw new Error("Renderer request manager is retired");
17854
+ if (model2 !== null && (typeof model2 !== "string" || !model2.startsWith("codexhost/"))) {
17855
+ throw new Error("Draft route Model must be a codexhost transport carrier");
17856
+ }
17857
+ if (draftId === void 0) {
17858
+ if (model2 === null) clearDrafts();
17859
+ } else if (model2 === null) {
17860
+ if (externalDrafts.get(draftId)?.owner === policy) externalDrafts.delete(draftId);
17861
+ } else {
17862
+ if (!draftId.startsWith("client-new-thread:"))
17863
+ throw new Error("External draft route is missing its client Thread identity");
17864
+ externalDrafts.set(draftId, { model: model2, owner: policy });
17865
+ }
17866
+ if ((selectedModels.get(hostId2) ?? null) === model2) return false;
17867
+ if (model2 === null) selectedModels.delete(hostId2);
17868
+ else selectedModels.set(hostId2, model2);
17869
+ void clear().catch(() => void 0);
17870
+ return true;
17871
+ },
17872
+ clear,
17873
+ dispose() {
17874
+ if (retired) return;
17875
+ retired = true;
17876
+ clearDrafts();
17877
+ selectedModels.delete(hostId2);
17878
+ }
17879
+ });
17880
+ return { hostId: hostId2, manager, policy };
17881
+ };
17882
+ const retire = (hostId2) => {
17883
+ const entry = routes.get(hostId2);
17884
+ routes.delete(hostId2);
17885
+ entry?.route.policy.dispose();
17886
+ };
17887
+ const routeFor = (hostId2) => {
17888
+ const current = read();
17889
+ const rpc = current ? dependencies.resolve(current, hostId2) : null;
17890
+ const previous = routes.get(hostId2);
17891
+ if (rpc && previous?.rpc === rpc) return previous.route;
17892
+ retire(hostId2);
17893
+ if (!rpc) return null;
17894
+ const route = createRoute(hostId2, rpc);
17895
+ routes.set(hostId2, { route, rpc });
17896
+ return route;
17897
+ };
17898
+ const publish = (route) => {
17899
+ const policy = route?.policy;
17900
+ if (target.__codexhostDraftPrewarmPolicyV1 === policy) return;
17901
+ Object.defineProperty(target, "__codexhostDraftPrewarmPolicyV1", {
17902
+ configurable: true,
17903
+ value: policy
17904
+ });
17905
+ if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
17906
+ target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
17907
+ }
17908
+ };
17909
+ const composerHostId = (composer) => {
17910
+ const hostIds = new Set(dependencies.composerHostIds(composer).hostIds);
17911
+ const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
17912
+ return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
17913
+ };
17914
+ const routing = {
17915
+ knownHostIds() {
17916
+ const current = read();
17917
+ return current ? dependencies.hostIds(current) : [];
17918
+ },
17919
+ forHost(hostId2) {
17920
+ return hostId2 && !disposed ? routeFor(hostId2) : null;
17921
+ },
17922
+ hostIdForComposer(composer) {
17923
+ if (disposed) return null;
17924
+ try {
17925
+ return composerHostId(composer);
17926
+ } catch {
17927
+ return null;
17928
+ }
17929
+ },
17930
+ forComposer(composer) {
17931
+ if (disposed) return null;
17932
+ let hostId2;
17933
+ try {
17934
+ hostId2 = composerHostId(composer);
17935
+ } catch {
17936
+ hostId2 = null;
17937
+ }
17938
+ const route = hostId2 ? routeFor(hostId2) : null;
17939
+ if (!composer) publish(route);
17940
+ return route;
17941
+ },
17942
+ dispose() {
17943
+ if (disposed) return;
17944
+ disposed = true;
17945
+ for (const hostId2 of [...routes.keys()]) retire(hostId2);
17946
+ discovery = null;
17947
+ externalDrafts.clear();
17948
+ selectedModels.clear();
17949
+ if (port.postMessage === postMessage) port.postMessage = originalPostMessage;
17950
+ if (target.__codexhostHostRoutingV1 === routing) {
17951
+ delete target.__codexhostHostRoutingV1;
17952
+ publish(null);
17953
+ }
17954
+ }
17955
+ };
17956
+ Object.defineProperty(target, "__codexhostHostRoutingV1", { configurable: true, value: routing });
17957
+ return routing;
17958
+ }
17959
+
17434
17960
  // packages/desktop-control/src/renderer-draft-prewarm-policy.ts
17435
17961
  var REQUEST_MANAGER_WAIT_TIMEOUT_MS = 6e4;
17436
17962
  var REQUEST_MANAGER_POLL_INTERVAL_MS = 25;
@@ -17442,14 +17968,41 @@ function directRendererInstaller() {
17442
17968
  const resolveRendererHostManager = ${resolveRendererHostManager.toString()};
17443
17969
  const retainRendererHostResponses = ${retainRendererHostResponses.toString()};
17444
17970
  const createDraftPrewarmPolicyBridge = ${createDraftPrewarmPolicyBridge.toString()};
17445
- const routing = (${installRendererHostRouting.toString()})(
17446
- document, window,
17447
- (root) => discoverRendererHosts(root, committedReactAncestors, requestManagerFromHookState),
17971
+ const isolateRendererPrewarmConsumption = ${isolateRendererPrewarmConsumption.toString()};
17972
+ const discover = (root) =>
17973
+ discoverRendererHosts(root, committedReactAncestors, requestManagerFromHookState);
17974
+ const installNative = () => (${installRendererHostRouting.toString()})(
17975
+ document, window, discover,
17448
17976
  (discovery, hostId) => resolveRendererHostManager(discovery, hostId, requestManagerFromHookState),
17449
17977
  (manager, bridge, hostId, target, prewarmed, isCurrent) => createDraftPrewarmPolicyBridge(
17450
17978
  manager, bridge, hostId, target, prewarmed, isCurrent, retainRendererHostResponses,
17979
+ isolateRendererPrewarmConsumption,
17451
17980
  ),
17452
17981
  );
17982
+ const installRpc = () => typeof MessagePort !== 'function' ? null : (${installRendererHostRpcRouting.toString()})(document, window, {
17983
+ findStore: ${findRendererAppScopeStore.toString()},
17984
+ findFamily: ${findRendererHostRpcFamily.toString()},
17985
+ resolve: ${resolveRendererHostRpc.toString()},
17986
+ hostIds: ${rendererHostRpcHostIds.toString()},
17987
+ composerHostIds: (composer) => {
17988
+ const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
17989
+ ? { querySelectorAll: () => [composer] }
17990
+ : (composer ?? document);
17991
+ return discover(source);
17992
+ },
17993
+ portPrototype: MessagePort.prototype,
17994
+ });
17995
+ // Desktop 26.1027 moved AppServerManagers to the main process. Older builds
17996
+ // expose native managers in Renderer hook state; the main-process mode only
17997
+ // applies when none is visible and its per-Host RPC store is identified.
17998
+ const routing = (() => {
17999
+ if (window.__codexhostHostRoutingV1) return window.__codexhostHostRoutingV1;
18000
+ const native = discover(document);
18001
+ if (native.managers.length || native.registries.length) return installNative();
18002
+ const rpc = installRpc();
18003
+ if (rpc) return rpc;
18004
+ throw new Error('Renderer Host request manager is unavailable');
18005
+ })();
17453
18006
  // Publish a default draft policy only when its Host is unambiguous. Host
17454
18007
  // connections can be ready even when multiple Composers coexist.
17455
18008
  const composerRoute = routing.forComposer();
@@ -17486,6 +18039,114 @@ function installRendererDraftPrewarmPolicyDirect(renderer) {
17486
18039
  );
17487
18040
  }
17488
18041
 
18042
+ // packages/desktop-control/src/renderer-loaded-modules.ts
18043
+ var record2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
18044
+ var MAX_MODULES = 4096;
18045
+ function nativeModuleCatalogExpression(urls, complete, owner) {
18046
+ return `Object.defineProperty(globalThis, '__codexhostLoadedModulesV1', {
18047
+ configurable: true,
18048
+ value: Object.freeze({ owner: ${JSON.stringify(owner)}, documentUrl: location.href, complete: ${complete}, urls: Object.freeze(${JSON.stringify(urls)}) })
18049
+ }); void 0`;
18050
+ }
18051
+ async function installRendererLoadedModules(renderer) {
18052
+ const owner = crypto.randomUUID();
18053
+ const contexts = /* @__PURE__ */ new Map();
18054
+ const contextIds = /* @__PURE__ */ new Map();
18055
+ const dirty = /* @__PURE__ */ new Set();
18056
+ let ready = false;
18057
+ let disposed = false;
18058
+ let timer;
18059
+ let publishing = Promise.resolve();
18060
+ const flush = () => {
18061
+ clearTimeout(timer);
18062
+ timer = void 0;
18063
+ const pending = [...dirty];
18064
+ dirty.clear();
18065
+ publishing = publishing.catch(() => void 0).then(async () => {
18066
+ for (const uniqueId of pending) {
18067
+ const context = contexts.get(uniqueId);
18068
+ if (!context || disposed) continue;
18069
+ const response = await renderer.command("Runtime.evaluate", {
18070
+ expression: nativeModuleCatalogExpression([...context.urls], context.complete, owner),
18071
+ uniqueContextId: uniqueId
18072
+ });
18073
+ if (record2(response) && record2(response.exceptionDetails))
18074
+ throw new Error("Loaded Renderer module catalog publication failed");
18075
+ }
18076
+ });
18077
+ return publishing;
18078
+ };
18079
+ const schedule = (uniqueId) => {
18080
+ dirty.add(uniqueId);
18081
+ if (ready && timer === void 0)
18082
+ timer = setTimeout(() => {
18083
+ void flush().catch((error51) => {
18084
+ console.error("Could not publish loaded Renderer modules", error51);
18085
+ });
18086
+ }, 10);
18087
+ };
18088
+ const remove = (id) => {
18089
+ const uniqueId = contextIds.get(id);
18090
+ contextIds.delete(id);
18091
+ if (uniqueId) {
18092
+ contexts.delete(uniqueId);
18093
+ dirty.delete(uniqueId);
18094
+ }
18095
+ };
18096
+ const listeners = [
18097
+ renderer.on("Runtime.executionContextCreated", (params) => {
18098
+ const context = record2(params) ? params.context : null;
18099
+ if (!record2(context) || typeof context.id !== "number" || typeof context.uniqueId !== "string" || !record2(context.auxData) || context.auxData.isDefault !== true)
18100
+ return;
18101
+ contextIds.set(context.id, context.uniqueId);
18102
+ contexts.set(context.uniqueId, { urls: /* @__PURE__ */ new Set(), complete: true });
18103
+ schedule(context.uniqueId);
18104
+ }),
18105
+ renderer.on("Runtime.executionContextDestroyed", (params) => {
18106
+ if (record2(params) && typeof params.executionContextId === "number")
18107
+ remove(params.executionContextId);
18108
+ }),
18109
+ renderer.on("Runtime.executionContextsCleared", () => {
18110
+ contextIds.clear();
18111
+ contexts.clear();
18112
+ dirty.clear();
18113
+ }),
18114
+ renderer.on("Debugger.scriptParsed", (params) => {
18115
+ if (!record2(params) || params.isModule !== true || params.hasSourceURL === true || typeof params.url !== "string" || typeof params.executionContextId !== "number")
18116
+ return;
18117
+ const uniqueId = contextIds.get(params.executionContextId);
18118
+ const context = uniqueId ? contexts.get(uniqueId) : null;
18119
+ if (!context || !uniqueId || context.urls.has(params.url)) return;
18120
+ if (context.urls.size >= MAX_MODULES) context.complete = false;
18121
+ else context.urls.add(params.url);
18122
+ schedule(uniqueId);
18123
+ })
18124
+ ];
18125
+ const dispose = () => {
18126
+ disposed = true;
18127
+ clearTimeout(timer);
18128
+ for (const unsubscribe of listeners) unsubscribe();
18129
+ for (const uniqueId of contexts.keys())
18130
+ void renderer.command("Runtime.evaluate", {
18131
+ expression: `if (globalThis.__codexhostLoadedModulesV1 === undefined || globalThis.__codexhostLoadedModulesV1?.owner === ${JSON.stringify(owner)}) { ${nativeModuleCatalogExpression([], false, owner)} }`,
18132
+ uniqueContextId: uniqueId
18133
+ }).catch(() => void 0);
18134
+ contexts.clear();
18135
+ contextIds.clear();
18136
+ dirty.clear();
18137
+ };
18138
+ try {
18139
+ await renderer.command("Runtime.enable");
18140
+ await renderer.command("Debugger.enable");
18141
+ ready = true;
18142
+ await flush();
18143
+ return dispose;
18144
+ } catch (error51) {
18145
+ dispose();
18146
+ throw error51;
18147
+ }
18148
+ }
18149
+
17489
18150
  // packages/desktop-control/src/renderer-cdp-control-session.ts
17490
18151
  function isRecord2(value) {
17491
18152
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -17630,21 +18291,23 @@ async function waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs
17630
18291
  }
17631
18292
  async function installTarget(target, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations) {
17632
18293
  const renderer = await operations.connect(target.webSocketDebuggerUrl);
18294
+ let disposeModules;
17633
18295
  try {
17634
- await renderer.command("Runtime.enable");
18296
+ disposeModules = await installRendererLoadedModules(renderer);
17635
18297
  await renderer.command("Page.enable");
17636
18298
  await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource });
17637
18299
  await evaluateSource(renderer, rendererSource);
17638
18300
  const draftPrewarmPolicy = await operations.installDraftPrewarmPolicy(renderer);
17639
18301
  const binding = await waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs);
17640
- return { renderer, snapshot: { target, draftPrewarmPolicy, binding } };
18302
+ return { renderer, snapshot: { target, draftPrewarmPolicy, binding }, disposeModules };
17641
18303
  } catch (error51) {
18304
+ disposeModules?.();
17642
18305
  renderer.close();
17643
18306
  throw error51;
17644
18307
  }
17645
18308
  }
17646
18309
  var InstalledRendererCdpControlSession = class {
17647
- constructor(renderer, rendererCdpEndpoint2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot) {
18310
+ constructor(renderer, rendererCdpEndpoint2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
17648
18311
  this.renderer = renderer;
17649
18312
  this.rendererCdpEndpoint = rendererCdpEndpoint2;
17650
18313
  this.rendererSource = rendererSource;
@@ -17653,6 +18316,7 @@ var InstalledRendererCdpControlSession = class {
17653
18316
  this.pollIntervalMs = pollIntervalMs;
17654
18317
  this.operations = operations;
17655
18318
  this.currentSnapshot = currentSnapshot;
18319
+ this.disposeModules = disposeModules;
17656
18320
  }
17657
18321
  renderer;
17658
18322
  rendererCdpEndpoint;
@@ -17662,6 +18326,7 @@ var InstalledRendererCdpControlSession = class {
17662
18326
  pollIntervalMs;
17663
18327
  operations;
17664
18328
  currentSnapshot;
18329
+ disposeModules;
17665
18330
  #closed = false;
17666
18331
  get snapshot() {
17667
18332
  return this.currentSnapshot;
@@ -17684,8 +18349,10 @@ var InstalledRendererCdpControlSession = class {
17684
18349
  this.pollIntervalMs,
17685
18350
  this.operations
17686
18351
  );
18352
+ this.disposeModules();
17687
18353
  this.renderer.close();
17688
18354
  this.renderer = replacement.renderer;
18355
+ this.disposeModules = replacement.disposeModules;
17689
18356
  this.currentSnapshot = replacement.snapshot;
17690
18357
  return this.currentSnapshot;
17691
18358
  }
@@ -17710,8 +18377,10 @@ var InstalledRendererCdpControlSession = class {
17710
18377
  this.pollIntervalMs,
17711
18378
  this.operations
17712
18379
  );
18380
+ this.disposeModules();
17713
18381
  this.renderer.close();
17714
18382
  this.renderer = replacement.renderer;
18383
+ this.disposeModules = replacement.disposeModules;
17715
18384
  this.currentSnapshot = replacement.snapshot;
17716
18385
  return this.currentSnapshot;
17717
18386
  }
@@ -17728,6 +18397,7 @@ var InstalledRendererCdpControlSession = class {
17728
18397
  close() {
17729
18398
  if (this.#closed) return;
17730
18399
  this.#closed = true;
18400
+ this.disposeModules();
17731
18401
  this.renderer.close();
17732
18402
  }
17733
18403
  };
@@ -17765,7 +18435,8 @@ async function createRendererCdpControlSession(options) {
17765
18435
  timeoutMs,
17766
18436
  pollIntervalMs,
17767
18437
  operations,
17768
- installed.snapshot
18438
+ installed.snapshot,
18439
+ installed.disposeModules
17769
18440
  );
17770
18441
  }
17771
18442
  function installRendererCdpControlSession(options) {