@codexhost/cli-darwin-x64 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +26 -6
  4. package/app/console-web.js +34 -7
  5. package/app/desktop-controller.mjs +162 -51
  6. package/app/host-runtime.mjs +35562 -29076
  7. package/app/plugins/antigravity/assets/icon.svg +1 -1
  8. package/app/plugins/antigravity/plugin.mjs +1112 -822
  9. package/app/plugins/claude-code/plugin.mjs +152 -28
  10. package/app/plugins/codebuddy/plugin.mjs +35 -6
  11. package/app/plugins/codex-usage/plugin.mjs +35 -6
  12. package/app/plugins/copilot/plugin.mjs +27 -6
  13. package/app/plugins/cursor-cli/plugin.mjs +27 -6
  14. package/app/plugins/deepseek-harness/plugin.mjs +52 -11
  15. package/app/plugins/devin/plugin.mjs +27 -6
  16. package/app/plugins/grok/plugin.mjs +63 -15
  17. package/app/plugins/hermes/plugin.mjs +27 -6
  18. package/app/plugins/kimi-code/plugin.mjs +52 -16
  19. package/app/plugins/kiro-cli/plugin.mjs +27 -6
  20. package/app/plugins/omp/plugin.mjs +35 -6
  21. package/app/plugins/opencode/plugin.mjs +53 -15
  22. package/app/plugins/pi/plugin.mjs +35 -6
  23. package/app/plugins/qoder/plugin.mjs +42 -6
  24. package/app/plugins/qoder-cn/plugin.mjs +42 -6
  25. package/app/plugins/qwen-code/plugin.mjs +27 -6
  26. package/app/plugins/workbuddy/plugin.mjs +35 -6
  27. package/app/plugins/zcode/plugin.mjs +35 -6
  28. package/app/renderer-extension.js +26 -6
  29. package/app/web/assets/{index-D85gPBbQ.js → index-BdmZfTRW.js} +62 -62
  30. package/app/web/assets/{index-D6-hvggd.css → index-DJW4bmyx.css} +1 -1
  31. package/app/web/codexhost-settings.js +34 -7
  32. package/app/web/index.html +2 -2
  33. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
  34. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +3 -3
  35. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +68 -68
  36. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +6 -6
  37. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +22 -22
  38. package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
  39. package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
  40. package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
  41. package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
  42. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +1 -1
  43. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  44. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +1 -1
  45. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +2 -2
  46. package/app/web-modules/server.mjs +1012 -667
  47. package/bin/codexhost +0 -0
  48. package/libexec/codexhost-shim +0 -0
  49. package/libexec/codexhost-updater +0 -0
  50. package/package.json +1 -1
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.20.0
10
+ npm install -g @codexhost/cli@0.21.0
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.20.0","distribution":"npm","target":"macos-x64"}
1
+ {"schemaVersion":1,"version":"0.21.0","distribution":"npm","target":"macos-x64"}
@@ -15621,7 +15621,7 @@ var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonneg
15621
15621
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
15622
15622
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
15623
15623
  var usageOutputTimingSchema = external_exports.object({
15624
- version: external_exports.literal(3).optional(),
15624
+ version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
15625
15625
  requestId: external_exports.string().min(1),
15626
15626
  turnId: external_exports.string().min(1).max(1024),
15627
15627
  outputTokens: nonNegativeSafeIntegerSchema,
@@ -15629,16 +15629,16 @@ var usageOutputTimingSchema = external_exports.object({
15629
15629
  completedAtMs: nonNegativeSafeIntegerSchema
15630
15630
  }).strict().refine((value) => value.completedAtMs > value.startedAtMs);
15631
15631
  var usageMeasurementSchema = external_exports.object({
15632
- version: external_exports.union([external_exports.literal(2), external_exports.literal(3)]).optional(),
15632
+ version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
15633
15633
  value: finiteNonNegativeNumberSchema,
15634
15634
  turnId: external_exports.string().min(1).max(1024),
15635
15635
  at: nonNegativeSafeIntegerSchema
15636
15636
  }).strict();
15637
15637
  var usageMeasurementsSchema = external_exports.object({
15638
- // Unversioned intervals can omit hidden thinking time; do not restore them into averages.
15639
- outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 3)).optional(),
15638
+ // Older intervals can omit hidden thinking time; do not restore them into averages.
15639
+ outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
15640
15640
  // Retain independent TTFT facts when dropping incompatible speed measurements.
15641
- outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 3).optional().catch(void 0),
15641
+ outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
15642
15642
  timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
15643
15643
  }).strict();
15644
15644
  var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
@@ -16104,6 +16104,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
16104
16104
  cursor: clientChannelCursorSchema,
16105
16105
  cwd: external_exports.string().optional()
16106
16106
  }),
16107
+ external_exports.object({
16108
+ type: external_exports.literal("harness-inspection-changed"),
16109
+ cursor: clientChannelCursorSchema,
16110
+ harnessId: external_exports.string().min(1)
16111
+ }),
16107
16112
  external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
16108
16113
  external_exports.object({
16109
16114
  type: external_exports.literal("preferences-changed"),
@@ -16175,6 +16180,8 @@ var clientItemTruncationSchema = external_exports.object({
16175
16180
  var clientTurnSchema = external_exports.object({
16176
16181
  id: external_exports.string().min(1),
16177
16182
  status: external_exports.string().min(1),
16183
+ /** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
16184
+ codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
16178
16185
  items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
16179
16186
  /** Original file operations, independent of the cumulative Desktop fileChange card.
16180
16187
  * Insert before the named non-file Item; null appends at the end of the Turn.
@@ -17399,6 +17406,7 @@ var THREAD_WATCH_NOTICE_OUTCOMES = [
17399
17406
  "completed",
17400
17407
  "failed",
17401
17408
  "interrupted",
17409
+ "needsInput",
17402
17410
  "timedOut",
17403
17411
  "unreadable",
17404
17412
  "notFound"
@@ -17445,13 +17453,25 @@ var target = { hostId: identity.regex(/^remote-(?:ssh(?:-|:)|control:)/u) };
17445
17453
  var thread = { ...target, threadId: identity };
17446
17454
  var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
17447
17455
  external_exports.strictObject({ kind: external_exports.literal("hosts") }),
17456
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
17448
17457
  external_exports.strictObject({
17449
17458
  kind: external_exports.literal("list"),
17450
17459
  ...target,
17451
17460
  cursor: external_exports.string().nullable(),
17452
17461
  archived: external_exports.boolean()
17453
17462
  }),
17454
- external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
17463
+ external_exports.strictObject({
17464
+ kind: external_exports.literal("read"),
17465
+ ...thread,
17466
+ page: external_exports.strictObject({
17467
+ cursor: external_exports.string().min(1).max(8192).nullable(),
17468
+ epoch: identity.optional(),
17469
+ sortDirection: external_exports.enum(["asc", "desc"]).optional(),
17470
+ limit: external_exports.number().int().min(1).max(20).optional()
17471
+ }).refine((page) => page.cursor === null || page.epoch !== void 0, {
17472
+ message: "A history continuation requires its connection epoch"
17473
+ }).optional()
17474
+ }),
17455
17475
  external_exports.strictObject({
17456
17476
  kind: external_exports.literal("configure"),
17457
17477
  ...thread,
@@ -14766,7 +14766,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14766
14766
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
14767
14767
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
14768
14768
  var usageOutputTimingSchema = external_exports.object({
14769
- version: external_exports.literal(3).optional(),
14769
+ version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
14770
14770
  requestId: external_exports.string().min(1),
14771
14771
  turnId: external_exports.string().min(1).max(1024),
14772
14772
  outputTokens: nonNegativeSafeIntegerSchema,
@@ -14774,16 +14774,16 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14774
14774
  completedAtMs: nonNegativeSafeIntegerSchema
14775
14775
  }).strict().refine((value) => value.completedAtMs > value.startedAtMs);
14776
14776
  var usageMeasurementSchema = external_exports.object({
14777
- version: external_exports.union([external_exports.literal(2), external_exports.literal(3)]).optional(),
14777
+ version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
14778
14778
  value: finiteNonNegativeNumberSchema,
14779
14779
  turnId: external_exports.string().min(1).max(1024),
14780
14780
  at: nonNegativeSafeIntegerSchema
14781
14781
  }).strict();
14782
14782
  var usageMeasurementsSchema = external_exports.object({
14783
- // Unversioned intervals can omit hidden thinking time; do not restore them into averages.
14784
- outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 3)).optional(),
14783
+ // Older intervals can omit hidden thinking time; do not restore them into averages.
14784
+ outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
14785
14785
  // Retain independent TTFT facts when dropping incompatible speed measurements.
14786
- outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 3).optional().catch(void 0),
14786
+ outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
14787
14787
  timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
14788
14788
  }).strict();
14789
14789
  var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
@@ -15250,6 +15250,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15250
15250
  cursor: clientChannelCursorSchema,
15251
15251
  cwd: external_exports.string().optional()
15252
15252
  }),
15253
+ external_exports.object({
15254
+ type: external_exports.literal("harness-inspection-changed"),
15255
+ cursor: clientChannelCursorSchema,
15256
+ harnessId: external_exports.string().min(1)
15257
+ }),
15253
15258
  external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
15254
15259
  external_exports.object({
15255
15260
  type: external_exports.literal("preferences-changed"),
@@ -15321,6 +15326,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15321
15326
  var clientTurnSchema = external_exports.object({
15322
15327
  id: external_exports.string().min(1),
15323
15328
  status: external_exports.string().min(1),
15329
+ /** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
15330
+ codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
15324
15331
  items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
15325
15332
  /** Original file operations, independent of the cumulative Desktop fileChange card.
15326
15333
  * Insert before the named non-file Item; null appends at the end of the Turn.
@@ -16587,6 +16594,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16587
16594
  "completed",
16588
16595
  "failed",
16589
16596
  "interrupted",
16597
+ "needsInput",
16590
16598
  "timedOut",
16591
16599
  "unreadable",
16592
16600
  "notFound"
@@ -16636,13 +16644,25 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16636
16644
  var thread = { ...target, threadId: identity };
16637
16645
  var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
16638
16646
  external_exports.strictObject({ kind: external_exports.literal("hosts") }),
16647
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
16639
16648
  external_exports.strictObject({
16640
16649
  kind: external_exports.literal("list"),
16641
16650
  ...target,
16642
16651
  cursor: external_exports.string().nullable(),
16643
16652
  archived: external_exports.boolean()
16644
16653
  }),
16645
- external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
16654
+ external_exports.strictObject({
16655
+ kind: external_exports.literal("read"),
16656
+ ...thread,
16657
+ page: external_exports.strictObject({
16658
+ cursor: external_exports.string().min(1).max(8192).nullable(),
16659
+ epoch: identity.optional(),
16660
+ sortDirection: external_exports.enum(["asc", "desc"]).optional(),
16661
+ limit: external_exports.number().int().min(1).max(20).optional()
16662
+ }).refine((page) => page.cursor === null || page.epoch !== void 0, {
16663
+ message: "A history continuation requires its connection epoch"
16664
+ }).optional()
16665
+ }),
16646
16666
  external_exports.strictObject({
16647
16667
  kind: external_exports.literal("configure"),
16648
16668
  ...thread,
@@ -17712,11 +17732,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17712
17732
  const webUi = /* @__PURE__ */ new Map();
17713
17733
  const listeners = /* @__PURE__ */ new Set();
17714
17734
  let pending = null;
17735
+ let queuedRefresh = null;
17715
17736
  const publish = () => {
17716
17737
  for (const listener of [...listeners]) listener();
17717
17738
  };
17718
17739
  const inspectAll = (refresh) => {
17719
- if (pending) return pending;
17740
+ if (pending) {
17741
+ if (!refresh) return pending;
17742
+ queuedRefresh ??= pending.then(() => inspectAll(true)).finally(() => {
17743
+ queuedRefresh = null;
17744
+ });
17745
+ return queuedRefresh;
17746
+ }
17720
17747
  pending = Promise.resolve().then(async () => {
17721
17748
  try {
17722
17749
  if (!client.listHarnessPlugins)
@@ -212,14 +212,14 @@ var CdpClient = class _CdpClient {
212
212
  if (listeners.size === 0) this.#listeners.delete(method);
213
213
  };
214
214
  }
215
- #send(method, params, sessionId) {
215
+ #send(method, params, sessionId, timeoutMs = this.#commandTimeoutMs) {
216
216
  if (this.#closed) return Promise.reject(new CdpConnectionClosedError("CDP client is closed"));
217
217
  const id = this.#nextId++;
218
218
  return new Promise((resolve, reject) => {
219
219
  const timeout = setTimeout(() => {
220
220
  this.#pending.delete(id);
221
221
  reject(new Error(`CDP command '${method}' timed out`));
222
- }, this.#commandTimeoutMs);
222
+ }, timeoutMs);
223
223
  this.#pending.set(id, { resolve, reject, timeout });
224
224
  try {
225
225
  this.#socket.send(
@@ -232,12 +232,13 @@ var CdpClient = class _CdpClient {
232
232
  }
233
233
  });
234
234
  }
235
- async evaluate(expression) {
236
- const response = await this.command("Runtime.evaluate", {
237
- expression,
238
- awaitPromise: true,
239
- returnByValue: true
240
- });
235
+ async evaluate(expression, timeoutMs) {
236
+ const response = await this.#send(
237
+ "Runtime.evaluate",
238
+ { expression, awaitPromise: true, returnByValue: true },
239
+ void 0,
240
+ timeoutMs
241
+ );
241
242
  if (!isRecord(response)) throw new Error("Runtime.evaluate returned an invalid result");
242
243
  try {
243
244
  if (isRecord(response.exceptionDetails)) {
@@ -316,7 +317,10 @@ var CdpClient = class _CdpClient {
316
317
  // packages/desktop-control/src/renderer-remote-sessions.ts
317
318
  async function rendererRemoteSession(target2, operation) {
318
319
  const routing = target2.__codexhostHostRoutingV1;
319
- if (!routing) throw new Error("Desktop remote session routing is unavailable");
320
+ if (!routing)
321
+ throw Object.assign(new Error("Desktop remote session routing is unavailable"), {
322
+ code: -32090
323
+ });
320
324
  const ids = [...new Set(routing.knownHostIds?.() ?? [])].filter(
321
325
  (id) => /^remote-(?:ssh(?:-|:)|control:)/u.test(id)
322
326
  );
@@ -390,49 +394,129 @@ async function rendererRemoteSession(target2, operation) {
390
394
  })
391
395
  );
392
396
  }
397
+ const connectionError = (message, changed = false) => Object.assign(new Error(message), {
398
+ code: changed && routing.forHost(operation.hostId) ? -32095 : -32090
399
+ });
393
400
  if (!ids.includes(operation.hostId))
394
- throw new Error("Remote Host is offline or no longer known to Desktop");
401
+ throw connectionError("Remote Host is offline or no longer known to Desktop");
395
402
  const route = routing.forHost(operation.hostId);
396
403
  const manager = route?.manager;
397
- if (!route || !manager) throw new Error("Remote Host is offline");
404
+ if (!route || !manager) throw connectionError("Remote Host is offline");
405
+ const read = async (request) => {
406
+ let result;
407
+ try {
408
+ result = await request();
409
+ } catch (error51) {
410
+ if (routing.forHost(operation.hostId) !== route)
411
+ throw connectionError("Remote connection changed during read", true);
412
+ throw error51;
413
+ }
414
+ if (routing.forHost(operation.hostId) !== route)
415
+ throw connectionError("Remote connection changed during read", true);
416
+ return result;
417
+ };
398
418
  let generation = state.managers.get(route);
399
419
  if (!generation) {
400
420
  generation = { epoch: crypto.randomUUID(), answered: /* @__PURE__ */ new Set() };
401
421
  state.managers.set(route, generation);
402
422
  }
403
423
  if ("epoch" in operation && operation.epoch !== generation.epoch)
404
- throw new Error("Remote connection changed; refresh before operating");
424
+ throw connectionError("Remote connection changed; refresh before operating", true);
405
425
  if (operation.kind === "list")
406
- return manager.sendRequest("thread/list", {
407
- cursor: operation.cursor,
408
- archived: operation.archived,
409
- limit: 100
410
- });
426
+ return read(
427
+ () => manager.sendRequest("thread/list", {
428
+ cursor: operation.cursor,
429
+ archived: operation.archived,
430
+ limit: 100
431
+ })
432
+ );
411
433
  const threadId = operation.threadId;
434
+ if (operation.kind === "status") {
435
+ const result = await read(
436
+ () => manager.sendRequest("thread/read", {
437
+ threadId,
438
+ includeTurns: false
439
+ })
440
+ );
441
+ if (result.thread?.id !== threadId || typeof result.thread.status?.type !== "string")
442
+ throw new Error("Invalid remote Thread status");
443
+ let turnId = null;
444
+ if (result.thread.status.type === "active") {
445
+ const page = await read(
446
+ () => manager.sendRequest("thread/turns/list", {
447
+ threadId,
448
+ cursor: null,
449
+ limit: 1,
450
+ sortDirection: "desc",
451
+ itemsView: "notLoaded"
452
+ })
453
+ );
454
+ if (!Array.isArray(page.data)) throw new Error("Invalid remote Turn status");
455
+ const latest = page.data[0];
456
+ if (latest?.status === "inProgress" && typeof latest.id === "string") turnId = latest.id;
457
+ }
458
+ return { threadId, status: result.thread.status.type, turnId, epoch: generation.epoch };
459
+ }
412
460
  const pendingRequests = async () => {
413
- const conversation = await manager.getConversation?.(threadId);
414
- if (routing.forHost(operation.hostId) !== route)
415
- throw new Error("Remote connection changed during interaction read");
461
+ const conversation = await read(() => manager.getConversation?.(threadId));
416
462
  return Array.isArray(conversation?.requests) ? conversation.requests : [];
417
463
  };
418
464
  if (operation.kind === "read") {
419
- let result = await manager.sendRequest("thread/read", { threadId, includeTurns: false });
420
- if (routing.forHost(operation.hostId) !== route)
421
- throw new Error("Remote connection changed during read");
465
+ if (operation.page?.epoch !== void 0 && operation.page.epoch !== generation.epoch)
466
+ throw connectionError(
467
+ "Remote connection changed during history pagination; refresh and retry",
468
+ true
469
+ );
470
+ let result = await read(
471
+ () => manager.sendRequest("thread/read", { threadId, includeTurns: false })
472
+ );
422
473
  const header = result;
423
- if (header.thread?.historyMode === "paginated") {
474
+ let nextCursor = null;
475
+ const requestedPage = operation.page;
476
+ if (header.thread?.historyMode === "paginated" && requestedPage) {
477
+ let limit = requestedPage.limit ?? 20;
478
+ for (; ; ) {
479
+ const response = await read(
480
+ () => manager.sendRequest("thread/turns/list", {
481
+ threadId,
482
+ cursor: requestedPage.cursor,
483
+ limit,
484
+ sortDirection: requestedPage.sortDirection ?? "asc",
485
+ itemsView: "full"
486
+ })
487
+ );
488
+ if (!Array.isArray(response.data) || response.nextCursor !== null && (typeof response.nextCursor !== "string" || response.nextCursor.length === 0))
489
+ throw new Error("Invalid remote history page");
490
+ if (new TextEncoder().encode(JSON.stringify(response.data)).byteLength > 14 * 1024 * 1024) {
491
+ if (response.data.length <= 1 || limit === 1)
492
+ throw Object.assign(
493
+ new Error(
494
+ "A remote Turn exceeds the history page limit; open this chat in Codex Desktop."
495
+ ),
496
+ { code: -32094 }
497
+ );
498
+ limit = Math.max(1, Math.floor(Math.min(limit, response.data.length) / 2));
499
+ continue;
500
+ }
501
+ result = { ...result, thread: { ...header.thread, turns: response.data } };
502
+ nextCursor = response.nextCursor;
503
+ break;
504
+ }
505
+ } else if (header.thread?.historyMode === "paginated") {
424
506
  const turns = [], cursors = /* @__PURE__ */ new Set();
425
507
  let cursor = null, bytes = 0, complete = false;
426
508
  for (let page = 0; page < 100; page++) {
427
509
  if (routing.forHost(operation.hostId) !== route)
428
- throw new Error("Remote connection changed during read");
429
- const response = await manager.sendRequest("thread/turns/list", {
430
- threadId,
431
- cursor,
432
- limit: 50,
433
- sortDirection: "asc",
434
- itemsView: "full"
435
- });
510
+ throw connectionError("Remote connection changed during read", true);
511
+ const response = await read(
512
+ () => manager.sendRequest("thread/turns/list", {
513
+ threadId,
514
+ cursor,
515
+ limit: 50,
516
+ sortDirection: "asc",
517
+ itemsView: "full"
518
+ })
519
+ );
436
520
  if (!Array.isArray(response.data) || response.nextCursor !== null && typeof response.nextCursor !== "string")
437
521
  throw new Error("Invalid remote history page");
438
522
  bytes += new TextEncoder().encode(JSON.stringify(response.data)).byteLength;
@@ -448,9 +532,12 @@ async function rendererRemoteSession(target2, operation) {
448
532
  }
449
533
  if (!complete) throw new Error("Remote history exceeds the page limit");
450
534
  result = { ...result, thread: { ...header.thread, turns } };
451
- } else result = await manager.sendRequest("thread/read", { threadId, includeTurns: true });
535
+ } else
536
+ result = await read(
537
+ () => manager.sendRequest("thread/read", { threadId, includeTurns: true })
538
+ );
452
539
  if (routing.forHost(operation.hostId) !== route)
453
- throw new Error("Remote connection changed during read");
540
+ throw connectionError("Remote connection changed during read", true);
454
541
  let metadata = {};
455
542
  if (header.thread) {
456
543
  const cwd = header.thread.cwd;
@@ -459,7 +546,7 @@ async function rendererRemoteSession(target2, operation) {
459
546
  threadId
460
547
  });
461
548
  if (routing.forHost(operation.hostId) !== route)
462
- throw new Error("Remote connection changed during read");
549
+ throw connectionError("Remote connection changed during read", true);
463
550
  metadata = {
464
551
  configuration,
465
552
  ...configuration.owner === "codex" ? {
@@ -473,7 +560,7 @@ async function rendererRemoteSession(target2, operation) {
473
560
  if (configuration.owner === "codex" && manager.getConversation) {
474
561
  const conversation = await Promise.resolve().then(() => manager.getConversation?.(threadId)).catch(() => void 0);
475
562
  if (routing.forHost(operation.hostId) !== route)
476
- throw new Error("Remote connection changed during read");
563
+ throw connectionError("Remote connection changed during read", true);
477
564
  const settings = conversation?.latestThreadSettings;
478
565
  if (settings?.model === header.thread.model && typeof settings?.model === "string")
479
566
  metadata.nativeSettings = {
@@ -490,7 +577,7 @@ async function rendererRemoteSession(target2, operation) {
490
577
  const loading = Promise.all([
491
578
  Promise.resolve().then(() => {
492
579
  if (routing.forHost(operation.hostId) !== route)
493
- throw new Error("Remote connection changed during read");
580
+ throw connectionError("Remote connection changed during read", true);
494
581
  return manager.sendRequest("codexhost/harness/inspect", {
495
582
  harnessId,
496
583
  ...cwd ? { cwd } : {}
@@ -498,7 +585,7 @@ async function rendererRemoteSession(target2, operation) {
498
585
  }),
499
586
  Promise.resolve().then(() => {
500
587
  if (routing.forHost(operation.hostId) !== route)
501
- throw new Error("Remote connection changed during read");
588
+ throw connectionError("Remote connection changed during read", true);
502
589
  return manager.sendRequest("codexhost/harness/plugins/list", {});
503
590
  }).catch(() => null)
504
591
  ]).then(([inspection, catalog]) => {
@@ -533,12 +620,13 @@ async function rendererRemoteSession(target2, operation) {
533
620
  }
534
621
  }
535
622
  if (routing.forHost(operation.hostId) !== route)
536
- throw new Error("Remote connection changed during read");
623
+ throw connectionError("Remote connection changed during read", true);
537
624
  const requests = await pendingRequests();
538
625
  return {
539
626
  result,
540
627
  ...metadata,
541
628
  epoch: generation.epoch,
629
+ ...operation.page ? { nextCursor } : {},
542
630
  interactionsAvailable: !!manager.getConversation && !!manager.replyWithCommandExecutionApprovalDecision && !!manager.replyWithFileChangeApprovalDecision,
543
631
  requests: requests.filter(
544
632
  (request) => (request.params.threadId ?? request.params.conversationId) === threadId && !generation.answered.has(JSON.stringify([threadId, request.id]))
@@ -591,7 +679,7 @@ async function rendererRemoteSession(target2, operation) {
591
679
  }
592
680
  }
593
681
  case "prompt":
594
- await manager.sendRequest("thread/resume", { threadId });
682
+ await manager.sendRequest("thread/resume", { threadId, excludeTurns: true });
595
683
  if (routing.forHost(operation.hostId) !== route)
596
684
  throw new Error("Remote connection changed during resume");
597
685
  return manager.sendRequest("turn/start", {
@@ -15262,7 +15350,7 @@ var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonneg
15262
15350
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
15263
15351
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
15264
15352
  var usageOutputTimingSchema = external_exports.object({
15265
- version: external_exports.literal(3).optional(),
15353
+ version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
15266
15354
  requestId: external_exports.string().min(1),
15267
15355
  turnId: external_exports.string().min(1).max(1024),
15268
15356
  outputTokens: nonNegativeSafeIntegerSchema,
@@ -15270,16 +15358,16 @@ var usageOutputTimingSchema = external_exports.object({
15270
15358
  completedAtMs: nonNegativeSafeIntegerSchema
15271
15359
  }).strict().refine((value) => value.completedAtMs > value.startedAtMs);
15272
15360
  var usageMeasurementSchema = external_exports.object({
15273
- version: external_exports.union([external_exports.literal(2), external_exports.literal(3)]).optional(),
15361
+ version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
15274
15362
  value: finiteNonNegativeNumberSchema,
15275
15363
  turnId: external_exports.string().min(1).max(1024),
15276
15364
  at: nonNegativeSafeIntegerSchema
15277
15365
  }).strict();
15278
15366
  var usageMeasurementsSchema = external_exports.object({
15279
- // Unversioned intervals can omit hidden thinking time; do not restore them into averages.
15280
- outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 3)).optional(),
15367
+ // Older intervals can omit hidden thinking time; do not restore them into averages.
15368
+ outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
15281
15369
  // Retain independent TTFT facts when dropping incompatible speed measurements.
15282
- outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 3).optional().catch(void 0),
15370
+ outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
15283
15371
  timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
15284
15372
  }).strict();
15285
15373
  var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
@@ -15745,6 +15833,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
15745
15833
  cursor: clientChannelCursorSchema,
15746
15834
  cwd: external_exports.string().optional()
15747
15835
  }),
15836
+ external_exports.object({
15837
+ type: external_exports.literal("harness-inspection-changed"),
15838
+ cursor: clientChannelCursorSchema,
15839
+ harnessId: external_exports.string().min(1)
15840
+ }),
15748
15841
  external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
15749
15842
  external_exports.object({
15750
15843
  type: external_exports.literal("preferences-changed"),
@@ -15816,6 +15909,8 @@ var clientItemTruncationSchema = external_exports.object({
15816
15909
  var clientTurnSchema = external_exports.object({
15817
15910
  id: external_exports.string().min(1),
15818
15911
  status: external_exports.string().min(1),
15912
+ /** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
15913
+ codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
15819
15914
  items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
15820
15915
  /** Original file operations, independent of the cumulative Desktop fileChange card.
15821
15916
  * Insert before the named non-file Item; null appends at the end of the Turn.
@@ -17028,6 +17123,7 @@ var THREAD_WATCH_NOTICE_OUTCOMES = [
17028
17123
  "completed",
17029
17124
  "failed",
17030
17125
  "interrupted",
17126
+ "needsInput",
17031
17127
  "timedOut",
17032
17128
  "unreadable",
17033
17129
  "notFound"
@@ -17074,13 +17170,25 @@ var target = { hostId: identity.regex(/^remote-(?:ssh(?:-|:)|control:)/u) };
17074
17170
  var thread = { ...target, threadId: identity };
17075
17171
  var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
17076
17172
  external_exports.strictObject({ kind: external_exports.literal("hosts") }),
17173
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
17077
17174
  external_exports.strictObject({
17078
17175
  kind: external_exports.literal("list"),
17079
17176
  ...target,
17080
17177
  cursor: external_exports.string().nullable(),
17081
17178
  archived: external_exports.boolean()
17082
17179
  }),
17083
- external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
17180
+ external_exports.strictObject({
17181
+ kind: external_exports.literal("read"),
17182
+ ...thread,
17183
+ page: external_exports.strictObject({
17184
+ cursor: external_exports.string().min(1).max(8192).nullable(),
17185
+ epoch: identity.optional(),
17186
+ sortDirection: external_exports.enum(["asc", "desc"]).optional(),
17187
+ limit: external_exports.number().int().min(1).max(20).optional()
17188
+ }).refine((page) => page.cursor === null || page.epoch !== void 0, {
17189
+ message: "A history continuation requires its connection epoch"
17190
+ }).optional()
17191
+ }),
17084
17192
  external_exports.strictObject({
17085
17193
  kind: external_exports.literal("configure"),
17086
17194
  ...thread,
@@ -17216,7 +17324,7 @@ var MAX_REPLY_BYTES = 1024 * 1024;
17216
17324
  function remoteConnectionsExpression(input) {
17217
17325
  const request = remoteConnectionsRequestSchema.parse(input);
17218
17326
  if (request.action === "session")
17219
- return `(async () => { try { return {result:await (${rendererRemoteSession.toString()})(window,${JSON.stringify(request.operation)})}; } catch(error) {return {error:{code:-32090,message:String(error?.message ?? error)}};} })()`;
17327
+ return `(async () => { try { return {result:await (${rendererRemoteSession.toString()})(window,${JSON.stringify(request.operation)})}; } catch(error) {return {error:{code:typeof error?.code === "number" ? error.code : -32603,message:String(error?.message ?? error)}};} })()`;
17220
17328
  return `(async () => {
17221
17329
  try {
17222
17330
  const api = window.__codexhostRendererBindingProbeV1;
@@ -17360,7 +17468,7 @@ async function startControllerAttachmentServer(options) {
17360
17468
  JSON.stringify({
17361
17469
  error: {
17362
17470
  code: -32094,
17363
- message: input.action === "session" ? "Remote Thread snapshot exceeds the 16 MiB response limit; open this Thread in Codex Desktop. Paged remote snapshots are not supported." : "Thread snapshot exceeds the 16 MiB response limit; reduce the message page size. Oversized individual results are not supported."
17471
+ message: input.action === "session" ? "Remote history reply exceeds the 16 MiB limit; update codexhost on this computer to use paged history, or open this chat in Codex Desktop." : "Thread snapshot exceeds the 16 MiB response limit; reduce the message page size. Oversized individual results are not supported."
17364
17472
  }
17365
17473
  }) + "\n"
17366
17474
  );
@@ -20343,9 +20451,9 @@ var InstalledRendererCdpControlSession = class {
20343
20451
  await this.renderer.command("Page.bringToFront");
20344
20452
  return 1;
20345
20453
  }
20346
- executeRenderer(expression) {
20454
+ executeRenderer(expression, timeoutMs) {
20347
20455
  if (this.#closed) return Promise.reject(new Error("Renderer CDP Control Session is closed"));
20348
- return this.renderer.evaluate(expression);
20456
+ return this.renderer.evaluate(expression, timeoutMs);
20349
20457
  }
20350
20458
  close() {
20351
20459
  if (this.#closed) return;
@@ -20641,7 +20749,10 @@ ${rendererSource}`,
20641
20749
  remoteConnections: async (request) => {
20642
20750
  const current = await useSession(() => recoverSession());
20643
20751
  return remoteConnectionsReplySchema.parse(
20644
- await current.executeRenderer(remoteConnectionsExpression(request))
20752
+ await current.executeRenderer(
20753
+ remoteConnectionsExpression(request),
20754
+ request.action === "read-thread" || request.action === "session" ? REMOTE_THREAD_CONTROL_TIMEOUT_MS : 3e4
20755
+ )
20645
20756
  );
20646
20757
  },
20647
20758
  openLocalPage: (url2) => openRendererLocalPage(