wildcrane-runner 0.6.92 → 0.6.93

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.74 — built by runner/scripts/build.mjs. Do not edit.
2
+ // ai4kanban 0.11.75 — 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;
@@ -58,6 +58,11 @@ function insideRun() {
58
58
  function runEnv(env2, value) {
59
59
  return { ...env2, [RUN_ENV]: value };
60
60
  }
61
+ function taskReviewContext() {
62
+ const { AI4KANBAN_TASK_REVIEW: review, AI4KANBAN_REVIEW_STAGES: assigned } = process.env;
63
+ if (!review) return void 0;
64
+ return { review: JSON.parse(review), assigned: assigned ? JSON.parse(assigned) : void 0 };
65
+ }
61
66
  var RUN_ENV, SCHEDULED_AGENTS_ENV, SESSION_COST_ENV, STOP_ENV, SESSION_VARS;
62
67
  var init_env = __esm({
63
68
  "../cli/src/lib/agent/env.ts"() {
@@ -20851,11 +20856,49 @@ function parseReviewPlan(value, previews) {
20851
20856
  function readReviewPlan(plan) {
20852
20857
  return plan?.map(({ id: id2, after: after2, previews }) => ({ id: id2, after: after2, previews })) ?? null;
20853
20858
  }
20859
+ function reviewAuthorization(review, assigned, dispatchRevision) {
20860
+ if (review.pending_plan) return { kind: "pending" };
20861
+ const states2 = new Map(review.stages.map((stage) => [stage.id, stage]));
20862
+ const nodes = (review.plan ?? []).filter((node2) => {
20863
+ const stage = states2.get(node2.id);
20864
+ if (!stage || assigned && !assigned.includes(node2.id)) return false;
20865
+ return stage.status === "running" || stage.status === "available" && (dispatchRevision === void 0 || stage.revision <= dispatchRevision);
20866
+ });
20867
+ if (assigned?.some((id2) => !nodes.some((node2) => node2.id === id2))) return { kind: "changed" };
20868
+ if (review.plan === null) return { kind: "plan" };
20869
+ if (review.plan.length === 0) return { kind: "unreviewed" };
20870
+ if (nodes.length) return { kind: "stages", nodes };
20871
+ if (review.plan.every((node2) => states2.get(node2.id)?.status === "approved")) return { kind: "delivery" };
20872
+ return { kind: "waiting" };
20873
+ }
20874
+ function reviewAllows(authorization, action) {
20875
+ return action === "refine" ? authorization.kind === "plan" || authorization.kind === "stages" : authorization.kind === "unreviewed" || authorization.kind === "delivery";
20876
+ }
20877
+ function reviewInstruction(authorization) {
20878
+ switch (authorization.kind) {
20879
+ case "plan":
20880
+ return "Planning only. Propose a review plan; wait for explicit plan approval.";
20881
+ case "pending":
20882
+ return "Wait for the proposed plan decision. Do not start new stages.";
20883
+ case "unreviewed":
20884
+ return "No extra review. Complete the authorized work and Studio delivery checks.";
20885
+ case "stages":
20886
+ return [
20887
+ "Work only on these unlocked stages: " + authorization.nodes.map((node2) => node2.id).join(", "),
20888
+ ...authorization.nodes.map((node2) => `- ${node2.id}: ${node2.previews.length ? node2.previews.join(", ") : "card body"}`)
20889
+ ].join("\n");
20890
+ case "delivery":
20891
+ return "Stages complete. Follow Studio delivery checks.";
20892
+ case "changed":
20893
+ return "Review authorization changed. Read the task again.";
20894
+ case "waiting":
20895
+ return "Wait for review. Do not execute locked stages.";
20896
+ }
20897
+ }
20854
20898
  function reviewBoundary(review, assigned) {
20855
- const allowed = review.pending_plan ? [] : review.stages.filter((s) => (s.status === "available" || s.status === "running") && (!assigned || assigned.includes(s.id)));
20856
20899
  return [
20857
20900
  "Task review: " + JSON.stringify(review),
20858
- review.plan === null ? "Planning only. Propose a review plan; wait for explicit plan approval." : review.pending_plan ? "Wait for the proposed plan decision. Do not start new stages." : !review.plan.length ? "No extra review. Complete the authorized work and Studio delivery checks." : allowed.length ? "Work only on these unlocked stages: " + allowed.map((s) => s.id).join(", ") : review.stages.every((s) => s.status === "approved") ? "Stages complete. Follow Studio delivery checks." : "Wait for review. Do not execute locked stages.",
20901
+ reviewInstruction(reviewAuthorization(review, assigned)),
20859
20902
  "Read akb task review before reporting running/done with its revision. Sync content and assets before done. Revise a stage before changing its approved output. Questions and plan approval never approve outputs."
20860
20903
  ].join("\n");
20861
20904
  }
@@ -41771,8 +41814,8 @@ var init_package = __esm({
41771
41814
  "../cli/package.json"() {
41772
41815
  package_default = {
41773
41816
  name: "wildcrane",
41774
- version: "0.11.74",
41775
- akbContract: 21,
41817
+ version: "0.11.75",
41818
+ akbContract: 22,
41776
41819
  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.",
41777
41820
  keywords: [
41778
41821
  "kanban",
@@ -63437,18 +63480,15 @@ function refinementStep(card) {
63437
63480
  function refinementRequest(req) {
63438
63481
  const card = req.id === void 0 ? null : currentCard(req.id);
63439
63482
  if (!card) return { error: `task #${req.id} does not exist` };
63440
- const context = process.env.AI4KANBAN_TASK_REVIEW;
63441
- const review = context ? JSON.parse(context) : void 0;
63442
- const assigned = process.env.AI4KANBAN_REVIEW_STAGES ? JSON.parse(process.env.AI4KANBAN_REVIEW_STAGES) : void 0;
63443
- const authorized = review && !review.pending_plan && (review.plan === null || review.stages.some((s) => ["available", "running"].includes(s.status) && (!assigned || assigned.includes(s.id))));
63444
- const step = review ? authorized && !card.questions.some((q) => q.options?.length) ? "clarify" : "done" : refinementStep(card);
63445
- if (step === "done") {
63483
+ const context = taskReviewContext();
63484
+ const canStart = context ? reviewAllows(reviewAuthorization(context.review, context.assigned), "refine") && !card.questions.some((q) => q.options?.length) : refinementStep(card) === "clarify";
63485
+ if (!canStart) {
63446
63486
  const waiting = card.questions.length > 0 && canRefine({ ...card, questions: [] });
63447
63487
  return {
63448
63488
  error: waiting ? `#${card.id} is waiting for the user to answer its open questions, so there is nothing to refine yet \u2014 the board refines it on its own once they are answered.` : `a refine would not move #${card.id}`
63449
63489
  };
63450
63490
  }
63451
- return { action: step, id: card.id, title: card.title, notes: req.notes, refineRound: 1, ...req.carry ? { carry: req.carry } : {} };
63491
+ return { action: "clarify", id: card.id, title: card.title, notes: req.notes, refineRound: 1, ...req.carry ? { carry: req.carry } : {} };
63452
63492
  }
63453
63493
  async function startRefinement(req) {
63454
63494
  const next = refinementRequest(req);
@@ -63514,6 +63554,8 @@ var init_refine2 = __esm({
63514
63554
  "use strict";
63515
63555
  init_read();
63516
63556
  init_rules();
63557
+ init_review_plan();
63558
+ init_env();
63517
63559
  init_start();
63518
63560
  init_stage_end();
63519
63561
  init_stages();
@@ -63703,7 +63745,8 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
63703
63745
  `);
63704
63746
  const basePrompt = record2.resumedFrom ? spec.prompt || resumePrompt(record2.deliveryId, record2.action) : spec.prompt;
63705
63747
  const recoveryPrompt = record2.harness === "antigravity" && record2.resumedFrom ? "First verify existing progress and operation results. Preserve user decisions and completed work; do not repeat completed operations. Check actual state before continuing any operation whose result is uncertain." : "";
63706
- const boundary = process.env.AI4KANBAN_TASK_REVIEW ? reviewBoundary(JSON.parse(process.env.AI4KANBAN_TASK_REVIEW), process.env.AI4KANBAN_REVIEW_STAGES ? JSON.parse(process.env.AI4KANBAN_REVIEW_STAGES) : void 0) : "";
63748
+ const reviewContext = taskReviewContext();
63749
+ const boundary = reviewContext ? reviewBoundary(reviewContext.review, reviewContext.assigned) : "";
63707
63750
  const prompt = [process.env.AI4KANBAN_SYNC_DIAGNOSTIC ? syncRepairPrompt(process.env.AI4KANBAN_SYNC_DIAGNOSTIC) : "", record2.retry ? `Previous execution failed: ${record2.retry.reason}. Check existing results before continuing; do not repeat completed operations.` : "", conflictPrompt(KANBAN), boundary, basePrompt, recoveryPrompt, discardedCardsPrompt(record2.discardedCards)].filter(Boolean).join("\n\n");
63708
63751
  const before = markBoard();
63709
63752
  const takes = active3.images;
@@ -64186,6 +64229,7 @@ var init_watch = __esm({
64186
64229
  "../cli/src/lib/agent/watch.ts"() {
64187
64230
  "use strict";
64188
64231
  init_review_plan();
64232
+ init_env();
64189
64233
  init_connection_process();
64190
64234
  init_deliveries();
64191
64235
  init_board_conflicts();
@@ -64673,11 +64717,21 @@ function deliveryOutcome(deliveryId) {
64673
64717
  id: deliveryId,
64674
64718
  status: delivery.status,
64675
64719
  line,
64720
+ ...delivery.status === "cancelled" ? {
64721
+ ending: { kind: delivery.steps.some((s) => s.step === "discarded") ? "discarded" : "stopped" }
64722
+ } : {},
64676
64723
  ...commit ? { commit, ...delivery.targetBranch ? { branch: delivery.targetBranch } : {} } : {}
64677
64724
  };
64678
64725
  }
64679
64726
  const state = deliveryState(delivery, delivery.cardId === null ? 0 : openQuestions(delivery.cardId));
64680
- return { id: deliveryId, status: delivery.status, stage: state.stage, line: state.line };
64727
+ const reason = delivery.review?.stopped?.why;
64728
+ return {
64729
+ id: deliveryId,
64730
+ status: delivery.status,
64731
+ stage: state.stage,
64732
+ line: state.line,
64733
+ ...reason ? { ending: { kind: "blocked", reason } } : {}
64734
+ };
64681
64735
  }
64682
64736
  function runLine(r, program2 = "akb", indent2 = "") {
64683
64737
  const sub = r.action === "sub";
@@ -1 +1 @@
1
- {"name":"wildcrane","version":"0.11.74","akbContract":21,"type":"module","private":true}
1
+ {"name":"wildcrane","version":"0.11.75","akbContract":22,"type":"module","private":true}
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -145846,11 +145846,49 @@ var reviewPlanSchema = external_exports.array(reviewNodeSchema).max(50).superRef
145846
145846
  function readReviewPlan(plan2) {
145847
145847
  return plan2?.map(({ id: id2, after, previews }) => ({ id: id2, after, previews })) ?? null;
145848
145848
  }
145849
+ function reviewAuthorization(review, assigned, dispatchRevision) {
145850
+ if (review.pending_plan) return { kind: "pending" };
145851
+ const states = new Map(review.stages.map((stage) => [stage.id, stage]));
145852
+ const nodes = (review.plan ?? []).filter((node2) => {
145853
+ const stage = states.get(node2.id);
145854
+ if (!stage || assigned && !assigned.includes(node2.id)) return false;
145855
+ return stage.status === "running" || stage.status === "available" && (dispatchRevision === void 0 || stage.revision <= dispatchRevision);
145856
+ });
145857
+ if (assigned?.some((id2) => !nodes.some((node2) => node2.id === id2))) return { kind: "changed" };
145858
+ if (review.plan === null) return { kind: "plan" };
145859
+ if (review.plan.length === 0) return { kind: "unreviewed" };
145860
+ if (nodes.length) return { kind: "stages", nodes };
145861
+ if (review.plan.every((node2) => states.get(node2.id)?.status === "approved")) return { kind: "delivery" };
145862
+ return { kind: "waiting" };
145863
+ }
145864
+ function reviewAllows(authorization, action) {
145865
+ return action === "refine" ? authorization.kind === "plan" || authorization.kind === "stages" : authorization.kind === "unreviewed" || authorization.kind === "delivery";
145866
+ }
145867
+ function reviewInstruction(authorization) {
145868
+ switch (authorization.kind) {
145869
+ case "plan":
145870
+ return "Planning only. Propose a review plan; wait for explicit plan approval.";
145871
+ case "pending":
145872
+ return "Wait for the proposed plan decision. Do not start new stages.";
145873
+ case "unreviewed":
145874
+ return "No extra review. Complete the authorized work and Studio delivery checks.";
145875
+ case "stages":
145876
+ return [
145877
+ "Work only on these unlocked stages: " + authorization.nodes.map((node2) => node2.id).join(", "),
145878
+ ...authorization.nodes.map((node2) => `- ${node2.id}: ${node2.previews.length ? node2.previews.join(", ") : "card body"}`)
145879
+ ].join("\n");
145880
+ case "delivery":
145881
+ return "Stages complete. Follow Studio delivery checks.";
145882
+ case "changed":
145883
+ return "Review authorization changed. Read the task again.";
145884
+ case "waiting":
145885
+ return "Wait for review. Do not execute locked stages.";
145886
+ }
145887
+ }
145849
145888
  function reviewBoundary(review, assigned) {
145850
- const allowed = review.pending_plan ? [] : review.stages.filter((s) => (s.status === "available" || s.status === "running") && (!assigned || assigned.includes(s.id)));
145851
145889
  return [
145852
145890
  "Task review: " + JSON.stringify(review),
145853
- review.plan === null ? "Planning only. Propose a review plan; wait for explicit plan approval." : review.pending_plan ? "Wait for the proposed plan decision. Do not start new stages." : !review.plan.length ? "No extra review. Complete the authorized work and Studio delivery checks." : allowed.length ? "Work only on these unlocked stages: " + allowed.map((s) => s.id).join(", ") : review.stages.every((s) => s.status === "approved") ? "Stages complete. Follow Studio delivery checks." : "Wait for review. Do not execute locked stages.",
145891
+ reviewInstruction(reviewAuthorization(review, assigned)),
145854
145892
  "Read akb task review before reporting running/done with its revision. Sync content and assets before done. Revise a stage before changing its approved output. Questions and plan approval never approve outputs."
145855
145893
  ].join("\n");
145856
145894
  }
@@ -146288,8 +146326,8 @@ async function studioSnapshot(workspace, catalog, list3) {
146288
146326
  }
146289
146327
 
146290
146328
  // src/protocol.ts
146291
- var AKB_VERSION = true ? "0.11.74" : "0.0.0";
146292
- var AKB_CONTRACT = true ? 21 : 0;
146329
+ var AKB_VERSION = true ? "0.11.75" : "0.0.0";
146330
+ var AKB_CONTRACT = true ? 22 : 0;
146293
146331
 
146294
146332
  // src/secrets.ts
146295
146333
  import fs9 from "node:fs";
@@ -149051,8 +149089,8 @@ function createTail(log) {
149051
149089
  // ../cli/package.json
149052
149090
  var package_default = {
149053
149091
  name: "wildcrane",
149054
- version: "0.11.74",
149055
- akbContract: 21,
149092
+ version: "0.11.75",
149093
+ akbContract: 22,
149056
149094
  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.",
149057
149095
  keywords: [
149058
149096
  "kanban",
@@ -156235,10 +156273,10 @@ function runtimeCosts(runs, job) {
156235
156273
  }
156236
156274
  return [...out.values()];
156237
156275
  }
156238
- function reviewOf2(file3) {
156276
+ function reviewOf2(file3, questionsOnly = false) {
156239
156277
  try {
156240
156278
  const meta3 = parseFrontmatter(fs38.readFileSync(file3, "utf8")).meta;
156241
- return meta3 ? reviewOf(meta3) : null;
156279
+ return meta3 && (!questionsOnly || meta3.questions?.length) ? reviewOf(meta3) : null;
156242
156280
  } catch {
156243
156281
  return null;
156244
156282
  }
@@ -156283,21 +156321,6 @@ async function stopRuns(akb, ws, id2, since, ms) {
156283
156321
  }
156284
156322
  var working = /* @__PURE__ */ new Map();
156285
156323
  var workKey = (ws, id2) => `${ws.board}#${id2}`;
156286
- function deliveryEnding(ws, id2, asked = false) {
156287
- if (!id2) return null;
156288
- let held5;
156289
- try {
156290
- held5 = JSON.parse(fs38.readFileSync(path42.join(ws.board, "deliveries", `${path42.basename(id2)}.json`), "utf8"));
156291
- } catch {
156292
- return null;
156293
- }
156294
- const stopped2 = held5.review?.stopped;
156295
- if (held5.status === "cancelled") {
156296
- return held5.steps?.some((s) => s.step === "discarded") ? { ok: false, reason: "The build was discarded." } : { ok: false, reason: "", stopped: true };
156297
- }
156298
- if (held5.status === "active" && stopped2?.why) return { ok: false, reason: reasonOf(stopped2.why) ?? stopped2.why };
156299
- return null;
156300
- }
156301
156324
  function checkoutsOf(ws, id2) {
156302
156325
  const dir = path42.join(ws.board, "deliveries");
156303
156326
  let names2;
@@ -156369,15 +156392,6 @@ function boardAkb(job, ws, deps, io, task) {
156369
156392
  return async (args2, show = false, env2) => {
156370
156393
  const refused = (last) => ({ code: 1, out: "", last });
156371
156394
  if (stopping(io)) return refused("Task preparation stopped.");
156372
- if (show && job.taskReview && job.task && job.flow) {
156373
- const current2 = await deps.api.readTask(job.task);
156374
- if (!current2.ok) return refused(current2.error);
156375
- const review = current2.value.review;
156376
- if (!review || review.pending_plan || ["stopped", "done", "cancelled"].includes(current2.value.status ?? "")) return refused("This execution no longer has review authorization.");
156377
- if (job.flow.review_stages?.some((id2) => !review.stages.some((s) => s.id === id2 && ["available", "running"].includes(s.status)))) return refused("Review authorization changed. Read the task again.");
156378
- if (args2.includes("implement") && (review.plan === null || review.stages.some((s) => s.status !== "approved"))) return refused("Finish the agreed review stages before delivery.");
156379
- job.taskReview = review;
156380
- }
156381
156395
  const at2 = args2.includes("--") ? args2.indexOf("--") : args2.length;
156382
156396
  const full = [...args2.slice(0, at2), "--board", ws.board, ...args2.slice(at2)];
156383
156397
  const log = show ? logLines(io.show, io.event) : void 0;
@@ -156470,7 +156484,7 @@ async function runReview(job, ws, tasks, deps, io) {
156470
156484
  const runs = answerOf2(await akb(["raw", "run", "list", "--all", "--json"]))?.runs ?? [];
156471
156485
  return { ok: true, report: { ...answer?.result?.trim() ? { reply: answer.result.trim() } : {}, ...spentBy(runs.filter((r2) => (r2.startedAt ?? 0) >= since), job) } };
156472
156486
  }
156473
- async function reviewRejections(job, ws, deps, io) {
156487
+ async function reviewRejections(job, ws, deps, io, refreshReview) {
156474
156488
  const workspace = workspaceOf(ws);
156475
156489
  if (!workspace) return { runs: [] };
156476
156490
  const read5 = await deps.api.readRejections(workspace);
@@ -156483,6 +156497,8 @@ async function reviewRejections(job, ws, deps, io) {
156483
156497
  const scratch = fs38.mkdtempSync(path42.join(directory3, "rejection-review-"));
156484
156498
  try {
156485
156499
  const laid = layOut(scratch, read5.value);
156500
+ const denied = await refreshReview?.();
156501
+ if (denied) return { runs: [], failure: denied };
156486
156502
  const ran = await akb(["raw", "review-dismissals", "--follow", "--events", "--json"], true, { AI4KANBAN_REJECTION_INPUT: scratch });
156487
156503
  const runs = (answerOf2(await akb(["raw", "run", "list", "--all", "--json"]))?.runs ?? []).filter((r2) => (r2.startedAt ?? 0) >= since);
156488
156504
  if (stopping(io)) return { runs };
@@ -156492,8 +156508,8 @@ async function reviewRejections(job, ws, deps, io) {
156492
156508
  fs38.rmSync(scratch, { recursive: true, force: true });
156493
156509
  }
156494
156510
  }
156495
- async function learnRejections(job, ws, deps, io) {
156496
- const { runs, failure: failure2, laid } = await reviewRejections(job, ws, deps, io);
156511
+ async function learnRejections(job, ws, deps, io, refreshReview) {
156512
+ const { runs, failure: failure2, laid } = await reviewRejections(job, ws, deps, io, refreshReview);
156497
156513
  if (failure2) console.error(`runner: rejections not learned: ${failure2}`);
156498
156514
  if (laid && !stopping(io)) {
156499
156515
  const sent = await push(ws, { id: job.id, machineId: deps.machineId });
@@ -156573,10 +156589,34 @@ async function runFlow(job, ws, deps, io) {
156573
156589
  return ran.code === 0 && answer?.id ? { ok: true, value: answer.id } : { ok: false, error: answer?.error?.message ?? refusal2(ran), code: answer?.error?.kind };
156574
156590
  };
156575
156591
  if (flow.verb === "discard") return discardBuilds();
156592
+ const hasReview = !!job.taskReview || flow.review_stages !== void 0;
156593
+ const initial = job.taskReview && reviewAuthorization(job.taskReview, flow.review_stages);
156594
+ const skipPlan = initial ? initial.kind === "unreviewed" : flow.skip_plan;
156595
+ const verb = flow.verb === "create" ? skipPlan ? "implement" : "refine" : flow.verb;
156596
+ async function refreshReview() {
156597
+ if (!hasReview) return;
156598
+ const current2 = await deps.api.readTask(ws.task);
156599
+ if (!current2.ok) return current2.error;
156600
+ const review = current2.value.review;
156601
+ if (!review || ["stopped", "done", "cancelled"].includes(current2.value.status ?? "")) {
156602
+ return "This execution no longer has review authorization.";
156603
+ }
156604
+ const authorization = reviewAuthorization(review, flow.review_stages, flow.review_revision);
156605
+ if (authorization.kind === "pending") return "This execution no longer has review authorization.";
156606
+ if (authorization.kind === "changed" || verb === "refine" && !reviewAllows(authorization, verb)) {
156607
+ return "Review authorization changed. Read the task again.";
156608
+ }
156609
+ if (verb === "implement" && !reviewAllows(authorization, verb)) return "Finish the agreed review stages before delivery.";
156610
+ job.taskReview = review;
156611
+ }
156612
+ async function launch2(...args2) {
156613
+ const denied = await refreshReview();
156614
+ return denied ? { code: 1, out: "", last: denied, reviewRefused: denied } : akb(...args2);
156615
+ }
156576
156616
  const failed = await setUp(job, ws, deps, io);
156577
156617
  if (failed) return fail(failed);
156578
156618
  let id2 = akbCardOf(ws);
156579
- const learned = flow.verb === "create" && !id2 && !flow.skip_plan ? await learnRejections(job, ws, deps, io) : [];
156619
+ const learned = flow.verb === "create" && !id2 && !skipPlan ? await learnRejections(job, ws, deps, io, refreshReview) : [];
156580
156620
  if (io.lost()) return fail("");
156581
156621
  if (flow.verb === "create" && !id2) {
156582
156622
  let said = { title: flow.title?.trim() ?? "", request: flow.text?.trim() ?? "" };
@@ -156636,7 +156676,7 @@ ${pictures(job, ws, ws.number)}`);
156636
156676
  }
156637
156677
  if (io.lost()) return fail("");
156638
156678
  const ended2 = await workOn(card);
156639
- if (ended2.ok && job.taskReview?.plan?.length === 0 && flow.verb === "create" && !ended2.report.review) ended2.report.deliveryCompleted = true;
156679
+ if (ended2.ok && flow.verb === "create" && verb === "implement" && job.taskReview && reviewAuthorization(job.taskReview).kind === "unreviewed" && !ended2.report.review) ended2.report.deliveryCompleted = true;
156640
156680
  return ended2;
156641
156681
  } finally {
156642
156682
  fs38.rmSync(path42.join(ws.board, ".sync", `${ws.task}.discussion`), { recursive: true, force: true });
@@ -156649,10 +156689,9 @@ ${pictures(job, ws, ws.number)}`);
156649
156689
  io.onStop(async () => {
156650
156690
  if (!await stopRuns(deps.akb, ws, id3, since, deps.stopMs)) throw new Error("\u672A\u80FD\u786E\u8BA4\u539F\u6267\u884C\u5DF2\u505C\u6B62\u3002");
156651
156691
  });
156652
- const verb = flow.verb === "create" ? job.taskReview ? job.taskReview.plan !== null && !job.taskReview.plan.length ? "implement" : "refine" : flow.skip_plan ? "implement" : "refine" : flow.verb;
156653
156692
  const text4 = flow.verb === "create" ? "" : (flow.text ?? "").trim();
156654
156693
  if (flow.resume && isArchived(ws, id3)) return { ok: true, report: { card: id3 } };
156655
- if (flow.resume && verb === "refine" && !job.taskReview) {
156694
+ if (flow.resume && verb === "refine" && !hasReview) {
156656
156695
  const review2 = reviewOf2(cardFile(ws));
156657
156696
  if (review2) return { ok: true, report: { card: id3, ...review2 === true ? {} : { review: review2 } } };
156658
156697
  }
@@ -156663,7 +156702,8 @@ ${pictures(job, ws, ws.number)}`);
156663
156702
  let continuation;
156664
156703
  let expectedDelivery;
156665
156704
  if (verb === "implement" && flow.resume) {
156666
- const restored = await akb(["raw", "delivery", "resume", String(id3), "--json"]);
156705
+ const restored = await launch2(["raw", "delivery", "resume", String(id3), "--json"]);
156706
+ if (restored.reviewRefused) return fail(restored.reviewRefused);
156667
156707
  const resumed = answerOf2(restored);
156668
156708
  if (io.lost()) return fail("");
156669
156709
  if (resumed?.landed) return { ok: true, report: { card: id3 } };
@@ -156682,7 +156722,8 @@ ${pictures(job, ws, ws.number)}`);
156682
156722
  }
156683
156723
  }
156684
156724
  } else if (verb === "implement" && text4) {
156685
- const resolved = await akb(["raw", "card", "resolve", String(id3), "--follow", "--events", "--json", "--", text4], true);
156725
+ const resolved = await launch2(["raw", "card", "resolve", String(id3), "--follow", "--events", "--json", "--", text4], true);
156726
+ if (resolved.reviewRefused) return fail(resolved.reviewRefused);
156686
156727
  if (io.lost()) return fail("");
156687
156728
  const file3 = findCard(ws.board, id3);
156688
156729
  rejected = !!file3 && path42.relative(ws.board, file3).split(path42.sep)[0] === ".archive" && parseFrontmatter(fs38.readFileSync(file3, "utf8")).meta?.rejected === true;
@@ -156692,20 +156733,23 @@ ${pictures(job, ws, ws.number)}`);
156692
156733
  const fresh = () => {
156693
156734
  const carry = carryArgs(verb);
156694
156735
  const costFrom = carry.includes("--session") && typeof job.resumeCostUsd === "number" ? { [SESSION_COST_ENV]: String(job.resumeCostUsd) } : void 0;
156695
- return akb(["raw", "card", verb, String(id3), "--follow", "--events", "--json", ...carry, ...note ? ["--", note] : []], true, costFrom);
156736
+ return launch2(["raw", "card", verb, String(id3), "--follow", "--events", "--json", ...carry, ...note ? ["--", note] : []], true, costFrom);
156696
156737
  };
156697
- ran ??= await (continuation ? akb([...continuation, "--follow", "--events", "--json"], true) : fresh());
156738
+ ran ??= await (continuation ? launch2([...continuation, "--follow", "--events", "--json"], true) : fresh());
156739
+ if (ran.reviewRefused) return fail(ran.reviewRefused);
156698
156740
  if (io.lost()) return fail("");
156699
156741
  const answer = answerOf2(ran);
156700
156742
  if (expectedDelivery && answer?.delivery?.id && answer.delivery.id !== expectedDelivery) {
156701
156743
  return fail("\u7EED\u8DD1\u8FD4\u56DE\u4E86\u5176\u4ED6\u4EA4\u4ED8\u7684\u7ED3\u679C\uFF0C\u539F\u4EA4\u4ED8\u4FDD\u6301\u672A\u5B8C\u6210\u3002");
156702
156744
  }
156703
- const asked = verb === "implement" && !rejected && asks(cardFile(ws));
156704
156745
  if (verb === "implement" && !rejected) {
156705
- const ending = deliveryEnding(ws, answer?.delivery?.id ?? answer?.error?.delivery?.id, asked);
156706
- if (ending) return ending;
156746
+ const ending = (answer?.delivery ?? answer?.error?.delivery)?.ending;
156747
+ if (ending?.kind === "stopped") return { ok: false, reason: "", stopped: true };
156748
+ if (ending?.kind === "discarded") return fail("The build was discarded.");
156749
+ if (ending?.kind === "blocked") return fail(ending.reason);
156707
156750
  }
156708
- const waiting = rejected ? null : reviewOf2(cardFile(ws));
156751
+ const asked = verb === "implement" && !rejected && asks(cardFile(ws));
156752
+ const waiting = rejected ? null : reviewOf2(cardFile(ws), hasReview);
156709
156753
  const review = waiting && waiting !== true ? waiting : void 0;
156710
156754
  if (!rejected && ran.code !== 0 && !(verb === "refine" && waiting) && !(answer?.error && asked)) {
156711
156755
  return fail(reasonOf(answer?.error?.message?.replace(/^run \S+ ended \w+: /, "")) ?? refusal2(ran));
@@ -156731,9 +156775,9 @@ ${pictures(job, ws, ws.number)}`);
156731
156775
  }
156732
156776
  return { ok: true, report: { card } };
156733
156777
  }
156734
- function carryArgs(verb) {
156778
+ function carryArgs(verb2) {
156735
156779
  if (flow.replan) return ["--new-session"];
156736
- if (!["refine", "resolve", "revise"].includes(verb)) return [];
156780
+ if (!["refine", "resolve", "revise"].includes(verb2)) return [];
156737
156781
  const transcript = writeTranscript(job, path42.join(ws.board, ".sync", `${ws.task}.discussion`));
156738
156782
  return [
156739
156783
  ...job.resume ? ["--session", job.resume, ...job.fork ? ["--fork"] : []] : [],
package/dist/launcher.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -41142,8 +41142,8 @@ function saveAlphaUpdates(value) {
41142
41142
  }
41143
41143
 
41144
41144
  // src/protocol.ts
41145
- var VERSION = true ? "0.6.92" : "0.0.0";
41146
- var AKB_VERSION = true ? "0.11.74" : "0.0.0";
41145
+ var VERSION = true ? "0.6.93" : "0.0.0";
41146
+ var AKB_VERSION = true ? "0.11.75" : "0.0.0";
41147
41147
  var EXIT_REFUSED = 10;
41148
41148
  var EXIT_OUTDATED = 11;
41149
41149
  var EXIT_UPDATE = 12;
@@ -62728,7 +62728,6 @@ function runOnce(candidate, options) {
62728
62728
  options.signal?.addEventListener("abort", onTerm, { once: true });
62729
62729
  if (options.signal?.aborted) onTerm();
62730
62730
  child.on("message", (message) => {
62731
- options.onMessage?.(message);
62732
62731
  if (message.type === "update-deferred") update3 = null;
62733
62732
  if (message.type === "reconnecting" && candidate.fresh && !connected && !timedOut) watchConnection();
62734
62733
  if (message.type === "waiting" && timer) {
@@ -62743,6 +62742,7 @@ function runOnce(candidate, options) {
62743
62742
  if (candidate.fresh || installed && !readState().good.includes(candidate.version)) markGood(candidate.version);
62744
62743
  if (candidate.fresh) status(t.updated(candidate.version));
62745
62744
  }
62745
+ options.onMessage?.(message);
62746
62746
  });
62747
62747
  let spawnError;
62748
62748
  child.once("error", (error62) => {
@@ -65177,8 +65177,8 @@ function createTail(log) {
65177
65177
  // ../cli/package.json
65178
65178
  var package_default = {
65179
65179
  name: "wildcrane",
65180
- version: "0.11.74",
65181
- akbContract: 21,
65180
+ version: "0.11.75",
65181
+ akbContract: 22,
65182
65182
  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.",
65183
65183
  keywords: [
65184
65184
  "kanban",
package/dist/plugin.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -107839,8 +107839,8 @@ function machineId() {
107839
107839
  var machineName = () => os3.hostname().replace(/\.local$/, "");
107840
107840
 
107841
107841
  // src/protocol.ts
107842
- var VERSION = true ? "0.6.92" : "0.0.0";
107843
- var AKB_VERSION = true ? "0.11.74" : "0.0.0";
107842
+ var VERSION = true ? "0.6.93" : "0.0.0";
107843
+ var AKB_VERSION = true ? "0.11.75" : "0.0.0";
107844
107844
  var EXIT_REFUSED = 10;
107845
107845
  var EXIT_OUTDATED = 11;
107846
107846
  var EXIT_UPDATE = 12;
@@ -109599,7 +109599,6 @@ function runOnce(candidate, options) {
109599
109599
  options.signal?.addEventListener("abort", onTerm, { once: true });
109600
109600
  if (options.signal?.aborted) onTerm();
109601
109601
  child.on("message", (message) => {
109602
- options.onMessage?.(message);
109603
109602
  if (message.type === "update-deferred") update3 = null;
109604
109603
  if (message.type === "reconnecting" && candidate.fresh && !connected && !timedOut) watchConnection();
109605
109604
  if (message.type === "waiting" && timer) {
@@ -109614,6 +109613,7 @@ function runOnce(candidate, options) {
109614
109613
  if (candidate.fresh || installed && !readState().good.includes(candidate.version)) markGood(candidate.version);
109615
109614
  if (candidate.fresh) status(t.updated(candidate.version));
109616
109615
  }
109616
+ options.onMessage?.(message);
109617
109617
  });
109618
109618
  let spawnError;
109619
109619
  child.once("error", (error63) => {
@@ -111767,8 +111767,8 @@ function createTail(log) {
111767
111767
  // ../cli/package.json
111768
111768
  var package_default = {
111769
111769
  name: "wildcrane",
111770
- version: "0.11.74",
111771
- akbContract: 21,
111770
+ version: "0.11.75",
111771
+ akbContract: 22,
111772
111772
  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.",
111773
111773
  keywords: [
111774
111774
  "kanban",
package/dist/runner.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -126428,9 +126428,9 @@ function status(line) {
126428
126428
  }
126429
126429
 
126430
126430
  // src/protocol.ts
126431
- var VERSION = true ? "0.6.92" : "0.0.0";
126432
- var AKB_VERSION = true ? "0.11.74" : "0.0.0";
126433
- var AKB_CONTRACT = true ? 21 : 0;
126431
+ var VERSION = true ? "0.6.93" : "0.0.0";
126432
+ var AKB_VERSION = true ? "0.11.75" : "0.0.0";
126433
+ var AKB_CONTRACT = true ? 22 : 0;
126434
126434
  var EXIT_REFUSED = 10;
126435
126435
  var EXIT_OUTDATED = 11;
126436
126436
  var EXIT_UPDATE = 12;
@@ -128783,8 +128783,8 @@ function createTail(log) {
128783
128783
  // ../cli/package.json
128784
128784
  var package_default = {
128785
128785
  name: "wildcrane",
128786
- version: "0.11.74",
128787
- akbContract: 21,
128786
+ version: "0.11.75",
128787
+ akbContract: 22,
128788
128788
  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.",
128789
128789
  keywords: [
128790
128790
  "kanban",
@@ -151763,11 +151763,49 @@ var reviewPlanSchema = external_exports.array(reviewNodeSchema).max(50).superRef
151763
151763
  function readReviewPlan(plan2) {
151764
151764
  return plan2?.map(({ id: id2, after, previews }) => ({ id: id2, after, previews })) ?? null;
151765
151765
  }
151766
+ function reviewAuthorization(review, assigned, dispatchRevision) {
151767
+ if (review.pending_plan) return { kind: "pending" };
151768
+ const states = new Map(review.stages.map((stage) => [stage.id, stage]));
151769
+ const nodes = (review.plan ?? []).filter((node2) => {
151770
+ const stage = states.get(node2.id);
151771
+ if (!stage || assigned && !assigned.includes(node2.id)) return false;
151772
+ return stage.status === "running" || stage.status === "available" && (dispatchRevision === void 0 || stage.revision <= dispatchRevision);
151773
+ });
151774
+ if (assigned?.some((id2) => !nodes.some((node2) => node2.id === id2))) return { kind: "changed" };
151775
+ if (review.plan === null) return { kind: "plan" };
151776
+ if (review.plan.length === 0) return { kind: "unreviewed" };
151777
+ if (nodes.length) return { kind: "stages", nodes };
151778
+ if (review.plan.every((node2) => states.get(node2.id)?.status === "approved")) return { kind: "delivery" };
151779
+ return { kind: "waiting" };
151780
+ }
151781
+ function reviewAllows(authorization, action) {
151782
+ return action === "refine" ? authorization.kind === "plan" || authorization.kind === "stages" : authorization.kind === "unreviewed" || authorization.kind === "delivery";
151783
+ }
151784
+ function reviewInstruction(authorization) {
151785
+ switch (authorization.kind) {
151786
+ case "plan":
151787
+ return "Planning only. Propose a review plan; wait for explicit plan approval.";
151788
+ case "pending":
151789
+ return "Wait for the proposed plan decision. Do not start new stages.";
151790
+ case "unreviewed":
151791
+ return "No extra review. Complete the authorized work and Studio delivery checks.";
151792
+ case "stages":
151793
+ return [
151794
+ "Work only on these unlocked stages: " + authorization.nodes.map((node2) => node2.id).join(", "),
151795
+ ...authorization.nodes.map((node2) => `- ${node2.id}: ${node2.previews.length ? node2.previews.join(", ") : "card body"}`)
151796
+ ].join("\n");
151797
+ case "delivery":
151798
+ return "Stages complete. Follow Studio delivery checks.";
151799
+ case "changed":
151800
+ return "Review authorization changed. Read the task again.";
151801
+ case "waiting":
151802
+ return "Wait for review. Do not execute locked stages.";
151803
+ }
151804
+ }
151766
151805
  function reviewBoundary(review, assigned) {
151767
- const allowed = review.pending_plan ? [] : review.stages.filter((s) => (s.status === "available" || s.status === "running") && (!assigned || assigned.includes(s.id)));
151768
151806
  return [
151769
151807
  "Task review: " + JSON.stringify(review),
151770
- review.plan === null ? "Planning only. Propose a review plan; wait for explicit plan approval." : review.pending_plan ? "Wait for the proposed plan decision. Do not start new stages." : !review.plan.length ? "No extra review. Complete the authorized work and Studio delivery checks." : allowed.length ? "Work only on these unlocked stages: " + allowed.map((s) => s.id).join(", ") : review.stages.every((s) => s.status === "approved") ? "Stages complete. Follow Studio delivery checks." : "Wait for review. Do not execute locked stages.",
151808
+ reviewInstruction(reviewAuthorization(review, assigned)),
151771
151809
  "Read akb task review before reporting running/done with its revision. Sync content and assets before done. Revise a stage before changing its approved output. Questions and plan approval never approve outputs."
151772
151810
  ].join("\n");
151773
151811
  }
@@ -158353,10 +158391,10 @@ function runtimeCosts(runs, job) {
158353
158391
  }
158354
158392
  return [...out.values()];
158355
158393
  }
158356
- function reviewOf2(file4) {
158394
+ function reviewOf2(file4, questionsOnly = false) {
158357
158395
  try {
158358
158396
  const meta3 = parseFrontmatter(fs45.readFileSync(file4, "utf8")).meta;
158359
- return meta3 ? reviewOf(meta3) : null;
158397
+ return meta3 && (!questionsOnly || meta3.questions?.length) ? reviewOf(meta3) : null;
158360
158398
  } catch {
158361
158399
  return null;
158362
158400
  }
@@ -158406,21 +158444,6 @@ async function stopLeftBehind(akb, ws, id2, ms) {
158406
158444
  throw new Error("\u672A\u80FD\u505C\u6B62\u4E0A\u6B21\u8FD0\u884C\uFF0C\u8BF7\u7B49\u5F85\u5176\u505C\u6B62\u540E\u7EED\u8DD1\u3002");
158407
158445
  }
158408
158446
  }
158409
- function deliveryEnding(ws, id2, asked = false) {
158410
- if (!id2) return null;
158411
- let held5;
158412
- try {
158413
- held5 = JSON.parse(fs45.readFileSync(path49.join(ws.board, "deliveries", `${path49.basename(id2)}.json`), "utf8"));
158414
- } catch {
158415
- return null;
158416
- }
158417
- const stopped2 = held5.review?.stopped;
158418
- if (held5.status === "cancelled") {
158419
- return held5.steps?.some((s) => s.step === "discarded") ? { ok: false, reason: "The build was discarded." } : { ok: false, reason: "", stopped: true };
158420
- }
158421
- if (held5.status === "active" && stopped2?.why) return { ok: false, reason: reasonOf(stopped2.why) ?? stopped2.why };
158422
- return null;
158423
- }
158424
158447
  function checkoutsOf(ws, id2) {
158425
158448
  const dir = path49.join(ws.board, "deliveries");
158426
158449
  let names2;
@@ -158492,15 +158515,6 @@ function boardAkb(job, ws, deps, io, task) {
158492
158515
  return async (args2, show = false, env2) => {
158493
158516
  const refused2 = (last2) => ({ code: 1, out: "", last: last2 });
158494
158517
  if (stopping(io)) return refused2("Task preparation stopped.");
158495
- if (show && job.taskReview && job.task && job.flow) {
158496
- const current2 = await deps.api.readTask(job.task);
158497
- if (!current2.ok) return refused2(current2.error);
158498
- const review = current2.value.review;
158499
- if (!review || review.pending_plan || ["stopped", "done", "cancelled"].includes(current2.value.status ?? "")) return refused2("This execution no longer has review authorization.");
158500
- if (job.flow.review_stages?.some((id2) => !review.stages.some((s) => s.id === id2 && ["available", "running"].includes(s.status)))) return refused2("Review authorization changed. Read the task again.");
158501
- if (args2.includes("implement") && (review.plan === null || review.stages.some((s) => s.status !== "approved"))) return refused2("Finish the agreed review stages before delivery.");
158502
- job.taskReview = review;
158503
- }
158504
158518
  const at2 = args2.includes("--") ? args2.indexOf("--") : args2.length;
158505
158519
  const full = [...args2.slice(0, at2), "--board", ws.board, ...args2.slice(at2)];
158506
158520
  const log = show ? logLines(io.show, io.event) : void 0;
@@ -158593,7 +158607,7 @@ async function runReview(job, ws, tasks, deps, io) {
158593
158607
  const runs = answerOf2(await akb(["raw", "run", "list", "--all", "--json"]))?.runs ?? [];
158594
158608
  return { ok: true, report: { ...answer?.result?.trim() ? { reply: answer.result.trim() } : {}, ...spentBy(runs.filter((r2) => (r2.startedAt ?? 0) >= since), job) } };
158595
158609
  }
158596
- async function reviewRejections(job, ws, deps, io) {
158610
+ async function reviewRejections(job, ws, deps, io, refreshReview) {
158597
158611
  const workspace = workspaceOf(ws);
158598
158612
  if (!workspace) return { runs: [] };
158599
158613
  const read6 = await deps.api.readRejections(workspace);
@@ -158606,6 +158620,8 @@ async function reviewRejections(job, ws, deps, io) {
158606
158620
  const scratch = fs45.mkdtempSync(path49.join(directory3, "rejection-review-"));
158607
158621
  try {
158608
158622
  const laid = layOut(scratch, read6.value);
158623
+ const denied = await refreshReview?.();
158624
+ if (denied) return { runs: [], failure: denied };
158609
158625
  const ran = await akb(["raw", "review-dismissals", "--follow", "--events", "--json"], true, { AI4KANBAN_REJECTION_INPUT: scratch });
158610
158626
  const runs = (answerOf2(await akb(["raw", "run", "list", "--all", "--json"]))?.runs ?? []).filter((r2) => (r2.startedAt ?? 0) >= since);
158611
158627
  if (stopping(io)) return { runs };
@@ -158615,8 +158631,8 @@ async function reviewRejections(job, ws, deps, io) {
158615
158631
  fs45.rmSync(scratch, { recursive: true, force: true });
158616
158632
  }
158617
158633
  }
158618
- async function learnRejections(job, ws, deps, io) {
158619
- const { runs, failure: failure3, laid } = await reviewRejections(job, ws, deps, io);
158634
+ async function learnRejections(job, ws, deps, io, refreshReview) {
158635
+ const { runs, failure: failure3, laid } = await reviewRejections(job, ws, deps, io, refreshReview);
158620
158636
  if (failure3) console.error(`runner: rejections not learned: ${failure3}`);
158621
158637
  if (laid && !stopping(io)) {
158622
158638
  const sent = await push(ws, { id: job.id, machineId: deps.machineId });
@@ -158696,10 +158712,34 @@ async function runFlow(job, ws, deps, io) {
158696
158712
  return ran.code === 0 && answer?.id ? { ok: true, value: answer.id } : { ok: false, error: answer?.error?.message ?? refusal3(ran), code: answer?.error?.kind };
158697
158713
  };
158698
158714
  if (flow.verb === "discard") return discardBuilds();
158715
+ const hasReview = !!job.taskReview || flow.review_stages !== void 0;
158716
+ const initial = job.taskReview && reviewAuthorization(job.taskReview, flow.review_stages);
158717
+ const skipPlan = initial ? initial.kind === "unreviewed" : flow.skip_plan;
158718
+ const verb = flow.verb === "create" ? skipPlan ? "implement" : "refine" : flow.verb;
158719
+ async function refreshReview() {
158720
+ if (!hasReview) return;
158721
+ const current2 = await deps.api.readTask(ws.task);
158722
+ if (!current2.ok) return current2.error;
158723
+ const review = current2.value.review;
158724
+ if (!review || ["stopped", "done", "cancelled"].includes(current2.value.status ?? "")) {
158725
+ return "This execution no longer has review authorization.";
158726
+ }
158727
+ const authorization = reviewAuthorization(review, flow.review_stages, flow.review_revision);
158728
+ if (authorization.kind === "pending") return "This execution no longer has review authorization.";
158729
+ if (authorization.kind === "changed" || verb === "refine" && !reviewAllows(authorization, verb)) {
158730
+ return "Review authorization changed. Read the task again.";
158731
+ }
158732
+ if (verb === "implement" && !reviewAllows(authorization, verb)) return "Finish the agreed review stages before delivery.";
158733
+ job.taskReview = review;
158734
+ }
158735
+ async function launch2(...args2) {
158736
+ const denied = await refreshReview();
158737
+ return denied ? { code: 1, out: "", last: denied, reviewRefused: denied } : akb(...args2);
158738
+ }
158699
158739
  const failed = await setUp(job, ws, deps, io);
158700
158740
  if (failed) return fail(failed);
158701
158741
  let id2 = akbCardOf(ws);
158702
- const learned = flow.verb === "create" && !id2 && !flow.skip_plan ? await learnRejections(job, ws, deps, io) : [];
158742
+ const learned = flow.verb === "create" && !id2 && !skipPlan ? await learnRejections(job, ws, deps, io, refreshReview) : [];
158703
158743
  if (io.lost()) return fail("");
158704
158744
  if (flow.verb === "create" && !id2) {
158705
158745
  let said = { title: flow.title?.trim() ?? "", request: flow.text?.trim() ?? "" };
@@ -158759,7 +158799,7 @@ ${pictures(job, ws, ws.number)}`);
158759
158799
  }
158760
158800
  if (io.lost()) return fail("");
158761
158801
  const ended2 = await workOn(card);
158762
- if (ended2.ok && job.taskReview?.plan?.length === 0 && flow.verb === "create" && !ended2.report.review) ended2.report.deliveryCompleted = true;
158802
+ if (ended2.ok && flow.verb === "create" && verb === "implement" && job.taskReview && reviewAuthorization(job.taskReview).kind === "unreviewed" && !ended2.report.review) ended2.report.deliveryCompleted = true;
158763
158803
  return ended2;
158764
158804
  } finally {
158765
158805
  fs45.rmSync(path49.join(ws.board, ".sync", `${ws.task}.discussion`), { recursive: true, force: true });
@@ -158772,10 +158812,9 @@ ${pictures(job, ws, ws.number)}`);
158772
158812
  io.onStop(async () => {
158773
158813
  if (!await stopRuns(deps.akb, ws, id3, since, deps.stopMs)) throw new Error("\u672A\u80FD\u786E\u8BA4\u539F\u6267\u884C\u5DF2\u505C\u6B62\u3002");
158774
158814
  });
158775
- const verb = flow.verb === "create" ? job.taskReview ? job.taskReview.plan !== null && !job.taskReview.plan.length ? "implement" : "refine" : flow.skip_plan ? "implement" : "refine" : flow.verb;
158776
158815
  const text4 = flow.verb === "create" ? "" : (flow.text ?? "").trim();
158777
158816
  if (flow.resume && isArchived(ws, id3)) return { ok: true, report: { card: id3 } };
158778
- if (flow.resume && verb === "refine" && !job.taskReview) {
158817
+ if (flow.resume && verb === "refine" && !hasReview) {
158779
158818
  const review2 = reviewOf2(cardFile(ws));
158780
158819
  if (review2) return { ok: true, report: { card: id3, ...review2 === true ? {} : { review: review2 } } };
158781
158820
  }
@@ -158786,7 +158825,8 @@ ${pictures(job, ws, ws.number)}`);
158786
158825
  let continuation;
158787
158826
  let expectedDelivery;
158788
158827
  if (verb === "implement" && flow.resume) {
158789
- const restored = await akb(["raw", "delivery", "resume", String(id3), "--json"]);
158828
+ const restored = await launch2(["raw", "delivery", "resume", String(id3), "--json"]);
158829
+ if (restored.reviewRefused) return fail(restored.reviewRefused);
158790
158830
  const resumed = answerOf2(restored);
158791
158831
  if (io.lost()) return fail("");
158792
158832
  if (resumed?.landed) return { ok: true, report: { card: id3 } };
@@ -158805,7 +158845,8 @@ ${pictures(job, ws, ws.number)}`);
158805
158845
  }
158806
158846
  }
158807
158847
  } else if (verb === "implement" && text4) {
158808
- const resolved = await akb(["raw", "card", "resolve", String(id3), "--follow", "--events", "--json", "--", text4], true);
158848
+ const resolved = await launch2(["raw", "card", "resolve", String(id3), "--follow", "--events", "--json", "--", text4], true);
158849
+ if (resolved.reviewRefused) return fail(resolved.reviewRefused);
158809
158850
  if (io.lost()) return fail("");
158810
158851
  const file4 = findCard(ws.board, id3);
158811
158852
  rejected = !!file4 && path49.relative(ws.board, file4).split(path49.sep)[0] === ".archive" && parseFrontmatter(fs45.readFileSync(file4, "utf8")).meta?.rejected === true;
@@ -158815,20 +158856,23 @@ ${pictures(job, ws, ws.number)}`);
158815
158856
  const fresh = () => {
158816
158857
  const carry = carryArgs(verb);
158817
158858
  const costFrom = carry.includes("--session") && typeof job.resumeCostUsd === "number" ? { [SESSION_COST_ENV]: String(job.resumeCostUsd) } : void 0;
158818
- return akb(["raw", "card", verb, String(id3), "--follow", "--events", "--json", ...carry, ...note ? ["--", note] : []], true, costFrom);
158859
+ return launch2(["raw", "card", verb, String(id3), "--follow", "--events", "--json", ...carry, ...note ? ["--", note] : []], true, costFrom);
158819
158860
  };
158820
- ran ??= await (continuation ? akb([...continuation, "--follow", "--events", "--json"], true) : fresh());
158861
+ ran ??= await (continuation ? launch2([...continuation, "--follow", "--events", "--json"], true) : fresh());
158862
+ if (ran.reviewRefused) return fail(ran.reviewRefused);
158821
158863
  if (io.lost()) return fail("");
158822
158864
  const answer = answerOf2(ran);
158823
158865
  if (expectedDelivery && answer?.delivery?.id && answer.delivery.id !== expectedDelivery) {
158824
158866
  return fail("\u7EED\u8DD1\u8FD4\u56DE\u4E86\u5176\u4ED6\u4EA4\u4ED8\u7684\u7ED3\u679C\uFF0C\u539F\u4EA4\u4ED8\u4FDD\u6301\u672A\u5B8C\u6210\u3002");
158825
158867
  }
158826
- const asked = verb === "implement" && !rejected && asks(cardFile(ws));
158827
158868
  if (verb === "implement" && !rejected) {
158828
- const ending = deliveryEnding(ws, answer?.delivery?.id ?? answer?.error?.delivery?.id, asked);
158829
- if (ending) return ending;
158869
+ const ending = (answer?.delivery ?? answer?.error?.delivery)?.ending;
158870
+ if (ending?.kind === "stopped") return { ok: false, reason: "", stopped: true };
158871
+ if (ending?.kind === "discarded") return fail("The build was discarded.");
158872
+ if (ending?.kind === "blocked") return fail(ending.reason);
158830
158873
  }
158831
- const waiting = rejected ? null : reviewOf2(cardFile(ws));
158874
+ const asked = verb === "implement" && !rejected && asks(cardFile(ws));
158875
+ const waiting = rejected ? null : reviewOf2(cardFile(ws), hasReview);
158832
158876
  const review = waiting && waiting !== true ? waiting : void 0;
158833
158877
  if (!rejected && ran.code !== 0 && !(verb === "refine" && waiting) && !(answer?.error && asked)) {
158834
158878
  return fail(reasonOf(answer?.error?.message?.replace(/^run \S+ ended \w+: /, "")) ?? refusal3(ran));
@@ -158854,9 +158898,9 @@ ${pictures(job, ws, ws.number)}`);
158854
158898
  }
158855
158899
  return { ok: true, report: { card } };
158856
158900
  }
158857
- function carryArgs(verb) {
158901
+ function carryArgs(verb2) {
158858
158902
  if (flow.replan) return ["--new-session"];
158859
- if (!["refine", "resolve", "revise"].includes(verb)) return [];
158903
+ if (!["refine", "resolve", "revise"].includes(verb2)) return [];
158860
158904
  const transcript = writeTranscript(job, path49.join(ws.board, ".sync", `${ws.task}.discussion`));
158861
158905
  return [
158862
158906
  ...job.resume ? ["--session", job.resume, ...job.fork ? ["--fork"] : []] : [],
package/dist/settings.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.92 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.93 — 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;
@@ -61499,8 +61499,8 @@ async function stopExecutors() {
61499
61499
  }
61500
61500
 
61501
61501
  // src/protocol.ts
61502
- var VERSION = true ? "0.6.92" : "0.0.0";
61503
- var AKB_VERSION = true ? "0.11.74" : "0.0.0";
61502
+ var VERSION = true ? "0.6.93" : "0.0.0";
61503
+ var AKB_VERSION = true ? "0.11.75" : "0.0.0";
61504
61504
 
61505
61505
  // src/api.ts
61506
61506
  var RUNTIMES = ["claude-code", "codex", "cursor", "opencode", "kimi", "dsh", "zcode", "grok", "antigravity"];
@@ -64445,8 +64445,8 @@ function createTail(log) {
64445
64445
  // ../cli/package.json
64446
64446
  var package_default = {
64447
64447
  name: "wildcrane",
64448
- version: "0.11.74",
64449
- akbContract: 21,
64448
+ version: "0.11.75",
64449
+ akbContract: 22,
64450
64450
  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.",
64451
64451
  keywords: [
64452
64452
  "kanban",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wildcrane-runner",
3
- "version": "0.6.92",
3
+ "version": "0.6.93",
4
4
  "description": "WildCrane's Local Runner — connects this computer to WildCrane and runs its jobs on your local Claude Code, Codex, OpenCode or Cursor.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://wildcrane.ai/",