wildcrane 0.11.23 → 0.11.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/kanban.mjs +1379 -824
  2. package/package.json +1 -1
package/dist/kanban.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // ai4kanban 0.11.23 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
2
+ // ai4kanban 0.11.24 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
3
3
  // Do not edit: every change belongs in cli/src/, and a build overwrites this file.
4
4
  import { createRequire as __ai4kanbanRequire } from 'node:module'
5
5
  const require = __ai4kanbanRequire(import.meta.url)
@@ -1994,8 +1994,8 @@ var require_command = __commonJS({
1994
1994
  "node_modules/commander/lib/command.js"(exports) {
1995
1995
  var EventEmitter = __require("node:events").EventEmitter;
1996
1996
  var childProcess = __require("node:child_process");
1997
- var path87 = __require("node:path");
1998
- var fs88 = __require("node:fs");
1997
+ var path90 = __require("node:path");
1998
+ var fs91 = __require("node:fs");
1999
1999
  var process2 = __require("node:process");
2000
2000
  var { Argument: Argument2, humanReadableArgName } = require_argument();
2001
2001
  var { CommanderError: CommanderError2 } = require_error();
@@ -2976,7 +2976,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2976
2976
  * @param {string} subcommandName
2977
2977
  */
2978
2978
  _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
2979
- if (fs88.existsSync(executableFile)) return;
2979
+ if (fs91.existsSync(executableFile)) return;
2980
2980
  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";
2981
2981
  const executableMissing = `'${executableFile}' does not exist
2982
2982
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
@@ -2994,11 +2994,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2994
2994
  let launchWithNode = false;
2995
2995
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
2996
2996
  function findFile(baseDir, baseName) {
2997
- const localBin = path87.resolve(baseDir, baseName);
2998
- if (fs88.existsSync(localBin)) return localBin;
2999
- if (sourceExt.includes(path87.extname(baseName))) return void 0;
2997
+ const localBin = path90.resolve(baseDir, baseName);
2998
+ if (fs91.existsSync(localBin)) return localBin;
2999
+ if (sourceExt.includes(path90.extname(baseName))) return void 0;
3000
3000
  const foundExt = sourceExt.find(
3001
- (ext) => fs88.existsSync(`${localBin}${ext}`)
3001
+ (ext) => fs91.existsSync(`${localBin}${ext}`)
3002
3002
  );
3003
3003
  if (foundExt) return `${localBin}${foundExt}`;
3004
3004
  return void 0;
@@ -3010,21 +3010,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
3010
3010
  if (this._scriptPath) {
3011
3011
  let resolvedScriptPath;
3012
3012
  try {
3013
- resolvedScriptPath = fs88.realpathSync(this._scriptPath);
3013
+ resolvedScriptPath = fs91.realpathSync(this._scriptPath);
3014
3014
  } catch {
3015
3015
  resolvedScriptPath = this._scriptPath;
3016
3016
  }
3017
- executableDir = path87.resolve(
3018
- path87.dirname(resolvedScriptPath),
3017
+ executableDir = path90.resolve(
3018
+ path90.dirname(resolvedScriptPath),
3019
3019
  executableDir
3020
3020
  );
3021
3021
  }
3022
3022
  if (executableDir) {
3023
3023
  let localFile = findFile(executableDir, executableFile);
3024
3024
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
3025
- const legacyName = path87.basename(
3025
+ const legacyName = path90.basename(
3026
3026
  this._scriptPath,
3027
- path87.extname(this._scriptPath)
3027
+ path90.extname(this._scriptPath)
3028
3028
  );
3029
3029
  if (legacyName !== this._name) {
3030
3030
  localFile = findFile(
@@ -3035,7 +3035,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3035
3035
  }
3036
3036
  executableFile = localFile || executableFile;
3037
3037
  }
3038
- launchWithNode = sourceExt.includes(path87.extname(executableFile));
3038
+ launchWithNode = sourceExt.includes(path90.extname(executableFile));
3039
3039
  let proc;
3040
3040
  if (process2.platform !== "win32") {
3041
3041
  if (launchWithNode) {
@@ -3882,7 +3882,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3882
3882
  * @return {Command}
3883
3883
  */
3884
3884
  nameFromFilename(filename) {
3885
- this._name = path87.basename(filename, path87.extname(filename));
3885
+ this._name = path90.basename(filename, path90.extname(filename));
3886
3886
  return this;
3887
3887
  }
3888
3888
  /**
@@ -3896,9 +3896,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3896
3896
  * @param {string} [path]
3897
3897
  * @return {(string|null|Command)}
3898
3898
  */
3899
- executableDir(path88) {
3900
- if (path88 === void 0) return this._executableDir;
3901
- this._executableDir = path88;
3899
+ executableDir(path91) {
3900
+ if (path91 === void 0) return this._executableDir;
3901
+ this._executableDir = path91;
3902
3902
  return this;
3903
3903
  }
3904
3904
  /**
@@ -4843,7 +4843,7 @@ function moveSignal(from, into, fields) {
4843
4843
  function dismissInboxItems(sourceIds, by, reason = "") {
4844
4844
  const waiting = bySource(readInbox());
4845
4845
  const ignored = bySource(readAllDismissed());
4846
- const why = reason.trim();
4846
+ const why2 = reason.trim();
4847
4847
  return [...new Set(sourceIds)].map((sourceId) => {
4848
4848
  const missing = { sourceId, ok: false, error: `nothing waiting in triage is ${sourceId}` };
4849
4849
  const found2 = waiting.get(sourceId);
@@ -4853,7 +4853,7 @@ function dismissInboxItems(sourceIds, by, reason = "") {
4853
4853
  const at2 = moveSignal(path11.join(TRIAGE, path11.basename(found2.relPath)), SIGNALS_DISMISSED, {
4854
4854
  dismissed_at: formatStamp(/* @__PURE__ */ new Date()),
4855
4855
  dismissed_by: by,
4856
- ...why ? { dismissed_reason: why } : {}
4856
+ ...why2 ? { dismissed_reason: why2 } : {}
4857
4857
  });
4858
4858
  return at2 ? { sourceId, ok: true, relPath: at2 } : missing;
4859
4859
  });
@@ -5759,7 +5759,7 @@ var init_package = __esm({
5759
5759
  "package.json"() {
5760
5760
  package_default = {
5761
5761
  name: "wildcrane",
5762
- version: "0.11.23",
5762
+ version: "0.11.24",
5763
5763
  akbContract: 7,
5764
5764
  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.",
5765
5765
  keywords: [
@@ -6344,14 +6344,14 @@ function currentTurn() {
6344
6344
  function forgetFileMemos() {
6345
6345
  turn++;
6346
6346
  }
6347
- function memoByFiles(paths, read4) {
6347
+ function memoByFiles(paths, read5) {
6348
6348
  let last = null;
6349
6349
  return () => {
6350
6350
  const now = currentTurn();
6351
6351
  if (last?.turn !== now) {
6352
6352
  const seen = stamp3(paths());
6353
6353
  if (last?.stamp === seen) last.turn = now;
6354
- else last = { stamp: seen, turn: now, value: read4() };
6354
+ else last = { stamp: seen, turn: now, value: read5() };
6355
6355
  }
6356
6356
  return copy(last.value);
6357
6357
  };
@@ -6367,15 +6367,15 @@ var init_file_memo = __esm({
6367
6367
  });
6368
6368
 
6369
6369
  // ../cloud/src/board-files.ts
6370
- function isBoardPath(path87) {
6371
- if (!path87 || path87.length > 500 || path87.startsWith("/") || path87.includes("\\") || path87.includes("\0")) return false;
6372
- if (path87.split("/").some((part) => !part || part === "." || part === "..")) return false;
6373
- if (path87 === "todo/README.md" || path87.split("/").includes(".sync")) return false;
6374
- if (path87.startsWith("workflows/")) return true;
6375
- if (SETTINGS.includes(path87)) return true;
6376
- if (path87.startsWith("rules/")) return isSettingsPath(path87);
6377
- if (path87.startsWith("assets/")) return path87.endsWith(".json");
6378
- return ROOTS.some((root2) => path87.startsWith(root2)) && path87.endsWith(".md");
6370
+ function isBoardPath(path90) {
6371
+ if (!path90 || path90.length > 500 || path90.startsWith("/") || path90.includes("\\") || path90.includes("\0")) return false;
6372
+ if (path90.split("/").some((part) => !part || part === "." || part === "..")) return false;
6373
+ if (path90 === "todo/README.md" || path90.split("/").includes(".sync")) return false;
6374
+ if (path90.startsWith("workflows/")) return true;
6375
+ if (SETTINGS.includes(path90)) return true;
6376
+ if (path90.startsWith("rules/")) return isSettingsPath(path90);
6377
+ if (path90.startsWith("assets/")) return path90.endsWith(".json");
6378
+ return ROOTS.some((root2) => path90.startsWith(root2)) && path90.endsWith(".md");
6379
6379
  }
6380
6380
  var ROOTS, SETTINGS, isSettingsPath, BOARD_FILE_LIMIT, cardSlug, workflowFolder, workflowName, draftFolder;
6381
6381
  var init_board_files = __esm({
@@ -6383,7 +6383,7 @@ var init_board_files = __esm({
6383
6383
  "use strict";
6384
6384
  ROOTS = ["todo/", ".archive/", "memory/", "workflows/", "triage/", "assets/", "rules/"];
6385
6385
  SETTINGS = ["modules.md", "config.md"];
6386
- isSettingsPath = (path87) => SETTINGS.includes(path87) || /^rules\/(?:workflows\/)?[^/]+\.md$/.test(path87);
6386
+ isSettingsPath = (path90) => SETTINGS.includes(path90) || /^rules\/(?:workflows\/)?[^/]+\.md$/.test(path90);
6387
6387
  BOARD_FILE_LIMIT = 256 * 1024;
6388
6388
  cardSlug = (task) => task.toLowerCase().replace(/_/g, "-");
6389
6389
  workflowFolder = (id) => id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
@@ -6392,6 +6392,93 @@ var init_board_files = __esm({
6392
6392
  }
6393
6393
  });
6394
6394
 
6395
+ // src/lib/agents/icon.ts
6396
+ function readIcon(raw) {
6397
+ if (raw === void 0 || raw === "") return void 0;
6398
+ if (typeof raw === "string") return ICON_NAMES.includes(raw.trim()) ? raw.trim() : { problem: `"${raw}" is not a glyph name` };
6399
+ if (!Array.isArray(raw) || !raw.length || raw.length > 12) return { problem: "the value is neither a glyph name nor a list of 1 to 12 parts" };
6400
+ const parts = [];
6401
+ for (const [i, item] of raw.entries()) {
6402
+ const at2 = `part ${i + 1}`;
6403
+ if (!item || typeof item !== "object" || Array.isArray(item)) return { problem: `${at2} is not a map of \`d\`, \`f\`, \`o\`, \`s\`, \`w\`` };
6404
+ const { d: d2, f: f2, o: o3, s, w: w2, ...extra } = item;
6405
+ if (Object.keys(extra).length) return { problem: `${at2} has \`${Object.keys(extra).join("`, `")}\`` };
6406
+ if (typeof d2 !== "string" || !PATH.test(d2)) return { problem: `${at2} has no \`d\` of SVG path commands and numbers` };
6407
+ const part = { d: d2.trim() };
6408
+ for (const [key, value] of [["f", f2], ["s", s]]) {
6409
+ if (value === void 0) continue;
6410
+ if (typeof value !== "string" || !isColor(value)) return { problem: `${at2} colours \`${key}\` with "${String(value)}"` };
6411
+ part[key] = value;
6412
+ }
6413
+ if (o3 !== void 0) {
6414
+ if (o3 !== "true") return { problem: `${at2} has \`o: ${String(o3)}\`, not \`true\`` };
6415
+ part.o = true;
6416
+ }
6417
+ if (w2 !== void 0) {
6418
+ const width = typeof w2 === "string" ? Number(w2) : NaN;
6419
+ if (!(width > 0 && width <= 3)) return { problem: `${at2} has \`w: ${String(w2)}\`, not above 0 and up to 3` };
6420
+ part.w = width;
6421
+ }
6422
+ parts.push(part);
6423
+ }
6424
+ return parts;
6425
+ }
6426
+ var ICON_NAMES, ICON_COLORS, PATH, isColor;
6427
+ var init_icon = __esm({
6428
+ "src/lib/agents/icon.ts"() {
6429
+ "use strict";
6430
+ ICON_NAMES = [
6431
+ "file",
6432
+ "text",
6433
+ "article",
6434
+ "outline",
6435
+ "script",
6436
+ "prompt",
6437
+ "email",
6438
+ "image",
6439
+ "post-image",
6440
+ "social-image",
6441
+ "cover",
6442
+ "carousel",
6443
+ "carousel-outline",
6444
+ "slides",
6445
+ "wireframe",
6446
+ "screen",
6447
+ "video",
6448
+ "storyboard",
6449
+ "template",
6450
+ "shots",
6451
+ "api",
6452
+ "schema",
6453
+ "compare",
6454
+ "stack",
6455
+ "workflow",
6456
+ "code",
6457
+ "checklist",
6458
+ "card",
6459
+ "plan",
6460
+ "proposal",
6461
+ "dismissed",
6462
+ "inbox",
6463
+ "notebook",
6464
+ "squeeze",
6465
+ "folder",
6466
+ "reply",
6467
+ "feedback",
6468
+ "software",
6469
+ "product-video",
6470
+ "social-post",
6471
+ "blog",
6472
+ "deck",
6473
+ "video-clone",
6474
+ "workflow-kit"
6475
+ ];
6476
+ ICON_COLORS = ["k", "w", "c", "g", "o", "p", "s", "m", "l", "r", "y"];
6477
+ PATH = /^[MmLlHhVvCcSsQqTtAaZz0-9.,\s-]+$/;
6478
+ isColor = (v) => ICON_COLORS.includes(v);
6479
+ }
6480
+ });
6481
+
6395
6482
  // src/lib/agents/yaml.ts
6396
6483
  function stripComment(value) {
6397
6484
  let from = 0;
@@ -6506,8 +6593,8 @@ var init_yaml2 = __esm({
6506
6593
  // src/lib/agents/parse.ts
6507
6594
  function parseSpecAgent(text5, from, file, builtIn = false, list = () => []) {
6508
6595
  let named2 = "";
6509
- const bad = (why, old2) => ({
6510
- problem: `${from}: ${why}`,
6596
+ const bad = (why2, old2) => ({
6597
+ problem: `${from}: ${why2}`,
6511
6598
  ...named2 ? { name: named2 } : {},
6512
6599
  ...old2 ? { old: old2 } : {}
6513
6600
  });
@@ -6542,6 +6629,12 @@ function parseSpecAgent(text5, from, file, builtIn = false, list = () => []) {
6542
6629
  if (!Array.isArray(components) || components.some((value) => typeof value !== "string" || !value.trim())) {
6543
6630
  return bad(`\`${name}\` declares \`akb.components\` that is not a list of component IDs`);
6544
6631
  }
6632
+ const icon = readIcon(akb.icon);
6633
+ if (icon && typeof icon === "object" && "problem" in icon) {
6634
+ return bad(
6635
+ `\`${name}\` declares an \`akb.icon\` where ${icon.problem} \u2014 use one of ${ICON_NAMES.join(", ")}, or 1 to 12 parts \`{ d, f?, o?: true, s?, w? }\` coloured with ${ICON_COLORS.join(", ")}`
6636
+ );
6637
+ }
6545
6638
  const workspace = memoryPaths(akb.memoryFiles);
6546
6639
  if (typeof workspace === "string") return bad(`\`${name}\` declares ${workspace}`);
6547
6640
  const instructions = body.trim();
@@ -6553,6 +6646,7 @@ function parseSpecAgent(text5, from, file, builtIn = false, list = () => []) {
6553
6646
  ...when ? { when } : {},
6554
6647
  after: after2,
6555
6648
  components: [...new Set(components.map((value) => value.trim()))],
6649
+ ...icon ? { icon } : {},
6556
6650
  i18n: readTranslations(akb.i18n),
6557
6651
  ...declaredReads ? { reads: declaredReads } : {},
6558
6652
  ...declaredSession ? { session: "new" } : {},
@@ -6601,6 +6695,7 @@ var OLD_ROLE_KEYS, AGENT_NAME, SCHEDULE_READS, isScheduleReads, names, str, map;
6601
6695
  var init_parse = __esm({
6602
6696
  "src/lib/agents/parse.ts"() {
6603
6697
  "use strict";
6698
+ init_icon();
6604
6699
  init_yaml2();
6605
6700
  OLD_ROLE_KEYS = ["lead", "hook", "stage", "kind"];
6606
6701
  AGENT_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
@@ -6654,6 +6749,12 @@ function parseWorkflowFile(id, source, from) {
6654
6749
  problem: `${from}: \`${old.join("`, `")}\` ${old.length > 1 ? "are" : "is"} no longer read \u2014 list the agents under \`previews\`, \`land\` and \`scheduled\` instead (\`akb guide write-agent\`), or ask the Workflow builder to rewrite it`
6655
6750
  };
6656
6751
  }
6752
+ const icon = readIcon(raw.icon);
6753
+ if (icon && typeof icon === "object" && "problem" in icon) {
6754
+ return {
6755
+ problem: `${from}: its \`icon\` is wrong \u2014 ${icon.problem}; use one of ${ICON_NAMES.join(", ")}, or 1 to 12 parts \`{ d, f?, o?: true, s?, w? }\` coloured with ${ICON_COLORS.join(", ")}`
6756
+ };
6757
+ }
6657
6758
  const previews = readPreviews(raw.previews);
6658
6759
  if (typeof previews === "string") return { problem: `${from}: ${previews}` };
6659
6760
  const land = readGroup(raw.land);
@@ -6678,6 +6779,7 @@ function parseWorkflowFile(id, source, from) {
6678
6779
  description: text(raw.description),
6679
6780
  when: text(raw.when),
6680
6781
  needsArtifact: text(raw.needsArtifact) === "true",
6782
+ ...icon ? { icon } : {},
6681
6783
  previews,
6682
6784
  land,
6683
6785
  scheduled,
@@ -6689,6 +6791,7 @@ var WORKFLOW_ID, OLD_KEYS, box, text, readGroup;
6689
6791
  var init_workflow_def = __esm({
6690
6792
  "src/lib/agent/workflow-def.ts"() {
6691
6793
  "use strict";
6794
+ init_icon();
6692
6795
  init_yaml2();
6693
6796
  init_spec_agent_names();
6694
6797
  WORKFLOW_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
@@ -6699,6 +6802,36 @@ var init_workflow_def = __esm({
6699
6802
  }
6700
6803
  });
6701
6804
 
6805
+ // src/lib/agent/workflow-diagram.ts
6806
+ function workflowDiagram(def, agentOf3) {
6807
+ const step = (name) => {
6808
+ const agent = ROLES[name] ? null : agentOf3(name);
6809
+ const en2 = agent?.i18n.en?.title || name;
6810
+ return {
6811
+ agent: name,
6812
+ title: ROLES[name] ?? { en: en2, zh: agent?.i18n.zh?.title || en2 },
6813
+ ...agent?.icon ? { icon: agent.icon } : {},
6814
+ ...agent?.when ? { optional: true } : {}
6815
+ };
6816
+ };
6817
+ const previews = def.previews.filter((h3) => !h3.off).map((h3) => h3.agent);
6818
+ const after2 = (name) => (agentOf3(name)?.after ?? []).filter((other) => previews.includes(other));
6819
+ return {
6820
+ version: 1,
6821
+ rounds: stagesOf(previews, after2).map((round) => round.map(step)),
6822
+ land: def.land.filter((h3) => !h3.off).map((h3) => step(h3.agent)),
6823
+ scheduled: def.scheduled.map((s) => ({ ...step(s.agent), ...s.cadence ? { cadence: s.cadence } : {} }))
6824
+ };
6825
+ }
6826
+ var ROLES;
6827
+ var init_workflow_diagram = __esm({
6828
+ "src/lib/agent/workflow-diagram.ts"() {
6829
+ "use strict";
6830
+ init_workflow_def();
6831
+ ROLES = { builder: { en: "Build and merge", zh: "\u5B9E\u73B0\u5E76\u5408\u5165" } };
6832
+ }
6833
+ });
6834
+
6702
6835
  // ../cloud/src/v1/workflow-files.ts
6703
6836
  function folderPath(file, top) {
6704
6837
  const parts = file.split("/");
@@ -6707,13 +6840,13 @@ function folderPath(file, top) {
6707
6840
  return [parts[1], parts.slice(2).join("/")];
6708
6841
  }
6709
6842
  function mcpProblem(text5) {
6710
- let read4;
6843
+ let read5;
6711
6844
  try {
6712
- read4 = JSON.parse(text5);
6845
+ read5 = JSON.parse(text5);
6713
6846
  } catch {
6714
6847
  return "is not JSON";
6715
6848
  }
6716
- const servers = read4?.mcpServers;
6849
+ const servers = read5?.mcpServers;
6717
6850
  if (!servers || typeof servers !== "object" || Array.isArray(servers)) return "must hold `mcpServers`, an object of name \u2192 server";
6718
6851
  for (const [name, server] of Object.entries(servers)) {
6719
6852
  const { command, args, ...rest } = server ?? {};
@@ -6760,9 +6893,9 @@ function checkWorkflowFiles(value, official = false) {
6760
6893
  }
6761
6894
  const source = value[WORKFLOW_FILE];
6762
6895
  if (source === void 0) return fail(WORKFLOW_FILE, "is missing");
6763
- const read4 = parseWorkflowFile("workflow", source, WORKFLOW_FILE);
6764
- if ("problem" in read4) return fail(WORKFLOW_FILE, read4.problem.replace(`${WORKFLOW_FILE}: `, ""));
6765
- const def = read4.def;
6896
+ const read5 = parseWorkflowFile("workflow", source, WORKFLOW_FILE);
6897
+ if ("problem" in read5) return fail(WORKFLOW_FILE, read5.problem.replace(`${WORKFLOW_FILE}: `, ""));
6898
+ const def = read5.def;
6766
6899
  const agents = /* @__PURE__ */ new Map();
6767
6900
  for (const [name, own] of folders2) {
6768
6901
  const from = `agents/${name}/AGENT.md`;
@@ -6778,8 +6911,8 @@ function checkWorkflowFiles(value, official = false) {
6778
6911
  ...def.land.filter((h3) => !LAND_ROLES.includes(h3.agent)).map((h3) => [h3.agent, "it lands with"]),
6779
6912
  ...def.scheduled.map((s) => [s.agent, "it schedules"])
6780
6913
  ];
6781
- for (const [name, why] of named2) {
6782
- if (!agents.has(name)) return fail(WORKFLOW_FILE, `${why} \`${name}\`, which has no agents/${name}/AGENT.md`);
6914
+ for (const [name, why2] of named2) {
6915
+ if (!agents.has(name)) return fail(WORKFLOW_FILE, `${why2} \`${name}\`, which has no agents/${name}/AGENT.md`);
6783
6916
  }
6784
6917
  return { ok: true, def, files: value };
6785
6918
  }
@@ -6789,6 +6922,7 @@ var init_workflow_files = __esm({
6789
6922
  "use strict";
6790
6923
  init_workflow_def();
6791
6924
  init_parse();
6925
+ init_workflow_diagram();
6792
6926
  WORKFLOW_FILE = "WORKFLOW.md";
6793
6927
  MCP_FILE = "mcp.json";
6794
6928
  KB = 1024;
@@ -6818,8 +6952,8 @@ function packOfficial(root2 = OFFICIAL, loose = false) {
6818
6952
  return [name, Object.fromEntries(filesOf(dir).sort().map((f2) => [f2, fs20.readFileSync(path21.join(dir, f2), "utf8")]))];
6819
6953
  }));
6820
6954
  for (const [name, own] of Object.entries(loose ? {} : agentFiles)) {
6821
- const read4 = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p2) => own[p2] ?? null, true);
6822
- if ("problem" in read4) throw new Error(read4.problem);
6955
+ const read5 = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p2) => own[p2] ?? null, true);
6956
+ if ("problem" in read5) throw new Error(read5.problem);
6823
6957
  }
6824
6958
  const workflowsDir = path21.join(root2, "workflows");
6825
6959
  return dirs(workflowsDir).map((folder) => {
@@ -6828,10 +6962,10 @@ function packOfficial(root2 = OFFICIAL, loose = false) {
6828
6962
  for (const f2 of filesOf(dir).sort()) {
6829
6963
  if (f2 === WORKFLOW_FILE || f2 === MCP_FILE || f2.startsWith("skills/")) files2[f2] = fs20.readFileSync(path21.join(dir, f2), "utf8");
6830
6964
  }
6831
- const read4 = checkWorkflowFiles({ [WORKFLOW_FILE]: files2[WORKFLOW_FILE], ...Object.fromEntries(
6965
+ const read5 = checkWorkflowFiles({ [WORKFLOW_FILE]: files2[WORKFLOW_FILE], ...Object.fromEntries(
6832
6966
  Object.entries(agentFiles).flatMap(([name, own]) => Object.entries(own).map(([f2, t]) => [`agents/${name}/${f2}`, t]))
6833
6967
  ) });
6834
- if (!read4.ok && !loose) throw new Error(`official/workflows/${folder}: ${read4.file}: ${read4.reason}`);
6968
+ if (!read5.ok && !loose) throw new Error(`official/workflows/${folder}: ${read5.file}: ${read5.reason}`);
6835
6969
  const parsed = parseWorkflowFile(folder, files2[WORKFLOW_FILE] ?? "", WORKFLOW_FILE);
6836
6970
  if ("problem" in parsed) throw new Error(parsed.problem);
6837
6971
  const def = parsed.def;
@@ -6904,18 +7038,18 @@ function pinMissing() {
6904
7038
  async function versionOf(id, version) {
6905
7039
  const held4 = readVersion(id, version);
6906
7040
  if (held4) return { ok: true, value: held4 };
6907
- const read4 = await call("GET", `/v1/workflows/${encodeURIComponent(id)}`);
6908
- if (!read4.ok) return read4;
6909
- saveVersion(read4.value);
6910
- return read4;
7041
+ const read5 = await call("GET", `/v1/workflows/${encodeURIComponent(id)}`);
7042
+ if (!read5.ok) return read5;
7043
+ saveVersion(read5.value);
7044
+ return read5;
6911
7045
  }
6912
7046
  async function pinTask(task) {
6913
7047
  const pin = readPin(task);
6914
7048
  const held4 = pin && readVersion(pin.workflow, pin.version);
6915
7049
  if (held4) return { ok: true, value: held4 };
6916
- const read4 = await call("GET", `/v1/tasks/${encodeURIComponent(task)}/workflow`);
6917
- if (!read4.ok) return read4;
6918
- const value = { id: read4.value.workflow, version: read4.value.version, name: read4.value.name, files: read4.value.files };
7050
+ const read5 = await call("GET", `/v1/tasks/${encodeURIComponent(task)}/workflow`);
7051
+ if (!read5.ok) return read5;
7052
+ const value = { id: read5.value.workflow, version: read5.value.version, name: read5.value.name, files: read5.value.files };
6919
7053
  savePin(task, value);
6920
7054
  return { ok: true, value };
6921
7055
  }
@@ -6934,12 +7068,12 @@ async function syncWorkflows(force = false) {
6934
7068
  if (fresh && !force) return;
6935
7069
  let workspace = held4?.workspace;
6936
7070
  if (!workspace) {
6937
- const read4 = await call("GET", `/v1/projects/${encodeURIComponent(project)}`);
6938
- if (!read4.ok) {
6939
- offline = !read4.code;
7071
+ const read5 = await call("GET", `/v1/projects/${encodeURIComponent(project)}`);
7072
+ if (!read5.ok) {
7073
+ offline = !read5.code;
6940
7074
  return;
6941
7075
  }
6942
- workspace = read4.value.workspace;
7076
+ workspace = read5.value.workspace;
6943
7077
  }
6944
7078
  const listed = [];
6945
7079
  let after2 = null;
@@ -6957,9 +7091,9 @@ async function syncWorkflows(force = false) {
6957
7091
  } while (after2);
6958
7092
  const kept2 = [];
6959
7093
  for (const w2 of listed) {
6960
- const read4 = await versionOf(w2.id, w2.version);
6961
- if (read4.ok) kept2.push({ id: read4.value.id, version: read4.value.version });
6962
- else if (!read4.code) offline = true;
7094
+ const read5 = await versionOf(w2.id, w2.version);
7095
+ if (read5.ok) kept2.push({ id: read5.value.id, version: read5.value.version });
7096
+ else if (!read5.code) offline = true;
6963
7097
  }
6964
7098
  writeJson(listFile(project), { at: (/* @__PURE__ */ new Date()).toISOString(), workspace, workflows: kept2 });
6965
7099
  } catch {
@@ -7032,9 +7166,9 @@ var init_cloud_workflows = __esm({
7032
7166
  workflowsOffline = () => offline;
7033
7167
  flowOf = (held4) => {
7034
7168
  const id = workflowName(held4.id);
7035
- const read4 = parseWorkflowFile(id, held4.files["WORKFLOW.md"] ?? "", `the \`${id}\` workflow`);
7036
- if ("problem" in read4) return null;
7037
- return { def: read4.def, cloudId: held4.id, version: held4.version, builtIn: held4.id.startsWith("wf_builtin_"), files: held4.files };
7169
+ const read5 = parseWorkflowFile(id, held4.files["WORKFLOW.md"] ?? "", `the \`${id}\` workflow`);
7170
+ if ("problem" in read5) return null;
7171
+ return { def: read5.def, cloudId: held4.id, version: held4.version, builtIn: held4.id.startsWith("wf_builtin_"), files: held4.files };
7038
7172
  };
7039
7173
  sources = () => {
7040
7174
  if (devFolder()) return [devFolder()];
@@ -7066,16 +7200,16 @@ function readCatalog() {
7066
7200
  const agents = [];
7067
7201
  const problems = [];
7068
7202
  const refused = [];
7069
- const take = (read4, folder) => {
7070
- if ("problem" in read4) {
7071
- if (!read4.missing) problems.push(read4.problem);
7072
- if (!read4.file) return;
7073
- const { file, name: name2, old } = read4;
7074
- const cause = read4.missing ? "noFile" : old ? "oldKeys" : "file";
7203
+ const take = (read5, folder) => {
7204
+ if ("problem" in read5) {
7205
+ if (!read5.missing) problems.push(read5.problem);
7206
+ if (!read5.file) return;
7207
+ const { file, name: name2, old } = read5;
7208
+ const cause = read5.missing ? "noFile" : old ? "oldKeys" : "file";
7075
7209
  refused.push({ folder, file, cause, ...name2 ? { name: name2 } : {}, ...old ? { keys: old.keys } : {} });
7076
7210
  return;
7077
7211
  }
7078
- const { name, from, builtIn } = read4.agent;
7212
+ const { name, from, builtIn } = read5.agent;
7079
7213
  const refuse3 = (cause, problem) => {
7080
7214
  problems.push(problem);
7081
7215
  if (!builtIn) refused.push({ folder, name, file: from, cause });
@@ -7099,14 +7233,14 @@ function readCatalog() {
7099
7233
  `${from}: its folder is \`${folder}\` but it calls itself \`${name}\`. An agent is asked for by its folder name \u2014 make the two match.`
7100
7234
  );
7101
7235
  }
7102
- agents.push(read4.agent);
7236
+ agents.push(read5.agent);
7103
7237
  };
7104
7238
  for (const folder of bundledFolders()) take(readBundled(folder), folder);
7105
7239
  for (const folder of projectFolders(AGENTS)) {
7106
- const read4 = readProject(AGENTS, folder);
7107
- take(read4, folder);
7108
- if ("agent" in read4 && read4.agent.from.endsWith(LEGACY_AGENT_FILE)) {
7109
- problems.push(`${read4.agent.from}: rename it to ${AGENT_FILE}`);
7240
+ const read5 = readProject(AGENTS, folder);
7241
+ take(read5, folder);
7242
+ if ("agent" in read5 && read5.agent.from.endsWith(LEGACY_AGENT_FILE)) {
7243
+ problems.push(`${read5.agent.from}: rename it to ${AGENT_FILE}`);
7110
7244
  }
7111
7245
  }
7112
7246
  for (const folder of projectFolders(LEGACY_AGENTS)) {
@@ -7211,10 +7345,10 @@ function readProject(root2, folder) {
7211
7345
  const missing = rel(path23.join(dir, AGENT_FILE));
7212
7346
  if (!found2) return { problem: `${missing} is missing`, file: missing, missing: true };
7213
7347
  const from = rel(path23.join(dir, found2.name));
7214
- const read4 = parseSpecAgent(found2.text, from, file, false, () => ownFiles(walkFolder(dir, "")));
7215
- if ("problem" in read4) return { ...read4, file: from };
7216
- if ("agent" in read4) Object.assign(read4.agent, { dir, text: found2.text });
7217
- return read4;
7348
+ const read5 = parseSpecAgent(found2.text, from, file, false, () => ownFiles(walkFolder(dir, "")));
7349
+ if ("problem" in read5) return { ...read5, file: from };
7350
+ if ("agent" in read5) Object.assign(read5.agent, { dir, text: found2.text });
7351
+ return read5;
7218
7352
  }
7219
7353
  var specAgentCatalog, bundledFolders, AGENT_FILE, LEGACY_AGENT_FILE, AGENT_FILES, ownFiles;
7220
7354
  var init_catalog2 = __esm({
@@ -8256,10 +8390,10 @@ function findRollout(threadId) {
8256
8390
  }
8257
8391
  for (const name of names3) {
8258
8392
  if (!name.startsWith("rollout-") || !name.endsWith(tail2)) continue;
8259
- const path87 = join(dir, name);
8393
+ const path90 = join(dir, name);
8260
8394
  try {
8261
- const at2 = statSync(path87).mtimeMs;
8262
- if (!newest2 || at2 > newest2.at) newest2 = { path: path87, at: at2 };
8395
+ const at2 = statSync(path90).mtimeMs;
8396
+ if (!newest2 || at2 > newest2.at) newest2 = { path: path90, at: at2 };
8263
8397
  } catch {
8264
8398
  }
8265
8399
  }
@@ -8267,11 +8401,11 @@ function findRollout(threadId) {
8267
8401
  return newest2?.path;
8268
8402
  }
8269
8403
  function readCodexRunFacts(threadId) {
8270
- const path87 = findRollout(threadId);
8271
- if (!path87) return void 0;
8404
+ const path90 = findRollout(threadId);
8405
+ if (!path90) return void 0;
8272
8406
  let raw;
8273
8407
  try {
8274
- raw = readFileSync(path87, "utf8");
8408
+ raw = readFileSync(path90, "utf8");
8275
8409
  } catch {
8276
8410
  return void 0;
8277
8411
  }
@@ -8399,8 +8533,8 @@ function renderCompleted(item) {
8399
8533
  const changes = Array.isArray(item.changes) ? item.changes : [];
8400
8534
  return changes.map((raw) => {
8401
8535
  const change2 = obj(raw);
8402
- const path87 = str2(change2.path);
8403
- return path87 ? `\u23FA ${str2(change2.kind) || "change"}(${path87})
8536
+ const path90 = str2(change2.path);
8537
+ return path90 ? `\u23FA ${str2(change2.kind) || "change"}(${path90})
8404
8538
  ` : "";
8405
8539
  }).join("");
8406
8540
  }
@@ -8662,10 +8796,10 @@ function readKimiRunFacts(sessionId) {
8662
8796
  const total = { input: 0, cacheCreation: 0, cacheRead: 0, output: 0 };
8663
8797
  let model;
8664
8798
  let holding = 0;
8665
- for (const { path: path87, main } of wireFiles(entry.sessionDir)) {
8799
+ for (const { path: path90, main } of wireFiles(entry.sessionDir)) {
8666
8800
  let raw;
8667
8801
  try {
8668
- raw = readFileSync2(path87, "utf8");
8802
+ raw = readFileSync2(path90, "utf8");
8669
8803
  } catch {
8670
8804
  continue;
8671
8805
  }
@@ -8728,9 +8862,9 @@ function toolCalls(row) {
8728
8862
  }).join("");
8729
8863
  }
8730
8864
  function retry(row) {
8731
- const why = str2(row.error_message) || str2(row.error_name) || "the provider failed";
8865
+ const why2 = str2(row.error_message) || str2(row.error_name) || "the provider failed";
8732
8866
  const attempt2 = `${num(row.next_attempt)}/${num(row.max_attempts)}`;
8733
- return `[retry ${attempt2}] ${why}
8867
+ return `[retry ${attempt2}] ${why2}
8734
8868
  `;
8735
8869
  }
8736
8870
  function createKimiStreamRenderer(cwd) {
@@ -8819,10 +8953,10 @@ function connect(stdout, stdin, onCall, dialect = {}) {
8819
8953
  } catch {
8820
8954
  }
8821
8955
  };
8822
- const closed2 = (why) => {
8956
+ const closed2 = (why2) => {
8823
8957
  if (gone) return;
8824
- gone = why;
8825
- for (const { fail } of waiting.values()) fail(new Error(why));
8958
+ gone = why2;
8959
+ for (const { fail } of waiting.values()) fail(new Error(why2));
8826
8960
  waiting.clear();
8827
8961
  };
8828
8962
  stdout.on("data", (chunk) => {
@@ -8946,8 +9080,8 @@ var init_tail = __esm({
8946
9080
  import fs28 from "node:fs";
8947
9081
  function whereHint(update2, title) {
8948
9082
  const locations = Array.isArray(update2.locations) ? update2.locations : [];
8949
- const path87 = str2(obj(locations[0]).path);
8950
- return path87 && !title.includes(path87) ? hint(path87) : "";
9083
+ const path90 = str2(obj(locations[0]).path);
9084
+ return path90 && !title.includes(path90) ? hint(path90) : "";
8951
9085
  }
8952
9086
  function saidBy(update2) {
8953
9087
  const content = Array.isArray(update2.content) ? update2.content : [];
@@ -9112,12 +9246,12 @@ async function oneTurn(io, options) {
9112
9246
  const usage3 = usageOf2(done2.usage) ?? usageOf2(spent, true);
9113
9247
  costUsd ??= ticksUsd(spent.costUsdTicks);
9114
9248
  if (stopReason2 && stopReason2 !== "end_turn") {
9115
- const why = STOPPED[stopReason2] ?? `the agent stopped: ${stopReason2}`;
9116
- io.log(`[error] ${why}
9249
+ const why2 = STOPPED[stopReason2] ?? `the agent stopped: ${stopReason2}`;
9250
+ io.log(`[error] ${why2}
9117
9251
  `);
9118
- events.error(why);
9252
+ events.error(why2);
9119
9253
  emit();
9120
- return { ok: false, result, error: why, usage: usage3, context, costUsd };
9254
+ return { ok: false, result, error: why2, usage: usage3, context, costUsd };
9121
9255
  }
9122
9256
  emit();
9123
9257
  return { ok: true, result, usage: usage3, context, costUsd };
@@ -9147,8 +9281,8 @@ function update(raw, tail2, gotCost, gotContext) {
9147
9281
  }
9148
9282
  case "tool_call_update": {
9149
9283
  if (change2.status !== "failed") return;
9150
- const why = saidBy(change2);
9151
- tail2.line(`[error] ${str2(change2.title) || "that tool call"} failed${why ? `: ${why}` : ""}`);
9284
+ const why2 = saidBy(change2);
9285
+ tail2.line(`[error] ${str2(change2.title) || "that tool call"} failed${why2 ? `: ${why2}` : ""}`);
9152
9286
  return;
9153
9287
  }
9154
9288
  case "usage_update": {
@@ -9262,8 +9396,8 @@ function createParts(tail2) {
9262
9396
  tail2.line(`\u23FA ${title}${whereHint2(state.input, title)}`);
9263
9397
  }
9264
9398
  if (str2(state.status) === "error") {
9265
- const why = str2(state.error).trim();
9266
- tail2.line(`[error] ${title} failed${why ? `: ${why}` : ""}`);
9399
+ const why2 = str2(state.error).trim();
9400
+ tail2.line(`[error] ${title} failed${why2 ? `: ${why2}` : ""}`);
9267
9401
  }
9268
9402
  },
9269
9403
  /** A piece of one part, as `part.delta` sends it. */
@@ -9296,18 +9430,18 @@ function createParts(tail2) {
9296
9430
  toolUpdate(payload) {
9297
9431
  if (str2(payload.kind) !== "error") return;
9298
9432
  const name = named2.get(str2(payload.toolCallId)) ?? "tool";
9299
- const why = str2(obj(payload.error).message).split("\n")[0].trim();
9300
- tail2.line(`[error] ${name} failed${why ? `: ${why.slice(0, 200)}` : ""}`);
9433
+ const why2 = str2(obj(payload.error).message).split("\n")[0].trim();
9434
+ tail2.line(`[error] ${name} failed${why2 ? `: ${why2.slice(0, 200)}` : ""}`);
9301
9435
  }
9302
9436
  };
9303
9437
  }
9304
9438
  function createZcodeClient(options = {}) {
9305
9439
  return { turn: (io) => oneTurn2(io, options) };
9306
9440
  }
9307
- function stopped(io, why) {
9308
- io.log(`[error] ${why}
9441
+ function stopped(io, why2) {
9442
+ io.log(`[error] ${why2}
9309
9443
  `);
9310
- if (MISSING_KEY.test(why)) {
9444
+ if (MISSING_KEY.test(why2)) {
9311
9445
  io.log("[board] paste a Z.AI or BigModel Coding Plan key into ZCode's key box in Configuration.\n");
9312
9446
  }
9313
9447
  }
@@ -9397,9 +9531,9 @@ async function oneTurn2(io, options) {
9397
9531
  const usage3 = done2.usage ?? await tokensOf(rpc, sessionId);
9398
9532
  const context = await contextOf(rpc, sessionId);
9399
9533
  if (!done2.ok) {
9400
- const why = done2.error ?? "the agent stopped without saying why";
9401
- stopped(io, why);
9402
- return { ok: false, result, error: why, usage: usage3, context };
9534
+ const why2 = done2.error ?? "the agent stopped without saying why";
9535
+ stopped(io, why2);
9536
+ return { ok: false, result, error: why2, usage: usage3, context };
9403
9537
  }
9404
9538
  return { ok: true, result, usage: usage3, context };
9405
9539
  } catch (e2) {
@@ -9418,8 +9552,8 @@ async function tokensOf(rpc, sessionId) {
9418
9552
  }
9419
9553
  async function contextOf(rpc, sessionId) {
9420
9554
  try {
9421
- const read4 = await rpc.call("session/read", { sessionId, messageLimit: 1 });
9422
- const state = obj(read4.projection);
9555
+ const read5 = await rpc.call("session/read", { sessionId, messageLimit: 1 });
9556
+ const state = obj(read5.projection);
9423
9557
  const used = num(state.contextUsed);
9424
9558
  const limit = num(state.contextWindow);
9425
9559
  return used > 0 ? { used, limit: limit > 0 ? limit : void 0 } : void 0;
@@ -11135,12 +11269,12 @@ var init_language = __esm({
11135
11269
 
11136
11270
  // src/lib/agent/proxy.ts
11137
11271
  import { execFileSync } from "node:child_process";
11138
- function withSystemProxy(env2 = process.env, platform = process.platform, read4 = () => execFileSync("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 1e3, stdio: ["ignore", "pipe", "ignore"] })) {
11272
+ function withSystemProxy(env2 = process.env, platform = process.platform, read5 = () => execFileSync("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 1e3, stdio: ["ignore", "pipe", "ignore"] })) {
11139
11273
  const out = { ...env2 };
11140
11274
  if (platform !== "darwin" || PROXY_KEYS.some((key) => env2[key] !== void 0)) return out;
11141
11275
  let raw;
11142
11276
  try {
11143
- raw = read4();
11277
+ raw = read5();
11144
11278
  } catch {
11145
11279
  return out;
11146
11280
  }
@@ -11780,12 +11914,12 @@ function readAnswers(raw) {
11780
11914
  if (!Array.isArray(raw)) return void 0;
11781
11915
  const answers2 = raw.flatMap((entry) => {
11782
11916
  if (!entry || entry.outcome !== "changed" && entry.outcome !== "unchanged") return [];
11783
- const why = text3(entry.why);
11784
- if (!why) return [];
11917
+ const why2 = text3(entry.why);
11918
+ if (!why2) return [];
11785
11919
  return [
11786
11920
  {
11787
11921
  outcome: entry.outcome,
11788
- why,
11922
+ why: why2,
11789
11923
  at: typeof entry.at === "number" ? entry.at : 0,
11790
11924
  actedAt: typeof entry.actedAt === "number" ? entry.actedAt : void 0
11791
11925
  }
@@ -12212,12 +12346,12 @@ function writeConfig(change2) {
12212
12346
  try {
12213
12347
  cfg = readConfigRaw();
12214
12348
  } catch (e2) {
12215
- const why = e2 instanceof Error ? e2.message : String(e2);
12349
+ const why2 = e2 instanceof Error ? e2.message : String(e2);
12216
12350
  return {
12217
12351
  ok: false,
12218
- ...refusal("fileParse", `couldn't save: ${UI_CONFIG} won't parse (${why}). Fix the file, then try again.`, {
12352
+ ...refusal("fileParse", `couldn't save: ${UI_CONFIG} won't parse (${why2}). Fix the file, then try again.`, {
12219
12353
  path: UI_CONFIG,
12220
- details: why
12354
+ details: why2
12221
12355
  })
12222
12356
  };
12223
12357
  }
@@ -12228,8 +12362,8 @@ function writeConfig(change2) {
12228
12362
  forgetFileMemos();
12229
12363
  return { ok: true };
12230
12364
  } catch (e2) {
12231
- const why = e2 instanceof Error ? e2.message : String(e2);
12232
- return { ok: false, ...refusal("fileWrite", `couldn't write ${UI_CONFIG}: ${why}`, { path: UI_CONFIG, details: why }) };
12365
+ const why2 = e2 instanceof Error ? e2.message : String(e2);
12366
+ return { ok: false, ...refusal("fileWrite", `couldn't write ${UI_CONFIG}: ${why2}`, { path: UI_CONFIG, details: why2 }) };
12233
12367
  }
12234
12368
  }
12235
12369
  function parseLine(line) {
@@ -12275,12 +12409,12 @@ function ensureIgnored() {
12275
12409
  fs34.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${IGNORE_BLOCK}`);
12276
12410
  return { ok: true };
12277
12411
  } catch (e2) {
12278
- const why = e2 instanceof Error ? e2.message : String(e2);
12412
+ const why2 = e2 instanceof Error ? e2.message : String(e2);
12279
12413
  return {
12280
12414
  ok: false,
12281
- ...refusal("gitignoreWrite", `couldn't write ${KANBAN_GITIGNORE} to keep the key out of git: ${why}`, {
12415
+ ...refusal("gitignoreWrite", `couldn't write ${KANBAN_GITIGNORE} to keep the key out of git: ${why2}`, {
12282
12416
  path: KANBAN_GITIGNORE,
12283
- details: why
12417
+ details: why2
12284
12418
  })
12285
12419
  };
12286
12420
  }
@@ -12292,8 +12426,8 @@ function setSecret(name, value) {
12292
12426
  try {
12293
12427
  lines = fs34.existsSync(ENV_FILE) ? fs34.readFileSync(ENV_FILE, "utf8").split("\n") : [];
12294
12428
  } catch (e2) {
12295
- const why = e2 instanceof Error ? e2.message : String(e2);
12296
- return { ok: false, ...refusal("fileRead", `couldn't read ${ENV_FILE}: ${why}`, { path: ENV_FILE, details: why }) };
12429
+ const why2 = e2 instanceof Error ? e2.message : String(e2);
12430
+ return { ok: false, ...refusal("fileRead", `couldn't read ${ENV_FILE}: ${why2}`, { path: ENV_FILE, details: why2 }) };
12297
12431
  }
12298
12432
  const next = value.trim();
12299
12433
  const kept2 = [];
@@ -12316,8 +12450,8 @@ function setSecret(name, value) {
12316
12450
  fs34.writeFileSync(ENV_FILE, text5, { mode: 384 });
12317
12451
  return { ok: true };
12318
12452
  } catch (e2) {
12319
- const why = e2 instanceof Error ? e2.message : String(e2);
12320
- return { ok: false, ...refusal("fileWrite", `couldn't write ${ENV_FILE}: ${why}`, { path: ENV_FILE, details: why }) };
12453
+ const why2 = e2 instanceof Error ? e2.message : String(e2);
12454
+ return { ok: false, ...refusal("fileWrite", `couldn't write ${ENV_FILE}: ${why2}`, { path: ENV_FILE, details: why2 }) };
12321
12455
  }
12322
12456
  }
12323
12457
  function stampSchedule(key, when) {
@@ -13595,12 +13729,12 @@ function readFolder2(id, problems) {
13595
13729
  problems.push(`${rel(fileOf(id))} is missing`);
13596
13730
  return null;
13597
13731
  }
13598
- const read4 = parseWorkflowFile(id, source, rel(fileOf(id)));
13599
- if ("problem" in read4) {
13600
- problems.push(read4.problem);
13732
+ const read5 = parseWorkflowFile(id, source, rel(fileOf(id)));
13733
+ if ("problem" in read5) {
13734
+ problems.push(read5.problem);
13601
13735
  return null;
13602
13736
  }
13603
- return read4.def;
13737
+ return read5.def;
13604
13738
  }
13605
13739
  function boardWorkflowDefs() {
13606
13740
  const problems = [];
@@ -13761,8 +13895,8 @@ function writeDraft(def, settings) {
13761
13895
  try {
13762
13896
  writeWorkflowDef(def);
13763
13897
  } catch (e2) {
13764
- const why = e2 instanceof Error ? e2.message : String(e2);
13765
- return { ok: false, ...refusal("fileWrite", `couldn't write the "${def.name}" workflow: ${why}`, { path: def.id, details: why }) };
13898
+ const why2 = e2 instanceof Error ? e2.message : String(e2);
13899
+ return { ok: false, ...refusal("fileWrite", `couldn't write the "${def.name}" workflow: ${why2}`, { path: def.id, details: why2 }) };
13766
13900
  }
13767
13901
  return settings ? save2(settings) : { ok: true };
13768
13902
  }
@@ -14718,8 +14852,8 @@ function takeUnchanged(delivery) {
14718
14852
  for (const answer2 of live.answers ?? []) if (!answer2.actedAt && answer2.outcome === "unchanged") answer2.actedAt = now;
14719
14853
  });
14720
14854
  }
14721
- function recordAnswer(deliveryId, outcome, why) {
14722
- const line = why.trim();
14855
+ function recordAnswer(deliveryId, outcome, why2) {
14856
+ const line = why2.trim();
14723
14857
  if (!line) return { ok: false, error: "say in one sentence what the answers did \u2014 an unexplained conclusion is not one." };
14724
14858
  return withStore((store) => {
14725
14859
  const delivery = store.deliveries.find((d2) => d2.deliveryId === deliveryId);
@@ -15534,6 +15668,14 @@ var init_Storyboard = __esm({
15534
15668
  }
15535
15669
  });
15536
15670
 
15671
+ // src/components/Workflow.md
15672
+ var Workflow_default;
15673
+ var init_Workflow = __esm({
15674
+ "src/components/Workflow.md"() {
15675
+ Workflow_default = '# Workflow\n\nShow how a workflow runs with `<Workflow src=".assets/<card id>/workflow.json" label="..." />` alone in a paragraph. Inline and fenced examples remain text.\n\n- **Data**: `akb workflow diagram <workflow id> <card id>` writes the file from the workflow and prints the tag; never write or edit the JSON by hand. Rerun it after changing the workflow.\n';
15676
+ }
15677
+ });
15678
+
15537
15679
  // src/lib/components.ts
15538
15680
  function agentComponents(names3, documents = DOCUMENTS) {
15539
15681
  const docs = /* @__PURE__ */ new Map();
@@ -15566,11 +15708,12 @@ var init_components = __esm({
15566
15708
  init_Asset();
15567
15709
  init_Compare();
15568
15710
  init_Storyboard();
15711
+ init_Workflow();
15569
15712
  init_agents();
15570
15713
  init_io();
15571
15714
  init_paths();
15572
15715
  init_workflows();
15573
- DOCUMENTS = { Asset: Asset_default, Compare: Compare_default, Storyboard: Storyboard_default };
15716
+ DOCUMENTS = { Asset: Asset_default, Compare: Compare_default, Storyboard: Storyboard_default, Workflow: Workflow_default };
15574
15717
  componentDocsText = (docs) => docs.map((doc) => doc.text.trim()).join("\n\n");
15575
15718
  }
15576
15719
  });
@@ -15715,8 +15858,8 @@ import path51 from "node:path";
15715
15858
  function stopReason(deliveryId) {
15716
15859
  const delivery = findDelivery(deliveryId);
15717
15860
  if (!delivery) return void 0;
15718
- const why = firstLine(delivery.review?.stopped?.why);
15719
- if (why) return why;
15861
+ const why2 = firstLine(delivery.review?.stopped?.why);
15862
+ if (why2) return why2;
15720
15863
  const ids = new Set(delivery.sessions);
15721
15864
  const last = readRuns().filter((r2) => ids.has(r2.sessionId) && r2.action === "implement" && r2.status !== "running").at(-1);
15722
15865
  if (!last) return void 0;
@@ -16530,9 +16673,9 @@ function endedDeliveryRefusal(r2, refusals) {
16530
16673
  if (refusals?.has(r2.deliveryId)) return refusals.get(r2.deliveryId);
16531
16674
  const delivery = findDelivery(r2.deliveryId);
16532
16675
  const ended = delivery && delivery.status !== "active" && (delivery.status !== "failed" || delivery.worktree);
16533
- const why = ended ? resumeRefusal(delivery) : void 0;
16534
- refusals?.set(r2.deliveryId, why);
16535
- return why;
16676
+ const why2 = ended ? resumeRefusal(delivery) : void 0;
16677
+ refusals?.set(r2.deliveryId, why2);
16678
+ return why2;
16536
16679
  }
16537
16680
  function retryAsk(r2) {
16538
16681
  if (r2.resumedFrom && r2.action !== "create" || isRetired(r2.action)) return void 0;
@@ -16863,7 +17006,7 @@ function planningSession(cardId2, cwd = REPO_ROOT) {
16863
17006
  function carriedSession(req) {
16864
17007
  const carries = PLANNING.has(req.action) || req.action === "implement" && !!req.carry?.resumeId;
16865
17008
  if (!Number.isInteger(req.id) || !carries) return void 0;
16866
- const fresh = (why) => ({ note: `new session \u2014 ${why}` });
17009
+ const fresh = (why2) => ({ note: `new session \u2014 ${why2}` });
16867
17010
  if (req.session === "new") return fresh("the earlier one is gone, so this step was started again");
16868
17011
  const agent = agentForRun(req);
16869
17012
  const own = planRun(randomUUID5(), REPO_ROOT, agent, req.runtime ? { pin: req.runtime } : {});
@@ -17447,7 +17590,7 @@ var init_sessions = __esm({
17447
17590
  asksPathOf = (sessionId) => path52.join(SESSIONS_DIR, `${sessionId}.asks.json`);
17448
17591
  carriesSession = (r2) => !!(r2.resumedFrom || r2.continues && !r2.continues.fork);
17449
17592
  canPickUp = (r2) => (r2.status === "error" || r2.status === "interrupted" || r2.status === "stopped") && !(r2.action === "create" && readRuns().some((next) => next.resumedFrom === r2.sessionId));
17450
- neverStarted = (r2) => r2.unspawned === true || !!r2.errorWhy?.some((why) => why.kind === "notInstalled");
17593
+ neverStarted = (r2) => r2.unspawned === true || !!r2.errorWhy?.some((why2) => why2.kind === "notInstalled");
17451
17594
  lacksSession = (r2) => neverStarted(r2) || !resumeIdOf(r2);
17452
17595
  carriesOn = (r2) => resumesUnder(r2.harness) || restartable(r2);
17453
17596
  CARDLESS = /* @__PURE__ */ new Set(["prune-memory", "review-memory", "review-dismissals", "describe-project"]);
@@ -17828,7 +17971,7 @@ function storyboardAttrs(raw) {
17828
17971
  const text5 = label ? (label[1] ?? label[2]).trim() : "";
17829
17972
  return { src: src[1] ?? src[2], ...text5 ? { label: text5 } : {} };
17830
17973
  }
17831
- function storyboardMarkers(body) {
17974
+ function storyboardMarkers(body, tagOf = storyboardTag) {
17832
17975
  const lines = body.replace(/\r\n/g, "\n").split("\n");
17833
17976
  const found2 = [];
17834
17977
  let fence = null;
@@ -17842,7 +17985,7 @@ function storyboardMarkers(body) {
17842
17985
  fence = delimiter[1];
17843
17986
  return;
17844
17987
  }
17845
- const src = storyboardTag(line);
17988
+ const src = tagOf(line);
17846
17989
  if (src !== null && !lines[i - 1]?.trim() && !lines[i + 1]?.trim()) found2.push({ src, line: i + 1 });
17847
17990
  });
17848
17991
  return found2;
@@ -17859,7 +18002,7 @@ function assetName(src, cardId2, exts, nested = false) {
17859
18002
  if (!name.includes(".") || !exts.includes(ext)) return { expected, actual: `file type ${JSON.stringify(name.includes(".") ? ext : "")}` };
17860
18003
  return { name };
17861
18004
  }
17862
- var TAG2, attr, SRC_ATTR, LABEL_ATTR, SEGMENT2, storyboardTag;
18005
+ var TAG2, attr, SRC_ATTR, LABEL_ATTR, SEGMENT2, storyboardTag, workflowTag;
17863
18006
  var init_storyboard = __esm({
17864
18007
  "src/lib/storyboard.ts"() {
17865
18008
  "use strict";
@@ -17869,12 +18012,492 @@ var init_storyboard = __esm({
17869
18012
  LABEL_ATTR = attr("label");
17870
18013
  SEGMENT2 = /^(?!\.)[^/\\]+$/;
17871
18014
  storyboardTag = (raw) => storyboardAttrs(raw)?.src ?? null;
18015
+ workflowTag = (raw) => {
18016
+ const m = /^<Workflow\b([^<>]*?)\/>$/.exec(raw.trim());
18017
+ const src = m ? SRC_ATTR.exec(m[1]) : null;
18018
+ return src ? src[1] ?? src[2] : null;
18019
+ };
17872
18020
  }
17873
18021
  });
17874
18022
 
17875
- // src/lib/spec-contract.ts
18023
+ // ../artifact-sdk/src/builtin/compare.json
18024
+ var compare_default;
18025
+ var init_compare2 = __esm({
18026
+ "../artifact-sdk/src/builtin/compare.json"() {
18027
+ compare_default = '{\n "name": "compare",\n "title": { "en": "Compare", "zh": "\u5BF9\u6BD4" },\n "types": ["compare"],\n "schema": {\n "type": "object",\n "required": ["a", "b"],\n "properties": { "a": { "type": "string" }, "b": { "type": "string" } }\n },\n "references": [\n { "json": "/a", "types": ["storyboard", "compare"] },\n { "json": "/b", "types": ["storyboard", "compare"] },\n { "json": "/shots", "types": ["storyboard", "compare"] }\n ]\n}\n';
18028
+ }
18029
+ });
18030
+
18031
+ // ../artifact-sdk/src/builtin/html.json
18032
+ var html_default;
18033
+ var init_html = __esm({
18034
+ "../artifact-sdk/src/builtin/html.json"() {
18035
+ html_default = `{
18036
+ "name": "html",
18037
+ "title": { "en": "Page", "zh": "\u9875\u9762" },
18038
+ "types": ["html"],
18039
+ "references": [
18040
+ { "text": "<[a-z][^<>]*?\\\\ssrc\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
18041
+ { "text": "<[a-z][^<>]*?\\\\sposter\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
18042
+ { "text": "<[a-z][^<>]*?\\\\ssrcset\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']", "list": "," },
18043
+ { "text": "<link\\\\b[^<>]*?\\\\shref\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
18044
+ { "text": "url\\\\(\\\\s*[\\"']?([^\\"')]+?)[\\"']?\\\\s*\\\\)" }
18045
+ ]
18046
+ }
18047
+ `;
18048
+ }
18049
+ });
18050
+
18051
+ // ../artifact-sdk/src/builtin/image.json
18052
+ var image_default;
18053
+ var init_image = __esm({
18054
+ "../artifact-sdk/src/builtin/image.json"() {
18055
+ image_default = '{ "name": "image", "title": { "en": "Image", "zh": "\u56FE\u7247" }, "types": ["image"] }\n';
18056
+ }
18057
+ });
18058
+
18059
+ // ../artifact-sdk/src/builtin/markdown.json
18060
+ var markdown_default;
18061
+ var init_markdown = __esm({
18062
+ "../artifact-sdk/src/builtin/markdown.json"() {
18063
+ markdown_default = '{ "name": "markdown", "title": { "en": "Document", "zh": "\u6587\u6863" }, "types": ["markdown"] }\n';
18064
+ }
18065
+ });
18066
+
18067
+ // ../artifact-sdk/src/builtin/storyboard.json
18068
+ var storyboard_default;
18069
+ var init_storyboard2 = __esm({
18070
+ "../artifact-sdk/src/builtin/storyboard.json"() {
18071
+ storyboard_default = '{\n "name": "storyboard",\n "title": { "en": "Storyboard", "zh": "\u5206\u955C" },\n "types": ["storyboard"],\n "schema": {\n "type": "object",\n "anyOf": [{ "required": ["shots"] }, { "required": ["slides"] }],\n "properties": {\n "shots": {\n "type": "array",\n "items": {\n "type": "object",\n "properties": { "frames": { "type": "array", "items": { "type": "object", "properties": { "src": { "type": "string" } } } } }\n }\n },\n "slides": {\n "type": "array",\n "items": {\n "type": "object",\n "properties": {\n "preview": { "type": "object", "properties": { "src": { "type": "string" } } },\n "assets": { "type": "array", "items": { "type": "string" } }\n }\n }\n }\n }\n },\n "references": [\n { "json": "/shots/*/frames/*/src" },\n { "json": "/slides/*/preview/src" },\n { "json": "/slides/*/assets/*" }\n ]\n}\n';
18072
+ }
18073
+ });
18074
+
18075
+ // ../artifact-sdk/src/builtin/video.json
18076
+ var video_default;
18077
+ var init_video = __esm({
18078
+ "../artifact-sdk/src/builtin/video.json"() {
18079
+ video_default = '{ "name": "video", "title": { "en": "Video", "zh": "\u89C6\u9891" }, "types": ["video"] }\n';
18080
+ }
18081
+ });
18082
+
18083
+ // ../artifact-sdk/src/builtin/workflow.json
18084
+ var workflow_default;
18085
+ var init_workflow = __esm({
18086
+ "../artifact-sdk/src/builtin/workflow.json"() {
18087
+ workflow_default = '{\n "name": "workflow",\n "title": { "en": "Workflow", "zh": "\u5DE5\u4F5C\u6D41" },\n "types": ["workflow"],\n "schema": {\n "type": "object",\n "required": ["rounds", "land", "scheduled"],\n "properties": {\n "rounds": {\n "type": "array",\n "items": {\n "type": "array",\n "minItems": 1,\n "items": { "type": "object", "required": ["agent", "title"], "properties": { "agent": { "type": "string" }, "title": { "type": "object", "required": ["en"] } } }\n }\n },\n "land": { "type": "array", "items": { "type": "object", "required": ["agent", "title"] } },\n "scheduled": { "type": "array", "items": { "type": "object", "required": ["agent", "title"] } }\n }\n }\n}\n';
18088
+ }
18089
+ });
18090
+
18091
+ // ../artifact-sdk/src/builtin/index.ts
18092
+ var read, builtin_default;
18093
+ var init_builtin = __esm({
18094
+ "../artifact-sdk/src/builtin/index.ts"() {
18095
+ "use strict";
18096
+ init_compare2();
18097
+ init_html();
18098
+ init_image();
18099
+ init_markdown();
18100
+ init_storyboard2();
18101
+ init_video();
18102
+ init_workflow();
18103
+ read = (m) => typeof m === "string" ? JSON.parse(m) : m;
18104
+ builtin_default = [html_default, image_default, video_default, markdown_default, storyboard_default, compare_default, workflow_default].map(read);
18105
+ }
18106
+ });
18107
+
18108
+ // ../artifact-sdk/src/internal/schema.ts
18109
+ function typeOk(type, v) {
18110
+ const types = Array.isArray(type) ? type : [type];
18111
+ return types.some(
18112
+ (t) => t === "null" ? v === null : t === "array" ? Array.isArray(v) : t === "object" ? isObj(v) : t === "integer" ? Number.isInteger(v) : t === "number" ? typeof v === "number" && Number.isFinite(v) : typeof v === t
18113
+ );
18114
+ }
18115
+ function schemaProblem(schema, value, at2 = "") {
18116
+ if (!isObj(schema)) return null;
18117
+ const s = schema;
18118
+ const here = at2 || "/";
18119
+ if (s.type !== void 0 && !typeOk(s.type, value)) return here;
18120
+ if (Array.isArray(s.enum) && !s.enum.some((e2) => JSON.stringify(e2) === JSON.stringify(value))) return here;
18121
+ if (s.const !== void 0 && JSON.stringify(s.const) !== JSON.stringify(value)) return here;
18122
+ if (Array.isArray(s.anyOf) && !s.anyOf.some((x2) => !schemaProblem(x2, value, at2))) return here;
18123
+ if (typeof value === "string") {
18124
+ if (typeof s.minLength === "number" && value.length < s.minLength) return here;
18125
+ if (typeof s.maxLength === "number" && value.length > s.maxLength) return here;
18126
+ if (typeof s.pattern === "string") {
18127
+ try {
18128
+ if (!new RegExp(s.pattern, "u").test(value)) return here;
18129
+ } catch {
18130
+ }
18131
+ }
18132
+ }
18133
+ if (typeof value === "number") {
18134
+ if (typeof s.minimum === "number" && value < s.minimum) return here;
18135
+ if (typeof s.maximum === "number" && value > s.maximum) return here;
18136
+ }
18137
+ if (Array.isArray(value)) {
18138
+ if (typeof s.minItems === "number" && value.length < s.minItems) return here;
18139
+ if (typeof s.maxItems === "number" && value.length > s.maxItems) return here;
18140
+ if (isObj(s.items)) {
18141
+ for (let i = 0; i < value.length; i++) {
18142
+ const bad = schemaProblem(s.items, value[i], `${at2}/${i}`);
18143
+ if (bad) return bad;
18144
+ }
18145
+ }
18146
+ }
18147
+ if (isObj(value)) {
18148
+ const props = isObj(s.properties) ? s.properties : {};
18149
+ if (Array.isArray(s.required)) {
18150
+ for (const k2 of s.required) if (typeof k2 === "string" && !(k2 in value)) return `${at2}/${k2}`;
18151
+ }
18152
+ for (const [k2, v] of Object.entries(value)) {
18153
+ if (k2 in props) {
18154
+ const bad = schemaProblem(props[k2], v, `${at2}/${k2}`);
18155
+ if (bad) return bad;
18156
+ } else if (s.additionalProperties === false) return `${at2}/${k2}`;
18157
+ else if (isObj(s.additionalProperties)) {
18158
+ const bad = schemaProblem(s.additionalProperties, v, `${at2}/${k2}`);
18159
+ if (bad) return bad;
18160
+ }
18161
+ }
18162
+ }
18163
+ return null;
18164
+ }
18165
+ var isObj;
18166
+ var init_schema = __esm({
18167
+ "../artifact-sdk/src/internal/schema.ts"() {
18168
+ "use strict";
18169
+ isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
18170
+ }
18171
+ });
18172
+
18173
+ // ../artifact-sdk/src/internal/manifest.ts
18174
+ function typeOf(data, types) {
18175
+ for (const type of types) if (!schemaProblem(manifestOf(type)?.schema, data)) return { type };
18176
+ if (types.length !== 1) return { type: null };
18177
+ return { type: types[0], problem: `does not match ${types[0]} at ${schemaProblem(manifestOf(types[0])?.schema, data)}` };
18178
+ }
18179
+ function mapJson(node, keys, at2, visit) {
18180
+ if (!keys.length) return typeof node === "string" && node ? visit(node, at2) : node;
18181
+ const [key, ...rest] = keys;
18182
+ if (Array.isArray(node)) {
18183
+ if (key === "*") return node.map((x2, i2) => mapJson(x2, rest, `${at2}/${i2}`, visit));
18184
+ const i = Number(key);
18185
+ return Number.isInteger(i) && i in node ? node.map((x2, j2) => j2 === i ? mapJson(x2, rest, `${at2}/${j2}`, visit) : x2) : node;
18186
+ }
18187
+ if (!isObject(node)) return node;
18188
+ const out = { ...node };
18189
+ for (const k2 of key === "*" ? Object.keys(node) : key in node ? [key] : []) out[k2] = mapJson(node[k2], rest, `${at2}/${k2}`, visit);
18190
+ return out;
18191
+ }
18192
+ function mapText(text5, rule, visit) {
18193
+ let out = "";
18194
+ let last = 0;
18195
+ for (const m of text5.matchAll(new RegExp(rule.text, "gid"))) {
18196
+ const span = m.indices?.[1];
18197
+ if (!span || m[1] === void 0) continue;
18198
+ const line = text5.slice(0, span[0]).split("\n").length;
18199
+ const one = (src) => remote(src) ? src : visit(src, line);
18200
+ const value = rule.list ? m[1].split(rule.list).map((part) => part.replace(/^(\s*)(\S+)/, (_2, space, src) => space + one(src))).join(rule.list) : one(m[1]);
18201
+ out += text5.slice(last, span[0]) + value;
18202
+ last = span[1];
18203
+ }
18204
+ return out + text5.slice(last);
18205
+ }
18206
+ function mapReferences(manifest, content, map2) {
18207
+ for (const rule of manifest?.references ?? []) {
18208
+ const types = rule.types ?? [];
18209
+ if ("json" in rule) {
18210
+ if (typeof content !== "string") content = mapJson(content, rule.json.split("/").filter(Boolean), "", (src, at2) => map2(src, { src, types, text: false, at: at2 || "/" }));
18211
+ } else if (typeof content === "string") {
18212
+ content = mapText(content, rule, (src, line) => map2(src, { src, types, text: true, line }));
18213
+ }
18214
+ }
18215
+ return content;
18216
+ }
18217
+ function referencesOf(manifest, content) {
18218
+ const found2 = [];
18219
+ mapReferences(manifest, content, (src, ref) => (found2.push(ref), src));
18220
+ return found2;
18221
+ }
18222
+ var BUILTINS, manifestOf, isObject, remote;
18223
+ var init_manifest = __esm({
18224
+ "../artifact-sdk/src/internal/manifest.ts"() {
18225
+ "use strict";
18226
+ init_builtin();
18227
+ init_schema();
18228
+ BUILTINS = builtin_default;
18229
+ manifestOf = (type) => BUILTINS.find((m) => m.types.includes(type));
18230
+ isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
18231
+ remote = (src) => !src || /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src);
18232
+ }
18233
+ });
18234
+
18235
+ // ../artifact-sdk/src/internal/references.ts
18236
+ function bodyReferences(body) {
18237
+ const lines = body.replace(/<!--[^]*?-->/g, "").split(/\r?\n/);
18238
+ let fence = "";
18239
+ let inTag = false;
18240
+ const out = [];
18241
+ const visible = [];
18242
+ for (const line of lines) {
18243
+ const delimiter = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1];
18244
+ if (fence) {
18245
+ if (delimiter && delimiter[0] === fence[0] && delimiter.length >= fence.length) fence = "";
18246
+ visible.push("");
18247
+ continue;
18248
+ }
18249
+ if (delimiter) {
18250
+ fence = delimiter;
18251
+ visible.push("");
18252
+ continue;
18253
+ }
18254
+ const kept2 = inTag || !/^(?: {4}|\t)/.test(line);
18255
+ visible.push(kept2 ? line : "");
18256
+ if (kept2 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard|Workflow)\b/.test(line)) inTag = true;
18257
+ if (line.includes("/>")) inTag = false;
18258
+ }
18259
+ const text5 = visible.join("\n").replace(/(`+)[^]*?\1/g, "");
18260
+ const tag = /<(Asset|Mockup|Compare|Storyboard|Workflow)\b([^<>]*?)\/>/g;
18261
+ const blocks = text5.matchAll(/^ {0,3}(?:<(?:Asset|Mockup|Compare|Storyboard|Workflow)\b[^<>]*?\/>[ \t]*(?:\n[ \t]*)?)+$/gm);
18262
+ for (const block of blocks) {
18263
+ const tags = [...block[0].matchAll(tag)];
18264
+ for (const m of tags) {
18265
+ const a2 = {};
18266
+ for (const p2 of m[2].matchAll(/([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) a2[p2[1]] = p2[2] ?? p2[3];
18267
+ if (m[1] === "Compare") {
18268
+ if (!a2.a || !a2.b) continue;
18269
+ for (const k2 of ["a", "b", "shots"]) if (a2[k2]) out.push({ src: a2[k2], types: COMPARE });
18270
+ } else if (a2.src) {
18271
+ out.push({ src: a2.src, types: m[1] === "Storyboard" ? STORYBOARD : m[1] === "Workflow" ? WORKFLOW : [] });
18272
+ if (a2.variants) {
18273
+ try {
18274
+ const v = JSON.parse(a2.variants);
18275
+ if (isObject2(v)) {
18276
+ for (const src of Object.values(v)) if (typeof src === "string" && src) out.push({ src, types: [] });
18277
+ }
18278
+ } catch {
18279
+ }
18280
+ }
18281
+ }
18282
+ }
18283
+ }
18284
+ for (const m of text5.replace(tag, "").matchAll(/\]\(\s*<?([^\s)>]+)>?(?:\s+["'][^]*?["'])?\s*\)/g)) out.push({ src: m[1], types: [] });
18285
+ return out;
18286
+ }
18287
+ function kindOf(ext) {
18288
+ if (ext === ".tsx" || ext === ".html") return "html";
18289
+ if (ext === ".md" || ext === ".mdx") return "markdown";
18290
+ const type = TYPES[ext] ?? "";
18291
+ if (type.startsWith("image/")) return "image";
18292
+ return type.startsWith("video/") || type.startsWith("audio/") ? "video" : "asset";
18293
+ }
18294
+ var STORYBOARD, WORKFLOW, COMPARE, isObject2, bodySources, TYPES;
18295
+ var init_references = __esm({
18296
+ "../artifact-sdk/src/internal/references.ts"() {
18297
+ "use strict";
18298
+ STORYBOARD = ["storyboard"];
18299
+ WORKFLOW = ["workflow"];
18300
+ COMPARE = ["storyboard", "compare"];
18301
+ isObject2 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
18302
+ bodySources = (body) => [...new Set(bodyReferences(body).map((r2) => r2.src))];
18303
+ TYPES = {
18304
+ ".png": "image/png",
18305
+ ".jpg": "image/jpeg",
18306
+ ".jpeg": "image/jpeg",
18307
+ ".gif": "image/gif",
18308
+ ".webp": "image/webp",
18309
+ ".svg": "image/svg+xml",
18310
+ ".mp4": "video/mp4",
18311
+ ".webm": "video/webm",
18312
+ ".mp3": "audio/mpeg",
18313
+ ".pdf": "application/pdf",
18314
+ ".html": "text/html",
18315
+ ".md": "text/markdown",
18316
+ ".mdx": "text/markdown",
18317
+ ".mov": "video/quicktime",
18318
+ ".wav": "audio/wav",
18319
+ ".m4a": "audio/mp4",
18320
+ ".json": "application/json",
18321
+ ".txt": "text/plain",
18322
+ ".otf": "font/otf",
18323
+ ".ttf": "font/ttf",
18324
+ ".woff": "font/woff",
18325
+ ".woff2": "font/woff2",
18326
+ ".css": "text/css"
18327
+ };
18328
+ }
18329
+ });
18330
+
18331
+ // ../artifact-sdk/src/internal/collect.ts
18332
+ function collect(body, card, host2) {
18333
+ const nodes = /* @__PURE__ */ new Map();
18334
+ const active2 = /* @__PURE__ */ new Set();
18335
+ const out = [];
18336
+ const visit = (src, types, owner) => {
18337
+ const path90 = src.replace(/[?#].*$/, "");
18338
+ let resolved2;
18339
+ try {
18340
+ resolved2 = host2.resolve(path90, owner);
18341
+ } catch (error) {
18342
+ if (owner !== card) return { key: null, error: why(error) };
18343
+ if (!nodes.has(src)) {
18344
+ const node2 = { key: src, file: null, kind: kindAt(path90, types), error: why(error), problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([src]) };
18345
+ nodes.set(src, node2);
18346
+ out.push(node2);
18347
+ }
18348
+ return { key: src, error: nodes.get(src).error };
18349
+ }
18350
+ if (!resolved2) return { key: null };
18351
+ const { key, file } = resolved2;
18352
+ if (active2.has(key)) throw new Error(`${owner}: ${src}: \u8D44\u6E90\u4F9D\u8D56\u5FAA\u73AF`);
18353
+ const json = !!file && extOf(file) === ".json";
18354
+ const held4 = nodes.get(key);
18355
+ if (held4) {
18356
+ if (owner === card) held4.aliases.add(src);
18357
+ if (held4.error || !json || !types.length || held4.kind !== "asset") return { key, error: held4.error };
18358
+ out.splice(out.indexOf(held4), 1);
18359
+ }
18360
+ const node = { key, file, kind: "asset", problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: held4?.aliases ?? /* @__PURE__ */ new Set([key]) };
18361
+ if (owner === card) node.aliases.add(src);
18362
+ nodes.set(key, node);
18363
+ active2.add(key);
18364
+ const child = (ref, from) => {
18365
+ const found2 = visit(ref.src, ref.types, from);
18366
+ if (found2.key) node.dependencies.set(ref.src, found2.key);
18367
+ else if (found2.error) node.problems.push({ src: ref.src, ..."line" in ref ? { line: ref.line } : {}, ..."at" in ref ? { at: ref.at } : {}, message: found2.error });
18368
+ node.error ??= found2.error;
18369
+ };
18370
+ if (file) {
18371
+ if (json) {
18372
+ try {
18373
+ node.data = JSON.parse(host2.read(file));
18374
+ const typed = typeOf(node.data, types);
18375
+ node.kind = typed.type ?? "asset";
18376
+ if (typed.problem) node.problems.push({ src: file, message: `${typed.problem}: ${file}` });
18377
+ } catch {
18378
+ node.problems.push({ src: file, message: `not valid JSON: ${file}` });
18379
+ }
18380
+ } else {
18381
+ node.kind = kindOf(extOf(file));
18382
+ try {
18383
+ if (manifestOf(node.kind)?.references) node.data = host2.read(file);
18384
+ } catch (error) {
18385
+ node.problems.push({ src: file, message: why(error) });
18386
+ }
18387
+ }
18388
+ node.error = node.problems[0]?.message;
18389
+ if (!node.error) for (const ref of referencesOf(manifestOf(node.kind), node.data)) child(ref, file);
18390
+ } else {
18391
+ for (const ref of host2.retained(key)) child(ref, card);
18392
+ }
18393
+ active2.delete(key);
18394
+ out.push(node);
18395
+ return { key, error: node.error };
18396
+ };
18397
+ for (const ref of bodyReferences(body)) visit(ref.src, ref.types, card);
18398
+ const sorted = [];
18399
+ const done2 = /* @__PURE__ */ new Set();
18400
+ const order = (node) => {
18401
+ if (done2.has(node.key)) return;
18402
+ done2.add(node.key);
18403
+ for (const key of node.dependencies.values()) {
18404
+ const child = nodes.get(key);
18405
+ if (child) order(child);
18406
+ }
18407
+ sorted.push(node);
18408
+ };
18409
+ for (const node of out) order(node);
18410
+ return sorted;
18411
+ }
18412
+ var extOf, why, kindAt;
18413
+ var init_collect = __esm({
18414
+ "../artifact-sdk/src/internal/collect.ts"() {
18415
+ "use strict";
18416
+ init_manifest();
18417
+ init_references();
18418
+ extOf = (file) => /\.[^./\\]+$/.exec(file)?.[0].toLowerCase() ?? "";
18419
+ why = (error) => error instanceof Error ? error.message : String(error);
18420
+ kindAt = (src, types) => extOf(src) === ".json" ? types[0] ?? "asset" : kindOf(extOf(src));
18421
+ }
18422
+ });
18423
+
18424
+ // src/lib/dress-page.ts
17876
18425
  import fs51 from "node:fs";
17877
18426
  import path54 from "node:path";
18427
+ function dressPage(file) {
18428
+ const folder = path54.dirname(file);
18429
+ const html = fs51.readFileSync(file, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
18430
+ const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
18431
+ if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
18432
+ const at3 = path54.resolve(folder, href);
18433
+ if (!at3.startsWith(folder + path54.sep) || !fs51.existsSync(at3)) return tag;
18434
+ const css = fs51.readFileSync(at3, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole2, quote, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole2 : `url(${quote}${path54.relative(folder, path54.resolve(path54.dirname(at3), src)).split(path54.sep).join("/")}${quote})`);
18435
+ return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
18436
+ });
18437
+ const at2 = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
18438
+ return /<!doctype\b|<html[\s>]|<head[\s>]/i.test(html) ? html.slice(0, at2) + head + html.slice(at2) : `<!doctype html><html><head>${head}</head><body>${html}</body></html>`;
18439
+ }
18440
+ var CSP, head, referenceText;
18441
+ var init_dress_page = __esm({
18442
+ "src/lib/dress-page.ts"() {
18443
+ "use strict";
18444
+ 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'";
18445
+ 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>`;
18446
+ referenceText = (file) => /\.html$/i.test(file) ? dressPage(file) : fs51.readFileSync(file, "utf8");
18447
+ }
18448
+ });
18449
+
18450
+ // src/lib/preview-files.ts
18451
+ import fs52 from "node:fs";
18452
+ import path55 from "node:path";
18453
+ function resolver(card, id) {
18454
+ const roots = [KANBAN, path55.join(ASSETS, String(id)), path55.join(MOCKUPS, String(id))];
18455
+ const real2 = (p2) => fs52.existsSync(p2) ? fs52.realpathSync(p2) : p2;
18456
+ const inside2 = (p2) => roots.some((root2) => p2.startsWith(real2(root2) + path55.sep));
18457
+ return (src, owner) => {
18458
+ if (/^[a-z][\w+.-]*:/i.test(src) || src.startsWith("#") || src.startsWith("//")) return null;
18459
+ if (path55.isAbsolute(src)) throw new Error("an absolute path; name it relative to the file");
18460
+ const held4 = /^\.(assets|mockups)\//.exec(src);
18461
+ const file = held4 ? path55.resolve(held4[1] === "assets" ? ASSETS : MOCKUPS, src.slice(held4[0].length)) : path55.resolve(path55.dirname(owner), src);
18462
+ if (!inside2(path55.resolve(file)) || fs52.existsSync(file) && !inside2(fs52.realpathSync(file))) throw new Error(`outside this card's files (${rel(KANBAN)}, .assets/${id}/)`);
18463
+ if (!fs52.statSync(file, { throwIfNoEntry: false })?.isFile()) throw new Error("no such file");
18464
+ return { key: fs52.realpathSync(file), file };
18465
+ };
18466
+ }
18467
+ function validatePreviewFiles(card, id, text5) {
18468
+ const resolve2 = resolver(card, id);
18469
+ const errors = [];
18470
+ const graph = collect(text5, card, {
18471
+ resolve: (src, owner) => {
18472
+ if (owner !== card) return resolve2(src, owner);
18473
+ try {
18474
+ return resolve2(src, owner);
18475
+ } catch {
18476
+ return null;
18477
+ }
18478
+ },
18479
+ read: referenceText,
18480
+ retained: () => []
18481
+ });
18482
+ for (const node of graph) {
18483
+ for (const p2 of node.problems) {
18484
+ errors.push({ file: rel(node.file ?? card), line: p2.line ?? 1, rule: "preview-file", message: `${p2.at ? `${p2.at}: ` : ""}${p2.src}: ${p2.message}. Fix the reference or add the file.` });
18485
+ }
18486
+ }
18487
+ return errors;
18488
+ }
18489
+ var init_preview_files = __esm({
18490
+ "src/lib/preview-files.ts"() {
18491
+ "use strict";
18492
+ init_collect();
18493
+ init_dress_page();
18494
+ init_paths();
18495
+ }
18496
+ });
18497
+
18498
+ // src/lib/spec-contract.ts
18499
+ import fs53 from "node:fs";
18500
+ import path56 from "node:path";
17878
18501
  function scanCardLines(lines, start = 0) {
17879
18502
  const visible = lines.map(() => "");
17880
18503
  let fence = null;
@@ -17907,18 +18530,18 @@ function scanCardLines(lines, start = 0) {
17907
18530
  }
17908
18531
  function snapshotSpecs() {
17909
18532
  const out = /* @__PURE__ */ new Map();
17910
- if (!fs51.existsSync(TODO)) return out;
18533
+ if (!fs53.existsSync(TODO)) return out;
17911
18534
  for (const file of walkMd(TODO)) {
17912
- if (isLegacyRecurring(path54.relative(TODO, file))) continue;
17913
- const id = idPrefix(path54.basename(file) === "root.md" ? path54.basename(path54.dirname(file)) : path54.basename(file));
17914
- if (id !== null) out.set(file, { id, text: fs51.readFileSync(file, "utf8") });
18535
+ if (isLegacyRecurring(path56.relative(TODO, file))) continue;
18536
+ const id = idPrefix(path56.basename(file) === "root.md" ? path56.basename(path56.dirname(file)) : path56.basename(file));
18537
+ if (id !== null) out.set(file, { id, text: fs53.readFileSync(file, "utf8") });
17915
18538
  }
17916
18539
  return out;
17917
18540
  }
17918
18541
  function enclosingGroups(file) {
17919
18542
  const ids = [];
17920
18543
  for (let root2 = enclosingGroupRoot(file); root2; root2 = enclosingGroupRoot(root2)) {
17921
- const id = idPrefix(path54.basename(path54.dirname(root2)));
18544
+ const id = idPrefix(path56.basename(path56.dirname(root2)));
17922
18545
  if (id !== null) ids.push(id);
17923
18546
  }
17924
18547
  return ids;
@@ -18016,8 +18639,8 @@ function validateSpec(file, text5, id) {
18016
18639
  if (device !== void 0 && device !== "mobile" && device !== "desktop") add(i + 1, "mockup-device", `device="${device}" is not a device. Use device="mobile" or device="desktop".`);
18017
18640
  const src = line.match(/\bsrc="([^"]*)"/)?.[1] ?? "";
18018
18641
  const variants = line.match(/\bvariants='([^']*)'/)?.[1];
18019
- const why = variants === void 0 ? null : variantsProblem(variants, src, id);
18020
- if (why) add(i + 1, "mockup-variants", why);
18642
+ const why2 = variants === void 0 ? null : variantsProblem(variants, src, id);
18643
+ if (why2) add(i + 1, "mockup-variants", why2);
18021
18644
  else if (id !== void 0 && src.startsWith(".assets/") && !inside(ASSETS, src.slice(".assets/".length))) {
18022
18645
  add(i + 1, "asset-src", `src="${src}" names no file. Write it as ${rel(ASSETS)}/${src.slice(".assets/".length)}, or fix the path.`);
18023
18646
  }
@@ -18025,13 +18648,16 @@ function validateSpec(file, text5, id) {
18025
18648
  if (/^\s*<Storyboard\b/.test(line) && (storyboardTag(line) === null || lines[i - 1]?.trim() || lines[i + 1]?.trim())) {
18026
18649
  add(i + 1, "storyboard-block", 'Put one self-closing <Storyboard src=".assets/<card id>/storyboard.json" /> tag on its own line, with blank lines around it.');
18027
18650
  }
18651
+ if (/^\s*<Workflow\b/.test(line) && (workflowTag(line) === null || !/\blabel="[^"]+"/.test(line) || lines[i - 1]?.trim() || lines[i + 1]?.trim())) {
18652
+ add(i + 1, "workflow-block", 'Put one self-closing <Workflow src=".assets/<card id>/workflow.json" label="..." /> tag on its own line, with blank lines around it.');
18653
+ }
18028
18654
  if (/^\s*<Compare\b/.test(line)) {
18029
18655
  const attrs = compareAttrs(line);
18030
18656
  if (!attrs || lines[i - 1]?.trim() || lines[i + 1]?.trim()) add(i + 1, "compare-block", 'Put one self-closing <Compare a="..." b="..." label="..." /> tag on its own line, with blank lines around it.');
18031
18657
  else if (!attrs.a || !attrs.b || !attrs.label) add(i + 1, "compare-attributes", 'Add non-empty a="...", b="..." and label="..." attributes to the Compare tag.');
18032
18658
  else if (id !== void 0) {
18033
- const why = compareProblem(attrs, id);
18034
- if (why) add(i + 1, why.rule, why.message);
18659
+ const why2 = compareProblem(attrs, id);
18660
+ if (why2) add(i + 1, why2.rule, why2.message);
18035
18661
  }
18036
18662
  }
18037
18663
  }
@@ -18068,14 +18694,14 @@ function validateSpec(file, text5, id) {
18068
18694
  const next = headings.find((h3) => h3.line > todo.line)?.line ?? lines.length + 1;
18069
18695
  if (!visible.slice(todo.line, next - 1).some((line) => /^\s*[-*+]\s*\[[ xX]?\]/.test(line))) add(todo.line, "todos", "## Todo needs at least one checkbox step, for example - [ ] Implement the requested behavior.");
18070
18696
  }
18071
- if (id !== void 0) errors.push(...validateStoryboards(file, id, text5));
18697
+ if (id !== void 0) errors.push(...validateStoryboards(file, id, text5), ...validatePreviewFiles(file, id, text5));
18072
18698
  return errors;
18073
18699
  }
18074
18700
  function inside(dir, name) {
18075
18701
  try {
18076
- const root2 = fs51.realpathSync(dir);
18077
- const real2 = fs51.realpathSync(path54.join(dir, name));
18078
- return real2.startsWith(root2 + path54.sep) && fs51.statSync(real2).isFile() ? real2 : null;
18702
+ const root2 = fs53.realpathSync(dir);
18703
+ const real2 = fs53.realpathSync(path56.join(dir, name));
18704
+ return real2.startsWith(root2 + path56.sep) && fs53.statSync(real2).isFile() ? real2 : null;
18079
18705
  } catch {
18080
18706
  return null;
18081
18707
  }
@@ -18093,7 +18719,7 @@ function variantsProblem(raw, src, id) {
18093
18719
  if (files2.length < 2 || !files2.every((f2) => typeof f2 === "string" && f2)) return `variants needs at least two labels, each naming a file. ${shape}`;
18094
18720
  if (!files2.includes(src)) return `src="${src}" is not one of the variants. Set src to the version shown first.`;
18095
18721
  if (id === void 0) return null;
18096
- const dir = path54.join(ASSETS, String(id));
18722
+ const dir = path56.join(ASSETS, String(id));
18097
18723
  for (const f2 of files2) {
18098
18724
  const parts = f2.split("/");
18099
18725
  if (parts.length !== 3 || parts[0] !== ".assets" || parts[1] !== String(id) || !inside(dir, parts[2])) {
@@ -18103,7 +18729,7 @@ function variantsProblem(raw, src, id) {
18103
18729
  return null;
18104
18730
  }
18105
18731
  function compareProblem(attrs, id) {
18106
- const dir = path54.join(ASSETS, String(id));
18732
+ const dir = path56.join(ASSETS, String(id));
18107
18733
  const src = (message) => ({ rule: "compare-src", message });
18108
18734
  const shots = (message) => ({ rule: "compare-shots", message });
18109
18735
  for (const side of ["a", "b"]) {
@@ -18117,23 +18743,23 @@ function compareProblem(attrs, id) {
18117
18743
  if (!script && kind !== compareKind(attrs.b)) return src("Compare a and b must both be images or both be videos.");
18118
18744
  if (attrs.shots === void 0) return script ? shots('shots is required when b is a storyboard. Add shots="..." naming a storyboard or shots list of video a.') : null;
18119
18745
  if (kind !== "video") return shots("shots is for videos only. Remove it from this Compare tag.");
18120
- const read4 = (at2) => {
18746
+ const read5 = (at2) => {
18121
18747
  const named2 = assetName(at2, id, ["json"]);
18122
18748
  if (!("name" in named2)) return { message: `Compare shots is ${named2.actual}; expected ${named2.expected}.` };
18123
18749
  const file = inside(dir, named2.name);
18124
18750
  if (!file) return { message: `Compare shots ${at2} names no file in this card's asset folder. Write the JSON there or fix the path.` };
18125
18751
  try {
18126
- return { data: JSON.parse(fs51.readFileSync(file, "utf8")) };
18752
+ return { data: JSON.parse(fs53.readFileSync(file, "utf8")) };
18127
18753
  } catch {
18128
18754
  return { message: `${at2} is not valid JSON.` };
18129
18755
  }
18130
18756
  };
18131
- const list = read4(attrs.shots);
18757
+ const list = read5(attrs.shots);
18132
18758
  if ("message" in list) return shots(list.message);
18133
- const why = Array.isArray(list.data) ? shotsProblem(list.data) : storyboardProblem(list.data);
18134
- if (why) return shots(`${attrs.shots}: ${why}`);
18759
+ const why2 = Array.isArray(list.data) ? shotsProblem(list.data) : storyboardProblem(list.data);
18760
+ if (why2) return shots(`${attrs.shots}: ${why2}`);
18135
18761
  if (!script) return null;
18136
- const b2 = read4(attrs.b);
18762
+ const b2 = read5(attrs.b);
18137
18763
  if ("message" in b2) return src(b2.message);
18138
18764
  const bad = storyboardProblem(b2.data);
18139
18765
  if (bad) return src(`${attrs.b}: ${bad}`);
@@ -18143,12 +18769,17 @@ function compareProblem(attrs, id) {
18143
18769
  }
18144
18770
  function validateStoryboards(file, id, text5) {
18145
18771
  const errors = [];
18146
- const dir = path54.join(ASSETS, String(id));
18147
- for (const marker of storyboardMarkers(text5)) {
18148
- const named2 = assetName(marker.src, id, ["json"]);
18149
- const add = (message) => errors.push({ file: rel(file), line: marker.line, rule: "storyboard-src", message });
18150
- if (!("name" in named2)) add(`Storyboard src is ${named2.actual}; expected ${named2.expected}.`);
18151
- else if (!inside(dir, named2.name)) add(`Storyboard src ${marker.src} names no file in this card's asset folder. Write the JSON there or fix the path.`);
18772
+ const dir = path56.join(ASSETS, String(id));
18773
+ for (const [tag, tagOf, rule, fix] of [
18774
+ ["Storyboard", storyboardTag, "storyboard-src", "Write the JSON there or fix the path."],
18775
+ ["Workflow", workflowTag, "workflow-src", "Write it with `akb workflow diagram <workflow id> <card id>` or fix the path."]
18776
+ ]) {
18777
+ for (const marker of storyboardMarkers(text5, tagOf)) {
18778
+ const named2 = assetName(marker.src, id, ["json"]);
18779
+ const add = (message) => errors.push({ file: rel(file), line: marker.line, rule, message });
18780
+ if (!("name" in named2)) add(`${tag} src is ${named2.actual}; expected ${named2.expected}.`);
18781
+ else if (!inside(dir, named2.name)) add(`${tag} src ${marker.src} names no file in this card's asset folder. ${fix}`);
18782
+ }
18152
18783
  }
18153
18784
  return errors;
18154
18785
  }
@@ -18209,19 +18840,20 @@ var init_spec_contract = __esm({
18209
18840
  init_paths();
18210
18841
  init_compare();
18211
18842
  init_storyboard();
18843
+ init_preview_files();
18212
18844
  init_validate();
18213
18845
  }
18214
18846
  });
18215
18847
 
18216
18848
  // src/lib/reconcile.ts
18217
- import fs52 from "node:fs";
18218
- import path55 from "node:path";
18849
+ import fs54 from "node:fs";
18850
+ import path57 from "node:path";
18219
18851
  function liveIds() {
18220
18852
  const ids = /* @__PURE__ */ new Set();
18221
18853
  for (const file of walkMd(TODO)) {
18222
- const base = path55.basename(file);
18854
+ const base = path57.basename(file);
18223
18855
  if (base === "README.md") continue;
18224
- const id = base === "root.md" ? idPrefix(path55.basename(path55.dirname(file))) : idPrefix(base);
18856
+ const id = base === "root.md" ? idPrefix(path57.basename(path57.dirname(file))) : idPrefix(base);
18225
18857
  if (id != null) ids.add(id);
18226
18858
  }
18227
18859
  return ids;
@@ -18229,16 +18861,16 @@ function liveIds() {
18229
18861
  function indexableCards() {
18230
18862
  const out = [];
18231
18863
  for (const dir of walkDirs(TODO)) {
18232
- const id = idPrefix(path55.basename(dir));
18233
- if (id != null && fs52.existsSync(path55.join(dir, "root.md"))) {
18234
- out.push({ id, rel: path55.join(path55.relative(TODO, dir), "root.md").split(path55.sep).join("/") });
18864
+ const id = idPrefix(path57.basename(dir));
18865
+ if (id != null && fs54.existsSync(path57.join(dir, "root.md"))) {
18866
+ out.push({ id, rel: path57.join(path57.relative(TODO, dir), "root.md").split(path57.sep).join("/") });
18235
18867
  }
18236
18868
  }
18237
18869
  for (const file of walkMd(TODO)) {
18238
- const base = path55.basename(file);
18870
+ const base = path57.basename(file);
18239
18871
  if (base === "README.md" || base === "root.md") continue;
18240
- const relTODO = path55.relative(TODO, file);
18241
- const segs = relTODO.split(path55.sep);
18872
+ const relTODO = path57.relative(TODO, file);
18873
+ const segs = relTODO.split(path57.sep);
18242
18874
  if (segs.length !== 1) continue;
18243
18875
  const id = idPrefix(base);
18244
18876
  if (id != null) out.push({ id, rel: segs.join("/") });
@@ -18247,7 +18879,7 @@ function indexableCards() {
18247
18879
  }
18248
18880
  function readmeComplaints(fix) {
18249
18881
  const said3 = [];
18250
- const lines = fs52.readFileSync(README, "utf8").split("\n");
18882
+ const lines = fs54.readFileSync(README, "utf8").split("\n");
18251
18883
  const indexed = /* @__PURE__ */ new Set();
18252
18884
  let fixed = 0;
18253
18885
  for (let i = 0; i < lines.length; i++) {
@@ -18256,13 +18888,13 @@ function readmeComplaints(fix) {
18256
18888
  const id = Number(m[1]);
18257
18889
  const linkPath = m[2];
18258
18890
  indexed.add(id);
18259
- if (fs52.existsSync(path55.join(TODO, linkPath))) continue;
18891
+ if (fs54.existsSync(path57.join(TODO, linkPath))) continue;
18260
18892
  const found2 = locate(id);
18261
18893
  if (!found2) {
18262
18894
  said3.push(`README links #${id} \u2192 ${linkPath}, but no card with that id exists (removed by hand?). Drop the entry or restore the file.`);
18263
18895
  continue;
18264
18896
  }
18265
- const want = (found2.kind === "group" ? path55.join(found2.rel, "root.md") : found2.rel).split(path55.sep).join("/");
18897
+ const want = (found2.kind === "group" ? path57.join(found2.rel, "root.md") : found2.rel).split(path57.sep).join("/");
18266
18898
  if (want === linkPath) continue;
18267
18899
  if (!fix) {
18268
18900
  said3.push(`README links #${id} \u2192 ${linkPath}, which isn't there any more; the card is at ${want}.`);
@@ -18272,7 +18904,7 @@ function readmeComplaints(fix) {
18272
18904
  said3.push(`README link #${id} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
18273
18905
  fixed++;
18274
18906
  }
18275
- if (fixed) fs52.writeFileSync(README, lines.join("\n"));
18907
+ if (fixed) fs54.writeFileSync(README, lines.join("\n"));
18276
18908
  for (const c2 of indexableCards()) {
18277
18909
  if (!indexed.has(c2.id)) {
18278
18910
  said3.push(`card ${c2.rel} (#${c2.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
@@ -18284,11 +18916,11 @@ function crossRefComplaints() {
18284
18916
  const said3 = [];
18285
18917
  const live = liveIds();
18286
18918
  for (const file of walkMd(TODO)) {
18287
- const base = path55.basename(file);
18919
+ const base = path57.basename(file);
18288
18920
  if (base === "README.md") continue;
18289
- const ownerId = base === "root.md" ? idPrefix(path55.basename(path55.dirname(file))) : idPrefix(base);
18921
+ const ownerId = base === "root.md" ? idPrefix(path57.basename(path57.dirname(file))) : idPrefix(base);
18290
18922
  if (ownerId == null) continue;
18291
- const { meta } = parseFrontmatter(fs52.readFileSync(file, "utf8"));
18923
+ const { meta } = parseFrontmatter(fs54.readFileSync(file, "utf8"));
18292
18924
  if (!meta) continue;
18293
18925
  for (const field2 of ["blocked_by", "related"]) {
18294
18926
  for (const ref of meta[field2] || []) {
@@ -18301,11 +18933,11 @@ function crossRefComplaints() {
18301
18933
  return said3;
18302
18934
  }
18303
18935
  function reconcileBoard() {
18304
- if (!fs52.existsSync(README)) return;
18936
+ if (!fs54.existsSync(README)) return;
18305
18937
  for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
18306
18938
  }
18307
18939
  function boardComplaints() {
18308
- if (!fs52.existsSync(README)) return [];
18940
+ if (!fs54.existsSync(README)) return [];
18309
18941
  try {
18310
18942
  return [...readmeComplaints(false), ...crossRefComplaints()];
18311
18943
  } catch {
@@ -18325,8 +18957,8 @@ var init_reconcile = __esm({
18325
18957
  });
18326
18958
 
18327
18959
  // src/commands/card.ts
18328
- import fs53 from "node:fs";
18329
- import path56 from "node:path";
18960
+ import fs55 from "node:fs";
18961
+ import path58 from "node:path";
18330
18962
  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>") {
18331
18963
  return [
18332
18964
  summary,
@@ -18352,7 +18984,7 @@ function bodyFromFile(opts) {
18352
18984
  if (opts.body === false) die("pass --body-file or --no-body, not both");
18353
18985
  let text5;
18354
18986
  try {
18355
- text5 = fs53.readFileSync(opts.bodyFile, "utf8");
18987
+ text5 = fs55.readFileSync(opts.bodyFile, "utf8");
18356
18988
  } catch {
18357
18989
  die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
18358
18990
  }
@@ -18432,20 +19064,20 @@ function cmdCreate(opts) {
18432
19064
  const start = opts.id;
18433
19065
  const slug2 = slugify(opts.slug !== void 0 ? opts.slug : title);
18434
19066
  const fileRel = `${start}-${slug2}.md`;
18435
- const file = path56.join(TODO, fileRel);
19067
+ const file = path58.join(TODO, fileRel);
18436
19068
  const held4 = locate(start) ?? locateArchived(start);
18437
- if (held4 && path56.basename(held4.target) === `${start}-${slug2}.md`) {
19069
+ if (held4 && path58.basename(held4.target) === `${start}-${slug2}.md`) {
18438
19070
  say(start);
18439
19071
  say(` ${rel(held4.target)} was already written`);
18440
19072
  return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
18441
19073
  }
18442
19074
  if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
18443
- if (fs53.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
19075
+ if (fs55.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
18444
19076
  countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
18445
19077
  const meta = { title, priority, status: "todo", blocked_by, related, modules, workflow, previews, stages, triage, source, questions };
18446
19078
  const scaffolded = !written && opts.body !== false;
18447
19079
  const body = written ?? (scaffolded ? defaultBody() : "");
18448
- fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
19080
+ fs55.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
18449
19081
  const indexed = addReadmeRef(start, title, fileRel);
18450
19082
  say(start);
18451
19083
  say(
@@ -18492,8 +19124,8 @@ function cmdUpdate(id, flags) {
18492
19124
  if (creating) die(creating, { kind: "card-being-created", id });
18493
19125
  const found2 = locate(id);
18494
19126
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
18495
- const file = found2.kind === "group" ? path56.join(found2.target, "root.md") : found2.target;
18496
- const { meta, body } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
19127
+ const file = found2.kind === "group" ? path58.join(found2.target, "root.md") : found2.target;
19128
+ const { meta, body } = parseFrontmatter(fs55.readFileSync(file, "utf8"));
18497
19129
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
18498
19130
  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");
18499
19131
  if (flags.related !== void 0 && flags.addRelated !== void 0) die("--related replaces the list and --add-related appends to it \u2014 pass one");
@@ -18567,26 +19199,26 @@ function cmdUpdate(id, flags) {
18567
19199
  meta.status = "todo";
18568
19200
  changes.push("status\u2192todo (open questions)");
18569
19201
  }
18570
- const curRel = path56.relative(TODO, file);
19202
+ const curRel = path58.relative(TODO, file);
18571
19203
  const isSubtask = found2.kind === "file" && enclosingGroupRoot(file) !== null;
18572
- let base = path56.basename(file);
19204
+ let base = path58.basename(file);
18573
19205
  if (flags.slug !== void 0) {
18574
19206
  if (found2.kind === "group") die("renaming a group root by script is not supported");
18575
19207
  base = `${id}-${slugify(flags.slug)}.md`;
18576
19208
  }
18577
- const destRel = path56.join(path56.dirname(curRel), base);
18578
- const dest = path56.join(TODO, destRel);
19209
+ const destRel = path58.join(path58.dirname(curRel), base);
19210
+ const dest = path58.join(TODO, destRel);
18579
19211
  const moving = dest !== file;
18580
- if (moving && fs53.existsSync(dest)) die(`${rel(dest)} already exists`);
18581
- fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
18582
- if (moving) fs53.renameSync(file, dest);
19212
+ if (moving && fs55.existsSync(dest)) die(`${rel(dest)} already exists`);
19213
+ fs55.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
19214
+ if (moving) fs55.renameSync(file, dest);
18583
19215
  if (isSubtask) {
18584
19216
  if (moving || changes.includes("title")) repointReadmeLink(id, curRel, destRel, meta.title);
18585
- if (moving) changes.push(`renamed \u2192 ${destRel.split(path56.sep).join("/")}`);
19217
+ if (moving) changes.push(`renamed \u2192 ${destRel.split(path58.sep).join("/")}`);
18586
19218
  } else if (moving) {
18587
19219
  stripReadmeRefs({ kind: "file", rel: curRel });
18588
19220
  addReadmeRef(id, meta.title, destRel);
18589
- changes.push(`renamed \u2192 ${destRel.split(path56.sep).join("/")}`);
19221
+ changes.push(`renamed \u2192 ${destRel.split(path58.sep).join("/")}`);
18590
19222
  } else if (changes.includes("title")) {
18591
19223
  stripReadmeRefs({ kind: "file", rel: curRel });
18592
19224
  addReadmeRef(id, meta.title, curRel);
@@ -18598,8 +19230,8 @@ function cmdUpdateQuestions(id, input) {
18598
19230
  const ops = readQuestionOps(input.ops ?? []);
18599
19231
  const found2 = locate(id);
18600
19232
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
18601
- const file = found2.kind === "group" ? path56.join(found2.target, "root.md") : found2.target;
18602
- const { meta, body } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
19233
+ const file = found2.kind === "group" ? path58.join(found2.target, "root.md") : found2.target;
19234
+ const { meta, body } = parseFrontmatter(fs55.readFileSync(file, "utf8"));
18603
19235
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
18604
19236
  if (insideRun() && ops.some((op) => op.kind === "skip" || op.kind === "unskip")) {
18605
19237
  die("only the user skips or reopens a question \u2014 a run leaves questions for them to answer");
@@ -18672,7 +19304,7 @@ function cmdUpdateQuestions(id, input) {
18672
19304
  meta.status = "todo";
18673
19305
  changes.push("status\u2192todo (open questions)");
18674
19306
  }
18675
- fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
19307
+ fs55.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
18676
19308
  for (const kind of closed2) countBoardEvent(kind);
18677
19309
  settleDelivery2(id, skipped, unskipped);
18678
19310
  say(
@@ -18747,13 +19379,13 @@ var init_config_template = __esm({
18747
19379
  });
18748
19380
 
18749
19381
  // src/lib/agent/local.ts
18750
- import fs54 from "node:fs";
18751
- import path57 from "node:path";
19382
+ import fs56 from "node:fs";
19383
+ import path59 from "node:path";
18752
19384
  function takeLocalModels(board2) {
18753
- const file = path57.join(board2, ".local.json");
19385
+ const file = path59.join(board2, ".local.json");
18754
19386
  let held4;
18755
19387
  try {
18756
- held4 = configBlock(JSON.parse(fs54.readFileSync(file, "utf8")));
19388
+ held4 = configBlock(JSON.parse(fs56.readFileSync(file, "utf8")));
18757
19389
  } catch {
18758
19390
  return {};
18759
19391
  }
@@ -18771,7 +19403,7 @@ function takeLocalModels(board2) {
18771
19403
  }
18772
19404
  if (!Object.keys(agents).length) return out;
18773
19405
  delete held4.agents;
18774
- fs54.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
19406
+ fs56.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
18775
19407
  return out;
18776
19408
  }
18777
19409
  var LOCAL_IGNORE_LINE;
@@ -18832,12 +19464,12 @@ var init_identity2 = __esm({
18832
19464
  });
18833
19465
 
18834
19466
  // src/lib/signals/migrate.ts
18835
- import fs55 from "node:fs";
18836
- import path58 from "node:path";
19467
+ import fs57 from "node:fs";
19468
+ import path60 from "node:path";
18837
19469
  function readHandled() {
18838
19470
  let text5;
18839
19471
  try {
18840
- text5 = fs55.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
19472
+ text5 = fs57.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
18841
19473
  } catch {
18842
19474
  return [];
18843
19475
  }
@@ -18854,57 +19486,57 @@ function readHandled() {
18854
19486
  return held4;
18855
19487
  }
18856
19488
  function lift(from, into) {
18857
- fs55.mkdirSync(into, { recursive: true });
18858
- fs55.renameSync(from, path58.join(into, freeName(into, path58.basename(from))));
19489
+ fs57.mkdirSync(into, { recursive: true });
19490
+ fs57.renameSync(from, path60.join(into, freeName(into, path60.basename(from))));
18859
19491
  }
18860
19492
  function repoint(dir, from, into) {
18861
19493
  let entries;
18862
19494
  try {
18863
- entries = fs55.readdirSync(dir, { withFileTypes: true });
19495
+ entries = fs57.readdirSync(dir, { withFileTypes: true });
18864
19496
  } catch {
18865
19497
  return;
18866
19498
  }
18867
19499
  for (const entry of entries) {
18868
19500
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
18869
- const file = path58.join(dir, entry.name);
18870
- const text5 = fs55.readFileSync(file, "utf8");
18871
- if (text5.includes(from)) fs55.writeFileSync(file, text5.split(from).join(into));
19501
+ const file = path60.join(dir, entry.name);
19502
+ const text5 = fs57.readFileSync(file, "utf8");
19503
+ if (text5.includes(from)) fs57.writeFileSync(file, text5.split(from).join(into));
18872
19504
  }
18873
19505
  }
18874
19506
  function dropIfEmpty2(dir) {
18875
19507
  try {
18876
- fs55.rmdirSync(dir);
19508
+ fs57.rmdirSync(dir);
18877
19509
  } catch {
18878
19510
  }
18879
19511
  }
18880
19512
  function liftInbox() {
18881
- if (!fs55.existsSync(SIGNALS_OLD_INBOX)) return;
18882
- const oldFiles = path58.join(SIGNALS_OLD_INBOX, "files");
18883
- if (fs55.existsSync(oldFiles)) {
18884
- for (const entry of fs55.readdirSync(oldFiles, { withFileTypes: true })) {
18885
- if (entry.isFile()) lift(path58.join(oldFiles, entry.name), SIGNALS_FILES);
19513
+ if (!fs57.existsSync(SIGNALS_OLD_INBOX)) return;
19514
+ const oldFiles = path60.join(SIGNALS_OLD_INBOX, "files");
19515
+ if (fs57.existsSync(oldFiles)) {
19516
+ for (const entry of fs57.readdirSync(oldFiles, { withFileTypes: true })) {
19517
+ if (entry.isFile()) lift(path60.join(oldFiles, entry.name), SIGNALS_FILES);
18886
19518
  }
18887
19519
  dropIfEmpty2(oldFiles);
18888
19520
  }
18889
19521
  const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
18890
- for (const entry of fs55.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
19522
+ for (const entry of fs57.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
18891
19523
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
18892
- const from = path58.join(SIGNALS_OLD_INBOX, entry.name);
19524
+ const from = path60.join(SIGNALS_OLD_INBOX, entry.name);
18893
19525
  const item = parse(from);
18894
19526
  if (item && held4.has(item.sourceId)) {
18895
- fs55.rmSync(from, { force: true });
19527
+ fs57.rmSync(from, { force: true });
18896
19528
  continue;
18897
19529
  }
18898
19530
  if (item) held4.add(item.sourceId);
18899
19531
  lift(from, TRIAGE);
18900
19532
  }
18901
- const wasAt = asWritten(path58.join(SIGNALS_OLD_INBOX, "files"));
19533
+ const wasAt = asWritten(path60.join(SIGNALS_OLD_INBOX, "files"));
18902
19534
  const nowAt = asWritten(SIGNALS_FILES);
18903
19535
  for (const dir of [TRIAGE, SIGNALS_ARCHIVED, SIGNALS_DISMISSED]) repoint(dir, wasAt, nowAt);
18904
19536
  dropIfEmpty2(SIGNALS_OLD_INBOX);
18905
19537
  }
18906
19538
  function liftHandled() {
18907
- if (!fs55.existsSync(SIGNALS_OLD_HANDLED)) return;
19539
+ if (!fs57.existsSync(SIGNALS_OLD_HANDLED)) return;
18908
19540
  const lines = readHandled();
18909
19541
  const held4 = /* @__PURE__ */ new Set([
18910
19542
  ...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
@@ -18914,7 +19546,7 @@ function liftHandled() {
18914
19546
  for (const { sourceId, when } of lines) {
18915
19547
  if (held4.has(sourceId)) continue;
18916
19548
  held4.add(sourceId);
18917
- fs55.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
19549
+ fs57.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
18918
19550
  const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
18919
19551
  const front = [
18920
19552
  "---",
@@ -18924,13 +19556,13 @@ function liftHandled() {
18924
19556
  "---",
18925
19557
  ""
18926
19558
  ];
18927
- fs55.writeFileSync(path58.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
19559
+ fs57.writeFileSync(path60.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
18928
19560
  `);
18929
19561
  }
18930
- fs55.rmSync(SIGNALS_OLD_HANDLED, { force: true });
19562
+ fs57.rmSync(SIGNALS_OLD_HANDLED, { force: true });
18931
19563
  }
18932
19564
  function migrateTriage() {
18933
- if (!fs55.existsSync(SIGNALS_OLD_INBOX) && !fs55.existsSync(SIGNALS_OLD_HANDLED)) return;
19565
+ if (!fs57.existsSync(SIGNALS_OLD_INBOX) && !fs57.existsSync(SIGNALS_OLD_HANDLED)) return;
18934
19566
  try {
18935
19567
  liftInbox();
18936
19568
  liftHandled();
@@ -18945,13 +19577,13 @@ var init_migrate = __esm({
18945
19577
  init_yaml();
18946
19578
  init_inbox();
18947
19579
  HANDLED_LINE = /^-\s+(.+?)\s+—\s+(.+)$/;
18948
- asWritten = (dir) => `${rel(dir).split(path58.sep).join("/")}/`;
19580
+ asWritten = (dir) => `${rel(dir).split(path60.sep).join("/")}/`;
18949
19581
  }
18950
19582
  });
18951
19583
 
18952
19584
  // src/lib/signals/add.ts
18953
- import fs56 from "node:fs";
18954
- import path59 from "node:path";
19585
+ import fs58 from "node:fs";
19586
+ import path61 from "node:path";
18955
19587
  import { createHash as createHash4 } from "node:crypto";
18956
19588
  function linkTitle(url) {
18957
19589
  let at2;
@@ -18964,7 +19596,7 @@ function linkTitle(url) {
18964
19596
  return oneLine(where) || url.slice(0, TITLE_MAX);
18965
19597
  }
18966
19598
  function asText(file) {
18967
- const ext = path59.extname(file.name).toLowerCase();
19599
+ const ext = path61.extname(file.name).toLowerCase();
18968
19600
  if (!file.type.startsWith("text/") && file.type !== "application/json" && !TEXT_EXTENSIONS.has(ext)) return null;
18969
19601
  try {
18970
19602
  const text5 = new TextDecoder("utf-8", { fatal: true }).decode(file.data);
@@ -18974,9 +19606,9 @@ function asText(file) {
18974
19606
  }
18975
19607
  }
18976
19608
  function fileName2(name, data) {
18977
- const base = path59.basename(name);
18978
- const ext = path59.extname(base).toLowerCase().slice(0, 12);
18979
- const word = path59.basename(base, path59.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
19609
+ const base = path61.basename(name);
19610
+ const ext = path61.extname(base).toLowerCase().slice(0, 12);
19611
+ const word = path61.basename(base, path61.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
18980
19612
  const hash2 = createHash4("sha256").update(data).digest("hex").slice(0, 8);
18981
19613
  return `${word}-${hash2}${ext}`;
18982
19614
  }
@@ -18985,20 +19617,20 @@ function addToInbox(drop) {
18985
19617
  const typed = (drop.text ?? "").trim();
18986
19618
  const file = drop.file;
18987
19619
  if (!typed && !file) return { ok: false, error: "nothing to add \u2014 paste a link or some text, or drop a file." };
18988
- if (file && file.data.length === 0) return { ok: false, error: `${path59.basename(file.name)} is empty.` };
19620
+ if (file && file.data.length === 0) return { ok: false, error: `${path61.basename(file.name)} is empty.` };
18989
19621
  if (file && file.data.length > MAX_BYTES) {
18990
- return { ok: false, error: `${path59.basename(file.name)} is over ${MAX_BYTES / 1024 / 1024} MB \u2014 too big for the board.` };
19622
+ return { ok: false, error: `${path61.basename(file.name)} is over ${MAX_BYTES / 1024 / 1024} MB \u2014 too big for the board.` };
18991
19623
  }
18992
- const read4 = describe(typed, file);
18993
- const keep2 = read4.keep;
19624
+ const read5 = describe(typed, file);
19625
+ const keep2 = read5.keep;
18994
19626
  const said3 = drop.source?.trim() ?? "";
18995
19627
  const hit = said3 ? matchSourceType(said3) : "";
18996
19628
  const kept2 = said3 && !hit ? metaPair("source", said3) : null;
18997
19629
  const incoming = {
18998
- ...read4.incoming,
19630
+ ...read5.incoming,
18999
19631
  ...drop.title?.trim() ? { title: oneLine(drop.title) } : {},
19000
19632
  ...hit ? { sourceType: hit } : {},
19001
- ...kept2 ? { meta: [kept2, ...read4.incoming.meta] } : {},
19633
+ ...kept2 ? { meta: [kept2, ...read5.incoming.meta] } : {},
19002
19634
  ...drop.agent ? { agent: drop.agent } : {},
19003
19635
  ...drop.workflow ? { workflow: drop.workflow } : {}
19004
19636
  };
@@ -19009,8 +19641,8 @@ ${incoming.summary}`);
19009
19641
  if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
19010
19642
  try {
19011
19643
  if (keep2) {
19012
- fs56.mkdirSync(SIGNALS_FILES, { recursive: true });
19013
- fs56.writeFileSync(keep2.at, keep2.data);
19644
+ fs58.mkdirSync(SIGNALS_FILES, { recursive: true });
19645
+ fs58.writeFileSync(keep2.at, keep2.data);
19014
19646
  }
19015
19647
  return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
19016
19648
  } catch (e2) {
@@ -19024,7 +19656,7 @@ function describe(typed, file) {
19024
19656
  return only ? [only] : [];
19025
19657
  };
19026
19658
  if (file) {
19027
- const name = path59.basename(file.name);
19659
+ const name = path61.basename(file.name);
19028
19660
  const text5 = asText(file);
19029
19661
  const note = typed ? `
19030
19662
 
@@ -19036,7 +19668,7 @@ ${typed}` : "";
19036
19668
  const at2 = keepAt(file);
19037
19669
  return {
19038
19670
  incoming: {
19039
- title: path59.basename(name, path59.extname(name)) || name,
19671
+ title: path61.basename(name, path61.extname(name)) || name,
19040
19672
  summary: `${name} \u2014 ${boardRel2(at2)}${note}`,
19041
19673
  ...named2
19042
19674
  },
@@ -19074,73 +19706,73 @@ var init_add = __esm({
19074
19706
  MAX_BYTES = 25 * 1024 * 1024;
19075
19707
  TITLE_MAX = 120;
19076
19708
  TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".markdown", ".txt", ".text", ".csv", ".json", ".yml", ".yaml", ".log"]);
19077
- boardRel2 = (file) => rel(file).split(path59.sep).join("/");
19709
+ boardRel2 = (file) => rel(file).split(path61.sep).join("/");
19078
19710
  oneLine = (text5) => {
19079
19711
  const first = text5.split("\n").find((line) => line.trim()) ?? "";
19080
19712
  const clean = first.replace(/^#+\s*/, "").trim();
19081
19713
  return clean.length > TITLE_MAX ? `${clean.slice(0, TITLE_MAX - 1).trimEnd()}\u2026` : clean;
19082
19714
  };
19083
- keepAt = (file) => path59.join(SIGNALS_FILES, fileName2(file.name, file.data));
19715
+ keepAt = (file) => path61.join(SIGNALS_FILES, fileName2(file.name, file.data));
19084
19716
  }
19085
19717
  });
19086
19718
 
19087
19719
  // src/lib/recurring.ts
19088
- import fs57 from "node:fs";
19089
- import path60 from "node:path";
19720
+ import fs59 from "node:fs";
19721
+ import path62 from "node:path";
19090
19722
  function migratePruneMemoryCard() {
19091
19723
  const dir = recurringDir();
19092
19724
  let names3;
19093
19725
  try {
19094
- names3 = fs57.readdirSync(dir);
19726
+ names3 = fs59.readdirSync(dir);
19095
19727
  } catch {
19096
19728
  return null;
19097
19729
  }
19098
19730
  const name = names3.find((entry) => entry.endsWith(`-${PRUNE_SLUG}.md`));
19099
19731
  if (!name) return null;
19100
- const file = path60.join(dir, name);
19732
+ const file = path62.join(dir, name);
19101
19733
  try {
19102
- const { meta } = parseFrontmatter(fs57.readFileSync(file, "utf8"));
19734
+ const { meta } = parseFrontmatter(fs59.readFileSync(file, "utf8"));
19103
19735
  const cadence = meta?.cadence;
19104
19736
  if (typeof cadence === "string") adoptMemoryPruneCadence(cadence);
19105
19737
  } catch {
19106
19738
  }
19107
- fs57.rmSync(file, { force: true });
19739
+ fs59.rmSync(file, { force: true });
19108
19740
  return rel(file);
19109
19741
  }
19110
19742
  function legacyCards() {
19111
19743
  const dir = recurringDir();
19112
- if (!fs57.existsSync(dir)) return [];
19744
+ if (!fs59.existsSync(dir)) return [];
19113
19745
  const cards = [];
19114
- for (const entry of fs57.readdirSync(dir, { withFileTypes: true })) {
19746
+ for (const entry of fs59.readdirSync(dir, { withFileTypes: true })) {
19115
19747
  const id = idPrefix(entry.name);
19116
19748
  if (id === null) continue;
19117
- const full = path60.join(dir, entry.name);
19749
+ const full = path62.join(dir, entry.name);
19118
19750
  const slug2 = entry.name.replace(/\.md$/, "").replace(/^\d+-?/, "");
19119
19751
  if (entry.isFile() && entry.name.endsWith(".md")) cards.push({ id, slug: slug2, file: full });
19120
- else if (entry.isDirectory() && fs57.existsSync(path60.join(full, "root.md"))) {
19121
- cards.push({ id, slug: slug2, file: path60.join(full, "root.md"), folder: full });
19752
+ else if (entry.isDirectory() && fs59.existsSync(path62.join(full, "root.md"))) {
19753
+ cards.push({ id, slug: slug2, file: path62.join(full, "root.md"), folder: full });
19122
19754
  }
19123
19755
  }
19124
19756
  return cards.sort((a2, b2) => a2.id - b2.id);
19125
19757
  }
19126
19758
  function mergeInto2(from, to, skip = []) {
19127
- fs57.mkdirSync(to, { recursive: true });
19128
- for (const entry of fs57.readdirSync(from, { withFileTypes: true })) {
19759
+ fs59.mkdirSync(to, { recursive: true });
19760
+ for (const entry of fs59.readdirSync(from, { withFileTypes: true })) {
19129
19761
  if (skip.includes(entry.name)) continue;
19130
- const source = path60.join(from, entry.name);
19131
- const target = path60.join(to, entry.name);
19132
- if (!fs57.existsSync(target)) fs57.renameSync(source, target);
19133
- else if (entry.isDirectory() && fs57.statSync(target).isDirectory()) mergeInto2(source, target);
19762
+ const source = path62.join(from, entry.name);
19763
+ const target = path62.join(to, entry.name);
19764
+ if (!fs59.existsSync(target)) fs59.renameSync(source, target);
19765
+ else if (entry.isDirectory() && fs59.statSync(target).isDirectory()) mergeInto2(source, target);
19134
19766
  }
19135
- if (isEmpty(from)) fs57.rmSync(from, { recursive: true, force: true });
19767
+ if (isEmpty(from)) fs59.rmSync(from, { recursive: true, force: true });
19136
19768
  }
19137
19769
  function moveSideFolders() {
19138
19770
  const dir = recurringDir();
19139
- for (const entry of fs57.readdirSync(dir, { withFileTypes: true })) {
19771
+ for (const entry of fs59.readdirSync(dir, { withFileTypes: true })) {
19140
19772
  if (!entry.isDirectory() || idPrefix(entry.name) !== null) continue;
19141
- const from = path60.join(dir, entry.name);
19142
- if (isEmpty(from)) fs57.rmSync(from, { recursive: true, force: true });
19143
- else mergeInto2(from, path60.join(AGENTS, entry.name));
19773
+ const from = path62.join(dir, entry.name);
19774
+ if (isEmpty(from)) fs59.rmSync(from, { recursive: true, force: true });
19775
+ else mergeInto2(from, path62.join(AGENTS, entry.name));
19144
19776
  }
19145
19777
  }
19146
19778
  function sections(body) {
@@ -19190,8 +19822,8 @@ function agentName(card, text5) {
19190
19822
  const known2 = /* @__PURE__ */ new Set([...specAgentCatalog().agents.map((a2) => a2.name), ...ROLE_NAMES]);
19191
19823
  for (const name of [slug2, `${slug2}-${card.id}`]) {
19192
19824
  if (!AGENT_NAME.test(name)) continue;
19193
- const file = path60.join(AGENTS, name, AGENT_FILE3);
19194
- const written = fs57.existsSync(file) ? fs57.readFileSync(file, "utf8") : null;
19825
+ const file = path62.join(AGENTS, name, AGENT_FILE3);
19826
+ const written = fs59.existsSync(file) ? fs59.readFileSync(file, "utf8") : null;
19195
19827
  if (written === text5(name)) return name;
19196
19828
  if (written === null && !known2.has(name)) return name;
19197
19829
  }
@@ -19208,11 +19840,11 @@ ${q3.options.map((o3) => `- ${o3}`).join("\n")}` : "";
19208
19840
  function removeCard(card) {
19209
19841
  dropCrossRefs(card.id);
19210
19842
  const target = card.folder ?? card.file;
19211
- stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path60.relative(TODO, target).split(path60.sep).join("/") });
19212
- fs57.rmSync(target, { recursive: true, force: true });
19843
+ stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path62.relative(TODO, target).split(path62.sep).join("/") });
19844
+ fs59.rmSync(target, { recursive: true, force: true });
19213
19845
  }
19214
19846
  function migrateCard(card) {
19215
- const { meta, body } = parseFrontmatter(fs57.readFileSync(card.file, "utf8"));
19847
+ const { meta, body } = parseFrontmatter(fs59.readFileSync(card.file, "utf8"));
19216
19848
  if (!meta) throw new Error("its frontmatter cannot be read");
19217
19849
  const raw = meta;
19218
19850
  const said3 = (key) => typeof raw[key] === "string" ? raw[key].trim() : "";
@@ -19222,19 +19854,19 @@ function migrateCard(card) {
19222
19854
  if (!flow) throw new Error("this board has no workflow to put it in");
19223
19855
  const text5 = (name2) => agentText(name2, meta.title || card.slug, body);
19224
19856
  const name = agentName(card, text5);
19225
- const dir = path60.join(AGENTS, name);
19226
- const file = path60.join(dir, AGENT_FILE3);
19227
- const madeDir = !fs57.existsSync(dir);
19228
- const wrote = !fs57.existsSync(file);
19857
+ const dir = path62.join(AGENTS, name);
19858
+ const file = path62.join(dir, AGENT_FILE3);
19859
+ const madeDir = !fs59.existsSync(dir);
19860
+ const wrote = !fs59.existsSync(file);
19229
19861
  try {
19230
- fs57.mkdirSync(dir, { recursive: true });
19231
- if (wrote) fs57.writeFileSync(file, text5(name));
19862
+ fs59.mkdirSync(dir, { recursive: true });
19863
+ if (wrote) fs59.writeFileSync(file, text5(name));
19232
19864
  const adopted = adoptWorkflowScheduled(flow.id, name, { cadence, lastRun });
19233
19865
  if (!adopted.ok) throw new Error(adopted.error);
19234
19866
  questionsToTriage(meta, name);
19235
19867
  } catch (e2) {
19236
- if (madeDir) fs57.rmSync(dir, { recursive: true, force: true });
19237
- else if (wrote) fs57.rmSync(file, { force: true });
19868
+ if (madeDir) fs59.rmSync(dir, { recursive: true, force: true });
19869
+ else if (wrote) fs59.rmSync(file, { force: true });
19238
19870
  throw e2;
19239
19871
  }
19240
19872
  if (card.folder) mergeInto2(card.folder, dir, ["root.md"]);
@@ -19244,7 +19876,7 @@ function migrateCard(card) {
19244
19876
  function migrateRecurringCards() {
19245
19877
  const done2 = { agents: [], removed: [], failed: [] };
19246
19878
  const dir = recurringDir();
19247
- if (!fs57.existsSync(dir)) return done2;
19879
+ if (!fs59.existsSync(dir)) return done2;
19248
19880
  migratePruneMemoryCard();
19249
19881
  moveSideFolders();
19250
19882
  for (const card of legacyCards()) {
@@ -19257,7 +19889,7 @@ function migrateRecurringCards() {
19257
19889
  done2.failed.push({ card: rel(card.file), why: e2 instanceof Error ? e2.message : String(e2) });
19258
19890
  }
19259
19891
  }
19260
- if (isEmpty(dir)) fs57.rmSync(dir, { recursive: true, force: true });
19892
+ if (isEmpty(dir)) fs59.rmSync(dir, { recursive: true, force: true });
19261
19893
  return done2;
19262
19894
  }
19263
19895
  function recurringMigrationLines(done2) {
@@ -19290,14 +19922,14 @@ var init_recurring = __esm({
19290
19922
  PRUNE_SLUG = "prune-the-memory";
19291
19923
  FETCH_SLUG = "fetch-triage-items";
19292
19924
  AGENT_FILE3 = "AGENT.md";
19293
- recurringDir = () => path60.join(TODO, LEGACY_RECURRING);
19294
- isEmpty = (dir) => fs57.readdirSync(dir).every((name) => name === ".DS_Store");
19925
+ recurringDir = () => path62.join(TODO, LEGACY_RECURRING);
19926
+ isEmpty = (dir) => fs59.readdirSync(dir).every((name) => name === ".DS_Store");
19295
19927
  SECTION = /^##\s+(.+?)\s*$/;
19296
19928
  }
19297
19929
  });
19298
19930
 
19299
19931
  // src/commands/init.ts
19300
- import fs58 from "node:fs";
19932
+ import fs60 from "node:fs";
19301
19933
  function boardReadme() {
19302
19934
  return `# Board
19303
19935
 
@@ -19310,20 +19942,20 @@ _(none)_
19310
19942
  `;
19311
19943
  }
19312
19944
  function writeConfigIfMissing() {
19313
- if (fs58.existsSync(CONFIG)) return false;
19314
- fs58.mkdirSync(KANBAN, { recursive: true });
19315
- fs58.writeFileSync(CONFIG, CONFIG_TEMPLATE);
19945
+ if (fs60.existsSync(CONFIG)) return false;
19946
+ fs60.mkdirSync(KANBAN, { recursive: true });
19947
+ fs60.writeFileSync(CONFIG, CONFIG_TEMPLATE);
19316
19948
  return true;
19317
19949
  }
19318
19950
  function writeModulesIfMissing() {
19319
- if (fs58.existsSync(MODULES_MD)) return false;
19320
- fs58.mkdirSync(KANBAN, { recursive: true });
19321
- fs58.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
19951
+ if (fs60.existsSync(MODULES_MD)) return false;
19952
+ fs60.mkdirSync(KANBAN, { recursive: true });
19953
+ fs60.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
19322
19954
  return true;
19323
19955
  }
19324
19956
  function writeGitignoreIfMissing() {
19325
- fs58.mkdirSync(KANBAN, { recursive: true });
19326
- const text5 = fs58.existsSync(KANBAN_GITIGNORE) ? fs58.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
19957
+ fs60.mkdirSync(KANBAN, { recursive: true });
19958
+ const text5 = fs60.existsSync(KANBAN_GITIGNORE) ? fs60.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
19327
19959
  const has = (rule) => text5.split("\n").some((line) => line.trim() === rule.line);
19328
19960
  const missing = IGNORE_RULES.filter((rule) => !has(rule));
19329
19961
  if (!missing.length) return false;
@@ -19331,37 +19963,37 @@ function writeGitignoreIfMissing() {
19331
19963
  ${rule.line}
19332
19964
  `).join("");
19333
19965
  const separator = !text5 || text5.endsWith("\n") ? "" : "\n";
19334
- fs58.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
19966
+ fs60.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
19335
19967
  return true;
19336
19968
  }
19337
19969
  function writeSkeletonIfMissing() {
19338
19970
  const added = [];
19339
- if (!fs58.existsSync(TODO)) {
19340
- fs58.mkdirSync(TODO, { recursive: true });
19971
+ if (!fs60.existsSync(TODO)) {
19972
+ fs60.mkdirSync(TODO, { recursive: true });
19341
19973
  added.push(`${rel(TODO)}/`);
19342
19974
  }
19343
- if (!fs58.existsSync(README)) {
19344
- fs58.writeFileSync(README, boardReadme());
19975
+ if (!fs60.existsSync(README)) {
19976
+ fs60.writeFileSync(README, boardReadme());
19345
19977
  added.push(rel(README));
19346
19978
  }
19347
19979
  return added;
19348
19980
  }
19349
19981
  function retireReleases() {
19350
19982
  const done2 = [];
19351
- if (fs58.existsSync(RELEASES)) {
19352
- fs58.rmSync(RELEASES);
19983
+ if (fs60.existsSync(RELEASES)) {
19984
+ fs60.rmSync(RELEASES);
19353
19985
  done2.push(`deleted ${rel(RELEASES)}`);
19354
19986
  }
19355
19987
  let cards = 0;
19356
19988
  for (const dir of [TODO, ARCHIVE]) {
19357
- if (!fs58.existsSync(dir)) continue;
19989
+ if (!fs60.existsSync(dir)) continue;
19358
19990
  for (const file of walkMd(dir)) {
19359
- const text5 = fs58.readFileSync(file, "utf8");
19991
+ const text5 = fs60.readFileSync(file, "utf8");
19360
19992
  const end2 = text5.startsWith("---\n") ? text5.indexOf("\n---", 3) : -1;
19361
19993
  if (end2 < 0) continue;
19362
19994
  const head2 = text5.slice(0, end2).replace(/\nrelease:[^\n]*/, "");
19363
19995
  if (head2.length === end2) continue;
19364
- fs58.writeFileSync(file, head2 + text5.slice(end2));
19996
+ fs60.writeFileSync(file, head2 + text5.slice(end2));
19365
19997
  cards++;
19366
19998
  }
19367
19999
  }
@@ -19369,7 +20001,7 @@ function retireReleases() {
19369
20001
  return done2.join(", ");
19370
20002
  }
19371
20003
  function cmdInit() {
19372
- if (fs58.existsSync(KANBAN)) {
20004
+ if (fs60.existsSync(KANBAN)) {
19373
20005
  const added = [
19374
20006
  ...writeSkeletonIfMissing(),
19375
20007
  writeConfigIfMissing() && rel(CONFIG),
@@ -19404,8 +20036,8 @@ function cmdInit() {
19404
20036
  }
19405
20037
  return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
19406
20038
  }
19407
- fs58.mkdirSync(TODO, { recursive: true });
19408
- fs58.writeFileSync(README, boardReadme());
20039
+ fs60.mkdirSync(TODO, { recursive: true });
20040
+ fs60.writeFileSync(README, boardReadme());
19409
20041
  writeConfigIfMissing();
19410
20042
  scaffoldProjectMemory();
19411
20043
  writeModulesIfMissing();
@@ -19494,25 +20126,25 @@ var init_scheduled = __esm({
19494
20126
  });
19495
20127
 
19496
20128
  // src/lib/card-age.ts
19497
- import fs59 from "node:fs";
19498
- import path61 from "node:path";
20129
+ import fs61 from "node:fs";
20130
+ import path63 from "node:path";
19499
20131
  function staleAfterIn(config) {
19500
20132
  const days = Number(LINE.exec(config)?.[1]);
19501
20133
  return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
19502
20134
  }
19503
20135
  function staleAfter() {
19504
- if (!fs59.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
19505
- return staleAfterIn(fs59.readFileSync(CONFIG, "utf8"));
20136
+ if (!fs61.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
20137
+ return staleAfterIn(fs61.readFileSync(CONFIG, "utf8"));
19506
20138
  }
19507
20139
  function todoPathspec(top) {
19508
- const from = path61.relative(real(top), real(TODO));
19509
- if (!from || from.startsWith("..") || path61.isAbsolute(from)) return null;
19510
- return from.split(path61.sep).join("/");
20140
+ const from = path63.relative(real(top), real(TODO));
20141
+ if (!from || from.startsWith("..") || path63.isAbsolute(from)) return null;
20142
+ return from.split(path63.sep).join("/");
19511
20143
  }
19512
20144
  function cardFile2(spec, printed) {
19513
20145
  const p2 = unquotePath(printed);
19514
20146
  if (!p2.startsWith(`${spec}/`)) return null;
19515
- return path61.join(TODO, ...p2.slice(spec.length + 1).split("/"));
20147
+ return path63.join(TODO, ...p2.slice(spec.length + 1).split("/"));
19516
20148
  }
19517
20149
  function dirtyCards(top, spec) {
19518
20150
  const out = git(["status", "--porcelain", "--untracked-files=all", "--", spec], top);
@@ -19559,9 +20191,9 @@ var init_card_age = __esm({
19559
20191
  gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
19560
20192
  real = (p2) => {
19561
20193
  try {
19562
- return fs59.realpathSync(p2);
20194
+ return fs61.realpathSync(p2);
19563
20195
  } catch {
19564
- return path61.resolve(p2);
20196
+ return path63.resolve(p2);
19565
20197
  }
19566
20198
  };
19567
20199
  unquotePath = (line) => {
@@ -19596,8 +20228,8 @@ var init_card_holds = __esm({
19596
20228
  });
19597
20229
 
19598
20230
  // src/commands/list.ts
19599
- import fs60 from "node:fs";
19600
- import path62 from "node:path";
20231
+ import fs62 from "node:fs";
20232
+ import path64 from "node:path";
19601
20233
  function summaryLine(body) {
19602
20234
  const lines = body.split("\n");
19603
20235
  let i = 0;
@@ -19613,13 +20245,13 @@ function summaryLine(body) {
19613
20245
  function openRows() {
19614
20246
  const rows = [];
19615
20247
  for (const file of walkMd(TODO)) {
19616
- const base = path62.basename(file);
20248
+ const base = path64.basename(file);
19617
20249
  if (base === "README.md") continue;
19618
20250
  const isRoot = base === "root.md";
19619
- const id = isRoot ? idPrefix(path62.basename(path62.dirname(file))) : idPrefix(base);
20251
+ const id = isRoot ? idPrefix(path64.basename(path64.dirname(file))) : idPrefix(base);
19620
20252
  if (id == null) continue;
19621
- if (isLegacyRecurring(path62.relative(TODO, file))) continue;
19622
- const { meta, body } = parseFrontmatter(fs60.readFileSync(file, "utf8"));
20253
+ if (isLegacyRecurring(path64.relative(TODO, file))) continue;
20254
+ const { meta, body } = parseFrontmatter(fs62.readFileSync(file, "utf8"));
19623
20255
  rows.push({
19624
20256
  id,
19625
20257
  file,
@@ -19661,15 +20293,15 @@ function cmdStale(rows, all2, scope, mod) {
19661
20293
  }
19662
20294
  function archivedFiles() {
19663
20295
  const files2 = /* @__PURE__ */ new Map();
19664
- if (!fs60.existsSync(ARCHIVE)) return files2;
20296
+ if (!fs62.existsSync(ARCHIVE)) return files2;
19665
20297
  for (const file of walkMd(ARCHIVE)) {
19666
- const id = idPrefix(path62.basename(file));
20298
+ const id = idPrefix(path64.basename(file));
19667
20299
  if (id !== null) files2.set(id, file);
19668
20300
  }
19669
20301
  for (const dir of walkDirs(ARCHIVE)) {
19670
- const id = idPrefix(path62.basename(dir));
19671
- const root2 = path62.join(dir, "root.md");
19672
- if (id !== null && fs60.existsSync(root2)) files2.set(id, root2);
20302
+ const id = idPrefix(path64.basename(dir));
20303
+ const root2 = path64.join(dir, "root.md");
20304
+ if (id !== null && fs62.existsSync(root2)) files2.set(id, root2);
19673
20305
  }
19674
20306
  return files2;
19675
20307
  }
@@ -19780,14 +20412,14 @@ var init_list = __esm({
19780
20412
  });
19781
20413
 
19782
20414
  // src/commands/misc.ts
19783
- import fs61 from "node:fs";
19784
- import path63 from "node:path";
20415
+ import fs63 from "node:fs";
20416
+ import path65 from "node:path";
19785
20417
  function extractOldMeta(text5, file) {
19786
20418
  const grab = (re3) => {
19787
20419
  const m = text5.match(re3);
19788
20420
  return m ? m[1].trim() : null;
19789
20421
  };
19790
- const title = grab(/^#\s+(.+)$/m) || slugify(path63.basename(file, ".md").replace(/^\d+-/, "")).replace(/-/g, " ");
20422
+ const title = grab(/^#\s+(.+)$/m) || slugify(path65.basename(file, ".md").replace(/^\d+-/, "")).replace(/-/g, " ");
19791
20423
  const norm = (raw) => {
19792
20424
  const v = (raw || "").toLowerCase();
19793
20425
  return LEVELS.includes(v) ? v : "med";
@@ -19814,11 +20446,11 @@ function stripOldHeader(text5) {
19814
20446
  }
19815
20447
  function cmdMigrate(opts) {
19816
20448
  const dry = opts.dryRun === true;
19817
- const files2 = walkMd(TODO).filter((f2) => path63.basename(f2) !== "README.md");
20449
+ const files2 = walkMd(TODO).filter((f2) => path65.basename(f2) !== "README.md");
19818
20450
  let changed = 0;
19819
20451
  let skipped = 0;
19820
20452
  for (const file of files2) {
19821
- const text5 = fs61.readFileSync(file, "utf8");
20453
+ const text5 = fs63.readFileSync(file, "utf8");
19822
20454
  if (text5.trimStart().startsWith("---")) {
19823
20455
  skipped++;
19824
20456
  continue;
@@ -19827,7 +20459,7 @@ function cmdMigrate(opts) {
19827
20459
  const out = serializeFrontmatter(meta) + "\n\n" + stripOldHeader(text5).replace(/^\n+/, "");
19828
20460
  if (dry) say(`would migrate ${rel(file)} (priority=${meta.priority})`);
19829
20461
  else {
19830
- fs61.writeFileSync(file, out.endsWith("\n") ? out : out + "\n");
20462
+ fs63.writeFileSync(file, out.endsWith("\n") ? out : out + "\n");
19831
20463
  say(`migrated ${rel(file)}`);
19832
20464
  }
19833
20465
  changed++;
@@ -19848,8 +20480,8 @@ var init_misc = __esm({
19848
20480
  });
19849
20481
 
19850
20482
  // src/lib/card-sources.ts
19851
- import fs62 from "node:fs";
19852
- import path64 from "node:path";
20483
+ import fs64 from "node:fs";
20484
+ import path66 from "node:path";
19853
20485
  function planById(id) {
19854
20486
  const found2 = readPlan(`plans/${id}-.md`);
19855
20487
  return found2?.text.trim() ? found2 : null;
@@ -19859,8 +20491,8 @@ function cardLink(id) {
19859
20491
  const found2 = open3 ?? locateArchived(id);
19860
20492
  if (!found2) return null;
19861
20493
  try {
19862
- const file = found2.kind === "group" ? path64.join(found2.target, "root.md") : found2.target;
19863
- const title = parseFrontmatter(fs62.readFileSync(file, "utf8")).meta?.title ?? "";
20494
+ const file = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
20495
+ const title = parseFrontmatter(fs64.readFileSync(file, "utf8")).meta?.title ?? "";
19864
20496
  return { kind: "card", ref: String(id), title, ...open3 ? {} : { archived: true } };
19865
20497
  } catch {
19866
20498
  return null;
@@ -19885,7 +20517,7 @@ function link(ref, items) {
19885
20517
  if (ref.kind === "plan") return planLink(ref.id);
19886
20518
  if (ref.kind === "card") return cardLink(ref.id);
19887
20519
  if (ref.kind === "url") return urlLink(ref.url);
19888
- const item = items().find((signal2) => path64.basename(signal2.relPath) === ref.file);
20520
+ const item = items().find((signal2) => path66.basename(signal2.relPath) === ref.file);
19889
20521
  return item ? itemLink(item) : null;
19890
20522
  }
19891
20523
  function cardSources(meta, body) {
@@ -19926,12 +20558,12 @@ var init_card_sources = __esm({
19926
20558
  });
19927
20559
 
19928
20560
  // src/lib/view/read.ts
19929
- import fs63 from "node:fs";
19930
- import path65 from "node:path";
20561
+ import fs65 from "node:fs";
20562
+ import path67 from "node:path";
19931
20563
  function readCard(file, relFromTodo) {
19932
- const id = idPrefix(path65.basename(relFromTodo));
20564
+ const id = idPrefix(path67.basename(relFromTodo));
19933
20565
  if (id === null) {
19934
- const parts = relFromTodo.split(path65.sep);
20566
+ const parts = relFromTodo.split(path67.sep);
19935
20567
  const folderId = idPrefix(parts[parts.length - 2] || "");
19936
20568
  if (folderId === null) return null;
19937
20569
  return buildCard(folderId, file, relFromTodo);
@@ -19939,10 +20571,10 @@ function readCard(file, relFromTodo) {
19939
20571
  return buildCard(id, file, relFromTodo);
19940
20572
  }
19941
20573
  function buildCard(id, file, relFromTodo) {
19942
- const text5 = fs63.readFileSync(file, "utf8");
20574
+ const text5 = fs65.readFileSync(file, "utf8");
19943
20575
  const { meta, body } = parseFrontmatter(text5);
19944
20576
  if (!meta) return null;
19945
- const relPath = relFromTodo.split(path65.sep).join("/");
20577
+ const relPath = relFromTodo.split(path67.sep).join("/");
19946
20578
  const flow = workflowFor(meta.workflow);
19947
20579
  const plan = !!meta.workflow && archivesOnApproval(flow);
19948
20580
  const stages = cardStages(meta, flow).length;
@@ -19951,7 +20583,7 @@ function buildCard(id, file, relFromTodo) {
19951
20583
  // Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
19952
20584
  // read here and a card read by the contract agree on what version this is.
19953
20585
  revision: revisionOf(text5),
19954
- updatedAt: fs63.statSync(file).mtime.toISOString(),
20586
+ updatedAt: fs65.statSync(file).mtime.toISOString(),
19955
20587
  relPath,
19956
20588
  title: meta.title,
19957
20589
  priority: meta.priority,
@@ -19972,22 +20604,22 @@ function buildCard(id, file, relFromTodo) {
19972
20604
  };
19973
20605
  }
19974
20606
  function readGroup2(folderName) {
19975
- const groupDir = path65.join(TODO, folderName);
19976
- const rootFile = path65.join(groupDir, "root.md");
19977
- if (!fs63.existsSync(rootFile)) return null;
19978
- const root2 = readCard(rootFile, path65.join(folderName, "root.md"));
20607
+ const groupDir = path67.join(TODO, folderName);
20608
+ const rootFile = path67.join(groupDir, "root.md");
20609
+ if (!fs65.existsSync(rootFile)) return null;
20610
+ const root2 = readCard(rootFile, path67.join(folderName, "root.md"));
19979
20611
  if (!root2) return null;
19980
20612
  root2.isGroup = true;
19981
20613
  const { total, resolved: resolved2 } = subtaskLines(root2.body);
19982
20614
  root2.subtaskLines = { total, resolved: resolved2 };
19983
20615
  const subCards = [];
19984
20616
  const recurse = (dir, relDir) => {
19985
- for (const entry of fs63.readdirSync(dir, { withFileTypes: true })) {
19986
- const childRel = path65.join(relDir, entry.name);
20617
+ for (const entry of fs65.readdirSync(dir, { withFileTypes: true })) {
20618
+ const childRel = path67.join(relDir, entry.name);
19987
20619
  if (entry.isDirectory()) {
19988
- recurse(path65.join(dir, entry.name), childRel);
20620
+ recurse(path67.join(dir, entry.name), childRel);
19989
20621
  } else if (entry.name.endsWith(".md") && entry.name !== "README.md" && entry.name !== "root.md") {
19990
- const c2 = readCard(path65.join(dir, entry.name), childRel);
20622
+ const c2 = readCard(path67.join(dir, entry.name), childRel);
19991
20623
  if (c2) {
19992
20624
  c2.parent = { id: root2.id, title: root2.title };
19993
20625
  subCards.push(c2);
@@ -20008,12 +20640,12 @@ function readGroup2(folderName) {
20008
20640
  return { root: root2, subCards };
20009
20641
  }
20010
20642
  function standaloneCards(dirRel) {
20011
- const dir = dirRel ? path65.join(TODO, dirRel) : TODO;
20012
- if (!fs63.existsSync(dir)) return [];
20643
+ const dir = dirRel ? path67.join(TODO, dirRel) : TODO;
20644
+ if (!fs65.existsSync(dir)) return [];
20013
20645
  const cards = [];
20014
- for (const entry of fs63.readdirSync(dir, { withFileTypes: true })) {
20646
+ for (const entry of fs65.readdirSync(dir, { withFileTypes: true })) {
20015
20647
  if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
20016
- const c2 = readCard(path65.join(dir, entry.name), path65.join(dirRel, entry.name));
20648
+ const c2 = readCard(path67.join(dir, entry.name), path67.join(dirRel, entry.name));
20017
20649
  if (c2) cards.push(c2);
20018
20650
  }
20019
20651
  }
@@ -20025,7 +20657,7 @@ function collectCards() {
20025
20657
  const top = standaloneCards("");
20026
20658
  board2.push(...top);
20027
20659
  every.push(...top);
20028
- for (const entry of fs63.readdirSync(TODO, { withFileTypes: true })) {
20660
+ for (const entry of fs65.readdirSync(TODO, { withFileTypes: true })) {
20029
20661
  if (!entry.isDirectory()) continue;
20030
20662
  if (isGroupFolder(entry.name)) {
20031
20663
  const g3 = readGroup2(entry.name);
@@ -20057,7 +20689,7 @@ function findCard(id) {
20057
20689
  }
20058
20690
  function attachSources(card) {
20059
20691
  try {
20060
- const { meta, body } = parseFrontmatter(fs63.readFileSync(path65.join(TODO, card.relPath), "utf8"));
20692
+ const { meta, body } = parseFrontmatter(fs65.readFileSync(path67.join(TODO, card.relPath), "utf8"));
20061
20693
  const sources2 = meta ? cardSources(meta, body) : [];
20062
20694
  if (sources2.length) card.sources = sources2;
20063
20695
  } catch {
@@ -20162,10 +20794,10 @@ var init_read = __esm({
20162
20794
  });
20163
20795
 
20164
20796
  // src/lib/group-close.ts
20165
- import fs64 from "node:fs";
20797
+ import fs66 from "node:fs";
20166
20798
  function groupCloses(rootFile) {
20167
20799
  try {
20168
- return groupCloseOf(fs64.readFileSync(rootFile, "utf8"));
20800
+ return groupCloseOf(fs66.readFileSync(rootFile, "utf8"));
20169
20801
  } catch {
20170
20802
  return false;
20171
20803
  }
@@ -20178,12 +20810,12 @@ var init_group_close = __esm({
20178
20810
  });
20179
20811
 
20180
20812
  // src/commands/remove.ts
20181
- import fs65 from "node:fs";
20182
- import path66 from "node:path";
20813
+ import fs67 from "node:fs";
20814
+ import path68 from "node:path";
20183
20815
  function leavingIds(id, found2) {
20184
20816
  const ids = /* @__PURE__ */ new Set([id]);
20185
20817
  if (found2.kind === "group") {
20186
- const names3 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f2) => path66.basename(f2));
20818
+ const names3 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f2) => path68.basename(f2));
20187
20819
  for (const name of names3) {
20188
20820
  const n = idPrefix(name);
20189
20821
  if (n !== null) ids.add(n);
@@ -20195,10 +20827,10 @@ function findMentions(ids) {
20195
20827
  const hits = [];
20196
20828
  const re3 = new RegExp(ids.map((id) => `#${id}(?!\\d)`).join("|"));
20197
20829
  for (const dir of [TODO, MEMORY]) {
20198
- if (!fs65.existsSync(dir)) continue;
20830
+ if (!fs67.existsSync(dir)) continue;
20199
20831
  for (const file of walkMd(dir)) {
20200
- if (path66.basename(file) === "README.md") continue;
20201
- const lines = fs65.readFileSync(file, "utf8").split("\n");
20832
+ if (path68.basename(file) === "README.md") continue;
20833
+ const lines = fs67.readFileSync(file, "utf8").split("\n");
20202
20834
  const fmEnd = frontmatterEnd(lines);
20203
20835
  lines.forEach((line, i) => {
20204
20836
  if (!re3.test(line)) return;
@@ -20214,12 +20846,12 @@ function findMentions(ids) {
20214
20846
  return hits;
20215
20847
  }
20216
20848
  function leavingCards(id, found2) {
20217
- const own = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
20849
+ const own = found2.kind === "group" ? path68.join(found2.target, "root.md") : found2.target;
20218
20850
  const cards = [{ id, file: own }];
20219
20851
  if (found2.kind !== "group") return cards;
20220
20852
  for (const file of walkMd(found2.target)) {
20221
20853
  if (file === own) continue;
20222
- const n = idPrefix(path66.basename(file));
20854
+ const n = idPrefix(path68.basename(file));
20223
20855
  if (n !== null) cards.push({ id: n, file });
20224
20856
  }
20225
20857
  return cards;
@@ -20228,10 +20860,10 @@ function stampLeaving(cards, rejection) {
20228
20860
  const day = formatDay();
20229
20861
  const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() ? "agent" : "user" } : rejection && { reason: rejection.reason };
20230
20862
  for (const card of cards) {
20231
- if (!fs65.existsSync(card.file)) continue;
20232
- const text5 = fs65.readFileSync(card.file, "utf8");
20863
+ if (!fs67.existsSync(card.file)) continue;
20864
+ const text5 = fs67.readFileSync(card.file, "utf8");
20233
20865
  const stamped = stampLeavingIn(text5, day, stamp4);
20234
- if (stamped !== text5) fs65.writeFileSync(card.file, stamped);
20866
+ if (stamped !== text5) fs67.writeFileSync(card.file, stamped);
20235
20867
  }
20236
20868
  }
20237
20869
  function unfinishedDelivery(id) {
@@ -20247,7 +20879,7 @@ function unfinishedDelivery(id) {
20247
20879
  }[gap];
20248
20880
  return `#${id} is not finished: ${what}.`;
20249
20881
  }
20250
- const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs65.existsSync(path66.join(ASSETS, src.slice(".assets/".length))));
20882
+ const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs67.existsSync(path68.join(ASSETS, src.slice(".assets/".length))));
20251
20883
  return missing ? `#${id} is not finished: ${missing} is not on this machine.` : null;
20252
20884
  }
20253
20885
  function agentDecisions(text5) {
@@ -20278,8 +20910,8 @@ function removeCard2(id, metric, options) {
20278
20910
  const unfinished = metric === "completed" ? unfinishedDelivery(id) : null;
20279
20911
  if (unfinished) die(unfinished, { kind: "plan-delivery-unfinished" });
20280
20912
  const dest = options.cleanupDiscarded && locateArchived(id) ? null : archiveDest(found2);
20281
- const cardFile3 = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
20282
- const cardText = fs65.existsSync(cardFile3) ? fs65.readFileSync(cardFile3, "utf8") : "";
20913
+ const cardFile3 = found2.kind === "group" ? path68.join(found2.target, "root.md") : found2.target;
20914
+ const cardText = fs67.existsSync(cardFile3) ? fs67.readFileSync(cardFile3, "utf8") : "";
20283
20915
  const { meta: cardMeta3 } = parseFrontmatter(cardText);
20284
20916
  const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f2) => f2 !== cardFile3).map((f2) => rel(f2)).sort() : [];
20285
20917
  const leftIds = leavingIds(id, found2);
@@ -20310,10 +20942,10 @@ function removeCard2(id, metric, options) {
20310
20942
  const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
20311
20943
  if (dest) {
20312
20944
  stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
20313
- fs65.mkdirSync(ARCHIVE, { recursive: true });
20314
- fs65.renameSync(found2.target, dest);
20945
+ fs67.mkdirSync(ARCHIVE, { recursive: true });
20946
+ fs67.renameSync(found2.target, dest);
20315
20947
  } else {
20316
- fs65.rmSync(found2.target, { recursive: true, force: true });
20948
+ fs67.rmSync(found2.target, { recursive: true, force: true });
20317
20949
  }
20318
20950
  const removedRefs = stripReadmeRefs(found2);
20319
20951
  let marked2 = null;
@@ -20362,14 +20994,14 @@ function removeCard2(id, metric, options) {
20362
20994
  };
20363
20995
  }
20364
20996
  function closeGroup(rootFile) {
20365
- const rootId = idPrefix(path66.basename(path66.dirname(rootFile)));
20997
+ const rootId = idPrefix(path68.basename(path68.dirname(rootFile)));
20366
20998
  if (rootId === null) return null;
20367
20999
  if (runnerProject(KANBAN)) return null;
20368
21000
  if (!groupCloses(rootFile)) return null;
20369
21001
  say(`
20370
21002
  every subtask line on #${rootId} is resolved \u2014 closing the group:`);
20371
21003
  try {
20372
- const { meta, body } = parseFrontmatter(fs65.readFileSync(rootFile, "utf8"));
21004
+ const { meta, body } = parseFrontmatter(fs67.readFileSync(rootFile, "utf8"));
20373
21005
  const res = cmdRemove(rootId, "completed", { closing: true });
20374
21006
  return {
20375
21007
  id: rootId,
@@ -20426,7 +21058,7 @@ function cleanupDiscardedCards(sessionId) {
20426
21058
  if (card.pending) throw new Error(`Discarding #${card.id} did not finish. Retry the discard.`);
20427
21059
  while (locate(card.id)) cmdRemove(card.id, "rejected", { discard: true, cleanupDiscarded: true });
20428
21060
  dropCrossRefs(card.id);
20429
- stripReadmeRefs({ kind: "file", rel: path66.relative(TODO, path66.resolve(REPO_ROOT, card.path)).split(path66.sep).join("/") });
21061
+ stripReadmeRefs({ kind: "file", rel: path68.relative(TODO, path68.resolve(REPO_ROOT, card.path)).split(path68.sep).join("/") });
20430
21062
  }
20431
21063
  return discarded.map((c2) => c2.id);
20432
21064
  });
@@ -20434,8 +21066,8 @@ function cleanupDiscardedCards(sessionId) {
20434
21066
  function recoveredArchiveHandoff(id, source) {
20435
21067
  const found2 = locateArchived(id);
20436
21068
  if (!found2) throw new Error(`No archived card #${id} was found.`);
20437
- const file = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
20438
- const { meta } = parseFrontmatter(fs65.readFileSync(file, "utf8"));
21069
+ const file = found2.kind === "group" ? path68.join(found2.target, "root.md") : found2.target;
21070
+ const { meta } = parseFrontmatter(fs67.readFileSync(file, "utf8"));
20439
21071
  stripReadmeRefs(source ?? found2);
20440
21072
  const root2 = source?.kind === "file" ? enclosingGroupRoot(source.target) : null;
20441
21073
  if (root2) markSubtask(root2, id, "tick");
@@ -20533,8 +21165,8 @@ var init_memory_file = __esm({
20533
21165
  });
20534
21166
 
20535
21167
  // src/commands/rule.ts
20536
- import fs66 from "node:fs";
20537
- import path67 from "node:path";
21168
+ import fs68 from "node:fs";
21169
+ import path69 from "node:path";
20538
21170
  function cmdRule(askedName, flags) {
20539
21171
  const agent = askedName.trim();
20540
21172
  if (!agentRoster().some((a2) => a2.name === agent)) {
@@ -20543,7 +21175,7 @@ function cmdRule(askedName, flags) {
20543
21175
  const rule = readRuleText(flags.file, flags.text);
20544
21176
  const res = setAgentRule(agent, rule);
20545
21177
  if (!res.ok) die(res.error);
20546
- const file = rel(path67.join(RULES, `${agent}.md`));
21178
+ const file = rel(path69.join(RULES, `${agent}.md`));
20547
21179
  say(rule ? `wrote the \`${agent}\` rule (${file})` : `cleared the \`${agent}\` rule`);
20548
21180
  return { agent, file, cleared: !rule };
20549
21181
  }
@@ -20551,7 +21183,7 @@ function readRuleText(file, text5) {
20551
21183
  if (file !== void 0 && text5 !== void 0) die("pass --file or --text, not both");
20552
21184
  if (file !== void 0) {
20553
21185
  try {
20554
- return fs66.readFileSync(file, "utf8").trim();
21186
+ return fs68.readFileSync(file, "utf8").trim();
20555
21187
  } catch {
20556
21188
  die(`can't read ${file} \u2014 write the rule to a file, then pass its path`);
20557
21189
  }
@@ -20870,7 +21502,7 @@ var shared_exports = {};
20870
21502
  __export(shared_exports, {
20871
21503
  InvalidArgumentError: () => InvalidArgumentError,
20872
21504
  cardId: () => cardId,
20873
- collect: () => collect,
21505
+ collect: () => collect2,
20874
21506
  collectList: () => collectList,
20875
21507
  ctxOf: () => ctxOf,
20876
21508
  intInRange: () => intInRange,
@@ -20966,7 +21598,7 @@ function ordered(into) {
20966
21598
  return value ?? "";
20967
21599
  };
20968
21600
  }
20969
- var HELP_WIDTH, collect;
21601
+ var HELP_WIDTH, collect2;
20970
21602
  var init_shared = __esm({
20971
21603
  "src/lib/cli/shared.ts"() {
20972
21604
  "use strict";
@@ -20975,7 +21607,7 @@ var init_shared = __esm({
20975
21607
  init_board_cli();
20976
21608
  init_moved();
20977
21609
  HELP_WIDTH = 100;
20978
- collect = (value, previous = []) => previous.concat(value);
21610
+ collect2 = (value, previous = []) => previous.concat(value);
20979
21611
  }
20980
21612
  });
20981
21613
 
@@ -20985,8 +21617,8 @@ __export(board_exports, {
20985
21617
  buildBoardProgram: () => buildBoardProgram
20986
21618
  });
20987
21619
  import crypto5 from "node:crypto";
20988
- import fs67 from "node:fs";
20989
- import path68 from "node:path";
21620
+ import fs69 from "node:fs";
21621
+ import path70 from "node:path";
20990
21622
  async function dispatch(move, cmd, args, opts, cli) {
20991
21623
  const ctx = ctxOf(cmd, cli.program);
20992
21624
  const data = await runAction(ctx, {}, async () => {
@@ -21026,7 +21658,7 @@ async function cloudCard(task, opts) {
21026
21658
  let request2;
21027
21659
  if (typeof opts.bodyFile === "string") {
21028
21660
  try {
21029
- request2 = fs67.readFileSync(opts.bodyFile, "utf8");
21661
+ request2 = fs69.readFileSync(opts.bodyFile, "utf8");
21030
21662
  } catch {
21031
21663
  }
21032
21664
  }
@@ -21056,7 +21688,7 @@ async function cloudCard(task, opts) {
21056
21688
  const file = creationReceipt(`${checked.value}:${requestId}`, slot);
21057
21689
  const journal = readCreation(file, said3);
21058
21690
  if (!journal.made) {
21059
- const key = `akb-${path68.basename(file, ".json").slice(0, 40)}`;
21691
+ const key = `akb-${path70.basename(file, ".json").slice(0, 40)}`;
21060
21692
  const made = await createProjectTask(checked.value, journal.said, key);
21061
21693
  if (!made.ok) throw new BoardError(creationError(`Cloud did not make the task: ${made.error}`, triage), { kind: "refused" });
21062
21694
  journal.made = made.value;
@@ -21086,13 +21718,13 @@ function buildBoardProgram(cli) {
21086
21718
  const inOrder = ordered(asked);
21087
21719
  move("create").summary("write exactly one card \u2014 its fields, its body template and its index entry").description(
21088
21720
  'Write exactly ONE card: allocate its id, write its frontmatter and a body template, and index it. There is no separate id-reservation mode. --blocked-by and --related take ids of existing open cards; for a group, create the root first, then create each subtask related to its id (see "Group tasks" in `akb guide add-task`). The script owns the frontmatter and writes the body scaffold; fill only the body by hand. Without --id, Cloud assigns the number in the linked project (no source task required). A failed local write can resume the same creation without making another Cloud task. Missing or invalid project links and denied access exit with code 1 using the existing error envelope. --body-file accepts a short draft or full card body. Invalid bodies fail before allocating a task or writing a card, with repair instructions. Cloud moves the card on by itself once it reaches the board: do not refine it here. Turning what a user just asked for into a card goes through `akb create` instead: this move only writes what you already decided. Example: akb raw create --title "Add a delete command" --body-file /tmp/delete-command.md'
21089
- ).requiredOption("--title <title>", "what the card is called").addOption(new Option("--recurring").hideHelp()).option("--priority <level>", `how much it matters: ${LEVELS.join(" | ")} (default: med)`, oneOf(LEVELS)).option("--blocked-by <ids>", "ids of open cards this one waits on", collectList).option("--related <ids>", "ids of open cards this one relates to", collectList).option("--modules <names>", "the parts of the project it touches, validated against modules.md", collectList).option("--question <text>", "an open question; needs its --option choices. Repeatable; follow `akb guide update-questions`", inOrder("question")).option("--option <text>", "a choice for the --question before it", inOrder("option")).option("--recommended-option <text>", "a choice for the --question before it, ticked to start", inOrder("recommended-option")).option("--mode <mode>", "how many choices the --question before it takes: single | multi", inOrder("mode")).option("--slug <slug>", "the filename to write it under (default: from the title)").option("--no-body", "write the frontmatter and no body template").option("--body-file <path>", "a short draft or full card body, written to a file first").addOption(new Option("--cadence <cadence>").hideHelp()).option("--workflow <id>", "the workflow it runs through (`akb workflow list`). Left off, the board's default").option("--previews <agents>", `the preview agents it chose, from its workflow's; "" chooses none`, collectList).addOption(new Option("--id <n>", "the number Cloud gave this card's task; for the Runner").argParser(cardId).hideHelp()).option("--triage <source-id>", "the triage item this card is made of, so the item is never carded twice").option("--source <ref>", "where it came from: a plan's path, plan:<id>, #<id> or a URL. Repeatable", collect).action(async function() {
21721
+ ).requiredOption("--title <title>", "what the card is called").addOption(new Option("--recurring").hideHelp()).option("--priority <level>", `how much it matters: ${LEVELS.join(" | ")} (default: med)`, oneOf(LEVELS)).option("--blocked-by <ids>", "ids of open cards this one waits on", collectList).option("--related <ids>", "ids of open cards this one relates to", collectList).option("--modules <names>", "the parts of the project it touches, validated against modules.md", collectList).option("--question <text>", "an open question; needs its --option choices. Repeatable; follow `akb guide update-questions`", inOrder("question")).option("--option <text>", "a choice for the --question before it", inOrder("option")).option("--recommended-option <text>", "a choice for the --question before it, ticked to start", inOrder("recommended-option")).option("--mode <mode>", "how many choices the --question before it takes: single | multi", inOrder("mode")).option("--slug <slug>", "the filename to write it under (default: from the title)").option("--no-body", "write the frontmatter and no body template").option("--body-file <path>", "a short draft or full card body, written to a file first").addOption(new Option("--cadence <cadence>").hideHelp()).option("--workflow <id>", "the workflow it runs through (`akb workflow list`). Left off, the board's default").option("--previews <agents>", `the preview agents it chose, from its workflow's; "" chooses none`, collectList).addOption(new Option("--id <n>", "the number Cloud gave this card's task; for the Runner").argParser(cardId).hideHelp()).option("--triage <source-id>", "the triage item this card is made of, so the item is never carded twice").option("--source <ref>", "where it came from: a plan's path, plan:<id>, #<id> or a URL. Repeatable", collect2).action(async function() {
21090
21722
  refuseRecurring(this);
21091
21723
  await dispatch("create", this, [], { ...this.opts(), asked }, cli);
21092
21724
  });
21093
21725
  move("update").argument("<id>", ID, cardId).summary("rewrite a card's fields").description(
21094
21726
  "Rewrite a card's frontmatter fields. --slug renames it. Body and questions are left untouched \u2014 those have their own moves."
21095
- ).option("--title <title>", "what the card is called").option("--priority <level>", LEVELS.join(" | "), oneOf(LEVELS)).option("--status <status>", STATUSES.join(" | "), oneOf(STATUSES)).option("--blocked-by <ids>", "ids of open cards this one waits on", collectList).option("--related <ids>", "ids of open cards this one relates to", collectList).option("--add-blocked-by <ids>", "append ids to blocked_by, keeping the ids already there", collectList).option("--add-related <ids>", "append ids to related, keeping the ids already there", collectList).option("--modules <names>", "the parts of the project it touches", collectList).option("--source <ref>", `where it came from: a plan's path, plan:<id>, #<id> or a URL. Repeatable; "" clears the list`, collect).option("--add-source <ref>", "append one source, keeping the ones already there. Repeatable", collect).option("--previews <agents>", `the preview agents it chose, from its workflow's; "" chooses none`, collectList).option("--phase <n>", "the approval it is on, 1-based").option("--slug <slug>", "rename the file").option("--workflow <id>", 'the workflow it runs through; "" puts it back on the default. The card goes back to todo and is re-planned').addOption(new Option("--cadence <cadence>").hideHelp()).action(async function(id) {
21727
+ ).option("--title <title>", "what the card is called").option("--priority <level>", LEVELS.join(" | "), oneOf(LEVELS)).option("--status <status>", STATUSES.join(" | "), oneOf(STATUSES)).option("--blocked-by <ids>", "ids of open cards this one waits on", collectList).option("--related <ids>", "ids of open cards this one relates to", collectList).option("--add-blocked-by <ids>", "append ids to blocked_by, keeping the ids already there", collectList).option("--add-related <ids>", "append ids to related, keeping the ids already there", collectList).option("--modules <names>", "the parts of the project it touches", collectList).option("--source <ref>", `where it came from: a plan's path, plan:<id>, #<id> or a URL. Repeatable; "" clears the list`, collect2).option("--add-source <ref>", "append one source, keeping the ones already there. Repeatable", collect2).option("--previews <agents>", `the preview agents it chose, from its workflow's; "" chooses none`, collectList).option("--phase <n>", "the approval it is on, 1-based").option("--slug <slug>", "rename the file").option("--workflow <id>", 'the workflow it runs through; "" puts it back on the default. The card goes back to todo and is re-planned').addOption(new Option("--cadence <cadence>").hideHelp()).action(async function(id) {
21096
21728
  refuseRecurring(this);
21097
21729
  await dispatch("update", this, [String(id)], this.opts(), cli);
21098
21730
  });
@@ -21198,16 +21830,16 @@ var init_board2 = __esm({
21198
21830
  });
21199
21831
 
21200
21832
  // src/lib/board-cli.ts
21201
- import fs68 from "node:fs";
21202
- import path69 from "node:path";
21833
+ import fs70 from "node:fs";
21834
+ import path71 from "node:path";
21203
21835
  function useBoard(found2, dirNamed) {
21204
- if (!found2.named && found2.board === path69.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
21836
+ if (!found2.named && found2.board === path71.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
21205
21837
  else setBoardDir(found2.board, found2.root);
21206
21838
  useProjectState();
21207
21839
  }
21208
21840
  function whole(found2, move) {
21209
21841
  if (move === MAKES_A_BOARD) return found2;
21210
- if (!fs68.existsSync(path69.join(found2.board, "todo"))) {
21842
+ if (!fs70.existsSync(path71.join(found2.board, "todo"))) {
21211
21843
  die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
21212
21844
  kind: "board-incomplete",
21213
21845
  dir: found2.root
@@ -21216,13 +21848,13 @@ function whole(found2, move) {
21216
21848
  return found2;
21217
21849
  }
21218
21850
  function findBoardUpward(from, move) {
21219
- let dir = path69.resolve(from);
21851
+ let dir = path71.resolve(from);
21220
21852
  for (; ; ) {
21221
- if (hasBoard(dir)) return { root: dir, board: path69.join(dir, "docs", "kanban") };
21853
+ if (hasBoard(dir)) return { root: dir, board: path71.join(dir, "docs", "kanban") };
21222
21854
  if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
21223
- const kept2 = path69.join(dir, ".akb", "kanban");
21224
- if (move !== MAKES_A_BOARD && fs68.existsSync(path69.join(kept2, "todo"))) return { root: dir, board: kept2 };
21225
- const up = path69.dirname(dir);
21855
+ const kept2 = path71.join(dir, ".akb", "kanban");
21856
+ if (move !== MAKES_A_BOARD && fs70.existsSync(path71.join(kept2, "todo"))) return { root: dir, board: kept2 };
21857
+ const up = path71.dirname(dir);
21226
21858
  if (up === dir) return null;
21227
21859
  dir = up;
21228
21860
  }
@@ -21230,11 +21862,11 @@ function findBoardUpward(from, move) {
21230
21862
  function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
21231
21863
  const named2 = board2 ?? boardFromEnv();
21232
21864
  if (named2) {
21233
- const folder = path69.resolve(cwd, named2);
21234
- if (!fs68.existsSync(folder) && move !== MAKES_A_BOARD) {
21865
+ const folder = path71.resolve(cwd, named2);
21866
+ if (!fs70.existsSync(folder) && move !== MAKES_A_BOARD) {
21235
21867
  die(`no such folder: ${folder}`, { kind: "no-such-folder", dir: folder });
21236
21868
  }
21237
- if (fs68.existsSync(folder) && !isBoardDir(folder) && move !== MAKES_A_BOARD) {
21869
+ if (fs70.existsSync(folder) && !isBoardDir(folder) && move !== MAKES_A_BOARD) {
21238
21870
  die(`${folder} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
21239
21871
  kind: "no-board",
21240
21872
  dir: folder
@@ -21243,24 +21875,24 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
21243
21875
  return { root: projectRootOf(folder), board: folder, named: true };
21244
21876
  }
21245
21877
  if (dir !== null) {
21246
- const root2 = path69.resolve(dir);
21247
- if (!fs68.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
21248
- const kept2 = path69.join(root2, ".akb", "kanban");
21249
- if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs68.existsSync(path69.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
21878
+ const root2 = path71.resolve(dir);
21879
+ if (!fs70.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
21880
+ const kept2 = path71.join(root2, ".akb", "kanban");
21881
+ if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs70.existsSync(path71.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
21250
21882
  if (!hasBoard(root2) && move !== MAKES_A_BOARD) {
21251
21883
  die(`no board in ${root2} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
21252
21884
  kind: "no-board",
21253
21885
  dir: root2
21254
21886
  });
21255
21887
  }
21256
- return whole({ root: root2, board: path69.join(root2, "docs", "kanban") }, move);
21888
+ return whole({ root: root2, board: path71.join(root2, "docs", "kanban") }, move);
21257
21889
  }
21258
21890
  const found2 = findBoardUpward(cwd, move);
21259
21891
  if (found2) return whole(found2, move);
21260
- if (move === MAKES_A_BOARD) return { root: path69.resolve(cwd), board: path69.join(path69.resolve(cwd), "docs", "kanban") };
21892
+ if (move === MAKES_A_BOARD) return { root: path71.resolve(cwd), board: path71.join(path71.resolve(cwd), "docs", "kanban") };
21261
21893
  die(
21262
- `no board here. Looked in ${path69.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
21263
- { kind: "no-board", dir: path69.resolve(cwd) }
21894
+ `no board here. Looked in ${path71.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
21895
+ { kind: "no-board", dir: path71.resolve(cwd) }
21264
21896
  );
21265
21897
  }
21266
21898
  function editDistance(a2, b2) {
@@ -21342,8 +21974,8 @@ var init_board_cli = __esm({
21342
21974
  init_io();
21343
21975
  init_pointer();
21344
21976
  MAKES_A_BOARD = "init";
21345
- hasBoard = (dir) => fs68.existsSync(path69.join(dir, "docs", "kanban"));
21346
- isBoardDir = (dir) => fs68.existsSync(path69.join(dir, "todo")) && fs68.existsSync(path69.join(dir, "config.md"));
21977
+ hasBoard = (dir) => fs70.existsSync(path71.join(dir, "docs", "kanban"));
21978
+ isBoardDir = (dir) => fs70.existsSync(path71.join(dir, "todo")) && fs70.existsSync(path71.join(dir, "config.md"));
21347
21979
  boardFromEnv = () => {
21348
21980
  const named2 = process.env.AI4KANBAN_BOARD?.trim();
21349
21981
  return named2 ? named2 : null;
@@ -21451,7 +22083,7 @@ var init_review_rejections = __esm({
21451
22083
  var refine_default;
21452
22084
  var init_refine = __esm({
21453
22085
  "src/guide/refine.md"() {
21454
- refine_default = '# Refine a card\n\nPlan one card in this session until it can be built. Change no project code.\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. Search the relevant code and docs 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- **Split**: only when the card holds independently plannable areas and one is still vague,\n follow the group procedure in `akb guide add-task`, create each subtask, and stop: Cloud\n refines each one itself.\n- **Workflow rules**: write the card as the workflow 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 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- **Think like the one who ships it**: settle every fact from the code and authoritative\n sources, and write what shipping takes beyond the happy path: existing data and settings,\n release and rollback, failure, access, and ongoing cost. Once the card validates, judge\n whether it can be built as written, or before its last\n Approve: if so, run `akb raw update <id> --status ready`; otherwise leave what blocks it as\n an open question.\n\nFollow any closing steps the flow printed, then stop: the user approves the previews or starts\nthe build.\n';
22086
+ 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- **Workflow rules**: write the card as the workflow 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 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';
21455
22087
  }
21456
22088
  });
21457
22089
 
@@ -21507,7 +22139,7 @@ var init_troubleshoot = __esm({
21507
22139
  var write_agent_default;
21508
22140
  var init_write_agent = __esm({
21509
22141
  "src/guide/write-agent.md"() {
21510
- write_agent_default = "# Write an agent\n\nAn agent is one folder: `docs/kanban/agents/<name>/AGENT.md`. The folder name is the agent's\nname and the word every flow asks for it by \u2014 lower-case words joined by `-`, matching the\n`name` in its frontmatter. It cannot be a name the board already answers to: one of the\nboard's roles, an agent the command ships, or a folder already in `docs/kanban/agents/`.\n\n## The file\n\n```yaml\n---\n# Required; matches the folder name.\nname: ux-writer\n# Required: one sentence saying what it does.\ndescription: Writes the words a screen shows.\n# Optional.\nakb:\n # Optional, for a preview agent: when to request it, exceptions included. Without it, it\n # always runs.\n when: A card changes what the product says to the user; not a typo.\n # Optional, for a preview agent: it runs only after these agents' previews are approved,\n # when the card requests them too; it never makes them run.\n after: [ui-designer]\n # Optional, for a preview agent: `new` runs it in a session of its own.\n session: new\n # Preview components this agent uses; an empty list loads no component documentation.\n components: [Asset]\n---\n\nYou write the words a screen shows.\n```\n\nIts workflow, not the agent, sets its role: `WORKFLOW.md` lists it under `previews`, `land`\nor `scheduled`.\n\nA scheduled agent can also name the new input it works on; it then runs only when there is some:\n\n```yaml\nakb:\n # archived-cards | chats | dismissals; omit to run on its cadence alone.\n reads: archived-cards\n```\n\nAn agent that shares material with others names the global memories it keeps:\n\n```yaml\nakb:\n # Optional; global memories under `docs/kanban/memory/<name>/`, by name.\n memory: [competitors]\n # Optional; its own memory files, or folders ending in `/`, that hold in any of the user's\n # projects. Everything else is this project's.\n memoryFiles:\n workspace: [style.md]\n```\n\nEverything under the frontmatter is the agent's instructions, read fresh on every run \u2014\na file with none is refused.\n\nAn agent declares no options of its own. Two ways of working is two agents, each with its own\n`AGENT.md` \u2014 a switch that changes how one agent works costs more than it buys.\n\n## Translations\n\n```yaml\nakb:\n # Optional; UI text only. Runs use English; omitted text falls back to English.\n i18n:\n # Language tag; every field below is optional.\n zh:\n # Display name; does not change the agent's name.\n title: \u754C\u9762\u6587\u6848\u5E08\n description: \u64B0\u5199\u754C\u9762\u4E0A\u7684\u6587\u5B57\u3002\n when: \u5361\u7247\u65B0\u589E\u6216\u4FEE\u6539\u754C\u9762\u6587\u5B57\u65F6\u3002\n```\n\n## Files\n\nEvery file beside `AGENT.md`, in any subfolder, is named to the run by its path and opened only\nwhen the work calls for it. Put long material there and keep `AGENT.md` short.\n\n- **Scripts**: every agent owns its task scripts in its own folder, including built-in agents.\n Keep business validation there, outside the CLI's board logic. Document the runtime, inputs\n and invocation beside the script; consumers use the owner's script. Built-in files can be\n saved through `akb raw agent-file <agent> <path>` and run locally with their relative layout\n intact; custom agents use their existing folders.\n\n## Imported skills\n\nAn agent may carry several skills, each whole in its own `skills/<skill>/` folder.\n\n- **Keep the capability**: copy the skill's instructions, scripts, resources and license\n unchanged; never reduce it to rewritten instructions. Leave out installed packages and caches,\n and name any file it refers to that you could not get.\n- **Record the source**: list each in a `## Skills` section of `AGENT.md` as\n `- **<skill>**: <when to use it>. Source: <URL or pasted> @ <commit, tag or snapshot date>`.\n- **Adapt outside it**: say in `AGENT.md` when to use each skill and how its result becomes\n this agent's output; paths inside a skill resolve from its folder. Keep the skill folder\n untouched so an update can replace it whole.\n- **Runtime needs**: check every command, package and credential the skill needs on this\n machine. Name what is missing under its bullet and tell the user; never call the agent usable\n while anything is missing, and never copy a key into the folder.\n- **Update and remove**: update only when the user asks \u2014 replace the folder, show the diff and\n change the version. Remove a skill with its folder and bullet. Each agent owns its copies, so\n no change reaches another agent.\n\n## Memory\n\n`docs/kanban/memory/agents/<name>/` is read into every run. Keep none unless a user's\ncorrection should change the agent's next output. Otherwise say in `AGENT.md`:\n\n- **Files**: each file and what it holds; `## General` for what always holds, and a heading per\n situation (a format, a recipe, a channel) for what holds only there.\n- **When**: which file to apply before which step, and which answers or corrections to record.\n- **What goes in**: lasting preferences, decisions and corrections only \u2014 never raw feedback,\n run history, or what the instructions already say.\n- **Shared material**: what other agents also use goes in a global memory under `akb.memory`;\n its rules arrive with every run, so `AGENT.md` never restates them.\n\n## Output\n\nDeclare the preview components the agent uses in `akb.components` (Asset, Compare, Storyboard).\nTheir usage documentation is supplied with the run; omitted declarations default to Asset.\nUse `akb components --agent <name> --docs` or `--workflow <id> --docs` to read it.\n\nChoose the form the reader takes in fastest and say it in `AGENT.md`: an image for a look, a\nstoryboard for a sequence over time, readable Markdown for everything else.\n\n## Dependencies\n\n- **In `after`**: name the agents whose approved previews this one needs; it waits for those\n approvals and never requests the agents.\n- **In the instructions**: say what to do when the section it needs is missing or still\n carries an open question \u2014 normally draw nothing and write one line naming what is missing.\n A preview agent never asks for another.\n\n## Instructions\n\nSay what the agent owns, what it produces, and what it leaves alone. Don't repeat the contract\nevery run is pointed to (`akb guide preview-agent`): where the section goes, how to validate,\nhow to keep memory, and how to defer to the user. A scheduled agent says what one run does,\nnever when it runs.\n\n## Work with the user\n\n- **Ask little**: settle what the request, the skill and the board already answer; ask the rest\n as `akb guide update-questions` does, and never ask again what is answered.\n- **State between runs**: ask how a scheduled agent should keep what its next run needs, and\n write the answer into `AGENT.md`; assume no file or format.\n- **Important choices**: give a recommendation and its tradeoff, and accept a free answer.\n- **Show each edit**: when changing an existing agent, show every changed file as a unified\n diff with context, followed by one sentence of reason.\n\n## Check it\n\n- **Validate before finishing**: after creating or editing an agent, run `akb previews`. Read all trigger conditions with `akb previews --triggers`.\n Fix every problem reported for its file under \"Problems on this board\", then run it again.\n Do not finish until the agent is accepted with no problems reported for it.\n- **`akb previews <name> <id> --print`** on a real card prints the whole prompt the agent will get:\n its instructions, the reference for each chosen setting, its files and its memory. Read it, and cut whatever the run does not need.\n- **Workflow**: a new agent belongs to the workflow it was created in and starts switched on;\n a preview agent joins the end of that workflow's `previews`. `akb previews` refuses it while it is off.\n Switch it in that workflow's `WORKFLOW.md`.\n- **Schedule**: set `reads` from what the agent works on; it runs automatically by default.\n For a fixed cadence, add `cadence: 1d` to its entry in the workflow's `scheduled`.\n";
22142
+ write_agent_default = "# Write an agent\n\nAn agent is one folder: `docs/kanban/agents/<name>/AGENT.md`. The folder name is the agent's\nname and the word every flow asks for it by \u2014 lower-case words joined by `-`, matching the\n`name` in its frontmatter. It cannot be a name the board already answers to: one of the\nboard's roles, an agent the command ships, or a folder already in `docs/kanban/agents/`.\n\n## The file\n\n```yaml\n---\n# Required; matches the folder name.\nname: ux-writer\n# Required: one sentence saying what it does.\ndescription: Writes the words a screen shows.\n# Optional.\nakb:\n # Optional, for a preview agent: when to request it, exceptions included. Without it, it\n # always runs.\n when: A card changes what the product says to the user; not a typo.\n # Optional, for a preview agent: it runs only after these agents' previews are approved,\n # when the card requests them too; it never makes them run.\n after: [ui-designer]\n # Optional, for a preview agent: `new` runs it in a session of its own.\n session: new\n # Preview components this agent uses; an empty list loads no component documentation.\n components: [Asset]\n # Optional: a sticker of its deliverable, by glyph name (the Workflow builder lists them),\n # or 1 to 12 parts `{ d, f?, o?: true, s?, w? }`. Without it, a generic file is drawn.\n icon: text\n---\n\nYou write the words a screen shows.\n```\n\nIts workflow, not the agent, sets its role: `WORKFLOW.md` lists it under `previews`, `land`\nor `scheduled`.\n\nA scheduled agent can also name the new input it works on; it then runs only when there is some:\n\n```yaml\nakb:\n # archived-cards | chats | dismissals; omit to run on its cadence alone.\n reads: archived-cards\n```\n\nAn agent that shares material with others names the global memories it keeps:\n\n```yaml\nakb:\n # Optional; global memories under `docs/kanban/memory/<name>/`, by name.\n memory: [competitors]\n # Optional; its own memory files, or folders ending in `/`, that hold in any of the user's\n # projects. Everything else is this project's.\n memoryFiles:\n workspace: [style.md]\n```\n\nEverything under the frontmatter is the agent's instructions, read fresh on every run \u2014\na file with none is refused.\n\nAn agent declares no options of its own. Two ways of working is two agents, each with its own\n`AGENT.md` \u2014 a switch that changes how one agent works costs more than it buys.\n\n## Translations\n\n```yaml\nakb:\n # Optional; UI text only. Runs use English; omitted text falls back to English.\n i18n:\n # Language tag; every field below is optional.\n zh:\n # Display name; does not change the agent's name.\n title: \u754C\u9762\u6587\u6848\u5E08\n description: \u64B0\u5199\u754C\u9762\u4E0A\u7684\u6587\u5B57\u3002\n when: \u5361\u7247\u65B0\u589E\u6216\u4FEE\u6539\u754C\u9762\u6587\u5B57\u65F6\u3002\n```\n\n## Files\n\nEvery file beside `AGENT.md`, in any subfolder, is named to the run by its path and opened only\nwhen the work calls for it. Put long material there and keep `AGENT.md` short.\n\n- **Scripts**: every agent owns its task scripts in its own folder, including built-in agents.\n Keep business validation there, outside the CLI's board logic. Document the runtime, inputs\n and invocation beside the script; consumers use the owner's script. Built-in files can be\n saved through `akb raw agent-file <agent> <path>` and run locally with their relative layout\n intact; custom agents use their existing folders.\n\n## Imported skills\n\nAn agent may carry several skills, each whole in its own `skills/<skill>/` folder.\n\n- **Keep the capability**: copy the skill's instructions, scripts, resources and license\n unchanged; never reduce it to rewritten instructions. Leave out installed packages and caches,\n and name any file it refers to that you could not get.\n- **Record the source**: list each in a `## Skills` section of `AGENT.md` as\n `- **<skill>**: <when to use it>. Source: <URL or pasted> @ <commit, tag or snapshot date>`.\n- **Adapt outside it**: say in `AGENT.md` when to use each skill and how its result becomes\n this agent's output; paths inside a skill resolve from its folder. Keep the skill folder\n untouched so an update can replace it whole.\n- **Runtime needs**: check every command, package and credential the skill needs on this\n machine. Name what is missing under its bullet and tell the user; never call the agent usable\n while anything is missing, and never copy a key into the folder.\n- **Update and remove**: update only when the user asks \u2014 replace the folder, show the diff and\n change the version. Remove a skill with its folder and bullet. Each agent owns its copies, so\n no change reaches another agent.\n\n## Memory\n\n`docs/kanban/memory/agents/<name>/` is read into every run. Keep none unless a user's\ncorrection should change the agent's next output. Otherwise say in `AGENT.md`:\n\n- **Files**: each file and what it holds; `## General` for what always holds, and a heading per\n situation (a format, a recipe, a channel) for what holds only there.\n- **When**: which file to apply before which step, and which answers or corrections to record.\n- **What goes in**: lasting preferences, decisions and corrections only \u2014 never raw feedback,\n run history, or what the instructions already say.\n- **Shared material**: what other agents also use goes in a global memory under `akb.memory`;\n its rules arrive with every run, so `AGENT.md` never restates them.\n\n## Output\n\nDeclare the preview components the agent uses in `akb.components` (Asset, Compare, Storyboard).\nTheir usage documentation is supplied with the run; omitted declarations default to Asset.\nUse `akb components --agent <name> --docs` or `--workflow <id> --docs` to read it.\n\nChoose the form the reader takes in fastest and say it in `AGENT.md`: an image for a look, a\nstoryboard for a sequence over time, readable Markdown for everything else.\n\n## Dependencies\n\n- **In `after`**: name the agents whose approved previews this one needs; it waits for those\n approvals and never requests the agents.\n- **In the instructions**: say what to do when the section it needs is missing or still\n carries an open question \u2014 normally draw nothing and write one line naming what is missing.\n A preview agent never asks for another.\n\n## Instructions\n\nSay what the agent owns, what it produces, and what it leaves alone. Don't repeat the contract\nevery run is pointed to (`akb guide preview-agent`): where the section goes, how to validate,\nhow to keep memory, and how to defer to the user. A scheduled agent says what one run does,\nnever when it runs.\n\n## Work with the user\n\n- **Ask little**: settle what the request, the skill and the board already answer; ask the rest\n as `akb guide update-questions` does, and never ask again what is answered.\n- **State between runs**: ask how a scheduled agent should keep what its next run needs, and\n write the answer into `AGENT.md`; assume no file or format.\n- **Important choices**: give a recommendation and its tradeoff, and accept a free answer.\n- **Show each edit**: when changing an existing agent, show every changed file as a unified\n diff with context, followed by one sentence of reason.\n\n## Check it\n\n- **Validate before finishing**: after creating or editing an agent, run `akb previews`. Read all trigger conditions with `akb previews --triggers`.\n Fix every problem reported for its file under \"Problems on this board\", then run it again.\n Do not finish until the agent is accepted with no problems reported for it.\n- **`akb previews <name> <id> --print`** on a real card prints the whole prompt the agent will get:\n its instructions, the reference for each chosen setting, its files and its memory. Read it, and cut whatever the run does not need.\n- **Workflow**: a new agent belongs to the workflow it was created in and starts switched on;\n a preview agent joins the end of that workflow's `previews`. `akb previews` refuses it while it is off.\n Switch it in that workflow's `WORKFLOW.md`.\n- **Schedule**: set `reads` from what the agent works on; it runs automatically by default.\n For a fixed cadence, add `cadence: 1d` to its entry in the workflow's `scheduled`.\n";
21511
22143
  }
21512
22144
  });
21513
22145
 
@@ -21600,8 +22232,8 @@ var init_guide = __esm({
21600
22232
  });
21601
22233
 
21602
22234
  // src/lib/agent/approve.ts
21603
- import fs74 from "node:fs";
21604
- import path75 from "node:path";
22235
+ import fs77 from "node:fs";
22236
+ import path78 from "node:path";
21605
22237
  function approvalRequest(req) {
21606
22238
  const id = req.id;
21607
22239
  const card = id === void 0 ? null : findCard(id);
@@ -21619,12 +22251,12 @@ function advancePhase(id) {
21619
22251
  const card = findCard(id);
21620
22252
  const found2 = locate(id);
21621
22253
  if (!card || !found2 || !awaitingApproval(card)) return { error: `#${id} is no longer waiting on approval.` };
21622
- const file = found2.kind === "group" ? path75.join(found2.target, "root.md") : found2.target;
21623
- const { meta, body } = parseFrontmatter(fs74.readFileSync(file, "utf8"));
22254
+ const file = found2.kind === "group" ? path78.join(found2.target, "root.md") : found2.target;
22255
+ const { meta, body } = parseFrontmatter(fs77.readFileSync(file, "utf8"));
21624
22256
  if (!meta) return { error: `#${id} has no frontmatter` };
21625
22257
  meta.phase = card.stage + 1;
21626
22258
  meta.status = "todo";
21627
- fs74.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
22259
+ fs77.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
21628
22260
  return null;
21629
22261
  }
21630
22262
  var init_approve = __esm({
@@ -21757,16 +22389,16 @@ var init_start = __esm({
21757
22389
  });
21758
22390
 
21759
22391
  // src/lib/agent/task-chats.ts
21760
- import fs75 from "node:fs";
21761
- import path76 from "node:path";
22392
+ import fs78 from "node:fs";
22393
+ import path79 from "node:path";
21762
22394
  function taskChatFile(task, home3) {
21763
22395
  if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
21764
- return path76.join(taskChatsDir(home3), `${task}.jsonl`);
22396
+ return path79.join(taskChatsDir(home3), `${task}.jsonl`);
21765
22397
  }
21766
22398
  function readTaskChat(task, home3) {
21767
22399
  let text5;
21768
22400
  try {
21769
- text5 = fs75.readFileSync(taskChatFile(task, home3), "utf8");
22401
+ text5 = fs78.readFileSync(taskChatFile(task, home3), "utf8");
21770
22402
  } catch {
21771
22403
  return [];
21772
22404
  }
@@ -21787,13 +22419,13 @@ var init_task_chats = __esm({
21787
22419
  "use strict";
21788
22420
  init_home();
21789
22421
  TASK = /^[\w-]{1,100}$/;
21790
- taskChatsDir = (home3 = machineHome()) => path76.join(home3, "chats");
22422
+ taskChatsDir = (home3 = machineHome()) => path79.join(home3, "chats");
21791
22423
  }
21792
22424
  });
21793
22425
 
21794
22426
  // src/lib/agent/memory-review.ts
21795
- import fs76 from "node:fs";
21796
- import path77 from "node:path";
22427
+ import fs79 from "node:fs";
22428
+ import path80 from "node:path";
21797
22429
  function taskChatsToReview(tasks) {
21798
22430
  const out = [];
21799
22431
  for (const ref of [...new Set(tasks)]) {
@@ -21815,8 +22447,8 @@ function readArchived2(id) {
21815
22447
  const found2 = Number.isInteger(id) && id > 0 ? locateArchived(id) : null;
21816
22448
  if (!found2) return null;
21817
22449
  try {
21818
- const file = found2.kind === "group" ? path77.join(found2.target, "root.md") : found2.target;
21819
- const { meta, body } = parseFrontmatter(fs76.readFileSync(file, "utf8"));
22450
+ const file = found2.kind === "group" ? path80.join(found2.target, "root.md") : found2.target;
22451
+ const { meta, body } = parseFrontmatter(fs79.readFileSync(file, "utf8"));
21820
22452
  if (!meta) return null;
21821
22453
  return { id, title: meta.title, modules: meta.modules ?? [], rejected: meta.rejected, body };
21822
22454
  } catch {
@@ -21885,17 +22517,17 @@ var init_memory_review = __esm({
21885
22517
  });
21886
22518
 
21887
22519
  // src/lib/agent/dismissal-review.ts
21888
- import fs77 from "node:fs";
21889
- import path78 from "node:path";
22520
+ import fs80 from "node:fs";
22521
+ import path81 from "node:path";
21890
22522
  function rejectionsToReview() {
21891
- const dir = path78.join(ARCHIVE, REJECTIONS_TO_REVIEW);
21892
- if (!fs77.existsSync(dir)) return [];
22523
+ const dir = path81.join(ARCHIVE, REJECTIONS_TO_REVIEW);
22524
+ if (!fs80.existsSync(dir)) return [];
21893
22525
  const found2 = [];
21894
22526
  for (const file of walkMd(dir)) {
21895
22527
  const id = archivedId(file);
21896
22528
  if (id === null) continue;
21897
22529
  try {
21898
- const { meta } = parseFrontmatter(fs77.readFileSync(file, "utf8"));
22530
+ const { meta } = parseFrontmatter(fs80.readFileSync(file, "utf8"));
21899
22531
  if (!meta?.rejected || meta.rejected_by !== "user" || !meta.rejected_reason.trim()) continue;
21900
22532
  found2.push({ id, title: meta.title, file: rel(file), reason: meta.rejected_reason.trim(), rejectedAt: meta.rejected_at });
21901
22533
  } catch {
@@ -21925,7 +22557,7 @@ function citedSources(text5) {
21925
22557
  function withdrawnSources() {
21926
22558
  const cited = [...new Set(plannerCopies("rejected.md").flatMap((file) => {
21927
22559
  try {
21928
- return citedSources(fs77.readFileSync(file, "utf8"));
22560
+ return citedSources(fs80.readFileSync(file, "utf8"));
21929
22561
  } catch {
21930
22562
  return [];
21931
22563
  }
@@ -21950,8 +22582,8 @@ var init_dismissal_review = __esm({
21950
22582
  });
21951
22583
 
21952
22584
  // src/lib/agent/flow.ts
21953
- import fs78 from "node:fs";
21954
- import path79 from "node:path";
22585
+ import fs81 from "node:fs";
22586
+ import path82 from "node:path";
21955
22587
  function readCard2(id, home3 = "board") {
21956
22588
  const pending = activeDelivery(id)?.completions?.some((c2) => !c2.finished);
21957
22589
  const found2 = home3 === "archive" ? locateArchived(id) : locate(id) ?? (pending ? locateArchived(id) : null);
@@ -21961,10 +22593,10 @@ function readCard2(id, home3 = "board") {
21961
22593
  { kind: "card-not-found", id }
21962
22594
  );
21963
22595
  }
21964
- const file = found2.kind === "group" ? path79.join(found2.target, "root.md") : found2.target;
22596
+ const file = found2.kind === "group" ? path82.join(found2.target, "root.md") : found2.target;
21965
22597
  let text5;
21966
22598
  try {
21967
- text5 = fs78.readFileSync(file, "utf8");
22599
+ text5 = fs81.readFileSync(file, "utf8");
21968
22600
  } catch {
21969
22601
  die(`#${id} is on the board but ${rel(file)} can't be read.`, { kind: "card-unreadable", id });
21970
22602
  }
@@ -22652,94 +23284,6 @@ var init_refine2 = __esm({
22652
23284
  }
22653
23285
  });
22654
23286
 
22655
- // ../artifact-sdk/src/internal/references.ts
22656
- function bodyReferences(body) {
22657
- const lines = body.replace(/<!--[^]*?-->/g, "").split(/\r?\n/);
22658
- let fence = "";
22659
- let inTag = false;
22660
- const out = [];
22661
- const visible = [];
22662
- for (const line of lines) {
22663
- const delimiter = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1];
22664
- if (fence) {
22665
- if (delimiter && delimiter[0] === fence[0] && delimiter.length >= fence.length) fence = "";
22666
- visible.push("");
22667
- continue;
22668
- }
22669
- if (delimiter) {
22670
- fence = delimiter;
22671
- visible.push("");
22672
- continue;
22673
- }
22674
- const kept2 = inTag || !/^(?: {4}|\t)/.test(line);
22675
- visible.push(kept2 ? line : "");
22676
- if (kept2 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard)\b/.test(line)) inTag = true;
22677
- if (line.includes("/>")) inTag = false;
22678
- }
22679
- const text5 = visible.join("\n").replace(/(`+)[^]*?\1/g, "");
22680
- const tag = /<(Asset|Mockup|Compare|Storyboard)\b([^<>]*?)\/>/g;
22681
- const blocks = text5.matchAll(/^ {0,3}(?:<(?:Asset|Mockup|Compare|Storyboard)\b[^<>]*?\/>[ \t]*(?:\n[ \t]*)?)+$/gm);
22682
- for (const block of blocks) {
22683
- const tags = [...block[0].matchAll(tag)];
22684
- for (const m of tags) {
22685
- const a2 = {};
22686
- for (const p2 of m[2].matchAll(/([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) a2[p2[1]] = p2[2] ?? p2[3];
22687
- if (m[1] === "Compare") {
22688
- if (!a2.a || !a2.b) continue;
22689
- for (const k2 of ["a", "b", "shots"]) if (a2[k2]) out.push({ src: a2[k2], purpose: "compare" });
22690
- } else if (a2.src) {
22691
- out.push({ src: a2.src, purpose: m[1] === "Storyboard" ? "storyboard" : "asset" });
22692
- if (a2.variants) {
22693
- try {
22694
- const v = JSON.parse(a2.variants);
22695
- if (isObject(v)) {
22696
- for (const src of Object.values(v)) if (typeof src === "string" && src) out.push({ src, purpose: "asset" });
22697
- }
22698
- } catch {
22699
- }
22700
- }
22701
- }
22702
- }
22703
- }
22704
- for (const m of text5.replace(tag, "").matchAll(/\]\(\s*<?([^\s)>]+)>?(?:\s+["'][^]*?["'])?\s*\)/g)) out.push({ src: m[1], purpose: "asset" });
22705
- return out;
22706
- }
22707
- function kindOf2(ext) {
22708
- if (ext === ".tsx" || ext === ".html") return "html";
22709
- if (ext === ".md" || ext === ".mdx") return "markdown";
22710
- const type = TYPES2[ext] ?? "";
22711
- if (type.startsWith("image/")) return "image";
22712
- return type.startsWith("video/") || type.startsWith("audio/") ? "video" : "asset";
22713
- }
22714
- var isObject, bodySources, TYPES2;
22715
- var init_references = __esm({
22716
- "../artifact-sdk/src/internal/references.ts"() {
22717
- "use strict";
22718
- isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
22719
- bodySources = (body) => [...new Set(bodyReferences(body).map((r2) => r2.src))];
22720
- TYPES2 = {
22721
- ".png": "image/png",
22722
- ".jpg": "image/jpeg",
22723
- ".jpeg": "image/jpeg",
22724
- ".gif": "image/gif",
22725
- ".webp": "image/webp",
22726
- ".svg": "image/svg+xml",
22727
- ".mp4": "video/mp4",
22728
- ".webm": "video/webm",
22729
- ".mp3": "audio/mpeg",
22730
- ".pdf": "application/pdf",
22731
- ".html": "text/html",
22732
- ".md": "text/markdown",
22733
- ".mdx": "text/markdown",
22734
- ".mov": "video/quicktime",
22735
- ".wav": "audio/wav",
22736
- ".m4a": "audio/mp4",
22737
- ".json": "application/json",
22738
- ".txt": "text/plain"
22739
- };
22740
- }
22741
- });
22742
-
22743
23287
  // node_modules/react/cjs/react.production.js
22744
23288
  var require_react_production = __commonJS({
22745
23289
  "node_modules/react/cjs/react.production.js"(exports) {
@@ -30263,13 +30807,13 @@ var require_react_dom_server_node_production = __commonJS({
30263
30807
  var target = currentView;
30264
30808
  0 < writtenBytes && (target = currentView.subarray(writtenBytes));
30265
30809
  target = textEncoder.encodeInto(chunk, target);
30266
- var read4 = target.read;
30810
+ var read5 = target.read;
30267
30811
  writtenBytes += target.written;
30268
- read4 < chunk.length && (writeToDestination(
30812
+ read5 < chunk.length && (writeToDestination(
30269
30813
  destination,
30270
30814
  currentView.subarray(0, writtenBytes)
30271
30815
  ), currentView = new Uint8Array(4096), writtenBytes = textEncoder.encodeInto(
30272
- chunk.slice(read4),
30816
+ chunk.slice(read5),
30273
30817
  currentView
30274
30818
  ).written);
30275
30819
  4096 === writtenBytes && (writeToDestination(destination, currentView), currentView = new Uint8Array(4096), writtenBytes = 0);
@@ -44019,13 +44563,13 @@ var require_react_dom_server_node_development = __commonJS({
44019
44563
  var target = currentView;
44020
44564
  0 < writtenBytes && (target = currentView.subarray(writtenBytes));
44021
44565
  target = textEncoder.encodeInto(chunk, target);
44022
- var read4 = target.read;
44566
+ var read5 = target.read;
44023
44567
  writtenBytes += target.written;
44024
- read4 < chunk.length && (writeToDestination(
44568
+ read5 < chunk.length && (writeToDestination(
44025
44569
  destination,
44026
44570
  currentView.subarray(0, writtenBytes)
44027
44571
  ), currentView = new Uint8Array(4096), writtenBytes = textEncoder.encodeInto(
44028
- chunk.slice(read4),
44572
+ chunk.slice(read5),
44029
44573
  currentView
44030
44574
  ).written);
44031
44575
  4096 === writtenBytes && (writeToDestination(destination, currentView), currentView = new Uint8Array(4096), writtenBytes = 0);
@@ -63947,8 +64491,8 @@ var require_JSXTransformer = __commonJS({
63947
64491
  }
63948
64492
  if (this.isAutomaticRuntime) {
63949
64493
  if (this.importProcessor) {
63950
- for (const [path87, resolvedName] of Object.entries(this.cjsAutomaticModuleNameResolutions)) {
63951
- prefix += `var ${resolvedName} = require("${path87}");`;
64494
+ for (const [path90, resolvedName] of Object.entries(this.cjsAutomaticModuleNameResolutions)) {
64495
+ prefix += `var ${resolvedName} = require("${path90}");`;
63952
64496
  }
63953
64497
  } else {
63954
64498
  const { createElement: createElementResolution, ...otherResolutions } = this.esmAutomaticImportNameResolutions;
@@ -64141,11 +64685,11 @@ var require_JSXTransformer = __commonJS({
64141
64685
  }
64142
64686
  claimAutoImportedName(funcName, importPathSuffix) {
64143
64687
  if (this.importProcessor) {
64144
- const path87 = this.jsxImportSource + importPathSuffix;
64145
- if (!this.cjsAutomaticModuleNameResolutions[path87]) {
64146
- this.cjsAutomaticModuleNameResolutions[path87] = this.importProcessor.getFreeIdentifierForPath(path87);
64688
+ const path90 = this.jsxImportSource + importPathSuffix;
64689
+ if (!this.cjsAutomaticModuleNameResolutions[path90]) {
64690
+ this.cjsAutomaticModuleNameResolutions[path90] = this.importProcessor.getFreeIdentifierForPath(path90);
64147
64691
  }
64148
- return `${this.cjsAutomaticModuleNameResolutions[path87]}.${funcName}`;
64692
+ return `${this.cjsAutomaticModuleNameResolutions[path90]}.${funcName}`;
64149
64693
  } else {
64150
64694
  if (!this.esmAutomaticImportNameResolutions[funcName]) {
64151
64695
  this.esmAutomaticImportNameResolutions[funcName] = this.nameManager.claimFreeName(
@@ -64581,7 +65125,7 @@ var require_CJSImportProcessor = __commonJS({
64581
65125
  */
64582
65126
  pruneTypeOnlyImports() {
64583
65127
  this.nonTypeIdentifiers = _getNonTypeIdentifiers.getNonTypeIdentifiers.call(void 0, this.tokens, this.options);
64584
- for (const [path87, importInfo] of this.importInfoByPath.entries()) {
65128
+ for (const [path90, importInfo] of this.importInfoByPath.entries()) {
64585
65129
  if (importInfo.hasBareImport || importInfo.hasStarExport || importInfo.exportStarNames.length > 0 || importInfo.namedExports.length > 0) {
64586
65130
  continue;
64587
65131
  }
@@ -64591,7 +65135,7 @@ var require_CJSImportProcessor = __commonJS({
64591
65135
  ...importInfo.namedImports.map(({ localName }) => localName)
64592
65136
  ];
64593
65137
  if (names3.every((name) => this.shouldAutomaticallyElideImportedName(name))) {
64594
- this.importsToReplace.set(path87, "");
65138
+ this.importsToReplace.set(path90, "");
64595
65139
  }
64596
65140
  }
64597
65141
  }
@@ -64599,7 +65143,7 @@ var require_CJSImportProcessor = __commonJS({
64599
65143
  return this.isTypeScriptTransformEnabled && !this.keepUnusedImports && !this.nonTypeIdentifiers.has(name);
64600
65144
  }
64601
65145
  generateImportReplacements() {
64602
- for (const [path87, importInfo] of this.importInfoByPath.entries()) {
65146
+ for (const [path90, importInfo] of this.importInfoByPath.entries()) {
64603
65147
  const {
64604
65148
  defaultNames,
64605
65149
  wildcardNames,
@@ -64609,17 +65153,17 @@ var require_CJSImportProcessor = __commonJS({
64609
65153
  hasStarExport
64610
65154
  } = importInfo;
64611
65155
  if (defaultNames.length === 0 && wildcardNames.length === 0 && namedImports.length === 0 && namedExports.length === 0 && exportStarNames.length === 0 && !hasStarExport) {
64612
- this.importsToReplace.set(path87, `require('${path87}');`);
65156
+ this.importsToReplace.set(path90, `require('${path90}');`);
64613
65157
  continue;
64614
65158
  }
64615
- const primaryImportName = this.getFreeIdentifierForPath(path87);
65159
+ const primaryImportName = this.getFreeIdentifierForPath(path90);
64616
65160
  let secondaryImportName;
64617
65161
  if (this.enableLegacyTypeScriptModuleInterop) {
64618
65162
  secondaryImportName = primaryImportName;
64619
65163
  } else {
64620
- secondaryImportName = wildcardNames.length > 0 ? wildcardNames[0] : this.getFreeIdentifierForPath(path87);
65164
+ secondaryImportName = wildcardNames.length > 0 ? wildcardNames[0] : this.getFreeIdentifierForPath(path90);
64621
65165
  }
64622
- let requireCode = `var ${primaryImportName} = require('${path87}');`;
65166
+ let requireCode = `var ${primaryImportName} = require('${path90}');`;
64623
65167
  if (wildcardNames.length > 0) {
64624
65168
  for (const wildcardName of wildcardNames) {
64625
65169
  const moduleExpr = this.enableLegacyTypeScriptModuleInterop ? primaryImportName : `${this.helperManager.getHelperName("interopRequireWildcard")}(${primaryImportName})`;
@@ -64647,7 +65191,7 @@ var require_CJSImportProcessor = __commonJS({
64647
65191
  "createStarExport"
64648
65192
  )}(${primaryImportName});`;
64649
65193
  }
64650
- this.importsToReplace.set(path87, requireCode);
65194
+ this.importsToReplace.set(path90, requireCode);
64651
65195
  for (const defaultName of defaultNames) {
64652
65196
  this.identifierReplacements.set(defaultName, `${secondaryImportName}.default`);
64653
65197
  }
@@ -64656,8 +65200,8 @@ var require_CJSImportProcessor = __commonJS({
64656
65200
  }
64657
65201
  }
64658
65202
  }
64659
- getFreeIdentifierForPath(path87) {
64660
- const components = path87.split("/");
65203
+ getFreeIdentifierForPath(path90) {
65204
+ const components = path90.split("/");
64661
65205
  const lastComponent = components[components.length - 1];
64662
65206
  const baseName = lastComponent.replace(/\W/g, "");
64663
65207
  return this.nameManager.claimFreeName(`_${baseName}`);
@@ -64702,8 +65246,8 @@ var require_CJSImportProcessor = __commonJS({
64702
65246
  if (!this.tokens.matches1AtIndex(index, _types.TokenType.string)) {
64703
65247
  throw new Error("Expected string token at the end of import statement.");
64704
65248
  }
64705
- const path87 = this.tokens.stringValueAtIndex(index);
64706
- const importInfo = this.getImportInfo(path87);
65249
+ const path90 = this.tokens.stringValueAtIndex(index);
65250
+ const importInfo = this.getImportInfo(path90);
64707
65251
  importInfo.defaultNames.push(...defaultNames);
64708
65252
  importInfo.wildcardNames.push(...wildcardNames);
64709
65253
  importInfo.namedImports.push(...namedImports);
@@ -64770,8 +65314,8 @@ var require_CJSImportProcessor = __commonJS({
64770
65314
  if (!this.tokens.matches1AtIndex(index, _types.TokenType.string)) {
64771
65315
  throw new Error("Expected string token at the end of import statement.");
64772
65316
  }
64773
- const path87 = this.tokens.stringValueAtIndex(index);
64774
- const importInfo = this.getImportInfo(path87);
65317
+ const path90 = this.tokens.stringValueAtIndex(index);
65318
+ const importInfo = this.getImportInfo(path90);
64775
65319
  importInfo.namedExports.push(...namedImports);
64776
65320
  }
64777
65321
  preprocessExportStarAtIndex(index) {
@@ -64786,8 +65330,8 @@ var require_CJSImportProcessor = __commonJS({
64786
65330
  if (!this.tokens.matches1AtIndex(index, _types.TokenType.string)) {
64787
65331
  throw new Error("Expected string token at the end of star export statement.");
64788
65332
  }
64789
- const path87 = this.tokens.stringValueAtIndex(index);
64790
- const importInfo = this.getImportInfo(path87);
65333
+ const path90 = this.tokens.stringValueAtIndex(index);
65334
+ const importInfo = this.getImportInfo(path90);
64791
65335
  if (exportedName !== null) {
64792
65336
  importInfo.exportStarNames.push(exportedName);
64793
65337
  } else {
@@ -64827,8 +65371,8 @@ var require_CJSImportProcessor = __commonJS({
64827
65371
  * Get a mutable import info object for this path, creating one if it doesn't
64828
65372
  * exist yet.
64829
65373
  */
64830
- getImportInfo(path87) {
64831
- const existingInfo = this.importInfoByPath.get(path87);
65374
+ getImportInfo(path90) {
65375
+ const existingInfo = this.importInfoByPath.get(path90);
64832
65376
  if (existingInfo) {
64833
65377
  return existingInfo;
64834
65378
  }
@@ -64841,7 +65385,7 @@ var require_CJSImportProcessor = __commonJS({
64841
65385
  exportStarNames: [],
64842
65386
  hasStarExport: false
64843
65387
  };
64844
- this.importInfoByPath.set(path87, newInfo);
65388
+ this.importInfoByPath.set(path90, newInfo);
64845
65389
  return newInfo;
64846
65390
  }
64847
65391
  addExportBinding(localName, exportedName) {
@@ -65421,16 +65965,16 @@ var require_resolve_uri_umd = __commonJS({
65421
65965
  }
65422
65966
  function parseFileUrl(input) {
65423
65967
  const match = fileRegex.exec(input);
65424
- const path87 = match[2];
65425
- return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path87) ? path87 : "/" + path87, match[3] || "", match[4] || "");
65968
+ const path90 = match[2];
65969
+ return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path90) ? path90 : "/" + path90, match[3] || "", match[4] || "");
65426
65970
  }
65427
- function makeUrl(scheme, user, host2, port, path87, query, hash2) {
65971
+ function makeUrl(scheme, user, host2, port, path90, query, hash2) {
65428
65972
  return {
65429
65973
  scheme,
65430
65974
  user,
65431
65975
  host: host2,
65432
65976
  port,
65433
- path: path87,
65977
+ path: path90,
65434
65978
  query,
65435
65979
  hash: hash2,
65436
65980
  type: 7
@@ -65460,11 +66004,11 @@ var require_resolve_uri_umd = __commonJS({
65460
66004
  url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
65461
66005
  return url;
65462
66006
  }
65463
- function stripPathFilename(path87) {
65464
- if (path87.endsWith("/.."))
65465
- return path87;
65466
- const index = path87.lastIndexOf("/");
65467
- return path87.slice(0, index + 1);
66007
+ function stripPathFilename(path90) {
66008
+ if (path90.endsWith("/.."))
66009
+ return path90;
66010
+ const index = path90.lastIndexOf("/");
66011
+ return path90.slice(0, index + 1);
65468
66012
  }
65469
66013
  function mergePaths(url, base) {
65470
66014
  normalizePath(base, base.type);
@@ -65502,14 +66046,14 @@ var require_resolve_uri_umd = __commonJS({
65502
66046
  pieces[pointer++] = piece;
65503
66047
  positive++;
65504
66048
  }
65505
- let path87 = "";
66049
+ let path90 = "";
65506
66050
  for (let i = 1; i < pointer; i++) {
65507
- path87 += "/" + pieces[i];
66051
+ path90 += "/" + pieces[i];
65508
66052
  }
65509
- if (!path87 || addTrailingSlash && !path87.endsWith("/..")) {
65510
- path87 += "/";
66053
+ if (!path90 || addTrailingSlash && !path90.endsWith("/..")) {
66054
+ path90 += "/";
65511
66055
  }
65512
- url.path = path87;
66056
+ url.path = path90;
65513
66057
  }
65514
66058
  function resolve2(input, base) {
65515
66059
  if (!input && !base)
@@ -65550,13 +66094,13 @@ var require_resolve_uri_umd = __commonJS({
65550
66094
  case 3:
65551
66095
  return queryHash;
65552
66096
  case 4: {
65553
- const path87 = url.path.slice(1);
65554
- if (!path87)
66097
+ const path90 = url.path.slice(1);
66098
+ if (!path90)
65555
66099
  return queryHash || ".";
65556
- if (isRelative(base || input) && !isRelative(path87)) {
65557
- return "./" + path87 + queryHash;
66100
+ if (isRelative(base || input) && !isRelative(path90)) {
66101
+ return "./" + path90 + queryHash;
65558
66102
  }
65559
- return path87 + queryHash;
66103
+ return path90 + queryHash;
65560
66104
  }
65561
66105
  case 5:
65562
66106
  return url.path + queryHash;
@@ -65655,12 +66199,12 @@ var require_trace_mapping_umd = __commonJS({
65655
66199
  module2.exports = __toCommonJS(trace_mapping_exports);
65656
66200
  var import_sourcemap_codec = __toESM2(require_sourcemap_codec());
65657
66201
  var import_resolve_uri = __toESM2(require_resolve_uri());
65658
- function stripFilename(path87) {
65659
- if (!path87) return "";
65660
- const index = path87.lastIndexOf("/");
65661
- return path87.slice(0, index + 1);
66202
+ function stripFilename(path90) {
66203
+ if (!path90) return "";
66204
+ const index = path90.lastIndexOf("/");
66205
+ return path90.slice(0, index + 1);
65662
66206
  }
65663
- function resolver(mapUrl, sourceRoot) {
66207
+ function resolver2(mapUrl, sourceRoot) {
65664
66208
  const from = stripFilename(mapUrl);
65665
66209
  const prefix = sourceRoot ? sourceRoot + "/" : "";
65666
66210
  return (source) => (0, import_resolve_uri.default)(prefix + (source || ""), from);
@@ -65909,7 +66453,7 @@ var require_trace_mapping_umd = __commonJS({
65909
66453
  this.sources = sources2;
65910
66454
  this.sourcesContent = sourcesContent;
65911
66455
  this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
65912
- const resolve2 = resolver(mapUrl, sourceRoot);
66456
+ const resolve2 = resolver2(mapUrl, sourceRoot);
65913
66457
  this.resolvedSources = sources2.map(resolve2);
65914
66458
  const { mappings } = parsed;
65915
66459
  if (typeof mappings === "string") {
@@ -66866,9 +67410,9 @@ var require_util2 = __commonJS({
66866
67410
  /** @class */
66867
67411
  (function(_super) {
66868
67412
  __extends(VError2, _super);
66869
- function VError2(path87, message) {
67413
+ function VError2(path90, message) {
66870
67414
  var _this = _super.call(this, message) || this;
66871
- _this.path = path87;
67415
+ _this.path = path90;
66872
67416
  Object.setPrototypeOf(_this, VError2.prototype);
66873
67417
  return _this;
66874
67418
  }
@@ -66928,26 +67472,26 @@ var require_util2 = __commonJS({
66928
67472
  (_b = this._messages).push.apply(_b, best._messages);
66929
67473
  }
66930
67474
  };
66931
- DetailContext2.prototype.getError = function(path87) {
67475
+ DetailContext2.prototype.getError = function(path90) {
66932
67476
  var msgParts = [];
66933
67477
  for (var i = this._propNames.length - 1; i >= 0; i--) {
66934
67478
  var p2 = this._propNames[i];
66935
- path87 += typeof p2 === "number" ? "[" + p2 + "]" : p2 ? "." + p2 : "";
67479
+ path90 += typeof p2 === "number" ? "[" + p2 + "]" : p2 ? "." + p2 : "";
66936
67480
  var m = this._messages[i];
66937
67481
  if (m) {
66938
- msgParts.push(path87 + " " + m);
67482
+ msgParts.push(path90 + " " + m);
66939
67483
  }
66940
67484
  }
66941
- return new VError(path87, msgParts.join("; "));
67485
+ return new VError(path90, msgParts.join("; "));
66942
67486
  };
66943
- DetailContext2.prototype.getErrorDetail = function(path87) {
67487
+ DetailContext2.prototype.getErrorDetail = function(path90) {
66944
67488
  var details = [];
66945
67489
  for (var i = this._propNames.length - 1; i >= 0; i--) {
66946
67490
  var p2 = this._propNames[i];
66947
- path87 += typeof p2 === "number" ? "[" + p2 + "]" : p2 ? "." + p2 : "";
67491
+ path90 += typeof p2 === "number" ? "[" + p2 + "]" : p2 ? "." + p2 : "";
66948
67492
  var message = this._messages[i];
66949
67493
  if (message) {
66950
- details.push({ path: path87, message });
67494
+ details.push({ path: path90, message });
66951
67495
  }
66952
67496
  }
66953
67497
  var detail = null;
@@ -67760,8 +68304,8 @@ var require_dist = __commonJS({
67760
68304
  this.checkerPlain = this.ttype.getChecker(suite, false);
67761
68305
  this.checkerStrict = this.ttype.getChecker(suite, true);
67762
68306
  }
67763
- Checker2.prototype.setReportedPath = function(path87) {
67764
- this._path = path87;
68307
+ Checker2.prototype.setReportedPath = function(path90) {
68308
+ this._path = path90;
67765
68309
  };
67766
68310
  Checker2.prototype.check = function(value) {
67767
68311
  return this._doCheck(this.checkerPlain, value);
@@ -73194,9 +73738,9 @@ var require_CJSImportTransformer = __commonJS({
73194
73738
  if (shouldElideImport) {
73195
73739
  this.tokens.removeToken();
73196
73740
  } else {
73197
- const path87 = this.tokens.stringValue();
73198
- this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path87));
73199
- this.tokens.appendCode(this.importProcessor.claimImportCode(path87));
73741
+ const path90 = this.tokens.stringValue();
73742
+ this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path90));
73743
+ this.tokens.appendCode(this.importProcessor.claimImportCode(path90));
73200
73744
  }
73201
73745
  _removeMaybeImportAttributes.removeMaybeImportAttributes.call(void 0, this.tokens);
73202
73746
  if (this.tokens.matches1(_types.TokenType.semi)) {
@@ -73776,8 +74320,8 @@ var require_CJSImportTransformer = __commonJS({
73776
74320
  }
73777
74321
  if (this.tokens.matchesContextual(_keywords.ContextualKeyword._from)) {
73778
74322
  this.tokens.removeToken();
73779
- const path87 = this.tokens.stringValue();
73780
- this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path87));
74323
+ const path90 = this.tokens.stringValue();
74324
+ this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path90));
73781
74325
  _removeMaybeImportAttributes.removeMaybeImportAttributes.call(void 0, this.tokens);
73782
74326
  } else {
73783
74327
  this.tokens.appendCode(exportStatements.join(" "));
@@ -73791,8 +74335,8 @@ var require_CJSImportTransformer = __commonJS({
73791
74335
  while (!this.tokens.matches1(_types.TokenType.string)) {
73792
74336
  this.tokens.removeToken();
73793
74337
  }
73794
- const path87 = this.tokens.stringValue();
73795
- this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path87));
74338
+ const path90 = this.tokens.stringValue();
74339
+ this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path90));
73796
74340
  _removeMaybeImportAttributes.removeMaybeImportAttributes.call(void 0, this.tokens);
73797
74341
  if (this.tokens.matches1(_types.TokenType.semi)) {
73798
74342
  this.tokens.removeToken();
@@ -103646,9 +104190,9 @@ var init_bundle_mjs = __esm({
103646
104190
  processClassesRecursively(value, getPart(classPartObject, key), classGroupId, theme);
103647
104191
  }
103648
104192
  };
103649
- getPart = (classPartObject, path87) => {
104193
+ getPart = (classPartObject, path90) => {
103650
104194
  let current = classPartObject;
103651
- const parts = path87.split(CLASS_PART_SEPARATOR);
104195
+ const parts = path90.split(CLASS_PART_SEPARATOR);
103652
104196
  const len = parts.length;
103653
104197
  for (let i = 0; i < len; i++) {
103654
104198
  const part = parts[i];
@@ -106898,8 +107442,8 @@ var init_dist = __esm({
106898
107442
  });
106899
107443
 
106900
107444
  // src/lib/draw-mockup.ts
106901
- import fs79 from "node:fs";
106902
- import path81 from "node:path";
107445
+ import fs82 from "node:fs";
107446
+ import path84 from "node:path";
106903
107447
  import vm from "node:vm";
106904
107448
  async function loadPackage(id) {
106905
107449
  if (id === "react") return import_react3.default;
@@ -106912,22 +107456,22 @@ async function loadPackage(id) {
106912
107456
  return { __esModule: true, ...await load() };
106913
107457
  }
106914
107458
  function resolveFile(id, from, folder) {
106915
- const at2 = path81.resolve(path81.dirname(from), id);
106916
- if (at2 !== folder && !at2.startsWith(folder + path81.sep)) throw new Error(`${id} is outside the mockup's folder`);
106917
- const tries = path81.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path81.join(at2, `index${e2}`))];
106918
- const file = tries.find((f2) => fs79.statSync(f2, { throwIfNoEntry: false })?.isFile());
107459
+ const at2 = path84.resolve(path84.dirname(from), id);
107460
+ if (at2 !== folder && !at2.startsWith(folder + path84.sep)) throw new Error(`${id} is outside the mockup's folder`);
107461
+ const tries = path84.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path84.join(at2, `index${e2}`))];
107462
+ const file = tries.find((f2) => fs82.statSync(f2, { throwIfNoEntry: false })?.isFile());
106919
107463
  if (!file) throw new Error(`no such file: ${id}`);
106920
107464
  return file;
106921
107465
  }
106922
107466
  async function readGraph(entry) {
106923
- const folder = path81.dirname(entry);
107467
+ const folder = path84.dirname(entry);
106924
107468
  const graph = { code: /* @__PURE__ */ new Map(), links: /* @__PURE__ */ new Map(), sheets: [], packages: /* @__PURE__ */ new Map() };
106925
107469
  const walk3 = async (file) => {
106926
107470
  if (graph.code.has(file)) return;
106927
107471
  if (graph.code.size >= MAX_FILES) throw new Error(`a mockup imports more than ${MAX_FILES} files`);
106928
107472
  let location = file;
106929
107473
  try {
106930
- const js = (0, import_sucrase.transform)(fs79.readFileSync(file, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file }).code;
107474
+ const js = (0, import_sucrase.transform)(fs82.readFileSync(file, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file }).code;
106931
107475
  graph.code.set(file, js);
106932
107476
  const link2 = /* @__PURE__ */ new Map();
106933
107477
  graph.links.set(file, link2);
@@ -106941,7 +107485,7 @@ async function readGraph(entry) {
106941
107485
  const target = resolveFile(id, file, folder);
106942
107486
  link2.set(id, target);
106943
107487
  if (!target.endsWith(".css")) await walk3(target);
106944
- else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs79.readFileSync(target, "utf8") });
107488
+ else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs82.readFileSync(target, "utf8") });
106945
107489
  }
106946
107490
  } catch (error) {
106947
107491
  throw new Error(`${location}: ${error instanceof Error ? error.message : String(error)}`);
@@ -106958,29 +107502,17 @@ function run2(script, context, name, deadline, lineOffset = 0) {
106958
107502
  async function tailwindFor(markup, sheets) {
106959
107503
  const source = sheets.length ? sheets.map((s) => s.content).join("\n") : '@import "tailwindcss";';
106960
107504
  const compiler = await rc(source, {
106961
- base: sheets.length ? path81.dirname(sheets[0].path) : "/",
107505
+ base: sheets.length ? path84.dirname(sheets[0].path) : "/",
106962
107506
  loadStylesheet: async (id, from) => {
106963
107507
  if (id === "tailwindcss" || id.startsWith("tailwindcss/")) return { path: "tailwindcss/index.css", base: "/", content: tailwindcss_default };
106964
107508
  if (!id.startsWith(".")) throw new Error(`a mockup cannot import ${id}`);
106965
- const at2 = path81.resolve(from, id);
106966
- return { path: at2, base: path81.dirname(at2), content: fs79.readFileSync(at2, "utf8") };
107509
+ const at2 = path84.resolve(from, id);
107510
+ return { path: at2, base: path84.dirname(at2), content: fs82.readFileSync(at2, "utf8") };
106967
107511
  }
106968
107512
  });
106969
107513
  const classes = [...markup.matchAll(/class="([^"]*)"/g)].flatMap((m) => m[1].split(/\s+/));
106970
107514
  return compiler.build(classes.filter(Boolean));
106971
107515
  }
106972
- function dressPage(file) {
106973
- const folder = path81.dirname(file);
106974
- const html = fs79.readFileSync(file, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
106975
- const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
106976
- if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
106977
- const at3 = path81.resolve(folder, href);
106978
- if (!at3.startsWith(folder + path81.sep) || !fs79.existsSync(at3)) return tag;
106979
- return `<style>${fs79.readFileSync(at3, "utf8").replace(/<\/style/gi, "<\\/style")}</style>`;
106980
- });
106981
- const at2 = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
106982
- return /<!doctype\b|<html[\s>]|<head[\s>]/i.test(html) ? html.slice(0, at2) + head + html.slice(at2) : `<!doctype html><html><head>${head}</head><body>${html}</body></html>`;
106983
- }
106984
107516
  async function drawMockup(entry) {
106985
107517
  if (entry.toLowerCase().endsWith(".html")) return dressPage(entry);
106986
107518
  const graph = await readGraph(entry);
@@ -107027,7 +107559,7 @@ ${graph.code.get(file)}
107027
107559
  const css = (await tailwindFor(markup, graph.sheets)).replace(/<\/style/gi, "<\\/style");
107028
107560
  return `<!doctype html><html><head>${head}<style>${css}</style></head><body>${markup}</body></html>`;
107029
107561
  }
107030
- var import_react3, JSX, import_server, import_sucrase, DRAW_MS, MAX_FILES, CODE_EXTS, REQUIRES, NOTHING, NEXT_LINK, NEXT_IMAGE, NEXT_NAVIGATION, PACKAGES, CSP, head;
107562
+ var import_react3, JSX, import_server, import_sucrase, DRAW_MS, MAX_FILES, CODE_EXTS, REQUIRES, NOTHING, NEXT_LINK, NEXT_IMAGE, NEXT_NAVIGATION, PACKAGES;
107031
107563
  var init_draw_mockup = __esm({
107032
107564
  "src/lib/draw-mockup.ts"() {
107033
107565
  "use strict";
@@ -107037,6 +107569,7 @@ var init_draw_mockup = __esm({
107037
107569
  import_sucrase = __toESM(require_dist2(), 1);
107038
107570
  init_lib();
107039
107571
  init_tailwindcss();
107572
+ init_dress_page();
107040
107573
  DRAW_MS = 5e3;
107041
107574
  MAX_FILES = 60;
107042
107575
  CODE_EXTS = [".tsx", ".ts", ".jsx", ".js", ".mjs"];
@@ -107079,14 +107612,12 @@ var init_draw_mockup = __esm({
107079
107612
  "tailwind-merge": () => Promise.resolve().then(() => (init_bundle_mjs(), bundle_mjs_exports)),
107080
107613
  "class-variance-authority": () => Promise.resolve().then(() => (init_dist(), dist_exports))
107081
107614
  };
107082
- CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; media-src data:; font-src data:; worker-src 'none'; base-uri 'none'; form-action 'none'";
107083
- 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>`;
107084
107615
  }
107085
107616
  });
107086
107617
 
107087
107618
  // src/lib/preview-validation.ts
107088
- import fs80 from "node:fs";
107089
- import path82 from "node:path";
107619
+ import fs83 from "node:fs";
107620
+ import path85 from "node:path";
107090
107621
  function renderError(error) {
107091
107622
  if (!error || typeof error !== "object") return String(error);
107092
107623
  const { message, stack } = error;
@@ -107097,7 +107628,7 @@ function renderError(error) {
107097
107628
  async function validateScreens(files2) {
107098
107629
  const errors = [];
107099
107630
  const entries = /* @__PURE__ */ new Map();
107100
- for (const file of files2) entries.set(fs80.existsSync(file) ? fs80.realpathSync(file) : path82.resolve(file), path82.resolve(file));
107631
+ for (const file of files2) entries.set(fs83.existsSync(file) ? fs83.realpathSync(file) : path85.resolve(file), path85.resolve(file));
107101
107632
  for (const file of entries.values()) {
107102
107633
  try {
107103
107634
  await drawMockup(file);
@@ -107116,7 +107647,7 @@ async function validatePreview(file, text5) {
107116
107647
  if (/^ {0,3}<!--\s*agent\s*-->\s*$/.test(line)) own = false;
107117
107648
  if (own) section.push(line);
107118
107649
  }
107119
- const files2 = bodySources(section.join("\n")).filter((src) => !/^[a-z][\w+.-]*:|^#|^\/\//i.test(src) && kindOf2(path82.extname(src).toLowerCase()) === "html").map((src) => src.startsWith(".assets/") ? path82.join(ASSETS, src.slice(8)) : src.startsWith(".mockups/") ? path82.join(MOCKUPS, src.slice(9)) : path82.resolve(path82.dirname(file), src));
107650
+ const files2 = bodySources(section.join("\n")).filter((src) => !/^[a-z][\w+.-]*:|^#|^\/\//i.test(src) && kindOf(path85.extname(src).toLowerCase()) === "html").map((src) => src.startsWith(".assets/") ? path85.join(ASSETS, src.slice(8)) : src.startsWith(".mockups/") ? path85.join(MOCKUPS, src.slice(9)) : path85.resolve(path85.dirname(file), src));
107120
107651
  return validateScreens(files2);
107121
107652
  }
107122
107653
  var init_preview_validation = __esm({
@@ -107273,7 +107804,7 @@ __export(watch_exports, {
107273
107804
  watchRun: () => watchRun
107274
107805
  });
107275
107806
  import { spawn as spawn4 } from "node:child_process";
107276
- import fs81 from "node:fs";
107807
+ import fs84 from "node:fs";
107277
107808
  async function watchRun(sessionId, resume = startResume) {
107278
107809
  const spec = readSpec(sessionId);
107279
107810
  const run3 = peekRun(sessionId);
@@ -107309,11 +107840,11 @@ async function watchRun(sessionId, resume = startResume) {
107309
107840
  const record = claimed ?? run3;
107310
107841
  const sub = record.action === "sub";
107311
107842
  if (claim) await setCardStatus(claim.cardId, claim.status);
107312
- fs81.mkdirSync(SESSIONS_DIR, { recursive: true });
107313
- const logFile = fs81.createWriteStream(record.logPath, { flags: "a" });
107843
+ fs84.mkdirSync(SESSIONS_DIR, { recursive: true });
107844
+ const logFile = fs84.createWriteStream(record.logPath, { flags: "a" });
107314
107845
  logFile.on("error", () => {
107315
107846
  });
107316
- const eventsFile = fs81.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
107847
+ const eventsFile = fs84.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
107317
107848
  eventsFile.on("error", () => {
107318
107849
  });
107319
107850
  const event2 = (e2) => eventsFile.write(`${JSON.stringify(e2)}
@@ -107792,8 +108323,8 @@ function brokeBoard(wasBroken) {
107792
108323
  if (!broke.length) return null;
107793
108324
  const shown = broke.slice(0, MAX_BROKEN);
107794
108325
  const rest = broke.length - shown.length;
107795
- const why = { kind: "broken", args: { n: String(broke.length), more: String(rest) }, lines: shown };
107796
- return { why, note: [
108326
+ const why2 = { kind: "broken", args: { n: String(broke.length), more: String(rest) }, lines: shown };
108327
+ return { why: why2, note: [
107797
108328
  `the work is done, but the board came out of this run inconsistent \u2014 ${broke.length} thing${broke.length === 1 ? "" : "s"} to put right:`,
107798
108329
  ...shown.map((line) => ` ${line}`),
107799
108330
  ...rest ? [` \u2026 and ${rest} more`] : [],
@@ -107907,7 +108438,7 @@ var init_watch = __esm({
107907
108438
  });
107908
108439
 
107909
108440
  // src/kanban.ts
107910
- import fs87 from "node:fs";
108441
+ import fs90 from "node:fs";
107911
108442
  import { fileURLToPath as fileURLToPath4 } from "node:url";
107912
108443
 
107913
108444
  // src/lib/cli/agent.ts
@@ -108390,8 +108921,8 @@ async function testAgent(args) {
108390
108921
  }
108391
108922
 
108392
108923
  // src/commands/cloud.ts
108393
- import fs70 from "node:fs";
108394
- import path71 from "node:path";
108924
+ import fs72 from "node:fs";
108925
+ import path73 from "node:path";
108395
108926
 
108396
108927
  // src/lib/cloud/avatar.ts
108397
108928
  init_session();
@@ -108439,13 +108970,13 @@ init_config();
108439
108970
  init_home();
108440
108971
  init_config();
108441
108972
  init_session();
108442
- import fs69 from "node:fs";
108443
- import path70 from "node:path";
108973
+ import fs71 from "node:fs";
108974
+ import path72 from "node:path";
108444
108975
  var FRESH_MS2 = 10 * 6e4;
108445
108976
  var GRACE_MS = 7 * 24 * 60 * 6e4;
108446
- var heldFile = () => path70.join(machineHome(), "pro.json");
108977
+ var heldFile = () => path72.join(machineHome(), "pro.json");
108447
108978
  function forgetPro() {
108448
- fs69.rmSync(heldFile(), { force: true });
108979
+ fs71.rmSync(heldFile(), { force: true });
108449
108980
  }
108450
108981
 
108451
108982
  // src/lib/cloud/account.ts
@@ -108622,10 +109153,10 @@ async function cloudImage(opts, program2) {
108622
109153
  const prompt = opts.prompt.trim();
108623
109154
  if (!prompt) usage("Missing the prompt.", line);
108624
109155
  const references = opts.refs.map((file) => {
108625
- const type = REF_TYPES[path71.extname(file).toLowerCase()];
109156
+ const type = REF_TYPES[path73.extname(file).toLowerCase()];
108626
109157
  if (!type) usage(`--ref ${file}: use a PNG, JPEG or WebP file.`, line);
108627
109158
  try {
108628
- return `data:${type};base64,${fs70.readFileSync(file).toString("base64")}`;
109159
+ return `data:${type};base64,${fs72.readFileSync(file).toString("base64")}`;
108629
109160
  } catch (e2) {
108630
109161
  usage(`--ref ${file}: ${e2 instanceof Error ? e2.message : String(e2)}`, line);
108631
109162
  }
@@ -108731,8 +109262,8 @@ async function generate(g3) {
108731
109262
  refuse(g3.failed, g3.fallback);
108732
109263
  }
108733
109264
  const out = g3.outFor?.(res, g3.out) ?? g3.out;
108734
- fs70.mkdirSync(path71.dirname(path71.resolve(out)), { recursive: true });
108735
- fs70.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
109265
+ fs72.mkdirSync(path73.dirname(path73.resolve(out)), { recursive: true });
109266
+ fs72.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
108736
109267
  say(`${out} (${g3.label(res)})`);
108737
109268
  return { out };
108738
109269
  }
@@ -108741,35 +109272,35 @@ async function generate(g3) {
108741
109272
  init_board_files();
108742
109273
  init_workflow_files();
108743
109274
  import crypto6 from "node:crypto";
108744
- import fs72 from "node:fs";
108745
- import path73 from "node:path";
109275
+ import fs74 from "node:fs";
109276
+ import path75 from "node:path";
108746
109277
 
108747
109278
  // src/lib/agents/shared-memory.ts
108748
109279
  init_bundled();
108749
109280
  init_parse();
108750
- import fs71 from "node:fs";
108751
- import path72 from "node:path";
109281
+ import fs73 from "node:fs";
109282
+ import path74 from "node:path";
108752
109283
  function sharedMemory(board2) {
108753
109284
  const declared = /* @__PURE__ */ new Map();
108754
109285
  const take = (folder, text5, builtIn) => {
108755
109286
  if (text5 === null || declared.has(folder)) return;
108756
- const read4 = parseSpecAgent(text5, folder, () => null, builtIn);
108757
- if ("agent" in read4 && read4.agent.name === folder) declared.set(folder, read4.agent.memoryFiles.workspace);
109287
+ const read5 = parseSpecAgent(text5, folder, () => null, builtIn);
109288
+ if ("agent" in read5 && read5.agent.name === folder) declared.set(folder, read5.agent.memoryFiles.workspace);
108758
109289
  };
108759
109290
  for (const [key, text5] of Object.entries(shippedAgentFiles())) {
108760
109291
  const at2 = /^([^/]+)\/AGENT\.md$/.exec(key);
108761
109292
  if (at2) take(at2[1], text5, officialAgent(at2[1]));
108762
109293
  }
108763
- const root2 = path72.join(board2, "agents");
109294
+ const root2 = path74.join(board2, "agents");
108764
109295
  let folders2 = [];
108765
109296
  try {
108766
- folders2 = fs71.readdirSync(root2, { withFileTypes: true }).filter((e2) => e2.isDirectory() && !e2.name.startsWith(".")).map((e2) => e2.name);
109297
+ folders2 = fs73.readdirSync(root2, { withFileTypes: true }).filter((e2) => e2.isDirectory() && !e2.name.startsWith(".")).map((e2) => e2.name);
108767
109298
  } catch {
108768
109299
  }
108769
109300
  for (const folder of folders2.sort()) {
108770
109301
  let text5 = null;
108771
109302
  try {
108772
- text5 = fs71.readFileSync(path72.join(root2, folder, "AGENT.md"), "utf8");
109303
+ text5 = fs73.readFileSync(path74.join(root2, folder, "AGENT.md"), "utf8");
108773
109304
  } catch {
108774
109305
  }
108775
109306
  take(folder, text5, false);
@@ -108859,27 +109390,27 @@ async function findProject(asked) {
108859
109390
  }
108860
109391
  throw new Refused(`No project of yours has the id or prefix "${asked}".`, "not_found");
108861
109392
  }
108862
- var read = (file) => fs72.readFileSync(file, "utf8");
109393
+ var read2 = (file) => fs74.readFileSync(file, "utf8");
108863
109394
  var bytes2 = (text5) => Buffer.byteLength(text5, "utf8");
108864
109395
  function files(dir) {
108865
- if (!fs72.existsSync(dir)) return [];
109396
+ if (!fs74.existsSync(dir)) return [];
108866
109397
  const out = [];
108867
- for (const entry of fs72.readdirSync(dir, { withFileTypes: true })) {
109398
+ for (const entry of fs74.readdirSync(dir, { withFileTypes: true })) {
108868
109399
  if (entry.name.startsWith(".")) continue;
108869
- const full = path73.join(dir, entry.name);
109400
+ const full = path75.join(dir, entry.name);
108870
109401
  if (entry.isDirectory()) out.push(...files(full));
108871
109402
  else if (entry.isFile()) out.push(full);
108872
109403
  }
108873
109404
  return out;
108874
109405
  }
108875
- var posix = (p2) => p2.split(path73.sep).join("/");
109406
+ var posix = (p2) => p2.split(path75.sep).join("/");
108876
109407
  function openCards() {
108877
109408
  const out = [];
108878
109409
  for (const file of walkMd(TODO)) {
108879
- const rel2 = posix(path73.relative(TODO, file));
109410
+ const rel2 = posix(path75.relative(TODO, file));
108880
109411
  if (rel2 === "README.md") continue;
108881
109412
  const parts = rel2.split("/");
108882
- const text5 = read(file);
109413
+ const text5 = read2(file);
108883
109414
  const meta = parseFrontmatter(text5).meta;
108884
109415
  if (!meta) continue;
108885
109416
  const name = parts[parts.length - 1];
@@ -108963,12 +109494,12 @@ function draftsOf(text5) {
108963
109494
  const at2 = /^\.(assets|mockups)\/(.+)$/.exec(name);
108964
109495
  if (!at2) continue;
108965
109496
  const base = at2[1] === "assets" ? ASSETS : MOCKUPS;
108966
- const file = path73.resolve(base, at2[2]);
108967
- if (file.startsWith(base + path73.sep) && fs72.statSync(file, { throwIfNoEntry: false })?.isFile()) out.set(name, file);
109497
+ const file = path75.resolve(base, at2[2]);
109498
+ if (file.startsWith(base + path75.sep) && fs74.statSync(file, { throwIfNoEntry: false })?.isFile()) out.set(name, file);
108968
109499
  }
108969
109500
  return [...out].map(([name, file]) => ({ name, file }));
108970
109501
  }
108971
- var TYPES = {
109502
+ var TYPES2 = {
108972
109503
  ".png": "image/png",
108973
109504
  ".jpg": "image/jpeg",
108974
109505
  ".jpeg": "image/jpeg",
@@ -108985,10 +109516,10 @@ var TYPES = {
108985
109516
  ".wav": "audio/wav",
108986
109517
  ".json": "application/json"
108987
109518
  };
108988
- function kindOf(ext) {
109519
+ function kindOf2(ext) {
108989
109520
  if (ext === ".html") return "html";
108990
109521
  if (ext === ".md" || ext === ".mdx") return "markdown";
108991
- const type = TYPES[ext] ?? "";
109522
+ const type = TYPES2[ext] ?? "";
108992
109523
  if (type.startsWith("image/")) return "image";
108993
109524
  return type.startsWith("video/") || type.startsWith("audio/") ? "video" : "asset";
108994
109525
  }
@@ -108998,10 +109529,10 @@ async function uploadDrafts(task, drafts) {
108998
109529
  const assets = {};
108999
109530
  for (const { name, file } of drafts) {
109000
109531
  if (!card.body.includes(name)) continue;
109001
- const ext = path73.extname(file).toLowerCase();
109002
- const type = TYPES[ext] ?? "application/octet-stream";
109003
- const data = fs72.readFileSync(file);
109004
- const artifact = await api("POST", `/v1/tasks/${task}/artifacts`, { type: kindOf(ext), name: name.slice(0, 200) });
109532
+ const ext = path75.extname(file).toLowerCase();
109533
+ const type = TYPES2[ext] ?? "application/octet-stream";
109534
+ const data = fs74.readFileSync(file);
109535
+ const artifact = await api("POST", `/v1/tasks/${task}/artifacts`, { type: kindOf2(ext), name: name.slice(0, 200) });
109005
109536
  const upload = await api("POST", `/v1/artifacts/${artifact.id}/uploads`, { content_type: type, size: Math.max(data.length, 1) });
109006
109537
  await api("PUT", `/v1/uploads/${upload.id}`, void 0, { bytes: data, type });
109007
109538
  const version = await api("POST", `/v1/artifacts/${artifact.id}/versions`, { upload: upload.id });
@@ -109043,7 +109574,7 @@ usage: ${program2} cloud import --project <id or prefix> [--dry-run]`, { kind: "
109043
109574
  function localWorkflowFolders() {
109044
109575
  let folders2;
109045
109576
  try {
109046
- folders2 = fs72.readdirSync(WORKFLOWS, { withFileTypes: true }).filter((e2) => e2.isDirectory() && !e2.name.startsWith(".") && !e2.name.startsWith("task-")).map((e2) => e2.name).sort((a2, b2) => a2.localeCompare(b2, "en", { numeric: true }));
109577
+ folders2 = fs74.readdirSync(WORKFLOWS, { withFileTypes: true }).filter((e2) => e2.isDirectory() && !e2.name.startsWith(".") && !e2.name.startsWith("task-")).map((e2) => e2.name).sort((a2, b2) => a2.localeCompare(b2, "en", { numeric: true }));
109047
109578
  } catch {
109048
109579
  return [];
109049
109580
  }
@@ -109054,19 +109585,19 @@ function localWorkflowFolders() {
109054
109585
  });
109055
109586
  }
109056
109587
  function filesUnder(dir, base = dir) {
109057
- return fs72.readdirSync(dir, { withFileTypes: true }).flatMap((e2) => {
109058
- const full = path73.join(dir, e2.name);
109059
- return e2.isDirectory() ? filesUnder(full, base) : [posix(path73.relative(base, full))];
109588
+ return fs74.readdirSync(dir, { withFileTypes: true }).flatMap((e2) => {
109589
+ const full = path75.join(dir, e2.name);
109590
+ return e2.isDirectory() ? filesUnder(full, base) : [posix(path75.relative(base, full))];
109060
109591
  });
109061
109592
  }
109062
109593
  function packLocalWorkflow(id, def, shipped) {
109063
- const dir = path73.join(WORKFLOWS, id);
109064
- const out = Object.fromEntries(filesUnder(dir).map((f2) => [f2, fs72.readFileSync(path73.join(dir, f2), "utf8")]));
109594
+ const dir = path75.join(WORKFLOWS, id);
109595
+ const out = Object.fromEntries(filesUnder(dir).map((f2) => [f2, fs74.readFileSync(path75.join(dir, f2), "utf8")]));
109065
109596
  const named2 = [...def.previews, ...def.land, ...def.scheduled].map((h3) => h3.agent).filter((a2) => !LAND_ROLES2.includes(a2));
109066
109597
  for (const agent of new Set(named2)) {
109067
- const at2 = path73.join(AGENTS, agent);
109068
- if (fs72.existsSync(path73.join(at2, "AGENT.md"))) {
109069
- for (const file of filesUnder(at2)) out[`agents/${agent}/${file}`] = fs72.readFileSync(path73.join(at2, file), "utf8");
109598
+ const at2 = path75.join(AGENTS, agent);
109599
+ if (fs74.existsSync(path75.join(at2, "AGENT.md"))) {
109600
+ for (const file of filesUnder(at2)) out[`agents/${agent}/${file}`] = fs74.readFileSync(path75.join(at2, file), "utf8");
109070
109601
  continue;
109071
109602
  }
109072
109603
  for (const [key, text5] of Object.entries(shipped)) if (key.startsWith(`${agent}/`)) out[`agents/${key}`] = text5;
@@ -109076,10 +109607,10 @@ function packLocalWorkflow(id, def, shipped) {
109076
109607
  async function run(asked, dryRun) {
109077
109608
  const project = await findProject(asked);
109078
109609
  const cloudFlows2 = await all(`/v1/workflows?workspace=${encodeURIComponent(project.workspace)}`);
109079
- const board2 = crypto6.createHash("sha256").update(fs72.realpathSync(KANBAN)).digest("hex").slice(0, 16);
109610
+ const board2 = crypto6.createHash("sha256").update(fs74.realpathSync(KANBAN)).digest("hex").slice(0, 16);
109080
109611
  const cards = openCards();
109081
109612
  const problems = [];
109082
- const where = (file) => posix(path73.relative(KANBAN, file));
109613
+ const where = (file) => posix(path75.relative(KANBAN, file));
109083
109614
  const own = [];
109084
109615
  for (const f2 of localWorkflowFolders()) {
109085
109616
  if (f2.def) own.push({ id: f2.id, name: f2.def.name, def: f2.def });
@@ -109108,10 +109639,10 @@ async function run(asked, dryRun) {
109108
109639
  const root2 = `projects/${project.id}/`;
109109
109640
  const boardFiles = [];
109110
109641
  for (const file of [...files(MEMORY), ...files(RULES), CONFIG, MODULES_MD]) {
109111
- if (!fs72.existsSync(file)) continue;
109642
+ if (!fs74.existsSync(file)) continue;
109112
109643
  const rel2 = where(file);
109113
109644
  if (!isBoardPath(rel2)) continue;
109114
- const content = read(file);
109645
+ const content = read2(file);
109115
109646
  if (bytes2(content) > BOARD_FILE_LIMIT) {
109116
109647
  problems.push({ file: rel2, reason: { zh: "\u8D85\u8FC7 256 KB", en: "over 256 KB" } });
109117
109648
  continue;
@@ -109219,16 +109750,16 @@ async function run(asked, dryRun) {
109219
109750
  }
109220
109751
  function leftLocal(own) {
109221
109752
  const out = [];
109222
- const count4 = (dir) => fs72.existsSync(dir) ? walkMd(dir).length : 0;
109753
+ const count4 = (dir) => fs74.existsSync(dir) ? walkMd(dir).length : 0;
109223
109754
  const archived = count4(ARCHIVE);
109224
109755
  if (archived) out.push(`.archive/ (${archived})`);
109225
109756
  const triage = count4(TRIAGE);
109226
109757
  if (triage) out.push(`triage/ (${triage})`);
109227
- if (fs72.existsSync(DELIVERIES)) out.push("deliveries/");
109228
- if (fs72.existsSync(path73.join(KANBAN, "metrics.csv"))) out.push("metrics.csv");
109758
+ if (fs74.existsSync(DELIVERIES)) out.push("deliveries/");
109759
+ if (fs74.existsSync(path75.join(KANBAN, "metrics.csv"))) out.push("metrics.csv");
109229
109760
  const named2 = new Set(own.flatMap((w2) => [...w2.def.previews, ...w2.def.land, ...w2.def.scheduled].map((h3) => h3.agent)));
109230
- if (fs72.existsSync(AGENTS)) {
109231
- for (const e2 of fs72.readdirSync(AGENTS, { withFileTypes: true })) {
109761
+ if (fs74.existsSync(AGENTS)) {
109762
+ for (const e2 of fs74.readdirSync(AGENTS, { withFileTypes: true })) {
109232
109763
  if (e2.isDirectory() && !e2.name.startsWith(".") && !named2.has(e2.name)) out.push(`agents/${e2.name}/`);
109233
109764
  }
109234
109765
  }
@@ -109246,8 +109777,8 @@ init_session();
109246
109777
  init_io();
109247
109778
  init_paths();
109248
109779
  import { createHash as createHash5 } from "node:crypto";
109249
- import fs73 from "node:fs";
109250
- import path74 from "node:path";
109780
+ import fs75 from "node:fs";
109781
+ import path76 from "node:path";
109251
109782
  var SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
109252
109783
  var CAPTURED = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
109253
109784
  var MAX_BYTES3 = 50 * 1024 * 1024;
@@ -109346,10 +109877,10 @@ This template has no preview.`);
109346
109877
  const written = [];
109347
109878
  for (const p2 of previews) {
109348
109879
  const bytes3 = Buffer.from(await (await ask(`/${at2}/previews/${route(p2.path)}`, {}, WITHOUT)).arrayBuffer());
109349
- const file = path74.basename(p2.path);
109350
- const out = path74.join(opts.to, file.startsWith(`${name}-`) ? file : `${name}-${file}`);
109351
- fs73.mkdirSync(opts.to, { recursive: true });
109352
- fs73.writeFileSync(out, bytes3);
109880
+ const file = path76.basename(p2.path);
109881
+ const out = path76.join(opts.to, file.startsWith(`${name}-`) ? file : `${name}-${file}`);
109882
+ fs75.mkdirSync(opts.to, { recursive: true });
109883
+ fs75.writeFileSync(out, bytes3);
109353
109884
  written.push(out);
109354
109885
  say(out);
109355
109886
  }
@@ -109362,15 +109893,15 @@ async function templateGet(name, opts, program2) {
109362
109893
  const { template } = await asJson(await ask(`/${at2}`, {}, WITHOUT));
109363
109894
  const fetched = [];
109364
109895
  for (const f2 of template.files) {
109365
- const out = path74.resolve(to, f2.path);
109366
- if (!out.startsWith(path74.resolve(to) + path74.sep)) refuse2(T.corrupt, WITHOUT);
109896
+ const out = path76.resolve(to, f2.path);
109897
+ if (!out.startsWith(path76.resolve(to) + path76.sep)) refuse2(T.corrupt, WITHOUT);
109367
109898
  const bytes3 = Buffer.from(await (await ask(`/${at2}/files/${route(f2.path)}`, {}, WITHOUT)).arrayBuffer());
109368
109899
  if (bytes3.byteLength !== f2.size || createHash5("sha256").update(bytes3).digest("hex") !== f2.sha256) {
109369
109900
  refuse2(T.corrupt, WITHOUT);
109370
109901
  }
109371
109902
  fetched.push({ out, bytes: bytes3 });
109372
109903
  }
109373
- const taken = fetched.filter((f2) => fs73.existsSync(f2.out)).map((f2) => path74.relative(to, f2.out));
109904
+ const taken = fetched.filter((f2) => fs75.existsSync(f2.out)).map((f2) => path76.relative(to, f2.out));
109374
109905
  if (taken.length > 0) {
109375
109906
  refuse2({
109376
109907
  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`,
@@ -109378,8 +109909,8 @@ async function templateGet(name, opts, program2) {
109378
109909
  });
109379
109910
  }
109380
109911
  for (const f2 of fetched) {
109381
- fs73.mkdirSync(path74.dirname(f2.out), { recursive: true });
109382
- fs73.writeFileSync(f2.out, f2.bytes);
109912
+ fs75.mkdirSync(path76.dirname(f2.out), { recursive: true });
109913
+ fs75.writeFileSync(f2.out, f2.bytes);
109383
109914
  }
109384
109915
  say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
109385
109916
  Fetched ${name}: ${fetched.length} files into ${to}`);
@@ -109397,25 +109928,25 @@ async function templateSource(name, opts) {
109397
109928
  say(`evidence: ${e2.path}`);
109398
109929
  continue;
109399
109930
  }
109400
- const out = path74.join(opts.to, `${name}-${path74.basename(e2.path)}`);
109401
- fs73.mkdirSync(opts.to, { recursive: true });
109402
- fs73.writeFileSync(out, Buffer.from(await (await ask(`/${at2}/evidence/${route(e2.path)}`)).arrayBuffer()));
109931
+ const out = path76.join(opts.to, `${name}-${path76.basename(e2.path)}`);
109932
+ fs75.mkdirSync(opts.to, { recursive: true });
109933
+ fs75.writeFileSync(out, Buffer.from(await (await ask(`/${at2}/evidence/${route(e2.path)}`)).arrayBuffer()));
109403
109934
  written.push(out);
109404
109935
  say(out);
109405
109936
  }
109406
109937
  return { name, source, evidence: written.length > 0 ? written : evidence.map((e2) => e2.path) };
109407
109938
  }
109408
109939
  async function templatePublish(dir, opts) {
109409
- const root2 = path74.resolve(dir);
109410
- const manifest = path74.join(root2, "template.md");
109411
- if (!fs73.existsSync(manifest)) invalid("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
109412
- const meta = readTemplateMeta(fs73.readFileSync(manifest, "utf8"));
109940
+ const root2 = path76.resolve(dir);
109941
+ const manifest = path76.join(root2, "template.md");
109942
+ 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.");
109943
+ const meta = readTemplateMeta(fs75.readFileSync(manifest, "utf8"));
109413
109944
  const files2 = walk2(root2);
109414
- const total = files2.reduce((sum, f2) => sum + fs73.statSync(path74.join(root2, f2)).size, 0);
109945
+ const total = files2.reduce((sum, f2) => sum + fs75.statSync(path76.join(root2, f2)).size, 0);
109415
109946
  if (total > MAX_BYTES3) invalid("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
109416
109947
  for (const extra of [...opts.preview, ...opts.evidence]) {
109417
- if (!fs73.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
109418
- if (path74.resolve(extra).startsWith(root2 + path74.sep)) {
109948
+ if (!fs75.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
109949
+ if (path76.resolve(extra).startsWith(root2 + path76.sep)) {
109419
109950
  invalid(
109420
109951
  `${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`,
109421
109952
  `${extra} is inside the template folder; keep previews and evidence outside it.`
@@ -109427,10 +109958,10 @@ async function templatePublish(dir, opts) {
109427
109958
  }
109428
109959
  const form = new FormData();
109429
109960
  form.set("meta", JSON.stringify({ ...meta, replace: !!opts.replace }));
109430
- const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([fs73.readFileSync(file)]), path74.basename(name));
109431
- for (const f2 of files2) add("files", f2, path74.join(root2, f2));
109432
- for (const f2 of opts.preview) add("previews", path74.basename(f2), f2);
109433
- for (const f2 of opts.evidence) add("evidence", path74.basename(f2), f2);
109961
+ const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([fs75.readFileSync(file)]), path76.basename(name));
109962
+ for (const f2 of files2) add("files", f2, path76.join(root2, f2));
109963
+ for (const f2 of opts.preview) add("previews", path76.basename(f2), f2);
109964
+ for (const f2 of opts.evidence) add("evidence", path76.basename(f2), f2);
109434
109965
  const done2 = await asJson(await ask("", { method: "POST", body: form }));
109435
109966
  say(
109436
109967
  done2.replaced ? `\u5DF2\u66FF\u6362 ${done2.name}\uFF1A${files2.length} \u4E2A\u6587\u4EF6\u3002
@@ -109446,11 +109977,11 @@ Deleted ${name} from the catalog.`);
109446
109977
  return { name, deleted: true };
109447
109978
  }
109448
109979
  async function templateShowcase(name, dir) {
109449
- const file = path74.join(dir, "showcase.json");
109450
- if (!fs73.existsSync(file)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
109980
+ const file = path76.join(dir, "showcase.json");
109981
+ if (!fs75.existsSync(file)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
109451
109982
  let meta;
109452
109983
  try {
109453
- meta = JSON.parse(fs73.readFileSync(file, "utf8"));
109984
+ meta = JSON.parse(fs75.readFileSync(file, "utf8"));
109454
109985
  } catch {
109455
109986
  return invalid("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
109456
109987
  }
@@ -109462,9 +109993,9 @@ async function templateShowcase(name, dir) {
109462
109993
  const form = new FormData();
109463
109994
  form.set("meta", JSON.stringify(meta));
109464
109995
  for (const p2 of new Set(named2)) {
109465
- const at2 = path74.join(dir, p2);
109466
- if (!fs73.existsSync(at2)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at2}\u3002`, `${at2} does not exist.`);
109467
- form.append(`media:${p2}`, new Blob([fs73.readFileSync(at2)]), p2);
109996
+ const at2 = path76.join(dir, p2);
109997
+ if (!fs75.existsSync(at2)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at2}\u3002`, `${at2} does not exist.`);
109998
+ form.append(`media:${p2}`, new Blob([fs75.readFileSync(at2)]), p2);
109468
109999
  }
109469
110000
  const done2 = await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form }));
109470
110001
  say(`\u5DF2\u66F4\u65B0 ${name} \u7684\u5C55\u793A\u8D44\u6599\uFF1A${done2.files} \u4E2A\u6587\u4EF6\u3002
@@ -109473,7 +110004,7 @@ Updated ${name}'s showcase: ${done2.files} files.`);
109473
110004
  }
109474
110005
  function walk2(root2, sub = "") {
109475
110006
  const out = [];
109476
- for (const entry of fs73.readdirSync(path74.join(root2, sub), { withFileTypes: true })) {
110007
+ for (const entry of fs75.readdirSync(path76.join(root2, sub), { withFileTypes: true })) {
109477
110008
  if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
109478
110009
  const rel2 = sub ? `${sub}/${entry.name}` : entry.name;
109479
110010
  if (entry.isDirectory()) out.push(...walk2(root2, rel2));
@@ -109623,10 +110154,15 @@ function cmdGuide(topic, program2 = "akb") {
109623
110154
  }
109624
110155
 
109625
110156
  // src/commands/workflow.ts
110157
+ init_agents();
110158
+ init_cards();
109626
110159
  init_io();
109627
110160
  init_paths();
110161
+ init_workflow_diagram();
109628
110162
  init_cloud_workflows();
109629
110163
  init_workflows();
110164
+ import fs76 from "node:fs";
110165
+ import path77 from "node:path";
109630
110166
  var found = (id) => {
109631
110167
  const flow = workflowById(id);
109632
110168
  if (!flow) {
@@ -109686,6 +110222,22 @@ function cmdWorkflowRename(id, name) {
109686
110222
  say(`renamed ${id} to "${name.trim()}"`);
109687
110223
  return { id, name: name.trim() };
109688
110224
  }
110225
+ function cmdWorkflowDiagram(id, card) {
110226
+ const flow = found(id);
110227
+ const cardId2 = Number(card);
110228
+ if (!Number.isInteger(cardId2) || !locate(cardId2)) die(`no card #${card} on this board`, "no-such-card");
110229
+ const diagram = workflowDiagram({ previews: previewMembers(flow), land: flow.land, scheduled: scheduledMembers(flow) }, (name) => {
110230
+ const agent = findSpecAgent(name);
110231
+ return agent ? { ...agent, after: agentAfter(name) } : null;
110232
+ });
110233
+ const file = path77.join(ASSETS, String(cardId2), "workflow.json");
110234
+ fs76.mkdirSync(path77.dirname(file), { recursive: true });
110235
+ fs76.writeFileSync(file, `${JSON.stringify(diagram, null, 2)}
110236
+ `);
110237
+ const tag = `<Workflow src=".assets/${cardId2}/workflow.json" label="${flow.name.replace(/"/g, "")}" />`;
110238
+ say(tag);
110239
+ return { file, tag, diagram };
110240
+ }
109689
110241
 
109690
110242
  // src/commands/run.ts
109691
110243
  init_progress();
@@ -109836,7 +110388,7 @@ init_opencode();
109836
110388
  init_locate();
109837
110389
  init_store();
109838
110390
  import { spawnSync as spawnSync5 } from "node:child_process";
109839
- import path80 from "node:path";
110391
+ import path83 from "node:path";
109840
110392
  var AGENTS2 = {
109841
110393
  claude: "claude-code",
109842
110394
  codex: "codex",
@@ -109851,10 +110403,10 @@ var AGENTS2 = {
109851
110403
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun", "deno"]);
109852
110404
  function agentOf2(args) {
109853
110405
  const words = args.trim().split(/\s+/);
109854
- const first = path80.basename(words[0] ?? "");
110406
+ const first = path83.basename(words[0] ?? "");
109855
110407
  const script = RUNTIMES.has(first) ? words[1] ?? "" : words[0] ?? "";
109856
110408
  if (script.includes("/@anthropic-ai/claude-code/")) return "claude-code";
109857
- return AGENTS2[path80.basename(script).replace(/\.(m?js|cjs|exe)$/, "")];
110409
+ return AGENTS2[path83.basename(script).replace(/\.(m?js|cjs|exe)$/, "")];
109858
110410
  }
109859
110411
  function processChain() {
109860
110412
  if (process.platform === "win32") return [];
@@ -109918,8 +110470,8 @@ init_tasks();
109918
110470
  init_read();
109919
110471
  init_rules();
109920
110472
  init_board();
109921
- import fs82 from "node:fs";
109922
- import path83 from "node:path";
110473
+ import fs85 from "node:fs";
110474
+ import path86 from "node:path";
109923
110475
  var FOLLOW_MS = 400;
109924
110476
  async function cmdStartRun(action, args, opts, program2 = "akb") {
109925
110477
  const { req, follow: follow2, print } = readRequest(action, args, opts);
@@ -110006,8 +110558,8 @@ async function approveInCloud(project, id) {
110006
110558
  say(`approved #${id} in Cloud`);
110007
110559
  return { id, task: approved.value.key, approved: true };
110008
110560
  }
110009
- async function cmdReject(id, why, opts) {
110010
- const reason = why.trim();
110561
+ async function cmdReject(id, why2, opts) {
110562
+ const reason = why2.trim();
110011
110563
  const discard = opts.discard === true;
110012
110564
  if (!discard && !reason) die("say why the card is being dropped, or pass --discard to just drop it");
110013
110565
  const res = await rejectCard(id, { reason, discard }, true);
@@ -110167,7 +110719,7 @@ async function cmdSubStart(words, opts) {
110167
110719
  let prompt = words.join(" ");
110168
110720
  if (opts.file) {
110169
110721
  try {
110170
- prompt = fs82.readFileSync(path83.resolve(opts.file), "utf8");
110722
+ prompt = fs85.readFileSync(path86.resolve(opts.file), "utf8");
110171
110723
  } catch {
110172
110724
  die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
110173
110725
  }
@@ -110458,7 +111010,7 @@ function cmdCompleteDelivery(id, options) {
110458
111010
  // src/commands/triage.ts
110459
111011
  init_scheduled();
110460
111012
  init_workflows();
110461
- import fs84 from "node:fs";
111013
+ import fs87 from "node:fs";
110462
111014
 
110463
111015
  // src/lib/signals/index.ts
110464
111016
  init_cards();
@@ -110468,16 +111020,16 @@ init_yaml();
110468
111020
  // src/lib/signals/config.ts
110469
111021
  init_settings2();
110470
111022
  init_paths();
110471
- import fs83 from "node:fs";
110472
- import path84 from "node:path";
111023
+ import fs86 from "node:fs";
111024
+ import path87 from "node:path";
110473
111025
  var TOKEN_KEY = "TRIAGE_ENDPOINT_TOKEN";
110474
111026
  var ENDPOINT_SETTING = "Triage endpoint";
110475
111027
  var LINE2 = /^- \*\*Triage endpoint\*\*\s*[—-]\s*(.+)$/m;
110476
- var boardRel3 = (file) => rel(file).split(path84.sep).join("/");
111028
+ var boardRel3 = (file) => rel(file).split(path87.sep).join("/");
110477
111029
  function signalEndpoint() {
110478
111030
  let text5;
110479
111031
  try {
110480
- text5 = fs83.readFileSync(CONFIG, "utf8");
111032
+ text5 = fs86.readFileSync(CONFIG, "utf8");
110481
111033
  } catch {
110482
111034
  return "";
110483
111035
  }
@@ -110521,7 +111073,7 @@ function readMeta(sent) {
110521
111073
  }
110522
111074
  return pairs;
110523
111075
  }
110524
- function read2(raw) {
111076
+ function read3(raw) {
110525
111077
  const missing = REQUIRED.filter((field2) => !text4(raw[field2]));
110526
111078
  if (missing.length > 0) return { ok: false, why: `missing ${missing.join(", ")}` };
110527
111079
  const sent = text4(raw.collected_at);
@@ -110571,8 +111123,8 @@ async function fetchSignals() {
110571
111123
  });
110572
111124
  } catch (e2) {
110573
111125
  const late = e2 instanceof Error && (e2.name === "TimeoutError" || e2.name === "AbortError");
110574
- const why = late ? `did not answer within ${ANSWER_BY_MS2 / 1e3}s` : `could not be reached: ${e2 instanceof Error ? e2.message : String(e2)}`;
110575
- die(`${endpoint2} ${why}`, { kind: "triage-unreachable" });
111126
+ const why2 = late ? `did not answer within ${ANSWER_BY_MS2 / 1e3}s` : `could not be reached: ${e2 instanceof Error ? e2.message : String(e2)}`;
111127
+ die(`${endpoint2} ${why2}`, { kind: "triage-unreachable" });
110576
111128
  }
110577
111129
  if (!response.ok) {
110578
111130
  die(`${endpoint2} answered ${response.status}.`, { kind: "triage-endpoint-refused" });
@@ -110597,7 +111149,7 @@ async function fetchSignals() {
110597
111149
  report3.failed.push({ which: `item ${at2 + 1}`, why: "not an object" });
110598
111150
  return;
110599
111151
  }
110600
- const found2 = read2(raw);
111152
+ const found2 = read3(raw);
110601
111153
  if (!found2.ok) {
110602
111154
  report3.failed.push({ which: text4(raw.source_id) || `item ${at2 + 1}`, why: found2.why });
110603
111155
  return;
@@ -110653,7 +111205,7 @@ async function cmdTriageAdd(opts) {
110653
111205
  let body = opts.text;
110654
111206
  if (opts.file !== void 0) {
110655
111207
  try {
110656
- body = fs84.readFileSync(opts.file, "utf8");
111208
+ body = fs87.readFileSync(opts.file, "utf8");
110657
111209
  } catch {
110658
111210
  die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
110659
111211
  }
@@ -110689,13 +111241,13 @@ function cmdTriageArchive(sourceId, cardId2) {
110689
111241
  function cmdTriageDismiss(sourceId, reason) {
110690
111242
  const said3 = sourceId.trim();
110691
111243
  if (!said3) die('say which one: `dismiss <source-id> --reason "<why>"`', { kind: "needs-input" });
110692
- const why = reason.trim();
110693
- if (!why) die('say why it is being ignored: --reason "<why>"', { kind: "needs-input" });
111244
+ const why2 = reason.trim();
111245
+ if (!why2) die('say why it is being ignored: --reason "<why>"', { kind: "needs-input" });
110694
111246
  migrateTriage();
110695
- const done2 = dismissInboxItem(said3, "agent", why);
111247
+ const done2 = dismissInboxItem(said3, "agent", why2);
110696
111248
  if (!done2.ok) die(done2.error, { kind: "triage-item-gone" });
110697
111249
  say(`${said3} \u2014 ignored: ${done2.relPath}`);
110698
- return { source_id: said3, reason: why, file: done2.relPath };
111250
+ return { source_id: said3, reason: why2, file: done2.relPath };
110699
111251
  }
110700
111252
  function cmdTriageRestore(sourceId) {
110701
111253
  const said3 = sourceId.trim();
@@ -110905,8 +111457,8 @@ function declareRuns(program2, cli) {
110905
111457
  };
110906
111458
  for (const flow of FLOWS) declareFlow(flow.group ? groups[flow.group] : program2, flow, cli);
110907
111459
  withShared(groups.card.command("reject")).argument("<id>", "the card's id", cardId).argument("[why...]", "why the card is being dropped \u2014 required unless --discard").summary("drop the card").option("--discard", "just drop it: the why may be left off, and nothing learns from it").action(async function(...vals) {
110908
- const [id, why] = positional(vals);
110909
- await onBoard2(this, cli, () => cmdReject(id, why.join(" "), this.opts()));
111460
+ const [id, why2] = positional(vals);
111461
+ await onBoard2(this, cli, () => cmdReject(id, why2.join(" "), this.opts()));
110910
111462
  });
110911
111463
  declareRunning(groups.run, cli);
110912
111464
  declareDelivery(groups.delivery, cli);
@@ -111050,6 +111602,9 @@ List trigger conditions: ${cli.program} previews --triggers --json`).action(asyn
111050
111602
  flowWord("rename").argument("<id>", "the draft, from `workflow list`").argument("<name...>", "what to call it now").summary("rename the Workflow builder draft. Only inside that task's run.").action(async function(id, name) {
111051
111603
  await onBoard2(this, cli, () => cmdWorkflowRename(id, name.join(" ")));
111052
111604
  });
111605
+ flowWord("diagram").argument("<id>", "the workflow, from `workflow list`").argument("<card>", "the card whose asset folder gets workflow.json").summary("write the workflow's diagram to .assets/<card>/workflow.json and print the <Workflow> tag that shows it").action(async function(id, card) {
111606
+ await onBoard2(this, cli, () => cmdWorkflowDiagram(id, card));
111607
+ });
111053
111608
  withShared(program2.command("components")).summary("list an agent or workflow\u2019s preview components and their usage").option("--agent <name>", "one agent\u2019s components").option("--workflow <id>", "all components used by a workflow").option("--docs", "include component usage documentation").action(async function() {
111054
111609
  const ctx = ctxOf(this, cli.program);
111055
111610
  useBoard(resolveBoard("components", { board: ctx.board, dir: ctx.dir, cwd: cli.cwd, installHint: cli.installHint }), ctx.dir !== null);
@@ -111226,8 +111781,8 @@ function declareAgent(program2, cli) {
111226
111781
  }
111227
111782
 
111228
111783
  // src/lib/cli/setup.ts
111229
- import fs86 from "node:fs";
111230
- import path86 from "node:path";
111784
+ import fs89 from "node:fs";
111785
+ import path89 from "node:path";
111231
111786
  import { fileURLToPath as fileURLToPath3 } from "node:url";
111232
111787
 
111233
111788
  // src/commands/update.ts
@@ -111241,8 +111796,8 @@ init_paths();
111241
111796
  init_memory();
111242
111797
  init_yaml2();
111243
111798
  init_version();
111244
- import fs85 from "node:fs";
111245
- import path85 from "node:path";
111799
+ import fs88 from "node:fs";
111800
+ import path88 from "node:path";
111246
111801
  import { spawnSync as spawnSync6 } from "node:child_process";
111247
111802
  var NAME = "wildcrane";
111248
111803
  var REPO = "https://github.com/ai4kanban/ai4kanban";
@@ -111264,10 +111819,10 @@ var Report = class {
111264
111819
  for (const line of this.notes) say(` ! ${line}`);
111265
111820
  }
111266
111821
  };
111267
- var read3 = (file) => fs85.existsSync(file) ? fs85.readFileSync(file, "utf8") : null;
111822
+ var read4 = (file) => fs88.existsSync(file) ? fs88.readFileSync(file, "utf8") : null;
111268
111823
  function statOf(p2) {
111269
111824
  try {
111270
- return fs85.lstatSync(p2);
111825
+ return fs88.lstatSync(p2);
111271
111826
  } catch {
111272
111827
  return null;
111273
111828
  }
@@ -111292,10 +111847,10 @@ async function cmdUpdate2(ctx) {
111292
111847
  return { updated: ctx.dir, from, to: SKILL_VERSION };
111293
111848
  }
111294
111849
  async function repairBoard(root2, report3, named2) {
111295
- const legacy2 = path85.join(root2, "docs", "kanban");
111296
- const kept2 = path85.join(root2, ".akb", "kanban");
111297
- const board2 = named2 ?? (fs85.existsSync(legacy2) ? legacy2 : kept2);
111298
- if (!fs85.existsSync(board2)) {
111850
+ const legacy2 = path88.join(root2, "docs", "kanban");
111851
+ const kept2 = path88.join(root2, ".akb", "kanban");
111852
+ const board2 = named2 ?? (fs88.existsSync(legacy2) ? legacy2 : kept2);
111853
+ if (!fs88.existsSync(board2)) {
111299
111854
  report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
111300
111855
  return false;
111301
111856
  }
@@ -111326,20 +111881,20 @@ function moveRuntimes(root2, board2, report3) {
111326
111881
  }
111327
111882
  }
111328
111883
  function moveLegacyMemory(board2, report3) {
111329
- const memory = path85.join(board2, "memory");
111884
+ const memory = path88.join(board2, "memory");
111330
111885
  const moved = [];
111331
111886
  for (const name of MEMORY_FILES) {
111332
- const from = path85.join(board2, name);
111887
+ const from = path88.join(board2, name);
111333
111888
  const st2 = statOf(from);
111334
111889
  if (!st2 || !st2.isFile()) continue;
111335
- fs85.mkdirSync(memory, { recursive: true });
111336
- const to = path85.join(memory, name);
111337
- const there = read3(to);
111890
+ fs88.mkdirSync(memory, { recursive: true });
111891
+ const to = path88.join(memory, name);
111892
+ const there = read4(to);
111338
111893
  if (there === null) {
111339
- fs85.renameSync(from, to);
111894
+ fs88.renameSync(from, to);
111340
111895
  moved.push(name);
111341
- } else if (there === read3(from)) {
111342
- fs85.rmSync(from);
111896
+ } else if (there === read4(from)) {
111897
+ fs88.rmSync(from);
111343
111898
  moved.push(name);
111344
111899
  } else {
111345
111900
  report3.notes.push(`both docs/kanban/${name} and docs/kanban/memory/${name} exist and differ \u2014 merge them by hand`);
@@ -111348,23 +111903,23 @@ function moveLegacyMemory(board2, report3) {
111348
111903
  if (moved.length) report3.did.push(`moved the memory set into docs/kanban/memory/: ${moved.join(", ")}`);
111349
111904
  }
111350
111905
  function dropRecordFile(board2) {
111351
- const file = path85.join(board2, "record.csv");
111352
- if (!fs85.existsSync(file)) return null;
111353
- fs85.rmSync(file);
111906
+ const file = path88.join(board2, "record.csv");
111907
+ if (!fs88.existsSync(file)) return null;
111908
+ fs88.rmSync(file);
111354
111909
  return "removed docs/kanban/record.csv (the planning scores it fed are gone)";
111355
111910
  }
111356
111911
  function dropModuleGoals(board2, report3) {
111357
- const memory = path85.join(board2, "memory");
111358
- if (!fs85.existsSync(memory)) return;
111359
- const root2 = read3(path85.join(memory, "goal.md"));
111912
+ const memory = path88.join(board2, "memory");
111913
+ if (!fs88.existsSync(memory)) return;
111914
+ const root2 = read4(path88.join(memory, "goal.md"));
111360
111915
  let dropped = 0;
111361
- for (const entry of fs85.readdirSync(memory, { withFileTypes: true })) {
111916
+ for (const entry of fs88.readdirSync(memory, { withFileTypes: true })) {
111362
111917
  if (!entry.isDirectory()) continue;
111363
- const file = path85.join(memory, entry.name, "goal.md");
111364
- const text5 = read3(file);
111918
+ const file = path88.join(memory, entry.name, "goal.md");
111919
+ const text5 = read4(file);
111365
111920
  if (text5 === null) continue;
111366
111921
  if (text5 === root2 || text5.includes(UNFILLED) || !goalWords(text5)) {
111367
- fs85.rmSync(file);
111922
+ fs88.rmSync(file);
111368
111923
  dropped++;
111369
111924
  } else {
111370
111925
  report3.notes.push(
@@ -111386,10 +111941,10 @@ var PLAN_LEADS = {
111386
111941
  var GONE_LEADS = ["software-planner", "planner"];
111387
111942
  function planLeads(board2) {
111388
111943
  const leads = { ...PLAN_LEADS };
111389
- const root2 = path85.join(board2, "workflows");
111390
- for (const entry of fs85.existsSync(root2) ? fs85.readdirSync(root2, { withFileTypes: true }) : []) {
111944
+ const root2 = path88.join(board2, "workflows");
111945
+ for (const entry of fs88.existsSync(root2) ? fs88.readdirSync(root2, { withFileTypes: true }) : []) {
111391
111946
  if (!entry.isDirectory()) continue;
111392
- const meta = splitFrontmatter(read3(path85.join(root2, entry.name, "WORKFLOW.md")) ?? "").meta;
111947
+ const meta = splitFrontmatter(read4(path88.join(root2, entry.name, "WORKFLOW.md")) ?? "").meta;
111393
111948
  const stages = meta === null ? void 0 : parseYamlBlock(meta).stages;
111394
111949
  const plan = stages && typeof stages === "object" && !Array.isArray(stages) ? stages.plan : void 0;
111395
111950
  const lead = plan && typeof plan === "object" && !Array.isArray(plan) && typeof plan.lead === "string" ? plan.lead.trim() : "";
@@ -111398,30 +111953,30 @@ function planLeads(board2) {
111398
111953
  return leads;
111399
111954
  }
111400
111955
  function movePlanRules(board2, report3) {
111401
- const rules = path85.join(board2, "rules");
111956
+ const rules = path88.join(board2, "rules");
111402
111957
  const moved = [];
111403
111958
  for (const [id, leads] of Object.entries(planLeads(board2))) {
111404
111959
  for (const lead of leads) {
111405
- const from = path85.join(rules, `${lead}.md`);
111406
- const rule = read3(from)?.trim();
111960
+ const from = path88.join(rules, `${lead}.md`);
111961
+ const rule = read4(from)?.trim();
111407
111962
  if (!rule) continue;
111408
- const to = path85.join(rules, "workflows", `${id}.md`);
111409
- const there = read3(to)?.trim() ?? "";
111963
+ const to = path88.join(rules, "workflows", `${id}.md`);
111964
+ const there = read4(to)?.trim() ?? "";
111410
111965
  if (!there.includes(rule)) {
111411
- fs85.mkdirSync(path85.dirname(to), { recursive: true });
111412
- fs85.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
111966
+ fs88.mkdirSync(path88.dirname(to), { recursive: true });
111967
+ fs88.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
111413
111968
  `);
111414
111969
  moved.push(`${lead} \u2192 ${id}`);
111415
111970
  }
111416
111971
  }
111417
111972
  }
111418
- for (const lead of GONE_LEADS) fs85.rmSync(path85.join(rules, `${lead}.md`), { force: true });
111973
+ for (const lead of GONE_LEADS) fs88.rmSync(path88.join(rules, `${lead}.md`), { force: true });
111419
111974
  if (moved.length) report3.did.push(`made each plan agent's rule its workflow's card rule (docs/kanban/rules/workflows/): ${moved.join(", ")}`);
111420
111975
  }
111421
111976
  function noteOldWorkflows(board2, report3) {
111422
111977
  const old = (dir, file, keys) => {
111423
- const root2 = path85.join(board2, dir);
111424
- return (fs85.existsSync(root2) ? fs85.readdirSync(root2, { withFileTypes: true }) : []).filter((e2) => e2.isDirectory() && keys.test(splitFrontmatter(read3(path85.join(root2, e2.name, file)) ?? "").meta ?? "")).map((e2) => `docs/kanban/${dir}/${e2.name}/${file}`);
111978
+ const root2 = path88.join(board2, dir);
111979
+ return (fs88.existsSync(root2) ? fs88.readdirSync(root2, { withFileTypes: true }) : []).filter((e2) => e2.isDirectory() && keys.test(splitFrontmatter(read4(path88.join(root2, e2.name, file)) ?? "").meta ?? "")).map((e2) => `docs/kanban/${dir}/${e2.name}/${file}`);
111425
111980
  };
111426
111981
  const files2 = [...old("workflows", "WORKFLOW.md", /^(stages|delivers):/m), ...old("agents", "AGENT.md", /^\s+(hook|lead):/m)];
111427
111982
  if (files2.length) {
@@ -111431,7 +111986,7 @@ function noteOldWorkflows(board2, report3) {
111431
111986
  }
111432
111987
  }
111433
111988
  function checkConfig(board2, report3) {
111434
- const current = read3(path85.join(board2, "config.md"));
111989
+ const current = read4(path88.join(board2, "config.md"));
111435
111990
  if (!current) return;
111436
111991
  const added = missingConfigKeys(current);
111437
111992
  if (added.length) {
@@ -111441,7 +111996,7 @@ function checkConfig(board2, report3) {
111441
111996
  }
111442
111997
  }
111443
111998
  function checkModules(board2, report3) {
111444
- const map2 = read3(path85.join(board2, "modules.md"));
111999
+ const map2 = read4(path88.join(board2, "modules.md"));
111445
112000
  if (map2 && map2.includes(UNFILLED)) {
111446
112001
  report3.notes.push(
111447
112002
  "docs/kanban/modules.md is still blank \u2014 write it from the repo (`akb guide module-map`)"
@@ -111495,14 +112050,14 @@ function declareSetup(program2, cli) {
111495
112050
  program2.version(SKILL_VERSION, "-v, --version", "print this version").addHelpText("beforeAll", spelled(cli.program));
111496
112051
  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");
111497
112052
  const where = (cmd) => {
111498
- const dir = path86.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
111499
- if (!fs86.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
112053
+ const dir = path89.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
112054
+ if (!fs89.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
111500
112055
  return dir;
111501
112056
  };
111502
112057
  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() {
111503
112058
  const dir = where(this);
111504
112059
  const named2 = this.optsWithGlobals().board ?? process.env.AI4KANBAN_BOARD?.trim();
111505
- const board2 = named2 ? path86.resolve(cli.cwd, named2) : null;
112060
+ const board2 = named2 ? path89.resolve(cli.cwd, named2) : null;
111506
112061
  await runAction(ctxOf(this, cli.program), {}, () => cmdUpdate2({ dir, program: cli.program, board: board2 }));
111507
112062
  });
111508
112063
  program2.command("__rules", { hidden: true }).action(function() {
@@ -111547,7 +112102,7 @@ function invokedDirectly() {
111547
112102
  const entry = process.argv[1];
111548
112103
  if (!entry) return false;
111549
112104
  try {
111550
- return fs87.realpathSync(entry) === fs87.realpathSync(SELF2);
112105
+ return fs90.realpathSync(entry) === fs90.realpathSync(SELF2);
111551
112106
  } catch {
111552
112107
  return false;
111553
112108
  }