wildcrane-runner 0.6.57 → 0.6.58

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.
package/dist/plugin.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.58 — 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;
@@ -73774,7 +73774,7 @@ function machineId() {
73774
73774
  var machineName = () => os3.hostname().replace(/\.local$/, "");
73775
73775
 
73776
73776
  // src/protocol.ts
73777
- var VERSION = true ? "0.6.57" : "0.0.0";
73777
+ var VERSION = true ? "0.6.58" : "0.0.0";
73778
73778
  var AKB_VERSION = true ? "0.11.45" : "0.0.0";
73779
73779
  var EXIT_REFUSED = 10;
73780
73780
  var EXIT_OUTDATED = 11;
@@ -77024,6 +77024,21 @@ function createKimiStreamRenderer(cwd) {
77024
77024
  };
77025
77025
  }
77026
77026
 
77027
+ // ../cli/src/lib/shared/conversation.ts
77028
+ var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
77029
+ function bounded(work, ms, reason) {
77030
+ return new Promise((resolve2, reject) => {
77031
+ const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
77032
+ work.then((value) => {
77033
+ clearTimeout(timer);
77034
+ resolve2(value);
77035
+ }, (error2) => {
77036
+ clearTimeout(timer);
77037
+ reject(error2);
77038
+ });
77039
+ });
77040
+ }
77041
+
77027
77042
  // ../cli/src/lib/agent/wire/acp.ts
77028
77043
  import fs19 from "node:fs";
77029
77044
 
@@ -77317,6 +77332,11 @@ function createAcpClient(options = {}) {
77317
77332
  }
77318
77333
  async function oneTurn(io, options) {
77319
77334
  const tail = createTail(io.log);
77335
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
77336
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
77337
+ let started = false;
77338
+ let contentAt = 0;
77339
+ let currentSession = "";
77320
77340
  const events = createEventCollector();
77321
77341
  const emit = () => {
77322
77342
  for (const e of events.events()) io.event?.(e);
@@ -77329,7 +77349,16 @@ async function oneTurn(io, options) {
77329
77349
  io.stdin,
77330
77350
  (msg) => {
77331
77351
  if (msg.method === "session/update") {
77332
- if (live) {
77352
+ if (live && (!obj(msg.params).sessionId || obj(msg.params).sessionId === currentSession)) {
77353
+ const kind = str2(obj(obj(msg.params).update).sessionUpdate);
77354
+ if (!started && ["agent_message_chunk", "tool_call", "plan"].includes(kind)) {
77355
+ started = true;
77356
+ phase("started");
77357
+ }
77358
+ if (kind === "agent_message_chunk" && Date.now() - contentAt >= 1e3) {
77359
+ contentAt = Date.now();
77360
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
77361
+ }
77333
77362
  update2(obj(msg.params).update, tail, (usd) => costUsd = usd, (window) => context = window);
77334
77363
  events.update(obj(msg.params).update);
77335
77364
  emit();
@@ -77357,20 +77386,22 @@ async function oneTurn(io, options) {
77357
77386
  );
77358
77387
  try {
77359
77388
  const mcpServers = options.mcpConfig ? mcpServersIn(options.mcpConfig) : [];
77360
- await rpc.call("initialize", {
77389
+ phase("preparing");
77390
+ await bounded(rpc.call("initialize", {
77361
77391
  protocolVersion: PROTOCOL_VERSION,
77362
77392
  clientCapabilities: CLIENT_CAPABILITIES,
77363
77393
  clientInfo: { name: "ai4kanban", version: SKILL_VERSION }
77364
- });
77394
+ }), preparingUntil - Date.now(), "ACP initialize timed out.");
77395
+ phase("initialized");
77365
77396
  let sessionId = io.resumeId ?? "";
77366
77397
  let prompt = io.prompt;
77367
77398
  let opened;
77368
77399
  if (sessionId) {
77369
77400
  try {
77370
- opened = await rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers });
77401
+ opened = await bounded(rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers }), preparingUntil - Date.now(), "ACP session/load timed out.");
77371
77402
  } catch (e) {
77372
77403
  if (!sessionGone(e) || !io.restartPrompt) throw e;
77373
- const fresh = await newSession(rpc, io.cwd, mcpServers);
77404
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
77374
77405
  opened = fresh.opened;
77375
77406
  sessionId = fresh.sessionId;
77376
77407
  prompt = io.restartPrompt;
@@ -77380,7 +77411,7 @@ async function oneTurn(io, options) {
77380
77411
  emit();
77381
77412
  }
77382
77413
  } else {
77383
- const fresh = await newSession(rpc, io.cwd, mcpServers);
77414
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
77384
77415
  opened = fresh.opened;
77385
77416
  sessionId = fresh.sessionId;
77386
77417
  io.gotResumeId(sessionId);
@@ -77389,11 +77420,15 @@ async function oneTurn(io, options) {
77389
77420
  if (options.model) {
77390
77421
  const listed2 = obj(opened.models).currentModelId !== void 0;
77391
77422
  const picked = listed2 ? pickedModel(opened, options.model) : void 0;
77392
- 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 });
77423
+ 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.");
77393
77424
  model = picked?.name ?? modelOf(set) ?? options.model;
77394
77425
  }
77395
77426
  if (model) io.gotModel(model);
77427
+ if (Date.now() >= preparingUntil) throw Error("ACP preparation timed out.");
77428
+ phase("ready");
77429
+ currentSession = sessionId;
77396
77430
  live = true;
77431
+ phase("submitted");
77397
77432
  const done = await rpc.call("session/prompt", {
77398
77433
  sessionId,
77399
77434
  prompt: [{ type: "text", text: prompt }]
@@ -77810,10 +77845,24 @@ function createCodexClient(options = { images: [] }) {
77810
77845
  }
77811
77846
  async function run(io, options, tasks2) {
77812
77847
  const renderer = createCodexStreamRenderer();
77848
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
77849
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
77850
+ let submitted = false;
77851
+ let started = false;
77852
+ let contentAt = 0;
77853
+ let startupTimer;
77854
+ const began = () => {
77855
+ if (!submitted || started || ended) return;
77856
+ started = true;
77857
+ clearTimeout(startupTimer);
77858
+ phase("started");
77859
+ };
77813
77860
  const children = /* @__PURE__ */ new Set();
77814
77861
  const commands = /* @__PURE__ */ new Set();
77815
77862
  const seenItems = /* @__PURE__ */ new Set();
77816
77863
  const completedTurns = /* @__PURE__ */ new Set();
77864
+ const historicalTurns = /* @__PURE__ */ new Set();
77865
+ let currentTurn2 = "";
77817
77866
  let threadId = "";
77818
77867
  let active = true;
77819
77868
  let waiting2 = false;
@@ -77839,6 +77888,7 @@ async function run(io, options, tasks2) {
77839
77888
  if (ended) return;
77840
77889
  ended = true;
77841
77890
  clearTimeout(timer);
77891
+ clearTimeout(startupTimer);
77842
77892
  deadline.close();
77843
77893
  io.stdout.off("close", closed);
77844
77894
  io.log(renderer.flush());
@@ -77870,10 +77920,11 @@ async function run(io, options, tasks2) {
77870
77920
  io.event?.({ kind: "tool_call_update", data: { toolCallId: `agent:${id}`, status: failed ? "failed" : "completed", result: str2(state2.message) } });
77871
77921
  }
77872
77922
  };
77873
- const item = (raw, completed) => {
77923
+ const item = (raw, completed, proof = true) => {
77874
77924
  if (ended) return;
77875
77925
  const id = str2(raw.id);
77876
77926
  if (raw.type === "collabAgentToolCall") {
77927
+ if (proof) began();
77877
77928
  const key2 = `${id}:${completed}`;
77878
77929
  if (seenItems.has(key2)) return;
77879
77930
  seenItems.add(key2);
@@ -77901,6 +77952,7 @@ async function run(io, options, tasks2) {
77901
77952
  const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
77902
77953
  const type = types[str2(raw.type)];
77903
77954
  if (!type) return;
77955
+ if (proof) began();
77904
77956
  emit(completed ? "item.completed" : "item.started", { item: {
77905
77957
  ...raw,
77906
77958
  type,
@@ -77914,7 +77966,16 @@ async function run(io, options, tasks2) {
77914
77966
  const start = async (text4, images = []) => {
77915
77967
  active = true;
77916
77968
  waiting2 = false;
77917
- await rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path32) => ({ type: "localImage", path: path32 }))] });
77969
+ submitted = true;
77970
+ currentTurn2 = "";
77971
+ started = false;
77972
+ phase("submitted");
77973
+ startupTimer = setTimeout(() => {
77974
+ if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
77975
+ }, CONVERSATION_MS.start);
77976
+ await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path32) => ({ type: "localImage", path: path32 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error2) => {
77977
+ if (!started) throw error2;
77978
+ });
77918
77979
  };
77919
77980
  const schedule = () => {
77920
77981
  if (ended || timer) return;
@@ -77999,11 +78060,21 @@ async function run(io, options, tasks2) {
77999
78060
  }
78000
78061
  const p = obj(msg.params);
78001
78062
  if (str2(p.threadId) !== threadId) return;
78063
+ const turnId = str2(p.turnId) || str2(obj(p.turn).id);
78064
+ if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
78002
78065
  if (msg.method === "turn/started") {
78066
+ if (!submitted || completedTurns.has(turnId)) return;
78067
+ currentTurn2 = turnId;
78003
78068
  active = true;
78069
+ began();
78004
78070
  return;
78005
78071
  }
78006
- if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed");
78072
+ if (submitted && msg.method === "item/agentMessage/delta" && Date.now() - contentAt >= 1e3) {
78073
+ began();
78074
+ contentAt = Date.now();
78075
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
78076
+ }
78077
+ if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p.item), msg.method === "item/completed", !completedTurns.has(turnId));
78007
78078
  if (msg.method === "thread/tokenUsage/updated") {
78008
78079
  const token = obj(p.tokenUsage);
78009
78080
  const counts = obj(token.total);
@@ -78034,17 +78105,20 @@ async function run(io, options, tasks2) {
78034
78105
  }
78035
78106
  });
78036
78107
  try {
78037
- await rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } });
78108
+ phase("preparing");
78109
+ await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
78110
+ phase("initialized");
78038
78111
  rpc.notify("initialized");
78039
78112
  const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
78040
78113
  let response;
78041
78114
  try {
78042
- response = await rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} });
78115
+ 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.`);
78043
78116
  } catch (e) {
78044
78117
  if (mode && e instanceof RpcError && /no rollout found for thread id/i.test(e.message)) throw Error(`Thread not found: ${e.message}`);
78045
78118
  throw e;
78046
78119
  }
78047
78120
  const thread = obj(response.thread);
78121
+ for (const turn2 of list(thread.turns)) historicalTurns.add(str2(turn2.id));
78048
78122
  threadId = str2(thread.id);
78049
78123
  if (!threadId) throw Error("Codex did not return a thread id.");
78050
78124
  provider = str2(thread.modelProvider) || void 0;
@@ -78053,6 +78127,8 @@ async function run(io, options, tasks2) {
78053
78127
  io.gotResumeId(threadId);
78054
78128
  baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total;
78055
78129
  emit("thread.started", { thread_id: threadId });
78130
+ if (Date.now() >= preparingUntil) throw Error("Codex preparation timed out.");
78131
+ phase("ready");
78056
78132
  await start(io.prompt, options.images);
78057
78133
  } catch (e) {
78058
78134
  end(e instanceof Error ? e.message : String(e));
package/dist/runner.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.58 — 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;
@@ -111420,7 +111420,7 @@ function status(line) {
111420
111420
  }
111421
111421
 
111422
111422
  // src/protocol.ts
111423
- var VERSION = true ? "0.6.57" : "0.0.0";
111423
+ var VERSION = true ? "0.6.58" : "0.0.0";
111424
111424
  var AKB_VERSION = true ? "0.11.45" : "0.0.0";
111425
111425
  var AKB_CONTRACT = true ? 12 : 0;
111426
111426
  var EXIT_REFUSED = 10;
@@ -111939,7 +111939,7 @@ function argHint(input, keys) {
111939
111939
  }
111940
111940
 
111941
111941
  // ../cli/src/lib/agent/wire/events.ts
111942
- var EVENT_KINDS = ["message", "tool_call", "tool_call_update", "plan", "error", "log", "context"];
111942
+ var EVENT_KINDS = ["message", "tool_call", "tool_call_update", "plan", "error", "log", "context", "phase"];
111943
111943
  var TOOL_KINDS = ["read", "edit", "delete", "move", "search", "execute", "fetch", "other"];
111944
111944
  var toolKind = (v) => TOOL_KINDS.includes(str(v)) ? v : "other";
111945
111945
  function targetOf(raw) {
@@ -113016,6 +113016,21 @@ function createKimiStreamRenderer(cwd) {
113016
113016
  };
113017
113017
  }
113018
113018
 
113019
+ // ../cli/src/lib/shared/conversation.ts
113020
+ var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
113021
+ function bounded(work, ms, reason) {
113022
+ return new Promise((resolve2, reject) => {
113023
+ const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
113024
+ work.then((value) => {
113025
+ clearTimeout(timer);
113026
+ resolve2(value);
113027
+ }, (error) => {
113028
+ clearTimeout(timer);
113029
+ reject(error);
113030
+ });
113031
+ });
113032
+ }
113033
+
113019
113034
  // ../cli/src/lib/agent/wire/acp.ts
113020
113035
  import fs6 from "node:fs";
113021
113036
 
@@ -113309,6 +113324,11 @@ function createAcpClient(options = {}) {
113309
113324
  }
113310
113325
  async function oneTurn(io, options) {
113311
113326
  const tail = createTail(io.log);
113327
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
113328
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
113329
+ let started = false;
113330
+ let contentAt = 0;
113331
+ let currentSession = "";
113312
113332
  const events = createEventCollector();
113313
113333
  const emit = () => {
113314
113334
  for (const e2 of events.events()) io.event?.(e2);
@@ -113321,7 +113341,16 @@ async function oneTurn(io, options) {
113321
113341
  io.stdin,
113322
113342
  (msg) => {
113323
113343
  if (msg.method === "session/update") {
113324
- if (live) {
113344
+ if (live && (!obj(msg.params).sessionId || obj(msg.params).sessionId === currentSession)) {
113345
+ const kind = str(obj(obj(msg.params).update).sessionUpdate);
113346
+ if (!started && ["agent_message_chunk", "tool_call", "plan"].includes(kind)) {
113347
+ started = true;
113348
+ phase("started");
113349
+ }
113350
+ if (kind === "agent_message_chunk" && Date.now() - contentAt >= 1e3) {
113351
+ contentAt = Date.now();
113352
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
113353
+ }
113325
113354
  update(obj(msg.params).update, tail, (usd) => costUsd = usd, (window2) => context = window2);
113326
113355
  events.update(obj(msg.params).update);
113327
113356
  emit();
@@ -113349,20 +113378,22 @@ async function oneTurn(io, options) {
113349
113378
  );
113350
113379
  try {
113351
113380
  const mcpServers = options.mcpConfig ? mcpServersIn(options.mcpConfig) : [];
113352
- await rpc.call("initialize", {
113381
+ phase("preparing");
113382
+ await bounded(rpc.call("initialize", {
113353
113383
  protocolVersion: PROTOCOL_VERSION,
113354
113384
  clientCapabilities: CLIENT_CAPABILITIES,
113355
113385
  clientInfo: { name: "ai4kanban", version: SKILL_VERSION }
113356
- });
113386
+ }), preparingUntil - Date.now(), "ACP initialize timed out.");
113387
+ phase("initialized");
113357
113388
  let sessionId = io.resumeId ?? "";
113358
113389
  let prompt = io.prompt;
113359
113390
  let opened;
113360
113391
  if (sessionId) {
113361
113392
  try {
113362
- opened = await rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers });
113393
+ opened = await bounded(rpc.call("session/load", { sessionId, cwd: io.cwd, mcpServers }), preparingUntil - Date.now(), "ACP session/load timed out.");
113363
113394
  } catch (e2) {
113364
113395
  if (!sessionGone(e2) || !io.restartPrompt) throw e2;
113365
- const fresh = await newSession(rpc, io.cwd, mcpServers);
113396
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
113366
113397
  opened = fresh.opened;
113367
113398
  sessionId = fresh.sessionId;
113368
113399
  prompt = io.restartPrompt;
@@ -113372,7 +113403,7 @@ async function oneTurn(io, options) {
113372
113403
  emit();
113373
113404
  }
113374
113405
  } else {
113375
- const fresh = await newSession(rpc, io.cwd, mcpServers);
113406
+ const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
113376
113407
  opened = fresh.opened;
113377
113408
  sessionId = fresh.sessionId;
113378
113409
  io.gotResumeId(sessionId);
@@ -113381,11 +113412,15 @@ async function oneTurn(io, options) {
113381
113412
  if (options.model) {
113382
113413
  const listed2 = obj(opened.models).currentModelId !== void 0;
113383
113414
  const picked = listed2 ? pickedModel(opened, options.model) : void 0;
113384
- 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 });
113415
+ 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.");
113385
113416
  model = picked?.name ?? modelOf(set) ?? options.model;
113386
113417
  }
113387
113418
  if (model) io.gotModel(model);
113419
+ if (Date.now() >= preparingUntil) throw Error("ACP preparation timed out.");
113420
+ phase("ready");
113421
+ currentSession = sessionId;
113388
113422
  live = true;
113423
+ phase("submitted");
113389
113424
  const done = await rpc.call("session/prompt", {
113390
113425
  sessionId,
113391
113426
  prompt: [{ type: "text", text: prompt }]
@@ -114082,10 +114117,24 @@ function createCodexClient(options = { images: [] }) {
114082
114117
  }
114083
114118
  async function run(io, options, tasks) {
114084
114119
  const renderer = createCodexStreamRenderer();
114120
+ const preparingUntil = Math.min(io.prepareUntil ?? Infinity, Date.now() + CONVERSATION_MS.prepare);
114121
+ const phase = (phase2) => io.event?.({ kind: "phase", data: { phase: phase2, at: (/* @__PURE__ */ new Date()).toISOString() } });
114122
+ let submitted = false;
114123
+ let started = false;
114124
+ let contentAt = 0;
114125
+ let startupTimer;
114126
+ const began = () => {
114127
+ if (!submitted || started || ended2) return;
114128
+ started = true;
114129
+ clearTimeout(startupTimer);
114130
+ phase("started");
114131
+ };
114085
114132
  const children = /* @__PURE__ */ new Set();
114086
114133
  const commands = /* @__PURE__ */ new Set();
114087
114134
  const seenItems = /* @__PURE__ */ new Set();
114088
114135
  const completedTurns = /* @__PURE__ */ new Set();
114136
+ const historicalTurns = /* @__PURE__ */ new Set();
114137
+ let currentTurn2 = "";
114089
114138
  let threadId = "";
114090
114139
  let active = true;
114091
114140
  let waiting = false;
@@ -114111,6 +114160,7 @@ async function run(io, options, tasks) {
114111
114160
  if (ended2) return;
114112
114161
  ended2 = true;
114113
114162
  clearTimeout(timer);
114163
+ clearTimeout(startupTimer);
114114
114164
  deadline.close();
114115
114165
  io.stdout.off("close", closed);
114116
114166
  io.log(renderer.flush());
@@ -114142,10 +114192,11 @@ async function run(io, options, tasks) {
114142
114192
  io.event?.({ kind: "tool_call_update", data: { toolCallId: `agent:${id}`, status: failed ? "failed" : "completed", result: str(state.message) } });
114143
114193
  }
114144
114194
  };
114145
- const item = (raw, completed) => {
114195
+ const item = (raw, completed, proof = true) => {
114146
114196
  if (ended2) return;
114147
114197
  const id = str(raw.id);
114148
114198
  if (raw.type === "collabAgentToolCall") {
114199
+ if (proof) began();
114149
114200
  const key2 = `${id}:${completed}`;
114150
114201
  if (seenItems.has(key2)) return;
114151
114202
  seenItems.add(key2);
@@ -114173,6 +114224,7 @@ async function run(io, options, tasks) {
114173
114224
  const types = { agentMessage: "agent_message", commandExecution: "command_execution", fileChange: "file_change", mcpToolCall: "mcp_tool_call", webSearch: "web_search", imageGeneration: "image_generation" };
114174
114225
  const type = types[str(raw.type)];
114175
114226
  if (!type) return;
114227
+ if (proof) began();
114176
114228
  emit(completed ? "item.completed" : "item.started", { item: {
114177
114229
  ...raw,
114178
114230
  type,
@@ -114186,7 +114238,16 @@ async function run(io, options, tasks) {
114186
114238
  const start = async (text3, images = []) => {
114187
114239
  active = true;
114188
114240
  waiting = false;
114189
- await rpc.call("turn/start", { threadId, input: [{ type: "text", text: text3 }, ...images.map((path52) => ({ type: "localImage", path: path52 }))] });
114241
+ submitted = true;
114242
+ currentTurn2 = "";
114243
+ started = false;
114244
+ phase("submitted");
114245
+ startupTimer = setTimeout(() => {
114246
+ if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
114247
+ }, CONVERSATION_MS.start);
114248
+ await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text3 }, ...images.map((path52) => ({ type: "localImage", path: path52 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
114249
+ if (!started) throw error;
114250
+ });
114190
114251
  };
114191
114252
  const schedule = () => {
114192
114253
  if (ended2 || timer) return;
@@ -114271,11 +114332,21 @@ async function run(io, options, tasks) {
114271
114332
  }
114272
114333
  const p2 = obj(msg.params);
114273
114334
  if (str(p2.threadId) !== threadId) return;
114335
+ const turnId = str(p2.turnId) || str(obj(p2.turn).id);
114336
+ if (historicalTurns.has(turnId) || currentTurn2 && turnId && currentTurn2 !== turnId) return;
114274
114337
  if (msg.method === "turn/started") {
114338
+ if (!submitted || completedTurns.has(turnId)) return;
114339
+ currentTurn2 = turnId;
114275
114340
  active = true;
114341
+ began();
114276
114342
  return;
114277
114343
  }
114278
- if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p2.item), msg.method === "item/completed");
114344
+ if (submitted && msg.method === "item/agentMessage/delta" && Date.now() - contentAt >= 1e3) {
114345
+ began();
114346
+ contentAt = Date.now();
114347
+ io.event?.({ kind: "phase", data: { phase: "started", at: (/* @__PURE__ */ new Date()).toISOString(), contentAt: new Date(contentAt).toISOString() } });
114348
+ }
114349
+ if (msg.method === "item/started" || msg.method === "item/completed") item(obj(p2.item), msg.method === "item/completed", !completedTurns.has(turnId));
114279
114350
  if (msg.method === "thread/tokenUsage/updated") {
114280
114351
  const token = obj(p2.tokenUsage);
114281
114352
  const counts2 = obj(token.total);
@@ -114306,17 +114377,20 @@ async function run(io, options, tasks) {
114306
114377
  }
114307
114378
  });
114308
114379
  try {
114309
- await rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } });
114380
+ phase("preparing");
114381
+ await bounded(rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), preparingUntil - Date.now(), "Codex initialize timed out.");
114382
+ phase("initialized");
114310
114383
  rpc.notify("initialized");
114311
114384
  const mode = options.mode ?? (io.resumeId ? "resume" : void 0);
114312
114385
  let response;
114313
114386
  try {
114314
- response = await rpc.call(`thread/${mode ?? "start"}`, { cwd: options.cwd ?? io.cwd, ...mode ? { threadId: options.threadId ?? io.resumeId } : {} });
114387
+ 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.`);
114315
114388
  } catch (e2) {
114316
114389
  if (mode && e2 instanceof RpcError && /no rollout found for thread id/i.test(e2.message)) throw Error(`Thread not found: ${e2.message}`);
114317
114390
  throw e2;
114318
114391
  }
114319
114392
  const thread = obj(response.thread);
114393
+ for (const turn2 of list(thread.turns)) historicalTurns.add(str(turn2.id));
114320
114394
  threadId = str(thread.id);
114321
114395
  if (!threadId) throw Error("Codex did not return a thread id.");
114322
114396
  provider = str(thread.modelProvider) || void 0;
@@ -114325,6 +114399,8 @@ async function run(io, options, tasks) {
114325
114399
  io.gotResumeId(threadId);
114326
114400
  baseline = readCodexRunFacts(threadId)?.turns?.at(-1)?.total;
114327
114401
  emit("thread.started", { thread_id: threadId });
114402
+ if (Date.now() >= preparingUntil) throw Error("Codex preparation timed out.");
114403
+ phase("ready");
114328
114404
  await start(io.prompt, options.images);
114329
114405
  } catch (e2) {
114330
114406
  end(e2 instanceof Error ? e2.message : String(e2));
@@ -116075,7 +116151,7 @@ var release = (machineId2) => request("POST", "/v1/runner/release", { machineId:
116075
116151
  var listJobs = (machineId2) => request("GET", `/v1/runner/jobs?machine=${encodeURIComponent(machineId2)}`);
116076
116152
  var move = (job, what, body) => request("POST", `/v1/runner/jobs/${encodeURIComponent(job)}/${what}`, body);
116077
116153
  var claimJob = (machineId2, job) => move(job, "claim", { machineId: machineId2 });
116078
- var renewJob = (machineId2, job) => move(job, "renew", { machineId: machineId2 });
116154
+ var renewJob = (machineId2, job, progress) => move(job, "renew", { machineId: machineId2, ...progress ? { progress } : {} });
116079
116155
  async function openLog(machineId2, job) {
116080
116156
  const token = await accessToken();
116081
116157
  if (!token.ok) return null;
@@ -116206,10 +116282,11 @@ function plan(runtime, prompt, cwd, resume, model, given = {}, fork = false, lan
116206
116282
  command: started[0],
116207
116283
  args: started.slice(1),
116208
116284
  env: env2,
116209
- converse: (child, event2, restart = true) => client.turn({
116285
+ converse: (child, event2, restart = true, prepareUntil) => client.turn({
116210
116286
  stdout: child.stdout,
116211
116287
  stdin: child.stdin,
116212
116288
  prompt,
116289
+ prepareUntil,
116213
116290
  restartPrompt: restart ? prompt : void 0,
116214
116291
  cwd,
116215
116292
  resumeId: resume ?? void 0,
@@ -121187,6 +121264,7 @@ function clearCheckpoint(id) {
121187
121264
  fs38.rmSync(fileOf(id), { force: true });
121188
121265
  }
121189
121266
  function checkpointEvent(checkpoint, event2) {
121267
+ if (event2.kind === "phase" && event2.data.phase === "submitted") checkpoint.submitted = true;
121190
121268
  if (event2.kind === "tool_call") {
121191
121269
  const { toolCallId, status: status2, kind } = event2.data;
121192
121270
  if (!["read", "search", "fetch"].includes(kind)) checkpoint.effects = true;
@@ -121217,7 +121295,7 @@ function replyRetry(checkpoint, reason, now = Date.now(), backoff = backoffMs) {
121217
121295
  return at2 <= retry2.since + 12e4 ? at2 : null;
121218
121296
  }
121219
121297
  function replayable(checkpoint) {
121220
- return (checkpoint.effects === false || checkpoint.started === false) && !checkpoint.pending.length && !checkpoint.opaque;
121298
+ return checkpoint.submitted !== true && (checkpoint.effects === false || checkpoint.started === false) && !checkpoint.pending.length && !checkpoint.opaque;
121221
121299
  }
121222
121300
  function resumable(checkpoint) {
121223
121301
  return !!checkpoint.session && !checkpoint.pending.length && !checkpoint.opaque;
@@ -121933,7 +122011,7 @@ function toWire(events, first) {
121933
122011
  continue;
121934
122012
  }
121935
122013
  endLog();
121936
- const data = { ...e2.data };
122014
+ const data = { ...e2.data, eventAt: "eventAt" in e2.data ? e2.data.eventAt : (/* @__PURE__ */ new Date()).toISOString() };
121937
122015
  for (const key of ["text", "result"]) if (typeof data[key] === "string") data[key] = cut(data[key]);
121938
122016
  out.push({ seq: first + out.length, kind: e2.kind, text: "", data });
121939
122017
  }
@@ -122077,7 +122155,7 @@ function streamOut(deps, id, lease) {
122077
122155
  const event2 = (e2) => {
122078
122156
  if (!valid()) return;
122079
122157
  if (e2.kind === "message") messages.push(e2.data.text);
122080
- pending.push(e2);
122158
+ pending.push(Object.assign({}, e2, { data: { ...e2.data, eventAt: (/* @__PURE__ */ new Date()).toISOString() } }));
122081
122159
  size += JSON.stringify(e2.data).length;
122082
122160
  if (log.watched && size >= FLUSH_CHARS) flush();
122083
122161
  };
@@ -122146,6 +122224,7 @@ function streamOut(deps, id, lease) {
122146
122224
  return true;
122147
122225
  },
122148
122226
  stop: loseLease,
122227
+ requestStop: ask,
122149
122228
  lost: () => !valid(),
122150
122229
  asked: () => asked,
122151
122230
  whenAsked: askedOnce,
@@ -122387,7 +122466,7 @@ ${prompt}` : prompt;
122387
122466
  }
122388
122467
  if (deps.authorize && !await deps.authorize(job)) return finishClaimed("failed", "\u9879\u76EE\u76EE\u5F55\u6388\u6743\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u786E\u8BA4\u540E\u91CD\u8BD5\u3002");
122389
122468
  if (!held3(deps, lease)) return;
122390
- if (reply && recovering) {
122469
+ if (reply) {
122391
122470
  const renewed = await deps.api.renewJob(deps.machineId, id);
122392
122471
  if (!renewed.ok || !renewed.value.renewed) return;
122393
122472
  if (renewed.value.stop) return finishClaimed("stopped", "", { stopped: true });
@@ -122411,10 +122490,24 @@ ${prompt}` : prompt;
122411
122490
  return { ...rest, ...replySpent(checkpoint, job.runtime) };
122412
122491
  };
122413
122492
  let replyProgress = false;
122493
+ let evidence = Promise.resolve();
122494
+ let lastEvidence = 0;
122414
122495
  const subagents = trackSubagents();
122415
122496
  const remember = (event2) => {
122416
122497
  if (["message", "tool_call", "tool_call_update"].includes(event2.kind)) replyProgress = true;
122417
122498
  if (stream.lost()) return;
122499
+ const content = ["message", "tool_call", "tool_call_update", "plan"].includes(event2.kind) || event2.kind === "phase" && !!event2.data.contentAt;
122500
+ if (reply && (event2.kind === "phase" && !event2.data.contentAt || content && Date.now() - lastEvidence >= 5e3)) {
122501
+ if (content) lastEvidence = Date.now();
122502
+ const progress = { attempt: checkpoint.retry?.attempt ?? 1, ...event2.kind === "phase" ? { phase: event2.data.phase } : {}, ...content ? { contentAt: (/* @__PURE__ */ new Date()).toISOString() } : {} };
122503
+ evidence = evidence.then(async () => {
122504
+ if (stream.asked() || stream.lost()) return;
122505
+ const result = await deps.api.renewJob(deps.machineId, id, progress);
122506
+ if (result.ok && !result.value.renewed) await stream.stop();
122507
+ else if (result.ok && result.value.stop) stream.requestStop();
122508
+ }).catch(() => {
122509
+ });
122510
+ }
122418
122511
  subagents.event(event2);
122419
122512
  checkpointEvent(checkpoint, event2);
122420
122513
  const session = run3?.session();
@@ -122425,6 +122518,8 @@ ${prompt}` : prompt;
122425
122518
  };
122426
122519
  const retry2 = async (reason) => {
122427
122520
  if (!reply || !reason || stream.asked() || stream.lost()) return false;
122521
+ if ((checkpoint.retry?.attempt ?? 1) >= 2 || !/timed out|ECONNRESET|ETIMEDOUT|temporar|overload|capacity|rate.limit|429|503|network|connection.*(reset|closed)/i.test(reason)) return false;
122522
+ if (/timed out|start_unconfirmed/i.test(reason) && (!/initialize|session\/(new|load)|thread\/(start|resume|fork)/i.test(reason) || Date.now() >= checkpoint.retry.since + CONVERSATION_MS.prepare)) return false;
122428
122523
  checkpoint.approvalCancelled = true;
122429
122524
  persist();
122430
122525
  if (job.chat && checkpoint.approvalRequested) await cancelReplyApproval(deps.machineId, id);
@@ -122514,8 +122609,8 @@ ${prompt}` : prompt;
122514
122609
  await stream.end();
122515
122610
  if (stream.lost()) return;
122516
122611
  const boardStopped = await confirmFlowStopped(ws, job, deps);
122517
- const evidence = job.handoff?.action === "continue" || job.handoff?.action === "restart" ? progressEvidence(job, ws.cwd) : null;
122518
- const proof = boardStopped && await stream.confirmed() ? { processesStopped: true, ...evidence ? { evidence } : {} } : {};
122612
+ const evidence2 = job.handoff?.action === "continue" || job.handoff?.action === "restart" ? progressEvidence(job, ws.cwd) : null;
122613
+ const proof = boardStopped && await stream.confirmed() ? { processesStopped: true, ...evidence2 ? { evidence: evidence2 } : {} } : {};
122519
122614
  if (ended3.ok) complete("done", { ...ended3.report, ...proof });
122520
122615
  if (stopped3) return finishClaimed("stopped", "", proof);
122521
122616
  if (!ended3.ok) return finishClaimed("failed", ended3.reason, proof);
@@ -122542,7 +122637,7 @@ ${prompt}` : prompt;
122542
122637
  child.stderr.on("data", (chunk) => stream.out(quietLines(plan3, chunk)));
122543
122638
  const spawned = new Promise((resolve2) => child.on("error", (e2) => resolve2(e2.message)));
122544
122639
  const end = await Promise.race([
122545
- converse(child, remember, false),
122640
+ converse(child, remember, false, reply ? checkpoint.retry.since + CONVERSATION_MS.prepare : void 0),
122546
122641
  spawned.then((error) => ({ ok: false, error })),
122547
122642
  // Killed, the turn ends with what it said so far; one that never does is not waited on.
122548
122643
  stream.whenAsked.then(() => wait2(KILL_GRACE_MS * 2)).then(() => ({ ok: true }))
@@ -122576,8 +122671,13 @@ ${prompt}` : prompt;
122576
122671
  persist();
122577
122672
  }
122578
122673
  if (await retry2(end.ok ? void 0 : end.error)) return;
122674
+ await evidence;
122579
122675
  const stopped3 = await stopReply(id, deps.stopMs);
122580
122676
  stop(child);
122677
+ if (stream.asked() && (!stopped3 || !await stream.confirmed())) {
122678
+ await stream.end();
122679
+ return;
122680
+ }
122581
122681
  const ok = end.ok || stream.asked();
122582
122682
  const unsafe2 = reply && !ok && (!stopped3 || !replayable(checkpoint) && !resumable(checkpoint));
122583
122683
  const said2 = {
@@ -122681,6 +122781,10 @@ ${plan2.renderer.failure?.() ?? ""}`)) && (checkpoint.retry?.attempt ?? 1) < 3 &
122681
122781
  }
122682
122782
  if (await retry2(rawFailure)) return;
122683
122783
  const stopped2 = await stopReply(id, deps.stopMs);
122784
+ if (stream.asked() && (!stopped2 || !await stream.confirmed())) {
122785
+ await stream.end();
122786
+ return;
122787
+ }
122684
122788
  const unsafe = reply && !!rawFailure && (!stopped2 || !replayable(checkpoint) && !resumable(checkpoint));
122685
122789
  const failure2 = stream.asked() ? void 0 : unsafe ? "recovery_unsafe" : replyReason(ended2.error ?? renderer.failure?.() ?? (ended2.code === 0 ? void 0 : `Exited with code ${ended2.code}.`), job);
122686
122790
  const said = {