@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.
@@ -21099,6 +21099,22 @@ var threadSteeringInspectParamsSchema = external_exports.object({
21099
21099
  text: external_exports.string().optional()
21100
21100
  }).strict();
21101
21101
  var THREAD_STEER_DELIVERY_PARAM = "codexhostSteerDelivery";
21102
+ var THREAD_STEERING_CONTEXT_PARAM = "codexhost_external_steering";
21103
+ var threadSteeringContextSchema = external_exports.object({
21104
+ kind: external_exports.literal("application"),
21105
+ value: external_exports.string().transform((text, context) => {
21106
+ try {
21107
+ return JSON.parse(text);
21108
+ } catch {
21109
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
21110
+ return external_exports.NEVER;
21111
+ }
21112
+ }).pipe(external_exports.object({
21113
+ expectedTurnId: hostTurnIdSchema,
21114
+ clientUserMessageId: external_exports.string().min(1),
21115
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
21116
+ }).strict())
21117
+ }).strict().transform((context) => context.value);
21102
21118
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
21103
21119
  var threadSteeringInspectResultSchema = external_exports.object({
21104
21120
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -30173,7 +30189,9 @@ function findRendererHostRpcFamily(store) {
30173
30189
  if (!record6(members) || typeof members.get !== "function")
30174
30190
  continue;
30175
30191
  for (const [hostId2, member] of members) {
30176
- if (typeof hostId2 !== "string" || !record6(member))
30192
+ if (typeof hostId2 !== "string" || !/^(?:local$|durable$|remote[-:]|ssh:)/u.test(hostId2))
30193
+ continue;
30194
+ if (!record6(member))
30177
30195
  continue;
30178
30196
  const signal = member.value;
30179
30197
  if (!record6(signal) || typeof signal.get !== "function")
@@ -30303,7 +30321,9 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30303
30321
  return null;
30304
30322
  try {
30305
30323
  const store = dependencies2.findStore(root);
30306
- discovery = store ? dependencies2.findFamily(store) : null;
30324
+ const bound = store && discovery?.store === store ? [...store.familyBindings.values()].includes(discovery.family) : false;
30325
+ if (!bound)
30326
+ discovery = store ? dependencies2.findFamily(store) : null;
30307
30327
  } catch {
30308
30328
  discovery = null;
30309
30329
  }
@@ -30312,14 +30332,15 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30312
30332
  if (!read())
30313
30333
  return null;
30314
30334
  const queuePolicy = dependencies2.installQueuePolicy(root, target);
30315
- const native = () => {
30316
- if (disposed)
30317
- return null;
30318
- try {
30319
- nativeRouting ??= dependencies2.nativeRouting?.() ?? null;
30320
- } catch {
30335
+ const discoverComposer = (composer) => {
30336
+ const owners = dependencies2.discoverComposer(composer);
30337
+ if (!nativeRouting && (owners.managers.length || owners.registries.length)) {
30338
+ try {
30339
+ nativeRouting = dependencies2.installNativeRouting();
30340
+ } catch {
30341
+ }
30321
30342
  }
30322
- return nativeRouting;
30343
+ return owners;
30323
30344
  };
30324
30345
  const connectionFor = (hostId2) => {
30325
30346
  if (!hostId2.startsWith("remote-control:"))
@@ -30526,7 +30547,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30526
30547
  if (disposed)
30527
30548
  return null;
30528
30549
  const connection = connectionFor(hostId2);
30529
- const preferred = nativeRoute === void 0 ? native()?.forHost(hostId2) : nativeRoute;
30550
+ const preferred = nativeRoute === void 0 ? nativeRouting?.forHost(hostId2) : nativeRoute;
30530
30551
  if (connection === null || preferred) {
30531
30552
  retire(hostId2);
30532
30553
  return connection === null ? null : preferred ?? null;
@@ -30555,11 +30576,11 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30555
30576
  target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
30556
30577
  }
30557
30578
  };
30558
- const composerHostId = (composer) => {
30559
- const nativeHostId = native()?.hostIdForComposer(composer);
30579
+ const composerHostId = (owners, composer) => {
30580
+ const nativeHostId = nativeRouting?.hostIdForComposer(composer);
30560
30581
  if (nativeHostId)
30561
30582
  return nativeHostId;
30562
- const hostIds = new Set(dependencies2.composerHostIds(composer).hostIds);
30583
+ const hostIds = new Set((owners ?? discoverComposer(composer)).hostIds);
30563
30584
  const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
30564
30585
  return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
30565
30586
  };
@@ -30567,11 +30588,16 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30567
30588
  knownHostIds() {
30568
30589
  if (disposed)
30569
30590
  return [];
30591
+ try {
30592
+ if (!nativeRouting)
30593
+ discoverComposer();
30594
+ } catch {
30595
+ }
30570
30596
  const current = read();
30571
30597
  return [
30572
30598
  .../* @__PURE__ */ new Set([
30573
30599
  ...current ? dependencies2.hostIds(current) : [],
30574
- ...native()?.knownHostIds?.() ?? []
30600
+ ...nativeRouting?.knownHostIds?.() ?? []
30575
30601
  ])
30576
30602
  ];
30577
30603
  },
@@ -30582,7 +30608,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30582
30608
  if (disposed)
30583
30609
  return null;
30584
30610
  try {
30585
- return composerHostId(composer);
30611
+ return composerHostId(nativeRouting ? null : discoverComposer(composer), composer);
30586
30612
  } catch {
30587
30613
  return null;
30588
30614
  }
@@ -30593,8 +30619,9 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
30593
30619
  let hostId2;
30594
30620
  let preferred = null;
30595
30621
  try {
30596
- preferred = native()?.forComposer(composer) ?? null;
30597
- hostId2 = preferred?.hostId ?? composerHostId(composer);
30622
+ const owners = nativeRouting ? null : discoverComposer(composer);
30623
+ preferred = nativeRouting?.forComposer(composer) ?? null;
30624
+ hostId2 = preferred?.hostId ?? composerHostId(owners, composer);
30598
30625
  } catch {
30599
30626
  hostId2 = null;
30600
30627
  }
@@ -30686,7 +30713,7 @@ function directRendererInstaller() {
30686
30713
  findFamily: ${findRendererHostRpcFamily.toString()},
30687
30714
  resolve: ${resolveRendererHostRpc.toString()},
30688
30715
  hostIds: ${rendererHostRpcHostIds.toString()},
30689
- composerHostIds: (composer) => {
30716
+ discoverComposer: (composer) => {
30690
30717
  const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
30691
30718
  ? { querySelectorAll: () => [composer] }
30692
30719
  : (composer ?? document);
@@ -30698,10 +30725,7 @@ function directRendererInstaller() {
30698
30725
  portPrototype: MessagePort.prototype,
30699
30726
  }),
30700
30727
  portPrototype: MessagePort.prototype,
30701
- nativeRouting: () => {
30702
- const native = discover(document);
30703
- return native.managers.length || native.registries.length ? installNative(false) : null;
30704
- },
30728
+ installNativeRouting: () => installNative(false),
30705
30729
  readConnection: (hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
30706
30730
  });
30707
30731
  const connected = (routing) => routing.forComposer() !== null ||
@@ -30758,6 +30782,79 @@ var startupTraceStartedAt = Date.now();
30758
30782
  // packages/desktop-control/dist/cpa-live-voice-hook.js
30759
30783
  var CPA_LIVE_VOICE_HOOK_GLOBAL = "__codexhostCpaLiveVoiceHookV1";
30760
30784
 
30785
+ // packages/desktop-control/dist/browser-annotation-style-compat.js
30786
+ var BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE = String.raw`(() => {
30787
+ const key = '__codexhostBrowserAnnotationStylesV1';
30788
+ if (globalThis[key]?.refresh() === true) return;
30789
+ if (typeof CSSStyleSheet !== 'function' ||
30790
+ typeof CSSStyleSheet.prototype.replaceSync !== 'function') return;
30791
+ let root = null;
30792
+ let shadow = null;
30793
+ let stylesObserver = null;
30794
+ const copies = new Map();
30795
+ function removeCopies() {
30796
+ if (shadow) {
30797
+ const owned = new Set(Array.from(copies.values(), copy => copy.sheet));
30798
+ shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.filter(sheet => !owned.has(sheet));
30799
+ }
30800
+ copies.clear();
30801
+ }
30802
+ function syncStyles() {
30803
+ if (!shadow) return;
30804
+ const present = new Set();
30805
+ for (const style of shadow.querySelectorAll('style')) {
30806
+ const text = style.textContent || '';
30807
+ // Only repair Codex's cursor stylesheet when CSP rejected its style element.
30808
+ if (style.sheet || !text.includes('.annotation-selection-cursor')) continue;
30809
+ present.add(style);
30810
+ const previous = copies.get(style);
30811
+ if (previous?.text === text && shadow.adoptedStyleSheets.includes(previous.sheet)) continue;
30812
+ try {
30813
+ const sheet = previous?.sheet ?? new CSSStyleSheet();
30814
+ sheet.replaceSync(text);
30815
+ if (!shadow.adoptedStyleSheets.includes(sheet)) {
30816
+ shadow.adoptedStyleSheets = [...shadow.adoptedStyleSheets, sheet];
30817
+ }
30818
+ copies.set(style, { sheet, text });
30819
+ } catch { /* Unsupported annotation styles leave native behavior intact. */ }
30820
+ }
30821
+ for (const [style, copy] of copies) {
30822
+ if (present.has(style)) continue;
30823
+ shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.filter(sheet => sheet !== copy.sheet);
30824
+ copies.delete(style);
30825
+ }
30826
+ }
30827
+ function refresh() {
30828
+ const nextRoot = document.documentElement;
30829
+ if (root !== nextRoot) {
30830
+ rootObserver.disconnect();
30831
+ rootObserver.observe(document, { childList: true });
30832
+ root = nextRoot;
30833
+ if (root) rootObserver.observe(root, { childList: true });
30834
+ }
30835
+ const host = document.getElementById('codex-browser-sidebar-comments-root');
30836
+ const nextShadow = host?.parentElement === root ? host?.shadowRoot ?? null : null;
30837
+ if (nextShadow !== shadow) {
30838
+ stylesObserver?.disconnect();
30839
+ removeCopies();
30840
+ shadow = nextShadow;
30841
+ stylesObserver = null;
30842
+ if (shadow && 'adoptedStyleSheets' in shadow) {
30843
+ stylesObserver = new MutationObserver(syncStyles);
30844
+ stylesObserver.observe(shadow, { childList: true, subtree: true, characterData: true });
30845
+ } else {
30846
+ shadow = null;
30847
+ }
30848
+ }
30849
+ syncStyles();
30850
+ return true;
30851
+ }
30852
+ const rootObserver = new MutationObserver(refresh);
30853
+ rootObserver.observe(document, { childList: true });
30854
+ globalThis[key] = { refresh };
30855
+ refresh();
30856
+ })();`;
30857
+
30761
30858
  // packages/desktop-control/dist/renderer-loaded-modules.js
30762
30859
  var record3 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
30763
30860
  var MAX_MODULES = 4096;
@@ -31652,6 +31749,114 @@ async function installNativeRpcRemoteControlDirect(renderer) {
31652
31749
  }
31653
31750
  }
31654
31751
 
31752
+ // packages/desktop-control/dist/renderer-rpc-steering.js
31753
+ var RETRY_BASE_MS = 5e3;
31754
+ var RETRY_MAX_MS = 3e5;
31755
+ var retries = /* @__PURE__ */ new WeakMap();
31756
+ async function installRendererRpcSteeringDirect(client, now = Date.now) {
31757
+ try {
31758
+ const needed = await client.evaluate(`(() => {
31759
+ const steering = window.__codexhostRpcSteeringV1;
31760
+ if (steering && steering.controller.forHost === steering.forHost) return false;
31761
+ steering?.release();
31762
+ const routing=window.__codexhostHostRoutingV1;
31763
+ return ['local', ...(routing?.knownHostIds?.() ?? [])].some(id => routing?.forHost(id)?.manager.kind === 'main-process-rpc');
31764
+ })()`);
31765
+ if (!needed)
31766
+ return false;
31767
+ const retry = retries.get(client);
31768
+ if (retry && now() < retry.nextAt)
31769
+ return false;
31770
+ try {
31771
+ await discoverAndInstall(client);
31772
+ retries.delete(client);
31773
+ return true;
31774
+ } catch (error51) {
31775
+ const attempts = (retry?.attempts ?? 0) + 1;
31776
+ const delay8 = Math.min(RETRY_BASE_MS * 2 ** (attempts - 1), RETRY_MAX_MS);
31777
+ retries.set(client, { attempts, nextAt: now() + delay8 });
31778
+ console.error(`codexhost native steering discovery failed (attempt ${attempts}):`, error51 instanceof Error ? error51.message : String(error51));
31779
+ return false;
31780
+ }
31781
+ } catch {
31782
+ return false;
31783
+ }
31784
+ }
31785
+ async function discoverAndInstall(client) {
31786
+ const group = `codexhost-rpc-steering-${crypto.randomUUID()}`;
31787
+ const command = (method, params) => client.command(method, params);
31788
+ const properties = (objectId) => command("Runtime.getProperties", { objectId, ownProperties: true });
31789
+ const call = (objectId, functionDeclaration, args = []) => command("Runtime.callFunctionOn", {
31790
+ objectId,
31791
+ functionDeclaration,
31792
+ arguments: args,
31793
+ objectGroup: group,
31794
+ returnByValue: true
31795
+ });
31796
+ try {
31797
+ const proto = await command("Runtime.evaluate", {
31798
+ expression: "Object.getPrototypeOf(async function(){})",
31799
+ objectGroup: group
31800
+ });
31801
+ if (!proto.result.objectId)
31802
+ throw new Error("Native RPC steering discovery is unavailable");
31803
+ const objects = await command("Runtime.queryObjects", {
31804
+ prototypeObjectId: proto.result.objectId,
31805
+ objectGroup: group
31806
+ });
31807
+ if (!objects.objects.objectId)
31808
+ throw new Error("Native RPC steering discovery is unavailable");
31809
+ const filtered = await command("Runtime.callFunctionOn", {
31810
+ objectId: objects.objects.objectId,
31811
+ functionDeclaration: 'function(){return this.filter(fn=>fn.name==="collectAppStateSnapshot"&&String(fn).includes("collectSnapshot")).slice(0,9)}',
31812
+ objectGroup: group
31813
+ });
31814
+ if (!filtered.result.objectId)
31815
+ throw new Error("Native RPC Controller is unavailable");
31816
+ const snapshots = (await properties(filtered.result.objectId)).result.flatMap((entry) => entry.value?.type === "function" && entry.value.objectId ? [entry.value.objectId] : []);
31817
+ if (snapshots.length > 8)
31818
+ throw new Error("Native RPC Controller is ambiguous");
31819
+ const controllers = [];
31820
+ for (const snapshot2 of snapshots) {
31821
+ const scopes = (await properties(snapshot2)).internalProperties?.find((entry) => entry.name === "[[Scopes]]")?.value?.objectId;
31822
+ if (!scopes)
31823
+ continue;
31824
+ for (const scope of (await properties(scopes)).result) {
31825
+ if (!scope.value?.objectId || !scope.value.description?.startsWith("Closure"))
31826
+ continue;
31827
+ const bindings = (await properties(scope.value.objectId)).result;
31828
+ const owners = [];
31829
+ let rootScope;
31830
+ for (const binding of bindings) {
31831
+ if (binding.value?.type !== "object" || !binding.value.objectId)
31832
+ continue;
31833
+ const id2 = binding.value.objectId;
31834
+ const result2 = await call(id2, `function(){return (${nativeRpcObjectShape.toString()})(this)}`);
31835
+ const shape = result2.result.value;
31836
+ if (shape?.scope)
31837
+ rootScope = id2;
31838
+ if (shape?.controller && (await call(id2, "function(fn){return this.collectAppStateSnapshot===fn}", [
31839
+ { objectId: snapshot2 }
31840
+ ])).result.value === true)
31841
+ owners.push(id2);
31842
+ }
31843
+ if (owners.length !== 1 || !rootScope)
31844
+ continue;
31845
+ const root = await call(rootScope, `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}`);
31846
+ if (root.result.value === true)
31847
+ controllers.push(owners[0]);
31848
+ }
31849
+ }
31850
+ if (controllers.length !== 1)
31851
+ throw new Error("Native RPC Controller is missing or ambiguous");
31852
+ const result = await call(controllers[0], "function(){return window.__codexhostInstallRpcSteeringV1?.(this) === true}");
31853
+ if (result.exceptionDetails || result.result.value !== true)
31854
+ throw new Error("Native RPC steering installation failed");
31855
+ } finally {
31856
+ await client.command("Runtime.releaseObjectGroup", { objectGroup: group }).catch(() => void 0);
31857
+ }
31858
+ }
31859
+
31655
31860
  // packages/desktop-control/dist/renderer-cdp-control-session.js
31656
31861
  function isRecord9(value2) {
31657
31862
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
@@ -31850,6 +32055,40 @@ function isLocalThreadRenderer(target) {
31850
32055
  const route = url2.searchParams.get("initialRoute");
31851
32056
  return [...url2.searchParams.keys()].length === 1 && (route === "/local" || route?.startsWith("/local/") === true);
31852
32057
  }
32058
+ function isBrowserPage(target) {
32059
+ if (target.type !== "page")
32060
+ return false;
32061
+ try {
32062
+ return ["http:", "https:"].includes(new URL(target.url).protocol);
32063
+ } catch {
32064
+ return false;
32065
+ }
32066
+ }
32067
+ async function installBrowserAnnotationStyles(target, browserClients, operations, signal) {
32068
+ const timeoutMessage = "Browser annotation style compatibility installation timed out";
32069
+ const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
32070
+ let renderer = browserClients.get(target.id);
32071
+ const registered = renderer !== void 0;
32072
+ renderer ??= await connectRendererTarget(target, operations, signal, timeoutMessage);
32073
+ const connected = renderer;
32074
+ try {
32075
+ if (!registered) {
32076
+ await run(() => connected.command("Page.enable"));
32077
+ await run(() => connected.command("Page.addScriptToEvaluateOnNewDocument", {
32078
+ source: BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE
32079
+ }));
32080
+ browserClients.set(target.id, connected);
32081
+ }
32082
+ const installed = await run(() => connected.evaluate("globalThis.__codexhostBrowserAnnotationStylesV1?.refresh() === true"));
32083
+ if (installed !== true) {
32084
+ await run(() => evaluateSource(connected, BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE));
32085
+ }
32086
+ } catch (error51) {
32087
+ browserClients.delete(target.id);
32088
+ connected.close();
32089
+ throw error51;
32090
+ }
32091
+ }
31853
32092
  async function installLocalThreadRenderer(target, source, enabledAgents, operations, signal) {
31854
32093
  const timeoutMessage = "Local chat Renderer installation timed out";
31855
32094
  const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
@@ -31867,10 +32106,18 @@ async function installLocalThreadRenderer(target, source, enabledAgents, operati
31867
32106
  renderer.close();
31868
32107
  }
31869
32108
  }
31870
- async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, operations, signal) {
32109
+ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, browserStyleClients, operations, signal) {
31871
32110
  try {
31872
32111
  const targets = await awaitWithSignal(operations.listTargets(endpoint, signal), signal, "Auxiliary Renderer CDP target discovery timed out");
32112
+ const liveTargets = new Set(targets.map((target) => target.id));
32113
+ for (const [id2, client] of browserStyleClients) {
32114
+ if (!liveTargets.has(id2)) {
32115
+ client.close();
32116
+ browserStyleClients.delete(id2);
32117
+ }
32118
+ }
31873
32119
  await Promise.allSettled([
32120
+ ...targets.filter(isBrowserPage).map((target) => installBrowserAnnotationStyles(target, browserStyleClients, operations, signal)),
31874
32121
  ...overlayHookSource ? selectAvatarOverlayRendererTargets(targets).map((overlay) => installOverlayHook(overlay, overlayHookSource, operations, signal)) : [],
31875
32122
  ...targets.filter(isLocalThreadRenderer).map((target) => installLocalThreadRenderer(target, rendererSource, enabledAgents, operations, signal))
31876
32123
  ]);
@@ -31899,6 +32146,7 @@ var InstalledRendererCdpControlSession = class {
31899
32146
  rendererCdpEndpoint;
31900
32147
  rendererSource;
31901
32148
  overlayHookSource;
32149
+ browserStyleClients;
31902
32150
  enabledAgents;
31903
32151
  timeoutMs;
31904
32152
  pollIntervalMs;
@@ -31906,11 +32154,12 @@ var InstalledRendererCdpControlSession = class {
31906
32154
  currentSnapshot;
31907
32155
  disposeModules;
31908
32156
  #closed = false;
31909
- constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
32157
+ constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, browserStyleClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
31910
32158
  this.renderer = renderer;
31911
32159
  this.rendererCdpEndpoint = rendererCdpEndpoint;
31912
32160
  this.rendererSource = rendererSource;
31913
32161
  this.overlayHookSource = overlayHookSource;
32162
+ this.browserStyleClients = browserStyleClients;
31914
32163
  this.enabledAgents = enabledAgents;
31915
32164
  this.timeoutMs = timeoutMs;
31916
32165
  this.pollIntervalMs = pollIntervalMs;
@@ -31949,7 +32198,7 @@ var InstalledRendererCdpControlSession = class {
31949
32198
  this.currentSnapshot = replacement.snapshot;
31950
32199
  }
31951
32200
  }
31952
- await installAuxiliaryRenderers(this.rendererCdpEndpoint, this.rendererSource, this.enabledAgents, this.overlayHookSource, this.operations, discoveryTimeoutSignal(this.timeoutMs));
32201
+ await installAuxiliaryRenderers(this.rendererCdpEndpoint, this.rendererSource, this.enabledAgents, this.overlayHookSource, this.browserStyleClients, this.operations, discoveryTimeoutSignal(this.timeoutMs));
31953
32202
  return this.currentSnapshot;
31954
32203
  }
31955
32204
  async activateDesktop() {
@@ -31969,6 +32218,9 @@ var InstalledRendererCdpControlSession = class {
31969
32218
  this.#closed = true;
31970
32219
  this.disposeModules();
31971
32220
  this.renderer.close();
32221
+ for (const client of this.browserStyleClients.values())
32222
+ client.close();
32223
+ this.browserStyleClients.clear();
31972
32224
  }
31973
32225
  };
31974
32226
  var defaultOperations = {
@@ -31977,6 +32229,7 @@ var defaultOperations = {
31977
32229
  async installDraftPrewarmPolicy(renderer) {
31978
32230
  const status2 = await installRendererDraftPrewarmPolicyDirect(renderer);
31979
32231
  await installNativeRpcRemoteControlDirect(renderer);
32232
+ await installRendererRpcSteeringDirect(renderer);
31980
32233
  return status2;
31981
32234
  }
31982
32235
  };
@@ -31987,8 +32240,9 @@ async function createRendererCdpControlSession(options) {
31987
32240
  const operations = options.operations ?? defaultOperations;
31988
32241
  const target = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations, timeoutMs, pollIntervalMs, void 0, options.signal);
31989
32242
  const installed = await installTarget(target, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations);
31990
- await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, operations, discoveryTimeoutSignal(timeoutMs, options.signal));
31991
- return new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules);
32243
+ const browserStyleClients = /* @__PURE__ */ new Map();
32244
+ await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, browserStyleClients, operations, discoveryTimeoutSignal(timeoutMs, options.signal));
32245
+ return new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, browserStyleClients, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules);
31992
32246
  }
31993
32247
  function installRendererCdpControlSession(options) {
31994
32248
  return createRendererCdpControlSession(options);
@@ -37804,6 +38058,7 @@ var publicSubmission = ({
37804
38058
  var DEFAULT_PAGE_SIZE3 = 50;
37805
38059
  var ExternalThreadQueue = class {
37806
38060
  #queues = /* @__PURE__ */ new Map();
38061
+ #acceptedSteers = /* @__PURE__ */ new Map();
37807
38062
  #notifyChanged;
37808
38063
  #createId;
37809
38064
  constructor(options) {
@@ -37849,7 +38104,7 @@ var ExternalThreadQueue = class {
37849
38104
  async delete(threadId2, id2) {
37850
38105
  const items = this.#queues.get(threadId2);
37851
38106
  const index = items?.findIndex((item) => item.id === id2) ?? -1;
37852
- if (!items || index === -1) return false;
38107
+ if (!items || index === -1) return this.#acceptedSteers.get(id2) === threadId2;
37853
38108
  items.splice(index, 1);
37854
38109
  this.#prune(threadId2);
37855
38110
  await this.#notifyChanged(threadId2);
@@ -37882,6 +38137,26 @@ var ExternalThreadQueue = class {
37882
38137
  index
37883
38138
  };
37884
38139
  }
38140
+ /** Reserve the exact queued input before steering can finish a replacement Turn.
38141
+ * Otherwise automatic queue advancement can deliver that input a second time. */
38142
+ takeSteered(threadId2, clientUserMessageId, input) {
38143
+ if (typeof clientUserMessageId !== "string") return;
38144
+ const matches = (this.#queues.get(threadId2) ?? []).filter(
38145
+ (item2) => item2.clientUserMessageId === clientUserMessageId
38146
+ );
38147
+ if (matches.length === 0) return;
38148
+ const item = matches[0];
38149
+ if (matches.length !== 1 || externalTurnInputText(item.input) !== externalTurnInputText(input))
38150
+ throw new ExternalQueueError(-32602, "Queued steering input changed before delivery");
38151
+ return this.take(threadId2, item.id);
38152
+ }
38153
+ async acceptSteered(threadId2, taken) {
38154
+ this.#acceptedSteers.set(taken.submission.id, threadId2);
38155
+ while (this.#acceptedSteers.size > 128) {
38156
+ this.#acceptedSteers.delete(this.#acceptedSteers.keys().next().value);
38157
+ }
38158
+ await this.#notifyChanged(threadId2);
38159
+ }
37885
38160
  restore(threadId2, taken) {
37886
38161
  const items = this.#items(threadId2);
37887
38162
  if (items.some((item) => item.id === taken.submission.id)) return;
@@ -37895,6 +38170,9 @@ var ExternalThreadQueue = class {
37895
38170
  }
37896
38171
  forget(threadId2) {
37897
38172
  this.#queues.delete(threadId2);
38173
+ for (const [id2, owner] of this.#acceptedSteers) {
38174
+ if (owner === threadId2) this.#acceptedSteers.delete(id2);
38175
+ }
37898
38176
  }
37899
38177
  #items(threadId2) {
37900
38178
  let items = this.#queues.get(threadId2);
@@ -46089,7 +46367,7 @@ var AppServerHost = class {
46089
46367
  ...arguments_2 ? { arguments: arguments_2 } : {}
46090
46368
  });
46091
46369
  if (!result.ok) throw new ExternalCommandError(-32073, result.error.message);
46092
- return { turnId: result.value.turnId, turn: projection.projector.pendingTurn(), gate };
46370
+ return { turnId, turn: projection.projector.pendingTurn(), gate };
46093
46371
  } catch (error51) {
46094
46372
  restoreExecutionHost();
46095
46373
  thread.running = false;
@@ -46917,6 +47195,11 @@ var AppServerHost = class {
46917
47195
  );
46918
47196
  }
46919
47197
  async #startExternalTurn(request, thread) {
47198
+ const context = routingParams(request).additionalContext;
47199
+ if (isRecord21(context) && Object.hasOwn(context, THREAD_STEERING_CONTEXT_PARAM)) {
47200
+ await this.#steerExternalTurn(request, thread, true);
47201
+ return;
47202
+ }
46920
47203
  if (this.#externalThreadBusy(thread) || this.#pendingExternalCommandRequests.has(thread.id)) {
46921
47204
  await this.#writer.json(
46922
47205
  rpcError(request, -32072, "External Thread already has an active Turn")
@@ -47135,34 +47418,61 @@ var AppServerHost = class {
47135
47418
  this.#diagnose(error51);
47136
47419
  }
47137
47420
  }
47138
- async #steerExternalTurn(request, thread) {
47421
+ async #steerExternalTurn(request, thread, asStart = false) {
47422
+ let queued;
47423
+ let accepted = false;
47139
47424
  try {
47425
+ let params = requestObject(request);
47426
+ const context = params.additionalContext;
47427
+ if (isRecord21(context) && Object.hasOwn(context, THREAD_STEERING_CONTEXT_PARAM)) {
47428
+ const marker = threadSteeringContextSchema.safeParse(
47429
+ context[THREAD_STEERING_CONTEXT_PARAM]
47430
+ );
47431
+ if (!marker.success || marker.data.clientUserMessageId !== params.clientUserMessageId || asStart && marker.data.delivery !== "newTurn")
47432
+ throw new ExternalSteerError(-32602, "Invalid native steering preparation context");
47433
+ if (!asStart && params.expectedTurnId !== marker.data.expectedTurnId)
47434
+ throw new ExternalSteerError(-32074, "Native steering target changed before submission");
47435
+ params = {
47436
+ ...params,
47437
+ expectedTurnId: marker.data.expectedTurnId,
47438
+ [THREAD_STEER_DELIVERY_PARAM]: marker.data.delivery
47439
+ };
47440
+ }
47441
+ queued = this.#externalQueue.takeSteered(thread.id, params.clientUserMessageId, params.input);
47140
47442
  const started = await this.#externalSteering.run(
47141
47443
  thread,
47142
- requestObject(request),
47444
+ params,
47143
47445
  (text, assertActive) => this.#beginExternalInputTurn(
47144
47446
  thread,
47145
47447
  text,
47146
47448
  assertActive,
47147
47449
  typeof requestObject(request).clientUserMessageId === "string" ? requestObject(request).clientUserMessageId : void 0,
47148
- requestObject(request)[THREAD_REFERENCE_SOURCE_HOST_PARAM]
47450
+ queued ? queued.sourceHostId : requestObject(request)[THREAD_REFERENCE_SOURCE_HOST_PARAM]
47149
47451
  ),
47150
47452
  (input) => this.#insertExternalInput(thread, input)
47151
47453
  );
47454
+ accepted = true;
47455
+ if (queued) {
47456
+ await this.#externalQueue.acceptSteered(thread.id, queued).catch((error51) => this.#diagnose(error51));
47457
+ }
47152
47458
  try {
47153
47459
  await this.#writer.json(
47154
47460
  rpcEnvelope(request, {
47155
- result: { turnId: started.turnId, delivery: started.delivery }
47461
+ result: asStart ? { turn: this.#projectedTurn(thread, started.turnId).projector.pendingTurn() } : { turnId: started.turnId, delivery: started.delivery }
47156
47462
  })
47157
47463
  );
47158
47464
  } finally {
47159
47465
  started.gate.resolve();
47160
47466
  }
47161
47467
  } catch (error51) {
47468
+ if (queued && !accepted) {
47469
+ this.#externalQueue.restore(thread.id, queued);
47470
+ await this.#externalQueue.notifyChanged(thread.id).catch((failure3) => this.#diagnose(failure3));
47471
+ }
47162
47472
  await this.#writer.json(
47163
47473
  rpcError(
47164
47474
  request,
47165
- error51 instanceof ExternalSteerError || error51 instanceof ExternalCommandError ? error51.code : -32074,
47475
+ error51 instanceof ExternalSteerError || error51 instanceof ExternalCommandError || error51 instanceof ExternalQueueError ? error51.code : -32074,
47166
47476
  errorMessage4(error51)
47167
47477
  )
47168
47478
  );
@@ -15971,6 +15971,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15971
15971
  /** The text about to be steered; a Harness command always stops and restarts. */
15972
15972
  text: external_exports.string().optional()
15973
15973
  }).strict();
15974
+ var threadSteeringContextSchema = external_exports.object({
15975
+ kind: external_exports.literal("application"),
15976
+ value: external_exports.string().transform((text, context) => {
15977
+ try {
15978
+ return JSON.parse(text);
15979
+ } catch {
15980
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15981
+ return external_exports.NEVER;
15982
+ }
15983
+ }).pipe(external_exports.object({
15984
+ expectedTurnId: hostTurnIdSchema,
15985
+ clientUserMessageId: external_exports.string().min(1),
15986
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15987
+ }).strict())
15988
+ }).strict().transform((context) => context.value);
15974
15989
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15975
15990
  var threadSteeringInspectResultSchema = external_exports.object({
15976
15991
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15565,6 +15565,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15565
15565
  /** The text about to be steered; a Harness command always stops and restarts. */
15566
15566
  text: external_exports.string().optional()
15567
15567
  }).strict();
15568
+ var threadSteeringContextSchema = external_exports.object({
15569
+ kind: external_exports.literal("application"),
15570
+ value: external_exports.string().transform((text2, context) => {
15571
+ try {
15572
+ return JSON.parse(text2);
15573
+ } catch {
15574
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15575
+ return external_exports.NEVER;
15576
+ }
15577
+ }).pipe(external_exports.object({
15578
+ expectedTurnId: hostTurnIdSchema,
15579
+ clientUserMessageId: external_exports.string().min(1),
15580
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15581
+ }).strict())
15582
+ }).strict().transform((context) => context.value);
15568
15583
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15569
15584
  var threadSteeringInspectResultSchema = external_exports.object({
15570
15585
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -16041,6 +16041,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
16041
16041
  /** The text about to be steered; a Harness command always stops and restarts. */
16042
16042
  text: external_exports.string().optional()
16043
16043
  }).strict();
16044
+ var threadSteeringContextSchema = external_exports.object({
16045
+ kind: external_exports.literal("application"),
16046
+ value: external_exports.string().transform((text2, context) => {
16047
+ try {
16048
+ return JSON.parse(text2);
16049
+ } catch {
16050
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
16051
+ return external_exports.NEVER;
16052
+ }
16053
+ }).pipe(external_exports.object({
16054
+ expectedTurnId: hostTurnIdSchema,
16055
+ clientUserMessageId: external_exports.string().min(1),
16056
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
16057
+ }).strict())
16058
+ }).strict().transform((context) => context.value);
16044
16059
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
16045
16060
  var threadSteeringInspectResultSchema = external_exports.object({
16046
16061
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])