wildcrane-runner 0.6.26 → 0.6.28

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.
package/dist/runner.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.26 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.28 — built by runner/scripts/build.mjs. Do not edit.
2
2
  import { createRequire as __ai4kanbanRequire } from 'node:module'
3
3
  const require = __ai4kanbanRequire(import.meta.url)
4
4
  var __create = Object.create;
@@ -34205,13 +34205,13 @@ var require_react_dom_server_node_production = __commonJS({
34205
34205
  var target = currentView;
34206
34206
  0 < writtenBytes && (target = currentView.subarray(writtenBytes));
34207
34207
  target = textEncoder.encodeInto(chunk, target);
34208
- var read2 = target.read;
34208
+ var read3 = target.read;
34209
34209
  writtenBytes += target.written;
34210
- read2 < chunk.length && (writeToDestination(
34210
+ read3 < chunk.length && (writeToDestination(
34211
34211
  destination,
34212
34212
  currentView.subarray(0, writtenBytes)
34213
34213
  ), currentView = new Uint8Array(4096), writtenBytes = textEncoder.encodeInto(
34214
- chunk.slice(read2),
34214
+ chunk.slice(read3),
34215
34215
  currentView
34216
34216
  ).written);
34217
34217
  4096 === writtenBytes && (writeToDestination(destination, currentView), currentView = new Uint8Array(4096), writtenBytes = 0);
@@ -47961,13 +47961,13 @@ var require_react_dom_server_node_development = __commonJS({
47961
47961
  var target = currentView;
47962
47962
  0 < writtenBytes && (target = currentView.subarray(writtenBytes));
47963
47963
  target = textEncoder.encodeInto(chunk, target);
47964
- var read2 = target.read;
47964
+ var read3 = target.read;
47965
47965
  writtenBytes += target.written;
47966
- read2 < chunk.length && (writeToDestination(
47966
+ read3 < chunk.length && (writeToDestination(
47967
47967
  destination,
47968
47968
  currentView.subarray(0, writtenBytes)
47969
47969
  ), currentView = new Uint8Array(4096), writtenBytes = textEncoder.encodeInto(
47970
- chunk.slice(read2),
47970
+ chunk.slice(read3),
47971
47971
  currentView
47972
47972
  ).written);
47973
47973
  4096 === writtenBytes && (writeToDestination(destination, currentView), currentView = new Uint8Array(4096), writtenBytes = 0);
@@ -85861,6 +85861,32 @@ var init_tailwindcss = __esm({
85861
85861
  }
85862
85862
  });
85863
85863
 
85864
+ // ../cli/src/lib/dress-page.ts
85865
+ import fs28 from "node:fs";
85866
+ import path32 from "node:path";
85867
+ function dressPage(file2) {
85868
+ const folder = path32.dirname(file2);
85869
+ const html = fs28.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
85870
+ const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
85871
+ if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
85872
+ const at3 = path32.resolve(folder, href);
85873
+ if (!at3.startsWith(folder + path32.sep) || !fs28.existsSync(at3)) return tag;
85874
+ const css = fs28.readFileSync(at3, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole, quote2, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole : `url(${quote2}${path32.relative(folder, path32.resolve(path32.dirname(at3), src)).split(path32.sep).join("/")}${quote2})`);
85875
+ return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
85876
+ });
85877
+ const at2 = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
85878
+ 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>`;
85879
+ }
85880
+ var CSP, head, referenceText;
85881
+ var init_dress_page = __esm({
85882
+ "../cli/src/lib/dress-page.ts"() {
85883
+ "use strict";
85884
+ 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'";
85885
+ 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>`;
85886
+ referenceText = (file2) => /\.html$/i.test(file2) ? dressPage(file2) : fs28.readFileSync(file2, "utf8");
85887
+ }
85888
+ });
85889
+
85864
85890
  // ../cli/node_modules/react-icons/lib/iconsManifest.mjs
85865
85891
  var init_iconsManifest = __esm({
85866
85892
  "../cli/node_modules/react-icons/lib/iconsManifest.mjs"() {
@@ -110840,8 +110866,8 @@ var init_dist = __esm({
110840
110866
  });
110841
110867
 
110842
110868
  // ../cli/src/lib/draw-mockup.ts
110843
- import fs28 from "node:fs";
110844
- import path32 from "node:path";
110869
+ import fs29 from "node:fs";
110870
+ import path33 from "node:path";
110845
110871
  import vm from "node:vm";
110846
110872
  async function loadPackage(id) {
110847
110873
  if (id === "react") return import_react3.default;
@@ -110854,22 +110880,22 @@ async function loadPackage(id) {
110854
110880
  return { __esModule: true, ...await load() };
110855
110881
  }
110856
110882
  function resolveFile(id, from, folder) {
110857
- const at2 = path32.resolve(path32.dirname(from), id);
110858
- if (at2 !== folder && !at2.startsWith(folder + path32.sep)) throw new Error(`${id} is outside the mockup's folder`);
110859
- const tries = path32.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path32.join(at2, `index${e2}`))];
110860
- const file2 = tries.find((f2) => fs28.statSync(f2, { throwIfNoEntry: false })?.isFile());
110883
+ const at2 = path33.resolve(path33.dirname(from), id);
110884
+ if (at2 !== folder && !at2.startsWith(folder + path33.sep)) throw new Error(`${id} is outside the mockup's folder`);
110885
+ const tries = path33.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path33.join(at2, `index${e2}`))];
110886
+ const file2 = tries.find((f2) => fs29.statSync(f2, { throwIfNoEntry: false })?.isFile());
110861
110887
  if (!file2) throw new Error(`no such file: ${id}`);
110862
110888
  return file2;
110863
110889
  }
110864
110890
  async function readGraph(entry) {
110865
- const folder = path32.dirname(entry);
110891
+ const folder = path33.dirname(entry);
110866
110892
  const graph = { code: /* @__PURE__ */ new Map(), links: /* @__PURE__ */ new Map(), sheets: [], packages: /* @__PURE__ */ new Map() };
110867
110893
  const walk = async (file2) => {
110868
110894
  if (graph.code.has(file2)) return;
110869
110895
  if (graph.code.size >= MAX_FILES) throw new Error(`a mockup imports more than ${MAX_FILES} files`);
110870
110896
  let location = file2;
110871
110897
  try {
110872
- const js = (0, import_sucrase.transform)(fs28.readFileSync(file2, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file2 }).code;
110898
+ const js = (0, import_sucrase.transform)(fs29.readFileSync(file2, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file2 }).code;
110873
110899
  graph.code.set(file2, js);
110874
110900
  const link = /* @__PURE__ */ new Map();
110875
110901
  graph.links.set(file2, link);
@@ -110883,7 +110909,7 @@ async function readGraph(entry) {
110883
110909
  const target = resolveFile(id, file2, folder);
110884
110910
  link.set(id, target);
110885
110911
  if (!target.endsWith(".css")) await walk(target);
110886
- else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs28.readFileSync(target, "utf8") });
110912
+ else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs29.readFileSync(target, "utf8") });
110887
110913
  }
110888
110914
  } catch (error) {
110889
110915
  throw new Error(`${location}: ${error instanceof Error ? error.message : String(error)}`);
@@ -110900,29 +110926,17 @@ function run(script, context, name, deadline, lineOffset = 0) {
110900
110926
  async function tailwindFor(markup, sheets) {
110901
110927
  const source = sheets.length ? sheets.map((s) => s.content).join("\n") : '@import "tailwindcss";';
110902
110928
  const compiler = await rc(source, {
110903
- base: sheets.length ? path32.dirname(sheets[0].path) : "/",
110929
+ base: sheets.length ? path33.dirname(sheets[0].path) : "/",
110904
110930
  loadStylesheet: async (id, from) => {
110905
110931
  if (id === "tailwindcss" || id.startsWith("tailwindcss/")) return { path: "tailwindcss/index.css", base: "/", content: tailwindcss_default };
110906
110932
  if (!id.startsWith(".")) throw new Error(`a mockup cannot import ${id}`);
110907
- const at2 = path32.resolve(from, id);
110908
- return { path: at2, base: path32.dirname(at2), content: fs28.readFileSync(at2, "utf8") };
110933
+ const at2 = path33.resolve(from, id);
110934
+ return { path: at2, base: path33.dirname(at2), content: fs29.readFileSync(at2, "utf8") };
110909
110935
  }
110910
110936
  });
110911
110937
  const classes = [...markup.matchAll(/class="([^"]*)"/g)].flatMap((m) => m[1].split(/\s+/));
110912
110938
  return compiler.build(classes.filter(Boolean));
110913
110939
  }
110914
- function dressPage(file2) {
110915
- const folder = path32.dirname(file2);
110916
- const html = fs28.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
110917
- const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
110918
- if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
110919
- const at3 = path32.resolve(folder, href);
110920
- if (!at3.startsWith(folder + path32.sep) || !fs28.existsSync(at3)) return tag;
110921
- return `<style>${fs28.readFileSync(at3, "utf8").replace(/<\/style/gi, "<\\/style")}</style>`;
110922
- });
110923
- const at2 = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
110924
- 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>`;
110925
- }
110926
110940
  async function drawMockup(entry) {
110927
110941
  if (entry.toLowerCase().endsWith(".html")) return dressPage(entry);
110928
110942
  const graph = await readGraph(entry);
@@ -110969,7 +110983,7 @@ ${graph.code.get(file2)}
110969
110983
  const css = (await tailwindFor(markup, graph.sheets)).replace(/<\/style/gi, "<\\/style");
110970
110984
  return `<!doctype html><html><head>${head}<style>${css}</style></head><body>${markup}</body></html>`;
110971
110985
  }
110972
- 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;
110986
+ var import_react3, JSX, import_server, import_sucrase, DRAW_MS, MAX_FILES, CODE_EXTS, REQUIRES, NOTHING, NEXT_LINK, NEXT_IMAGE, NEXT_NAVIGATION, PACKAGES;
110973
110987
  var init_draw_mockup = __esm({
110974
110988
  "../cli/src/lib/draw-mockup.ts"() {
110975
110989
  "use strict";
@@ -110979,6 +110993,7 @@ var init_draw_mockup = __esm({
110979
110993
  import_sucrase = __toESM(require_dist2(), 1);
110980
110994
  init_lib();
110981
110995
  init_tailwindcss();
110996
+ init_dress_page();
110982
110997
  DRAW_MS = 5e3;
110983
110998
  MAX_FILES = 60;
110984
110999
  CODE_EXTS = [".tsx", ".ts", ".jsx", ".js", ".mjs"];
@@ -111021,8 +111036,6 @@ var init_draw_mockup = __esm({
111021
111036
  "tailwind-merge": () => Promise.resolve().then(() => (init_bundle_mjs(), bundle_mjs_exports)),
111022
111037
  "class-variance-authority": () => Promise.resolve().then(() => (init_dist(), dist_exports))
111023
111038
  };
111024
- 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'";
111025
- 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>`;
111026
111039
  }
111027
111040
  });
111028
111041
 
@@ -111225,12 +111238,12 @@ var import_undici = __toESM(require_undici(), 1);
111225
111238
  // ../cli/src/lib/agent/proxy.ts
111226
111239
  import { execFileSync } from "node:child_process";
111227
111240
  var PROXY_KEYS = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"];
111228
- function withSystemProxy(env2 = process.env, platform = process.platform, read2 = () => execFileSync("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 1e3, stdio: ["ignore", "pipe", "ignore"] })) {
111241
+ function withSystemProxy(env2 = process.env, platform = process.platform, read3 = () => execFileSync("/usr/sbin/scutil", ["--proxy"], { encoding: "utf8", timeout: 1e3, stdio: ["ignore", "pipe", "ignore"] })) {
111229
111242
  const out = { ...env2 };
111230
111243
  if (platform !== "darwin" || PROXY_KEYS.some((key) => env2[key] !== void 0)) return out;
111231
111244
  let raw;
111232
111245
  try {
111233
- raw = read2();
111246
+ raw = read3();
111234
111247
  } catch {
111235
111248
  return out;
111236
111249
  }
@@ -111272,8 +111285,8 @@ function hostProxy() {
111272
111285
  [...PROXY_KEYS, "NO_PROXY", "no_proxy"].flatMap((key) => process.env[key] === void 0 ? [] : [[key, process.env[key]]])
111273
111286
  );
111274
111287
  }
111275
- function followProxy(read2) {
111276
- current = read2 ? withSystemProxy(hostProxy(), process.platform, read2) : withSystemProxy(hostProxy());
111288
+ function followProxy(read3) {
111289
+ current = read3 ? withSystemProxy(hostProxy(), process.platform, read3) : withSystemProxy(hostProxy());
111277
111290
  const httpProxy = current.HTTP_PROXY || current.http_proxy || current.ALL_PROXY || current.all_proxy || void 0;
111278
111291
  const route = {
111279
111292
  httpProxy,
@@ -111336,13 +111349,13 @@ var ZH = {
111336
111349
  signIn: (url) => `\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u767B\u5F55 WildCrane\uFF1A
111337
111350
  ${url}`,
111338
111351
  signedIn: () => "\u5DF2\u767B\u5F55",
111339
- signInFailed: (why) => `\u767B\u5F55\u672A\u5B8C\u6210\uFF1A${why}`,
111352
+ signInFailed: (why2) => `\u767B\u5F55\u672A\u5B8C\u6210\uFF1A${why2}`,
111340
111353
  connected: (machine) => `\u5DF2\u8FDE\u63A5\uFF08${machine}\uFF09\uFF0C\u7B49\u5F85\u4EFB\u52A1`,
111341
111354
  running: (count2) => `\u6B63\u5728\u8FD0\u884C ${count2} \u4E2A\u4EFB\u52A1`,
111342
111355
  reconnecting: () => "\u5DF2\u65AD\u5F00\uFF0C\u6B63\u5728\u91CD\u8FDE\u2026",
111343
111356
  elsewhere: (machine) => `\u4F60\u7684 Runner \u5DF2\u5728\u300C${machine}\u300D\u4E0A\u8FDE\u63A5\u3002\u8BF7\u5148\u5728\u90A3\u53F0\u7535\u8111\u4E0A\u9000\u51FA\uFF0C\u518D\u5728\u8FD9\u91CC\u542F\u52A8\u3002`,
111344
111357
  outdated: () => "\u6B64\u7248\u672C\u5DF2\u8FC7\u65E7\uFF0C\u8BF7\u91CD\u542F\u4EE5\u66F4\u65B0\u3002",
111345
- refused: (why) => `WildCrane \u62D2\u7EDD\u4E86\u8FDE\u63A5\uFF1A${why}`,
111358
+ refused: (why2) => `WildCrane \u62D2\u7EDD\u4E86\u8FDE\u63A5\uFF1A${why2}`,
111346
111359
  updated: (version) => `\u5DF2\u66F4\u65B0\u5230 ${version}`,
111347
111360
  rolledBack: (version) => `\u65B0\u7248\u672C\u672A\u80FD\u542F\u52A8\uFF0C\u5DF2\u9000\u56DE ${version}`,
111348
111361
  nodeTooOld: (range) => `\u65B0\u7248\u672C\u9700\u8981 Node ${range}\uFF0C\u8BF7\u5347\u7EA7 Node\u3002\u672C\u6B21\u7EE7\u7EED\u4F7F\u7528\u5F53\u524D\u7248\u672C\u3002`,
@@ -111356,13 +111369,13 @@ var EN = {
111356
111369
  signIn: (url) => `Sign in to WildCrane in your browser:
111357
111370
  ${url}`,
111358
111371
  signedIn: () => "Signed in",
111359
- signInFailed: (why) => `Sign-in did not finish: ${why}`,
111372
+ signInFailed: (why2) => `Sign-in did not finish: ${why2}`,
111360
111373
  connected: (machine) => `Connected (${machine}) \u2014 waiting for tasks`,
111361
111374
  running: (count2) => `Running ${count2} ${count2 === 1 ? "task" : "tasks"}`,
111362
111375
  reconnecting: () => "Disconnected \u2014 reconnecting\u2026",
111363
111376
  elsewhere: (machine) => `Your Runner is already connected on "${machine}". Quit it there first, then start it here.`,
111364
111377
  outdated: () => "This version is out of date. Restart to update.",
111365
- refused: (why) => `WildCrane refused the connection: ${why}`,
111378
+ refused: (why2) => `WildCrane refused the connection: ${why2}`,
111366
111379
  updated: (version) => `Updated to ${version}`,
111367
111380
  rolledBack: (version) => `The new version did not start \u2014 back on ${version}`,
111368
111381
  nodeTooOld: (range) => `The new version needs Node ${range}. Update Node; running the current version for now.`,
@@ -111387,8 +111400,8 @@ function status(line) {
111387
111400
  }
111388
111401
 
111389
111402
  // src/protocol.ts
111390
- var VERSION = true ? "0.6.26" : "0.0.0";
111391
- var AKB_VERSION = true ? "0.11.23" : "0.0.0";
111403
+ var VERSION = true ? "0.6.28" : "0.0.0";
111404
+ var AKB_VERSION = true ? "0.11.25" : "0.0.0";
111392
111405
  var AKB_CONTRACT = true ? 7 : 0;
111393
111406
  var EXIT_REFUSED = 10;
111394
111407
  var EXIT_OUTDATED = 11;
@@ -112715,9 +112728,9 @@ function toolCalls(row) {
112715
112728
  }).join("");
112716
112729
  }
112717
112730
  function retry(row) {
112718
- const why = str(row.error_message) || str(row.error_name) || "the provider failed";
112731
+ const why2 = str(row.error_message) || str(row.error_name) || "the provider failed";
112719
112732
  const attempt = `${num(row.next_attempt)}/${num(row.max_attempts)}`;
112720
- return `[retry ${attempt}] ${why}
112733
+ return `[retry ${attempt}] ${why2}
112721
112734
  `;
112722
112735
  }
112723
112736
  var LOOK_EVERY_MS2 = 3e3;
@@ -112807,10 +112820,10 @@ function connect(stdout, stdin, onCall, dialect = {}) {
112807
112820
  } catch {
112808
112821
  }
112809
112822
  };
112810
- const closed = (why) => {
112823
+ const closed = (why2) => {
112811
112824
  if (gone) return;
112812
- gone = why;
112813
- for (const { fail } of waiting.values()) fail(new Error(why));
112825
+ gone = why2;
112826
+ for (const { fail } of waiting.values()) fail(new Error(why2));
112814
112827
  waiting.clear();
112815
112828
  };
112816
112829
  stdout.on("data", (chunk) => {
@@ -112913,7 +112926,7 @@ function createTail(log) {
112913
112926
  // ../cli/package.json
112914
112927
  var package_default = {
112915
112928
  name: "wildcrane",
112916
- version: "0.11.23",
112929
+ version: "0.11.25",
112917
112930
  akbContract: 7,
112918
112931
  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.",
112919
112932
  keywords: [
@@ -113160,12 +113173,12 @@ async function oneTurn(io, options) {
113160
113173
  const usage = usageOf2(done.usage) ?? usageOf2(spent, true);
113161
113174
  costUsd ??= ticksUsd(spent.costUsdTicks);
113162
113175
  if (stopReason && stopReason !== "end_turn") {
113163
- const why = STOPPED[stopReason] ?? `the agent stopped: ${stopReason}`;
113164
- io.log(`[error] ${why}
113176
+ const why2 = STOPPED[stopReason] ?? `the agent stopped: ${stopReason}`;
113177
+ io.log(`[error] ${why2}
113165
113178
  `);
113166
- events.error(why);
113179
+ events.error(why2);
113167
113180
  emit();
113168
- return { ok: false, result, error: why, usage, context, costUsd };
113181
+ return { ok: false, result, error: why2, usage, context, costUsd };
113169
113182
  }
113170
113183
  emit();
113171
113184
  return { ok: true, result, usage, context, costUsd };
@@ -113195,8 +113208,8 @@ function update(raw, tail, gotCost, gotContext) {
113195
113208
  }
113196
113209
  case "tool_call_update": {
113197
113210
  if (change.status !== "failed") return;
113198
- const why = saidBy(change);
113199
- tail.line(`[error] ${str(change.title) || "that tool call"} failed${why ? `: ${why}` : ""}`);
113211
+ const why2 = saidBy(change);
113212
+ tail.line(`[error] ${str(change.title) || "that tool call"} failed${why2 ? `: ${why2}` : ""}`);
113200
113213
  return;
113201
113214
  }
113202
113215
  case "usage_update": {
@@ -113292,8 +113305,8 @@ function createParts(tail) {
113292
113305
  tail.line(`\u23FA ${title}${whereHint2(state.input, title)}`);
113293
113306
  }
113294
113307
  if (str(state.status) === "error") {
113295
- const why = str(state.error).trim();
113296
- tail.line(`[error] ${title} failed${why ? `: ${why}` : ""}`);
113308
+ const why2 = str(state.error).trim();
113309
+ tail.line(`[error] ${title} failed${why2 ? `: ${why2}` : ""}`);
113297
113310
  }
113298
113311
  },
113299
113312
  /** A piece of one part, as `part.delta` sends it. */
@@ -113326,8 +113339,8 @@ function createParts(tail) {
113326
113339
  toolUpdate(payload) {
113327
113340
  if (str(payload.kind) !== "error") return;
113328
113341
  const name = named2.get(str(payload.toolCallId)) ?? "tool";
113329
- const why = str(obj(payload.error).message).split("\n")[0].trim();
113330
- tail.line(`[error] ${name} failed${why ? `: ${why.slice(0, 200)}` : ""}`);
113342
+ const why2 = str(obj(payload.error).message).split("\n")[0].trim();
113343
+ tail.line(`[error] ${name} failed${why2 ? `: ${why2.slice(0, 200)}` : ""}`);
113331
113344
  }
113332
113345
  };
113333
113346
  }
@@ -113342,10 +113355,10 @@ var RUNTIME_PREFERENCES = {
113342
113355
  modelContextBudgetStrategy: "preflight-v1"
113343
113356
  };
113344
113357
  var MISSING_KEY = /missing an API key/i;
113345
- function stopped(io, why) {
113346
- io.log(`[error] ${why}
113358
+ function stopped(io, why2) {
113359
+ io.log(`[error] ${why2}
113347
113360
  `);
113348
- if (MISSING_KEY.test(why)) {
113361
+ if (MISSING_KEY.test(why2)) {
113349
113362
  io.log("[board] paste a Z.AI or BigModel Coding Plan key into ZCode's key box in Configuration.\n");
113350
113363
  }
113351
113364
  }
@@ -113435,9 +113448,9 @@ async function oneTurn2(io, options) {
113435
113448
  const usage = done.usage ?? await tokensOf(rpc, sessionId);
113436
113449
  const context = await contextOf(rpc, sessionId);
113437
113450
  if (!done.ok) {
113438
- const why = done.error ?? "the agent stopped without saying why";
113439
- stopped(io, why);
113440
- return { ok: false, result, error: why, usage, context };
113451
+ const why2 = done.error ?? "the agent stopped without saying why";
113452
+ stopped(io, why2);
113453
+ return { ok: false, result, error: why2, usage, context };
113441
113454
  }
113442
113455
  return { ok: true, result, usage, context };
113443
113456
  } catch (e2) {
@@ -113456,8 +113469,8 @@ async function tokensOf(rpc, sessionId) {
113456
113469
  }
113457
113470
  async function contextOf(rpc, sessionId) {
113458
113471
  try {
113459
- const read2 = await rpc.call("session/read", { sessionId, messageLimit: 1 });
113460
- const state = obj(read2.projection);
113472
+ const read3 = await rpc.call("session/read", { sessionId, messageLimit: 1 });
113473
+ const state = obj(read3.projection);
113461
113474
  const used = num(state.contextUsed);
113462
113475
  const limit = num(state.contextWindow);
113463
113476
  return used > 0 ? { used, limit: limit > 0 ? limit : void 0 } : void 0;
@@ -116057,9 +116070,9 @@ async function askDueAgents(machineId2, now = Date.now()) {
116057
116070
  if (!folders2.ok) return false;
116058
116071
  let started = false;
116059
116072
  for (const { project } of folders2.value.folders) {
116060
- const read2 = await readAgents(machineId2, project);
116061
- if (!read2.ok) continue;
116062
- for (const agent of read2.value.agents.filter((a2) => agentDue(a2, now))) {
116073
+ const read3 = await readAgents(machineId2, project);
116074
+ if (!read3.ok) continue;
116075
+ for (const agent of read3.value.agents.filter((a2) => agentDue(a2, now))) {
116063
116076
  const asked = await requestAgent(machineId2, project, agent.name, agent.workflow ?? null, agent.lastSuccess);
116064
116077
  if (!asked.ok) console.error(`runner: ${agent.name} was not started on ${project}: ${asked.error}`);
116065
116078
  else if (asked.value.job) started = true;
@@ -116406,6 +116419,19 @@ var parse = (v) => {
116406
116419
  function compare(a2, b2) {
116407
116420
  const [x2, y2] = [parse(a2) ?? [0, 0, 0], parse(b2) ?? [0, 0, 0]];
116408
116421
  for (let i = 0; i < 3; i++) if (x2[i] !== y2[i]) return x2[i] - y2[i];
116422
+ const pre = (v) => /^v?\d+\.\d+\.\d+-([^+]+)/.exec(v)?.[1]?.split(".");
116423
+ const ap = pre(a2), bp = pre(b2);
116424
+ if (!ap || !bp) return ap ? -1 : bp ? 1 : 0;
116425
+ for (let i = 0; i < Math.max(ap.length, bp.length); i++) {
116426
+ const av = ap[i], bv = bp[i];
116427
+ if (av === bv) continue;
116428
+ if (av === void 0) return -1;
116429
+ if (bv === void 0) return 1;
116430
+ const an2 = /^\d+$/.test(av), bn2 = /^\d+$/.test(bv);
116431
+ if (an2 && bn2) return Number(av) - Number(bv);
116432
+ if (an2 !== bn2) return an2 ? -1 : 1;
116433
+ return av < bv ? -1 : 1;
116434
+ }
116409
116435
  return 0;
116410
116436
  }
116411
116437
  function satisfies(version, range) {
@@ -116614,11 +116640,11 @@ function keepCloudChat(task, messages) {
116614
116640
  fs19.writeFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
116615
116641
  `).join(""));
116616
116642
  }
116617
- async function keepDecisions(task, read2) {
116643
+ async function keepDecisions(task, read3) {
116618
116644
  const comments = [];
116619
116645
  let after = null;
116620
116646
  do {
116621
- const page = await read2(task, after);
116647
+ const page = await read3(task, after);
116622
116648
  if (!page.ok) return;
116623
116649
  for (const d2 of page.value.data) {
116624
116650
  if (d2.comment.trim()) comments.push({ id: d2.id, role: "user", text: d2.comment, at: Date.parse(d2.created_at) || Date.now() });
@@ -116737,8 +116763,161 @@ function cardFront(body) {
116737
116763
  return out;
116738
116764
  }
116739
116765
 
116740
- // ../artifact-sdk/src/internal/references.ts
116766
+ // ../artifact-sdk/src/builtin/compare.json
116767
+ var 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';
116768
+
116769
+ // ../artifact-sdk/src/builtin/html.json
116770
+ var html_default = `{
116771
+ "name": "html",
116772
+ "title": { "en": "Page", "zh": "\u9875\u9762" },
116773
+ "types": ["html"],
116774
+ "references": [
116775
+ { "text": "<[a-z][^<>]*?\\\\ssrc\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
116776
+ { "text": "<[a-z][^<>]*?\\\\sposter\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
116777
+ { "text": "<[a-z][^<>]*?\\\\ssrcset\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']", "list": "," },
116778
+ { "text": "<link\\\\b[^<>]*?\\\\shref\\\\s*=\\\\s*[\\"']([^\\"']+)[\\"']" },
116779
+ { "text": "url\\\\(\\\\s*[\\"']?([^\\"')]+?)[\\"']?\\\\s*\\\\)" }
116780
+ ]
116781
+ }
116782
+ `;
116783
+
116784
+ // ../artifact-sdk/src/builtin/image.json
116785
+ var image_default = '{ "name": "image", "title": { "en": "Image", "zh": "\u56FE\u7247" }, "types": ["image"] }\n';
116786
+
116787
+ // ../artifact-sdk/src/builtin/markdown.json
116788
+ var markdown_default = '{ "name": "markdown", "title": { "en": "Document", "zh": "\u6587\u6863" }, "types": ["markdown"] }\n';
116789
+
116790
+ // ../artifact-sdk/src/builtin/storyboard.json
116791
+ var 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';
116792
+
116793
+ // ../artifact-sdk/src/builtin/video.json
116794
+ var video_default = '{ "name": "video", "title": { "en": "Video", "zh": "\u89C6\u9891" }, "types": ["video"] }\n';
116795
+
116796
+ // ../artifact-sdk/src/builtin/workflow.json
116797
+ var 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';
116798
+
116799
+ // ../artifact-sdk/src/builtin/index.ts
116800
+ var read = (m) => typeof m === "string" ? JSON.parse(m) : m;
116801
+ var builtin_default = [html_default, image_default, video_default, markdown_default, storyboard_default, compare_default, workflow_default].map(read);
116802
+
116803
+ // ../artifact-sdk/src/internal/schema.ts
116804
+ var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
116805
+ function typeOk(type, v) {
116806
+ const types = Array.isArray(type) ? type : [type];
116807
+ return types.some(
116808
+ (t2) => t2 === "null" ? v === null : t2 === "array" ? Array.isArray(v) : t2 === "object" ? isObj(v) : t2 === "integer" ? Number.isInteger(v) : t2 === "number" ? typeof v === "number" && Number.isFinite(v) : typeof v === t2
116809
+ );
116810
+ }
116811
+ function schemaProblem(schema, value, at2 = "") {
116812
+ if (!isObj(schema)) return null;
116813
+ const s = schema;
116814
+ const here = at2 || "/";
116815
+ if (s.type !== void 0 && !typeOk(s.type, value)) return here;
116816
+ if (Array.isArray(s.enum) && !s.enum.some((e2) => JSON.stringify(e2) === JSON.stringify(value))) return here;
116817
+ if (s.const !== void 0 && JSON.stringify(s.const) !== JSON.stringify(value)) return here;
116818
+ if (Array.isArray(s.anyOf) && !s.anyOf.some((x2) => !schemaProblem(x2, value, at2))) return here;
116819
+ if (typeof value === "string") {
116820
+ if (typeof s.minLength === "number" && value.length < s.minLength) return here;
116821
+ if (typeof s.maxLength === "number" && value.length > s.maxLength) return here;
116822
+ if (typeof s.pattern === "string") {
116823
+ try {
116824
+ if (!new RegExp(s.pattern, "u").test(value)) return here;
116825
+ } catch {
116826
+ }
116827
+ }
116828
+ }
116829
+ if (typeof value === "number") {
116830
+ if (typeof s.minimum === "number" && value < s.minimum) return here;
116831
+ if (typeof s.maximum === "number" && value > s.maximum) return here;
116832
+ }
116833
+ if (Array.isArray(value)) {
116834
+ if (typeof s.minItems === "number" && value.length < s.minItems) return here;
116835
+ if (typeof s.maxItems === "number" && value.length > s.maxItems) return here;
116836
+ if (isObj(s.items)) {
116837
+ for (let i = 0; i < value.length; i++) {
116838
+ const bad = schemaProblem(s.items, value[i], `${at2}/${i}`);
116839
+ if (bad) return bad;
116840
+ }
116841
+ }
116842
+ }
116843
+ if (isObj(value)) {
116844
+ const props = isObj(s.properties) ? s.properties : {};
116845
+ if (Array.isArray(s.required)) {
116846
+ for (const k2 of s.required) if (typeof k2 === "string" && !(k2 in value)) return `${at2}/${k2}`;
116847
+ }
116848
+ for (const [k2, v] of Object.entries(value)) {
116849
+ if (k2 in props) {
116850
+ const bad = schemaProblem(props[k2], v, `${at2}/${k2}`);
116851
+ if (bad) return bad;
116852
+ } else if (s.additionalProperties === false) return `${at2}/${k2}`;
116853
+ else if (isObj(s.additionalProperties)) {
116854
+ const bad = schemaProblem(s.additionalProperties, v, `${at2}/${k2}`);
116855
+ if (bad) return bad;
116856
+ }
116857
+ }
116858
+ }
116859
+ return null;
116860
+ }
116861
+
116862
+ // ../artifact-sdk/src/internal/manifest.ts
116863
+ var BUILTINS = builtin_default;
116864
+ var manifestOf = (type) => BUILTINS.find((m) => m.types.includes(type));
116865
+ function typeOf(data, types) {
116866
+ for (const type of types) if (!schemaProblem(manifestOf(type)?.schema, data)) return { type };
116867
+ if (types.length !== 1) return { type: null };
116868
+ return { type: types[0], problem: `does not match ${types[0]} at ${schemaProblem(manifestOf(types[0])?.schema, data)}` };
116869
+ }
116741
116870
  var isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
116871
+ var remote = (src) => !src || /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src);
116872
+ function mapJson(node, keys, at2, visit) {
116873
+ if (!keys.length) return typeof node === "string" && node ? visit(node, at2) : node;
116874
+ const [key, ...rest] = keys;
116875
+ if (Array.isArray(node)) {
116876
+ if (key === "*") return node.map((x2, i2) => mapJson(x2, rest, `${at2}/${i2}`, visit));
116877
+ const i = Number(key);
116878
+ return Number.isInteger(i) && i in node ? node.map((x2, j2) => j2 === i ? mapJson(x2, rest, `${at2}/${j2}`, visit) : x2) : node;
116879
+ }
116880
+ if (!isObject(node)) return node;
116881
+ const out = { ...node };
116882
+ for (const k2 of key === "*" ? Object.keys(node) : key in node ? [key] : []) out[k2] = mapJson(node[k2], rest, `${at2}/${k2}`, visit);
116883
+ return out;
116884
+ }
116885
+ function mapText(text4, rule, visit) {
116886
+ let out = "";
116887
+ let last2 = 0;
116888
+ for (const m of text4.matchAll(new RegExp(rule.text, "gid"))) {
116889
+ const span = m.indices?.[1];
116890
+ if (!span || m[1] === void 0) continue;
116891
+ const line = text4.slice(0, span[0]).split("\n").length;
116892
+ const one = (src) => remote(src) ? src : visit(src, line);
116893
+ 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]);
116894
+ out += text4.slice(last2, span[0]) + value;
116895
+ last2 = span[1];
116896
+ }
116897
+ return out + text4.slice(last2);
116898
+ }
116899
+ function mapReferences(manifest, content, map2) {
116900
+ for (const rule of manifest?.references ?? []) {
116901
+ const types = rule.types ?? [];
116902
+ if ("json" in rule) {
116903
+ if (typeof content !== "string") content = mapJson(content, rule.json.split("/").filter(Boolean), "", (src, at2) => map2(src, { src, types, text: false, at: at2 || "/" }));
116904
+ } else if (typeof content === "string") {
116905
+ content = mapText(content, rule, (src, line) => map2(src, { src, types, text: true, line }));
116906
+ }
116907
+ }
116908
+ return content;
116909
+ }
116910
+ function referencesOf(manifest, content) {
116911
+ const found = [];
116912
+ mapReferences(manifest, content, (src, ref) => (found.push(ref), src));
116913
+ return found;
116914
+ }
116915
+
116916
+ // ../artifact-sdk/src/internal/references.ts
116917
+ var STORYBOARD = ["storyboard"];
116918
+ var WORKFLOW = ["workflow"];
116919
+ var COMPARE = ["storyboard", "compare"];
116920
+ var isObject2 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
116742
116921
  function bodyReferences(body) {
116743
116922
  const lines = body.replace(/<!--[^]*?-->/g, "").split(/\r?\n/);
116744
116923
  let fence = "";
@@ -116759,12 +116938,12 @@ function bodyReferences(body) {
116759
116938
  }
116760
116939
  const kept4 = inTag || !/^(?: {4}|\t)/.test(line);
116761
116940
  visible.push(kept4 ? line : "");
116762
- if (kept4 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard)\b/.test(line)) inTag = true;
116941
+ if (kept4 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard|Workflow)\b/.test(line)) inTag = true;
116763
116942
  if (line.includes("/>")) inTag = false;
116764
116943
  }
116765
116944
  const text4 = visible.join("\n").replace(/(`+)[^]*?\1/g, "");
116766
- const tag = /<(Asset|Mockup|Compare|Storyboard)\b([^<>]*?)\/>/g;
116767
- const blocks = text4.matchAll(/^ {0,3}(?:<(?:Asset|Mockup|Compare|Storyboard)\b[^<>]*?\/>[ \t]*(?:\n[ \t]*)?)+$/gm);
116945
+ const tag = /<(Asset|Mockup|Compare|Storyboard|Workflow)\b([^<>]*?)\/>/g;
116946
+ const blocks = text4.matchAll(/^ {0,3}(?:<(?:Asset|Mockup|Compare|Storyboard|Workflow)\b[^<>]*?\/>[ \t]*(?:\n[ \t]*)?)+$/gm);
116768
116947
  for (const block of blocks) {
116769
116948
  const tags = [...block[0].matchAll(tag)];
116770
116949
  for (const m of tags) {
@@ -116772,14 +116951,14 @@ function bodyReferences(body) {
116772
116951
  for (const p2 of m[2].matchAll(/([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) a2[p2[1]] = p2[2] ?? p2[3];
116773
116952
  if (m[1] === "Compare") {
116774
116953
  if (!a2.a || !a2.b) continue;
116775
- for (const k2 of ["a", "b", "shots"]) if (a2[k2]) out.push({ src: a2[k2], purpose: "compare" });
116954
+ for (const k2 of ["a", "b", "shots"]) if (a2[k2]) out.push({ src: a2[k2], types: COMPARE });
116776
116955
  } else if (a2.src) {
116777
- out.push({ src: a2.src, purpose: m[1] === "Storyboard" ? "storyboard" : "asset" });
116956
+ out.push({ src: a2.src, types: m[1] === "Storyboard" ? STORYBOARD : m[1] === "Workflow" ? WORKFLOW : [] });
116778
116957
  if (a2.variants) {
116779
116958
  try {
116780
116959
  const v = JSON.parse(a2.variants);
116781
- if (isObject(v)) {
116782
- for (const src of Object.values(v)) if (typeof src === "string" && src) out.push({ src, purpose: "asset" });
116960
+ if (isObject2(v)) {
116961
+ for (const src of Object.values(v)) if (typeof src === "string" && src) out.push({ src, types: [] });
116783
116962
  }
116784
116963
  } catch {
116785
116964
  }
@@ -116787,36 +116966,9 @@ function bodyReferences(body) {
116787
116966
  }
116788
116967
  }
116789
116968
  }
116790
- for (const m of text4.replace(tag, "").matchAll(/\]\(\s*<?([^\s)>]+)>?(?:\s+["'][^]*?["'])?\s*\)/g)) out.push({ src: m[1], purpose: "asset" });
116969
+ for (const m of text4.replace(tag, "").matchAll(/\]\(\s*<?([^\s)>]+)>?(?:\s+["'][^]*?["'])?\s*\)/g)) out.push({ src: m[1], types: [] });
116791
116970
  return out;
116792
116971
  }
116793
- function mapReferences(data, kind, map2) {
116794
- const c2 = structuredClone(data);
116795
- if (!isObject(c2)) return c2;
116796
- const field = (obj3, key, purpose = "asset") => {
116797
- if (typeof obj3[key] === "string" && obj3[key]) obj3[key] = map2(obj3[key], purpose);
116798
- };
116799
- if (kind === "compare") for (const key of ["a", "b", "shots"]) field(c2, key, "compare");
116800
- if (kind === "storyboard") {
116801
- if (Array.isArray(c2.shots)) for (const shot of c2.shots) {
116802
- if (isObject(shot) && Array.isArray(shot.frames)) {
116803
- for (const frame2 of shot.frames) if (isObject(frame2)) field(frame2, "src");
116804
- }
116805
- }
116806
- if (Array.isArray(c2.slides)) {
116807
- for (const slide of c2.slides) if (isObject(slide)) {
116808
- if (isObject(slide.preview)) field(slide.preview, "src");
116809
- if (Array.isArray(slide.assets)) slide.assets = slide.assets.map((src) => typeof src === "string" ? map2(src, "asset") : src);
116810
- }
116811
- }
116812
- }
116813
- return c2;
116814
- }
116815
- function jsonKind(data, purpose) {
116816
- if (!isObject(data)) return "asset";
116817
- if (purpose !== "asset" && typeof data.a === "string" && typeof data.b === "string") return "compare";
116818
- return purpose !== "asset" && (Array.isArray(data.shots) || Array.isArray(data.slides)) ? "storyboard" : "asset";
116819
- }
116820
116972
  var TYPES = {
116821
116973
  ".png": "image/png",
116822
116974
  ".jpg": "image/jpeg",
@@ -116835,7 +116987,12 @@ var TYPES = {
116835
116987
  ".wav": "audio/wav",
116836
116988
  ".m4a": "audio/mp4",
116837
116989
  ".json": "application/json",
116838
- ".txt": "text/plain"
116990
+ ".txt": "text/plain",
116991
+ ".otf": "font/otf",
116992
+ ".ttf": "font/ttf",
116993
+ ".woff": "font/woff",
116994
+ ".woff2": "font/woff2",
116995
+ ".css": "text/css"
116839
116996
  };
116840
116997
  function kindOf(ext) {
116841
116998
  if (ext === ".tsx" || ext === ".html") return "html";
@@ -116846,66 +117003,84 @@ function kindOf(ext) {
116846
117003
  }
116847
117004
 
116848
117005
  // ../artifact-sdk/src/internal/collect.ts
117006
+ var extOf = (file2) => /\.[^./\\]+$/.exec(file2)?.[0].toLowerCase() ?? "";
117007
+ var why = (error) => error instanceof Error ? error.message : String(error);
117008
+ var kindAt = (src, types) => extOf(src) === ".json" ? types[0] ?? "asset" : kindOf(extOf(src));
116849
117009
  function collect(body, card, host) {
116850
117010
  const nodes = /* @__PURE__ */ new Map();
116851
117011
  const active = /* @__PURE__ */ new Set();
116852
117012
  const out = [];
116853
- const visit = (src, purpose, owner) => {
117013
+ const visit = (src, types, owner) => {
117014
+ const path49 = src.replace(/[?#].*$/, "");
116854
117015
  let resolved2;
116855
117016
  try {
116856
- resolved2 = host.resolve(src, owner);
117017
+ resolved2 = host.resolve(path49, owner);
116857
117018
  } catch (error) {
116858
- throw new Error(`${owner}: ${src}: ${error instanceof Error ? error.message : String(error)}`);
117019
+ if (owner !== card) return { key: null, error: why(error) };
117020
+ if (!nodes.has(src)) {
117021
+ const node2 = { key: src, file: null, kind: kindAt(path49, types), error: why(error), problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([src]) };
117022
+ nodes.set(src, node2);
117023
+ out.push(node2);
117024
+ }
117025
+ return { key: src, error: nodes.get(src).error };
116859
117026
  }
116860
- if (!resolved2) return null;
117027
+ if (!resolved2) return { key: null };
116861
117028
  const { key, file: file2 } = resolved2;
116862
117029
  if (active.has(key)) throw new Error(`${owner}: ${src}: \u8D44\u6E90\u4F9D\u8D56\u5FAA\u73AF`);
117030
+ const json = !!file2 && extOf(file2) === ".json";
116863
117031
  const held4 = nodes.get(key);
116864
117032
  if (held4) {
116865
117033
  if (owner === card) held4.aliases.add(src);
116866
- if (!file2 || !/\.json$/i.test(file2) || purpose === "asset" || held4.kind !== "asset") return key;
117034
+ if (held4.error || !json || !types.length || held4.kind !== "asset") return { key, error: held4.error };
116867
117035
  out.splice(out.indexOf(held4), 1);
116868
117036
  }
116869
- const node = held4 ?? { key, file: file2, kind: "asset", dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([key]) };
117037
+ const node = { key, file: file2, kind: "asset", problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: held4?.aliases ?? /* @__PURE__ */ new Set([key]) };
116870
117038
  if (owner === card) node.aliases.add(src);
116871
117039
  nodes.set(key, node);
116872
117040
  active.add(key);
116873
- if (file2 && /\.json$/i.test(file2)) {
116874
- try {
116875
- node.data = host.readJSON(file2);
116876
- } catch {
116877
- throw new Error(`${owner}: ${src}: JSON \u65E0\u6CD5\u89E3\u6790`);
116878
- }
116879
- node.kind = jsonKind(node.data, purpose);
116880
- mapReferences(node.data, node.kind, (child, use) => {
116881
- const key2 = visit(child, use, file2);
116882
- if (key2) node.dependencies.set(child, key2);
116883
- return child;
116884
- });
116885
- } else if (!file2) {
116886
- for (const child of host.retained(key)) {
116887
- const key2 = visit(child.src, child.purpose, card);
116888
- if (key2) node.dependencies.set(child.src, key2);
117041
+ const child = (ref, from) => {
117042
+ const found = visit(ref.src, ref.types, from);
117043
+ if (found.key) node.dependencies.set(ref.src, found.key);
117044
+ else if (found.error) node.problems.push({ src: ref.src, ..."line" in ref ? { line: ref.line } : {}, ..."at" in ref ? { at: ref.at } : {}, message: found.error });
117045
+ node.error ??= found.error;
117046
+ };
117047
+ if (file2) {
117048
+ if (json) {
117049
+ try {
117050
+ node.data = JSON.parse(host.read(file2));
117051
+ const typed = typeOf(node.data, types);
117052
+ node.kind = typed.type ?? "asset";
117053
+ if (typed.problem) node.problems.push({ src: file2, message: `${typed.problem}: ${file2}` });
117054
+ } catch {
117055
+ node.problems.push({ src: file2, message: `not valid JSON: ${file2}` });
117056
+ }
117057
+ } else {
117058
+ node.kind = kindOf(extOf(file2));
117059
+ try {
117060
+ if (manifestOf(node.kind)?.references) node.data = host.read(file2);
117061
+ } catch (error) {
117062
+ node.problems.push({ src: file2, message: why(error) });
117063
+ }
116889
117064
  }
117065
+ node.error = node.problems[0]?.message;
117066
+ if (!node.error) for (const ref of referencesOf(manifestOf(node.kind), node.data)) child(ref, file2);
117067
+ } else {
117068
+ for (const ref of host.retained(key)) child(ref, card);
116890
117069
  }
116891
117070
  active.delete(key);
116892
117071
  out.push(node);
116893
- return key;
117072
+ return { key, error: node.error };
116894
117073
  };
116895
- for (const ref of bodyReferences(body)) visit(ref.src, ref.purpose, card);
117074
+ for (const ref of bodyReferences(body)) visit(ref.src, ref.types, card);
116896
117075
  const sorted = [];
116897
117076
  const done = /* @__PURE__ */ new Set();
116898
- const sorting = /* @__PURE__ */ new Set();
116899
117077
  const order = (node) => {
116900
117078
  if (done.has(node.key)) return;
116901
- if (sorting.has(node.key)) throw new Error(`${node.key}: \u8D44\u6E90\u4F9D\u8D56\u5FAA\u73AF`);
116902
- sorting.add(node.key);
117079
+ done.add(node.key);
116903
117080
  for (const key of node.dependencies.values()) {
116904
117081
  const child = nodes.get(key);
116905
117082
  if (child) order(child);
116906
117083
  }
116907
- sorting.delete(node.key);
116908
- done.add(node.key);
116909
117084
  sorted.push(node);
116910
117085
  };
116911
117086
  for (const node of out) order(node);
@@ -117182,6 +117357,87 @@ import fs20 from "node:fs";
117182
117357
  import path24 from "node:path";
117183
117358
  import { fileURLToPath as fileURLToPath2 } from "node:url";
117184
117359
 
117360
+ // ../cli/src/lib/agents/icon.ts
117361
+ var ICON_NAMES = [
117362
+ "file",
117363
+ "text",
117364
+ "article",
117365
+ "outline",
117366
+ "script",
117367
+ "prompt",
117368
+ "email",
117369
+ "image",
117370
+ "post-image",
117371
+ "social-image",
117372
+ "cover",
117373
+ "carousel",
117374
+ "carousel-outline",
117375
+ "slides",
117376
+ "wireframe",
117377
+ "screen",
117378
+ "video",
117379
+ "storyboard",
117380
+ "template",
117381
+ "shots",
117382
+ "api",
117383
+ "schema",
117384
+ "compare",
117385
+ "stack",
117386
+ "workflow",
117387
+ "code",
117388
+ "checklist",
117389
+ "card",
117390
+ "plan",
117391
+ "proposal",
117392
+ "dismissed",
117393
+ "inbox",
117394
+ "notebook",
117395
+ "squeeze",
117396
+ "folder",
117397
+ "reply",
117398
+ "feedback",
117399
+ "software",
117400
+ "product-video",
117401
+ "social-post",
117402
+ "blog",
117403
+ "deck",
117404
+ "video-clone",
117405
+ "workflow-kit"
117406
+ ];
117407
+ var ICON_COLORS = ["k", "w", "c", "g", "o", "p", "s", "m", "l", "r", "y"];
117408
+ var PATH = /^[MmLlHhVvCcSsQqTtAaZz0-9.,\s-]+$/;
117409
+ var isColor = (v) => ICON_COLORS.includes(v);
117410
+ function readIcon(raw) {
117411
+ if (raw === void 0 || raw === "") return void 0;
117412
+ if (typeof raw === "string") return ICON_NAMES.includes(raw.trim()) ? raw.trim() : { problem: `"${raw}" is not a glyph name` };
117413
+ 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" };
117414
+ const parts = [];
117415
+ for (const [i, item] of raw.entries()) {
117416
+ const at2 = `part ${i + 1}`;
117417
+ if (!item || typeof item !== "object" || Array.isArray(item)) return { problem: `${at2} is not a map of \`d\`, \`f\`, \`o\`, \`s\`, \`w\`` };
117418
+ const { d: d2, f: f2, o: o3, s, w: w2, ...extra } = item;
117419
+ if (Object.keys(extra).length) return { problem: `${at2} has \`${Object.keys(extra).join("`, `")}\`` };
117420
+ if (typeof d2 !== "string" || !PATH.test(d2)) return { problem: `${at2} has no \`d\` of SVG path commands and numbers` };
117421
+ const part = { d: d2.trim() };
117422
+ for (const [key, value] of [["f", f2], ["s", s]]) {
117423
+ if (value === void 0) continue;
117424
+ if (typeof value !== "string" || !isColor(value)) return { problem: `${at2} colours \`${key}\` with "${String(value)}"` };
117425
+ part[key] = value;
117426
+ }
117427
+ if (o3 !== void 0) {
117428
+ if (o3 !== "true") return { problem: `${at2} has \`o: ${String(o3)}\`, not \`true\`` };
117429
+ part.o = true;
117430
+ }
117431
+ if (w2 !== void 0) {
117432
+ const width = typeof w2 === "string" ? Number(w2) : NaN;
117433
+ if (!(width > 0 && width <= 3)) return { problem: `${at2} has \`w: ${String(w2)}\`, not above 0 and up to 3` };
117434
+ part.w = width;
117435
+ }
117436
+ parts.push(part);
117437
+ }
117438
+ return parts;
117439
+ }
117440
+
117185
117441
  // ../cli/src/lib/agents/yaml.ts
117186
117442
  function stripComment(value) {
117187
117443
  let from = 0;
@@ -117293,8 +117549,8 @@ var SCHEDULE_READS = ["archived-cards", "chats", "dismissals"];
117293
117549
  var isScheduleReads = (value) => SCHEDULE_READS.includes(value);
117294
117550
  function parseSpecAgent(text4, from, file2, builtIn = false, list = () => []) {
117295
117551
  let named2 = "";
117296
- const bad = (why, old2) => ({
117297
- problem: `${from}: ${why}`,
117552
+ const bad = (why2, old2) => ({
117553
+ problem: `${from}: ${why2}`,
117298
117554
  ...named2 ? { name: named2 } : {},
117299
117555
  ...old2 ? { old: old2 } : {}
117300
117556
  });
@@ -117329,6 +117585,12 @@ function parseSpecAgent(text4, from, file2, builtIn = false, list = () => []) {
117329
117585
  if (!Array.isArray(components) || components.some((value) => typeof value !== "string" || !value.trim())) {
117330
117586
  return bad(`\`${name}\` declares \`akb.components\` that is not a list of component IDs`);
117331
117587
  }
117588
+ const icon = readIcon(akb.icon);
117589
+ if (icon && typeof icon === "object" && "problem" in icon) {
117590
+ return bad(
117591
+ `\`${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(", ")}`
117592
+ );
117593
+ }
117332
117594
  const workspace = memoryPaths(akb.memoryFiles);
117333
117595
  if (typeof workspace === "string") return bad(`\`${name}\` declares ${workspace}`);
117334
117596
  const instructions = body.trim();
@@ -117340,6 +117602,7 @@ function parseSpecAgent(text4, from, file2, builtIn = false, list = () => []) {
117340
117602
  ...when ? { when } : {},
117341
117603
  after,
117342
117604
  components: [...new Set(components.map((value) => value.trim()))],
117605
+ ...icon ? { icon } : {},
117343
117606
  i18n: readTranslations(akb.i18n),
117344
117607
  ...declaredReads ? { reads: declaredReads } : {},
117345
117608
  ...declaredSession ? { session: "new" } : {},
@@ -117439,6 +117702,12 @@ function parseWorkflowFile(id, source, from) {
117439
117702
  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`
117440
117703
  };
117441
117704
  }
117705
+ const icon = readIcon(raw.icon);
117706
+ if (icon && typeof icon === "object" && "problem" in icon) {
117707
+ return {
117708
+ 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(", ")}`
117709
+ };
117710
+ }
117442
117711
  const previews = readPreviews(raw.previews);
117443
117712
  if (typeof previews === "string") return { problem: `${from}: ${previews}` };
117444
117713
  const land = readGroup(raw.land);
@@ -117463,6 +117732,7 @@ function parseWorkflowFile(id, source, from) {
117463
117732
  description: text2(raw.description),
117464
117733
  when: text2(raw.when),
117465
117734
  needsArtifact: text2(raw.needsArtifact) === "true",
117735
+ ...icon ? { icon } : {},
117466
117736
  previews,
117467
117737
  land,
117468
117738
  scheduled,
@@ -117479,6 +117749,7 @@ var FILE_LIMITS = { file: 256 * KB, total: 2 * KB * KB, count: 500, path: 512 };
117479
117749
  var LAND_ROLES = ["builder"];
117480
117750
  var landsOf = (def) => ({ lands: def.land.some((h3) => !h3.off) });
117481
117751
  var SEGMENT = /^[\w.-]+$/;
117752
+ var isAboutFile = (file2) => /^ABOUT(\.[a-z]{2})?\.md$/.test(file2) || /^screenshots\/[\w.-]+\.(png|jpe?g|webp)$/.test(file2);
117482
117753
  var bytes = (text4) => new TextEncoder().encode(text4).length;
117483
117754
  function folderPath(file2, top) {
117484
117755
  const parts = file2.split("/");
@@ -117487,13 +117758,13 @@ function folderPath(file2, top) {
117487
117758
  return [parts[1], parts.slice(2).join("/")];
117488
117759
  }
117489
117760
  function mcpProblem(text4) {
117490
- let read2;
117761
+ let read3;
117491
117762
  try {
117492
- read2 = JSON.parse(text4);
117763
+ read3 = JSON.parse(text4);
117493
117764
  } catch {
117494
117765
  return "is not JSON";
117495
117766
  }
117496
- const servers = read2?.mcpServers;
117767
+ const servers = read3?.mcpServers;
117497
117768
  if (!servers || typeof servers !== "object" || Array.isArray(servers)) return "must hold `mcpServers`, an object of name \u2192 server";
117498
117769
  for (const [name, server] of Object.entries(servers)) {
117499
117770
  const { command, args, ...rest } = server ?? {};
@@ -117525,6 +117796,7 @@ function checkWorkflowFiles(value, official = false) {
117525
117796
  if (problem) return fail(file2, problem);
117526
117797
  continue;
117527
117798
  }
117799
+ if (official && isAboutFile(file2)) continue;
117528
117800
  if (official && file2.startsWith("skills/")) {
117529
117801
  if (!folderPath(file2, "skills")) return fail(file2, "is not inside skills/<name>/");
117530
117802
  skills.add(file2.split("/")[1]);
@@ -117540,9 +117812,9 @@ function checkWorkflowFiles(value, official = false) {
117540
117812
  }
117541
117813
  const source = value[WORKFLOW_FILE];
117542
117814
  if (source === void 0) return fail(WORKFLOW_FILE, "is missing");
117543
- const read2 = parseWorkflowFile("workflow", source, WORKFLOW_FILE);
117544
- if ("problem" in read2) return fail(WORKFLOW_FILE, read2.problem.replace(`${WORKFLOW_FILE}: `, ""));
117545
- const def = read2.def;
117815
+ const read3 = parseWorkflowFile("workflow", source, WORKFLOW_FILE);
117816
+ if ("problem" in read3) return fail(WORKFLOW_FILE, read3.problem.replace(`${WORKFLOW_FILE}: `, ""));
117817
+ const def = read3.def;
117546
117818
  const agents = /* @__PURE__ */ new Map();
117547
117819
  for (const [name, own] of folders2) {
117548
117820
  const from = `agents/${name}/AGENT.md`;
@@ -117558,14 +117830,15 @@ function checkWorkflowFiles(value, official = false) {
117558
117830
  ...def.land.filter((h3) => !LAND_ROLES.includes(h3.agent)).map((h3) => [h3.agent, "it lands with"]),
117559
117831
  ...def.scheduled.map((s) => [s.agent, "it schedules"])
117560
117832
  ];
117561
- for (const [name, why] of named2) {
117562
- if (!agents.has(name)) return fail(WORKFLOW_FILE, `${why} \`${name}\`, which has no agents/${name}/AGENT.md`);
117833
+ for (const [name, why2] of named2) {
117834
+ if (!agents.has(name)) return fail(WORKFLOW_FILE, `${why2} \`${name}\`, which has no agents/${name}/AGENT.md`);
117563
117835
  }
117564
117836
  return { ok: true, def, files: value };
117565
117837
  }
117566
117838
 
117567
117839
  // ../official/pack.ts
117568
117840
  var OFFICIAL = path24.dirname(fileURLToPath2(import.meta.url));
117841
+ var MIME = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp" };
117569
117842
  var dirs = (dir) => fs20.readdirSync(dir, { withFileTypes: true }).filter((e2) => e2.isDirectory()).map((e2) => e2.name).sort();
117570
117843
  function filesOf(dir, base = dir) {
117571
117844
  return fs20.readdirSync(dir, { withFileTypes: true }).flatMap((e2) => {
@@ -117582,20 +117855,21 @@ function packOfficial(root2 = OFFICIAL, loose = false) {
117582
117855
  return [name, Object.fromEntries(filesOf(dir).sort().map((f2) => [f2, fs20.readFileSync(path24.join(dir, f2), "utf8")]))];
117583
117856
  }));
117584
117857
  for (const [name, own] of Object.entries(loose ? {} : agentFiles)) {
117585
- const read2 = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p2) => own[p2] ?? null, true);
117586
- if ("problem" in read2) throw new Error(read2.problem);
117858
+ const read3 = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p2) => own[p2] ?? null, true);
117859
+ if ("problem" in read3) throw new Error(read3.problem);
117587
117860
  }
117588
117861
  const workflowsDir = path24.join(root2, "workflows");
117589
117862
  return dirs(workflowsDir).map((folder) => {
117590
117863
  const dir = path24.join(workflowsDir, folder);
117591
117864
  const files = {};
117592
117865
  for (const f2 of filesOf(dir).sort()) {
117593
- if (f2 === WORKFLOW_FILE || f2 === MCP_FILE || f2.startsWith("skills/")) files[f2] = fs20.readFileSync(path24.join(dir, f2), "utf8");
117866
+ if (f2 === WORKFLOW_FILE || f2 === MCP_FILE || f2.startsWith("skills/") || /^ABOUT(\.[a-z]{2})?\.md$/.test(f2)) files[f2] = fs20.readFileSync(path24.join(dir, f2), "utf8");
117867
+ else if (isAboutFile(f2)) files[f2] = `data:${MIME[path24.extname(f2)]};base64,${fs20.readFileSync(path24.join(dir, f2)).toString("base64")}`;
117594
117868
  }
117595
- const read2 = checkWorkflowFiles({ [WORKFLOW_FILE]: files[WORKFLOW_FILE], ...Object.fromEntries(
117869
+ const read3 = checkWorkflowFiles({ [WORKFLOW_FILE]: files[WORKFLOW_FILE], ...Object.fromEntries(
117596
117870
  Object.entries(agentFiles).flatMap(([name, own]) => Object.entries(own).map(([f2, t2]) => [`agents/${name}/${f2}`, t2]))
117597
117871
  ) });
117598
- if (!read2.ok && !loose) throw new Error(`official/workflows/${folder}: ${read2.file}: ${read2.reason}`);
117872
+ if (!read3.ok && !loose) throw new Error(`official/workflows/${folder}: ${read3.file}: ${read3.reason}`);
117599
117873
  const parsed = parseWorkflowFile(folder, files[WORKFLOW_FILE] ?? "", WORKFLOW_FILE);
117600
117874
  if ("problem" in parsed) throw new Error(parsed.problem);
117601
117875
  const def = parsed.def;
@@ -117701,14 +117975,14 @@ function currentTurn() {
117701
117975
  function forgetFileMemos() {
117702
117976
  turn++;
117703
117977
  }
117704
- function memoByFiles(paths, read2) {
117978
+ function memoByFiles(paths, read3) {
117705
117979
  let last2 = null;
117706
117980
  return () => {
117707
117981
  const now = currentTurn();
117708
117982
  if (last2?.turn !== now) {
117709
117983
  const seen = stamp(paths());
117710
117984
  if (last2?.stamp === seen) last2.turn = now;
117711
- else last2 = { stamp: seen, turn: now, value: read2() };
117985
+ else last2 = { stamp: seen, turn: now, value: read3() };
117712
117986
  }
117713
117987
  return copy(last2.value);
117714
117988
  };
@@ -117749,9 +118023,9 @@ var boardProject = () => KANBAN ? runnerProject(KANBAN) : null;
117749
118023
  var devFolder = () => process.env[DEV]?.trim() || "";
117750
118024
  var flowOf = (held4) => {
117751
118025
  const id = workflowName(held4.id);
117752
- const read2 = parseWorkflowFile(id, held4.files["WORKFLOW.md"] ?? "", `the \`${id}\` workflow`);
117753
- if ("problem" in read2) return null;
117754
- return { def: read2.def, cloudId: held4.id, version: held4.version, builtIn: held4.id.startsWith("wf_builtin_"), files: held4.files };
118026
+ const read3 = parseWorkflowFile(id, held4.files["WORKFLOW.md"] ?? "", `the \`${id}\` workflow`);
118027
+ if ("problem" in read3) return null;
118028
+ return { def: read3.def, cloudId: held4.id, version: held4.version, builtIn: held4.id.startsWith("wf_builtin_"), files: held4.files };
117755
118029
  };
117756
118030
  function readFlows() {
117757
118031
  const dev = devFolder();
@@ -117799,10 +118073,6 @@ function cloudAgentFiles() {
117799
118073
  return { files, official };
117800
118074
  }
117801
118075
 
117802
- // ../cli/src/lib/preview-validation.ts
117803
- import fs29 from "node:fs";
117804
- import path33 from "node:path";
117805
-
117806
118076
  // ../cli/src/lib/agent/launch.ts
117807
118077
  import { fileURLToPath as fileURLToPath3 } from "node:url";
117808
118078
  var SELF = fileURLToPath3(import.meta.url);
@@ -118163,12 +118433,12 @@ function readAnswers(raw) {
118163
118433
  if (!Array.isArray(raw)) return void 0;
118164
118434
  const answers3 = raw.flatMap((entry) => {
118165
118435
  if (!entry || entry.outcome !== "changed" && entry.outcome !== "unchanged") return [];
118166
- const why = text3(entry.why);
118167
- if (!why) return [];
118436
+ const why2 = text3(entry.why);
118437
+ if (!why2) return [];
118168
118438
  return [
118169
118439
  {
118170
118440
  outcome: entry.outcome,
118171
- why,
118441
+ why: why2,
118172
118442
  at: typeof entry.at === "number" ? entry.at : 0,
118173
118443
  actedAt: typeof entry.actedAt === "number" ? entry.actedAt : void 0
118174
118444
  }
@@ -118370,16 +118640,16 @@ function readCatalog() {
118370
118640
  const agents = [];
118371
118641
  const problems = [];
118372
118642
  const refused = [];
118373
- const take = (read2, folder) => {
118374
- if ("problem" in read2) {
118375
- if (!read2.missing) problems.push(read2.problem);
118376
- if (!read2.file) return;
118377
- const { file: file2, name: name2, old } = read2;
118378
- const cause = read2.missing ? "noFile" : old ? "oldKeys" : "file";
118643
+ const take = (read3, folder) => {
118644
+ if ("problem" in read3) {
118645
+ if (!read3.missing) problems.push(read3.problem);
118646
+ if (!read3.file) return;
118647
+ const { file: file2, name: name2, old } = read3;
118648
+ const cause = read3.missing ? "noFile" : old ? "oldKeys" : "file";
118379
118649
  refused.push({ folder, file: file2, cause, ...name2 ? { name: name2 } : {}, ...old ? { keys: old.keys } : {} });
118380
118650
  return;
118381
118651
  }
118382
- const { name, from, builtIn } = read2.agent;
118652
+ const { name, from, builtIn } = read3.agent;
118383
118653
  const refuse = (cause, problem) => {
118384
118654
  problems.push(problem);
118385
118655
  if (!builtIn) refused.push({ folder, name, file: from, cause });
@@ -118403,14 +118673,14 @@ function readCatalog() {
118403
118673
  `${from}: its folder is \`${folder}\` but it calls itself \`${name}\`. An agent is asked for by its folder name \u2014 make the two match.`
118404
118674
  );
118405
118675
  }
118406
- agents.push(read2.agent);
118676
+ agents.push(read3.agent);
118407
118677
  };
118408
118678
  for (const folder of bundledFolders()) take(readBundled(folder), folder);
118409
118679
  for (const folder of projectFolders(AGENTS)) {
118410
- const read2 = readProject2(AGENTS, folder);
118411
- take(read2, folder);
118412
- if ("agent" in read2 && read2.agent.from.endsWith(LEGACY_AGENT_FILE)) {
118413
- problems.push(`${read2.agent.from}: rename it to ${AGENT_FILE}`);
118680
+ const read3 = readProject2(AGENTS, folder);
118681
+ take(read3, folder);
118682
+ if ("agent" in read3 && read3.agent.from.endsWith(LEGACY_AGENT_FILE)) {
118683
+ problems.push(`${read3.agent.from}: rename it to ${AGENT_FILE}`);
118414
118684
  }
118415
118685
  }
118416
118686
  for (const folder of projectFolders(LEGACY_AGENTS)) {
@@ -118520,10 +118790,10 @@ function readProject2(root2, folder) {
118520
118790
  const missing = rel(path29.join(dir, AGENT_FILE));
118521
118791
  if (!found) return { problem: `${missing} is missing`, file: missing, missing: true };
118522
118792
  const from = rel(path29.join(dir, found.name));
118523
- const read2 = parseSpecAgent(found.text, from, file2, false, () => ownFiles(walkFolder(dir, "")));
118524
- if ("problem" in read2) return { ...read2, file: from };
118525
- if ("agent" in read2) Object.assign(read2.agent, { dir, text: found.text });
118526
- return read2;
118793
+ const read3 = parseSpecAgent(found.text, from, file2, false, () => ownFiles(walkFolder(dir, "")));
118794
+ if ("problem" in read3) return { ...read3, file: from };
118795
+ if ("agent" in read3) Object.assign(read3.agent, { dir, text: found.text });
118796
+ return read3;
118527
118797
  }
118528
118798
 
118529
118799
  // ../cli/src/lib/question-block.ts
@@ -118786,12 +119056,12 @@ function readFolder(id, problems) {
118786
119056
  problems.push(`${rel(fileOf(id))} is missing`);
118787
119057
  return null;
118788
119058
  }
118789
- const read2 = parseWorkflowFile(id, source, rel(fileOf(id)));
118790
- if ("problem" in read2) {
118791
- problems.push(read2.problem);
119059
+ const read3 = parseWorkflowFile(id, source, rel(fileOf(id)));
119060
+ if ("problem" in read3) {
119061
+ problems.push(read3.problem);
118792
119062
  return null;
118793
119063
  }
118794
- return read2.def;
119064
+ return read3.def;
118795
119065
  }
118796
119066
  function boardWorkflowDefs() {
118797
119067
  const problems = [];
@@ -118971,6 +119241,9 @@ var attr = (name) => new RegExp(`\\b${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`);
118971
119241
  var SRC_ATTR = attr("src");
118972
119242
  var LABEL_ATTR = attr("label");
118973
119243
 
119244
+ // ../cli/src/lib/preview-files.ts
119245
+ init_dress_page();
119246
+
118974
119247
  // ../cli/src/lib/preview-validation.ts
118975
119248
  function renderError(error) {
118976
119249
  if (!error || typeof error !== "object") return String(error);
@@ -118979,19 +119252,9 @@ function renderError(error) {
118979
119252
  const reason = message ?? String(error);
118980
119253
  return location && !reason.includes(location) ? `${reason} (${location})` : reason;
118981
119254
  }
118982
- async function validateScreens(files) {
118983
- const errors = [];
118984
- const entries = /* @__PURE__ */ new Map();
118985
- for (const file2 of files) entries.set(fs29.existsSync(file2) ? fs29.realpathSync(file2) : path33.resolve(file2), path33.resolve(file2));
118986
- for (const file2 of entries.values()) {
118987
- try {
118988
- await drawMockup(file2);
118989
- } catch (error) {
118990
- errors.push({ file: file2, line: 1, rule: "preview-render", message: renderError(error) });
118991
- }
118992
- }
118993
- return errors;
118994
- }
119255
+
119256
+ // src/task-folder.ts
119257
+ init_dress_page();
118995
119258
 
118996
119259
  // ../cli/src/lib/agents/shared-memory.ts
118997
119260
  import fs30 from "node:fs";
@@ -119000,8 +119263,8 @@ function sharedMemory(board) {
119000
119263
  const declared = /* @__PURE__ */ new Map();
119001
119264
  const take = (folder, text4, builtIn) => {
119002
119265
  if (text4 === null || declared.has(folder)) return;
119003
- const read2 = parseSpecAgent(text4, folder, () => null, builtIn);
119004
- if ("agent" in read2 && read2.agent.name === folder) declared.set(folder, read2.agent.memoryFiles.workspace);
119266
+ const read3 = parseSpecAgent(text4, folder, () => null, builtIn);
119267
+ if ("agent" in read3 && read3.agent.name === folder) declared.set(folder, read3.agent.memoryFiles.workspace);
119005
119268
  };
119006
119269
  for (const [key, text4] of Object.entries(shippedAgentFiles())) {
119007
119270
  const at2 = /^([^/]+)\/AGENT\.md$/.exec(key);
@@ -119204,7 +119467,14 @@ function viewOf(ws, base, shared) {
119204
119467
  }
119205
119468
  function assetFiles(ws, list) {
119206
119469
  const card = cardFile(ws);
119207
- return new Set(Object.keys(assetsOf(list)).map((name) => assetPath(ws, name, card)).filter((f2) => !!f2).map((f2) => path35.relative(ws.board, f2).split(path35.sep).join("/")));
119470
+ const at2 = (name) => {
119471
+ try {
119472
+ return assetPath(ws, name, card);
119473
+ } catch {
119474
+ return null;
119475
+ }
119476
+ };
119477
+ return new Set(Object.keys(assetsOf(list)).map(at2).filter((f2) => !!f2).map((f2) => path35.relative(ws.board, f2).split(path35.sep).join("/")));
119208
119478
  }
119209
119479
  var assetsListOf = (ws, base) => base.files[rootOf(ws) + assetsFile(ws.task)]?.content;
119210
119480
  var localFiles = (ws, base) => {
@@ -119252,15 +119522,15 @@ async function workflowFiles(ws) {
119252
119522
  const pin = readPin(ws.cloudTask);
119253
119523
  const held4 = pin && readVersion2(pin.workflow, pin.version);
119254
119524
  if (held4) return { ok: true, value: held4.files };
119255
- const read3 = await readTaskWorkflow(ws.cloudTask);
119256
- if (!read3.ok) return read3;
119257
- savePin(ws.cloudTask, { id: read3.value.workflow, version: read3.value.version, name: read3.value.name ?? read3.value.workflow, files: read3.value.files });
119258
- return { ok: true, value: read3.value.files };
119525
+ const read4 = await readTaskWorkflow(ws.cloudTask);
119526
+ if (!read4.ok) return read4;
119527
+ savePin(ws.cloudTask, { id: read4.value.workflow, version: read4.value.version, name: read4.value.name ?? read4.value.workflow, files: read4.value.files });
119528
+ return { ok: true, value: read4.value.files };
119259
119529
  }
119260
- const read2 = await readWorkflow(workflow);
119261
- if (!read2.ok) return read2;
119262
- saveVersion({ id: workflow, version: read2.value.version, name: read2.value.name ?? workflow, files: read2.value.files });
119263
- return { ok: true, value: read2.value.files };
119530
+ const read3 = await readWorkflow(workflow);
119531
+ if (!read3.ok) return read3;
119532
+ saveVersion({ id: workflow, version: read3.value.version, name: read3.value.name ?? workflow, files: read3.value.files });
119533
+ return { ok: true, value: read3.value.files };
119264
119534
  }
119265
119535
  async function pullWorkflow(ws, record) {
119266
119536
  if (ws.workflow) {
@@ -119300,14 +119570,14 @@ function pullDraftAgents(ws, record) {
119300
119570
  }
119301
119571
  function assetPath(ws, name, owner) {
119302
119572
  if (/^[a-z][\w+.-]*:/i.test(name) || name.startsWith("#") || name.startsWith("//")) return null;
119303
- if (path35.isAbsolute(name)) throw new Error("\u8D44\u6E90\u8DEF\u5F84\u4E0D\u80FD\u662F\u7EDD\u5BF9\u8DEF\u5F84");
119573
+ if (path35.isAbsolute(name)) throw new Error(`absolute path: ${name}`);
119304
119574
  const held4 = /^\.(assets|mockups)\//.exec(name);
119305
119575
  const state = stateDir(ws);
119306
119576
  const root2 = held4 && state ? path35.join(state, held4[1]) : ws.board;
119307
119577
  const file2 = held4 && state ? path35.resolve(root2, name.slice(held4[0].length)) : path35.resolve(path35.dirname(owner), name);
119308
119578
  const roots = [ws.board, ...state ? ["assets", "mockups"].map((folder) => path35.join(state, folder, ...ws.number ? [String(ws.number)] : [])) : []];
119309
119579
  const inside = (file3, root3) => file3.startsWith(root3 + path35.sep);
119310
- if (!roots.some((root3) => inside(file2, root3))) throw new Error("\u8D44\u6E90\u8DEF\u5F84\u8D8A\u754C");
119580
+ if (!roots.some((root3) => inside(file2, root3))) throw new Error(`outside the board: ${name}`);
119311
119581
  let existing = file2;
119312
119582
  while (!fs31.existsSync(existing) && path35.dirname(existing) !== existing) existing = path35.dirname(existing);
119313
119583
  const real = fs31.realpathSync(existing);
@@ -119315,7 +119585,7 @@ function assetPath(ws, name, owner) {
119315
119585
  while (stateParent && !fs31.existsSync(stateParent) && path35.dirname(stateParent) !== stateParent) stateParent = path35.dirname(stateParent);
119316
119586
  const realState = state && stateParent ? path35.resolve(fs31.realpathSync(stateParent), path35.relative(stateParent, state)) : null;
119317
119587
  const realRoots = [fs31.realpathSync(ws.board), ...realState ? ["assets", "mockups"].map((folder) => path35.join(realState, folder, ...ws.number ? [String(ws.number)] : [])) : []];
119318
- if (!realRoots.some((root3) => real === root3 || inside(real, root3))) throw new Error("\u7B26\u53F7\u94FE\u63A5\u8D8A\u754C");
119588
+ if (!realRoots.some((root3) => real === root3 || inside(real, root3))) throw new Error(`link outside the board: ${name}`);
119319
119589
  return file2;
119320
119590
  }
119321
119591
  function cardAssetsDir(ws, id) {
@@ -119353,12 +119623,12 @@ var readHead = (ws) => readBase(ws).head_seq;
119353
119623
  var pullChanges = (ws) => inFolder(ws.cwd, async () => {
119354
119624
  const base = readBase(ws);
119355
119625
  if (base.head_seq === null) return { ok: true, value: void 0 };
119356
- const read2 = await readBoard(ws.project, base.head_seq);
119357
- if (!read2.ok) return read2;
119626
+ const read3 = await readBoard(ws.project, base.head_seq);
119627
+ if (!read3.ok) return read3;
119358
119628
  const shared = sharedMemory(ws.board);
119359
119629
  const root2 = rootOf(ws);
119360
119630
  let skipped = false;
119361
- for (const f2 of read2.value.files) {
119631
+ for (const f2 of read3.value.files) {
119362
119632
  const p2 = f2.path.startsWith(root2) ? f2.path.slice(root2.length) : f2.path;
119363
119633
  const isShared = p2.startsWith(MEMORY2) && shared(p2.slice(MEMORY2.length));
119364
119634
  if (kept3(p2) && isShared === !f2.path.startsWith(root2)) {
@@ -119374,7 +119644,7 @@ var pullChanges = (ws) => inFolder(ws.cwd, async () => {
119374
119644
  if (f2.content === null) delete base.files[f2.path];
119375
119645
  else base.files[f2.path] = { seq: f2.seq, content: f2.content };
119376
119646
  }
119377
- if (!skipped) base.head_seq = read2.value.head_seq;
119647
+ if (!skipped) base.head_seq = read3.value.head_seq;
119378
119648
  writeBase(ws, base);
119379
119649
  writeIndex(ws.board);
119380
119650
  return { ok: true, value: void 0 };
@@ -119388,14 +119658,14 @@ async function readCloud(ws) {
119388
119658
  if (!project.ok) return project;
119389
119659
  base.workspace = project.value.workspace ?? null;
119390
119660
  }
119391
- const read2 = await readBoard(ws.project, base.head_seq);
119392
- if (!read2.ok) return read2;
119661
+ const read3 = await readBoard(ws.project, base.head_seq);
119662
+ if (!read3.ok) return read3;
119393
119663
  if (base.head_seq === null) base.files = {};
119394
- for (const f2 of read2.value.files) {
119664
+ for (const f2 of read3.value.files) {
119395
119665
  if (f2.content === null) delete base.files[f2.path];
119396
119666
  else base.files[f2.path] = { seq: f2.seq, content: f2.content };
119397
119667
  }
119398
- base.head_seq = read2.value.head_seq;
119668
+ base.head_seq = read3.value.head_seq;
119399
119669
  base.project = ws.project;
119400
119670
  writeBase(ws, base);
119401
119671
  const reset = (view2) => {
@@ -119457,9 +119727,13 @@ async function pullAssets(ws, record, assets) {
119457
119727
  const file2 = cardFile(ws);
119458
119728
  const out = {};
119459
119729
  for (const [name, ref] of Object.entries(assets)) {
119730
+ const held4 = record.assets[name];
119731
+ if (ref.error && !ref.version) {
119732
+ if (held4?.artifact === ref.artifact) out[name] = held4;
119733
+ continue;
119734
+ }
119460
119735
  const target = assetPath(ws, name, file2);
119461
119736
  if (!target) continue;
119462
- const held4 = record.assets[name];
119463
119737
  let kind = held4?.artifact === ref.artifact ? held4.kind : void 0;
119464
119738
  let version = ref.version;
119465
119739
  const localHash = hashFile(target);
@@ -119483,29 +119757,34 @@ async function pullAssets(ws, record, assets) {
119483
119757
  if (!bytes2.ok) return bytes2;
119484
119758
  let local = bytes2.value;
119485
119759
  const dependencies = [];
119486
- if (kind === "storyboard" || kind === "compare") {
119487
- let data;
119488
- try {
119489
- data = JSON.parse(Buffer.from(local).toString());
119490
- } catch {
119491
- }
119492
- if (data !== void 0) {
119493
- let changed = false;
119494
- const restore = (src) => {
119495
- const name2 = Object.entries(assets).find(([, r2]) => r2.artifact === src)?.[0];
119496
- if (!name2) return src;
119497
- const child = assetPath(ws, name2, file2);
119498
- if (!child) return src;
119499
- dependencies.push(name2);
119500
- const restored2 = /^\.(assets|mockups)\//.test(name2) ? name2 : path35.relative(path35.dirname(target), child).split(path35.sep).join("/");
119501
- if (restored2 !== src) changed = true;
119502
- return restored2;
119503
- };
119504
- const restored = mapReferences(data, kind, restore);
119505
- if (changed) local = Buffer.from(JSON.stringify(restored));
119760
+ const manifest = manifestOf(kind);
119761
+ let data;
119762
+ if (manifest?.references) {
119763
+ data = Buffer.from(local).toString();
119764
+ if (manifest.references.some((r2) => "json" in r2)) {
119765
+ try {
119766
+ data = JSON.parse(data);
119767
+ } catch {
119768
+ data = void 0;
119769
+ }
119506
119770
  }
119507
119771
  }
119508
- if (held4?.artifact === ref.artifact && held4.version === version && !held4.localHash && (kind === "storyboard" || kind === "compare")) {
119772
+ if (data !== void 0) {
119773
+ let changed = false;
119774
+ const restored = mapReferences(manifest, data, (src, found) => {
119775
+ const name2 = Object.entries(assets).find(([, r2]) => r2.artifact === src)?.[0];
119776
+ if (!name2) return src;
119777
+ const child = assetPath(ws, name2, file2);
119778
+ if (!child) return src;
119779
+ dependencies.push(name2);
119780
+ const back = !found.text && /^\.(assets|mockups)\//.test(name2) ? name2 : path35.relative(path35.dirname(target), child).split(path35.sep).join("/");
119781
+ if (back !== src) changed = true;
119782
+ return back;
119783
+ });
119784
+ if (changed) local = Buffer.from(typeof restored === "string" ? restored : JSON.stringify(restored));
119785
+ }
119786
+ const json = data !== void 0 && typeof data !== "string";
119787
+ if (held4?.artifact === ref.artifact && held4.version === version && !held4.localHash && json) {
119509
119788
  const source = readText(target);
119510
119789
  if (source !== null) {
119511
119790
  let same = false;
@@ -119521,7 +119800,8 @@ async function pullAssets(ws, record, assets) {
119521
119800
  }
119522
119801
  }
119523
119802
  write(target, local);
119524
- out[name] = { ...held4, kind, dependencies: [...new Set(dependencies)], artifact: ref.artifact, version, hash: hashOf2(bytes2.value), localHash: hashOf2(local) };
119803
+ const hash = hashOf2(typeof data === "string" ? local : bytes2.value);
119804
+ out[name] = { ...held4, kind, dependencies: [...new Set(dependencies)], artifact: ref.artifact, version, hash, localHash: hashOf2(local) };
119525
119805
  }
119526
119806
  record.assets = out;
119527
119807
  return { ok: true, value: void 0 };
@@ -119540,6 +119820,14 @@ async function sentOf(file2) {
119540
119820
  const page = await (await Promise.resolve().then(() => (init_mockup(), mockup_exports))).drawMockup(file2);
119541
119821
  return { bytes: Buffer.from(page), type: "text/html", kind };
119542
119822
  }
119823
+ var undrawnPreviews = (ws) => Object.entries(assetsOf(readText(path35.join(ws.board, assetsFile(ws.task))))).flatMap(([key, ref]) => ref.error ? [`${key}: ${ref.error}`] : []);
119824
+ function undrawn(ws, reason) {
119825
+ const state = stateDir(ws);
119826
+ for (const [root2, shown] of [...state ? [[path35.join(state, "assets"), ".assets"], [path35.join(state, "mockups"), ".mockups"]] : [], [ws.board, ""]]) {
119827
+ reason = reason.split(`file://${root2}${path35.sep}`).join(shown && `${shown}/`).split(`${root2}${path35.sep}`).join(shown && `${shown}/`);
119828
+ }
119829
+ return reason.replace(/ \(at [^)]*file:\/\/[^)]*\)$/, "").slice(0, 500);
119830
+ }
119543
119831
  async function uploadAsset(artifact, { bytes: bytes2, type }) {
119544
119832
  const upload2 = await createUpload(artifact, type, Math.max(bytes2.length, 1));
119545
119833
  if (!upload2.ok) return upload2;
@@ -119559,7 +119847,7 @@ async function pushAssets(ws, record, before) {
119559
119847
  if (body === null) return { ok: true, value: void 0 };
119560
119848
  const refs = {};
119561
119849
  const canonical = (target) => {
119562
- const real = (file3) => fs31.existsSync(file3) ? fs31.realpathSync(file3) : file3;
119850
+ const real = (file3) => fs31.existsSync(file3) ? fs31.realpathSync(file3) : path35.dirname(file3) === file3 ? file3 : path35.join(real(path35.dirname(file3)), path35.basename(file3));
119563
119851
  target = real(target);
119564
119852
  const state = stateDir(ws);
119565
119853
  for (const folder of ["assets", "mockups"]) {
@@ -119578,23 +119866,49 @@ async function pushAssets(ws, record, before) {
119578
119866
  const key = owner === file2 && before[src] ? src : canonical(target);
119579
119867
  if (!fs31.statSync(target, { throwIfNoEntry: false })?.isFile()) {
119580
119868
  if (before[key]) return { key, file: null };
119581
- throw new Error("\u660E\u786E\u5F15\u7528\u7684\u8D44\u6E90\u6587\u4EF6\u4E0D\u5B58\u5728");
119869
+ throw new Error(`file not found: ${target}`);
119582
119870
  }
119583
119871
  return { key: canonical(fs31.realpathSync(target)), file: target };
119584
119872
  },
119585
- readJSON: (target) => JSON.parse(fs31.readFileSync(target, "utf8")),
119873
+ read: referenceText,
119586
119874
  retained: (key) => (record.assets[key]?.dependencies ?? []).map((src) => {
119587
119875
  const kind = record.assets[src]?.kind;
119588
- return { src, purpose: kind === "storyboard" || kind === "compare" ? kind : "asset" };
119876
+ return { src, types: kind ? [kind] : [] };
119589
119877
  })
119590
119878
  });
119591
- const errors = await validateScreens(graph.flatMap((node) => node.file && kindOf(path35.extname(node.file).toLowerCase()) === "html" ? [node.file] : []));
119592
- if (errors.length) return { ok: false, code: "bad_request", error: errors.map((e2) => `${e2.file}: ${e2.message}`).join("\n") };
119593
119879
  for (const node of graph) {
119594
119880
  const previous = [...node.aliases].map((key) => record.assets[key]).find(Boolean);
119595
119881
  const old = [...node.aliases].map((key) => before[key]).find(Boolean);
119596
- if (!node.file) {
119597
- if (old) {
119882
+ const kind = node.kind;
119883
+ let out;
119884
+ let why2 = node.error ?? [...node.dependencies.values()].map((key) => refs[key]?.error).find(Boolean);
119885
+ if (!why2 && node.file) {
119886
+ try {
119887
+ out = await sentOf(node.file);
119888
+ } catch (error) {
119889
+ why2 = renderError(error);
119890
+ }
119891
+ }
119892
+ if (why2) {
119893
+ let pin = old ? { artifact: old.artifact, ...old.version ? { version: old.version } : {} } : previous?.version ? { artifact: previous.artifact, version: previous.version } : null;
119894
+ if (!pin) {
119895
+ if (!ws.cloudTask) continue;
119896
+ let artifact = previous?.artifact;
119897
+ if (!artifact) {
119898
+ const made = await createArtifact(ws.cloudTask, node.key.slice(0, 200), kind);
119899
+ if (!made.ok) return { ...made, error: `${node.key}: ${made.error}` };
119900
+ artifact = made.value.id;
119901
+ for (const alias of node.aliases) record.assets[alias] = { artifact, kind, version: 0, hash: "" };
119902
+ writeRecord(ws, record);
119903
+ }
119904
+ pin = { artifact };
119905
+ }
119906
+ for (const alias of node.aliases) refs[alias] = { ...pin, error: undrawn(ws, why2) };
119907
+ continue;
119908
+ }
119909
+ if (!node.file || !out) {
119910
+ if (old?.error && !old.version) for (const alias of node.aliases) refs[alias] = old;
119911
+ else if (old) {
119598
119912
  let version = old.version ?? (previous?.artifact === old.artifact ? previous.version : void 0);
119599
119913
  if (version === void 0) {
119600
119914
  const art = await readArtifact(old.artifact);
@@ -119605,30 +119919,25 @@ async function pushAssets(ws, record, before) {
119605
119919
  }
119606
119920
  continue;
119607
119921
  }
119608
- const kind = node.kind === "asset" ? kindOf(path35.extname(node.file).toLowerCase()) : node.kind;
119609
119922
  if (previous && previous.kind !== kind) {
119610
119923
  const artifact = await readArtifact(previous.artifact);
119611
119924
  if (!artifact.ok) return artifact;
119612
119925
  if (!artifact.value.type) return { ok: false, code: "bad_request", error: `${node.key}: \u8D44\u6E90\u7C7B\u578B\u7F3A\u5931` };
119613
119926
  previous.kind = artifact.value.type;
119614
119927
  }
119615
- let out;
119616
- try {
119617
- out = await sentOf(node.file);
119618
- } catch (error) {
119619
- throw new Error(`${node.file}: ${renderError(error)}`);
119620
- }
119621
- if (node.kind !== "asset") {
119622
- const data = mapReferences(node.data, node.kind, (src) => {
119928
+ const manifest = manifestOf(kind);
119929
+ const json = !!manifest?.references && node.data !== void 0 && typeof node.data !== "string";
119930
+ if (manifest?.references && node.data !== void 0) {
119931
+ const map2 = (src) => {
119623
119932
  const key = node.dependencies.get(src);
119624
119933
  return key ? refs[key]?.artifact ?? src : src;
119625
- });
119626
- out = { kind: node.kind, type: "application/json", bytes: Buffer.from(JSON.stringify(data)) };
119934
+ };
119935
+ out = json ? { kind, type: "application/json", bytes: Buffer.from(JSON.stringify(mapReferences(manifest, node.data, map2))) } : { ...out, bytes: Buffer.from(mapReferences(manifest, Buffer.from(out.bytes).toString(), map2)) };
119627
119936
  }
119628
119937
  const hash = hashOf2(out.bytes);
119629
119938
  let entry = previous;
119630
119939
  const localHash = hashFile(node.file);
119631
- const restored = node.kind !== "asset" || out.kind === "html" && previous?.hash === localHash;
119940
+ const restored = json || out.kind === "html" && previous?.hash === localHash;
119632
119941
  const unchanged = restored && previous && (previous.kind ?? out.kind) === out.kind && localHash === (previous.localHash ?? previous.hash) && [...node.dependencies.values()].every((key) => refs[key]?.artifact === before[key]?.artifact);
119633
119942
  if (!entry || !unchanged && entry.hash !== hash || entry.kind && entry.kind !== out.kind) {
119634
119943
  if (!ws.cloudTask) continue;
@@ -119766,18 +120075,18 @@ async function send2(ws, job) {
119766
120075
  for (const p2 of local) {
119767
120076
  if (defer(p2) || owed(p2)) continue;
119768
120077
  const content = fs31.readFileSync(path35.join(ws.board, p2), "utf8");
119769
- const remote = remoteOf(ws, shared, p2);
119770
- localOf.set(remote, p2);
119771
- const held4 = base.files[remote];
120078
+ const remote2 = remoteOf(ws, shared, p2);
120079
+ localOf.set(remote2, p2);
120080
+ const held4 = base.files[remote2];
119772
120081
  if (held4?.content === content) continue;
119773
120082
  if (Buffer.byteLength(content) > BOARD_FILE_LIMIT) return fail(`${p2} is over ${BOARD_FILE_LIMIT / 1024} KB; keep large files as assets.`, false, "too_large");
119774
- changes.push({ path: remote, content, base_seq: held4?.seq ?? 0 });
120083
+ changes.push({ path: remote2, content, base_seq: held4?.seq ?? 0 });
119775
120084
  }
119776
120085
  for (const p2 of viewOf(ws, base, shared).keys()) {
119777
- const remote = remoteOf(ws, shared, p2);
119778
- if (!defer(p2) && kept3(p2) && !localOf.has(remote) && base.files[remote]) {
119779
- localOf.set(remote, p2);
119780
- changes.push({ path: remote, content: null, base_seq: base.files[remote].seq });
120086
+ const remote2 = remoteOf(ws, shared, p2);
120087
+ if (!defer(p2) && kept3(p2) && !localOf.has(remote2) && base.files[remote2]) {
120088
+ localOf.set(remote2, p2);
120089
+ changes.push({ path: remote2, content: null, base_seq: base.files[remote2].seq });
119781
120090
  }
119782
120091
  }
119783
120092
  const memory = rootOf(ws) + MEMORY2;
@@ -119840,8 +120149,8 @@ function watchBoards(machineId2, ms, lookMs = LOOK_MS, pullMs = PULL_MS, busyMs
119840
120149
  if (closed) return;
119841
120150
  if (busy(ws.cwd)) return void afterJob.add(ws.cwd);
119842
120151
  afterJob.delete(ws.cwd);
119843
- const read2 = await pullChanges(ws);
119844
- if (!read2.ok && read2.code) console.error(`runner: the board in ${ws.cwd} was not read: ${read2.error}`);
120152
+ const read3 = await pullChanges(ws);
120153
+ if (!read3.ok && read3.code) console.error(`runner: the board in ${ws.cwd} was not read: ${read3.error}`);
119845
120154
  };
119846
120155
  const send3 = async (ws) => {
119847
120156
  const sent = await pushBoard(ws, machineId2);
@@ -120278,7 +120587,7 @@ import { spawnSync as spawnSync5 } from "node:child_process";
120278
120587
  import fs37 from "node:fs";
120279
120588
  import path40 from "node:path";
120280
120589
  var MARKER_LINE = /^# ai4kanban commit guard\b/m;
120281
- var read = (file2) => {
120590
+ var read2 = (file2) => {
120282
120591
  try {
120283
120592
  return fs37.readFileSync(file2, "utf8");
120284
120593
  } catch {
@@ -120299,7 +120608,7 @@ function installCommitHook(root2, _board) {
120299
120608
  if (!dir) return {};
120300
120609
  const file2 = path40.join(dir, "pre-commit");
120301
120610
  if (fs37.lstatSync(file2, { throwIfNoEntry: false })?.isSymbolicLink()) return {};
120302
- const source = read(file2);
120611
+ const source = read2(file2);
120303
120612
  if (source && MARKER_LINE.test(source)) fs37.unlinkSync(file2);
120304
120613
  return {};
120305
120614
  }
@@ -120311,15 +120620,15 @@ var isBuilder = (ws) => ws.workflow === BUILDER;
120311
120620
  var draftDir = (ws) => path41.join(ws.board, "workflows", draftFolder(ws.task));
120312
120621
  var draftLine = (ws) => `<!-- workflow folder: ${path41.relative(ws.cwd, draftDir(ws)).split(path41.sep).join("/")}/ -->`;
120313
120622
  var skeleton = (name) => ["---", `name: ${/\s#/.test(name) ? JSON.stringify(name) : yamlScalar(name)}`, "needsArtifact: false", "---", ""].join("\n");
120314
- async function placeDraft(ws, read2) {
120623
+ async function placeDraft(ws, read3) {
120315
120624
  const dir = draftDir(ws);
120316
120625
  if (fs38.existsSync(path41.join(dir, WORKFLOW_FILE))) return { ok: true, value: void 0 };
120317
- const task = await read2.readTask(ws.task);
120626
+ const task = await read3.readTask(ws.task);
120318
120627
  if (!task.ok) return task;
120319
120628
  let files = { [WORKFLOW_FILE]: skeleton(task.value.title.trim() || "Untitled") };
120320
120629
  const changes = task.value.context?.workflow;
120321
120630
  if (changes) {
120322
- const held4 = await read2.readWorkflow(changes);
120631
+ const held4 = await read3.readWorkflow(changes);
120323
120632
  if (!held4.ok) return held4;
120324
120633
  files = held4.value.files;
120325
120634
  }
@@ -120343,9 +120652,9 @@ async function builtWorkflow(ws, akb) {
120343
120652
  } catch {
120344
120653
  return fail(`workflows/${id}/${WORKFLOW_FILE} is missing.`);
120345
120654
  }
120346
- const read2 = parseWorkflowFile(id, source, `workflows/${id}/${WORKFLOW_FILE}`);
120347
- if ("problem" in read2) return fail(read2.problem);
120348
- const names2 = named(read2.def);
120655
+ const read3 = parseWorkflowFile(id, source, `workflows/${id}/${WORKFLOW_FILE}`);
120656
+ if ("problem" in read3) return fail(read3.problem);
120657
+ const names2 = named(read3.def);
120349
120658
  fs38.rmSync(path41.join(dir, "agents"), { recursive: true, force: true });
120350
120659
  for (const name of names2) {
120351
120660
  const from = path41.join(ws.board, "agents", name);
@@ -120587,13 +120896,13 @@ async function runReview(job, ws, tasks, deps, io) {
120587
120896
  async function reviewRejections(job, ws, deps, io) {
120588
120897
  const workspace = workspaceOf(ws);
120589
120898
  if (!workspace) return { runs: [] };
120590
- const read2 = await deps.api.readRejections(workspace);
120591
- if (!read2.ok) return { runs: [], failure: read2.error };
120592
- if (!read2.value.tasks.length && !read2.value.triage.length) return { runs: [] };
120899
+ const read3 = await deps.api.readRejections(workspace);
120900
+ if (!read3.ok) return { runs: [], failure: read3.error };
120901
+ if (!read3.value.tasks.length && !read3.value.triage.length) return { runs: [] };
120593
120902
  const since = Date.now();
120594
120903
  const akb = boardAkb(job, ws, deps, io);
120595
120904
  return withBoard(ws, async (push2) => {
120596
- const laid = layOut(ws.board, read2.value);
120905
+ const laid = layOut(ws.board, read3.value);
120597
120906
  const ran = await akb(["review-dismissals", "--follow", "--events", "--json"], true);
120598
120907
  clearLaid(ws.board);
120599
120908
  resetSorted(ws);
@@ -120612,12 +120921,12 @@ async function learnRejections(job, ws, deps, io) {
120612
120921
  return runs;
120613
120922
  }
120614
120923
  async function scheduledEnv(ws, deps) {
120615
- const read2 = await deps.api.readAgents(deps.machineId, ws.project);
120616
- if (!read2.ok) {
120617
- console.error(`runner: scheduled agents not read: ${read2.error}`);
120924
+ const read3 = await deps.api.readAgents(deps.machineId, ws.project);
120925
+ if (!read3.ok) {
120926
+ console.error(`runner: scheduled agents not read: ${read3.error}`);
120618
120927
  return {};
120619
120928
  }
120620
- const names2 = read2.value.agents.filter((a2) => a2.workflow).map((a2) => a2.name);
120929
+ const names2 = read3.value.agents.filter((a2) => a2.workflow).map((a2) => a2.name);
120621
120930
  return { [SCHEDULED_AGENTS_ENV]: [...new Set(names2)].join(",") };
120622
120931
  }
120623
120932
  async function runAgent(job, ws, deps, io) {
@@ -122257,10 +122566,13 @@ function report(job, run2, turn2) {
122257
122566
  var cutShort = (said, text4) => ({ ...said, reply: said.reply || text4 || void 0, stopped: true });
122258
122567
  function folderLines(ws) {
122259
122568
  if (!ws) return "";
122569
+ const undrawn2 = undrawnPreviews(ws);
122260
122570
  return `
122261
122571
 
122262
122572
  Task card: ${cardFile(ws)}
122263
- Memory: ${ws.board}/memory`;
122573
+ Memory: ${ws.board}/memory` + (undrawn2.length ? `
122574
+ Previews that cannot be drawn:
122575
+ ${undrawn2.map((l2) => `- ${l2}`).join("\n")}` : "");
122264
122576
  }
122265
122577
 
122266
122578
  // src/presence.ts