@karlorz/codexhost-cli-win32-x64 0.17.1-0 → 0.17.3-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- npm install -g @karlorz/codexhost-cli@0.17.1-0
10
+ npm install -g @karlorz/codexhost-cli@0.17.3-0
11
11
  ```
12
12
 
13
13
  Do not install this package directly. npm selects it through the optional dependencies of `@karlorz/codexhost-cli`.
@@ -1 +1 @@
1
- {"schemaVersion":1,"version":"0.17.1-0","distribution":"npm","target":"windows-x64"}
1
+ {"schemaVersion":1,"version":"0.17.3-0","distribution":"npm","target":"windows-x64"}
@@ -16455,6 +16455,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
16455
16455
  /** The text about to be steered; a Harness command always stops and restarts. */
16456
16456
  text: external_exports.string().optional()
16457
16457
  }).strict();
16458
+ var threadSteeringContextSchema = external_exports.object({
16459
+ kind: external_exports.literal("application"),
16460
+ value: external_exports.string().transform((text, context) => {
16461
+ try {
16462
+ return JSON.parse(text);
16463
+ } catch {
16464
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
16465
+ return external_exports.NEVER;
16466
+ }
16467
+ }).pipe(external_exports.object({
16468
+ expectedTurnId: hostTurnIdSchema,
16469
+ clientUserMessageId: external_exports.string().min(1),
16470
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
16471
+ }).strict())
16472
+ }).strict().transform((context) => context.value);
16458
16473
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
16459
16474
  var threadSteeringInspectResultSchema = external_exports.object({
16460
16475
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15675,6 +15675,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15675
15675
  /** The text about to be steered; a Harness command always stops and restarts. */
15676
15676
  text: external_exports.string().optional()
15677
15677
  }).strict();
15678
+ var threadSteeringContextSchema = external_exports.object({
15679
+ kind: external_exports.literal("application"),
15680
+ value: external_exports.string().transform((text, context) => {
15681
+ try {
15682
+ return JSON.parse(text);
15683
+ } catch {
15684
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15685
+ return external_exports.NEVER;
15686
+ }
15687
+ }).pipe(external_exports.object({
15688
+ expectedTurnId: hostTurnIdSchema,
15689
+ clientUserMessageId: external_exports.string().min(1),
15690
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15691
+ }).strict())
15692
+ }).strict().transform((context) => context.value);
15678
15693
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15679
15694
  var threadSteeringInspectResultSchema = external_exports.object({
15680
15695
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15581,6 +15581,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15581
15581
  text: external_exports.string().optional()
15582
15582
  }).strict();
15583
15583
  var THREAD_STEER_DELIVERY_PARAM = "codexhostSteerDelivery";
15584
+ var threadSteeringContextSchema = external_exports.object({
15585
+ kind: external_exports.literal("application"),
15586
+ value: external_exports.string().transform((text, context) => {
15587
+ try {
15588
+ return JSON.parse(text);
15589
+ } catch {
15590
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15591
+ return external_exports.NEVER;
15592
+ }
15593
+ }).pipe(external_exports.object({
15594
+ expectedTurnId: hostTurnIdSchema,
15595
+ clientUserMessageId: external_exports.string().min(1),
15596
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15597
+ }).strict())
15598
+ }).strict().transform((context) => context.value);
15584
15599
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15585
15600
  var threadSteeringInspectResultSchema = external_exports.object({
15586
15601
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -17079,9 +17094,31 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17079
17094
  return code === -32601 || code === -32600 && typeof message === "string" && message.startsWith(`Invalid request: unknown variant \`${method}\``);
17080
17095
  }
17081
17096
 
17097
+ // src/renderer-steering-delivery.ts
17098
+ async function inspectRendererSteeringDelivery(send, threadId, text) {
17099
+ const inspect = "codexhost/thread/steering/inspect";
17100
+ try {
17101
+ const response2 = await send(inspect, { threadId, ...text !== void 0 ? { text } : {} });
17102
+ return threadSteeringInspectResultSchema.parse(response2).delivery;
17103
+ } catch (error51) {
17104
+ if (!isUnsupportedMethod(error51, inspect)) throw error51;
17105
+ }
17106
+ const ownership = "codexhost/thread/ownership/list";
17107
+ let response;
17108
+ try {
17109
+ response = await send(ownership, { threadIds: [threadId] });
17110
+ } catch (error51) {
17111
+ if (!isUnsupportedMethod(error51, ownership)) throw error51;
17112
+ await verifyNativeCodexThread(send, threadId);
17113
+ return "official";
17114
+ }
17115
+ const result = threadOwnershipListResultSchema.parse(response);
17116
+ const owner = result.threads.find((thread) => thread.threadId === threadId)?.owner;
17117
+ if (!owner) throw new Error("Thread ownership could not be resolved for steering");
17118
+ return owner === "codex" ? "official" : "newTurn";
17119
+ }
17120
+
17082
17121
  // src/renderer-external-steering.ts
17083
- var THREAD_STEERING_INSPECT_METHOD = "codexhost/thread/steering/inspect";
17084
- var THREAD_OWNERSHIP_LIST_METHOD = "codexhost/thread/ownership/list";
17085
17122
  function isRecord4(value) {
17086
17123
  return value !== null && typeof value === "object" && !Array.isArray(value);
17087
17124
  }
@@ -17288,34 +17325,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17288
17325
  };
17289
17326
  });
17290
17327
  };
17291
- const inspectDelivery = async (threadId, text) => {
17292
- try {
17293
- const response = await originalSend.call(manager, THREAD_STEERING_INSPECT_METHOD, {
17294
- threadId,
17295
- ...text !== void 0 ? { text } : {}
17296
- });
17297
- return threadSteeringInspectResultSchema.parse(response).delivery;
17298
- } catch (error51) {
17299
- if (!isUnsupportedMethod(error51, THREAD_STEERING_INSPECT_METHOD)) throw error51;
17300
- }
17301
- let ownershipResponse;
17302
- try {
17303
- ownershipResponse = await originalSend.call(manager, THREAD_OWNERSHIP_LIST_METHOD, {
17304
- threadIds: [threadId]
17305
- });
17306
- } catch (error51) {
17307
- if (!isUnsupportedMethod(error51, THREAD_OWNERSHIP_LIST_METHOD)) throw error51;
17308
- await verifyNativeCodexThread(
17309
- (method, params) => originalSend.call(manager, method, params),
17310
- threadId
17311
- );
17312
- return "official";
17313
- }
17314
- const ownership = threadOwnershipListResultSchema.parse(ownershipResponse);
17315
- const owner = ownership.threads.find((thread) => thread.threadId === threadId)?.owner;
17316
- if (!owner) throw new Error("Thread ownership could not be resolved for steering");
17317
- return owner === "codex" ? "official" : "newTurn";
17318
- };
17328
+ const inspectDelivery = (threadId, text) => inspectRendererSteeringDelivery(
17329
+ (method, params) => originalSend.call(manager, method, params),
17330
+ threadId,
17331
+ text
17332
+ );
17319
17333
  const steer = async function(...args) {
17320
17334
  const [
17321
17335
  threadId,
@@ -17326,7 +17340,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17326
17340
  clientUserMessageId,
17327
17341
  additionalContext,
17328
17342
  toolOutput,
17329
- onMessageAdded
17343
+ onMessageAdded,
17344
+ beforeSendRequest,
17345
+ assertRequestCurrent
17330
17346
  ] = args;
17331
17347
  if (typeof threadId !== "string") return originalSteer.apply(manager, args);
17332
17348
  const role = manager.getStreamRole?.(threadId);
@@ -17411,7 +17427,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17411
17427
  attachments: attachments ?? [],
17412
17428
  commentAttachments: context.commentAttachments ?? [],
17413
17429
  mcpAppModelContextAttachments: context.mcpAppModelContextAttachments,
17414
- useAppServerPermissionDefault: true
17430
+ useAppServerPermissionDefault: true,
17431
+ beforeSendRequest,
17432
+ assertRequestCurrent
17415
17433
  }
17416
17434
  },
17417
17435
  onMessageAdded
@@ -15853,6 +15853,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15853
15853
  /** The text about to be steered; a Harness command always stops and restarts. */
15854
15854
  text: external_exports.string().optional()
15855
15855
  }).strict();
15856
+ var threadSteeringContextSchema = external_exports.object({
15857
+ kind: external_exports.literal("application"),
15858
+ value: external_exports.string().transform((text, context) => {
15859
+ try {
15860
+ return JSON.parse(text);
15861
+ } catch {
15862
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15863
+ return external_exports.NEVER;
15864
+ }
15865
+ }).pipe(external_exports.object({
15866
+ expectedTurnId: hostTurnIdSchema,
15867
+ clientUserMessageId: external_exports.string().min(1),
15868
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15869
+ }).strict())
15870
+ }).strict().transform((context) => context.value);
15856
15871
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15857
15872
  var threadSteeringInspectResultSchema = external_exports.object({
15858
15873
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -16856,6 +16871,79 @@ function cpaLiveVoiceHookBootstrap(environment = process.env, desktopVersion) {
16856
16871
  `;
16857
16872
  }
16858
16873
 
16874
+ // packages/desktop-control/src/browser-annotation-style-compat.ts
16875
+ var BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE = String.raw`(() => {
16876
+ const key = '__codexhostBrowserAnnotationStylesV1';
16877
+ if (globalThis[key]?.refresh() === true) return;
16878
+ if (typeof CSSStyleSheet !== 'function' ||
16879
+ typeof CSSStyleSheet.prototype.replaceSync !== 'function') return;
16880
+ let root = null;
16881
+ let shadow = null;
16882
+ let stylesObserver = null;
16883
+ const copies = new Map();
16884
+ function removeCopies() {
16885
+ if (shadow) {
16886
+ const owned = new Set(Array.from(copies.values(), copy => copy.sheet));
16887
+ shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.filter(sheet => !owned.has(sheet));
16888
+ }
16889
+ copies.clear();
16890
+ }
16891
+ function syncStyles() {
16892
+ if (!shadow) return;
16893
+ const present = new Set();
16894
+ for (const style of shadow.querySelectorAll('style')) {
16895
+ const text = style.textContent || '';
16896
+ // Only repair Codex's cursor stylesheet when CSP rejected its style element.
16897
+ if (style.sheet || !text.includes('.annotation-selection-cursor')) continue;
16898
+ present.add(style);
16899
+ const previous = copies.get(style);
16900
+ if (previous?.text === text && shadow.adoptedStyleSheets.includes(previous.sheet)) continue;
16901
+ try {
16902
+ const sheet = previous?.sheet ?? new CSSStyleSheet();
16903
+ sheet.replaceSync(text);
16904
+ if (!shadow.adoptedStyleSheets.includes(sheet)) {
16905
+ shadow.adoptedStyleSheets = [...shadow.adoptedStyleSheets, sheet];
16906
+ }
16907
+ copies.set(style, { sheet, text });
16908
+ } catch { /* Unsupported annotation styles leave native behavior intact. */ }
16909
+ }
16910
+ for (const [style, copy] of copies) {
16911
+ if (present.has(style)) continue;
16912
+ shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.filter(sheet => sheet !== copy.sheet);
16913
+ copies.delete(style);
16914
+ }
16915
+ }
16916
+ function refresh() {
16917
+ const nextRoot = document.documentElement;
16918
+ if (root !== nextRoot) {
16919
+ rootObserver.disconnect();
16920
+ rootObserver.observe(document, { childList: true });
16921
+ root = nextRoot;
16922
+ if (root) rootObserver.observe(root, { childList: true });
16923
+ }
16924
+ const host = document.getElementById('codex-browser-sidebar-comments-root');
16925
+ const nextShadow = host?.parentElement === root ? host?.shadowRoot ?? null : null;
16926
+ if (nextShadow !== shadow) {
16927
+ stylesObserver?.disconnect();
16928
+ removeCopies();
16929
+ shadow = nextShadow;
16930
+ stylesObserver = null;
16931
+ if (shadow && 'adoptedStyleSheets' in shadow) {
16932
+ stylesObserver = new MutationObserver(syncStyles);
16933
+ stylesObserver.observe(shadow, { childList: true, subtree: true, characterData: true });
16934
+ } else {
16935
+ shadow = null;
16936
+ }
16937
+ }
16938
+ syncStyles();
16939
+ return true;
16940
+ }
16941
+ const rootObserver = new MutationObserver(refresh);
16942
+ rootObserver.observe(document, { childList: true });
16943
+ globalThis[key] = { refresh };
16944
+ refresh();
16945
+ })();`;
16946
+
16859
16947
  // packages/desktop-control/src/renderer-react-ownership.ts
16860
16948
  function committedReactAncestors(value) {
16861
16949
  const MAX_VISITED_FIBERS = 2e5;
@@ -17920,7 +18008,9 @@ function findRendererHostRpcFamily(store) {
17920
18008
  if (!record3(definition) || definition.kind !== "signal-family") continue;
17921
18009
  if (!record3(members) || typeof members.get !== "function") continue;
17922
18010
  for (const [hostId2, member] of members) {
17923
- if (typeof hostId2 !== "string" || !record3(member)) continue;
18011
+ if (typeof hostId2 !== "string" || !/^(?:local$|durable$|remote[-:]|ssh:)/u.test(hostId2))
18012
+ continue;
18013
+ if (!record3(member)) continue;
17924
18014
  const signal = member.value;
17925
18015
  if (!record3(signal) || typeof signal.get !== "function") continue;
17926
18016
  let value;
@@ -18042,7 +18132,8 @@ function installRendererHostRpcRouting(root, target, dependencies) {
18042
18132
  if (disposed) return null;
18043
18133
  try {
18044
18134
  const store = dependencies.findStore(root);
18045
- discovery = store ? dependencies.findFamily(store) : null;
18135
+ const bound = store && discovery?.store === store ? [...store.familyBindings.values()].includes(discovery.family) : false;
18136
+ if (!bound) discovery = store ? dependencies.findFamily(store) : null;
18046
18137
  } catch {
18047
18138
  discovery = null;
18048
18139
  }
@@ -18050,13 +18141,15 @@ function installRendererHostRpcRouting(root, target, dependencies) {
18050
18141
  };
18051
18142
  if (!read()) return null;
18052
18143
  const queuePolicy = dependencies.installQueuePolicy(root, target);
18053
- const native = () => {
18054
- if (disposed) return null;
18055
- try {
18056
- nativeRouting ??= dependencies.nativeRouting?.() ?? null;
18057
- } catch {
18144
+ const discoverComposer = (composer) => {
18145
+ const owners = dependencies.discoverComposer(composer);
18146
+ if (!nativeRouting && (owners.managers.length || owners.registries.length)) {
18147
+ try {
18148
+ nativeRouting = dependencies.installNativeRouting();
18149
+ } catch {
18150
+ }
18058
18151
  }
18059
- return nativeRouting;
18152
+ return owners;
18060
18153
  };
18061
18154
  const connectionFor = (hostId2) => {
18062
18155
  if (!hostId2.startsWith("remote-control:")) return void 0;
@@ -18242,7 +18335,7 @@ function installRendererHostRpcRouting(root, target, dependencies) {
18242
18335
  const routeFor = (hostId2, nativeRoute) => {
18243
18336
  if (disposed) return null;
18244
18337
  const connection = connectionFor(hostId2);
18245
- const preferred = nativeRoute === void 0 ? native()?.forHost(hostId2) : nativeRoute;
18338
+ const preferred = nativeRoute === void 0 ? nativeRouting?.forHost(hostId2) : nativeRoute;
18246
18339
  if (connection === null || preferred) {
18247
18340
  retire(hostId2);
18248
18341
  return connection === null ? null : preferred ?? null;
@@ -18269,21 +18362,25 @@ function installRendererHostRpcRouting(root, target, dependencies) {
18269
18362
  target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
18270
18363
  }
18271
18364
  };
18272
- const composerHostId = (composer) => {
18273
- const nativeHostId = native()?.hostIdForComposer(composer);
18365
+ const composerHostId = (owners, composer) => {
18366
+ const nativeHostId = nativeRouting?.hostIdForComposer(composer);
18274
18367
  if (nativeHostId) return nativeHostId;
18275
- const hostIds = new Set(dependencies.composerHostIds(composer).hostIds);
18368
+ const hostIds = new Set((owners ?? discoverComposer(composer)).hostIds);
18276
18369
  const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
18277
18370
  return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
18278
18371
  };
18279
18372
  const routing = {
18280
18373
  knownHostIds() {
18281
18374
  if (disposed) return [];
18375
+ try {
18376
+ if (!nativeRouting) discoverComposer();
18377
+ } catch {
18378
+ }
18282
18379
  const current = read();
18283
18380
  return [
18284
18381
  .../* @__PURE__ */ new Set([
18285
18382
  ...current ? dependencies.hostIds(current) : [],
18286
- ...native()?.knownHostIds?.() ?? []
18383
+ ...nativeRouting?.knownHostIds?.() ?? []
18287
18384
  ])
18288
18385
  ];
18289
18386
  },
@@ -18293,7 +18390,7 @@ function installRendererHostRpcRouting(root, target, dependencies) {
18293
18390
  hostIdForComposer(composer) {
18294
18391
  if (disposed) return null;
18295
18392
  try {
18296
- return composerHostId(composer);
18393
+ return composerHostId(nativeRouting ? null : discoverComposer(composer), composer);
18297
18394
  } catch {
18298
18395
  return null;
18299
18396
  }
@@ -18303,8 +18400,9 @@ function installRendererHostRpcRouting(root, target, dependencies) {
18303
18400
  let hostId2;
18304
18401
  let preferred = null;
18305
18402
  try {
18306
- preferred = native()?.forComposer(composer) ?? null;
18307
- hostId2 = preferred?.hostId ?? composerHostId(composer);
18403
+ const owners = nativeRouting ? null : discoverComposer(composer);
18404
+ preferred = nativeRouting?.forComposer(composer) ?? null;
18405
+ hostId2 = preferred?.hostId ?? composerHostId(owners, composer);
18308
18406
  } catch {
18309
18407
  hostId2 = null;
18310
18408
  }
@@ -18388,7 +18486,7 @@ function directRendererInstaller() {
18388
18486
  findFamily: ${findRendererHostRpcFamily.toString()},
18389
18487
  resolve: ${resolveRendererHostRpc.toString()},
18390
18488
  hostIds: ${rendererHostRpcHostIds.toString()},
18391
- composerHostIds: (composer) => {
18489
+ discoverComposer: (composer) => {
18392
18490
  const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
18393
18491
  ? { querySelectorAll: () => [composer] }
18394
18492
  : (composer ?? document);
@@ -18400,10 +18498,7 @@ function directRendererInstaller() {
18400
18498
  portPrototype: MessagePort.prototype,
18401
18499
  }),
18402
18500
  portPrototype: MessagePort.prototype,
18403
- nativeRouting: () => {
18404
- const native = discover(document);
18405
- return native.managers.length || native.registries.length ? installNative(false) : null;
18406
- },
18501
+ installNativeRouting: () => installNative(false),
18407
18502
  readConnection: (hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
18408
18503
  });
18409
18504
  const connected = (routing) => routing.forComposer() !== null ||
@@ -19358,6 +19453,117 @@ async function installNativeRpcRemoteControlDirect(renderer) {
19358
19453
  }
19359
19454
  }
19360
19455
 
19456
+ // packages/desktop-control/src/renderer-rpc-steering.ts
19457
+ var RETRY_BASE_MS = 5e3;
19458
+ var RETRY_MAX_MS = 3e5;
19459
+ var retries = /* @__PURE__ */ new WeakMap();
19460
+ async function installRendererRpcSteeringDirect(client, now = Date.now) {
19461
+ try {
19462
+ const needed = await client.evaluate(`(() => {
19463
+ const steering = window.__codexhostRpcSteeringV1;
19464
+ if (steering && steering.controller.forHost === steering.forHost) return false;
19465
+ steering?.release();
19466
+ const routing=window.__codexhostHostRoutingV1;
19467
+ return ['local', ...(routing?.knownHostIds?.() ?? [])].some(id => routing?.forHost(id)?.manager.kind === 'main-process-rpc');
19468
+ })()`);
19469
+ if (!needed) return false;
19470
+ const retry = retries.get(client);
19471
+ if (retry && now() < retry.nextAt) return false;
19472
+ try {
19473
+ await discoverAndInstall(client);
19474
+ retries.delete(client);
19475
+ return true;
19476
+ } catch (error51) {
19477
+ const attempts = (retry?.attempts ?? 0) + 1;
19478
+ const delay = Math.min(RETRY_BASE_MS * 2 ** (attempts - 1), RETRY_MAX_MS);
19479
+ retries.set(client, { attempts, nextAt: now() + delay });
19480
+ console.error(
19481
+ `codexhost native steering discovery failed (attempt ${attempts}):`,
19482
+ error51 instanceof Error ? error51.message : String(error51)
19483
+ );
19484
+ return false;
19485
+ }
19486
+ } catch {
19487
+ return false;
19488
+ }
19489
+ }
19490
+ async function discoverAndInstall(client) {
19491
+ const group = `codexhost-rpc-steering-${crypto.randomUUID()}`;
19492
+ const command = (method, params) => client.command(method, params);
19493
+ const properties = (objectId) => command("Runtime.getProperties", { objectId, ownProperties: true });
19494
+ const call = (objectId, functionDeclaration, args = []) => command("Runtime.callFunctionOn", {
19495
+ objectId,
19496
+ functionDeclaration,
19497
+ arguments: args,
19498
+ objectGroup: group,
19499
+ returnByValue: true
19500
+ });
19501
+ try {
19502
+ const proto = await command("Runtime.evaluate", {
19503
+ expression: "Object.getPrototypeOf(async function(){})",
19504
+ objectGroup: group
19505
+ });
19506
+ if (!proto.result.objectId) throw new Error("Native RPC steering discovery is unavailable");
19507
+ const objects = await command("Runtime.queryObjects", {
19508
+ prototypeObjectId: proto.result.objectId,
19509
+ objectGroup: group
19510
+ });
19511
+ if (!objects.objects.objectId) throw new Error("Native RPC steering discovery is unavailable");
19512
+ const filtered = await command("Runtime.callFunctionOn", {
19513
+ objectId: objects.objects.objectId,
19514
+ functionDeclaration: 'function(){return this.filter(fn=>fn.name==="collectAppStateSnapshot"&&String(fn).includes("collectSnapshot")).slice(0,9)}',
19515
+ objectGroup: group
19516
+ });
19517
+ if (!filtered.result.objectId) throw new Error("Native RPC Controller is unavailable");
19518
+ const snapshots = (await properties(filtered.result.objectId)).result.flatMap(
19519
+ (entry) => entry.value?.type === "function" && entry.value.objectId ? [entry.value.objectId] : []
19520
+ );
19521
+ if (snapshots.length > 8) throw new Error("Native RPC Controller is ambiguous");
19522
+ const controllers = [];
19523
+ for (const snapshot of snapshots) {
19524
+ const scopes = (await properties(snapshot)).internalProperties?.find(
19525
+ (entry) => entry.name === "[[Scopes]]"
19526
+ )?.value?.objectId;
19527
+ if (!scopes) continue;
19528
+ for (const scope of (await properties(scopes)).result) {
19529
+ if (!scope.value?.objectId || !scope.value.description?.startsWith("Closure")) continue;
19530
+ const bindings = (await properties(scope.value.objectId)).result;
19531
+ const owners = [];
19532
+ let rootScope;
19533
+ for (const binding of bindings) {
19534
+ if (binding.value?.type !== "object" || !binding.value.objectId) continue;
19535
+ const id = binding.value.objectId;
19536
+ const result2 = await call(
19537
+ id,
19538
+ `function(){return (${nativeRpcObjectShape.toString()})(this)}`
19539
+ );
19540
+ const shape = result2.result.value;
19541
+ if (shape?.scope) rootScope = id;
19542
+ if (shape?.controller && (await call(id, "function(fn){return this.collectAppStateSnapshot===fn}", [
19543
+ { objectId: snapshot }
19544
+ ])).result.value === true)
19545
+ owners.push(id);
19546
+ }
19547
+ if (owners.length !== 1 || !rootScope) continue;
19548
+ const root = await call(
19549
+ rootScope,
19550
+ `function(){let node=this.node;const seen=new Set();while(node?.parent&&!seen.has(node.parent)&&seen.size<100){seen.add(node);node=node.parent}return (${findRendererAppScopeStore.toString()})(document)===node}`
19551
+ );
19552
+ if (root.result.value === true) controllers.push(owners[0]);
19553
+ }
19554
+ }
19555
+ if (controllers.length !== 1) throw new Error("Native RPC Controller is missing or ambiguous");
19556
+ const result = await call(
19557
+ controllers[0],
19558
+ "function(){return window.__codexhostInstallRpcSteeringV1?.(this) === true}"
19559
+ );
19560
+ if (result.exceptionDetails || result.result.value !== true)
19561
+ throw new Error("Native RPC steering installation failed");
19562
+ } finally {
19563
+ await client.command("Runtime.releaseObjectGroup", { objectGroup: group }).catch(() => void 0);
19564
+ }
19565
+ }
19566
+
19361
19567
  // packages/desktop-control/src/renderer-cdp-control-session.ts
19362
19568
  function isRecord2(value) {
19363
19569
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -19565,6 +19771,45 @@ function isLocalThreadRenderer(target) {
19565
19771
  const route = url2.searchParams.get("initialRoute");
19566
19772
  return [...url2.searchParams.keys()].length === 1 && (route === "/local" || route?.startsWith("/local/") === true);
19567
19773
  }
19774
+ function isBrowserPage(target) {
19775
+ if (target.type !== "page") return false;
19776
+ try {
19777
+ return ["http:", "https:"].includes(new URL(target.url).protocol);
19778
+ } catch {
19779
+ return false;
19780
+ }
19781
+ }
19782
+ async function installBrowserAnnotationStyles(target, browserClients, operations, signal) {
19783
+ const timeoutMessage = "Browser annotation style compatibility installation timed out";
19784
+ const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
19785
+ let renderer = browserClients.get(target.id);
19786
+ const registered = renderer !== void 0;
19787
+ renderer ??= await connectRendererTarget(target, operations, signal, timeoutMessage);
19788
+ const connected = renderer;
19789
+ try {
19790
+ if (!registered) {
19791
+ await run(() => connected.command("Page.enable"));
19792
+ await run(
19793
+ () => connected.command("Page.addScriptToEvaluateOnNewDocument", {
19794
+ source: BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE
19795
+ })
19796
+ );
19797
+ browserClients.set(target.id, connected);
19798
+ }
19799
+ const installed = await run(
19800
+ () => connected.evaluate(
19801
+ "globalThis.__codexhostBrowserAnnotationStylesV1?.refresh() === true"
19802
+ )
19803
+ );
19804
+ if (installed !== true) {
19805
+ await run(() => evaluateSource(connected, BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE));
19806
+ }
19807
+ } catch (error51) {
19808
+ browserClients.delete(target.id);
19809
+ connected.close();
19810
+ throw error51;
19811
+ }
19812
+ }
19568
19813
  async function installLocalThreadRenderer(target, source, enabledAgents, operations, signal) {
19569
19814
  const timeoutMessage = "Local chat Renderer installation timed out";
19570
19815
  const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
@@ -19582,14 +19827,24 @@ async function installLocalThreadRenderer(target, source, enabledAgents, operati
19582
19827
  renderer.close();
19583
19828
  }
19584
19829
  }
19585
- async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, operations, signal) {
19830
+ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, browserStyleClients, operations, signal) {
19586
19831
  try {
19587
19832
  const targets = await awaitWithSignal(
19588
19833
  operations.listTargets(endpoint, signal),
19589
19834
  signal,
19590
19835
  "Auxiliary Renderer CDP target discovery timed out"
19591
19836
  );
19837
+ const liveTargets = new Set(targets.map((target) => target.id));
19838
+ for (const [id, client] of browserStyleClients) {
19839
+ if (!liveTargets.has(id)) {
19840
+ client.close();
19841
+ browserStyleClients.delete(id);
19842
+ }
19843
+ }
19592
19844
  await Promise.allSettled([
19845
+ ...targets.filter(isBrowserPage).map(
19846
+ (target) => installBrowserAnnotationStyles(target, browserStyleClients, operations, signal)
19847
+ ),
19593
19848
  ...overlayHookSource ? selectAvatarOverlayRendererTargets(targets).map(
19594
19849
  (overlay) => installOverlayHook(overlay, overlayHookSource, operations, signal)
19595
19850
  ) : [],
@@ -19618,11 +19873,12 @@ async function installTarget(target, rendererSource, enabledAgents, timeoutMs, p
19618
19873
  }
19619
19874
  }
19620
19875
  var InstalledRendererCdpControlSession = class {
19621
- constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
19876
+ constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, browserStyleClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
19622
19877
  this.renderer = renderer;
19623
19878
  this.rendererCdpEndpoint = rendererCdpEndpoint2;
19624
19879
  this.rendererSource = rendererSource;
19625
19880
  this.overlayHookSource = overlayHookSource;
19881
+ this.browserStyleClients = browserStyleClients;
19626
19882
  this.enabledAgents = enabledAgents;
19627
19883
  this.timeoutMs = timeoutMs;
19628
19884
  this.pollIntervalMs = pollIntervalMs;
@@ -19634,6 +19890,7 @@ var InstalledRendererCdpControlSession = class {
19634
19890
  rendererCdpEndpoint;
19635
19891
  rendererSource;
19636
19892
  overlayHookSource;
19893
+ browserStyleClients;
19637
19894
  enabledAgents;
19638
19895
  timeoutMs;
19639
19896
  pollIntervalMs;
@@ -19700,6 +19957,7 @@ var InstalledRendererCdpControlSession = class {
19700
19957
  this.rendererSource,
19701
19958
  this.enabledAgents,
19702
19959
  this.overlayHookSource,
19960
+ this.browserStyleClients,
19703
19961
  this.operations,
19704
19962
  discoveryTimeoutSignal(this.timeoutMs)
19705
19963
  );
@@ -19719,6 +19977,8 @@ var InstalledRendererCdpControlSession = class {
19719
19977
  this.#closed = true;
19720
19978
  this.disposeModules();
19721
19979
  this.renderer.close();
19980
+ for (const client of this.browserStyleClients.values()) client.close();
19981
+ this.browserStyleClients.clear();
19722
19982
  }
19723
19983
  };
19724
19984
  var defaultOperations = {
@@ -19727,6 +19987,7 @@ var defaultOperations = {
19727
19987
  async installDraftPrewarmPolicy(renderer) {
19728
19988
  const status = await installRendererDraftPrewarmPolicyDirect(renderer);
19729
19989
  await installNativeRpcRemoteControlDirect(renderer);
19990
+ await installRendererRpcSteeringDirect(renderer);
19730
19991
  return status;
19731
19992
  }
19732
19993
  };
@@ -19751,11 +20012,13 @@ async function createRendererCdpControlSession(options) {
19751
20012
  pollIntervalMs,
19752
20013
  operations
19753
20014
  );
20015
+ const browserStyleClients = /* @__PURE__ */ new Map();
19754
20016
  await installAuxiliaryRenderers(
19755
20017
  options.rendererCdpEndpoint,
19756
20018
  options.rendererSource,
19757
20019
  enabledAgents,
19758
20020
  options.overlayHookSource,
20021
+ browserStyleClients,
19759
20022
  operations,
19760
20023
  discoveryTimeoutSignal(timeoutMs, options.signal)
19761
20024
  );
@@ -19764,6 +20027,7 @@ async function createRendererCdpControlSession(options) {
19764
20027
  options.rendererCdpEndpoint,
19765
20028
  options.rendererSource,
19766
20029
  options.overlayHookSource,
20030
+ browserStyleClients,
19767
20031
  enabledAgents,
19768
20032
  timeoutMs,
19769
20033
  pollIntervalMs,