wildcrane-runner 0.6.59 → 0.6.60

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.46 — built by runner/scripts/build.mjs. Do not edit.
2
+ // ai4kanban 0.11.48 — 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;
@@ -866,8 +866,8 @@ function planDeliveryGap(card) {
866
866
  if (card.questions.length > 0) return "questions";
867
867
  if (!planDeliverables(card.body).length) return "deliverable";
868
868
  if (!/^[ \t]*[-*]\s+\[[xX]\].*`[^`]+`/m.test(card.body)) return "command";
869
- const { total, done: done2 } = card.todos;
870
- return total > 0 && done2 === total ? null : "todos";
869
+ const { total, done } = card.todos;
870
+ return total > 0 && done === total ? null : "todos";
871
871
  }
872
872
  function awaitingApproval(card) {
873
873
  const { stages, stage } = card;
@@ -878,11 +878,11 @@ function byDispatchOrder(a, b) {
878
878
  return rank(LEVEL_RANK, a.priority) - rank(LEVEL_RANK, b.priority) || a.id - b.id;
879
879
  }
880
880
  function canRefine(card) {
881
- if (card.isGroup) return false;
882
881
  if (awaitingApproval(card)) return false;
883
- if (card.status !== "todo" && !planUnfinished(card)) return false;
884
- const { total, done: done2 } = card.todos;
885
- if (total > 0 && done2 === total && !planUnfinished(card)) return false;
882
+ const unfinished = !card.isGroup && planUnfinished(card);
883
+ if (card.status !== "todo" && !unfinished) return false;
884
+ const { total, done } = card.todos;
885
+ if (total > 0 && done === total && !unfinished) return false;
886
886
  if (card.questions.length > 0 && card.questions.every(hasOptions)) return false;
887
887
  return true;
888
888
  }
@@ -1660,10 +1660,10 @@ async function taskCreate(request2, opts) {
1660
1660
  say(`Created ${task.key}: ${task.title} ${taskUrl(task.key)}`);
1661
1661
  return { ...task };
1662
1662
  }
1663
- async function act(id, route2, body, done2) {
1663
+ async function act(id, route2, body, done) {
1664
1664
  const ref = await taskRef(id);
1665
1665
  const value = await cloud("POST", `/v1/tasks/${enc(ref)}/${route2}`, body);
1666
- say(done2(ref));
1666
+ say(done(ref));
1667
1667
  return value;
1668
1668
  }
1669
1669
  async function taskApprove(id, comment) {
@@ -1684,9 +1684,9 @@ async function taskUpdateQuestions(id, typed) {
1684
1684
  let changes;
1685
1685
  let open3;
1686
1686
  try {
1687
- const done2 = applyQuestionOps(questions, ops);
1688
- changes = done2.changes;
1689
- open3 = done2.questions.length;
1687
+ const done = applyQuestionOps(questions, ops);
1688
+ changes = done.changes;
1689
+ open3 = done.questions.length;
1690
1690
  } catch (e) {
1691
1691
  if (e instanceof QuestionOpError) die(`${ref}: ${e.message}`);
1692
1692
  throw e;
@@ -1797,9 +1797,9 @@ function subtaskLines(body) {
1797
1797
  const m = line.match(/^[ \t]*[-*]\s+\[( |x|X)\]\s*(.*)$/);
1798
1798
  if (!m || !/#\d+/.test(m[2])) continue;
1799
1799
  total++;
1800
- const done2 = /[xX]/.test(m[1]);
1801
- if (done2) ticked++;
1802
- if (done2 || /~~[\s\S]*~~/.test(m[2])) resolved2++;
1800
+ const done = /[xX]/.test(m[1]);
1801
+ if (done) ticked++;
1802
+ if (done || /~~[\s\S]*~~/.test(m[2])) resolved2++;
1803
1803
  }
1804
1804
  return { total, resolved: resolved2, ticked };
1805
1805
  }
@@ -1858,8 +1858,8 @@ var init_leaving = __esm({
1858
1858
  // ../cli/src/lib/board/assemble.ts
1859
1859
  function countTodos(body) {
1860
1860
  const matches = body.match(/^[ \t]*[-*]\s+\[( |x|X)\]/gm) || [];
1861
- const done2 = matches.filter((l) => /\[[xX]\]/.test(l)).length;
1862
- return { total: matches.length, done: done2 };
1861
+ const done = matches.filter((l) => /\[[xX]\]/.test(l)).length;
1862
+ return { total: matches.length, done };
1863
1863
  }
1864
1864
  function attachBlockers(cards) {
1865
1865
  const byId = new Map(cards.map((c) => [c.id, c]));
@@ -2772,8 +2772,8 @@ import fs16 from "node:fs";
2772
2772
  import os4 from "node:os";
2773
2773
  import path17 from "node:path";
2774
2774
  function versionIn(output) {
2775
- const plain2 = output.replace(/\x1b\[[0-9;]*m/g, "");
2776
- return /(?<![\w.-])v?(\d+(?:\.\d+)+(?:-[0-9A-Za-z.-]+)?)/.exec(plain2)?.[1] ?? null;
2775
+ const plain = output.replace(/\x1b\[[0-9;]*m/g, "");
2776
+ return /(?<![\w.-])v?(\d+(?:\.\d+)+(?:-[0-9A-Za-z.-]+)?)/.exec(plain)?.[1] ?? null;
2777
2777
  }
2778
2778
  function compareVersions(a, b) {
2779
2779
  const [numberA = "", ...restA] = a.split("-");
@@ -3562,10 +3562,10 @@ function findRollout(threadId) {
3562
3562
  }
3563
3563
  for (const name of names3) {
3564
3564
  if (!name.startsWith("rollout-") || !name.endsWith(tail)) continue;
3565
- const path86 = join(dir, name);
3565
+ const path85 = join(dir, name);
3566
3566
  try {
3567
- const at = statSync(path86).mtimeMs;
3568
- if (!newest2 || at > newest2.at) newest2 = { path: path86, at };
3567
+ const at = statSync(path85).mtimeMs;
3568
+ if (!newest2 || at > newest2.at) newest2 = { path: path85, at };
3569
3569
  } catch {
3570
3570
  }
3571
3571
  }
@@ -3573,11 +3573,11 @@ function findRollout(threadId) {
3573
3573
  return newest2?.path;
3574
3574
  }
3575
3575
  function readCodexRunFacts(threadId) {
3576
- const path86 = findRollout(threadId);
3577
- if (!path86) return void 0;
3576
+ const path85 = findRollout(threadId);
3577
+ if (!path85) return void 0;
3578
3578
  let raw;
3579
3579
  try {
3580
- raw = readFileSync(path86, "utf8");
3580
+ raw = readFileSync(path85, "utf8");
3581
3581
  } catch {
3582
3582
  return void 0;
3583
3583
  }
@@ -3705,8 +3705,8 @@ function renderCompleted(item) {
3705
3705
  const changes = Array.isArray(item.changes) ? item.changes : [];
3706
3706
  return changes.map((raw) => {
3707
3707
  const change2 = obj(raw);
3708
- const path86 = str(change2.path);
3709
- return path86 ? `\u23FA ${str(change2.kind) || "change"}(${path86})
3708
+ const path85 = str(change2.path);
3709
+ return path85 ? `\u23FA ${str(change2.kind) || "change"}(${path85})
3710
3710
  ` : "";
3711
3711
  }).join("");
3712
3712
  }
@@ -3753,10 +3753,10 @@ function callResult(item) {
3753
3753
  }
3754
3754
  return "";
3755
3755
  }
3756
- function itemEvents(events, started, item, done2) {
3756
+ function itemEvents(events, started, item, done) {
3757
3757
  const id = str(item.id);
3758
3758
  if (item.type === "agent_message") {
3759
- if (done2) events.message(imageSafeText(str(item.text)));
3759
+ if (done) events.message(imageSafeText(str(item.text)));
3760
3760
  return;
3761
3761
  }
3762
3762
  if (item.type === "todo_list") {
@@ -3765,7 +3765,7 @@ function itemEvents(events, started, item, done2) {
3765
3765
  return;
3766
3766
  }
3767
3767
  if (item.type === "error") {
3768
- if (done2) events.log(`${str(item.message)}
3768
+ if (done) events.log(`${str(item.message)}
3769
3769
  `);
3770
3770
  return;
3771
3771
  }
@@ -3776,7 +3776,7 @@ function itemEvents(events, started, item, done2) {
3776
3776
  const call2 = callOf(item);
3777
3777
  events.toolCall(id, call2.title, kind, call2.target);
3778
3778
  }
3779
- if (done2) {
3779
+ if (done) {
3780
3780
  const failed = item.status === "failed" || typeof item.exit_code === "number" && item.exit_code !== 0;
3781
3781
  events.toolResult(id, failed ? "failed" : "completed", callResult(item));
3782
3782
  }
@@ -3794,9 +3794,9 @@ function createCodexStreamRenderer(carried = false) {
3794
3794
  const background = createBackgroundTasks();
3795
3795
  const subagents = /* @__PURE__ */ new Set();
3796
3796
  const collabItems = /* @__PURE__ */ new Set();
3797
- const collab = (item, done2) => {
3797
+ const collab = (item, done) => {
3798
3798
  if (item.type !== "collab_tool_call") return;
3799
- const key = `${str(item.id)}:${done2}`;
3799
+ const key = `${str(item.id)}:${done}`;
3800
3800
  if (collabItems.has(key)) return;
3801
3801
  collabItems.add(key);
3802
3802
  for (const [id, raw] of Object.entries(obj(item.agents_states))) {
@@ -4013,10 +4013,10 @@ function readKimiRunFacts(sessionId) {
4013
4013
  const total = { input: 0, cacheCreation: 0, cacheRead: 0, output: 0 };
4014
4014
  let model;
4015
4015
  let holding = 0;
4016
- for (const { path: path86, main } of wireFiles(entry.sessionDir)) {
4016
+ for (const { path: path85, main } of wireFiles(entry.sessionDir)) {
4017
4017
  let raw;
4018
4018
  try {
4019
- raw = readFileSync2(path86, "utf8");
4019
+ raw = readFileSync2(path85, "utf8");
4020
4020
  } catch {
4021
4021
  continue;
4022
4022
  }
@@ -4256,6 +4256,7 @@ function connect(stdout, stdin, onCall, dialect = {}) {
4256
4256
  });
4257
4257
  stdout.on("close", () => closed2("the agent closed the connection"));
4258
4258
  stdout.on("error", (err) => closed2(String(err)));
4259
+ stdin.on("error", (err) => closed2(String(err)));
4259
4260
  return {
4260
4261
  /** Ask the agent something. Rejects with the agent's own words when it says no. */
4261
4262
  call(method, params) {
@@ -4354,8 +4355,8 @@ var init_package = __esm({
4354
4355
  "../cli/package.json"() {
4355
4356
  package_default = {
4356
4357
  name: "wildcrane",
4357
- version: "0.11.46",
4358
- akbContract: 12,
4358
+ version: "0.11.48",
4359
+ akbContract: 13,
4359
4360
  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.",
4360
4361
  keywords: [
4361
4362
  "kanban",
@@ -4431,8 +4432,8 @@ var init_version = __esm({
4431
4432
  import fs17 from "node:fs";
4432
4433
  function whereHint(update2, title) {
4433
4434
  const locations = Array.isArray(update2.locations) ? update2.locations : [];
4434
- const path86 = str(obj(locations[0]).path);
4435
- return path86 && !title.includes(path86) ? hint(path86) : "";
4435
+ const path85 = str(obj(locations[0]).path);
4436
+ return path85 && !title.includes(path85) ? hint(path85) : "";
4436
4437
  }
4437
4438
  function saidBy(update2) {
4438
4439
  const content = Array.isArray(update2.content) ? update2.content : [];
@@ -4606,15 +4607,15 @@ async function oneTurn(io, options) {
4606
4607
  currentSession = sessionId;
4607
4608
  live = true;
4608
4609
  phase("submitted");
4609
- const done2 = await rpc.call("session/prompt", {
4610
+ const done = await rpc.call("session/prompt", {
4610
4611
  sessionId,
4611
4612
  prompt: [{ type: "text", text: prompt }]
4612
4613
  });
4613
4614
  const result = tail.end();
4614
4615
  events.end();
4615
- const stopReason2 = str(done2.stopReason);
4616
- const spent = obj(obj(done2._meta).usage);
4617
- const usage3 = usageOf2(done2.usage) ?? usageOf2(spent, true);
4616
+ const stopReason2 = str(done.stopReason);
4617
+ const spent = obj(obj(done._meta).usage);
4618
+ const usage3 = usageOf2(done.usage) ?? usageOf2(spent, true);
4618
4619
  costUsd ??= ticksUsd(spent.costUsdTicks);
4619
4620
  if (stopReason2 && stopReason2 !== "end_turn") {
4620
4621
  const why2 = STOPPED[stopReason2] ?? `the agent stopped: ${stopReason2}`;
@@ -4898,12 +4899,12 @@ async function oneTurn2(io, options) {
4898
4899
  live = true;
4899
4900
  const accepted = await rpc.call("session/send", { sessionId, content: io.prompt });
4900
4901
  if (accepted.accepted === false) throw new Error("the agent would not take the prompt");
4901
- const done2 = await finished;
4902
- const result = tail.end() || done2.response || void 0;
4903
- const usage3 = done2.usage ?? await tokensOf(rpc, sessionId);
4902
+ const done = await finished;
4903
+ const result = tail.end() || done.response || void 0;
4904
+ const usage3 = done.usage ?? await tokensOf(rpc, sessionId);
4904
4905
  const context = await contextOf(rpc, sessionId);
4905
- if (!done2.ok) {
4906
- const why2 = done2.error ?? "the agent stopped without saying why";
4906
+ if (!done.ok) {
4907
+ const why2 = done.error ?? "the agent stopped without saying why";
4907
4908
  stopped(io, why2);
4908
4909
  return { ok: false, result, error: why2, usage: usage3, context };
4909
4910
  }
@@ -5084,7 +5085,7 @@ async function run(io, options, tasks) {
5084
5085
  let model;
5085
5086
  let provider;
5086
5087
  let resolve2;
5087
- const done2 = new Promise((r) => {
5088
+ const done = new Promise((r) => {
5088
5089
  resolve2 = r;
5089
5090
  });
5090
5091
  const deadline = createBackgroundWait(BACKGROUND_WAIT.minutes * 6e4, () => end2(backgroundWaitMessage(BACKGROUND_WAIT.minutes)));
@@ -5181,7 +5182,7 @@ async function run(io, options, tasks) {
5181
5182
  startupTimer = setTimeout(() => {
5182
5183
  if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
5183
5184
  }, CONVERSATION_MS.start);
5184
- await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path86) => ({ type: "localImage", path: path86 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
5185
+ await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text4 }, ...images.map((path85) => ({ type: "localImage", path: path85 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
5185
5186
  if (!started) throw error;
5186
5187
  });
5187
5188
  };
@@ -5341,7 +5342,7 @@ async function run(io, options, tasks) {
5341
5342
  } catch (e) {
5342
5343
  end2(e instanceof Error ? e.message : String(e));
5343
5344
  }
5344
- return done2;
5345
+ return done;
5345
5346
  }
5346
5347
  var list;
5347
5348
  var init_codex = __esm({
@@ -9740,8 +9741,8 @@ var init_file_limits = __esm({
9740
9741
  });
9741
9742
 
9742
9743
  // ../cli/src/lib/shared/board-files.ts
9743
- function studioRenamed(path86, content) {
9744
- const to = path86.replace(/^(rules\/)?workflows\//, "$1studios/").replace(/^(studios\/[^/]+)\/WORKFLOW\.md$/, "$1/STUDIO.md");
9744
+ function studioRenamed(path85, content) {
9745
+ const to = path85.replace(/^(rules\/)?workflows\//, "$1studios/").replace(/^(studios\/[^/]+)\/WORKFLOW\.md$/, "$1/STUDIO.md");
9745
9746
  if (!to.endsWith(".md")) return { path: to, content };
9746
9747
  if (to.startsWith("studios/")) return { path: to, content: content.replace(/^(icon:\s*["']?)workflow(-kit)?(["']?\s*)$/gm, "$1studio$2$3") };
9747
9748
  const front = /^(?:todo|triage)\//.test(to) ? /^---\r?\n[\s\S]*?\r?\n---/.exec(content)?.[0] : void 0;
@@ -9750,15 +9751,13 @@ function studioRenamed(path86, content) {
9750
9751
  const renamed = front.replace(/^workflow:[ \t]*(.*)$/m, (_, id) => `studio: ${id === "workflow-builder" ? "studio-builder" : id}`);
9751
9752
  return { path: to, content: renamed + body };
9752
9753
  }
9753
- var cardSlug, studioFolder, studioName, draftFolder;
9754
+ var studioFolder, studioName;
9754
9755
  var init_board_files = __esm({
9755
9756
  "../cli/src/lib/shared/board-files.ts"() {
9756
9757
  "use strict";
9757
9758
  init_file_limits();
9758
- cardSlug = (task) => task.toLowerCase().replace(/_/g, "-");
9759
9759
  studioFolder = (id) => id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
9760
9760
  studioName = (id) => id.startsWith("wf_builtin_") ? id.slice("wf_builtin_".length).replace(/_/g, "-") : studioFolder(id);
9761
- draftFolder = (task) => cardSlug(task);
9762
9761
  }
9763
9762
  });
9764
9763
 
@@ -10079,15 +10078,6 @@ var init_parse = __esm({
10079
10078
  });
10080
10079
 
10081
10080
  // ../cli/src/lib/agent/studio-def.ts
10082
- function agentLines2(agents, indent2) {
10083
- return agents.flatMap(
10084
- (h) => !h.extra && !h.off ? [`${indent2}- ${scalar(h.agent)}`] : [
10085
- `${indent2}- agent: ${scalar(h.agent)}`,
10086
- ...h.extra ? [`${indent2} extra: ${JSON.stringify(h.extra)}`] : [],
10087
- ...h.off ? [`${indent2} off: true`] : []
10088
- ]
10089
- );
10090
- }
10091
10081
  function readAgent(item) {
10092
10082
  const row = typeof item === "string" ? { agent: item } : box(item);
10093
10083
  const agent = canonicalSpecAgent(text3(row.agent));
@@ -10170,7 +10160,7 @@ function parseStudioFile(id, source, from) {
10170
10160
  }
10171
10161
  };
10172
10162
  }
10173
- var scalar, plain, flowList, groupLines, STUDIO_ID, OLD_KEYS, box, text3, readGroup;
10163
+ var STUDIO_ID, OLD_KEYS, box, text3, readGroup;
10174
10164
  var init_studio_def = __esm({
10175
10165
  "../cli/src/lib/agent/studio-def.ts"() {
10176
10166
  "use strict";
@@ -10179,10 +10169,6 @@ var init_studio_def = __esm({
10179
10169
  init_yaml2();
10180
10170
  init_spec_agent_names();
10181
10171
  init_yaml();
10182
- scalar = (value) => /\s#/.test(value) ? JSON.stringify(value) : yamlScalar(value);
10183
- plain = (agents) => agents.every((h) => !h.extra && !h.off);
10184
- flowList = (agents) => `[${agents.map((h) => scalar(h.agent)).join(", ")}]`;
10185
- groupLines = (key, agents) => !agents.length ? [] : plain(agents) ? [`${key}: ${flowList(agents)}`] : [`${key}:`, ...agentLines2(agents, " ")];
10186
10172
  STUDIO_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
10187
10173
  OLD_KEYS = ["stages", "delivers", "helpers", "every"];
10188
10174
  box = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
@@ -10225,6 +10211,15 @@ var init_studio_diagram = __esm({
10225
10211
  });
10226
10212
 
10227
10213
  // ../cli/src/lib/shared/studio-files.ts
10214
+ function diagramFrom(files) {
10215
+ const read3 = parseStudioFile("studio", files[STUDIO_FILE] ?? "", STUDIO_FILE);
10216
+ if ("problem" in read3) return null;
10217
+ return studioDiagram(read3.def, (name) => {
10218
+ const text4 = files[`agents/${name}/AGENT.md`];
10219
+ const parsed = text4 === void 0 ? null : parseSpecAgent(text4, name, () => null, false);
10220
+ return parsed && "agent" in parsed ? parsed.agent : null;
10221
+ });
10222
+ }
10228
10223
  function folderPath(file, top) {
10229
10224
  const parts = file.split("/");
10230
10225
  if (parts.length < 3 || parts[0] !== top || !AGENT_NAME.test(parts[1])) return null;
@@ -10829,84 +10824,23 @@ var init_catalog = __esm({
10829
10824
  });
10830
10825
 
10831
10826
  // ../cli/src/lib/agent/studio-file.ts
10832
- import fs32 from "node:fs";
10833
- import path36 from "node:path";
10834
- function studioFileText(def) {
10835
- const lines = ["---", `name: ${scalar(def.name)}`];
10836
- const names3 = Object.entries(def.names ?? {});
10837
- if (names3.length) lines.push("names:", ...names3.map(([lang, said2]) => ` ${lang}: ${scalar(said2)}`));
10838
- if (def.description) lines.push(`description: ${scalar(def.description)}`);
10839
- if (def.when) lines.push(`when: ${scalar(def.when)}`);
10840
- lines.push(`needsArtifact: ${def.needsArtifact}`);
10841
- lines.push(...groupLines("previews", def.previews), ...groupLines("land", def.land));
10842
- if (def.memoryFiles?.workspace.length) lines.push("memoryFiles:", ` workspace: [${def.memoryFiles.workspace.map(scalar).join(", ")}]`);
10843
- if (def.scheduled.length) {
10844
- lines.push("scheduled:");
10845
- for (const s of def.scheduled) {
10846
- lines.push(` - agent: ${scalar(s.agent)}`);
10847
- if (s.cadence) lines.push(` cadence: ${scalar(s.cadence)}`);
10848
- }
10849
- }
10850
- lines.push("---");
10851
- return `${lines.join("\n")}
10852
- ${def.rules ? `
10853
- ${def.rules}
10854
- ` : ""}`;
10855
- }
10856
- function draftId() {
10857
- const task = workspaceTask();
10858
- if (!task) return null;
10859
- const id = draftFolder(task);
10860
- return fs32.existsSync(fileOf(id)) ? id : null;
10861
- }
10862
- function readFolder(id, problems) {
10863
- let source;
10864
- try {
10865
- source = fs32.readFileSync(fileOf(id), "utf8");
10866
- } catch {
10867
- problems.push(`${rel(fileOf(id))} is missing`);
10868
- return null;
10869
- }
10870
- const read3 = parseStudioFile(id, source, rel(fileOf(id)));
10871
- if ("problem" in read3) {
10872
- problems.push(read3.problem);
10873
- return null;
10874
- }
10875
- return read3.def;
10876
- }
10877
10827
  function boardStudioDefs() {
10878
- const problems = [];
10879
- const defs = cloudFlows().filter((f) => !f.builtIn).map((f) => f.def);
10880
- const draft = draftId();
10881
- const mine = draft ? readFolder(draft, problems) : null;
10882
- return { defs: mine ? [...defs, mine] : defs, problems };
10883
- }
10884
- function writeStudioDef(def) {
10885
- const file = fileOf(def.id);
10886
- fs32.mkdirSync(path36.dirname(file), { recursive: true });
10887
- fs32.writeFileSync(file, studioFileText(def));
10888
- forgetFileMemos();
10828
+ return { defs: cloudFlows().filter((f) => !f.builtIn).map((f) => f.def), problems: [] };
10889
10829
  }
10890
- var STUDIO_FILE2, builtinDefs, fileOf;
10830
+ var builtinDefs;
10891
10831
  var init_studio_file = __esm({
10892
10832
  "../cli/src/lib/agent/studio-file.ts"() {
10893
10833
  "use strict";
10894
- init_file_memo();
10895
- init_board_files();
10896
- init_tasks();
10897
- init_paths();
10898
10834
  init_cloud_studios();
10899
10835
  init_studio_def();
10900
10836
  init_studio_def();
10901
- STUDIO_FILE2 = "STUDIO.md";
10902
10837
  builtinDefs = () => cloudFlows().filter((f) => f.builtIn).map((f) => f.def);
10903
- fileOf = (id) => path36.join(STUDIOS, id, STUDIO_FILE2);
10904
10838
  }
10905
10839
  });
10906
10840
 
10907
10841
  // ../cli/src/lib/agent/studios.ts
10908
- import fs33 from "node:fs";
10909
- import path37 from "node:path";
10842
+ import fs32 from "node:fs";
10843
+ import path36 from "node:path";
10910
10844
  function studioPurpose(flow) {
10911
10845
  if (flow.builtIn) return builtinDescription(flow.id) || flow.name;
10912
10846
  return boardStudioDefs().defs.find((d) => d.id === flow.id)?.description || flow.name;
@@ -10980,7 +10914,7 @@ function previewStages(flow, chosen) {
10980
10914
  }
10981
10915
  function userStudioRules(flow) {
10982
10916
  try {
10983
- return fs33.readFileSync(studioRuleFile(flow.id), "utf8").trim();
10917
+ return fs32.readFileSync(studioRuleFile(flow.id), "utf8").trim();
10984
10918
  } catch {
10985
10919
  return "";
10986
10920
  }
@@ -11032,25 +10966,6 @@ function landRefused(flow, agent, found2) {
11032
10966
  keys: keys.join(",")
11033
10967
  });
11034
10968
  }
11035
- function writeDraft(def, settings) {
11036
- try {
11037
- writeStudioDef(def);
11038
- } catch (e) {
11039
- const why2 = e instanceof Error ? e.message : String(e);
11040
- return { ok: false, ...refusal("fileWrite", `couldn't write the "${def.name}" studio: ${why2}`, { path: def.id, details: why2 }) };
11041
- }
11042
- return settings ? save2(settings) : { ok: true };
11043
- }
11044
- function renameStudio(id, name) {
11045
- const draft = draftId();
11046
- if (!draft) return readOnly();
11047
- if (id !== draft) return { ok: false, ...refusal("studioReadOnly", `only the draft, \`${draft}\`, is renamed here`, { id }) };
11048
- const wanted = trimmedName(name);
11049
- if (!wanted) return { ok: false, ...refusal("studioUnnamed", "a studio needs a name") };
11050
- if (nameTaken(wanted, id)) return { ok: false, ...refusal("studioTaken", `this workspace already has a studio called "${wanted}"`, { name: wanted }) };
11051
- const def = draftDef(id);
11052
- return def ? writeDraft({ ...def, name: wanted }) : notFound(id);
11053
- }
11054
10969
  function elsewhere(agent, id) {
11055
10970
  const owner = agentStudio(agent);
11056
10971
  if (!owner || owner === id) return null;
@@ -11115,8 +11030,8 @@ function cardMeta(id) {
11115
11030
  try {
11116
11031
  const found2 = locate(id) ?? locateArchived(id);
11117
11032
  if (!found2) return null;
11118
- const file = found2.kind === "group" ? path37.join(found2.target, "root.md") : found2.target;
11119
- return parseFrontmatter(fs33.readFileSync(file, "utf8")).meta;
11033
+ const file = found2.kind === "group" ? path36.join(found2.target, "root.md") : found2.target;
11034
+ return parseFrontmatter(fs32.readFileSync(file, "utf8")).meta;
11120
11035
  } catch {
11121
11036
  return null;
11122
11037
  }
@@ -11133,7 +11048,7 @@ function frozenStudio(id) {
11133
11048
  land: landAgents(flow).map(row)
11134
11049
  };
11135
11050
  }
11136
- var builtinDescription, studiosBlock, storedStages, SCHEDULE, toRow, scheduledRow, studioFileProblems, allListed, resolved, agentAfter, agentKeyProblems, agentStudio, studios, studioById, onBoard, previewMembers, previewAgents, landAgents, archivesOnApproval, studioRuleFile, save2, draftDef, notFound, readOnly, trimmedName, nameTaken, scheduledAgent, cardStudioId, cardStages, cardStage;
11051
+ var builtinDescription, studiosBlock, storedStages, SCHEDULE, toRow, scheduledRow, studioFileProblems, allListed, resolved, agentAfter, agentKeyProblems, agentStudio, studios, studioById, onBoard, previewMembers, previewAgents, landAgents, archivesOnApproval, studioRuleFile, save2, notFound, scheduledAgent, cardStudioId, cardStages, cardStage;
11137
11052
  var init_studios = __esm({
11138
11053
  "../cli/src/lib/agent/studios.ts"() {
11139
11054
  "use strict";
@@ -11206,18 +11121,14 @@ var init_studios = __esm({
11206
11121
  previewAgents = (flow) => previewMembers(flow).filter((h) => !h.off);
11207
11122
  landAgents = (flow) => flow.land.filter((h) => !h.off);
11208
11123
  archivesOnApproval = (flow) => !!flow && !landAgents(flow).length;
11209
- studioRuleFile = (id) => path37.join(RULES, "studios", `${id}.md`);
11124
+ studioRuleFile = (id) => path36.join(RULES, "studios", `${id}.md`);
11210
11125
  save2 = (change2) => writeConfig((cfg) => {
11211
11126
  const block = configBlock(cfg.studios);
11212
11127
  change2(block);
11213
11128
  if (Object.keys(block).length === 0) delete cfg.studios;
11214
11129
  else cfg.studios = block;
11215
11130
  });
11216
- draftDef = (id) => boardStudioDefs().defs.find((d) => d.id === id);
11217
11131
  notFound = (id) => ({ ok: false, ...refusal("studioNotFound", `this board has no \`${id}\` studio`, { id }) });
11218
- readOnly = () => ({ ok: false, ...refusal("studioReadOnly", "Only a Studio builder draft is renamed here; change a studio with `akb studio pull` and `push`.") });
11219
- trimmedName = (name) => name.replace(/\s+/g, " ").trim();
11220
- nameTaken = (name, except = "") => studios().some((w) => w.id !== except && trimmedName(w.name).toLowerCase() === trimmedName(name).toLowerCase());
11221
11132
  scheduledAgent = (id, agent) => {
11222
11133
  const flow = studioById(id);
11223
11134
  return flow ? scheduledMembers(flow).find((h) => h.agent === canonicalSpecAgent(agent.trim())) : void 0;
@@ -11229,11 +11140,11 @@ var init_studios = __esm({
11229
11140
  });
11230
11141
 
11231
11142
  // ../cli/src/commands/goal.ts
11232
- import fs34 from "node:fs";
11143
+ import fs33 from "node:fs";
11233
11144
  function loadGoals() {
11234
11145
  const file = goalsFile();
11235
11146
  if (!file) die("Goals exist only inside a WildCrane goal discussion.");
11236
- const held4 = JSON.parse(fs34.readFileSync(file, "utf8"));
11147
+ const held4 = JSON.parse(fs33.readFileSync(file, "utf8"));
11237
11148
  if (held4.goals !== void 0 && held4.ideas !== void 0 && JSON.stringify(held4.goals) !== JSON.stringify(held4.ideas)) die("goals and ideas do not match.");
11238
11149
  const goals = held4.goals ?? held4.ideas;
11239
11150
  if (!Array.isArray(goals)) die("The goals array is missing or invalid.");
@@ -11263,7 +11174,7 @@ function splitBody2(text4) {
11263
11174
  }
11264
11175
  function readBody(bodyFile) {
11265
11176
  if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
11266
- const text4 = fs34.readFileSync(bodyFile, "utf8");
11177
+ const text4 = fs33.readFileSync(bodyFile, "utf8");
11267
11178
  if (!text4.trim()) die("The goal must not be empty.");
11268
11179
  return splitBody2(text4);
11269
11180
  }
@@ -11275,7 +11186,7 @@ function named(held4, id) {
11275
11186
  function cmdGoal(args, opts) {
11276
11187
  const sub = args[0] ?? "";
11277
11188
  const { file, held: held4 } = loadGoals();
11278
- const write2 = () => fs34.writeFileSync(file, `${JSON.stringify({ ...held4, goals: void 0, ideas: held4.goals }, null, 2)}
11189
+ const write2 = () => fs33.writeFileSync(file, `${JSON.stringify({ ...held4, goals: void 0, ideas: held4.goals }, null, 2)}
11279
11190
  `);
11280
11191
  if (sub === "new") {
11281
11192
  const title = opts.title?.trim();
@@ -11363,9 +11274,9 @@ var init_goal = __esm({
11363
11274
  });
11364
11275
 
11365
11276
  // ../cli/src/commands/goal-cloud.ts
11366
- import fs35 from "node:fs";
11277
+ import fs34 from "node:fs";
11367
11278
  import os5 from "node:os";
11368
- import path38 from "node:path";
11279
+ import path37 from "node:path";
11369
11280
  import crypto3 from "node:crypto";
11370
11281
  function hostSession() {
11371
11282
  const { CLAUDE_CODE_SESSION_ID: claude, CODEX_THREAD_ID: codex, CURSOR_CONVERSATION_ID: cursor, KIMI_SESSION_ID: kimi, WILDCRANE_DISCUSSION: discussion2 } = process.env;
@@ -11394,24 +11305,24 @@ function goalsOf(d) {
11394
11305
  async function discussion() {
11395
11306
  const session = hostSession();
11396
11307
  if (!session) die("Goals exist only inside a WildCrane goal discussion.");
11397
- const home3 = process.env.WILDCRANE_HOME || path38.join(os5.homedir(), ".wildcrane");
11308
+ const home3 = process.env.WILDCRANE_HOME || path37.join(os5.homedir(), ".wildcrane");
11398
11309
  process.env.AI4KANBAN_HOME ??= home3;
11399
11310
  if (session.host === "discussion") return request("GET", `/v1/discussions/${encodeURIComponent(session.id)}`);
11400
- const machineFile2 = path38.join(home3, "machine.json");
11311
+ const machineFile2 = path37.join(home3, "machine.json");
11401
11312
  let machine;
11402
11313
  try {
11403
- machine = JSON.parse(fs35.readFileSync(machineFile2, "utf8")).id;
11314
+ machine = JSON.parse(fs34.readFileSync(machineFile2, "utf8")).id;
11404
11315
  } catch {
11405
11316
  machine = crypto3.randomUUID();
11406
- fs35.mkdirSync(home3, { recursive: true });
11407
- fs35.writeFileSync(machineFile2, JSON.stringify({ id: machine }));
11317
+ fs34.mkdirSync(home3, { recursive: true });
11318
+ fs34.writeFileSync(machineFile2, JSON.stringify({ id: machine }));
11408
11319
  }
11409
11320
  const held4 = await request("GET", `/v1/runner/folders?machine=${encodeURIComponent(machine)}`);
11410
- const cwd = fs35.realpathSync(process.cwd());
11321
+ const cwd = fs34.realpathSync(process.cwd());
11411
11322
  const folder = held4.folders.filter((f) => {
11412
11323
  try {
11413
- const dir = fs35.realpathSync(f.path);
11414
- return cwd === dir || cwd.startsWith(dir + path38.sep);
11324
+ const dir = fs34.realpathSync(f.path);
11325
+ return cwd === dir || cwd.startsWith(dir + path37.sep);
11415
11326
  } catch {
11416
11327
  return false;
11417
11328
  }
@@ -11420,16 +11331,16 @@ async function discussion() {
11420
11331
  }
11421
11332
  async function withGoalDiscussion(action, save3 = false) {
11422
11333
  const d = await discussion();
11423
- const dir = fs35.mkdtempSync(path38.join(os5.tmpdir(), "akb-goals-"));
11424
- const file = path38.join(dir, "goals.json");
11334
+ const dir = fs34.mkdtempSync(path37.join(os5.tmpdir(), "akb-goals-"));
11335
+ const file = path37.join(dir, "goals.json");
11425
11336
  const before = process.env.KANBAN_GOALS;
11426
11337
  try {
11427
11338
  const previous = goalsOf(d);
11428
- fs35.writeFileSync(file, JSON.stringify({ workspace: d.workspace, studios: await studios2(d.workspace), ideas: previous.map((g) => ({ ...g, task: typeof g.task === "object" && g.task ? g.task.id : g.task })) }));
11339
+ fs34.writeFileSync(file, JSON.stringify({ workspace: d.workspace, studios: await studios2(d.workspace), ideas: previous.map((g) => ({ ...g, task: typeof g.task === "object" && g.task ? g.task.id : g.task })) }));
11429
11340
  process.env.KANBAN_GOALS = file;
11430
11341
  const result = save3 ? await quietlyAsync(async () => action()) : await action();
11431
11342
  if (save3) {
11432
- const goals = JSON.parse(fs35.readFileSync(file, "utf8")).ideas;
11343
+ const goals = JSON.parse(fs34.readFileSync(file, "utf8")).ideas;
11433
11344
  const saved = await request("PUT", `/v1/discussions/${d.id}/draft`, { expectedVersion: d.version, goals: goals.filter((g) => !g.dropped) });
11434
11345
  const savedGoals = goalsOf(saved);
11435
11346
  const fresh = goals.filter((g) => !g.dropped && !previous.some((p) => p.id === g.id));
@@ -11448,7 +11359,7 @@ async function withGoalDiscussion(action, save3 = false) {
11448
11359
  } finally {
11449
11360
  if (before === void 0) delete process.env.KANBAN_GOALS;
11450
11361
  else process.env.KANBAN_GOALS = before;
11451
- fs35.rmSync(dir, { recursive: true, force: true });
11362
+ fs34.rmSync(dir, { recursive: true, force: true });
11452
11363
  }
11453
11364
  }
11454
11365
  async function queryPreviews(studio, workspace2) {
@@ -11480,9 +11391,9 @@ var init_goal_cloud = __esm({
11480
11391
  }
11481
11392
  });
11482
11393
 
11483
- // ../cli/node_modules/commander/lib/error.js
11394
+ // ../../work/cli/node_modules/commander/lib/error.js
11484
11395
  var require_error = __commonJS({
11485
- "../cli/node_modules/commander/lib/error.js"(exports) {
11396
+ "../../work/cli/node_modules/commander/lib/error.js"(exports) {
11486
11397
  var CommanderError2 = class extends Error {
11487
11398
  /**
11488
11399
  * Constructs the CommanderError class
@@ -11515,9 +11426,9 @@ var require_error = __commonJS({
11515
11426
  }
11516
11427
  });
11517
11428
 
11518
- // ../cli/node_modules/commander/lib/argument.js
11429
+ // ../../work/cli/node_modules/commander/lib/argument.js
11519
11430
  var require_argument = __commonJS({
11520
- "../cli/node_modules/commander/lib/argument.js"(exports) {
11431
+ "../../work/cli/node_modules/commander/lib/argument.js"(exports) {
11521
11432
  var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
11522
11433
  var Argument2 = class {
11523
11434
  /**
@@ -11642,9 +11553,9 @@ var require_argument = __commonJS({
11642
11553
  }
11643
11554
  });
11644
11555
 
11645
- // ../cli/node_modules/commander/lib/help.js
11556
+ // ../../work/cli/node_modules/commander/lib/help.js
11646
11557
  var require_help = __commonJS({
11647
- "../cli/node_modules/commander/lib/help.js"(exports) {
11558
+ "../../work/cli/node_modules/commander/lib/help.js"(exports) {
11648
11559
  var { humanReadableArgName } = require_argument();
11649
11560
  var Help2 = class {
11650
11561
  constructor() {
@@ -12211,9 +12122,9 @@ ${itemIndentStr}`);
12211
12122
  }
12212
12123
  });
12213
12124
 
12214
- // ../cli/node_modules/commander/lib/option.js
12125
+ // ../../work/cli/node_modules/commander/lib/option.js
12215
12126
  var require_option = __commonJS({
12216
- "../cli/node_modules/commander/lib/option.js"(exports) {
12127
+ "../../work/cli/node_modules/commander/lib/option.js"(exports) {
12217
12128
  var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
12218
12129
  var Option2 = class {
12219
12130
  /**
@@ -12512,9 +12423,9 @@ var require_option = __commonJS({
12512
12423
  }
12513
12424
  });
12514
12425
 
12515
- // ../cli/node_modules/commander/lib/suggestSimilar.js
12426
+ // ../../work/cli/node_modules/commander/lib/suggestSimilar.js
12516
12427
  var require_suggestSimilar = __commonJS({
12517
- "../cli/node_modules/commander/lib/suggestSimilar.js"(exports) {
12428
+ "../../work/cli/node_modules/commander/lib/suggestSimilar.js"(exports) {
12518
12429
  var maxDistance = 3;
12519
12430
  function editDistance2(a, b) {
12520
12431
  if (Math.abs(a.length - b.length) > maxDistance)
@@ -12592,13 +12503,13 @@ var require_suggestSimilar = __commonJS({
12592
12503
  }
12593
12504
  });
12594
12505
 
12595
- // ../cli/node_modules/commander/lib/command.js
12506
+ // ../../work/cli/node_modules/commander/lib/command.js
12596
12507
  var require_command = __commonJS({
12597
- "../cli/node_modules/commander/lib/command.js"(exports) {
12508
+ "../../work/cli/node_modules/commander/lib/command.js"(exports) {
12598
12509
  var EventEmitter = __require("node:events").EventEmitter;
12599
12510
  var childProcess = __require("node:child_process");
12600
- var path86 = __require("node:path");
12601
- var fs88 = __require("node:fs");
12511
+ var path85 = __require("node:path");
12512
+ var fs87 = __require("node:fs");
12602
12513
  var process2 = __require("node:process");
12603
12514
  var { Argument: Argument2, humanReadableArgName } = require_argument();
12604
12515
  var { CommanderError: CommanderError2 } = require_error();
@@ -13579,7 +13490,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
13579
13490
  * @param {string} subcommandName
13580
13491
  */
13581
13492
  _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
13582
- if (fs88.existsSync(executableFile)) return;
13493
+ if (fs87.existsSync(executableFile)) return;
13583
13494
  const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
13584
13495
  const executableMissing = `'${executableFile}' does not exist
13585
13496
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
@@ -13597,11 +13508,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
13597
13508
  let launchWithNode = false;
13598
13509
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
13599
13510
  function findFile(baseDir, baseName) {
13600
- const localBin = path86.resolve(baseDir, baseName);
13601
- if (fs88.existsSync(localBin)) return localBin;
13602
- if (sourceExt.includes(path86.extname(baseName))) return void 0;
13511
+ const localBin = path85.resolve(baseDir, baseName);
13512
+ if (fs87.existsSync(localBin)) return localBin;
13513
+ if (sourceExt.includes(path85.extname(baseName))) return void 0;
13603
13514
  const foundExt = sourceExt.find(
13604
- (ext) => fs88.existsSync(`${localBin}${ext}`)
13515
+ (ext) => fs87.existsSync(`${localBin}${ext}`)
13605
13516
  );
13606
13517
  if (foundExt) return `${localBin}${foundExt}`;
13607
13518
  return void 0;
@@ -13613,21 +13524,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
13613
13524
  if (this._scriptPath) {
13614
13525
  let resolvedScriptPath;
13615
13526
  try {
13616
- resolvedScriptPath = fs88.realpathSync(this._scriptPath);
13527
+ resolvedScriptPath = fs87.realpathSync(this._scriptPath);
13617
13528
  } catch {
13618
13529
  resolvedScriptPath = this._scriptPath;
13619
13530
  }
13620
- executableDir = path86.resolve(
13621
- path86.dirname(resolvedScriptPath),
13531
+ executableDir = path85.resolve(
13532
+ path85.dirname(resolvedScriptPath),
13622
13533
  executableDir
13623
13534
  );
13624
13535
  }
13625
13536
  if (executableDir) {
13626
13537
  let localFile = findFile(executableDir, executableFile);
13627
13538
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
13628
- const legacyName = path86.basename(
13539
+ const legacyName = path85.basename(
13629
13540
  this._scriptPath,
13630
- path86.extname(this._scriptPath)
13541
+ path85.extname(this._scriptPath)
13631
13542
  );
13632
13543
  if (legacyName !== this._name) {
13633
13544
  localFile = findFile(
@@ -13638,7 +13549,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
13638
13549
  }
13639
13550
  executableFile = localFile || executableFile;
13640
13551
  }
13641
- launchWithNode = sourceExt.includes(path86.extname(executableFile));
13552
+ launchWithNode = sourceExt.includes(path85.extname(executableFile));
13642
13553
  let proc;
13643
13554
  if (process2.platform !== "win32") {
13644
13555
  if (launchWithNode) {
@@ -14485,7 +14396,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
14485
14396
  * @return {Command}
14486
14397
  */
14487
14398
  nameFromFilename(filename) {
14488
- this._name = path86.basename(filename, path86.extname(filename));
14399
+ this._name = path85.basename(filename, path85.extname(filename));
14489
14400
  return this;
14490
14401
  }
14491
14402
  /**
@@ -14499,9 +14410,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
14499
14410
  * @param {string} [path]
14500
14411
  * @return {(string|null|Command)}
14501
14412
  */
14502
- executableDir(path87) {
14503
- if (path87 === void 0) return this._executableDir;
14504
- this._executableDir = path87;
14413
+ executableDir(path86) {
14414
+ if (path86 === void 0) return this._executableDir;
14415
+ this._executableDir = path86;
14505
14416
  return this;
14506
14417
  }
14507
14418
  /**
@@ -14751,9 +14662,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
14751
14662
  }
14752
14663
  });
14753
14664
 
14754
- // ../cli/node_modules/commander/index.js
14665
+ // ../../work/cli/node_modules/commander/index.js
14755
14666
  var require_commander = __commonJS({
14756
- "../cli/node_modules/commander/index.js"(exports) {
14667
+ "../../work/cli/node_modules/commander/index.js"(exports) {
14757
14668
  var { Argument: Argument2 } = require_argument();
14758
14669
  var { Command: Command2 } = require_command();
14759
14670
  var { CommanderError: CommanderError2, InvalidArgumentError: InvalidArgumentError2 } = require_error();
@@ -14773,10 +14684,10 @@ var require_commander = __commonJS({
14773
14684
  }
14774
14685
  });
14775
14686
 
14776
- // ../cli/node_modules/commander/esm.mjs
14687
+ // ../../work/cli/node_modules/commander/esm.mjs
14777
14688
  var import_index, program, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help;
14778
14689
  var init_esm = __esm({
14779
- "../cli/node_modules/commander/esm.mjs"() {
14690
+ "../../work/cli/node_modules/commander/esm.mjs"() {
14780
14691
  import_index = __toESM(require_commander(), 1);
14781
14692
  ({
14782
14693
  program,
@@ -14798,11 +14709,11 @@ var init_esm = __esm({
14798
14709
  });
14799
14710
 
14800
14711
  // ../cli/src/lib/cloud/pointer.ts
14801
- import fs36 from "node:fs";
14802
- import path39 from "node:path";
14712
+ import fs35 from "node:fs";
14713
+ import path38 from "node:path";
14803
14714
  function hasRetiredPointer(root2) {
14804
14715
  try {
14805
- const held4 = JSON.parse(fs36.readFileSync(path39.join(root2, POINTER_FILE), "utf8"));
14716
+ const held4 = JSON.parse(fs35.readFileSync(path38.join(root2, POINTER_FILE), "utf8"));
14806
14717
  return typeof held4.workspace === "string" && held4.workspace.trim() !== "";
14807
14718
  } catch {
14808
14719
  return false;
@@ -14817,39 +14728,39 @@ var init_pointer = __esm({
14817
14728
  });
14818
14729
 
14819
14730
  // ../cli/src/lib/card-studio-backfill.ts
14820
- import fs37 from "node:fs";
14821
- import path40 from "node:path";
14731
+ import fs36 from "node:fs";
14732
+ import path39 from "node:path";
14822
14733
  function renameToStudio() {
14823
14734
  if (!KANBAN || !BOARD_STATE) return;
14824
- const mark = path40.join(BOARD_STATE, RENAMED);
14735
+ const mark = path39.join(BOARD_STATE, RENAMED);
14825
14736
  try {
14826
- if (fs37.existsSync(mark)) return;
14827
- for (const [from, to] of [[path40.join(KANBAN, "workflows"), STUDIOS], [path40.join(RULES, "workflows"), path40.join(RULES, "studios")]]) {
14828
- if (fs37.existsSync(from) && !fs37.existsSync(to)) fs37.renameSync(from, to);
14737
+ if (fs36.existsSync(mark)) return;
14738
+ for (const [from, to] of [[path39.join(KANBAN, "workflows"), STUDIOS], [path39.join(RULES, "workflows"), path39.join(RULES, "studios")]]) {
14739
+ if (fs36.existsSync(from) && !fs36.existsSync(to)) fs36.renameSync(from, to);
14829
14740
  }
14830
- for (const file of [STUDIOS, TODO, TRIAGE].flatMap((dir) => fs37.existsSync(dir) ? walkMd(dir) : [])) {
14831
- const at = path40.relative(KANBAN, file).split(path40.sep).join("/");
14832
- const text4 = fs37.readFileSync(file, "utf8");
14741
+ for (const file of [STUDIOS, TODO, TRIAGE].flatMap((dir) => fs36.existsSync(dir) ? walkMd(dir) : [])) {
14742
+ const at = path39.relative(KANBAN, file).split(path39.sep).join("/");
14743
+ const text4 = fs36.readFileSync(file, "utf8");
14833
14744
  const to = studioRenamed(at, text4);
14834
14745
  if (to.path === at && to.content === text4) continue;
14835
- const target = path40.join(KANBAN, to.path);
14836
- if (target !== file && fs37.existsSync(target)) continue;
14837
- fs37.writeFileSync(target, to.content);
14838
- if (target !== file) fs37.rmSync(file);
14746
+ const target = path39.join(KANBAN, to.path);
14747
+ if (target !== file && fs36.existsSync(target)) continue;
14748
+ fs36.writeFileSync(target, to.content);
14749
+ if (target !== file) fs36.rmSync(file);
14839
14750
  }
14840
- fs37.mkdirSync(BOARD_STATE, { recursive: true });
14841
- fs37.writeFileSync(mark, "");
14751
+ fs36.mkdirSync(BOARD_STATE, { recursive: true });
14752
+ fs36.writeFileSync(mark, "");
14842
14753
  } catch {
14843
14754
  }
14844
14755
  }
14845
14756
  function backfillCardStudios() {
14846
14757
  renameToStudio();
14847
14758
  if (!TODO || !BOARD_STATE) return;
14848
- const mark = path40.join(BOARD_STATE, MARK);
14759
+ const mark = path39.join(BOARD_STATE, MARK);
14849
14760
  try {
14850
- if (fs37.existsSync(mark) || !fs37.existsSync(TODO)) return;
14761
+ if (fs36.existsSync(mark) || !fs36.existsSync(TODO)) return;
14851
14762
  for (const file of walkMd(TODO)) {
14852
- const text4 = fs37.readFileSync(file, "utf8");
14763
+ const text4 = fs36.readFileSync(file, "utf8");
14853
14764
  if (!text4.startsWith("---\n")) continue;
14854
14765
  const end2 = text4.indexOf("\n---", 3);
14855
14766
  if (end2 < 0) continue;
@@ -14857,11 +14768,11 @@ function backfillCardStudios() {
14857
14768
  if (!/\ntitle:/.test(head2) || /\nstudio:/.test(head2)) continue;
14858
14769
  const modules = /\nmodules:[^\n]*/.exec(head2);
14859
14770
  const at = modules ? modules.index + modules[0].length : end2;
14860
- fs37.writeFileSync(file, `${text4.slice(0, at)}
14771
+ fs36.writeFileSync(file, `${text4.slice(0, at)}
14861
14772
  studio: coding${text4.slice(at)}`);
14862
14773
  }
14863
- fs37.mkdirSync(BOARD_STATE, { recursive: true });
14864
- fs37.writeFileSync(mark, "");
14774
+ fs36.mkdirSync(BOARD_STATE, { recursive: true });
14775
+ fs36.writeFileSync(mark, "");
14865
14776
  } catch {
14866
14777
  }
14867
14778
  }
@@ -14878,11 +14789,11 @@ var init_card_studio_backfill = __esm({
14878
14789
  });
14879
14790
 
14880
14791
  // ../cli/src/lib/view/stamp.ts
14881
- import fs38 from "node:fs";
14882
- import path41 from "node:path";
14792
+ import fs37 from "node:fs";
14793
+ import path40 from "node:path";
14883
14794
  function boardStamp() {
14884
14795
  const parts = [];
14885
- for (const dir of [TODO, MEMORY, ASSETS, MOCKUPS, path41.join(KANBAN, ".mockups")]) walk(dir, parts, 0);
14796
+ for (const dir of [TODO, MEMORY, ASSETS, MOCKUPS, path40.join(KANBAN, ".mockups")]) walk(dir, parts, 0);
14886
14797
  for (const file of [MODULES_MD, ARCHIVE_MD, CONFIG]) {
14887
14798
  stamp2(file, parts);
14888
14799
  }
@@ -14892,19 +14803,19 @@ function walk(dir, parts, depth3) {
14892
14803
  if (depth3 > MAX_DEPTH) return;
14893
14804
  let entries;
14894
14805
  try {
14895
- entries = fs38.readdirSync(dir, { withFileTypes: true });
14806
+ entries = fs37.readdirSync(dir, { withFileTypes: true });
14896
14807
  } catch {
14897
14808
  return;
14898
14809
  }
14899
14810
  for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
14900
- const full = path41.join(dir, entry.name);
14811
+ const full = path40.join(dir, entry.name);
14901
14812
  if (entry.isDirectory()) walk(full, parts, depth3 + 1);
14902
14813
  else stamp2(full, parts);
14903
14814
  }
14904
14815
  }
14905
14816
  function stamp2(file, parts) {
14906
14817
  try {
14907
- const s = fs38.statSync(file);
14818
+ const s = fs37.statSync(file);
14908
14819
  parts.push(`${file}:${s.size}:${Math.round(s.mtimeMs)}`);
14909
14820
  } catch {
14910
14821
  }
@@ -14936,8 +14847,8 @@ var init_contract = __esm({
14936
14847
  });
14937
14848
 
14938
14849
  // ../cli/src/lib/board/revision.ts
14939
- import fs39 from "node:fs";
14940
- import path42 from "node:path";
14850
+ import fs38 from "node:fs";
14851
+ import path41 from "node:path";
14941
14852
  function revisionOf(text4) {
14942
14853
  let h = 2166136261;
14943
14854
  for (let i = 0; i < text4.length; i++) {
@@ -14949,13 +14860,13 @@ function revisionOf(text4) {
14949
14860
  function cardFile(id) {
14950
14861
  const found2 = locate(id);
14951
14862
  if (!found2) return null;
14952
- return found2.kind === "group" ? path42.join(found2.target, "root.md") : found2.target;
14863
+ return found2.kind === "group" ? path41.join(found2.target, "root.md") : found2.target;
14953
14864
  }
14954
14865
  function cardRevision(id) {
14955
14866
  const file = cardFile(id);
14956
14867
  if (!file) return NO_REVISION;
14957
14868
  try {
14958
- return revisionOf(fs39.readFileSync(file, "utf8"));
14869
+ return revisionOf(fs38.readFileSync(file, "utf8"));
14959
14870
  } catch {
14960
14871
  return NO_REVISION;
14961
14872
  }
@@ -14977,14 +14888,14 @@ var init_revision = __esm({
14977
14888
  });
14978
14889
 
14979
14890
  // ../cli/src/lib/plans.ts
14980
- import fs40 from "node:fs";
14981
- import path43 from "node:path";
14891
+ import fs39 from "node:fs";
14892
+ import path42 from "node:path";
14982
14893
  function planFile(rel2) {
14983
14894
  if (!/^plans\/(archive\/)?[^/\\]+\.md$/.test(rel2)) return null;
14984
14895
  const dir = isArchivedPlan(rel2) ? PLANS_ARCHIVE : PLANS;
14985
14896
  const name = rel2.replace(/^plans\/(archive\/)?/, "");
14986
14897
  if (!name || name.includes("/") || !name.endsWith(".md")) return null;
14987
- return path43.join(dir, name);
14898
+ return path42.join(dir, name);
14988
14899
  }
14989
14900
  function readPlan(rel2) {
14990
14901
  const file = planFile(rel2);
@@ -14992,12 +14903,12 @@ function readPlan(rel2) {
14992
14903
  let text4 = "";
14993
14904
  let found2 = rel2;
14994
14905
  try {
14995
- text4 = fs40.readFileSync(file, "utf8");
14906
+ text4 = fs39.readFileSync(file, "utf8");
14996
14907
  } catch {
14997
14908
  const moved = renamedPlan(rel2);
14998
14909
  if (moved) {
14999
14910
  found2 = moved;
15000
- text4 = fs40.readFileSync(planFile(moved), "utf8");
14911
+ text4 = fs39.readFileSync(planFile(moved), "utf8");
15001
14912
  }
15002
14913
  }
15003
14914
  return { path: found2, text: text4, lines: text4.trim() ? text4.trimEnd().split("\n").length : 0 };
@@ -15012,13 +14923,13 @@ function renamedPlan(rel2) {
15012
14923
  ]) {
15013
14924
  let names3;
15014
14925
  try {
15015
- names3 = fs40.readdirSync(dir);
14926
+ names3 = fs39.readdirSync(dir);
15016
14927
  } catch {
15017
14928
  continue;
15018
14929
  }
15019
14930
  for (const n of names3) {
15020
14931
  if (!n.startsWith(`${id}-`) || !n.endsWith(".md")) continue;
15021
- found2.push({ rel: `${prefix}${n}`, at: fs40.statSync(path43.join(dir, n)).mtimeMs });
14932
+ found2.push({ rel: `${prefix}${n}`, at: fs39.statSync(path42.join(dir, n)).mtimeMs });
15022
14933
  }
15023
14934
  }
15024
14935
  if (!found2.length) return null;
@@ -15027,7 +14938,7 @@ function renamedPlan(rel2) {
15027
14938
  function planFromText(text4) {
15028
14939
  const legacy2 = `${legacyProjectStateDir(KANBAN)}/`;
15029
14940
  if (text4.startsWith(legacy2)) text4 = text4.slice(legacy2.length);
15030
- const local = `${path43.dirname(PLANS)}/`;
14941
+ const local = `${path42.dirname(PLANS)}/`;
15031
14942
  if (text4.startsWith(local)) text4 = text4.slice(local.length);
15032
14943
  if (text4.startsWith(`${KANBAN}/`)) text4 = text4.slice(KANBAN.length + 1);
15033
14944
  const here = `${boardPath()}/`;
@@ -15155,23 +15066,23 @@ var init_telemetry_contract = __esm({
15155
15066
  });
15156
15067
 
15157
15068
  // ../cli/src/lib/agent/catalog.ts
15158
- import fs41 from "node:fs";
15159
- import path44 from "node:path";
15069
+ import fs40 from "node:fs";
15070
+ import path43 from "node:path";
15160
15071
  function cacheFile() {
15161
- return path44.join(machineHome(), "models-dev.json");
15072
+ return path43.join(machineHome(), "models-dev.json");
15162
15073
  }
15163
15074
  function readCache() {
15164
15075
  const file = cacheFile();
15165
15076
  let stamp4;
15166
15077
  try {
15167
- const stat = fs41.statSync(file);
15078
+ const stat = fs40.statSync(file);
15168
15079
  stamp4 = `${stat.mtimeMs}:${stat.size}`;
15169
15080
  } catch {
15170
15081
  return void 0;
15171
15082
  }
15172
15083
  if (held3?.stamp === stamp4) return held3.cached;
15173
15084
  try {
15174
- const data = JSON.parse(fs41.readFileSync(file, "utf8"));
15085
+ const data = JSON.parse(fs40.readFileSync(file, "utf8"));
15175
15086
  if (!data || typeof data.limits !== "object" || !data.limits) return void 0;
15176
15087
  const cached2 = {
15177
15088
  fetchedAt: typeof data.fetchedAt === "number" ? data.fetchedAt : 0,
@@ -15209,8 +15120,8 @@ function refreshCatalog() {
15209
15120
  const limits = limitsIn(await answer2.json());
15210
15121
  if (Object.keys(limits).length === 0) return;
15211
15122
  const file = cacheFile();
15212
- fs41.mkdirSync(path44.dirname(file), { recursive: true });
15213
- fs41.writeFileSync(file, JSON.stringify({ fetchedAt: Date.now(), limits }));
15123
+ fs40.mkdirSync(path43.dirname(file), { recursive: true });
15124
+ fs40.writeFileSync(file, JSON.stringify({ fetchedAt: Date.now(), limits }));
15214
15125
  } catch {
15215
15126
  }
15216
15127
  })();
@@ -15273,8 +15184,8 @@ var init_catalog2 = __esm({
15273
15184
  });
15274
15185
 
15275
15186
  // ../cli/src/lib/machine/telemetry.ts
15276
- import fs42 from "node:fs";
15277
- import path45 from "node:path";
15187
+ import fs41 from "node:fs";
15188
+ import path44 from "node:path";
15278
15189
  import { randomUUID as randomUUID2 } from "node:crypto";
15279
15190
  function readUsageReporting() {
15280
15191
  const { unreadable, values } = heldSettings();
@@ -15308,8 +15219,8 @@ function write(on, disclosed) {
15308
15219
  if (!on) patch2.usageInstallId = void 0;
15309
15220
  const saved = saveSettings(patch2);
15310
15221
  if (saved.ok && !on) {
15311
- fs42.rmSync(usageQueueFile(), { force: true });
15312
- fs42.rmSync(usageStateFile(), { force: true });
15222
+ fs41.rmSync(usageQueueFile(), { force: true });
15223
+ fs41.rmSync(usageStateFile(), { force: true });
15313
15224
  }
15314
15225
  return saved;
15315
15226
  }
@@ -15319,14 +15230,14 @@ var init_telemetry = __esm({
15319
15230
  "use strict";
15320
15231
  init_home();
15321
15232
  init_settings2();
15322
- usageQueueFile = () => path45.join(machineHome(), "usage-queue.jsonl");
15323
- usageStateFile = () => path45.join(machineHome(), "usage-state.json");
15233
+ usageQueueFile = () => path44.join(machineHome(), "usage-queue.jsonl");
15234
+ usageStateFile = () => path44.join(machineHome(), "usage-state.json");
15324
15235
  }
15325
15236
  });
15326
15237
 
15327
15238
  // ../cli/src/lib/machine/usage.ts
15328
- import fs43 from "node:fs";
15329
- import path46 from "node:path";
15239
+ import fs42 from "node:fs";
15240
+ import path45 from "node:path";
15330
15241
  import { randomUUID as randomUUID3 } from "node:crypto";
15331
15242
  function usageSurface() {
15332
15243
  return process.env.KANBAN_DESKTOP === "1" ? "app" : "command";
@@ -15403,15 +15314,15 @@ function endFields({ model, costUsd, ownEndpoint }) {
15403
15314
  }
15404
15315
  function readBoard() {
15405
15316
  try {
15406
- const held4 = JSON.parse(fs43.readFileSync(boardFile(), "utf8"));
15317
+ const held4 = JSON.parse(fs42.readFileSync(boardFile(), "utf8"));
15407
15318
  return held4 && typeof held4 === "object" ? held4 : {};
15408
15319
  } catch {
15409
15320
  return {};
15410
15321
  }
15411
15322
  }
15412
15323
  function writeBoard(state) {
15413
- fs43.mkdirSync(BOARD_STATE, { recursive: true });
15414
- fs43.writeFileSync(boardFile(), `${JSON.stringify(state)}
15324
+ fs42.mkdirSync(BOARD_STATE, { recursive: true });
15325
+ fs42.writeFileSync(boardFile(), `${JSON.stringify(state)}
15415
15326
  `);
15416
15327
  }
15417
15328
  function countBoardEvent(name, n = 1) {
@@ -15455,7 +15366,7 @@ function reportBoardNumbers(customAgentsOn2) {
15455
15366
  function readQueue(day = usageDay()) {
15456
15367
  let text4;
15457
15368
  try {
15458
- text4 = fs43.readFileSync(usageQueueFile(), "utf8");
15369
+ text4 = fs42.readFileSync(usageQueueFile(), "utf8");
15459
15370
  } catch {
15460
15371
  return [];
15461
15372
  }
@@ -15477,8 +15388,8 @@ function readQueue(day = usageDay()) {
15477
15388
  }
15478
15389
  function append(event2) {
15479
15390
  const file = usageQueueFile();
15480
- fs43.mkdirSync(machineHome(), { recursive: true, mode: 448 });
15481
- fs43.appendFileSync(file, `${JSON.stringify(event2)}
15391
+ fs42.mkdirSync(machineHome(), { recursive: true, mode: 448 });
15392
+ fs42.appendFileSync(file, `${JSON.stringify(event2)}
15482
15393
  `);
15483
15394
  const queued = readQueue();
15484
15395
  if (queued.length > QUEUE_MAX) writeQueue(queued.slice(queued.length - QUEUE_MAX));
@@ -15486,14 +15397,14 @@ function append(event2) {
15486
15397
  function writeQueue(events) {
15487
15398
  const file = usageQueueFile();
15488
15399
  if (!events.length) {
15489
- fs43.rmSync(file, { force: true });
15400
+ fs42.rmSync(file, { force: true });
15490
15401
  return;
15491
15402
  }
15492
- fs43.mkdirSync(machineHome(), { recursive: true, mode: 448 });
15403
+ fs42.mkdirSync(machineHome(), { recursive: true, mode: 448 });
15493
15404
  const tmp = `${file}.${process.pid}.tmp`;
15494
- fs43.writeFileSync(tmp, `${events.map((e) => JSON.stringify(e)).join("\n")}
15405
+ fs42.writeFileSync(tmp, `${events.map((e) => JSON.stringify(e)).join("\n")}
15495
15406
  `);
15496
- fs43.renameSync(tmp, file);
15407
+ fs42.renameSync(tmp, file);
15497
15408
  }
15498
15409
  function shiftDay(day, days) {
15499
15410
  const at = Date.parse(`${day}T00:00:00Z`);
@@ -15501,7 +15412,7 @@ function shiftDay(day, days) {
15501
15412
  }
15502
15413
  function readState() {
15503
15414
  try {
15504
- const parsed = JSON.parse(fs43.readFileSync(usageStateFile(), "utf8"));
15415
+ const parsed = JSON.parse(fs42.readFileSync(usageStateFile(), "utf8"));
15505
15416
  return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
15506
15417
  } catch {
15507
15418
  return {};
@@ -15509,12 +15420,12 @@ function readState() {
15509
15420
  }
15510
15421
  function writeState(state) {
15511
15422
  try {
15512
- fs43.mkdirSync(machineHome(), { recursive: true, mode: 448 });
15423
+ fs42.mkdirSync(machineHome(), { recursive: true, mode: 448 });
15513
15424
  const file = usageStateFile();
15514
15425
  const tmp = `${file}.${process.pid}.tmp`;
15515
- fs43.writeFileSync(tmp, `${JSON.stringify(state, null, 2)}
15426
+ fs42.writeFileSync(tmp, `${JSON.stringify(state, null, 2)}
15516
15427
  `);
15517
- fs43.renameSync(tmp, file);
15428
+ fs42.renameSync(tmp, file);
15518
15429
  } catch {
15519
15430
  return;
15520
15431
  }
@@ -15605,7 +15516,7 @@ var init_usage = __esm({
15605
15516
  "decisions_stood",
15606
15517
  "decisions_overruled"
15607
15518
  ];
15608
- boardFile = () => path46.join(BOARD_STATE, "usage-board.json");
15519
+ boardFile = () => path45.join(BOARD_STATE, "usage-board.json");
15609
15520
  countOf = (counts, name) => {
15610
15521
  const n = counts?.[name];
15611
15522
  return typeof n === "number" && Number.isInteger(n) && n > 0 ? n : 0;
@@ -15652,14 +15563,14 @@ var init_candidate = __esm({
15652
15563
  });
15653
15564
 
15654
15565
  // ../cli/src/lib/agent/outputs.ts
15655
- import fs44 from "node:fs";
15566
+ import fs43 from "node:fs";
15656
15567
  import os6 from "node:os";
15657
- import path47 from "node:path";
15568
+ import path46 from "node:path";
15658
15569
  function cardBody(cardId2) {
15659
15570
  const found2 = locate(cardId2) ?? locateArchived(cardId2);
15660
15571
  if (!found2) return "";
15661
15572
  try {
15662
- return fs44.readFileSync(found2.kind === "group" ? path47.join(found2.target, "root.md") : found2.target, "utf8");
15573
+ return fs43.readFileSync(found2.kind === "group" ? path46.join(found2.target, "root.md") : found2.target, "utf8");
15663
15574
  } catch {
15664
15575
  return "";
15665
15576
  }
@@ -15682,7 +15593,7 @@ function filesStop(delivery) {
15682
15593
  if (!outputs.length) {
15683
15594
  return { reason: "output", why: "the card records no output file", paths: [] };
15684
15595
  }
15685
- const missing = outputs.filter((f) => !fs44.existsSync(resolveOutput(f)));
15596
+ const missing = outputs.filter((f) => !fs43.existsSync(resolveOutput(f)));
15686
15597
  if (missing.length) {
15687
15598
  return { reason: "output", why: `recorded output files are missing: ${missing.join(", ")}`, paths: missing };
15688
15599
  }
@@ -15702,20 +15613,20 @@ var init_outputs = __esm({
15702
15613
  plannedTodos = (cardId2) => todos(cardId2).map((t) => t.text);
15703
15614
  looksLikePath = (token2) => !/\s/.test(token2) && !token2.includes("://") && !token2.startsWith("-") && token2.includes("/");
15704
15615
  resolveOutput = (file) => {
15705
- if (file.startsWith("~/")) return path47.join(os6.homedir(), file.slice(2));
15706
- if (path47.isAbsolute(file)) return file;
15707
- if (file.startsWith(".assets/")) return path47.join(ASSETS, file.slice(".assets/".length));
15708
- return path47.join(REPO_ROOT, file);
15616
+ if (file.startsWith("~/")) return path46.join(os6.homedir(), file.slice(2));
15617
+ if (path46.isAbsolute(file)) return file;
15618
+ if (file.startsWith(".assets/")) return path46.join(ASSETS, file.slice(".assets/".length));
15619
+ return path46.join(REPO_ROOT, file);
15709
15620
  };
15710
15621
  }
15711
15622
  });
15712
15623
 
15713
15624
  // ../cli/src/lib/agent/commit-mode.ts
15714
- import fs45 from "node:fs";
15625
+ import fs44 from "node:fs";
15715
15626
  function recordedIds() {
15716
15627
  try {
15717
15628
  return new Set(
15718
- fs45.readdirSync(DELIVERIES).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -".json".length))
15629
+ fs44.readdirSync(DELIVERIES).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -".json".length))
15719
15630
  );
15720
15631
  } catch {
15721
15632
  return /* @__PURE__ */ new Set();
@@ -15748,7 +15659,7 @@ var init_commit_mode = __esm({
15748
15659
  init_worktree();
15749
15660
  ID_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
15750
15661
  ID_LENGTH2 = 8;
15751
- deliveryCwd = (delivery) => delivery.worktree && fs45.existsSync(worktreeDir(delivery.worktree)) ? worktreeDir(delivery.worktree) : REPO_ROOT;
15662
+ deliveryCwd = (delivery) => delivery.worktree && fs44.existsSync(worktreeDir(delivery.worktree)) ? worktreeDir(delivery.worktree) : REPO_ROOT;
15752
15663
  }
15753
15664
  });
15754
15665
 
@@ -15929,12 +15840,12 @@ var init_runner = __esm({
15929
15840
  });
15930
15841
 
15931
15842
  // ../cli/src/lib/agent/rules.ts
15932
- import fs46 from "node:fs";
15933
- import path48 from "node:path";
15843
+ import fs45 from "node:fs";
15844
+ import path47 from "node:path";
15934
15845
  function ruleFile(agent) {
15935
15846
  if (!agent || hiddenRole(agent)) return "";
15936
15847
  try {
15937
- return fs46.readFileSync(rulePath(agent), "utf8").trim();
15848
+ return fs45.readFileSync(rulePath(agent), "utf8").trim();
15938
15849
  } catch {
15939
15850
  return "";
15940
15851
  }
@@ -15993,7 +15904,7 @@ function migrateFlowRules() {
15993
15904
  adoptRenamedRules();
15994
15905
  let here;
15995
15906
  try {
15996
- here = new Set(fs46.readdirSync(RULES));
15907
+ here = new Set(fs45.readdirSync(RULES));
15997
15908
  } catch {
15998
15909
  return [];
15999
15910
  }
@@ -16007,9 +15918,9 @@ function migrateFlowRules() {
16007
15918
  if (!from.length) continue;
16008
15919
  const parts = [ruleFile(owner.name), ...from.map(ruleFile)].filter(Boolean);
16009
15920
  try {
16010
- if (parts.length) fs46.writeFileSync(rulePath(owner.name), `${parts.join("\n\n")}
15921
+ if (parts.length) fs45.writeFileSync(rulePath(owner.name), `${parts.join("\n\n")}
16011
15922
  `);
16012
- for (const flow of from) fs46.rmSync(rulePath(flow), { force: true });
15923
+ for (const flow of from) fs45.rmSync(rulePath(flow), { force: true });
16013
15924
  } catch (err) {
16014
15925
  notes.push(`could not move the ${from.join(", ")} rule(s) onto \`${owner.name}\`: ${String(err)}`);
16015
15926
  continue;
@@ -16023,7 +15934,7 @@ function migrateFlowRules() {
16023
15934
  function adoptRenamedRules() {
16024
15935
  let here;
16025
15936
  try {
16026
- here = fs46.readdirSync(RULES);
15937
+ here = fs45.readdirSync(RULES);
16027
15938
  } catch {
16028
15939
  return;
16029
15940
  }
@@ -16033,13 +15944,13 @@ function adoptRenamedRules() {
16033
15944
  const now = RENAMED_ROLES[was] ?? canonicalSpecAgent(was);
16034
15945
  if (now === was) continue;
16035
15946
  try {
16036
- if (!fs46.existsSync(rulePath(now))) fs46.renameSync(rulePath(was), rulePath(now));
15947
+ if (!fs45.existsSync(rulePath(now))) fs45.renameSync(rulePath(was), rulePath(now));
16037
15948
  else if (FOLDED_SPEC_AGENTS.has(was)) {
16038
15949
  const kept2 = ruleFile(now);
16039
15950
  const carried = ruleFile(was);
16040
- if (carried && !kept2.includes(carried)) fs46.writeFileSync(rulePath(now), `${[kept2, carried].filter(Boolean).join("\n\n")}
15951
+ if (carried && !kept2.includes(carried)) fs45.writeFileSync(rulePath(now), `${[kept2, carried].filter(Boolean).join("\n\n")}
16041
15952
  `);
16042
- fs46.rmSync(rulePath(was), { force: true });
15953
+ fs45.rmSync(rulePath(was), { force: true });
16043
15954
  }
16044
15955
  } catch {
16045
15956
  }
@@ -16056,7 +15967,7 @@ var init_rules2 = __esm({
16056
15967
  init_runner();
16057
15968
  init_studios();
16058
15969
  init_types();
16059
- rulePath = (agent) => path48.join(RULES, `${agent}.md`);
15970
+ rulePath = (agent) => path47.join(RULES, `${agent}.md`);
16060
15971
  flowForRequest = (req) => req.refineRound !== void 0 && REFINE_ACTIONS.has(req.action) ? flowByCommand("refine") : flowByAction(req.action);
16061
15972
  ruleOwnerSays = (owner) => `\`${owner.name}\` agent carries one rule of its own${owner.role ? ", on every flow it runs" : ""}`;
16062
15973
  said = (owner, rule) => owner && rule ? [
@@ -16068,8 +15979,8 @@ var init_rules2 = __esm({
16068
15979
  });
16069
15980
 
16070
15981
  // ../cli/src/lib/agent/deliveries.ts
16071
- import fs47 from "node:fs";
16072
- import path49 from "node:path";
15982
+ import fs46 from "node:fs";
15983
+ import path48 from "node:path";
16073
15984
  function writeAudit(delivery, runs) {
16074
15985
  const known2 = new Map(readAudit(delivery.deliveryId)?.sessions.map((s) => [s.sessionId, s]) ?? []);
16075
15986
  const sessions = delivery.sessions.flatMap((id) => {
@@ -16097,10 +16008,10 @@ function writeAudit(delivery, runs) {
16097
16008
  }
16098
16009
  function writeAuditFile(record) {
16099
16010
  try {
16100
- fs47.mkdirSync(DELIVERIES, { recursive: true });
16011
+ fs46.mkdirSync(DELIVERIES, { recursive: true });
16101
16012
  const tmp = `${auditPath(record.deliveryId)}.tmp`;
16102
- fs47.writeFileSync(tmp, JSON.stringify(record, null, 2) + "\n");
16103
- fs47.renameSync(tmp, auditPath(record.deliveryId));
16013
+ fs46.writeFileSync(tmp, JSON.stringify(record, null, 2) + "\n");
16014
+ fs46.renameSync(tmp, auditPath(record.deliveryId));
16104
16015
  return true;
16105
16016
  } catch {
16106
16017
  return false;
@@ -16108,7 +16019,7 @@ function writeAuditFile(record) {
16108
16019
  }
16109
16020
  function readAudit(deliveryId) {
16110
16021
  try {
16111
- const data = JSON.parse(fs47.readFileSync(auditPath(deliveryId), "utf8"));
16022
+ const data = JSON.parse(fs46.readFileSync(auditPath(deliveryId), "utf8"));
16112
16023
  return { sessions: Array.isArray(data?.sessions) ? data.sessions : [] };
16113
16024
  } catch {
16114
16025
  return null;
@@ -16123,7 +16034,7 @@ function syncAudit(deliveryId, just) {
16123
16034
  }
16124
16035
  function wholeAudit(file) {
16125
16036
  try {
16126
- const data = JSON.parse(fs47.readFileSync(file, "utf8"));
16037
+ const data = JSON.parse(fs46.readFileSync(file, "utf8"));
16127
16038
  return typeof data?.deliveryId === "string" && Array.isArray(data.sessions) ? data : null;
16128
16039
  } catch {
16129
16040
  return null;
@@ -16136,14 +16047,14 @@ function activeAudit(file) {
16136
16047
  function allAudits() {
16137
16048
  let names3;
16138
16049
  try {
16139
- names3 = fs47.readdirSync(DELIVERIES);
16050
+ names3 = fs46.readdirSync(DELIVERIES);
16140
16051
  } catch {
16141
16052
  return [];
16142
16053
  }
16143
16054
  const out = [];
16144
16055
  for (const name of names3) {
16145
16056
  if (!name.endsWith(".json")) continue;
16146
- const audit = wholeAudit(path49.join(DELIVERIES, name));
16057
+ const audit = wholeAudit(path48.join(DELIVERIES, name));
16147
16058
  if (audit) out.push(audit);
16148
16059
  }
16149
16060
  return out;
@@ -16316,10 +16227,10 @@ function carryOnFrom(_deliveryId) {
16316
16227
  function approvedRequirements(cardId2) {
16317
16228
  const found2 = locate(cardId2);
16318
16229
  if (!found2) return "";
16319
- const file = found2.kind === "group" ? path49.join(found2.target, "root.md") : found2.target;
16230
+ const file = found2.kind === "group" ? path48.join(found2.target, "root.md") : found2.target;
16320
16231
  let text4;
16321
16232
  try {
16322
- text4 = fs47.readFileSync(file, "utf8");
16233
+ text4 = fs46.readFileSync(file, "utf8");
16323
16234
  } catch {
16324
16235
  return "";
16325
16236
  }
@@ -16349,8 +16260,8 @@ function cardMeta2(cardId2) {
16349
16260
  try {
16350
16261
  const found2 = locate(cardId2);
16351
16262
  if (!found2) return null;
16352
- const file = found2.kind === "group" ? path49.join(found2.target, "root.md") : found2.target;
16353
- return parseFrontmatter(fs47.readFileSync(file, "utf8")).meta;
16263
+ const file = found2.kind === "group" ? path48.join(found2.target, "root.md") : found2.target;
16264
+ return parseFrontmatter(fs46.readFileSync(file, "utf8")).meta;
16354
16265
  } catch {
16355
16266
  return null;
16356
16267
  }
@@ -16521,11 +16432,11 @@ var init_deliveries = __esm({
16521
16432
  init_types();
16522
16433
  init_worktree();
16523
16434
  init_lock();
16524
- auditPath = (deliveryId) => path49.join(DELIVERIES, `${deliveryId}.json`);
16435
+ auditPath = (deliveryId) => path48.join(DELIVERIES, `${deliveryId}.json`);
16525
16436
  activeAudits = () => allAudits().filter((a) => a.status === "active");
16526
16437
  auditRow = (audit) => readDeliveryRow({ ...audit, sessions: audit.sessions.map((s) => s.sessionId) });
16527
16438
  lastSessionRunning = (audit) => audit.sessions[audit.sessions.length - 1]?.status === "running";
16528
- localAudit = (audit) => worktreeExists(audit.worktree) || audit.sessions.some((session) => path49.resolve(REPO_ROOT, session.log) === logPathOf(session.sessionId) && fs47.existsSync(logPathOf(session.sessionId)));
16439
+ localAudit = (audit) => worktreeExists(audit.worktree) || audit.sessions.some((session) => path48.resolve(REPO_ROOT, session.log) === logPathOf(session.sessionId) && fs46.existsSync(logPathOf(session.sessionId)));
16529
16440
  unknownDelivery = (id) => refusal("deliveryNotFound", `no delivery here answers to "${id}"`, { id });
16530
16441
  isResumable = (delivery) => !resumeRefusal(delivery);
16531
16442
  APPROVED = [
@@ -16549,35 +16460,35 @@ var init_deliveries = __esm({
16549
16460
  });
16550
16461
 
16551
16462
  // ../cli/src/lib/agent/pictures.ts
16552
- import fs48 from "node:fs";
16553
- import path50 from "node:path";
16463
+ import fs47 from "node:fs";
16464
+ import path49 from "node:path";
16554
16465
  function claimRunPictures(box2, sessionId, names3 = []) {
16555
16466
  if (!box2 || !freeBox(box2) || names3.length === 0) return [];
16556
16467
  const from = pictureBox(box2);
16557
16468
  const to = pictureBox(sessionId);
16558
16469
  try {
16559
- fs48.mkdirSync(SESSIONS_DIR, { recursive: true });
16560
- fs48.renameSync(from, to);
16470
+ fs47.mkdirSync(SESSIONS_DIR, { recursive: true });
16471
+ fs47.renameSync(from, to);
16561
16472
  } catch {
16562
16473
  return [];
16563
16474
  }
16564
- return names3.filter(pictureName).map((name) => path50.join(to, name)).filter((file) => fs48.existsSync(file));
16475
+ return names3.filter(pictureName).map((name) => path49.join(to, name)).filter((file) => fs47.existsSync(file));
16565
16476
  }
16566
16477
  function returnRunPictures(sessionId, box2) {
16567
16478
  if (!box2 || !boxId(box2)) return;
16568
16479
  try {
16569
- fs48.renameSync(pictureBox(sessionId), pictureBox(box2));
16480
+ fs47.renameSync(pictureBox(sessionId), pictureBox(box2));
16570
16481
  } catch {
16571
16482
  }
16572
16483
  }
16573
16484
  function moveRunPictures(from, to, files = []) {
16574
16485
  if (files.length === 0) return [];
16575
16486
  try {
16576
- fs48.renameSync(pictureBox(from), pictureBox(to));
16487
+ fs47.renameSync(pictureBox(from), pictureBox(to));
16577
16488
  } catch {
16578
16489
  return files;
16579
16490
  }
16580
- return files.map((file) => path50.join(pictureBox(to), path50.basename(file)));
16491
+ return files.map((file) => path49.join(pictureBox(to), path49.basename(file)));
16581
16492
  }
16582
16493
  var pictureName, boxId, freeBox, pictureBox;
16583
16494
  var init_pictures = __esm({
@@ -16586,8 +16497,8 @@ var init_pictures = __esm({
16586
16497
  init_paths();
16587
16498
  pictureName = (name) => /^[0-9a-f-]{36}\.[a-z0-9]{2,5}$/.test(name);
16588
16499
  boxId = (box2) => /^[0-9a-f-]{36}$/.test(box2);
16589
- freeBox = (box2) => boxId(box2) && !fs48.existsSync(path50.join(SESSIONS_DIR, `${box2}.log`));
16590
- pictureBox = (box2) => path50.join(SESSIONS_DIR, `${box2}.images`);
16500
+ freeBox = (box2) => boxId(box2) && !fs47.existsSync(path49.join(SESSIONS_DIR, `${box2}.log`));
16501
+ pictureBox = (box2) => path49.join(SESSIONS_DIR, `${box2}.images`);
16591
16502
  }
16592
16503
  });
16593
16504
 
@@ -16685,8 +16596,8 @@ var init_components = __esm({
16685
16596
  });
16686
16597
 
16687
16598
  // ../cli/src/lib/memories.ts
16688
- import fs49 from "node:fs";
16689
- import path51 from "node:path";
16599
+ import fs48 from "node:fs";
16600
+ import path50 from "node:path";
16690
16601
  function readMemory(text4, builtIn, folder) {
16691
16602
  const { meta, body } = splitFrontmatter(text4);
16692
16603
  if (meta === null) return null;
@@ -16706,7 +16617,7 @@ function readMemory(text4, builtIn, folder) {
16706
16617
  rules: body.trim(),
16707
16618
  text: text4,
16708
16619
  builtIn,
16709
- dir: path51.join(MEMORY, folder)
16620
+ dir: path50.join(MEMORY, folder)
16710
16621
  };
16711
16622
  }
16712
16623
  function globalMemories() {
@@ -16717,14 +16628,14 @@ function globalMemories() {
16717
16628
  }
16718
16629
  let folders2 = [];
16719
16630
  try {
16720
- folders2 = fs49.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
16631
+ folders2 = fs48.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
16721
16632
  } catch {
16722
16633
  }
16723
16634
  for (const name of folders2) {
16724
16635
  if (name in BUNDLED_MEMORY_FILES || name === RESERVED_MEMORY_DIR || name === STUDIO_MEMORY_DIR) continue;
16725
- const file = path51.join(MEMORY, name, GLOBAL_MEMORY_FILE);
16726
- if (!fs49.existsSync(file)) continue;
16727
- const memory = readMemory(fs49.readFileSync(file, "utf8"), false, name);
16636
+ const file = path50.join(MEMORY, name, GLOBAL_MEMORY_FILE);
16637
+ if (!fs48.existsSync(file)) continue;
16638
+ const memory = readMemory(fs48.readFileSync(file, "utf8"), false, name);
16728
16639
  if (memory) out.push(memory);
16729
16640
  }
16730
16641
  return out;
@@ -16780,16 +16691,16 @@ var init_facts = __esm({
16780
16691
  });
16781
16692
 
16782
16693
  // ../cli/src/lib/view/archive.ts
16783
- import fs50 from "node:fs";
16784
- import path52 from "node:path";
16694
+ import fs49 from "node:fs";
16695
+ import path51 from "node:path";
16785
16696
  function archivedId(file) {
16786
- const own = idPrefix(path52.basename(file));
16787
- return own !== null ? own : idPrefix(path52.basename(path52.dirname(file)));
16697
+ const own = idPrefix(path51.basename(file));
16698
+ return own !== null ? own : idPrefix(path51.basename(path51.dirname(file)));
16788
16699
  }
16789
16700
  function readFile(file) {
16790
16701
  const id = archivedId(file);
16791
16702
  if (id === null) return null;
16792
- const { meta, body } = parseFrontmatter(fs50.readFileSync(file, "utf8"));
16703
+ const { meta, body } = parseFrontmatter(fs49.readFileSync(file, "utf8"));
16793
16704
  if (!meta) return null;
16794
16705
  return {
16795
16706
  row: {
@@ -16797,15 +16708,15 @@ function readFile(file) {
16797
16708
  title: meta.title,
16798
16709
  archived: meta.archived,
16799
16710
  rejected: meta.rejected,
16800
- relPath: rel(file).split(path52.sep).join("/")
16711
+ relPath: rel(file).split(path51.sep).join("/")
16801
16712
  },
16802
16713
  body: body.replace(/^\n+/, "").replace(/\s+$/, ""),
16803
16714
  meta
16804
16715
  };
16805
16716
  }
16806
16717
  function readArchive() {
16807
- const relPath = rel(ARCHIVE).split(path52.sep).join("/");
16808
- if (!fs50.existsSync(ARCHIVE)) return { relPath, cards: [] };
16718
+ const relPath = rel(ARCHIVE).split(path51.sep).join("/");
16719
+ if (!fs49.existsSync(ARCHIVE)) return { relPath, cards: [] };
16809
16720
  const cards = walkMd(ARCHIVE).map(readFile).filter((found2) => found2 !== null).map((found2) => found2.row);
16810
16721
  cards.sort((a, b) => b.id - a.id);
16811
16722
  return { relPath, cards };
@@ -16820,31 +16731,24 @@ var init_archive = __esm({
16820
16731
  });
16821
16732
 
16822
16733
  // ../cli/src/lib/agent/studio-shared.ts
16823
- import fs51 from "node:fs";
16824
- import path53 from "node:path";
16734
+ import fs50 from "node:fs";
16735
+ import path52 from "node:path";
16825
16736
  function studioFiles(studio) {
16826
16737
  const flow = cloudFlows().find((f) => f.def.id === studio || f.cloudId === studio);
16827
16738
  if (flow) return flow.files;
16828
- if (studio && draftId() === studio) {
16829
- try {
16830
- return readStudioFolder(path53.join(STUDIOS, studio));
16831
- } catch {
16832
- return null;
16833
- }
16834
- }
16835
16739
  return null;
16836
16740
  }
16837
16741
  function readStudioMemory(studio) {
16838
16742
  const dir = studioMemoryDir(studio);
16839
16743
  let names3 = [];
16840
16744
  try {
16841
- names3 = fs51.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name).sort();
16745
+ names3 = fs50.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name).sort();
16842
16746
  } catch {
16843
16747
  return [];
16844
16748
  }
16845
16749
  return names3.flatMap((name) => {
16846
16750
  try {
16847
- return [{ name, text: fs51.readFileSync(path53.join(dir, name), "utf8").trim() }];
16751
+ return [{ name, text: fs50.readFileSync(path52.join(dir, name), "utf8").trim() }];
16848
16752
  } catch {
16849
16753
  return [];
16850
16754
  }
@@ -16884,17 +16788,15 @@ var init_studio_shared = __esm({
16884
16788
  init_studio_files();
16885
16789
  init_command();
16886
16790
  init_cloud_studios();
16887
- init_studio_file();
16888
- init_studio_folder();
16889
16791
  sharedFiles = (files) => Object.keys(files).filter((f) => f.startsWith(SHARED_DIR) && f !== RULES_FILE).sort();
16890
- studioMemoryDir = (studio) => path53.join(MEMORY, STUDIO_MEMORY_DIR, studio);
16792
+ studioMemoryDir = (studio) => path52.join(MEMORY, STUDIO_MEMORY_DIR, studio);
16891
16793
  fileLine = (studio, file) => `- \`${file}\` \u2014 \`${rawMove(`file ${studio} ${file}`)}\``;
16892
16794
  studioHoldsAgent = (studio, agent) => !!studio && Object.keys(studioFiles(studio) ?? {}).some((f) => f.startsWith(`agents/${agent}/`));
16893
16795
  }
16894
16796
  });
16895
16797
 
16896
16798
  // ../cli/src/lib/agent/prompts.ts
16897
- import path54 from "node:path";
16799
+ import path53 from "node:path";
16898
16800
  function stopReason(deliveryId) {
16899
16801
  const delivery = findDelivery(deliveryId);
16900
16802
  if (!delivery) return void 0;
@@ -16955,7 +16857,7 @@ ${text4}` : "";
16955
16857
  }
16956
16858
  function cardFileOf(id) {
16957
16859
  const found2 = id === void 0 ? null : locate(id);
16958
- return found2 ? found2.kind === "group" ? path54.join(found2.target, "root.md") : found2.target : "";
16860
+ return found2 ? found2.kind === "group" ? path53.join(found2.target, "root.md") : found2.target : "";
16959
16861
  }
16960
16862
  function realPaths(text4, req) {
16961
16863
  if (req.action !== "scheduled" && req.action !== "sub") return text4;
@@ -17053,7 +16955,7 @@ function frozenRules(req) {
17053
16955
  function archivedCardFile(id) {
17054
16956
  const found2 = locateArchived(id);
17055
16957
  if (!found2) return `${rel(ARCHIVE)}/`;
17056
- return rel(found2.kind === "group" ? path54.join(found2.target, "root.md") : found2.target);
16958
+ return rel(found2.kind === "group" ? path53.join(found2.target, "root.md") : found2.target);
17057
16959
  }
17058
16960
  function shippedLines(cardId2) {
17059
16961
  const delivery = endedDelivery(`${cardId2}`);
@@ -17196,7 +17098,7 @@ function actionPrompt(req, command, notes) {
17196
17098
  case "spec": {
17197
17099
  const agent = findSpecAgent(req.specAgent ?? "");
17198
17100
  const found2 = req.id === void 0 ? null : locate(req.id);
17199
- const cardFile3 = found2 ? rel(found2.kind === "group" ? path54.join(found2.target, "root.md") : found2.target) : `task #${req.id}`;
17101
+ const cardFile3 = found2 ? rel(found2.kind === "group" ? path53.join(found2.target, "root.md") : found2.target) : `task #${req.id}`;
17200
17102
  const own = agent ? specAgentInstructions(agent) : null;
17201
17103
  if (own) notes.push(...own.notes);
17202
17104
  const memory = agent ? agentMemoryBlock(agent) : "";
@@ -17372,16 +17274,16 @@ var init_prompts = __esm({
17372
17274
 
17373
17275
  // ../cli/src/lib/agent/stop.ts
17374
17276
  import { spawnSync as spawnSync4 } from "node:child_process";
17375
- import fs52 from "node:fs";
17277
+ import fs51 from "node:fs";
17376
17278
  function markedInProc(entry, strict = false, since) {
17377
17279
  const pids = [];
17378
- for (const name of fs52.readdirSync("/proc")) {
17280
+ for (const name of fs51.readdirSync("/proc")) {
17379
17281
  if (!/^\d+$/.test(name)) continue;
17380
17282
  try {
17381
- if (fs52.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
17283
+ if (fs51.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
17382
17284
  } catch (error) {
17383
17285
  if (strict && !["ENOENT", "ESRCH"].includes(error.code ?? "")) {
17384
- const stat = fs52.statSync(`/proc/${name}`, { throwIfNoEntry: false });
17286
+ const stat = fs51.statSync(`/proc/${name}`, { throwIfNoEntry: false });
17385
17287
  if (stat?.uid === process.getuid?.() && !startedBefore(Number(name), since)) throw error;
17386
17288
  }
17387
17289
  }
@@ -17546,10 +17448,10 @@ var init_stop = __esm({
17546
17448
  });
17547
17449
 
17548
17450
  // ../cli/src/lib/agent/creation-lock.ts
17549
- import path55 from "node:path";
17451
+ import path54 from "node:path";
17550
17452
  function withCreationLock(fn) {
17551
17453
  if (depth2) return fn();
17552
- return withLock(path55.join(SESSIONS_DIR, "creation.lock"), "changing card creation", () => {
17454
+ return withLock(path54.join(SESSIONS_DIR, "creation.lock"), "changing card creation", () => {
17553
17455
  depth2++;
17554
17456
  try {
17555
17457
  return fn();
@@ -17570,8 +17472,8 @@ var init_creation_lock = __esm({
17570
17472
 
17571
17473
  // ../cli/src/lib/agent/sessions.ts
17572
17474
  import { randomUUID as randomUUID4 } from "node:crypto";
17573
- import fs53 from "node:fs";
17574
- import path56 from "node:path";
17475
+ import fs52 from "node:fs";
17476
+ import path55 from "node:path";
17575
17477
  function reap(runs, reaped = [], restore = []) {
17576
17478
  let changed = false;
17577
17479
  const now = Date.now();
@@ -17591,7 +17493,7 @@ function reap(runs, reaped = [], restore = []) {
17591
17493
  }
17592
17494
  function stampDuration(run3, endedAt) {
17593
17495
  try {
17594
- fs53.appendFileSync(run3.logPath, durationLine(endedAt - run3.startedAt));
17496
+ fs52.appendFileSync(run3.logPath, durationLine(endedAt - run3.startedAt));
17595
17497
  } catch {
17596
17498
  }
17597
17499
  }
@@ -17605,7 +17507,7 @@ function cardNow(cardId2) {
17605
17507
  try {
17606
17508
  const file = cardFile(cardId2);
17607
17509
  if (!file) return null;
17608
- const { meta } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
17510
+ const { meta } = parseFrontmatter(fs52.readFileSync(file, "utf8"));
17609
17511
  if (!meta) return null;
17610
17512
  return { status: meta.status || "todo", questions: meta.questions.length, title: meta.title };
17611
17513
  } catch {
@@ -17738,9 +17640,9 @@ function leftBoardOnLanding(id) {
17738
17640
  function archivedRejected(id) {
17739
17641
  const filed = locateArchived(id);
17740
17642
  if (!filed) return null;
17741
- const file = filed.kind === "group" ? path56.join(filed.target, "root.md") : filed.target;
17643
+ const file = filed.kind === "group" ? path55.join(filed.target, "root.md") : filed.target;
17742
17644
  try {
17743
- return !!parseFrontmatter(fs53.readFileSync(file, "utf8")).meta?.rejected;
17645
+ return !!parseFrontmatter(fs52.readFileSync(file, "utf8")).meta?.rejected;
17744
17646
  } catch {
17745
17647
  return false;
17746
17648
  }
@@ -17990,7 +17892,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID4(), said2) {
17990
17892
  return { run: record, spec };
17991
17893
  }
17992
17894
  function planningSession(cardId2, cwd = REPO_ROOT) {
17993
- const here = (dir) => !dir || path56.resolve(dir) === cwd;
17895
+ const here = (dir) => !dir || path55.resolve(dir) === cwd;
17994
17896
  const planned = readRuns().filter((r) => r.status === "done" && r.cardId === cardId2 && PLANNING.has(r.action)).sort((a, b) => b.startedAt - a.startedAt)[0];
17995
17897
  if (!planned) return { none: "unrecorded" };
17996
17898
  if (!here(planned.cwd)) return { none: "elsewhere" };
@@ -18210,8 +18112,8 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
18210
18112
  if (inherited.asks.length || inherited.refines.length) writeAsks(sessionId, inherited);
18211
18113
  clearAsks(prev.sessionId);
18212
18114
  try {
18213
- fs53.unlinkSync(prev.logPath);
18214
- fs53.rmSync(eventsPathOf(prev.sessionId), { force: true });
18115
+ fs52.unlinkSync(prev.logPath);
18116
+ fs52.rmSync(eventsPathOf(prev.sessionId), { force: true });
18215
18117
  } catch {
18216
18118
  }
18217
18119
  if (retry2 && prev.pictures?.length) {
@@ -18234,8 +18136,8 @@ function forgetRun(sessionId) {
18234
18136
  if (!gone) return;
18235
18137
  clearAsks(sessionId);
18236
18138
  try {
18237
- fs53.unlinkSync(gone.logPath);
18238
- fs53.rmSync(eventsPathOf(gone.sessionId), { force: true });
18139
+ fs52.unlinkSync(gone.logPath);
18140
+ fs52.rmSync(eventsPathOf(gone.sessionId), { force: true });
18239
18141
  } catch {
18240
18142
  }
18241
18143
  }
@@ -18264,14 +18166,14 @@ function noteSpecRefusals(sessionId, refused) {
18264
18166
  }
18265
18167
  function clearAsks(sessionId) {
18266
18168
  try {
18267
- fs53.unlinkSync(asksPathOf(sessionId));
18169
+ fs52.unlinkSync(asksPathOf(sessionId));
18268
18170
  } catch {
18269
18171
  }
18270
18172
  }
18271
18173
  function readAsks(sessionId) {
18272
18174
  let data;
18273
18175
  try {
18274
- data = JSON.parse(fs53.readFileSync(asksPathOf(sessionId), "utf8"));
18176
+ data = JSON.parse(fs52.readFileSync(asksPathOf(sessionId), "utf8"));
18275
18177
  } catch {
18276
18178
  return { asks: [], refines: [], refused: [] };
18277
18179
  }
@@ -18298,10 +18200,10 @@ function readAsks(sessionId) {
18298
18200
  return { asks: asks.filter((a) => !discarded.has(a.cardId)), refines: refines.filter((a) => !discarded.has(a.cardId)), refused };
18299
18201
  }
18300
18202
  function writeAsks(sessionId, file) {
18301
- fs53.mkdirSync(SESSIONS_DIR, { recursive: true });
18203
+ fs52.mkdirSync(SESSIONS_DIR, { recursive: true });
18302
18204
  const tmp = `${asksPathOf(sessionId)}.tmp`;
18303
- fs53.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n");
18304
- fs53.renameSync(tmp, asksPathOf(sessionId));
18205
+ fs52.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n");
18206
+ fs52.renameSync(tmp, asksPathOf(sessionId));
18305
18207
  }
18306
18208
  function markSpawned(sessionId, pid) {
18307
18209
  patch(sessionId, (r) => {
@@ -18432,12 +18334,12 @@ async function resumeDelivery(id) {
18432
18334
  return { ok: true, deliveryId: delivery.deliveryId, carryOn };
18433
18335
  }
18434
18336
  function writeSpec(spec) {
18435
- fs53.mkdirSync(SESSIONS_DIR, { recursive: true });
18436
- fs53.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
18337
+ fs52.mkdirSync(SESSIONS_DIR, { recursive: true });
18338
+ fs52.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
18437
18339
  }
18438
18340
  function readSpec(sessionId) {
18439
18341
  try {
18440
- const spec = JSON.parse(fs53.readFileSync(specPathOf(sessionId), "utf8"));
18342
+ const spec = JSON.parse(fs52.readFileSync(specPathOf(sessionId), "utf8"));
18441
18343
  return spec && Array.isArray(spec.plan?.argv) ? spec : null;
18442
18344
  } catch {
18443
18345
  return null;
@@ -18445,28 +18347,28 @@ function readSpec(sessionId) {
18445
18347
  }
18446
18348
  function dropSpec(sessionId) {
18447
18349
  try {
18448
- fs53.unlinkSync(specPathOf(sessionId));
18350
+ fs52.unlinkSync(specPathOf(sessionId));
18449
18351
  } catch {
18450
18352
  }
18451
18353
  }
18452
18354
  async function acquireIndexLock(giveUp) {
18453
18355
  const until = Date.now() + INDEX_WAIT_MS;
18454
- const holder = path56.join(INDEX_LOCK2, "holder");
18356
+ const holder = path55.join(INDEX_LOCK2, "holder");
18455
18357
  for (; ; ) {
18456
18358
  if (giveUp()) return null;
18457
18359
  try {
18458
- fs53.mkdirSync(INDEX_LOCK2, { recursive: false });
18459
- fs53.writeFileSync(holder, String(process.pid));
18460
- return () => fs53.rmSync(INDEX_LOCK2, { recursive: true, force: true });
18360
+ fs52.mkdirSync(INDEX_LOCK2, { recursive: false });
18361
+ fs52.writeFileSync(holder, String(process.pid));
18362
+ return () => fs52.rmSync(INDEX_LOCK2, { recursive: true, force: true });
18461
18363
  } catch (err) {
18462
18364
  const code = err.code;
18463
18365
  if (code === "ENOENT") {
18464
- fs53.mkdirSync(path56.dirname(INDEX_LOCK2), { recursive: true });
18366
+ fs52.mkdirSync(path55.dirname(INDEX_LOCK2), { recursive: true });
18465
18367
  continue;
18466
18368
  }
18467
18369
  if (code !== "EEXIST") throw err;
18468
18370
  if (!pidAlive(Number(readHolder(holder)))) {
18469
- fs53.rmSync(INDEX_LOCK2, { recursive: true, force: true });
18371
+ fs52.rmSync(INDEX_LOCK2, { recursive: true, force: true });
18470
18372
  continue;
18471
18373
  }
18472
18374
  if (Date.now() > until) return null;
@@ -18476,7 +18378,7 @@ async function acquireIndexLock(giveUp) {
18476
18378
  }
18477
18379
  function readHolder(file) {
18478
18380
  try {
18479
- return fs53.readFileSync(file, "utf8").trim();
18381
+ return fs52.readFileSync(file, "utf8").trim();
18480
18382
  } catch {
18481
18383
  return String(process.pid);
18482
18384
  }
@@ -18561,8 +18463,8 @@ var init_sessions = __esm({
18561
18463
  implement: "implementing",
18562
18464
  hook: "implementing"
18563
18465
  };
18564
- specPathOf = (sessionId) => path56.join(SESSIONS_DIR, `${sessionId}.plan.json`);
18565
- asksPathOf = (sessionId) => path56.join(SESSIONS_DIR, `${sessionId}.asks.json`);
18466
+ specPathOf = (sessionId) => path55.join(SESSIONS_DIR, `${sessionId}.plan.json`);
18467
+ asksPathOf = (sessionId) => path55.join(SESSIONS_DIR, `${sessionId}.asks.json`);
18566
18468
  carriesSession = (r) => !!(r.resumedFrom || r.continues && !r.continues.fork);
18567
18469
  canPickUp = (r) => r.status === "error" || r.status === "interrupted" || r.status === "stopped";
18568
18470
  neverStarted = (r) => r.unspawned === true || !!r.errorWhy?.some((why2) => why2.kind === "notInstalled");
@@ -18615,8 +18517,8 @@ var init_sources = __esm({
18615
18517
  });
18616
18518
 
18617
18519
  // ../cli/src/lib/signals/inbox.ts
18618
- import fs54 from "node:fs";
18619
- import path57 from "node:path";
18520
+ import fs53 from "node:fs";
18521
+ import path56 from "node:path";
18620
18522
  function metaPair(key, value) {
18621
18523
  const name = typeof key === "string" ? key.trim() : "";
18622
18524
  if (!name) return null;
@@ -18647,7 +18549,7 @@ ${signal2.summary.trim()}
18647
18549
  function parse(file, lenient = false) {
18648
18550
  let text4;
18649
18551
  try {
18650
- text4 = fs54.readFileSync(file, "utf8");
18552
+ text4 = fs53.readFileSync(file, "utf8");
18651
18553
  } catch {
18652
18554
  return null;
18653
18555
  }
@@ -18701,28 +18603,28 @@ function parse(file, lenient = false) {
18701
18603
  };
18702
18604
  }
18703
18605
  function freeName(dir, wanted) {
18704
- const ext = path57.extname(wanted);
18606
+ const ext = path56.extname(wanted);
18705
18607
  const stem = wanted.slice(0, wanted.length - ext.length);
18706
18608
  let name = wanted;
18707
- for (let n = 2; fs54.existsSync(path57.join(dir, name)); n++) name = `${stem}-${n}${ext}`;
18609
+ for (let n = 2; fs53.existsSync(path56.join(dir, name)); n++) name = `${stem}-${n}${ext}`;
18708
18610
  return name;
18709
18611
  }
18710
- function readFolder2(dir, lenient = false) {
18612
+ function readFolder(dir, lenient = false) {
18711
18613
  let entries;
18712
18614
  try {
18713
- entries = fs54.readdirSync(dir, { withFileTypes: true });
18615
+ entries = fs53.readdirSync(dir, { withFileTypes: true });
18714
18616
  } catch {
18715
18617
  return [];
18716
18618
  }
18717
- return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".md")).map((entry) => parse(path57.join(dir, entry.name), lenient)).filter((signal2) => signal2 !== null);
18619
+ return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".md")).map((entry) => parse(path56.join(dir, entry.name), lenient)).filter((signal2) => signal2 !== null);
18718
18620
  }
18719
18621
  function readInbox() {
18720
- const signals = readFolder2(TRIAGE);
18622
+ const signals = readFolder(TRIAGE);
18721
18623
  signals.sort((a, b) => b.collectedAt.localeCompare(a.collectedAt) || a.sourceId.localeCompare(b.sourceId));
18722
18624
  return signals;
18723
18625
  }
18724
18626
  function writeSignal(incoming, importedAt, slug2 = "") {
18725
- fs54.mkdirSync(TRIAGE, { recursive: true });
18627
+ fs53.mkdirSync(TRIAGE, { recursive: true });
18726
18628
  const signal2 = {
18727
18629
  ...incoming,
18728
18630
  importedAt,
@@ -18734,12 +18636,12 @@ function writeSignal(incoming, importedAt, slug2 = "") {
18734
18636
  contentKept: true,
18735
18637
  relPath: ""
18736
18638
  };
18737
- const file = path57.join(TRIAGE, freeName(TRIAGE, fileName(signal2.title, slug2)));
18738
- fs54.writeFileSync(file, serialize({ ...signal2, relPath: boardRel(file) }));
18639
+ const file = path56.join(TRIAGE, freeName(TRIAGE, fileName(signal2.title, slug2)));
18640
+ fs53.writeFileSync(file, serialize({ ...signal2, relPath: boardRel(file) }));
18739
18641
  return { ...signal2, relPath: boardRel(file) };
18740
18642
  }
18741
18643
  function stamp3(file, fields) {
18742
- const text4 = fs54.readFileSync(file, "utf8");
18644
+ const text4 = fs53.readFileSync(file, "utf8");
18743
18645
  const lines = text4.split("\n");
18744
18646
  const close = lines.indexOf("---", 1);
18745
18647
  if (close < 0) return;
@@ -18748,13 +18650,13 @@ function stamp3(file, fields) {
18748
18650
  return !key || fields[key[1]] === void 0;
18749
18651
  });
18750
18652
  const added = Object.entries(fields).flatMap(([key, value]) => value === null ? [] : [`${key}: ${yamlScalar(value)}`]);
18751
- fs54.writeFileSync(file, ["---", ...kept2, ...added, ...lines.slice(close)].join("\n"));
18653
+ fs53.writeFileSync(file, ["---", ...kept2, ...added, ...lines.slice(close)].join("\n"));
18752
18654
  }
18753
18655
  function moveSignal(from, into, fields) {
18754
- if (!fs54.existsSync(from)) return "";
18755
- fs54.mkdirSync(into, { recursive: true });
18756
- const at = path57.join(into, freeName(into, path57.basename(from)));
18757
- fs54.renameSync(from, at);
18656
+ if (!fs53.existsSync(from)) return "";
18657
+ fs53.mkdirSync(into, { recursive: true });
18658
+ const at = path56.join(into, freeName(into, path56.basename(from)));
18659
+ fs53.renameSync(from, at);
18758
18660
  stamp3(at, fields);
18759
18661
  return boardRel(at);
18760
18662
  }
@@ -18763,10 +18665,10 @@ function archiveInboxItem(sourceId, cardId2) {
18763
18665
  if (!found2) {
18764
18666
  const ignored = readAllDismissed().find((signal2) => signal2.sourceId === sourceId);
18765
18667
  if (!ignored) return { ok: false, error: `nothing waiting in triage is ${sourceId}` };
18766
- stamp3(path57.join(SIGNALS_DISMISSED, path57.basename(ignored.relPath)), { card_id: String(cardId2) });
18668
+ stamp3(path56.join(SIGNALS_DISMISSED, path56.basename(ignored.relPath)), { card_id: String(cardId2) });
18767
18669
  return { ok: true, relPath: ignored.relPath, where: "dismissed" };
18768
18670
  }
18769
- const at = moveSignal(path57.join(TRIAGE, path57.basename(found2.relPath)), SIGNALS_ARCHIVED, {
18671
+ const at = moveSignal(path56.join(TRIAGE, path56.basename(found2.relPath)), SIGNALS_ARCHIVED, {
18770
18672
  card_id: String(cardId2),
18771
18673
  archived_at: formatStamp(/* @__PURE__ */ new Date())
18772
18674
  });
@@ -18780,13 +18682,13 @@ var init_inbox = __esm({
18780
18682
  init_sources();
18781
18683
  init_paths();
18782
18684
  init_yaml();
18783
- boardRel = (file) => rel(file).split(path57.sep).join("/");
18685
+ boardRel = (file) => rel(file).split(path56.sep).join("/");
18784
18686
  FIELDS = ["source_id", "title", "collected_at", "imported_at"];
18785
18687
  META_LINE = /^\s+("(?:[^"\\]|\\.)*"|[^:]+):\s*(.*)$/;
18786
18688
  slugOf = (said2) => said2.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 56).replace(/-+$/, "");
18787
18689
  fileName = (title, slug2 = "") => `${slugOf(slug2) || slugOf(title) || "item"}.md`;
18788
- readArchived = () => readFolder2(SIGNALS_ARCHIVED);
18789
- readAllDismissed = () => readFolder2(SIGNALS_DISMISSED, true);
18690
+ readArchived = () => readFolder(SIGNALS_ARCHIVED);
18691
+ readAllDismissed = () => readFolder(SIGNALS_DISMISSED, true);
18790
18692
  }
18791
18693
  });
18792
18694
 
@@ -18889,12 +18791,12 @@ var init_studio_cards = __esm({
18889
18791
  });
18890
18792
 
18891
18793
  // ../cli/src/lib/readme.ts
18892
- import fs55 from "node:fs";
18893
- import path58 from "node:path";
18794
+ import fs54 from "node:fs";
18795
+ import path57 from "node:path";
18894
18796
  function stripReadmeRefs(target) {
18895
- if (!fs55.existsSync(README)) return [];
18797
+ if (!fs54.existsSync(README)) return [];
18896
18798
  const needle = target.kind === "group" ? `](${target.rel}/` : `](${target.rel})`;
18897
- const lines = fs55.readFileSync(README, "utf8").split("\n");
18799
+ const lines = fs54.readFileSync(README, "utf8").split("\n");
18898
18800
  const out = [];
18899
18801
  const removed = [];
18900
18802
  let i = 0;
@@ -18916,20 +18818,20 @@ function stripReadmeRefs(target) {
18916
18818
  out.push(line);
18917
18819
  i++;
18918
18820
  }
18919
- if (removed.length) fs55.writeFileSync(README, out.join("\n"));
18821
+ if (removed.length) fs54.writeFileSync(README, out.join("\n"));
18920
18822
  return removed;
18921
18823
  }
18922
18824
  function addReadmeRef(id, title, relPath) {
18923
- if (!fs55.existsSync(README)) return false;
18924
- const link2 = relPath.split(path58.sep).join("/");
18825
+ if (!fs54.existsSync(README)) return false;
18826
+ const link2 = relPath.split(path57.sep).join("/");
18925
18827
  const bullet = `- [#${id} ${title}](${link2})`;
18926
18828
  const heading = `## ${TASKS_HEADING}`;
18927
- let lines = fs55.readFileSync(README, "utf8").split("\n");
18829
+ let lines = fs54.readFileSync(README, "utf8").split("\n");
18928
18830
  const hi = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
18929
18831
  if (hi === -1) {
18930
18832
  while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
18931
18833
  lines.push("", heading, "", bullet);
18932
- fs55.writeFileSync(README, lines.join("\n") + "\n");
18834
+ fs54.writeFileSync(README, lines.join("\n") + "\n");
18933
18835
  return true;
18934
18836
  }
18935
18837
  let end2 = hi + 1;
@@ -18943,15 +18845,15 @@ function addReadmeRef(id, title, relPath) {
18943
18845
  const at = lastBullet !== -1 ? lastBullet + 1 : lines[hi + 1] === "" ? hi + 2 : hi + 1;
18944
18846
  lines.splice(at, 0, bullet);
18945
18847
  }
18946
- fs55.writeFileSync(README, lines.join("\n"));
18848
+ fs54.writeFileSync(README, lines.join("\n"));
18947
18849
  return true;
18948
18850
  }
18949
18851
  function repointReadmeLink(id, oldRel, newRel, title) {
18950
- if (!fs55.existsSync(README)) return false;
18951
- const oldLink = oldRel.split(path58.sep).join("/");
18952
- const newLink = newRel.split(path58.sep).join("/");
18852
+ if (!fs54.existsSync(README)) return false;
18853
+ const oldLink = oldRel.split(path57.sep).join("/");
18854
+ const newLink = newRel.split(path57.sep).join("/");
18953
18855
  const linkRe = new RegExp(`\\[#${id}\\b[^\\]]*\\]\\(${escapeRegex(oldLink)}\\)`);
18954
- const lines = fs55.readFileSync(README, "utf8").split("\n");
18856
+ const lines = fs54.readFileSync(README, "utf8").split("\n");
18955
18857
  let changed = false;
18956
18858
  for (let i = 0; i < lines.length; i++) {
18957
18859
  if (!lines[i].includes(`](${oldLink})`)) continue;
@@ -18961,7 +18863,7 @@ function repointReadmeLink(id, oldRel, newRel, title) {
18961
18863
  changed = true;
18962
18864
  }
18963
18865
  }
18964
- if (changed) fs55.writeFileSync(README, lines.join("\n"));
18866
+ if (changed) fs54.writeFileSync(README, lines.join("\n"));
18965
18867
  return changed;
18966
18868
  }
18967
18869
  var isTableRow, isBulletStart, bulletIndent, TASKS_HEADING, escapeRegex;
@@ -19448,14 +19350,14 @@ function collect(body, card, host2) {
19448
19350
  const active2 = /* @__PURE__ */ new Set();
19449
19351
  const out = [];
19450
19352
  const visit = (src, types, owner) => {
19451
- const path86 = src.replace(/[?#].*$/, "");
19353
+ const path85 = src.replace(/[?#].*$/, "");
19452
19354
  let resolved2;
19453
19355
  try {
19454
- resolved2 = host2.resolve(path86, owner);
19356
+ resolved2 = host2.resolve(path85, owner);
19455
19357
  } catch (error) {
19456
19358
  if (owner !== card) return { key: null, error: why(error) };
19457
19359
  if (!nodes.has(src)) {
19458
- const node2 = { key: src, file: null, kind: kindAt(path86, types), error: why(error), problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([src]) };
19360
+ const node2 = { key: src, file: null, kind: kindAt(path85, types), error: why(error), problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([src]) };
19459
19361
  nodes.set(src, node2);
19460
19362
  out.push(node2);
19461
19363
  }
@@ -19510,10 +19412,10 @@ function collect(body, card, host2) {
19510
19412
  };
19511
19413
  for (const ref of bodyReferences(body)) visit(ref.src, ref.types, card);
19512
19414
  const sorted = [];
19513
- const done2 = /* @__PURE__ */ new Set();
19415
+ const done = /* @__PURE__ */ new Set();
19514
19416
  const order = (node) => {
19515
- if (done2.has(node.key)) return;
19516
- done2.add(node.key);
19417
+ if (done.has(node.key)) return;
19418
+ done.add(node.key);
19517
19419
  for (const key of node.dependencies.values()) {
19518
19420
  const child = nodes.get(key);
19519
19421
  if (child) order(child);
@@ -19540,16 +19442,16 @@ var init_collect = __esm({
19540
19442
  });
19541
19443
 
19542
19444
  // ../cli/src/lib/dress-page.ts
19543
- import fs56 from "node:fs";
19544
- import path59 from "node:path";
19445
+ import fs55 from "node:fs";
19446
+ import path58 from "node:path";
19545
19447
  function dressPage(file) {
19546
- const folder = path59.dirname(file);
19547
- const html = fs56.readFileSync(file, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
19448
+ const folder = path58.dirname(file);
19449
+ const html = fs55.readFileSync(file, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
19548
19450
  const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
19549
19451
  if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
19550
- const at2 = path59.resolve(folder, href);
19551
- if (!at2.startsWith(folder + path59.sep) || !fs56.existsSync(at2)) return tag;
19552
- const css = fs56.readFileSync(at2, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole2, quote, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole2 : `url(${quote}${path59.relative(folder, path59.resolve(path59.dirname(at2), src)).split(path59.sep).join("/")}${quote})`);
19452
+ const at2 = path58.resolve(folder, href);
19453
+ if (!at2.startsWith(folder + path58.sep) || !fs55.existsSync(at2)) return tag;
19454
+ const css = fs55.readFileSync(at2, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole2, quote, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole2 : `url(${quote}${path58.relative(folder, path58.resolve(path58.dirname(at2), src)).split(path58.sep).join("/")}${quote})`);
19553
19455
  return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
19554
19456
  });
19555
19457
  const at = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
@@ -19561,25 +19463,25 @@ var init_dress_page = __esm({
19561
19463
  "use strict";
19562
19464
  CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:; font-src data: blob:; worker-src 'none'; base-uri 'none'; form-action 'none'";
19563
19465
  head = `<meta http-equiv="Content-Security-Policy" content="${CSP}"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><style>html{overflow-x:hidden;overscroll-behavior:contain}</style>`;
19564
- referenceText = (file) => /\.html$/i.test(file) ? dressPage(file) : fs56.readFileSync(file, "utf8");
19466
+ referenceText = (file) => /\.html$/i.test(file) ? dressPage(file) : fs55.readFileSync(file, "utf8");
19565
19467
  }
19566
19468
  });
19567
19469
 
19568
19470
  // ../cli/src/lib/preview-files.ts
19569
- import fs57 from "node:fs";
19570
- import path60 from "node:path";
19471
+ import fs56 from "node:fs";
19472
+ import path59 from "node:path";
19571
19473
  function resolver(card, id) {
19572
- const roots = [KANBAN, path60.join(ASSETS, String(id)), path60.join(MOCKUPS, String(id))];
19573
- const real2 = (p) => fs57.existsSync(p) ? fs57.realpathSync(p) : p;
19574
- const inside2 = (p) => roots.some((root2) => p.startsWith(real2(root2) + path60.sep));
19474
+ const roots = [KANBAN, path59.join(ASSETS, String(id)), path59.join(MOCKUPS, String(id))];
19475
+ const real2 = (p) => fs56.existsSync(p) ? fs56.realpathSync(p) : p;
19476
+ const inside2 = (p) => roots.some((root2) => p.startsWith(real2(root2) + path59.sep));
19575
19477
  return (src, owner) => {
19576
19478
  if (/^[a-z][\w+.-]*:/i.test(src) || src.startsWith("#") || src.startsWith("//")) return null;
19577
- if (path60.isAbsolute(src)) throw new Error("an absolute path; name it relative to the file");
19479
+ if (path59.isAbsolute(src)) throw new Error("an absolute path; name it relative to the file");
19578
19480
  const held4 = /^\.(assets|mockups)\//.exec(src);
19579
- const file = held4 ? path60.resolve(held4[1] === "assets" ? ASSETS : MOCKUPS, src.slice(held4[0].length)) : path60.resolve(path60.dirname(owner), src);
19580
- if (!inside2(path60.resolve(file)) || fs57.existsSync(file) && !inside2(fs57.realpathSync(file))) throw new Error(`outside this card's files (${rel(KANBAN)}, .assets/${id}/)`);
19581
- if (!fs57.statSync(file, { throwIfNoEntry: false })?.isFile()) throw new Error("no such file");
19582
- return { key: fs57.realpathSync(file), file };
19481
+ const file = held4 ? path59.resolve(held4[1] === "assets" ? ASSETS : MOCKUPS, src.slice(held4[0].length)) : path59.resolve(path59.dirname(owner), src);
19482
+ if (!inside2(path59.resolve(file)) || fs56.existsSync(file) && !inside2(fs56.realpathSync(file))) throw new Error(`outside this card's files (${rel(KANBAN)}, .assets/${id}/)`);
19483
+ if (!fs56.statSync(file, { throwIfNoEntry: false })?.isFile()) throw new Error("no such file");
19484
+ return { key: fs56.realpathSync(file), file };
19583
19485
  };
19584
19486
  }
19585
19487
  function validatePreviewFiles(card, id, text4) {
@@ -19622,8 +19524,8 @@ var init_preview_files = __esm({
19622
19524
  });
19623
19525
 
19624
19526
  // ../cli/src/lib/spec-contract.ts
19625
- import fs58 from "node:fs";
19626
- import path61 from "node:path";
19527
+ import fs57 from "node:fs";
19528
+ import path60 from "node:path";
19627
19529
  function scanCardLines(lines, start = 0) {
19628
19530
  const visible = lines.map(() => "");
19629
19531
  let fence = null;
@@ -19656,18 +19558,18 @@ function scanCardLines(lines, start = 0) {
19656
19558
  }
19657
19559
  function snapshotSpecs() {
19658
19560
  const out = /* @__PURE__ */ new Map();
19659
- if (!fs58.existsSync(TODO)) return out;
19561
+ if (!fs57.existsSync(TODO)) return out;
19660
19562
  for (const file of walkMd(TODO)) {
19661
- if (isLegacyRecurring(path61.relative(TODO, file))) continue;
19662
- const id = idPrefix(path61.basename(file) === "root.md" ? path61.basename(path61.dirname(file)) : path61.basename(file));
19663
- if (id !== null) out.set(file, { id, text: fs58.readFileSync(file, "utf8") });
19563
+ if (isLegacyRecurring(path60.relative(TODO, file))) continue;
19564
+ const id = idPrefix(path60.basename(file) === "root.md" ? path60.basename(path60.dirname(file)) : path60.basename(file));
19565
+ if (id !== null) out.set(file, { id, text: fs57.readFileSync(file, "utf8") });
19664
19566
  }
19665
19567
  return out;
19666
19568
  }
19667
19569
  function enclosingGroups(file) {
19668
19570
  const ids = [];
19669
19571
  for (let root2 = enclosingGroupRoot(file); root2; root2 = enclosingGroupRoot(root2)) {
19670
- const id = idPrefix(path61.basename(path61.dirname(root2)));
19572
+ const id = idPrefix(path60.basename(path60.dirname(root2)));
19671
19573
  if (id !== null) ids.push(id);
19672
19574
  }
19673
19575
  return ids;
@@ -19752,8 +19654,8 @@ function validateSpec(file, text4, id) {
19752
19654
  markers.push(i + 1);
19753
19655
  continue;
19754
19656
  }
19755
- const done2 = line.match(/^ {0,3}(#{2,3})\s+Done when\s*#*\s*$/);
19756
- if (done2) acceptance.push({ line: i + 1, level: done2[1].length });
19657
+ const done = line.match(/^ {0,3}(#{2,3})\s+Done when\s*#*\s*$/);
19658
+ if (done) acceptance.push({ line: i + 1, level: done[1].length });
19757
19659
  const heading = line.match(/^ {0,3}(#{1,2})\s+(.+?)\s*#*\s*$/);
19758
19660
  if (heading?.[1] === "#") add(i + 1, "heading", "Do not repeat the card title as an H1. Remove this heading or use ### inside your section.");
19759
19661
  if (heading?.[1] === "##") headings.push({ title: heading[2], line: i + 1 });
@@ -19817,10 +19719,10 @@ function validateSpec(file, text4, id) {
19817
19719
  lastOrder = Math.max(lastOrder, rank2);
19818
19720
  }
19819
19721
  }
19820
- for (const [index, done2] of acceptance.entries()) {
19821
- if (index) add(done2.line, "duplicate-section", "Duplicate Done when. Keep one ### Done when under ## Scope.");
19822
- const parent = headings.filter((h) => h.line < done2.line).at(-1);
19823
- if (done2.level !== 3 || parent?.title !== "Scope") add(done2.line, "acceptance-section", "Move the acceptance list to ### Done when under ## Scope.");
19722
+ for (const [index, done] of acceptance.entries()) {
19723
+ if (index) add(done.line, "duplicate-section", "Duplicate Done when. Keep one ### Done when under ## Scope.");
19724
+ const parent = headings.filter((h) => h.line < done.line).at(-1);
19725
+ if (done.level !== 3 || parent?.title !== "Scope") add(done.line, "acceptance-section", "Move the acceptance list to ### Done when under ## Scope.");
19824
19726
  }
19825
19727
  for (const title of required) if (!seen.has(title)) add(end2 + 2, "missing-section", `Missing ## ${title}. Restore that section; keep its title in English.`);
19826
19728
  if (markers.length !== 1) add(markers[1] ?? end2 + 2, "boundary", `Found ${markers.length} <!-- agent --> boundaries; expected exactly one, between the human and agent sections.`);
@@ -19842,9 +19744,9 @@ function setEnd(lines, at) {
19842
19744
  }
19843
19745
  function inside(dir, name) {
19844
19746
  try {
19845
- const root2 = fs58.realpathSync(dir);
19846
- const real2 = fs58.realpathSync(path61.join(dir, name));
19847
- return real2.startsWith(root2 + path61.sep) && fs58.statSync(real2).isFile() ? real2 : null;
19747
+ const root2 = fs57.realpathSync(dir);
19748
+ const real2 = fs57.realpathSync(path60.join(dir, name));
19749
+ return real2.startsWith(root2 + path60.sep) && fs57.statSync(real2).isFile() ? real2 : null;
19848
19750
  } catch {
19849
19751
  return null;
19850
19752
  }
@@ -19862,7 +19764,7 @@ function variantsProblem(raw, src, id) {
19862
19764
  if (files.length < 2 || !files.every((f) => typeof f === "string" && f)) return `variants needs at least two labels, each naming a file. ${shape}`;
19863
19765
  if (!files.includes(src)) return `src="${src}" is not one of the variants. Set src to the version shown first.`;
19864
19766
  if (id === void 0) return null;
19865
- const dir = path61.join(ASSETS, String(id));
19767
+ const dir = path60.join(ASSETS, String(id));
19866
19768
  for (const f of files) {
19867
19769
  const parts = f.split("/");
19868
19770
  if (parts.length !== 3 || parts[0] !== ".assets" || parts[1] !== String(id) || !inside(dir, parts[2])) {
@@ -19872,12 +19774,12 @@ function variantsProblem(raw, src, id) {
19872
19774
  return null;
19873
19775
  }
19874
19776
  function compareProblem(attrs, id) {
19875
- const dir = path61.join(ASSETS, String(id));
19777
+ const dir = path60.join(ASSETS, String(id));
19876
19778
  const src = (message) => ({ rule: "compare-src", message });
19877
19779
  const shots = (message) => ({ rule: "compare-shots", message });
19878
19780
  const json = (file) => {
19879
19781
  try {
19880
- return file.endsWith(".json") ? JSON.parse(fs58.readFileSync(file, "utf8")) : null;
19782
+ return file.endsWith(".json") ? JSON.parse(fs57.readFileSync(file, "utf8")) : null;
19881
19783
  } catch {
19882
19784
  return null;
19883
19785
  }
@@ -19902,7 +19804,7 @@ function compareProblem(attrs, id) {
19902
19804
  const file = inside(dir, named2.name);
19903
19805
  if (!file) return { message: `Compare shots ${at} names no file in this card's asset folder. Write the JSON there or fix the path.` };
19904
19806
  try {
19905
- return { data: JSON.parse(fs58.readFileSync(file, "utf8")) };
19807
+ return { data: JSON.parse(fs57.readFileSync(file, "utf8")) };
19906
19808
  } catch {
19907
19809
  return { message: `${at} is not valid JSON.` };
19908
19810
  }
@@ -19920,7 +19822,7 @@ function compareProblem(attrs, id) {
19920
19822
  }
19921
19823
  function validateStoryboards(file, id, text4) {
19922
19824
  const errors = [];
19923
- const dir = path61.join(ASSETS, String(id));
19825
+ const dir = path60.join(ASSETS, String(id));
19924
19826
  for (const [tag, tagOf, rule, fix] of [
19925
19827
  ["Storyboard", storyboardTag, "storyboard-src", "Write the JSON there or fix the path."],
19926
19828
  ["Studio", studioTag, "studio-src", "Write it with `akb raw studio diagram <studio id> <card id>` or fix the path."]
@@ -19956,14 +19858,14 @@ var init_spec_contract = __esm({
19956
19858
  });
19957
19859
 
19958
19860
  // ../cli/src/lib/reconcile.ts
19959
- import fs59 from "node:fs";
19960
- import path62 from "node:path";
19861
+ import fs58 from "node:fs";
19862
+ import path61 from "node:path";
19961
19863
  function liveIds() {
19962
19864
  const ids = /* @__PURE__ */ new Set();
19963
19865
  for (const file of walkMd(TODO)) {
19964
- const base = path62.basename(file);
19866
+ const base = path61.basename(file);
19965
19867
  if (base === "README.md") continue;
19966
- const id = base === "root.md" ? idPrefix(path62.basename(path62.dirname(file))) : idPrefix(base);
19868
+ const id = base === "root.md" ? idPrefix(path61.basename(path61.dirname(file))) : idPrefix(base);
19967
19869
  if (id != null) ids.add(id);
19968
19870
  }
19969
19871
  return ids;
@@ -19971,16 +19873,16 @@ function liveIds() {
19971
19873
  function indexableCards() {
19972
19874
  const out = [];
19973
19875
  for (const dir of walkDirs(TODO)) {
19974
- const id = idPrefix(path62.basename(dir));
19975
- if (id != null && fs59.existsSync(path62.join(dir, "root.md"))) {
19976
- out.push({ id, rel: path62.join(path62.relative(TODO, dir), "root.md").split(path62.sep).join("/") });
19876
+ const id = idPrefix(path61.basename(dir));
19877
+ if (id != null && fs58.existsSync(path61.join(dir, "root.md"))) {
19878
+ out.push({ id, rel: path61.join(path61.relative(TODO, dir), "root.md").split(path61.sep).join("/") });
19977
19879
  }
19978
19880
  }
19979
19881
  for (const file of walkMd(TODO)) {
19980
- const base = path62.basename(file);
19882
+ const base = path61.basename(file);
19981
19883
  if (base === "README.md" || base === "root.md") continue;
19982
- const relTODO = path62.relative(TODO, file);
19983
- const segs = relTODO.split(path62.sep);
19884
+ const relTODO = path61.relative(TODO, file);
19885
+ const segs = relTODO.split(path61.sep);
19984
19886
  if (segs.length !== 1) continue;
19985
19887
  const id = idPrefix(base);
19986
19888
  if (id != null) out.push({ id, rel: segs.join("/") });
@@ -19989,7 +19891,7 @@ function indexableCards() {
19989
19891
  }
19990
19892
  function readmeComplaints(fix) {
19991
19893
  const said2 = [];
19992
- const lines = fs59.readFileSync(README, "utf8").split("\n");
19894
+ const lines = fs58.readFileSync(README, "utf8").split("\n");
19993
19895
  const indexed = /* @__PURE__ */ new Set();
19994
19896
  let fixed = 0;
19995
19897
  for (let i = 0; i < lines.length; i++) {
@@ -19998,13 +19900,13 @@ function readmeComplaints(fix) {
19998
19900
  const id = Number(m[1]);
19999
19901
  const linkPath = m[2];
20000
19902
  indexed.add(id);
20001
- if (fs59.existsSync(path62.join(TODO, linkPath))) continue;
19903
+ if (fs58.existsSync(path61.join(TODO, linkPath))) continue;
20002
19904
  const found2 = locate(id);
20003
19905
  if (!found2) {
20004
19906
  said2.push(`README links #${id} \u2192 ${linkPath}, but no card with that id exists (removed by hand?). Drop the entry or restore the file.`);
20005
19907
  continue;
20006
19908
  }
20007
- const want = (found2.kind === "group" ? path62.join(found2.rel, "root.md") : found2.rel).split(path62.sep).join("/");
19909
+ const want = (found2.kind === "group" ? path61.join(found2.rel, "root.md") : found2.rel).split(path61.sep).join("/");
20008
19910
  if (want === linkPath) continue;
20009
19911
  if (!fix) {
20010
19912
  said2.push(`README links #${id} \u2192 ${linkPath}, which isn't there any more; the card is at ${want}.`);
@@ -20014,7 +19916,7 @@ function readmeComplaints(fix) {
20014
19916
  said2.push(`README link #${id} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
20015
19917
  fixed++;
20016
19918
  }
20017
- if (fixed) fs59.writeFileSync(README, lines.join("\n"));
19919
+ if (fixed) fs58.writeFileSync(README, lines.join("\n"));
20018
19920
  for (const c of indexableCards()) {
20019
19921
  if (!indexed.has(c.id)) {
20020
19922
  said2.push(`card ${c.rel} (#${c.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
@@ -20026,11 +19928,11 @@ function crossRefComplaints() {
20026
19928
  const said2 = [];
20027
19929
  const live = liveIds();
20028
19930
  for (const file of walkMd(TODO)) {
20029
- const base = path62.basename(file);
19931
+ const base = path61.basename(file);
20030
19932
  if (base === "README.md") continue;
20031
- const ownerId = base === "root.md" ? idPrefix(path62.basename(path62.dirname(file))) : idPrefix(base);
19933
+ const ownerId = base === "root.md" ? idPrefix(path61.basename(path61.dirname(file))) : idPrefix(base);
20032
19934
  if (ownerId == null) continue;
20033
- const { meta } = parseFrontmatter(fs59.readFileSync(file, "utf8"));
19935
+ const { meta } = parseFrontmatter(fs58.readFileSync(file, "utf8"));
20034
19936
  if (!meta) continue;
20035
19937
  for (const field2 of ["blocked_by", "related"]) {
20036
19938
  for (const ref of meta[field2] || []) {
@@ -20043,11 +19945,11 @@ function crossRefComplaints() {
20043
19945
  return said2;
20044
19946
  }
20045
19947
  function reconcileBoard() {
20046
- if (!fs59.existsSync(README)) return;
19948
+ if (!fs58.existsSync(README)) return;
20047
19949
  for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
20048
19950
  }
20049
19951
  function boardComplaints() {
20050
- if (!fs59.existsSync(README)) return [];
19952
+ if (!fs58.existsSync(README)) return [];
20051
19953
  try {
20052
19954
  return [...readmeComplaints(false), ...crossRefComplaints()];
20053
19955
  } catch {
@@ -20067,8 +19969,8 @@ var init_reconcile = __esm({
20067
19969
  });
20068
19970
 
20069
19971
  // ../cli/src/commands/card.ts
20070
- import fs60 from "node:fs";
20071
- import path63 from "node:path";
19972
+ import fs59 from "node:fs";
19973
+ import path62 from "node:path";
20072
19974
  function defaultBody(summary = "<\u7528\u4E00\u5C0F\u6BB5\u8BDD\u5148\u8BB2\u53D1\u751F\u4E86\u4EC0\u4E48\u3001\u7528\u6237\u9047\u5230\u4EC0\u4E48\uFF0C\u518D\u8BB2\u8FD9\u5F20\u5361\u8981\u8FBE\u5230\u7684\u7ED3\u679C\u3002>") {
20073
19975
  return [
20074
19976
  summary,
@@ -20094,7 +19996,7 @@ function bodyFromFile(opts) {
20094
19996
  if (opts.body === false) die("pass --body-file or --no-body, not both");
20095
19997
  let text4;
20096
19998
  try {
20097
- text4 = fs60.readFileSync(opts.bodyFile, "utf8");
19999
+ text4 = fs59.readFileSync(opts.bodyFile, "utf8");
20098
20000
  } catch {
20099
20001
  die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
20100
20002
  }
@@ -20118,11 +20020,11 @@ function normalizeBody(text4) {
20118
20020
  const boundary = (line) => /^\s*<!--\s*agent\s*-->\s*$/.test(line);
20119
20021
  const sectionEnd = (line) => /^ {0,3}#{1,2}\s/.test(line) || boundary(line);
20120
20022
  const formal = sections2.some((h) => h.level <= 2 && h.title !== "Done when") || visible.some(boundary);
20121
- const done2 = acceptance.find((h) => h.level === 2);
20023
+ const done = acceptance.find((h) => h.level === 2);
20122
20024
  let checklist = [];
20123
- if (done2) {
20124
- const end2 = visible.findIndex((line, i) => i > done2.index && sectionEnd(line));
20125
- checklist = trim(rows.splice(done2.index, (end2 < 0 ? rows.length : end2) - done2.index));
20025
+ if (done) {
20026
+ const end2 = visible.findIndex((line, i) => i > done.index && sectionEnd(line));
20027
+ checklist = trim(rows.splice(done.index, (end2 < 0 ? rows.length : end2) - done.index));
20126
20028
  checklist[0] = "### Done when";
20127
20029
  }
20128
20030
  if (!formal) rows = [...trim(rows), ...defaultBody("").split("\n").slice(1)];
@@ -20159,20 +20061,20 @@ function cmdCreate(opts) {
20159
20061
  const start = opts.id;
20160
20062
  const slug2 = slugify(opts.slug !== void 0 ? opts.slug : title);
20161
20063
  const fileRel = `${start}-${slug2}.md`;
20162
- const file = path63.join(TODO, fileRel);
20064
+ const file = path62.join(TODO, fileRel);
20163
20065
  const held4 = locate(start) ?? locateArchived(start);
20164
- if (held4 && path63.basename(held4.target) === `${start}-${slug2}.md`) {
20066
+ if (held4 && path62.basename(held4.target) === `${start}-${slug2}.md`) {
20165
20067
  say(start);
20166
20068
  say(` ${rel(held4.target)} was already written`);
20167
20069
  return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
20168
20070
  }
20169
20071
  if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
20170
- if (fs60.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
20072
+ if (fs59.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
20171
20073
  countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
20172
20074
  const meta = { title, priority, status: "todo", blocked_by, related, modules, studio, previews, stages, triage, source, questions };
20173
20075
  const scaffolded = !written && opts.body !== false;
20174
20076
  const body = written ?? (scaffolded ? defaultBody() : "");
20175
- fs60.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
20077
+ fs59.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
20176
20078
  const indexed = addReadmeRef(start, title, fileRel);
20177
20079
  say(start);
20178
20080
  say(
@@ -20224,8 +20126,8 @@ function cmdUpdate(id, flags) {
20224
20126
  if (creating) die(creating, { kind: "card-being-created", id });
20225
20127
  const found2 = locate(id);
20226
20128
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
20227
- const file = found2.kind === "group" ? path63.join(found2.target, "root.md") : found2.target;
20228
- const { meta, body } = parseFrontmatter(fs60.readFileSync(file, "utf8"));
20129
+ const file = found2.kind === "group" ? path62.join(found2.target, "root.md") : found2.target;
20130
+ const { meta, body } = parseFrontmatter(fs59.readFileSync(file, "utf8"));
20229
20131
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
20230
20132
  if (flags.blockedBy !== void 0 && flags.addBlockedBy !== void 0) die("--blocked-by replaces the list and --add-blocked-by appends to it \u2014 pass one");
20231
20133
  if (flags.related !== void 0 && flags.addRelated !== void 0) die("--related replaces the list and --add-related appends to it \u2014 pass one");
@@ -20299,26 +20201,26 @@ function cmdUpdate(id, flags) {
20299
20201
  meta.status = "todo";
20300
20202
  changes.push("status\u2192todo (open questions)");
20301
20203
  }
20302
- const curRel = path63.relative(TODO, file);
20204
+ const curRel = path62.relative(TODO, file);
20303
20205
  const isSubtask = found2.kind === "file" && enclosingGroupRoot(file) !== null;
20304
- let base = path63.basename(file);
20206
+ let base = path62.basename(file);
20305
20207
  if (flags.slug !== void 0) {
20306
20208
  if (found2.kind === "group") die("renaming a group root by script is not supported");
20307
20209
  base = `${id}-${slugify(flags.slug)}.md`;
20308
20210
  }
20309
- const destRel = path63.join(path63.dirname(curRel), base);
20310
- const dest = path63.join(TODO, destRel);
20211
+ const destRel = path62.join(path62.dirname(curRel), base);
20212
+ const dest = path62.join(TODO, destRel);
20311
20213
  const moving = dest !== file;
20312
- if (moving && fs60.existsSync(dest)) die(`${rel(dest)} already exists`);
20313
- fs60.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20314
- if (moving) fs60.renameSync(file, dest);
20214
+ if (moving && fs59.existsSync(dest)) die(`${rel(dest)} already exists`);
20215
+ fs59.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20216
+ if (moving) fs59.renameSync(file, dest);
20315
20217
  if (isSubtask) {
20316
20218
  if (moving || changes.includes("title")) repointReadmeLink(id, curRel, destRel, meta.title);
20317
- if (moving) changes.push(`renamed \u2192 ${destRel.split(path63.sep).join("/")}`);
20219
+ if (moving) changes.push(`renamed \u2192 ${destRel.split(path62.sep).join("/")}`);
20318
20220
  } else if (moving) {
20319
20221
  stripReadmeRefs({ kind: "file", rel: curRel });
20320
20222
  addReadmeRef(id, meta.title, destRel);
20321
- changes.push(`renamed \u2192 ${destRel.split(path63.sep).join("/")}`);
20223
+ changes.push(`renamed \u2192 ${destRel.split(path62.sep).join("/")}`);
20322
20224
  } else if (changes.includes("title")) {
20323
20225
  stripReadmeRefs({ kind: "file", rel: curRel });
20324
20226
  addReadmeRef(id, meta.title, curRel);
@@ -20330,8 +20232,8 @@ function cmdUpdateQuestions(id, input) {
20330
20232
  const ops = readQuestionOps(input.ops ?? []);
20331
20233
  const found2 = locate(id);
20332
20234
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
20333
- const file = found2.kind === "group" ? path63.join(found2.target, "root.md") : found2.target;
20334
- const { meta, body } = parseFrontmatter(fs60.readFileSync(file, "utf8"));
20235
+ const file = found2.kind === "group" ? path62.join(found2.target, "root.md") : found2.target;
20236
+ const { meta, body } = parseFrontmatter(fs59.readFileSync(file, "utf8"));
20335
20237
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
20336
20238
  for (const op of ops) {
20337
20239
  if (!op.question?.agent) continue;
@@ -20339,23 +20241,23 @@ function cmdUpdateQuestions(id, input) {
20339
20241
  if (!agent) die(`--agent "${op.question.agent}" is not an agent on this board`, { kind: "no-such-spec-agent", specAgent: op.question.agent });
20340
20242
  op.question.agent = agent.name;
20341
20243
  }
20342
- let done2;
20244
+ let done;
20343
20245
  try {
20344
- done2 = applyQuestionOps(meta.questions, ops, specRunAgent());
20246
+ done = applyQuestionOps(meta.questions, ops, specRunAgent());
20345
20247
  } catch (e) {
20346
20248
  if (e instanceof QuestionOpError) die(`#${id}: ${e.message}`);
20347
20249
  throw e;
20348
20250
  }
20349
- const { changes } = done2;
20350
- meta.questions = done2.questions;
20251
+ const { changes } = done;
20252
+ meta.questions = done.questions;
20351
20253
  const open3 = meta.questions.length;
20352
20254
  if (open3 > 0 && meta.status === "ready") {
20353
20255
  meta.status = "todo";
20354
20256
  changes.push("status\u2192todo (open questions)");
20355
20257
  }
20356
- fs60.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20258
+ fs59.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20357
20259
  const closed2 = activeDelivery(id) ? "questions_closed_verify" : "questions_closed_user";
20358
- for (const _ of done2.closed) countBoardEvent(closed2);
20260
+ for (const _ of done.closed) countBoardEvent(closed2);
20359
20261
  say(`updated #${id} questions: ${changes.join(", ")} (${open3} open)`);
20360
20262
  return { id, changes, open: open3, file: rel(file) };
20361
20263
  }
@@ -20420,13 +20322,13 @@ var init_config_template = __esm({
20420
20322
  });
20421
20323
 
20422
20324
  // ../cli/src/lib/agent/local.ts
20423
- import fs61 from "node:fs";
20424
- import path64 from "node:path";
20325
+ import fs60 from "node:fs";
20326
+ import path63 from "node:path";
20425
20327
  function takeLocalModels(board2) {
20426
- const file = path64.join(board2, ".local.json");
20328
+ const file = path63.join(board2, ".local.json");
20427
20329
  let held4;
20428
20330
  try {
20429
- held4 = configBlock(JSON.parse(fs61.readFileSync(file, "utf8")));
20331
+ held4 = configBlock(JSON.parse(fs60.readFileSync(file, "utf8")));
20430
20332
  } catch {
20431
20333
  return {};
20432
20334
  }
@@ -20444,7 +20346,7 @@ function takeLocalModels(board2) {
20444
20346
  }
20445
20347
  if (!Object.keys(agents).length) return out;
20446
20348
  delete held4.agents;
20447
- fs61.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
20349
+ fs60.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
20448
20350
  return out;
20449
20351
  }
20450
20352
  var LOCAL_IGNORE_LINE;
@@ -20505,12 +20407,12 @@ var init_identity2 = __esm({
20505
20407
  });
20506
20408
 
20507
20409
  // ../cli/src/lib/signals/migrate.ts
20508
- import fs62 from "node:fs";
20509
- import path65 from "node:path";
20410
+ import fs61 from "node:fs";
20411
+ import path64 from "node:path";
20510
20412
  function readHandled() {
20511
20413
  let text4;
20512
20414
  try {
20513
- text4 = fs62.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
20415
+ text4 = fs61.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
20514
20416
  } catch {
20515
20417
  return [];
20516
20418
  }
@@ -20527,67 +20429,67 @@ function readHandled() {
20527
20429
  return held4;
20528
20430
  }
20529
20431
  function lift(from, into) {
20530
- fs62.mkdirSync(into, { recursive: true });
20531
- fs62.renameSync(from, path65.join(into, freeName(into, path65.basename(from))));
20432
+ fs61.mkdirSync(into, { recursive: true });
20433
+ fs61.renameSync(from, path64.join(into, freeName(into, path64.basename(from))));
20532
20434
  }
20533
20435
  function repoint(dir, from, into) {
20534
20436
  let entries;
20535
20437
  try {
20536
- entries = fs62.readdirSync(dir, { withFileTypes: true });
20438
+ entries = fs61.readdirSync(dir, { withFileTypes: true });
20537
20439
  } catch {
20538
20440
  return;
20539
20441
  }
20540
20442
  for (const entry of entries) {
20541
20443
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
20542
- const file = path65.join(dir, entry.name);
20543
- const text4 = fs62.readFileSync(file, "utf8");
20544
- if (text4.includes(from)) fs62.writeFileSync(file, text4.split(from).join(into));
20444
+ const file = path64.join(dir, entry.name);
20445
+ const text4 = fs61.readFileSync(file, "utf8");
20446
+ if (text4.includes(from)) fs61.writeFileSync(file, text4.split(from).join(into));
20545
20447
  }
20546
20448
  }
20547
20449
  function dropIfEmpty2(dir) {
20548
20450
  try {
20549
- fs62.rmdirSync(dir);
20451
+ fs61.rmdirSync(dir);
20550
20452
  } catch {
20551
20453
  }
20552
20454
  }
20553
20455
  function liftInbox() {
20554
- if (!fs62.existsSync(SIGNALS_OLD_INBOX)) return;
20555
- const oldFiles = path65.join(SIGNALS_OLD_INBOX, "files");
20556
- if (fs62.existsSync(oldFiles)) {
20557
- for (const entry of fs62.readdirSync(oldFiles, { withFileTypes: true })) {
20558
- if (entry.isFile()) lift(path65.join(oldFiles, entry.name), SIGNALS_FILES);
20456
+ if (!fs61.existsSync(SIGNALS_OLD_INBOX)) return;
20457
+ const oldFiles = path64.join(SIGNALS_OLD_INBOX, "files");
20458
+ if (fs61.existsSync(oldFiles)) {
20459
+ for (const entry of fs61.readdirSync(oldFiles, { withFileTypes: true })) {
20460
+ if (entry.isFile()) lift(path64.join(oldFiles, entry.name), SIGNALS_FILES);
20559
20461
  }
20560
20462
  dropIfEmpty2(oldFiles);
20561
20463
  }
20562
- const held4 = new Set(readFolder2(TRIAGE).map((signal2) => signal2.sourceId));
20563
- for (const entry of fs62.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
20464
+ const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
20465
+ for (const entry of fs61.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
20564
20466
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
20565
- const from = path65.join(SIGNALS_OLD_INBOX, entry.name);
20467
+ const from = path64.join(SIGNALS_OLD_INBOX, entry.name);
20566
20468
  const item = parse(from);
20567
20469
  if (item && held4.has(item.sourceId)) {
20568
- fs62.rmSync(from, { force: true });
20470
+ fs61.rmSync(from, { force: true });
20569
20471
  continue;
20570
20472
  }
20571
20473
  if (item) held4.add(item.sourceId);
20572
20474
  lift(from, TRIAGE);
20573
20475
  }
20574
- const wasAt = asWritten(path65.join(SIGNALS_OLD_INBOX, "files"));
20476
+ const wasAt = asWritten(path64.join(SIGNALS_OLD_INBOX, "files"));
20575
20477
  const nowAt = asWritten(SIGNALS_FILES);
20576
20478
  for (const dir of [TRIAGE, SIGNALS_ARCHIVED, SIGNALS_DISMISSED]) repoint(dir, wasAt, nowAt);
20577
20479
  dropIfEmpty2(SIGNALS_OLD_INBOX);
20578
20480
  }
20579
20481
  function liftHandled() {
20580
- if (!fs62.existsSync(SIGNALS_OLD_HANDLED)) return;
20482
+ if (!fs61.existsSync(SIGNALS_OLD_HANDLED)) return;
20581
20483
  const lines = readHandled();
20582
20484
  const held4 = /* @__PURE__ */ new Set([
20583
- ...readFolder2(TRIAGE).map((signal2) => signal2.sourceId),
20584
- ...readFolder2(SIGNALS_ARCHIVED).map((signal2) => signal2.sourceId),
20485
+ ...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
20486
+ ...readFolder(SIGNALS_ARCHIVED).map((signal2) => signal2.sourceId),
20585
20487
  ...readAllDismissed().map((signal2) => signal2.sourceId)
20586
20488
  ]);
20587
20489
  for (const { sourceId, when } of lines) {
20588
20490
  if (held4.has(sourceId)) continue;
20589
20491
  held4.add(sourceId);
20590
- fs62.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
20492
+ fs61.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
20591
20493
  const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
20592
20494
  const front = [
20593
20495
  "---",
@@ -20597,13 +20499,13 @@ function liftHandled() {
20597
20499
  "---",
20598
20500
  ""
20599
20501
  ];
20600
- fs62.writeFileSync(path65.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
20502
+ fs61.writeFileSync(path64.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
20601
20503
  `);
20602
20504
  }
20603
- fs62.rmSync(SIGNALS_OLD_HANDLED, { force: true });
20505
+ fs61.rmSync(SIGNALS_OLD_HANDLED, { force: true });
20604
20506
  }
20605
20507
  function migrateTriage() {
20606
- if (!fs62.existsSync(SIGNALS_OLD_INBOX) && !fs62.existsSync(SIGNALS_OLD_HANDLED)) return;
20508
+ if (!fs61.existsSync(SIGNALS_OLD_INBOX) && !fs61.existsSync(SIGNALS_OLD_HANDLED)) return;
20607
20509
  try {
20608
20510
  liftInbox();
20609
20511
  liftHandled();
@@ -20618,13 +20520,13 @@ var init_migrate = __esm({
20618
20520
  init_yaml();
20619
20521
  init_inbox();
20620
20522
  HANDLED_LINE = /^-\s+(.+?)\s+—\s+(.+)$/;
20621
- asWritten = (dir) => `${rel(dir).split(path65.sep).join("/")}/`;
20523
+ asWritten = (dir) => `${rel(dir).split(path64.sep).join("/")}/`;
20622
20524
  }
20623
20525
  });
20624
20526
 
20625
20527
  // ../cli/src/lib/signals/add.ts
20626
- import fs63 from "node:fs";
20627
- import path66 from "node:path";
20528
+ import fs62 from "node:fs";
20529
+ import path65 from "node:path";
20628
20530
  import { createHash as createHash4 } from "node:crypto";
20629
20531
  function linkTitle(url) {
20630
20532
  let at;
@@ -20637,7 +20539,7 @@ function linkTitle(url) {
20637
20539
  return oneLine(where) || url.slice(0, TITLE_MAX);
20638
20540
  }
20639
20541
  function asText(file) {
20640
- const ext = path66.extname(file.name).toLowerCase();
20542
+ const ext = path65.extname(file.name).toLowerCase();
20641
20543
  if (!file.type.startsWith("text/") && file.type !== "application/json" && !TEXT_EXTENSIONS.has(ext)) return null;
20642
20544
  try {
20643
20545
  const text4 = new TextDecoder("utf-8", { fatal: true }).decode(file.data);
@@ -20647,9 +20549,9 @@ function asText(file) {
20647
20549
  }
20648
20550
  }
20649
20551
  function fileName2(name, data) {
20650
- const base = path66.basename(name);
20651
- const ext = path66.extname(base).toLowerCase().slice(0, 12);
20652
- const word = path66.basename(base, path66.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
20552
+ const base = path65.basename(name);
20553
+ const ext = path65.extname(base).toLowerCase().slice(0, 12);
20554
+ const word = path65.basename(base, path65.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
20653
20555
  const hash2 = createHash4("sha256").update(data).digest("hex").slice(0, 8);
20654
20556
  return `${word}-${hash2}${ext}`;
20655
20557
  }
@@ -20658,9 +20560,9 @@ function addToInbox(drop) {
20658
20560
  const typed = (drop.text ?? "").trim();
20659
20561
  const file = drop.file;
20660
20562
  if (!typed && !file) return { ok: false, error: "nothing to add \u2014 paste a link or some text, or drop a file." };
20661
- if (file && file.data.length === 0) return { ok: false, error: `${path66.basename(file.name)} is empty.` };
20563
+ if (file && file.data.length === 0) return { ok: false, error: `${path65.basename(file.name)} is empty.` };
20662
20564
  if (file && file.data.length > MAX_BYTES2) {
20663
- return { ok: false, error: `${path66.basename(file.name)} is over ${MAX_BYTES2 / 1024 / 1024} MB \u2014 too big for the board.` };
20565
+ return { ok: false, error: `${path65.basename(file.name)} is over ${MAX_BYTES2 / 1024 / 1024} MB \u2014 too big for the board.` };
20664
20566
  }
20665
20567
  const read3 = describe(typed, file);
20666
20568
  const keep2 = read3.keep;
@@ -20682,8 +20584,8 @@ ${incoming.summary}`);
20682
20584
  if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
20683
20585
  try {
20684
20586
  if (keep2) {
20685
- fs63.mkdirSync(SIGNALS_FILES, { recursive: true });
20686
- fs63.writeFileSync(keep2.at, keep2.data);
20587
+ fs62.mkdirSync(SIGNALS_FILES, { recursive: true });
20588
+ fs62.writeFileSync(keep2.at, keep2.data);
20687
20589
  }
20688
20590
  return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
20689
20591
  } catch (e) {
@@ -20697,7 +20599,7 @@ function describe(typed, file) {
20697
20599
  return only ? [only] : [];
20698
20600
  };
20699
20601
  if (file) {
20700
- const name = path66.basename(file.name);
20602
+ const name = path65.basename(file.name);
20701
20603
  const text4 = asText(file);
20702
20604
  const note = typed ? `
20703
20605
 
@@ -20709,7 +20611,7 @@ ${typed}` : "";
20709
20611
  const at = keepAt(file);
20710
20612
  return {
20711
20613
  incoming: {
20712
- title: path66.basename(name, path66.extname(name)) || name,
20614
+ title: path65.basename(name, path65.extname(name)) || name,
20713
20615
  summary: `${name} \u2014 ${boardRel2(at)}${note}`,
20714
20616
  ...named2
20715
20617
  },
@@ -20747,73 +20649,73 @@ var init_add = __esm({
20747
20649
  MAX_BYTES2 = 25 * 1024 * 1024;
20748
20650
  TITLE_MAX = 120;
20749
20651
  TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".markdown", ".txt", ".text", ".csv", ".json", ".yml", ".yaml", ".log"]);
20750
- boardRel2 = (file) => rel(file).split(path66.sep).join("/");
20652
+ boardRel2 = (file) => rel(file).split(path65.sep).join("/");
20751
20653
  oneLine = (text4) => {
20752
20654
  const first = text4.split("\n").find((line) => line.trim()) ?? "";
20753
20655
  const clean = first.replace(/^#+\s*/, "").trim();
20754
20656
  return clean.length > TITLE_MAX ? `${clean.slice(0, TITLE_MAX - 1).trimEnd()}\u2026` : clean;
20755
20657
  };
20756
- keepAt = (file) => path66.join(SIGNALS_FILES, fileName2(file.name, file.data));
20658
+ keepAt = (file) => path65.join(SIGNALS_FILES, fileName2(file.name, file.data));
20757
20659
  }
20758
20660
  });
20759
20661
 
20760
20662
  // ../cli/src/lib/recurring.ts
20761
- import fs64 from "node:fs";
20762
- import path67 from "node:path";
20663
+ import fs63 from "node:fs";
20664
+ import path66 from "node:path";
20763
20665
  function migratePruneMemoryCard() {
20764
20666
  const dir = recurringDir();
20765
20667
  let names3;
20766
20668
  try {
20767
- names3 = fs64.readdirSync(dir);
20669
+ names3 = fs63.readdirSync(dir);
20768
20670
  } catch {
20769
20671
  return null;
20770
20672
  }
20771
20673
  const name = names3.find((entry) => entry.endsWith(`-${PRUNE_SLUG}.md`));
20772
20674
  if (!name) return null;
20773
- const file = path67.join(dir, name);
20675
+ const file = path66.join(dir, name);
20774
20676
  try {
20775
- const { meta } = parseFrontmatter(fs64.readFileSync(file, "utf8"));
20677
+ const { meta } = parseFrontmatter(fs63.readFileSync(file, "utf8"));
20776
20678
  const cadence = meta?.cadence;
20777
20679
  if (typeof cadence === "string") adoptMemoryPruneCadence(cadence);
20778
20680
  } catch {
20779
20681
  }
20780
- fs64.rmSync(file, { force: true });
20682
+ fs63.rmSync(file, { force: true });
20781
20683
  return rel(file);
20782
20684
  }
20783
20685
  function legacyCards() {
20784
20686
  const dir = recurringDir();
20785
- if (!fs64.existsSync(dir)) return [];
20687
+ if (!fs63.existsSync(dir)) return [];
20786
20688
  const cards = [];
20787
- for (const entry of fs64.readdirSync(dir, { withFileTypes: true })) {
20689
+ for (const entry of fs63.readdirSync(dir, { withFileTypes: true })) {
20788
20690
  const id = idPrefix(entry.name);
20789
20691
  if (id === null) continue;
20790
- const full = path67.join(dir, entry.name);
20692
+ const full = path66.join(dir, entry.name);
20791
20693
  const slug2 = entry.name.replace(/\.md$/, "").replace(/^\d+-?/, "");
20792
20694
  if (entry.isFile() && entry.name.endsWith(".md")) cards.push({ id, slug: slug2, file: full });
20793
- else if (entry.isDirectory() && fs64.existsSync(path67.join(full, "root.md"))) {
20794
- cards.push({ id, slug: slug2, file: path67.join(full, "root.md"), folder: full });
20695
+ else if (entry.isDirectory() && fs63.existsSync(path66.join(full, "root.md"))) {
20696
+ cards.push({ id, slug: slug2, file: path66.join(full, "root.md"), folder: full });
20795
20697
  }
20796
20698
  }
20797
20699
  return cards.sort((a, b) => a.id - b.id);
20798
20700
  }
20799
20701
  function mergeInto2(from, to, skip = []) {
20800
- fs64.mkdirSync(to, { recursive: true });
20801
- for (const entry of fs64.readdirSync(from, { withFileTypes: true })) {
20702
+ fs63.mkdirSync(to, { recursive: true });
20703
+ for (const entry of fs63.readdirSync(from, { withFileTypes: true })) {
20802
20704
  if (skip.includes(entry.name)) continue;
20803
- const source = path67.join(from, entry.name);
20804
- const target = path67.join(to, entry.name);
20805
- if (!fs64.existsSync(target)) fs64.renameSync(source, target);
20806
- else if (entry.isDirectory() && fs64.statSync(target).isDirectory()) mergeInto2(source, target);
20705
+ const source = path66.join(from, entry.name);
20706
+ const target = path66.join(to, entry.name);
20707
+ if (!fs63.existsSync(target)) fs63.renameSync(source, target);
20708
+ else if (entry.isDirectory() && fs63.statSync(target).isDirectory()) mergeInto2(source, target);
20807
20709
  }
20808
- if (isEmpty(from)) fs64.rmSync(from, { recursive: true, force: true });
20710
+ if (isEmpty(from)) fs63.rmSync(from, { recursive: true, force: true });
20809
20711
  }
20810
20712
  function moveSideFolders() {
20811
20713
  const dir = recurringDir();
20812
- for (const entry of fs64.readdirSync(dir, { withFileTypes: true })) {
20714
+ for (const entry of fs63.readdirSync(dir, { withFileTypes: true })) {
20813
20715
  if (!entry.isDirectory() || idPrefix(entry.name) !== null) continue;
20814
- const from = path67.join(dir, entry.name);
20815
- if (isEmpty(from)) fs64.rmSync(from, { recursive: true, force: true });
20816
- else mergeInto2(from, path67.join(AGENTS, entry.name));
20716
+ const from = path66.join(dir, entry.name);
20717
+ if (isEmpty(from)) fs63.rmSync(from, { recursive: true, force: true });
20718
+ else mergeInto2(from, path66.join(AGENTS, entry.name));
20817
20719
  }
20818
20720
  }
20819
20721
  function sections(body) {
@@ -20863,8 +20765,8 @@ function agentName(card, text4) {
20863
20765
  const known2 = /* @__PURE__ */ new Set([...specAgentCatalog().agents.map((a) => a.name), ...ROLE_NAMES]);
20864
20766
  for (const name of [slug2, `${slug2}-${card.id}`]) {
20865
20767
  if (!AGENT_NAME.test(name)) continue;
20866
- const file = path67.join(AGENTS, name, AGENT_FILE2);
20867
- const written = fs64.existsSync(file) ? fs64.readFileSync(file, "utf8") : null;
20768
+ const file = path66.join(AGENTS, name, AGENT_FILE2);
20769
+ const written = fs63.existsSync(file) ? fs63.readFileSync(file, "utf8") : null;
20868
20770
  if (written === text4(name)) return name;
20869
20771
  if (written === null && !known2.has(name)) return name;
20870
20772
  }
@@ -20881,11 +20783,11 @@ ${q.options.map((o) => `- ${o}`).join("\n")}` : "";
20881
20783
  function removeCard(card) {
20882
20784
  dropCrossRefs(card.id);
20883
20785
  const target = card.folder ?? card.file;
20884
- stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path67.relative(TODO, target).split(path67.sep).join("/") });
20885
- fs64.rmSync(target, { recursive: true, force: true });
20786
+ stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path66.relative(TODO, target).split(path66.sep).join("/") });
20787
+ fs63.rmSync(target, { recursive: true, force: true });
20886
20788
  }
20887
20789
  function migrateCard(card) {
20888
- const { meta, body } = parseFrontmatter(fs64.readFileSync(card.file, "utf8"));
20790
+ const { meta, body } = parseFrontmatter(fs63.readFileSync(card.file, "utf8"));
20889
20791
  if (!meta) throw new Error("its frontmatter cannot be read");
20890
20792
  const raw = meta;
20891
20793
  const said2 = (key) => typeof raw[key] === "string" ? raw[key].trim() : "";
@@ -20895,19 +20797,19 @@ function migrateCard(card) {
20895
20797
  if (!flow) throw new Error(noStudioMessage(""));
20896
20798
  const text4 = (name2) => agentText(name2, meta.title || card.slug, body);
20897
20799
  const name = agentName(card, text4);
20898
- const dir = path67.join(AGENTS, name);
20899
- const file = path67.join(dir, AGENT_FILE2);
20900
- const madeDir = !fs64.existsSync(dir);
20901
- const wrote = !fs64.existsSync(file);
20800
+ const dir = path66.join(AGENTS, name);
20801
+ const file = path66.join(dir, AGENT_FILE2);
20802
+ const madeDir = !fs63.existsSync(dir);
20803
+ const wrote = !fs63.existsSync(file);
20902
20804
  try {
20903
- fs64.mkdirSync(dir, { recursive: true });
20904
- if (wrote) fs64.writeFileSync(file, text4(name));
20805
+ fs63.mkdirSync(dir, { recursive: true });
20806
+ if (wrote) fs63.writeFileSync(file, text4(name));
20905
20807
  const adopted = adoptStudioScheduled(flow.id, name, { cadence, lastRun });
20906
20808
  if (!adopted.ok) throw new Error(adopted.error);
20907
20809
  questionsToTriage(meta, name);
20908
20810
  } catch (e) {
20909
- if (madeDir) fs64.rmSync(dir, { recursive: true, force: true });
20910
- else if (wrote) fs64.rmSync(file, { force: true });
20811
+ if (madeDir) fs63.rmSync(dir, { recursive: true, force: true });
20812
+ else if (wrote) fs63.rmSync(file, { force: true });
20911
20813
  throw e;
20912
20814
  }
20913
20815
  if (card.folder) mergeInto2(card.folder, dir, ["root.md"]);
@@ -20915,31 +20817,31 @@ function migrateCard(card) {
20915
20817
  return { card: rel(card.file), agent: name, studio: flow.name, on: !!cadence, cadence };
20916
20818
  }
20917
20819
  function migrateRecurringCards() {
20918
- const done2 = { agents: [], removed: [], failed: [] };
20820
+ const done = { agents: [], removed: [], failed: [] };
20919
20821
  const dir = recurringDir();
20920
- if (!fs64.existsSync(dir)) return done2;
20822
+ if (!fs63.existsSync(dir)) return done;
20921
20823
  migratePruneMemoryCard();
20922
20824
  moveSideFolders();
20923
20825
  for (const card of legacyCards()) {
20924
20826
  try {
20925
20827
  if (card.slug === FETCH_SLUG) {
20926
20828
  removeCard(card);
20927
- done2.removed.push(rel(card.file));
20928
- } else done2.agents.push(migrateCard(card));
20829
+ done.removed.push(rel(card.file));
20830
+ } else done.agents.push(migrateCard(card));
20929
20831
  } catch (e) {
20930
- done2.failed.push({ card: rel(card.file), why: e instanceof Error ? e.message : String(e) });
20832
+ done.failed.push({ card: rel(card.file), why: e instanceof Error ? e.message : String(e) });
20931
20833
  }
20932
20834
  }
20933
- if (isEmpty(dir)) fs64.rmSync(dir, { recursive: true, force: true });
20934
- return done2;
20835
+ if (isEmpty(dir)) fs63.rmSync(dir, { recursive: true, force: true });
20836
+ return done;
20935
20837
  }
20936
- function recurringMigrationLines(done2) {
20838
+ function recurringMigrationLines(done) {
20937
20839
  return [
20938
- ...done2.agents.map(
20840
+ ...done.agents.map(
20939
20841
  (one) => `${one.card} is now the scheduled agent \`${one.agent}\` in the ${one.studio} studio \u2014 ` + (one.on ? `on, cadence ${one.cadence}` : "off: it had no cadence, so it runs only when you run it")
20940
20842
  ),
20941
- ...done2.removed.map((card) => `removed ${card} \u2014 write a scheduled agent to pull triage items on a cadence (\`akb guide write-agent\`)`),
20942
- ...done2.failed.map((one) => `could not turn ${one.card} into a scheduled agent: ${one.why}. It is left as it was and tried again next time`)
20843
+ ...done.removed.map((card) => `removed ${card} \u2014 write a scheduled agent to pull triage items on a cadence (\`akb guide write-agent\`)`),
20844
+ ...done.failed.map((one) => `could not turn ${one.card} into a scheduled agent: ${one.why}. It is left as it was and tried again next time`)
20943
20845
  ];
20944
20846
  }
20945
20847
  var PRUNE_SLUG, FETCH_SLUG, AGENT_FILE2, recurringDir, isEmpty, SECTION;
@@ -20963,14 +20865,14 @@ var init_recurring = __esm({
20963
20865
  PRUNE_SLUG = "prune-the-memory";
20964
20866
  FETCH_SLUG = "fetch-triage-items";
20965
20867
  AGENT_FILE2 = "AGENT.md";
20966
- recurringDir = () => path67.join(TODO, LEGACY_RECURRING);
20967
- isEmpty = (dir) => fs64.readdirSync(dir).every((name) => name === ".DS_Store");
20868
+ recurringDir = () => path66.join(TODO, LEGACY_RECURRING);
20869
+ isEmpty = (dir) => fs63.readdirSync(dir).every((name) => name === ".DS_Store");
20968
20870
  SECTION = /^##\s+(.+?)\s*$/;
20969
20871
  }
20970
20872
  });
20971
20873
 
20972
20874
  // ../cli/src/commands/init.ts
20973
- import fs65 from "node:fs";
20875
+ import fs64 from "node:fs";
20974
20876
  function boardReadme() {
20975
20877
  return `# Board
20976
20878
 
@@ -20983,20 +20885,20 @@ _(none)_
20983
20885
  `;
20984
20886
  }
20985
20887
  function writeConfigIfMissing() {
20986
- if (fs65.existsSync(CONFIG)) return false;
20987
- fs65.mkdirSync(KANBAN, { recursive: true });
20988
- fs65.writeFileSync(CONFIG, CONFIG_TEMPLATE);
20888
+ if (fs64.existsSync(CONFIG)) return false;
20889
+ fs64.mkdirSync(KANBAN, { recursive: true });
20890
+ fs64.writeFileSync(CONFIG, CONFIG_TEMPLATE);
20989
20891
  return true;
20990
20892
  }
20991
20893
  function writeModulesIfMissing() {
20992
- if (fs65.existsSync(MODULES_MD)) return false;
20993
- fs65.mkdirSync(KANBAN, { recursive: true });
20994
- fs65.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
20894
+ if (fs64.existsSync(MODULES_MD)) return false;
20895
+ fs64.mkdirSync(KANBAN, { recursive: true });
20896
+ fs64.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
20995
20897
  return true;
20996
20898
  }
20997
20899
  function writeGitignoreIfMissing() {
20998
- fs65.mkdirSync(KANBAN, { recursive: true });
20999
- const text4 = fs65.existsSync(KANBAN_GITIGNORE) ? fs65.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
20900
+ fs64.mkdirSync(KANBAN, { recursive: true });
20901
+ const text4 = fs64.existsSync(KANBAN_GITIGNORE) ? fs64.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
21000
20902
  const has = (rule) => text4.split("\n").some((line) => line.trim() === rule.line);
21001
20903
  const missing = IGNORE_RULES.filter((rule) => !has(rule));
21002
20904
  if (!missing.length) return false;
@@ -21004,45 +20906,45 @@ function writeGitignoreIfMissing() {
21004
20906
  ${rule.line}
21005
20907
  `).join("");
21006
20908
  const separator = !text4 || text4.endsWith("\n") ? "" : "\n";
21007
- fs65.writeFileSync(KANBAN_GITIGNORE, `${text4}${separator}${block}`);
20909
+ fs64.writeFileSync(KANBAN_GITIGNORE, `${text4}${separator}${block}`);
21008
20910
  return true;
21009
20911
  }
21010
20912
  function writeSkeletonIfMissing() {
21011
20913
  const added = [];
21012
- if (!fs65.existsSync(TODO)) {
21013
- fs65.mkdirSync(TODO, { recursive: true });
20914
+ if (!fs64.existsSync(TODO)) {
20915
+ fs64.mkdirSync(TODO, { recursive: true });
21014
20916
  added.push(`${rel(TODO)}/`);
21015
20917
  }
21016
- if (!fs65.existsSync(README)) {
21017
- fs65.writeFileSync(README, boardReadme());
20918
+ if (!fs64.existsSync(README)) {
20919
+ fs64.writeFileSync(README, boardReadme());
21018
20920
  added.push(rel(README));
21019
20921
  }
21020
20922
  return added;
21021
20923
  }
21022
20924
  function retireReleases() {
21023
- const done2 = [];
21024
- if (fs65.existsSync(RELEASES)) {
21025
- fs65.rmSync(RELEASES);
21026
- done2.push(`deleted ${rel(RELEASES)}`);
20925
+ const done = [];
20926
+ if (fs64.existsSync(RELEASES)) {
20927
+ fs64.rmSync(RELEASES);
20928
+ done.push(`deleted ${rel(RELEASES)}`);
21027
20929
  }
21028
20930
  let cards = 0;
21029
20931
  for (const dir of [TODO, ARCHIVE]) {
21030
- if (!fs65.existsSync(dir)) continue;
20932
+ if (!fs64.existsSync(dir)) continue;
21031
20933
  for (const file of walkMd(dir)) {
21032
- const text4 = fs65.readFileSync(file, "utf8");
20934
+ const text4 = fs64.readFileSync(file, "utf8");
21033
20935
  const end2 = text4.startsWith("---\n") ? text4.indexOf("\n---", 3) : -1;
21034
20936
  if (end2 < 0) continue;
21035
20937
  const head2 = text4.slice(0, end2).replace(/\nrelease:[^\n]*/, "");
21036
20938
  if (head2.length === end2) continue;
21037
- fs65.writeFileSync(file, head2 + text4.slice(end2));
20939
+ fs64.writeFileSync(file, head2 + text4.slice(end2));
21038
20940
  cards++;
21039
20941
  }
21040
20942
  }
21041
- if (cards) done2.push(`cleared the release on ${cards} card${cards === 1 ? "" : "s"}`);
21042
- return done2.join(", ");
20943
+ if (cards) done.push(`cleared the release on ${cards} card${cards === 1 ? "" : "s"}`);
20944
+ return done.join(", ");
21043
20945
  }
21044
20946
  function cmdInit() {
21045
- if (fs65.existsSync(KANBAN)) {
20947
+ if (fs64.existsSync(KANBAN)) {
21046
20948
  const added = [
21047
20949
  ...writeSkeletonIfMissing(),
21048
20950
  writeConfigIfMissing() && rel(CONFIG),
@@ -21077,8 +20979,8 @@ function cmdInit() {
21077
20979
  }
21078
20980
  return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
21079
20981
  }
21080
- fs65.mkdirSync(TODO, { recursive: true });
21081
- fs65.writeFileSync(README, boardReadme());
20982
+ fs64.mkdirSync(TODO, { recursive: true });
20983
+ fs64.writeFileSync(README, boardReadme());
21082
20984
  writeConfigIfMissing();
21083
20985
  scaffoldProjectMemory();
21084
20986
  writeModulesIfMissing();
@@ -21167,25 +21069,25 @@ var init_scheduled = __esm({
21167
21069
  });
21168
21070
 
21169
21071
  // ../cli/src/lib/card-age.ts
21170
- import fs66 from "node:fs";
21171
- import path68 from "node:path";
21072
+ import fs65 from "node:fs";
21073
+ import path67 from "node:path";
21172
21074
  function staleAfterIn(config) {
21173
21075
  const days = Number(LINE.exec(config)?.[1]);
21174
21076
  return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
21175
21077
  }
21176
21078
  function staleAfter() {
21177
- if (!fs66.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
21178
- return staleAfterIn(fs66.readFileSync(CONFIG, "utf8"));
21079
+ if (!fs65.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
21080
+ return staleAfterIn(fs65.readFileSync(CONFIG, "utf8"));
21179
21081
  }
21180
21082
  function todoPathspec(top) {
21181
- const from = path68.relative(real(top), real(TODO));
21182
- if (!from || from.startsWith("..") || path68.isAbsolute(from)) return null;
21183
- return from.split(path68.sep).join("/");
21083
+ const from = path67.relative(real(top), real(TODO));
21084
+ if (!from || from.startsWith("..") || path67.isAbsolute(from)) return null;
21085
+ return from.split(path67.sep).join("/");
21184
21086
  }
21185
21087
  function cardFile2(spec, printed) {
21186
21088
  const p = unquotePath(printed);
21187
21089
  if (!p.startsWith(`${spec}/`)) return null;
21188
- return path68.join(TODO, ...p.slice(spec.length + 1).split("/"));
21090
+ return path67.join(TODO, ...p.slice(spec.length + 1).split("/"));
21189
21091
  }
21190
21092
  function dirtyCards(top, spec) {
21191
21093
  const out = git(["status", "--porcelain", "--untracked-files=all", "--", spec], top);
@@ -21232,9 +21134,9 @@ var init_card_age = __esm({
21232
21134
  gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
21233
21135
  real = (p) => {
21234
21136
  try {
21235
- return fs66.realpathSync(p);
21137
+ return fs65.realpathSync(p);
21236
21138
  } catch {
21237
- return path68.resolve(p);
21139
+ return path67.resolve(p);
21238
21140
  }
21239
21141
  };
21240
21142
  unquotePath = (line) => {
@@ -21268,8 +21170,8 @@ var init_card_holds = __esm({
21268
21170
  });
21269
21171
 
21270
21172
  // ../cli/src/commands/list.ts
21271
- import fs67 from "node:fs";
21272
- import path69 from "node:path";
21173
+ import fs66 from "node:fs";
21174
+ import path68 from "node:path";
21273
21175
  function summaryLine(body) {
21274
21176
  const lines = body.split("\n");
21275
21177
  let i = 0;
@@ -21285,13 +21187,13 @@ function summaryLine(body) {
21285
21187
  function openRows() {
21286
21188
  const rows = [];
21287
21189
  for (const file of walkMd(TODO)) {
21288
- const base = path69.basename(file);
21190
+ const base = path68.basename(file);
21289
21191
  if (base === "README.md") continue;
21290
21192
  const isRoot = base === "root.md";
21291
- const id = isRoot ? idPrefix(path69.basename(path69.dirname(file))) : idPrefix(base);
21193
+ const id = isRoot ? idPrefix(path68.basename(path68.dirname(file))) : idPrefix(base);
21292
21194
  if (id == null) continue;
21293
- if (isLegacyRecurring(path69.relative(TODO, file))) continue;
21294
- const { meta, body } = parseFrontmatter(fs67.readFileSync(file, "utf8"));
21195
+ if (isLegacyRecurring(path68.relative(TODO, file))) continue;
21196
+ const { meta, body } = parseFrontmatter(fs66.readFileSync(file, "utf8"));
21295
21197
  rows.push({
21296
21198
  id,
21297
21199
  file,
@@ -21333,15 +21235,15 @@ function cmdStale(rows, all2, scope, mod) {
21333
21235
  }
21334
21236
  function archivedFiles() {
21335
21237
  const files = /* @__PURE__ */ new Map();
21336
- if (!fs67.existsSync(ARCHIVE)) return files;
21238
+ if (!fs66.existsSync(ARCHIVE)) return files;
21337
21239
  for (const file of walkMd(ARCHIVE)) {
21338
- const id = idPrefix(path69.basename(file));
21240
+ const id = idPrefix(path68.basename(file));
21339
21241
  if (id !== null) files.set(id, file);
21340
21242
  }
21341
21243
  for (const dir of walkDirs(ARCHIVE)) {
21342
- const id = idPrefix(path69.basename(dir));
21343
- const root2 = path69.join(dir, "root.md");
21344
- if (id !== null && fs67.existsSync(root2)) files.set(id, root2);
21244
+ const id = idPrefix(path68.basename(dir));
21245
+ const root2 = path68.join(dir, "root.md");
21246
+ if (id !== null && fs66.existsSync(root2)) files.set(id, root2);
21345
21247
  }
21346
21248
  return files;
21347
21249
  }
@@ -21451,8 +21353,8 @@ var init_list = __esm({
21451
21353
  });
21452
21354
 
21453
21355
  // ../cli/src/lib/card-sources.ts
21454
- import fs68 from "node:fs";
21455
- import path70 from "node:path";
21356
+ import fs67 from "node:fs";
21357
+ import path69 from "node:path";
21456
21358
  function planById(id) {
21457
21359
  const found2 = readPlan(`plans/${id}-.md`);
21458
21360
  return found2?.text.trim() ? found2 : null;
@@ -21462,8 +21364,8 @@ function cardLink(id) {
21462
21364
  const found2 = open3 ?? locateArchived(id);
21463
21365
  if (!found2) return null;
21464
21366
  try {
21465
- const file = found2.kind === "group" ? path70.join(found2.target, "root.md") : found2.target;
21466
- const title = parseFrontmatter(fs68.readFileSync(file, "utf8")).meta?.title ?? "";
21367
+ const file = found2.kind === "group" ? path69.join(found2.target, "root.md") : found2.target;
21368
+ const title = parseFrontmatter(fs67.readFileSync(file, "utf8")).meta?.title ?? "";
21467
21369
  return { kind: "card", ref: String(id), title, ...open3 ? {} : { archived: true } };
21468
21370
  } catch {
21469
21371
  return null;
@@ -21488,7 +21390,7 @@ function link(ref, items) {
21488
21390
  if (ref.kind === "plan") return planLink(ref.id);
21489
21391
  if (ref.kind === "card") return cardLink(ref.id);
21490
21392
  if (ref.kind === "url") return urlLink(ref.url);
21491
- const item = items().find((signal2) => path70.basename(signal2.relPath) === ref.file);
21393
+ const item = items().find((signal2) => path69.basename(signal2.relPath) === ref.file);
21492
21394
  return item ? itemLink(item) : null;
21493
21395
  }
21494
21396
  function cardSources(meta, body) {
@@ -21529,12 +21431,12 @@ var init_card_sources = __esm({
21529
21431
  });
21530
21432
 
21531
21433
  // ../cli/src/lib/view/read.ts
21532
- import fs69 from "node:fs";
21533
- import path71 from "node:path";
21434
+ import fs68 from "node:fs";
21435
+ import path70 from "node:path";
21534
21436
  function readCard(file, relFromTodo) {
21535
- const id = idPrefix(path71.basename(relFromTodo));
21437
+ const id = idPrefix(path70.basename(relFromTodo));
21536
21438
  if (id === null) {
21537
- const parts = relFromTodo.split(path71.sep);
21439
+ const parts = relFromTodo.split(path70.sep);
21538
21440
  const folderId = idPrefix(parts[parts.length - 2] || "");
21539
21441
  if (folderId === null) return null;
21540
21442
  return buildCard(folderId, file, relFromTodo);
@@ -21542,10 +21444,10 @@ function readCard(file, relFromTodo) {
21542
21444
  return buildCard(id, file, relFromTodo);
21543
21445
  }
21544
21446
  function buildCard(id, file, relFromTodo) {
21545
- const text4 = fs69.readFileSync(file, "utf8");
21447
+ const text4 = fs68.readFileSync(file, "utf8");
21546
21448
  const { meta, body } = parseFrontmatter(text4);
21547
21449
  if (!meta) return null;
21548
- const relPath = relFromTodo.split(path71.sep).join("/");
21450
+ const relPath = relFromTodo.split(path70.sep).join("/");
21549
21451
  const flow = studioFor(meta.studio);
21550
21452
  const plan = !!meta.studio && archivesOnApproval(flow);
21551
21453
  const stages = cardStages(meta, flow).length;
@@ -21554,7 +21456,7 @@ function buildCard(id, file, relFromTodo) {
21554
21456
  // Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
21555
21457
  // read here and a card read by the contract agree on what version this is.
21556
21458
  revision: revisionOf(text4),
21557
- updatedAt: fs69.statSync(file).mtime.toISOString(),
21459
+ updatedAt: fs68.statSync(file).mtime.toISOString(),
21558
21460
  relPath,
21559
21461
  title: meta.title,
21560
21462
  priority: meta.priority,
@@ -21575,22 +21477,22 @@ function buildCard(id, file, relFromTodo) {
21575
21477
  };
21576
21478
  }
21577
21479
  function readGroup2(folderName) {
21578
- const groupDir = path71.join(TODO, folderName);
21579
- const rootFile = path71.join(groupDir, "root.md");
21580
- if (!fs69.existsSync(rootFile)) return null;
21581
- const root2 = readCard(rootFile, path71.join(folderName, "root.md"));
21480
+ const groupDir = path70.join(TODO, folderName);
21481
+ const rootFile = path70.join(groupDir, "root.md");
21482
+ if (!fs68.existsSync(rootFile)) return null;
21483
+ const root2 = readCard(rootFile, path70.join(folderName, "root.md"));
21582
21484
  if (!root2) return null;
21583
21485
  root2.isGroup = true;
21584
21486
  const { total, resolved: resolved2 } = subtaskLines(root2.body);
21585
21487
  root2.subtaskLines = { total, resolved: resolved2 };
21586
21488
  const subCards = [];
21587
21489
  const recurse = (dir, relDir) => {
21588
- for (const entry of fs69.readdirSync(dir, { withFileTypes: true })) {
21589
- const childRel = path71.join(relDir, entry.name);
21490
+ for (const entry of fs68.readdirSync(dir, { withFileTypes: true })) {
21491
+ const childRel = path70.join(relDir, entry.name);
21590
21492
  if (entry.isDirectory()) {
21591
- recurse(path71.join(dir, entry.name), childRel);
21493
+ recurse(path70.join(dir, entry.name), childRel);
21592
21494
  } else if (entry.name.endsWith(".md") && entry.name !== "README.md" && entry.name !== "root.md") {
21593
- const c = readCard(path71.join(dir, entry.name), childRel);
21495
+ const c = readCard(path70.join(dir, entry.name), childRel);
21594
21496
  if (c) {
21595
21497
  c.parent = { id: root2.id, title: root2.title };
21596
21498
  subCards.push(c);
@@ -21611,12 +21513,12 @@ function readGroup2(folderName) {
21611
21513
  return { root: root2, subCards };
21612
21514
  }
21613
21515
  function standaloneCards(dirRel) {
21614
- const dir = dirRel ? path71.join(TODO, dirRel) : TODO;
21615
- if (!fs69.existsSync(dir)) return [];
21516
+ const dir = dirRel ? path70.join(TODO, dirRel) : TODO;
21517
+ if (!fs68.existsSync(dir)) return [];
21616
21518
  const cards = [];
21617
- for (const entry of fs69.readdirSync(dir, { withFileTypes: true })) {
21519
+ for (const entry of fs68.readdirSync(dir, { withFileTypes: true })) {
21618
21520
  if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
21619
- const c = readCard(path71.join(dir, entry.name), path71.join(dirRel, entry.name));
21521
+ const c = readCard(path70.join(dir, entry.name), path70.join(dirRel, entry.name));
21620
21522
  if (c) cards.push(c);
21621
21523
  }
21622
21524
  }
@@ -21628,7 +21530,7 @@ function collectCards() {
21628
21530
  const top = standaloneCards("");
21629
21531
  board2.push(...top);
21630
21532
  every.push(...top);
21631
- for (const entry of fs69.readdirSync(TODO, { withFileTypes: true })) {
21533
+ for (const entry of fs68.readdirSync(TODO, { withFileTypes: true })) {
21632
21534
  if (!entry.isDirectory()) continue;
21633
21535
  if (isGroupFolder(entry.name)) {
21634
21536
  const g = readGroup2(entry.name);
@@ -21660,7 +21562,7 @@ function findCard(id) {
21660
21562
  }
21661
21563
  function attachSources(card) {
21662
21564
  try {
21663
- const { meta, body } = parseFrontmatter(fs69.readFileSync(path71.join(TODO, card.relPath), "utf8"));
21565
+ const { meta, body } = parseFrontmatter(fs68.readFileSync(path70.join(TODO, card.relPath), "utf8"));
21664
21566
  const sources2 = meta ? cardSources(meta, body) : [];
21665
21567
  if (sources2.length) card.sources = sources2;
21666
21568
  } catch {
@@ -21764,10 +21666,10 @@ var init_read = __esm({
21764
21666
  });
21765
21667
 
21766
21668
  // ../cli/src/lib/group-close.ts
21767
- import fs70 from "node:fs";
21669
+ import fs69 from "node:fs";
21768
21670
  function groupCloses(rootFile) {
21769
21671
  try {
21770
- return groupCloseOf(fs70.readFileSync(rootFile, "utf8"));
21672
+ return groupCloseOf(fs69.readFileSync(rootFile, "utf8"));
21771
21673
  } catch {
21772
21674
  return false;
21773
21675
  }
@@ -21780,12 +21682,12 @@ var init_group_close = __esm({
21780
21682
  });
21781
21683
 
21782
21684
  // ../cli/src/commands/remove.ts
21783
- import fs71 from "node:fs";
21784
- import path72 from "node:path";
21685
+ import fs70 from "node:fs";
21686
+ import path71 from "node:path";
21785
21687
  function leavingIds(id, found2) {
21786
21688
  const ids = /* @__PURE__ */ new Set([id]);
21787
21689
  if (found2.kind === "group") {
21788
- const names3 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f) => path72.basename(f));
21690
+ const names3 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f) => path71.basename(f));
21789
21691
  for (const name of names3) {
21790
21692
  const n = idPrefix(name);
21791
21693
  if (n !== null) ids.add(n);
@@ -21797,10 +21699,10 @@ function findMentions(ids) {
21797
21699
  const hits = [];
21798
21700
  const re = new RegExp(ids.map((id) => `#${id}(?!\\d)`).join("|"));
21799
21701
  for (const dir of [TODO, MEMORY]) {
21800
- if (!fs71.existsSync(dir)) continue;
21702
+ if (!fs70.existsSync(dir)) continue;
21801
21703
  for (const file of walkMd(dir)) {
21802
- if (path72.basename(file) === "README.md") continue;
21803
- const lines = fs71.readFileSync(file, "utf8").split("\n");
21704
+ if (path71.basename(file) === "README.md") continue;
21705
+ const lines = fs70.readFileSync(file, "utf8").split("\n");
21804
21706
  const fmEnd = frontmatterEnd(lines);
21805
21707
  lines.forEach((line, i) => {
21806
21708
  if (!re.test(line)) return;
@@ -21816,12 +21718,12 @@ function findMentions(ids) {
21816
21718
  return hits;
21817
21719
  }
21818
21720
  function leavingCards(id, found2) {
21819
- const own = found2.kind === "group" ? path72.join(found2.target, "root.md") : found2.target;
21721
+ const own = found2.kind === "group" ? path71.join(found2.target, "root.md") : found2.target;
21820
21722
  const cards = [{ id, file: own }];
21821
21723
  if (found2.kind !== "group") return cards;
21822
21724
  for (const file of walkMd(found2.target)) {
21823
21725
  if (file === own) continue;
21824
- const n = idPrefix(path72.basename(file));
21726
+ const n = idPrefix(path71.basename(file));
21825
21727
  if (n !== null) cards.push({ id: n, file });
21826
21728
  }
21827
21729
  return cards;
@@ -21830,10 +21732,10 @@ function stampLeaving(cards, rejection) {
21830
21732
  const day = formatDay();
21831
21733
  const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() ? "agent" : "user" } : rejection && { reason: rejection.reason };
21832
21734
  for (const card of cards) {
21833
- if (!fs71.existsSync(card.file)) continue;
21834
- const text4 = fs71.readFileSync(card.file, "utf8");
21735
+ if (!fs70.existsSync(card.file)) continue;
21736
+ const text4 = fs70.readFileSync(card.file, "utf8");
21835
21737
  const stamped = stampLeavingIn(text4, day, stamp4);
21836
- if (stamped !== text4) fs71.writeFileSync(card.file, stamped);
21738
+ if (stamped !== text4) fs70.writeFileSync(card.file, stamped);
21837
21739
  }
21838
21740
  }
21839
21741
  function unfinishedDelivery(id) {
@@ -21849,7 +21751,7 @@ function unfinishedDelivery(id) {
21849
21751
  }[gap];
21850
21752
  return `#${id} is not finished: ${what}.`;
21851
21753
  }
21852
- const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs71.existsSync(path72.join(ASSETS, src.slice(".assets/".length))));
21754
+ const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs70.existsSync(path71.join(ASSETS, src.slice(".assets/".length))));
21853
21755
  return missing ? `#${id} is not finished: ${missing} is not on this machine.` : null;
21854
21756
  }
21855
21757
  function agentDecisions(text4) {
@@ -21880,8 +21782,8 @@ function removeCard2(id, metric, options) {
21880
21782
  const unfinished = metric === "completed" ? unfinishedDelivery(id) : null;
21881
21783
  if (unfinished) die(unfinished, { kind: "plan-delivery-unfinished" });
21882
21784
  const dest = options.cleanupDiscarded && locateArchived(id) ? null : archiveDest(found2);
21883
- const cardFile3 = found2.kind === "group" ? path72.join(found2.target, "root.md") : found2.target;
21884
- const cardText = fs71.existsSync(cardFile3) ? fs71.readFileSync(cardFile3, "utf8") : "";
21785
+ const cardFile3 = found2.kind === "group" ? path71.join(found2.target, "root.md") : found2.target;
21786
+ const cardText = fs70.existsSync(cardFile3) ? fs70.readFileSync(cardFile3, "utf8") : "";
21885
21787
  const { meta: cardMeta3 } = parseFrontmatter(cardText);
21886
21788
  const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f) => f !== cardFile3).map((f) => rel(f)).sort() : [];
21887
21789
  const leftIds = leavingIds(id, found2);
@@ -21912,10 +21814,10 @@ function removeCard2(id, metric, options) {
21912
21814
  const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
21913
21815
  if (dest) {
21914
21816
  stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
21915
- fs71.mkdirSync(ARCHIVE, { recursive: true });
21916
- fs71.renameSync(found2.target, dest);
21817
+ fs70.mkdirSync(ARCHIVE, { recursive: true });
21818
+ fs70.renameSync(found2.target, dest);
21917
21819
  } else {
21918
- fs71.rmSync(found2.target, { recursive: true, force: true });
21820
+ fs70.rmSync(found2.target, { recursive: true, force: true });
21919
21821
  }
21920
21822
  const removedRefs = stripReadmeRefs(found2);
21921
21823
  let marked2 = null;
@@ -21964,14 +21866,14 @@ function removeCard2(id, metric, options) {
21964
21866
  };
21965
21867
  }
21966
21868
  function closeGroup(rootFile) {
21967
- const rootId = idPrefix(path72.basename(path72.dirname(rootFile)));
21869
+ const rootId = idPrefix(path71.basename(path71.dirname(rootFile)));
21968
21870
  if (rootId === null) return null;
21969
21871
  if (runnerProject(KANBAN)) return null;
21970
21872
  if (!groupCloses(rootFile)) return null;
21971
21873
  say(`
21972
21874
  every subtask line on #${rootId} is resolved \u2014 closing the group:`);
21973
21875
  try {
21974
- const { meta, body } = parseFrontmatter(fs71.readFileSync(rootFile, "utf8"));
21876
+ const { meta, body } = parseFrontmatter(fs70.readFileSync(rootFile, "utf8"));
21975
21877
  const res = cmdRemove(rootId, "completed", { closing: true });
21976
21878
  return {
21977
21879
  id: rootId,
@@ -22028,7 +21930,7 @@ function cleanupDiscardedCards(sessionId) {
22028
21930
  if (card.pending) throw new Error(`Discarding #${card.id} did not finish. Retry the discard.`);
22029
21931
  while (locate(card.id)) cmdRemove(card.id, "rejected", { discard: true, cleanupDiscarded: true });
22030
21932
  dropCrossRefs(card.id);
22031
- stripReadmeRefs({ kind: "file", rel: path72.relative(TODO, path72.resolve(REPO_ROOT, card.path)).split(path72.sep).join("/") });
21933
+ stripReadmeRefs({ kind: "file", rel: path71.relative(TODO, path71.resolve(REPO_ROOT, card.path)).split(path71.sep).join("/") });
22032
21934
  }
22033
21935
  return discarded.map((c) => c.id);
22034
21936
  });
@@ -22036,8 +21938,8 @@ function cleanupDiscardedCards(sessionId) {
22036
21938
  function recoveredArchiveHandoff(id, source) {
22037
21939
  const found2 = locateArchived(id);
22038
21940
  if (!found2) throw new Error(`No archived card #${id} was found.`);
22039
- const file = found2.kind === "group" ? path72.join(found2.target, "root.md") : found2.target;
22040
- const { meta } = parseFrontmatter(fs71.readFileSync(file, "utf8"));
21941
+ const file = found2.kind === "group" ? path71.join(found2.target, "root.md") : found2.target;
21942
+ const { meta } = parseFrontmatter(fs70.readFileSync(file, "utf8"));
22041
21943
  stripReadmeRefs(source ?? found2);
22042
21944
  const root2 = source?.kind === "file" ? enclosingGroupRoot(source.target) : null;
22043
21945
  if (root2) markSubtask(root2, id, "tick");
@@ -22424,8 +22326,8 @@ var init_created_cards = __esm({
22424
22326
 
22425
22327
  // ../cli/src/lib/agent/creation.ts
22426
22328
  import crypto4 from "node:crypto";
22427
- import fs72 from "node:fs";
22428
- import path73 from "node:path";
22329
+ import fs71 from "node:fs";
22330
+ import path72 from "node:path";
22429
22331
  function creationError(error, triage) {
22430
22332
  const zh = readLanguage() === "zh";
22431
22333
  const messages = {
@@ -22451,12 +22353,12 @@ ${zh ? `\u539F\u6761\u76EE\u4ECD\u5728 triage\uFF1A${triage}\u3002${unreachable
22451
22353
  function creationReceipt(request2, slot) {
22452
22354
  const hash2 = crypto4.createHash("sha256").update(`${request2}
22453
22355
  ${slot}`).digest("hex");
22454
- return path73.join(projectStateDir(KANBAN, REPO_ROOT), "creations", `${hash2}.json`);
22356
+ return path72.join(projectStateDir(KANBAN, REPO_ROOT), "creations", `${hash2}.json`);
22455
22357
  }
22456
22358
  function readCreation(file, said2) {
22457
22359
  return withCreationLock(() => {
22458
22360
  try {
22459
- const held4 = JSON.parse(fs72.readFileSync(file, "utf8"));
22361
+ const held4 = JSON.parse(fs71.readFileSync(file, "utf8"));
22460
22362
  if (!held4.said || typeof held4.said.title !== "string") throw new Error("Invalid creation journal");
22461
22363
  return held4;
22462
22364
  } catch (error) {
@@ -22468,10 +22370,10 @@ function readCreation(file, said2) {
22468
22370
  });
22469
22371
  }
22470
22372
  function saveCreation(file, journal) {
22471
- fs72.mkdirSync(path73.dirname(file), { recursive: true });
22373
+ fs71.mkdirSync(path72.dirname(file), { recursive: true });
22472
22374
  const temp = `${file}.${crypto4.randomUUID()}.tmp`;
22473
- fs72.writeFileSync(temp, JSON.stringify(journal));
22474
- fs72.renameSync(temp, file);
22375
+ fs71.writeFileSync(temp, JSON.stringify(journal));
22376
+ fs71.renameSync(temp, file);
22475
22377
  }
22476
22378
  function archiveCreation(source, id) {
22477
22379
  if (readArchived().some((s) => s.sourceId === source && s.cardId === id)) return;
@@ -22485,7 +22387,7 @@ function archiveCreation(source, id) {
22485
22387
  function triageFile(sourceId) {
22486
22388
  const found2 = [...readInbox(), ...readAllDismissed(), ...readArchived()].find((s) => s.sourceId === sourceId.trim());
22487
22389
  if (!found2) throw new BoardError(`nothing in triage is ${sourceId}`, { kind: "refused" });
22488
- return path73.basename(found2.relPath, ".md");
22390
+ return path72.basename(found2.relPath, ".md");
22489
22391
  }
22490
22392
  var init_creation = __esm({
22491
22393
  "../cli/src/lib/agent/creation.ts"() {
@@ -22653,8 +22555,8 @@ __export(board_exports, {
22653
22555
  buildBoardProgram: () => buildBoardProgram
22654
22556
  });
22655
22557
  import crypto5 from "node:crypto";
22656
- import fs73 from "node:fs";
22657
- import path74 from "node:path";
22558
+ import fs72 from "node:fs";
22559
+ import path73 from "node:path";
22658
22560
  async function dispatch(move, cmd, args, opts, cli) {
22659
22561
  const ctx = ctxOf(cmd, cli.program);
22660
22562
  const data = await runAction(ctx, {}, async () => {
@@ -22694,7 +22596,7 @@ async function cloudCard(task, opts) {
22694
22596
  let request2;
22695
22597
  if (typeof opts.bodyFile === "string") {
22696
22598
  try {
22697
- request2 = fs73.readFileSync(opts.bodyFile, "utf8");
22599
+ request2 = fs72.readFileSync(opts.bodyFile, "utf8");
22698
22600
  } catch {
22699
22601
  }
22700
22602
  }
@@ -22724,7 +22626,7 @@ async function cloudCard(task, opts) {
22724
22626
  const file = creationReceipt(`${checked.value}:${requestId}`, slot);
22725
22627
  const journal = readCreation(file, said2);
22726
22628
  if (!journal.made) {
22727
- const key = `akb-${path74.basename(file, ".json").slice(0, 40)}`;
22629
+ const key = `akb-${path73.basename(file, ".json").slice(0, 40)}`;
22728
22630
  const made = await createProjectTask(checked.value, journal.said, key);
22729
22631
  if (!made.ok) throw new BoardError(creationError(`Cloud did not make the task: ${made.error}`, triage), { kind: "refused" });
22730
22632
  journal.made = made.value;
@@ -22853,17 +22755,17 @@ var init_board2 = __esm({
22853
22755
  });
22854
22756
 
22855
22757
  // ../cli/src/lib/board-cli.ts
22856
- import fs74 from "node:fs";
22857
- import path75 from "node:path";
22758
+ import fs73 from "node:fs";
22759
+ import path74 from "node:path";
22858
22760
  function useBoard(found2, dirNamed) {
22859
- if (!found2.named && found2.board === path75.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
22761
+ if (!found2.named && found2.board === path74.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
22860
22762
  else setBoardDir(found2.board, found2.root);
22861
22763
  useProjectState();
22862
22764
  backfillCardStudios();
22863
22765
  }
22864
22766
  function whole(found2, move) {
22865
22767
  if (move === MAKES_A_BOARD) return found2;
22866
- if (!fs74.existsSync(path75.join(found2.board, "todo"))) {
22768
+ if (!fs73.existsSync(path74.join(found2.board, "todo"))) {
22867
22769
  die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
22868
22770
  kind: "board-incomplete",
22869
22771
  dir: found2.root
@@ -22872,13 +22774,13 @@ function whole(found2, move) {
22872
22774
  return found2;
22873
22775
  }
22874
22776
  function findBoardUpward(from, move) {
22875
- let dir = path75.resolve(from);
22777
+ let dir = path74.resolve(from);
22876
22778
  for (; ; ) {
22877
- if (hasBoard(dir)) return { root: dir, board: path75.join(dir, "docs", "kanban") };
22779
+ if (hasBoard(dir)) return { root: dir, board: path74.join(dir, "docs", "kanban") };
22878
22780
  if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
22879
- const kept2 = path75.join(dir, ".akb", "kanban");
22880
- if (move !== MAKES_A_BOARD && fs74.existsSync(path75.join(kept2, "todo"))) return { root: dir, board: kept2 };
22881
- const up = path75.dirname(dir);
22781
+ const kept2 = path74.join(dir, ".akb", "kanban");
22782
+ if (move !== MAKES_A_BOARD && fs73.existsSync(path74.join(kept2, "todo"))) return { root: dir, board: kept2 };
22783
+ const up = path74.dirname(dir);
22882
22784
  if (up === dir) return null;
22883
22785
  dir = up;
22884
22786
  }
@@ -22886,11 +22788,11 @@ function findBoardUpward(from, move) {
22886
22788
  function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
22887
22789
  const named2 = board2 ?? boardFromEnv();
22888
22790
  if (named2) {
22889
- const folder = path75.resolve(cwd, named2);
22890
- if (!fs74.existsSync(folder) && move !== MAKES_A_BOARD) {
22791
+ const folder = path74.resolve(cwd, named2);
22792
+ if (!fs73.existsSync(folder) && move !== MAKES_A_BOARD) {
22891
22793
  die(`no such folder: ${folder}`, { kind: "no-such-folder", dir: folder });
22892
22794
  }
22893
- if (fs74.existsSync(folder) && !isBoardDir(folder) && move !== MAKES_A_BOARD) {
22795
+ if (fs73.existsSync(folder) && !isBoardDir(folder) && move !== MAKES_A_BOARD) {
22894
22796
  die(`${folder} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
22895
22797
  kind: "no-board",
22896
22798
  dir: folder
@@ -22899,24 +22801,24 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
22899
22801
  return { root: projectRootOf(folder), board: folder, named: true };
22900
22802
  }
22901
22803
  if (dir !== null) {
22902
- const root2 = path75.resolve(dir);
22903
- if (!fs74.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
22904
- const kept2 = path75.join(root2, ".akb", "kanban");
22905
- if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs74.existsSync(path75.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
22804
+ const root2 = path74.resolve(dir);
22805
+ if (!fs73.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
22806
+ const kept2 = path74.join(root2, ".akb", "kanban");
22807
+ if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs73.existsSync(path74.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
22906
22808
  if (!hasBoard(root2) && move !== MAKES_A_BOARD) {
22907
22809
  die(`no board in ${root2} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
22908
22810
  kind: "no-board",
22909
22811
  dir: root2
22910
22812
  });
22911
22813
  }
22912
- return whole({ root: root2, board: path75.join(root2, "docs", "kanban") }, move);
22814
+ return whole({ root: root2, board: path74.join(root2, "docs", "kanban") }, move);
22913
22815
  }
22914
22816
  const found2 = findBoardUpward(cwd, move);
22915
22817
  if (found2) return whole(found2, move);
22916
- if (move === MAKES_A_BOARD) return { root: path75.resolve(cwd), board: path75.join(path75.resolve(cwd), "docs", "kanban") };
22818
+ if (move === MAKES_A_BOARD) return { root: path74.resolve(cwd), board: path74.join(path74.resolve(cwd), "docs", "kanban") };
22917
22819
  die(
22918
- `no board here. Looked in ${path75.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
22919
- { kind: "no-board", dir: path75.resolve(cwd) }
22820
+ `no board here. Looked in ${path74.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
22821
+ { kind: "no-board", dir: path74.resolve(cwd) }
22920
22822
  );
22921
22823
  }
22922
22824
  function editDistance(a, b) {
@@ -22999,8 +22901,8 @@ var init_board_cli = __esm({
22999
22901
  init_pointer();
23000
22902
  init_card_studio_backfill();
23001
22903
  MAKES_A_BOARD = "init";
23002
- hasBoard = (dir) => fs74.existsSync(path75.join(dir, "docs", "kanban"));
23003
- isBoardDir = (dir) => fs74.existsSync(path75.join(dir, "todo")) && fs74.existsSync(path75.join(dir, "config.md"));
22904
+ hasBoard = (dir) => fs73.existsSync(path74.join(dir, "docs", "kanban"));
22905
+ isBoardDir = (dir) => fs73.existsSync(path74.join(dir, "todo")) && fs73.existsSync(path74.join(dir, "config.md"));
23004
22906
  boardFromEnv = () => {
23005
22907
  const named2 = process.env.AI4KANBAN_BOARD?.trim();
23006
22908
  return named2 ? named2 : null;
@@ -23260,8 +23162,8 @@ var init_agent = __esm({
23260
23162
 
23261
23163
  // ../cli/src/commands/cloud-template.ts
23262
23164
  import { createHash as createHash5 } from "node:crypto";
23263
- import fs75 from "node:fs";
23264
- import path76 from "node:path";
23165
+ import fs74 from "node:fs";
23166
+ import path75 from "node:path";
23265
23167
  function usage2(problem, line) {
23266
23168
  die(`${problem}
23267
23169
  usage: ${line}`, { kind: "bad-args", bare: true, exitCode: 2 });
@@ -23338,10 +23240,10 @@ This template has no preview.`);
23338
23240
  const written = [];
23339
23241
  for (const p of previews) {
23340
23242
  const bytes2 = Buffer.from(await (await ask(`/${at}/previews/${route(p.path)}`, {}, WITHOUT)).arrayBuffer());
23341
- const file = path76.basename(p.path);
23342
- const out = path76.join(opts.to, file.startsWith(`${name}-`) ? file : `${name}-${file}`);
23343
- fs75.mkdirSync(opts.to, { recursive: true });
23344
- fs75.writeFileSync(out, bytes2);
23243
+ const file = path75.basename(p.path);
23244
+ const out = path75.join(opts.to, file.startsWith(`${name}-`) ? file : `${name}-${file}`);
23245
+ fs74.mkdirSync(opts.to, { recursive: true });
23246
+ fs74.writeFileSync(out, bytes2);
23345
23247
  written.push(out);
23346
23248
  say(out);
23347
23249
  }
@@ -23354,15 +23256,15 @@ async function templateGet(name, opts, program2) {
23354
23256
  const { template } = await asJson(await ask(`/${at}`, {}, WITHOUT));
23355
23257
  const fetched = [];
23356
23258
  for (const f of template.files) {
23357
- const out = path76.resolve(to, f.path);
23358
- if (!out.startsWith(path76.resolve(to) + path76.sep)) refuse3(T.corrupt, WITHOUT);
23259
+ const out = path75.resolve(to, f.path);
23260
+ if (!out.startsWith(path75.resolve(to) + path75.sep)) refuse3(T.corrupt, WITHOUT);
23359
23261
  const bytes2 = Buffer.from(await (await ask(`/${at}/files/${route(f.path)}`, {}, WITHOUT)).arrayBuffer());
23360
23262
  if (bytes2.byteLength !== f.size || createHash5("sha256").update(bytes2).digest("hex") !== f.sha256) {
23361
23263
  refuse3(T.corrupt, WITHOUT);
23362
23264
  }
23363
23265
  fetched.push({ out, bytes: bytes2 });
23364
23266
  }
23365
- const taken = fetched.filter((f) => fs75.existsSync(f.out)).map((f) => path76.relative(to, f.out));
23267
+ const taken = fetched.filter((f) => fs74.existsSync(f.out)).map((f) => path75.relative(to, f.out));
23366
23268
  if (taken.length > 0) {
23367
23269
  refuse3({
23368
23270
  zh: `\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u6709\u540C\u540D\u6587\u4EF6\uFF1A${taken.join("\u3001")}\u3002\u8BF7\u6362\u4E00\u4E2A\u6587\u4EF6\u5939\uFF0C\u6216\u5148\u79FB\u8D70\u8FD9\u4E9B\u6587\u4EF6\u3002`,
@@ -23370,8 +23272,8 @@ async function templateGet(name, opts, program2) {
23370
23272
  });
23371
23273
  }
23372
23274
  for (const f of fetched) {
23373
- fs75.mkdirSync(path76.dirname(f.out), { recursive: true });
23374
- fs75.writeFileSync(f.out, f.bytes);
23275
+ fs74.mkdirSync(path75.dirname(f.out), { recursive: true });
23276
+ fs74.writeFileSync(f.out, f.bytes);
23375
23277
  }
23376
23278
  say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
23377
23279
  Fetched ${name}: ${fetched.length} files into ${to}`);
@@ -23388,25 +23290,25 @@ async function templateSource(name, opts) {
23388
23290
  say(`evidence: ${e.path}`);
23389
23291
  continue;
23390
23292
  }
23391
- const out = path76.join(opts.to, `${name}-${path76.basename(e.path)}`);
23392
- fs75.mkdirSync(opts.to, { recursive: true });
23393
- fs75.writeFileSync(out, Buffer.from(await (await ask(`/${at}/evidence/${route(e.path)}`)).arrayBuffer()));
23293
+ const out = path75.join(opts.to, `${name}-${path75.basename(e.path)}`);
23294
+ fs74.mkdirSync(opts.to, { recursive: true });
23295
+ fs74.writeFileSync(out, Buffer.from(await (await ask(`/${at}/evidence/${route(e.path)}`)).arrayBuffer()));
23394
23296
  written.push(out);
23395
23297
  say(out);
23396
23298
  }
23397
23299
  return { name, source, evidence: written.length > 0 ? written : evidence.map((e) => e.path) };
23398
23300
  }
23399
23301
  async function templatePublish(dir, opts) {
23400
- const root2 = path76.resolve(dir);
23401
- const manifest = path76.join(root2, "template.md");
23402
- if (!fs75.existsSync(manifest)) invalid("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
23403
- const meta = readTemplateMeta(fs75.readFileSync(manifest, "utf8"));
23302
+ const root2 = path75.resolve(dir);
23303
+ const manifest = path75.join(root2, "template.md");
23304
+ if (!fs74.existsSync(manifest)) invalid("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
23305
+ const meta = readTemplateMeta(fs74.readFileSync(manifest, "utf8"));
23404
23306
  const files = walk2(root2);
23405
- const total = files.reduce((sum, f) => sum + fs75.statSync(path76.join(root2, f)).size, 0);
23307
+ const total = files.reduce((sum, f) => sum + fs74.statSync(path75.join(root2, f)).size, 0);
23406
23308
  if (total > MAX_BYTES3) invalid("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
23407
23309
  for (const extra of [...opts.preview, ...opts.evidence]) {
23408
- if (!fs75.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
23409
- if (path76.resolve(extra).startsWith(root2 + path76.sep)) {
23310
+ if (!fs74.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
23311
+ if (path75.resolve(extra).startsWith(root2 + path75.sep)) {
23410
23312
  invalid(
23411
23313
  `${extra} \u5728\u6A21\u677F\u6587\u4EF6\u5939\u5185\uFF1B\u9884\u89C8\u56FE\u4E0E\u6765\u6E90\u51ED\u8BC1\u9700\u653E\u5728\u6A21\u677F\u6587\u4EF6\u5939\u4E4B\u5916\u3002`,
23412
23314
  `${extra} is inside the template folder; keep previews and evidence outside it.`
@@ -23418,17 +23320,17 @@ async function templatePublish(dir, opts) {
23418
23320
  }
23419
23321
  const form = new FormData();
23420
23322
  form.set("meta", JSON.stringify({ ...meta, replace: !!opts.replace }));
23421
- const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([fs75.readFileSync(file)]), path76.basename(name));
23422
- for (const f of files) add("files", f, path76.join(root2, f));
23423
- for (const f of opts.preview) add("previews", path76.basename(f), f);
23424
- for (const f of opts.evidence) add("evidence", path76.basename(f), f);
23425
- const done2 = await asJson(await ask("", { method: "POST", body: form }));
23323
+ const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([fs74.readFileSync(file)]), path75.basename(name));
23324
+ for (const f of files) add("files", f, path75.join(root2, f));
23325
+ for (const f of opts.preview) add("previews", path75.basename(f), f);
23326
+ for (const f of opts.evidence) add("evidence", path75.basename(f), f);
23327
+ const done = await asJson(await ask("", { method: "POST", body: form }));
23426
23328
  say(
23427
- done2.replaced ? `\u5DF2\u66FF\u6362 ${done2.name}\uFF1A${files.length} \u4E2A\u6587\u4EF6\u3002
23428
- Replaced ${done2.name}: ${files.length} files.` : `\u5DF2\u53D1\u5E03 ${done2.name}\uFF1A${files.length} \u4E2A\u6587\u4EF6\u3002
23429
- Published ${done2.name}: ${files.length} files.`
23329
+ done.replaced ? `\u5DF2\u66FF\u6362 ${done.name}\uFF1A${files.length} \u4E2A\u6587\u4EF6\u3002
23330
+ Replaced ${done.name}: ${files.length} files.` : `\u5DF2\u53D1\u5E03 ${done.name}\uFF1A${files.length} \u4E2A\u6587\u4EF6\u3002
23331
+ Published ${done.name}: ${files.length} files.`
23430
23332
  );
23431
- return { name: done2.name, replaced: done2.replaced, files };
23333
+ return { name: done.name, replaced: done.replaced, files };
23432
23334
  }
23433
23335
  async function templateDelete(name) {
23434
23336
  await ask(`/${encodeURIComponent(name)}`, { method: "DELETE" });
@@ -23437,11 +23339,11 @@ Deleted ${name} from the catalog.`);
23437
23339
  return { name, deleted: true };
23438
23340
  }
23439
23341
  async function templateShowcase(name, dir) {
23440
- const file = path76.join(dir, "showcase.json");
23441
- if (!fs75.existsSync(file)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
23342
+ const file = path75.join(dir, "showcase.json");
23343
+ if (!fs74.existsSync(file)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
23442
23344
  let meta;
23443
23345
  try {
23444
- meta = JSON.parse(fs75.readFileSync(file, "utf8"));
23346
+ meta = JSON.parse(fs74.readFileSync(file, "utf8"));
23445
23347
  } catch {
23446
23348
  return invalid("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
23447
23349
  }
@@ -23453,18 +23355,18 @@ async function templateShowcase(name, dir) {
23453
23355
  const form = new FormData();
23454
23356
  form.set("meta", JSON.stringify(meta));
23455
23357
  for (const p of new Set(named2)) {
23456
- const at = path76.join(dir, p);
23457
- if (!fs75.existsSync(at)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at}\u3002`, `${at} does not exist.`);
23458
- form.append(`media:${p}`, new Blob([fs75.readFileSync(at)]), p);
23358
+ const at = path75.join(dir, p);
23359
+ if (!fs74.existsSync(at)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at}\u3002`, `${at} does not exist.`);
23360
+ form.append(`media:${p}`, new Blob([fs74.readFileSync(at)]), p);
23459
23361
  }
23460
- const done2 = await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form }));
23461
- say(`\u5DF2\u66F4\u65B0 ${name} \u7684\u5C55\u793A\u8D44\u6599\uFF1A${done2.files} \u4E2A\u6587\u4EF6\u3002
23462
- Updated ${name}'s showcase: ${done2.files} files.`);
23463
- return { name, files: done2.files };
23362
+ const done = await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form }));
23363
+ say(`\u5DF2\u66F4\u65B0 ${name} \u7684\u5C55\u793A\u8D44\u6599\uFF1A${done.files} \u4E2A\u6587\u4EF6\u3002
23364
+ Updated ${name}'s showcase: ${done.files} files.`);
23365
+ return { name, files: done.files };
23464
23366
  }
23465
23367
  function walk2(root2, sub = "") {
23466
23368
  const out = [];
23467
- for (const entry of fs75.readdirSync(path76.join(root2, sub), { withFileTypes: true })) {
23369
+ for (const entry of fs74.readdirSync(path75.join(root2, sub), { withFileTypes: true })) {
23468
23370
  if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
23469
23371
  const rel2 = sub ? `${sub}/${entry.name}` : entry.name;
23470
23372
  if (entry.isDirectory()) out.push(...walk2(root2, rel2));
@@ -23657,7 +23559,7 @@ var init_board3 = __esm({
23657
23559
  var card_chat_default;
23658
23560
  var init_card_chat = __esm({
23659
23561
  "../cli/src/guide/card-chat.md"() {
23660
- 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 embed 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**: when the user asks to change a studio or one of its agents, follow `akb guide update-studio`.\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';
23562
+ 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 embed 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';
23661
23563
  }
23662
23564
  });
23663
23565
 
@@ -23665,7 +23567,7 @@ var init_card_chat = __esm({
23665
23567
  var update_studio_default;
23666
23568
  var init_update_studio = __esm({
23667
23569
  "../cli/src/guide/update-studio.md"() {
23668
- update_studio_default = "# Update a studio\n\nChange one of this workspace's studios so new tasks run the new version.\n\n## How a studio works\n\nA studio is steerable: agents do the work, and a person reviews and fine-tunes only the parts where precision matters most, so the result stays reliable.\n\n- **Previews**: usually one preview agent shows the work, finished or a draft, where the person can fine-tune it; add another only when a part needs precision and a mistake there is costly, such as a developer tool's screens. Each shows only what the person decides on, without overlapping another. With none, the card the `STUDIO.md` body writes is the only review.\n- **Unreviewable previews**: when the user finds a preview unneeded or cannot judge it, remove it; a land agent checks that part instead, or nobody does.\n- **Stages**: one stage by default. Add `after` only when a draft is too costly to make before another is approved, such as a video's storyboard, which waits for its script.\n- **Minimal**: when the user outlines the studio, keep it that simple or simpler; add no review point or constraint they did not ask for, and let the trial show what else needs review.\n- **Judgment**: leave to an agent what it can judge; never add a hard rule for one case, and keep a rule only once real runs show it holds widely.\n- **Memory**: give an agent memory only where it has wide latitude and tends to err or be corrected to taste, naming those error-prone points as what it records; give a narrow agent none.\n- **Shared**: what several of the studio's agents follow, run or remember belongs to the studio, never to one agent that the others point to.\n- **Card template**: put what every card of the studio starts from, such as its shared Todo steps, in `CARD.md`, not in the `STUDIO.md` body.\n- **Land**: everything else runs unattended after the last approval and follows the approved previews, such as building and merging a change; leave `land` empty when the last approved preview is the deliverable.\n- **Scheduled**: repeating work runs as a scheduled agent without previews; a studio may hold only scheduled agents.\n- **Agents**: write each as `akb guide write-agent` says.\n\n## The folder\n\n`akb studio pull` writes a studio as this folder:\n\n```text\n<folder>/\n\u251C\u2500\u2500 STUDIO.md frontmatter: `description`, what it does in one sentence; `when`, which requests\n\u2502 it is for, exceptions included; its agents under `previews`, `land`, `scheduled`;\n\u2502 `memoryFiles.workspace`, the studio memory shared by every project\n\u2502 body: how a card of this kind is written; every planning run on its cards reads it\n\u251C\u2500\u2500 CARD.md optional: the card template; the planner fits it to each card, such as its `## Todo`\n\u251C\u2500\u2500 shared/\n\u2502 \u251C\u2500\u2500 RULES.md terms and formats every agent follows; every run of the studio reads it\n\u2502 \u2514\u2500\u2500 \u2026 files any of its agents may read with `akb raw file <studio> shared/<path>`\n\u251C\u2500\u2500 agents/<name>/\n\u2502 \u251C\u2500\u2500 AGENT.md one agent: what its preview shows, or what its land or scheduled run does\n\u2502 \u2514\u2500\u2500 \u2026 files its AGENT.md points to\n\u2514\u2500\u2500 version.json the version pulled; push reads it, never edit it\n```\n\n## Versions\n\n- **Pinned**: a studio and the agents it holds live in Cloud as numbered versions; a task\n keeps the version it started with, and only tasks started after a push take the new one.\n- **Project agents**: agents under the board's `agents/` folder are the project's own; a\n studio may name them, but they are not part of its versions and an edit there applies to\n every card at once.\n- **Own studios only**: only the workspace's own studios take a new version; ask the user to\n copy a built-in or marketplace one on the web first.\n\n## Change it\n\n- **Standing preference**: when the user only wants a lasting rule for a studio or one of its\n agents and the flow itself stays, set it with `akb studio rule <studio>` or\n `akb studio instructions <agent>` instead of pushing; it reaches every task's later runs and\n works on built-in studios too. Either replaces all of them, so run it bare first to read the\n current ones, and keep each unless the user asks to change or drop it.\n- **Direct or task**: push directly a change the user spelled out; start a Studio builder task\n instead when the change adds, removes or restages agents, or when the user wants to review\n it before it applies.\n- **Steps**: `akb studio pull <id> <folder>`, edit the files there and keep what the request\n leaves alone, fix every problem `akb raw studio validate <folder>` reports, then\n `akb studio push <folder>`.\n- **Moved on**: when push says Cloud has a newer version, pull again and redo the change.\n- **Borrowed parts**: when an agent points to another agent's sections, files or memory\n folder, move them into `shared/`, `memoryFiles` and the studio memory folder, then push.\n";
23570
+ update_studio_default = "# Update a studio\n\n- **Studio files**: follow `akb guide add-task` to create a card with `--studio studio-builder`\n for a new studio or a change to an existing studio.\n- **Current draft**: a correction to the current card\u2019s deliverable follows `akb guide card-chat`.\n- **User rules**: for an explicit request to read or change attached rules, use\n `akb studio rule <studio>` or `akb studio instructions <agent>`; bare reads,\n `--text` or `--file` replaces all, and empty text clears. Read before changing and keep\n what the request leaves alone. These commands change attached rules, not `AGENT.md`.\n";
23669
23571
  }
23670
23572
  });
23671
23573
 
@@ -23737,7 +23639,7 @@ var init_review_rejections = __esm({
23737
23639
  var refine_default;
23738
23640
  var init_refine = __esm({
23739
23641
  "../cli/src/guide/refine.md"() {
23740
- refine_default = '# Refine a card\n\nPlan one card in this session until it can be built.\n\n- **\u91CD\u590D\u5361\u7247**: \u82E5\u53D1\u73B0\u53E6\u4E00\u5F20\u4EFB\u52A1\u5B8C\u6574\u8986\u76D6\u672C\u5361\uFF0C\u5373\u4F7F\u5BF9\u65B9\u5C1A\u672A\u5B9E\u65BD\uFF0C\u4E5F\u5148\u5C06\u5176\u7F3A\u5C11\u7684\u6709\u7528\u4FE1\u606F\u8865\u5165\u5E76\u786E\u8BA4\u4FDD\u5B58\u6210\u529F\uFF1B\n \u4FDD\u5B58\u5931\u8D25\u5219\u4FDD\u7559\u672C\u5361\u5E76\u505C\u6B62\u3002\u6CA1\u6709\u4FE1\u606F\u9700\u8981\u8865\u5145\u6216\u5DF2\u4FDD\u5B58\u6210\u529F\u540E\uFF0C\u8FD0\u884C\n `akb raw reject <id> --reason "<\u627F\u63A5\u4EFB\u52A1\u7F16\u53F7\u53CA\u5B8C\u6574\u8986\u76D6\u539F\u56E0>"` \u5E76\u505C\u6B62\u3002\n \u4E0D\u8BF7\u6C42\u786E\u8BA4\uFF0C\u4E0D\u8FD0\u884C\u9884\u89C8\uFF1B\u4EC5\u90E8\u5206\u91CD\u53E0\u4E0D\u4E22\u5F03\u3002\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- **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';
23642
+ 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";
23741
23643
  }
23742
23644
  });
23743
23645
 
@@ -23926,8 +23828,9 @@ var init_guide2 = __esm({
23926
23828
  });
23927
23829
 
23928
23830
  // ../cli/src/commands/studio.ts
23929
- import fs76 from "node:fs";
23930
- import path77 from "node:path";
23831
+ import crypto6 from "node:crypto";
23832
+ import fs75 from "node:fs";
23833
+ import path76 from "node:path";
23931
23834
  function cmdStudioList() {
23932
23835
  if (!studiosReachable().ok) die(NEEDS_CLOUD, "needs-cloud");
23933
23836
  const offline2 = studiosOffline();
@@ -23955,30 +23858,28 @@ function cmdStudioList() {
23955
23858
  ...offline2 ? { offline: offline2 } : {}
23956
23859
  };
23957
23860
  }
23958
- function cmdStudioRename(id, name) {
23959
- done(renameStudio(id, name));
23960
- say(`renamed ${id} to "${name.trim()}"`);
23961
- return { id, name: name.trim() };
23962
- }
23963
- function cmdStudioDiagram(id, card) {
23964
- const flow = found(id);
23861
+ function cmdStudioDiagram(id, card, folder) {
23862
+ const files = folder ? readStudioFolder(path76.resolve(folder)) : null;
23863
+ const local = files ? parseStudioFile("studio", files[STUDIO_FILE] ?? "", STUDIO_FILE) : null;
23864
+ if (local && "problem" in local) die(local.problem, "bad-studio");
23865
+ const flow = local && "def" in local ? local.def : found(id);
23965
23866
  const cardId2 = Number(card);
23966
23867
  if (!Number.isInteger(cardId2) || !locate(cardId2)) die(`no card #${card} on this board`, "no-such-card");
23967
- const diagram = studioDiagram({ previews: previewMembers(flow), land: flow.land, scheduled: scheduledMembers(flow) }, (name) => {
23868
+ const diagram = files ? diagramFrom(files) : studioDiagram({ previews: previewMembers(found(id)), land: flow.land, scheduled: scheduledMembers(found(id)) }, (name) => {
23968
23869
  const agent = findSpecAgent(name);
23969
23870
  return agent ? { ...agent, after: agentAfter(name) } : null;
23970
23871
  });
23971
- const file = path77.join(ASSETS, String(cardId2), "studio.json");
23972
- fs76.mkdirSync(path77.dirname(file), { recursive: true });
23973
- fs76.writeFileSync(file, `${JSON.stringify(diagram, null, 2)}
23872
+ const file = path76.join(ASSETS, String(cardId2), "studio.json");
23873
+ fs75.mkdirSync(path76.dirname(file), { recursive: true });
23874
+ fs75.writeFileSync(file, `${JSON.stringify(diagram, null, 2)}
23974
23875
  `);
23975
23876
  const tag = `<Studio src=".assets/${cardId2}/studio.json" label="${flow.name.replace(/"/g, "")}" />`;
23976
23877
  say(tag);
23977
23878
  return { file, tag, diagram };
23978
23879
  }
23979
23880
  function cmdStudioValidate(folder) {
23980
- const dir = path77.resolve(folder);
23981
- if (!fs76.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) die(`${folder} is not a folder`, "bad-args");
23881
+ const dir = path76.resolve(folder);
23882
+ if (!fs75.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) die(`${folder} is not a folder`, "bad-args");
23982
23883
  const files = readStudioFolder(dir);
23983
23884
  const read3 = parseStudioFile("studio", files[STUDIO_FILE] ?? "", STUDIO_FILE);
23984
23885
  const def = "def" in read3 ? read3.def : null;
@@ -23994,69 +23895,92 @@ function cmdStudioValidate(folder) {
23994
23895
  const problems = studioFilesProblems(files).map((p) => `${p.file} ${p.reason}`);
23995
23896
  if (problems.length) die(problems.map((p) => `! ${p}`).join("\n"), { kind: "studio-problems", bare: true, problems });
23996
23897
  say(`${folder}: no problems`);
23997
- return { folder: dir, problems };
23898
+ const checked = checkStudioFiles(files);
23899
+ const fingerprint = checked.ok ? crypto6.createHash("sha256").update(hashInput({ ...checked.files, ...files[VERSION_FILE] ? { [VERSION_FILE]: files[VERSION_FILE] } : {} })).digest("hex") : null;
23900
+ return { folder: dir, problems, fingerprint };
23998
23901
  }
23999
23902
  async function cmdStudioPull(id, folder) {
24000
23903
  const cloudId = cloudIdOf(id);
24001
23904
  if (!cloudId) found(id);
24002
- const dir = path77.resolve(folder ?? id);
24003
- if (fs76.existsSync(dir) && fs76.readdirSync(dir).length) die(`${folder ?? id} is not empty`, "bad-args");
23905
+ const dir = path76.resolve(folder ?? id);
23906
+ if (fs75.existsSync(dir) && fs75.readdirSync(dir).length) die(`${folder ?? id} is not empty`, "bad-args");
24004
23907
  const read3 = await call("GET", `/v1/studios/${encodeURIComponent(cloudId)}`);
24005
23908
  if (!read3.ok) die(read3.error, read3.code === "not_found" ? "no-such-studio" : "cloud-refused");
24006
23909
  const { version, files } = read3.value;
24007
23910
  for (const [file, text4] of Object.entries({ ...files, [VERSION_FILE]: versionText(cloudId, version) })) {
24008
- const full = path77.join(dir, ...file.split("/"));
24009
- fs76.mkdirSync(path77.dirname(full), { recursive: true });
23911
+ const full = path76.join(dir, ...file.split("/"));
23912
+ fs75.mkdirSync(path76.dirname(full), { recursive: true });
24010
23913
  const data = isAboutFile(file) && !file.endsWith(".md") && /^data:[^;]+;base64,/.exec(text4);
24011
- fs76.writeFileSync(full, data ? Buffer.from(text4.slice(data[0].length), "base64") : text4);
23914
+ fs75.writeFileSync(full, data ? Buffer.from(text4.slice(data[0].length), "base64") : text4);
24012
23915
  }
24013
23916
  const shown = folder ?? `./${id}`;
24014
23917
  say(`Pulled ${id} v${version} into ${shown}.`);
24015
23918
  return { id, version, folder: dir };
24016
23919
  }
23920
+ function publicationFiles(dir) {
23921
+ const checked = checkStudioFiles(readStudioFolder(dir));
23922
+ if (!checked.ok) die(`${checked.file} ${checked.reason}`, "bad-studio");
23923
+ return checked.files;
23924
+ }
23925
+ async function publishFolder(dir, route2, body, requestId) {
23926
+ const pendingFile = path76.join(dir, ".publication.json");
23927
+ const hash2 = crypto6.createHash("sha256").update(JSON.stringify({ route: route2, files: body.files, workspace: body.workspace })).digest("hex");
23928
+ let held4;
23929
+ try {
23930
+ held4 = JSON.parse(fs75.readFileSync(pendingFile, "utf8"));
23931
+ } catch {
23932
+ }
23933
+ if (requestId && held4?.requestId === requestId && held4.hash !== hash2) die("This request ID already names different files; use a new request ID.", "bad-args");
23934
+ const replay = held4?.hash === hash2 && held4.route === route2 && (!requestId || held4.requestId === requestId) && (body.expectedVersion === held4.body.expectedVersion || body.expectedVersion === held4.resultVersion);
23935
+ const pending = replay ? held4 : { requestId: requestId ?? crypto6.randomUUID(), hash: hash2, body, route: route2 };
23936
+ fs75.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
23937
+ const res = await call(route2 === "/v1/studios" ? "POST" : "PATCH", route2, pending.body, pending.requestId);
23938
+ if (!res.ok) die(res.error, res.code === "version_conflict" || res.code === "conflict" ? "studio-moved" : "cloud-refused");
23939
+ const { id, version } = res.value;
23940
+ pending.resultVersion = version;
23941
+ fs75.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
23942
+ fs75.writeFileSync(path76.join(dir, VERSION_FILE), versionText(id, version));
23943
+ say(`Saved ${studioName(id)} v${version}. New tasks take it.`);
23944
+ return { id, version, changed: true, requestId: pending.requestId };
23945
+ }
23946
+ async function cmdStudioCreate(folder, opts) {
23947
+ if (!opts.requestId) die("--request-id is required", "bad-args");
23948
+ const dir = path76.resolve(folder);
23949
+ const files = publicationFiles(dir);
23950
+ const workspace2 = opts.workspace ?? (await cloudScope()).workspace;
23951
+ return publishFolder(dir, "/v1/studios", { files, workspace: workspace2 }, opts.requestId);
23952
+ }
24017
23953
  async function cmdStudioPush(folder, opts) {
24018
- const dir = path77.resolve(folder);
23954
+ const dir = path76.resolve(folder);
24019
23955
  let pulled = null;
24020
23956
  try {
24021
- pulled = JSON.parse(fs76.readFileSync(path77.join(dir, VERSION_FILE), "utf8"));
23957
+ pulled = JSON.parse(fs75.readFileSync(path76.join(dir, VERSION_FILE), "utf8"));
24022
23958
  } catch {
24023
23959
  }
24024
- if (!pulled?.id || !Number.isInteger(pulled.version)) die(`${folder} was not written by \`akb studio pull\``, "bad-args");
24025
- const { id: cloudId, version } = pulled;
24026
- const id = studioName(cloudId);
24027
- const readOnly2 = () => die(`${id} is not this workspace's own; copy it on the web first.`, "studio-read-only");
24028
- if (cloudId.startsWith("wf_builtin_")) readOnly2();
24029
- const read3 = readStudioFolder(dir);
24030
- const problems = studioFilesProblems(read3).map((p) => `${p.file} ${p.reason}`);
24031
- if (problems.length) die(problems.map((p) => `! ${p}`).join("\n"), { kind: "bad-studio", bare: true, problems });
24032
- const checked = checkStudioFiles(read3);
24033
- const { files } = checked;
24034
- const now = await call("GET", `/v1/studios/${encodeURIComponent(cloudId)}`);
24035
- if (!now.ok) die(now.error, now.code === "not_found" ? "no-such-studio" : "cloud-refused");
24036
- if (now.value.version !== version) die(`${id} is at v${now.value.version} now; pull again and redo the change.`, "studio-moved");
24037
- if (JSON.stringify(files) === JSON.stringify(Object.fromEntries(Object.entries(now.value.files).filter(([f]) => f !== VERSION_FILE).sort()))) {
24038
- say(`${id} is unchanged (v${version}).`);
24039
- return { id, version, changed: false, ...opts.dryRun ? { dryRun: true } : {} };
23960
+ if (!pulled?.id || !Number.isInteger(pulled.version) || pulled.version < 1) die(`${folder} has no valid version.json; pull again.`, "bad-args");
23961
+ const { id, version } = pulled;
23962
+ if (id.startsWith("wf_builtin_")) die("Copy this studio before editing it.", "studio-read-only");
23963
+ const files = publicationFiles(dir);
23964
+ if (!fs75.existsSync(path76.join(dir, ".publication.json")) && !opts.requestId) {
23965
+ const now = await call("GET", `/v1/studios/${encodeURIComponent(id)}`);
23966
+ if (now.ok && now.value.version === version && JSON.stringify(files) === JSON.stringify(Object.fromEntries(Object.entries(now.value.files).filter(([f]) => f !== VERSION_FILE).sort()))) {
23967
+ say(`${studioName(id)} is unchanged (v${version}).`);
23968
+ return { id: studioName(id), version, changed: false, ...opts.dryRun ? { dryRun: true } : {} };
23969
+ }
24040
23970
  }
24041
23971
  if (opts.dryRun) {
24042
- say(`${id} would push v${version + 1}.`);
24043
- return { id, version: version + 1, changed: true, dryRun: true };
24044
- }
24045
- const res = await call("PATCH", `/v1/studios/${encodeURIComponent(cloudId)}`, { files });
24046
- if (!res.ok) {
24047
- if (res.code === "read_only" || res.code === "not_found") readOnly2();
24048
- die(res.error, res.code === "bad_request" || res.code === "payload_too_large" ? "bad-studio" : "cloud-refused");
23972
+ const now = cloudOk(await call("GET", `/v1/studios/${encodeURIComponent(id)}`));
23973
+ if (now.version !== version) die(`The studio is at v${now.version}; pull again.`, "studio-moved");
23974
+ say(`${studioName(id)} would push v${version + 1}.`);
23975
+ return { id: studioName(id), version: version + 1, changed: true, dryRun: true };
24049
23976
  }
24050
- const next = res.value.version;
24051
- fs76.writeFileSync(path77.join(dir, VERSION_FILE), versionText(cloudId, next));
24052
- say(`Pushed ${id} v${next}. New tasks take it.`);
24053
- return { id, version: next, changed: true };
23977
+ return publishFolder(dir, `/v1/studios/${encodeURIComponent(id)}`, { files, expectedVersion: version }, opts.requestId);
24054
23978
  }
24055
23979
  function noteText({ file, text: text4 }) {
24056
23980
  if (file !== void 0 && text4 !== void 0) die("pass --file or --text, not both", "bad-args");
24057
23981
  if (file !== void 0) {
24058
23982
  try {
24059
- return fs76.readFileSync(file, "utf8").trim();
23983
+ return fs75.readFileSync(file, "utf8").trim();
24060
23984
  } catch {
24061
23985
  die(`can't read ${file}`, "bad-args");
24062
23986
  }
@@ -24121,7 +24045,7 @@ async function cmdStudioInstructions(agent, opts) {
24121
24045
  say(rule ? `saved ${agent}'s instructions (${scope === "project" ? "this project" : "every project"})` : `cleared ${agent}'s instructions`);
24122
24046
  return { agent, rule, scope };
24123
24047
  }
24124
- var found, done, names2, previewNames, cloudIdOf, enc2;
24048
+ var found, names2, previewNames, cloudIdOf, enc2;
24125
24049
  var init_studio2 = __esm({
24126
24050
  "../cli/src/commands/studio.ts"() {
24127
24051
  "use strict";
@@ -24147,9 +24071,6 @@ var init_studio2 = __esm({
24147
24071
  }
24148
24072
  return flow;
24149
24073
  };
24150
- done = (res) => {
24151
- if (!res.ok) die(res.error ?? "the board refused that change", res.reason === "studioReadOnly" ? "studio-read-only" : void 0);
24152
- };
24153
24074
  names2 = (rows) => rows.map((h) => `${h.agent}${h.off ? " (off)" : ""}`).join(", ");
24154
24075
  previewNames = (rows) => rows.map((h) => `${names2([h])}${agentAfter(h.agent).length ? ` (after ${agentAfter(h.agent).join(", ")})` : ""}`).join(", ");
24155
24076
  cloudIdOf = (id) => cloudFlows().find((f) => studioName(f.cloudId) === id)?.cloudId;
@@ -24281,8 +24202,8 @@ var init_complete = __esm({
24281
24202
  });
24282
24203
 
24283
24204
  // ../cli/src/lib/agent/approve.ts
24284
- import fs77 from "node:fs";
24285
- import path78 from "node:path";
24205
+ import fs76 from "node:fs";
24206
+ import path77 from "node:path";
24286
24207
  function approvalRequest(req) {
24287
24208
  const id = req.id;
24288
24209
  const card = id === void 0 ? null : findCard(id);
@@ -24300,12 +24221,12 @@ function advancePhase(id) {
24300
24221
  const card = findCard(id);
24301
24222
  const found2 = locate(id);
24302
24223
  if (!card || !found2 || !awaitingApproval(card)) return { error: `#${id} is no longer waiting on approval.` };
24303
- const file = found2.kind === "group" ? path78.join(found2.target, "root.md") : found2.target;
24304
- const { meta, body } = parseFrontmatter(fs77.readFileSync(file, "utf8"));
24224
+ const file = found2.kind === "group" ? path77.join(found2.target, "root.md") : found2.target;
24225
+ const { meta, body } = parseFrontmatter(fs76.readFileSync(file, "utf8"));
24305
24226
  if (!meta) return { error: `#${id} has no frontmatter` };
24306
24227
  meta.phase = card.stage + 1;
24307
24228
  meta.status = "todo";
24308
- fs77.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
24229
+ fs76.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
24309
24230
  return null;
24310
24231
  }
24311
24232
  var init_approve = __esm({
@@ -24428,16 +24349,16 @@ var init_start = __esm({
24428
24349
  });
24429
24350
 
24430
24351
  // ../cli/src/lib/agent/task-chats.ts
24431
- import fs78 from "node:fs";
24432
- import path79 from "node:path";
24352
+ import fs77 from "node:fs";
24353
+ import path78 from "node:path";
24433
24354
  function taskChatFile(task, home3) {
24434
24355
  if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
24435
- return path79.join(taskChatsDir(home3), `${task}.jsonl`);
24356
+ return path78.join(taskChatsDir(home3), `${task}.jsonl`);
24436
24357
  }
24437
24358
  function readTaskChat(task, home3) {
24438
24359
  let text4;
24439
24360
  try {
24440
- text4 = fs78.readFileSync(taskChatFile(task, home3), "utf8");
24361
+ text4 = fs77.readFileSync(taskChatFile(task, home3), "utf8");
24441
24362
  } catch {
24442
24363
  return [];
24443
24364
  }
@@ -24458,13 +24379,13 @@ var init_task_chats = __esm({
24458
24379
  "use strict";
24459
24380
  init_home();
24460
24381
  TASK = /^[\w-]{1,100}$/;
24461
- taskChatsDir = (home3 = machineHome()) => path79.join(home3, "chats");
24382
+ taskChatsDir = (home3 = machineHome()) => path78.join(home3, "chats");
24462
24383
  }
24463
24384
  });
24464
24385
 
24465
24386
  // ../cli/src/lib/agent/memory-review.ts
24466
- import fs79 from "node:fs";
24467
- import path80 from "node:path";
24387
+ import fs78 from "node:fs";
24388
+ import path79 from "node:path";
24468
24389
  function taskChatsToReview(tasks) {
24469
24390
  const out = [];
24470
24391
  for (const ref of [...new Set(tasks)]) {
@@ -24486,8 +24407,8 @@ function readArchived2(id) {
24486
24407
  const found2 = Number.isInteger(id) && id > 0 ? locateArchived(id) : null;
24487
24408
  if (!found2) return null;
24488
24409
  try {
24489
- const file = found2.kind === "group" ? path80.join(found2.target, "root.md") : found2.target;
24490
- const { meta, body } = parseFrontmatter(fs79.readFileSync(file, "utf8"));
24410
+ const file = found2.kind === "group" ? path79.join(found2.target, "root.md") : found2.target;
24411
+ const { meta, body } = parseFrontmatter(fs78.readFileSync(file, "utf8"));
24491
24412
  if (!meta) return null;
24492
24413
  return { id, title: meta.title, modules: meta.modules ?? [], rejected: meta.rejected, body };
24493
24414
  } catch {
@@ -24556,17 +24477,17 @@ var init_memory_review = __esm({
24556
24477
  });
24557
24478
 
24558
24479
  // ../cli/src/lib/agent/dismissal-review.ts
24559
- import fs80 from "node:fs";
24560
- import path81 from "node:path";
24480
+ import fs79 from "node:fs";
24481
+ import path80 from "node:path";
24561
24482
  function rejectionsToReview() {
24562
- const dir = path81.join(ARCHIVE, REJECTIONS_TO_REVIEW);
24563
- if (!fs80.existsSync(dir)) return [];
24483
+ const dir = path80.join(ARCHIVE, REJECTIONS_TO_REVIEW);
24484
+ if (!fs79.existsSync(dir)) return [];
24564
24485
  const found2 = [];
24565
24486
  for (const file of walkMd(dir)) {
24566
24487
  const id = archivedId(file);
24567
24488
  if (id === null) continue;
24568
24489
  try {
24569
- const { meta } = parseFrontmatter(fs80.readFileSync(file, "utf8"));
24490
+ const { meta } = parseFrontmatter(fs79.readFileSync(file, "utf8"));
24570
24491
  if (!meta?.rejected || meta.rejected_by !== "user" || !meta.rejected_reason.trim()) continue;
24571
24492
  found2.push({ id, title: meta.title, file: rel(file), reason: meta.rejected_reason.trim(), rejectedAt: meta.rejected_at });
24572
24493
  } catch {
@@ -24596,7 +24517,7 @@ function citedSources(text4) {
24596
24517
  function withdrawnSources() {
24597
24518
  const cited = [...new Set(plannerCopies("rejected.md").flatMap((file) => {
24598
24519
  try {
24599
- return citedSources(fs80.readFileSync(file, "utf8"));
24520
+ return citedSources(fs79.readFileSync(file, "utf8"));
24600
24521
  } catch {
24601
24522
  return [];
24602
24523
  }
@@ -24621,8 +24542,8 @@ var init_dismissal_review = __esm({
24621
24542
  });
24622
24543
 
24623
24544
  // ../cli/src/lib/agent/flow.ts
24624
- import fs81 from "node:fs";
24625
- import path82 from "node:path";
24545
+ import fs80 from "node:fs";
24546
+ import path81 from "node:path";
24626
24547
  function readCard2(id, home3 = "board") {
24627
24548
  const pending = activeDelivery(id)?.completions?.some((c) => !c.finished);
24628
24549
  const found2 = home3 === "archive" ? locateArchived(id) : locate(id) ?? (pending ? locateArchived(id) : null);
@@ -24632,10 +24553,10 @@ function readCard2(id, home3 = "board") {
24632
24553
  { kind: "card-not-found", id }
24633
24554
  );
24634
24555
  }
24635
- const file = found2.kind === "group" ? path82.join(found2.target, "root.md") : found2.target;
24556
+ const file = found2.kind === "group" ? path81.join(found2.target, "root.md") : found2.target;
24636
24557
  let text4;
24637
24558
  try {
24638
- text4 = fs81.readFileSync(file, "utf8");
24559
+ text4 = fs80.readFileSync(file, "utf8");
24639
24560
  } catch {
24640
24561
  die(`#${id} is on the board but ${rel(file)} can't be read.`, { kind: "card-unreadable", id });
24641
24562
  }
@@ -25196,7 +25117,7 @@ async function startRefinement(req) {
25196
25117
  }
25197
25118
  function refinementAfter(action, cardId2, flowId) {
25198
25119
  const card = currentCard(cardId2);
25199
- if (!card || card.openBlockers.length > 0) return null;
25120
+ if (!card || card.isGroup || card.openBlockers.length > 0) return null;
25200
25121
  if (card.questions.length > 0 || action === "clarify" || card.deliversIn !== "plan") return null;
25201
25122
  if (planDeliveryGap(card) === null) return null;
25202
25123
  if (awaitingApproval(card)) return null;
@@ -25218,13 +25139,13 @@ function refinesAfter(action, changed, before) {
25218
25139
  function stalledLine(cardId2, next) {
25219
25140
  if (next !== null) return null;
25220
25141
  const card = cardId2 === null ? null : currentCard(cardId2);
25221
- if (!card || refinementStep(card) === "done") return null;
25142
+ if (!card || card.isGroup || refinementStep(card) === "done") return null;
25222
25143
  return `#${card.id} is still in To do after planning, and the board won't plan it again on its own \u2014 refine it again, or mark it ready yourself.`;
25223
25144
  }
25224
25145
  function planStageEnd(run3) {
25225
25146
  if (run3.cardId === null || stageOfAction(run3.action) !== "plan") return null;
25226
25147
  const card = currentCard(run3.cardId);
25227
- if (!card || card.openBlockers.length > 0 || card.questions.length > 0) return null;
25148
+ if (!card || card.isGroup || card.openBlockers.length > 0 || card.questions.length > 0) return null;
25228
25149
  if (refinementStep(card) !== "done") return null;
25229
25150
  return endOfStage(stageContract("plan"), card);
25230
25151
  }
@@ -25378,15 +25299,15 @@ var init_follow = __esm({
25378
25299
  function queueCompleted(openBefore) {
25379
25300
  const before = new Set(openBefore);
25380
25301
  if (!before.size) return false;
25381
- let done2;
25302
+ let done;
25382
25303
  try {
25383
- done2 = readArchive().cards.filter((card) => before.has(card.id) && !card.rejected).map((card) => card.id);
25304
+ done = readArchive().cards.filter((card) => before.has(card.id) && !card.rejected).map((card) => card.id);
25384
25305
  } catch {
25385
25306
  return false;
25386
25307
  }
25387
25308
  const queue = reflectQueue();
25388
25309
  const covered = reflectedOn();
25389
- const fresh = done2.filter((id) => !queue.includes(id) && !covered.has(id)).reverse();
25310
+ const fresh = done.filter((id) => !queue.includes(id) && !covered.has(id)).reverse();
25390
25311
  if (!fresh.length) return false;
25391
25312
  queueReflect(fresh);
25392
25313
  return true;
@@ -25451,7 +25372,7 @@ __export(watch_exports, {
25451
25372
  watchRun: () => watchRun
25452
25373
  });
25453
25374
  import { spawn as spawn3 } from "node:child_process";
25454
- import fs82 from "node:fs";
25375
+ import fs81 from "node:fs";
25455
25376
  async function watchRun(sessionId, resume = startResume) {
25456
25377
  const spec = readSpec(sessionId);
25457
25378
  const run3 = peekRun(sessionId);
@@ -25487,11 +25408,11 @@ async function watchRun(sessionId, resume = startResume) {
25487
25408
  const record = claimed ?? run3;
25488
25409
  const sub = record.action === "sub";
25489
25410
  if (claim) await setCardStatus(claim.cardId, claim.status);
25490
- fs82.mkdirSync(SESSIONS_DIR, { recursive: true });
25491
- const logFile = fs82.createWriteStream(record.logPath, { flags: "a" });
25411
+ fs81.mkdirSync(SESSIONS_DIR, { recursive: true });
25412
+ const logFile = fs81.createWriteStream(record.logPath, { flags: "a" });
25492
25413
  logFile.on("error", () => {
25493
25414
  });
25494
- const eventsFile = fs82.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
25415
+ const eventsFile = fs81.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
25495
25416
  eventsFile.on("error", () => {
25496
25417
  });
25497
25418
  const event2 = (e) => eventsFile.write(`${JSON.stringify(e)}
@@ -25646,7 +25567,7 @@ async function watchRun(sessionId, resume = startResume) {
25646
25567
  [error] ${spawnError}`);
25647
25568
  });
25648
25569
  return await new Promise((resolve2) => {
25649
- let done2 = false;
25570
+ let done = false;
25650
25571
  let spoken;
25651
25572
  let silent = false;
25652
25573
  let waited = false;
@@ -25664,8 +25585,8 @@ async function watchRun(sessionId, resume = startResume) {
25664
25585
  };
25665
25586
  });
25666
25587
  const finish = async (code, wanted) => {
25667
- if (done2) return;
25668
- done2 = true;
25588
+ if (done) return;
25589
+ done = true;
25669
25590
  let asked = wanted;
25670
25591
  if (idle) clearTimeout(idle);
25671
25592
  await stopSubRuns(sessionId);
@@ -25893,17 +25814,17 @@ Cannot resume board repair: ${next.error}`;
25893
25814
  wakeUp();
25894
25815
  return;
25895
25816
  }
25896
- if (done2) return;
25817
+ if (done) return;
25897
25818
  giveUp(true);
25898
25819
  };
25899
25820
  process.on("SIGTERM", askToStop);
25900
25821
  process.on("SIGINT", askToStop);
25901
25822
  touch = () => {
25902
- if (done2 || !silenceMs) return;
25823
+ if (done || !silenceMs) return;
25903
25824
  if (idle) clearTimeout(idle);
25904
25825
  const background = client?.background?.() ?? renderer?.background?.() ?? 0;
25905
25826
  idle = setTimeout(() => {
25906
- if (done2 || stopped2 || silent) return;
25827
+ if (done || stopped2 || silent) return;
25907
25828
  if (liveSubRuns(sessionId).length) {
25908
25829
  touch();
25909
25830
  return;
@@ -26062,8 +25983,8 @@ var init_watch = __esm({
26062
25983
  });
26063
25984
 
26064
25985
  // ../cli/src/commands/run.ts
26065
- import fs83 from "node:fs";
26066
- import path83 from "node:path";
25986
+ import fs82 from "node:fs";
25987
+ import path82 from "node:path";
26067
25988
  async function cmdStartRun(action, args, opts, program2 = "akb") {
26068
25989
  const { req, follow: follow2, print } = readRequest(action, args, opts);
26069
25990
  if (!print && (action === "approve" || action === "implement")) {
@@ -26283,7 +26204,7 @@ async function cmdSubStart(words, opts) {
26283
26204
  let prompt = words.join(" ");
26284
26205
  if (opts.file) {
26285
26206
  try {
26286
- prompt = fs83.readFileSync(path83.resolve(opts.file), "utf8");
26207
+ prompt = fs82.readFileSync(path82.resolve(opts.file), "utf8");
26287
26208
  } catch {
26288
26209
  die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
26289
26210
  }
@@ -26593,7 +26514,7 @@ var init_run = __esm({
26593
26514
  WAIT_MS2 = 9e4;
26594
26515
  WAIT_POLL_MS = 1e3;
26595
26516
  follow = { pollMs: 2e3, idleMs: 10 * 6e4 };
26596
- pause = (ms) => new Promise((done2) => setTimeout(done2, ms));
26517
+ pause = (ms) => new Promise((done) => setTimeout(done, ms));
26597
26518
  MARK2 = {
26598
26519
  running: "\xB7",
26599
26520
  done: "\u2713",
@@ -26651,7 +26572,7 @@ var init_signals = __esm({
26651
26572
  });
26652
26573
 
26653
26574
  // ../cli/src/commands/triage.ts
26654
- import fs84 from "node:fs";
26575
+ import fs83 from "node:fs";
26655
26576
  async function cmdTriageAdd(opts) {
26656
26577
  const title = (opts.title ?? "").trim();
26657
26578
  if (!title) die('say what it is: --title "<one line>"', { kind: "needs-input" });
@@ -26661,7 +26582,7 @@ async function cmdTriageAdd(opts) {
26661
26582
  let body = opts.text;
26662
26583
  if (opts.file !== void 0) {
26663
26584
  try {
26664
- body = fs84.readFileSync(opts.file, "utf8");
26585
+ body = fs83.readFileSync(opts.file, "utf8");
26665
26586
  } catch {
26666
26587
  die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
26667
26588
  }
@@ -26670,10 +26591,10 @@ async function cmdTriageAdd(opts) {
26670
26591
  die('the item has to say something: --text ".." , or --file <path> for a longer one', { kind: "needs-input" });
26671
26592
  }
26672
26593
  const agent = runAgent();
26673
- const done2 = addToInbox({ title, text: body, source: opts.source, slug: opts.slug, studio, ...agent ? { agent } : {} });
26674
- if (!done2.ok) die(done2.error, { kind: "triage-item-refused" });
26675
- say(`added to triage: ${done2.signal.relPath}`);
26676
- return { title: done2.signal.title, source_id: done2.signal.sourceId, file: done2.signal.relPath };
26594
+ const done = addToInbox({ title, text: body, source: opts.source, slug: opts.slug, studio, ...agent ? { agent } : {} });
26595
+ if (!done.ok) die(done.error, { kind: "triage-item-refused" });
26596
+ say(`added to triage: ${done.signal.relPath}`);
26597
+ return { title: done.signal.title, source_id: done.signal.sourceId, file: done.signal.relPath };
26677
26598
  }
26678
26599
  function cmdTriageCheck(sourceId) {
26679
26600
  const said2 = sourceId.trim();
@@ -26974,15 +26895,12 @@ List trigger conditions: ${raw} previews --triggers --json`).action(async functi
26974
26895
  useBoard(resolveBoard("components", { board: ctx.board, dir: ctx.dir, cwd: cli.cwd, installHint: cli.installHint }), ctx.dir !== null);
26975
26896
  await boardless(this, cli, () => cmdComponents(this.opts()));
26976
26897
  });
26977
- const studio = noun("studio", "check a studio folder, or rename a draft or draw a diagram inside a run");
26898
+ const studio = noun("studio", "check a studio folder or draw its diagram");
26978
26899
  withShared(studio.command("validate")).argument("<folder>", "a studio folder: STUDIO.md and agents/").summary("report every problem in a studio folder; agents it names but lacks are read from the board").action(async function(folder) {
26979
26900
  await onBoard2(this, cli, () => cmdStudioValidate(folder));
26980
26901
  });
26981
- withShared(studio.command("rename")).argument("<id>", "the draft, from `studio list`").argument("<name...>", "what to call it now").summary("rename the Studio builder draft. Only inside that task's run.").action(async function(id, name) {
26982
- await onBoard2(this, cli, () => cmdStudioRename(id, name.join(" ")));
26983
- });
26984
- withShared(studio.command("diagram")).argument("<id>", "the studio, from `studio list`").argument("<card>", "the card whose asset folder gets studio.json").summary("write the studio's diagram to .assets/<card>/studio.json and print the <Studio> tag that shows it").action(async function(id, card) {
26985
- await onBoard2(this, cli, () => cmdStudioDiagram(id, card));
26902
+ withShared(studio.command("diagram")).argument("<id-or-card>", "studio id, or card number with --folder").argument("[card]", "the card whose asset folder gets studio.json").option("--folder <folder>", "read a local studio folder").summary("write the studio's diagram to .assets/<card>/studio.json and print the <Studio> tag that shows it").action(async function(id, card) {
26903
+ await onBoard2(this, cli, () => cmdStudioDiagram(id, this.opts().folder ? id : card, this.opts().folder));
26986
26904
  });
26987
26905
  }
26988
26906
  function declareRuns(program2, cli) {
@@ -27117,7 +27035,7 @@ function declareRuns(program2, cli) {
27117
27035
  "Every card runs through one studio, kept in Cloud: the built-ins and the studios this workspace installed or made. To change one of this workspace's own: `pull` it into a folder, edit, `push`. New tasks take the new version; a task already started keeps its own. `akb guide update-studio` has the whole flow."
27118
27036
  ).allowExcessArguments().allowUnknownOption().action(async function() {
27119
27037
  const word = this.args[0];
27120
- if (word === "rename" || word === "diagram") {
27038
+ if (word === "diagram") {
27121
27039
  this.error(`\`${cli.program} studio ${word}\` is now \`${cli.program} raw studio ${word}\`.`, { code: "commander.unknownCommand" });
27122
27040
  }
27123
27041
  if (word) this.error(`unknown command '${word}'`, { code: "commander.unknownCommand" });
@@ -27130,7 +27048,10 @@ function declareRuns(program2, cli) {
27130
27048
  flowWord("pull").argument("<id>", "the studio, from `studio list`").argument("[folder]", "where to write it, empty or new; default ./<id>").summary("write the studio's current version into a folder to edit").action(async function(id, folder) {
27131
27049
  await onBoard2(this, cli, () => cmdStudioPull(id, folder));
27132
27050
  });
27133
- flowWord("push").argument("<folder>", "a folder `studio pull` wrote").option("--dry-run", "check the folder and print what would happen, saving nothing").summary("save the edited folder as the studio's next version, which new tasks take").action(async function(folder) {
27051
+ flowWord("create").argument("<folder>", "the studio files to create").requiredOption("--request-id <id>", "the publication request, reused on retry").option("--workspace <id>", "the target workspace; otherwise use the linked project").summary("create a workspace studio from a local folder").action(async function(folder) {
27052
+ await boardless(this, cli, () => cmdStudioCreate(folder, this.opts()));
27053
+ });
27054
+ flowWord("push").argument("<folder>", "a folder `studio pull` wrote").option("--request-id <id>", "reuse this publication request after a timeout").option("--dry-run", "check the folder and print what would happen, saving nothing").summary("save the edited folder as the studio's next version, which new tasks take").action(async function(folder) {
27134
27055
  await boardless(this, cli, () => cmdStudioPush(folder, this.opts()));
27135
27056
  });
27136
27057
  flowWord("rule").argument("<studio>", "a studio id from `akb studio list`").option("--text <text>", "the rules, for a one-liner; empty clears them").option("--file <path>", "the rules, as markdown written to a file first").summary("set a studio's rules \u2014 what every card on it follows \u2014 in the user's own words").description(
@@ -27332,15 +27253,15 @@ var init_agent2 = __esm({
27332
27253
  });
27333
27254
 
27334
27255
  // ../cli/src/kanban.ts
27335
- import fs87 from "node:fs";
27256
+ import fs86 from "node:fs";
27336
27257
  import { fileURLToPath as fileURLToPath4 } from "node:url";
27337
27258
 
27338
27259
  // ../cli/src/lib/cli/akb.ts
27339
27260
  init_agent2();
27340
27261
 
27341
27262
  // ../cli/src/lib/cli/setup.ts
27342
- import fs86 from "node:fs";
27343
- import path85 from "node:path";
27263
+ import fs85 from "node:fs";
27264
+ import path84 from "node:path";
27344
27265
  import { fileURLToPath as fileURLToPath3 } from "node:url";
27345
27266
 
27346
27267
  // ../cli/src/commands/update.ts
@@ -27354,8 +27275,8 @@ init_paths();
27354
27275
  init_memory();
27355
27276
  init_yaml2();
27356
27277
  init_version();
27357
- import fs85 from "node:fs";
27358
- import path84 from "node:path";
27278
+ import fs84 from "node:fs";
27279
+ import path83 from "node:path";
27359
27280
  import { spawnSync as spawnSync6 } from "node:child_process";
27360
27281
  var NAME = "wildcrane";
27361
27282
  var REPO = "https://github.com/wildcrane-ai/wildcrane";
@@ -27377,10 +27298,10 @@ var Report = class {
27377
27298
  for (const line of this.notes) say(` ! ${line}`);
27378
27299
  }
27379
27300
  };
27380
- var read2 = (file) => fs85.existsSync(file) ? fs85.readFileSync(file, "utf8") : null;
27301
+ var read2 = (file) => fs84.existsSync(file) ? fs84.readFileSync(file, "utf8") : null;
27381
27302
  function statOf(p) {
27382
27303
  try {
27383
- return fs85.lstatSync(p);
27304
+ return fs84.lstatSync(p);
27384
27305
  } catch {
27385
27306
  return null;
27386
27307
  }
@@ -27405,10 +27326,10 @@ async function cmdUpdate2(ctx) {
27405
27326
  return { updated: ctx.dir, from, to: SKILL_VERSION };
27406
27327
  }
27407
27328
  async function repairBoard(root2, report3, named2) {
27408
- const legacy2 = path84.join(root2, "docs", "kanban");
27409
- const kept2 = path84.join(root2, ".akb", "kanban");
27410
- const board2 = named2 ?? (fs85.existsSync(legacy2) ? legacy2 : kept2);
27411
- if (!fs85.existsSync(board2)) {
27329
+ const legacy2 = path83.join(root2, "docs", "kanban");
27330
+ const kept2 = path83.join(root2, ".akb", "kanban");
27331
+ const board2 = named2 ?? (fs84.existsSync(legacy2) ? legacy2 : kept2);
27332
+ if (!fs84.existsSync(board2)) {
27412
27333
  report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
27413
27334
  return false;
27414
27335
  }
@@ -27439,20 +27360,20 @@ function moveRuntimes(root2, board2, report3) {
27439
27360
  }
27440
27361
  }
27441
27362
  function moveLegacyMemory(board2, report3) {
27442
- const memory = path84.join(board2, "memory");
27363
+ const memory = path83.join(board2, "memory");
27443
27364
  const moved = [];
27444
27365
  for (const name of MEMORY_FILES) {
27445
- const from = path84.join(board2, name);
27366
+ const from = path83.join(board2, name);
27446
27367
  const st = statOf(from);
27447
27368
  if (!st || !st.isFile()) continue;
27448
- fs85.mkdirSync(memory, { recursive: true });
27449
- const to = path84.join(memory, name);
27369
+ fs84.mkdirSync(memory, { recursive: true });
27370
+ const to = path83.join(memory, name);
27450
27371
  const there = read2(to);
27451
27372
  if (there === null) {
27452
- fs85.renameSync(from, to);
27373
+ fs84.renameSync(from, to);
27453
27374
  moved.push(name);
27454
27375
  } else if (there === read2(from)) {
27455
- fs85.rmSync(from);
27376
+ fs84.rmSync(from);
27456
27377
  moved.push(name);
27457
27378
  } else {
27458
27379
  report3.notes.push(`both docs/kanban/${name} and docs/kanban/memory/${name} exist and differ \u2014 merge them by hand`);
@@ -27461,23 +27382,23 @@ function moveLegacyMemory(board2, report3) {
27461
27382
  if (moved.length) report3.did.push(`moved the memory set into docs/kanban/memory/: ${moved.join(", ")}`);
27462
27383
  }
27463
27384
  function dropRecordFile(board2) {
27464
- const file = path84.join(board2, "record.csv");
27465
- if (!fs85.existsSync(file)) return null;
27466
- fs85.rmSync(file);
27385
+ const file = path83.join(board2, "record.csv");
27386
+ if (!fs84.existsSync(file)) return null;
27387
+ fs84.rmSync(file);
27467
27388
  return "removed docs/kanban/record.csv (the planning scores it fed are gone)";
27468
27389
  }
27469
27390
  function dropModuleGoals(board2, report3) {
27470
- const memory = path84.join(board2, "memory");
27471
- if (!fs85.existsSync(memory)) return;
27472
- const root2 = read2(path84.join(memory, "goal.md"));
27391
+ const memory = path83.join(board2, "memory");
27392
+ if (!fs84.existsSync(memory)) return;
27393
+ const root2 = read2(path83.join(memory, "goal.md"));
27473
27394
  let dropped = 0;
27474
- for (const entry of fs85.readdirSync(memory, { withFileTypes: true })) {
27395
+ for (const entry of fs84.readdirSync(memory, { withFileTypes: true })) {
27475
27396
  if (!entry.isDirectory()) continue;
27476
- const file = path84.join(memory, entry.name, "goal.md");
27397
+ const file = path83.join(memory, entry.name, "goal.md");
27477
27398
  const text4 = read2(file);
27478
27399
  if (text4 === null) continue;
27479
27400
  if (text4 === root2 || text4.includes(UNFILLED) || !goalWords(text4)) {
27480
- fs85.rmSync(file);
27401
+ fs84.rmSync(file);
27481
27402
  dropped++;
27482
27403
  } else {
27483
27404
  report3.notes.push(
@@ -27499,10 +27420,10 @@ var PLAN_LEADS = {
27499
27420
  var GONE_LEADS = ["software-planner", "planner"];
27500
27421
  function planLeads(board2) {
27501
27422
  const leads = { ...PLAN_LEADS };
27502
- const root2 = path84.join(board2, "studios");
27503
- for (const entry of fs85.existsSync(root2) ? fs85.readdirSync(root2, { withFileTypes: true }) : []) {
27423
+ const root2 = path83.join(board2, "studios");
27424
+ for (const entry of fs84.existsSync(root2) ? fs84.readdirSync(root2, { withFileTypes: true }) : []) {
27504
27425
  if (!entry.isDirectory()) continue;
27505
- const meta = splitFrontmatter(read2(path84.join(root2, entry.name, "STUDIO.md")) ?? "").meta;
27426
+ const meta = splitFrontmatter(read2(path83.join(root2, entry.name, "STUDIO.md")) ?? "").meta;
27506
27427
  const stages = meta === null ? void 0 : parseYamlBlock(meta).stages;
27507
27428
  const plan = stages && typeof stages === "object" && !Array.isArray(stages) ? stages.plan : void 0;
27508
27429
  const lead = plan && typeof plan === "object" && !Array.isArray(plan) && typeof plan.lead === "string" ? plan.lead.trim() : "";
@@ -27511,30 +27432,30 @@ function planLeads(board2) {
27511
27432
  return leads;
27512
27433
  }
27513
27434
  function movePlanRules(board2, report3) {
27514
- const rules = path84.join(board2, "rules");
27435
+ const rules = path83.join(board2, "rules");
27515
27436
  const moved = [];
27516
27437
  for (const [id, leads] of Object.entries(planLeads(board2))) {
27517
27438
  for (const lead of leads) {
27518
- const from = path84.join(rules, `${lead}.md`);
27439
+ const from = path83.join(rules, `${lead}.md`);
27519
27440
  const rule = read2(from)?.trim();
27520
27441
  if (!rule) continue;
27521
- const to = path84.join(rules, "studios", `${id}.md`);
27442
+ const to = path83.join(rules, "studios", `${id}.md`);
27522
27443
  const there = read2(to)?.trim() ?? "";
27523
27444
  if (!there.includes(rule)) {
27524
- fs85.mkdirSync(path84.dirname(to), { recursive: true });
27525
- fs85.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
27445
+ fs84.mkdirSync(path83.dirname(to), { recursive: true });
27446
+ fs84.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
27526
27447
  `);
27527
27448
  moved.push(`${lead} \u2192 ${id}`);
27528
27449
  }
27529
27450
  }
27530
27451
  }
27531
- for (const lead of GONE_LEADS) fs85.rmSync(path84.join(rules, `${lead}.md`), { force: true });
27452
+ for (const lead of GONE_LEADS) fs84.rmSync(path83.join(rules, `${lead}.md`), { force: true });
27532
27453
  if (moved.length) report3.did.push(`made each plan agent's rule its studio's card rule (docs/kanban/rules/studios/): ${moved.join(", ")}`);
27533
27454
  }
27534
27455
  function noteOldStudios(board2, report3) {
27535
27456
  const old = (dir, file, keys) => {
27536
- const root2 = path84.join(board2, dir);
27537
- return (fs85.existsSync(root2) ? fs85.readdirSync(root2, { withFileTypes: true }) : []).filter((e) => e.isDirectory() && keys.test(splitFrontmatter(read2(path84.join(root2, e.name, file)) ?? "").meta ?? "")).map((e) => `docs/kanban/${dir}/${e.name}/${file}`);
27457
+ const root2 = path83.join(board2, dir);
27458
+ return (fs84.existsSync(root2) ? fs84.readdirSync(root2, { withFileTypes: true }) : []).filter((e) => e.isDirectory() && keys.test(splitFrontmatter(read2(path83.join(root2, e.name, file)) ?? "").meta ?? "")).map((e) => `docs/kanban/${dir}/${e.name}/${file}`);
27538
27459
  };
27539
27460
  const files = [...old("studios", "STUDIO.md", /^(stages|delivers):/m), ...old("agents", "AGENT.md", /^\s+(hook|lead):/m)];
27540
27461
  if (files.length) {
@@ -27544,7 +27465,7 @@ function noteOldStudios(board2, report3) {
27544
27465
  }
27545
27466
  }
27546
27467
  function checkConfig(board2, report3) {
27547
- const current = read2(path84.join(board2, "config.md"));
27468
+ const current = read2(path83.join(board2, "config.md"));
27548
27469
  if (!current) return;
27549
27470
  const added = missingConfigKeys(current);
27550
27471
  if (added.length) {
@@ -27554,7 +27475,7 @@ function checkConfig(board2, report3) {
27554
27475
  }
27555
27476
  }
27556
27477
  function checkModules(board2, report3) {
27557
- const map2 = read2(path84.join(board2, "modules.md"));
27478
+ const map2 = read2(path83.join(board2, "modules.md"));
27558
27479
  if (map2 && map2.includes(UNFILLED)) {
27559
27480
  report3.notes.push(
27560
27481
  "docs/kanban/modules.md is still blank \u2014 write it from the repo (`akb guide module-map`)"
@@ -27608,14 +27529,14 @@ function declareSetup(program2, cli) {
27608
27529
  program2.version(SKILL_VERSION, "-v, --version", "print this version").addHelpText("beforeAll", spelled(cli.program));
27609
27530
  const dirOption = (cmd) => cmd.option("--dir <path>", "the project to work on (default: the current folder)").option("--json", "answer as one JSON object instead of prose");
27610
27531
  const where = (cmd) => {
27611
- const dir = path85.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
27612
- if (!fs86.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
27532
+ const dir = path84.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
27533
+ if (!fs85.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
27613
27534
  return dir;
27614
27535
  };
27615
27536
  dirOption(program2.command("update")).summary("\u4FEE\u590D\u5DF2\u6709\u770B\u677F\u5E76\u68C0\u67E5 CLI \u65B0\u7248\u672C").description("\u4FEE\u590D\u5DF2\u6709\u770B\u677F\u5E76\u63D0\u793A CLI \u5347\u7EA7\u547D\u4EE4\u3002\u6CA1\u6709\u770B\u677F\u65F6\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002").action(async function() {
27616
27537
  const dir = where(this);
27617
27538
  const named2 = this.optsWithGlobals().board ?? process.env.AI4KANBAN_BOARD?.trim();
27618
- const board2 = named2 ? path85.resolve(cli.cwd, named2) : null;
27539
+ const board2 = named2 ? path84.resolve(cli.cwd, named2) : null;
27619
27540
  await runAction(ctxOf(this, cli.program), {}, () => cmdUpdate2({ dir, program: cli.program, board: board2 }));
27620
27541
  });
27621
27542
  program2.command("__rules", { hidden: true }).action(function() {
@@ -27660,7 +27581,7 @@ function invokedDirectly() {
27660
27581
  const entry = process.argv[1];
27661
27582
  if (!entry) return false;
27662
27583
  try {
27663
- return fs87.realpathSync(entry) === fs87.realpathSync(SELF2);
27584
+ return fs86.realpathSync(entry) === fs86.realpathSync(SELF2);
27664
27585
  } catch {
27665
27586
  return false;
27666
27587
  }