@codexhost/cli-darwin-arm64 0.17.1 → 0.17.3

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.1
10
+ npm install -g @codexhost/cli@0.17.3
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.1","distribution":"npm","target":"macos-arm64"}
1
+ {"schemaVersion":1,"version":"0.17.3","distribution":"npm","target":"macos-arm64"}
@@ -16381,6 +16381,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
16381
16381
  /** The text about to be steered; a Harness command always stops and restarts. */
16382
16382
  text: external_exports.string().optional()
16383
16383
  }).strict();
16384
+ var threadSteeringContextSchema = external_exports.object({
16385
+ kind: external_exports.literal("application"),
16386
+ value: external_exports.string().transform((text, context) => {
16387
+ try {
16388
+ return JSON.parse(text);
16389
+ } catch {
16390
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
16391
+ return external_exports.NEVER;
16392
+ }
16393
+ }).pipe(external_exports.object({
16394
+ expectedTurnId: hostTurnIdSchema,
16395
+ clientUserMessageId: external_exports.string().min(1),
16396
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
16397
+ }).strict())
16398
+ }).strict().transform((context) => context.value);
16384
16399
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
16385
16400
  var threadSteeringInspectResultSchema = external_exports.object({
16386
16401
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15602,6 +15602,21 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15602
15602
  /** The text about to be steered; a Harness command always stops and restarts. */
15603
15603
  text: external_exports.string().optional()
15604
15604
  }).strict();
15605
+ var threadSteeringContextSchema = external_exports.object({
15606
+ kind: external_exports.literal("application"),
15607
+ value: external_exports.string().transform((text, context) => {
15608
+ try {
15609
+ return JSON.parse(text);
15610
+ } catch {
15611
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15612
+ return external_exports.NEVER;
15613
+ }
15614
+ }).pipe(external_exports.object({
15615
+ expectedTurnId: hostTurnIdSchema,
15616
+ clientUserMessageId: external_exports.string().min(1),
15617
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15618
+ }).strict())
15619
+ }).strict().transform((context) => context.value);
15605
15620
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15606
15621
  var threadSteeringInspectResultSchema = external_exports.object({
15607
15622
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -15780,6 +15780,21 @@ var threadSteeringInspectParamsSchema = external_exports.object({
15780
15780
  /** The text about to be steered; a Harness command always stops and restarts. */
15781
15781
  text: external_exports.string().optional()
15782
15782
  }).strict();
15783
+ var threadSteeringContextSchema = external_exports.object({
15784
+ kind: external_exports.literal("application"),
15785
+ value: external_exports.string().transform((text, context) => {
15786
+ try {
15787
+ return JSON.parse(text);
15788
+ } catch {
15789
+ context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
15790
+ return external_exports.NEVER;
15791
+ }
15792
+ }).pipe(external_exports.object({
15793
+ expectedTurnId: hostTurnIdSchema,
15794
+ clientUserMessageId: external_exports.string().min(1),
15795
+ delivery: external_exports.enum(["newTurn", "activeTurn"])
15796
+ }).strict())
15797
+ }).strict().transform((context) => context.value);
15783
15798
  var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
15784
15799
  var threadSteeringInspectResultSchema = external_exports.object({
15785
15800
  delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
@@ -17663,7 +17678,8 @@ function findRendererHostRpcFamily(store) {
17663
17678
  if (!record3(definition) || definition.kind !== "signal-family") continue;
17664
17679
  if (!record3(members) || typeof members.get !== "function") continue;
17665
17680
  for (const [hostId2, member] of members) {
17666
- if (typeof hostId2 !== "string" || !record3(member)) continue;
17681
+ if (typeof hostId2 !== "string" || !/^(?:local$|durable$|remote[-:])/u.test(hostId2)) continue;
17682
+ if (!record3(member)) continue;
17667
17683
  const signal = member.value;
17668
17684
  if (!record3(signal) || typeof signal.get !== "function") continue;
17669
17685
  let value;
@@ -17714,20 +17730,23 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17714
17730
  if (disposed) return null;
17715
17731
  try {
17716
17732
  const store = dependencies.findStore(root);
17717
- discovery = store ? dependencies.findFamily(store) : null;
17733
+ const bound = store && discovery?.store === store ? [...store.familyBindings.values()].includes(discovery.family) : false;
17734
+ if (!bound) discovery = store ? dependencies.findFamily(store) : null;
17718
17735
  } catch {
17719
17736
  discovery = null;
17720
17737
  }
17721
17738
  return discovery;
17722
17739
  };
17723
17740
  if (!read()) return null;
17724
- const native = () => {
17725
- if (disposed) return null;
17726
- try {
17727
- nativeRouting ??= dependencies.nativeRouting?.() ?? null;
17728
- } catch {
17741
+ const discoverComposer = (composer) => {
17742
+ const owners = dependencies.discoverComposer(composer);
17743
+ if (!nativeRouting && (owners.managers.length || owners.registries.length)) {
17744
+ try {
17745
+ nativeRouting = dependencies.installNativeRouting();
17746
+ } catch {
17747
+ }
17729
17748
  }
17730
- return nativeRouting;
17749
+ return owners;
17731
17750
  };
17732
17751
  const connectionFor = (hostId2) => {
17733
17752
  if (!hostId2.startsWith("remote-control:")) return void 0;
@@ -17909,7 +17928,7 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17909
17928
  const routeFor = (hostId2, nativeRoute) => {
17910
17929
  if (disposed) return null;
17911
17930
  const connection = connectionFor(hostId2);
17912
- const preferred = nativeRoute === void 0 ? native()?.forHost(hostId2) : nativeRoute;
17931
+ const preferred = nativeRoute === void 0 ? nativeRouting?.forHost(hostId2) : nativeRoute;
17913
17932
  if (connection === null || preferred) {
17914
17933
  retire(hostId2);
17915
17934
  return connection === null ? null : preferred ?? null;
@@ -17936,21 +17955,25 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17936
17955
  target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
17937
17956
  }
17938
17957
  };
17939
- const composerHostId = (composer) => {
17940
- const nativeHostId = native()?.hostIdForComposer(composer);
17958
+ const composerHostId = (owners, composer) => {
17959
+ const nativeHostId = nativeRouting?.hostIdForComposer(composer);
17941
17960
  if (nativeHostId) return nativeHostId;
17942
- const hostIds = new Set(dependencies.composerHostIds(composer).hostIds);
17961
+ const hostIds = new Set((owners ?? discoverComposer(composer)).hostIds);
17943
17962
  const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
17944
17963
  return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
17945
17964
  };
17946
17965
  const routing = {
17947
17966
  knownHostIds() {
17948
17967
  if (disposed) return [];
17968
+ try {
17969
+ if (!nativeRouting) discoverComposer();
17970
+ } catch {
17971
+ }
17949
17972
  const current = read();
17950
17973
  return [
17951
17974
  .../* @__PURE__ */ new Set([
17952
17975
  ...current ? dependencies.hostIds(current) : [],
17953
- ...native()?.knownHostIds?.() ?? []
17976
+ ...nativeRouting?.knownHostIds?.() ?? []
17954
17977
  ])
17955
17978
  ];
17956
17979
  },
@@ -17960,7 +17983,7 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17960
17983
  hostIdForComposer(composer) {
17961
17984
  if (disposed) return null;
17962
17985
  try {
17963
- return composerHostId(composer);
17986
+ return composerHostId(nativeRouting ? null : discoverComposer(composer), composer);
17964
17987
  } catch {
17965
17988
  return null;
17966
17989
  }
@@ -17970,8 +17993,9 @@ function installRendererHostRpcRouting(root, target, dependencies) {
17970
17993
  let hostId2;
17971
17994
  let preferred = null;
17972
17995
  try {
17973
- preferred = native()?.forComposer(composer) ?? null;
17974
- hostId2 = preferred?.hostId ?? composerHostId(composer);
17996
+ const owners = nativeRouting ? null : discoverComposer(composer);
17997
+ preferred = nativeRouting?.forComposer(composer) ?? null;
17998
+ hostId2 = preferred?.hostId ?? composerHostId(owners, composer);
17975
17999
  } catch {
17976
18000
  hostId2 = null;
17977
18001
  }
@@ -18054,17 +18078,14 @@ function directRendererInstaller() {
18054
18078
  findFamily: ${findRendererHostRpcFamily.toString()},
18055
18079
  resolve: ${resolveRendererHostRpc.toString()},
18056
18080
  hostIds: ${rendererHostRpcHostIds.toString()},
18057
- composerHostIds: (composer) => {
18081
+ discoverComposer: (composer) => {
18058
18082
  const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
18059
18083
  ? { querySelectorAll: () => [composer] }
18060
18084
  : (composer ?? document);
18061
18085
  return discover(source);
18062
18086
  },
18063
18087
  portPrototype: MessagePort.prototype,
18064
- nativeRouting: () => {
18065
- const native = discover(document);
18066
- return native.managers.length || native.registries.length ? installNative(false) : null;
18067
- },
18088
+ installNativeRouting: () => installNative(false),
18068
18089
  readConnection: (hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
18069
18090
  });
18070
18091
  const connected = (routing) => routing.forComposer() !== null ||
@@ -19019,6 +19040,117 @@ async function installNativeRpcRemoteControlDirect(renderer) {
19019
19040
  }
19020
19041
  }
19021
19042
 
19043
+ // packages/desktop-control/src/renderer-rpc-steering.ts
19044
+ var RETRY_BASE_MS = 5e3;
19045
+ var RETRY_MAX_MS = 3e5;
19046
+ var retries = /* @__PURE__ */ new WeakMap();
19047
+ async function installRendererRpcSteeringDirect(client, now = Date.now) {
19048
+ try {
19049
+ const needed = await client.evaluate(`(() => {
19050
+ const steering = window.__codexhostRpcSteeringV1;
19051
+ if (steering && steering.controller.forHost === steering.forHost) return false;
19052
+ steering?.release();
19053
+ const routing=window.__codexhostHostRoutingV1;
19054
+ return ['local', ...(routing?.knownHostIds?.() ?? [])].some(id => routing?.forHost(id)?.manager.kind === 'main-process-rpc');
19055
+ })()`);
19056
+ if (!needed) return false;
19057
+ const retry = retries.get(client);
19058
+ if (retry && now() < retry.nextAt) return false;
19059
+ try {
19060
+ await discoverAndInstall(client);
19061
+ retries.delete(client);
19062
+ return true;
19063
+ } catch (error51) {
19064
+ const attempts = (retry?.attempts ?? 0) + 1;
19065
+ const delay = Math.min(RETRY_BASE_MS * 2 ** (attempts - 1), RETRY_MAX_MS);
19066
+ retries.set(client, { attempts, nextAt: now() + delay });
19067
+ console.error(
19068
+ `codexhost native steering discovery failed (attempt ${attempts}):`,
19069
+ error51 instanceof Error ? error51.message : String(error51)
19070
+ );
19071
+ return false;
19072
+ }
19073
+ } catch {
19074
+ return false;
19075
+ }
19076
+ }
19077
+ async function discoverAndInstall(client) {
19078
+ const group = `codexhost-rpc-steering-${crypto.randomUUID()}`;
19079
+ const command = (method, params) => client.command(method, params);
19080
+ const properties = (objectId) => command("Runtime.getProperties", { objectId, ownProperties: true });
19081
+ const call = (objectId, functionDeclaration, args = []) => command("Runtime.callFunctionOn", {
19082
+ objectId,
19083
+ functionDeclaration,
19084
+ arguments: args,
19085
+ objectGroup: group,
19086
+ returnByValue: true
19087
+ });
19088
+ try {
19089
+ const proto = await command("Runtime.evaluate", {
19090
+ expression: "Object.getPrototypeOf(async function(){})",
19091
+ objectGroup: group
19092
+ });
19093
+ if (!proto.result.objectId) throw new Error("Native RPC steering discovery is unavailable");
19094
+ const objects = await command("Runtime.queryObjects", {
19095
+ prototypeObjectId: proto.result.objectId,
19096
+ objectGroup: group
19097
+ });
19098
+ if (!objects.objects.objectId) throw new Error("Native RPC steering discovery is unavailable");
19099
+ const filtered = await command("Runtime.callFunctionOn", {
19100
+ objectId: objects.objects.objectId,
19101
+ functionDeclaration: 'function(){return this.filter(fn=>fn.name==="collectAppStateSnapshot"&&String(fn).includes("collectSnapshot")).slice(0,9)}',
19102
+ objectGroup: group
19103
+ });
19104
+ if (!filtered.result.objectId) throw new Error("Native RPC Controller is unavailable");
19105
+ const snapshots = (await properties(filtered.result.objectId)).result.flatMap(
19106
+ (entry) => entry.value?.type === "function" && entry.value.objectId ? [entry.value.objectId] : []
19107
+ );
19108
+ if (snapshots.length > 8) throw new Error("Native RPC Controller is ambiguous");
19109
+ const controllers = [];
19110
+ for (const snapshot of snapshots) {
19111
+ const scopes = (await properties(snapshot)).internalProperties?.find(
19112
+ (entry) => entry.name === "[[Scopes]]"
19113
+ )?.value?.objectId;
19114
+ if (!scopes) continue;
19115
+ for (const scope of (await properties(scopes)).result) {
19116
+ if (!scope.value?.objectId || !scope.value.description?.startsWith("Closure")) continue;
19117
+ const bindings = (await properties(scope.value.objectId)).result;
19118
+ const owners = [];
19119
+ let rootScope;
19120
+ for (const binding of bindings) {
19121
+ if (binding.value?.type !== "object" || !binding.value.objectId) continue;
19122
+ const id = binding.value.objectId;
19123
+ const result2 = await call(
19124
+ id,
19125
+ `function(){return (${nativeRpcObjectShape.toString()})(this)}`
19126
+ );
19127
+ const shape = result2.result.value;
19128
+ if (shape?.scope) rootScope = id;
19129
+ if (shape?.controller && (await call(id, "function(fn){return this.collectAppStateSnapshot===fn}", [
19130
+ { objectId: snapshot }
19131
+ ])).result.value === true)
19132
+ owners.push(id);
19133
+ }
19134
+ if (owners.length !== 1 || !rootScope) continue;
19135
+ const root = await call(
19136
+ rootScope,
19137
+ `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}`
19138
+ );
19139
+ if (root.result.value === true) controllers.push(owners[0]);
19140
+ }
19141
+ }
19142
+ if (controllers.length !== 1) throw new Error("Native RPC Controller is missing or ambiguous");
19143
+ const result = await call(
19144
+ controllers[0],
19145
+ "function(){return window.__codexhostInstallRpcSteeringV1?.(this) === true}"
19146
+ );
19147
+ if (result.exceptionDetails || result.result.value !== true)
19148
+ throw new Error("Native RPC steering installation failed");
19149
+ } finally {
19150
+ await client.command("Runtime.releaseObjectGroup", { objectGroup: group }).catch(() => void 0);
19151
+ }
19152
+ }
19153
+
19022
19154
  // packages/desktop-control/src/renderer-cdp-control-session.ts
19023
19155
  function isRecord2(value) {
19024
19156
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -19279,6 +19411,7 @@ var defaultOperations = {
19279
19411
  async installDraftPrewarmPolicy(renderer) {
19280
19412
  const status = await installRendererDraftPrewarmPolicyDirect(renderer);
19281
19413
  await installNativeRpcRemoteControlDirect(renderer);
19414
+ await installRendererRpcSteeringDirect(renderer);
19282
19415
  return status;
19283
19416
  }
19284
19417
  };