@liberseek/boft-cli-linux-x64 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3716,8 +3716,10 @@ List Harnesses available in the active Runtime.`,
3716
3716
  "harness inspect": `boft harness inspect <harness> [--cwd <path>] [--refresh true|false] [--format json|compact]
3717
3717
  Read available Models, native defaults, Thinking options, and configuration capabilities.
3718
3718
  Use the returned Model and Thinking IDs for explicit selections.`,
3719
- "delegate start": `boft delegate start --harness <id> --task <text> [--cwd <path>] [--model <opaque-ref>] [--thinking <option-id>] [--parent-thread <thread>] [--request-id <id>] [--watch true|false] [--watch-timeout-ms <n>] [--format json|compact]
3719
+ "delegate start": `boft delegate start --harness <id> --task <text> [--task-name <name>] [--cwd <path>] [--model <opaque-ref>] [--thinking <option-id>] [--parent-thread <thread>] [--request-id <id>] [--watch true|false] [--watch-timeout-ms <n>] [--format json|compact]
3720
3720
  Create an independent child Thread, submit the task, and return immediately.
3721
+ --task-name supplies a short subtask name (1-120 characters); otherwise the first task line is used.
3722
+ The child title is "subtask name · parent title", fixed at creation; renaming the parent does not rename existing children.
3721
3723
  Omit --model and --thinking to use the Harness native defaults.
3722
3724
  --cwd overrides the child workspace. Otherwise use the resolved parent Thread workspace, then the Host Runtime process cwd.
3723
3725
  --parent-thread overrides caller inference. PARENT_THREAD_AMBIGUOUS requires an explicit parent.
@@ -4161,6 +4163,7 @@ async function runDelegationCli(input) {
4161
4163
  rejectUnknown(parsed2, [
4162
4164
  "--harness",
4163
4165
  "--task",
4166
+ "--task-name",
4164
4167
  "--cwd",
4165
4168
  "--model",
4166
4169
  "--thinking",
@@ -4195,6 +4198,7 @@ async function runDelegationCli(input) {
4195
4198
  body: {
4196
4199
  harnessId,
4197
4200
  task,
4201
+ ...value(parsed2, "--task-name") !== void 0 ? { taskName: value(parsed2, "--task-name") } : {},
4198
4202
  ...value(parsed2, "--cwd") ? { cwd: value(parsed2, "--cwd") } : {},
4199
4203
  ...value(parsed2, "--model") ? { model: { id: value(parsed2, "--model") } } : {},
4200
4204
  ...value(parsed2, "--thinking") ? { thinkingOptionId: value(parsed2, "--thinking") } : {},
@@ -20094,10 +20098,19 @@ var model = external_exports.string().min(1).max(512);
20094
20098
  var project = external_exports.string().min(1).max(4096);
20095
20099
  var usageStatisticsParamsSchema = external_exports.strictObject({
20096
20100
  range: external_exports.enum(USAGE_STATISTICS_RANGES),
20101
+ /** Display timezone for ranges, dates and hourly buckets; omitted means the Host's local zone. */
20102
+ timeZone: external_exports.string().min(1).max(128).refine((value2) => {
20103
+ try {
20104
+ new Intl.DateTimeFormat("en", { timeZone: value2 });
20105
+ return true;
20106
+ } catch {
20107
+ return false;
20108
+ }
20109
+ }, "Unsupported usage statistics timezone").optional(),
20097
20110
  harness: harness.optional(),
20098
20111
  model: model.nullable().optional(),
20099
20112
  project: project.nullable().optional(),
20100
- /** One local date inside the range. */
20113
+ /** One date in the query timezone inside the range. */
20101
20114
  date: localDate.optional()
20102
20115
  });
20103
20116
  var usageStatisticsTotalsSchema = external_exports.strictObject({
@@ -20133,7 +20146,7 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
20133
20146
  });
20134
20147
  var usageStatisticsResultSchema = external_exports.strictObject({
20135
20148
  range: external_exports.enum(USAGE_STATISTICS_RANGES),
20136
- /** First local date of the range; null for all time. */
20149
+ /** First date in the query timezone (Host local when omitted); null for all time. */
20137
20150
  from: localDate.nullable(),
20138
20151
  to: localDate,
20139
20152
  /** The filters these figures apply, echoed so a late answer to older filters is recognised. */
@@ -20173,7 +20186,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
20173
20186
  totals: usageStatisticsTotalsSchema,
20174
20187
  /** Each date and Harness of the range: every filter except the day. */
20175
20188
  daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
20176
- /** Local weekday (0 = Sunday) and hour, all filters applied. */
20189
+ /** Weekday (0 = Sunday) and hour in the query timezone, all filters applied. */
20177
20190
  hourly: external_exports.array(external_exports.strictObject({
20178
20191
  weekday: external_exports.number().int().min(0).max(6),
20179
20192
  hour: external_exports.number().int().min(0).max(23),
@@ -20319,6 +20332,8 @@ var CONSOLE_HOST_METHODS = Object.freeze([
20319
20332
  "codexhost/harness/display-settings/set",
20320
20333
  "codexhost/harness/inspect",
20321
20334
  "codexhost/harness/installation",
20335
+ "codexhost/harness/installation/start",
20336
+ "codexhost/harness/installation/status",
20322
20337
  "codexhost/harness/launch-settings/get",
20323
20338
  "codexhost/harness/launch-settings/set",
20324
20339
  HARNESS_LONG_CONTEXT_GET_METHOD,
@@ -20402,7 +20417,18 @@ var threadManualCompactionStartedSchema = external_exports.strictObject({
20402
20417
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
20403
20418
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
20404
20419
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
20420
+ var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text2) => text2.length <= maximum));
20421
+ var composerIndicatorsSchema = external_exports.array(external_exports.object({
20422
+ kind: external_exports.literal("countdown"),
20423
+ id: external_exports.string().min(1).max(64),
20424
+ expiresAtUnix: nonNegativeSafeIntegerSchema,
20425
+ label: indicatorTextSchema(256).optional(),
20426
+ tooltip: indicatorTextSchema(1024).optional()
20427
+ }).strict()).max(2).refine((entries) => new Set(entries.map(({ id: id2 }) => id2)).size === entries.length, {
20428
+ message: "Composer indicator IDs must be unique"
20429
+ });
20405
20430
  var threadUsageSnapshotSchema = external_exports.object({
20431
+ composerIndicators: composerIndicatorsSchema.optional(),
20406
20432
  inputTokens: nonNegativeSafeIntegerSchema.optional(),
20407
20433
  cachedInputTokens: nonNegativeSafeIntegerSchema.optional(),
20408
20434
  cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
@@ -20836,7 +20862,9 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
20836
20862
  }).strict().optional(),
20837
20863
  input: external_exports.object({
20838
20864
  image: external_exports.boolean()
20839
- }).strict().optional()
20865
+ }).strict().optional(),
20866
+ /** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
20867
+ steer: external_exports.boolean().optional()
20840
20868
  }).strict();
20841
20869
  var harnessConfigurationStateSchema = external_exports.object({
20842
20870
  effectiveModel: harnessModelRefSchema.optional(),
@@ -20884,7 +20912,9 @@ var harnessInspectionSchema = external_exports.union([
20884
20912
  var harnessInspectParamsSchema = external_exports.object({
20885
20913
  harnessId: harnessIdSchema,
20886
20914
  cwd: nonBlankTextSchema2.max(16384).optional(),
20887
- refresh: external_exports.boolean().optional()
20915
+ refresh: external_exports.boolean().optional(),
20916
+ /** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
20917
+ purpose: external_exports.literal("availability").optional()
20888
20918
  }).strict();
20889
20919
  var harnessWebUiOpenParamsSchema = external_exports.object({
20890
20920
  harnessId: harnessIdSchema
@@ -20969,6 +20999,16 @@ var threadOwnershipListResultSchema = external_exports.object({
20969
20999
  seen.add(thread.threadId);
20970
21000
  }
20971
21001
  });
21002
+ var threadSteeringInspectParamsSchema = external_exports.object({
21003
+ threadId: hostThreadIdSchema,
21004
+ /** The text about to be steered; a Harness command always stops and restarts. */
21005
+ text: external_exports.string().optional()
21006
+ }).strict();
21007
+ var THREAD_STEER_DELIVERY_PARAM = "codexhostSteerDelivery";
21008
+ var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
21009
+ var threadSteeringInspectResultSchema = external_exports.object({
21010
+ delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
21011
+ }).strict();
20972
21012
 
20973
21013
  // packages/shared-contracts/dist/harness-route.js
20974
21014
  var HARNESS_PLUGIN_ROUTE_PREFIX = "codexhost/plugin-v1@";
@@ -21019,6 +21059,8 @@ var harnessLaunchSettingsSchema = external_exports.object({
21019
21059
 
21020
21060
  // packages/shared-contracts/dist/harness-installation.js
21021
21061
  var HARNESS_INSTALLATION_METHOD = "codexhost/harness/installation";
21062
+ var HARNESS_INSTALLATION_START_METHOD = "codexhost/harness/installation/start";
21063
+ var HARNESS_INSTALLATION_STATUS_METHOD = "codexhost/harness/installation/status";
21022
21064
  var harnessInstallationParamsSchema = external_exports.object({
21023
21065
  harnessId: harnessIdSchema,
21024
21066
  action: external_exports.enum(["check", "update", "install"])
@@ -21028,6 +21070,10 @@ var harnessInstallationStateSchema = external_exports.object({
21028
21070
  latestVersion: external_exports.string().min(1).max(128),
21029
21071
  updateAvailable: external_exports.boolean(),
21030
21072
  canUpdate: external_exports.boolean(),
21073
+ /** Defaults to CLI; some Harnesses ship only inside a desktop application. */
21074
+ versionKind: external_exports.enum(["cli", "application"]).optional(),
21075
+ /** Official download opened by the user; does not imply an automatic installation. */
21076
+ manualUpdateUrl: external_exports.url().max(2048).refine((value2) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value2), "Manual updates require a credential-free HTTPS URL").optional(),
21031
21077
  // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
21032
21078
  message: external_exports.string().max(2048).optional(),
21033
21079
  messageCode: external_exports.string().min(1).max(128).optional(),
@@ -21035,6 +21081,20 @@ var harnessInstallationStateSchema = external_exports.object({
21035
21081
  notice: harnessLocalizedTextSchema.optional(),
21036
21082
  latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
21037
21083
  }).strict();
21084
+ var harnessInstallationTaskParamsSchema = external_exports.object({ taskId: external_exports.string().uuid() }).strict();
21085
+ var harnessInstallationTaskSchema = external_exports.discriminatedUnion("status", [
21086
+ external_exports.object({ taskId: external_exports.string().uuid(), status: external_exports.literal("running") }).strict(),
21087
+ external_exports.object({
21088
+ taskId: external_exports.string().uuid(),
21089
+ status: external_exports.literal("succeeded"),
21090
+ result: harnessInstallationStateSchema
21091
+ }).strict(),
21092
+ external_exports.object({
21093
+ taskId: external_exports.string().uuid(),
21094
+ status: external_exports.literal("failed"),
21095
+ error: external_exports.object({ code: external_exports.number().int(), message: external_exports.string().min(1).max(2048) }).strict()
21096
+ }).strict()
21097
+ ]);
21038
21098
 
21039
21099
  // packages/shared-contracts/dist/codex-accounts.js
21040
21100
  var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
@@ -23035,9 +23095,13 @@ function requestManagerFromHookState(value2, hostId2) {
23035
23095
  const direct = manager(value2) ?? manager(value2.manager);
23036
23096
  if (direct)
23037
23097
  return direct;
23038
- if (!hostId2 || typeof value2.addManager !== "function" || typeof value2.getForHostId !== "function" || typeof value2.waitForManagerForHostId !== "function")
23098
+ if (!hostId2 || typeof value2.addManager !== "function" || typeof value2.getForHostId !== "function")
23039
23099
  return null;
23040
- return manager(value2.getForHostId(hostId2));
23100
+ try {
23101
+ return manager(value2.getForHostId(hostId2));
23102
+ } catch {
23103
+ return null;
23104
+ }
23041
23105
  }
23042
23106
  function discoverRendererHosts(root, ancestors = committedReactAncestors, managerFrom = requestManagerFromHookState) {
23043
23107
  const editors = [
@@ -23073,7 +23137,7 @@ function discoverRendererHosts(root, ancestors = committedReactAncestors, manage
23073
23137
  const manager = managerFrom(value2);
23074
23138
  if (manager)
23075
23139
  managers.add(manager);
23076
- if (value2 && typeof value2 === "object" && "addManager" in value2 && typeof value2.addManager === "function" && "getForHostId" in value2 && typeof value2.getForHostId === "function" && "waitForManagerForHostId" in value2 && typeof value2.waitForManagerForHostId === "function") {
23140
+ if (value2 && typeof value2 === "object" && "addManager" in value2 && typeof value2.addManager === "function" && "getForHostId" in value2 && typeof value2.getForHostId === "function") {
23077
23141
  registries.add(value2);
23078
23142
  }
23079
23143
  hook = hook.next && typeof hook.next === "object" ? hook.next : null;
@@ -23089,7 +23153,13 @@ function discoverRendererHosts(root, ancestors = committedReactAncestors, manage
23089
23153
  function resolveRendererHostManager(discovery, hostId2, managerFrom = requestManagerFromHookState) {
23090
23154
  if (!hostId2)
23091
23155
  return null;
23092
- const candidates = discovery.registries.length ? discovery.registries.map((registry2) => managerFrom(registry2.getForHostId(hostId2))) : discovery.managers;
23156
+ const candidates = discovery.registries.length ? discovery.registries.flatMap((registry2) => {
23157
+ try {
23158
+ return [managerFrom(registry2.getForHostId(hostId2))];
23159
+ } catch {
23160
+ return [];
23161
+ }
23162
+ }) : discovery.managers;
23093
23163
  const matching = new Set(candidates.filter((manager) => manager && (manager.getHostId?.() ?? manager.requestClient.hostId) === hostId2 && (manager.requestClient.hostId === void 0 || manager.requestClient.hostId === hostId2)));
23094
23164
  return matching.size === 1 ? matching.values().next().value ?? null : null;
23095
23165
  }
@@ -24101,6 +24171,64 @@ async function handleHarnessInstallation(params, adapters) {
24101
24171
  }
24102
24172
  }
24103
24173
 
24174
+ // packages/host-runtime/src/harness-installation-tasks.ts
24175
+ import { randomUUID as randomUUID3 } from "node:crypto";
24176
+ var HarnessInstallationTasks = class {
24177
+ #tasks = /* @__PURE__ */ new Map();
24178
+ #active = /* @__PURE__ */ new Map();
24179
+ #prune() {
24180
+ const cutoff = Date.now() - 15 * 6e4;
24181
+ for (const [id2, task] of this.#tasks) {
24182
+ if (task.finishedAt !== void 0 && task.finishedAt < cutoff) this.#tasks.delete(id2);
24183
+ }
24184
+ }
24185
+ start(params, adapters) {
24186
+ const parsed2 = harnessInstallationParamsSchema.safeParse(params);
24187
+ if (!parsed2.success)
24188
+ throw new HarnessInstallationError(-32602, "Invalid Harness installation request");
24189
+ this.#prune();
24190
+ const key = JSON.stringify([parsed2.data.harnessId, parsed2.data.action]);
24191
+ const activeId = this.#active.get(key);
24192
+ const active = activeId ? this.#tasks.get(activeId) : void 0;
24193
+ if (active) return active.state;
24194
+ const taskId = randomUUID3();
24195
+ const task = {
24196
+ state: { taskId, status: "running" }
24197
+ };
24198
+ this.#tasks.set(taskId, task);
24199
+ this.#active.set(key, taskId);
24200
+ void handleHarnessInstallation(parsed2.data, adapters).then(
24201
+ (result) => {
24202
+ task.state = { taskId, status: "succeeded", result };
24203
+ },
24204
+ (error51) => {
24205
+ task.state = {
24206
+ taskId,
24207
+ status: "failed",
24208
+ error: error51 instanceof HarnessInstallationError ? { code: error51.code, message: error51.message } : { code: -32077, message: "Harness version management failed" }
24209
+ };
24210
+ }
24211
+ ).finally(() => {
24212
+ task.finishedAt = Date.now();
24213
+ this.#active.delete(key);
24214
+ });
24215
+ return task.state;
24216
+ }
24217
+ status(params) {
24218
+ const parsed2 = harnessInstallationTaskParamsSchema.safeParse(params);
24219
+ if (!parsed2.success)
24220
+ throw new HarnessInstallationError(-32602, "Invalid Harness installation task request");
24221
+ this.#prune();
24222
+ const task = this.#tasks.get(parsed2.data.taskId);
24223
+ if (!task)
24224
+ throw new HarnessInstallationError(
24225
+ -32079,
24226
+ "Harness installation task is unavailable on this Host"
24227
+ );
24228
+ return task.state;
24229
+ }
24230
+ };
24231
+
24104
24232
  // packages/host-runtime/src/harness-long-context.ts
24105
24233
  var HarnessLongContextError = class extends Error {
24106
24234
  constructor(code, message2) {
@@ -24226,7 +24354,7 @@ async function listOthers(adapter) {
24226
24354
  }
24227
24355
 
24228
24356
  // packages/host-runtime/src/harness-display-settings.ts
24229
- import { randomUUID as randomUUID3 } from "node:crypto";
24357
+ import { randomUUID as randomUUID4 } from "node:crypto";
24230
24358
  import { link, mkdir as mkdir6, readFile as readFile9, rename as rename4, rm as rm5, writeFile as writeFile6 } from "node:fs/promises";
24231
24359
  import os4 from "node:os";
24232
24360
  import path13 from "node:path";
@@ -24251,7 +24379,7 @@ var HarnessDisplaySettingsStore = class {
24251
24379
  async set(input) {
24252
24380
  const entries = harnessDisplayEntriesSchema.parse(input.entries);
24253
24381
  await mkdir6(path13.dirname(this.#file), { recursive: true, mode: 448 });
24254
- const temporary = `${this.#file}.${randomUUID3()}.tmp`;
24382
+ const temporary = `${this.#file}.${randomUUID4()}.tmp`;
24255
24383
  try {
24256
24384
  await writeFile6(temporary, `${JSON.stringify(entries)}
24257
24385
  `, { mode: 384, flag: "wx" });
@@ -24272,7 +24400,7 @@ var HarnessDisplaySettingsStore = class {
24272
24400
  };
24273
24401
 
24274
24402
  // packages/host-runtime/src/model-price-overrides-file.ts
24275
- import { randomUUID as randomUUID4 } from "node:crypto";
24403
+ import { randomUUID as randomUUID5 } from "node:crypto";
24276
24404
  import { mkdir as mkdir8, readFile as readFile11, rename as rename6, rm as rm6, writeFile as writeFile8 } from "node:fs/promises";
24277
24405
  import path15 from "node:path";
24278
24406
 
@@ -24847,7 +24975,7 @@ async function updateModelPriceOverridesFile(file2, change) {
24847
24975
  const updated = { ...document, models: next };
24848
24976
  parseModelPriceOverrides(updated);
24849
24977
  await mkdir8(path15.dirname(file2), { recursive: true });
24850
- const temporary = `${file2}.${randomUUID4()}.tmp`;
24978
+ const temporary = `${file2}.${randomUUID5()}.tmp`;
24851
24979
  try {
24852
24980
  await writeFile8(temporary, `${JSON.stringify(updated, null, 2)}
24853
24981
  `, { flag: "wx" });
@@ -24883,11 +25011,11 @@ async function handleModelPriceOverridesRequest(catalog, method, params) {
24883
25011
  }
24884
25012
 
24885
25013
  // packages/host-runtime/src/delegation-skill.ts
24886
- import { createHash as createHash4, randomUUID as randomUUID5 } from "node:crypto";
25014
+ import { createHash as createHash4, randomUUID as randomUUID6 } from "node:crypto";
24887
25015
  import { mkdir as mkdir9, open as open4, readFile as readFile12, rename as rename7, rm as rm7, stat as stat5 } from "node:fs/promises";
24888
25016
  import os6 from "node:os";
24889
25017
  import path16 from "node:path";
24890
- var SKILL_VERSION = 9;
25018
+ var SKILL_VERSION = 10;
24891
25019
  var DELEGATION_SKILL_NAME = "codexhost-delegation";
24892
25020
  var SKILL_RELATIVE_PATH = path16.join("skills", DELEGATION_SKILL_NAME, "SKILL.md");
24893
25021
  var PREVIOUS_MANAGED_DIGESTS = [
@@ -24904,7 +25032,9 @@ var PREVIOUS_MANAGED_DIGESTS = [
24904
25032
  "17a50fc087edce40c8ff61e1c28f36b815edf2f0d73c2925f5d29a9e88af6070",
24905
25033
  "b40666ca01c9c46caeb2c4d672cda628127616679d04dd735231f5fab6583e88",
24906
25034
  // v8, which ran a bare `codexhost` from PATH.
24907
- "ca06be59f0d47c9a54d05ed2d9588c9c737306cc155cb4dff3fe2a2a61891dde"
25035
+ "ca06be59f0d47c9a54d05ed2d9588c9c737306cc155cb4dff3fe2a2a61891dde",
25036
+ // v9, before the child-session name guidance.
25037
+ "b72a059e139bd5b93b95f7ac02ab80f428d5a721cc67b004210d5263e75baed7"
24908
25038
  ];
24909
25039
  var CODEXHOST_DELEGATION_SKILL = `---
24910
25040
  name: codexhost-delegation
@@ -24940,7 +25070,8 @@ Use the Harness native defaults. Inspect the target when a Model or Thinking
24940
25070
  selection is needed or the default is unavailable.
24941
25071
 
24942
25072
  For a new delegation, create an independent child session and submit the
24943
- requested task. For an existing external session, resolve the target from the
25073
+ requested task. Give it a short task name that tells it apart from sibling
25074
+ tasks, using the help's task-name option. For an existing external session, resolve the target from the
24944
25075
  user-provided session link, identifier, or context and operate on that Thread
24945
25076
  directly; it need not have been created by the current assistant. If the target
24946
25077
  is ambiguous, ask the user to identify it. Keep requests to view or summarize a
@@ -24982,7 +25113,7 @@ async function readOptional(filePath) {
24982
25113
  }
24983
25114
  async function atomicWrite(filePath, content) {
24984
25115
  await mkdir9(path16.dirname(filePath), { recursive: true, mode: 448 });
24985
- const temporaryPath = path16.join(path16.dirname(filePath), `.SKILL.md.${randomUUID5()}.tmp`);
25116
+ const temporaryPath = path16.join(path16.dirname(filePath), `.SKILL.md.${randomUUID6()}.tmp`);
24986
25117
  const handle = await open4(temporaryPath, "wx", 384);
24987
25118
  try {
24988
25119
  await handle.writeFile(content, "utf8");
@@ -25219,6 +25350,7 @@ var usageFields = /* @__PURE__ */ new Set([
25219
25350
  ...safeIntegerFields,
25220
25351
  ...percentFields,
25221
25352
  "sessionCacheUsage",
25353
+ "composerIndicators",
25222
25354
  "totalCostUsd",
25223
25355
  "totalCredits",
25224
25356
  "contextUsagePercent",
@@ -25241,6 +25373,7 @@ function parseHostUsage(value2) {
25241
25373
  throw new Error(`Harness Usage contains unknown field '${key}'`);
25242
25374
  }
25243
25375
  }
25376
+ const indicators = value2.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value2.composerIndicators) };
25244
25377
  for (const field of [
25245
25378
  "totalCredits",
25246
25379
  "contextUsagePercent",
@@ -25317,9 +25450,9 @@ function parseHostUsage(value2) {
25317
25450
  if (value2.costSource !== "publicPrice") {
25318
25451
  throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
25319
25452
  }
25320
- return { ...value2, unpricedModels: [...models] };
25453
+ return { ...value2, ...indicators, unpricedModels: [...models] };
25321
25454
  }
25322
- return { ...value2 };
25455
+ return { ...value2, ...indicators };
25323
25456
  }
25324
25457
  var requestTokenFields = [
25325
25458
  "inputTokens",
@@ -25470,7 +25603,7 @@ var packageMetadata = {
25470
25603
 
25471
25604
  // packages/mapping-store/dist/mapping-store.js
25472
25605
  import { execFileSync } from "node:child_process";
25473
- import { randomUUID as randomUUID8 } from "node:crypto";
25606
+ import { randomUUID as randomUUID9 } from "node:crypto";
25474
25607
  import { constants as constants3 } from "node:fs";
25475
25608
  import { copyFile as copyFile3, mkdir as mkdir11, open as open7, readFile as readFile15, readdir as readdir4, rename as rename10, rm as rm10, stat as stat6 } from "node:fs/promises";
25476
25609
  import path18 from "node:path";
@@ -25532,7 +25665,7 @@ var storedThreadMetadataV1Schema = external_exports.object({
25532
25665
  formatVersion: external_exports.literal(1),
25533
25666
  hostThreadId: storedHostThreadIdSchema,
25534
25667
  ...storedThreadMetadataFieldsShape
25535
- }).strict();
25668
+ }).passthrough();
25536
25669
  function refineThreadRecord(record4, context) {
25537
25670
  if (record4.state === "ready" && !record4.nativeSessionRef) {
25538
25671
  context.addIssue({
@@ -25591,8 +25724,8 @@ function refineThreadRecord(record4, context) {
25591
25724
  }
25592
25725
  }
25593
25726
  }
25594
- var storedThreadCoreV1Schema = external_exports.object(storedThreadCoreV1Shape).strict().superRefine(refineThreadRecord);
25595
- var storedThreadRecordV1Schema = external_exports.object({ ...storedThreadCoreV1Shape, ...storedThreadMetadataFieldsShape }).strict().superRefine(refineThreadRecord);
25727
+ var storedThreadCoreV1Schema = external_exports.object(storedThreadCoreV1Shape).passthrough().superRefine(refineThreadRecord);
25728
+ var storedThreadRecordV1Schema = external_exports.object({ ...storedThreadCoreV1Shape, ...storedThreadMetadataFieldsShape }).passthrough().superRefine(refineThreadRecord);
25596
25729
  var delegationStatusSchema = external_exports.enum([
25597
25730
  "creating",
25598
25731
  "running",
@@ -25619,7 +25752,7 @@ var storedDelegationRecordV1Schema = external_exports.object({
25619
25752
  });
25620
25753
 
25621
25754
  // packages/mapping-store/dist/section-placements.js
25622
- import { randomUUID as randomUUID6 } from "node:crypto";
25755
+ import { randomUUID as randomUUID7 } from "node:crypto";
25623
25756
  import { constants } from "node:fs";
25624
25757
  import { open as open5, readFile as readFile13, rename as rename8, rm as rm8 } from "node:fs/promises";
25625
25758
  var threadIdSchema = external_exports.string().min(1).max(1024);
@@ -25671,7 +25804,7 @@ async function readSectionPlacementsFile(file2) {
25671
25804
  }
25672
25805
  async function writeSectionPlacementsFile(file2, placements) {
25673
25806
  const parsed2 = parseSectionPlacements({ formatVersion: 1, placements });
25674
- const temp = `${file2}.tmp-${randomUUID6()}`;
25807
+ const temp = `${file2}.tmp-${randomUUID7()}`;
25675
25808
  let handle = null;
25676
25809
  try {
25677
25810
  handle = await open5(temp, "wx", constants.S_IRUSR | constants.S_IWUSR);
@@ -25690,7 +25823,7 @@ async function writeSectionPlacementsFile(file2, placements) {
25690
25823
  }
25691
25824
 
25692
25825
  // packages/mapping-store/dist/superseded-sessions.js
25693
- import { randomUUID as randomUUID7 } from "node:crypto";
25826
+ import { randomUUID as randomUUID8 } from "node:crypto";
25694
25827
  import { constants as constants2 } from "node:fs";
25695
25828
  import { mkdir as mkdir10, open as open6, readFile as readFile14, rename as rename9, rm as rm9 } from "node:fs/promises";
25696
25829
  import path17 from "node:path";
@@ -25725,7 +25858,7 @@ async function writeSupersededSessionsFile(file2, sessions) {
25725
25858
  formatVersion: 1,
25726
25859
  sessions: sessions.slice(-SUPERSEDED_SESSIONS_MAX)
25727
25860
  }).sessions;
25728
- const temp = `${file2}.tmp-${randomUUID7()}`;
25861
+ const temp = `${file2}.tmp-${randomUUID8()}`;
25729
25862
  let handle = null;
25730
25863
  try {
25731
25864
  await mkdir10(path17.dirname(file2), { recursive: true });
@@ -25970,7 +26103,7 @@ var MappingStore = class {
25970
26103
  this.#sectionsDirectory = path18.join(this.#directory, "sections");
25971
26104
  this.#metadataDirectory = path18.join(this.#directory, "thread-metadata");
25972
26105
  this.#lockPath = path18.join(this.#directory, "store.lock");
25973
- this.#instanceId = options2.instanceId ?? randomUUID8();
26106
+ this.#instanceId = options2.instanceId ?? randomUUID9();
25974
26107
  this.#now = options2.now ?? (() => /* @__PURE__ */ new Date());
25975
26108
  this.#beforeReplace = options2.beforeReplace;
25976
26109
  }
@@ -26502,7 +26635,7 @@ var MappingStore = class {
26502
26635
  this.#rebuildIndexes();
26503
26636
  }
26504
26637
  async #replaceFile(target, record4, preserveBackup) {
26505
- const temp = `${target}.tmp-${randomUUID8()}`;
26638
+ const temp = `${target}.tmp-${randomUUID9()}`;
26506
26639
  let handle = null;
26507
26640
  try {
26508
26641
  await this.#beforeReplace?.(cloneRecord(record4));
@@ -26526,18 +26659,20 @@ var MappingStore = class {
26526
26659
  });
26527
26660
  }
26528
26661
  }
26529
- /** Atomically writes, or with null removes, a Thread's Desktop metadata file. */
26662
+ /** Atomically patches owned metadata fields, retaining unknown fields on disk. */
26530
26663
  async #writeMetadataFile(hostThreadId, metadata) {
26531
26664
  const target = this.#metadataPath(hostThreadId);
26532
- const temp = `${target}.tmp-${randomUUID8()}`;
26665
+ const temp = `${target}.tmp-${randomUUID9()}`;
26533
26666
  let handle = null;
26534
26667
  try {
26535
- if (!metadata) {
26668
+ const retained = Object.fromEntries(Object.entries(await this.#readMetadata(hostThreadId) ?? {}).filter(([name]) => !["formatVersion", "hostThreadId", ...THREAD_METADATA_FIELDS].includes(name)));
26669
+ if (!metadata && Object.keys(retained).length === 0) {
26536
26670
  await rm10(target, { force: true });
26537
26671
  return;
26538
26672
  }
26673
+ const next = { ...retained, formatVersion: 1, hostThreadId, ...metadata };
26539
26674
  handle = await open7(temp, "wx", constants3.S_IRUSR | constants3.S_IWUSR);
26540
- await handle.writeFile(`${JSON.stringify(metadata, null, 2)}
26675
+ await handle.writeFile(`${JSON.stringify(next, null, 2)}
26541
26676
  `, "utf8");
26542
26677
  await handle.sync();
26543
26678
  await handle.close();
@@ -26574,7 +26709,7 @@ var MappingStore = class {
26574
26709
  }
26575
26710
  async #replaceDelegationFile(record4) {
26576
26711
  const target = this.#delegationPath(record4.delegationId);
26577
- const temp = `${target}.tmp-${randomUUID8()}`;
26712
+ const temp = `${target}.tmp-${randomUUID9()}`;
26578
26713
  let handle = null;
26579
26714
  try {
26580
26715
  handle = await open7(temp, "wx", constants3.S_IRUSR | constants3.S_IWUSR);
@@ -28275,8 +28410,18 @@ function collabAgentStatus(status2) {
28275
28410
  return "interrupted";
28276
28411
  }
28277
28412
  }
28413
+ function projectUserMessage(item, clientId) {
28414
+ return {
28415
+ id: item.itemId,
28416
+ type: "userMessage",
28417
+ clientId,
28418
+ content: item.input.map(({ text: text2 }) => ({ type: "text", text: text2, text_elements: [] }))
28419
+ };
28420
+ }
28278
28421
  function projectItem(item, outcome, defaultCwd, includeCommandOutput = true, senderThreadId) {
28279
28422
  switch (item.type) {
28423
+ case "userMessage":
28424
+ return projectUserMessage(item, null);
28280
28425
  case "agentMessage":
28281
28426
  return {
28282
28427
  id: item.itemId,
@@ -28490,6 +28635,7 @@ var CodexTurnProjector = class {
28490
28635
  #interactions = /* @__PURE__ */ new Map();
28491
28636
  #items = /* @__PURE__ */ new Map();
28492
28637
  #wireItemOrder = [];
28638
+ #userMessageClientIds = /* @__PURE__ */ new Map();
28493
28639
  #startedAt;
28494
28640
  #startedAtMs;
28495
28641
  #threadId;
@@ -28531,6 +28677,10 @@ var CodexTurnProjector = class {
28531
28677
  }
28532
28678
  return items;
28533
28679
  }
28680
+ /** Associate steered input with the Desktop message that submitted it, before it is published. */
28681
+ bindUserMessageClientId(itemId, clientId) {
28682
+ this.#userMessageClientIds.set(itemId, clientId);
28683
+ }
28534
28684
  pendingTurn(startedAt = null) {
28535
28685
  return {
28536
28686
  id: this.#turnId,
@@ -28541,6 +28691,8 @@ var CodexTurnProjector = class {
28541
28691
  const projected = this.#items.get(itemId);
28542
28692
  if (!projected?.wireStarted)
28543
28693
  return [];
28694
+ if (projected.item.type === "userMessage")
28695
+ return [this.#projectItem(projected.item)];
28544
28696
  if (projected.item.type === "agentMessage") {
28545
28697
  return [projectItem(projected.item, projected.outcome, this.#cwd)];
28546
28698
  }
@@ -28868,7 +29020,7 @@ var CodexTurnProjector = class {
28868
29020
  return { messages: [] };
28869
29021
  }
28870
29022
  const messages = [
28871
- completedItem(projectItem(projected.item, projected.outcome, this.#cwd, !projected.streamedCommandOutput, this.#threadId))
29023
+ completedItem(this.#projectItem(projected.item, projected.outcome, !projected.streamedCommandOutput))
28872
29024
  ];
28873
29025
  if (projected.item.type === "reasoning") {
28874
29026
  const reasoning = projected.item;
@@ -28934,6 +29086,8 @@ var CodexTurnProjector = class {
28934
29086
  projectReasoningTranscriptItem(reasoning, projected.outcome, this.#cwd, projected.durationMs ?? null)
28935
29087
  ];
28936
29088
  }
29089
+ if (projected.item.type === "userMessage")
29090
+ return [this.#projectItem(projected.item)];
28937
29091
  if (projected.item.type === "agentMessage") {
28938
29092
  return [projectItem(projected.item, projected.outcome, this.#cwd)];
28939
29093
  }
@@ -29019,10 +29173,13 @@ var CodexTurnProjector = class {
29019
29173
  threadId: this.#threadId,
29020
29174
  turnId: this.#turnId,
29021
29175
  startedAtMs,
29022
- item: projectItem(item, null, this.#cwd, true, this.#threadId)
29176
+ item: this.#projectItem(item, null)
29023
29177
  }
29024
29178
  };
29025
29179
  }
29180
+ #projectItem(item, outcome = null, includeCommandOutput = true) {
29181
+ return item.type === "userMessage" ? projectUserMessage(item, this.#userMessageClientIds.get(item.itemId) ?? null) : projectItem(item, outcome, this.#cwd, includeCommandOutput, this.#threadId);
29182
+ }
29026
29183
  #startReasoningTranscript(item, startedAtMs) {
29027
29184
  return {
29028
29185
  method: "item/started",
@@ -30417,7 +30574,7 @@ var HarnessAccountInspectionCache = class {
30417
30574
  };
30418
30575
 
30419
30576
  // packages/host-runtime/src/app-server-host.ts
30420
- import { createHash as createHash9, randomUUID as randomUUID14 } from "node:crypto";
30577
+ import { createHash as createHash9, randomUUID as randomUUID16 } from "node:crypto";
30421
30578
  import os8 from "node:os";
30422
30579
  import path26 from "node:path";
30423
30580
 
@@ -30425,12 +30582,12 @@ import path26 from "node:path";
30425
30582
  import nodePath from "node:path";
30426
30583
 
30427
30584
  // packages/host-runtime/src/external-thread-repository.ts
30428
- import { randomUUID as randomUUID10 } from "node:crypto";
30585
+ import { randomUUID as randomUUID11 } from "node:crypto";
30429
30586
  import os7 from "node:os";
30430
30587
  import path22 from "node:path";
30431
30588
 
30432
30589
  // packages/host-runtime/src/external-subagent-threads.ts
30433
- import { createHash as createHash6, randomUUID as randomUUID9 } from "node:crypto";
30590
+ import { createHash as createHash6, randomUUID as randomUUID10 } from "node:crypto";
30434
30591
  function childCreateRequest(parent, nativeRef, id2) {
30435
30592
  const key = createHash6("sha256").update(JSON.stringify([parent.hostThreadId, parent.harnessId, nativeRef.nativeSessionId, id2])).digest("hex");
30436
30593
  return `subagent:${key}`;
@@ -30505,7 +30662,7 @@ function subagentMaterializer(store, parent, previousParent) {
30505
30662
  return rebind(existing, parent);
30506
30663
  }
30507
30664
  const provisional = existing ?? await store.createProvisional({
30508
- hostThreadId: hostThreadIdSchema.parse(randomUUID9()),
30665
+ hostThreadId: hostThreadIdSchema.parse(randomUUID10()),
30509
30666
  createRequestId,
30510
30667
  harnessId: parent.harnessId,
30511
30668
  cwd: parent.cwd,
@@ -30685,7 +30842,7 @@ var ExternalThreadRepository = class {
30685
30842
  throw new Error("Derived Snapshot identity does not belong to its Native Session");
30686
30843
  }
30687
30844
  return {
30688
- hostTurnId: hostTurnIdSchema.parse(randomUUID10()),
30845
+ hostTurnId: hostTurnIdSchema.parse(randomUUID11()),
30689
30846
  nativeTurnRef: turn.nativeTurnRef,
30690
30847
  ...turn.checkpoint ? { nativeCheckpointRef: turn.checkpoint } : {}
30691
30848
  };
@@ -30808,14 +30965,14 @@ var ExternalThreadRepository = class {
30808
30965
  const aligned = snapshot2.turns.map((turn) => {
30809
30966
  const existing = mappingsByNative.get(nativeTurnKey2(turn.nativeTurnRef));
30810
30967
  const mapping = existing ?? {
30811
- hostTurnId: hostTurnIdSchema.parse(randomUUID10()),
30968
+ hostTurnId: hostTurnIdSchema.parse(randomUUID11()),
30812
30969
  nativeTurnRef: turn.nativeTurnRef,
30813
30970
  ...turn.checkpoint ? { nativeCheckpointRef: turn.checkpoint } : {}
30814
30971
  };
30815
30972
  return {
30816
30973
  snapshot: turn,
30817
30974
  mapping: {
30818
- ...mapping,
30975
+ hostTurnId: mapping.hostTurnId,
30819
30976
  nativeTurnRef: turn.nativeTurnRef,
30820
30977
  ...turn.checkpoint ? { nativeCheckpointRef: turn.checkpoint } : {}
30821
30978
  }
@@ -30835,8 +30992,8 @@ var ExternalThreadRepository = class {
30835
30992
  };
30836
30993
  function createExternalThreadRecordInput(input) {
30837
30994
  return {
30838
- hostThreadId: input.hostThreadId ?? hostThreadIdSchema.parse(randomUUID10()),
30839
- createRequestId: input.createRequestId ?? randomUUID10(),
30995
+ hostThreadId: input.hostThreadId ?? hostThreadIdSchema.parse(randomUUID11()),
30996
+ createRequestId: input.createRequestId ?? randomUUID11(),
30840
30997
  harnessId: input.harnessId,
30841
30998
  cwd: input.cwd,
30842
30999
  ...input.title ? { title: input.title } : {},
@@ -30968,6 +31125,15 @@ async function executeExternalThreadFork(input) {
30968
31125
  boundaryIndex = mappings.length - 1;
30969
31126
  }
30970
31127
  const boundary = mappings[boundaryIndex];
31128
+ if (boundary && source.steeredTurnIds.has(boundary.hostTurnId)) {
31129
+ return {
31130
+ ok: false,
31131
+ error: {
31132
+ code: -32080,
31133
+ message: "This Turn took steered input; reopen the Thread before forking from it"
31134
+ }
31135
+ };
31136
+ }
30971
31137
  if (boundaryIndex < 0 || !boundary?.nativeCheckpointRef) {
30972
31138
  return {
30973
31139
  ok: false,
@@ -31024,6 +31190,7 @@ async function executeExternalThreadFork(input) {
31024
31190
  return { ok: false, error: mapExternalThreadHarnessError(opened.error, "fork") };
31025
31191
  }
31026
31192
  const session = opened.value;
31193
+ await inheritSourceModel(source, session);
31027
31194
  const inheritedPermissionModeId = await inheritSourcePermissionMode(source, session);
31028
31195
  try {
31029
31196
  const derivedNativeRef = session.initialState.nativeRef;
@@ -31041,7 +31208,7 @@ async function executeExternalThreadFork(input) {
31041
31208
  source.harnessId,
31042
31209
  provisional.transportModelId
31043
31210
  );
31044
- if (effectiveModel && selection?.model && selection.model.id !== effectiveModel.id) {
31211
+ if (effectiveModel && selection && selection.model?.id !== effectiveModel.id) {
31045
31212
  const transportModelId = encodeExternalTransportSelection(source.harnessId, {
31046
31213
  ...selection,
31047
31214
  model: effectiveModel
@@ -31086,6 +31253,22 @@ async function executeExternalThreadFork(input) {
31086
31253
  };
31087
31254
  }
31088
31255
  }
31256
+ async function inheritSourceModel(source, session) {
31257
+ let persisted;
31258
+ try {
31259
+ persisted = decodeExternalTransportSelection(source.harnessId, source.transportModelId)?.model;
31260
+ } catch {
31261
+ persisted = void 0;
31262
+ }
31263
+ const sourceModel = source.stateObserver.state.effectiveModel ?? source.requestedModel ?? persisted;
31264
+ if (!sourceModel || !session.capabilities.configuration.selectModel || session.initialState.effectiveModel !== void 0) {
31265
+ return;
31266
+ }
31267
+ try {
31268
+ await session.execute({ type: "model.select", model: sourceModel });
31269
+ } catch {
31270
+ }
31271
+ }
31089
31272
  async function inheritSourcePermissionMode(source, session) {
31090
31273
  const sourceModeId = source.stateObserver.state.effectivePermissionModeId ?? source.requestedPermissionModeId;
31091
31274
  if (!sourceModeId) return void 0;
@@ -31724,6 +31907,16 @@ async function executeExternalThreadRollback(input) {
31724
31907
  if (derived.running) {
31725
31908
  return { ok: false, error: { code: -32072, message: "External Thread has an active Turn" } };
31726
31909
  }
31910
+ const undone = derived.record.turnMappings.slice(-rollback.numTurns);
31911
+ if (undone.some((mapping) => derived.steeredTurnIds.has(mapping.hostTurnId))) {
31912
+ return {
31913
+ ok: false,
31914
+ error: {
31915
+ code: -32080,
31916
+ message: "A Turn here took steered input; reopen the Thread before undoing Turns"
31917
+ }
31918
+ };
31919
+ }
31727
31920
  const refreshError = await runtime.refresh(derived);
31728
31921
  if (refreshError) return { ok: false, error: refreshError };
31729
31922
  if (expectedLastTurnId !== void 0 && derived.record.turnMappings.at(-1)?.hostTurnId !== expectedLastTurnId) {
@@ -32523,6 +32716,7 @@ var ExternalThreadRuntime = class {
32523
32716
  #repository;
32524
32717
  #lifecycle = new ExternalThreadLifecycle();
32525
32718
  #hasRunningDescendants;
32719
+ #steeredTurnIds = /* @__PURE__ */ new Map();
32526
32720
  #subagentRunning;
32527
32721
  #threads = /* @__PURE__ */ new Map();
32528
32722
  constructor(input) {
@@ -32536,7 +32730,8 @@ var ExternalThreadRuntime = class {
32536
32730
  this.idleRelease = new ExternalThreadIdleRelease({
32537
32731
  threads: () => this.values(),
32538
32732
  get: (id2) => this.get(id2),
32539
- remove: (id2) => this.remove(id2),
32733
+ // Idle release detaches only the Native Session. Host Thread state survives restoration.
32734
+ remove: (id2) => this.#detach(id2),
32540
32735
  queue: input.idleRelease?.queue ?? new DesktopRequestQueue(),
32541
32736
  canRelease: (thread) => !thread.sessionUnavailable && !this.#lifecycle.busy(thread.id) && (input.idleRelease?.canRelease(thread) ?? false),
32542
32737
  ...input.idleRelease?.onClosed ? { onClosed: input.idleRelease.onClosed } : {},
@@ -32546,14 +32741,21 @@ var ExternalThreadRuntime = class {
32546
32741
  get(threadId2) {
32547
32742
  return this.#threads.get(threadId2);
32548
32743
  }
32744
+ #detach(threadId2) {
32745
+ const thread = this.#threads.get(threadId2);
32746
+ this.#threads.delete(threadId2);
32747
+ if (!thread || thread.steeredTurnIds.size === 0) this.#steeredTurnIds.delete(threadId2);
32748
+ }
32549
32749
  values() {
32550
32750
  return [...this.#threads.values()];
32551
32751
  }
32552
32752
  remove(threadId2) {
32553
32753
  this.#threads.delete(threadId2);
32754
+ this.#steeredTurnIds.delete(threadId2);
32554
32755
  }
32555
32756
  clear() {
32556
32757
  this.#threads.clear();
32758
+ this.#steeredTurnIds.clear();
32557
32759
  }
32558
32760
  drain() {
32559
32761
  return this.#lifecycle.drain();
@@ -32610,6 +32812,11 @@ var ExternalThreadRuntime = class {
32610
32812
  ...effectivePermissionModeId ? { effectivePermissionModeId } : {}
32611
32813
  };
32612
32814
  const running = this.#subagentRunning(input.record.hostThreadId);
32815
+ let steeredTurnIds = this.#steeredTurnIds.get(input.record.hostThreadId);
32816
+ if (!steeredTurnIds) {
32817
+ steeredTurnIds = /* @__PURE__ */ new Set();
32818
+ this.#steeredTurnIds.set(input.record.hostThreadId, steeredTurnIds);
32819
+ }
32613
32820
  const externalThread = {
32614
32821
  id: input.record.hostThreadId,
32615
32822
  cwd: input.record.cwd,
@@ -32634,11 +32841,13 @@ var ExternalThreadRuntime = class {
32634
32841
  usageTurnId: null,
32635
32842
  projectedTurns: /* @__PURE__ */ new Map(),
32636
32843
  responseGates: /* @__PURE__ */ new Map(),
32844
+ pendingSteerProjections: /* @__PURE__ */ new Set(),
32637
32845
  ephemeralTurnIds: /* @__PURE__ */ new Set(),
32638
32846
  persistenceError: null,
32639
32847
  projectedTerminalTurnId: null,
32640
32848
  ignoredInteractionIds: /* @__PURE__ */ new Set(),
32641
- sessionUnavailable: false
32849
+ sessionUnavailable: false,
32850
+ steeredTurnIds
32642
32851
  };
32643
32852
  this.idleRelease.touch(externalThread);
32644
32853
  externalThread.outputTask = this.#consumeOutputs(externalThread);
@@ -32695,13 +32904,13 @@ var ExternalThreadRuntime = class {
32695
32904
  const retire = async () => {
32696
32905
  if (this.#threads.get(parentId) !== parent || this.#threads.get(child.id) !== child) return;
32697
32906
  if (bestEffort) {
32698
- this.#threads.delete(child.id);
32907
+ this.remove(child.id);
32699
32908
  await child.session.close();
32700
32909
  await child.outputTask;
32701
32910
  } else {
32702
32911
  child.sessionUnavailable = true;
32703
32912
  await this.#lifecycle.release(child.id, child.session, child.outputTask);
32704
- if (this.#threads.get(child.id) === child) this.#threads.delete(child.id);
32913
+ if (this.#threads.get(child.id) === child) this.remove(child.id);
32705
32914
  }
32706
32915
  };
32707
32916
  if (bestEffort) await retire().catch(this.#diagnose);
@@ -33074,6 +33283,71 @@ var ExternalThreadRuntime = class {
33074
33283
  };
33075
33284
 
33076
33285
  // packages/host-runtime/src/external-turn-steering.ts
33286
+ import { randomUUID as randomUUID12 } from "node:crypto";
33287
+
33288
+ // packages/host-runtime/src/external-command-routing.ts
33289
+ var ExternalCommandError = class extends Error {
33290
+ constructor(code, message2) {
33291
+ super(message2);
33292
+ this.code = code;
33293
+ }
33294
+ code;
33295
+ };
33296
+ function isExternalCommandCandidate(text2) {
33297
+ return /^\/[^\s/]+(?:\s|$)/u.test(text2.trimStart());
33298
+ }
33299
+ async function inspectLiveCommandCatalog(commands, timeoutMs = 1e3) {
33300
+ let timeout;
33301
+ try {
33302
+ const result = await Promise.race([
33303
+ commands.list(),
33304
+ new Promise((resolve) => {
33305
+ timeout = setTimeout(() => resolve(null), timeoutMs);
33306
+ })
33307
+ ]);
33308
+ return result?.ok ? harnessCommandCatalogSchema.parse(result.value) : null;
33309
+ } catch {
33310
+ return null;
33311
+ } finally {
33312
+ if (timeout !== void 0) clearTimeout(timeout);
33313
+ }
33314
+ }
33315
+ async function resolveExternalCommand(commands, text2, options2 = {}) {
33316
+ const catalog = await commands.list();
33317
+ if (!catalog.ok) throw new ExternalCommandError(-32073, catalog.error.message);
33318
+ const commandText = text2.trim();
33319
+ const matched = catalog.value.commands.toSorted((left, right) => right.invocation.length - left.invocation.length).find((command) => {
33320
+ if (commandText === command.invocation) return true;
33321
+ return command.argumentMode === "text" && commandText.startsWith(`${command.invocation} `);
33322
+ });
33323
+ if (!matched) {
33324
+ const name = /^\/(\S+)/u.exec(commandText)?.[1] ?? "";
33325
+ if (name && !isExcludedLiveCommand(name, "command") && options2.liveCatalogPending?.(catalog.value)) {
33326
+ return null;
33327
+ }
33328
+ throw new ExternalCommandError(
33329
+ -32078,
33330
+ "External Harness does not expose the requested command"
33331
+ );
33332
+ }
33333
+ const argumentText = commandText.slice(matched.invocation.length).trimStart();
33334
+ return {
33335
+ descriptor: matched,
33336
+ ...argumentText.length > 0 ? { arguments: { text: argumentText } } : {}
33337
+ };
33338
+ }
33339
+
33340
+ // packages/host-runtime/src/external-turn-steering.ts
33341
+ function isHarnessCommand(thread, text2) {
33342
+ return thread.session.commands !== void 0 && isExternalCommandCandidate(restoreHarnessCommandMentions(text2));
33343
+ }
33344
+ function externalSteeringDelivery(thread, text2) {
33345
+ if (text2 !== void 0 && isHarnessCommand(thread, text2)) return "newTurn";
33346
+ if (thread.session.readCapabilities) {
33347
+ return thread.session.readCapabilities().then((capabilities) => capabilities.steer === true ? "activeTurn" : "newTurn");
33348
+ }
33349
+ return thread.session.capabilities.steer === true ? "activeTurn" : "newTurn";
33350
+ }
33077
33351
  var ExternalSteerError = class extends Error {
33078
33352
  constructor(code, message2) {
33079
33353
  super(message2);
@@ -33081,6 +33355,11 @@ var ExternalSteerError = class extends Error {
33081
33355
  }
33082
33356
  code;
33083
33357
  };
33358
+ var ExternalSteerNotTakenError = class extends ExternalSteerError {
33359
+ constructor(message2) {
33360
+ super(-32074, message2);
33361
+ }
33362
+ };
33084
33363
  function parseInput(params) {
33085
33364
  if (typeof params.expectedTurnId !== "string" || !params.expectedTurnId.trim()) {
33086
33365
  throw new ExternalSteerError(-32602, "External steering requires expectedTurnId");
@@ -33097,12 +33376,47 @@ function parseInput(params) {
33097
33376
  if (clientUserMessageId != null && (typeof clientUserMessageId !== "string" || !clientUserMessageId.trim())) {
33098
33377
  throw new ExternalSteerError(-32602, "External steering message identity is invalid");
33099
33378
  }
33379
+ const delivery = params[THREAD_STEER_DELIVERY_PARAM];
33380
+ const parsedDelivery = delivery == null ? void 0 : threadSteerDeliverySchema.safeParse(delivery);
33381
+ if (parsedDelivery && !parsedDelivery.success) {
33382
+ throw new ExternalSteerError(-32602, "External steering delivery is invalid");
33383
+ }
33100
33384
  return {
33101
33385
  expectedTurnId: params.expectedTurnId,
33102
33386
  text: text2,
33103
- ...typeof clientUserMessageId === "string" ? { clientUserMessageId } : {}
33387
+ ...typeof clientUserMessageId === "string" ? { clientUserMessageId } : {},
33388
+ ...parsedDelivery ? { delivery: parsedDelivery.data } : {}
33104
33389
  };
33105
33390
  }
33391
+ async function insertNativeSteer(thread, input, host) {
33392
+ const restored = restoreHarnessCommandMentions(input.text);
33393
+ const steered = [{ type: "text", text: rewriteDelegationMentionText(restored) }];
33394
+ const displayed = [{ type: "text", text: restored }];
33395
+ const projectionDone = Promise.withResolvers();
33396
+ thread.pendingSteerProjections.add(projectionDone.promise);
33397
+ try {
33398
+ const result = await thread.session.execute({
33399
+ type: "turn.steer",
33400
+ turnId: input.turnId,
33401
+ input: steered
33402
+ });
33403
+ if (!result.ok) throw new ExternalSteerNotTakenError(result.error.message);
33404
+ thread.steeredTurnIds.add(input.turnId);
33405
+ const item = {
33406
+ type: "userMessage",
33407
+ itemId: hostItemIdSchema.parse(randomUUID12()),
33408
+ input: displayed
33409
+ };
33410
+ try {
33411
+ await host.project(input.turnId, item, input.clientUserMessageId);
33412
+ } catch (error51) {
33413
+ host.diagnose(error51);
33414
+ }
33415
+ } finally {
33416
+ projectionDone.resolve(void 0);
33417
+ thread.pendingSteerProjections.delete(projectionDone.promise);
33418
+ }
33419
+ }
33106
33420
  var ExternalTurnSteering = class {
33107
33421
  constructor(timeoutMs = 2e4) {
33108
33422
  this.timeoutMs = timeoutMs;
@@ -33114,7 +33428,7 @@ var ExternalTurnSteering = class {
33114
33428
  hasPending(threadId2) {
33115
33429
  return threadId2 === void 0 ? this.#pending.size > 0 : this.#pending.has(threadId2);
33116
33430
  }
33117
- run(thread, params, start) {
33431
+ run(thread, params, start, insert) {
33118
33432
  try {
33119
33433
  const input = parseInput(params);
33120
33434
  if (this.#closed)
@@ -33136,7 +33450,7 @@ var ExternalTurnSteering = class {
33136
33450
  if (!thread.running || thread.activeTurnId !== input.expectedTurnId) {
33137
33451
  throw new ExternalSteerError(-32074, "External steering must reference the active Turn");
33138
33452
  }
33139
- const result = this.#replace(thread, input, start);
33453
+ const result = this.#deliver(thread, input, start, insert);
33140
33454
  if (key) {
33141
33455
  const receipt2 = { fingerprint, result, settled: false };
33142
33456
  this.#receipts.set(key, receipt2);
@@ -33159,6 +33473,56 @@ var ExternalTurnSteering = class {
33159
33473
  return Promise.reject(error51);
33160
33474
  }
33161
33475
  }
33476
+ /**
33477
+ * A Renderer that already presented a delivery gets exactly that one. Otherwise native delivery
33478
+ * is tried only when the Session can take the input now, and input the Harness did not take
33479
+ * falls back to stopping and restarting, so no case is worse than the stop-then-start path.
33480
+ */
33481
+ #deliver(thread, input, start, insert) {
33482
+ const delivery = input.delivery === "newTurn" || isHarnessCommand(thread, input.text) ? "newTurn" : input.delivery ?? externalSteeringDelivery(thread);
33483
+ const deliver = (mode) => {
33484
+ if (this.#closed || !thread.running || thread.activeTurnId !== input.expectedTurnId) {
33485
+ throw new ExternalSteerError(-32074, "External steering target is no longer active");
33486
+ }
33487
+ if (this.hasPending(thread.id))
33488
+ throw new ExternalSteerError(-32072, "External Thread is already changing direction");
33489
+ if (mode === "newTurn") return this.#replace(thread, input, start);
33490
+ const native = insert({
33491
+ turnId: thread.activeTurnId,
33492
+ text: input.text,
33493
+ ...input.clientUserMessageId ? { clientUserMessageId: input.clientUserMessageId } : {}
33494
+ }).then((admitted) => ({ ...admitted, delivery: "activeTurn" }));
33495
+ if (input.delivery === "activeTurn") return native;
33496
+ return native.catch(async (error51) => {
33497
+ if (!(error51 instanceof ExternalSteerNotTakenError)) throw error51;
33498
+ if (thread.running || thread.activeTurnId) return deliver("newTurn");
33499
+ const assertActive = () => {
33500
+ if (this.#closed)
33501
+ throw new ExternalSteerError(-32074, "External steering connection is closed");
33502
+ };
33503
+ return { ...await start(input.text, assertActive), delivery: "newTurn" };
33504
+ });
33505
+ };
33506
+ if (typeof delivery === "string") return deliver(delivery);
33507
+ const failure = Promise.withResolvers();
33508
+ let failureReason = null;
33509
+ const pending = {
33510
+ turnId: input.expectedTurnId,
33511
+ resolve: () => void 0,
33512
+ reject(error51) {
33513
+ failureReason ??= error51;
33514
+ failure.reject(error51);
33515
+ }
33516
+ };
33517
+ this.#pending.set(thread.id, pending);
33518
+ return Promise.race([delivery, failure.promise]).then((mode) => {
33519
+ if (failureReason) throw failureReason;
33520
+ if (this.#pending.get(thread.id) === pending) this.#pending.delete(thread.id);
33521
+ return deliver(mode);
33522
+ }).finally(() => {
33523
+ if (this.#pending.get(thread.id) === pending) this.#pending.delete(thread.id);
33524
+ });
33525
+ }
33162
33526
  terminal(threadId2, turnId, outcome) {
33163
33527
  const pending = this.#pending.get(threadId2);
33164
33528
  if (pending?.turnId === turnId) pending.resolve(outcome);
@@ -33213,7 +33577,9 @@ var ExternalTurnSteering = class {
33213
33577
  thread.session.execute({ type: "turn.cancel", turnId }),
33214
33578
  failure.promise
33215
33579
  ]);
33216
- if (!cancelled.ok) throw new ExternalSteerError(-32074, cancelled.error.message);
33580
+ if (!cancelled.ok && cancelled.error.code !== "invalidState") {
33581
+ throw new ExternalSteerError(-32074, cancelled.error.message);
33582
+ }
33217
33583
  const outcome = await Promise.race([terminal3.promise, failure.promise]);
33218
33584
  clearTimeout(timeout);
33219
33585
  const assertActive = () => {
@@ -33231,7 +33597,7 @@ var ExternalTurnSteering = class {
33231
33597
  if (thread.running || thread.activeTurnId) {
33232
33598
  throw new ExternalSteerError(-32072, "Another External Turn started before replacement");
33233
33599
  }
33234
- return await start(input.text, assertActive);
33600
+ return { ...await start(input.text, assertActive), delivery: "newTurn" };
33235
33601
  } finally {
33236
33602
  clearTimeout(timeout);
33237
33603
  if (this.#pending.get(thread.id) === pending) this.#pending.delete(thread.id);
@@ -33239,58 +33605,6 @@ var ExternalTurnSteering = class {
33239
33605
  }
33240
33606
  };
33241
33607
 
33242
- // packages/host-runtime/src/external-command-routing.ts
33243
- var ExternalCommandError = class extends Error {
33244
- constructor(code, message2) {
33245
- super(message2);
33246
- this.code = code;
33247
- }
33248
- code;
33249
- };
33250
- function isExternalCommandCandidate(text2) {
33251
- return /^\/[^\s/]+(?:\s|$)/u.test(text2.trimStart());
33252
- }
33253
- async function inspectLiveCommandCatalog(commands, timeoutMs = 1e3) {
33254
- let timeout;
33255
- try {
33256
- const result = await Promise.race([
33257
- commands.list(),
33258
- new Promise((resolve) => {
33259
- timeout = setTimeout(() => resolve(null), timeoutMs);
33260
- })
33261
- ]);
33262
- return result?.ok ? harnessCommandCatalogSchema.parse(result.value) : null;
33263
- } catch {
33264
- return null;
33265
- } finally {
33266
- if (timeout !== void 0) clearTimeout(timeout);
33267
- }
33268
- }
33269
- async function resolveExternalCommand(commands, text2, options2 = {}) {
33270
- const catalog = await commands.list();
33271
- if (!catalog.ok) throw new ExternalCommandError(-32073, catalog.error.message);
33272
- const commandText = text2.trim();
33273
- const matched = catalog.value.commands.toSorted((left, right) => right.invocation.length - left.invocation.length).find((command) => {
33274
- if (commandText === command.invocation) return true;
33275
- return command.argumentMode === "text" && commandText.startsWith(`${command.invocation} `);
33276
- });
33277
- if (!matched) {
33278
- const name = /^\/(\S+)/u.exec(commandText)?.[1] ?? "";
33279
- if (name && !isExcludedLiveCommand(name, "command") && options2.liveCatalogPending?.(catalog.value)) {
33280
- return null;
33281
- }
33282
- throw new ExternalCommandError(
33283
- -32078,
33284
- "External Harness does not expose the requested command"
33285
- );
33286
- }
33287
- const argumentText = commandText.slice(matched.invocation.length).trimStart();
33288
- return {
33289
- descriptor: matched,
33290
- ...argumentText.length > 0 ? { arguments: { text: argumentText } } : {}
33291
- };
33292
- }
33293
-
33294
33608
  // packages/host-runtime/src/live-command-catalog-cache.ts
33295
33609
  import path23 from "node:path";
33296
33610
  var MAX_ENTRIES = 64;
@@ -33322,7 +33636,7 @@ function sameWorkspace(left, right) {
33322
33636
  }
33323
33637
 
33324
33638
  // packages/host-runtime/src/harness-delegation-coordinator.ts
33325
- import { createHash as createHash8, randomUUID as randomUUID11 } from "node:crypto";
33639
+ import { createHash as createHash8, randomUUID as randomUUID13 } from "node:crypto";
33326
33640
  import path24 from "node:path";
33327
33641
 
33328
33642
  // packages/host-runtime/src/delegation-snapshot.ts
@@ -33473,17 +33787,28 @@ var DELEGATION_TITLE_ELLIPSIS = "...";
33473
33787
  var ANSI_CSI_PATTERN = /\u001B\[[0-9;]*[a-zA-Z]/gu;
33474
33788
  var C0_AND_DEL_CONTROL_CHARACTERS = /[\u0000-\u001F\u007F]/gu;
33475
33789
  var CONSECUTIVE_WHITESPACE = /\s+/gu;
33476
- function sanitizeDelegationTitle(task) {
33477
- const withoutAnsi = task.replace(ANSI_CSI_PATTERN, "");
33790
+ function cleanDelegationTitle(value2) {
33791
+ const withoutAnsi = value2.replace(ANSI_CSI_PATTERN, "");
33478
33792
  const withoutControls = withoutAnsi.replace(C0_AND_DEL_CONTROL_CHARACTERS, " ");
33479
- const collapsed = withoutControls.replace(CONSECUTIVE_WHITESPACE, " ");
33480
- const trimmed = collapsed.trim();
33793
+ return withoutControls.replace(CONSECUTIVE_WHITESPACE, " ").trim();
33794
+ }
33795
+ function sanitizeDelegationTitle(task) {
33796
+ const trimmed = cleanDelegationTitle(task);
33481
33797
  if (trimmed.length <= DELEGATION_TITLE_MAX_LENGTH) {
33482
33798
  return trimmed;
33483
33799
  }
33484
33800
  const cutLength = Math.max(0, DELEGATION_TITLE_MAX_LENGTH - DELEGATION_TITLE_ELLIPSIS.length);
33485
33801
  return `${trimmed.slice(0, cutLength)}${DELEGATION_TITLE_ELLIPSIS}`;
33486
33802
  }
33803
+ function truncateTitle(value2, length) {
33804
+ return value2.slice(0, length).replace(/[\uD800-\uDBFF]$/u, "");
33805
+ }
33806
+ function delegationTitle(parentTitle, input) {
33807
+ const taskName = input.taskName ?? input.task.trim().split(/\r?\n/u)[0] ?? input.task;
33808
+ const subtask = sanitizeDelegationTitle(taskName);
33809
+ const parent = cleanDelegationTitle(parentTitle?.trim() || "Untitled Thread");
33810
+ return `${subtask} · ${truncateTitle(parent, 200 - subtask.length - 3)}`;
33811
+ }
33487
33812
  function delay3(milliseconds) {
33488
33813
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
33489
33814
  }
@@ -33510,6 +33835,12 @@ function statusFromThread(thread, busy) {
33510
33835
  function validateStart(input) {
33511
33836
  if (typeof input.task !== "string" || !input.task.trim())
33512
33837
  throw new DelegationControlError("INVALID_ARGUMENT", "Task must not be empty");
33838
+ if (input.taskName !== void 0 && (typeof input.taskName !== "string" || !input.taskName.trim() || input.taskName.length > 120)) {
33839
+ throw new DelegationControlError(
33840
+ "INVALID_ARGUMENT",
33841
+ "Task name must contain 1 to 120 characters"
33842
+ );
33843
+ }
33513
33844
  if (input.cwd !== void 0 && (typeof input.cwd !== "string" || !input.cwd.trim()))
33514
33845
  throw new DelegationControlError("INVALID_ARGUMENT", "cwd must not be empty");
33515
33846
  if (input.requestId !== void 0 && (typeof input.requestId !== "string" || !input.requestId.trim())) {
@@ -33530,7 +33861,7 @@ var HarnessDelegationCoordinator = class {
33530
33861
  #cancelOfficial;
33531
33862
  #startOfficial;
33532
33863
  #listOfficial;
33533
- #officialThreadCwd;
33864
+ #officialThreadMetadata;
33534
33865
  #activeOfficialParents;
33535
33866
  #externalThreadBusy;
33536
33867
  constructor(input) {
@@ -33547,7 +33878,7 @@ var HarnessDelegationCoordinator = class {
33547
33878
  this.#cancelOfficial = input.cancelOfficial;
33548
33879
  this.#startOfficial = input.startOfficial;
33549
33880
  this.#listOfficial = input.listOfficial;
33550
- this.#officialThreadCwd = input.officialThreadCwd;
33881
+ this.#officialThreadMetadata = input.officialThreadMetadata;
33551
33882
  this.#activeOfficialParents = input.activeOfficialParents;
33552
33883
  this.#externalThreadBusy = input.externalThreadBusy;
33553
33884
  }
@@ -33577,8 +33908,14 @@ var HarnessDelegationCoordinator = class {
33577
33908
  const parentThreadId = await this.#resolveParent(input.parentThreadId);
33578
33909
  const parent = await this.#parentMetadata(parentThreadId);
33579
33910
  const selectedCwd = input.cwd ?? parent.cwd ?? process.cwd();
33911
+ const title = delegationTitle(parent.title, input);
33580
33912
  if (input.harnessId === "codex") {
33581
- const result = await this.#startOfficial({ ...input, parentThreadId, cwd: selectedCwd });
33913
+ const result = await this.#startOfficial({
33914
+ ...input,
33915
+ parentThreadId,
33916
+ cwd: selectedCwd,
33917
+ title
33918
+ });
33582
33919
  return { ...result, parentThreadId, cwd: result.cwd ?? selectedCwd };
33583
33920
  }
33584
33921
  const startInput = { ...input, parentThreadId, cwd: path24.resolve(selectedCwd) };
@@ -33621,17 +33958,17 @@ var HarnessDelegationCoordinator = class {
33621
33958
  });
33622
33959
  this.#validateConfiguration(inspected.inspection, input.model, input.thinkingOptionId);
33623
33960
  }
33624
- const delegationId = hostThreadIdSchema.parse(randomUUID11());
33625
- const childThreadId = hostThreadIdSchema.parse(randomUUID11());
33626
- const turnId = hostTurnIdSchema.parse(randomUUID11());
33627
- const createRequestId = input.requestId ? `delegation:${input.requestId}` : randomUUID11();
33961
+ const delegationId = hostThreadIdSchema.parse(randomUUID13());
33962
+ const childThreadId = hostThreadIdSchema.parse(randomUUID13());
33963
+ const turnId = hostTurnIdSchema.parse(randomUUID13());
33964
+ const createRequestId = input.requestId ? `delegation:${input.requestId}` : randomUUID13();
33628
33965
  let record4 = await this.#repository.createProvisional(
33629
33966
  createExternalThreadRecordInput({
33630
33967
  hostThreadId: childThreadId,
33631
33968
  createRequestId,
33632
33969
  harnessId: harnessIdSchema.parse(targetHarnessId),
33633
33970
  cwd: startInput.cwd,
33634
- title: sanitizeDelegationTitle(input.task),
33971
+ title,
33635
33972
  transportModelId: input.model || input.thinkingOptionId ? encodeExternalTransportSelection(targetHarnessId, {
33636
33973
  ...input.model ? { model: input.model } : {},
33637
33974
  ...input.thinkingOptionId ? { thinkingOptionId: input.thinkingOptionId } : {}
@@ -33778,7 +34115,7 @@ var HarnessDelegationCoordinator = class {
33778
34115
  if (this.#externalThreadBusy(thread) || thread.activeTurnId) {
33779
34116
  throw new DelegationControlError("THREAD_BUSY", "Thread already has an active Turn");
33780
34117
  }
33781
- const turnId = hostTurnIdSchema.parse(randomUUID11());
34118
+ const turnId = hostTurnIdSchema.parse(randomUUID13());
33782
34119
  try {
33783
34120
  await this.#startExternalTurn(thread, input.message, turnId);
33784
34121
  } catch (error51) {
@@ -33992,9 +34329,14 @@ var HarnessDelegationCoordinator = class {
33992
34329
  }
33993
34330
  async #parentMetadata(parentThreadId) {
33994
34331
  const record4 = await this.#repository.find(parentThreadId);
33995
- if (record4) return { harnessId: record4.harnessId, cwd: record4.cwd };
33996
- const cwd = await this.#officialThreadCwd(parentThreadId).catch(() => void 0);
33997
- return { harnessId: "codex", ...cwd ? { cwd } : {} };
34332
+ if (record4)
34333
+ return {
34334
+ harnessId: record4.harnessId,
34335
+ cwd: record4.cwd,
34336
+ title: record4.title
34337
+ };
34338
+ const metadata = await this.#officialThreadMetadata(parentThreadId).catch(() => ({}));
34339
+ return { harnessId: "codex", ...metadata };
33998
34340
  }
33999
34341
  async #existingResult(delegation) {
34000
34342
  const record4 = await this.#repository.find(delegation.childHostThreadId);
@@ -36727,10 +37069,10 @@ function projectCodexAccountAuth(snapshot2, homeAuth) {
36727
37069
  }
36728
37070
 
36729
37071
  // packages/host-runtime/src/codex-runtime/official-runtime-owner.ts
36730
- import { randomUUID as randomUUID13 } from "node:crypto";
37072
+ import { randomUUID as randomUUID15 } from "node:crypto";
36731
37073
 
36732
37074
  // packages/host-runtime/src/official-request-broker.ts
36733
- import { randomUUID as randomUUID12 } from "node:crypto";
37075
+ import { randomUUID as randomUUID14 } from "node:crypto";
36734
37076
  var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
36735
37077
  var MAX_RETIRED_IDS = 1024;
36736
37078
  function isRecord16(value2) {
@@ -36746,7 +37088,7 @@ var OfficialRequestBroker = class {
36746
37088
  constructor(input) {
36747
37089
  this.#send = input.send;
36748
37090
  this.#timeoutMs = input.timeoutMs ?? 3e4;
36749
- this.#nextId = input.nextId ?? (() => `${INTERNAL_REQUEST_PREFIX}${randomUUID12()}`);
37091
+ this.#nextId = input.nextId ?? (() => `${INTERNAL_REQUEST_PREFIX}${randomUUID14()}`);
36750
37092
  }
36751
37093
  get pendingCount() {
36752
37094
  return this.#pending.size;
@@ -37100,7 +37442,7 @@ var OfficialRuntimeOwner = class {
37100
37442
  }
37101
37443
  #attach(role, output, onBackendStopped) {
37102
37444
  const client = {
37103
- id: randomUUID13(),
37445
+ id: randomUUID15(),
37104
37446
  role,
37105
37447
  output,
37106
37448
  ...onBackendStopped ? { onBackendStopped } : {},
@@ -37258,7 +37600,7 @@ var OfficialRuntimeOwner = class {
37258
37600
  if (!object4(value2)) return client.output(event);
37259
37601
  if (typeof value2.id === "string" || typeof value2.id === "number") {
37260
37602
  if (typeof value2.method === "string") {
37261
- const id2 = `codexhost:server:${client.id}:${event.generation}:${randomUUID13()}`;
37603
+ const id2 = `codexhost:server:${client.id}:${event.generation}:${randomUUID15()}`;
37262
37604
  client.serverRequests.set(id2, value2.id);
37263
37605
  const projected = { ...value2, id: id2 };
37264
37606
  return client.output({
@@ -37434,16 +37776,16 @@ var OfficialRuntimeScope = class {
37434
37776
  #scheduleRecovery() {
37435
37777
  if (!this.#recovery || this.#closed || this.#recoveryTimer || this.#starting) return;
37436
37778
  const { delaysMs } = this.#recovery;
37437
- const delay6 = delaysMs[Math.min(this.#recoveryAttempt, delaysMs.length - 1)] ?? 0;
37779
+ const delay7 = delaysMs[Math.min(this.#recoveryAttempt, delaysMs.length - 1)] ?? 0;
37438
37780
  this.#recoveryAttempt++;
37439
37781
  this.#diagnosticOutput.write(
37440
- `codexhost: official Codex is unavailable; restarting in ${String(delay6)}ms
37782
+ `codexhost: official Codex is unavailable; restarting in ${String(delay7)}ms
37441
37783
  `
37442
37784
  );
37443
37785
  const timer = setTimeout(() => {
37444
37786
  this.#recoveryTimer = void 0;
37445
37787
  this.start().catch(() => void 0);
37446
- }, delay6);
37788
+ }, delay7);
37447
37789
  timer.unref();
37448
37790
  this.#recoveryTimer = timer;
37449
37791
  }
@@ -38546,6 +38888,7 @@ var AppServerHost = class {
38546
38888
  #plugins;
38547
38889
  #launchSettings;
38548
38890
  #accountInspections = new HarnessAccountInspectionCache();
38891
+ #installationTasks = new HarnessInstallationTasks();
38549
38892
  #externalRuntime;
38550
38893
  #executionHosts = /* @__PURE__ */ new WeakMap();
38551
38894
  #externalPrewarms = new ExternalThreadPrewarms();
@@ -38576,7 +38919,7 @@ var AppServerHost = class {
38576
38919
  #sectionMoves = Promise.resolve();
38577
38920
  #writer;
38578
38921
  /** Console requests share Desktop handling; their replies return to the console. */
38579
- #consoleRequestPrefix = `codexhost-console:${randomUUID14()}:`;
38922
+ #consoleRequestPrefix = `codexhost-console:${randomUUID16()}:`;
38580
38923
  #consoleReplies = /* @__PURE__ */ new Map();
38581
38924
  #nextConsoleRequest = 0;
38582
38925
  #subagentThreadStatuses = /* @__PURE__ */ new Map();
@@ -38720,7 +39063,7 @@ var AppServerHost = class {
38720
39063
  cancelOfficial: (input) => this.#cancelOfficialDelegationThread(input),
38721
39064
  startOfficial: (input) => this.#startOfficialDelegation(input),
38722
39065
  listOfficial: (input) => this.#listDelegationThreads(input),
38723
- officialThreadCwd: (threadId2) => this.#readOfficialThreadCwd(threadId2),
39066
+ officialThreadMetadata: (threadId2) => this.#readOfficialThreadMetadata(threadId2),
38724
39067
  activeOfficialParents: () => [...this.#activeOfficialTurns.keys()],
38725
39068
  externalThreadBusy: (thread) => this.#externalThreadBusy(thread)
38726
39069
  });
@@ -39370,11 +39713,11 @@ var AppServerHost = class {
39370
39713
  this.#dispatchDesktopReply(request, () => this.#inspectHarness(request));
39371
39714
  return;
39372
39715
  }
39373
- if (request.method === HARNESS_INSTALLATION_METHOD) {
39716
+ if (request.method === HARNESS_INSTALLATION_METHOD || request.method === HARNESS_INSTALLATION_START_METHOD || request.method === HARNESS_INSTALLATION_STATUS_METHOD) {
39374
39717
  this.#dispatchDesktopReply(request, async () => {
39375
- await this.#waitForPlugins();
39376
39718
  try {
39377
- const result = await handleHarnessInstallation(request.params, this.#externalAdapters);
39719
+ if (request.method !== HARNESS_INSTALLATION_STATUS_METHOD) await this.#waitForPlugins();
39720
+ const result = request.method === HARNESS_INSTALLATION_START_METHOD ? this.#installationTasks.start(request.params, this.#externalAdapters) : request.method === HARNESS_INSTALLATION_STATUS_METHOD ? this.#installationTasks.status(request.params) : await handleHarnessInstallation(request.params, this.#externalAdapters);
39378
39721
  await this.#writer.json(rpcEnvelope(request, { result: jsonValueSchema.parse(result) }));
39379
39722
  } catch (error51) {
39380
39723
  await this.#writer.json(
@@ -39481,6 +39824,10 @@ var AppServerHost = class {
39481
39824
  await this.#listThreadOwnership(request);
39482
39825
  return;
39483
39826
  }
39827
+ if (request.method === "codexhost/thread/steering/inspect") {
39828
+ await this.#inspectThreadSteering(request);
39829
+ return;
39830
+ }
39484
39831
  if (request.method === "codexhost/thread/model/select") {
39485
39832
  await this.#selectThreadModel(request);
39486
39833
  return;
@@ -40095,12 +40442,17 @@ var AppServerHost = class {
40095
40442
  ]);
40096
40443
  return thread !== null || childDelegation !== null || delegation !== null;
40097
40444
  }
40098
- async #readOfficialThreadCwd(threadId2) {
40099
- const response = await this.#requestOfficial("thread/read", { threadId: threadId2 });
40100
- if (isRecord19(response.error)) return void 0;
40445
+ async #readOfficialThreadMetadata(threadId2) {
40446
+ const response = await this.#requestOfficial("thread/read", { threadId: threadId2, includeTurns: false });
40447
+ if (isRecord19(response.error)) return {};
40101
40448
  const result = isRecord19(response.result) ? response.result : null;
40102
40449
  const thread = result && isRecord19(result.thread) ? result.thread : null;
40103
- return thread && typeof thread.cwd === "string" && thread.cwd.trim() ? thread.cwd : void 0;
40450
+ if (!thread) return {};
40451
+ const title = typeof thread.name === "string" && thread.name.trim() ? thread.name : thread.preview;
40452
+ return {
40453
+ ...typeof thread.cwd === "string" && thread.cwd.trim() ? { cwd: thread.cwd } : {},
40454
+ ...typeof title === "string" && title.trim() ? { title } : {}
40455
+ };
40104
40456
  }
40105
40457
  async #inspectOfficialDelegationTarget(input) {
40106
40458
  const response = await this.#requestOfficial("model/list", {});
@@ -40253,6 +40605,9 @@ var AppServerHost = class {
40253
40605
  this.#pendingOfficialDelegationThreads.add(threadId2);
40254
40606
  let turnId;
40255
40607
  try {
40608
+ await this.#requestOfficial("thread/name/set", { threadId: threadId2, name: input.title }).catch(
40609
+ () => void 0
40610
+ );
40256
40611
  const turn = await this.#requestOfficial("turn/start", {
40257
40612
  threadId: threadId2,
40258
40613
  input: [{ type: "text", text: input.task }],
@@ -40271,7 +40626,7 @@ var AppServerHost = class {
40271
40626
  throw error51;
40272
40627
  }
40273
40628
  this.#activeOfficialTurns.set(threadId2, turnId);
40274
- const delegationId = hostThreadIdSchema.parse(randomUUID14());
40629
+ const delegationId = hostThreadIdSchema.parse(randomUUID16());
40275
40630
  try {
40276
40631
  const source = await this.#repository.find(input.parentThreadId);
40277
40632
  const pendingTerminal = this.#pendingOfficialTerminalStatuses.get(threadId2);
@@ -40459,7 +40814,7 @@ var AppServerHost = class {
40459
40814
  async #listDelegationThreads(input) {
40460
40815
  const [sortKey, sortDirection2] = input.sort.split("-");
40461
40816
  const request = {
40462
- id: `codexhost:delegation-list:${randomUUID14()}`,
40817
+ id: `codexhost:delegation-list:${randomUUID16()}`,
40463
40818
  method: "thread/list",
40464
40819
  params: {
40465
40820
  cwd: input.cwd ? [input.cwd] : null,
@@ -40868,7 +41223,8 @@ var AppServerHost = class {
40868
41223
  try {
40869
41224
  inspection = await adapter.inspect({
40870
41225
  ...params.data.cwd ? { cwd: params.data.cwd } : {},
40871
- ...params.data.refresh !== void 0 ? { refresh: params.data.refresh } : {}
41226
+ ...params.data.refresh !== void 0 ? { refresh: params.data.refresh } : {},
41227
+ ...params.data.purpose ? { purpose: params.data.purpose } : {}
40872
41228
  });
40873
41229
  } catch (error51) {
40874
41230
  await this.#writer.json(
@@ -41061,6 +41417,28 @@ var AppServerHost = class {
41061
41417
  );
41062
41418
  }
41063
41419
  }
41420
+ /** Read the same delivery decision that Desktop `turn/steer` will follow. */
41421
+ async #inspectThreadSteering(request) {
41422
+ const params = threadSteeringInspectParamsSchema.safeParse(request.params);
41423
+ if (!params.success) {
41424
+ await this.#writer.json(rpcError(request, -32602, "Invalid Thread steering params"));
41425
+ return;
41426
+ }
41427
+ let delivery;
41428
+ try {
41429
+ const location = await this.#locateExternalThread(params.data.threadId);
41430
+ if (await this.#writeResolutionError(request, location)) return;
41431
+ const thread = location.kind === "external" ? this.#externalRuntime.get(params.data.threadId) : void 0;
41432
+ delivery = location.kind !== "external" ? "official" : thread ? await externalSteeringDelivery(thread, params.data.text) : "newTurn";
41433
+ } catch {
41434
+ await this.#writer.json(
41435
+ rpcError(request, -32081, "Thread steering metadata could not be read")
41436
+ );
41437
+ return;
41438
+ }
41439
+ const result = threadSteeringInspectResultSchema.parse({ delivery });
41440
+ await this.#writer.json(rpcEnvelope(request, { result: jsonValueSchema.parse(result) }));
41441
+ }
41064
41442
  async #inspectThreadCommands(request) {
41065
41443
  const params = threadCommandsInspectParamsSchema.safeParse(request.params);
41066
41444
  if (!params.success) {
@@ -41224,7 +41602,7 @@ var AppServerHost = class {
41224
41602
  if (thread.running || thread.activeTurnId) {
41225
41603
  throw new ExternalCommandError(-32072, "External Thread already has an active operation");
41226
41604
  }
41227
- const turnId = requestedTurnId ?? hostTurnIdSchema.parse(randomUUID14());
41605
+ const turnId = requestedTurnId ?? hostTurnIdSchema.parse(randomUUID16());
41228
41606
  const projection = {
41229
41607
  projector: new CodexTurnProjector({
41230
41608
  threadId: thread.id,
@@ -41312,6 +41690,26 @@ var AppServerHost = class {
41312
41690
  if (!projected.effectiveModel) {
41313
41691
  throw new Error("Harness Session did not report an effective Model");
41314
41692
  }
41693
+ const transportModelId = encodeExternalTransportSelection(thread.harnessId, {
41694
+ ...decodeExternalTransportSelection(thread.harnessId, thread.transportModelId) ?? {},
41695
+ model: projected.effectiveModel
41696
+ });
41697
+ thread.transportModelId = transportModelId;
41698
+ thread.requestedModel = projected.effectiveModel;
41699
+ try {
41700
+ thread.record = await this.#repository.setTransportModelId(
41701
+ thread.record.hostThreadId,
41702
+ transportModelId
41703
+ );
41704
+ } catch (error51) {
41705
+ this.#diagnose(error51);
41706
+ }
41707
+ thread.thread = externalThreadValue({
41708
+ record: { ...thread.record, transportModelId },
41709
+ turns: thread.turns,
41710
+ sessionId: thread.sessionId,
41711
+ running: thread.running
41712
+ });
41315
41713
  await this.#writer.json(rpcEnvelope(request, { result: jsonValueSchema.parse(projected) }));
41316
41714
  } catch (error51) {
41317
41715
  await this.#writer.json(
@@ -41641,9 +42039,20 @@ var AppServerHost = class {
41641
42039
  await this.#writer.json(rpcError(request, resolution.error.code, resolution.error.message));
41642
42040
  return true;
41643
42041
  }
42042
+ /** Refresh history before Desktop acts on native Turn boundaries. */
41644
42043
  #refreshExternalThread(thread) {
41645
42044
  return this.#externalRuntime.refresh(thread);
41646
42045
  }
42046
+ #markExternalHistoryRead(thread, turns) {
42047
+ if (!thread.historyHydrated) return;
42048
+ for (const turnId of thread.steeredTurnIds) {
42049
+ if (turnId !== thread.activeTurnId && turns.some(
42050
+ (turn) => turn.id === turnId && (turn.status === "completed" || turn.status === "failed" || turn.status === "interrupted")
42051
+ )) {
42052
+ thread.steeredTurnIds.delete(turnId);
42053
+ }
42054
+ }
42055
+ }
41647
42056
  #persistTerminalIdentity(thread, event) {
41648
42057
  return this.#externalRuntime.persistTerminalIdentity(thread, event);
41649
42058
  }
@@ -41845,17 +42254,19 @@ var AppServerHost = class {
41845
42254
  return;
41846
42255
  }
41847
42256
  }
42257
+ const readTurns = includeTurns ? [...this.#externalHistoryTurns(thread)] : [];
41848
42258
  await this.#writer.json(
41849
42259
  rpcEnvelope(request, {
41850
42260
  result: {
41851
42261
  thread: {
41852
42262
  ...thread.thread,
41853
42263
  ...await this.#externalSectionFields(thread.record.hostThreadId),
41854
- turns: includeTurns ? this.#externalHistoryTurns(thread) : []
42264
+ turns: readTurns
41855
42265
  }
41856
42266
  }
41857
42267
  })
41858
42268
  );
42269
+ if (includeTurns) this.#markExternalHistoryRead(thread, readTurns);
41859
42270
  await this.#replayExternalUsage(thread);
41860
42271
  }
41861
42272
  async #listExternalHistory(request, thread, params, historyFresh) {
@@ -41872,6 +42283,9 @@ var AppServerHost = class {
41872
42283
  const turns = this.#externalHistoryTurns(thread);
41873
42284
  const result = request.method === "thread/turns/list" ? listExternalTurns(turns, params) : listExternalItems(turns, params);
41874
42285
  await this.#writer.json(rpcEnvelope(request, { result }));
42286
+ if (request.method === "thread/turns/list") {
42287
+ this.#markExternalHistoryRead(thread, result.data);
42288
+ }
41875
42289
  } catch (error51) {
41876
42290
  await this.#writer.json(
41877
42291
  rpcError(
@@ -41890,7 +42304,7 @@ var AppServerHost = class {
41890
42304
  return;
41891
42305
  }
41892
42306
  }
41893
- const turns = this.#externalHistoryTurns(thread);
42307
+ const turns = [...this.#externalHistoryTurns(thread)];
41894
42308
  const responseThread = {
41895
42309
  ...await this.#withExternalSection(thread.thread),
41896
42310
  turns: params.excludeTurns === true ? [] : turns
@@ -41922,6 +42336,8 @@ var AppServerHost = class {
41922
42336
  }
41923
42337
  })
41924
42338
  );
42339
+ if (params.excludeTurns !== true) this.#markExternalHistoryRead(thread, turns);
42340
+ else if (initialTurnsPage) this.#markExternalHistoryRead(thread, initialTurnsPage.data);
41925
42341
  } catch (error51) {
41926
42342
  await this.#writer.json(
41927
42343
  rpcError(
@@ -42064,10 +42480,15 @@ var AppServerHost = class {
42064
42480
  assertActive,
42065
42481
  typeof requestObject(request).clientUserMessageId === "string" ? requestObject(request).clientUserMessageId : void 0,
42066
42482
  requestObject(request)[THREAD_REFERENCE_SOURCE_HOST_PARAM]
42067
- )
42483
+ ),
42484
+ (input) => this.#insertExternalInput(thread, input)
42068
42485
  );
42069
42486
  try {
42070
- await this.#writer.json(rpcEnvelope(request, { result: { turnId: started.turnId } }));
42487
+ await this.#writer.json(
42488
+ rpcEnvelope(request, {
42489
+ result: { turnId: started.turnId, delivery: started.delivery }
42490
+ })
42491
+ );
42071
42492
  } finally {
42072
42493
  started.gate.resolve();
42073
42494
  }
@@ -42083,6 +42504,34 @@ var AppServerHost = class {
42083
42504
  this.#signalActiveWorkChanged();
42084
42505
  }
42085
42506
  }
42507
+ /** Native same-Turn input; `insertNativeSteer` owns the delivery and its fallback signal. */
42508
+ async #insertExternalInput(thread, input) {
42509
+ await insertNativeSteer(thread, input, {
42510
+ project: async (turnId, item, clientUserMessageId) => {
42511
+ const projection = this.#projectedTurn(thread, turnId);
42512
+ if (clientUserMessageId) {
42513
+ projection.projector.bindUserMessageClientId(item.itemId, clientUserMessageId);
42514
+ }
42515
+ await this.#projectHarnessOutput(thread, {
42516
+ kind: "event",
42517
+ event: { type: "item.started", turnId, item }
42518
+ });
42519
+ await this.#projectHarnessOutput(thread, {
42520
+ kind: "event",
42521
+ event: {
42522
+ type: "item.completed",
42523
+ turnId,
42524
+ snapshot: { item, outcome: { status: "succeeded" } }
42525
+ }
42526
+ });
42527
+ },
42528
+ diagnose: (error51) => this.#diagnose(error51)
42529
+ });
42530
+ return {
42531
+ turnId: input.turnId,
42532
+ gate: { promise: Promise.resolve(), resolve: () => void 0 }
42533
+ };
42534
+ }
42086
42535
  /** Keep command restoration and dispatch identical for start and steer submissions. */
42087
42536
  async #beginExternalInputTurn(thread, inputText, assertActive, clientUserMessageId, sourceHostId) {
42088
42537
  const text2 = restoreHarnessCommandMentions(inputText);
@@ -42140,7 +42589,7 @@ var AppServerHost = class {
42140
42589
  if (thread.running || thread.activeTurnId || this.#pendingExternalCommandRequests.has(thread.id)) {
42141
42590
  throw new ExternalSteerError(-32072, "External Thread already has an active Turn");
42142
42591
  }
42143
- const turnId = hostTurnIdSchema.parse(randomUUID14());
42592
+ const turnId = hostTurnIdSchema.parse(randomUUID16());
42144
42593
  const startedAtMs = Date.now();
42145
42594
  const projection = {
42146
42595
  projector: new CodexTurnProjector({
@@ -42515,6 +42964,9 @@ var AppServerHost = class {
42515
42964
  }
42516
42965
  return;
42517
42966
  }
42967
+ if (event.type === "turn.completed" && thread.pendingSteerProjections.size > 0) {
42968
+ await Promise.allSettled([...thread.pendingSteerProjections]);
42969
+ }
42518
42970
  const projection = this.#projectedTurn(thread, event.turnId);
42519
42971
  await this.#waitForTurnResponse(thread, event.turnId);
42520
42972
  if (event.type === "interaction.closed" && thread.ignoredInteractionIds.delete(event.interactionId)) {
@@ -42564,6 +43016,7 @@ var AppServerHost = class {
42564
43016
  thread.activeTurnId = null;
42565
43017
  if (!projection.projector.hasOpenDetachedItems) thread.projectedTurns.delete(event.turnId);
42566
43018
  thread.responseGates.delete(event.turnId);
43019
+ thread.pendingSteerProjections.clear();
42567
43020
  this.#signalActiveWorkChanged();
42568
43021
  const delegation = await this.#repository.getDelegationByChild(thread.record.hostThreadId);
42569
43022
  if (delegation) {
@@ -42854,7 +43307,7 @@ var AppServerHost = class {
42854
43307
  try {
42855
43308
  result = projection.projector.projectQuestion(
42856
43309
  interaction,
42857
- hostItemIdSchema.parse(randomUUID14())
43310
+ hostItemIdSchema.parse(randomUUID16())
42858
43311
  );
42859
43312
  } catch (error51) {
42860
43313
  this.#diagnose(error51);
@@ -43093,7 +43546,7 @@ var import_websocket_server = __toESM(require_websocket_server(), 1);
43093
43546
  var wrapper_default = import_websocket.default;
43094
43547
 
43095
43548
  // packages/host-runtime/src/remote-socket-lock.ts
43096
- import { randomUUID as randomUUID15 } from "node:crypto";
43549
+ import { randomUUID as randomUUID17 } from "node:crypto";
43097
43550
  import { chmod as chmod3, lstat as lstat5, mkdir as mkdir12, open as open9, readFile as readFile17, readdir as readdir5, rename as rename11, rm as rm11 } from "node:fs/promises";
43098
43551
  import { uptime } from "node:os";
43099
43552
  import path27 from "node:path";
@@ -43219,7 +43672,7 @@ async function preparePrivateLockDirectory(lockDirectory) {
43219
43672
  await chmod3(lockDirectory, 448);
43220
43673
  }
43221
43674
  async function writeLockRecordAtomic(lockDirectory, entryPath, record4) {
43222
- const temporary = path27.join(lockDirectory, `.tmp-${record4.ownerToken}-${randomUUID15()}`);
43675
+ const temporary = path27.join(lockDirectory, `.tmp-${record4.ownerToken}-${randomUUID17()}`);
43223
43676
  const handle = await open9(temporary, "wx", 384);
43224
43677
  try {
43225
43678
  await handle.writeFile(`${JSON.stringify(record4)}
@@ -43294,7 +43747,7 @@ async function withRemoteAppServerSocketInitializationLock(socketPath, action) {
43294
43747
  const legacyPath = `${socketPath}.initializing`;
43295
43748
  const lockDirectory = `${socketPath}.initializers`;
43296
43749
  await preparePrivateLockDirectory(lockDirectory);
43297
- const ownerToken = randomUUID15();
43750
+ const ownerToken = randomUUID17();
43298
43751
  const entryPath = path27.join(lockDirectory, lockEntryName(ownerToken));
43299
43752
  const baseRecord = {
43300
43753
  version: 2,
@@ -43805,12 +44258,12 @@ function createRemoteAppServerWebSocketListener(input) {
43805
44258
 
43806
44259
  // packages/host-runtime/src/remote-official-app-server.ts
43807
44260
  import { spawn as spawn5 } from "node:child_process";
43808
- import { randomUUID as randomUUID16 } from "node:crypto";
44261
+ import { randomUUID as randomUUID18 } from "node:crypto";
43809
44262
  import { lstat as lstat7, rm as rm13, stat as stat7 } from "node:fs/promises";
43810
44263
  import path29 from "node:path";
43811
44264
  var DEFAULT_CLOSE_TIMEOUT_MS = 2e3;
43812
44265
  var DEFAULT_LISTEN_TIMEOUT_MS = 1e4;
43813
- function remoteOfficialAppServerSocketPath(desktopControlSocketPath, token = randomUUID16()) {
44266
+ function remoteOfficialAppServerSocketPath(desktopControlSocketPath, token = randomUUID18()) {
43814
44267
  if (!path29.posix.isAbsolute(desktopControlSocketPath)) {
43815
44268
  throw new Error("Desktop control socket path must be absolute");
43816
44269
  }
@@ -45061,11 +45514,11 @@ async function readRemoteDelegationThread(environment, input) {
45061
45514
  }
45062
45515
 
45063
45516
  // packages/host-runtime/src/shared-thread-owner.ts
45064
- import { randomUUID as randomUUID18 } from "node:crypto";
45517
+ import { randomUUID as randomUUID20 } from "node:crypto";
45065
45518
  import { PassThrough as PassThrough3 } from "node:stream";
45066
45519
 
45067
45520
  // packages/host-runtime/src/shared-thread-peer.ts
45068
- import { randomUUID as randomUUID17 } from "node:crypto";
45521
+ import { randomUUID as randomUUID19 } from "node:crypto";
45069
45522
  function object5(value2) {
45070
45523
  return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
45071
45524
  }
@@ -45079,7 +45532,7 @@ var StreamThreadPeer = class {
45079
45532
  input;
45080
45533
  output;
45081
45534
  stop;
45082
- #prefix = `shared:${randomUUID17()}:`;
45535
+ #prefix = `shared:${randomUUID19()}:`;
45083
45536
  #pending = /* @__PURE__ */ new Map();
45084
45537
  #listeners = /* @__PURE__ */ new Set();
45085
45538
  #ended = Promise.withResolvers();
@@ -45157,7 +45610,7 @@ var SharedThreadOwner = class {
45157
45610
  input = new PassThrough3();
45158
45611
  output = new PassThrough3();
45159
45612
  #peer = new StreamThreadPeer(this.output, this.input, () => this.input.end());
45160
- #prefix = `shared-interaction:${randomUUID18()}:`;
45613
+ #prefix = `shared-interaction:${randomUUID20()}:`;
45161
45614
  #interactions = /* @__PURE__ */ new Map();
45162
45615
  #listeners = /* @__PURE__ */ new Set();
45163
45616
  #receipts = /* @__PURE__ */ new Map();
@@ -45467,7 +45920,7 @@ var SharedThreadBridge = class {
45467
45920
  };
45468
45921
 
45469
45922
  // packages/host-runtime/src/remote-control-app-server.ts
45470
- import { randomUUID as randomUUID19 } from "node:crypto";
45923
+ import { randomUUID as randomUUID21 } from "node:crypto";
45471
45924
  import { mkdir as mkdir15, open as open10, rename as rename12, rm as rm14 } from "node:fs/promises";
45472
45925
  import path34 from "node:path";
45473
45926
  var REMOTE_CONTROL_BRIDGE_PIPE_ENV = "CODEXHOST_REMOTE_CONTROL_BRIDGE_PIPE";
@@ -45488,7 +45941,7 @@ function nodeCompatibleWindowsPath(value2) {
45488
45941
  if (value2.startsWith("\\\\?\\")) return value2.slice(4);
45489
45942
  return value2;
45490
45943
  }
45491
- function remoteControlBridgePipePath(processId = process.pid, instanceId = randomUUID19()) {
45944
+ function remoteControlBridgePipePath(processId = process.pid, instanceId = randomUUID21()) {
45492
45945
  const safeInstance = instanceId.replaceAll(/[^a-zA-Z0-9-]/gu, "");
45493
45946
  if (!safeInstance) throw new Error("Remote Control bridge instance ID is invalid");
45494
45947
  return `\\\\.\\pipe\\codexhost-remote-control-${processId}-${safeInstance}`;
@@ -45503,7 +45956,7 @@ async function publishRemoteControlAppServerDescriptor(plan) {
45503
45956
  await mkdir15(directory, { recursive: true, mode: 448 });
45504
45957
  const temporaryPath = path34.join(
45505
45958
  directory,
45506
- `.${REMOTE_CONTROL_BRIDGE_DESCRIPTOR_FILE}.${plan.descriptor.ownerPid}.${randomUUID19()}.tmp`
45959
+ `.${REMOTE_CONTROL_BRIDGE_DESCRIPTOR_FILE}.${plan.descriptor.ownerPid}.${randomUUID21()}.tmp`
45507
45960
  );
45508
45961
  const handle = await open10(temporaryPath, "wx", 384);
45509
45962
  try {
@@ -46025,12 +46478,19 @@ function createHostUpdateCoordinator(options2) {
46025
46478
  }
46026
46479
 
46027
46480
  // packages/host-runtime/src/usage-statistics.ts
46028
- import { randomUUID as randomUUID20 } from "node:crypto";
46481
+ import { randomUUID as randomUUID22 } from "node:crypto";
46029
46482
  import { mkdir as mkdir17, readFile as readFile18, readdir as readdir6, rename as rename14, rm as rm16, writeFile as writeFile10 } from "node:fs/promises";
46030
46483
  import path37 from "node:path";
46031
46484
  import { setImmediate as yieldToEventLoop } from "node:timers/promises";
46032
46485
 
46033
46486
  // packages/harness-adapter/dist/usage-statistics.js
46487
+ var HarnessUsageSourceChangedError = class extends Error {
46488
+ code = "HARNESS_USAGE_SOURCE_CHANGED";
46489
+ /** Plugins may bundle their own copy of this contract, so instanceof is insufficient. */
46490
+ static is(error51) {
46491
+ return typeof error51 === "object" && error51 !== null && "code" in error51 && error51.code === "HARNESS_USAGE_SOURCE_CHANGED";
46492
+ }
46493
+ };
46034
46494
  var MAX_SESSION_ID_LENGTH = 512;
46035
46495
  var MAX_CWD_LENGTH = 4096;
46036
46496
  var MAX_SESSION_TITLE_LENGTH = 200;
@@ -46042,10 +46502,13 @@ function usageSessionTitle(value2) {
46042
46502
  return void 0;
46043
46503
  if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
46044
46504
  return normalized;
46045
- const characters = [...normalized];
46046
- if (characters.length <= MAX_SESSION_TITLE_LENGTH)
46047
- return normalized;
46048
- return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
46505
+ let title = "";
46506
+ for (const character of normalized) {
46507
+ if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
46508
+ break;
46509
+ title += character;
46510
+ }
46511
+ return `${title.trimEnd()}…`;
46049
46512
  }
46050
46513
  function sessionIdOk(value2) {
46051
46514
  return typeof value2 === "string" && value2.length > 0 && value2.length <= MAX_SESSION_ID_LENGTH;
@@ -46130,6 +46593,95 @@ function withHostSessionTitles(result, records) {
46130
46593
  };
46131
46594
  }
46132
46595
 
46596
+ // packages/host-runtime/src/usage-statistics-sources.ts
46597
+ import { setTimeout as delay6 } from "node:timers/promises";
46598
+ async function* readUsageStatisticsSources(capability, sources, signal) {
46599
+ let pending = sources;
46600
+ for (let attempt = 0; ; attempt++) {
46601
+ const changed = [];
46602
+ for (const source of pending) {
46603
+ signal.throwIfAborted();
46604
+ try {
46605
+ const entries = (await capability.readSource(source.id, signal)).map(parseHarnessUsageEntry).filter((entry) => entry !== null);
46606
+ yield { source, entries };
46607
+ } catch (error51) {
46608
+ signal.throwIfAborted();
46609
+ if (HarnessUsageSourceChangedError.is(error51) && attempt < 2) changed.push(source);
46610
+ else yield { source, error: error51 };
46611
+ }
46612
+ }
46613
+ if (!changed.length) return;
46614
+ await delay6(50 * (attempt + 1), void 0, { signal });
46615
+ let current;
46616
+ try {
46617
+ current = new Map(
46618
+ (await capability.listSources(signal)).map((source) => [source.id, source])
46619
+ );
46620
+ } catch (error51) {
46621
+ signal.throwIfAborted();
46622
+ for (const source of changed) yield { source, error: error51 };
46623
+ return;
46624
+ }
46625
+ const next = [];
46626
+ for (const source of changed) {
46627
+ const fresh = current.get(source.id);
46628
+ if (fresh) next.push(fresh);
46629
+ else yield { source, removed: true };
46630
+ }
46631
+ pending = next;
46632
+ }
46633
+ }
46634
+
46635
+ // packages/host-runtime/src/usage-statistics-calendar.ts
46636
+ function dateKey(year, month, day) {
46637
+ return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
46638
+ }
46639
+ function createUsageStatisticsCalendar(timeZone) {
46640
+ const localZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
46641
+ const zone = timeZone ?? localZone;
46642
+ if (zone === localZone) {
46643
+ return {
46644
+ timeZone: zone,
46645
+ at(ms) {
46646
+ const date5 = new Date(ms);
46647
+ return {
46648
+ date: dateKey(date5.getFullYear(), date5.getMonth() + 1, date5.getDate()),
46649
+ weekday: date5.getDay(),
46650
+ hour: date5.getHours()
46651
+ };
46652
+ }
46653
+ };
46654
+ }
46655
+ const format = new Intl.DateTimeFormat("en-US", {
46656
+ timeZone: zone,
46657
+ calendar: "gregory",
46658
+ numberingSystem: "latn",
46659
+ year: "numeric",
46660
+ month: "2-digit",
46661
+ day: "2-digit",
46662
+ hour: "2-digit",
46663
+ hourCycle: "h23"
46664
+ });
46665
+ return {
46666
+ timeZone: zone,
46667
+ at(ms) {
46668
+ const parts = format.formatToParts(ms);
46669
+ const part = (type) => Number(parts.find((value2) => value2.type === type)?.value);
46670
+ const year = part("year"), month = part("month"), day = part("day");
46671
+ return {
46672
+ date: dateKey(year, month, day),
46673
+ weekday: new Date(Date.UTC(year, month - 1, day)).getUTCDay(),
46674
+ hour: part("hour")
46675
+ };
46676
+ }
46677
+ };
46678
+ }
46679
+ function shiftUsageDate(date5, days) {
46680
+ const value2 = /* @__PURE__ */ new Date(`${date5}T12:00:00Z`);
46681
+ value2.setUTCDate(value2.getUTCDate() + days);
46682
+ return dateKey(value2.getUTCFullYear(), value2.getUTCMonth() + 1, value2.getUTCDate());
46683
+ }
46684
+
46133
46685
  // packages/host-runtime/src/usage-statistics.ts
46134
46686
  var CACHE_VERSION = 7;
46135
46687
  var STALE_AFTER_MS = 1e4;
@@ -46190,17 +46742,6 @@ function expand(value2, intern) {
46190
46742
  function message(error51) {
46191
46743
  return error51 instanceof Error ? error51.message : String(error51);
46192
46744
  }
46193
- function localDate2(ms) {
46194
- const date5 = new Date(ms);
46195
- const month = String(date5.getMonth() + 1).padStart(2, "0");
46196
- const day = String(date5.getDate()).padStart(2, "0");
46197
- return `${date5.getFullYear()}-${month}-${day}`;
46198
- }
46199
- function shiftDate(date5, days) {
46200
- const value2 = /* @__PURE__ */ new Date(`${date5}T12:00:00`);
46201
- value2.setDate(value2.getDate() + days);
46202
- return localDate2(value2.getTime());
46203
- }
46204
46745
  var SESSIONS_PER_MEASURE = 50;
46205
46746
  var MODELS_PER_SESSION = 16;
46206
46747
  function emptyTotals() {
@@ -46387,23 +46928,27 @@ var UsageStatistics = class {
46387
46928
  }
46388
46929
  for (const { harness: harness2, capability, ids } of listed) {
46389
46930
  const cache = this.#cache(harness2);
46390
- const present = /* @__PURE__ */ new Set();
46931
+ const present = new Set(ids.map(({ id: id2 }) => id2));
46391
46932
  let failed = null;
46392
- for (const { id: id2, fingerprint } of ids) {
46393
- present.add(id2);
46394
- if (cache.sources.get(id2)?.fingerprint !== fingerprint) {
46395
- try {
46396
- const entries = (await capability.readSource(id2, signal)).map(parseHarnessUsageEntry).filter((entry) => entry !== null);
46397
- cache.sources.set(id2, { fingerprint, entries });
46933
+ const pending = ids.filter(
46934
+ ({ id: id2, fingerprint }) => cache.sources.get(id2)?.fingerprint !== fingerprint
46935
+ );
46936
+ this.#progress.read += ids.length - pending.length;
46937
+ try {
46938
+ for await (const result of readUsageStatisticsSources(capability, pending, signal)) {
46939
+ const { id: id2, fingerprint } = result.source;
46940
+ if ("entries" in result) {
46941
+ cache.sources.set(id2, { fingerprint, entries: result.entries });
46398
46942
  cache.dirty = true;
46399
46943
  this.#generation += 1;
46400
- } catch (error51) {
46401
- if (signal.aborted) return;
46402
- failed ??= message(error51);
46403
- }
46944
+ } else if ("error" in result) failed ??= message(result.error);
46945
+ else present.delete(id2);
46946
+ this.#progress.read += 1;
46404
46947
  await yieldToEventLoop();
46405
46948
  }
46406
- this.#progress.read += 1;
46949
+ } catch (error51) {
46950
+ if (signal.aborted) return;
46951
+ throw error51;
46407
46952
  }
46408
46953
  for (const id2 of cache.sources.keys()) {
46409
46954
  if (!present.has(id2)) {
@@ -46468,7 +47013,7 @@ var UsageStatistics = class {
46468
47013
  async #persist(harness2, cache) {
46469
47014
  if (!cache.dirty || this.#now() - cache.persistedAtMs < PERSIST_INTERVAL_MS) return;
46470
47015
  const file2 = this.#file(harness2);
46471
- const temporary = `${file2}.${randomUUID20()}.tmp`;
47016
+ const temporary = `${file2}.${randomUUID22()}.tmp`;
46472
47017
  try {
46473
47018
  await mkdir17(this.#directory, { recursive: true });
46474
47019
  const sources = [...cache.sources].map(([id2, source]) => [
@@ -46486,9 +47031,10 @@ var UsageStatistics = class {
46486
47031
  await rm16(temporary, { force: true });
46487
47032
  }
46488
47033
  }
46489
- /** Every request once, per Harness in source order, with its local date and hour. */
46490
- #indexed() {
46491
- if (this.#index?.generation === this.#generation) return this.#index.entries;
47034
+ /** Every request once, per Harness in source order, in the requested calendar. */
47035
+ #indexed(calendar) {
47036
+ if (this.#index?.generation === this.#generation && this.#index.timeZone === calendar.timeZone)
47037
+ return this.#index.entries;
46492
47038
  const entries = [];
46493
47039
  for (const [harness2, cache] of this.#caches) {
46494
47040
  const seen = /* @__PURE__ */ new Set();
@@ -46496,26 +47042,20 @@ var UsageStatistics = class {
46496
47042
  for (const entry of parsed2) {
46497
47043
  if (seen.has(entry.id)) continue;
46498
47044
  seen.add(entry.id);
46499
- const at = new Date(entry.occurredAtMs);
46500
- entries.push({
46501
- harness: harness2,
46502
- entry,
46503
- date: localDate2(entry.occurredAtMs),
46504
- weekday: at.getDay(),
46505
- hour: at.getHours()
46506
- });
47045
+ entries.push({ harness: harness2, entry, ...calendar.at(entry.occurredAtMs) });
46507
47046
  }
46508
47047
  }
46509
47048
  }
46510
- this.#index = { generation: this.#generation, entries };
47049
+ this.#index = { generation: this.#generation, timeZone: calendar.timeZone, entries };
46511
47050
  return entries;
46512
47051
  }
46513
47052
  #aggregate(params, now, lookup) {
46514
47053
  const { range } = params;
46515
47054
  const days = RANGE_DAYS[range];
46516
- const to = localDate2(now);
47055
+ const calendar = createUsageStatisticsCalendar(params.timeZone);
47056
+ const to = calendar.at(now).date;
46517
47057
  let from = null;
46518
- if (days !== null) from = shiftDate(to, -days + 1);
47058
+ if (days !== null) from = shiftUsageDate(to, -days + 1);
46519
47059
  const inRange = (date5) => (from === null || date5 >= from) && date5 <= to;
46520
47060
  const day = params.date !== void 0 && inRange(params.date) ? params.date : null;
46521
47061
  const harnessFilter = params.harness ?? null;
@@ -46556,7 +47096,7 @@ var UsageStatistics = class {
46556
47096
  const harnessPriced = /* @__PURE__ */ new Map();
46557
47097
  const byProject = /* @__PURE__ */ new Map();
46558
47098
  const sessions = /* @__PURE__ */ new Map();
46559
- for (const indexed of this.#indexed()) {
47099
+ for (const indexed of this.#indexed(calendar)) {
46560
47100
  const { harness: harness2, entry, date: date5 } = indexed;
46561
47101
  if (!inRange(date5)) continue;
46562
47102
  const model2 = entry.model ?? null;
@@ -47087,7 +47627,7 @@ async function runHostRuntime(input) {
47087
47627
  }
47088
47628
 
47089
47629
  // packages/host-runtime/src/remote-host-install.ts
47090
- import { createHash as createHash11, randomUUID as randomUUID21 } from "node:crypto";
47630
+ import { createHash as createHash11, randomUUID as randomUUID23 } from "node:crypto";
47091
47631
  import { constants as fsConstants } from "node:fs";
47092
47632
  import {
47093
47633
  access as access3,
@@ -47186,7 +47726,7 @@ async function writeAtomic(filePath, contents, mode) {
47186
47726
  await mkdir18(path39.dirname(filePath), { recursive: true, mode: 448 });
47187
47727
  const temporary = path39.join(
47188
47728
  path39.dirname(filePath),
47189
- `.${path39.basename(filePath)}.${process.pid}.${randomUUID21()}.tmp`
47729
+ `.${path39.basename(filePath)}.${process.pid}.${randomUUID23()}.tmp`
47190
47730
  );
47191
47731
  try {
47192
47732
  if (typeof contents === "string") {
@@ -47210,7 +47750,7 @@ async function writeAtomicExecutable(filePath, sourcePath) {
47210
47750
  await mkdir18(path39.dirname(filePath), { recursive: true, mode: 448 });
47211
47751
  const temporary = path39.join(
47212
47752
  path39.dirname(filePath),
47213
- `.${path39.basename(filePath)}.${process.pid}.${randomUUID21()}.tmp`
47753
+ `.${path39.basename(filePath)}.${process.pid}.${randomUUID23()}.tmp`
47214
47754
  );
47215
47755
  try {
47216
47756
  await copyFile4(sourcePath, temporary);
@@ -47965,6 +48505,7 @@ var harnessBrokerMethodSchema = external_exports.enum([
47965
48505
  "adapter.sessionImport.resolve",
47966
48506
  "adapter.subagent.readSnapshot",
47967
48507
  "session.readSnapshot",
48508
+ "session.readCapabilities",
47968
48509
  "session.refreshUsage",
47969
48510
  "session.execute",
47970
48511
  "session.commands.list",
@@ -48168,6 +48709,11 @@ var turnStartSchema = external_exports.object({
48168
48709
  turnId: hostTurnIdSchema,
48169
48710
  input: external_exports.array(textInputSchema)
48170
48711
  }).strict();
48712
+ var turnSteerSchema = external_exports.object({
48713
+ type: external_exports.literal("turn.steer"),
48714
+ turnId: hostTurnIdSchema,
48715
+ input: external_exports.array(textInputSchema)
48716
+ }).strict();
48171
48717
  var turnCancelSchema = external_exports.object({ type: external_exports.literal("turn.cancel"), turnId: hostTurnIdSchema }).strict();
48172
48718
  var interactionResponseSchema = external_exports.union([
48173
48719
  external_exports.object({
@@ -48193,6 +48739,7 @@ var permissionSelectSchema = external_exports.object({
48193
48739
  }).strict();
48194
48740
  var brokerHostCommandSchema = external_exports.discriminatedUnion("type", [
48195
48741
  turnStartSchema,
48742
+ turnSteerSchema,
48196
48743
  turnCancelSchema,
48197
48744
  interactionRespondSchema,
48198
48745
  modelSelectSchema,
@@ -48327,7 +48874,7 @@ var harnessOutputSchema = external_exports.custom((value2) => {
48327
48874
  });
48328
48875
 
48329
48876
  // packages/harness-broker/dist/server.js
48330
- import { randomBytes as randomBytes5, randomUUID as randomUUID22 } from "node:crypto";
48877
+ import { randomBytes as randomBytes5, randomUUID as randomUUID24 } from "node:crypto";
48331
48878
  import { chmod as chmod6, lstat as lstat10, mkdir as mkdir19, open as open11, readFile as readFile20, rename as rename16, rm as rm18 } from "node:fs/promises";
48332
48879
  import net4, {} from "node:net";
48333
48880
  import path42 from "node:path";
@@ -48386,7 +48933,7 @@ async function assertNoLiveDescriptor(descriptorPath) {
48386
48933
  }
48387
48934
  }
48388
48935
  async function publishDescriptor(descriptorPath, descriptor) {
48389
- const temporary = `${descriptorPath}.${process.pid}.${randomUUID22()}.tmp`;
48936
+ const temporary = `${descriptorPath}.${process.pid}.${randomUUID24()}.tmp`;
48390
48937
  const handle = await open11(temporary, "wx", 384);
48391
48938
  try {
48392
48939
  await handle.writeFile(`${JSON.stringify(descriptor)}
@@ -48411,6 +48958,7 @@ function sessionMetadata(record4) {
48411
48958
  sessionId: record4.id,
48412
48959
  sessionGeneration: record4.generation,
48413
48960
  capabilities: record4.session.capabilities,
48961
+ readCapabilities: true,
48414
48962
  initialState: {
48415
48963
  ...initialState,
48416
48964
  ...record4.nativeRef ? { nativeRef: record4.nativeRef } : {},
@@ -48463,7 +49011,7 @@ async function startHarnessBrokerServer(input) {
48463
49011
  await assertNoLiveDescriptor(input.descriptorPath);
48464
49012
  if (process.platform !== "win32")
48465
49013
  await prepareUnixSocketPath(input.socketPath);
48466
- const generation = input.generation ?? randomUUID22();
49014
+ const generation = input.generation ?? randomUUID24();
48467
49015
  const token = input.token ?? randomBytes5(32).toString("hex");
48468
49016
  const descriptor = {
48469
49017
  schemaVersion: 1,
@@ -48504,7 +49052,7 @@ async function startHarnessBrokerServer(input) {
48504
49052
  };
48505
49053
  const server = net4.createServer((socket) => {
48506
49054
  const state = {
48507
- id: randomUUID22(),
49055
+ id: randomUUID24(),
48508
49056
  socket,
48509
49057
  authenticated: false,
48510
49058
  inputSequence: 0,
@@ -48786,7 +49334,7 @@ async function startHarnessBrokerServer(input) {
48786
49334
  }
48787
49335
  };
48788
49336
  }
48789
- const openReservation = randomUUID22();
49337
+ const openReservation = randomUUID24();
48790
49338
  if (sourceKey)
48791
49339
  nativeWriters.set(sourceKey, openReservation);
48792
49340
  const provisionalReservation = openInput.kind === "create" ? openReservation : void 0;
@@ -48930,6 +49478,8 @@ async function startHarnessBrokerServer(input) {
48930
49478
  let result;
48931
49479
  if (command.type === "turn.start")
48932
49480
  result = await record5.session.execute(command);
49481
+ else if (command.type === "turn.steer")
49482
+ result = await record5.session.execute(command);
48933
49483
  else if (command.type === "turn.cancel")
48934
49484
  result = await record5.session.execute(command);
48935
49485
  else if (command.type === "interaction.respond") {
@@ -48961,6 +49511,10 @@ async function startHarnessBrokerServer(input) {
48961
49511
  }
48962
49512
  return result;
48963
49513
  }
49514
+ if (request.method === "session.readCapabilities") {
49515
+ const session = requireSession(request.params).session;
49516
+ return session.readCapabilities ? session.readCapabilities() : session.capabilities;
49517
+ }
48964
49518
  if (request.method === "session.readSnapshot") {
48965
49519
  return requireSession(request.params).session.readSnapshot();
48966
49520
  }
@@ -49087,7 +49641,7 @@ async function startHarnessBrokerServer(input) {
49087
49641
  }
49088
49642
  state.authenticated = true;
49089
49643
  state.inputSequence = 1;
49090
- await send({ kind: "response", id: randomUUID22(), ok: true, value: { ready: true } });
49644
+ await send({ kind: "response", id: randomUUID24(), ok: true, value: { ready: true } });
49091
49645
  return;
49092
49646
  }
49093
49647
  const parsed2 = harnessBrokerRequestSchema.safeParse(raw);