wildcrane 0.11.56 → 0.11.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/kanban.mjs +120 -64
  2. package/package.json +1 -1
package/dist/kanban.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // ai4kanban 0.11.56 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
2
+ // ai4kanban 0.11.57 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
3
3
  // Do not edit: every change belongs in cli/src/, and a build overwrites this file.
4
4
  import { createRequire as __ai4kanbanRequire } from 'node:module'
5
5
  const require = __ai4kanbanRequire(import.meta.url)
@@ -4206,7 +4206,7 @@ var init_package = __esm({
4206
4206
  "package.json"() {
4207
4207
  package_default = {
4208
4208
  name: "wildcrane",
4209
- version: "0.11.56",
4209
+ version: "0.11.57",
4210
4210
  akbContract: 15,
4211
4211
  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.",
4212
4212
  keywords: [
@@ -8311,7 +8311,7 @@ var init_flows = __esm({
8311
8311
  group: "card",
8312
8312
  action: "refine",
8313
8313
  argument: "<id>",
8314
- gloss: "plan the card in one session",
8314
+ gloss: "plan the card",
8315
8315
  options: CARRY_OPTIONS
8316
8316
  },
8317
8317
  {
@@ -8674,7 +8674,7 @@ function parseSpecAgent(text5, from, file2, builtIn = false, list2 = () => []) {
8674
8674
  const after2 = names(akb.after);
8675
8675
  const declaredSession = str3(akb.session);
8676
8676
  if (declaredSession && declaredSession !== "new") {
8677
- return bad(`\`${name}\` declares \`akb.session: ${declaredSession}\` \u2014 it is \`new\`, or left out to run in the planning session`);
8677
+ return bad(`\`${name}\` declares \`akb.session: ${declaredSession}\` \u2014 use \`new\` to recommend a separate session, or omit the preference`);
8678
8678
  }
8679
8679
  let stages;
8680
8680
  if (akb.stages !== void 0) {
@@ -10946,7 +10946,7 @@ function specAgentSelector(id, studio, meta) {
10946
10946
  `\`akb raw previews --triggers --studio ${flow.id}\` whose conditions the card meets, always including those marked \`Always\`. Save them with`,
10947
10947
  `\`akb raw update ${id} --previews <agents>\` (\`""\` when that leaves none); its stages follow from them.`,
10948
10948
  "Then run only the chosen agents whose `After` is empty \u2014 the first stage; the rest run after its approval.",
10949
- `Command: \`akb raw previews <agent> ${id} <short note>\` \u2014 add \`--print\` to run it in this session, as \`akb guide refine\` says.`,
10949
+ `Command: \`akb raw previews <agent> ${id} <short note>\` \u2014 choose \`--print\` for this session or omit it for a separate session.`,
10950
10950
  "</preview-agents>"
10951
10951
  ].join("\n");
10952
10952
  }
@@ -10958,8 +10958,8 @@ function specAgentSelector(id, studio, meta) {
10958
10958
  // own job.
10959
10959
  "<preview-agents>",
10960
10960
  "The preview agents of this card's current stage, each writing one part of the card.",
10961
- ...agents.map((a2) => `- \`${a2.name}\` \u2014 ${a2.description}${a2.session || agentRun(a2.name).own ? " \xB7 runs in a session of its own: leave out `--print`" : ""}`),
10962
- `Command: \`akb raw previews <agent> ${id} <short note>\` \u2014 add \`--print\` to run it in this session, as \`akb guide refine\` says.`,
10961
+ ...agents.map((a2) => `- \`${a2.name}\` \u2014 ${a2.description}${a2.session === "new" ? " \xB7 separate session recommended" : ""}`),
10962
+ `Command: \`akb raw previews <agent> ${id} <short note>\` \u2014 choose \`--print\` for this session or omit it for a separate session.`,
10963
10963
  "</preview-agents>"
10964
10964
  ].join("\n");
10965
10965
  }
@@ -17031,7 +17031,7 @@ function actionPrompt(req, command, notes) {
17031
17031
  ].filter(Boolean).join(" ");
17032
17032
  case "clarify": {
17033
17033
  return [
17034
- `Plan task ${req.id} ${named2} in this one session following \`akb guide refine\`. Work the board only through \`akb\`; a command with \`--print\` prints its flow for you to follow here, and without it starts a separate agent.`,
17034
+ `Plan task ${req.id} ${named2} following \`akb guide refine\`. Work the board only through \`akb\`; a command with \`--print\` prints its flow for you to follow here, and without it starts a separate session.`,
17035
17035
  carriedNote(req),
17036
17036
  // A refine has no note box of its own, but one SCHEDULED on a blocked card
17037
17037
  // carries whatever was typed when it was scheduled — often the very reason the user
@@ -18891,18 +18891,57 @@ ${stage.artifact?.body ?? ""}`),
18891
18891
  `Write only the current work in your existing section. Submit it with: ${command} raw previews ${name} ${id} --submit --stage ${current.id}. Stop after success.`
18892
18892
  ].join("\n\n");
18893
18893
  }
18894
+ async function assertPreviewTask(id) {
18895
+ if (!process.env[PREVIEW_BRIDGE_ENV]) return;
18896
+ const task = workspaceTask();
18897
+ if (!task) throw Error("The preview bridge needs its current task.");
18898
+ const source2 = await call("GET", `/v1/tasks/${encodeURIComponent(task)}`);
18899
+ if (!source2.ok) throw Error(source2.error);
18900
+ if (numberOf(source2.value.key) !== id) throw Error("Only the current task can prepare previews from this session.");
18901
+ }
18902
+ function previewOwner(id, name, inside2 = insideRun()) {
18903
+ const found2 = locate(id);
18904
+ if (!found2) throw Error("The task is no longer open.");
18905
+ const card = found2.kind === "group" ? path68.join(found2.target, "root.md") : found2.target;
18906
+ const { meta } = parseFrontmatter(fs66.readFileSync(card, "utf8"));
18907
+ if (!specAgentAssigned(name, meta?.studio) || !meta?.previews?.some((agent) => canonicalSpecAgent(agent) === name)) throw Error("Choose this preview agent on the task first.");
18908
+ if (inside2) {
18909
+ const run4 = readRuns().find((run5) => run5.sessionId === inside2);
18910
+ if (!run4 || run4.status !== "running" || run4.cardId !== id || (run4.action === "spec" ? run4.specAgent !== name : !["clarify", "edit", "resolve", "approve"].includes(run4.action))) throw Error("Only the active task session can prepare its selected previews.");
18911
+ return `run:${inside2}`;
18912
+ }
18913
+ const execution = executionOf();
18914
+ if (execution) return `job:${execution.job}`;
18915
+ return process.env[STOP_ENV] || Object.values(SESSION_VARS).map((key) => process.env[key]).find(Boolean) || "external";
18916
+ }
18917
+ function readContext(file2) {
18918
+ try {
18919
+ return JSON.parse(fs66.readFileSync(file2, "utf8"));
18920
+ } catch (error) {
18921
+ if (error.code === "ENOENT") return void 0;
18922
+ throw error;
18923
+ }
18924
+ }
18925
+ function writeJson2(file2, value) {
18926
+ fs66.mkdirSync(path68.dirname(file2), { recursive: true });
18927
+ const temp = `${file2}.${process.pid}.tmp`;
18928
+ fs66.writeFileSync(temp, JSON.stringify(value) + "\n");
18929
+ fs66.renameSync(temp, file2);
18930
+ }
18894
18931
  function previewRun(id, name) {
18895
- const run4 = readRuns().find((run5) => run5.sessionId === insideRun());
18896
- if (!run4 || run4.status !== "running" || run4.action !== "spec" || run4.specAgent !== name || run4.cardId !== id) throw Error("Only the active preview agent can select or submit its stages.");
18897
- return run4;
18932
+ const context = readContext(contextFile(id, name, previewOwner(id, name)));
18933
+ if (!context?.active) throw Error("Enter this preview with --print before selecting or submitting its stages.");
18934
+ const progress = readPreviewProgress(id)[name];
18935
+ if (progress?.execution && progress.execution !== context.sessionId && !progress.execution.endsWith(`:${context.sessionId}`)) throw Error("This execution is outdated. Reload the task.");
18936
+ return context;
18898
18937
  }
18899
18938
  function selectLocalPreview(id, name, ids) {
18900
18939
  const run4 = previewRun(id, name);
18901
- freezePreviewProgress(id, name);
18902
18940
  return updatePreviewProgress(id, (all2) => {
18903
18941
  const progress = all2[name];
18904
18942
  if (!progress) throw Error("This agent has no staged preview.");
18905
- if (progress.stages.length && progress.execution === run4.sessionId && JSON.stringify(progress.stages.map((stage) => stage.id)) === JSON.stringify(ids)) return { progress, baseline: readPreviewBaseline(run4.sessionId) };
18943
+ if (progress.execution !== run4.sessionId) throw Error("This execution is outdated. Reload the task.");
18944
+ if (progress.stages.length && JSON.stringify(progress.stages.map((stage) => stage.id)) === JSON.stringify(ids)) return { progress, baseline: readPreviewBaseline(id, name, run4.sessionId) };
18906
18945
  selectPreviewStages(progress, ids);
18907
18946
  const baseline = previewBaseline(progress, progress.currentStageId, run4.sessionId);
18908
18947
  return { progress, baseline };
@@ -18929,34 +18968,52 @@ function submitLocalPreview(id, name, stage, baseline) {
18929
18968
  return updatePreviewProgress(id, (all2) => {
18930
18969
  const progress = all2[name];
18931
18970
  if (!progress) throw Error("Select the stages first.");
18932
- const base = baseline ?? { definitionRevision: progress.definitionRevision, generation: progress.generation, stageId: stage, execution: run4.sessionId };
18971
+ const base = baseline ?? readPreviewBaseline(id, name, run4.sessionId);
18933
18972
  if (base.stageId !== stage) throw Error("Wrong stage.");
18934
18973
  return submitPreviewStage(progress, base, body, { folder: dest });
18935
18974
  });
18936
18975
  }
18937
- function savePreviewBaseline(run4, baseline) {
18938
- fs66.mkdirSync(path68.dirname(baselineFile(run4)), { recursive: true });
18939
- fs66.writeFileSync(baselineFile(run4), JSON.stringify(baseline) + "\n");
18976
+ function savePreviewBaseline(id, name, run4, baseline) {
18977
+ writeJson2(baselineFile(id, name, run4), baseline);
18940
18978
  }
18941
- function readPreviewBaseline(run4) {
18942
- return JSON.parse(fs66.readFileSync(baselineFile(run4), "utf8"));
18979
+ function readPreviewBaseline(id, name, run4) {
18980
+ return JSON.parse(fs66.readFileSync(baselineFile(id, name, run4), "utf8"));
18943
18981
  }
18944
- async function activatePreviewRun(id, name, run4) {
18982
+ async function activatePreviewRun(id, name, run4, request2 = "") {
18983
+ await assertPreviewTask(id);
18984
+ const owner = previewOwner(id, name, run4 ?? insideRun());
18985
+ const file2 = contextFile(id, name, owner);
18986
+ const held4 = readContext(file2);
18987
+ const context = held4 && held4.request === request2 ? held4 : { sessionId: run4 ?? randomUUID5(), request: request2 };
18988
+ if (held4?.active && held4.sessionId === context.sessionId) {
18989
+ const progress = readPreviewProgress(id)[name];
18990
+ if (progress?.execution && progress.execution !== context.sessionId && !progress.execution.endsWith(`:${context.sessionId}`)) throw Error("This execution is outdated. Reload the task.");
18991
+ }
18992
+ writeJson2(file2, context);
18993
+ run4 = context.sessionId;
18945
18994
  const { previewBridge: previewBridge2 } = await Promise.resolve().then(() => (init_preview(), preview_exports));
18946
18995
  const remote2 = await previewBridge2(name, "start", { run: run4 });
18947
- if (remote2?.progress) {
18948
- updatePreviewProgress(id, (all2) => {
18996
+ if (remote2) {
18997
+ if (remote2.progress) updatePreviewProgress(id, (all2) => {
18949
18998
  all2[name] = remote2.progress;
18950
18999
  });
18951
- if (remote2.baseline) savePreviewBaseline(run4, remote2.baseline);
19000
+ if (remote2.baseline) savePreviewBaseline(id, name, run4, remote2.baseline);
18952
19001
  } else {
18953
19002
  freezePreviewProgress(id, name);
18954
19003
  updatePreviewProgress(id, (all2) => {
18955
19004
  const progress = all2[name];
18956
- if (progress?.currentStageId && ["awaiting_confirmation", "ready"].includes(progress.stages.find((stage) => stage.id === progress.currentStageId)?.status ?? "") && progress.execution !== run4) beginPreviewRevision(progress, run4);
18957
- if (progress?.currentStageId && !progress.revisionBase) savePreviewBaseline(run4, previewBaseline(progress, progress.currentStageId, run4));
19005
+ if (!progress) return;
19006
+ const current = progress.stages.find((stage) => stage.id === progress.currentStageId);
19007
+ if (held4?.active && held4.sessionId === run4 && progress.execution && progress.execution !== run4) throw Error("This execution is outdated. Reload the task.");
19008
+ if (current && ["awaiting_confirmation", "ready"].includes(current.status)) {
19009
+ if (progress.execution === run4) return;
19010
+ beginPreviewRevision(progress, run4);
19011
+ }
19012
+ if (progress.currentStageId && !progress.revisionBase) savePreviewBaseline(id, name, run4, previewBaseline(progress, progress.currentStageId, run4));
19013
+ else progress.execution = run4;
18958
19014
  });
18959
19015
  }
19016
+ writeJson2(file2, { ...context, active: true });
18960
19017
  }
18961
19018
  function frozenPreviewFile(agent, relative) {
18962
19019
  const run4 = readRuns().find((run5) => run5.sessionId === insideRun());
@@ -18972,7 +19029,7 @@ ${fs66.readFileSync(path68.join(folder, name), "utf8")}`).join("\n\n");
18972
19029
  return "";
18973
19030
  }
18974
19031
  }
18975
- var file, baselineFile;
19032
+ var file, contextFile, baselineFile;
18976
19033
  var init_preview_progress = __esm({
18977
19034
  "src/lib/agent/preview-progress.ts"() {
18978
19035
  "use strict";
@@ -18980,15 +19037,22 @@ var init_preview_progress = __esm({
18980
19037
  init_memory();
18981
19038
  init_lock();
18982
19039
  init_agents();
19040
+ init_spec_agent_names();
18983
19041
  init_read();
18984
19042
  init_studios();
18985
19043
  init_studio_shared();
18986
19044
  init_store();
18987
19045
  init_env();
19046
+ init_cards();
19047
+ init_frontmatter();
19048
+ init_execution();
19049
+ init_tasks();
19050
+ init_preview();
18988
19051
  init_preview_files();
18989
19052
  init_preview_stages();
18990
19053
  file = (id) => path68.join(BOARD_STATE, "previews", `${id}.json`);
18991
- baselineFile = (run4) => path68.join(BOARD_STATE, "previews", "runs", `${run4}.json`);
19054
+ contextFile = (id, name, owner) => path68.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash7("sha256").update(owner).digest("hex")}.json`);
19055
+ baselineFile = (id, name, run4) => path68.join(BOARD_STATE, "previews", "runs", String(id), name, `${run4}.json`);
18992
19056
  }
18993
19057
  });
18994
19058
 
@@ -24033,30 +24097,14 @@ var init_manual = __esm({
24033
24097
  /** Under every flow: print it, or run it. The one choice each of them has. */
24034
24098
  flow: `
24035
24099
  Print it, or run it
24036
- --print say what to do and start nothing. What it prints is filled in for this board:
24100
+ --print print the flow to follow in the current session, filled in for this board:
24037
24101
  the card's own path, the steps it has left, the memory file its modules point
24038
24102
  at, the flows the job is done by in full, and the
24039
24103
  command that closes the job \u2014 because nothing is watching you finish.
24040
- (no flag) start a run: a second agent, its own context, working on its own.
24041
-
24042
- Print when the user is asking you for the action here, in a session. You do the job in the
24043
- conversation you are already in: it costs no second agent and can't collide with the
24044
- changes already in the working tree.
24104
+ (no flag) start a separate session with its own context.
24045
24105
 
24046
- Start a run when the user wants the work to happen on its own \u2014 in the background, while
24047
- they do something else, on a card they are not watching. That is the explicit ask. It also
24048
- wins on long read-heavy jobs that need nothing from the conversation.
24049
-
24050
- Some jobs are better done by the agent that was there. It just built the card, so it knows
24051
- which steps it really did; a fresh agent sees unticked boxes and works the rest out from
24052
- the diff.
24053
-
24054
- When it is not clear which was meant, print. A printed flow costs nothing and can still be
24055
- followed by starting a run; a started run costs a second agent, a second context, and money
24056
- nobody asked to spend.
24057
-
24058
- One caller does not choose: an agent already working inside a run the board started always
24059
- prints, because a run never starts another.
24106
+ Choose either mode for preview work. Other board actions inside a board run print their
24107
+ flows; preview requests can queue a separate session.
24060
24108
  `,
24061
24109
  /** Under `delivery`: what one is, which no verb of it says on its own. */
24062
24110
  deliveries: (program2) => `
@@ -24673,7 +24721,7 @@ var init_board3 = __esm({
24673
24721
  var card_chat_default;
24674
24722
  var init_card_chat = __esm({
24675
24723
  "src/guide/card-chat.md"() {
24676
- card_chat_default = '# Answer a card\'s conversation\n\nWork on the current card and its assets by default. Project implementation requires approval on the review page.\n\n- **Where the task stands**: read it with `akb task show <id>`.\n- **Button labels**: name actions by their labels on the page, in the user\'s language: "Approve" or "Approve, start \u2026" (\u6279\u51C6 / \u6279\u51C6\uFF0C\u5F00\u59CB\u2026), "Resume" (\u7EED\u8DD1), "Start again" (\u91CD\u65B0\u53D1\u8D77).\n\n- **Change requirements or drafts**: when the user changes the scope, expected behavior, or draft, use `akb raw card revise <id> --print "<change>"`.\n- **Record an answer**: when the user answers an open question on the card, use `akb raw card resolve <id> --print`.\n- **Manage open questions**: when a decision needs the user\'s input, follow `akb guide update-questions` and use `akb raw update-questions <id>` to edit the question list.\n- **Change card fields**: when the user changes metadata such as priority, modules, or dependencies, use `akb raw update <id>`.\n- **Choose a preview agent**: when a preview is needed and the agent is unclear, use `akb raw previews --triggers` to match the work to an agent.\n- **Create or revise a preview**: when the user asks to see or change a preview for the current card, use `akb raw previews <agent> <id> --print`; never write Preview Components tags by hand.\n- **Create a separate task**: when the user asks to capture work unrelated to this card, follow `akb guide add-task`.\n- **Split this card**: when the user asks to break this card\'s outcome into subtasks, follow the group procedure in `akb guide add-task`.\n- **Change a studio**: use `akb guide update-studio` for shared studio or agent changes; a correction to this card\'s draft alone stays on this card.\n- **Check card edits**: after writing a card, run `akb raw validate <id>` and fix what it reports.\n- **Anything else**: for a request this guide does not cover, read `akb help` once, then the matching command\'s `--help`.\n\nReply in plain, natural language. Do not write memory, including through any flow this conversation starts.\n\n- **Start this task**: when the user explicitly asks to start, implement or approve it, use `akb task approve` or `akb raw card approve/implement`. In a task reply these register one approval for after the reply finishes and syncs. Pending means accepted, not started; finish the reply and do not wait or edit the card again. Preview approvals still apply.\n';
24724
+ card_chat_default = '# Answer a card\'s conversation\n\nWork on the current card and its assets by default. Project implementation requires approval on the review page.\n\n- **Where the task stands**: read it with `akb task show <id>`.\n- **Button labels**: name actions by their labels on the page, in the user\'s language: "Approve" or "Approve, start \u2026" (\u6279\u51C6 / \u6279\u51C6\uFF0C\u5F00\u59CB\u2026), "Resume" (\u7EED\u8DD1), "Start again" (\u91CD\u65B0\u53D1\u8D77).\n\n- **Change requirements or drafts**: when the user changes the scope, expected behavior, or draft, use `akb raw card revise <id> --print "<change>"`.\n- **Record an answer**: when the user answers an open question on the card, use `akb raw card resolve <id> --print`.\n- **Manage open questions**: when a decision needs the user\'s input, follow `akb guide update-questions` and use `akb raw update-questions <id>` to edit the question list.\n- **Change card fields**: when the user changes metadata such as priority, modules, or dependencies, use `akb raw update <id>`.\n- **Choose a preview agent**: when a preview is needed and the agent is unclear, use `akb raw previews --triggers` to match the work to an agent.\n- **Create or revise a preview**: when the user asks to see or change a preview for the current card,\n use `akb raw previews <agent> <id>`; choose `--print` for this session or omit it for a separate\n session. The agent carrying out that role writes and maintains its section and Preview Components.\n- **Create a separate task**: when the user asks to capture work unrelated to this card, follow `akb guide add-task`.\n- **Split this card**: when the user asks to break this card\'s outcome into subtasks, follow the group procedure in `akb guide add-task`.\n- **Change a studio**: use `akb guide update-studio` for shared studio or agent changes; a correction to this card\'s draft alone stays on this card.\n- **Check card edits**: after writing a card, run `akb raw validate <id>` and fix what it reports.\n- **Anything else**: for a request this guide does not cover, read `akb help` once, then the matching command\'s `--help`.\n\nReply in plain, natural language. Do not write memory, including through any flow this conversation starts.\n\n- **Start this task**: when the user explicitly asks to start, implement or approve it, use `akb task approve` or `akb raw card approve/implement`. In a task reply these register one approval for after the reply finishes and syncs. Pending means accepted, not started; finish the reply and do not wait or edit the card again. Preview approvals still apply.\n';
24677
24725
  }
24678
24726
  });
24679
24727
 
@@ -24753,7 +24801,7 @@ var init_review_rejections = __esm({
24753
24801
  var refine_default;
24754
24802
  var init_refine = __esm({
24755
24803
  "src/guide/refine.md"() {
24756
- refine_default = "# Refine a card\n\nPlan one card in this session until it can be built.\n\n- **Unchecked card**: a card with `triage:` set and an empty `## Scope` was never checked\n against the project. Check it first; when the project already does\n the work, or what it concerns no longer exists, run\n `akb raw reject <id> --reason \"<what shows it>\"` and stop.\n- **Gone or already done**: for any other card, append a question asking the user whether to\n discard it, run no preview agent, and stop.\n- **Existing group**: read its subtasks and check that they cover the parent\u2019s outcome;\n keep a complete split, or fill gaps by updating subtasks and dependencies without\n duplicating work or resetting progress. Finish the pass without marking the parent\n ready merely because its split is complete; its completion still follows its subtasks.\n- **Studio rules**: write the card as the studio rules at the end of this prompt say.\n- **Preview agents**: an agent's `After` names the previews it waits for; the board approves\n previews in stages, one stage per Approve, and the card's `previews` were chosen when its\n goal was written. A card without `previews` has not chosen: choose and save them first, as\n the list says, then run only its first stage. Run each agent the list above names whose\n section is missing or outdated with `akb raw previews <agent> <id> --print`, one at a time in this\n session; leave out `--print` only for an agent the list says runs in a session of its own.\n- **Stale mentions**: rewrite any sentence that relies on a card no longer on the board.\n- **Questions**: settle every decision you can and record the answers as `akb guide writing`\n says; ask only what `akb guide update-questions` says to ask.\n- **Write**: shape the card as `akb guide writing` says, then run `akb raw validate <id>` and\n fix every reported line.\n- **Ready**: settle every fact from the project and authoritative sources. Once the card\n validates, judge whether it can be built as written, or before its last Approve: if so, run\n `akb raw update <id> --status ready`; otherwise leave what blocks it as an open question.\n\nFollow any closing steps the flow printed, then stop: the user approves the previews or starts\nthe build.\n";
24804
+ refine_default = "# Refine a card\n\nPlan one card until it can be built.\n\n- **Unchecked card**: a card with `triage:` set and an empty `## Scope` was never checked\n against the project. Check it first; when the project already does\n the work, or what it concerns no longer exists, run\n `akb raw reject <id> --reason \"<what shows it>\"` and stop.\n- **Gone or already done**: for any other card, append a question asking the user whether to\n discard it, run no preview agent, and stop.\n- **Existing group**: read its subtasks and check that they cover the parent\u2019s outcome;\n keep a complete split, or fill gaps by updating subtasks and dependencies without\n duplicating work or resetting progress. Finish the pass without marking the parent\n ready merely because its split is complete; its completion still follows its subtasks.\n- **Studio rules**: write the card as the studio rules at the end of this prompt say.\n- **Preview agents**: an agent's `After` names the previews it waits for; the board approves\n previews in stages, one stage per Approve, and the card's `previews` were chosen when its\n goal was written. A card without `previews` has not chosen: choose and save them first, as\n the list says, then run only its first stage. Run each listed agent whose section is missing\n or outdated with `akb raw previews <agent> <id>`; choose `--print` for this session or\n omit it for a separate session.\n- **Stale mentions**: rewrite any sentence that relies on a card no longer on the board.\n- **Questions**: settle every decision you can and record the answers as `akb guide writing`\n says; ask only what `akb guide update-questions` says to ask.\n- **Write**: shape the card as `akb guide writing` says, then run `akb raw validate <id>` and\n fix every reported line.\n- **Ready**: settle every fact from the project and authoritative sources. Once the card\n validates, judge whether it can be built as written, or before its last Approve: if so, run\n `akb raw update <id> --status ready`; otherwise leave what blocks it as an open question.\n\nFollow any closing steps the flow printed, then stop: the user approves the previews or starts\nthe build.\n";
24757
24805
  }
24758
24806
  });
24759
24807
 
@@ -24777,7 +24825,7 @@ var init_resolve2 = __esm({
24777
24825
  var revise_default;
24778
24826
  var init_revise = __esm({
24779
24827
  "src/guide/revise.md"() {
24780
- revise_default = "# Revise\n\nMake the requested change and fix what it contradicts in the card. Apply answers supported by\nthe project and leave only decisions the user owns.\n\n- **Owned content first**: before the edit, follow \"Preview ownership\" in `akb guide writing`.\n- **Dependencies**: when the card comes to need another card's output, add that id to its\n `blocked_by` as `akb guide add-task` says.\n- **Changed outcome**: if the request materially changes what the task delivers, write the\n revision, then plan the card in this session as `akb guide refine` says. Ordinary scope\n and wording changes need no replanning.\n- **Preview agents**: when the revision adds or changes work a preview agent's `When` covers,\n such as images, page copy or a screen, add it to the card's `previews` and run it as\n \"Preview agents\" in `akb guide refine` says; a plan of that work written into `## Scope` is\n no substitute.\n- **Drafts**: when the change affects a draft on the card, revise its files and previews in\n place on this run, with `akb raw previews` for each preview agent whose draft it affects, including\n one from an earlier stage. Keep the unaffected content and the IDs. A note or todo is no\n substitute.\n- **Superseded decisions**: An entry under `## Decided by the agent`, or a line under the\n human half's `## Worth noting`, that the revision makes invalid is a call the user\n overruled \u2014 keep it. Move the line, as it stands, under a `### Overruled by the user`\n heading at the end of `## Decided by the agent`, adding the heading if the card has none.\n The subsection stays last inside that section. Delete an overruled line once the card\n leaves the builder no room to repeat that call.\n- **The two halves**: write the card in the shape `akb guide writing` sets out; when the change\n lands in the agent half, re-read the opening paragraph and `## Worth noting` so both hold.\n- **Other actions**: for another board action asked, follow `akb <action> <id> --print`.\n";
24828
+ revise_default = "# Revise\n\nMake the requested change and fix what it contradicts in the card. Apply answers supported by\nthe project and leave only decisions the user owns.\n\n- **Owned content first**: before the edit, follow \"Preview ownership\" in `akb guide writing`.\n- **Dependencies**: when the card comes to need another card's output, add that id to its\n `blocked_by` as `akb guide add-task` says.\n- **Changed outcome**: if the request materially changes what the task delivers, write the\n revision, then plan the card as `akb guide refine` says. Ordinary scope\n and wording changes need no replanning.\n- **Preview agents**: when the revision adds or changes work a preview agent's `When` covers,\n such as images, page copy or a screen, add it to the card's `previews` and run it as\n \"Preview agents\" in `akb guide refine` says; a plan of that work written into `## Scope` is\n no substitute.\n- **Drafts**: when the change affects a draft on the card, revise its files and previews in\n place, with `akb raw previews` for each preview agent whose draft it affects, including\n one from an earlier stage. Keep the unaffected content and the IDs. A note or todo is no\n substitute.\n- **Superseded decisions**: An entry under `## Decided by the agent`, or a line under the\n human half's `## Worth noting`, that the revision makes invalid is a call the user\n overruled \u2014 keep it. Move the line, as it stands, under a `### Overruled by the user`\n heading at the end of `## Decided by the agent`, adding the heading if the card has none.\n The subsection stays last inside that section. Delete an overruled line once the card\n leaves the builder no room to repeat that call.\n- **The two halves**: write the card in the shape `akb guide writing` sets out; when the change\n lands in the agent half, re-read the opening paragraph and `## Worth noting` so both hold.\n- **Other actions**: for another board action asked, follow its guide.\n";
24781
24829
  }
24782
24830
  });
24783
24831
 
@@ -24809,7 +24857,7 @@ var init_troubleshoot = __esm({
24809
24857
  var write_agent_default;
24810
24858
  var init_write_agent = __esm({
24811
24859
  "src/guide/write-agent.md"() {
24812
- write_agent_default = "# Write an agent\n\nCreate `docs/kanban/agents/<name>/AGENT.md`; use an unused lowercase, hyphenated name matching\nthe folder. Its studio lists it under `previews`, `land` or `scheduled` in `STUDIO.md`.\n\n## Example: a preview agent\n\n```yaml\n---\nname: page-designer\ndescription: Makes complete page designs with their copy.\nakb:\n when: A card needs a page designed or changed.\n icon: screen\n components: [Asset, Set]\n i18n:\n en:\n title: Page design\n zh:\n title: \u9875\u9762\u8BBE\u8BA1\n stages:\n - id: copy\n title: {en: Copy, zh: \u6587\u6848}\n when: The page needs new or revised copy; existing text is insufficient.\n instructions: references/copy.md\n - id: layout\n title: {en: Page layout, zh: \u9875\u9762\u7A3F}\n instructions: references/layout.md\n---\n\nChoose the stages this task needs on first entry; reuse the saved selection on continuation.\nFollow the current stage's instructions, preserving confirmed copy in the page design.\n```\n\nWith existing copy, this agent selects only `layout`; otherwise it selects `copy,layout`.\nEach selected step except the last waits for user confirmation. The last is ready for the\ncard's approval. The agent chooses its steps, not the planner; the program saves and advances\nthem. Omit `stages` for a single preview. Stage IDs are unique; instruction paths stay inside\nthe agent folder. A task freezes its definition, files and selection.\n\n**Legacy**: `after` remains readable for frozen workflows; use internal stages for new agents.\n\n## Other fields\n\nOnly `name`, `description` and nonempty body instructions are required. Omit unused fields.\n\n| Field | Use |\n| --- | --- |\n| `akb.when` | When to request a preview; omitted means every task on its studio. |\n| `akb.session: new` | Run a preview in its own session. |\n| `akb.components` | Asset, Set, Compare or Storyboard; default `[Asset]`, `[]` loads no component docs. |\n| `akb.icon` | Glyph name, or 1\u201312 `{d, f?, o?: true, s?, w?}` parts using supported colours. |\n| `akb.i18n` | Display-only title, description and when by language; missing text falls back to English. Keep titles short and name the output. |\n| `akb.reads` | Scheduled input: `archived-cards`, `chats` or `dismissals`; omitted uses cadence alone. Set fixed cadence on the studio's scheduled entry. |\n| `akb.merges: true` | A land agent merges code; completion requires its merged commit and branch. |\n| `akb.memory` | Names of shared global memories. |\n| `akb.memoryFiles.workspace` | Paths such as `[style.md]` shared across projects within this agent's memory. |\n\n## Instructions and files\n\n- **Keep the body small**: say what the agent owns and delivers. Use `akb guide write-prompt`;\n do not repeat `preview-agent` rules. Stage-specific work belongs in its instruction file.\n- **Load on demand**: files beside AGENT.md are listed to the run. Put shared studio material\n in `shared/`; keep scripts and business validation with their owning agent, documenting\n runtime and invocation. Retrieve bundled files with `akb raw file <studio> <path>`.\n- **Memory**: keep only preferences or corrections that change future work. Name each file's\n purpose and when to read it; omit transcripts and duplicated rules. Agent memory is under\n `docs/kanban/memory/agents/<name>/`; studio memory follows its `shared/RULES.md`. Agree on\n any scheduled agent's persistent state rather than inventing its format.\n- **User decisions**: follow `akb guide update-questions`; do not ask again about settled\n choices. Show each changed file as a unified diff with one sentence explaining why.\n\n## Imported skills\n\nKeep each skill whole under `skills/<skill>/`, including instructions, scripts, resources and\nlicense; exclude caches and installed packages. Record its source and version in AGENT.md:\n`- **<skill>**: <when to use>. Source: <URL or pasted> @ <commit, tag or date>`.\nAdapt routing outside the skill, preserving its relative paths. Report missing files, tools\nor credentials; never copy keys or claim an unusable skill works. Update or remove only when\nasked, replacing the whole owned copy and showing the diff and version.\n\n## Check\n\nRun `akb raw previews` and `akb raw previews --triggers`; fix every reported problem.\nThen inspect `akb raw previews <name> <id> --print` on a real task and trim unnecessary context.\nUse `akb raw components --agent <name> --docs` for output formats. New agents start enabled\nin their studio; disabled previews cannot run. Keep registration and instructions consistent.\n";
24860
+ write_agent_default = "# Write an agent\n\nCreate `docs/kanban/agents/<name>/AGENT.md`; use an unused lowercase, hyphenated name matching\nthe folder. Its studio lists it under `previews`, `land` or `scheduled` in `STUDIO.md`.\n\n## Example: a preview agent\n\n```yaml\n---\nname: page-designer\ndescription: Makes complete page designs with their copy.\nakb:\n when: A card needs a page designed or changed.\n icon: screen\n components: [Asset, Set]\n i18n:\n en:\n title: Page design\n zh:\n title: \u9875\u9762\u8BBE\u8BA1\n stages:\n - id: copy\n title: {en: Copy, zh: \u6587\u6848}\n when: The page needs new or revised copy; existing text is insufficient.\n instructions: references/copy.md\n - id: layout\n title: {en: Page layout, zh: \u9875\u9762\u7A3F}\n instructions: references/layout.md\n---\n\nChoose the stages this task needs on first entry; reuse the saved selection on continuation.\nFollow the current stage's instructions, preserving confirmed copy in the page design.\n```\n\nWith existing copy, this agent selects only `layout`; otherwise it selects `copy,layout`.\nEach selected step except the last waits for user confirmation. The last is ready for the\ncard's approval. The agent chooses its steps, not the planner; the program saves and advances\nthem. Omit `stages` for a single preview. Stage IDs are unique; instruction paths stay inside\nthe agent folder. A task freezes its definition, files and selection.\n\n**Dependencies**: `akb.after` names other previews in the same studio to approve first when the card requests them too.\n\n## Other fields\n\nOnly `name`, `description` and nonempty body instructions are required. Omit unused fields.\n\n| Field | Use |\n| --- | --- |\n| `akb.when` | When to request a preview; omitted means every task on its studio. |\n| `akb.session: new` | A preference for a separate session; the calling agent decides. |\n| `akb.components` | Asset, Set, Compare or Storyboard; default `[Asset]`, `[]` loads no component docs. |\n| `akb.icon` | Glyph name, or 1\u201312 `{d, f?, o?: true, s?, w?}` parts using supported colours. |\n| `akb.i18n` | Display-only title, description and when by language; missing text falls back to English. Keep titles short and name the output. |\n| `akb.reads` | Scheduled input: `archived-cards`, `chats` or `dismissals`; omitted uses cadence alone. Set fixed cadence on the studio's scheduled entry. |\n| `akb.merges: true` | A land agent merges code; completion requires its merged commit and branch. |\n| `akb.memory` | Names of shared global memories. |\n| `akb.memoryFiles.workspace` | Paths such as `[style.md]` shared across projects within this agent's memory. |\n\n## Instructions and files\n\n- **Keep the body small**: say what the agent owns and delivers. Use `akb guide write-prompt`;\n do not repeat `preview-agent` rules. Stage-specific work belongs in its instruction file.\n- **Load on demand**: files beside AGENT.md are listed to the run. Put shared studio material\n in `shared/`; keep scripts and business validation with their owning agent, documenting\n runtime and invocation. Retrieve bundled files with `akb raw file <studio> <path>`.\n- **Memory**: keep only preferences or corrections that change future work. Name each file's\n purpose and when to read it; omit transcripts and duplicated rules. Agent memory is under\n `docs/kanban/memory/agents/<name>/`; studio memory follows its `shared/RULES.md`. Agree on\n any scheduled agent's persistent state rather than inventing its format.\n- **User decisions**: follow `akb guide update-questions`; do not ask again about settled\n choices. Show each changed file as a unified diff with one sentence explaining why.\n\n## Imported skills\n\nKeep each skill whole under `skills/<skill>/`, including instructions, scripts, resources and\nlicense; exclude caches and installed packages. Record its source and version in AGENT.md:\n`- **<skill>**: <when to use>. Source: <URL or pasted> @ <commit, tag or date>`.\nAdapt routing outside the skill, preserving its relative paths. Report missing files, tools\nor credentials; never copy keys or claim an unusable skill works. Update or remove only when\nasked, replacing the whole owned copy and showing the diff and version.\n\n## Check\n\nRun `akb raw previews` and `akb raw previews --triggers`; fix every reported problem.\nThen inspect `akb raw previews <name> <id> --print` on a real task and trim unnecessary context.\nUse `akb raw components --agent <name> --docs` for output formats. New agents start enabled\nin their studio; disabled previews cannot run. Keep registration and instructions consistent.\n";
24813
24861
  }
24814
24862
  });
24815
24863
 
@@ -24891,7 +24939,7 @@ var init_guide = __esm({
24891
24939
  { name: "implement", when: "build a settled card and stop cleanly on an execution blocker", text: implement_default },
24892
24940
  { name: "archive", when: "finish a task \u2014 write its shipped line, then take it off the board", text: archive_default },
24893
24941
  { name: "update-questions", when: "decide what to ask the user, and write the question", text: update_questions_default },
24894
- { name: "refine", when: "plan one card until it can be built, in one session", text: refine_default },
24942
+ { name: "refine", when: "plan one card until it can be built", text: refine_default },
24895
24943
  { name: "revise", when: "make the one change to a card the user asked for", text: revise_default },
24896
24944
  { name: "resolve", when: "apply the user's answers to a card's open questions", text: resolve_default },
24897
24945
  { name: "prune-memory", when: "compress the memory set back to what helps planning", text: prune_memory_default },
@@ -27697,24 +27745,25 @@ async function cmdSpec(opts, program2 = "akb") {
27697
27745
  if (!locate(id)) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
27698
27746
  if (opts.stages !== void 0 || opts.submit || opts.reviseFrom) {
27699
27747
  try {
27748
+ await assertPreviewTask(id);
27700
27749
  const run5 = previewRun(id, name);
27701
27750
  const ids = opts.stages?.split(",").map((id2) => id2.trim());
27702
- const result = await previewBridge(name, ids ? "select" : opts.reviseFrom ? "revise" : "submit", { run: run5.sessionId, ...ids ? { stages: ids } : opts.reviseFrom ? { stageId: opts.reviseFrom } : { baseline: readPreviewBaseline(run5.sessionId), stageId: opts.stage } });
27751
+ const result = await previewBridge(name, ids ? "select" : opts.reviseFrom ? "revise" : "submit", { run: run5.sessionId, ...ids ? { stages: ids } : opts.reviseFrom ? { stageId: opts.reviseFrom } : { baseline: readPreviewBaseline(id, name, run5.sessionId), stageId: opts.stage } });
27703
27752
  if (result?.progress) {
27704
27753
  updatePreviewProgress(id, (all2) => {
27705
27754
  all2[name] = result.progress;
27706
27755
  });
27707
- if (result.baseline) savePreviewBaseline(run5.sessionId, result.baseline);
27756
+ if (result.baseline) savePreviewBaseline(id, name, run5.sessionId, result.baseline);
27708
27757
  } else if (opts.reviseFrom) {
27709
27758
  updatePreviewProgress(id, (all2) => {
27710
27759
  const progress = all2[name];
27711
27760
  choosePreviewRevision(progress, opts.reviseFrom, run5.sessionId);
27712
- savePreviewBaseline(run5.sessionId, previewBaseline(progress, opts.reviseFrom, run5.sessionId));
27761
+ savePreviewBaseline(id, name, run5.sessionId, previewBaseline(progress, opts.reviseFrom, run5.sessionId));
27713
27762
  });
27714
27763
  } else if (ids) {
27715
27764
  const selected = selectLocalPreview(id, name, ids);
27716
- savePreviewBaseline(run5.sessionId, selected.baseline);
27717
- } else submitLocalPreview(id, name, opts.stage, readPreviewBaseline(run5.sessionId));
27765
+ savePreviewBaseline(id, name, run5.sessionId, selected.baseline);
27766
+ } else submitLocalPreview(id, name, opts.stage, readPreviewBaseline(id, name, run5.sessionId));
27718
27767
  if (ids || opts.reviseFrom) say(previewStagePrompt(id, name, boardCommandFor(id)));
27719
27768
  else say("Preview stage submitted. Stop here; the program controls confirmation and continuation.");
27720
27769
  return { specAgent: name, cardId: id, submitted: !!opts.submit };
@@ -27739,7 +27788,14 @@ async function cmdSpec(opts, program2 = "akb") {
27739
27788
  { kind: "spec-agent-recursion", specAgent: name }
27740
27789
  );
27741
27790
  }
27742
- if (opts.print === true) return printFlow(req, program2);
27791
+ if (opts.print === true) {
27792
+ try {
27793
+ await activatePreviewRun(id, name, void 0, notes);
27794
+ } catch (error) {
27795
+ die(error instanceof Error ? error.message : "Could not prepare the preview.", { kind: "preview-refused" });
27796
+ }
27797
+ return printFlow(req, program2);
27798
+ }
27743
27799
  const live = readRuns().find(
27744
27800
  (r2) => r2.status === "running" && r2.action === "spec" && r2.cardId === id && r2.specAgent === name
27745
27801
  );
@@ -44443,7 +44499,7 @@ var require_react_dom_server_legacy_node_development = __commonJS({
44443
44499
  numberOfReRenders = 0;
44444
44500
  workInProgressHook = renderPhaseUpdates = null;
44445
44501
  }
44446
- function readContext(context) {
44502
+ function readContext2(context) {
44447
44503
  isInHookUserCodeInDev && console.error(
44448
44504
  "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()."
44449
44505
  );
@@ -48796,7 +48852,7 @@ A.finished.finally(function(){document.__reactViewTransition===A&&(document.__re
48796
48852
  }, emptyTreeContext = { id: 1, overflow: "" }, clz32 = Math.clz32 ? Math.clz32 : clz32Fallback, log = Math.log, LN2 = Math.LN2, currentTaskInDEV = null, SuspenseException = Error(
48797
48853
  "Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary, or call the promise's `.catch` method and pass the result to `use`."
48798
48854
  ), suspendedThenable = null, shouldCaptureSuspendedCallSite = false, suspendedCallSiteStack = null, suspendedCallSiteDebugTask = null, objectIs = "function" === typeof Object.is ? Object.is : is, currentlyRenderingComponent = null, currentlyRenderingTask = null, currentlyRenderingRequest = null, currentlyRenderingKeyPath = null, firstWorkInProgressHook = null, workInProgressHook = null, isReRender = false, didScheduleRenderPhaseUpdate = false, localIdCounter = 0, actionStateCounter = 0, actionStateMatchingIndex = -1, thenableIndexCounter = 0, thenableState = null, renderPhaseUpdates = null, numberOfReRenders = 0, isInHookUserCodeInDev = false, currentHookNameInDev, HooksDispatcher = {
48799
- readContext,
48855
+ readContext: readContext2,
48800
48856
  use: function(usable) {
48801
48857
  if (null !== usable && "object" === typeof usable) {
48802
48858
  if ("function" === typeof usable.then)
@@ -48804,7 +48860,7 @@ A.finished.finally(function(){document.__reactViewTransition===A&&(document.__re
48804
48860
  if (usable.$$typeof === REACT_RECOVERABLE_TYPE)
48805
48861
  throw createRecoverableError(usable);
48806
48862
  if (usable.$$typeof === REACT_CONTEXT_TYPE)
48807
- return readContext(usable);
48863
+ return readContext2(usable);
48808
48864
  }
48809
48865
  throw Error(
48810
48866
  "An unsupported type was passed to use(): " + String(usable)
@@ -52012,7 +52068,7 @@ var require_react_dom_server_node_development = __commonJS({
52012
52068
  numberOfReRenders = 0;
52013
52069
  workInProgressHook = renderPhaseUpdates = null;
52014
52070
  }
52015
- function readContext(context) {
52071
+ function readContext2(context) {
52016
52072
  isInHookUserCodeInDev && console.error(
52017
52073
  "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()."
52018
52074
  );
@@ -56745,7 +56801,7 @@ A.finished.finally(function(){document.__reactViewTransition===A&&(document.__re
56745
56801
  }, emptyTreeContext = { id: 1, overflow: "" }, clz32 = Math.clz32 ? Math.clz32 : clz32Fallback, log = Math.log, LN2 = Math.LN2, currentTaskInDEV = null, SuspenseException = Error(
56746
56802
  "Suspense Exception: This is not a real error! It's an implementation detail of `use` to interrupt the current render. You must either rethrow it immediately, or move the `use` call outside of the `try/catch` block. Capturing without rethrowing will lead to unexpected behavior.\n\nTo handle async errors, wrap your component in an error boundary, or call the promise's `.catch` method and pass the result to `use`."
56747
56803
  ), suspendedThenable = null, shouldCaptureSuspendedCallSite = false, suspendedCallSiteStack = null, suspendedCallSiteDebugTask = null, objectIs = "function" === typeof Object.is ? Object.is : is, currentlyRenderingComponent = null, currentlyRenderingTask = null, currentlyRenderingRequest = null, currentlyRenderingKeyPath = null, firstWorkInProgressHook = null, workInProgressHook = null, isReRender = false, didScheduleRenderPhaseUpdate = false, localIdCounter = 0, actionStateCounter = 0, actionStateMatchingIndex = -1, thenableIndexCounter = 0, thenableState = null, renderPhaseUpdates = null, numberOfReRenders = 0, isInHookUserCodeInDev = false, currentHookNameInDev, HooksDispatcher = {
56748
- readContext,
56804
+ readContext: readContext2,
56749
56805
  use: function(usable) {
56750
56806
  if (null !== usable && "object" === typeof usable) {
56751
56807
  if ("function" === typeof usable.then)
@@ -56753,7 +56809,7 @@ A.finished.finally(function(){document.__reactViewTransition===A&&(document.__re
56753
56809
  if (usable.$$typeof === REACT_RECOVERABLE_TYPE)
56754
56810
  throw createRecoverableError(usable);
56755
56811
  if (usable.$$typeof === REACT_CONTEXT_TYPE)
56756
- return readContext(usable);
56812
+ return readContext2(usable);
56757
56813
  }
56758
56814
  throw Error(
56759
56815
  "An unsupported type was passed to use(): " + String(usable)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wildcrane",
3
- "version": "0.11.56",
3
+ "version": "0.11.57",
4
4
  "akbContract": 15,
5
5
  "description": "WildCrane's `akb` command — scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
6
6
  "keywords": [