@karlorz/codexhost-cli-win32-x64 0.16.1-0 → 0.16.1-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.
@@ -5121,12 +5121,12 @@ async function verifyDownloadedArtifact(source, filePath, result) {
5121
5121
  // packages/update-manager/dist/updater-ready.js
5122
5122
  import { setTimeout as delay } from "node:timers/promises";
5123
5123
  async function waitForUpdaterReady(child, readStatus, timeoutMs = 1e4) {
5124
- let failure2;
5124
+ let failure3;
5125
5125
  const onError = (error51) => {
5126
- failure2 = error51;
5126
+ failure3 = error51;
5127
5127
  };
5128
5128
  const onExit = () => {
5129
- failure2 = new Error("Background Updater exited before completing handoff");
5129
+ failure3 = new Error("Background Updater exited before completing handoff");
5130
5130
  };
5131
5131
  child.on("error", onError);
5132
5132
  child.on("exit", onExit);
@@ -5136,8 +5136,8 @@ async function waitForUpdaterReady(child, readStatus, timeoutMs = 1e4) {
5136
5136
  const status2 = await readStatus();
5137
5137
  if (status2?.phase === "failed")
5138
5138
  throw new Error(status2.error ?? "Background Updater failed");
5139
- if (failure2)
5140
- throw failure2;
5139
+ if (failure3)
5140
+ throw failure3;
5141
5141
  if (child.exitCode != null || child.signalCode != null) {
5142
5142
  throw new Error("Background Updater exited before completing handoff");
5143
5143
  }
@@ -21695,6 +21695,40 @@ var voiceSettingsStateSchema = external_exports.strictObject({
21695
21695
  })
21696
21696
  });
21697
21697
 
21698
+ // packages/shared-contracts/dist/background-activity.js
21699
+ var THREAD_ACTIVITY_LIST_METHOD = "codexhost/thread/activity/list";
21700
+ var THREAD_ACTIVITY_READ_METHOD = "codexhost/thread/activity/read";
21701
+ var THREAD_ACTIVITY_STOP_METHOD = "codexhost/thread/activity/stop";
21702
+ var backgroundActivitySchema = external_exports.strictObject({
21703
+ id: external_exports.string().min(1),
21704
+ kind: external_exports.enum(["task", "monitor", "loop", "subagent"]),
21705
+ label: external_exports.string(),
21706
+ status: external_exports.enum(["running", "scheduled", "completed", "failed", "cancelled", "unknown"]),
21707
+ canStop: external_exports.boolean(),
21708
+ /** Existing detached command Item presented by Desktop's native process UI. */
21709
+ commandItemId: hostItemIdSchema.optional(),
21710
+ schedule: external_exports.string().optional(),
21711
+ nextRunAt: external_exports.string().datetime({ offset: true }).optional(),
21712
+ relatedActivityId: external_exports.string().optional(),
21713
+ threadId: hostThreadIdSchema.optional()
21714
+ });
21715
+ var backgroundActivityDetailSchema = external_exports.strictObject({
21716
+ activity: backgroundActivitySchema,
21717
+ output: external_exports.string(),
21718
+ truncated: external_exports.boolean()
21719
+ });
21720
+ var threadActivityParamsSchema = external_exports.strictObject({ threadId: hostThreadIdSchema });
21721
+ var threadActivityItemParamsSchema = threadActivityParamsSchema.extend({
21722
+ activityId: external_exports.string().min(1)
21723
+ });
21724
+ var threadActivityListResultSchema = external_exports.strictObject({
21725
+ supported: external_exports.boolean(),
21726
+ activities: external_exports.array(backgroundActivitySchema)
21727
+ });
21728
+ var threadActivityStopResultSchema = external_exports.strictObject({
21729
+ outcome: external_exports.enum(["stopped", "alreadyStopped", "notFound"])
21730
+ });
21731
+
21698
21732
  // packages/shared-contracts/dist/index.js
21699
21733
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
21700
21734
 
@@ -21807,11 +21841,11 @@ var RuntimeMaintenance = class {
21807
21841
  }, UPDATER_WATCH_INTERVAL_MS);
21808
21842
  this.#watch.unref();
21809
21843
  }
21810
- async #recordStartFailure(version2, failure2) {
21844
+ async #recordStartFailure(version2, failure3) {
21811
21845
  await writeFile3(this.#cancelPath, JSON.stringify({ targetVersion: version2 }), { mode: 384 });
21812
21846
  await writeFile3(
21813
21847
  this.#statusPath,
21814
- JSON.stringify({ phase: "failed", targetVersion: version2, error: failure2 }),
21848
+ JSON.stringify({ phase: "failed", targetVersion: version2, error: failure3 }),
21815
21849
  { mode: 384 }
21816
21850
  );
21817
21851
  }
@@ -22022,9 +22056,9 @@ var RuntimeMaintenance = class {
22022
22056
  process.kill(helperPid);
22023
22057
  } catch {
22024
22058
  }
22025
- const failure2 = "Remote updater did not start";
22026
- await this.#recordStartFailure(version2, failure2);
22027
- throw new Error(failure2);
22059
+ const failure3 = "Remote updater did not start";
22060
+ await this.#recordStartFailure(version2, failure3);
22061
+ throw new Error(failure3);
22028
22062
  }
22029
22063
  await new Promise((resolve) => setTimeout(resolve, 50));
22030
22064
  }
@@ -22047,6 +22081,65 @@ import path41 from "node:path";
22047
22081
  import { homedir as homedir5 } from "node:os";
22048
22082
  import { fileURLToPath as fileURLToPath2 } from "node:url";
22049
22083
 
22084
+ // packages/host-runtime/src/external-thread-activity.ts
22085
+ async function executeExternalActivity(input) {
22086
+ const capability = input.session.backgroundActivity;
22087
+ if (!capability)
22088
+ return input.method === THREAD_ACTIVITY_LIST_METHOD ? { result: { supported: false, activities: [] } } : { error: { code: -32076, message: "Background activity is unsupported" } };
22089
+ const current = () => {
22090
+ if (!input.isCurrent()) throw new Error("Background activity Session changed");
22091
+ };
22092
+ const resolveChildren = async (activities) => {
22093
+ const children = capability.subagents?.() ?? [];
22094
+ return Promise.all(
22095
+ activities.map(async (activity) => {
22096
+ if (activity.kind !== "subagent") return activity;
22097
+ const child = children.find((entry) => entry.activityId === activity.id)?.state;
22098
+ if (!child) return activity;
22099
+ current();
22100
+ const resolved = await input.materialize(child);
22101
+ current();
22102
+ return resolved.subagentId !== child.nativeSubagentId ? { ...activity, threadId: resolved.subagentId } : activity;
22103
+ })
22104
+ );
22105
+ };
22106
+ try {
22107
+ current();
22108
+ if (input.method === THREAD_ACTIVITY_LIST_METHOD) {
22109
+ const result2 = await capability.list();
22110
+ current();
22111
+ if (!result2.ok) return failure(result2.error);
22112
+ const activities = await resolveChildren(result2.value);
22113
+ return { result: threadActivityListResultSchema.parse({ supported: true, activities }) };
22114
+ }
22115
+ if (input.method === THREAD_ACTIVITY_READ_METHOD) {
22116
+ const result2 = await capability.read(input.activityId ?? "");
22117
+ current();
22118
+ if (!result2.ok) return failure(result2.error);
22119
+ const [activity] = await resolveChildren([result2.value.activity]);
22120
+ return { result: backgroundActivityDetailSchema.parse({ ...result2.value, activity }) };
22121
+ }
22122
+ const result = await capability.stop(input.activityId ?? "");
22123
+ current();
22124
+ return result.ok ? { result: threadActivityStopResultSchema.parse(result.value) } : failure(result.error);
22125
+ } catch (error51) {
22126
+ return {
22127
+ error: {
22128
+ code: -32083,
22129
+ message: error51 instanceof Error ? error51.message : "Background activity failed"
22130
+ }
22131
+ };
22132
+ }
22133
+ }
22134
+ function failure(error51) {
22135
+ return {
22136
+ error: {
22137
+ code: error51.code === "unsupported" ? -32076 : error51.code === "invalidRequest" ? -32602 : -32083,
22138
+ message: error51.message
22139
+ }
22140
+ };
22141
+ }
22142
+
22050
22143
  // packages/harness-adapter/dist/account-credits.js
22051
22144
  function parseHarnessAccountCredits(value2) {
22052
22145
  if (!value2 || typeof value2 !== "object" || Array.isArray(value2))
@@ -27156,11 +27249,11 @@ async function executeExternalGoal(session, threadId2, method, params) {
27156
27249
  try {
27157
27250
  if (method === "thread/goal/get") {
27158
27251
  let read = await goals.read();
27159
- if (!read.ok) return failure(read.error);
27252
+ if (!read.ok) return failure2(read.error);
27160
27253
  const completed = read.value === null ? await goals.readLastCompleted?.() : void 0;
27161
27254
  if (completed?.ok && completed.value?.status === "complete") {
27162
27255
  read = await goals.read();
27163
- if (!read.ok) return failure(read.error);
27256
+ if (!read.ok) return failure2(read.error);
27164
27257
  }
27165
27258
  return {
27166
27259
  result: {
@@ -27176,7 +27269,7 @@ async function executeExternalGoal(session, threadId2, method, params) {
27176
27269
  }
27177
27270
  if (method === "thread/goal/clear") {
27178
27271
  const cleared = await goals.clear({ origin });
27179
- return cleared.ok ? { result: { cleared: cleared.value.cleared } } : failure(cleared.error);
27272
+ return cleared.ok ? { result: { cleared: cleared.value.cleared } } : failure2(cleared.error);
27180
27273
  }
27181
27274
  const parsed2 = harnessGoalSetSchema.safeParse({
27182
27275
  ...params.objective == null ? {} : { objective: params.objective },
@@ -27187,12 +27280,12 @@ async function executeExternalGoal(session, threadId2, method, params) {
27187
27280
  if (!parsed2.success)
27188
27281
  return { error: { code: -32602, message: "Invalid external goal mutation" } };
27189
27282
  const set2 = await goals.set(parsed2.data);
27190
- return set2.ok ? { result: { goal: projectCodexGoal(threadId2, set2.value) } } : failure(set2.error);
27283
+ return set2.ok ? { result: { goal: projectCodexGoal(threadId2, set2.value) } } : failure2(set2.error);
27191
27284
  } catch {
27192
27285
  return { error: { code: -32076, message: "External goal state or operation is unavailable" } };
27193
27286
  }
27194
27287
  }
27195
- function failure(error51) {
27288
+ function failure2(error51) {
27196
27289
  return {
27197
27290
  error: { code: error51.code === "invalidRequest" ? -32602 : -32076, message: error51.message }
27198
27291
  };
@@ -28071,10 +28164,10 @@ function createLocalPageOpener(environment) {
28071
28164
  socket.setEncoding("utf8");
28072
28165
  let buffer = "";
28073
28166
  let pending;
28074
- let failure2;
28167
+ let failure3;
28075
28168
  const fail = () => {
28076
- failure2 ??= new Error("Codex local page connection closed");
28077
- pending?.reject(failure2);
28169
+ failure3 ??= new Error("Codex local page connection closed");
28170
+ pending?.reject(failure3);
28078
28171
  pending = void 0;
28079
28172
  };
28080
28173
  socket.on("error", fail);
@@ -28100,8 +28193,8 @@ function createLocalPageOpener(environment) {
28100
28193
  }
28101
28194
  });
28102
28195
  const request = async (command) => {
28103
- if (failure2)
28104
- throw failure2;
28196
+ if (failure3)
28197
+ throw failure3;
28105
28198
  if (pending)
28106
28199
  throw new Error("Local page operation already pending");
28107
28200
  const result = Promise.withResolvers();
@@ -28131,7 +28224,7 @@ function createLocalPageOpener(environment) {
28131
28224
  },
28132
28225
  close() {
28133
28226
  closing ??= operations.catch(() => void 0).then(async () => {
28134
- if (!socket.destroyed && !failure2)
28227
+ if (!socket.destroyed && !failure3)
28135
28228
  await request("CLOSE");
28136
28229
  }).catch(() => void 0).finally(() => socket.destroy());
28137
28230
  return closing;
@@ -29602,12 +29695,87 @@ function resolveRendererHostRpc(discovery, hostId2) {
29602
29695
  function rendererHostRpcHostIds(discovery) {
29603
29696
  return [...discovery.family.keys()].filter((hostId2) => typeof hostId2 === "string");
29604
29697
  }
29698
+ function rendererHostRpcUsesExternalQueue(store, conversationId) {
29699
+ const providers = /* @__PURE__ */ new Map();
29700
+ for (const members of store.familyBindings.values()) {
29701
+ for (const member of members.values()) {
29702
+ const signal = member.value;
29703
+ if (signal === null || typeof signal !== "object" || !("get" in signal) || typeof signal.get !== "function")
29704
+ continue;
29705
+ let value2;
29706
+ try {
29707
+ value2 = signal.get();
29708
+ } catch {
29709
+ continue;
29710
+ }
29711
+ if (value2 === null || typeof value2 !== "object" || !("conversationId" in value2) || value2.conversationId !== conversationId || !("hostId" in value2) || typeof value2.hostId !== "string" || !("modelProvider" in value2) || typeof value2.modelProvider !== "string")
29712
+ continue;
29713
+ const hostProviders = providers.get(value2.hostId) ?? /* @__PURE__ */ new Set();
29714
+ hostProviders.add(value2.modelProvider);
29715
+ providers.set(value2.hostId, hostProviders);
29716
+ }
29717
+ }
29718
+ if (providers.size !== 1)
29719
+ return false;
29720
+ const values = providers.values().next().value;
29721
+ return values?.size === 1 && values.has("codexhost");
29722
+ }
29723
+
29724
+ // packages/desktop-control/dist/renderer-external-queue-policy.js
29725
+ function installRendererExternalQueuePolicy(root, target, dependencies2) {
29726
+ if (target.__codexhostExternalQueuePolicyV1)
29727
+ return target.__codexhostExternalQueuePolicyV1;
29728
+ const store = dependencies2.findStore(root);
29729
+ if (!store)
29730
+ return null;
29731
+ const record5 = (value2) => value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
29732
+ let disposed = false;
29733
+ const route = (message2) => {
29734
+ if (!Array.isArray(message2) || message2.length !== 2 || message2[0] !== "push")
29735
+ return message2;
29736
+ const expression = message2[1];
29737
+ if (!Array.isArray(expression) || expression.length !== 4 || expression[0] !== "pipeline")
29738
+ return message2;
29739
+ const [, importId, path47, args] = expression;
29740
+ if (!Array.isArray(path47) || path47.length !== 1 || path47[0] !== "sendMessage" || !Array.isArray(args))
29741
+ return message2;
29742
+ const input = args[0];
29743
+ if (!record5(input) || typeof input.conversationId !== "string" || !record5(input.message) || !dependencies2.usesExternalQueue(store, input.conversationId))
29744
+ return message2;
29745
+ return [
29746
+ "push",
29747
+ ["pipeline", importId, path47, [{ ...input, queueModeOverride: "queue" }, ...args.slice(1)]]
29748
+ ];
29749
+ };
29750
+ const port = dependencies2.portPrototype;
29751
+ const original = port.postMessage;
29752
+ const postMessage = function(message2, ...rest) {
29753
+ return original.call(this, disposed ? message2 : route(message2), ...rest);
29754
+ };
29755
+ port.postMessage = postMessage;
29756
+ const policy = {
29757
+ dispose() {
29758
+ disposed = true;
29759
+ if (port.postMessage === postMessage)
29760
+ port.postMessage = original;
29761
+ if (target.__codexhostExternalQueuePolicyV1 === policy)
29762
+ delete target.__codexhostExternalQueuePolicyV1;
29763
+ }
29764
+ };
29765
+ Object.defineProperty(target, "__codexhostExternalQueuePolicyV1", {
29766
+ configurable: true,
29767
+ value: policy
29768
+ });
29769
+ return policy;
29770
+ }
29605
29771
 
29606
29772
  // packages/desktop-control/dist/renderer-host-rpc-routing.js
29607
29773
  function installRendererHostRpcRouting(root, target, dependencies2) {
29608
29774
  const existing = target.__codexhostHostRoutingV1;
29609
- if (existing)
29775
+ if (existing) {
29776
+ dependencies2.installQueuePolicy(root, target);
29610
29777
  return existing;
29778
+ }
29611
29779
  let disposed = false;
29612
29780
  let discovery = null;
29613
29781
  const routes = /* @__PURE__ */ new Map();
@@ -29622,6 +29790,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
29622
29790
  };
29623
29791
  if (!read())
29624
29792
  return null;
29793
+ const queuePolicy = dependencies2.installQueuePolicy(root, target);
29625
29794
  const isRecord22 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
29626
29795
  const externalDrafts = /* @__PURE__ */ new Map();
29627
29796
  const selectedModels = /* @__PURE__ */ new Map();
@@ -29872,6 +30041,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
29872
30041
  selectedModels.clear();
29873
30042
  if (port.postMessage === postMessage)
29874
30043
  port.postMessage = originalPostMessage;
30044
+ queuePolicy?.dispose();
29875
30045
  if (target.__codexhostHostRoutingV1 === routing) {
29876
30046
  delete target.__codexhostHostRoutingV1;
29877
30047
  publish(null);
@@ -29915,13 +30085,24 @@ function directRendererInstaller() {
29915
30085
  : (composer ?? document);
29916
30086
  return discover(source);
29917
30087
  },
30088
+ installQueuePolicy: (root, target) => (${installRendererExternalQueuePolicy.toString()})(root, target, {
30089
+ findStore: ${findRendererAppScopeStore.toString()},
30090
+ usesExternalQueue: ${rendererHostRpcUsesExternalQueue.toString()},
30091
+ portPrototype: MessagePort.prototype,
30092
+ }),
29918
30093
  portPrototype: MessagePort.prototype,
29919
30094
  });
29920
30095
  // Desktop 26.1027 moved AppServerManagers to the main process. Older builds
29921
30096
  // expose native managers in Renderer hook state; the main-process mode only
29922
30097
  // applies when none is visible and its per-Host RPC store is identified.
29923
30098
  const routing = (() => {
29924
- if (window.__codexhostHostRoutingV1) return window.__codexhostHostRoutingV1;
30099
+ if (window.__codexhostHostRoutingV1) {
30100
+ const existing = window.__codexhostHostRoutingV1;
30101
+ if (['local', ...(existing.knownHostIds?.() ?? [])].some(
30102
+ hostId => existing.forHost(hostId)?.manager.kind === 'main-process-rpc'
30103
+ )) installRpc();
30104
+ return existing;
30105
+ }
29925
30106
  const native = discover(document);
29926
30107
  if (native.managers.length || native.registries.length) return installNative();
29927
30108
  const rpc = installRpc();
@@ -33776,7 +33957,7 @@ function externalThreadValue(input) {
33776
33957
  thread_spawn: {
33777
33958
  parent_thread_id: record5.subagent.parentHostThreadId,
33778
33959
  depth: 1,
33779
- agent_path: null,
33960
+ agent_path: record5.title || record5.subagent.role || record5.subagent.nativeSubagentId,
33780
33961
  agent_nickname: record5.title || null,
33781
33962
  agent_role: record5.subagent.role ?? null
33782
33963
  }
@@ -35697,8 +35878,8 @@ var ExternalThreadRuntime = class {
35697
35878
  async #locate(threadId2) {
35698
35879
  const loaded = this.#threads.get(threadId2);
35699
35880
  if (loaded) {
35700
- const failure2 = this.idleRelease.failure(loaded);
35701
- if (failure2) return { kind: "error", error: { code: -32075, message: failure2 } };
35881
+ const failure3 = this.idleRelease.failure(loaded);
35882
+ if (failure3) return { kind: "error", error: { code: -32075, message: failure3 } };
35702
35883
  return { kind: "external", record: loaded.record, thread: loaded };
35703
35884
  }
35704
35885
  let record5;
@@ -35758,8 +35939,8 @@ var ExternalThreadRuntime = class {
35758
35939
  message: "External Session changed during recovery; retry the request"
35759
35940
  };
35760
35941
  }
35761
- const failure2 = this.idleRelease.failure(thread);
35762
- if (failure2) return { code: -32075, message: failure2 };
35942
+ const failure3 = this.idleRelease.failure(thread);
35943
+ if (failure3) return { code: -32075, message: failure3 };
35763
35944
  if (thread.sessionUnavailable && this.#idleForRestore(thread)) {
35764
35945
  const revived = await this.#reviveIdleSession(thread);
35765
35946
  if (revived) return revived;
@@ -35922,11 +36103,11 @@ var ExternalThreadRuntime = class {
35922
36103
  );
35923
36104
  return null;
35924
36105
  } catch (error51) {
35925
- const failure2 = error51 instanceof Error ? error51 : new Error(errorMessage3(error51));
35926
- thread.persistenceError = failure2;
35927
- thread.stateObserver.fault(failure2);
36106
+ const failure3 = error51 instanceof Error ? error51 : new Error(errorMessage3(error51));
36107
+ thread.persistenceError = failure3;
36108
+ thread.stateObserver.fault(failure3);
35928
36109
  this.#diagnose("External Turn identity could not be persisted");
35929
- return failure2;
36110
+ return failure3;
35930
36111
  }
35931
36112
  }
35932
36113
  async #restore(record5) {
@@ -36083,6 +36264,10 @@ var ExternalThreadQueue = class {
36083
36264
  has(threadId2) {
36084
36265
  return (this.#queues.get(threadId2)?.length ?? 0) > 0;
36085
36266
  }
36267
+ peek(threadId2) {
36268
+ const item = this.#queues.get(threadId2)?.[0];
36269
+ return item ? publicSubmission(item) : void 0;
36270
+ }
36086
36271
  list(threadId2, params) {
36087
36272
  const items = this.#queues.get(threadId2) ?? [];
36088
36273
  const start = params.cursor == null ? 0 : Number(params.cursor);
@@ -36230,6 +36415,30 @@ async function resolveExternalCommand(commands, text, options2 = {}) {
36230
36415
  };
36231
36416
  }
36232
36417
 
36418
+ // packages/host-runtime/src/external-thread-follow-up-queue.ts
36419
+ function isRecord15(value2) {
36420
+ return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
36421
+ }
36422
+ function queuedSubmissionText(input) {
36423
+ return input.filter(isRecord15).map((item) => item.text).filter((value2) => typeof value2 === "string" && value2.length > 0).join("\n");
36424
+ }
36425
+ function queuedSubmissionInput(input) {
36426
+ return input.map((entry) => {
36427
+ if (!isRecord15(entry) || typeof entry.text !== "string" || entry.text.length === 0) {
36428
+ return entry;
36429
+ }
36430
+ if (entry.type === "input_text") {
36431
+ return {
36432
+ type: "text",
36433
+ text: entry.text,
36434
+ text_elements: Array.isArray(entry.text_elements) ? entry.text_elements : []
36435
+ };
36436
+ }
36437
+ if (entry.type !== "text" || Array.isArray(entry.text_elements)) return entry;
36438
+ return { ...entry, text_elements: [] };
36439
+ });
36440
+ }
36441
+
36233
36442
  // packages/host-runtime/src/external-turn-steering.ts
36234
36443
  function isHarnessCommand(thread, text) {
36235
36444
  return thread.session.commands !== void 0 && isExternalCommandCandidate(restoreHarnessCommandMentions(text));
@@ -36241,6 +36450,13 @@ function externalSteeringDelivery(thread, text) {
36241
36450
  }
36242
36451
  return thread.session.capabilities.steer === true ? "activeTurn" : "newTurn";
36243
36452
  }
36453
+ async function sessionCanNativeSteer(thread) {
36454
+ if (thread.session.readCapabilities) {
36455
+ const capabilities = await thread.session.readCapabilities();
36456
+ return capabilities.steer === true;
36457
+ }
36458
+ return thread.session.capabilities.steer === true;
36459
+ }
36244
36460
  var ExternalSteerError = class extends Error {
36245
36461
  constructor(code, message2) {
36246
36462
  super(message2);
@@ -36257,14 +36473,17 @@ function parseInput(params) {
36257
36473
  if (typeof params.expectedTurnId !== "string" || !params.expectedTurnId.trim()) {
36258
36474
  throw new ExternalSteerError(-32602, "External steering requires expectedTurnId");
36259
36475
  }
36260
- if (!Array.isArray(params.input) || params.input.length === 0 || params.input.some(
36261
- (item) => !item || typeof item !== "object" || Array.isArray(item) || item.type !== "text" || typeof item.text !== "string"
36262
- )) {
36476
+ const input = Array.isArray(params.input) ? queuedSubmissionInput(params.input) : [];
36477
+ const textItems = input.filter(
36478
+ (item) => item !== null && typeof item === "object" && !Array.isArray(item) && typeof item.text === "string" && (item.type === void 0 || item.type === "text" || item.type === "input_text")
36479
+ );
36480
+ if (input.length === 0 || textItems.length !== input.length) {
36263
36481
  throw new ExternalSteerError(-32602, "External steering requires text input");
36264
36482
  }
36265
- const text = params.input.map((item) => item.text).join("\n");
36266
- if (!text.trim())
36483
+ const text = queuedSubmissionText(textItems);
36484
+ if (!text.trim()) {
36267
36485
  throw new ExternalSteerError(-32602, "External steering input must not be empty");
36486
+ }
36268
36487
  const clientUserMessageId = params.clientUserMessageId;
36269
36488
  if (clientUserMessageId != null && (typeof clientUserMessageId !== "string" || !clientUserMessageId.trim())) {
36270
36489
  throw new ExternalSteerError(-32602, "External steering message identity is invalid");
@@ -36397,18 +36616,18 @@ var ExternalTurnSteering = class {
36397
36616
  });
36398
36617
  };
36399
36618
  if (typeof delivery === "string") return deliver(delivery);
36400
- const failure2 = Promise.withResolvers();
36619
+ const failure3 = Promise.withResolvers();
36401
36620
  let failureReason = null;
36402
36621
  const pending = {
36403
36622
  turnId: input.expectedTurnId,
36404
36623
  resolve: () => void 0,
36405
36624
  reject(error51) {
36406
36625
  failureReason ??= error51;
36407
- failure2.reject(error51);
36626
+ failure3.reject(error51);
36408
36627
  }
36409
36628
  };
36410
36629
  this.#pending.set(thread.id, pending);
36411
- return Promise.race([delivery, failure2.promise]).then((mode) => {
36630
+ return Promise.race([delivery, failure3.promise]).then((mode) => {
36412
36631
  if (failureReason) throw failureReason;
36413
36632
  if (this.#pending.get(thread.id) === pending) this.#pending.delete(thread.id);
36414
36633
  return deliver(mode);
@@ -36445,14 +36664,14 @@ var ExternalTurnSteering = class {
36445
36664
  if (!turnId)
36446
36665
  throw new ExternalSteerError(-32074, "External steering must reference the active Turn");
36447
36666
  const terminal3 = Promise.withResolvers();
36448
- const failure2 = Promise.withResolvers();
36667
+ const failure3 = Promise.withResolvers();
36449
36668
  let failureReason = null;
36450
36669
  const pending = {
36451
36670
  turnId: input.expectedTurnId,
36452
36671
  resolve: terminal3.resolve,
36453
36672
  reject(error51) {
36454
36673
  failureReason ??= error51;
36455
- failure2.reject(error51);
36674
+ failure3.reject(error51);
36456
36675
  }
36457
36676
  };
36458
36677
  this.#pending.set(thread.id, pending);
@@ -36468,12 +36687,12 @@ var ExternalTurnSteering = class {
36468
36687
  try {
36469
36688
  const cancelled = await Promise.race([
36470
36689
  thread.session.execute({ type: "turn.cancel", turnId }),
36471
- failure2.promise
36690
+ failure3.promise
36472
36691
  ]);
36473
36692
  if (!cancelled.ok && cancelled.error.code !== "invalidState") {
36474
36693
  throw new ExternalSteerError(-32074, cancelled.error.message);
36475
36694
  }
36476
- const outcome = await Promise.race([terminal3.promise, failure2.promise]);
36695
+ const outcome = await Promise.race([terminal3.promise, failure3.promise]);
36477
36696
  clearTimeout(timeout);
36478
36697
  const assertActive = () => {
36479
36698
  if (failureReason) throw failureReason;
@@ -36537,7 +36756,7 @@ import { createHash as createHash7 } from "node:crypto";
36537
36756
  var CURSOR_PREFIX = "codexhost:thread-messages:v1:";
36538
36757
  var DEFAULT_MESSAGE_LIMIT = 25;
36539
36758
  var MAX_MESSAGE_LIMIT = 100;
36540
- function isRecord15(value2) {
36759
+ function isRecord16(value2) {
36541
36760
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
36542
36761
  }
36543
36762
  function stringValue(value2) {
@@ -36546,12 +36765,12 @@ function stringValue(value2) {
36546
36765
  function textFromUserItem(item) {
36547
36766
  if (!Array.isArray(item.content)) return "";
36548
36767
  return item.content.flatMap(
36549
- (part) => isRecord15(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []
36768
+ (part) => isRecord16(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []
36550
36769
  ).join("\n");
36551
36770
  }
36552
36771
  function threadStatus(value2, running) {
36553
36772
  if (running) return "running";
36554
- if (isRecord15(value2)) {
36773
+ if (isRecord16(value2)) {
36555
36774
  if (value2.type === "active") return "running";
36556
36775
  }
36557
36776
  return "completed";
@@ -36568,10 +36787,10 @@ function allVisibleMessages(turns) {
36568
36787
  const turnId = stringValue(turn.id);
36569
36788
  if (!turnId || !Array.isArray(turn.items)) continue;
36570
36789
  const agentItems = turn.items.filter(
36571
- (item) => isRecord15(item) && item.type === "agentMessage"
36790
+ (item) => isRecord16(item) && item.type === "agentMessage"
36572
36791
  );
36573
36792
  for (const item of turn.items) {
36574
- if (!isRecord15(item)) continue;
36793
+ if (!isRecord16(item)) continue;
36575
36794
  const id2 = stringValue(item.id);
36576
36795
  if (!id2) continue;
36577
36796
  if (item.type === "userMessage") {
@@ -36646,7 +36865,7 @@ function projectDelegationThreadSnapshot(input) {
36646
36865
  const progress = latestTurnMessages.filter((message2) => message2.phase !== "final" && message2.text.trim()).map(({ id: id2, turnId, text }) => ({ id: id2, turnId, text }));
36647
36866
  const result = input.running ? { availability: "pending" } : final ? { availability: "available", text: final.text } : {
36648
36867
  availability: "unavailable",
36649
- ...isRecord15(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
36868
+ ...isRecord16(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
36650
36869
  };
36651
36870
  const offset = options2.view === "messages" ? decodeCursor(input.threadId, options2.cursor) : visible.length;
36652
36871
  const page = options2.view === "messages" ? [] : void 0;
@@ -39403,10 +39622,10 @@ async function loadHarnessPlugins(options2) {
39403
39622
  ...manifest.notice ? { notice: manifest.notice } : {}
39404
39623
  });
39405
39624
  let adapter;
39406
- let failure2;
39625
+ let failure3;
39407
39626
  if (manifest.adapterApiVersion !== HARNESS_PLUGIN_API_VERSION) {
39408
- failure2 = "incompatibleVersion";
39409
- adapter = unavailableAdapter(descriptor, failure2);
39627
+ failure3 = "incompatibleVersion";
39628
+ adapter = unavailableAdapter(descriptor, failure3);
39410
39629
  } else {
39411
39630
  try {
39412
39631
  if (manifest.icon) descriptor.icon = await readPluginIcon(candidate.root, manifest.icon);
@@ -39425,11 +39644,11 @@ async function loadHarnessPlugins(options2) {
39425
39644
  }
39426
39645
  } catch (error51) {
39427
39646
  if (error51 instanceof PluginLoadCancelled) return;
39428
- failure2 = error51 instanceof PluginLoadTimeout ? "loadTimeout" : "loadFailed";
39429
- adapter = unavailableAdapter(descriptor, failure2);
39647
+ failure3 = error51 instanceof PluginLoadTimeout ? "loadTimeout" : "loadFailed";
39648
+ adapter = unavailableAdapter(descriptor, failure3);
39430
39649
  }
39431
39650
  }
39432
- if (failure2) diagnose({ id: manifest.id, code: failure2 });
39651
+ if (failure3) diagnose({ id: manifest.id, code: failure3 });
39433
39652
  loaded.set(candidate, { descriptor, adapter });
39434
39653
  }
39435
39654
  };
@@ -39606,11 +39825,11 @@ function spawnOfficialAppServerConnection(input) {
39606
39825
  }
39607
39826
 
39608
39827
  // packages/host-runtime/src/account/codex-account-control.ts
39609
- function isRecord16(value2) {
39828
+ function isRecord17(value2) {
39610
39829
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
39611
39830
  }
39612
39831
  function currentCodexAccountFromOfficialRead(result) {
39613
- if (!isRecord16(result) || !isRecord16(result.account) || result.account.type !== "chatgpt") {
39832
+ if (!isRecord17(result) || !isRecord17(result.account) || result.account.type !== "chatgpt") {
39614
39833
  return null;
39615
39834
  }
39616
39835
  const email3 = external_exports.string().email().max(320).safeParse(result.account.email);
@@ -39646,7 +39865,7 @@ import { randomUUID as randomUUID18 } from "node:crypto";
39646
39865
  import { randomUUID as randomUUID17 } from "node:crypto";
39647
39866
  var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
39648
39867
  var MAX_RETIRED_IDS = 1024;
39649
- function isRecord17(value2) {
39868
+ function isRecord18(value2) {
39650
39869
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
39651
39870
  }
39652
39871
  var OfficialRequestBroker = class {
@@ -39689,7 +39908,7 @@ var OfficialRequestBroker = class {
39689
39908
  });
39690
39909
  }
39691
39910
  handle(value2) {
39692
- if (!isRecord17(value2) || typeof value2.id !== "string") return false;
39911
+ if (!isRecord18(value2) || typeof value2.id !== "string") return false;
39693
39912
  const pending = this.#pending.get(value2.id);
39694
39913
  if (!pending) return this.#retired.has(value2.id);
39695
39914
  clearTimeout(pending.timeout);
@@ -40467,11 +40686,11 @@ function createOwnedConnectionBackend(factory) {
40467
40686
  }
40468
40687
 
40469
40688
  // packages/host-runtime/src/route-observation.ts
40470
- function isRecord18(value2) {
40689
+ function isRecord19(value2) {
40471
40690
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
40472
40691
  }
40473
40692
  function classifyThreadPurpose(request) {
40474
- return isRecord18(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
40693
+ return isRecord19(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
40475
40694
  }
40476
40695
  var RequestRouteObservationTracker = class {
40477
40696
  #nextCreateOrdinal = 0;
@@ -40496,13 +40715,13 @@ var RequestRouteObservationTracker = class {
40496
40715
  this.#createByThreadId.set(threadId2, tracked);
40497
40716
  }
40498
40717
  bindOfficialResponse(response) {
40499
- if (!isRecord18(response) || !("id" in response)) return;
40718
+ if (!isRecord19(response) || !("id" in response)) return;
40500
40719
  const tracked = this.#pendingByRequestId.get(response.id);
40501
40720
  if (!tracked) return;
40502
40721
  this.#pendingByRequestId.delete(response.id);
40503
40722
  const result = response.result;
40504
- const thread = isRecord18(result) ? result.thread : null;
40505
- if (isRecord18(thread) && typeof thread.id === "string") {
40723
+ const thread = isRecord19(result) ? result.thread : null;
40724
+ if (isRecord19(thread) && typeof thread.id === "string") {
40506
40725
  this.#createByThreadId.set(thread.id, tracked);
40507
40726
  }
40508
40727
  }
@@ -40720,11 +40939,11 @@ var OfficialThreadListError = class extends Error {
40720
40939
  }
40721
40940
  rpcError;
40722
40941
  };
40723
- function isRecord19(value2) {
40942
+ function isRecord20(value2) {
40724
40943
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
40725
40944
  }
40726
40945
  function officialThreadListPageFromResponse(response) {
40727
- if (isRecord19(response.error)) {
40946
+ if (isRecord20(response.error)) {
40728
40947
  if (!Number.isSafeInteger(response.error.code) || typeof response.error.message !== "string") {
40729
40948
  throw new Error("Official thread/list error response is invalid");
40730
40949
  }
@@ -41129,30 +41348,6 @@ function externalThreadEmptyOfficialResult(method) {
41129
41348
  return EMPTY_RESULTS.get(method)?.();
41130
41349
  }
41131
41350
 
41132
- // packages/host-runtime/src/external-thread-follow-up-queue.ts
41133
- function isRecord20(value2) {
41134
- return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
41135
- }
41136
- function queuedSubmissionText(input) {
41137
- return input.filter(isRecord20).map((item) => item.text).filter((value2) => typeof value2 === "string" && value2.length > 0).join("\n");
41138
- }
41139
- function queuedSubmissionInput(input) {
41140
- return input.map((entry) => {
41141
- if (!isRecord20(entry) || typeof entry.text !== "string" || entry.text.length === 0) {
41142
- return entry;
41143
- }
41144
- if (entry.type === "input_text") {
41145
- return {
41146
- type: "text",
41147
- text: entry.text,
41148
- text_elements: Array.isArray(entry.text_elements) ? entry.text_elements : []
41149
- };
41150
- }
41151
- if (entry.type !== "text" || Array.isArray(entry.text_elements)) return entry;
41152
- return { ...entry, text_elements: [] };
41153
- });
41154
- }
41155
-
41156
41351
  // packages/host-runtime/src/observed-session-usage.ts
41157
41352
  var ObservedSessionUsage = class {
41158
41353
  constructor(providers, prices, diagnose) {
@@ -41494,6 +41689,7 @@ var AppServerHost = class {
41494
41689
  #externalVoiceResults = new ExternalVoiceResults(
41495
41690
  (threadId2, text) => this.#externalVoice.reportProgress(threadId2, text)
41496
41691
  );
41692
+ #injectingQueuedFollowUp = /* @__PURE__ */ new Set();
41497
41693
  #externalQueue = new ExternalThreadQueue({
41498
41694
  notifyChanged: (threadId2) => this.#writer.json({ method: "thread/queue/changed", params: { threadId: threadId2 } })
41499
41695
  });
@@ -42153,6 +42349,39 @@ var AppServerHost = class {
42153
42349
  }
42154
42350
  return;
42155
42351
  }
42352
+ if ([
42353
+ THREAD_ACTIVITY_LIST_METHOD,
42354
+ THREAD_ACTIVITY_READ_METHOD,
42355
+ THREAD_ACTIVITY_STOP_METHOD
42356
+ ].includes(request.method)) {
42357
+ const parsed2 = (request.method === THREAD_ACTIVITY_LIST_METHOD ? threadActivityParamsSchema : threadActivityItemParamsSchema).safeParse(request.params);
42358
+ if (!parsed2.success) {
42359
+ await this.#writer.json(rpcError(request, -32602, "Invalid background activity request"));
42360
+ return;
42361
+ }
42362
+ await this.#externalRuntime.idleRelease.runOperation(parsed2.data.threadId, async () => {
42363
+ const resolution = await this.#resolveExternalThread(parsed2.data.threadId);
42364
+ if (await this.#writeResolutionError(request, resolution)) return;
42365
+ if (resolution.kind !== "external") {
42366
+ await this.#writer.json(
42367
+ request.method === THREAD_ACTIVITY_LIST_METHOD ? rpcEnvelope(request, { result: { supported: false, activities: [] } }) : rpcError(request, -32076, "Background activity is unsupported")
42368
+ );
42369
+ return;
42370
+ }
42371
+ const thread = resolution.thread;
42372
+ const result = await executeExternalActivity({
42373
+ session: thread.session,
42374
+ method: request.method,
42375
+ ..."activityId" in parsed2.data ? { activityId: String(parsed2.data.activityId) } : {},
42376
+ isCurrent: () => this.#externalRuntime.get(thread.id) === thread,
42377
+ materialize: (child) => this.#materializeSubagent(thread, child)
42378
+ });
42379
+ await this.#writer.json(
42380
+ result.error ? rpcError(request, result.error.code, result.error.message) : rpcEnvelope(request, { result: jsonValueSchema.parse(result.result) })
42381
+ );
42382
+ });
42383
+ return;
42384
+ }
42156
42385
  if (request.method === THREAD_QUESTIONS_LIST_METHOD || request.method === THREAD_QUESTION_RESPOND_METHOD || request.method === THREAD_QUESTION_ACTIVITY_METHOD) {
42157
42386
  await this.#handleSharedQuestionRequest(request);
42158
42387
  return;
@@ -43046,8 +43275,8 @@ var AppServerHost = class {
43046
43275
  })
43047
43276
  );
43048
43277
  } catch (error51) {
43049
- const failure2 = codexAccountRpcError(error51);
43050
- await this.#writer.json(rpcError(request, failure2.code, failure2.message));
43278
+ const failure3 = codexAccountRpcError(error51);
43279
+ await this.#writer.json(rpcError(request, failure3.code, failure3.message));
43051
43280
  }
43052
43281
  }
43053
43282
  async #observeOfficialTurnLifecycle(value2) {
@@ -45231,6 +45460,38 @@ var AppServerHost = class {
45231
45460
  throw error51;
45232
45461
  }
45233
45462
  }
45463
+ /** Pending rows remain editable until a tool/model boundary hands them to native steering. */
45464
+ async #injectQueuedFollowUp(thread, turnId) {
45465
+ if (this.#injectingQueuedFollowUp.has(thread.id)) return;
45466
+ this.#injectingQueuedFollowUp.add(thread.id);
45467
+ try {
45468
+ while (thread.running && thread.activeTurnId === turnId && this.#externalQueue.has(thread.id) && !this.#externalSteering.hasPending(thread.id)) {
45469
+ if (!await sessionCanNativeSteer(thread)) return;
45470
+ if (!thread.running || thread.activeTurnId !== turnId) return;
45471
+ const peeked = this.#externalQueue.peek(thread.id);
45472
+ if (!peeked) return;
45473
+ const text = queuedSubmissionText(peeked.input);
45474
+ if (!text.trim() || thread.session.commands && isExternalCommandCandidate(text)) return;
45475
+ const taken = this.#externalQueue.take(thread.id, peeked.id);
45476
+ try {
45477
+ await this.#insertExternalInput(thread, {
45478
+ turnId,
45479
+ text,
45480
+ clientUserMessageId: taken.submission.clientUserMessageId
45481
+ });
45482
+ await this.#externalQueue.notifyChanged(thread.id);
45483
+ } catch (error51) {
45484
+ this.#externalQueue.restore(thread.id, taken);
45485
+ await this.#externalQueue.notifyChanged(thread.id);
45486
+ throw error51;
45487
+ }
45488
+ }
45489
+ } catch (error51) {
45490
+ this.#diagnose(error51);
45491
+ } finally {
45492
+ this.#injectingQueuedFollowUp.delete(thread.id);
45493
+ }
45494
+ }
45234
45495
  /** Desktop leaves queued follow-ups to the app-server once a Turn completes normally. */
45235
45496
  async #drainExternalQueue(thread) {
45236
45497
  if (!this.#externalQueue.has(thread.id) || this.#externalThreadBusy(thread) || this.#pendingExternalCommandRequests.has(thread.id))
@@ -45277,26 +45538,37 @@ var AppServerHost = class {
45277
45538
  }
45278
45539
  }
45279
45540
  /** Native same-Turn input; `insertNativeSteer` owns the delivery and its fallback signal. */
45541
+ async #projectQueuedSteer(thread, turnId, text, clientUserMessageId) {
45542
+ const item = {
45543
+ type: "userMessage",
45544
+ itemId: hostItemIdSchema.parse(randomUUID19()),
45545
+ input: [{ type: "text", text }]
45546
+ };
45547
+ const projection = this.#projectedTurn(thread, turnId);
45548
+ if (clientUserMessageId) {
45549
+ projection.projector.bindUserMessageClientId(item.itemId, clientUserMessageId);
45550
+ }
45551
+ await this.#projectHarnessOutput(thread, {
45552
+ kind: "event",
45553
+ event: { type: "item.started", turnId, item }
45554
+ });
45555
+ await this.#projectHarnessOutput(thread, {
45556
+ kind: "event",
45557
+ event: {
45558
+ type: "item.completed",
45559
+ turnId,
45560
+ snapshot: { item, outcome: { status: "succeeded" } }
45561
+ }
45562
+ });
45563
+ }
45280
45564
  async #insertExternalInput(thread, input) {
45281
45565
  await insertNativeSteer(thread, input, {
45282
- project: async (turnId, item, clientUserMessageId) => {
45283
- const projection = this.#projectedTurn(thread, turnId);
45284
- if (clientUserMessageId) {
45285
- projection.projector.bindUserMessageClientId(item.itemId, clientUserMessageId);
45286
- }
45287
- await this.#projectHarnessOutput(thread, {
45288
- kind: "event",
45289
- event: { type: "item.started", turnId, item }
45290
- });
45291
- await this.#projectHarnessOutput(thread, {
45292
- kind: "event",
45293
- event: {
45294
- type: "item.completed",
45295
- turnId,
45296
- snapshot: { item, outcome: { status: "succeeded" } }
45297
- }
45298
- });
45299
- },
45566
+ project: (turnId, item, clientUserMessageId) => this.#projectQueuedSteer(
45567
+ thread,
45568
+ turnId,
45569
+ item.input.map((part) => part.text).join("\n"),
45570
+ clientUserMessageId
45571
+ ),
45300
45572
  diagnose: (error51) => this.#diagnose(error51)
45301
45573
  });
45302
45574
  return {
@@ -45490,7 +45762,7 @@ var AppServerHost = class {
45490
45762
  thread,
45491
45763
  error51,
45492
45764
  (output) => this.#projectHarnessOutput(thread, output),
45493
- (failure2) => this.#diagnose(failure2)
45765
+ (failure3) => this.#diagnose(failure3)
45494
45766
  );
45495
45767
  } finally {
45496
45768
  this.#externalSteering.fault(
@@ -45767,6 +46039,9 @@ var AppServerHost = class {
45767
46039
  event,
45768
46040
  event.type === "turn.completed" ? result.completedTurn : void 0
45769
46041
  );
46042
+ if (event.type === "item.completed" && !ephemeralTurn && (event.snapshot.item.type === "commandExecution" || event.snapshot.item.type === "toolExecution" || event.snapshot.item.type === "agentMessage")) {
46043
+ await this.#injectQueuedFollowUp(thread, event.turnId);
46044
+ }
45770
46045
  if (event.type === "turn.completed") {
45771
46046
  await this.#setThreadStatus(
45772
46047
  thread,
@@ -47908,12 +48183,12 @@ var DelegationWatchService = class {
47908
48183
  await this.#api.send({ threadId: notifyThreadId, message: notification(pending) });
47909
48184
  for (const watch of pending) this.#remove(watch);
47910
48185
  } catch (error51) {
47911
- const failure2 = deliveryFailure(error51);
48186
+ const failure3 = deliveryFailure(error51);
47912
48187
  const message2 = error51 instanceof Error ? error51.message : String(error51);
47913
48188
  for (const watch of pending) {
47914
- if (failure2 !== "rejected" || Date.now() >= (watch.deliveryDeadline ?? 0)) {
48189
+ if (failure3 !== "rejected" || Date.now() >= (watch.deliveryDeadline ?? 0)) {
47915
48190
  watch.state = "undeliverable";
47916
- watch.reason = failure2 === "unknown" ? `Delivery outcome unknown; the notification may already have started a Turn, so it is not retried (${message2})` : message2;
48191
+ watch.reason = failure3 === "unknown" ? `Delivery outcome unknown; the notification may already have started a Turn, so it is not retried (${message2})` : message2;
47917
48192
  }
47918
48193
  }
47919
48194
  this.#trimUndeliverable();