@karlorz/codexhost-cli-darwin-x64 0.22.0-2 → 0.22.0-6

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.22.0-2
10
+ npm install -g @karlorz/codexhost-cli@0.22.0-6
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.22.0-2","distribution":"npm","target":"macos-x64"}
1
+ {"schemaVersion":1,"version":"0.22.0-6","distribution":"npm","target":"macos-x64"}
@@ -21750,6 +21750,30 @@ function discoveryTimeoutSignal(timeoutMs, signal) {
21750
21750
  function abortFailure(signal, fallback) {
21751
21751
  return signal.reason instanceof Error ? signal.reason : new Error(fallback);
21752
21752
  }
21753
+ function isRendererDocumentLoadEvent(params) {
21754
+ if (!isRecord3(params) || typeof params.name !== "string") return false;
21755
+ return params.name === "DOMContentLoaded" || params.name === "load" || params.name === "networkIdle";
21756
+ }
21757
+ async function waitForRendererDocumentLoad(renderer, run, signal, timeoutMessage) {
21758
+ await run(() => renderer.command("Page.enable"));
21759
+ let finished = false;
21760
+ const loaded = new Promise((resolve) => {
21761
+ const complete = () => {
21762
+ if (finished) return;
21763
+ finished = true;
21764
+ unsubscribeLoad();
21765
+ unsubscribeLifecycle();
21766
+ resolve();
21767
+ };
21768
+ const unsubscribeLoad = renderer.on("Page.loadEventFired", complete);
21769
+ const unsubscribeLifecycle = renderer.on("Page.lifecycleEvent", (params) => {
21770
+ if (isRendererDocumentLoadEvent(params)) complete();
21771
+ });
21772
+ });
21773
+ await run(() => renderer.command("Page.setLifecycleEventsEnabled", { enabled: true }));
21774
+ if (signal) await awaitWithSignal(loaded, signal, timeoutMessage);
21775
+ else await loaded;
21776
+ }
21753
21777
  function throwIfCdpAborted(signal, fallback) {
21754
21778
  if (signal.aborted) throw abortFailure(signal, fallback);
21755
21779
  }
@@ -22255,10 +22279,11 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
22255
22279
  } catch {
22256
22280
  }
22257
22281
  }
22258
- async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals, signal) {
22282
+ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals, signal, waitForDocumentLoad) {
22259
22283
  const timeoutMessage = "Primary Renderer installation timed out";
22260
- const run = (operation) => signal ? runWithCdpSignal(signal, timeoutMessage, operation) : operation();
22261
- const renderer = signal ? await connectRendererTarget(target2, operations, signal, timeoutMessage) : await operations.connect(target2.webSocketDebuggerUrl);
22284
+ const loadSignal = signal ?? (waitForDocumentLoad ? AbortSignal.timeout(timeoutMs) : void 0);
22285
+ const run = (operation) => loadSignal ? runWithCdpSignal(loadSignal, timeoutMessage, operation) : operation();
22286
+ const renderer = loadSignal ? await connectRendererTarget(target2, operations, loadSignal, timeoutMessage) : await operations.connect(target2.webSocketDebuggerUrl);
22262
22287
  let disposeModules;
22263
22288
  try {
22264
22289
  if (voiceHost && voiceHostDisposals)
@@ -22267,6 +22292,9 @@ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs,
22267
22292
  enableRuntime: false
22268
22293
  })
22269
22294
  );
22295
+ if (waitForDocumentLoad) {
22296
+ await waitForRendererDocumentLoad(renderer, run, loadSignal, timeoutMessage);
22297
+ }
22270
22298
  disposeModules = await run(() => installRendererLoadedModules(renderer));
22271
22299
  await run(() => renderer.command("Page.enable"));
22272
22300
  await run(
@@ -22290,7 +22318,7 @@ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs,
22290
22318
  }
22291
22319
  }
22292
22320
  var InstalledRendererCdpControlSession = class {
22293
- constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals) {
22321
+ constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals, waitForDocumentLoad) {
22294
22322
  this.renderer = renderer;
22295
22323
  this.rendererCdpEndpoint = rendererCdpEndpoint2;
22296
22324
  this.rendererSource = rendererSource;
@@ -22306,6 +22334,7 @@ var InstalledRendererCdpControlSession = class {
22306
22334
  this.disposeModules = disposeModules;
22307
22335
  this.voiceHost = voiceHost;
22308
22336
  this.voiceHostDisposals = voiceHostDisposals;
22337
+ this.waitForDocumentLoad = waitForDocumentLoad;
22309
22338
  }
22310
22339
  renderer;
22311
22340
  rendererCdpEndpoint;
@@ -22322,6 +22351,7 @@ var InstalledRendererCdpControlSession = class {
22322
22351
  disposeModules;
22323
22352
  voiceHost;
22324
22353
  voiceHostDisposals;
22354
+ waitForDocumentLoad;
22325
22355
  #closed = false;
22326
22356
  #lateVoiceHost;
22327
22357
  #lateVoicePrimaryId;
@@ -22401,7 +22431,8 @@ var InstalledRendererCdpControlSession = class {
22401
22431
  this.operations,
22402
22432
  this.voiceHost,
22403
22433
  this.voiceHostDisposals,
22404
- this.#shutdown.signal
22434
+ this.#shutdown.signal,
22435
+ this.waitForDocumentLoad
22405
22436
  );
22406
22437
  if (this.#closed) {
22407
22438
  replacement.disposeModules();
@@ -22589,7 +22620,9 @@ async function createRendererCdpControlSession(options) {
22589
22620
  pollIntervalMs,
22590
22621
  operations,
22591
22622
  options.voiceHost,
22592
- voiceHostDisposals
22623
+ voiceHostDisposals,
22624
+ options.signal,
22625
+ options.waitForDocumentLoad
22593
22626
  );
22594
22627
  const browserStyleClients = /* @__PURE__ */ new Map();
22595
22628
  const overlayClients = /* @__PURE__ */ new Map();
@@ -22621,7 +22654,8 @@ async function createRendererCdpControlSession(options) {
22621
22654
  installed.snapshot,
22622
22655
  installed.disposeModules,
22623
22656
  options.voiceHost,
22624
- voiceHostDisposals
22657
+ voiceHostDisposals,
22658
+ options.waitForDocumentLoad === true
22625
22659
  );
22626
22660
  }
22627
22661
  function installRendererCdpControlSession(options) {
@@ -22631,10 +22665,15 @@ function installRendererCdpControlSession(options) {
22631
22665
  // packages/desktop-control/src/renderer-injection-skip.ts
22632
22666
  var SKIPPED_DESKTOP_VERSION_PREFIXES = ["26.1103.", "26.1106."];
22633
22667
  var HASHED_RENDERER_CANDIDATE_VERSION = "26.1106.51428";
22668
+ function hashedRendererWaitsForDocumentLoad(desktopVersion, platform = process.platform) {
22669
+ return platform === "win32" && desktopVersion?.trim() === HASHED_RENDERER_CANDIDATE_VERSION;
22670
+ }
22634
22671
  function rendererInjectionSkipReason(desktopVersion, platform = process.platform, options) {
22635
22672
  const version2 = desktopVersion?.trim();
22636
22673
  if (!version2) return null;
22637
- if (platform === "darwin" && version2 === HASHED_RENDERER_CANDIDATE_VERSION) return null;
22674
+ if (version2 === HASHED_RENDERER_CANDIDATE_VERSION && (platform === "darwin" || platform === "win32")) {
22675
+ return null;
22676
+ }
22638
22677
  if (SKIPPED_DESKTOP_VERSION_PREFIXES.some((prefix) => version2.startsWith(prefix))) {
22639
22678
  if (allowsIsolatedHashedInjection(version2, platform, options)) return null;
22640
22679
  return `Desktop ${version2} is skipped until hashed Renderer bindings are requalified`;
@@ -23239,6 +23278,7 @@ ${bootstrap}${overlayBundle}` : void 0;
23239
23278
  const overlayVoiceBootstrapSource = overlayHookSource && overlayBootstrapBundle.trim().length > 0 ? `${RENDERER_CSP_BOOTSTRAP}
23240
23279
  ${bootstrap}${overlayBootstrapBundle}` : void 0;
23241
23280
  startupTrace("installing Renderer Session");
23281
+ const waitForDocumentLoad = hashedRendererWaitsForDocumentLoad(desktopVersion);
23242
23282
  if (!voiceHost && options.hostDataDirectory && !skipReason) {
23243
23283
  for (let attempt = 0; attempt < 8 && !voiceHost && !signal.aborted; attempt += 1) {
23244
23284
  if (attempt > 0) await dependencies.sleep(250);
@@ -23259,7 +23299,8 @@ ${bootstrap}${rendererSource}`,
23259
23299
  ...voiceHost ? { voiceHost } : {},
23260
23300
  // External Agents are discovered from each target Host after installation.
23261
23301
  timeoutMs: PRODUCTION_INSTALL_TIMEOUT_MS,
23262
- signal
23302
+ signal,
23303
+ ...waitForDocumentLoad ? { waitForDocumentLoad } : {}
23263
23304
  },
23264
23305
  dependencies
23265
23306
  );
@@ -33585,7 +33585,9 @@ var storedTurnMappingV1Schema = external_exports.object({
33585
33585
  nativeTurnRef: nativeTurnRefSchema,
33586
33586
  nativeCheckpointRef: nativeCheckpointRefSchema.optional(),
33587
33587
  /** Desktop presentation for work completed during an external voice call. */
33588
- realtimeInline: external_exports.literal(true).optional()
33588
+ realtimeInline: external_exports.literal(true).optional(),
33589
+ /** Voice-originated input uses Desktop's native delegation presentation. */
33590
+ realtimeDelegation: external_exports.literal(true).optional()
33589
33591
  }).strict();
33590
33592
  var storedGitInfoV1Schema = external_exports.object({
33591
33593
  branch: nonBlankTextSchema6.max(4096).optional(),
@@ -34903,6 +34905,8 @@ var MappingStore = class {
34903
34905
  }
34904
34906
  if (update.realtimeInline)
34905
34907
  hostMatch.realtimeInline = true;
34908
+ if (update.realtimeDelegation)
34909
+ hostMatch.realtimeDelegation = true;
34906
34910
  continue;
34907
34911
  }
34908
34912
  const added = { ...update };
@@ -51196,6 +51200,35 @@ function discoveryTimeoutSignal(timeoutMs, signal) {
51196
51200
  function abortFailure(signal, fallback) {
51197
51201
  return signal.reason instanceof Error ? signal.reason : new Error(fallback);
51198
51202
  }
51203
+ function isRendererDocumentLoadEvent(params) {
51204
+ if (!isRecord12(params) || typeof params.name !== "string")
51205
+ return false;
51206
+ return params.name === "DOMContentLoaded" || params.name === "load" || params.name === "networkIdle";
51207
+ }
51208
+ async function waitForRendererDocumentLoad(renderer, run, signal, timeoutMessage) {
51209
+ await run(() => renderer.command("Page.enable"));
51210
+ let finished = false;
51211
+ const loaded = new Promise((resolve3) => {
51212
+ const complete = () => {
51213
+ if (finished)
51214
+ return;
51215
+ finished = true;
51216
+ unsubscribeLoad();
51217
+ unsubscribeLifecycle();
51218
+ resolve3();
51219
+ };
51220
+ const unsubscribeLoad = renderer.on("Page.loadEventFired", complete);
51221
+ const unsubscribeLifecycle = renderer.on("Page.lifecycleEvent", (params) => {
51222
+ if (isRendererDocumentLoadEvent(params))
51223
+ complete();
51224
+ });
51225
+ });
51226
+ await run(() => renderer.command("Page.setLifecycleEventsEnabled", { enabled: true }));
51227
+ if (signal)
51228
+ await awaitWithSignal(loaded, signal, timeoutMessage);
51229
+ else
51230
+ await loaded;
51231
+ }
51199
51232
  function throwIfCdpAborted(signal, fallback) {
51200
51233
  if (signal.aborted)
51201
51234
  throw abortFailure(signal, fallback);
@@ -51673,16 +51706,20 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
51673
51706
  } catch {
51674
51707
  }
51675
51708
  }
51676
- async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations2, voiceHost, voiceHostDisposals, signal) {
51709
+ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations2, voiceHost, voiceHostDisposals, signal, waitForDocumentLoad) {
51677
51710
  const timeoutMessage = "Primary Renderer installation timed out";
51678
- const run = (operation) => signal ? runWithCdpSignal(signal, timeoutMessage, operation) : operation();
51679
- const renderer = signal ? await connectRendererTarget(target2, operations2, signal, timeoutMessage) : await operations2.connect(target2.webSocketDebuggerUrl);
51711
+ const loadSignal = signal ?? (waitForDocumentLoad ? AbortSignal.timeout(timeoutMs) : void 0);
51712
+ const run = (operation) => loadSignal ? runWithCdpSignal(loadSignal, timeoutMessage, operation) : operation();
51713
+ const renderer = loadSignal ? await connectRendererTarget(target2, operations2, loadSignal, timeoutMessage) : await operations2.connect(target2.webSocketDebuggerUrl);
51680
51714
  let disposeModules;
51681
51715
  try {
51682
51716
  if (voiceHost && voiceHostDisposals)
51683
51717
  await run(() => bindRendererVoiceHost(renderer, voiceHost, voiceHostDisposals, {
51684
51718
  enableRuntime: false
51685
51719
  }));
51720
+ if (waitForDocumentLoad) {
51721
+ await waitForRendererDocumentLoad(renderer, run, loadSignal, timeoutMessage);
51722
+ }
51686
51723
  disposeModules = await run(() => installRendererLoadedModules(renderer));
51687
51724
  await run(() => renderer.command("Page.enable"));
51688
51725
  await run(() => renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource }));
@@ -51714,6 +51751,7 @@ var InstalledRendererCdpControlSession = class {
51714
51751
  disposeModules;
51715
51752
  voiceHost;
51716
51753
  voiceHostDisposals;
51754
+ waitForDocumentLoad;
51717
51755
  #closed = false;
51718
51756
  #lateVoiceHost;
51719
51757
  #lateVoicePrimaryId;
@@ -51723,7 +51761,7 @@ var InstalledRendererCdpControlSession = class {
51723
51761
  // close() aborts this deadline, so discovery, connects, installs, and
51724
51762
  // liveness probes in flight stop instead of running to their own timeouts.
51725
51763
  #shutdown = new AbortController();
51726
- constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations2, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals) {
51764
+ constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations2, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals, waitForDocumentLoad) {
51727
51765
  this.renderer = renderer;
51728
51766
  this.rendererCdpEndpoint = rendererCdpEndpoint;
51729
51767
  this.rendererSource = rendererSource;
@@ -51739,6 +51777,7 @@ var InstalledRendererCdpControlSession = class {
51739
51777
  this.disposeModules = disposeModules;
51740
51778
  this.voiceHost = voiceHost;
51741
51779
  this.voiceHostDisposals = voiceHostDisposals;
51780
+ this.waitForDocumentLoad = waitForDocumentLoad;
51742
51781
  }
51743
51782
  get snapshot() {
51744
51783
  return this.currentSnapshot;
@@ -51773,7 +51812,7 @@ var InstalledRendererCdpControlSession = class {
51773
51812
  }
51774
51813
  }
51775
51814
  async #replacePrimary(target2) {
51776
- const replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals, this.#shutdown.signal);
51815
+ const replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals, this.#shutdown.signal, this.waitForDocumentLoad);
51777
51816
  if (this.#closed) {
51778
51817
  replacement.disposeModules();
51779
51818
  unbindRendererVoiceHost(replacement.renderer, this.voiceHostDisposals);
@@ -51938,11 +51977,11 @@ async function createRendererCdpControlSession(options) {
51938
51977
  const operations2 = options.operations ?? defaultOperations;
51939
51978
  const target2 = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations2, timeoutMs, pollIntervalMs, void 0, options.signal);
51940
51979
  const voiceHostDisposals = /* @__PURE__ */ new Map();
51941
- const installed = await installTarget(target2, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations2, options.voiceHost, voiceHostDisposals);
51980
+ const installed = await installTarget(target2, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations2, options.voiceHost, voiceHostDisposals, options.signal, options.waitForDocumentLoad);
51942
51981
  const browserStyleClients = /* @__PURE__ */ new Map();
51943
51982
  const overlayClients = /* @__PURE__ */ new Map();
51944
51983
  await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations2, discoveryTimeoutSignal(timeoutMs, options.signal), options.voiceHost, voiceHostDisposals);
51945
- return new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations2, installed.snapshot, installed.disposeModules, options.voiceHost, voiceHostDisposals);
51984
+ return new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations2, installed.snapshot, installed.disposeModules, options.voiceHost, voiceHostDisposals, options.waitForDocumentLoad === true);
51946
51985
  }
51947
51986
  function installRendererCdpControlSession(options) {
51948
51987
  return createRendererCdpControlSession(options);
@@ -52425,29 +52464,67 @@ import { createHash as createHash10, randomUUID as randomUUID10 } from "node:cry
52425
52464
  // packages/host-runtime/src/external-voice-presentation.ts
52426
52465
  var INLINE_MARKDOWN = "::codex-realtime-inline{}\n";
52427
52466
  var inlineMarker = /^::codex-realtime-inline\{\}\r?\n/u;
52467
+ var delegationInput = /^<realtime_delegation>\n <input>([\s\S]*)<\/input>\n<\/realtime_delegation>$/u;
52468
+ function externalVoiceUserInputText(text4) {
52469
+ const captured = delegationInput.exec(text4)?.[1];
52470
+ return captured === void 0 ? text4 : captured.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&amp;", "&");
52471
+ }
52472
+ function presentUserInput(text4) {
52473
+ if (delegationInput.test(text4)) return text4;
52474
+ const escaped = text4.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
52475
+ return `<realtime_delegation>
52476
+ <input>${escaped}</input>
52477
+ </realtime_delegation>`;
52478
+ }
52428
52479
  function externalVoiceContentText(text4) {
52429
52480
  return text4.replace(inlineMarker, "");
52430
52481
  }
52431
52482
  function object5(value2) {
52432
52483
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
52433
52484
  }
52434
- function presentItem(item) {
52485
+ function presentItem(item, delegatedInput = false) {
52486
+ if (delegatedInput && object5(item) && item.type === "userMessage" && Array.isArray(item.content)) {
52487
+ return {
52488
+ ...item,
52489
+ codexhostNativeInput: item.codexhostNativeInput ?? item.content,
52490
+ content: item.content.map(
52491
+ (part) => object5(part) && part.type === "text" && typeof part.text === "string" ? { ...part, text: presentUserInput(part.text) } : part
52492
+ )
52493
+ };
52494
+ }
52435
52495
  if (!object5(item) || item.type !== "agentMessage" || typeof item.text !== "string") return item;
52436
52496
  if (!item.text.trim() || inlineMarker.test(item.text)) return item;
52437
52497
  return { ...item, text: INLINE_MARKDOWN + item.text };
52438
52498
  }
52439
- function presentExternalVoiceTurn(turn) {
52499
+ function presentExternalVoiceTurn(turn, realtimeDelegation = false) {
52440
52500
  if (!Array.isArray(turn.items)) return turn;
52441
- return { ...turn, items: turn.items.map(presentItem) };
52501
+ return {
52502
+ ...turn,
52503
+ items: turn.items.map(
52504
+ (item) => presentItem(item, realtimeDelegation && object5(item) && item.id === `${turn.id}-user`)
52505
+ )
52506
+ };
52442
52507
  }
52443
- function presentExternalVoiceMessage(message2) {
52508
+ function presentExternalVoiceMessage(message2, realtimeDelegation = false) {
52444
52509
  const params = message2.params;
52445
52510
  if (!object5(params)) return message2;
52446
52511
  if ((message2.method === "item/started" || message2.method === "item/completed") && params.item) {
52447
- return { ...message2, params: { ...params, item: presentItem(params.item) } };
52512
+ return {
52513
+ ...message2,
52514
+ params: {
52515
+ ...params,
52516
+ item: presentItem(
52517
+ params.item,
52518
+ realtimeDelegation && object5(params.item) && params.item.id === `${params.turnId}-user`
52519
+ )
52520
+ }
52521
+ };
52448
52522
  }
52449
52523
  if ((message2.method === "turn/started" || message2.method === "turn/completed") && object5(params.turn)) {
52450
- return { ...message2, params: { ...params, turn: presentExternalVoiceTurn(params.turn) } };
52524
+ return {
52525
+ ...message2,
52526
+ params: { ...params, turn: presentExternalVoiceTurn(params.turn, realtimeDelegation) }
52527
+ };
52451
52528
  }
52452
52529
  return message2;
52453
52530
  }
@@ -52602,7 +52679,9 @@ async function projectExternalSnapshot(store, record7, snapshot2, previousParent
52602
52679
  cwd: record7.cwd,
52603
52680
  snapshot: { ...turn, input: withoutInjectedText(turn.input, injected), items }
52604
52681
  });
52605
- turns.push(mapping.realtimeInline ? presentExternalVoiceTurn(projected) : projected);
52682
+ turns.push(
52683
+ mapping.realtimeInline || mapping.realtimeDelegation ? presentExternalVoiceTurn(projected, mapping.realtimeDelegation) : projected
52684
+ );
52606
52685
  }
52607
52686
  return turns;
52608
52687
  }
@@ -52735,7 +52814,7 @@ var ExternalThreadRepository = class {
52735
52814
  if (!record7.nativeSessionRef || !this.store.saveUsageMeasurements) return record7;
52736
52815
  return this.store.saveUsageMeasurements(record7.hostThreadId, record7.nativeSessionRef, values);
52737
52816
  }
52738
- async persistTurn(record7, hostTurnId, nativeTurnRef, nativeCheckpointRef, realtimeInline) {
52817
+ async persistTurn(record7, hostTurnId, nativeTurnRef, nativeCheckpointRef, realtimeInline, realtimeDelegation) {
52739
52818
  if (record7.state !== "ready" || !record7.nativeSessionRef || nativeTurnRef.harnessId !== record7.harnessId || nativeTurnRef.nativeSessionId !== record7.nativeSessionRef.nativeSessionId || nativeCheckpointRef && (nativeCheckpointRef.harnessId !== record7.harnessId || nativeCheckpointRef.nativeSessionId !== record7.nativeSessionRef.nativeSessionId)) {
52740
52819
  throw new Error("Live Turn identity does not belong to the stored Thread");
52741
52820
  }
@@ -52744,7 +52823,8 @@ var ExternalThreadRepository = class {
52744
52823
  hostTurnId,
52745
52824
  nativeTurnRef,
52746
52825
  ...nativeCheckpointRef ? { nativeCheckpointRef } : {},
52747
- ...realtimeInline ? { realtimeInline } : {}
52826
+ ...realtimeInline ? { realtimeInline } : {},
52827
+ ...realtimeDelegation ? { realtimeDelegation } : {}
52748
52828
  }
52749
52829
  ]);
52750
52830
  }
@@ -52791,6 +52871,7 @@ var ExternalThreadRepository = class {
52791
52871
  return {
52792
52872
  hostTurnId: previous.hostTurnId,
52793
52873
  ...previous.realtimeInline ? { realtimeInline: true } : {},
52874
+ ...previous.realtimeDelegation ? { realtimeDelegation: true } : {},
52794
52875
  nativeTurnRef: turn.nativeTurnRef,
52795
52876
  ...turn.checkpoint ? { nativeCheckpointRef: turn.checkpoint } : {}
52796
52877
  };
@@ -52823,6 +52904,7 @@ var ExternalThreadRepository = class {
52823
52904
  return {
52824
52905
  hostTurnId: previous.hostTurnId,
52825
52906
  ...previous.realtimeInline ? { realtimeInline: true } : {},
52907
+ ...previous.realtimeDelegation ? { realtimeDelegation: true } : {},
52826
52908
  nativeTurnRef: turn.nativeTurnRef,
52827
52909
  ...turn.checkpoint ? { nativeCheckpointRef: turn.checkpoint } : {}
52828
52910
  };
@@ -52882,6 +52964,7 @@ var ExternalThreadRepository = class {
52882
52964
  mapping: {
52883
52965
  hostTurnId: mapping.hostTurnId,
52884
52966
  ...mapping.realtimeInline ? { realtimeInline: true } : {},
52967
+ ...mapping.realtimeDelegation ? { realtimeDelegation: true } : {},
52885
52968
  nativeTurnRef: turn.nativeTurnRef,
52886
52969
  ...turn.checkpoint ? { nativeCheckpointRef: turn.checkpoint } : {}
52887
52970
  }
@@ -54033,7 +54116,9 @@ function isRecord15(value2) {
54033
54116
  }
54034
54117
  function userMessageText(item) {
54035
54118
  if (!Array.isArray(item.content)) return "";
54036
- return item.content.filter(isRecord15).map((part) => part.type === "text" && typeof part.text === "string" ? part.text.trim() : "").filter((text4) => text4.length > 0).join("\n");
54119
+ return item.content.filter(isRecord15).map(
54120
+ (part) => part.type === "text" && typeof part.text === "string" ? externalVoiceUserInputText(part.text).trim() : ""
54121
+ ).filter((text4) => text4.length > 0).join("\n");
54037
54122
  }
54038
54123
  function clip(text4) {
54039
54124
  return text4.length <= MAX_MESSAGE_CHARS ? text4 : text4.slice(0, MAX_MESSAGE_CHARS);
@@ -59821,7 +59906,8 @@ var ExternalThreadRuntime = class {
59821
59906
  event.turnId,
59822
59907
  event.nativeTurnRef,
59823
59908
  event.outcome.checkpoint,
59824
- thread3.projectedTurns.get(event.turnId)?.realtimeInline
59909
+ thread3.projectedTurns.get(event.turnId)?.realtimeInline,
59910
+ thread3.projectedTurns.get(event.turnId)?.realtimeDelegation
59825
59911
  );
59826
59912
  thread3.persistenceError = null;
59827
59913
  await this.persistUsageMeasurements(thread3);
@@ -69331,8 +69417,17 @@ var AppServerHost = class {
69331
69417
  this.#unregisterDelegationApi = typeof unregisterDelegationApi === "function" ? unregisterDelegationApi : void 0;
69332
69418
  this.#turnProjection = new ExternalTurnProjection({
69333
69419
  writeJson: (value2) => {
69334
- if (isRecord29(value2) && isRecord29(value2.params) && typeof value2.params.threadId === "string" && this.#externalVoice.has(value2.params.threadId)) {
69335
- return this.#writer.json(presentExternalVoiceMessage(value2));
69420
+ if (isRecord29(value2) && isRecord29(value2.params) && typeof value2.params.threadId === "string") {
69421
+ const threadId3 = value2.params.threadId;
69422
+ const thread3 = this.#externalRuntime.get(threadId3);
69423
+ const turnId = isRecord29(value2.params.turn) ? value2.params.turn.id : value2.params.turnId;
69424
+ const realtimeDelegation = typeof turnId === "string" && (thread3?.projectedTurns.get(turnId)?.realtimeDelegation === true || thread3?.record.turnMappings.some(
69425
+ (mapping) => mapping.hostTurnId === turnId && mapping.realtimeDelegation
69426
+ ) === true);
69427
+ if (realtimeDelegation || this.#externalVoice.has(threadId3))
69428
+ return this.#writer.json(
69429
+ presentExternalVoiceMessage(value2, realtimeDelegation)
69430
+ );
69336
69431
  }
69337
69432
  return this.#writer.json(value2);
69338
69433
  },
@@ -72814,7 +72909,9 @@ var AppServerHost = class {
72814
72909
  if (!thread3.activeTurnId || forClient2 && thread3.ephemeralTurnIds.has(thread3.activeTurnId))
72815
72910
  return turns;
72816
72911
  const active2 = thread3.projectedTurns.get(thread3.activeTurnId);
72817
- return active2 ? [...turns, forClient2 ? active2.projector.snapshotTurn() : active2.projector.pendingTurn()] : turns;
72912
+ if (!active2) return turns;
72913
+ const turn = forClient2 ? active2.projector.snapshotTurn() : active2.projector.pendingTurn();
72914
+ return [...turns, active2.realtimeDelegation ? presentExternalVoiceTurn(turn, true) : turn];
72818
72915
  }
72819
72916
  /**
72820
72917
  * Background commands whose native task has not settled overlay their live
@@ -72930,7 +73027,8 @@ var AppServerHost = class {
72930
73027
  if (signal.aborted) throw new Error("Voice session ended");
72931
73028
  const thread3 = this.#externalRuntime.get(threadId3);
72932
73029
  if (!thread3 || this.#closeRequested) throw new Error("External chat is unavailable");
72933
- const started = await this.#beginExternalInputTurn(thread3, text4);
73030
+ const started = await this.#beginExternalInputTurn(thread3, text4, void 0, void 0, true);
73031
+ projectedTurn(thread3, started.turnId).realtimeDelegation = true;
72934
73032
  answer = this.#externalVoiceResults.watch(threadId3, started.turnId, signal);
72935
73033
  void answer.catch(() => void 0);
72936
73034
  started.gate.resolve();
@@ -73851,11 +73949,12 @@ var AppServerHost = class {
73851
73949
  this.#followExternalVoiceTurn(thread3.id, event.turnId);
73852
73950
  }
73853
73951
  const ephemeralTurn = event.type === "turn.completed" && (event.ephemeral === true || thread3.ephemeralTurnIds.has(event.turnId));
73952
+ const realtimeDelegation = thread3.projectedTurns.get(event.turnId)?.realtimeDelegation;
73854
73953
  await this.#turnProjection.project(thread3, event);
73855
- if (event.type === "turn.completed" && this.#externalVoice.has(thread3.id) && !ephemeralTurn) {
73954
+ if (event.type === "turn.completed" && (realtimeDelegation || this.#externalVoice.has(thread3.id)) && !ephemeralTurn) {
73856
73955
  const last = thread3.turns.at(-1);
73857
73956
  if (last && isRecord29(last)) {
73858
- thread3.turns[thread3.turns.length - 1] = presentExternalVoiceTurn(last);
73957
+ thread3.turns[thread3.turns.length - 1] = presentExternalVoiceTurn(last, realtimeDelegation);
73859
73958
  }
73860
73959
  }
73861
73960
  this.#externalVoiceResults.observe(
@@ -18242,7 +18242,7 @@ var SessionImportScope = class {
18242
18242
  };
18243
18243
 
18244
18244
  // dist/native-history.js
18245
- import { existsSync as existsSync2, readFileSync, realpathSync } from "node:fs";
18245
+ import { existsSync as existsSync2, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
18246
18246
  import os2 from "node:os";
18247
18247
  import path6 from "node:path";
18248
18248
  import { DatabaseSync } from "node:sqlite";
@@ -18265,6 +18265,13 @@ function cursorSessionDirectory(sessionId, environment) {
18265
18265
  throw new Error("Unsupported Cursor native session ID");
18266
18266
  return path6.join(cursorConfigDirectory(environment), "acp-sessions", sessionId);
18267
18267
  }
18268
+ function cursorNativeStoreExists(sessionId, environment) {
18269
+ try {
18270
+ return existsSync2(path6.join(cursorSessionDirectory(sessionId, environment), "store.db"));
18271
+ } catch {
18272
+ return false;
18273
+ }
18274
+ }
18268
18275
  function cursorSameWorkspace(left, right) {
18269
18276
  return path6.resolve(left) === path6.resolve(right) || existsSync2(left) && existsSync2(right) && realpathSync.native(left) === realpathSync.native(right);
18270
18277
  }
@@ -18366,6 +18373,47 @@ function readCursorNativeHistory(sessionId, cwd, environment, allowMissing = fal
18366
18373
  db.close();
18367
18374
  }
18368
18375
  }
18376
+ function acpOnlyHistoryFile(sessionId, environment) {
18377
+ return path6.join(cursorConfigDirectory(environment), "codexhost-acp-only", `${sessionId}.json`);
18378
+ }
18379
+ function readCursorAcpOnlyTurns(sessionId, environment) {
18380
+ try {
18381
+ cursorSessionDirectory(sessionId, environment);
18382
+ const filename = acpOnlyHistoryFile(sessionId, environment);
18383
+ if (!existsSync2(filename))
18384
+ return [];
18385
+ const raw = JSON.parse(readFileSync(filename, "utf8"));
18386
+ if (!raw || typeof raw !== "object" || !Array.isArray(raw.turns))
18387
+ return [];
18388
+ const turns = [];
18389
+ for (const item of raw.turns) {
18390
+ if (!item || typeof item !== "object")
18391
+ continue;
18392
+ const id = item.id;
18393
+ const text = item.text;
18394
+ if (typeof id !== "string" || !id.trim() || typeof text !== "string")
18395
+ continue;
18396
+ const assistantText = item.assistantText;
18397
+ const itemId = item.itemId;
18398
+ turns.push({
18399
+ id,
18400
+ text,
18401
+ ...typeof assistantText === "string" && assistantText.trim() ? { assistantText } : {},
18402
+ ...typeof itemId === "string" && itemId.trim() ? { itemId } : {}
18403
+ });
18404
+ }
18405
+ return turns;
18406
+ } catch {
18407
+ return [];
18408
+ }
18409
+ }
18410
+ function writeCursorAcpOnlyTurns(sessionId, environment, turns) {
18411
+ cursorSessionDirectory(sessionId, environment);
18412
+ const filename = acpOnlyHistoryFile(sessionId, environment);
18413
+ mkdirSync(path6.dirname(filename), { recursive: true });
18414
+ writeFileSync(filename, `${JSON.stringify({ version: 1, nativeSessionId: sessionId, turns })}
18415
+ `, "utf8");
18416
+ }
18369
18417
  function readCursorNativeTurns(sessionId, cwd, environment, allowMissing = false) {
18370
18418
  return readCursorNativeHistory(sessionId, cwd, environment, allowMissing).turns;
18371
18419
  }
@@ -18383,6 +18431,14 @@ function cursorNativeSessionRef(nativeSessionId, executionPolicy) {
18383
18431
  formatVersion: 1
18384
18432
  });
18385
18433
  }
18434
+ function cursorNativeTurnRef(nativeSessionId, nativeTurnKey) {
18435
+ return nativeTurnRefSchema.parse({
18436
+ harnessId: cursorHarnessId,
18437
+ nativeSessionId,
18438
+ nativeTurnKey,
18439
+ formatVersion: 1
18440
+ });
18441
+ }
18386
18442
  function cursorExecutionPolicy(ref) {
18387
18443
  if (ref.harnessId !== cursorHarnessId || ref.formatVersion !== 1)
18388
18444
  throw new Error("Invalid Cursor Native Session Ref");
@@ -18619,6 +18675,55 @@ var CURSOR_MODES = harnessPermissionModeCatalogSchema.parse({
18619
18675
  }
18620
18676
  ]
18621
18677
  });
18678
+ var GROK_ACP_MODES = harnessPermissionModeCatalogSchema.parse({
18679
+ defaultModeId: "default",
18680
+ modes: [
18681
+ {
18682
+ id: "default",
18683
+ label: "Default",
18684
+ description: "Native ACP default session mode"
18685
+ },
18686
+ {
18687
+ id: "plan",
18688
+ label: "Plan",
18689
+ description: "Native ACP plan session mode"
18690
+ }
18691
+ ]
18692
+ });
18693
+ function parsedPermissionModeId(value) {
18694
+ const parsed = harnessPermissionModeIdSchema.safeParse(value);
18695
+ return parsed.success ? parsed.data : void 0;
18696
+ }
18697
+ function cursorUsesNativeSessionModes(info) {
18698
+ return cursorModes(info) !== CURSOR_MODES;
18699
+ }
18700
+ function cursorModes(info) {
18701
+ const available = (info.modes?.availableModes ?? []).flatMap((mode) => {
18702
+ const id = parsedPermissionModeId(mode.id);
18703
+ return id ? [
18704
+ {
18705
+ id,
18706
+ label: mode.name,
18707
+ ...mode.description ? { description: mode.description } : {}
18708
+ }
18709
+ ] : [];
18710
+ });
18711
+ const currentMode = info.modes?.currentModeId;
18712
+ if (available.length) {
18713
+ const current = available.some((mode) => mode.id === currentMode) ? currentMode : available[0]?.id;
18714
+ if (current)
18715
+ return harnessPermissionModeCatalogSchema.parse({ modes: available, defaultModeId: current });
18716
+ }
18717
+ if (GROK_ACP_MODES.modes.some((mode) => mode.id === currentMode) && currentMode)
18718
+ return harnessPermissionModeCatalogSchema.parse({
18719
+ ...GROK_ACP_MODES,
18720
+ defaultModeId: currentMode
18721
+ });
18722
+ return CURSOR_MODES;
18723
+ }
18724
+ function cursorCurrentPermissionModeId(info) {
18725
+ return harnessPermissionModeIdSchema.parse(info.configOptions?.find((option) => option.id === "mode")?.currentValue ?? info.modes?.currentModeId ?? CURSOR_MODES.defaultModeId);
18726
+ }
18622
18727
  var cursorModelRef = (nativeId) => harnessModelRefSchema.parse({ id: `cursor.${Buffer.from(nativeId).toString("base64url")}` });
18623
18728
  function cursorModels(info) {
18624
18729
  const option = info.configOptions?.find((option2) => option2.id === "model");
@@ -23036,6 +23141,11 @@ var CursorTransport = class {
23036
23141
  throw new Error("Cursor session is not open");
23037
23142
  return this.#bounded(this.#connection.setSessionConfigOption({ sessionId: this.sessionId, configId, value }));
23038
23143
  }
23144
+ async setMode(modeId) {
23145
+ if (!this.#connection)
23146
+ throw new Error("Cursor session is not open");
23147
+ return this.#bounded(this.#connection.setSessionMode({ sessionId: this.sessionId, modeId }));
23148
+ }
23039
23149
  async prompt(text, callbacks) {
23040
23150
  if (!this.#connection || this.#closed || this.#callbacks)
23041
23151
  throw new Error("Cursor session is closed or busy");
@@ -23808,6 +23918,7 @@ var CursorTurnOutput = class {
23808
23918
  #hold = "";
23809
23919
  #writableIterableClosed = false;
23810
23920
  #visibleAssistantText = false;
23921
+ #agentMessage;
23811
23922
  constructor(turnId, emit, nativeTurnIndex = 0) {
23812
23923
  this.turnId = turnId;
23813
23924
  this.emit = emit;
@@ -23825,6 +23936,13 @@ var CursorTurnOutput = class {
23825
23936
  hasVisibleAssistantText() {
23826
23937
  return this.#visibleAssistantText || takeCursorWritableIterableClosed(this.#hold).visible.trim().length > 0;
23827
23938
  }
23939
+ visibleAgentMessage() {
23940
+ if (this.#agentMessage)
23941
+ return this.#agentMessage;
23942
+ if (this.#text?.type === "agentMessage" && this.#text.text.trim())
23943
+ return { itemId: this.#text.itemId, text: this.#text.text };
23944
+ return void 0;
23945
+ }
23828
23946
  #flushHold() {
23829
23947
  if (!this.#hold)
23830
23948
  return;
@@ -23858,6 +23976,8 @@ var CursorTurnOutput = class {
23858
23976
  });
23859
23977
  }
23860
23978
  #finishText(outcome = { status: "succeeded" }) {
23979
+ if (this.#text?.type === "agentMessage" && this.#text.text.trim())
23980
+ this.#agentMessage = { itemId: this.#text.itemId, text: this.#text.text };
23861
23981
  if (this.#text)
23862
23982
  this.emit({
23863
23983
  type: "item.completed",
@@ -24527,7 +24647,33 @@ var CursorAdapter = class {
24527
24647
  #sessions = /* @__PURE__ */ new Set();
24528
24648
  #forks = /* @__PURE__ */ new Map();
24529
24649
  #inspections = /* @__PURE__ */ new Map();
24650
+ /** Grok 2.0.7 holds GROK_HOME for one stdio child. Inspect and open must not overlap. */
24651
+ #stdioBusy = false;
24652
+ #liveStdioSession;
24530
24653
  #closed = false;
24654
+ #tryAcquireStdio() {
24655
+ if (this.#stdioBusy)
24656
+ return false;
24657
+ this.#stdioBusy = true;
24658
+ return true;
24659
+ }
24660
+ #releaseStdio() {
24661
+ this.#stdioBusy = false;
24662
+ }
24663
+ #stdioBusyError() {
24664
+ const id = this.#liveStdioSession?.initialState.nativeRef?.nativeSessionId;
24665
+ return rejected("sessionBusy", id ? `Grok ACP is busy with session ${id}; close that cursor-cli thread or continue there` : "Grok ACP is already starting a session; close that cursor-cli thread or retry");
24666
+ }
24667
+ #busyInspection() {
24668
+ return {
24669
+ status: "unavailable",
24670
+ error: {
24671
+ code: "unavailable",
24672
+ message: "Grok ACP is busy; retry inspect after the live session is ready",
24673
+ retryable: true
24674
+ }
24675
+ };
24676
+ }
24531
24677
  sessionImport;
24532
24678
  constructor(options = {}) {
24533
24679
  this.options = options;
@@ -24546,6 +24692,18 @@ var CursorAdapter = class {
24546
24692
  ...this.options.timeoutMs ? { timeoutMs: this.options.timeoutMs } : {}
24547
24693
  };
24548
24694
  }
24695
+ #inspectionFromLiveSession(cwd) {
24696
+ const sessions = [...this.#sessions];
24697
+ const match = sessions.find((session) => path9.resolve(session.transport.options.cwd) === cwd) ?? sessions[0];
24698
+ if (!match)
24699
+ return;
24700
+ return {
24701
+ status: "ready",
24702
+ catalog: cursorCatalog(match.info),
24703
+ capabilities: cursorCapabilities(match.info),
24704
+ permissionModes: cursorModes(match.info)
24705
+ };
24706
+ }
24549
24707
  async inspect(input = {}) {
24550
24708
  if (this.#closed)
24551
24709
  return {
@@ -24553,27 +24711,40 @@ var CursorAdapter = class {
24553
24711
  error: { code: "unavailable", message: "Cursor adapter is closed", retryable: false }
24554
24712
  };
24555
24713
  const cwd = path9.resolve(input.cwd ?? process.cwd());
24714
+ const live = this.#inspectionFromLiveSession(cwd);
24715
+ if (live)
24716
+ return live;
24717
+ if (this.#stdioBusy)
24718
+ return this.#busyInspection();
24556
24719
  const cached2 = this.#inspections.get(cwd);
24557
24720
  if (cached2 && (cached2.pending || !input.refresh))
24558
24721
  return cached2.result;
24559
24722
  const result = (async () => {
24560
- const transport = new CursorTransport(this.transportOptions(cwd));
24723
+ if (!this.#tryAcquireStdio()) {
24724
+ this.#inspections.delete(cwd);
24725
+ return this.#busyInspection();
24726
+ }
24561
24727
  try {
24562
- const info = await transport.open();
24563
- return {
24564
- status: "ready",
24565
- catalog: cursorCatalog(info),
24566
- capabilities: cursorCapabilities(info),
24567
- permissionModes: CURSOR_MODES
24568
- };
24569
- } catch (error51) {
24570
- const failure = cursorError(error51);
24571
- return {
24572
- status: failure.code === "notInstalled" ? "notInstalled" : "unavailable",
24573
- error: failure
24574
- };
24728
+ const transport = new CursorTransport(this.transportOptions(cwd));
24729
+ try {
24730
+ const info = await transport.open();
24731
+ return {
24732
+ status: "ready",
24733
+ catalog: cursorCatalog(info),
24734
+ capabilities: cursorCapabilities(info),
24735
+ permissionModes: cursorModes(info)
24736
+ };
24737
+ } catch (error51) {
24738
+ const failure = cursorError(error51);
24739
+ return {
24740
+ status: failure.code === "notInstalled" ? "notInstalled" : "unavailable",
24741
+ error: failure
24742
+ };
24743
+ } finally {
24744
+ await transport.close();
24745
+ }
24575
24746
  } finally {
24576
- await transport.close();
24747
+ this.#releaseStdio();
24577
24748
  }
24578
24749
  })();
24579
24750
  const entry = { pending: true, result };
@@ -24622,52 +24793,88 @@ var CursorAdapter = class {
24622
24793
  executionPolicy
24623
24794
  };
24624
24795
  const transport = prepared ?? new CursorTransport(options);
24625
- try {
24626
- const before = input.kind === "resume" ? readCursorNativeHistory(input.nativeRef.nativeSessionId, options.cwd, options.environment) : void 0;
24627
- const info = await transport.open(input.kind === "resume" ? input.nativeRef.nativeSessionId : void 0);
24628
- let loadedSnapshot;
24629
- if (input.kind === "resume") {
24630
- const native = readCursorNativeHistory(transport.sessionId, options.cwd, options.environment);
24631
- const snapshot = cursorSnapshot(transport.sessionId, native.turns, transport.replay);
24632
- if (input.knownTurnRefs?.some((ref) => ref.harnessId !== this.harnessId || ref.nativeSessionId !== transport.sessionId || !native.turns.some((turn) => turn.id === ref.nativeTurnKey)))
24633
- throw new Error("Saved Cursor turn identity no longer exists in native history");
24634
- if (native.revision && before?.revision === native.revision)
24635
- loadedSnapshot = { revision: native.revision, snapshot };
24636
- }
24637
- const session = new CursorSession(transport, info, () => {
24638
- this.#sessions.delete(session);
24639
- }, input.kind === "create", loadedSnapshot);
24640
- if (input.model) {
24641
- const selected = await session.execute({ type: "model.select", model: input.model });
24642
- if (!selected.ok)
24643
- throw new Error(selected.error.message);
24644
- }
24645
- if (input.thinkingOptionId) {
24646
- const selected = await session.execute({
24647
- type: "thinking.select",
24648
- thinkingOptionId: input.thinkingOptionId
24649
- });
24650
- if (!selected.ok)
24651
- throw new Error(selected.error.message);
24652
- }
24653
- if (input.permissionModeId) {
24654
- const selected = await session.execute({
24655
- type: "permissionMode.select",
24656
- permissionModeId: input.permissionModeId
24657
- });
24658
- if (!selected.ok)
24659
- throw new Error(selected.error.message);
24796
+ let session;
24797
+ const held = !prepared;
24798
+ const run = async () => {
24799
+ let acquired = false;
24800
+ if (held) {
24801
+ const live = this.#liveStdioSession;
24802
+ if (live) {
24803
+ const liveId = live.initialState.nativeRef?.nativeSessionId;
24804
+ if (input.kind === "resume" && liveId && input.nativeRef.nativeSessionId === liveId)
24805
+ return { ok: true, value: live };
24806
+ if (!live.stdioIdle())
24807
+ return this.#stdioBusyError();
24808
+ await live.close();
24809
+ }
24810
+ if (!this.#tryAcquireStdio())
24811
+ return this.#stdioBusyError();
24812
+ acquired = true;
24660
24813
  }
24661
- if (this.#closed) {
24662
- await session.close();
24663
- return rejected("invalidState", "Cursor adapter closed during session startup");
24814
+ try {
24815
+ const acpOnlyResume = input.kind === "resume" && !cursorNativeStoreExists(input.nativeRef.nativeSessionId, options.environment);
24816
+ const before = input.kind === "resume" && !acpOnlyResume ? readCursorNativeHistory(input.nativeRef.nativeSessionId, options.cwd, options.environment) : void 0;
24817
+ let info;
24818
+ if (acpOnlyResume) {
24819
+ info = await transport.open();
24820
+ } else {
24821
+ info = await transport.open(input.kind === "resume" ? input.nativeRef.nativeSessionId : void 0);
24822
+ }
24823
+ let loadedSnapshot;
24824
+ if (input.kind === "resume" && !acpOnlyResume) {
24825
+ const native = readCursorNativeHistory(transport.sessionId, options.cwd, options.environment);
24826
+ const snapshot = cursorSnapshot(transport.sessionId, native.turns, transport.replay);
24827
+ if (input.knownTurnRefs?.some((ref) => ref.harnessId !== this.harnessId || ref.nativeSessionId !== transport.sessionId || !native.turns.some((turn) => turn.id === ref.nativeTurnKey)))
24828
+ throw new Error("Saved Cursor turn identity no longer exists in native history");
24829
+ if (native.revision && before?.revision === native.revision)
24830
+ loadedSnapshot = { revision: native.revision, snapshot };
24831
+ }
24832
+ session = new CursorSession(transport, info, () => {
24833
+ const opened = session;
24834
+ if (!opened)
24835
+ return;
24836
+ this.#sessions.delete(opened);
24837
+ if (this.#liveStdioSession === opened) {
24838
+ this.#liveStdioSession = void 0;
24839
+ this.#releaseStdio();
24840
+ }
24841
+ }, input.kind === "create" || acpOnlyResume, loadedSnapshot, input.kind === "resume" ? input.nativeRef.nativeSessionId : void 0);
24842
+ this.#sessions.add(session);
24843
+ const restoreOrThrow = async (selected) => {
24844
+ if (!selected.ok && !acpOnlyResume)
24845
+ throw new Error(selected.error.message);
24846
+ };
24847
+ if (input.model)
24848
+ await restoreOrThrow(await session.execute({ type: "model.select", model: input.model }));
24849
+ if (input.thinkingOptionId)
24850
+ await restoreOrThrow(await session.execute({
24851
+ type: "thinking.select",
24852
+ thinkingOptionId: input.thinkingOptionId
24853
+ }));
24854
+ if (input.permissionModeId && cursorModes(info).modes.some((mode) => mode.id === input.permissionModeId))
24855
+ await restoreOrThrow(await session.execute({
24856
+ type: "permissionMode.select",
24857
+ permissionModeId: input.permissionModeId
24858
+ }));
24859
+ if (this.#closed) {
24860
+ await session.close();
24861
+ return rejected("invalidState", "Cursor adapter closed during session startup");
24862
+ }
24863
+ const acpOnly = acpOnlyResume || !cursorNativeStoreExists(transport.sessionId, options.environment);
24864
+ if (held && acpOnly)
24865
+ this.#liveStdioSession = session;
24866
+ return { ok: true, value: session };
24867
+ } catch (error51) {
24868
+ await session?.close();
24869
+ if (!session)
24870
+ await transport.close();
24871
+ return { ok: false, error: cursorError(error51) };
24872
+ } finally {
24873
+ if (acquired && !this.#liveStdioSession)
24874
+ this.#releaseStdio();
24664
24875
  }
24665
- this.#sessions.add(session);
24666
- return { ok: true, value: session };
24667
- } catch (error51) {
24668
- await transport.close();
24669
- return { ok: false, error: cursorError(error51) };
24670
- }
24876
+ };
24877
+ return run();
24671
24878
  }
24672
24879
  async #fork(input, controller) {
24673
24880
  const signal = controller.signal;
@@ -24770,6 +24977,8 @@ var CursorAdapter = class {
24770
24977
  controller.abort();
24771
24978
  await Promise.allSettled([importing, ...this.#forks.values()]);
24772
24979
  await Promise.allSettled([...this.#sessions].map((session) => session.close()));
24980
+ this.#liveStdioSession = void 0;
24981
+ this.#stdioBusy = false;
24773
24982
  await Promise.allSettled([...this.#inspections.values()].map((inspection) => inspection.result));
24774
24983
  }
24775
24984
  };
@@ -24808,12 +25017,17 @@ var CursorSession = class {
24808
25017
  #configuring = false;
24809
25018
  #closed = false;
24810
25019
  #fresh;
25020
+ #nativeSessionId;
25021
+ #acpOnlyTurns;
24811
25022
  #snapshot;
24812
25023
  #subagentOutput;
24813
25024
  /** A Turn is running and no configuration change is in flight. */
24814
25025
  turnRunningForFork() {
24815
25026
  return !this.#closed && !this.#configuring && this.#active !== void 0;
24816
25027
  }
25028
+ stdioIdle() {
25029
+ return this.#closed || !this.#active && !this.#configuring;
25030
+ }
24817
25031
  lockForFork() {
24818
25032
  if (this.#closed || this.#active || this.#configuring)
24819
25033
  return;
@@ -24829,24 +25043,68 @@ var CursorSession = class {
24829
25043
  return void 0;
24830
25044
  }
24831
25045
  }
24832
- constructor(transport, info, onClose, created = true, loadedSnapshot) {
25046
+ constructor(transport, info, onClose, created = true, loadedSnapshot, persistedSessionId) {
24833
25047
  this.transport = transport;
24834
25048
  this.info = info;
24835
25049
  this.onClose = onClose;
24836
25050
  this.info = structuredClone(info);
24837
25051
  this.#fresh = created;
25052
+ this.#nativeSessionId = persistedSessionId ?? transport.sessionId;
25053
+ this.#acpOnlyTurns = readCursorAcpOnlyTurns(this.#nativeSessionId, transport.options.environment);
24838
25054
  this.#snapshot = loadedSnapshot;
24839
25055
  this.#executionPolicy = transport.options.executionPolicy ?? "default";
24840
25056
  this.#interactions = new CursorInteractions((output) => this.#channel.emit(output), this.#executionPolicy === "unattended-full-access" ? () => this.#refuseUnattendedApproval() : void 0);
24841
25057
  this.initialState = {
24842
- nativeRef: cursorNativeSessionRef(transport.sessionId, this.#executionPolicy),
25058
+ nativeRef: cursorNativeSessionRef(this.#nativeSessionId, this.#executionPolicy),
24843
25059
  effectiveModel: cursorConfiguredModelRef(cursorModels(info).current, info.configOptions),
24844
25060
  ...cursorThinkingState(info),
24845
- effectivePermissionModeId: harnessPermissionModeIdSchema.parse(info.configOptions?.find((option) => option.id === "mode")?.currentValue ?? info.modes?.currentModeId ?? "agent")
25061
+ effectivePermissionModeId: cursorCurrentPermissionModeId(info)
24846
25062
  };
24847
25063
  }
24848
25064
  #native(allowMissing = false) {
24849
- return readCursorNativeTurns(this.transport.sessionId, this.transport.options.cwd, this.transport.options.environment, allowMissing);
25065
+ const missing = !cursorNativeStoreExists(this.transport.sessionId, this.transport.options.environment);
25066
+ try {
25067
+ return readCursorNativeTurns(this.transport.sessionId, this.transport.options.cwd, this.transport.options.environment, allowMissing || missing);
25068
+ } catch (error51) {
25069
+ if (allowMissing || missing)
25070
+ return [];
25071
+ throw error51;
25072
+ }
25073
+ }
25074
+ #acpOnlyNativeStore() {
25075
+ return !cursorNativeStoreExists(this.transport.sessionId, this.transport.options.environment);
25076
+ }
25077
+ #acpOnlySnapshotTurns() {
25078
+ return this.#acpOnlyTurns.map((turn) => ({
25079
+ nativeTurnRef: cursorNativeTurnRef(this.#nativeSessionId, turn.id),
25080
+ input: [{ type: "text", text: turn.text }],
25081
+ items: turn.assistantText ? [
25082
+ {
25083
+ item: {
25084
+ type: "agentMessage",
25085
+ itemId: hostItemIdSchema.parse(turn.itemId ?? `cursor-${turn.id}-1`),
25086
+ text: turn.assistantText
25087
+ },
25088
+ outcome: { status: "succeeded" }
25089
+ }
25090
+ ] : [],
25091
+ outcome: turn.assistantText ? { status: "succeeded" } : {
25092
+ status: "unknown",
25093
+ reason: "ACP-only history does not expose the terminal stop reason"
25094
+ }
25095
+ }));
25096
+ }
25097
+ #recordAcpOnlyTurn(command, output) {
25098
+ const assistant = output.visibleAgentMessage();
25099
+ this.#acpOnlyTurns.push({
25100
+ id: command.turnId,
25101
+ text: command.input.map((part) => part.text).join("\n"),
25102
+ ...assistant ? { assistantText: assistant.text, itemId: assistant.itemId } : {}
25103
+ });
25104
+ try {
25105
+ writeCursorAcpOnlyTurns(this.#nativeSessionId, this.transport.options.environment, this.#acpOnlyTurns);
25106
+ } catch {
25107
+ }
24850
25108
  }
24851
25109
  /** Bound to unattended full access only; Cursor itself keeps enforcing its team policy. */
24852
25110
  #refuseUnattendedApproval() {
@@ -24873,9 +25131,19 @@ var CursorSession = class {
24873
25131
  this.#configuring = true;
24874
25132
  let replay;
24875
25133
  try {
24876
- const history = () => readCursorNativeHistory(this.transport.sessionId, this.transport.options.cwd, this.transport.options.environment, this.#fresh);
25134
+ const acpOnly = this.#acpOnlyNativeStore();
25135
+ if (acpOnly)
25136
+ return {
25137
+ ok: true,
25138
+ value: {
25139
+ turns: this.#acpOnlySnapshotTurns(),
25140
+ state: structuredClone(this.initialState)
25141
+ }
25142
+ };
25143
+ const allowMissing = this.#fresh;
25144
+ const history = () => readCursorNativeHistory(this.transport.sessionId, this.transport.options.cwd, this.transport.options.environment, allowMissing);
24877
25145
  const before = history();
24878
- if (before.turns.length === 0 && this.#fresh)
25146
+ if (before.turns.length === 0 && allowMissing)
24879
25147
  return { ok: true, value: { turns: [], state: structuredClone(this.initialState) } };
24880
25148
  if (!this.#snapshot || !before.revision || this.#snapshot.revision !== before.revision) {
24881
25149
  replay = new CursorTransport({
@@ -24940,7 +25208,7 @@ var CursorSession = class {
24940
25208
  return rejected("invalidRequest", "Cursor requires nonempty text input");
24941
25209
  let before;
24942
25210
  try {
24943
- before = this.#native(this.#fresh);
25211
+ before = this.#acpOnlyNativeStore() ? [] : this.#native(this.#fresh);
24944
25212
  } catch (error51) {
24945
25213
  return { ok: false, error: cursorError(error51) };
24946
25214
  }
@@ -24962,8 +25230,26 @@ var CursorSession = class {
24962
25230
  } else if (command.type === "model.select") {
24963
25231
  selections = cursorModelSelection(this.info, command.model.id);
24964
25232
  } else {
24965
- if (!CURSOR_MODES.modes.some((mode) => mode.id === command.permissionModeId))
25233
+ const catalog = cursorModes(this.info);
25234
+ if (!catalog.modes.some((mode) => mode.id === command.permissionModeId))
24966
25235
  return rejected("invalidRequest", "Unknown Cursor execution mode");
25236
+ if (cursorCurrentPermissionModeId(this.info) === command.permissionModeId) {
25237
+ this.initialState.effectivePermissionModeId = command.permissionModeId;
25238
+ return { ok: true, value: { completed: true } };
25239
+ }
25240
+ if (cursorUsesNativeSessionModes(this.info)) {
25241
+ await this.transport.setMode(command.permissionModeId);
25242
+ this.info.modes = {
25243
+ currentModeId: command.permissionModeId,
25244
+ availableModes: this.info.modes?.availableModes ?? []
25245
+ };
25246
+ this.initialState.effectivePermissionModeId = command.permissionModeId;
25247
+ this.#channel.emit({
25248
+ kind: "event",
25249
+ event: { type: "session.state.changed", state: structuredClone(this.initialState) }
25250
+ });
25251
+ return { ok: true, value: { completed: true } };
25252
+ }
24967
25253
  selections = [["mode", command.permissionModeId]];
24968
25254
  }
24969
25255
  for (const [configId, value] of selections) {
@@ -25046,21 +25332,21 @@ var CursorSession = class {
25046
25332
  }
25047
25333
  };
25048
25334
  try {
25049
- const after = this.#native(this.#fresh);
25335
+ const acpOnly = this.#acpOnlyNativeStore();
25336
+ const after = acpOnly ? [] : this.#native(this.#fresh);
25050
25337
  const added = after.filter((turn) => !before.some((old) => old.id === turn.id));
25051
25338
  const administrative = command.input.map((part) => part.text).join("\n").trim().toLowerCase() === "/copy-request-id";
25052
25339
  if (administrative && JSON.stringify(before) === JSON.stringify(after)) {
25340
+ } else if (acpOnly && outcome.status === "succeeded" && output.hasVisibleAssistantText()) {
25341
+ nativeTurnRef = cursorNativeTurnRef(this.#nativeSessionId, command.turnId);
25342
+ this.#recordAcpOnlyTurn(command, output);
25343
+ this.#fresh = false;
25053
25344
  } else {
25054
25345
  const prompted = added.filter((turn) => !turn.notification);
25055
25346
  const own = prompted[0];
25056
25347
  if (!own || prompted.length !== 1 || after.length !== before.length + added.length || before.some((turn, index) => after[index]?.id !== turn.id) || own.text !== command.input.map((part) => part.text).join("\n"))
25057
25348
  throw new Error("Cursor terminal has no unique, verified native turn identity");
25058
- nativeTurnRef = nativeTurnRefSchema.parse({
25059
- harnessId: "cursor-cli",
25060
- nativeSessionId: this.transport.sessionId,
25061
- nativeTurnKey: own.id,
25062
- formatVersion: 1
25063
- });
25349
+ nativeTurnRef = cursorNativeTurnRef(this.#nativeSessionId, own.id);
25064
25350
  this.#fresh = false;
25065
25351
  const ownIndex = after.findIndex((turn) => turn.id === own.id);
25066
25352
  if (outcome.status === "succeeded" && cursorForkAvailable() && (ownIndex === after.length - 1 || after[ownIndex + 1]?.rewindRoot))
@@ -77080,8 +77080,12 @@ function itemOf(item, reasoningPreviewIds) {
77080
77080
  return;
77081
77081
  }
77082
77082
  }
77083
+ function userMessageContent(item) {
77084
+ let content = item.codexhostNativeInput ?? item.content;
77085
+ return Array.isArray(content) ? content : [];
77086
+ }
77083
77087
  function userMessageIdentity(item) {
77084
- return JSON.stringify([item.content, item.clientId ?? null]);
77088
+ return JSON.stringify([userMessageContent(item), item.clientId ?? null]);
77085
77089
  }
77086
77090
  function nativeTime(seconds) {
77087
77091
  return typeof seconds == "number" && Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : void 0;
@@ -77165,7 +77169,7 @@ var ChThreadView = class _ChThreadView {
77165
77169
  let currentTurn;
77166
77170
  for (let event of this.log.events)
77167
77171
  if (event.type === "turn/start" && (currentTurn = event.data.turn), currentTurn === view.projector.turn && event.type === "user/message")
77168
- return { seq: event.seq, turnId: turn.id, input: messages2[0].content };
77172
+ return { seq: event.seq, turnId: turn.id, input: userMessageContent(messages2[0]) };
77169
77173
  }
77170
77174
  /** Older native pages are projected separately, without changing the visible tail. */
77171
77175
  prepend(turns) {
@@ -77294,7 +77298,7 @@ var ChThreadView = class _ChThreadView {
77294
77298
  }
77295
77299
  }), opening = items[0]?.type === "userMessage" ? items[0] : void 0;
77296
77300
  opening ? projector.begin(
77297
- this.projectInput(Array.isArray(opening.content) ? opening.content : []),
77301
+ this.projectInput(userMessageContent(opening)),
77298
77302
  typeof opening.clientId == "string" ? opening.clientId : void 0
77299
77303
  ) : projector.beginAutonomous([]), view = {
77300
77304
  projector,
@@ -77312,7 +77316,7 @@ var ChThreadView = class _ChThreadView {
77312
77316
  for (let item of items) {
77313
77317
  if (item.type === "userMessage") {
77314
77318
  view.userMessages.has(item.id) || (view.projector.steer(
77315
- this.projectInput(Array.isArray(item.content) ? item.content : []),
77319
+ this.projectInput(userMessageContent(item)),
77316
77320
  typeof item.clientId == "string" ? item.clientId : void 0
77317
77321
  ), view.userMessages.set(item.id, userMessageIdentity(item)), view.started.add(item.id));
77318
77322
  continue;
@@ -83556,6 +83560,20 @@ function discoveryTimeoutSignal(timeoutMs, signal) {
83556
83560
  function abortFailure(signal, fallback) {
83557
83561
  return signal.reason instanceof Error ? signal.reason : new Error(fallback);
83558
83562
  }
83563
+ function isRendererDocumentLoadEvent(params) {
83564
+ return !isRecord5(params) || typeof params.name != "string" ? !1 : params.name === "DOMContentLoaded" || params.name === "load" || params.name === "networkIdle";
83565
+ }
83566
+ async function waitForRendererDocumentLoad(renderer, run2, signal, timeoutMessage) {
83567
+ await run2(() => renderer.command("Page.enable"));
83568
+ let finished2 = !1, loaded = new Promise((resolve22) => {
83569
+ let complete = () => {
83570
+ finished2 || (finished2 = !0, unsubscribeLoad(), unsubscribeLifecycle(), resolve22());
83571
+ }, unsubscribeLoad = renderer.on("Page.loadEventFired", complete), unsubscribeLifecycle = renderer.on("Page.lifecycleEvent", (params) => {
83572
+ isRendererDocumentLoadEvent(params) && complete();
83573
+ });
83574
+ });
83575
+ await run2(() => renderer.command("Page.setLifecycleEventsEnabled", { enabled: !0 })), signal ? await awaitWithSignal(loaded, signal, timeoutMessage) : await loaded;
83576
+ }
83559
83577
  function throwIfCdpAborted(signal, fallback) {
83560
83578
  if (signal.aborted)
83561
83579
  throw abortFailure(signal, fallback);
@@ -83919,12 +83937,12 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
83919
83937
  } catch {
83920
83938
  }
83921
83939
  }
83922
- async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals, signal) {
83923
- let timeoutMessage = "Primary Renderer installation timed out", run2 = (operation) => signal ? runWithCdpSignal(signal, timeoutMessage, operation) : operation(), renderer = signal ? await connectRendererTarget(target2, operations, signal, timeoutMessage) : await operations.connect(target2.webSocketDebuggerUrl), disposeModules;
83940
+ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals, signal, waitForDocumentLoad) {
83941
+ let timeoutMessage = "Primary Renderer installation timed out", loadSignal = signal ?? (waitForDocumentLoad ? AbortSignal.timeout(timeoutMs) : void 0), run2 = (operation) => loadSignal ? runWithCdpSignal(loadSignal, timeoutMessage, operation) : operation(), renderer = loadSignal ? await connectRendererTarget(target2, operations, loadSignal, timeoutMessage) : await operations.connect(target2.webSocketDebuggerUrl), disposeModules;
83924
83942
  try {
83925
83943
  voiceHost && voiceHostDisposals && await run2(() => bindRendererVoiceHost(renderer, voiceHost, voiceHostDisposals, {
83926
83944
  enableRuntime: !1
83927
- })), disposeModules = await run2(() => installRendererLoadedModules(renderer)), await run2(() => renderer.command("Page.enable")), await run2(() => renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource })), await run2(() => evaluateSource(renderer, rendererSource));
83945
+ })), waitForDocumentLoad && await waitForRendererDocumentLoad(renderer, run2, loadSignal, timeoutMessage), disposeModules = await run2(() => installRendererLoadedModules(renderer)), await run2(() => renderer.command("Page.enable")), await run2(() => renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource })), await run2(() => evaluateSource(renderer, rendererSource));
83928
83946
  let draftPrewarmPolicy = await run2(() => operations.installDraftPrewarmPolicy(renderer)), binding = await waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs, signal);
83929
83947
  return { renderer, snapshot: { target: target2, draftPrewarmPolicy, binding }, disposeModules };
83930
83948
  } catch (error51) {
@@ -83947,6 +83965,7 @@ var InstalledRendererCdpControlSession = class {
83947
83965
  disposeModules;
83948
83966
  voiceHost;
83949
83967
  voiceHostDisposals;
83968
+ waitForDocumentLoad;
83950
83969
  #closed = !1;
83951
83970
  #lateVoiceHost;
83952
83971
  #lateVoicePrimaryId;
@@ -83956,8 +83975,8 @@ var InstalledRendererCdpControlSession = class {
83956
83975
  // close() aborts this deadline, so discovery, connects, installs, and
83957
83976
  // liveness probes in flight stop instead of running to their own timeouts.
83958
83977
  #shutdown = new AbortController();
83959
- constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals) {
83960
- this.renderer = renderer, this.rendererCdpEndpoint = rendererCdpEndpoint, this.rendererSource = rendererSource, this.overlayHookSource = overlayHookSource, this.overlayVoiceBootstrapSource = overlayVoiceBootstrapSource, this.browserStyleClients = browserStyleClients, this.overlayClients = overlayClients, this.enabledAgents = enabledAgents, this.timeoutMs = timeoutMs, this.pollIntervalMs = pollIntervalMs, this.operations = operations, this.currentSnapshot = currentSnapshot, this.disposeModules = disposeModules, this.voiceHost = voiceHost, this.voiceHostDisposals = voiceHostDisposals;
83978
+ constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals, waitForDocumentLoad) {
83979
+ this.renderer = renderer, this.rendererCdpEndpoint = rendererCdpEndpoint, this.rendererSource = rendererSource, this.overlayHookSource = overlayHookSource, this.overlayVoiceBootstrapSource = overlayVoiceBootstrapSource, this.browserStyleClients = browserStyleClients, this.overlayClients = overlayClients, this.enabledAgents = enabledAgents, this.timeoutMs = timeoutMs, this.pollIntervalMs = pollIntervalMs, this.operations = operations, this.currentSnapshot = currentSnapshot, this.disposeModules = disposeModules, this.voiceHost = voiceHost, this.voiceHostDisposals = voiceHostDisposals, this.waitForDocumentLoad = waitForDocumentLoad;
83961
83980
  }
83962
83981
  get snapshot() {
83963
83982
  return this.currentSnapshot;
@@ -83977,7 +83996,7 @@ var InstalledRendererCdpControlSession = class {
83977
83996
  }
83978
83997
  }
83979
83998
  async #replacePrimary(target2) {
83980
- let replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals, this.#shutdown.signal);
83999
+ let replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals, this.#shutdown.signal, this.waitForDocumentLoad);
83981
84000
  if (this.#closed)
83982
84001
  throw replacement.disposeModules(), unbindRendererVoiceHost(replacement.renderer, this.voiceHostDisposals), replacement.renderer.close(), new Error("Renderer CDP Control Session is closed");
83983
84002
  this.disposeModules(), unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals), this.renderer.close(), this.renderer = replacement.renderer, this.disposeModules = replacement.disposeModules, this.currentSnapshot = replacement.snapshot;
@@ -84083,8 +84102,8 @@ var InstalledRendererCdpControlSession = class {
84083
84102
  }
84084
84103
  };
84085
84104
  async function createRendererCdpControlSession(options) {
84086
- let enabledAgents = options.enabledAgents, timeoutMs = options.timeoutMs ?? 3e4, pollIntervalMs = options.pollIntervalMs ?? 250, operations = options.operations ?? defaultOperations, target2 = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations, timeoutMs, pollIntervalMs, void 0, options.signal), voiceHostDisposals = /* @__PURE__ */ new Map(), installed = await installTarget(target2, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, options.voiceHost, voiceHostDisposals), browserStyleClients = /* @__PURE__ */ new Map(), overlayClients = /* @__PURE__ */ new Map();
84087
- return await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, discoveryTimeoutSignal(timeoutMs, options.signal), options.voiceHost, voiceHostDisposals), new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules, options.voiceHost, voiceHostDisposals);
84105
+ let enabledAgents = options.enabledAgents, timeoutMs = options.timeoutMs ?? 3e4, pollIntervalMs = options.pollIntervalMs ?? 250, operations = options.operations ?? defaultOperations, target2 = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations, timeoutMs, pollIntervalMs, void 0, options.signal), voiceHostDisposals = /* @__PURE__ */ new Map(), installed = await installTarget(target2, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, options.voiceHost, voiceHostDisposals, options.signal, options.waitForDocumentLoad), browserStyleClients = /* @__PURE__ */ new Map(), overlayClients = /* @__PURE__ */ new Map();
84106
+ return await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, discoveryTimeoutSignal(timeoutMs, options.signal), options.voiceHost, voiceHostDisposals), new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules, options.voiceHost, voiceHostDisposals, options.waitForDocumentLoad === !0);
84088
84107
  }
84089
84108
  function installRendererCdpControlSession(options) {
84090
84109
  return createRendererCdpControlSession(options);
package/bin/codexhost CHANGED
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karlorz/codexhost-cli-darwin-x64",
3
- "version": "0.22.0-2",
3
+ "version": "0.22.0-6",
4
4
  "description": "Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.",
5
5
  "type": "module",
6
6
  "files": [