wildcrane-runner 0.6.66 → 0.6.68

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.52 — built by runner/scripts/build.mjs. Do not edit.
2
+ // ai4kanban 0.11.54 — 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;
@@ -4205,7 +4205,7 @@ var init_package = __esm({
4205
4205
  "../cli/package.json"() {
4206
4206
  package_default = {
4207
4207
  name: "wildcrane",
4208
- version: "0.11.52",
4208
+ version: "0.11.54",
4209
4209
  akbContract: 15,
4210
4210
  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.",
4211
4211
  keywords: [
@@ -5365,7 +5365,7 @@ async function run(io, options, tasks) {
5365
5365
  if (failure) io.event?.({ kind: "error", data: { text: failure } });
5366
5366
  resolve2({ ok: !failure, error: failure, result: renderer.result(), replyParts: renderer.replyParts?.(), usage: combinedUsage, context, costUsd, costIncomplete: child.costIncomplete || cost === void 0 && child.costUsd !== void 0 || void 0 });
5367
5367
  };
5368
- const closed2 = () => end2("Codex closed the connection before all work and results finished.");
5368
+ const closed2 = () => end2("Codex connection closed before all work and results finished.");
5369
5369
  io.stdout.once("close", closed2);
5370
5370
  const update2 = (id, state, title = "") => {
5371
5371
  if (ended) return;
@@ -5451,6 +5451,10 @@ async function run(io, options, tasks) {
5451
5451
  if (ended || checking || active2) return;
5452
5452
  checking = true;
5453
5453
  try {
5454
+ if (io.completed?.()) {
5455
+ end2();
5456
+ return;
5457
+ }
5454
5458
  for (const key of tasks.running().filter((id) => id.startsWith("agent:"))) {
5455
5459
  const id = key.slice(6);
5456
5460
  let thread = obj2((await rpc.call("thread/read", { threadId: id, includeTurns: false })).thread);
@@ -17363,6 +17367,21 @@ function endAgent(child, mark, graceMs) {
17363
17367
  round(KILL_ROUNDS);
17364
17368
  });
17365
17369
  }
17370
+ function processesStopped(mark, root2) {
17371
+ try {
17372
+ if (WINDOWS3) {
17373
+ const list2 = procsOnWindows();
17374
+ if (!list2 || !root2) return false;
17375
+ const current = list2.procs.find((p) => p.pid === root2.pid);
17376
+ if (current && current.startedAt > root2.since) return false;
17377
+ return startedUnder(list2, root2.pid, root2.since).length === 0;
17378
+ }
17379
+ const entry = `${mark.name}=${mark.value}`;
17380
+ return (process.platform === "linux" ? markedInProc(entry, true, mark.since) : markedInPs(entry, root2 ? [root2.pid] : [])).length === 0;
17381
+ } catch {
17382
+ return false;
17383
+ }
17384
+ }
17366
17385
  var runMark, WINDOWS3, KILL_ROUND_MS, KILL_ROUNDS, LIST_PROCS;
17367
17386
  var init_stop = __esm({
17368
17387
  "../cli/src/lib/agent/stop.ts"() {
@@ -18816,18 +18835,6 @@ ${stage.artifact?.body ?? ""}`),
18816
18835
  `Write only the current work in your existing section. Submit it with: ${command} raw previews ${name} ${id} --submit --stage ${current.id}. Stop after success.`
18817
18836
  ].join("\n\n");
18818
18837
  }
18819
- function previewBlocker(id) {
18820
- const card = findCard(id);
18821
- if (!card) return null;
18822
- const meta = cardMeta(id);
18823
- const flow = studioFor(card.studio);
18824
- const required = cardStages(meta, flow).slice(0, cardStage(meta, flow)).flat();
18825
- for (const name of required) {
18826
- const progress = freezePreviewProgress(id, name);
18827
- if (progress && !previewReady(progress)) return `#${id}: ${name} / ${progress.currentStageId ?? "stage selection"} is unfinished. Review that preview before approving or implementing.`;
18828
- }
18829
- return null;
18830
- }
18831
18838
  function previewRun(id, name) {
18832
18839
  const run3 = readRuns().find((run4) => run4.sessionId === insideRun());
18833
18840
  if (!run3 || run3.status !== "running" || run3.action !== "spec" || run3.specAgent !== name || run3.cardId !== id) throw Error("Only the active preview agent can select or submit its stages.");
@@ -18936,8 +18943,6 @@ function approvalRequest(req) {
18936
18943
  const id = req.id;
18937
18944
  const card = id === void 0 ? null : findCard(id);
18938
18945
  if (!card) return { error: `task #${id} does not exist` };
18939
- const blocked = previewBlocker(card.id);
18940
- if (blocked) return { error: blocked };
18941
18946
  if (card.questions.length) return { error: `#${card.id} has open questions \u2014 answer them before approving it.` };
18942
18947
  if (readRuns().some((r) => r.status === "running" && r.cardId === card.id && holdsCard(r.action))) {
18943
18948
  return { error: `#${card.id} has a run in flight \u2014 approve once it ends.` };
@@ -18962,7 +18967,6 @@ function advancePhase(id) {
18962
18967
  var init_approve = __esm({
18963
18968
  "../cli/src/lib/agent/approve.ts"() {
18964
18969
  "use strict";
18965
- init_preview_progress();
18966
18970
  init_cards();
18967
18971
  init_frontmatter();
18968
18972
  init_read();
@@ -18980,10 +18984,6 @@ async function startRun(req) {
18980
18984
  const cardId2 = Number.isInteger(req.id) ? req.id : null;
18981
18985
  const short2 = studioRefusal(req) ?? await scheduledRefusal(req);
18982
18986
  if (short2) return short2;
18983
- if (cardId2 !== null && ["implement", "approve", "archive"].includes(req.action)) {
18984
- const blocked = previewBlocker(cardId2);
18985
- if (blocked) return { error: blocked };
18986
- }
18987
18987
  const delivery = req.action === "implement" ? deliveryFor(req) : void 0;
18988
18988
  if (delivery && req.session !== "new") {
18989
18989
  const previous = readRuns().filter((r) => r.deliveryId === delivery.deliveryId && r.action === "implement").reverse().sort((a, b) => b.startedAt - a.startedAt)[0];
@@ -19068,7 +19068,6 @@ async function startResume(id, options) {
19068
19068
  var init_start = __esm({
19069
19069
  "../cli/src/lib/agent/start.ts"() {
19070
19070
  "use strict";
19071
- init_preview_progress();
19072
19071
  init_approve();
19073
19072
  init_launch();
19074
19073
  init_pictures();
@@ -26327,8 +26326,13 @@ async function watchRun(sessionId, resume = startResume) {
26327
26326
  const eventsFile = fs84.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
26328
26327
  eventsFile.on("error", () => {
26329
26328
  });
26330
- const event2 = (e) => eventsFile.write(`${JSON.stringify(e)}
26329
+ const pendingOperations = /* @__PURE__ */ new Set();
26330
+ const event2 = (e) => {
26331
+ if (e.kind === "tool_call" && !["read", "search", "fetch"].includes(e.data.kind) && !["completed", "failed"].includes(e.data.status)) pendingOperations.add(e.data.toolCallId);
26332
+ if ((e.kind === "tool_call" || e.kind === "tool_call_update") && ["completed", "failed"].includes(e.data.status ?? "")) pendingOperations.delete(e.data.toolCallId);
26333
+ eventsFile.write(`${JSON.stringify(e)}
26331
26334
  `);
26335
+ };
26332
26336
  const log = {
26333
26337
  write(text4) {
26334
26338
  logFile.write(text4);
@@ -26428,12 +26432,16 @@ async function watchRun(sessionId, resume = startResume) {
26428
26432
  });
26429
26433
  child.stdin.write(stdinPrompt(prompt));
26430
26434
  }
26435
+ const completed = () => !!record.deliveryId && findDelivery(record.deliveryId)?.status === "finished";
26436
+ let finishCompletedTurn = () => {
26437
+ };
26431
26438
  let turnsSeen = 0;
26432
26439
  const afterTurn = () => {
26433
26440
  const turns = renderer?.turns?.() ?? [];
26434
26441
  if (turns.length === turnsSeen) return;
26435
26442
  turnsSeen = turns.length;
26436
- if (renderer && streamFinished(renderer)) endInput();
26443
+ if (completed()) finishCompletedTurn();
26444
+ else if (renderer && streamFinished(renderer)) endInput();
26437
26445
  };
26438
26446
  let sawResumeId = !!record.resumeId;
26439
26447
  let sawModel = false;
@@ -26493,6 +26501,7 @@ async function watchRun(sessionId, resume = startResume) {
26493
26501
  return await new Promise((resolve2) => {
26494
26502
  let done = false;
26495
26503
  let spoken;
26504
+ let crashed = false;
26496
26505
  let silent = false;
26497
26506
  let waited = false;
26498
26507
  let idle;
@@ -26514,6 +26523,18 @@ async function watchRun(sessionId, resume = startResume) {
26514
26523
  let asked = wanted;
26515
26524
  if (idle) clearTimeout(idle);
26516
26525
  await stopSubRuns(sessionId);
26526
+ const taskCompleted = completed();
26527
+ if (taskCompleted) {
26528
+ endChild();
26529
+ const mark = runMark(sessionId, agentStartedAt);
26530
+ const root2 = child.pid ? { pid: child.pid, since: agentStartedAt } : void 0;
26531
+ const until = Date.now() + STOP_GRACE_MS + STOP_CLOSE_MS;
26532
+ while (!processesStopped(mark, root2) && Date.now() < until) await sleep4(100);
26533
+ if (!processesStopped(mark, root2)) {
26534
+ spawnError = "Task completed, but its background processes could not be confirmed stopped.";
26535
+ code = 1;
26536
+ }
26537
+ }
26517
26538
  if (renderer) {
26518
26539
  append2(renderer.flush());
26519
26540
  drainEvents();
@@ -26525,7 +26546,10 @@ async function watchRun(sessionId, resume = startResume) {
26525
26546
  if (errRest) log.write(errRest);
26526
26547
  const endedAt = Date.now();
26527
26548
  const blocker = peekRun(sessionId)?.blocker;
26528
- let failure = renderer?.failure?.() ?? (renderer?.background?.() ? "The agent exited with unfinished background tasks." : void 0);
26549
+ let failure = renderer?.failure?.() ?? (!taskCompleted && renderer?.background?.() ? "The agent exited with unfinished background tasks." : void 0);
26550
+ if (!asked && pendingOperations.size > 0 && (code !== 0 || spoken?.ok === false)) {
26551
+ failure = `${failure ?? spoken?.error ?? "Agent exited."} Operation results are unconfirmed; automatic recovery was skipped.`;
26552
+ }
26529
26553
  const unfinished = blocker || failure;
26530
26554
  const result = spoken ? spoken.result : renderer?.result();
26531
26555
  const held4 = peekRun(sessionId) ?? record;
@@ -26533,8 +26557,19 @@ async function watchRun(sessionId, resume = startResume) {
26533
26557
  const said2 = failure ?? spoken?.error;
26534
26558
  const offStream = renderer?.offStream?.();
26535
26559
  const quiet = silent && !asked && !blocker && !sub && !!resumeSessionId(held4);
26536
- const blip = quiet ? { reason: waited ? backgroundWaitMessage(BACKGROUND_WAIT.minutes) : silenceSaid(silenceFor) } : ours || sub || code === 0 && !said2 || !resumeSessionId(held4) ? void 0 : active2.transient?.({ failure: said2, result, offStream });
26537
- const again = blip ? planRetry2(held4.retry, blip, held4.startedAt, Date.now(), Math.random, !quiet) : null;
26560
+ let blip = quiet ? { reason: waited ? backgroundWaitMessage(BACKGROUND_WAIT.minutes) : silenceSaid(silenceFor) } : ours || sub || pendingOperations.size > 0 || code === 0 && !said2 || !resumeSessionId(held4) ? void 0 : active2.transient?.({ failure: said2, result, offStream }) ?? (crashed && !said2 ? { reason: `Agent process exited unexpectedly (${child.signalCode}).` } : void 0);
26561
+ if (blip) {
26562
+ const mark = runMark(sessionId, agentStartedAt);
26563
+ const root2 = child.pid ? { pid: child.pid, since: agentStartedAt } : void 0;
26564
+ const until = Date.now() + STOP_GRACE_MS + STOP_CLOSE_MS;
26565
+ while (!processesStopped(mark, root2) && Date.now() < until) await sleep4(100);
26566
+ if (!processesStopped(mark, root2)) {
26567
+ blip = void 0;
26568
+ failure = "Previous execution could not be confirmed stopped; existing results were preserved.";
26569
+ }
26570
+ }
26571
+ const serviceClosed = said2 === "Codex connection closed before all work and results finished.";
26572
+ const again = blip ? planRetry2(held4.retry, blip, serviceClosed || crashed ? Date.now() : held4.startedAt, Date.now(), Math.random, !quiet) : null;
26538
26573
  if (again) {
26539
26574
  log.write(`
26540
26575
  [board] ${retryLine(again)}
@@ -26731,6 +26766,7 @@ Cannot resume board repair: ${next.error}`;
26731
26766
  };
26732
26767
  let ending = false;
26733
26768
  const endChild = () => {
26769
+ if (ending) return;
26734
26770
  ending = true;
26735
26771
  try {
26736
26772
  child.stdin?.end();
@@ -26738,6 +26774,10 @@ Cannot resume board repair: ${next.error}`;
26738
26774
  }
26739
26775
  endAgent(child, runMark(sessionId), STOP_GRACE_MS);
26740
26776
  };
26777
+ finishCompletedTurn = () => {
26778
+ endChild();
26779
+ void finish(0, false);
26780
+ };
26741
26781
  const giveUp = (asked) => {
26742
26782
  endChild();
26743
26783
  after(STOP_GRACE_MS + STOP_CLOSE_MS, () => {
@@ -26804,15 +26844,18 @@ Cannot resume board repair: ${next.error}`;
26804
26844
  gotResumeId: (id, restarted) => gotResumeId(id, restarted),
26805
26845
  gotModel: (model) => gotModel(model),
26806
26846
  event: event2,
26807
- gotContext
26847
+ gotContext,
26848
+ completed
26808
26849
  }).then((end2) => {
26850
+ if (done) return;
26809
26851
  spoken = end2;
26810
26852
  endChild();
26811
26853
  void finish(end2.ok ? 0 : 1, peekRun(sessionId)?.stopping === true || stopped2);
26812
26854
  });
26813
26855
  }
26814
26856
  }
26815
- child.once("exit", () => {
26857
+ child.once("exit", (_code, signal2) => {
26858
+ crashed = !ending && !!signal2 && ["SIGKILL", "SIGTERM", "SIGSEGV", "SIGABRT", "SIGBUS", "SIGILL"].includes(signal2);
26816
26859
  if (!ending) killMarked(runMark(sessionId), child.pid ? { pid: child.pid, since: agentStartedAt } : void 0);
26817
26860
  });
26818
26861
  child.on("close", (code) => void finish(code, peekRun(sessionId)?.stopping === true || stopped2));
@@ -26889,6 +26932,7 @@ var init_watch = __esm({
26889
26932
  init_command();
26890
26933
  init_preview_progress();
26891
26934
  init_progress();
26935
+ init_deliveries();
26892
26936
  init_paths();
26893
26937
  init_reconcile();
26894
26938
  init_spec_contract();
@@ -26929,10 +26973,6 @@ import path85 from "node:path";
26929
26973
  async function cmdStartRun(action, args2, opts, program2 = "akb") {
26930
26974
  if (action === "approve" && (opts.preview || opts.previewStage || opts.previewVersion || opts.definitionRevision)) return confirmLocalPreview(Number(args2[0]), opts);
26931
26975
  const { req, follow: follow2, print } = readRequest(action, args2, opts);
26932
- if (Number.isInteger(req.id) && ["approve", "implement", "archive"].includes(action)) {
26933
- const blocked = previewBlocker(req.id);
26934
- if (blocked) die(blocked, { kind: "preview-unfinished" });
26935
- }
26936
26976
  if (!print && (action === "approve" || action === "implement")) {
26937
26977
  const deferred = await approveAfterReply(String(req.id), req.notes);
26938
26978
  if (deferred) return deferred;
@@ -27432,7 +27472,6 @@ var init_run = __esm({
27432
27472
  "../cli/src/commands/run.ts"() {
27433
27473
  "use strict";
27434
27474
  init_preview_confirm();
27435
- init_preview_progress();
27436
27475
  init_progress();
27437
27476
  init_complete();
27438
27477
  init_answers();
@@ -1 +1 @@
1
- {"name":"wildcrane","version":"0.11.52","akbContract":15,"type":"module","private":true}
1
+ {"name":"wildcrane","version":"0.11.54","akbContract":15,"type":"module","private":true}
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.66 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.68 — 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;