@super-one/cli 0.77.0-alpha.1 → 0.77.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/MANIFEST.json +2 -2
  2. package/lib/cli.mjs +537 -407
  3. package/package.json +1 -1
package/lib/cli.mjs CHANGED
@@ -142,8 +142,8 @@ import { fileURLToPath } from "node:url";
142
142
  function resolveCliReleaseVersion() {
143
143
  const fromEnv = process.env.SUPERONE_CLI_VERSION?.trim();
144
144
  if (fromEnv) return fromEnv;
145
- if ("0.77.0-alpha.1".trim()) {
146
- return "0.77.0-alpha.1".trim();
145
+ if ("0.77.0-alpha.2".trim()) {
146
+ return "0.77.0-alpha.2".trim();
147
147
  }
148
148
  const fromDist = readDistManifestVersion();
149
149
  if (fromDist) return fromDist;
@@ -10753,8 +10753,8 @@ var init_mcp_app_resource = __esm({
10753
10753
  return cached5 ? Promise.resolve(cached5) : this.refresh(key3, read5);
10754
10754
  }
10755
10755
  refresh(key3, read5) {
10756
- const pending3 = this.pending.get(key3);
10757
- if (pending3) return pending3;
10756
+ const pending4 = this.pending.get(key3);
10757
+ if (pending4) return pending4;
10758
10758
  if (this.pending.size >= this.limits.pending) return Promise.reject(new McpAppsError("denied", "Too many pending MCP App resource reads"));
10759
10759
  const next = Promise.resolve().then(read5).then((value) => {
10760
10760
  this.put(key3, value);
@@ -11170,6 +11170,10 @@ function isToolResultBlock(block) {
11170
11170
  function isToolUseBlock(block) {
11171
11171
  return "toolName" in block;
11172
11172
  }
11173
+ function hasEditReplacementFields(input) {
11174
+ const obj = parseInputObject(input);
11175
+ return typeof obj.old_string === "string" || typeof obj.new_string === "string" || typeof obj.TargetContent === "string" || typeof obj.ReplacementContent === "string" || Array.isArray(obj.ReplacementChunks) || Array.isArray(obj.edits);
11176
+ }
11173
11177
  function parseInputObject(input) {
11174
11178
  if (input == null || input === "") return {};
11175
11179
  if (typeof input === "object" && !Array.isArray(input)) {
@@ -11301,12 +11305,14 @@ function applyContentDelta(content, delta, now = Date.now, options = {}) {
11301
11305
  delta.toolSummary,
11302
11306
  mergedInput
11303
11307
  );
11308
+ const preservedToolName = existing.toolName === "Write" && delta.toolName === "Edit" && !hasEditReplacementFields(delta.input) ? existing.toolName : delta.toolName;
11304
11309
  const liveOutput = delta.outputDelta === void 0 ? existing.liveOutput : options.replace ? delta.outputDelta : (existing.liveOutput ?? "") + delta.outputDelta;
11305
11310
  return content.map((b5, i2) => i2 === idx ? {
11306
11311
  ...existing,
11307
11312
  ...withoutOutputDelta(delta),
11308
11313
  ...liveOutput !== void 0 ? { liveOutput } : {},
11309
11314
  ...existing.app || delta.app ? { app: mergeMcpAppAttachment(existing.app, delta.app) } : {},
11315
+ toolName: preservedToolName,
11310
11316
  startedAt: existing.startedAt,
11311
11317
  elapsedSeconds: delta.elapsedSeconds ?? existing.elapsedSeconds,
11312
11318
  status: delta.status ?? existing.status,
@@ -11452,7 +11458,14 @@ var init_content_delta = __esm({
11452
11458
  "skill",
11453
11459
  "tool_name",
11454
11460
  "subject",
11455
- "task_id"
11461
+ "task_id",
11462
+ "content",
11463
+ "CodeContent",
11464
+ "old_string",
11465
+ "new_string",
11466
+ "TargetContent",
11467
+ "ReplacementContent",
11468
+ "TargetFile"
11456
11469
  ];
11457
11470
  CODEX_DETACHED_ITEM_TYPES = /* @__PURE__ */ new Set(["image_generation", "video_generation"]);
11458
11471
  }
@@ -11822,21 +11835,21 @@ function codexAsyncQuestionItems(message) {
11822
11835
  function pendingCodexAsyncQuestions(messages) {
11823
11836
  const answered = new Set(messages.filter(isCodexAsyncAnswer).map((message) => message.id));
11824
11837
  const seen = /* @__PURE__ */ new Set();
11825
- const pending3 = [];
11838
+ const pending4 = [];
11826
11839
  for (const message of messages) {
11827
11840
  if (message.role !== "assistant") continue;
11828
11841
  for (const item of codexAsyncQuestionItems(message)) {
11829
11842
  if (seen.has(item.id)) continue;
11830
11843
  seen.add(item.id);
11831
- if (!answered.has(codexAsyncAnswerId(item.id))) pending3.push({ messageId: message.id, item, request: codexAsyncQuestionRequest(item) });
11844
+ if (!answered.has(codexAsyncAnswerId(item.id))) pending4.push({ messageId: message.id, item, request: codexAsyncQuestionRequest(item) });
11832
11845
  }
11833
11846
  }
11834
- return pending3;
11847
+ return pending4;
11835
11848
  }
11836
11849
  function codexAsyncQuestionQueue(session) {
11837
- const pending3 = session.pendingAsyncQuestions ?? pendingCodexAsyncQuestions(session.messages);
11850
+ const pending4 = session.pendingAsyncQuestions ?? pendingCodexAsyncQuestions(session.messages);
11838
11851
  const answered = new Set(session.messages.filter(isCodexAsyncAnswer).map((message) => message.id));
11839
- return pending3.some((q3) => answered.has(q3.request.requestId)) ? pending3.filter((q3) => !answered.has(q3.request.requestId)) : pending3;
11852
+ return pending4.some((q3) => answered.has(q3.request.requestId)) ? pending4.filter((q3) => !answered.has(q3.request.requestId)) : pending4;
11840
11853
  }
11841
11854
  function codexAsyncAnswerQuestions(message, messages) {
11842
11855
  if (!isCodexAsyncAnswer(message)) return void 0;
@@ -12004,10 +12017,10 @@ function coverBeforeCut(content, at2) {
12004
12017
  const keys = contentKeys(content);
12005
12018
  const counts = /* @__PURE__ */ new Map();
12006
12019
  const map2 = {};
12007
- let pending3 = [];
12020
+ let pending4 = [];
12008
12021
  const flush = () => {
12009
- for (const item of pending3) map2[item.key] = item.length;
12010
- pending3 = [];
12022
+ for (const item of pending4) map2[item.key] = item.length;
12023
+ pending4 = [];
12011
12024
  };
12012
12025
  const placed = () => (counts.get(kind) ?? 0) === target2 && Object.keys(map2).length ? map2 : null;
12013
12026
  for (let index = 0; index < content.length; index++) {
@@ -12023,7 +12036,7 @@ function coverBeforeCut(content, at2) {
12023
12036
  counts.set(name, (counts.get(name) ?? 0) + value);
12024
12037
  }
12025
12038
  if (count === 0) {
12026
- if (key3) pending3.push({ key: key3, length: -1 });
12039
+ if (key3) pending4.push({ key: key3, length: -1 });
12027
12040
  continue;
12028
12041
  }
12029
12042
  if (target2 < start || target2 < start + count) return target2 < start ? placed() : null;
@@ -12048,7 +12061,7 @@ function coverBeforeCut(content, at2) {
12048
12061
  }
12049
12062
  }
12050
12063
  const text4 = blockText(block);
12051
- if (key3) pending3.push({ key: key3, length: text4 === void 0 ? -1 : text4.length });
12064
+ if (key3) pending4.push({ key: key3, length: text4 === void 0 ? -1 : text4.length });
12052
12065
  }
12053
12066
  return placed();
12054
12067
  }
@@ -13990,6 +14003,53 @@ var init_input_admission = __esm({
13990
14003
  }
13991
14004
  });
13992
14005
 
14006
+ // ../../packages/runtime/src/session/codex-async-question.ts
14007
+ async function answerNodeAsyncQuestion(session, messages, command, deliver) {
14008
+ if (session.harnessId !== "codex") throw Object.assign(new Error("Async questions require a Codex session"), { code: "unsupported" });
14009
+ const savedId = typeof command.itemId === "string" ? codexAsyncAnswerId(command.itemId) : null;
14010
+ const saved = codexAsyncReplyText(messages.find((message2) => message2.id === savedId && message2.role === "user"));
14011
+ if (saved !== null) return { reply: saved };
14012
+ const message = messages.find((message2) => message2.id === command.messageId && message2.role === "assistant");
14013
+ const item = message ? codexAsyncQuestionItems(message).find((item2) => item2.id === command.itemId) : void 0;
14014
+ if (!item?.questions?.length) throw Object.assign(new Error("Async question not found"), { code: "not_found" });
14015
+ if (!Array.isArray(command.answers) || command.answers.length !== item.questions.length || command.answers.some((answer2) => typeof answer2 !== "string" || !answer2.trim())) {
14016
+ throw Object.assign(new Error("Every question requires an answer"), { code: "invalid_argument" });
14017
+ }
14018
+ const replyId = codexAsyncAnswerId(item.id);
14019
+ let requests2 = pending.get(session);
14020
+ if (!requests2) {
14021
+ requests2 = /* @__PURE__ */ new Map();
14022
+ pending.set(session, requests2);
14023
+ }
14024
+ const existing = requests2.get(replyId);
14025
+ if (existing) return existing;
14026
+ const reply = formatCodexAsyncQuestionReply(item.questions, command.answers);
14027
+ const answer = anchorAsyncAnswer({
14028
+ id: replyId,
14029
+ role: "user",
14030
+ status: "complete",
14031
+ content: [{ type: "text", text: reply, codexAsyncQuestions: item.questions }],
14032
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
14033
+ providerId: "codex"
14034
+ }, messages);
14035
+ const request = deliver(answer, reply).then(() => ({ reply }));
14036
+ requests2.set(replyId, request);
14037
+ try {
14038
+ return await request;
14039
+ } finally {
14040
+ requests2.delete(replyId);
14041
+ }
14042
+ }
14043
+ var pending;
14044
+ var init_codex_async_question2 = __esm({
14045
+ "../../packages/runtime/src/session/codex-async-question.ts"() {
14046
+ "use strict";
14047
+ init_codex_async_question();
14048
+ init_transcript_boundary();
14049
+ pending = /* @__PURE__ */ new WeakMap();
14050
+ }
14051
+ });
14052
+
13993
14053
  // ../../packages/shared/src/codex-accounts.ts
13994
14054
  function isCodexAccountProvider(id) {
13995
14055
  return !!id?.startsWith(CODEX_ACCOUNT_PREFIX);
@@ -17610,6 +17670,7 @@ var init_session_runtime = __esm({
17610
17670
  init_attachment_state();
17611
17671
  init_artifact_wakes();
17612
17672
  init_input_admission();
17673
+ init_codex_async_question2();
17613
17674
  init_codex_accounts();
17614
17675
  init_session_send();
17615
17676
  init_agent_types();
@@ -18587,6 +18648,45 @@ var init_session_runtime = __esm({
18587
18648
  }) {
18588
18649
  const session = this.live.get(sessionId);
18589
18650
  if (!session || session.closed) throw Object.assign(new Error("session not found"), { code: "not_found" });
18651
+ if (method === "session.answerAsyncQuestion") {
18652
+ assertControl2();
18653
+ if (this.disposing || session.status === "ended") throw Object.assign(new Error("session is closed"), { code: "failed_precondition" });
18654
+ return answerNodeAsyncQuestion(session, this.messages(sessionId), input, async (message, text4) => {
18655
+ const admission = new InputAdmission({
18656
+ beforeInput: assertControl2,
18657
+ onInputAccepted: () => {
18658
+ session.transcript.push({
18659
+ id: message.id,
18660
+ role: "user",
18661
+ text: text4,
18662
+ createdAt: Date.parse(message.createdAt),
18663
+ userMessageContent: message.content,
18664
+ ...message.metadata ? { metadata: message.metadata } : {}
18665
+ });
18666
+ session.updatedAt = Date.now();
18667
+ this.persist(session);
18668
+ this.events.appendSession({
18669
+ sessionId,
18670
+ eventType: SESSION_DURABLE_EVENT.userMessage,
18671
+ payload: { blockId: message.id, text: text4, message, echoUserMessage: true }
18672
+ });
18673
+ }
18674
+ });
18675
+ this.beginTurn(session, {
18676
+ text: text4,
18677
+ userBlockId: message.id,
18678
+ inputAdmission: admission,
18679
+ // The Codex runner steers a live turn and starts normally when it has ended.
18680
+ turnKind: "run",
18681
+ model: session.model,
18682
+ effort: session.effort,
18683
+ apiProviderId: session.apiProviderId,
18684
+ permissionMode: session.permissionMode,
18685
+ sandboxMode: session.sandboxMode
18686
+ });
18687
+ await admission.promise;
18688
+ });
18689
+ }
18590
18690
  if (method === "session.steer" || method === "session.dequeue") return operateNodeQueue(method, input, {
18591
18691
  session,
18592
18692
  queue: this.turnQueues.get(sessionId) ?? [],
@@ -18615,7 +18715,7 @@ var init_session_runtime = __esm({
18615
18715
  });
18616
18716
  }
18617
18717
  get servedOperations() {
18618
- return this.turnRunner.servedOperations ?? /* @__PURE__ */ new Set();
18718
+ return /* @__PURE__ */ new Set(["session.answerAsyncQuestion", ...this.turnRunner.servedOperations ?? []]);
18619
18719
  }
18620
18720
  /** Live Codex app-server for a voice call on this node. */
18621
18721
  codexVoice() {
@@ -19199,11 +19299,11 @@ var init_session_runtime = __esm({
19199
19299
  generation: input.generation,
19200
19300
  holderClientId: input.client.clientSessionId
19201
19301
  });
19202
- const pending3 = session.pendingInteraction;
19203
- if (!pending3 || pending3.interactionId !== input.interactionId) {
19302
+ const pending4 = session.pendingInteraction;
19303
+ if (!pending4 || pending4.interactionId !== input.interactionId) {
19204
19304
  throw Object.assign(new Error("no matching pending permission"), { code: "failed_precondition" });
19205
19305
  }
19206
- if (pending3.kind === "session_agents_confirm" || pending3.kind === "session_cleanup_confirm") {
19306
+ if (pending4.kind === "session_agents_confirm" || pending4.kind === "session_cleanup_confirm") {
19207
19307
  const waiter2 = this.agentsConfirmWaiters.get(input.interactionId);
19208
19308
  if (!waiter2 || waiter2.sessionId !== input.sessionId) {
19209
19309
  throw Object.assign(new Error("no matching pending agents confirm"), {
@@ -19221,7 +19321,7 @@ var init_session_runtime = __esm({
19221
19321
  });
19222
19322
  return;
19223
19323
  }
19224
- if (pending3.kind && pending3.kind !== "permission") {
19324
+ if (pending4.kind && pending4.kind !== "permission") {
19225
19325
  throw Object.assign(new Error("no matching pending permission"), { code: "failed_precondition" });
19226
19326
  }
19227
19327
  const waiter = this.permissionWaiters.get(input.interactionId);
@@ -19229,14 +19329,14 @@ var init_session_runtime = __esm({
19229
19329
  throw Object.assign(new Error("no matching pending permission"), { code: "failed_precondition" });
19230
19330
  }
19231
19331
  const decision = input.decision === "deny" || input.cancel ? "deny" : "allow";
19232
- if (input.decision === "allow_always" && pending3.permissionDetails && pending3.allowAlwaysAllow === false && !input.cancel) {
19332
+ if (input.decision === "allow_always" && pending4.permissionDetails && pending4.allowAlwaysAllow === false && !input.cancel) {
19233
19333
  throw Object.assign(new Error("This native permission request supports allow once or deny"), { code: "failed_precondition" });
19234
19334
  }
19235
- if (pending3.requestKind === "mcp_elicitation" && decision === "allow") {
19236
- const accepted = acceptedElicitationContent(pending3.schemaForm, input.formAnswers);
19335
+ if (pending4.requestKind === "mcp_elicitation" && decision === "allow") {
19336
+ const accepted = acceptedElicitationContent(pending4.schemaForm, input.formAnswers);
19237
19337
  if (!accepted.ok) throw Object.assign(new Error(accepted.reason), { code: "failed_precondition" });
19238
19338
  }
19239
- if (input.decision === "allow_always" && pending3.requestKind !== "mcp_elicitation" && !input.cancel) {
19339
+ if (input.decision === "allow_always" && pending4.requestKind !== "mcp_elicitation" && !input.cancel) {
19240
19340
  const tool2 = session.pendingInteraction?.toolName?.trim();
19241
19341
  if (tool2) {
19242
19342
  const list = session.alwaysAllowedTools ?? [];
@@ -19559,27 +19659,27 @@ var init_session_runtime = __esm({
19559
19659
  }
19560
19660
  /** Deny and clear any active permission waiter for this session. */
19561
19661
  rejectPendingPermission(session) {
19562
- const pending3 = session.pendingInteraction;
19563
- if (!pending3) return;
19564
- if (pending3.kind === "question") {
19565
- const qw = this.questionWaiters.get(pending3.interactionId);
19662
+ const pending4 = session.pendingInteraction;
19663
+ if (!pending4) return;
19664
+ if (pending4.kind === "question") {
19665
+ const qw = this.questionWaiters.get(pending4.interactionId);
19566
19666
  if (qw) qw.settle({ answers: {}, reason: "aborted" });
19567
19667
  else session.pendingInteraction = null;
19568
19668
  return;
19569
19669
  }
19570
- if (pending3.kind === "plan") {
19571
- const pw = this.planWaiters.get(pending3.interactionId);
19670
+ if (pending4.kind === "plan") {
19671
+ const pw = this.planWaiters.get(pending4.interactionId);
19572
19672
  if (pw) pw.settle({ decision: "reject", reason: "aborted" });
19573
19673
  else session.pendingInteraction = null;
19574
19674
  return;
19575
19675
  }
19576
- if (pending3.kind === "session_agents_confirm" || pending3.kind === "session_cleanup_confirm") {
19577
- const aw = this.agentsConfirmWaiters.get(pending3.interactionId);
19676
+ if (pending4.kind === "session_agents_confirm" || pending4.kind === "session_cleanup_confirm") {
19677
+ const aw = this.agentsConfirmWaiters.get(pending4.interactionId);
19578
19678
  if (aw) aw.settle({ action: "cancel", reason: "aborted" });
19579
19679
  else session.pendingInteraction = null;
19580
19680
  return;
19581
19681
  }
19582
- const waiter = this.permissionWaiters.get(pending3.interactionId);
19682
+ const waiter = this.permissionWaiters.get(pending4.interactionId);
19583
19683
  if (waiter) {
19584
19684
  waiter.settle({ decision: "deny", reason: "aborted" });
19585
19685
  } else {
@@ -19590,23 +19690,23 @@ var init_session_runtime = __esm({
19590
19690
  if (session.pendingInteraction) {
19591
19691
  this.rejectPendingPermission(session);
19592
19692
  }
19593
- const pending3 = { ...interaction, kind: "question" };
19693
+ const pending4 = { ...interaction, kind: "question" };
19594
19694
  return new Promise((resolve24) => {
19595
19695
  let settled = false;
19596
- session.pendingInteraction = pending3;
19696
+ session.pendingInteraction = pending4;
19597
19697
  session.updatedAt = Date.now();
19598
19698
  this.persist(session);
19599
19699
  this.events.appendSession({
19600
19700
  sessionId: session.sessionId,
19601
19701
  eventType: SESSION_DURABLE_EVENT.questionRequested,
19602
- payload: pending3,
19702
+ payload: pending4,
19603
19703
  causationRequestId: requestId
19604
19704
  });
19605
19705
  const settle2 = (result3) => {
19606
19706
  if (settled) return;
19607
19707
  settled = true;
19608
- this.questionWaiters.delete(pending3.interactionId);
19609
- if (session.pendingInteraction?.interactionId === pending3.interactionId) {
19708
+ this.questionWaiters.delete(pending4.interactionId);
19709
+ if (session.pendingInteraction?.interactionId === pending4.interactionId) {
19610
19710
  session.pendingInteraction = null;
19611
19711
  session.updatedAt = Date.now();
19612
19712
  this.persist(session);
@@ -19615,18 +19715,18 @@ var init_session_runtime = __esm({
19615
19715
  this.events.appendSession({
19616
19716
  sessionId: session.sessionId,
19617
19717
  eventType: SESSION_DURABLE_EVENT.questionResponded,
19618
- payload: { interactionId: pending3.interactionId, answers: result3.answers }
19718
+ payload: { interactionId: pending4.interactionId, answers: result3.answers }
19619
19719
  });
19620
19720
  } else {
19621
19721
  this.events.appendSession({
19622
19722
  sessionId: session.sessionId,
19623
19723
  eventType: SESSION_DURABLE_EVENT.questionAborted,
19624
- payload: { interactionId: pending3.interactionId }
19724
+ payload: { interactionId: pending4.interactionId }
19625
19725
  });
19626
19726
  }
19627
19727
  resolve24(result3.answers);
19628
19728
  };
19629
- this.questionWaiters.set(pending3.interactionId, {
19729
+ this.questionWaiters.set(pending4.interactionId, {
19630
19730
  sessionId: session.sessionId,
19631
19731
  settle: settle2
19632
19732
  });
@@ -19647,23 +19747,23 @@ var init_session_runtime = __esm({
19647
19747
  if (session.pendingInteraction) {
19648
19748
  this.rejectPendingPermission(session);
19649
19749
  }
19650
- const pending3 = { ...interaction, kind: "plan" };
19750
+ const pending4 = { ...interaction, kind: "plan" };
19651
19751
  return new Promise((resolve24) => {
19652
19752
  let settled = false;
19653
- session.pendingInteraction = pending3;
19753
+ session.pendingInteraction = pending4;
19654
19754
  session.updatedAt = Date.now();
19655
19755
  this.persist(session);
19656
19756
  this.events.appendSession({
19657
19757
  sessionId: session.sessionId,
19658
19758
  eventType: SESSION_DURABLE_EVENT.planRequested,
19659
- payload: pending3,
19759
+ payload: pending4,
19660
19760
  causationRequestId: requestId
19661
19761
  });
19662
19762
  const settle2 = (result3) => {
19663
19763
  if (settled) return;
19664
19764
  settled = true;
19665
- this.planWaiters.delete(pending3.interactionId);
19666
- if (session.pendingInteraction?.interactionId === pending3.interactionId) {
19765
+ this.planWaiters.delete(pending4.interactionId);
19766
+ if (session.pendingInteraction?.interactionId === pending4.interactionId) {
19667
19767
  session.pendingInteraction = null;
19668
19768
  session.updatedAt = Date.now();
19669
19769
  this.persist(session);
@@ -19673,7 +19773,7 @@ var init_session_runtime = __esm({
19673
19773
  sessionId: session.sessionId,
19674
19774
  eventType: SESSION_DURABLE_EVENT.planResponded,
19675
19775
  payload: {
19676
- interactionId: pending3.interactionId,
19776
+ interactionId: pending4.interactionId,
19677
19777
  decision: result3.decision,
19678
19778
  options: result3.options
19679
19779
  }
@@ -19682,12 +19782,12 @@ var init_session_runtime = __esm({
19682
19782
  this.events.appendSession({
19683
19783
  sessionId: session.sessionId,
19684
19784
  eventType: SESSION_DURABLE_EVENT.planAborted,
19685
- payload: { interactionId: pending3.interactionId, decision: "reject" }
19785
+ payload: { interactionId: pending4.interactionId, decision: "reject" }
19686
19786
  });
19687
19787
  }
19688
19788
  resolve24({ decision: result3.decision, options: result3.options });
19689
19789
  };
19690
- this.planWaiters.set(pending3.interactionId, {
19790
+ this.planWaiters.set(pending4.interactionId, {
19691
19791
  sessionId: session.sessionId,
19692
19792
  settle: settle2
19693
19793
  });
@@ -22850,85 +22950,85 @@ var init_ask_user_question = __esm({
22850
22950
  });
22851
22951
 
22852
22952
  // ../../packages/shared/src/node-session-messages.ts
22853
- function nodePendingToPermissionRequest(pending3) {
22854
- if (!pending3?.interactionId) return null;
22855
- if (pending3.kind === "session_agents_confirm") {
22856
- const confirm = pending3.sessionAgentsConfirm;
22953
+ function nodePendingToPermissionRequest(pending4) {
22954
+ if (!pending4?.interactionId) return null;
22955
+ if (pending4.kind === "session_agents_confirm") {
22956
+ const confirm = pending4.sessionAgentsConfirm;
22857
22957
  const payload = {
22858
22958
  launches: Array.isArray(confirm?.launches) ? confirm.launches : [],
22859
22959
  profiles: Array.isArray(confirm?.profiles) ? confirm.profiles : []
22860
22960
  };
22861
22961
  return {
22862
- requestId: pending3.interactionId,
22863
- toolName: pending3.toolName || "session_collab_request",
22864
- toolUseId: pending3.toolUseId ?? pending3.interactionId,
22865
- input: pending3.input && typeof pending3.input === "object" ? pending3.input : {},
22962
+ requestId: pending4.interactionId,
22963
+ toolName: pending4.toolName || "session_collab_request",
22964
+ toolUseId: pending4.toolUseId ?? pending4.interactionId,
22965
+ input: pending4.input && typeof pending4.input === "object" ? pending4.input : {},
22866
22966
  allowAlwaysAllow: false,
22867
22967
  requestKind: "session_agents_confirm",
22868
- serverName: pending3.serverName || "superone",
22869
- message: pending3.message || "Allow this agent to start the following sessions?",
22968
+ serverName: pending4.serverName || "superone",
22969
+ message: pending4.message || "Allow this agent to start the following sessions?",
22870
22970
  sessionAgentsConfirm: payload
22871
22971
  };
22872
22972
  }
22873
- if (pending3.kind === "session_cleanup_confirm") {
22874
- const sessions = Array.isArray(pending3.sessionCleanupConfirm?.sessions) ? pending3.sessionCleanupConfirm.sessions : [];
22973
+ if (pending4.kind === "session_cleanup_confirm") {
22974
+ const sessions = Array.isArray(pending4.sessionCleanupConfirm?.sessions) ? pending4.sessionCleanupConfirm.sessions : [];
22875
22975
  return {
22876
- requestId: pending3.interactionId,
22877
- toolName: pending3.toolName || "mcp__superone__session_cleanup",
22878
- toolUseId: pending3.toolUseId ?? pending3.interactionId,
22879
- input: pending3.input && typeof pending3.input === "object" ? pending3.input : {},
22976
+ requestId: pending4.interactionId,
22977
+ toolName: pending4.toolName || "mcp__superone__session_cleanup",
22978
+ toolUseId: pending4.toolUseId ?? pending4.interactionId,
22979
+ input: pending4.input && typeof pending4.input === "object" ? pending4.input : {},
22880
22980
  allowAlwaysAllow: false,
22881
22981
  requestKind: "session_cleanup_confirm",
22882
- serverName: pending3.serverName || "superone",
22883
- message: pending3.message || "Delete these sessions permanently?",
22982
+ serverName: pending4.serverName || "superone",
22983
+ message: pending4.message || "Delete these sessions permanently?",
22884
22984
  sessionCleanupConfirm: { sessions }
22885
22985
  };
22886
22986
  }
22887
- if (pending3.kind && pending3.kind !== "permission") return null;
22888
- if (pending3.requestKind === "input_request") {
22889
- if (!pending3.inputRequest || !pending3.schemaForm) return null;
22987
+ if (pending4.kind && pending4.kind !== "permission") return null;
22988
+ if (pending4.requestKind === "input_request") {
22989
+ if (!pending4.inputRequest || !pending4.schemaForm) return null;
22890
22990
  return {
22891
- requestId: pending3.interactionId,
22892
- toolName: pending3.toolName || "composer_request",
22893
- toolUseId: pending3.toolUseId ?? pending3.interactionId,
22991
+ requestId: pending4.interactionId,
22992
+ toolName: pending4.toolName || "composer_request",
22993
+ toolUseId: pending4.toolUseId ?? pending4.interactionId,
22894
22994
  input: {},
22895
22995
  allowAlwaysAllow: false,
22896
22996
  requestKind: "input_request",
22897
- serverName: pending3.serverName || "superone",
22898
- message: pending3.message || pending3.inputRequest.title,
22899
- schemaForm: pending3.schemaForm,
22900
- inputRequest: pending3.inputRequest
22997
+ serverName: pending4.serverName || "superone",
22998
+ message: pending4.message || pending4.inputRequest.title,
22999
+ schemaForm: pending4.schemaForm,
23000
+ inputRequest: pending4.inputRequest
22901
23001
  };
22902
23002
  }
22903
- const input = pending3.input && typeof pending3.input === "object" ? pending3.input : {};
22904
- const elicitationUrl = pending3.elicitationUrl ?? (typeof input.elicitationUrl === "string" ? input.elicitationUrl : void 0);
22905
- const elicitationId = pending3.elicitationId ?? (typeof input.elicitationId === "string" ? input.elicitationId : void 0);
22906
- const schemaForm = pending3.schemaForm ?? (input.schemaForm && typeof input.schemaForm === "object" ? input.schemaForm : void 0);
22907
- const requestKind = pending3.requestKind === "mcp_elicitation" ? "mcp_elicitation" : void 0;
23003
+ const input = pending4.input && typeof pending4.input === "object" ? pending4.input : {};
23004
+ const elicitationUrl = pending4.elicitationUrl ?? (typeof input.elicitationUrl === "string" ? input.elicitationUrl : void 0);
23005
+ const elicitationId = pending4.elicitationId ?? (typeof input.elicitationId === "string" ? input.elicitationId : void 0);
23006
+ const schemaForm = pending4.schemaForm ?? (input.schemaForm && typeof input.schemaForm === "object" ? input.schemaForm : void 0);
23007
+ const requestKind = pending4.requestKind === "mcp_elicitation" ? "mcp_elicitation" : void 0;
22908
23008
  return {
22909
- requestId: pending3.interactionId,
22910
- toolName: pending3.toolName || "tool",
22911
- toolUseId: pending3.toolUseId,
23009
+ requestId: pending4.interactionId,
23010
+ toolName: pending4.toolName || "tool",
23011
+ toolUseId: pending4.toolUseId,
22912
23012
  input,
22913
- allowAlwaysAllow: requestKind === "mcp_elicitation" ? !schemaForm && pending3.allowAlwaysAllow === true : pending3.allowAlwaysAllow !== false,
23013
+ allowAlwaysAllow: requestKind === "mcp_elicitation" ? !schemaForm && pending4.allowAlwaysAllow === true : pending4.allowAlwaysAllow !== false,
22914
23014
  ...requestKind ? { requestKind } : {},
22915
- ...pending3.message ? { message: pending3.message } : {},
22916
- ...pending3.permissionDetails ? { permissionDetails: pending3.permissionDetails } : {},
22917
- ...pending3.serverName ? { serverName: pending3.serverName } : {},
22918
- ...pending3.serverLabel ? { serverLabel: pending3.serverLabel } : {},
23015
+ ...pending4.message ? { message: pending4.message } : {},
23016
+ ...pending4.permissionDetails ? { permissionDetails: pending4.permissionDetails } : {},
23017
+ ...pending4.serverName ? { serverName: pending4.serverName } : {},
23018
+ ...pending4.serverLabel ? { serverLabel: pending4.serverLabel } : {},
22919
23019
  ...elicitationUrl ? { elicitationUrl, subtitle: elicitationUrl } : {},
22920
23020
  ...elicitationId ? { elicitationId } : {},
22921
- ...elicitationUrl && pending3.elicitationAcceptOnOpen ? { elicitationAcceptOnOpen: true } : {},
23021
+ ...elicitationUrl && pending4.elicitationAcceptOnOpen ? { elicitationAcceptOnOpen: true } : {},
22922
23022
  ...schemaForm ? { schemaForm } : {},
22923
- ...pending3.elicitationForm ? { elicitationForm: pending3.elicitationForm } : {},
22924
- ...pending3.subtitle ? { subtitle: pending3.subtitle } : {},
22925
- ...pending3.riskLevel ? { riskLevel: pending3.riskLevel } : {},
22926
- ...pending3.supportsAlwaysPersist !== void 0 ? { supportsAlwaysPersist: pending3.supportsAlwaysPersist } : {}
23023
+ ...pending4.elicitationForm ? { elicitationForm: pending4.elicitationForm } : {},
23024
+ ...pending4.subtitle ? { subtitle: pending4.subtitle } : {},
23025
+ ...pending4.riskLevel ? { riskLevel: pending4.riskLevel } : {},
23026
+ ...pending4.supportsAlwaysPersist !== void 0 ? { supportsAlwaysPersist: pending4.supportsAlwaysPersist } : {}
22927
23027
  };
22928
23028
  }
22929
- function nodePendingToQuestionRequest(pending3) {
22930
- if (!pending3?.interactionId || pending3.kind !== "question") return null;
22931
- const input = pending3.input && typeof pending3.input === "object" ? pending3.input : {};
23029
+ function nodePendingToQuestionRequest(pending4) {
23030
+ if (!pending4?.interactionId || pending4.kind !== "question") return null;
23031
+ const input = pending4.input && typeof pending4.input === "object" ? pending4.input : {};
22932
23032
  const raw2 = Array.isArray(input.questions) ? input.questions : [];
22933
23033
  const questions = [];
22934
23034
  for (const q3 of raw2) {
@@ -22970,26 +23070,26 @@ function nodePendingToQuestionRequest(pending3) {
22970
23070
  typeof input.previewFormat === "string" ? input.previewFormat : void 0
22971
23071
  );
22972
23072
  return {
22973
- requestId: pending3.interactionId,
23073
+ requestId: pending4.interactionId,
22974
23074
  questions,
22975
23075
  ...previewFormat ? { previewFormat } : {}
22976
23076
  };
22977
23077
  }
22978
- function nodePendingToPlanApprovalRequest(pending3) {
22979
- if (!pending3?.interactionId || pending3.kind !== "plan") return null;
22980
- const input = pending3.input && typeof pending3.input === "object" ? pending3.input : {};
23078
+ function nodePendingToPlanApprovalRequest(pending4) {
23079
+ if (!pending4?.interactionId || pending4.kind !== "plan") return null;
23080
+ const input = pending4.input && typeof pending4.input === "object" ? pending4.input : {};
22981
23081
  const plan = typeof input.plan === "string" ? input.plan : typeof input.planContent === "string" ? input.planContent : input.plan && typeof input.plan === "object" ? JSON.stringify(input.plan) : "Plan approval required";
22982
23082
  return {
22983
- requestId: pending3.interactionId,
23083
+ requestId: pending4.interactionId,
22984
23084
  planContent: plan,
22985
23085
  planFilePath: typeof input.planFilePath === "string" ? input.planFilePath : "",
22986
23086
  allowedPrompts: Array.isArray(input.allowedPrompts) ? input.allowedPrompts : []
22987
23087
  };
22988
23088
  }
22989
- function nodePendingInteractionFields(pending3, inputRequests = []) {
22990
- const perm = nodePendingToPermissionRequest(pending3);
22991
- const question = nodePendingToQuestionRequest(pending3);
22992
- const plan = nodePendingToPlanApprovalRequest(pending3);
23089
+ function nodePendingInteractionFields(pending4, inputRequests = []) {
23090
+ const perm = nodePendingToPermissionRequest(pending4);
23091
+ const question = nodePendingToQuestionRequest(pending4);
23092
+ const plan = nodePendingToPlanApprovalRequest(pending4);
22993
23093
  const forms = inputRequests.flatMap((request) => nodePendingToPermissionRequest(request) ?? []);
22994
23094
  return {
22995
23095
  pendingPermissions: [...perm ? [perm] : [], ...forms],
@@ -23198,7 +23298,7 @@ var init_read_model = __esm({
23198
23298
  return session;
23199
23299
  }
23200
23300
  const events = this.log.listForSession(sessionId, Number.MAX_SAFE_INTEGER);
23201
- const pending3 = nodePendingInteractionFields(record13?.pendingInteraction);
23301
+ const pending4 = nodePendingInteractionFields(record13?.pendingInteraction);
23202
23302
  const core2 = {
23203
23303
  ...createDefaultChatCoreSession(),
23204
23304
  sessionProvider: providerId,
@@ -23206,7 +23306,7 @@ var init_read_model = __esm({
23206
23306
  claudeFastMode: record13?.claudeFastMode ?? void 0,
23207
23307
  messages: record13 ? sessionMessageBlocksToChatMessages(buildSessionMessageCatalog(record13, events), providerId) : [],
23208
23308
  status: record13?.status === "streaming" ? "streaming" : "idle",
23209
- ...pending3
23309
+ ...pending4
23210
23310
  };
23211
23311
  session = {
23212
23312
  mapper,
@@ -40975,7 +41075,7 @@ var init_scanner_DX8LRFGE = __esm({
40975
41075
  }
40976
41076
  findNextMatchSync(string8, startPosition, _options) {
40977
41077
  const str5 = typeof string8 === "string" ? string8 : string8.content;
40978
- const pending3 = [];
41078
+ const pending4 = [];
40979
41079
  function toResult(index, match, offset = 0) {
40980
41080
  return {
40981
41081
  index,
@@ -41001,7 +41101,7 @@ var init_scanner_DX8LRFGE = __esm({
41001
41101
  const match = regexp.exec(str5);
41002
41102
  if (!match) continue;
41003
41103
  if (match.index === startPosition) return toResult(i2, match, 0);
41004
- pending3.push([
41104
+ pending4.push([
41005
41105
  i2,
41006
41106
  match,
41007
41107
  0
@@ -41011,9 +41111,9 @@ var init_scanner_DX8LRFGE = __esm({
41011
41111
  throw e;
41012
41112
  }
41013
41113
  }
41014
- if (pending3.length) {
41015
- const minIndex = Math.min(...pending3.map((m5) => m5[1].index));
41016
- for (const [i2, match, offset] of pending3) if (match.index === minIndex) return toResult(i2, match, offset);
41114
+ if (pending4.length) {
41115
+ const minIndex = Math.min(...pending4.map((m5) => m5[1].index));
41116
+ for (const [i2, match, offset] of pending4) if (match.index === minIndex) return toResult(i2, match, offset);
41017
41117
  }
41018
41118
  return null;
41019
41119
  }
@@ -48035,7 +48135,7 @@ async function openCodexAppServer(opts) {
48035
48135
  stderrBuf = (stderrBuf + chunk).slice(-MAX_STDERR_CHARS);
48036
48136
  });
48037
48137
  const rl = createInterface({ input: child.stdout });
48038
- const pending3 = /* @__PURE__ */ new Map();
48138
+ const pending4 = /* @__PURE__ */ new Map();
48039
48139
  const notificationWaiters = [];
48040
48140
  const notificationQueue = [];
48041
48141
  let nextId = 1;
@@ -48059,11 +48159,11 @@ async function openCodexAppServer(opts) {
48059
48159
  };
48060
48160
  const failAll = (err) => {
48061
48161
  inboundAbort.abort();
48062
- for (const [, p4] of pending3) {
48162
+ for (const [, p4] of pending4) {
48063
48163
  p4.cancelDeadline();
48064
48164
  p4.reject(err);
48065
48165
  }
48066
- pending3.clear();
48166
+ pending4.clear();
48067
48167
  while (notificationWaiters.length) {
48068
48168
  const w5 = notificationWaiters.shift();
48069
48169
  clearTimeout(w5.timer);
@@ -48191,9 +48291,9 @@ async function openCodexAppServer(opts) {
48191
48291
  }
48192
48292
  if (rec.id != null && (typeof rec.id === "number" || typeof rec.id === "string")) {
48193
48293
  const id = typeof rec.id === "number" ? rec.id : Number(rec.id);
48194
- const waiter = pending3.get(id);
48294
+ const waiter = pending4.get(id);
48195
48295
  if (!waiter) continue;
48196
- pending3.delete(id);
48296
+ pending4.delete(id);
48197
48297
  waiter.cancelDeadline();
48198
48298
  if (rec.error) {
48199
48299
  const errObj = rec.error;
@@ -48211,6 +48311,10 @@ async function openCodexAppServer(opts) {
48211
48311
  pushNotification({ method: rec.method, params });
48212
48312
  }
48213
48313
  }
48314
+ if (!closed && !readLoopError) {
48315
+ readLoopError = new Error("Codex app-server connection closed");
48316
+ failAll(readLoopError);
48317
+ }
48214
48318
  } catch (err) {
48215
48319
  readLoopError = err instanceof Error ? err : new Error(String(err));
48216
48320
  failAll(safePublicError("Codex app-server read failed", readLoopError));
@@ -48232,15 +48336,15 @@ async function openCodexAppServer(opts) {
48232
48336
  }
48233
48337
  const id = nextId++;
48234
48338
  const cancelDeadline = inputBudget.deadline(timeoutMs, () => {
48235
- pending3.delete(id);
48339
+ pending4.delete(id);
48236
48340
  reject(new Error(`Codex app-server ${method} timed out after ${timeoutMs}ms`));
48237
48341
  });
48238
48342
  const waiter = { resolve: resolve24, reject, cancelDeadline };
48239
- pending3.set(id, waiter);
48343
+ pending4.set(id, waiter);
48240
48344
  try {
48241
48345
  writeLine({ jsonrpc: "2.0", id, method, params: params ?? {} });
48242
48346
  } catch (err) {
48243
- pending3.delete(id);
48347
+ pending4.delete(id);
48244
48348
  waiter.cancelDeadline();
48245
48349
  reject(safePublicError("Codex app-server write failed", err));
48246
48350
  }
@@ -48258,7 +48362,7 @@ async function openCodexAppServer(opts) {
48258
48362
  return;
48259
48363
  }
48260
48364
  if (closed) {
48261
- resolve24(null);
48365
+ reject(new Error("Codex app-server closed"));
48262
48366
  return;
48263
48367
  }
48264
48368
  const timer = setTimeout(() => {
@@ -48457,9 +48561,6 @@ async function runCodexAppServerTurn(opts) {
48457
48561
  turnId = readString4(turn?.id);
48458
48562
  }
48459
48563
  let finalText = "";
48460
- const deadline = Date.now() + TURN_WAIT_TIMEOUT_MS;
48461
- const inputWaitAtStart = opts.client.getUserInputWaitMs?.() ?? 0;
48462
- const remaining = () => deadline - Date.now() + (opts.client.getUserInputWaitMs?.() ?? 0) - inputWaitAtStart;
48463
48564
  const agentEventMapper = opts.onAgentEvent ? createCodexAgentEventMapper({
48464
48565
  messageId: opts.messageId ?? `codex_${turnId ?? Date.now()}`,
48465
48566
  emit: opts.onAgentEvent,
@@ -48470,10 +48571,10 @@ async function runCodexAppServerTurn(opts) {
48470
48571
  turnKind
48471
48572
  }) : null;
48472
48573
  agentEventMapper?.start(threadId);
48473
- while (!opts.signal.aborted && remaining() > 0) {
48574
+ while (!opts.signal.aborted) {
48474
48575
  let note;
48475
48576
  try {
48476
- note = await opts.client.nextNotification(Math.min(5e3, Math.max(0, remaining())));
48577
+ note = await opts.client.nextNotification(5e3);
48477
48578
  } catch (err) {
48478
48579
  const error51 = err instanceof Error ? err : new Error(String(err));
48479
48580
  agentEventMapper?.fail(error51.message, /interrupt|abort/i.test(error51.message));
@@ -48523,12 +48624,8 @@ async function runCodexAppServerTurn(opts) {
48523
48624
  return { finalText, threadId, turnId };
48524
48625
  }
48525
48626
  }
48526
- if (opts.signal.aborted) {
48527
- agentEventMapper?.fail("Codex turn interrupted", true);
48528
- throw new Error("Codex turn interrupted");
48529
- }
48530
- agentEventMapper?.fail("Codex turn timed out waiting for turn/completed");
48531
- throw new Error("Codex turn timed out waiting for turn/completed");
48627
+ agentEventMapper?.fail("Codex turn interrupted", true);
48628
+ throw new Error("Codex turn interrupted");
48532
48629
  }
48533
48630
  function normalizeCollaborationMode(value, model, reasoningEffort) {
48534
48631
  if (!value) return void 0;
@@ -48590,7 +48687,7 @@ function asRecord9(value) {
48590
48687
  function readString4(value) {
48591
48688
  return typeof value === "string" && value.length > 0 ? value : null;
48592
48689
  }
48593
- var DEFAULT_REQUEST_TIMEOUT_MS, THREAD_TIMEOUT_MS, TURN_WAIT_TIMEOUT_MS, MAX_STDERR_CHARS;
48690
+ var DEFAULT_REQUEST_TIMEOUT_MS, THREAD_TIMEOUT_MS, MAX_STDERR_CHARS;
48594
48691
  var init_app_server_client = __esm({
48595
48692
  "../../packages/codex/src/app-server-client.ts"() {
48596
48693
  "use strict";
@@ -48608,7 +48705,6 @@ var init_app_server_client = __esm({
48608
48705
  init_agent_event_mapper();
48609
48706
  DEFAULT_REQUEST_TIMEOUT_MS = 12e4;
48610
48707
  THREAD_TIMEOUT_MS = 6e4;
48611
- TURN_WAIT_TIMEOUT_MS = 3e5;
48612
48708
  MAX_STDERR_CHARS = 8e3;
48613
48709
  }
48614
48710
  });
@@ -49239,8 +49335,8 @@ var init_account_manager = __esm({
49239
49335
  if (browser) this.browserStarting = true;
49240
49336
  try {
49241
49337
  this.store.home(id);
49242
- for (const [loginId, pending3] of this.pending) {
49243
- if (pending3.accountId === id) await this.cancel(loginId).catch(() => {
49338
+ for (const [loginId, pending4] of this.pending) {
49339
+ if (pending4.accountId === id) await this.cancel(loginId).catch(() => {
49244
49340
  });
49245
49341
  }
49246
49342
  this.failed.delete(id);
@@ -49251,9 +49347,9 @@ var init_account_manager = __esm({
49251
49347
  type,
49252
49348
  ...browser ? { useHostedLoginSuccessPage: true, appBrand: "chatgpt" } : {}
49253
49349
  }));
49254
- const pending3 = { accountId: id, connection, browser };
49255
- this.pending.set(result3.loginId, pending3);
49256
- void this.wait(result3.loginId, pending3);
49350
+ const pending4 = { accountId: id, connection, browser };
49351
+ this.pending.set(result3.loginId, pending4);
49352
+ void this.wait(result3.loginId, pending4);
49257
49353
  return { ...result3, accountId: id };
49258
49354
  } catch (error51) {
49259
49355
  this.failed.add(id);
@@ -49265,53 +49361,53 @@ var init_account_manager = __esm({
49265
49361
  if (browser) this.browserStarting = false;
49266
49362
  }
49267
49363
  }
49268
- async wait(loginId, pending3) {
49364
+ async wait(loginId, pending4) {
49269
49365
  const deadline = Date.now() + 15 * 6e4;
49270
49366
  const timeout = setTimeout(() => {
49271
49367
  void this.cancel(loginId).catch(() => {
49272
49368
  });
49273
- this.failed.add(pending3.accountId);
49369
+ this.failed.add(pending4.accountId);
49274
49370
  }, 15 * 6e4);
49275
49371
  timeout.unref?.();
49276
49372
  try {
49277
- while (this.pending.get(loginId) === pending3 && Date.now() < deadline) {
49278
- const notification = await pending3.connection.nextNotification();
49373
+ while (this.pending.get(loginId) === pending4 && Date.now() < deadline) {
49374
+ const notification = await pending4.connection.nextNotification();
49279
49375
  if (!notification) throw new Error("Login connection closed");
49280
49376
  if (notification?.method !== "account/login/completed" || notification.params.loginId !== loginId) continue;
49281
49377
  if (notification.params.success !== true) throw new Error("Sign-in failed");
49282
- const status2 = parseAccountStatus(await pending3.connection.request("account/read", { refreshToken: false }));
49378
+ const status2 = parseAccountStatus(await pending4.connection.request("account/read", { refreshToken: false }));
49283
49379
  if (!status2.signedIn) throw new Error("Sign-in did not complete");
49284
- if (this.pending.get(loginId) !== pending3) return;
49285
- this.store.update(pending3.accountId, status2);
49286
- this.store.invalidateCredentials(pending3.accountId);
49287
- this.changed(codexAccountProviderId(pending3.accountId));
49380
+ if (this.pending.get(loginId) !== pending4) return;
49381
+ this.store.update(pending4.accountId, status2);
49382
+ this.store.invalidateCredentials(pending4.accountId);
49383
+ this.changed(codexAccountProviderId(pending4.accountId));
49288
49384
  return;
49289
49385
  }
49290
- if (this.pending.get(loginId) === pending3) this.failed.add(pending3.accountId);
49386
+ if (this.pending.get(loginId) === pending4) this.failed.add(pending4.accountId);
49291
49387
  } catch {
49292
- this.failed.add(pending3.accountId);
49388
+ this.failed.add(pending4.accountId);
49293
49389
  } finally {
49294
49390
  clearTimeout(timeout);
49295
- if (this.pending.get(loginId) === pending3) this.pending.delete(loginId);
49296
- await pending3.connection.close().catch(() => {
49391
+ if (this.pending.get(loginId) === pending4) this.pending.delete(loginId);
49392
+ await pending4.connection.close().catch(() => {
49297
49393
  });
49298
49394
  }
49299
49395
  }
49300
49396
  async cancel(loginId) {
49301
- const pending3 = this.pending.get(loginId);
49302
- if (!pending3) return;
49397
+ const pending4 = this.pending.get(loginId);
49398
+ if (!pending4) return;
49303
49399
  this.pending.delete(loginId);
49304
49400
  try {
49305
- await pending3.connection.request("account/login/cancel", { loginId });
49401
+ await pending4.connection.request("account/login/cancel", { loginId });
49306
49402
  } finally {
49307
- await pending3.connection.close();
49403
+ await pending4.connection.close();
49308
49404
  }
49309
49405
  }
49310
49406
  async logout(providerId) {
49311
49407
  const id = codexAccountId(providerId) ?? codexAccountId(this.store.defaultProviderId()) ?? CODEX_CLI_ACCOUNT_ID;
49312
49408
  this.revisions.set(id, (this.revisions.get(id) ?? 0) + 1);
49313
- for (const [loginId, pending3] of this.pending) {
49314
- if (pending3.accountId === id) await this.cancel(loginId);
49409
+ for (const [loginId, pending4] of this.pending) {
49410
+ if (pending4.accountId === id) await this.cancel(loginId);
49315
49411
  }
49316
49412
  const selected = codexAccountProviderId(id);
49317
49413
  const connection = await this.open(selected);
@@ -49338,8 +49434,8 @@ var init_account_manager = __esm({
49338
49434
  const unreachable = signedIn() && await this.status(providerId).then(() => false, () => true);
49339
49435
  if (!unreachable && signedIn()) throw new Error("Sign out before removing this Codex account.");
49340
49436
  this.revisions.set(id, (this.revisions.get(id) ?? 0) + 1);
49341
- for (const [loginId, pending3] of this.pending) {
49342
- if (pending3.accountId === id) await this.cancel(loginId);
49437
+ for (const [loginId, pending4] of this.pending) {
49438
+ if (pending4.accountId === id) await this.cancel(loginId);
49343
49439
  }
49344
49440
  this.store.remove(id, unreachable);
49345
49441
  this.failed.delete(id);
@@ -51869,7 +51965,7 @@ var init_claude_live_session = __esm({
51869
51965
  this.failAmbient("Claude SDK stream ended before the background turn completed");
51870
51966
  this.active?.reject(new Error("Claude SDK stream ended before the user turn completed"));
51871
51967
  this.active = null;
51872
- for (const pending3 of this.pending.splice(0)) pending3.reject(new Error("Claude SDK stream ended before the queued turn started"));
51968
+ for (const pending4 of this.pending.splice(0)) pending4.reject(new Error("Claude SDK stream ended before the queued turn started"));
51873
51969
  }
51874
51970
  this.closed = true;
51875
51971
  this.bridge.close();
@@ -52322,7 +52418,7 @@ var init_mod_surface = __esm({
52322
52418
  this.disposed = true;
52323
52419
  if (this.available) this.opts.emit({ type: "mod_ui_state", available: false });
52324
52420
  this.available = false;
52325
- for (const pending3 of this.pendingHost.values()) pending3.resolve(null);
52421
+ for (const pending4 of this.pendingHost.values()) pending4.resolve(null);
52326
52422
  this.pendingHost.clear();
52327
52423
  }
52328
52424
  /**
@@ -52357,10 +52453,10 @@ var init_mod_surface = __esm({
52357
52453
  return this.pendingHost.has(requestId);
52358
52454
  }
52359
52455
  acceptHostReply({ requestId, clientId: clientId2, reply }) {
52360
- const pending3 = this.pendingHost.get(requestId);
52361
- if (!pending3 || pending3.kind !== reply.kind || pending3.clientId !== clientId2) return { accepted: false };
52456
+ const pending4 = this.pendingHost.get(requestId);
52457
+ if (!pending4 || pending4.kind !== reply.kind || pending4.clientId !== clientId2) return { accepted: false };
52362
52458
  this.pendingHost.delete(requestId);
52363
- pending3.resolve(reply);
52459
+ pending4.resolve(reply);
52364
52460
  return { accepted: true };
52365
52461
  }
52366
52462
  };
@@ -102834,7 +102930,7 @@ function make7(connect) {
102834
102930
  subscribe(options) {
102835
102931
  return {
102836
102932
  [Symbol.asyncIterator]() {
102837
- const pending3 = [];
102933
+ const pending4 = [];
102838
102934
  const queued = [];
102839
102935
  let started = false;
102840
102936
  let completion;
@@ -102846,7 +102942,7 @@ function make7(connect) {
102846
102942
  options?.signal?.removeEventListener("abort", abort);
102847
102943
  if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
102848
102944
  stop3(connection);
102849
- pending3.splice(0).forEach((request) => {
102945
+ pending4.splice(0).forEach((request) => {
102850
102946
  if ("error" in result3)
102851
102947
  request.reject(result3.error);
102852
102948
  else
@@ -102864,7 +102960,7 @@ function make7(connect) {
102864
102960
  push(value) {
102865
102961
  if (completion)
102866
102962
  return;
102867
- const request = pending3.shift();
102963
+ const request = pending4.shift();
102868
102964
  if (request) {
102869
102965
  request.resolve({ done: false, value });
102870
102966
  return;
@@ -102906,7 +103002,7 @@ function make7(connect) {
102906
103002
  return Promise.resolve({ done: true, value: void 0 });
102907
103003
  }
102908
103004
  const request = Promise.withResolvers();
102909
- pending3.push(request);
103005
+ pending4.push(request);
102910
103006
  if (!started) {
102911
103007
  started = true;
102912
103008
  options?.signal?.addEventListener("abort", abort, { once: true });
@@ -106245,15 +106341,15 @@ var init_opencode_oauth = __esm({
106245
106341
  return task;
106246
106342
  }
106247
106343
  reply(id, answers) {
106248
- const pending3 = this.forms.get(id);
106249
- if (!pending3) return false;
106250
- pending3.reply(openCodeV2FormAnswer(pending3.form, answers));
106344
+ const pending4 = this.forms.get(id);
106345
+ if (!pending4) return false;
106346
+ pending4.reply(openCodeV2FormAnswer(pending4.form, answers));
106251
106347
  return true;
106252
106348
  }
106253
106349
  reject(id) {
106254
- const pending3 = this.forms.get(id);
106255
- if (!pending3) return false;
106256
- pending3.cancel();
106350
+ const pending4 = this.forms.get(id);
106351
+ if (!pending4) return false;
106352
+ pending4.cancel();
106257
106353
  return true;
106258
106354
  }
106259
106355
  async close() {
@@ -106403,8 +106499,8 @@ var init_opencode_oauth = __esm({
106403
106499
  } finally {
106404
106500
  clearTimeout(expiry);
106405
106501
  if (!complete && !signal2.aborted) controller.abort(new Error("OpenCode sign-in did not complete"));
106406
- for (const pending3 of [...this.forms.values()]) {
106407
- if (pending3.owner === controller) pending3.reply({});
106502
+ for (const pending4 of [...this.forms.values()]) {
106503
+ if (pending4.owner === controller) pending4.reply({});
106408
106504
  }
106409
106505
  if (!complete) await this.deps.client.cancelOAuth(id, attempt.attemptID).catch(() => void 0);
106410
106506
  }
@@ -108469,13 +108565,13 @@ function createManagedOpenCodeTurnRunner(resolveProjectPath2, options = {}) {
108469
108565
  if (existing.active || existing.host) throw new Error("Wait for OpenCode to become idle before changing its provider or launch configuration");
108470
108566
  await runner.disposeSession(id);
108471
108567
  }
108472
- let pending3 = sessions.get(id);
108473
- if (!pending3) {
108568
+ let pending4 = sessions.get(id);
108569
+ if (!pending4) {
108474
108570
  if (!isOpenCodeBinaryRunnable(opts.binaryPath) && !opts.serverUrl?.trim())
108475
108571
  throw new Error(
108476
108572
  "OpenCode runtime client not available on node: enable the harness with a real binary or endpoint"
108477
108573
  );
108478
- pending3 = startOpenCodeSessionServer({
108574
+ pending4 = startOpenCodeSessionServer({
108479
108575
  ...opts,
108480
108576
  sessionId: id,
108481
108577
  nativeSessionId: input.session.providerResume?.startsWith("opencode:") ? input.session.providerResume.slice(9) : void 0,
@@ -108498,9 +108594,9 @@ function createManagedOpenCodeTurnRunner(resolveProjectPath2, options = {}) {
108498
108594
  return live2;
108499
108595
  }
108500
108596
  );
108501
- sessions.set(id, pending3);
108597
+ sessions.set(id, pending4);
108502
108598
  }
108503
- const live = await pending3.catch((error51) => {
108599
+ const live = await pending4.catch((error51) => {
108504
108600
  sessions.delete(id);
108505
108601
  throw error51;
108506
108602
  });
@@ -108583,7 +108679,7 @@ function createManagedOpenCodeTurnRunner(resolveProjectPath2, options = {}) {
108583
108679
  const opts = { ...options, ...options.resolveLaunch?.(connection) };
108584
108680
  const cwd = session.cwd?.trim() || resolveProjectPath2(session.projectId) || process.cwd();
108585
108681
  if (!isOpenCodeBinaryRunnable(opts.binaryPath) && !opts.serverUrl?.trim()) throw new Error("OpenCode runtime is unavailable");
108586
- const pending3 = sessions.get(session.sessionId) ?? startOpenCodeSessionServer({
108682
+ const pending4 = sessions.get(session.sessionId) ?? startOpenCodeSessionServer({
108587
108683
  ...opts,
108588
108684
  sessionId: session.sessionId,
108589
108685
  nativeSessionId: session.providerResume.slice(9),
@@ -108597,8 +108693,8 @@ function createManagedOpenCodeTurnRunner(resolveProjectPath2, options = {}) {
108597
108693
  }
108598
108694
  return open2(connection, opts, server, cwd);
108599
108695
  });
108600
- sessions.set(session.sessionId, pending3);
108601
- const handle2 = await pending3;
108696
+ sessions.set(session.sessionId, pending4);
108697
+ const handle2 = await pending4;
108602
108698
  if (!("legacy" in handle2)) live = handle2;
108603
108699
  }
108604
108700
  if (!live) {
@@ -108797,9 +108893,9 @@ function createManagedOpenCodeTurnRunner(resolveProjectPath2, options = {}) {
108797
108893
  events?.finish(void 0, true);
108798
108894
  };
108799
108895
  runner.disposeSession = async (id) => {
108800
- const pending3 = sessions.get(id);
108896
+ const pending4 = sessions.get(id);
108801
108897
  sessions.delete(id);
108802
- const live = await pending3?.catch(() => null);
108898
+ const live = await pending4?.catch(() => null);
108803
108899
  if (live && !("legacy" in live)) {
108804
108900
  live.abort.abort();
108805
108901
  await live.runtime.close();
@@ -110674,17 +110770,17 @@ var init_cursor_store = __esm({
110674
110770
 
110675
110771
  // ../../packages/cursor/src/cursor-sdk.ts
110676
110772
  function loadCursorSdk() {
110677
- pending ??= import("@cursor/sdk").then((sdk) => loaded = sdk);
110678
- return pending;
110773
+ pending2 ??= import("@cursor/sdk").then((sdk) => loaded = sdk);
110774
+ return pending2;
110679
110775
  }
110680
110776
  function isCursorSdkError(error51, name) {
110681
110777
  return loaded !== null && error51 instanceof loaded[name];
110682
110778
  }
110683
- var pending, loaded;
110779
+ var pending2, loaded;
110684
110780
  var init_cursor_sdk = __esm({
110685
110781
  "../../packages/cursor/src/cursor-sdk.ts"() {
110686
110782
  "use strict";
110687
- pending = null;
110783
+ pending2 = null;
110688
110784
  loaded = null;
110689
110785
  }
110690
110786
  });
@@ -111707,9 +111803,6 @@ async function openTurnAndStream(opts) {
111707
111803
  const turnId = readString6(turn?.id);
111708
111804
  opts.onTurnStarted?.(turnId);
111709
111805
  let finalText = "";
111710
- const deadline = Date.now() + TURN_WAIT_TIMEOUT_MS2;
111711
- const inputWaitAtStart = opts.client.getUserInputWaitMs?.() ?? 0;
111712
- const remaining = () => deadline - Date.now() + (opts.client.getUserInputWaitMs?.() ?? 0) - inputWaitAtStart;
111713
111806
  const agentEventMapper = opts.onAgentEvent ? createCodexAgentEventMapper({
111714
111807
  messageId: opts.messageId ?? `codex_${turnId ?? Date.now()}`,
111715
111808
  emit: opts.onAgentEvent,
@@ -111720,12 +111813,10 @@ async function openTurnAndStream(opts) {
111720
111813
  ...opts.parentTurnId || opts.rootTurnId ? { requestedProvenance: { ...opts.parentTurnId ? { parentTurnId: opts.parentTurnId } : {}, ...opts.rootTurnId ? { rootTurnId: opts.rootTurnId } : {} } } : {}
111721
111814
  }) : null;
111722
111815
  agentEventMapper?.start(opts.threadId);
111723
- while (!opts.signal.aborted && remaining() > 0) {
111816
+ while (!opts.signal.aborted) {
111724
111817
  let note;
111725
111818
  try {
111726
- note = await opts.client.nextNotification(
111727
- Math.min(5e3, Math.max(0, remaining()))
111728
- );
111819
+ note = await opts.client.nextNotification(5e3);
111729
111820
  } catch (err) {
111730
111821
  const error51 = err instanceof Error ? err : new Error(String(err));
111731
111822
  agentEventMapper?.fail(error51.message, /interrupt|abort/i.test(error51.message));
@@ -111768,20 +111859,14 @@ async function openTurnAndStream(opts) {
111768
111859
  return { finalText, threadId: opts.threadId, turnId };
111769
111860
  }
111770
111861
  }
111771
- if (opts.signal.aborted) {
111772
- agentEventMapper?.fail("Codex turn interrupted", true);
111773
- throw new Error("Codex turn interrupted");
111774
- }
111775
- agentEventMapper?.fail("Codex turn timed out waiting for turn/completed");
111776
- throw new Error("Codex turn timed out waiting for turn/completed");
111862
+ agentEventMapper?.fail("Codex turn interrupted", true);
111863
+ throw new Error("Codex turn interrupted");
111777
111864
  }
111778
- var TURN_WAIT_TIMEOUT_MS2;
111779
111865
  var init_codex_live_turn = __esm({
111780
111866
  "src/session/codex-live-turn.ts"() {
111781
111867
  "use strict";
111782
111868
  init_protocol_v162();
111783
111869
  init_src4();
111784
- TURN_WAIT_TIMEOUT_MS2 = 3e5;
111785
111870
  }
111786
111871
  });
111787
111872
 
@@ -127623,6 +127708,7 @@ init_environment();
127623
127708
 
127624
127709
  // ../../packages/shared/src/environment/session-operations.ts
127625
127710
  var SESSION_OPERATION_METHODS = /* @__PURE__ */ new Set([
127711
+ "session.answerAsyncQuestion",
127626
127712
  "session.dequeue",
127627
127713
  "session.steer",
127628
127714
  "session.reportWorktreeRemoved",
@@ -127684,6 +127770,13 @@ async function callOperation(payload, ctx, method) {
127684
127770
  const p4 = asRecord(payload);
127685
127771
  try {
127686
127772
  const sessionId = requiredText(p4, "sessionId");
127773
+ if (method === "session.answerAsyncQuestion") {
127774
+ requiredText(p4, "messageId");
127775
+ requiredText(p4, "itemId");
127776
+ if (!Array.isArray(p4.answers) || p4.answers.some((answer) => typeof answer !== "string")) {
127777
+ throw Object.assign(new Error("answers must be a string array"), { code: "invalid_argument" });
127778
+ }
127779
+ }
127687
127780
  if (method === "session.dequeue" || method === "session.steer") requiredText(p4, "clientMessageId");
127688
127781
  if (method === "session.rewind" || method === "session.previewRewind" || method === "session.truncateAtCheckpoint") requiredText(p4, "checkpointId");
127689
127782
  if (method === "session.mcpAuthenticate") requiredText(p4, "serverName");
@@ -128518,14 +128611,14 @@ async function cloneRepository(input, onProgress) {
128518
128611
  }
128519
128612
  });
128520
128613
  let stderrTail = "";
128521
- let pending3 = "";
128614
+ let pending4 = "";
128522
128615
  let lastPercent = -1;
128523
128616
  child.stderr.setEncoding("utf8");
128524
128617
  child.stderr.on("data", (chunk) => {
128525
128618
  stderrTail = (stderrTail + chunk).slice(-STDERR_TAIL_CHARS);
128526
128619
  if (!onProgress) return;
128527
- const lines2 = (pending3 + chunk).split(/\r|\n/);
128528
- pending3 = lines2.pop() ?? "";
128620
+ const lines2 = (pending4 + chunk).split(/\r|\n/);
128621
+ pending4 = lines2.pop() ?? "";
128529
128622
  for (const line of lines2) {
128530
128623
  const percent = parseCloneProgress(line);
128531
128624
  if (percent !== null && percent > lastPercent) {
@@ -130571,10 +130664,10 @@ init_environment();
130571
130664
  // ../../packages/shared/src/environment/draft-content.ts
130572
130665
  function hasPersistableDraftContent(draft) {
130573
130666
  if (draft.text.trim() || draft.attachments?.length) return true;
130574
- const pending3 = [draft.docJson];
130667
+ const pending4 = [draft.docJson];
130575
130668
  const seen = /* @__PURE__ */ new Set();
130576
- while (pending3.length) {
130577
- const node = pending3.pop();
130669
+ while (pending4.length) {
130670
+ const node = pending4.pop();
130578
130671
  if (!node || typeof node !== "object") continue;
130579
130672
  if (seen.has(node)) continue;
130580
130673
  seen.add(node);
@@ -130582,7 +130675,7 @@ function hasPersistableDraftContent(draft) {
130582
130675
  if (type === "text" && typeof text4 === "string" && text4.trim()) return true;
130583
130676
  const value = type === "pasteChip" ? attrs?.text : type === "mention" ? attrs?.value : null;
130584
130677
  if (typeof value === "string" && value.trim()) return true;
130585
- if (Array.isArray(content)) pending3.push(...content);
130678
+ if (Array.isArray(content)) pending4.push(...content);
130586
130679
  }
130587
130680
  return false;
130588
130681
  }
@@ -130615,15 +130708,15 @@ function openTerminalStream(opts) {
130615
130708
  }
130616
130709
  function openDraftStream(opts) {
130617
130710
  let following = false;
130618
- const pending3 = /* @__PURE__ */ new Map();
130711
+ const pending4 = /* @__PURE__ */ new Map();
130619
130712
  const cancel = (draftId) => {
130620
- clearTimeout(pending3.get(draftId)?.timer);
130621
- pending3.delete(draftId);
130713
+ clearTimeout(pending4.get(draftId)?.timer);
130714
+ pending4.delete(draftId);
130622
130715
  };
130623
130716
  const send = (event) => opts.push(event.draft ? { ...event, draft: withoutDraftAttachmentBytes(event.draft) } : event);
130624
130717
  const setTopics = (topics) => {
130625
130718
  following = topics.some((topic2) => topic2.kind === "drafts" && topic2.environmentId === opts.environmentId);
130626
- if (!following) for (const draftId of [...pending3.keys()]) cancel(draftId);
130719
+ if (!following) for (const draftId of [...pending4.keys()]) cancel(draftId);
130627
130720
  };
130628
130721
  setTopics(opts.topics);
130629
130722
  const off = opts.source.watch((event) => {
@@ -130633,23 +130726,23 @@ function openDraftStream(opts) {
130633
130726
  send(event);
130634
130727
  return;
130635
130728
  }
130636
- const queued = pending3.get(event.draftId);
130729
+ const queued = pending4.get(event.draftId);
130637
130730
  if (queued) {
130638
130731
  queued.event = event;
130639
130732
  return;
130640
130733
  }
130641
130734
  const timer = setTimeout(() => {
130642
- const latest = pending3.get(event.draftId);
130643
- pending3.delete(event.draftId);
130735
+ const latest = pending4.get(event.draftId);
130736
+ pending4.delete(event.draftId);
130644
130737
  if (latest) send(latest.event);
130645
130738
  }, DRAFT_SAVE_INTERVAL_MS);
130646
- pending3.set(event.draftId, { event, timer });
130739
+ pending4.set(event.draftId, { event, timer });
130647
130740
  });
130648
130741
  return {
130649
130742
  setTopics,
130650
130743
  close: () => {
130651
130744
  off();
130652
- for (const draftId of [...pending3.keys()]) cancel(draftId);
130745
+ for (const draftId of [...pending4.keys()]) cancel(draftId);
130653
130746
  }
130654
130747
  };
130655
130748
  }
@@ -144534,32 +144627,32 @@ function sidebarStatus(status2) {
144534
144627
  if (status2 === "streaming" || status2 === "background" || status2 === "error") return status2;
144535
144628
  return "idle";
144536
144629
  }
144537
- function pendingAgentEvents(pending3) {
144538
- if (!pending3) return [];
144539
- if (pending3.kind === "question") return [questionEvent(pending3)];
144540
- if (pending3.kind === "plan") return [planEvent(pending3)];
144541
- return [permissionEvent(pending3)];
144630
+ function pendingAgentEvents(pending4) {
144631
+ if (!pending4) return [];
144632
+ if (pending4.kind === "question") return [questionEvent(pending4)];
144633
+ if (pending4.kind === "plan") return [planEvent(pending4)];
144634
+ return [permissionEvent(pending4)];
144542
144635
  }
144543
- function permissionEvent(pending3) {
144544
- const confirm = pending3.requestKind === "session_agents_confirm" || pending3.kind === "session_agents_confirm";
144636
+ function permissionEvent(pending4) {
144637
+ const confirm = pending4.requestKind === "session_agents_confirm" || pending4.kind === "session_agents_confirm";
144545
144638
  return {
144546
144639
  type: "permission_request",
144547
144640
  request: {
144548
- requestId: pending3.interactionId,
144549
- toolName: pending3.toolName ?? "",
144550
- ...pending3.toolUseId ? { toolUseId: pending3.toolUseId } : {},
144551
- input: pending3.input ?? {},
144552
- allowAlwaysAllow: pending3.allowAlwaysAllow === true,
144553
- ...pending3.message ? { message: pending3.message } : {},
144641
+ requestId: pending4.interactionId,
144642
+ toolName: pending4.toolName ?? "",
144643
+ ...pending4.toolUseId ? { toolUseId: pending4.toolUseId } : {},
144644
+ input: pending4.input ?? {},
144645
+ allowAlwaysAllow: pending4.allowAlwaysAllow === true,
144646
+ ...pending4.message ? { message: pending4.message } : {},
144554
144647
  ...confirm ? {
144555
144648
  requestKind: "session_agents_confirm",
144556
- ...pending3.sessionAgentsConfirm ? { sessionAgentsConfirm: pending3.sessionAgentsConfirm } : {}
144649
+ ...pending4.sessionAgentsConfirm ? { sessionAgentsConfirm: pending4.sessionAgentsConfirm } : {}
144557
144650
  } : {}
144558
144651
  }
144559
144652
  };
144560
144653
  }
144561
- function questionEvent(pending3) {
144562
- const raw2 = pending3.input?.questions;
144654
+ function questionEvent(pending4) {
144655
+ const raw2 = pending4.input?.questions;
144563
144656
  const questions = Array.isArray(raw2) ? raw2.flatMap((item) => {
144564
144657
  if (!item || typeof item !== "object") return [];
144565
144658
  const row2 = item;
@@ -144577,11 +144670,11 @@ function questionEvent(pending3) {
144577
144670
  multiSelect: row2.multiSelect === true
144578
144671
  }];
144579
144672
  }) : [];
144580
- return { type: "ask_user_question", request: { requestId: pending3.interactionId, questions } };
144673
+ return { type: "ask_user_question", request: { requestId: pending4.interactionId, questions } };
144581
144674
  }
144582
- function planEvent(pending3) {
144583
- const input = pending3.input ?? {};
144584
- const planContent2 = typeof input.plan === "string" ? input.plan : typeof input.planContent === "string" ? input.planContent : pending3.message ?? "";
144675
+ function planEvent(pending4) {
144676
+ const input = pending4.input ?? {};
144677
+ const planContent2 = typeof input.plan === "string" ? input.plan : typeof input.planContent === "string" ? input.planContent : pending4.message ?? "";
144585
144678
  const planFilePath = typeof input.planFilePath === "string" ? input.planFilePath : "";
144586
144679
  const allowedPrompts = Array.isArray(input.allowedPrompts) ? input.allowedPrompts.flatMap((item) => {
144587
144680
  if (!item || typeof item !== "object") return [];
@@ -144589,7 +144682,7 @@ function planEvent(pending3) {
144589
144682
  if (typeof row2.tool !== "string" || typeof row2.prompt !== "string") return [];
144590
144683
  return [{ tool: row2.tool, prompt: row2.prompt }];
144591
144684
  }) : [];
144592
- return { type: "plan_approval", request: { requestId: pending3.interactionId, planContent: planContent2, planFilePath, allowedPrompts } };
144685
+ return { type: "plan_approval", request: { requestId: pending4.interactionId, planContent: planContent2, planFilePath, allowedPrompts } };
144593
144686
  }
144594
144687
 
144595
144688
  // src/runtime.ts
@@ -145967,7 +146060,7 @@ async function dispatchSuggestedTaskRpc(method, payload, ctx) {
145967
146060
  }
145968
146061
  }
145969
146062
 
145970
- // ../../node_modules/@toon-format/toon/dist/index.mjs
146063
+ // node_modules/@toon-format/toon/dist/index.mjs
145971
146064
  var NULL_LITERAL = "null";
145972
146065
  var DELIMITERS = {
145973
146066
  comma: ",",
@@ -145993,13 +146086,29 @@ function setOwnProperty(target2, key3, value) {
145993
146086
  }
145994
146087
  target2[key3] = value;
145995
146088
  }
146089
+ var COMMENT_LINE_PATTERN = new RegExp(`(?:^\uFEFF?|\\n) *#`);
146090
+ var RawString = class {
146091
+ constructor(value) {
146092
+ if (COMMENT_LINE_PATTERN.test(value)) throw new TypeError(`Raw string must not contain a line starting with "#": ${JSON.stringify(value)}`);
146093
+ this.value = value;
146094
+ }
146095
+ };
146096
+ function isRawString(value) {
146097
+ return value instanceof RawString;
146098
+ }
146099
+ var SURROGATE_PATTERN = /[\uD800-\uDFFF]/;
145996
146100
  function normalizeValue(value) {
145997
146101
  if (value === null) return null;
146102
+ if (isRawString(value)) return value;
145998
146103
  if (typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function") {
145999
146104
  const next = value.toJSON();
146000
146105
  if (next !== value) return normalizeValue(next);
146001
146106
  }
146002
- if (typeof value === "string" || typeof value === "boolean") return value;
146107
+ if (typeof value === "string") {
146108
+ assertNoLoneSurrogate(value, "string value");
146109
+ return value;
146110
+ }
146111
+ if (typeof value === "boolean") return value;
146003
146112
  if (typeof value === "number") {
146004
146113
  if (Object.is(value, -0)) return 0;
146005
146114
  if (!Number.isFinite(value)) return null;
@@ -146015,19 +146124,39 @@ function normalizeValue(value) {
146015
146124
  if (value instanceof Map) return Object.fromEntries(Array.from(value, ([k5, v4]) => [String(k5), normalizeValue(v4)]));
146016
146125
  if (isPlainObject2(value)) {
146017
146126
  const encodedValues = {};
146018
- for (const key3 in value) if (Object.hasOwn(value, key3)) setOwnProperty(encodedValues, key3, normalizeValue(value[key3]));
146127
+ for (const key3 in value) if (Object.hasOwn(value, key3)) {
146128
+ assertNoLoneSurrogate(key3, "object key");
146129
+ setOwnProperty(encodedValues, key3, normalizeValue(value[key3]));
146130
+ }
146019
146131
  return encodedValues;
146020
146132
  }
146021
146133
  return null;
146022
146134
  }
146135
+ function assertNoLoneSurrogate(value, context) {
146136
+ if (!SURROGATE_PATTERN.test(value)) return;
146137
+ for (let index = 0; index < value.length; index++) {
146138
+ const code = value.charCodeAt(index);
146139
+ if (code < 55296 || code > 57343) continue;
146140
+ const isHighSurrogate = code <= 56319;
146141
+ const next = value.charCodeAt(index + 1);
146142
+ if (isHighSurrogate && next >= 56320 && next <= 57343) {
146143
+ index++;
146144
+ continue;
146145
+ }
146146
+ throw new TypeError(`Cannot encode ${context} containing an unpaired surrogate U+${code.toString(16).toUpperCase()} at index ${index}`);
146147
+ }
146148
+ }
146023
146149
  function isJsonPrimitive(value) {
146024
146150
  return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
146025
146151
  }
146152
+ function isEncodablePrimitive(value) {
146153
+ return isJsonPrimitive(value) || isRawString(value);
146154
+ }
146026
146155
  function isJsonArray(value) {
146027
146156
  return Array.isArray(value);
146028
146157
  }
146029
146158
  function isJsonObject(value) {
146030
- return value !== null && typeof value === "object" && !Array.isArray(value);
146159
+ return value !== null && typeof value === "object" && !Array.isArray(value) && !isRawString(value);
146031
146160
  }
146032
146161
  function isEmptyObject(value) {
146033
146162
  return Object.keys(value).length === 0;
@@ -146038,7 +146167,7 @@ function isPlainObject2(value) {
146038
146167
  return prototype === null || prototype === Object.prototype;
146039
146168
  }
146040
146169
  function isArrayOfPrimitives(value) {
146041
- return value.length === 0 || value.every((item) => isJsonPrimitive(item));
146170
+ return value.length === 0 || value.every((item) => isEncodablePrimitive(item));
146042
146171
  }
146043
146172
  function isArrayOfArrays(value) {
146044
146173
  return value.length === 0 || value.every((item) => isJsonArray(item));
@@ -146046,17 +146175,16 @@ function isArrayOfArrays(value) {
146046
146175
  function isArrayOfObjects(value) {
146047
146176
  return value.length === 0 || value.every((item) => isJsonObject(item));
146048
146177
  }
146049
- var NUMERIC_LIKE_PATTERN = /^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;
146050
- var LEADING_ZERO_PATTERN = /^0\d+$/;
146178
+ var NUMERIC_LIKE_PATTERN = /^[+-]?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i;
146179
+ function assertValidDelimiter(delimiter3) {
146180
+ if (!Object.values(DELIMITERS).includes(delimiter3)) throw new TypeError(`Invalid delimiter ${JSON.stringify(delimiter3)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)`);
146181
+ }
146051
146182
  function isValidUnquotedKey(key3) {
146052
146183
  return /^[A-Z_][\w.]*$/i.test(key3);
146053
146184
  }
146054
- function isIdentifierSegment(key3) {
146055
- return /^[A-Z_]\w*$/i.test(key3);
146056
- }
146057
146185
  function isSafeUnquoted(value, delimiter3 = DEFAULT_DELIMITER) {
146058
146186
  if (!value) return false;
146059
- if (value !== value.trim()) return false;
146187
+ if (/^[ \t]|[ \t]$/.test(value)) return false;
146060
146188
  if (isBooleanOrNullLiteral(value) || isNumericLike(value)) return false;
146061
146189
  if (value.includes(":")) return false;
146062
146190
  if (value.includes('"') || value.includes("\\")) return false;
@@ -146064,55 +146192,14 @@ function isSafeUnquoted(value, delimiter3 = DEFAULT_DELIMITER) {
146064
146192
  if (/[\u0000-\u001F]/.test(value)) return false;
146065
146193
  if (value.includes(delimiter3)) return false;
146066
146194
  if (value.startsWith("-")) return false;
146195
+ if (value.startsWith("#")) return false;
146067
146196
  return true;
146068
146197
  }
146069
146198
  function isNumericLike(value) {
146070
- return NUMERIC_LIKE_PATTERN.test(value) || LEADING_ZERO_PATTERN.test(value);
146071
- }
146072
- function tryFoldKeyChain(key3, value, siblings2, options, rootLiteralKeys, pathPrefix, flattenDepth) {
146073
- if (options.keyFolding !== "safe") return;
146074
- if (!isJsonObject(value)) return;
146075
- const { segments, tail, leafValue } = collectSingleKeyChain(key3, value, flattenDepth ?? options.flattenDepth);
146076
- if (segments.length < 2) return;
146077
- if (!segments.every((seg) => isIdentifierSegment(seg))) return;
146078
- const foldedKey = buildFoldedKey(segments);
146079
- const absolutePath2 = pathPrefix ? `${pathPrefix}.${foldedKey}` : foldedKey;
146080
- if (siblings2.includes(foldedKey)) return;
146081
- if (rootLiteralKeys && rootLiteralKeys.has(absolutePath2)) return;
146082
- return {
146083
- foldedKey,
146084
- remainder: tail,
146085
- leafValue,
146086
- segmentCount: segments.length
146087
- };
146088
- }
146089
- function collectSingleKeyChain(startKey, startValue, maxDepth) {
146090
- const segments = [startKey];
146091
- let currentValue = startValue;
146092
- while (segments.length < maxDepth) {
146093
- if (!isJsonObject(currentValue)) break;
146094
- const keys = Object.keys(currentValue);
146095
- if (keys.length !== 1) break;
146096
- const nextKey = keys[0];
146097
- const nextValue = currentValue[nextKey];
146098
- segments.push(nextKey);
146099
- currentValue = nextValue;
146100
- }
146101
- if (!isJsonObject(currentValue) || isEmptyObject(currentValue)) return {
146102
- segments,
146103
- tail: void 0,
146104
- leafValue: currentValue
146105
- };
146106
- return {
146107
- segments,
146108
- tail: currentValue,
146109
- leafValue: currentValue
146110
- };
146111
- }
146112
- function buildFoldedKey(segments) {
146113
- return segments.join(".");
146199
+ return NUMERIC_LIKE_PATTERN.test(value);
146114
146200
  }
146115
146201
  function encodePrimitive(value, delimiter3) {
146202
+ if (isRawString(value)) return value.value;
146116
146203
  if (value === null) return NULL_LITERAL;
146117
146204
  if (typeof value === "boolean") return String(value);
146118
146205
  if (typeof value === "number") return String(value);
@@ -146135,73 +146222,114 @@ function formatHeader(length, options) {
146135
146222
  const delimiter3 = options?.delimiter ?? ",";
146136
146223
  let header = "";
146137
146224
  if (key3 != null) header += encodeKey(key3);
146138
- header += `[${length}${delimiter3 !== DEFAULT_DELIMITER ? delimiter3 : ""}]`;
146139
- if (fields) {
146140
- const quotedFields = fields.map((f4) => encodeKey(f4));
146141
- header += `{${quotedFields.join(delimiter3)}}`;
146142
- }
146225
+ header += `[${length}${options?.keyed ? ":" : ""}${delimiter3 !== DEFAULT_DELIMITER ? delimiter3 : ""}]`;
146226
+ if (fields) header += `{${formatFieldSegment(fields, delimiter3)}}`;
146143
146227
  header += ":";
146144
146228
  return header;
146145
146229
  }
146230
+ function formatFieldSegment(fields, delimiter3) {
146231
+ return fields.map((field) => encodeKey(field.name) + (field.children ? `{${formatFieldSegment(field.children, delimiter3)}}` : "")).join(delimiter3);
146232
+ }
146233
+ function extractTabularFields(rows) {
146234
+ if (rows.length === 0) return;
146235
+ const firstKeys = Object.keys(rows[0]);
146236
+ if (firstKeys.length === 0) return;
146237
+ for (const row2 of rows) {
146238
+ if (Object.keys(row2).length !== firstKeys.length) return;
146239
+ for (const key3 of firstKeys) if (!Object.hasOwn(row2, key3)) return;
146240
+ }
146241
+ const fieldNodes = [];
146242
+ for (const key3 of firstKeys) {
146243
+ const fieldNode = classifyColumn(key3, rows.map((row2) => row2[key3]));
146244
+ if (!fieldNode) return;
146245
+ fieldNodes.push(fieldNode);
146246
+ }
146247
+ return fieldNodes;
146248
+ }
146249
+ function extractKeyedTabularFields(value) {
146250
+ const entryValues = Object.values(value);
146251
+ if (entryValues.length < 2) return;
146252
+ if (!entryValues.every((entryValue) => isJsonObject(entryValue) && !isEmptyObject(entryValue))) return;
146253
+ return extractTabularFields(entryValues);
146254
+ }
146255
+ function collectRowLeaves(row2, fields) {
146256
+ const leaves = [];
146257
+ collectLeafValues(row2, fields, leaves);
146258
+ return leaves;
146259
+ }
146260
+ function classifyColumn(name, values) {
146261
+ if (values.every((value) => isEncodablePrimitive(value))) return { name };
146262
+ if (!values.every((value) => isJsonObject(value) && !isEmptyObject(value))) return;
146263
+ const children = extractTabularFields(values);
146264
+ if (!children) return;
146265
+ return {
146266
+ name,
146267
+ children
146268
+ };
146269
+ }
146270
+ function collectLeafValues(row2, fields, leaves) {
146271
+ for (const field of fields) {
146272
+ const value = row2[field.name];
146273
+ if (field.children) collectLeafValues(value, field.children, leaves);
146274
+ else leaves.push(value);
146275
+ }
146276
+ }
146146
146277
  function* encodeJsonValue(value, options, depth) {
146147
- if (isJsonPrimitive(value)) {
146278
+ if (isEncodablePrimitive(value)) {
146148
146279
  const encodedPrimitive = encodePrimitive(value, options.delimiter);
146149
146280
  if (encodedPrimitive !== "") yield encodedPrimitive;
146150
146281
  return;
146151
146282
  }
146152
146283
  if (isJsonArray(value)) yield* encodeArrayLines(void 0, value, depth, options);
146153
- else if (isJsonObject(value)) yield* encodeObjectLines(value, depth, options);
146154
- }
146155
- function* encodeObjectLines(value, depth, options, rootLiteralKeys, pathPrefix, remainingDepth) {
146156
- const keys = Object.keys(value);
146157
- if (depth === 0 && !rootLiteralKeys) rootLiteralKeys = new Set(keys.filter((k5) => k5.includes(".")));
146158
- const effectiveFlattenDepth = remainingDepth ?? options.flattenDepth;
146159
- for (const [key3, val] of Object.entries(value)) yield* encodeKeyValuePairLines(key3, val, depth, options, keys, rootLiteralKeys, pathPrefix, effectiveFlattenDepth);
146160
- }
146161
- function* encodeKeyValuePairLines(key3, value, depth, options, siblings2, rootLiteralKeys, pathPrefix, flattenDepth) {
146162
- const currentPath = pathPrefix ? `${pathPrefix}.${key3}` : key3;
146163
- const effectiveFlattenDepth = flattenDepth ?? options.flattenDepth;
146164
- if (options.keyFolding === "safe" && siblings2) {
146165
- const foldResult = tryFoldKeyChain(key3, value, siblings2, options, rootLiteralKeys, pathPrefix, effectiveFlattenDepth);
146166
- if (foldResult) {
146167
- const { foldedKey, remainder, leafValue, segmentCount } = foldResult;
146168
- const encodedFoldedKey = encodeKey(foldedKey);
146169
- if (remainder === void 0) {
146170
- if (isJsonPrimitive(leafValue)) {
146171
- yield indentedLine(depth, `${encodedFoldedKey}: ${encodePrimitive(leafValue, options.delimiter)}`, options.indent);
146172
- return;
146173
- } else if (isJsonArray(leafValue)) {
146174
- yield* encodeArrayLines(foldedKey, leafValue, depth, options);
146175
- return;
146176
- } else if (isJsonObject(leafValue) && isEmptyObject(leafValue)) {
146177
- yield indentedLine(depth, `${encodedFoldedKey}:`, options.indent);
146178
- return;
146179
- }
146180
- }
146181
- if (isJsonObject(remainder)) {
146182
- yield indentedLine(depth, `${encodedFoldedKey}:`, options.indent);
146183
- const remainingDepth = effectiveFlattenDepth - segmentCount;
146184
- const foldedPath = pathPrefix ? `${pathPrefix}.${foldedKey}` : foldedKey;
146185
- yield* encodeObjectLines(remainder, depth + 1, options, rootLiteralKeys, foldedPath, remainingDepth);
146186
- return;
146187
- }
146284
+ else if (isJsonObject(value)) {
146285
+ const keyedFields = extractKeyedTabularFields(value);
146286
+ if (keyedFields) {
146287
+ yield* encodeKeyedObjectLines(void 0, value, keyedFields, depth, options);
146288
+ return;
146188
146289
  }
146290
+ yield* encodeObjectLines(value, depth, options);
146189
146291
  }
146292
+ }
146293
+ function* encodeObjectLines(value, depth, options) {
146294
+ for (const [key3, val] of Object.entries(value)) yield* encodeKeyValuePairLines(key3, val, depth, options);
146295
+ }
146296
+ function* encodeKeyValuePairLines(key3, value, depth, options) {
146190
146297
  const encodedKey = encodeKey(key3);
146191
- if (isJsonPrimitive(value)) yield indentedLine(depth, `${encodedKey}: ${encodePrimitive(value, options.delimiter)}`, options.indent);
146298
+ if (isEncodablePrimitive(value)) yield indentedLine(depth, `${encodedKey}: ${encodePrimitive(value, options.delimiter)}`, options.indentSize);
146192
146299
  else if (isJsonArray(value)) yield* encodeArrayLines(key3, value, depth, options);
146193
146300
  else if (isJsonObject(value)) {
146194
- yield indentedLine(depth, `${encodedKey}:`, options.indent);
146195
- if (!isEmptyObject(value)) yield* encodeObjectLines(value, depth + 1, options, rootLiteralKeys, currentPath, effectiveFlattenDepth);
146301
+ const keyedFields = extractKeyedTabularFields(value);
146302
+ if (keyedFields) {
146303
+ yield* encodeKeyedObjectLines(key3, value, keyedFields, depth, options);
146304
+ return;
146305
+ }
146306
+ yield indentedLine(depth, `${encodedKey}:`, options.indentSize);
146307
+ if (!isEmptyObject(value)) yield* encodeObjectLines(value, depth + 1, options);
146308
+ }
146309
+ }
146310
+ function* encodeKeyedObjectLines(key3, value, fields, depth, options) {
146311
+ const entries = Object.entries(value);
146312
+ yield indentedLine(depth, formatHeader(entries.length, {
146313
+ key: key3,
146314
+ fields,
146315
+ delimiter: options.delimiter,
146316
+ keyed: true
146317
+ }), options.indentSize);
146318
+ yield* encodeKeyedEntryRowsLines(entries, fields, depth + 1, options);
146319
+ }
146320
+ function* encodeKeyedEntryRowsLines(entries, fields, depth, options) {
146321
+ for (const [entryKey, entryValue] of entries) {
146322
+ const leaves = collectRowLeaves(entryValue, fields);
146323
+ yield indentedLine(depth, `${encodeKey(entryKey)}: ${encodeAndJoinPrimitives(leaves, options.delimiter)}`, options.indentSize);
146196
146324
  }
146197
146325
  }
146198
146326
  function* encodeArrayLines(key3, value, depth, options) {
146199
146327
  if (value.length === 0) {
146200
- yield indentedLine(depth, key3 != null ? `${encodeKey(key3)}: []` : "[]", options.indent);
146328
+ yield indentedLine(depth, key3 != null ? `${encodeKey(key3)}: []` : "[]", options.indentSize);
146201
146329
  return;
146202
146330
  }
146203
146331
  if (isArrayOfPrimitives(value)) {
146204
- yield indentedLine(depth, encodeInlineArrayLine(value, options.delimiter, key3), options.indent);
146332
+ yield indentedLine(depth, encodeInlineArrayLine(value, options.delimiter, key3), options.indentSize);
146205
146333
  return;
146206
146334
  }
146207
146335
  if (isArrayOfArrays(value)) {
@@ -146211,8 +146339,8 @@ function* encodeArrayLines(key3, value, depth, options) {
146211
146339
  }
146212
146340
  }
146213
146341
  if (isArrayOfObjects(value)) {
146214
- const header = extractTabularHeader(value);
146215
- if (header) yield* encodeArrayOfObjectsAsTabularLines(key3, value, header, depth, options);
146342
+ const fields = extractTabularFields(value);
146343
+ if (fields) yield* encodeArrayOfObjectsAsTabularLines(key3, value, fields, depth, options);
146216
146344
  else yield* encodeMixedArrayAsListItemsLines(key3, value, depth, options);
146217
146345
  return;
146218
146346
  }
@@ -146222,10 +146350,10 @@ function* encodeArrayOfArraysAsListItemsLines(prefix, values, depth, options) {
146222
146350
  yield indentedLine(depth, formatHeader(values.length, {
146223
146351
  key: prefix,
146224
146352
  delimiter: options.delimiter
146225
- }), options.indent);
146353
+ }), options.indentSize);
146226
146354
  for (const arr of values) if (isArrayOfPrimitives(arr)) {
146227
146355
  const arrayLine = encodeInlineArrayLine(arr, options.delimiter);
146228
- yield indentedListItem(depth + 1, arrayLine, options.indent);
146356
+ yield indentedListItem(depth + 1, arrayLine, options.indentSize);
146229
146357
  }
146230
146358
  }
146231
146359
  function encodeInlineArrayLine(values, delimiter3, prefix) {
@@ -146237,81 +146365,79 @@ function encodeInlineArrayLine(values, delimiter3, prefix) {
146237
146365
  if (values.length === 0) return header;
146238
146366
  return `${header} ${joinedValue}`;
146239
146367
  }
146240
- function* encodeArrayOfObjectsAsTabularLines(prefix, rows, header, depth, options) {
146368
+ function* encodeArrayOfObjectsAsTabularLines(prefix, rows, fields, depth, options) {
146241
146369
  yield indentedLine(depth, formatHeader(rows.length, {
146242
146370
  key: prefix,
146243
- fields: header,
146371
+ fields,
146244
146372
  delimiter: options.delimiter
146245
- }), options.indent);
146246
- yield* writeTabularRowsLines(rows, header, depth + 1, options);
146373
+ }), options.indentSize);
146374
+ yield* writeTabularRowsLines(rows, fields, depth + 1, options);
146247
146375
  }
146248
- function extractTabularHeader(rows) {
146249
- if (rows.length === 0) return;
146250
- const firstRow = rows[0];
146251
- const firstKeys = Object.keys(firstRow);
146252
- if (firstKeys.length === 0) return;
146253
- if (isTabularArray(rows, firstKeys)) return firstKeys;
146254
- }
146255
- function isTabularArray(rows, header) {
146256
- for (const row2 of rows) {
146257
- if (Object.keys(row2).length !== header.length) return false;
146258
- for (const key3 of header) {
146259
- if (!Object.hasOwn(row2, key3)) return false;
146260
- if (!isJsonPrimitive(row2[key3])) return false;
146261
- }
146262
- }
146263
- return true;
146264
- }
146265
- function* writeTabularRowsLines(rows, header, depth, options) {
146266
- for (const row2 of rows) yield indentedLine(depth, encodeAndJoinPrimitives(header.map((key3) => row2[key3]), options.delimiter), options.indent);
146376
+ function* writeTabularRowsLines(rows, fields, depth, options) {
146377
+ for (const row2 of rows) yield indentedLine(depth, encodeAndJoinPrimitives(collectRowLeaves(row2, fields), options.delimiter), options.indentSize);
146267
146378
  }
146268
146379
  function* encodeMixedArrayAsListItemsLines(prefix, items, depth, options) {
146269
146380
  yield indentedLine(depth, formatHeader(items.length, {
146270
146381
  key: prefix,
146271
146382
  delimiter: options.delimiter
146272
- }), options.indent);
146383
+ }), options.indentSize);
146273
146384
  for (const item of items) yield* encodeListItemValueLines(item, depth + 1, options);
146274
146385
  }
146275
146386
  function* encodeObjectAsListItemLines(obj, depth, options) {
146276
146387
  if (isEmptyObject(obj)) {
146277
- yield indentedLine(depth, "-", options.indent);
146388
+ yield indentedLine(depth, "-", options.indentSize);
146278
146389
  return;
146279
146390
  }
146280
146391
  const entries = Object.entries(obj);
146281
146392
  const [firstKey, firstValue] = entries[0];
146282
146393
  const restEntries = entries.slice(1);
146283
146394
  if (isJsonArray(firstValue) && isArrayOfObjects(firstValue)) {
146284
- const header = extractTabularHeader(firstValue);
146285
- if (header) {
146395
+ const fields = extractTabularFields(firstValue);
146396
+ if (fields) {
146286
146397
  yield indentedListItem(depth, formatHeader(firstValue.length, {
146287
146398
  key: firstKey,
146288
- fields: header,
146399
+ fields,
146289
146400
  delimiter: options.delimiter
146290
- }), options.indent);
146291
- yield* writeTabularRowsLines(firstValue, header, depth + 2, options);
146401
+ }), options.indentSize);
146402
+ yield* writeTabularRowsLines(firstValue, fields, depth + 2, options);
146403
+ if (restEntries.length > 0) yield* encodeObjectLines(Object.fromEntries(restEntries), depth + 1, options);
146404
+ return;
146405
+ }
146406
+ }
146407
+ if (isJsonObject(firstValue)) {
146408
+ const keyedFields = extractKeyedTabularFields(firstValue);
146409
+ if (keyedFields) {
146410
+ const keyedEntries = Object.entries(firstValue);
146411
+ yield indentedListItem(depth, formatHeader(keyedEntries.length, {
146412
+ key: firstKey,
146413
+ fields: keyedFields,
146414
+ delimiter: options.delimiter,
146415
+ keyed: true
146416
+ }), options.indentSize);
146417
+ yield* encodeKeyedEntryRowsLines(keyedEntries, keyedFields, depth + 2, options);
146292
146418
  if (restEntries.length > 0) yield* encodeObjectLines(Object.fromEntries(restEntries), depth + 1, options);
146293
146419
  return;
146294
146420
  }
146295
146421
  }
146296
146422
  const encodedKey = encodeKey(firstKey);
146297
- if (isJsonPrimitive(firstValue)) yield indentedListItem(depth, `${encodedKey}: ${encodePrimitive(firstValue, options.delimiter)}`, options.indent);
146298
- else if (isJsonArray(firstValue)) if (firstValue.length === 0) yield indentedListItem(depth, `${encodedKey}: []`, options.indent);
146299
- else if (isArrayOfPrimitives(firstValue)) yield indentedListItem(depth, `${encodedKey}${encodeInlineArrayLine(firstValue, options.delimiter)}`, options.indent);
146423
+ if (isEncodablePrimitive(firstValue)) yield indentedListItem(depth, `${encodedKey}: ${encodePrimitive(firstValue, options.delimiter)}`, options.indentSize);
146424
+ else if (isJsonArray(firstValue)) if (firstValue.length === 0) yield indentedListItem(depth, `${encodedKey}: []`, options.indentSize);
146425
+ else if (isArrayOfPrimitives(firstValue)) yield indentedListItem(depth, `${encodedKey}${encodeInlineArrayLine(firstValue, options.delimiter)}`, options.indentSize);
146300
146426
  else {
146301
- yield indentedListItem(depth, `${encodedKey}${formatHeader(firstValue.length, { delimiter: options.delimiter })}`, options.indent);
146427
+ yield indentedListItem(depth, `${encodedKey}${formatHeader(firstValue.length, { delimiter: options.delimiter })}`, options.indentSize);
146302
146428
  for (const item of firstValue) yield* encodeListItemValueLines(item, depth + 2, options);
146303
146429
  }
146304
146430
  else if (isJsonObject(firstValue)) {
146305
- yield indentedListItem(depth, `${encodedKey}:`, options.indent);
146431
+ yield indentedListItem(depth, `${encodedKey}:`, options.indentSize);
146306
146432
  if (!isEmptyObject(firstValue)) yield* encodeObjectLines(firstValue, depth + 2, options);
146307
146433
  }
146308
146434
  if (restEntries.length > 0) yield* encodeObjectLines(Object.fromEntries(restEntries), depth + 1, options);
146309
146435
  }
146310
146436
  function* encodeListItemValueLines(value, depth, options) {
146311
- if (isJsonPrimitive(value)) yield indentedListItem(depth, encodePrimitive(value, options.delimiter), options.indent);
146312
- else if (isJsonArray(value)) if (isArrayOfPrimitives(value)) yield indentedListItem(depth, encodeInlineArrayLine(value, options.delimiter), options.indent);
146437
+ if (isEncodablePrimitive(value)) yield indentedListItem(depth, encodePrimitive(value, options.delimiter), options.indentSize);
146438
+ else if (isJsonArray(value)) if (isArrayOfPrimitives(value)) yield indentedListItem(depth, encodeInlineArrayLine(value, options.delimiter), options.indentSize);
146313
146439
  else {
146314
- yield indentedListItem(depth, formatHeader(value.length, { delimiter: options.delimiter }), options.indent);
146440
+ yield indentedListItem(depth, formatHeader(value.length, { delimiter: options.delimiter }), options.indentSize);
146315
146441
  for (const item of value) yield* encodeListItemValueLines(item, depth + 1, options);
146316
146442
  }
146317
146443
  else if (isJsonObject(value)) yield* encodeObjectAsListItemLines(value, depth, options);
@@ -146325,7 +146451,11 @@ function indentedListItem(depth, content, indentSize) {
146325
146451
  function applyReplacer(root2, replacer) {
146326
146452
  const replacedRoot = replacer("", root2, []);
146327
146453
  if (replacedRoot === void 0) return transformChildren(root2, replacer, []);
146328
- return transformChildren(normalizeValue(replacedRoot), replacer, []);
146454
+ return transformReplaced(root2, replacedRoot, replacer, []);
146455
+ }
146456
+ function transformReplaced(original, replaced, replacer, path) {
146457
+ if (isRawString(replaced) && !isEncodablePrimitive(original)) return transformChildren(original, replacer, path);
146458
+ return transformChildren(normalizeValue(replaced), replacer, path);
146329
146459
  }
146330
146460
  function transformChildren(value, replacer, path) {
146331
146461
  if (isJsonObject(value)) return transformObject(value, replacer, path);
@@ -146338,7 +146468,7 @@ function transformObject(obj, replacer, path) {
146338
146468
  const childPath = [...path, key3];
146339
146469
  const replacedValue = replacer(key3, value, childPath);
146340
146470
  if (replacedValue === void 0) continue;
146341
- setOwnProperty(result3, key3, transformChildren(normalizeValue(replacedValue), replacer, childPath));
146471
+ setOwnProperty(result3, key3, transformReplaced(value, replacedValue, replacer, childPath));
146342
146472
  }
146343
146473
  return result3;
146344
146474
  }
@@ -146349,8 +146479,7 @@ function transformArray(arr, replacer, path) {
146349
146479
  const childPath = [...path, i2];
146350
146480
  const replacedValue = replacer(String(i2), value, childPath);
146351
146481
  if (replacedValue === void 0) continue;
146352
- const normalizedValue = normalizeValue(replacedValue);
146353
- result3.push(transformChildren(normalizedValue, replacer, childPath));
146482
+ result3.push(transformReplaced(value, replacedValue, replacer, childPath));
146354
146483
  }
146355
146484
  return result3;
146356
146485
  }
@@ -146363,11 +146492,11 @@ function encodeLines(input, options) {
146363
146492
  return encodeJsonValue(resolvedOptions.replacer ? applyReplacer(normalizedValue, resolvedOptions.replacer) : normalizedValue, resolvedOptions, 0);
146364
146493
  }
146365
146494
  function resolveOptions(options) {
146495
+ const delimiter3 = options?.delimiter ?? DEFAULT_DELIMITER;
146496
+ assertValidDelimiter(delimiter3);
146366
146497
  return {
146367
- indent: options?.indent ?? 2,
146368
- delimiter: options?.delimiter ?? DEFAULT_DELIMITER,
146369
- keyFolding: options?.keyFolding ?? "off",
146370
- flattenDepth: options?.flattenDepth ?? Number.POSITIVE_INFINITY,
146498
+ indentSize: options?.indentSize ?? options?.indent ?? 2,
146499
+ delimiter: delimiter3,
146371
146500
  replacer: options?.replacer
146372
146501
  };
146373
146502
  }
@@ -147478,14 +147607,14 @@ async function startMcpOauth(client3, login) {
147478
147607
  return { loginId, authorizationUrl: first };
147479
147608
  }
147480
147609
  async function completeMcpOauth(client3, loginId, callbackUrl) {
147481
- const pending3 = pendingMcpOauth.get(loginId);
147482
- if (!pending3 || pending3.clientSessionId !== client3.clientSessionId) {
147610
+ const pending4 = pendingMcpOauth.get(loginId);
147611
+ if (!pending4 || pending4.clientSessionId !== client3.clientSessionId) {
147483
147612
  throw Object.assign(new Error("MCP sign-in not found"), { code: "not_found" });
147484
147613
  }
147485
147614
  if (callbackUrl) {
147486
147615
  let callback;
147487
147616
  try {
147488
- callback = validateLoopbackOAuthCallback(pending3.authorizationUrl, callbackUrl);
147617
+ callback = validateLoopbackOAuthCallback(pending4.authorizationUrl, callbackUrl);
147489
147618
  } catch (err) {
147490
147619
  invalid10(err.message);
147491
147620
  }
@@ -147493,7 +147622,7 @@ async function completeMcpOauth(client3, loginId, callbackUrl) {
147493
147622
  await response.body?.cancel();
147494
147623
  }
147495
147624
  try {
147496
- return await pending3.result;
147625
+ return await pending4.result;
147497
147626
  } finally {
147498
147627
  pendingMcpOauth.delete(loginId);
147499
147628
  }
@@ -147990,8 +148119,8 @@ function claudeCatalogFor(ctx, apiProviderId, cwd) {
147990
148119
  if (ctx.probeModels) return null;
147991
148120
  if (ctx.probeClaudeCatalog) {
147992
148121
  const probe = ctx.probeClaudeCatalog;
147993
- let pending4 = null;
147994
- return () => pending4 ??= probe(cwd);
148122
+ let pending5 = null;
148123
+ return () => pending5 ??= probe(cwd);
147995
148124
  }
147996
148125
  const binaryPath = resolveClaudeBinaryPath({ harnesses: ctx.harnesses });
147997
148126
  if (!binaryPath) {
@@ -148000,8 +148129,8 @@ function claudeCatalogFor(ctx, apiProviderId, cwd) {
148000
148129
  );
148001
148130
  return async () => EMPTY_CLAUDE_CATALOG;
148002
148131
  }
148003
- let pending3 = null;
148004
- return () => pending3 ??= getNodeClaudeCatalog({
148132
+ let pending4 = null;
148133
+ return () => pending4 ??= getNodeClaudeCatalog({
148005
148134
  cwd,
148006
148135
  binaryPath,
148007
148136
  env: claudeAccountProbeEnv(apiProviderId),
@@ -152480,7 +152609,7 @@ function suggestedTaskToolResult(raw2) {
152480
152609
 
152481
152610
  // src/session/suggested-task.ts
152482
152611
  var exec = promisify2(execFile6);
152483
- function pending2(ctx, sessionId, taskId) {
152612
+ function pending3(ctx, sessionId, taskId) {
152484
152613
  const parent = ctx.deps.sessions.get(sessionId);
152485
152614
  if (!parent || parent.closed) throw new CollaborationError("This session is no longer available.", "not_found");
152486
152615
  const found = findSuggestedTask(ctx.deps.sessions.messages(sessionId), taskId);
@@ -152495,7 +152624,7 @@ function suggestTask(ctx, sessionId, args) {
152495
152624
  return suggestedTaskToolResult(args);
152496
152625
  }
152497
152626
  async function suggestedTaskOptions(ctx, sessionId, taskId) {
152498
- const { parent } = pending2(ctx, sessionId, taskId);
152627
+ const { parent } = pending3(ctx, sessionId, taskId);
152499
152628
  const profiles = ctx.listProfiles();
152500
152629
  if (profiles.some((profile2) => profile2.harnessId === "claude")) {
152501
152630
  const { getNodeClaudeModelCatalog: getNodeClaudeModelCatalog2 } = await Promise.resolve().then(() => (init_claude_model_catalog(), claude_model_catalog_exports));
@@ -152530,7 +152659,7 @@ async function taskLocation(ctx, projectId, cwd, input, taskId, assertControl2)
152530
152659
  }
152531
152660
  async function launchNodeSuggestedTask(ctx, sessionId, taskId, choice, assertControl2, controllerClientSessionId) {
152532
152661
  assertControl2();
152533
- const { parent, input } = pending2(ctx, sessionId, taskId);
152662
+ const { parent, input } = pending3(ctx, sessionId, taskId);
152534
152663
  const launchId = `suggested-task-${taskId}`;
152535
152664
  if (!ctx.store.grantForLaunch(sessionId, launchId)?.started_at) {
152536
152665
  const { profiles, initial } = await suggestedTaskOptions(ctx, sessionId, taskId);
@@ -166886,6 +167015,7 @@ function withSessionZone(runner, syncRoot) {
166886
167015
  wrapped.disposeSession = runner.disposeSession;
166887
167016
  wrapped.disposeAll = runner.disposeAll;
166888
167017
  wrapped.listActiveRuntimes = runner.listActiveRuntimes;
167018
+ wrapped.codexVoice = runner.codexVoice;
166889
167019
  return wrapped;
166890
167020
  }
166891
167021