wildcrane-runner 0.6.57 → 0.6.59

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // ai4kanban 0.11.45 — built by runner/scripts/build.mjs. Do not edit.
2
+ // ai4kanban 0.11.46 — built by runner/scripts/build.mjs. Do not edit.
3
3
  import { createRequire as __ai4kanbanRequire } from 'node:module'
4
4
  const require = __ai4kanbanRequire(import.meta.url)
5
5
  var __create = Object.create;
@@ -4187,6 +4187,27 @@ var init_kimi_stream = __esm({
4187
4187
  }
4188
4188
  });
4189
4189
 
4190
+ // ../cli/src/lib/shared/conversation.ts
4191
+ function bounded(work, ms, reason) {
4192
+ return new Promise((resolve2, reject) => {
4193
+ const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
4194
+ work.then((value) => {
4195
+ clearTimeout(timer);
4196
+ resolve2(value);
4197
+ }, (error) => {
4198
+ clearTimeout(timer);
4199
+ reject(error);
4200
+ });
4201
+ });
4202
+ }
4203
+ var CONVERSATION_MS;
4204
+ var init_conversation = __esm({
4205
+ "../cli/src/lib/shared/conversation.ts"() {
4206
+ "use strict";
4207
+ CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
4208
+ }
4209
+ });
4210
+
4190
4211
  // ../cli/src/lib/agent/wire/rpc.ts
4191
4212
  function connect(stdout, stdin, onCall, dialect = {}) {
4192
4213
  let buf = "";
@@ -4333,7 +4354,7 @@ var init_package = __esm({
4333
4354
  "../cli/package.json"() {
4334
4355
  package_default = {
4335
4356
  name: "wildcrane",
4336
- version: "0.11.45",
4357
+ version: "0.11.46",
4337
4358
  akbContract: 12,
4338
4359
  description: "WildCrane's `akb` command \u2014 scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
4339
4360
  keywords: [
@@ -4488,6 +4509,11 @@ function createAcpClient(options = {}) {
4488
4509
  }
4489
4510
  async function oneTurn(io, options) {
4490
4511
  const tail = createTail(io.log);
4512
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
4513
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
4514
+ let started = false;
4515
+ let contentAt = 0;
4516
+ let currentSession = "";
4491
4517
  const events = createEventCollector();
4492
4518
  const emit = () => {
4493
4519
  for (const e of events.events()) io.event?.(e);
@@ -4500,7 +4526,16 @@ async function oneTurn(io, options) {
4500
4526
  io.stdin,
4501
4527
  (msg) => {
4502
4528
  if (msg.method === "session/update") {
4503
- if (live) {
4529
+ if (live && (!obj(msg.params).sessionId || obj(msg.params).sessionId === currentSession)) {
4530
+ const kind = str(obj(obj(msg.params).update).sessionUpdate);
4531
+ if (!started && ["agent_message_chunk", "tool_call", "plan"].includes(kind)) {
4532
+ started = true;
4533
+ phase("started");
4534
+ }
4535
+ if (kind === "agent_message_chunk" && Date.now() - contentAt >= 1e3) {
4536
+ contentAt = Date.now();
4537
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
4538
+ }
4504
4539
  update(obj(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
4505
4540
  events.update(obj(msg.params).update);
4506
4541
  emit();
@@ -4528,20 +4563,22 @@ async function oneTurn(io, options) {
4528
4563
  );
4529
4564
  try {
4530
4565
  const mcpServers = options.mcpConfig ? mcpServersIn(options.mcpConfig) : [];
4531
- await rpc.call("initialize", {
4566
+ phase("preparing");
4567
+ await bounded(rpc.call("initialize", {
4532
4568
  protocolVersion: PROTOCOL_VERSION,
4533
4569
  clientCapabilities: CLIENT_CAPABILITIES,
4534
4570
  clientInfo: { name: "ai4kanban", version: SKILL_VERSION }
4535
- });
4571
+ }), preparingUntil - Date.now(), "ACP initialize timed out.");
4572
+ phase("initialized");
4536
4573
  let sessionId = io.resumeId ?? "";
4537
4574
  let prompt = io.prompt;
4538
4575
  let opened;
4539
4576
  if (sessionId) {
4540
4577
  try {
4541
- opened = await rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers });
4578
+ opened = await bounded(rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers }), preparingUntil - Date.now(), "ACP session/load timed out.");
4542
4579
  } catch (e) {
4543
4580
  if (!sessionGone(e) || !io.restartPrompt) throw e;
4544
- const fresh = await newSession(rpc, io.cwd, mcpServers);
4581
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
4545
4582
  opened = fresh.opened;
4546
4583
  sessionId = fresh.sessionId;
4547
4584
  prompt = io.restartPrompt;
@@ -4551,7 +4588,7 @@ async function oneTurn(io, options) {
4551
4588
  emit();
4552
4589
  }
4553
4590
  } else {
4554
- const fresh = await newSession(rpc, io.cwd, mcpServers);
4591
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
4555
4592
  opened = fresh.opened;
4556
4593
  sessionId = fresh.sessionId;
4557
4594
  io.gotResumeId(sessionId);
@@ -4560,11 +4597,15 @@ async function oneTurn(io, options) {
4560
4597
  if (options.model) {
4561
4598
  const listed = obj(opened.models).currentModelId !== void 0;
4562
4599
  const picked = listed ? pickedModel(opened, options.model) : void 0;
4563
- const set = listed ? await rpc.call("session/set_model", { sessionId, modelId: picked?.modelId ?? options.model }) : await rpc.call("session/set_config_option", { sessionId, configId: "model", value: options.model });
4600
+ const set = listed ? await bounded(rpc.call("session/set_model", { sessionId, modelId: picked?.modelId ?? options.model }), preparingUntil - Date.now(), "ACP session/set_model timed out.") : await bounded(rpc.call("session/set_config_option", { sessionId, configId: "model", value: options.model }), preparingUntil - Date.now(), "ACP session/set_config_option timed out.");
4564
4601
  model = picked?.name ?? modelOf(set) ?? options.model;
4565
4602
  }
4566
4603
  if (model) io.gotModel(model);
4604
+ if (Date.now() >= preparingUntil) throw Error("ACP preparation timed out.");
4605
+ phase("ready");
4606
+ currentSession = sessionId;
4567
4607
  live = true;
4608
+ phase("submitted");
4568
4609
  const done2 = await rpc.call("session/prompt", {
4569
4610
  sessionId,
4570
4611
  prompt: [{ type: "text", text: prompt }]
@@ -4645,6 +4686,7 @@ var PROTOCOL_VERSION, CLIENT_CAPABILITIES, INVALID_PARAMS, RESTARTED, TICKS_PER_
4645
4686
  var init_acp = __esm({
4646
4687
  "../cli/src/lib/agent/wire/acp.ts"() {
4647
4688
  "use strict";
4689
+ init_conversation();
4648
4690
  init_events();
4649
4691
  init_json();
4650
4692
  init_rpc();
@@ -5011,10 +5053,24 @@ function createCodexClient(options = { images: [] }) {
5011
5053
  }
5012
5054
  async function run(io, options, tasks) {
5013
5055
  const renderer = createCodexStreamRenderer();
5056
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
5057
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
5058
+ let submitted = false;
5059
+ let started = false;
5060
+ let contentAt = 0;
5061
+ let startupTimer;
5062
+ const began = () => {
5063
+ if (!submitted || started || ended) return;
5064
+ started = true;
5065
+ clearTimeout(startupTimer);
5066
+ phase("started");
5067
+ };
5014
5068
  const children = /* @__PURE__ */ new Set();
5015
5069
  const commands = /* @__PURE__ */ new Set();
5016
5070
  const seenItems = /* @__PURE__ */ new Set();
5017
5071
  const completedTurns = /* @__PURE__ */ new Set();
5072
+ const historicalTurns = /* @__PURE__ */ new Set();
5073
+ let currentTurn2 = "";
5018
5074
  let threadId = "";
5019
5075
  let active2 = true;
5020
5076
  let waiting = false;
@@ -5040,6 +5096,7 @@ async function run(io, options, tasks) {
5040
5096
  if (ended) return;
5041
5097
  ended = true;
5042
5098
  clearTimeout(timer);
5099
+ clearTimeout(startupTimer);
5043
5100
  deadline.close();
5044
5101
  io.stdout.off("close", closed2);
5045
5102
  io.log(renderer.flush());
@@ -5071,10 +5128,11 @@ async function run(io, options, tasks) {
5071
5128
  io.event?.({ kind: "tool_call_update", data: { toolCallId: `agent:${id}`, status: failed ? "failed" : "completed", result: str(state.message) } });
5072
5129
  }
5073
5130
  };
5074
- const item = (raw, completed) => {
5131
+ const item = (raw, completed, proof = true) => {
5075
5132
  if (ended) return;
5076
5133
  const id = str(raw.id);
5077
5134
  if (raw.type === "collabAgentToolCall") {
5135
+ if (proof) began();
5078
5136
  const key2 = `${id}:${completed}`;
5079
5137
  if (seenItems.has(key2)) return;
5080
5138
  seenItems.add(key2);
@@ -5102,6 +5160,7 @@ async function run(io, options, tasks) {
5102
5160
  const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
5103
5161
  const type = types[str(raw.type)];
5104
5162
  if (!type) return;
5163
+ if (proof) began();
5105
5164
  emit(completed ? "item.completed" : "item.started", { item: {
5106
5165
  ...raw,
5107
5166
  type,
@@ -5115,7 +5174,16 @@ async function run(io, options, tasks) {
5115
5174
  const start = async (text4, images = []) => {
5116
5175
  active2 = true;
5117
5176
  waiting = false;
5118
- await rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path86) => ({ type: "localImage", path: path86 }))] });
5177
+ submitted = true;
5178
+ currentTurn2 = "";
5179
+ started = false;
5180
+ phase("submitted");
5181
+ startupTimer = setTimeout(() => {
5182
+ if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
5183
+ }, CONVERSATION_MS.start);
5184
+ await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path86) => ({ type: "localImage", path: path86 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
5185
+ if (!started) throw error;
5186
+ });
5119
5187
  };
5120
5188
  const schedule = () => {
5121
5189
  if (ended || timer) return;
@@ -5200,11 +5268,21 @@ async function run(io, options, tasks) {
5200
5268
  }
5201
5269
  const p = obj(msg.params);
5202
5270
  if (str(p.threadId) !== threadId) return;
5271
+ const turnId = str(p.turnId) || str(obj(p.turn).id);
5272
+ if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
5203
5273
  if (msg.method === "turn/started") {
5274
+ if (!submitted || completedTurns.has(turnId)) return;
5275
+ currentTurn2 = turnId;
5204
5276
  active2 = true;
5277
+ began();
5205
5278
  return;
5206
5279
  }
5207
- if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed");
5280
+ if (submitted && msg.method === "item/agentMessage/delta" && Date.now() - contentAt >= 1e3) {
5281
+ began();
5282
+ contentAt = Date.now();
5283
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
5284
+ }
5285
+ if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
5208
5286
  if (msg.method === "thread/tokenUsage/updated") {
5209
5287
  const token2 = obj(p.tokenUsage);
5210
5288
  const counts = obj(token2.total);
@@ -5235,17 +5313,20 @@ async function run(io, options, tasks) {
5235
5313
  }
5236
5314
  });
5237
5315
  try {
5238
- await rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } });
5316
+ phase("preparing");
5317
+ await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
5318
+ phase("initialized");
5239
5319
  rpc.notify("initialized");
5240
5320
  const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
5241
5321
  let response;
5242
5322
  try {
5243
- response = await rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} });
5323
+ response = await bounded(rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} }), preparingUntil - Date.now(), `Codex thread/${mode ?? "start"} timed out.`);
5244
5324
  } catch (e) {
5245
5325
  if (mode && e instanceof RpcError && /no rollout found for thread id/i.test(e.message)) throw Error(`Thread not found: ${e.message}`);
5246
5326
  throw e;
5247
5327
  }
5248
5328
  const thread = obj(response.thread);
5329
+ for (const turn2 of list(thread.turns)) historicalTurns.add(str(turn2.id));
5249
5330
  threadId = str(thread.id);
5250
5331
  if (!threadId) throw Error("Codex did not return a thread id.");
5251
5332
  provider = str(thread.modelProvider) || void 0;
@@ -5254,6 +5335,8 @@ async function run(io, options, tasks) {
5254
5335
  io.gotResumeId(threadId);
5255
5336
  baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total;
5256
5337
  emit("thread.started", { thread_id: threadId });
5338
+ if (Date.now() >= preparingUntil) throw Error("Codex preparation timed out.");
5339
+ phase("ready");
5257
5340
  await start(io.prompt, options.images);
5258
5341
  } catch (e) {
5259
5342
  end2(e instanceof Error ? e.message : String(e));
@@ -5264,6 +5347,7 @@ var list;
5264
5347
  var init_codex = __esm({
5265
5348
  "../cli/src/lib/agent/wire/codex.ts"() {
5266
5349
  "use strict";
5350
+ init_conversation();
5267
5351
  init_settings();
5268
5352
  init_background();
5269
5353
  init_codex_stream();
@@ -1 +1 @@
1
- {"name":"wildcrane","version":"0.11.45","akbContract":12,"type":"module","private":true}
1
+ {"name":"wildcrane","version":"0.11.46","akbContract":12,"type":"module","private":true}
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.57 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.59 — built by runner/scripts/build.mjs. Do not edit.
2
2
  import { createRequire as __ai4kanbanRequire } from 'node:module'
3
3
  const require = __ai4kanbanRequire(import.meta.url)
4
4
  var __create = Object.create;
package/dist/launcher.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.57 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.59 — built by runner/scripts/build.mjs. Do not edit.
2
2
  import { createRequire as __ai4kanbanRequire } from 'node:module'
3
3
  const require = __ai4kanbanRequire(import.meta.url)
4
4
  var __create = Object.create;
@@ -26903,8 +26903,8 @@ function saveAlphaUpdates(value) {
26903
26903
  }
26904
26904
 
26905
26905
  // src/protocol.ts
26906
- var VERSION = true ? "0.6.57" : "0.0.0";
26907
- var AKB_VERSION = true ? "0.11.45" : "0.0.0";
26906
+ var VERSION = true ? "0.6.59" : "0.0.0";
26907
+ var AKB_VERSION = true ? "0.11.46" : "0.0.0";
26908
26908
  var EXIT_REFUSED = 10;
26909
26909
  var EXIT_OUTDATED = 11;
26910
26910
  var EXIT_UPDATE = 12;
@@ -30441,6 +30441,21 @@ function createKimiStreamRenderer(cwd) {
30441
30441
  };
30442
30442
  }
30443
30443
 
30444
+ // ../cli/src/lib/shared/conversation.ts
30445
+ var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
30446
+ function bounded(work, ms, reason) {
30447
+ return new Promise((resolve2, reject) => {
30448
+ const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
30449
+ work.then((value) => {
30450
+ clearTimeout(timer);
30451
+ resolve2(value);
30452
+ }, (error) => {
30453
+ clearTimeout(timer);
30454
+ reject(error);
30455
+ });
30456
+ });
30457
+ }
30458
+
30444
30459
  // ../cli/src/lib/agent/wire/acp.ts
30445
30460
  import fs19 from "node:fs";
30446
30461
 
@@ -30575,7 +30590,7 @@ function createTail(log) {
30575
30590
  // ../cli/package.json
30576
30591
  var package_default = {
30577
30592
  name: "wildcrane",
30578
- version: "0.11.45",
30593
+ version: "0.11.46",
30579
30594
  akbContract: 12,
30580
30595
  description: "WildCrane's `akb` command \u2014 scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
30581
30596
  keywords: [
@@ -30734,6 +30749,11 @@ function createAcpClient(options = {}) {
30734
30749
  }
30735
30750
  async function oneTurn(io, options) {
30736
30751
  const tail = createTail(io.log);
30752
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
30753
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
30754
+ let started = false;
30755
+ let contentAt = 0;
30756
+ let currentSession = "";
30737
30757
  const events = createEventCollector();
30738
30758
  const emit = () => {
30739
30759
  for (const e of events.events()) io.event?.(e);
@@ -30746,7 +30766,16 @@ async function oneTurn(io, options) {
30746
30766
  io.stdin,
30747
30767
  (msg) => {
30748
30768
  if (msg.method === "session/update") {
30749
- if (live) {
30769
+ if (live && (!obj(msg.params).sessionId || obj(msg.params).sessionId === currentSession)) {
30770
+ const kind = str2(obj(obj(msg.params).update).sessionUpdate);
30771
+ if (!started && ["agent_message_chunk", "tool_call", "plan"].includes(kind)) {
30772
+ started = true;
30773
+ phase("started");
30774
+ }
30775
+ if (kind === "agent_message_chunk" && Date.now() - contentAt >= 1e3) {
30776
+ contentAt = Date.now();
30777
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
30778
+ }
30750
30779
  update2(obj(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
30751
30780
  events.update(obj(msg.params).update);
30752
30781
  emit();
@@ -30774,20 +30803,22 @@ async function oneTurn(io, options) {
30774
30803
  );
30775
30804
  try {
30776
30805
  const mcpServers = options.mcpConfig ? mcpServersIn(options.mcpConfig) : [];
30777
- await rpc.call("initialize", {
30806
+ phase("preparing");
30807
+ await bounded(rpc.call("initialize", {
30778
30808
  protocolVersion: PROTOCOL_VERSION,
30779
30809
  clientCapabilities: CLIENT_CAPABILITIES,
30780
30810
  clientInfo: { name: "ai4kanban", version: SKILL_VERSION }
30781
- });
30811
+ }), preparingUntil - Date.now(), "ACP initialize timed out.");
30812
+ phase("initialized");
30782
30813
  let sessionId = io.resumeId ?? "";
30783
30814
  let prompt = io.prompt;
30784
30815
  let opened;
30785
30816
  if (sessionId) {
30786
30817
  try {
30787
- opened = await rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers });
30818
+ opened = await bounded(rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers }), preparingUntil - Date.now(), "ACP session/load timed out.");
30788
30819
  } catch (e) {
30789
30820
  if (!sessionGone(e) || !io.restartPrompt) throw e;
30790
- const fresh = await newSession(rpc, io.cwd, mcpServers);
30821
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
30791
30822
  opened = fresh.opened;
30792
30823
  sessionId = fresh.sessionId;
30793
30824
  prompt = io.restartPrompt;
@@ -30797,7 +30828,7 @@ async function oneTurn(io, options) {
30797
30828
  emit();
30798
30829
  }
30799
30830
  } else {
30800
- const fresh = await newSession(rpc, io.cwd, mcpServers);
30831
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
30801
30832
  opened = fresh.opened;
30802
30833
  sessionId = fresh.sessionId;
30803
30834
  io.gotResumeId(sessionId);
@@ -30806,11 +30837,15 @@ async function oneTurn(io, options) {
30806
30837
  if (options.model) {
30807
30838
  const listed2 = obj(opened.models).currentModelId !== void 0;
30808
30839
  const picked = listed2 ? pickedModel(opened, options.model) : void 0;
30809
- const set = listed2 ? await rpc.call("session/set_model", { sessionId, modelId: picked?.modelId ?? options.model }) : await rpc.call("session/set_config_option", { sessionId, configId: "model", value: options.model });
30840
+ const set = listed2 ? await bounded(rpc.call("session/set_model", { sessionId, modelId: picked?.modelId ?? options.model }), preparingUntil - Date.now(), "ACP session/set_model timed out.") : await bounded(rpc.call("session/set_config_option", { sessionId, configId: "model", value: options.model }), preparingUntil - Date.now(), "ACP session/set_config_option timed out.");
30810
30841
  model = picked?.name ?? modelOf(set) ?? options.model;
30811
30842
  }
30812
30843
  if (model) io.gotModel(model);
30844
+ if (Date.now() >= preparingUntil) throw Error("ACP preparation timed out.");
30845
+ phase("ready");
30846
+ currentSession = sessionId;
30813
30847
  live = true;
30848
+ phase("submitted");
30814
30849
  const done = await rpc.call("session/prompt", {
30815
30850
  sessionId,
30816
30851
  prompt: [{ type: "text", text: prompt }]
@@ -31227,10 +31262,24 @@ function createCodexClient(options = { images: [] }) {
31227
31262
  }
31228
31263
  async function run(io, options, tasks) {
31229
31264
  const renderer = createCodexStreamRenderer();
31265
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
31266
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
31267
+ let submitted = false;
31268
+ let started = false;
31269
+ let contentAt = 0;
31270
+ let startupTimer;
31271
+ const began = () => {
31272
+ if (!submitted || started || ended) return;
31273
+ started = true;
31274
+ clearTimeout(startupTimer);
31275
+ phase("started");
31276
+ };
31230
31277
  const children = /* @__PURE__ */ new Set();
31231
31278
  const commands = /* @__PURE__ */ new Set();
31232
31279
  const seenItems = /* @__PURE__ */ new Set();
31233
31280
  const completedTurns = /* @__PURE__ */ new Set();
31281
+ const historicalTurns = /* @__PURE__ */ new Set();
31282
+ let currentTurn2 = "";
31234
31283
  let threadId = "";
31235
31284
  let active = true;
31236
31285
  let waiting2 = false;
@@ -31256,6 +31305,7 @@ async function run(io, options, tasks) {
31256
31305
  if (ended) return;
31257
31306
  ended = true;
31258
31307
  clearTimeout(timer);
31308
+ clearTimeout(startupTimer);
31259
31309
  deadline.close();
31260
31310
  io.stdout.off("close", closed);
31261
31311
  io.log(renderer.flush());
@@ -31287,10 +31337,11 @@ async function run(io, options, tasks) {
31287
31337
  io.event?.({ kind: "tool_call_update", data: { toolCallId: `agent:${id}`, status: failed ? "failed" : "completed", result: str2(state.message) } });
31288
31338
  }
31289
31339
  };
31290
- const item = (raw, completed) => {
31340
+ const item = (raw, completed, proof = true) => {
31291
31341
  if (ended) return;
31292
31342
  const id = str2(raw.id);
31293
31343
  if (raw.type === "collabAgentToolCall") {
31344
+ if (proof) began();
31294
31345
  const key2 = `${id}:${completed}`;
31295
31346
  if (seenItems.has(key2)) return;
31296
31347
  seenItems.add(key2);
@@ -31318,6 +31369,7 @@ async function run(io, options, tasks) {
31318
31369
  const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
31319
31370
  const type = types[str2(raw.type)];
31320
31371
  if (!type) return;
31372
+ if (proof) began();
31321
31373
  emit(completed ? "item.completed" : "item.started", { item: {
31322
31374
  ...raw,
31323
31375
  type,
@@ -31331,7 +31383,16 @@ async function run(io, options, tasks) {
31331
31383
  const start = async (text3, images = []) => {
31332
31384
  active = true;
31333
31385
  waiting2 = false;
31334
- await rpc.call("turn/start", { threadId, input: [{ type: "text", text: text3 }, ...images.map((path31) => ({ type: "localImage", path: path31 }))] });
31386
+ submitted = true;
31387
+ currentTurn2 = "";
31388
+ started = false;
31389
+ phase("submitted");
31390
+ startupTimer = setTimeout(() => {
31391
+ if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
31392
+ }, CONVERSATION_MS.start);
31393
+ await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text3 }, ...images.map((path31) => ({ type: "localImage", path: path31 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
31394
+ if (!started) throw error;
31395
+ });
31335
31396
  };
31336
31397
  const schedule = () => {
31337
31398
  if (ended || timer) return;
@@ -31416,11 +31477,21 @@ async function run(io, options, tasks) {
31416
31477
  }
31417
31478
  const p = obj(msg.params);
31418
31479
  if (str2(p.threadId) !== threadId) return;
31480
+ const turnId = str2(p.turnId) || str2(obj(p.turn).id);
31481
+ if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
31419
31482
  if (msg.method === "turn/started") {
31483
+ if (!submitted || completedTurns.has(turnId)) return;
31484
+ currentTurn2 = turnId;
31420
31485
  active = true;
31486
+ began();
31421
31487
  return;
31422
31488
  }
31423
- if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed");
31489
+ if (submitted && msg.method === "item/agentMessage/delta" && Date.now() - contentAt >= 1e3) {
31490
+ began();
31491
+ contentAt = Date.now();
31492
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
31493
+ }
31494
+ if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
31424
31495
  if (msg.method === "thread/tokenUsage/updated") {
31425
31496
  const token = obj(p.tokenUsage);
31426
31497
  const counts = obj(token.total);
@@ -31451,17 +31522,20 @@ async function run(io, options, tasks) {
31451
31522
  }
31452
31523
  });
31453
31524
  try {
31454
- await rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } });
31525
+ phase("preparing");
31526
+ await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
31527
+ phase("initialized");
31455
31528
  rpc.notify("initialized");
31456
31529
  const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
31457
31530
  let response;
31458
31531
  try {
31459
- response = await rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} });
31532
+ response = await bounded(rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} }), preparingUntil - Date.now(), `Codex thread/${mode ?? "start"} timed out.`);
31460
31533
  } catch (e) {
31461
31534
  if (mode && e instanceof RpcError && /no rollout found for thread id/i.test(e.message)) throw Error(`Thread not found: ${e.message}`);
31462
31535
  throw e;
31463
31536
  }
31464
31537
  const thread = obj(response.thread);
31538
+ for (const turn2 of list(thread.turns)) historicalTurns.add(str2(turn2.id));
31465
31539
  threadId = str2(thread.id);
31466
31540
  if (!threadId) throw Error("Codex did not return a thread id.");
31467
31541
  provider = str2(thread.modelProvider) || void 0;
@@ -31470,6 +31544,8 @@ async function run(io, options, tasks) {
31470
31544
  io.gotResumeId(threadId);
31471
31545
  baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total;
31472
31546
  emit("thread.started", { thread_id: threadId });
31547
+ if (Date.now() >= preparingUntil) throw Error("Codex preparation timed out.");
31548
+ phase("ready");
31473
31549
  await start(io.prompt, options.images);
31474
31550
  } catch (e) {
31475
31551
  end(e instanceof Error ? e.message : String(e));