@karlorz/codexhost-cli-win32-x64 0.14.0-4 → 0.14.0-5

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.14.0-4
10
+ npm install -g @karlorz/codexhost-cli@0.14.0-5
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.14.0-4","distribution":"npm","target":"windows-x64"}
1
+ {"schemaVersion":1,"version":"0.14.0-5","distribution":"npm","target":"windows-x64"}
@@ -16787,12 +16787,46 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16787
16787
  function isRecord2(value) {
16788
16788
  return value !== null && typeof value === "object" && !Array.isArray(value);
16789
16789
  }
16790
- function installRendererExternalQueue(target) {
16791
- if (!isRecord2(target) || typeof target.getTurnCoordinator !== "function" || typeof target.getConversation !== "function") {
16792
- return null;
16793
- }
16794
- if (typeof target.getStreamRole === "function") return null;
16795
- const coordinator = target.getTurnCoordinator();
16790
+ function notificationTarget(manager) {
16791
+ if (typeof manager.addNotificationCallback === "function") {
16792
+ return manager;
16793
+ }
16794
+ const nested = manager.requestClient;
16795
+ return isRecord2(nested) && typeof nested.addNotificationCallback === "function" ? nested : null;
16796
+ }
16797
+ function notificationParams(notification) {
16798
+ if (!isRecord2(notification)) return null;
16799
+ return isRecord2(notification.params) ? notification.params : notification;
16800
+ }
16801
+ function notificationThreadId(notification) {
16802
+ const params = notificationParams(notification);
16803
+ if (!params) return null;
16804
+ if (typeof params.threadId === "string" && params.threadId) return params.threadId;
16805
+ if (typeof params.conversationId === "string" && params.conversationId)
16806
+ return params.conversationId;
16807
+ return null;
16808
+ }
16809
+ function turnStatus(notification) {
16810
+ const params = notificationParams(notification);
16811
+ if (!params) return null;
16812
+ if (typeof params.status === "string") return params.status;
16813
+ const turn = params.turn;
16814
+ return isRecord2(turn) && typeof turn.status === "string" ? turn.status : null;
16815
+ }
16816
+ function isExternalConversation(conversation, threadId) {
16817
+ return isRecord2(conversation) && conversation.id === threadId && conversation.modelProvider === "codexhost";
16818
+ }
16819
+ function firstQueuedItemId(items) {
16820
+ if (!Array.isArray(items)) return null;
16821
+ for (const item of items) {
16822
+ if (!isRecord2(item) || item.pausedReason != null) continue;
16823
+ if (typeof item.id === "string" && item.id) return item.id;
16824
+ }
16825
+ return null;
16826
+ }
16827
+ function installLocalQueueGate(target) {
16828
+ const getTurnCoordinator = target.getTurnCoordinator;
16829
+ const coordinator = getTurnCoordinator.call(target);
16796
16830
  const queue = isRecord2(coordinator) ? coordinator.serverQueue : null;
16797
16831
  if (!isRecord2(queue) || typeof queue.isEnabled !== "function") return null;
16798
16832
  const descriptor = Object.getOwnPropertyDescriptor(queue, "isEnabled");
@@ -16801,13 +16835,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16801
16835
  const getConversation = target.getConversation;
16802
16836
  const isEnabled = (...args) => {
16803
16837
  const threadId = args[0];
16804
- if (typeof threadId === "string") {
16805
- const conversation = getConversation.call(target, threadId);
16806
- if (isRecord2(conversation) && conversation.id === threadId && // Reserved transport marker from externalThreadValue, retained by
16807
- // Desktop in both newly created and hydrated conversation metadata.
16808
- conversation.modelProvider === "codexhost") {
16809
- return false;
16810
- }
16838
+ if (typeof threadId === "string" && isExternalConversation(getConversation.call(target, threadId), threadId)) {
16839
+ return false;
16811
16840
  }
16812
16841
  return original.apply(queue, args);
16813
16842
  };
@@ -16816,6 +16845,90 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16816
16845
  if (queue.isEnabled === isEnabled) Object.defineProperty(queue, "isEnabled", descriptor);
16817
16846
  };
16818
16847
  }
16848
+ function installServerQueueDrain(target) {
16849
+ if (typeof target.sendRequest !== "function") return null;
16850
+ const notifications = notificationTarget(target);
16851
+ if (!notifications) return null;
16852
+ const getConversation = target.getConversation;
16853
+ const getTurnCoordinator = target.getTurnCoordinator;
16854
+ const getStreamRole = target.getStreamRole;
16855
+ const sendRequest = target.sendRequest;
16856
+ const draining = /* @__PURE__ */ new Set();
16857
+ let disposed = false;
16858
+ const isExternalOwner = (threadId) => {
16859
+ if (!isExternalConversation(getConversation.call(target, threadId), threadId)) return false;
16860
+ const role = getStreamRole.call(target, threadId);
16861
+ return !(isRecord2(role) && role.role === "follower");
16862
+ };
16863
+ const isIdle = (threadId, coordinator) => {
16864
+ const options = isRecord2(coordinator) ? coordinator.options : null;
16865
+ const host = isRecord2(options) ? options.submissionHost : null;
16866
+ if (isRecord2(host) && typeof host.getActiveTurnId === "function" && typeof host.hasPendingTurnStart === "function") {
16867
+ return host.getActiveTurnId.call(host, threadId) == null && host.hasPendingTurnStart.call(host, threadId) !== true;
16868
+ }
16869
+ const conversation = getConversation.call(target, threadId);
16870
+ return isRecord2(conversation) && isRecord2(conversation.threadRuntimeStatus) && conversation.threadRuntimeStatus.type === "idle";
16871
+ };
16872
+ const queuedSubmissionId = (coordinator, threadId) => {
16873
+ if (isRecord2(coordinator) && typeof coordinator.readMessages === "function") {
16874
+ const messages = coordinator.readMessages.call(coordinator, threadId);
16875
+ if (Array.isArray(messages)) return firstQueuedItemId(messages);
16876
+ }
16877
+ const queue = isRecord2(coordinator) ? coordinator.serverQueue : null;
16878
+ if (isRecord2(queue) && typeof queue.read === "function") {
16879
+ return firstQueuedItemId(queue.read.call(queue, threadId));
16880
+ }
16881
+ return null;
16882
+ };
16883
+ const drain = (threadId) => {
16884
+ if (disposed || draining.has(threadId) || !isExternalOwner(threadId)) return;
16885
+ const coordinator = getTurnCoordinator.call(target);
16886
+ if (!isIdle(threadId, coordinator)) return;
16887
+ const queuedSubmissionIdValue = queuedSubmissionId(coordinator, threadId);
16888
+ if (!queuedSubmissionIdValue) return;
16889
+ draining.add(threadId);
16890
+ Promise.resolve(
16891
+ sendRequest.call(target, "thread/queue/start", {
16892
+ threadId,
16893
+ queuedSubmissionId: queuedSubmissionIdValue
16894
+ })
16895
+ ).catch((error51) => {
16896
+ const message = error51 instanceof Error ? error51.message : String(error51);
16897
+ if (message.includes("Queued follow-up was not found")) return;
16898
+ console.error("codexhost could not start the queued follow-up", error51);
16899
+ }).finally(() => {
16900
+ draining.delete(threadId);
16901
+ });
16902
+ };
16903
+ const onNotification = (notification) => {
16904
+ if (disposed) return;
16905
+ const method = isRecord2(notification) && typeof notification.method === "string" ? notification.method : null;
16906
+ const threadId = notificationThreadId(notification);
16907
+ if (!threadId) return;
16908
+ if (method === "turn/completed") {
16909
+ if (turnStatus(notification) === "interrupted") return;
16910
+ drain(threadId);
16911
+ return;
16912
+ }
16913
+ if (method === "thread/queue/changed") drain(threadId);
16914
+ };
16915
+ const unsubscribe = notifications.addNotificationCallback(
16916
+ ["turn/completed", "thread/queue/changed"],
16917
+ onNotification
16918
+ );
16919
+ return () => {
16920
+ disposed = true;
16921
+ draining.clear();
16922
+ if (typeof unsubscribe === "function") unsubscribe();
16923
+ };
16924
+ }
16925
+ function installRendererExternalQueue(target) {
16926
+ if (!isRecord2(target) || typeof target.getTurnCoordinator !== "function" || typeof target.getConversation !== "function") {
16927
+ return null;
16928
+ }
16929
+ if (typeof target.getStreamRole === "function") return installServerQueueDrain(target);
16930
+ return installLocalQueueGate(target);
16931
+ }
16819
16932
 
16820
16933
  // src/renderer-native-thread.ts
16821
16934
  function isRecord3(value) {
@@ -17203,7 +17316,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17203
17316
  if (BLOCKED_METHODS.has(method)) return true;
17204
17317
  return method.startsWith("turn/") || method.startsWith("item/");
17205
17318
  }
17206
- function notificationThreadId(params) {
17319
+ function notificationThreadId2(params) {
17207
17320
  if (!isRecord5(params)) return void 0;
17208
17321
  if (typeof params.threadId === "string" && params.threadId.length > 0) return params.threadId;
17209
17322
  const thread = params.thread;
@@ -17227,7 +17340,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17227
17340
  const message = event.data;
17228
17341
  if (!isRecord5(message) || message.type !== "mcp-notification") return;
17229
17342
  if (typeof message.method !== "string") return;
17230
- const threadId = notificationThreadId(message.params);
17343
+ const threadId = notificationThreadId2(message.params);
17231
17344
  if (message.method === "thread/realtime/started" && threadId) {
17232
17345
  voiceThreadIds.add(threadId);
17233
17346
  return;
@@ -26765,12 +26765,46 @@ Codex Fast mode prioritizes requests and may increase usage.`
26765
26765
  function isRecord8(value) {
26766
26766
  return value !== null && typeof value === "object" && !Array.isArray(value);
26767
26767
  }
26768
- function installRendererExternalQueue(target) {
26769
- if (!isRecord8(target) || typeof target.getTurnCoordinator !== "function" || typeof target.getConversation !== "function") {
26770
- return null;
26768
+ function notificationTarget2(manager) {
26769
+ if (typeof manager.addNotificationCallback === "function") {
26770
+ return manager;
26771
26771
  }
26772
- if (typeof target.getStreamRole === "function") return null;
26773
- const coordinator = target.getTurnCoordinator();
26772
+ const nested = manager.requestClient;
26773
+ return isRecord8(nested) && typeof nested.addNotificationCallback === "function" ? nested : null;
26774
+ }
26775
+ function notificationParams(notification) {
26776
+ if (!isRecord8(notification)) return null;
26777
+ return isRecord8(notification.params) ? notification.params : notification;
26778
+ }
26779
+ function notificationThreadId(notification) {
26780
+ const params = notificationParams(notification);
26781
+ if (!params) return null;
26782
+ if (typeof params.threadId === "string" && params.threadId) return params.threadId;
26783
+ if (typeof params.conversationId === "string" && params.conversationId)
26784
+ return params.conversationId;
26785
+ return null;
26786
+ }
26787
+ function turnStatus(notification) {
26788
+ const params = notificationParams(notification);
26789
+ if (!params) return null;
26790
+ if (typeof params.status === "string") return params.status;
26791
+ const turn = params.turn;
26792
+ return isRecord8(turn) && typeof turn.status === "string" ? turn.status : null;
26793
+ }
26794
+ function isExternalConversation(conversation, threadId) {
26795
+ return isRecord8(conversation) && conversation.id === threadId && conversation.modelProvider === "codexhost";
26796
+ }
26797
+ function firstQueuedItemId(items) {
26798
+ if (!Array.isArray(items)) return null;
26799
+ for (const item of items) {
26800
+ if (!isRecord8(item) || item.pausedReason != null) continue;
26801
+ if (typeof item.id === "string" && item.id) return item.id;
26802
+ }
26803
+ return null;
26804
+ }
26805
+ function installLocalQueueGate(target) {
26806
+ const getTurnCoordinator = target.getTurnCoordinator;
26807
+ const coordinator = getTurnCoordinator.call(target);
26774
26808
  const queue = isRecord8(coordinator) ? coordinator.serverQueue : null;
26775
26809
  if (!isRecord8(queue) || typeof queue.isEnabled !== "function") return null;
26776
26810
  const descriptor = Object.getOwnPropertyDescriptor(queue, "isEnabled");
@@ -26779,13 +26813,8 @@ Codex Fast mode prioritizes requests and may increase usage.`
26779
26813
  const getConversation = target.getConversation;
26780
26814
  const isEnabled = (...args) => {
26781
26815
  const threadId = args[0];
26782
- if (typeof threadId === "string") {
26783
- const conversation = getConversation.call(target, threadId);
26784
- if (isRecord8(conversation) && conversation.id === threadId && // Reserved transport marker from externalThreadValue, retained by
26785
- // Desktop in both newly created and hydrated conversation metadata.
26786
- conversation.modelProvider === "codexhost") {
26787
- return false;
26788
- }
26816
+ if (typeof threadId === "string" && isExternalConversation(getConversation.call(target, threadId), threadId)) {
26817
+ return false;
26789
26818
  }
26790
26819
  return original.apply(queue, args);
26791
26820
  };
@@ -26794,6 +26823,90 @@ Codex Fast mode prioritizes requests and may increase usage.`
26794
26823
  if (queue.isEnabled === isEnabled) Object.defineProperty(queue, "isEnabled", descriptor);
26795
26824
  };
26796
26825
  }
26826
+ function installServerQueueDrain(target) {
26827
+ if (typeof target.sendRequest !== "function") return null;
26828
+ const notifications = notificationTarget2(target);
26829
+ if (!notifications) return null;
26830
+ const getConversation = target.getConversation;
26831
+ const getTurnCoordinator = target.getTurnCoordinator;
26832
+ const getStreamRole = target.getStreamRole;
26833
+ const sendRequest = target.sendRequest;
26834
+ const draining = /* @__PURE__ */ new Set();
26835
+ let disposed = false;
26836
+ const isExternalOwner = (threadId) => {
26837
+ if (!isExternalConversation(getConversation.call(target, threadId), threadId)) return false;
26838
+ const role = getStreamRole.call(target, threadId);
26839
+ return !(isRecord8(role) && role.role === "follower");
26840
+ };
26841
+ const isIdle = (threadId, coordinator) => {
26842
+ const options = isRecord8(coordinator) ? coordinator.options : null;
26843
+ const host = isRecord8(options) ? options.submissionHost : null;
26844
+ if (isRecord8(host) && typeof host.getActiveTurnId === "function" && typeof host.hasPendingTurnStart === "function") {
26845
+ return host.getActiveTurnId.call(host, threadId) == null && host.hasPendingTurnStart.call(host, threadId) !== true;
26846
+ }
26847
+ const conversation = getConversation.call(target, threadId);
26848
+ return isRecord8(conversation) && isRecord8(conversation.threadRuntimeStatus) && conversation.threadRuntimeStatus.type === "idle";
26849
+ };
26850
+ const queuedSubmissionId = (coordinator, threadId) => {
26851
+ if (isRecord8(coordinator) && typeof coordinator.readMessages === "function") {
26852
+ const messages = coordinator.readMessages.call(coordinator, threadId);
26853
+ if (Array.isArray(messages)) return firstQueuedItemId(messages);
26854
+ }
26855
+ const queue = isRecord8(coordinator) ? coordinator.serverQueue : null;
26856
+ if (isRecord8(queue) && typeof queue.read === "function") {
26857
+ return firstQueuedItemId(queue.read.call(queue, threadId));
26858
+ }
26859
+ return null;
26860
+ };
26861
+ const drain = (threadId) => {
26862
+ if (disposed || draining.has(threadId) || !isExternalOwner(threadId)) return;
26863
+ const coordinator = getTurnCoordinator.call(target);
26864
+ if (!isIdle(threadId, coordinator)) return;
26865
+ const queuedSubmissionIdValue = queuedSubmissionId(coordinator, threadId);
26866
+ if (!queuedSubmissionIdValue) return;
26867
+ draining.add(threadId);
26868
+ Promise.resolve(
26869
+ sendRequest.call(target, "thread/queue/start", {
26870
+ threadId,
26871
+ queuedSubmissionId: queuedSubmissionIdValue
26872
+ })
26873
+ ).catch((error51) => {
26874
+ const message2 = error51 instanceof Error ? error51.message : String(error51);
26875
+ if (message2.includes("Queued follow-up was not found")) return;
26876
+ console.error("codexhost could not start the queued follow-up", error51);
26877
+ }).finally(() => {
26878
+ draining.delete(threadId);
26879
+ });
26880
+ };
26881
+ const onNotification = (notification) => {
26882
+ if (disposed) return;
26883
+ const method = isRecord8(notification) && typeof notification.method === "string" ? notification.method : null;
26884
+ const threadId = notificationThreadId(notification);
26885
+ if (!threadId) return;
26886
+ if (method === "turn/completed") {
26887
+ if (turnStatus(notification) === "interrupted") return;
26888
+ drain(threadId);
26889
+ return;
26890
+ }
26891
+ if (method === "thread/queue/changed") drain(threadId);
26892
+ };
26893
+ const unsubscribe = notifications.addNotificationCallback(
26894
+ ["turn/completed", "thread/queue/changed"],
26895
+ onNotification
26896
+ );
26897
+ return () => {
26898
+ disposed = true;
26899
+ draining.clear();
26900
+ if (typeof unsubscribe === "function") unsubscribe();
26901
+ };
26902
+ }
26903
+ function installRendererExternalQueue(target) {
26904
+ if (!isRecord8(target) || typeof target.getTurnCoordinator !== "function" || typeof target.getConversation !== "function") {
26905
+ return null;
26906
+ }
26907
+ if (typeof target.getStreamRole === "function") return installServerQueueDrain(target);
26908
+ return installLocalQueueGate(target);
26909
+ }
26797
26910
 
26798
26911
  // src/renderer-external-steering.ts
26799
26912
  var THREAD_STEERING_INSPECT_METHOD = "codexhost/thread/steering/inspect";
package/bin/codexhost.exe CHANGED
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karlorz/codexhost-cli-win32-x64",
3
- "version": "0.14.0-4",
3
+ "version": "0.14.0-5",
4
4
  "description": "Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.",
5
5
  "type": "module",
6
6
  "files": [