@codexhost/cli-darwin-arm64 0.17.2 → 0.17.4

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 @codexhost/cli@0.17.2
10
+ npm install -g @codexhost/cli@0.17.4
11
11
  ```
12
12
 
13
13
  Do not install this package directly. npm selects it through the optional dependencies of `@codexhost/cli`.
@@ -1 +1 @@
1
- {"schemaVersion":1,"version":"0.17.2","distribution":"npm","target":"macos-arm64"}
1
+ {"schemaVersion":1,"version":"0.17.4","distribution":"npm","target":"macos-arm64"}
@@ -65,6 +65,12 @@ async function openRendererLocalPage(execute, url2, targets) {
65
65
  }
66
66
 
67
67
  // packages/desktop-control/src/cdp-client.ts
68
+ var CdpConnectionClosedError = class extends Error {
69
+ constructor(message) {
70
+ super(message);
71
+ this.name = "CdpConnectionClosedError";
72
+ }
73
+ };
68
74
  function cdpExceptionMessage(details, fallback) {
69
75
  const exception = details.exception;
70
76
  if (isRecord(exception) && typeof exception.description === "string" && exception.description) {
@@ -152,8 +158,14 @@ var CdpClient = class _CdpClient {
152
158
  this.#socket = socket;
153
159
  this.#commandTimeoutMs = commandTimeoutMs;
154
160
  socket.addEventListener("message", (event) => this.#onMessage(event));
155
- socket.addEventListener("error", () => this.#fail(new Error("CDP WebSocket failed")));
156
- socket.addEventListener("close", () => this.#fail(new Error("CDP WebSocket closed")));
161
+ socket.addEventListener(
162
+ "error",
163
+ () => this.#disconnect(new CdpConnectionClosedError("CDP WebSocket failed"))
164
+ );
165
+ socket.addEventListener(
166
+ "close",
167
+ () => this.#disconnect(new CdpConnectionClosedError("CDP WebSocket closed"))
168
+ );
157
169
  }
158
170
  static async connect(url2, options = {}) {
159
171
  loopbackUrl(url2, ["ws:", "wss:"]);
@@ -201,7 +213,7 @@ var CdpClient = class _CdpClient {
201
213
  };
202
214
  }
203
215
  #send(method, params, sessionId) {
204
- if (this.#closed) return Promise.reject(new Error("CDP client is closed"));
216
+ if (this.#closed) return Promise.reject(new CdpConnectionClosedError("CDP client is closed"));
205
217
  const id = this.#nextId++;
206
218
  return new Promise((resolve, reject) => {
207
219
  const timeout = setTimeout(() => {
@@ -255,9 +267,12 @@ var CdpClient = class _CdpClient {
255
267
  }
256
268
  }
257
269
  close() {
270
+ this.#disconnect(new CdpConnectionClosedError("CDP client closed"));
271
+ }
272
+ #disconnect(error51) {
258
273
  if (this.#closed) return;
259
274
  this.#closed = true;
260
- this.#fail(new Error("CDP client closed"));
275
+ this.#fail(error51);
261
276
  this.#listeners.clear();
262
277
  this.#socket.close();
263
278
  }
@@ -17738,13 +17753,15 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17738
17753
  return discovery;
17739
17754
  };
17740
17755
  if (!read()) return null;
17741
- const native = () => {
17742
- if (disposed) return null;
17743
- try {
17744
- nativeRouting ??= dependencies.nativeRouting?.() ?? null;
17745
- } catch {
17756
+ const discoverComposer = (composer) => {
17757
+ const owners = dependencies.discoverComposer(composer);
17758
+ if (!nativeRouting && (owners.managers.length || owners.registries.length)) {
17759
+ try {
17760
+ nativeRouting = dependencies.installNativeRouting();
17761
+ } catch {
17762
+ }
17746
17763
  }
17747
- return nativeRouting;
17764
+ return owners;
17748
17765
  };
17749
17766
  const connectionFor = (hostId2) => {
17750
17767
  if (!hostId2.startsWith("remote-control:")) return void 0;
@@ -17926,7 +17943,7 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17926
17943
  const routeFor = (hostId2, nativeRoute) => {
17927
17944
  if (disposed) return null;
17928
17945
  const connection = connectionFor(hostId2);
17929
- const preferred = nativeRoute === void 0 ? native()?.forHost(hostId2) : nativeRoute;
17946
+ const preferred = nativeRoute === void 0 ? nativeRouting?.forHost(hostId2) : nativeRoute;
17930
17947
  if (connection === null || preferred) {
17931
17948
  retire(hostId2);
17932
17949
  return connection === null ? null : preferred ?? null;
@@ -17953,21 +17970,25 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17953
17970
  target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
17954
17971
  }
17955
17972
  };
17956
- const composerHostId = (composer) => {
17957
- const nativeHostId = native()?.hostIdForComposer(composer);
17973
+ const composerHostId = (owners, composer) => {
17974
+ const nativeHostId = nativeRouting?.hostIdForComposer(composer);
17958
17975
  if (nativeHostId) return nativeHostId;
17959
- const hostIds = new Set(dependencies.composerHostIds(composer).hostIds);
17976
+ const hostIds = new Set((owners ?? discoverComposer(composer)).hostIds);
17960
17977
  const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
17961
17978
  return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
17962
17979
  };
17963
17980
  const routing = {
17964
17981
  knownHostIds() {
17965
17982
  if (disposed) return [];
17983
+ try {
17984
+ if (!nativeRouting) discoverComposer();
17985
+ } catch {
17986
+ }
17966
17987
  const current = read();
17967
17988
  return [
17968
17989
  .../* @__PURE__ */ new Set([
17969
17990
  ...current ? dependencies.hostIds(current) : [],
17970
- ...native()?.knownHostIds?.() ?? []
17991
+ ...nativeRouting?.knownHostIds?.() ?? []
17971
17992
  ])
17972
17993
  ];
17973
17994
  },
@@ -17977,7 +17998,7 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17977
17998
  hostIdForComposer(composer) {
17978
17999
  if (disposed) return null;
17979
18000
  try {
17980
- return composerHostId(composer);
18001
+ return composerHostId(nativeRouting ? null : discoverComposer(composer), composer);
17981
18002
  } catch {
17982
18003
  return null;
17983
18004
  }
@@ -17987,8 +18008,9 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17987
18008
  let hostId2;
17988
18009
  let preferred = null;
17989
18010
  try {
17990
- preferred = native()?.forComposer(composer) ?? null;
17991
- hostId2 = preferred?.hostId ?? composerHostId(composer);
18011
+ const owners = nativeRouting ? null : discoverComposer(composer);
18012
+ preferred = nativeRouting?.forComposer(composer) ?? null;
18013
+ hostId2 = preferred?.hostId ?? composerHostId(owners, composer);
17992
18014
  } catch {
17993
18015
  hostId2 = null;
17994
18016
  }
@@ -18071,17 +18093,14 @@ function directRendererInstaller() {
18071
18093
  findFamily: ${findRendererHostRpcFamily.toString()},
18072
18094
  resolve: ${resolveRendererHostRpc.toString()},
18073
18095
  hostIds: ${rendererHostRpcHostIds.toString()},
18074
- composerHostIds: (composer) => {
18096
+ discoverComposer: (composer) => {
18075
18097
  const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
18076
18098
  ? { querySelectorAll: () => [composer] }
18077
18099
  : (composer ?? document);
18078
18100
  return discover(source);
18079
18101
  },
18080
18102
  portPrototype: MessagePort.prototype,
18081
- nativeRouting: () => {
18082
- const native = discover(document);
18083
- return native.managers.length || native.registries.length ? installNative(false) : null;
18084
- },
18103
+ installNativeRouting: () => installNative(false),
18085
18104
  readConnection: (hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
18086
18105
  });
18087
18106
  const connected = (routing) => routing.forComposer() !== null ||
@@ -19280,6 +19299,7 @@ async function waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs
19280
19299
  if (value !== null) return validateBindingStatus(value, enabledAgents);
19281
19300
  } catch (error51) {
19282
19301
  lastError = error51;
19302
+ if (error51 instanceof CdpConnectionClosedError) throw error51;
19283
19303
  if (error51 instanceof RendererAdapterReadinessError && error51.state !== "installing") {
19284
19304
  throw error51;
19285
19305
  }
@@ -19557,6 +19577,7 @@ function parseDesktopControllerArguments(arguments_) {
19557
19577
  function isTransientRendererInstallError(error51) {
19558
19578
  let current = error51;
19559
19579
  for (let depth = 0; depth < 4; depth += 1) {
19580
+ if (current instanceof CdpConnectionClosedError) return true;
19560
19581
  const message = current instanceof Error ? current.message : String(current);
19561
19582
  if (message.includes("Execution context was destroyed") || message.includes("Promise was collected")) {
19562
19583
  return true;
@@ -22113,6 +22113,12 @@ function createLocalPageOpener(environment) {
22113
22113
  }
22114
22114
 
22115
22115
  // packages/desktop-control/dist/cdp-client.js
22116
+ var CdpConnectionClosedError = class extends Error {
22117
+ constructor(message2) {
22118
+ super(message2);
22119
+ this.name = "CdpConnectionClosedError";
22120
+ }
22121
+ };
22116
22122
  function cdpExceptionMessage(details, fallback) {
22117
22123
  const exception = details.exception;
22118
22124
  if (isRecord(exception) && typeof exception.description === "string" && exception.description) {
@@ -22207,8 +22213,8 @@ var CdpClient = class _CdpClient {
22207
22213
  this.#socket = socket;
22208
22214
  this.#commandTimeoutMs = commandTimeoutMs;
22209
22215
  socket.addEventListener("message", (event) => this.#onMessage(event));
22210
- socket.addEventListener("error", () => this.#fail(new Error("CDP WebSocket failed")));
22211
- socket.addEventListener("close", () => this.#fail(new Error("CDP WebSocket closed")));
22216
+ socket.addEventListener("error", () => this.#disconnect(new CdpConnectionClosedError("CDP WebSocket failed")));
22217
+ socket.addEventListener("close", () => this.#disconnect(new CdpConnectionClosedError("CDP WebSocket closed")));
22212
22218
  }
22213
22219
  static async connect(url2, options = {}) {
22214
22220
  loopbackUrl(url2, ["ws:", "wss:"]);
@@ -22259,7 +22265,7 @@ var CdpClient = class _CdpClient {
22259
22265
  }
22260
22266
  #send(method, params, sessionId) {
22261
22267
  if (this.#closed)
22262
- return Promise.reject(new Error("CDP client is closed"));
22268
+ return Promise.reject(new CdpConnectionClosedError("CDP client is closed"));
22263
22269
  const id2 = this.#nextId++;
22264
22270
  return new Promise((resolve, reject) => {
22265
22271
  const timeout = setTimeout(() => {
@@ -22302,10 +22308,13 @@ var CdpClient = class _CdpClient {
22302
22308
  }
22303
22309
  }
22304
22310
  close() {
22311
+ this.#disconnect(new CdpConnectionClosedError("CDP client closed"));
22312
+ }
22313
+ #disconnect(error51) {
22305
22314
  if (this.#closed)
22306
22315
  return;
22307
22316
  this.#closed = true;
22308
- this.#fail(new Error("CDP client closed"));
22317
+ this.#fail(error51);
22309
22318
  this.#listeners.clear();
22310
22319
  this.#socket.close();
22311
22320
  }
@@ -23624,14 +23633,15 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
23624
23633
  };
23625
23634
  if (!read())
23626
23635
  return null;
23627
- const native = () => {
23628
- if (disposed)
23629
- return null;
23630
- try {
23631
- nativeRouting ??= dependencies2.nativeRouting?.() ?? null;
23632
- } catch {
23636
+ const discoverComposer = (composer) => {
23637
+ const owners = dependencies2.discoverComposer(composer);
23638
+ if (!nativeRouting && (owners.managers.length || owners.registries.length)) {
23639
+ try {
23640
+ nativeRouting = dependencies2.installNativeRouting();
23641
+ } catch {
23642
+ }
23633
23643
  }
23634
- return nativeRouting;
23644
+ return owners;
23635
23645
  };
23636
23646
  const connectionFor = (hostId2) => {
23637
23647
  if (!hostId2.startsWith("remote-control:"))
@@ -23833,7 +23843,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
23833
23843
  if (disposed)
23834
23844
  return null;
23835
23845
  const connection = connectionFor(hostId2);
23836
- const preferred = nativeRoute === void 0 ? native()?.forHost(hostId2) : nativeRoute;
23846
+ const preferred = nativeRoute === void 0 ? nativeRouting?.forHost(hostId2) : nativeRoute;
23837
23847
  if (connection === null || preferred) {
23838
23848
  retire(hostId2);
23839
23849
  return connection === null ? null : preferred ?? null;
@@ -23862,11 +23872,11 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
23862
23872
  target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
23863
23873
  }
23864
23874
  };
23865
- const composerHostId = (composer) => {
23866
- const nativeHostId = native()?.hostIdForComposer(composer);
23875
+ const composerHostId = (owners, composer) => {
23876
+ const nativeHostId = nativeRouting?.hostIdForComposer(composer);
23867
23877
  if (nativeHostId)
23868
23878
  return nativeHostId;
23869
- const hostIds = new Set(dependencies2.composerHostIds(composer).hostIds);
23879
+ const hostIds = new Set((owners ?? discoverComposer(composer)).hostIds);
23870
23880
  const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
23871
23881
  return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
23872
23882
  };
@@ -23874,11 +23884,16 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
23874
23884
  knownHostIds() {
23875
23885
  if (disposed)
23876
23886
  return [];
23887
+ try {
23888
+ if (!nativeRouting)
23889
+ discoverComposer();
23890
+ } catch {
23891
+ }
23877
23892
  const current = read();
23878
23893
  return [
23879
23894
  .../* @__PURE__ */ new Set([
23880
23895
  ...current ? dependencies2.hostIds(current) : [],
23881
- ...native()?.knownHostIds?.() ?? []
23896
+ ...nativeRouting?.knownHostIds?.() ?? []
23882
23897
  ])
23883
23898
  ];
23884
23899
  },
@@ -23889,7 +23904,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
23889
23904
  if (disposed)
23890
23905
  return null;
23891
23906
  try {
23892
- return composerHostId(composer);
23907
+ return composerHostId(nativeRouting ? null : discoverComposer(composer), composer);
23893
23908
  } catch {
23894
23909
  return null;
23895
23910
  }
@@ -23900,8 +23915,9 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
23900
23915
  let hostId2;
23901
23916
  let preferred = null;
23902
23917
  try {
23903
- preferred = native()?.forComposer(composer) ?? null;
23904
- hostId2 = preferred?.hostId ?? composerHostId(composer);
23918
+ const owners = nativeRouting ? null : discoverComposer(composer);
23919
+ preferred = nativeRouting?.forComposer(composer) ?? null;
23920
+ hostId2 = preferred?.hostId ?? composerHostId(owners, composer);
23905
23921
  } catch {
23906
23922
  hostId2 = null;
23907
23923
  }
@@ -23992,17 +24008,14 @@ function directRendererInstaller() {
23992
24008
  findFamily: ${findRendererHostRpcFamily.toString()},
23993
24009
  resolve: ${resolveRendererHostRpc.toString()},
23994
24010
  hostIds: ${rendererHostRpcHostIds.toString()},
23995
- composerHostIds: (composer) => {
24011
+ discoverComposer: (composer) => {
23996
24012
  const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
23997
24013
  ? { querySelectorAll: () => [composer] }
23998
24014
  : (composer ?? document);
23999
24015
  return discover(source);
24000
24016
  },
24001
24017
  portPrototype: MessagePort.prototype,
24002
- nativeRouting: () => {
24003
- const native = discover(document);
24004
- return native.managers.length || native.registries.length ? installNative(false) : null;
24005
- },
24018
+ installNativeRouting: () => installNative(false),
24006
24019
  readConnection: (hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
24007
24020
  });
24008
24021
  const connected = (routing) => routing.forComposer() !== null ||
@@ -25181,6 +25194,8 @@ async function waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs
25181
25194
  return validateBindingStatus(value2, enabledAgents);
25182
25195
  } catch (error51) {
25183
25196
  lastError = error51;
25197
+ if (error51 instanceof CdpConnectionClosedError)
25198
+ throw error51;
25184
25199
  if (error51 instanceof RendererAdapterReadinessError && error51.state !== "installing") {
25185
25200
  throw error51;
25186
25201
  }
@@ -32617,7 +32632,6 @@ var NativeAccountObserver = class {
32617
32632
  this.#initialized = true;
32618
32633
  this.#lastGeneration = nativeGeneration ?? -1;
32619
32634
  this.#scheduleAccountUpdate();
32620
- if (nativeGeneration !== void 0) this.observe({ method: "account/updated" });
32621
32635
  }
32622
32636
  /** Called after forwarding the native frame. Identity read failure cannot alter its outcome. */
32623
32637
  observe(value2) {
@@ -47050,9 +47064,6 @@ async function prepareLocalCodex(input) {
47050
47064
  current = currentCodexAccountFromOfficialRead(response.result);
47051
47065
  return snapshot2();
47052
47066
  });
47053
- void accounts.refresh?.()?.catch(() => {
47054
- input.diagnosticOutput.write("codexhost: Codex Account identity could not be read\n");
47055
- });
47056
47067
  return {
47057
47068
  officialRuntimeScope: scope,
47058
47069
  accountControl: accounts,
package/bin/codexhost CHANGED
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codexhost/cli-darwin-arm64",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.",
5
5
  "type": "module",
6
6
  "files": [