wildcrane-runner 0.6.66 → 0.6.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.66 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.68 — 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;
@@ -7269,14 +7269,14 @@ var require_client_h1 = __commonJS({
7269
7269
  if (!parser) {
7270
7270
  return;
7271
7271
  }
7272
- const { socket, timeoutType, client, paused } = parser;
7272
+ const { socket, timeoutType, client, paused: paused2 } = parser;
7273
7273
  if (timeoutType === TIMEOUT_HEADERS) {
7274
7274
  if (!socket[kWriting] || socket.writableNeedDrain || client[kRunning] > 1) {
7275
- assert(!paused, "cannot be paused while waiting for headers");
7275
+ assert(!paused2, "cannot be paused while waiting for headers");
7276
7276
  util.destroy(socket, new HeadersTimeoutError());
7277
7277
  }
7278
7278
  } else if (timeoutType === TIMEOUT_BODY) {
7279
- if (!paused) {
7279
+ if (!paused2) {
7280
7280
  util.destroy(socket, new BodyTimeoutError());
7281
7281
  }
7282
7282
  } else if (timeoutType === TIMEOUT_KEEP_ALIVE) {
@@ -26683,16 +26683,16 @@ ${captureLines}` : capture.stack;
26683
26683
  });
26684
26684
 
26685
26685
  // ../cli/src/lib/dress-page.ts
26686
- import fs15 from "node:fs";
26687
- import path16 from "node:path";
26686
+ import fs16 from "node:fs";
26687
+ import path17 from "node:path";
26688
26688
  function dressPage(file2) {
26689
- const folder = path16.dirname(file2);
26690
- const html = fs15.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
26689
+ const folder = path17.dirname(file2);
26690
+ const html = fs16.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
26691
26691
  const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
26692
26692
  if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
26693
- const at3 = path16.resolve(folder, href);
26694
- if (!at3.startsWith(folder + path16.sep) || !fs15.existsSync(at3)) return tag;
26695
- const css = fs15.readFileSync(at3, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole, quote2, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole : `url(${quote2}${path16.relative(folder, path16.resolve(path16.dirname(at3), src)).split(path16.sep).join("/")}${quote2})`);
26693
+ const at3 = path17.resolve(folder, href);
26694
+ if (!at3.startsWith(folder + path17.sep) || !fs16.existsSync(at3)) return tag;
26695
+ const css = fs16.readFileSync(at3, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole, quote2, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole : `url(${quote2}${path17.relative(folder, path17.resolve(path17.dirname(at3), src)).split(path17.sep).join("/")}${quote2})`);
26696
26696
  return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
26697
26697
  });
26698
26698
  const at2 = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
@@ -26704,7 +26704,7 @@ var init_dress_page = __esm({
26704
26704
  "use strict";
26705
26705
  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'";
26706
26706
  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>`;
26707
- referenceText = (file2) => /\.html$/i.test(file2) ? dressPage(file2) : fs15.readFileSync(file2, "utf8");
26707
+ referenceText = (file2) => /\.html$/i.test(file2) ? dressPage(file2) : fs16.readFileSync(file2, "utf8");
26708
26708
  }
26709
26709
  });
26710
26710
 
@@ -27323,14 +27323,14 @@ var require_react_development = __commonJS({
27323
27323
  componentName = this.props.ref;
27324
27324
  return void 0 !== componentName ? componentName : null;
27325
27325
  }
27326
- function ReactElement(type, key, props, owner, debugStack, debugTask) {
27326
+ function ReactElement(type, key, props, owner2, debugStack, debugTask) {
27327
27327
  var refProp = props.ref;
27328
27328
  type = {
27329
27329
  $$typeof: REACT_ELEMENT_TYPE,
27330
27330
  type,
27331
27331
  key,
27332
27332
  props,
27333
- _owner: owner
27333
+ _owner: owner2
27334
27334
  };
27335
27335
  null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", {
27336
27336
  enumerable: false,
@@ -27901,7 +27901,7 @@ var require_react_development = __commonJS({
27901
27901
  throw Error(
27902
27902
  "The argument must be a React element, but you passed " + element + "."
27903
27903
  );
27904
- var props = assign({}, element.props), key = element.key, owner = element._owner;
27904
+ var props = assign({}, element.props), key = element.key, owner2 = element._owner;
27905
27905
  if (null != config) {
27906
27906
  var JSCompiler_inline_result;
27907
27907
  a: {
@@ -27914,7 +27914,7 @@ var require_react_development = __commonJS({
27914
27914
  }
27915
27915
  JSCompiler_inline_result = void 0 !== config.ref;
27916
27916
  }
27917
- JSCompiler_inline_result && (owner = getOwner());
27917
+ JSCompiler_inline_result && (owner2 = getOwner());
27918
27918
  hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key);
27919
27919
  for (propName in config)
27920
27920
  !hasOwnProperty.call(config, propName) || "key" === propName || "__self" === propName || "__source" === propName || "ref" === propName && void 0 === config.ref || (props[propName] = config[propName]);
@@ -27931,7 +27931,7 @@ var require_react_development = __commonJS({
27931
27931
  element.type,
27932
27932
  key,
27933
27933
  props,
27934
- owner,
27934
+ owner2,
27935
27935
  element._debugStack,
27936
27936
  element._debugTask
27937
27937
  );
@@ -28320,14 +28320,14 @@ var require_react_jsx_runtime_development = __commonJS({
28320
28320
  componentName = this.props.ref;
28321
28321
  return void 0 !== componentName ? componentName : null;
28322
28322
  }
28323
- function ReactElement(type, key, props, owner, debugStack, debugTask) {
28323
+ function ReactElement(type, key, props, owner2, debugStack, debugTask) {
28324
28324
  var refProp = props.ref;
28325
28325
  type = {
28326
28326
  $$typeof: REACT_ELEMENT_TYPE,
28327
28327
  type,
28328
28328
  key,
28329
28329
  props,
28330
- _owner: owner
28330
+ _owner: owner2
28331
28331
  };
28332
28332
  null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", {
28333
28333
  enumerable: false,
@@ -44085,13 +44085,13 @@ var require_react_dom_server_legacy_node_development = __commonJS({
44085
44085
  if ("object" === typeof node && null !== node)
44086
44086
  switch (node.$$typeof) {
44087
44087
  case REACT_ELEMENT_TYPE:
44088
- var type = node.type, owner = node._owner, stack = node._debugStack;
44088
+ var type = node.type, owner2 = node._owner, stack = node._debugStack;
44089
44089
  pushServerComponentStack(task, node._debugInfo);
44090
44090
  task.debugTask = node._debugTask;
44091
44091
  task.componentStack = {
44092
44092
  parent: task.componentStack,
44093
44093
  type,
44094
- owner,
44094
+ owner: owner2,
44095
44095
  stack
44096
44096
  };
44097
44097
  break;
@@ -51797,13 +51797,13 @@ var require_react_dom_server_node_development = __commonJS({
51797
51797
  if ("object" === typeof node && null !== node)
51798
51798
  switch (node.$$typeof) {
51799
51799
  case REACT_ELEMENT_TYPE:
51800
- var type = node.type, owner = node._owner, stack = node._debugStack;
51800
+ var type = node.type, owner2 = node._owner, stack = node._debugStack;
51801
51801
  pushServerComponentStack(task, node._debugInfo);
51802
51802
  task.debugTask = node._debugTask;
51803
51803
  task.componentStack = {
51804
51804
  parent: task.componentStack,
51805
51805
  type,
51806
- owner,
51806
+ owner: owner2,
51807
51807
  stack
51808
51808
  };
51809
51809
  break;
@@ -68725,8 +68725,8 @@ var require_CJSImportProcessor = __commonJS({
68725
68725
  */
68726
68726
  preprocessNamedExportAtIndex(index) {
68727
68727
  index += 2;
68728
- const { newIndex, namedImports } = this.getNamedImports(index);
68729
- index = newIndex;
68728
+ const { newIndex: newIndex2, namedImports } = this.getNamedImports(index);
68729
+ index = newIndex2;
68730
68730
  if (this.tokens.matchesContextualAtIndex(index, _keywords.ContextualKeyword._from)) {
68731
68731
  index++;
68732
68732
  } else {
@@ -110866,8 +110866,8 @@ var init_dist = __esm({
110866
110866
  });
110867
110867
 
110868
110868
  // ../cli/src/lib/draw-mockup.ts
110869
- import fs18 from "node:fs";
110870
- import path19 from "node:path";
110869
+ import fs19 from "node:fs";
110870
+ import path20 from "node:path";
110871
110871
  import vm from "node:vm";
110872
110872
  async function loadPackage(id) {
110873
110873
  if (id === "react") return import_react3.default;
@@ -110880,22 +110880,22 @@ async function loadPackage(id) {
110880
110880
  return { __esModule: true, ...await load() };
110881
110881
  }
110882
110882
  function resolveFile(id, from, folder) {
110883
- const at2 = path19.resolve(path19.dirname(from), id);
110884
- if (at2 !== folder && !at2.startsWith(folder + path19.sep)) throw new Error(`${id} is outside the mockup's folder`);
110885
- const tries = path19.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path19.join(at2, `index${e2}`))];
110886
- const file2 = tries.find((f2) => fs18.statSync(f2, { throwIfNoEntry: false })?.isFile());
110883
+ const at2 = path20.resolve(path20.dirname(from), id);
110884
+ if (at2 !== folder && !at2.startsWith(folder + path20.sep)) throw new Error(`${id} is outside the mockup's folder`);
110885
+ const tries = path20.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path20.join(at2, `index${e2}`))];
110886
+ const file2 = tries.find((f2) => fs19.statSync(f2, { throwIfNoEntry: false })?.isFile());
110887
110887
  if (!file2) throw new Error(`no such file: ${id}`);
110888
110888
  return file2;
110889
110889
  }
110890
110890
  async function readGraph(entry) {
110891
- const folder = path19.dirname(entry);
110891
+ const folder = path20.dirname(entry);
110892
110892
  const graph = { code: /* @__PURE__ */ new Map(), links: /* @__PURE__ */ new Map(), sheets: [], packages: /* @__PURE__ */ new Map() };
110893
110893
  const walk = async (file2) => {
110894
110894
  if (graph.code.has(file2)) return;
110895
110895
  if (graph.code.size >= MAX_FILES) throw new Error(`a mockup imports more than ${MAX_FILES} files`);
110896
110896
  let location = file2;
110897
110897
  try {
110898
- const js = (0, import_sucrase.transform)(fs18.readFileSync(file2, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file2 }).code;
110898
+ const js = (0, import_sucrase.transform)(fs19.readFileSync(file2, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file2 }).code;
110899
110899
  graph.code.set(file2, js);
110900
110900
  const link = /* @__PURE__ */ new Map();
110901
110901
  graph.links.set(file2, link);
@@ -110909,7 +110909,7 @@ async function readGraph(entry) {
110909
110909
  const target = resolveFile(id, file2, folder);
110910
110910
  link.set(id, target);
110911
110911
  if (!target.endsWith(".css")) await walk(target);
110912
- else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs18.readFileSync(target, "utf8") });
110912
+ else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs19.readFileSync(target, "utf8") });
110913
110913
  }
110914
110914
  } catch (error) {
110915
110915
  throw new Error(`${location}: ${error instanceof Error ? error.message : String(error)}`);
@@ -110926,12 +110926,12 @@ function run(script, context, name, deadline, lineOffset = 0) {
110926
110926
  async function tailwindFor(markup, sheets) {
110927
110927
  const source = sheets.length ? sheets.map((s) => s.content).join("\n") : '@import "tailwindcss";';
110928
110928
  const compiler = await rc(source, {
110929
- base: sheets.length ? path19.dirname(sheets[0].path) : "/",
110929
+ base: sheets.length ? path20.dirname(sheets[0].path) : "/",
110930
110930
  loadStylesheet: async (id, from) => {
110931
110931
  if (id === "tailwindcss" || id.startsWith("tailwindcss/")) return { path: "tailwindcss/index.css", base: "/", content: tailwindcss_default };
110932
110932
  if (!id.startsWith(".")) throw new Error(`a mockup cannot import ${id}`);
110933
- const at2 = path19.resolve(from, id);
110934
- return { path: at2, base: path19.dirname(at2), content: fs18.readFileSync(at2, "utf8") };
110933
+ const at2 = path20.resolve(from, id);
110934
+ return { path: at2, base: path20.dirname(at2), content: fs19.readFileSync(at2, "utf8") };
110935
110935
  }
110936
110936
  });
110937
110937
  const classes = [...markup.matchAll(/class="([^"]*)"/g)].flatMap((m) => m[1].split(/\s+/));
@@ -110983,7 +110983,7 @@ ${graph.code.get(file2)}
110983
110983
  const css = (await tailwindFor(markup, graph.sheets)).replace(/<\/style/gi, "<\\/style");
110984
110984
  return `<!doctype html><html><head>${head}<style>${css}</style></head><body>${markup}</body></html>`;
110985
110985
  }
110986
- var import_react3, JSX, import_server, import_sucrase, DRAW_MS, MAX_FILES, CODE_EXTS, REQUIRES, NOTHING, NEXT_LINK, NEXT_IMAGE, NEXT_NAVIGATION, PACKAGES;
110986
+ var import_react3, JSX, import_server, import_sucrase, DRAW_MS, MAX_FILES, CODE_EXTS, REQUIRES, NOTHING, NEXT_LINK, NEXT_IMAGE, NEXT_NAVIGATION, PACKAGES, MOCKUP_IMPORTS;
110987
110987
  var init_draw_mockup = __esm({
110988
110988
  "../cli/src/lib/draw-mockup.ts"() {
110989
110989
  "use strict";
@@ -111036,6 +111036,7 @@ var init_draw_mockup = __esm({
111036
111036
  "tailwind-merge": () => Promise.resolve().then(() => (init_bundle_mjs(), bundle_mjs_exports)),
111037
111037
  "class-variance-authority": () => Promise.resolve().then(() => (init_dist(), dist_exports))
111038
111038
  };
111039
+ MOCKUP_IMPORTS = /* @__PURE__ */ new Set(["react", "react/jsx-runtime", "react/jsx-dev-runtime", "next/link", "next/image", "next/navigation", ...Object.keys(PACKAGES)]);
111039
111040
  }
111040
111041
  });
111041
111042
 
@@ -111713,8 +111714,8 @@ function tryLock(dir) {
111713
111714
  }
111714
111715
  if (entries.length) {
111715
111716
  if (entries.length !== 1 || !/^\d+-[a-f0-9-]{36}$/.test(entries[0])) return void 0;
111716
- const owner = Number(entries[0].split("-")[0]);
111717
- if (pidAlive(owner)) return void 0;
111717
+ const owner2 = Number(entries[0].split("-")[0]);
111718
+ if (pidAlive(owner2)) return void 0;
111718
111719
  }
111719
111720
  if (!removeClaim(dir, entries[0])) return void 0;
111720
111721
  }
@@ -111788,57 +111789,118 @@ __export(api_exports, {
111788
111789
  });
111789
111790
 
111790
111791
  // src/goals.ts
111792
+ import fs7 from "node:fs";
111793
+ import path8 from "node:path";
111794
+
111795
+ // src/settings-control.ts
111791
111796
  import fs6 from "node:fs";
111792
111797
  import path7 from "node:path";
111798
+ var directory = () => path7.join(runnerHome(), "executors");
111799
+ var epochFile = () => path7.join(runnerHome(), "account-generation");
111800
+ function accountGeneration() {
111801
+ try {
111802
+ return fs6.readFileSync(epochFile(), "utf8");
111803
+ } catch {
111804
+ return "";
111805
+ }
111806
+ }
111807
+ function executorRecord() {
111808
+ fs6.mkdirSync(directory(), { recursive: true, mode: 448 });
111809
+ const file2 = path7.join(directory(), `${process.pid}.json`);
111810
+ fs6.writeFileSync(file2, "{}", { mode: 384 });
111811
+ return () => fs6.rmSync(file2, { force: true });
111812
+ }
111813
+
111814
+ // src/goals.ts
111793
111815
  function goalsOf(held5) {
111794
111816
  if (held5.goals !== void 0 && held5.ideas !== void 0 && JSON.stringify(held5.goals) !== JSON.stringify(held5.ideas)) throw new Error("goals and ideas do not match.");
111795
111817
  const goals = held5.goals ?? held5.ideas;
111796
111818
  if (!Array.isArray(goals)) throw new Error("The goals array is missing or invalid.");
111797
111819
  return goals;
111798
111820
  }
111799
- var goalsFileOf = (job) => path7.join(runnerHome(), "ideas", `${job.id}.json`);
111800
- async function writeGoals(job, list2) {
111821
+ var goalsFileOf = (job) => path8.join(runnerHome(), "ideas", `${job.id}.json`);
111822
+ async function writeGoals(job, list2, preserveGoals = false) {
111801
111823
  let goals;
111802
111824
  try {
111803
- goals = goalsOf(job.discussion);
111825
+ goals = preserveGoals && fs7.existsSync(goalsFileOf(job)) ? goalsOf(JSON.parse(fs7.readFileSync(goalsFileOf(job), "utf8"))) : goalsOf(job.discussion);
111804
111826
  } catch (e2) {
111805
111827
  return { error: String(e2) };
111806
111828
  }
111807
- const studios = [];
111808
- let after = null;
111809
- do {
111810
- const page = await list2(job.discussion.workspace, after);
111811
- if (!page.ok) return { error: page.error };
111812
- for (const w2 of page.value.data) studios.push({ ...w2, id: w2.id, name: w2.names ? `${w2.names.en} / ${w2.names.zh}` : w2.name, ...w2.description ? { description: w2.description } : {} });
111813
- after = page.value.next;
111814
- } while (after);
111829
+ let studios;
111830
+ try {
111831
+ studios = await studioSnapshot(job.discussion.workspace, job.discussion.catalog, list2);
111832
+ } catch (e2) {
111833
+ return { error: e2 instanceof Error ? e2.message : String(e2) };
111834
+ }
111815
111835
  const file2 = goalsFileOf(job);
111816
- fs6.mkdirSync(path7.dirname(file2), { recursive: true });
111817
- fs6.writeFileSync(file2, `${JSON.stringify({ workspace: job.discussion.workspace, studios, ideas: goals }, null, 2)}
111836
+ fs7.mkdirSync(path8.dirname(file2), { recursive: true });
111837
+ fs7.writeFileSync(file2, `${JSON.stringify({ workspace: job.discussion.workspace, studios, ideas: goals }, null, 2)}
111818
111838
  `);
111819
111839
  return { file: file2 };
111820
111840
  }
111821
111841
  function readGoals(file2) {
111822
111842
  try {
111823
- return goalsOf(JSON.parse(fs6.readFileSync(file2, "utf8")));
111843
+ return goalsOf(JSON.parse(fs7.readFileSync(file2, "utf8")));
111824
111844
  } catch {
111825
111845
  return void 0;
111826
111846
  } finally {
111827
- fs6.rmSync(file2, { force: true });
111847
+ fs7.rmSync(file2, { force: true });
111848
+ }
111849
+ }
111850
+ var owner = "";
111851
+ var snapshots = /* @__PURE__ */ new Map();
111852
+ function clearStudioSnapshots() {
111853
+ owner = "";
111854
+ snapshots.clear();
111855
+ }
111856
+ async function studioSnapshot(workspace, catalog, list2) {
111857
+ const account = `${readSession()?.subject ?? ""}:${accountGeneration()}`;
111858
+ if (owner !== account) {
111859
+ clearStudioSnapshots();
111860
+ owner = account;
111861
+ }
111862
+ const reusable = catalog?.account === readSession()?.subject && !!catalog?.version;
111863
+ const key = reusable ? JSON.stringify([account, workspace, catalog.version]) : null;
111864
+ if (key && snapshots.has(key)) return snapshots.get(key);
111865
+ const load = async () => {
111866
+ const studios = [];
111867
+ let after = null;
111868
+ const seen = /* @__PURE__ */ new Set();
111869
+ do {
111870
+ const page = await list2(workspace, after);
111871
+ if (!page.ok) throw new Error(page.error);
111872
+ if (account !== `${readSession()?.subject ?? ""}:${accountGeneration()}`) throw new Error("Account changed while reading studios.");
111873
+ if (catalog?.version && page.value.catalogVersion && page.value.catalogVersion !== catalog.version) throw new Error("Studios changed while reading the catalog. Try again.");
111874
+ if (key && !page.value.catalogVersion) snapshots.delete(key);
111875
+ for (const w2 of page.value.data) studios.push({ ...w2, name: w2.names ? `${w2.names.en} / ${w2.names.zh}` : w2.name });
111876
+ after = page.value.next;
111877
+ if (after && seen.has(after)) throw new Error("The studio catalog did not finish.");
111878
+ if (after) seen.add(after);
111879
+ } while (after);
111880
+ return studios;
111881
+ };
111882
+ const loading = load();
111883
+ if (key) {
111884
+ if (snapshots.size >= 16) snapshots.delete(snapshots.keys().next().value);
111885
+ snapshots.set(key, loading);
111886
+ void loading.catch(() => {
111887
+ if (snapshots.get(key) === loading) snapshots.delete(key);
111888
+ });
111828
111889
  }
111890
+ return loading;
111829
111891
  }
111830
111892
 
111831
111893
  // src/protocol.ts
111832
- var AKB_VERSION = true ? "0.11.52" : "0.0.0";
111894
+ var AKB_VERSION = true ? "0.11.54" : "0.0.0";
111833
111895
  var AKB_CONTRACT = true ? 15 : 0;
111834
111896
 
111835
111897
  // src/secrets.ts
111836
- import fs7 from "node:fs";
111837
- import path8 from "node:path";
111838
- var file = () => path8.join(runnerHome(), "secrets.json");
111898
+ import fs8 from "node:fs";
111899
+ import path9 from "node:path";
111900
+ var file = () => path9.join(runnerHome(), "secrets.json");
111839
111901
  function readAll() {
111840
111902
  try {
111841
- const held5 = JSON.parse(fs7.readFileSync(file(), "utf8"));
111903
+ const held5 = JSON.parse(fs8.readFileSync(file(), "utf8"));
111842
111904
  return held5 && typeof held5 === "object" ? held5 : {};
111843
111905
  } catch {
111844
111906
  return {};
@@ -111854,11 +111916,11 @@ function keepSecrets(runtime, given) {
111854
111916
  }
111855
111917
  if (Object.keys(held5).length) all[runtime] = held5;
111856
111918
  else delete all[runtime];
111857
- fs7.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
111919
+ fs8.mkdirSync(runnerHome(), { recursive: true, mode: 448 });
111858
111920
  const temp = `${file()}.${process.pid}.tmp`;
111859
- fs7.writeFileSync(temp, `${JSON.stringify(all)}
111921
+ fs8.writeFileSync(temp, `${JSON.stringify(all)}
111860
111922
  `, { mode: 384 });
111861
- fs7.renameSync(temp, file());
111923
+ fs8.renameSync(temp, file());
111862
111924
  }
111863
111925
  var secretsSet = () => Object.fromEntries(Object.entries(readAll()).map(([id, keys]) => [id, Object.keys(keys)]));
111864
111926
 
@@ -112021,12 +112083,12 @@ var previewOperation = (machineId, job, agent, fields) => request("POST", `/v1/r
112021
112083
 
112022
112084
  // src/cache.ts
112023
112085
  import crypto2 from "node:crypto";
112024
- import fs14 from "node:fs";
112025
- import path15 from "node:path";
112086
+ import fs15 from "node:fs";
112087
+ import path16 from "node:path";
112026
112088
 
112027
112089
  // ../cli/src/lib/agent/cloud-studios.ts
112028
- import fs12 from "node:fs";
112029
- import path13 from "node:path";
112090
+ import fs13 from "node:fs";
112091
+ import path14 from "node:path";
112030
112092
 
112031
112093
  // ../cli/src/lib/shared/file-limits.ts
112032
112094
  var BOARD_FILE_LIMIT = 10 * 1024 * 1024;
@@ -112079,8 +112141,8 @@ function cardFront(body) {
112079
112141
 
112080
112142
  // ../official/pack.ts
112081
112143
  import crypto from "node:crypto";
112082
- import fs9 from "node:fs";
112083
- import path10 from "node:path";
112144
+ import fs10 from "node:fs";
112145
+ import path11 from "node:path";
112084
112146
  import { fileURLToPath } from "node:url";
112085
112147
 
112086
112148
  // ../cli/src/lib/agents/icon.ts
@@ -112521,8 +112583,8 @@ function parseStudioFile(id, source, from) {
112521
112583
  }
112522
112584
 
112523
112585
  // ../cli/src/lib/agent/studio-folder.ts
112524
- import fs8 from "node:fs";
112525
- import path9 from "node:path";
112586
+ import fs9 from "node:fs";
112587
+ import path10 from "node:path";
112526
112588
 
112527
112589
  // ../cli/src/lib/shared/studio-files.ts
112528
112590
  var STUDIO_FILE = "STUDIO.md";
@@ -112657,34 +112719,34 @@ function inspect(value, official) {
112657
112719
  // ../cli/src/lib/agent/studio-folder.ts
112658
112720
  var MIME = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp" };
112659
112721
  function filesOf(dir, base = dir) {
112660
- return fs8.readdirSync(dir, { withFileTypes: true }).filter((e2) => !e2.name.startsWith(".")).flatMap((e2) => {
112661
- const full = path9.join(dir, e2.name);
112662
- return e2.isDirectory() ? filesOf(full, base) : [path9.relative(base, full).split(path9.sep).join("/")];
112722
+ return fs9.readdirSync(dir, { withFileTypes: true }).filter((e2) => !e2.name.startsWith(".")).flatMap((e2) => {
112723
+ const full = path10.join(dir, e2.name);
112724
+ return e2.isDirectory() ? filesOf(full, base) : [path10.relative(base, full).split(path10.sep).join("/")];
112663
112725
  });
112664
112726
  }
112665
112727
  function readStudioFile(dir, file2) {
112666
- const full = path9.join(dir, file2);
112667
- return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path9.extname(file2)]};base64,${fs8.readFileSync(full).toString("base64")}` : fs8.readFileSync(full, "utf8");
112728
+ const full = path10.join(dir, file2);
112729
+ return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path10.extname(file2)]};base64,${fs9.readFileSync(full).toString("base64")}` : fs9.readFileSync(full, "utf8");
112668
112730
  }
112669
112731
  var readStudioFolder = (dir) => Object.fromEntries(filesOf(dir).sort().map((f2) => [f2, readStudioFile(dir, f2)]));
112670
112732
 
112671
112733
  // ../official/pack.ts
112672
- var OFFICIAL = path10.dirname(fileURLToPath(import.meta.url));
112673
- var dirs = (dir) => fs9.readdirSync(dir, { withFileTypes: true }).filter((e2) => e2.isDirectory()).map((e2) => e2.name).sort();
112734
+ var OFFICIAL = path11.dirname(fileURLToPath(import.meta.url));
112735
+ var dirs = (dir) => fs10.readdirSync(dir, { withFileTypes: true }).filter((e2) => e2.isDirectory()).map((e2) => e2.name).sort();
112674
112736
  var hashOf = (files) => crypto.createHash("sha256").update(hashInput(files)).digest("hex");
112675
112737
  function packOfficial(root2 = OFFICIAL, loose = false) {
112676
- const agentsDir = path10.join(root2, "agents");
112738
+ const agentsDir = path11.join(root2, "agents");
112677
112739
  const agentFiles = Object.fromEntries(dirs(agentsDir).map((name) => {
112678
- const dir = path10.join(agentsDir, name);
112740
+ const dir = path11.join(agentsDir, name);
112679
112741
  return [name, readStudioFolder(dir)];
112680
112742
  }));
112681
112743
  for (const [name, own] of Object.entries(loose ? {} : agentFiles)) {
112682
112744
  const read4 = parseSpecAgent(own["AGENT.md"] ?? "", `official/agents/${name}/AGENT.md`, (p2) => own[p2] ?? null, true);
112683
112745
  if ("problem" in read4) throw new Error(read4.problem);
112684
112746
  }
112685
- const studiosDir = path10.join(root2, "studios");
112747
+ const studiosDir = path11.join(root2, "studios");
112686
112748
  return dirs(studiosDir).map((folder) => {
112687
- const dir = path10.join(studiosDir, folder);
112749
+ const dir = path11.join(studiosDir, folder);
112688
112750
  const files = {};
112689
112751
  for (const f2 of filesOf(dir).sort()) {
112690
112752
  if (f2 === STUDIO_FILE || f2 === CARD_TEMPLATE_FILE || f2 === MCP_FILE || f2.startsWith("skills/") || f2.startsWith(SHARED_DIR) || isAboutFile(f2)) files[f2] = readStudioFile(dir, f2);
@@ -112716,23 +112778,23 @@ function packOfficial(root2 = OFFICIAL, loose = false) {
112716
112778
  }
112717
112779
 
112718
112780
  // ../cli/src/lib/cloud/tasks.ts
112719
- import fs10 from "node:fs";
112720
- import path11 from "node:path";
112781
+ import fs11 from "node:fs";
112782
+ import path12 from "node:path";
112721
112783
  var TASK_ENV = "AI4KANBAN_TASK";
112722
112784
  function workspaceTask() {
112723
112785
  const id = process.env[TASK_ENV];
112724
112786
  return id && id.trim() ? id.trim() : null;
112725
112787
  }
112726
112788
  function runnerProject(board) {
112727
- if (path11.basename(board) !== "kanban" || path11.basename(path11.dirname(board)) !== ".akb") return null;
112728
- const linked = linkedProject(board, path11.dirname(path11.dirname(board)));
112789
+ if (path12.basename(board) !== "kanban" || path12.basename(path12.dirname(board)) !== ".akb") return null;
112790
+ const linked = linkedProject(board, path12.dirname(path12.dirname(board)));
112729
112791
  return linked.ok ? linked.value : null;
112730
112792
  }
112731
112793
  function linkedProject(board, root2) {
112732
- const file2 = path11.join(root2, ".akb", "base.json");
112733
- if (!fs10.existsSync(file2)) return { ok: true, value: null };
112794
+ const file2 = path12.join(root2, ".akb", "base.json");
112795
+ if (!fs11.existsSync(file2)) return { ok: true, value: null };
112734
112796
  try {
112735
- const base = JSON.parse(fs10.readFileSync(file2, "utf8"));
112797
+ const base = JSON.parse(fs11.readFileSync(file2, "utf8"));
112736
112798
  if (!base || typeof base !== "object" || base.project !== void 0 && (typeof base.project !== "string" || !base.project.trim()) || base.files !== void 0 && (!base.files || typeof base.files !== "object" || Array.isArray(base.files))) throw new Error();
112737
112799
  const projects = new Set(Object.keys(base.files ?? {}).flatMap((p2) => /^projects\/([^/]+)\//.exec(p2)?.[1] ?? []));
112738
112800
  if (typeof base.project === "string") projects.add(base.project);
@@ -112744,14 +112806,14 @@ function linkedProject(board, root2) {
112744
112806
  }
112745
112807
 
112746
112808
  // ../cli/src/lib/file-memo.ts
112747
- import fs11 from "node:fs";
112748
- import path12 from "node:path";
112809
+ import fs12 from "node:fs";
112810
+ import path13 from "node:path";
112749
112811
  function stamp(paths) {
112750
112812
  const parts = [];
112751
112813
  const visit = (p2) => {
112752
112814
  let st2;
112753
112815
  try {
112754
- st2 = fs11.statSync(p2, { bigint: true });
112816
+ st2 = fs12.statSync(p2, { bigint: true });
112755
112817
  } catch {
112756
112818
  parts.push(`${p2}:-`);
112757
112819
  return;
@@ -112763,11 +112825,11 @@ function stamp(paths) {
112763
112825
  parts.push(`${p2}/`);
112764
112826
  let names2;
112765
112827
  try {
112766
- names2 = fs11.readdirSync(p2).sort();
112828
+ names2 = fs12.readdirSync(p2).sort();
112767
112829
  } catch {
112768
112830
  return;
112769
112831
  }
112770
- for (const name of names2) if (name !== "node_modules" && name !== ".git") visit(path12.join(p2, name));
112832
+ for (const name of names2) if (name !== "node_modules" && name !== ".git") visit(path13.join(p2, name));
112771
112833
  };
112772
112834
  for (const p2 of paths) visit(p2);
112773
112835
  return parts.join("\n");
@@ -112810,29 +112872,29 @@ function memoByFiles(paths, read4) {
112810
112872
 
112811
112873
  // ../cli/src/lib/agent/cloud-studios.ts
112812
112874
  var DEV = "AI4KANBAN_STUDIOS";
112813
- var root = () => path13.join(machineHome(), "studios");
112875
+ var root = () => path14.join(machineHome(), "studios");
112814
112876
  var safe = (name) => name.replace(/[^\w.@-]/g, "_");
112815
- var versionFile = (id, version) => path13.join(root(), "versions", `${safe(id)}@${version}.json`);
112816
- var listFile = (project) => path13.join(root(), "lists", `${safe(project)}.json`);
112817
- var pinFile = (task) => path13.join(root(), "tasks", `${safe(task)}.json`);
112877
+ var versionFile = (id, version) => path14.join(root(), "versions", `${safe(id)}@${version}.json`);
112878
+ var listFile = (project) => path14.join(root(), "lists", `${safe(project)}.json`);
112879
+ var pinFile = (task) => path14.join(root(), "tasks", `${safe(task)}.json`);
112818
112880
  function readJson(file2) {
112819
112881
  try {
112820
- return JSON.parse(fs12.readFileSync(file2, "utf8"));
112882
+ return JSON.parse(fs13.readFileSync(file2, "utf8"));
112821
112883
  } catch {
112822
112884
  return null;
112823
112885
  }
112824
112886
  }
112825
112887
  function writeJson(file2, value) {
112826
- fs12.mkdirSync(path13.dirname(file2), { recursive: true });
112888
+ fs13.mkdirSync(path14.dirname(file2), { recursive: true });
112827
112889
  const tmp = `${file2}.${process.pid}.tmp`;
112828
- fs12.writeFileSync(tmp, `${JSON.stringify(value)}
112890
+ fs13.writeFileSync(tmp, `${JSON.stringify(value)}
112829
112891
  `);
112830
- fs12.renameSync(tmp, file2);
112892
+ fs13.renameSync(tmp, file2);
112831
112893
  }
112832
112894
  var readVersion2 = (id, version) => readJson(versionFile(id, version));
112833
112895
  function saveVersion(held5) {
112834
112896
  const file2 = versionFile(held5.id, held5.version);
112835
- if (!fs12.existsSync(file2)) writeJson(file2, { id: held5.id, version: held5.version, name: held5.name, names: held5.names, files: held5.files });
112897
+ if (!fs13.existsSync(file2)) writeJson(file2, { id: held5.id, version: held5.version, name: held5.name, names: held5.names, files: held5.files });
112836
112898
  }
112837
112899
  function savePin(task, held5) {
112838
112900
  saveVersion(held5);
@@ -112877,14 +112939,14 @@ var cloudFlows = () => flows();
112877
112939
  function cloudAgentFiles() {
112878
112940
  const files = {};
112879
112941
  const official = /* @__PURE__ */ new Set();
112880
- const owner = /* @__PURE__ */ new Map();
112942
+ const owner2 = /* @__PURE__ */ new Map();
112881
112943
  for (const flow of cloudFlows()) {
112882
112944
  for (const [name, text3] of Object.entries(flow.files)) {
112883
112945
  const at2 = /^agents\/([^/]+)\/(.+)$/.exec(name);
112884
112946
  if (!at2) continue;
112885
112947
  const [, agent, rest] = at2;
112886
- if (owner.has(agent) && owner.get(agent) !== flow.cloudId) continue;
112887
- owner.set(agent, flow.cloudId);
112948
+ if (owner2.has(agent) && owner2.get(agent) !== flow.cloudId) continue;
112949
+ owner2.set(agent, flow.cloudId);
112888
112950
  if (flow.builtIn) official.add(agent);
112889
112951
  files[`${agent}/${rest}`] = text3;
112890
112952
  }
@@ -112893,19 +112955,19 @@ function cloudAgentFiles() {
112893
112955
  }
112894
112956
 
112895
112957
  // src/folders.ts
112896
- import fs13 from "node:fs";
112897
- import path14 from "node:path";
112898
- var projectsFile = () => path14.join(runnerHome(), "projects.json");
112958
+ import fs14 from "node:fs";
112959
+ import path15 from "node:path";
112960
+ var projectsFile = () => path15.join(runnerHome(), "projects.json");
112899
112961
  function realpath(p2) {
112900
112962
  try {
112901
- return fs13.realpathSync(p2);
112963
+ return fs14.realpathSync(p2);
112902
112964
  } catch {
112903
112965
  return null;
112904
112966
  }
112905
112967
  }
112906
112968
  function readGrants() {
112907
112969
  try {
112908
- const held5 = JSON.parse(fs13.readFileSync(projectsFile(), "utf8"));
112970
+ const held5 = JSON.parse(fs14.readFileSync(projectsFile(), "utf8"));
112909
112971
  if (!Array.isArray(held5.projects)) throw new Error("invalid_projects");
112910
112972
  return held5;
112911
112973
  } catch (error) {
@@ -112921,32 +112983,33 @@ function listOf(held5) {
112921
112983
  function allowedProjects() {
112922
112984
  return listOf(readGrants()).flatMap((p2) => {
112923
112985
  const real = realpath(p2);
112924
- return real && fs13.statSync(real).isDirectory() ? [real] : [];
112986
+ return real && fs14.statSync(real).isDirectory() ? [real] : [];
112925
112987
  });
112926
112988
  }
112927
112989
 
112928
112990
  // src/cache.ts
112929
112991
  var IDLE_MS = 7 * 24 * 60 * 6e4;
112930
112992
  var SWEEP_MS = 24 * 60 * 6e4;
112931
- var akbDir = (dir) => path15.join(dir, ".akb");
112932
- var usedFile = (dir) => path15.join(akbDir(dir), "used.json");
112933
- var unsentFile = (dir) => path15.join(akbDir(dir), "unsent");
112993
+ var akbDir = (dir) => path16.join(dir, ".akb");
112994
+ var usedFile = (dir) => path16.join(akbDir(dir), "used.json");
112995
+ var unsentFile = (dir) => path16.join(akbDir(dir), "unsent");
112934
112996
  function markUsed(dir, at2 = Date.now()) {
112935
- fs14.mkdirSync(akbDir(dir), { recursive: true });
112936
- fs14.writeFileSync(usedFile(dir), `${JSON.stringify({ at: at2 })}
112997
+ fs15.mkdirSync(akbDir(dir), { recursive: true });
112998
+ fs15.writeFileSync(usedFile(dir), `${JSON.stringify({ at: at2 })}
112937
112999
  `);
112938
113000
  }
112939
- function markUnsent(dir, unsent) {
112940
- if (!unsent) return void fs14.rmSync(unsentFile(dir), { force: true });
112941
- fs14.mkdirSync(akbDir(dir), { recursive: true });
112942
- fs14.writeFileSync(unsentFile(dir), "");
113001
+ var unsent = (dir) => fs15.existsSync(unsentFile(dir));
113002
+ function markUnsent(dir, unsent2) {
113003
+ if (!unsent2) return void fs15.rmSync(unsentFile(dir), { force: true });
113004
+ fs15.mkdirSync(akbDir(dir), { recursive: true });
113005
+ fs15.writeFileSync(unsentFile(dir), "");
112943
113006
  }
112944
113007
  var holds = /* @__PURE__ */ new Map();
112945
- var holdsDir = () => path15.join(runnerHome(), "holds");
112946
- var holdFile = (dir) => path15.join(holdsDir(), `${crypto2.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
113008
+ var holdsDir = () => path16.join(runnerHome(), "holds");
113009
+ var holdFile = (dir) => path16.join(holdsDir(), `${crypto2.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
112947
113010
  function hold(dir) {
112948
- fs14.mkdirSync(holdsDir(), { recursive: true, mode: 448 });
112949
- fs14.writeFileSync(holdFile(dir), "", { mode: 384 });
113011
+ fs15.mkdirSync(holdsDir(), { recursive: true, mode: 448 });
113012
+ fs15.writeFileSync(holdFile(dir), "", { mode: 384 });
112950
113013
  holds.set(dir, (holds.get(dir) ?? 0) + 1);
112951
113014
  let held5 = true;
112952
113015
  return () => {
@@ -112956,20 +113019,29 @@ function hold(dir) {
112956
113019
  if (left) holds.set(dir, left);
112957
113020
  else {
112958
113021
  holds.delete(dir);
112959
- fs14.rmSync(holdFile(dir), { force: true });
113022
+ fs15.rmSync(holdFile(dir), { force: true });
112960
113023
  }
112961
113024
  };
112962
113025
  }
113026
+ function paused(dir) {
113027
+ try {
113028
+ const file2 = path16.join(projectStateDir(path16.join(akbDir(dir), "kanban")), SESSIONS_FILE);
113029
+ const held5 = JSON.parse(fs15.readFileSync(file2, "utf8"));
113030
+ return (held5.deliveries ?? []).some((d2) => d2.status === "active");
113031
+ } catch {
113032
+ return false;
113033
+ }
113034
+ }
112963
113035
  function busy(dir) {
112964
113036
  if (holds.has(dir)) return true;
112965
- const prefix = path15.basename(holdFile(dir)).split(".")[0] + ".";
113037
+ const prefix = path16.basename(holdFile(dir)).split(".")[0] + ".";
112966
113038
  try {
112967
- return fs14.readdirSync(holdsDir()).filter((file2) => file2.startsWith(prefix)).some((file2) => {
113039
+ return fs15.readdirSync(holdsDir()).filter((file2) => file2.startsWith(prefix)).some((file2) => {
112968
113040
  try {
112969
113041
  process.kill(Number(file2.split(".")[1]), 0);
112970
113042
  return true;
112971
113043
  } catch {
112972
- fs14.rmSync(path15.join(holdsDir(), file2), { force: true });
113044
+ fs15.rmSync(path16.join(holdsDir(), file2), { force: true });
112973
113045
  return false;
112974
113046
  }
112975
113047
  });
@@ -112977,6 +113049,7 @@ function busy(dir) {
112977
113049
  return false;
112978
113050
  }
112979
113051
  }
113052
+ var kept = (dir) => busy(dir) || unsent(dir) || paused(dir);
112980
113053
 
112981
113054
  // src/preview-bridge.ts
112982
113055
  import http from "node:http";
@@ -113219,9 +113292,9 @@ function bodyReferences(body) {
113219
113292
  visible.push("");
113220
113293
  continue;
113221
113294
  }
113222
- const kept3 = inTag || !/^(?: {4}|\t)/.test(line);
113223
- visible.push(kept3 ? line : "");
113224
- if (kept3 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard|Studio)\b/.test(line)) inTag = true;
113295
+ const kept4 = inTag || !/^(?: {4}|\t)/.test(line);
113296
+ visible.push(kept4 ? line : "");
113297
+ if (kept4 && /^ {0,3}<(?:Asset|Mockup|Compare|Storyboard|Studio)\b/.test(line)) inTag = true;
113225
113298
  if (line.includes("/>")) inTag = false;
113226
113299
  }
113227
113300
  const text3 = visible.join("\n").replace(/(`+)[^]*?\1/g, "");
@@ -113301,13 +113374,13 @@ function collect(body, card, host) {
113301
113374
  const nodes = /* @__PURE__ */ new Map();
113302
113375
  const active = /* @__PURE__ */ new Set();
113303
113376
  const out = [];
113304
- const visit = (src, types, owner) => {
113377
+ const visit = (src, types, owner2) => {
113305
113378
  const path47 = src.replace(/[?#].*$/, "");
113306
113379
  let resolved;
113307
113380
  try {
113308
- resolved = host.resolve(path47, owner);
113381
+ resolved = host.resolve(path47, owner2);
113309
113382
  } catch (error) {
113310
- if (owner !== card) return { key: null, error: why(error) };
113383
+ if (owner2 !== card) return { key: null, error: why(error) };
113311
113384
  if (!nodes.has(src)) {
113312
113385
  const node2 = { key: src, file: null, kind: kindAt(path47, types), error: why(error), problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([src]) };
113313
113386
  nodes.set(src, node2);
@@ -113317,16 +113390,16 @@ function collect(body, card, host) {
113317
113390
  }
113318
113391
  if (!resolved) return { key: null };
113319
113392
  const { key, file: file2 } = resolved;
113320
- if (active.has(key)) throw new Error(`${owner}: ${src}: \u8D44\u6E90\u4F9D\u8D56\u5FAA\u73AF`);
113393
+ if (active.has(key)) throw new Error(`${owner2}: ${src}: \u8D44\u6E90\u4F9D\u8D56\u5FAA\u73AF`);
113321
113394
  const json = !!file2 && extOf(file2) === ".json";
113322
113395
  const held5 = nodes.get(key);
113323
113396
  if (held5) {
113324
- if (owner === card) held5.aliases.add(src);
113397
+ if (owner2 === card) held5.aliases.add(src);
113325
113398
  if (held5.error || !json || !types.length || held5.kind !== "asset") return { key, error: held5.error };
113326
113399
  out.splice(out.indexOf(held5), 1);
113327
113400
  }
113328
113401
  const node = { key, file: file2, kind: "asset", problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: held5?.aliases ?? /* @__PURE__ */ new Set([key]) };
113329
- if (owner === card) node.aliases.add(src);
113402
+ if (owner2 === card) node.aliases.add(src);
113330
113403
  nodes.set(key, node);
113331
113404
  active.add(key);
113332
113405
  const child = (ref, from) => {
@@ -113380,8 +113453,8 @@ function collect(body, card, host) {
113380
113453
 
113381
113454
  // src/task-folder.ts
113382
113455
  import crypto4 from "node:crypto";
113383
- import fs19 from "node:fs";
113384
- import path20 from "node:path";
113456
+ import fs20 from "node:fs";
113457
+ import path21 from "node:path";
113385
113458
  import { isDeepStrictEqual } from "node:util";
113386
113459
 
113387
113460
  // node_modules/node-diff3/dist/diff3.mjs
@@ -113608,12 +113681,12 @@ function stampItem(content, fields) {
113608
113681
  const lines = content.split("\n");
113609
113682
  const close = lines.indexOf("---", 1);
113610
113683
  if (close < 0) return content;
113611
- const kept3 = lines.slice(1, close).filter((line) => {
113684
+ const kept4 = lines.slice(1, close).filter((line) => {
113612
113685
  const key = /^([a-z_]+):/.exec(line);
113613
113686
  return !key || fields[key[1]] === void 0;
113614
113687
  });
113615
113688
  const added = Object.entries(fields).flatMap(([k2, v]) => v === null ? [] : [`${k2}: ${yamlScalar(v)}`]);
113616
- return ["---", ...kept3, ...added, ...lines.slice(close)].join("\n");
113689
+ return ["---", ...kept4, ...added, ...lines.slice(close)].join("\n");
113617
113690
  }
113618
113691
 
113619
113692
  // ../cli/src/lib/preview-validation.ts
@@ -113630,8 +113703,8 @@ init_dress_page();
113630
113703
 
113631
113704
  // src/kanban-skill.ts
113632
113705
  import { spawnSync as spawnSync2 } from "node:child_process";
113633
- import fs16 from "node:fs";
113634
- import path17 from "node:path";
113706
+ import fs17 from "node:fs";
113707
+ import path18 from "node:path";
113635
113708
 
113636
113709
  // ../skill/SKILL.md
113637
113710
  var SKILL_default = '---\nname: kanban\ndescription: Manage the file-based task board with akb. Use for creating and planning tasks, revising or implementing cards, and managing background runs; also for "what\'s running".\n---\n\n# Kanban board\n\nThe board is worked only through `akb`. Find the command for the job in `akb help` and run\nit; never do its work by hand or from memory.\n\n- **`--print` does it here**: `akb raw card revise 12 --print "drop the export"` prints the whole\n flow for that card on this board; follow it to its closing steps. Without `--print` the\n same command starts a separate agent.\n- **Keys**: never read or write API keys; the user sets them with `akb raw agent set apiKey`.\n';
@@ -113645,24 +113718,24 @@ var CONTENT = `${SKILL_default.trimEnd()}
113645
113718
  var MANAGED = /^<!-- ai4kanban \S+ -->$/m;
113646
113719
  function prepareKanbanSkill(root2) {
113647
113720
  for (const folder of SKILL_FOLDERS) {
113648
- const dir = path17.join(root2, folder);
113649
- const file2 = path17.join(dir, "SKILL.md");
113721
+ const dir = path18.join(root2, folder);
113722
+ const file2 = path18.join(dir, "SKILL.md");
113650
113723
  try {
113651
113724
  let linked = false;
113652
113725
  let at2 = root2;
113653
113726
  for (const name of `${folder}/SKILL.md`.split("/")) {
113654
- at2 = path17.join(at2, name);
113655
- if (fs16.lstatSync(at2, { throwIfNoEntry: false })?.isSymbolicLink()) linked = true;
113727
+ at2 = path18.join(at2, name);
113728
+ if (fs17.lstatSync(at2, { throwIfNoEntry: false })?.isSymbolicLink()) linked = true;
113656
113729
  }
113657
- const held5 = fs16.existsSync(file2) ? fs16.readFileSync(file2, "utf8") : null;
113658
- const exists = fs16.lstatSync(dir, { throwIfNoEntry: false }) !== void 0;
113730
+ const held5 = fs17.existsSync(file2) ? fs17.readFileSync(file2, "utf8") : null;
113731
+ const exists = fs17.lstatSync(dir, { throwIfNoEntry: false }) !== void 0;
113659
113732
  if (linked || exists && !MANAGED.test(held5 ?? "")) {
113660
113733
  if (!held5?.trim()) throw new Error("\u7528\u6237\u81EA\u6709\u76EE\u5F55\u6216\u7B26\u53F7\u94FE\u63A5\u4E2D\u7F3A\u5C11\u53EF\u8BFB\u7684 SKILL.md");
113661
113734
  continue;
113662
113735
  }
113663
113736
  if (held5 !== CONTENT) {
113664
- fs16.mkdirSync(dir, { recursive: true });
113665
- fs16.writeFileSync(file2, CONTENT);
113737
+ fs17.mkdirSync(dir, { recursive: true });
113738
+ fs17.writeFileSync(file2, CONTENT);
113666
113739
  }
113667
113740
  } catch (e2) {
113668
113741
  throw new Error(`\u65E0\u6CD5\u51C6\u5907 ${folder}\uFF1A${e2 instanceof Error ? e2.message : String(e2)}`);
@@ -113675,16 +113748,16 @@ function keepOutOfGit(dir, folders2 = SKILL_FOLDERS) {
113675
113748
  if (inside2.status !== 0) return;
113676
113749
  const missing = [".akb/", ...folders2.map((f2) => `${f2}/`)].filter((p2) => git2("check-ignore", "-q", p2).status !== 0);
113677
113750
  if (!missing.length) return;
113678
- const exclude = path17.resolve(dir, inside2.stdout.trim());
113679
- fs16.mkdirSync(path17.dirname(exclude), { recursive: true });
113680
- const held5 = fs16.existsSync(exclude) ? fs16.readFileSync(exclude, "utf8") : "";
113681
- fs16.writeFileSync(exclude, `${held5}${held5 && !held5.endsWith("\n") ? "\n" : ""}${missing.join("\n")}
113751
+ const exclude = path18.resolve(dir, inside2.stdout.trim());
113752
+ fs17.mkdirSync(path18.dirname(exclude), { recursive: true });
113753
+ const held5 = fs17.existsSync(exclude) ? fs17.readFileSync(exclude, "utf8") : "";
113754
+ fs17.writeFileSync(exclude, `${held5}${held5 && !held5.endsWith("\n") ? "\n" : ""}${missing.join("\n")}
113682
113755
  `);
113683
113756
  }
113684
113757
 
113685
113758
  // ../cli/src/lib/agents/shared-memory.ts
113686
- import fs17 from "node:fs";
113687
- import path18 from "node:path";
113759
+ import fs18 from "node:fs";
113760
+ import path19 from "node:path";
113688
113761
 
113689
113762
  // ../cli/src/lib/agents/bundled.ts
113690
113763
  var shippedAgentFiles = () => cloudAgentFiles().files;
@@ -113698,7 +113771,7 @@ function sharedMemory(board) {
113698
113771
  const read4 = parseSpecAgent(text3, folder, (relative) => {
113699
113772
  if (builtIn) return shippedAgentFiles()[`${folder}/${relative}`] ?? null;
113700
113773
  try {
113701
- return fs17.readFileSync(path18.join(board, "agents", folder, relative), "utf8");
113774
+ return fs18.readFileSync(path19.join(board, "agents", folder, relative), "utf8");
113702
113775
  } catch {
113703
113776
  return null;
113704
113777
  }
@@ -113709,16 +113782,16 @@ function sharedMemory(board) {
113709
113782
  const at2 = /^([^/]+)\/AGENT\.md$/.exec(key);
113710
113783
  if (at2) take(at2[1], text3, officialAgent(at2[1]));
113711
113784
  }
113712
- const root2 = path18.join(board, "agents");
113785
+ const root2 = path19.join(board, "agents");
113713
113786
  let folders2 = [];
113714
113787
  try {
113715
- folders2 = fs17.readdirSync(root2, { withFileTypes: true }).filter((e2) => e2.isDirectory() && !e2.name.startsWith(".")).map((e2) => e2.name);
113788
+ folders2 = fs18.readdirSync(root2, { withFileTypes: true }).filter((e2) => e2.isDirectory() && !e2.name.startsWith(".")).map((e2) => e2.name);
113716
113789
  } catch {
113717
113790
  }
113718
113791
  for (const folder of folders2.sort()) {
113719
113792
  let text3 = null;
113720
113793
  try {
113721
- text3 = fs17.readFileSync(path18.join(root2, folder, "AGENT.md"), "utf8");
113794
+ text3 = fs18.readFileSync(path19.join(root2, folder, "AGENT.md"), "utf8");
113722
113795
  } catch {
113723
113796
  }
113724
113797
  take(folder, text3, false);
@@ -113778,16 +113851,16 @@ function openTaskFolder(job, projectDir) {
113778
113851
  if (!projectDir) throw new Error(NO_FOLDER);
113779
113852
  keepOutOfGit(projectDir);
113780
113853
  markUsed(projectDir);
113781
- const board = path20.join(projectDir, ".akb", "kanban");
113782
- fs19.mkdirSync(board, { recursive: true });
113854
+ const board = path21.join(projectDir, ".akb", "kanban");
113855
+ fs20.mkdirSync(board, { recursive: true });
113783
113856
  return { task, cloudTask: task, board, cwd: projectDir, project: job.project, number: job.number ?? null, studio: job.studio ?? job.flow?.studio ?? null };
113784
113857
  }
113785
113858
  function openAgentFolder(job, projectDir) {
113786
113859
  if (!job.project || !job.agent) throw new Error("This job names no project.");
113787
113860
  keepOutOfGit(projectDir);
113788
113861
  markUsed(projectDir);
113789
- const board = path20.join(projectDir, ".akb", "kanban");
113790
- fs19.mkdirSync(board, { recursive: true });
113862
+ const board = path21.join(projectDir, ".akb", "kanban");
113863
+ fs20.mkdirSync(board, { recursive: true });
113791
113864
  return {
113792
113865
  task: `agent-${safe2(job.agent.studio ? `${job.agent.studio}-${job.agent.name}` : job.agent.name)}`,
113793
113866
  cloudTask: job.agent.tasks?.[0]?.id ?? null,
@@ -113802,8 +113875,8 @@ function openDiscussionFolder(job, projectDir) {
113802
113875
  if (!job.project) throw new Error("This job names no project.");
113803
113876
  keepOutOfGit(projectDir);
113804
113877
  markUsed(projectDir);
113805
- const board = path20.join(projectDir, ".akb", "kanban");
113806
- fs19.mkdirSync(board, { recursive: true });
113878
+ const board = path21.join(projectDir, ".akb", "kanban");
113879
+ fs20.mkdirSync(board, { recursive: true });
113807
113880
  return { task: "discussion", cloudTask: null, board, cwd: projectDir, project: job.project, number: null, studio: null };
113808
113881
  }
113809
113882
  var boardFolder = (ws) => ({ task: "board", cloudTask: null, board: ws.board, cwd: ws.cwd, project: ws.project, number: null, studio: null });
@@ -113828,37 +113901,37 @@ function inFolder(dir, work) {
113828
113901
  }
113829
113902
  var safe2 = (name) => name.replace(/[^\w.-]/g, "_") || "default";
113830
113903
  var SKILL_ROOTS = [".claude/skills", ".agents/skills"];
113831
- var cardFile = (ws) => (ws.number ? findCard(ws.board, ws.number) : null) ?? path20.join(ws.board, "todo", `${ws.number ?? 0}-task.md`);
113904
+ var cardFile = (ws) => (ws.number ? findCard(ws.board, ws.number) : null) ?? path21.join(ws.board, "todo", `${ws.number ?? 0}-task.md`);
113832
113905
  function findCard(board, number) {
113833
113906
  const named = new RegExp(`^${number}-`);
113834
113907
  const walk = (dir) => {
113835
113908
  let entries;
113836
113909
  try {
113837
- entries = fs19.readdirSync(dir, { withFileTypes: true });
113910
+ entries = fs20.readdirSync(dir, { withFileTypes: true });
113838
113911
  } catch {
113839
113912
  return null;
113840
113913
  }
113841
113914
  for (const e2 of entries) {
113842
113915
  if (!named.test(e2.name)) continue;
113843
- if (e2.isFile() && e2.name.endsWith(".md")) return path20.join(dir, e2.name);
113844
- const root2 = path20.join(dir, e2.name, "root.md");
113845
- if (e2.isDirectory() && fs19.existsSync(root2)) return root2;
113916
+ if (e2.isFile() && e2.name.endsWith(".md")) return path21.join(dir, e2.name);
113917
+ const root2 = path21.join(dir, e2.name, "root.md");
113918
+ if (e2.isDirectory() && fs20.existsSync(root2)) return root2;
113846
113919
  }
113847
113920
  for (const e2 of entries) if (e2.isDirectory() && !e2.name.startsWith(".")) {
113848
- const hit = walk(path20.join(dir, e2.name));
113921
+ const hit = walk(path21.join(dir, e2.name));
113849
113922
  if (hit) return hit;
113850
113923
  }
113851
113924
  return null;
113852
113925
  };
113853
- return walk(path20.join(board, "todo")) ?? walk(path20.join(board, ".archive"));
113926
+ return walk(path21.join(board, "todo")) ?? walk(path21.join(board, ".archive"));
113854
113927
  }
113855
113928
  function akbCardOf(ws) {
113856
113929
  return ws.number && findCard(ws.board, ws.number) ? ws.number : void 0;
113857
113930
  }
113858
- var recordFile = (ws) => path20.join(ws.board, ".sync", `${ws.task}.json`);
113931
+ var recordFile = (ws) => path21.join(ws.board, ".sync", `${ws.task}.json`);
113859
113932
  function readRecord(ws) {
113860
113933
  try {
113861
- return { ...EMPTY, ...JSON.parse(fs19.readFileSync(recordFile(ws), "utf8")) };
113934
+ return { ...EMPTY, ...JSON.parse(fs20.readFileSync(recordFile(ws), "utf8")) };
113862
113935
  } catch {
113863
113936
  return structuredClone(EMPTY);
113864
113937
  }
@@ -113869,13 +113942,72 @@ function writeRecord(ws, record) {
113869
113942
  if (readText(recordFile(ws)) === content) return;
113870
113943
  countSync("recordWrites");
113871
113944
  if (syncDebug) countSync("recordBytes", Buffer.byteLength(content));
113872
- fs19.mkdirSync(path20.dirname(recordFile(ws)), { recursive: true });
113873
- fs19.writeFileSync(recordFile(ws), content);
113945
+ fs20.mkdirSync(path21.dirname(recordFile(ws)), { recursive: true });
113946
+ fs20.writeFileSync(recordFile(ws), content);
113947
+ }
113948
+ async function cleanRecords(ws, base, removed = [], tasks) {
113949
+ const retired = /* @__PURE__ */ new Set();
113950
+ const root2 = rootOf(ws);
113951
+ const removedPaths = new Set(removed);
113952
+ const numbers = new Set(Object.keys(base.files).filter((p2) => p2.startsWith(root2) && !removedPaths.has(p2)).map((p2) => numberOfCard(p2.slice(root2.length))));
113953
+ const deleted = new Map(removed.filter((p2) => p2.startsWith(root2 + ".archive/")).map((p2) => [numberOfCard(p2.slice(root2.length)), p2.slice(root2.length)]));
113954
+ for (const name of tasks ? [...tasks].map((task) => `${task}.json`) : filesUnder(path21.join(ws.board, ".sync"))) {
113955
+ if (!name.endsWith(".json") || name.includes("/")) continue;
113956
+ let record;
113957
+ try {
113958
+ record = JSON.parse(fs20.readFileSync(path21.join(ws.board, ".sync", name), "utf8"));
113959
+ } catch {
113960
+ continue;
113961
+ }
113962
+ if (!record.task || !TASK_ID.test(record.task) || name !== `${record.task}.json` || !record.number || numbers.has(record.number)) continue;
113963
+ const folder = { ...ws, task: record.task, cloudTask: record.task, number: record.number };
113964
+ const card = findCard(ws.board, record.number);
113965
+ if (!record.deleted && deleted.has(record.number)) {
113966
+ record.deleted = deleted.get(record.number);
113967
+ writeRecord(folder, record);
113968
+ }
113969
+ if (!record.deleted) {
113970
+ if (card) continue;
113971
+ const read4 = await readTask(record.task);
113972
+ if (read4.ok || read4.code !== "not_found") continue;
113973
+ record.deleted = true;
113974
+ writeRecord(folder, record);
113975
+ }
113976
+ retired.add(record.task);
113977
+ const index = syncIndex(ws) ?? newIndex(ws);
113978
+ taskIndexes.set(ws.cwd, index);
113979
+ index.retiring.add(record.task);
113980
+ if (card || kept(ws.cwd) || base.pendingAssets?.includes(record.task)) continue;
113981
+ const list2 = assetsFile(record.task);
113982
+ const here = readText(path21.join(ws.board, list2));
113983
+ if (here !== null && here !== (base.files[root2 + list2]?.content ?? null)) continue;
113984
+ let changed = false;
113985
+ for (const [name2, entry] of Object.entries(record.assets ?? {})) {
113986
+ let file2;
113987
+ try {
113988
+ file2 = assetPath(folder, name2, typeof record.deleted === "string" ? path21.join(ws.board, record.deleted) : cardFile(folder));
113989
+ } catch {
113990
+ changed = true;
113991
+ break;
113992
+ }
113993
+ if (!file2) continue;
113994
+ const hash = hashFile(file2);
113995
+ if (hash !== null && hash !== (entry.localHash ?? entry.hash)) {
113996
+ changed = true;
113997
+ break;
113998
+ }
113999
+ }
114000
+ if (!changed) {
114001
+ fs20.rmSync(recordFile(folder), { force: true });
114002
+ forgetTask(index, record.task);
114003
+ }
114004
+ }
114005
+ return retired;
113874
114006
  }
113875
- var baseFile = (ws) => path20.join(ws.cwd, ".akb", "base.json");
114007
+ var baseFile = (ws) => path21.join(ws.cwd, ".akb", "base.json");
113876
114008
  function readBase(ws) {
113877
114009
  try {
113878
- const base = JSON.parse(fs19.readFileSync(baseFile(ws), "utf8"));
114010
+ const base = JSON.parse(fs20.readFileSync(baseFile(ws), "utf8"));
113879
114011
  if (base.layout === "workspace") return base;
113880
114012
  } catch {
113881
114013
  }
@@ -113883,25 +114015,25 @@ function readBase(ws) {
113883
114015
  }
113884
114016
  function writeBase(ws, base) {
113885
114017
  const file2 = baseFile(ws);
113886
- fs19.mkdirSync(path20.dirname(file2), { recursive: true });
113887
- fs19.writeFileSync(`${file2}.tmp`, JSON.stringify(base));
113888
- fs19.renameSync(`${file2}.tmp`, file2);
114018
+ fs20.mkdirSync(path21.dirname(file2), { recursive: true });
114019
+ fs20.writeFileSync(`${file2}.tmp`, JSON.stringify(base));
114020
+ fs20.renameSync(`${file2}.tmp`, file2);
113889
114021
  }
113890
114022
  var hashOf2 = (bytes2) => crypto4.createHash("sha256").update(bytes2).digest("hex");
113891
114023
  function hashFile(file2) {
113892
114024
  try {
113893
- return hashOf2(fs19.readFileSync(file2));
114025
+ return hashOf2(fs20.readFileSync(file2));
113894
114026
  } catch {
113895
114027
  return null;
113896
114028
  }
113897
114029
  }
113898
114030
  function write(file2, bytes2) {
113899
- fs19.mkdirSync(path20.dirname(file2), { recursive: true });
113900
- fs19.writeFileSync(file2, bytes2);
114031
+ fs20.mkdirSync(path21.dirname(file2), { recursive: true });
114032
+ fs20.writeFileSync(file2, bytes2);
113901
114033
  }
113902
114034
  function readText(file2) {
113903
114035
  try {
113904
- return fs19.readFileSync(file2, "utf8");
114036
+ return fs20.readFileSync(file2, "utf8");
113905
114037
  } catch {
113906
114038
  return null;
113907
114039
  }
@@ -113909,17 +114041,17 @@ function readText(file2) {
113909
114041
  function filesUnder(dir, base = dir) {
113910
114042
  let entries;
113911
114043
  try {
113912
- entries = fs19.readdirSync(dir, { withFileTypes: true });
114044
+ entries = fs20.readdirSync(dir, { withFileTypes: true });
113913
114045
  } catch {
113914
114046
  return [];
113915
114047
  }
113916
114048
  return entries.flatMap((e2) => {
113917
- const full = path20.join(dir, e2.name);
114049
+ const full = path21.join(dir, e2.name);
113918
114050
  if (e2.isDirectory()) return filesUnder(full, base);
113919
- return e2.isFile() ? [path20.relative(base, full).split(path20.sep).join("/")] : [];
114051
+ return e2.isFile() ? [path21.relative(base, full).split(path21.sep).join("/")] : [];
113920
114052
  });
113921
114053
  }
113922
- var kept = isBoardPath;
114054
+ var kept2 = isBoardPath;
113923
114055
  var MEMORY2 = "memory/";
113924
114056
  var rootOf = (ws) => `projects/${ws.project}/`;
113925
114057
  var remoteOf = (ws, shared, p2) => p2.startsWith(MEMORY2) && shared(p2.slice(MEMORY2.length)) ? p2 : rootOf(ws) + p2;
@@ -113939,26 +114071,26 @@ function assetFiles(ws, list2) {
113939
114071
  return null;
113940
114072
  }
113941
114073
  };
113942
- return new Set(Object.keys(assetsOf(list2)).map(at2).filter((f2) => !!f2).map((f2) => path20.relative(ws.board, f2).split(path20.sep).join("/")));
114074
+ return new Set(Object.keys(assetsOf(list2)).map(at2).filter((f2) => !!f2).map((f2) => path21.relative(ws.board, f2).split(path21.sep).join("/")));
113943
114075
  }
113944
114076
  var assetsListOf = (ws, base) => base.files[rootOf(ws) + assetsFile(ws.task)]?.content;
113945
114077
  var localFiles = (ws, base) => {
113946
- const assets = /* @__PURE__ */ new Set([...assetFiles(ws, assetsListOf(ws, base)), ...assetFiles(ws, readText(path20.join(ws.board, assetsFile(ws.task))))]);
113947
- return filesUnder(ws.board).filter((p2) => kept(p2) && !assets.has(p2));
114078
+ const assets = /* @__PURE__ */ new Set([...assetFiles(ws, assetsListOf(ws, base)), ...assetFiles(ws, readText(path21.join(ws.board, assetsFile(ws.task))))]);
114079
+ return filesUnder(ws.board).filter((p2) => kept2(p2) && !assets.has(p2));
113948
114080
  };
113949
114081
  var SKILL_PATH = /^skills\/([a-z0-9]+(?:-[a-z0-9]+)*)\/((?:[\w.-]+\/)*[\w.-]+)$/;
113950
114082
  function pullTools(ws, record, files) {
113951
114083
  const held5 = record.tools?.skills ?? {};
113952
114084
  const ours = new Set(Object.keys(held5).map((name) => name.split("/")[1]));
113953
- const theirs = (skill) => !ours.has(skill) && SKILL_ROOTS.some((root2) => fs19.existsSync(path20.join(ws.cwd, root2, skill)));
113954
- const kept3 = Object.keys(files).map((name) => SKILL_PATH.exec(name)?.[1]).filter((skill) => skill && !theirs(skill));
114085
+ const theirs = (skill) => !ours.has(skill) && SKILL_ROOTS.some((root2) => fs20.existsSync(path21.join(ws.cwd, root2, skill)));
114086
+ const kept4 = Object.keys(files).map((name) => SKILL_PATH.exec(name)?.[1]).filter((skill) => skill && !theirs(skill));
113955
114087
  const skills = {};
113956
114088
  for (const [name, text3] of Object.entries(files)) {
113957
114089
  const at2 = SKILL_PATH.exec(name);
113958
- if (!at2 || at2[1] === "kanban" || !kept3.includes(at2[1]) || at2[2].split("/").includes("..")) continue;
114090
+ if (!at2 || at2[1] === "kanban" || !kept4.includes(at2[1]) || at2[2].split("/").includes("..")) continue;
113959
114091
  skills[name] = hashOf2(text3);
113960
114092
  for (const root2 of SKILL_ROOTS) {
113961
- const file2 = path20.join(ws.cwd, root2, at2[1], at2[2]);
114093
+ const file2 = path21.join(ws.cwd, root2, at2[1], at2[2]);
113962
114094
  if (held5[name] !== skills[name] || hashFile(file2) !== skills[name]) write(file2, text3);
113963
114095
  }
113964
114096
  }
@@ -113967,8 +114099,8 @@ function pullTools(ws, record, files) {
113967
114099
  const [, skill, rest] = SKILL_PATH.exec(name) ?? [];
113968
114100
  if (!skill || !rest) continue;
113969
114101
  for (const root2 of SKILL_ROOTS) {
113970
- fs19.rmSync(path20.join(ws.cwd, root2, skill, rest), { force: true });
113971
- if (!Object.keys(skills).some((n) => n.startsWith(`skills/${skill}/`))) fs19.rmSync(path20.join(ws.cwd, root2, skill), { recursive: true, force: true });
114102
+ fs20.rmSync(path21.join(ws.cwd, root2, skill, rest), { force: true });
114103
+ if (!Object.keys(skills).some((n) => n.startsWith(`skills/${skill}/`))) fs20.rmSync(path21.join(ws.cwd, root2, skill), { recursive: true, force: true });
113972
114104
  }
113973
114105
  }
113974
114106
  const names2 = [...new Set(Object.keys(skills).map((name) => name.split("/")[1]))];
@@ -114005,46 +114137,46 @@ async function pullStudio(ws, record) {
114005
114137
  if (files.ok) pullTools(ws, record, files.value);
114006
114138
  }
114007
114139
  dropPlacedAgents(ws);
114008
- for (const name of Object.keys(record.agents ?? {})) fs19.rmSync(path20.join(ws.board, name), { force: true });
114140
+ for (const name of Object.keys(record.agents ?? {})) fs20.rmSync(path21.join(ws.board, name), { force: true });
114009
114141
  record.agents = {};
114010
114142
  return { ok: true, value: void 0 };
114011
114143
  }
114012
- var agentsRecord = (ws) => path20.join(ws.board, ".sync", "agents.json");
114144
+ var agentsRecord = (ws) => path21.join(ws.board, ".sync", "agents.json");
114013
114145
  function readPlaced(ws) {
114014
114146
  try {
114015
- return JSON.parse(fs19.readFileSync(agentsRecord(ws), "utf8"));
114147
+ return JSON.parse(fs20.readFileSync(agentsRecord(ws), "utf8"));
114016
114148
  } catch {
114017
114149
  return {};
114018
114150
  }
114019
114151
  }
114020
114152
  function dropPlacedAgents(ws) {
114021
114153
  const placed = readPlaced(ws);
114022
- for (const name of Object.keys(placed)) if (hashFile(path20.join(ws.board, name)) === placed[name]) fs19.rmSync(path20.join(ws.board, name), { force: true });
114023
- fs19.rmSync(agentsRecord(ws), { force: true });
114154
+ for (const name of Object.keys(placed)) if (hashFile(path21.join(ws.board, name)) === placed[name]) fs20.rmSync(path21.join(ws.board, name), { force: true });
114155
+ fs20.rmSync(agentsRecord(ws), { force: true });
114024
114156
  }
114025
- function assetPath(ws, name, owner) {
114157
+ function assetPath(ws, name, owner2) {
114026
114158
  if (/^[a-z][\w+.-]*:/i.test(name) || name.startsWith("#") || name.startsWith("//")) return null;
114027
- if (path20.isAbsolute(name)) throw new Error(`absolute path: ${name}`);
114159
+ if (path21.isAbsolute(name)) throw new Error(`absolute path: ${name}`);
114028
114160
  const held5 = /^\.(assets|mockups)\//.exec(name);
114029
114161
  const state = stateDir(ws);
114030
- const root2 = held5 && state ? path20.join(state, held5[1]) : ws.board;
114031
- const file2 = held5 && state ? path20.resolve(root2, name.slice(held5[0].length)) : path20.resolve(path20.dirname(owner), name);
114032
- const roots = [ws.board, ...state ? ["assets", "mockups"].map((folder) => path20.join(state, folder, ...ws.number ? [String(ws.number)] : [])) : []];
114033
- const inside2 = (file3, root3) => file3.startsWith(root3 + path20.sep);
114162
+ const root2 = held5 && state ? path21.join(state, held5[1]) : ws.board;
114163
+ const file2 = held5 && state ? path21.resolve(root2, name.slice(held5[0].length)) : path21.resolve(path21.dirname(owner2), name);
114164
+ const roots = [ws.board, ...state ? ["assets", "mockups"].map((folder) => path21.join(state, folder, ...ws.number ? [String(ws.number)] : [])) : []];
114165
+ const inside2 = (file3, root3) => file3.startsWith(root3 + path21.sep);
114034
114166
  if (!roots.some((root3) => inside2(file2, root3))) throw new Error(`outside the board: ${name}`);
114035
114167
  let existing = file2;
114036
- while (!fs19.existsSync(existing) && path20.dirname(existing) !== existing) existing = path20.dirname(existing);
114037
- const real = path20.join(fs19.realpathSync(existing), path20.relative(existing, file2));
114168
+ while (!fs20.existsSync(existing) && path21.dirname(existing) !== existing) existing = path21.dirname(existing);
114169
+ const real = path21.join(fs20.realpathSync(existing), path21.relative(existing, file2));
114038
114170
  let stateParent = state;
114039
- while (stateParent && !fs19.existsSync(stateParent) && path20.dirname(stateParent) !== stateParent) stateParent = path20.dirname(stateParent);
114040
- const realState = state && stateParent ? path20.resolve(fs19.realpathSync(stateParent), path20.relative(stateParent, state)) : null;
114041
- const realRoots = [fs19.realpathSync(ws.board), ...realState ? ["assets", "mockups"].map((folder) => path20.join(realState, folder, ...ws.number ? [String(ws.number)] : [])) : []];
114171
+ while (stateParent && !fs20.existsSync(stateParent) && path21.dirname(stateParent) !== stateParent) stateParent = path21.dirname(stateParent);
114172
+ const realState = state && stateParent ? path21.resolve(fs20.realpathSync(stateParent), path21.relative(stateParent, state)) : null;
114173
+ const realRoots = [fs20.realpathSync(ws.board), ...realState ? ["assets", "mockups"].map((folder) => path21.join(realState, folder, ...ws.number ? [String(ws.number)] : [])) : []];
114042
114174
  if (!realRoots.some((root3) => real === root3 || inside2(real, root3))) throw new Error(`link outside the board: ${name}`);
114043
114175
  return file2;
114044
114176
  }
114045
114177
  function cardAssetsDir(ws, id) {
114046
114178
  const state = stateDir(ws);
114047
- return state && path20.join(state, "assets", String(id));
114179
+ return state && path21.join(state, "assets", String(id));
114048
114180
  }
114049
114181
  function stateDir(ws) {
114050
114182
  try {
@@ -114081,8 +114213,9 @@ function syncedCardVersion(ws) {
114081
114213
  }
114082
114214
  async function readCloud(ws) {
114083
114215
  const base = readBase(ws);
114216
+ const previous = { ...base.files };
114084
114217
  const known2 = new Set(Object.keys(base.files));
114085
- const keepDraft = new Set((base.deferred ?? []).filter((p2) => readText(path20.join(ws.board, p2)) !== (base.files[rootOf(ws) + p2]?.content ?? null)));
114218
+ const keepDraft = new Set((base.deferred ?? []).filter((p2) => readText(path21.join(ws.board, p2)) !== (base.files[rootOf(ws) + p2]?.content ?? null)));
114086
114219
  if (base.workspace === void 0) {
114087
114220
  const project = await readProject(ws.project);
114088
114221
  if (!project.ok) return project;
@@ -114095,19 +114228,29 @@ async function readCloud(ws) {
114095
114228
  if (f2.content === null) delete base.files[f2.path];
114096
114229
  else base.files[f2.path] = { seq: f2.seq, content: f2.content };
114097
114230
  }
114231
+ const removed = [...known2].filter((p2) => !base.files[p2]);
114232
+ for (const p2 of removed) {
114233
+ const local = p2.startsWith(rootOf(ws)) ? p2.slice(rootOf(ws).length) : p2;
114234
+ if (local.startsWith(".archive/") && readText(path21.join(ws.board, local)) !== null && readText(path21.join(ws.board, local)) !== previous[p2]?.content) keepDraft.add(local);
114235
+ }
114098
114236
  base.head_seq = read4.value.head_seq;
114099
114237
  base.project = ws.project;
114100
114238
  writeBase(ws, base);
114101
114239
  const reset = (view2) => {
114102
114240
  for (const [p2, content] of view2) {
114103
- const file2 = path20.join(ws.board, p2);
114104
- if (!keepDraft.has(p2) && kept(p2) && readText(file2) !== content) write(file2, content);
114241
+ const file2 = path21.join(ws.board, p2);
114242
+ if (!keepDraft.has(p2) && kept2(p2) && readText(file2) !== content) write(file2, content);
114105
114243
  }
114106
114244
  };
114107
114245
  const view = viewOf(ws, base, sharedMemory(ws.board));
114108
114246
  const first = (p2) => isSettingsPath(p2) && !known2.has(rootOf(ws) + p2);
114109
- for (const p2 of localFiles(ws, base)) if (!keepDraft.has(p2) && !view.has(p2) && !first(p2)) fs19.rmSync(path20.join(ws.board, p2), { force: true });
114247
+ for (const p2 of localFiles(ws, base)) if (!keepDraft.has(p2) && !view.has(p2) && !first(p2)) fs20.rmSync(path21.join(ws.board, p2), { force: true });
114110
114248
  reset(view);
114249
+ const retired = await cleanRecords(ws, base, removed);
114250
+ if (retired.has(ws.task)) {
114251
+ writeIndex(ws.board);
114252
+ return { ok: true, value: void 0 };
114253
+ }
114111
114254
  const record = readRecord(ws);
114112
114255
  const studio = await pullStudio(ws, record);
114113
114256
  if (!studio.ok) return studio;
@@ -114119,18 +114262,18 @@ async function readCloud(ws) {
114119
114262
  return { ok: true, value: void 0 };
114120
114263
  }
114121
114264
  function writeIndex(board) {
114122
- const todo = path20.join(board, "todo");
114265
+ const todo = path21.join(board, "todo");
114123
114266
  const cards = [];
114124
114267
  let entries = [];
114125
114268
  try {
114126
- entries = fs19.readdirSync(todo, { withFileTypes: true });
114269
+ entries = fs20.readdirSync(todo, { withFileTypes: true });
114127
114270
  } catch {
114128
114271
  }
114129
114272
  for (const e2 of entries) {
114130
114273
  const id = /^(\d+)-/.exec(e2.name)?.[1];
114131
114274
  if (!id) continue;
114132
114275
  const link = e2.isDirectory() ? `${e2.name}/root.md` : e2.name.endsWith(".md") ? e2.name : null;
114133
- const text4 = link && readText(path20.join(todo, link));
114276
+ const text4 = link && readText(path21.join(todo, link));
114134
114277
  if (text4 === null || !link) continue;
114135
114278
  cards.push({ id: Number(id), title: cardFront(text4).title ?? e2.name.replace(/\.md$/, ""), link });
114136
114279
  }
@@ -114145,7 +114288,7 @@ the number at the front of a filename is the task id.
114145
114288
 
114146
114289
  ${list2}
114147
114290
  `;
114148
- if (readText(path20.join(todo, "README.md")) !== text3) write(path20.join(todo, "README.md"), text3);
114291
+ if (readText(path21.join(todo, "README.md")) !== text3) write(path21.join(todo, "README.md"), text3);
114149
114292
  }
114150
114293
  var workspaceOf = (ws) => readBase(ws).workspace ?? null;
114151
114294
  async function pullAssets(ws, record, assets) {
@@ -114224,7 +114367,7 @@ async function pullAssets(ws, record, assets) {
114224
114367
  }
114225
114368
  if (!child) return src;
114226
114369
  dependencies.push(name2);
114227
- const back = !found.text && /^\.(assets|mockups)\//.test(name2) ? name2 : path20.relative(path20.dirname(target), child).split(path20.sep).join("/");
114370
+ const back = !found.text && /^\.(assets|mockups)\//.test(name2) ? name2 : path21.relative(path21.dirname(target), child).split(path21.sep).join("/");
114228
114371
  if (back !== src) changed = true;
114229
114372
  return back;
114230
114373
  });
@@ -114261,16 +114404,16 @@ async function readAsset(artifact, version) {
114261
114404
  return { ok: true, value: Buffer.from(typeof content === "string" ? content : JSON.stringify(content)) };
114262
114405
  }
114263
114406
  async function sentOf(file2, kind) {
114264
- const ext = path20.extname(file2).toLowerCase();
114265
- if (kind !== "html") return { bytes: fs19.readFileSync(file2), type: kind === "tiled" && ext === ".tsx" ? "application/xml" : TYPES[ext] ?? "application/octet-stream", kind };
114407
+ const ext = path21.extname(file2).toLowerCase();
114408
+ if (kind !== "html") return { bytes: fs20.readFileSync(file2), type: kind === "tiled" && ext === ".tsx" ? "application/xml" : TYPES[ext] ?? "application/octet-stream", kind };
114266
114409
  const page = await (await Promise.resolve().then(() => (init_mockup(), mockup_exports))).drawMockup(file2);
114267
114410
  return { bytes: Buffer.from(page), type: "text/html", kind };
114268
114411
  }
114269
- var undrawnPreviews = (ws) => Object.entries(assetsOf(readText(path20.join(ws.board, assetsFile(ws.task))))).flatMap(([key, ref]) => ref.error ? [`${key}: ${ref.error}`] : []);
114412
+ var undrawnPreviews = (ws) => Object.entries(assetsOf(readText(path21.join(ws.board, assetsFile(ws.task))))).flatMap(([key, ref]) => ref.error ? [`${key}: ${ref.error}`] : []);
114270
114413
  function undrawn(ws, reason) {
114271
114414
  const state = stateDir(ws);
114272
- for (const [root2, shown] of [...state ? [[path20.join(state, "assets"), ".assets"], [path20.join(state, "mockups"), ".mockups"]] : [], [ws.board, ""]]) {
114273
- reason = reason.split(`file://${root2}${path20.sep}`).join(shown && `${shown}/`).split(`${root2}${path20.sep}`).join(shown && `${shown}/`);
114415
+ for (const [root2, shown] of [...state ? [[path21.join(state, "assets"), ".assets"], [path21.join(state, "mockups"), ".mockups"]] : [], [ws.board, ""]]) {
114416
+ reason = reason.split(`file://${root2}${path21.sep}`).join(shown && `${shown}/`).split(`${root2}${path21.sep}`).join(shown && `${shown}/`);
114274
114417
  }
114275
114418
  return reason.replace(/ \(at [^)]*file:\/\/[^)]*\)$/, "").slice(0, 500);
114276
114419
  }
@@ -114305,28 +114448,28 @@ async function pushAssets(ws, record, before) {
114305
114448
  if (body === null) return { ok: true, value: void 0 };
114306
114449
  const refs = {};
114307
114450
  const canonical = (target) => {
114308
- const real = (file3) => fs19.existsSync(file3) ? fs19.realpathSync(file3) : path20.dirname(file3) === file3 ? file3 : path20.join(real(path20.dirname(file3)), path20.basename(file3));
114451
+ const real = (file3) => fs20.existsSync(file3) ? fs20.realpathSync(file3) : path21.dirname(file3) === file3 ? file3 : path21.join(real(path21.dirname(file3)), path21.basename(file3));
114309
114452
  target = real(target);
114310
114453
  const state = stateDir(ws);
114311
114454
  for (const folder of ["assets", "mockups"]) {
114312
- const root2 = state && real(path20.join(state, folder));
114313
- if (root2 && target.startsWith(root2 + path20.sep)) return `.${folder}/${path20.relative(root2, target).split(path20.sep).join("/")}`;
114455
+ const root2 = state && real(path21.join(state, folder));
114456
+ if (root2 && target.startsWith(root2 + path21.sep)) return `.${folder}/${path21.relative(root2, target).split(path21.sep).join("/")}`;
114314
114457
  }
114315
- return path20.relative(real(path20.dirname(file2)), target).split(path20.sep).join("/");
114458
+ return path21.relative(real(path21.dirname(file2)), target).split(path21.sep).join("/");
114316
114459
  };
114317
114460
  try {
114318
114461
  const graph = collect(body, file2, {
114319
- resolve: (src, owner) => {
114462
+ resolve: (src, owner2) => {
114320
114463
  const id = Object.entries(before).find(([, ref]) => ref.artifact === src);
114321
114464
  if (id) return { key: id[0], file: null };
114322
- const target = assetPath(ws, src, owner);
114465
+ const target = assetPath(ws, src, owner2);
114323
114466
  if (!target) return null;
114324
- const key = owner === file2 && before[src] ? src : canonical(target);
114325
- if (!fs19.statSync(target, { throwIfNoEntry: false })?.isFile()) {
114467
+ const key = owner2 === file2 && before[src] ? src : canonical(target);
114468
+ if (!fs20.statSync(target, { throwIfNoEntry: false })?.isFile()) {
114326
114469
  if (before[key]) return { key, file: null };
114327
114470
  throw new Error(`file not found: ${target}`);
114328
114471
  }
114329
- return { key: canonical(fs19.realpathSync(target)), file: target };
114472
+ return { key: canonical(fs20.realpathSync(target)), file: target };
114330
114473
  },
114331
114474
  read: referenceText,
114332
114475
  retained: (key) => (record.assets[key]?.dependencies ?? []).map((src) => {
@@ -114342,7 +114485,7 @@ async function pushAssets(ws, record, before) {
114342
114485
  let why2 = node.error ?? [...node.dependencies.values()].map((key) => refs[key]?.error).find(Boolean);
114343
114486
  if (!why2 && node.file) {
114344
114487
  try {
114345
- if (fs19.statSync(node.file).size > ASSET_FILE_LIMIT) throw new Error("This asset is over 100 MiB.");
114488
+ if (fs20.statSync(node.file).size > ASSET_FILE_LIMIT) throw new Error("This asset is over 100 MiB.");
114346
114489
  out = await sentOf(node.file, kind);
114347
114490
  } catch (error) {
114348
114491
  why2 = renderError(error);
@@ -114400,7 +114543,7 @@ async function pushAssets(ws, record, before) {
114400
114543
  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);
114401
114544
  if (!entry || !unchanged && entry.hash !== hash || entry.kind && entry.kind !== out.kind) {
114402
114545
  if (!ws.cloudTask) continue;
114403
- let artifact = previous && (previous.kind ?? kindOf(path20.extname(node.file).toLowerCase())) === out.kind ? previous.artifact : void 0;
114546
+ let artifact = previous && (previous.kind ?? kindOf(path21.extname(node.file).toLowerCase())) === out.kind ? previous.artifact : void 0;
114404
114547
  if (!artifact) {
114405
114548
  const made = await createArtifact(ws.cloudTask, node.key.slice(0, 200), out.kind);
114406
114549
  if (!made.ok) return { ...made, error: `${node.key}: ${made.error}` };
@@ -114426,25 +114569,25 @@ async function pushAssets(ws, record, before) {
114426
114569
  } catch (error) {
114427
114570
  return { ok: false, code: "bad_request", error: error instanceof Error ? error.message : String(error) };
114428
114571
  }
114429
- const list2 = path20.join(ws.board, assetsFile(ws.task));
114430
- if (Object.keys(refs).length || fs19.existsSync(list2)) {
114572
+ const list2 = path21.join(ws.board, assetsFile(ws.task));
114573
+ if (Object.keys(refs).length || fs20.existsSync(list2)) {
114431
114574
  if (!isDeepStrictEqual(assetsOf(readText(list2)), refs)) write(list2, assetsText(refs));
114432
114575
  }
114433
114576
  logSync("assets.end", { project: ws.project, task: ws.task, ms: Math.round(performance.now() - started) });
114434
114577
  return { ok: true, value: void 0 };
114435
114578
  }
114436
114579
  function resetSorted(ws) {
114437
- for (const sub of ["dismissed", "archived"]) fs19.rmSync(path20.join(ws.board, "triage", sub), { recursive: true, force: true });
114580
+ for (const sub of ["dismissed", "archived"]) fs20.rmSync(path21.join(ws.board, "triage", sub), { recursive: true, force: true });
114438
114581
  for (const [p2, content] of viewOf(ws, readBase(ws), sharedMemory(ws.board))) {
114439
- if (/^triage\/(?:dismissed|archived)\//.test(p2)) write(path20.join(ws.board, p2), content);
114582
+ if (/^triage\/(?:dismissed|archived)\//.test(p2)) write(path21.join(ws.board, p2), content);
114440
114583
  }
114441
114584
  }
114442
- function proposeItems(ws, base) {
114585
+ function proposeItems(ws, base, paths) {
114443
114586
  const root2 = rootOf(ws);
114444
- for (const p2 of localFiles(ws, base)) {
114587
+ for (const p2 of paths ?? localFiles(ws, base)) {
114445
114588
  if (itemAt(p2)?.state !== "open" || base.files[root2 + p2]) continue;
114446
- const file2 = path20.join(ws.board, p2);
114447
- const content = fs19.readFileSync(file2, "utf8");
114589
+ const file2 = path21.join(ws.board, p2);
114590
+ const content = fs20.readFileSync(file2, "utf8");
114448
114591
  const said = (key) => new RegExp(`^${key}:`, "m").test(content.split(/\n---/)[0] ?? "");
114449
114592
  const fields = {
114450
114593
  ...ws.cloudTask && !said("source_task") ? { source_task: ws.cloudTask } : {},
@@ -114472,42 +114615,151 @@ var push = (ws, job) => inFolder(ws.cwd, async () => {
114472
114615
  return pushed;
114473
114616
  });
114474
114617
  var withBoard = (ws, work) => inFolder(ws.cwd, () => work((job) => sendMarked(ws, job)));
114475
- async function sendBoard(ws, machineId) {
114618
+ async function sendBoard(ws, machineId, paths) {
114476
114619
  if (readBase(ws).head_seq === null) return { ok: true, changed: false };
114477
- return sendMarked(ws, { id: null, machineId });
114620
+ return sendMarked(ws, { id: null, machineId }, paths);
114478
114621
  }
114479
- async function sendMarked(ws, job) {
114480
- const pushed = await send2(ws, job);
114622
+ async function sendMarked(ws, job, paths) {
114623
+ const pushed = await send2(ws, job, paths);
114481
114624
  markUnsent(ws.cwd, !pushed.ok || !!readBase(ws).pendingAssets?.length);
114482
114625
  return pushed;
114483
114626
  }
114484
- async function send2(ws, job) {
114627
+ var boardIdentity = (ws) => {
114628
+ const stat = fs20.statSync(ws.board);
114629
+ return `${stat.dev}:${stat.ino}:${stat.birthtimeMs}`;
114630
+ };
114631
+ function rememberDirectories(directories, file2) {
114632
+ for (let dir = path21.posix.dirname(file2); dir !== "." && dir !== "/"; dir = path21.posix.dirname(dir)) directories.add(dir);
114633
+ }
114634
+ function newIndex(ws) {
114635
+ const directories = /* @__PURE__ */ new Set();
114636
+ for (const p2 of Object.keys(readBase(ws).files)) {
114637
+ if (p2.startsWith(rootOf(ws))) rememberDirectories(directories, p2.slice(rootOf(ws).length));
114638
+ }
114639
+ return { identity: boardIdentity(ws), directories, ready: false, retiring: /* @__PURE__ */ new Set(), tasks: /* @__PURE__ */ new Map(), files: /* @__PURE__ */ new Map() };
114640
+ }
114641
+ var taskIndexes = /* @__PURE__ */ new Map();
114642
+ function syncIndex(ws) {
114643
+ const index = taskIndexes.get(ws.cwd);
114644
+ if (index && index.identity !== boardIdentity(ws)) {
114645
+ taskIndexes.delete(ws.cwd);
114646
+ return void 0;
114647
+ }
114648
+ return index;
114649
+ }
114650
+ function forgetTask(index, task) {
114651
+ for (const file2 of index.tasks.get(task)?.paths ?? []) {
114652
+ const tasks = index.files.get(file2);
114653
+ tasks.delete(task);
114654
+ if (!tasks.size) index.files.delete(file2);
114655
+ }
114656
+ index.tasks.delete(task);
114657
+ index.retiring.delete(task);
114658
+ }
114659
+ function indexTask(ws, record, card = cardFile(ws)) {
114660
+ if (!ws.cloudTask || !ws.number) return;
114661
+ const paths = /* @__PURE__ */ new Set([card, path21.join(ws.board, assetsFile(ws.task)), recordFile(ws)]);
114662
+ for (const name of Object.keys(record.assets)) {
114663
+ try {
114664
+ const file2 = assetPath(ws, name, card);
114665
+ if (file2) paths.add(file2);
114666
+ } catch {
114667
+ }
114668
+ }
114669
+ for (const file2 of [...paths]) {
114670
+ for (let dir = path21.dirname(file2); dir.startsWith(ws.cwd + path21.sep); dir = path21.dirname(dir)) paths.add(dir);
114671
+ }
114672
+ const index = syncIndex(ws) ?? newIndex(ws);
114673
+ for (const file2 of index.tasks.get(ws.task)?.paths ?? []) {
114674
+ const tasks = index.files.get(file2);
114675
+ tasks.delete(ws.task);
114676
+ if (!tasks.size) index.files.delete(file2);
114677
+ }
114678
+ index.tasks.set(ws.task, { task: ws.task, number: ws.number, deleted: record.deleted, paths });
114679
+ for (const file2 of paths) {
114680
+ const tasks = index.files.get(file2) ?? /* @__PURE__ */ new Set();
114681
+ tasks.add(ws.task);
114682
+ index.files.set(file2, tasks);
114683
+ }
114684
+ taskIndexes.set(ws.cwd, index);
114685
+ }
114686
+ function affectedTasks(ws, paths) {
114687
+ const index = syncIndex(ws);
114688
+ const tasks = new Set(index?.retiring);
114689
+ for (const p2 of paths) {
114690
+ for (const task2 of index?.files.get(path21.resolve(ws.board, p2)) ?? []) tasks.add(task2);
114691
+ const task = /^\.sync\/([\w-]+)\.json$/.exec(p2)?.[1];
114692
+ if (task) tasks.add(task);
114693
+ }
114694
+ return tasks;
114695
+ }
114696
+ async function send2(ws, job, paths) {
114485
114697
  const record = readRecord(ws);
114486
114698
  const base = readBase(ws);
114487
114699
  const fail = (error, conflict = false, code) => ({ ok: false, conflict, error, ...code ? {} : { offline: true } });
114488
- const tasks = ws.cloudTask ? [{ folder: ws, record }] : filesUnder(path20.join(ws.board, ".sync")).filter((name) => name.endsWith(".json")).flatMap((name) => {
114700
+ if (!syncIndex(ws)?.ready) paths = void 0;
114701
+ const selected = paths && new Set(paths);
114702
+ const names2 = selected ? new Set(base.pendingAssets ?? []) : null;
114703
+ if (selected) for (const task of affectedTasks(ws, selected)) names2.add(task);
114704
+ const retired = await cleanRecords(ws, base, [], names2 ?? void 0);
114705
+ if (retired.has(ws.task)) record.deleted = true;
114706
+ const records = ws.cloudTask ? [] : names2 ? [...names2].map((task) => `${task}.json`) : [.../* @__PURE__ */ new Set([
114707
+ ...filesUnder(path21.join(ws.board, ".sync")).filter((name) => name.endsWith(".json")),
114708
+ ...[...syncIndex(ws)?.tasks.keys() ?? []].map((task) => `${task}.json`)
114709
+ ])];
114710
+ const tasks = ws.cloudTask ? [{ folder: ws, record }] : records.flatMap((name) => {
114711
+ let held5;
114489
114712
  try {
114490
- const held5 = JSON.parse(fs19.readFileSync(path20.join(ws.board, ".sync", name), "utf8"));
114491
- if (!held5.task || !TASK_ID.test(held5.task) || !held5.number) return [];
114492
- return [{ folder: { ...ws, task: held5.task, cloudTask: held5.task, number: held5.number }, record: held5 }];
114713
+ held5 = JSON.parse(fs20.readFileSync(path21.join(ws.board, ".sync", name), "utf8"));
114493
114714
  } catch {
114494
- return [];
114495
- }
114715
+ const known2 = syncIndex(ws)?.tasks.get(name.replace(/\.json$/, ""));
114716
+ if (!known2) return [];
114717
+ const before = assetsOf(assetsListOf({ ...ws, task: known2.task }, base));
114718
+ held5 = { task: known2.task, number: known2.number, deleted: known2.deleted ?? (syncIndex(ws)?.retiring.has(known2.task) ? true : void 0), assets: Object.fromEntries(Object.entries(before).map(([name2, ref]) => [name2, { artifact: ref.artifact, version: ref.version ?? 0, hash: "" }])) };
114719
+ writeRecord({ ...ws, task: known2.task }, held5);
114720
+ }
114721
+ if (!held5.task || !TASK_ID.test(held5.task) || !held5.number) return [];
114722
+ return [{ folder: { ...ws, task: held5.task, cloudTask: held5.task, number: held5.number }, record: held5 }];
114496
114723
  });
114724
+ if (!syncIndex(ws)) taskIndexes.set(ws.cwd, newIndex(ws));
114497
114725
  const boardSync = !job.id && !ws.cloudTask;
114498
114726
  const deferredCards = /* @__PURE__ */ new Set();
114499
114727
  const deferredLists = /* @__PURE__ */ new Set();
114500
114728
  const assetErrors = {};
114501
114729
  const processed = /* @__PURE__ */ new Set();
114730
+ const cards = !selected && !ws.cloudTask ? new Map(
114731
+ [".archive", "todo"].flatMap((dir) => filesUnder(path21.join(ws.board, dir), ws.board)).flatMap((p2) => {
114732
+ const number = numberOfCard(p2);
114733
+ return number ? [[number, p2]] : [];
114734
+ })
114735
+ ) : null;
114502
114736
  for (const item of tasks) {
114503
114737
  processed.add(item.folder.task);
114504
114738
  if (processed.size === 1 || processed.size % 25 === 0) logSync("board.progress", { project: ws.project, processed: processed.size, total: tasks.length });
114505
- const card = path20.relative(ws.board, cardFile(item.folder)).split(path20.sep).join("/");
114506
- const archived = boardSync && card.startsWith(".archive/") && base.files[rootOf(ws) + card];
114507
- if (!archived) {
114508
- const assets = await pushAssets(item.folder, item.record, assetsOf(assetsListOf(item.folder, base)));
114739
+ const card = cards?.get(item.folder.number) ?? path21.relative(ws.board, cardFile(item.folder)).split(path21.sep).join("/");
114740
+ indexTask(item.folder, item.record, path21.join(ws.board, card));
114741
+ selected?.add(card);
114742
+ const before = assetsOf(assetsListOf(item.folder, base));
114743
+ const newer = Object.entries(before).some(([name, ref]) => {
114744
+ const held5 = item.record.assets[name];
114745
+ return held5?.artifact === ref.artifact && (ref.version ?? 0) > held5.version;
114746
+ });
114747
+ const clean = () => Object.entries(item.record.assets).every(([name, entry]) => {
114748
+ try {
114749
+ const file2 = assetPath(item.folder, name, path21.join(ws.board, card));
114750
+ return !file2 || hashFile(file2) === (entry.localHash ?? entry.hash);
114751
+ } catch {
114752
+ return false;
114753
+ }
114754
+ });
114755
+ const archived = !selected && boardSync && card.startsWith(".archive/") && readText(path21.join(ws.board, card)) === base.files[rootOf(ws) + card]?.content && !newer && clean();
114756
+ if (!archived && !item.record.deleted) {
114757
+ const refreshed = newer && clean() ? await pullAssets(item.folder, item.record, before) : { ok: true, value: void 0 };
114758
+ const assets = refreshed.ok ? await pushAssets(item.folder, item.record, before) : refreshed;
114509
114759
  if (assets.ok) {
114510
114760
  writeRecord(item.folder, item.record);
114761
+ indexTask(item.folder, item.record);
114762
+ selected?.add(assetsFile(item.folder.task));
114511
114763
  continue;
114512
114764
  }
114513
114765
  if (!boardSync) return fail(assets.error, false, assets.code);
@@ -114518,12 +114770,25 @@ async function send2(ws, job) {
114518
114770
  deferredCards.add(item.folder.number);
114519
114771
  deferredLists.add(assetsFile(item.folder.task));
114520
114772
  }
114521
- proposeItems(ws, base);
114773
+ if (!ws.cloudTask) syncIndex(ws).ready = true;
114774
+ const scoped = selected && [...new Set([...selected].flatMap((p2) => {
114775
+ if (!isBoardPath(p2) && !fs20.statSync(path21.join(ws.board, p2), { throwIfNoEntry: false })?.isDirectory()) return [];
114776
+ const file2 = path21.join(ws.board, p2);
114777
+ return fs20.statSync(file2, { throwIfNoEntry: false })?.isDirectory() ? filesUnder(file2, ws.board).filter(kept2) : kept2(p2) ? [p2] : [];
114778
+ }))].filter((p2) => fs20.statSync(path21.join(ws.board, p2), { throwIfNoEntry: false })?.isFile());
114779
+ for (const p2 of scoped ?? []) rememberDirectories(syncIndex(ws).directories, p2);
114780
+ proposeItems(ws, base, scoped);
114522
114781
  const shared = sharedMemory(ws.board);
114523
- const deferred = new Set((base.deferred ?? []).filter((p2) => !boardSync && !tasks.some((item) => processed.has(item.folder.task) && !deferredCards.has(item.folder.number) && (p2 === assetsFile(item.folder.task) || numberOfCard(p2) === item.folder.number))));
114782
+ const deferred = new Set((base.deferred ?? []).filter((p2) => !tasks.some((item) => processed.has(item.folder.task) && !deferredCards.has(item.folder.number) && (p2 === assetsFile(item.folder.task) || numberOfCard(p2) === item.folder.number))));
114783
+ const retiredCards = new Set(tasks.filter((item) => item.record.deleted).map((item) => item.folder.number));
114784
+ const retiredLists = new Set(tasks.filter((item) => item.record.deleted).map((item) => assetsFile(item.folder.task)));
114524
114785
  const defer = (p2) => {
114786
+ if (retiredCards.has(numberOfCard(p2)) || retiredLists.has(p2)) {
114787
+ deferred.add(p2);
114788
+ return true;
114789
+ }
114525
114790
  if (!boardSync) return deferred.has(p2);
114526
- if (!deferredLists.has(p2) && !deferredCards.has(numberOfCard(p2) ?? 0)) return false;
114791
+ if (!deferredLists.has(p2) && !deferredCards.has(numberOfCard(p2) ?? 0)) return deferred.has(p2);
114527
114792
  deferred.add(p2);
114528
114793
  return true;
114529
114794
  };
@@ -114538,13 +114803,14 @@ async function send2(ws, job) {
114538
114803
  if (firstError && boardSync) return { ok: false, conflict: false, ...firstError, tasks: assetErrors };
114539
114804
  return { ok: true, changed };
114540
114805
  };
114541
- const local = localFiles(ws, base);
114806
+ const local = scoped ?? localFiles(ws, base);
114542
114807
  const localOf = /* @__PURE__ */ new Map();
114543
114808
  const changes = [];
114544
114809
  const owed = (p2) => !job.id && busy(ws.cwd) && itemAt(p2)?.state === "open" && !base.files[rootOf(ws) + p2];
114545
114810
  for (const p2 of local) {
114546
114811
  if (defer(p2) || owed(p2)) continue;
114547
- const content = fs19.readFileSync(path20.join(ws.board, p2), "utf8");
114812
+ if (selected && tasks.some((item) => assetFiles(item.folder, assetsListOf(item.folder, base)).has(p2))) continue;
114813
+ const content = fs20.readFileSync(path21.join(ws.board, p2), "utf8");
114548
114814
  const remote2 = remoteOf(ws, shared, p2);
114549
114815
  localOf.set(remote2, p2);
114550
114816
  const held5 = base.files[remote2];
@@ -114552,9 +114818,14 @@ async function send2(ws, job) {
114552
114818
  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");
114553
114819
  changes.push({ path: remote2, content, base_seq: held5?.seq ?? 0 });
114554
114820
  }
114555
- for (const p2 of viewOf(ws, base, shared).keys()) {
114821
+ const previous = selected ? new Set([...selected].flatMap((p2) => {
114822
+ if (base.files[remoteOf(ws, shared, p2)]) return [p2];
114823
+ if (!syncIndex(ws)?.directories.has(p2) && !fs20.statSync(path21.join(ws.board, p2), { throwIfNoEntry: false })?.isDirectory()) return [];
114824
+ return [...viewOf(ws, base, shared).keys()].filter((file2) => file2.startsWith(p2 + "/"));
114825
+ })) : viewOf(ws, base, shared).keys();
114826
+ for (const p2 of previous) {
114556
114827
  const remote2 = remoteOf(ws, shared, p2);
114557
- if (!defer(p2) && kept(p2) && !localOf.has(remote2) && base.files[remote2]) {
114828
+ if (!defer(p2) && kept2(p2) && !localOf.has(remote2) && base.files[remote2]) {
114558
114829
  localOf.set(remote2, p2);
114559
114830
  changes.push({ path: remote2, content: null, base_seq: base.files[remote2].seq });
114560
114831
  }
@@ -114572,12 +114843,22 @@ async function send2(ws, job) {
114572
114843
  continue;
114573
114844
  }
114574
114845
  const p2 = localOf.get(theirs.path) ?? theirs.path;
114575
- if (at2 >= 0 && theirs.content === null && changes[at2].content !== null && p2.startsWith("todo/") && numberOfCard(p2) !== null) {
114846
+ if (at2 >= 0 && theirs.content === null && changes[at2].content !== null && (p2.startsWith("todo/") || p2.startsWith(".archive/")) && numberOfCard(p2) !== null) {
114576
114847
  changes.splice(at2, 1);
114577
114848
  delete base.files[theirs.path];
114849
+ if (p2.startsWith(".archive/")) {
114850
+ deferred.add(p2);
114851
+ const item = tasks.find((item2) => item2.folder.number === numberOfCard(p2));
114852
+ if (item) {
114853
+ item.record.deleted = p2;
114854
+ writeRecord(item.folder, item.record);
114855
+ deferred.add(assetsFile(item.folder.task));
114856
+ }
114857
+ } else {
114858
+ fs20.rmSync(path21.join(ws.board, p2), { force: true });
114859
+ writeIndex(ws.board);
114860
+ }
114578
114861
  writeBase(ws, base);
114579
- fs19.rmSync(path20.join(ws.board, p2), { force: true });
114580
- writeIndex(ws.board);
114581
114862
  continue;
114582
114863
  }
114583
114864
  if (at2 < 0) continue;
@@ -114586,8 +114867,8 @@ async function send2(ws, job) {
114586
114867
  const merged = itemAt(p2) ? { content: theirs.content } : mergeFile(base.files[theirs.path]?.content ?? null, changes[at2].content, theirs.content);
114587
114868
  logSync("merge.end", { project: ws.project, path: p2, ms: Math.round(performance.now() - started) });
114588
114869
  changes[at2] = { path: theirs.path, content: merged.content, base_seq: theirs.seq };
114589
- if (merged.content === null) fs19.rmSync(path20.join(ws.board, p2), { force: true });
114590
- else write(path20.join(ws.board, p2), merged.content);
114870
+ if (merged.content === null) fs20.rmSync(path21.join(ws.board, p2), { force: true });
114871
+ else write(path21.join(ws.board, p2), merged.content);
114591
114872
  }
114592
114873
  if (!changes.length) return success(false);
114593
114874
  sent = await commitBoard(ws.project, job.id, job.machineId, changes);
@@ -114602,8 +114883,8 @@ async function send2(ws, job) {
114602
114883
  }
114603
114884
 
114604
114885
  // ../cli/src/lib/machine/settings.ts
114605
- import fs20 from "node:fs";
114606
- import path21 from "node:path";
114886
+ import fs21 from "node:fs";
114887
+ import path22 from "node:path";
114607
114888
 
114608
114889
  // ../cli/src/lib/machine/types.ts
114609
114890
  var LANGUAGES = ["en", "zh"];
@@ -114613,11 +114894,11 @@ function isLanguage(value) {
114613
114894
  }
114614
114895
 
114615
114896
  // ../cli/src/lib/machine/settings.ts
114616
- var settingsFile = () => path21.join(machineHome(), "settings.json");
114897
+ var settingsFile = () => path22.join(machineHome(), "settings.json");
114617
114898
  function heldSettings() {
114618
114899
  let text3;
114619
114900
  try {
114620
- text3 = fs20.readFileSync(settingsFile(), "utf8");
114901
+ text3 = fs21.readFileSync(settingsFile(), "utf8");
114621
114902
  } catch (err) {
114622
114903
  if (err.code === "ENOENT") return { unreadable: false, values: {} };
114623
114904
  return { unreadable: true, values: {} };
@@ -114676,8 +114957,8 @@ ${input.languageLine}`;
114676
114957
  }
114677
114958
 
114678
114959
  // src/flow.ts
114679
- import fs33 from "node:fs";
114680
- import path36 from "node:path";
114960
+ import fs34 from "node:fs";
114961
+ import path37 from "node:path";
114681
114962
 
114682
114963
  // ../cli/src/lib/agent/types.ts
114683
114964
  var NOT_COMPLETED = "The delivery has not recorded completion.";
@@ -115989,16 +116270,16 @@ function createKimiStreamRenderer(cwd, resumeId) {
115989
116270
  }
115990
116271
 
115991
116272
  // ../cli/src/lib/agent/wire/acp-cost.ts
115992
- import fs21 from "node:fs";
115993
- import path22 from "node:path";
116273
+ import fs22 from "node:fs";
116274
+ import path23 from "node:path";
115994
116275
  import { createHash } from "node:crypto";
115995
116276
  function acpCostFile(tool, cwd, session) {
115996
116277
  const key = createHash("sha256").update(JSON.stringify([tool, cwd, session])).digest("hex");
115997
- return path22.join(machineHome(), "usage", "acp", `${key}.json`);
116278
+ return path23.join(machineHome(), "usage", "acp", `${key}.json`);
115998
116279
  }
115999
116280
  function readAcpCost(file2) {
116000
116281
  try {
116001
- const n = JSON.parse(fs21.readFileSync(file2, "utf8"));
116282
+ const n = JSON.parse(fs22.readFileSync(file2, "utf8"));
116002
116283
  return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
116003
116284
  } catch {
116004
116285
  return void 0;
@@ -116007,16 +116288,17 @@ function readAcpCost(file2) {
116007
116288
  function saveAcpCost(file2, cost) {
116008
116289
  if (cost === void 0) return;
116009
116290
  try {
116010
- fs21.mkdirSync(path22.dirname(file2), { recursive: true, mode: 448 });
116291
+ fs22.mkdirSync(path23.dirname(file2), { recursive: true, mode: 448 });
116011
116292
  const tmp = `${file2}.${process.pid}.tmp`;
116012
- fs21.writeFileSync(tmp, JSON.stringify(cost), { mode: 384 });
116013
- fs21.renameSync(tmp, file2);
116293
+ fs22.writeFileSync(tmp, JSON.stringify(cost), { mode: 384 });
116294
+ fs22.renameSync(tmp, file2);
116014
116295
  } catch {
116015
116296
  }
116016
116297
  }
116017
116298
 
116018
116299
  // ../cli/src/lib/shared/conversation.ts
116019
116300
  var CONVERSATION_MS = { send: 15e3, claim: 3e4, prepare: 6e4, start: 15e3, startup: 12e4, quiet: 6e4, stop: 1e4 };
116301
+ var CONVERSATION_PHASES = ["preparing", "initialized", "ready", "submitted", "started"];
116020
116302
  function bounded(work, ms, reason) {
116021
116303
  return new Promise((resolve2, reject) => {
116022
116304
  const timer = setTimeout(() => reject(new Error(reason)), Math.max(0, ms));
@@ -116031,7 +116313,7 @@ function bounded(work, ms, reason) {
116031
116313
  }
116032
116314
 
116033
116315
  // ../cli/src/lib/agent/wire/acp.ts
116034
- import fs22 from "node:fs";
116316
+ import fs23 from "node:fs";
116035
116317
 
116036
116318
  // ../cli/src/lib/agent/wire/rpc.ts
116037
116319
  var RpcError = class extends Error {
@@ -116165,7 +116447,7 @@ function createTail(log) {
116165
116447
  // ../cli/package.json
116166
116448
  var package_default = {
116167
116449
  name: "wildcrane",
116168
- version: "0.11.52",
116450
+ version: "0.11.54",
116169
116451
  akbContract: 15,
116170
116452
  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.",
116171
116453
  keywords: [
@@ -116308,7 +116590,7 @@ var STOPPED = {
116308
116590
  cancelled: "the turn was cancelled"
116309
116591
  };
116310
116592
  function mcpServersIn(file2) {
116311
- const servers = obj(obj(JSON.parse(fs22.readFileSync(file2, "utf8"))).mcpServers);
116593
+ const servers = obj(obj(JSON.parse(fs23.readFileSync(file2, "utf8"))).mcpServers);
116312
116594
  return Object.entries(servers).map(([name, raw]) => {
116313
116595
  const s = obj(raw);
116314
116596
  return {
@@ -116511,7 +116793,7 @@ function decide(params, tail, events) {
116511
116793
  }
116512
116794
 
116513
116795
  // ../cli/src/lib/agent/wire/zcode.ts
116514
- import path23 from "node:path";
116796
+ import path24 from "node:path";
116515
116797
  function whereHint2(input, title) {
116516
116798
  const named = obj(input);
116517
116799
  for (const key of ["command", "file_path", "path", "url", "pattern"]) {
@@ -116677,7 +116959,7 @@ async function oneTurn2(io, options) {
116677
116959
  { stringIds: true }
116678
116960
  );
116679
116961
  try {
116680
- const workspacePath = path23.resolve(io.cwd);
116962
+ const workspacePath = path24.resolve(io.cwd);
116681
116963
  const workspace = { workspacePath, workspaceKey: workspacePath };
116682
116964
  let opened;
116683
116965
  if (io.resumeId) {
@@ -116917,7 +117199,7 @@ async function run2(io, options, tasks) {
116917
117199
  if (failure) io.event?.({ kind: "error", data: { text: failure } });
116918
117200
  resolve2({ ok: !failure, error: failure, result: renderer.result(), replyParts: renderer.replyParts?.(), usage: combinedUsage, context, costUsd, costIncomplete: child.costIncomplete || cost === void 0 && child.costUsd !== void 0 || void 0 });
116919
117201
  };
116920
- const closed = () => end("Codex closed the connection before all work and results finished.");
117202
+ const closed = () => end("Codex connection closed before all work and results finished.");
116921
117203
  io.stdout.once("close", closed);
116922
117204
  const update2 = (id, state, title = "") => {
116923
117205
  if (ended2) return;
@@ -117003,6 +117285,10 @@ async function run2(io, options, tasks) {
117003
117285
  if (ended2 || checking || active) return;
117004
117286
  checking = true;
117005
117287
  try {
117288
+ if (io.completed?.()) {
117289
+ end();
117290
+ return;
117291
+ }
117006
117292
  for (const key of tasks.running().filter((id) => id.startsWith("agent:"))) {
117007
117293
  const id = key.slice(6);
117008
117294
  let thread = obj((await rpc.call("thread/read", { threadId: id, includeTurns: false })).thread);
@@ -117168,43 +117454,43 @@ function reviewOf(meta) {
117168
117454
 
117169
117455
  // src/akb.ts
117170
117456
  import { spawn } from "node:child_process";
117171
- import fs23 from "node:fs";
117172
- import path24 from "node:path";
117457
+ import fs24 from "node:fs";
117458
+ import path25 from "node:path";
117173
117459
  import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
117174
- var akbHome = () => path24.join(runnerHome(), "bin", "akb");
117460
+ var akbHome = () => path25.join(runnerHome(), "bin", "akb");
117175
117461
  var BUNDLED_SHIM = `bundled-${AKB_VERSION}`;
117176
- var HERE = path24.dirname(fileURLToPath2(import.meta.url));
117462
+ var HERE = path25.dirname(fileURLToPath2(import.meta.url));
117177
117463
  function akbArgs(entry, dist = HERE) {
117178
- const preload = path24.join(dist, "akb-proxy.mjs");
117179
- return fs23.existsSync(preload) ? ["--import", pathToFileURL(preload).href, entry] : [entry];
117464
+ const preload = path25.join(dist, "akb-proxy.mjs");
117465
+ return fs24.existsSync(preload) ? ["--import", pathToFileURL(preload).href, entry] : [entry];
117180
117466
  }
117181
117467
  var bundledAkb = (dist = HERE) => ({
117182
117468
  command: process.execPath,
117183
- args: akbArgs(path24.join(dist, "akb", "bin", "ai4kanban.mjs"), dist),
117469
+ args: akbArgs(path25.join(dist, "akb", "bin", "ai4kanban.mjs"), dist),
117184
117470
  version: AKB_VERSION,
117185
- shim: path24.join(akbHome(), BUNDLED_SHIM)
117471
+ shim: path25.join(akbHome(), BUNDLED_SHIM)
117186
117472
  });
117187
117473
  var quote = (s) => /^[\w./:@=-]+$/.test(s) ? s : `"${s}"`;
117188
117474
  function shimDir(akb) {
117189
117475
  const dir = akb.shim;
117190
117476
  const line = [akb.command, ...akb.args].map(quote).join(" ");
117191
- const [file2, text3] = process.platform === "win32" ? [path24.join(dir, "akb.cmd"), `@${line} %*\r
117192
- `] : [path24.join(dir, "akb"), `#!/bin/sh
117477
+ const [file2, text3] = process.platform === "win32" ? [path25.join(dir, "akb.cmd"), `@${line} %*\r
117478
+ `] : [path25.join(dir, "akb"), `#!/bin/sh
117193
117479
  exec ${line} "$@"
117194
117480
  `];
117195
117481
  if (process.platform === "win32") {
117196
- fs23.mkdirSync(dir, { recursive: true });
117482
+ fs24.mkdirSync(dir, { recursive: true });
117197
117483
  const shellLine = [akb.command, ...akb.args].map((s) => `'${s.replaceAll("\\", "/").replaceAll("'", "'\\''")}'`).join(" ");
117198
- fs23.writeFileSync(path24.join(dir, "akb"), `#!/bin/sh
117484
+ fs24.writeFileSync(path25.join(dir, "akb"), `#!/bin/sh
117199
117485
  exec ${shellLine} "$@"
117200
117486
  `, { mode: 493 });
117201
117487
  }
117202
117488
  try {
117203
- if (fs23.readFileSync(file2, "utf8") === text3) return dir;
117489
+ if (fs24.readFileSync(file2, "utf8") === text3) return dir;
117204
117490
  } catch {
117205
117491
  }
117206
- fs23.mkdirSync(dir, { recursive: true });
117207
- fs23.writeFileSync(file2, text3, { mode: 493 });
117492
+ fs24.mkdirSync(dir, { recursive: true });
117493
+ fs24.writeFileSync(file2, text3, { mode: 493 });
117208
117494
  return dir;
117209
117495
  }
117210
117496
  function akbEnv(akb, board, task, language, base = process.env) {
@@ -117212,7 +117498,7 @@ function akbEnv(akb, board, task, language, base = process.env) {
117212
117498
  const dropped = ["AI4KANBAN_PREVIEW_BRIDGE", "AI4KANBAN_REPLY_APPROVAL", "AI4KANBAN_BOARD", "AI4KANBAN_TASK", "AI4KANBAN_EXECUTION", LANGUAGE_ENV, LANGUAGE_LINE_ENV, SCHEDULED_AGENTS_ENV, SESSION_COST_ENV];
117213
117499
  for (const [k2, v] of Object.entries({ ...proxyEnv(), ...base })) if (!k2.startsWith("KANBAN_") && !dropped.includes(k2)) env2[k2] = v;
117214
117500
  const key = Object.keys(env2).find((k2) => k2.toUpperCase() === "PATH") ?? "PATH";
117215
- env2[key] = [shimDir(akb), env2[key]].filter(Boolean).join(path24.delimiter);
117501
+ env2[key] = [shimDir(akb), env2[key]].filter(Boolean).join(path25.delimiter);
117216
117502
  if (Object.keys(proxyEnv()).some((k2) => !/^no_proxy$/i.test(k2)) && env2.NODE_USE_ENV_PROXY === void 0) env2.NODE_USE_ENV_PROXY = "1";
117217
117503
  env2[HOST_PROXY_ENV] = JSON.stringify(hostProxy());
117218
117504
  env2.AI4KANBAN_COMMAND = "akb";
@@ -117296,8 +117582,8 @@ function quoteArg(arg) {
117296
117582
 
117297
117583
  // ../cli/src/lib/agent/harnesses/types.ts
117298
117584
  import { createHash as createHash2 } from "node:crypto";
117299
- import fs24 from "node:fs";
117300
- import path25 from "node:path";
117585
+ import fs25 from "node:fs";
117586
+ import path26 from "node:path";
117301
117587
  var SKILL_SENTENCE = "Use the kanban skill";
117302
117588
  function namesFlag(argv, flags) {
117303
117589
  return argv.some((tok) => flags.some((flag) => tok === flag || tok.startsWith(`${flag}=`)));
@@ -117320,34 +117606,34 @@ var MCP_CONFIG = {
117320
117606
  };
117321
117607
  function machineFile(name, text3) {
117322
117608
  const suffix = createHash2("sha256").update(text3).digest("hex").slice(0, 16);
117323
- const file2 = path25.join(machineHome(), "prompts", `${path25.parse(name).name}-${suffix}${path25.extname(name)}`);
117609
+ const file2 = path26.join(machineHome(), "prompts", `${path26.parse(name).name}-${suffix}${path26.extname(name)}`);
117324
117610
  try {
117325
- if (fs24.readFileSync(file2, "utf8") === text3) return file2;
117611
+ if (fs25.readFileSync(file2, "utf8") === text3) return file2;
117326
117612
  } catch {
117327
117613
  }
117328
- fs24.mkdirSync(path25.dirname(file2), { recursive: true });
117329
- fs24.writeFileSync(file2, text3);
117614
+ fs25.mkdirSync(path26.dirname(file2), { recursive: true });
117615
+ fs25.writeFileSync(file2, text3);
117330
117616
  return file2;
117331
117617
  }
117332
117618
 
117333
117619
  // src/runtimes.ts
117334
117620
  import { spawn as spawn3 } from "node:child_process";
117335
117621
  import { randomUUID as randomUUID3 } from "node:crypto";
117336
- import fs30 from "node:fs";
117622
+ import fs31 from "node:fs";
117337
117623
  import os5 from "node:os";
117338
- import path33 from "node:path";
117624
+ import path34 from "node:path";
117339
117625
 
117340
117626
  // ../cli/src/lib/agent/harnesses/antigravity.ts
117341
- import fs27 from "node:fs";
117342
- import path28 from "node:path";
117627
+ import fs28 from "node:fs";
117628
+ import path29 from "node:path";
117343
117629
  import { createHash as createHash3 } from "node:crypto";
117344
117630
  import { spawnSync as spawnSync4 } from "node:child_process";
117345
117631
 
117346
117632
  // ../cli/src/lib/agent/locate.ts
117347
117633
  import { spawn as spawn2, spawnSync as spawnSync3 } from "node:child_process";
117348
- import fs26 from "node:fs";
117634
+ import fs27 from "node:fs";
117349
117635
  import os4 from "node:os";
117350
- import path27 from "node:path";
117636
+ import path28 from "node:path";
117351
117637
 
117352
117638
  // ../cli/src/lib/agent/installed.ts
117353
117639
  var WINDOWS2 = process.platform === "win32";
@@ -117356,8 +117642,8 @@ function commandBinary(command) {
117356
117642
  }
117357
117643
 
117358
117644
  // ../cli/src/lib/agent/spawnable.ts
117359
- import fs25 from "node:fs";
117360
- import path26 from "node:path";
117645
+ import fs26 from "node:fs";
117646
+ import path27 from "node:path";
117361
117647
  var META = /([()\][%!^"`<>&|;, *?])/g;
117362
117648
  function cmdArg(arg) {
117363
117649
  const quoted = `"${arg.replace(/\r?\n|\r/g, " ").replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1")}"`;
@@ -117367,21 +117653,21 @@ function cmdLine(file2, args2) {
117367
117653
  return `"${[file2.replace(META, "^$1"), ...args2.map(cmdArg)].join(" ")}"`;
117368
117654
  }
117369
117655
  function shimTarget(text3, file2) {
117370
- const dir = path26.win32.dirname(file2);
117656
+ const dir = path27.win32.dirname(file2);
117371
117657
  const found = /"%(?:~dp0|dp0%)\\?([^"%]+)"\s+%\*/i.exec(text3);
117372
117658
  if (!found || !/\\node\.exe"/i.test(text3)) return null;
117373
- const script = path26.win32.resolve(dir, found[1].replace(/\//g, "\\"));
117374
- const local = path26.win32.join(dir, "node.exe");
117659
+ const script = path27.win32.resolve(dir, found[1].replace(/\//g, "\\"));
117660
+ const local = path27.win32.join(dir, "node.exe");
117375
117661
  const nodePath = /SET "NODE_PATH=([^"]*)"/i.exec(text3)?.[1];
117376
- return { script, node: fs25.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
117662
+ return { script, node: fs26.existsSync(local) ? local : "node", env: nodePath ? { NODE_PATH: nodePath } : {} };
117377
117663
  }
117378
117664
  function onWindowsPath(name, env2) {
117379
117665
  const exts = (env2.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
117380
117666
  const key = Object.keys(env2).find((k2) => k2.toUpperCase() === "PATH") ?? "PATH";
117381
117667
  for (const dir of (env2[key] ?? "").split(";").filter(Boolean)) {
117382
117668
  for (const ext of exts) {
117383
- const file2 = path26.win32.join(dir, `${name}${ext.toLowerCase()}`);
117384
- if (fs25.existsSync(file2)) return file2;
117669
+ const file2 = path27.win32.join(dir, `${name}${ext.toLowerCase()}`);
117670
+ if (fs26.existsSync(file2)) return file2;
117385
117671
  }
117386
117672
  }
117387
117673
  return void 0;
@@ -117389,13 +117675,13 @@ function onWindowsPath(name, env2) {
117389
117675
  function spawnable(command, args2, options = {}, platform = process.platform) {
117390
117676
  if (platform !== "win32") return { command, args: args2, options };
117391
117677
  const env2 = options.env ?? process.env;
117392
- const file2 = path26.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env2) ?? command;
117393
- const ext = path26.extname(file2).toLowerCase();
117678
+ const file2 = path27.extname(command) || /[\\/]/.test(command) ? command : onWindowsPath(command, env2) ?? command;
117679
+ const ext = path27.extname(file2).toLowerCase();
117394
117680
  const hidden = { ...options, windowsHide: true, shell: false };
117395
117681
  if (ext !== ".cmd" && ext !== ".bat") return { command: file2, args: args2, options: hidden };
117396
117682
  let text3 = "";
117397
117683
  try {
117398
- text3 = fs25.readFileSync(file2, "utf8");
117684
+ text3 = fs26.readFileSync(file2, "utf8");
117399
117685
  } catch {
117400
117686
  }
117401
117687
  const shim = shimTarget(text3, file2);
@@ -117459,7 +117745,7 @@ function pick(copies) {
117459
117745
  }
117460
117746
  function folders(parent) {
117461
117747
  try {
117462
- return fs26.readdirSync(parent, { withFileTypes: true }).filter((one) => one.isDirectory()).map((one) => one.name);
117748
+ return fs27.readdirSync(parent, { withFileTypes: true }).filter((one) => one.isDirectory()).map((one) => one.name);
117463
117749
  } catch {
117464
117750
  return [];
117465
117751
  }
@@ -117478,29 +117764,29 @@ function byVersion(names2) {
117478
117764
  function latestIn(parent, tail = "") {
117479
117765
  let names2;
117480
117766
  try {
117481
- names2 = fs26.readdirSync(parent);
117767
+ names2 = fs27.readdirSync(parent);
117482
117768
  } catch {
117483
117769
  return [];
117484
117770
  }
117485
- return byVersion(names2.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) => path27.join(parent, name, tail));
117771
+ return byVersion(names2.filter((name) => !name.startsWith("."))).slice(0, 2).map((name) => path28.join(parent, name, tail));
117486
117772
  }
117487
117773
  var env = (name) => process.env[name]?.trim() ?? "";
117488
117774
  function commonDirs() {
117489
117775
  const home4 = os4.homedir();
117490
- const under = (...parts) => path27.join(home4, ...parts);
117491
- const nodes = (root2, tail = []) => root2 ? folders(root2).map((version) => path27.join(root2, version, ...tail)) : [];
117776
+ const under = (...parts) => path28.join(home4, ...parts);
117777
+ const nodes = (root2, tail = []) => root2 ? folders(root2).map((version) => path28.join(root2, version, ...tail)) : [];
117492
117778
  if (WINDOWS3) {
117493
117779
  const [app, local, data, programs] = [env("APPDATA"), env("LOCALAPPDATA"), env("ProgramData"), env("ProgramFiles")];
117494
117780
  return [
117495
117781
  under(".local", "bin"),
117496
117782
  under(".bun", "bin"),
117497
117783
  under("scoop", "shims"),
117498
- ...app ? [path27.join(app, "npm")] : [],
117499
- ...local ? [path27.join(local, "pnpm"), path27.join(local, "Volta", "bin"), path27.join(local, "Microsoft", "WinGet", "Links")] : [],
117500
- ...data ? [path27.join(data, "chocolatey", "bin")] : [],
117501
- ...programs ? [path27.join(programs, "nodejs")] : [],
117784
+ ...app ? [path28.join(app, "npm")] : [],
117785
+ ...local ? [path28.join(local, "pnpm"), path28.join(local, "Volta", "bin"), path28.join(local, "Microsoft", "WinGet", "Links")] : [],
117786
+ ...data ? [path28.join(data, "chocolatey", "bin")] : [],
117787
+ ...programs ? [path28.join(programs, "nodejs")] : [],
117502
117788
  ...nodes(env("NVM_HOME")),
117503
- ...app ? nodes(path27.join(app, "fnm", "node-versions"), ["installation"]) : []
117789
+ ...app ? nodes(path28.join(app, "fnm", "node-versions"), ["installation"]) : []
117504
117790
  ];
117505
117791
  }
117506
117792
  const support = process.platform === "darwin" ? under("Library", "Application Support") : under(".local", "share");
@@ -117517,10 +117803,10 @@ function commonDirs() {
117517
117803
  ...env("PNPM_HOME") ? [env("PNPM_HOME")] : [],
117518
117804
  under("Library", "pnpm"),
117519
117805
  under(".local", "share", "pnpm"),
117520
- path27.join(env("VOLTA_HOME") || under(".volta"), "bin"),
117521
- ...nodes(path27.join(env("NVM_DIR") || under(".nvm"), "versions", "node"), ["bin"]),
117522
- ...nodes(path27.join(env("FNM_DIR") || path27.join(support, "fnm"), "node-versions"), ["installation", "bin"]),
117523
- ...nodes(path27.join(env("ASDF_DATA_DIR") || under(".asdf"), "installs", "nodejs"), ["bin"]),
117806
+ path28.join(env("VOLTA_HOME") || under(".volta"), "bin"),
117807
+ ...nodes(path28.join(env("NVM_DIR") || under(".nvm"), "versions", "node"), ["bin"]),
117808
+ ...nodes(path28.join(env("FNM_DIR") || path28.join(support, "fnm"), "node-versions"), ["installation", "bin"]),
117809
+ ...nodes(path28.join(env("ASDF_DATA_DIR") || under(".asdf"), "installs", "nodejs"), ["bin"]),
117524
117810
  ...nodes(under(".local", "share", "mise", "installs", "node"), ["bin"]),
117525
117811
  ...nodes(under(".nodenv", "versions"), ["bin"]),
117526
117812
  ...nodes("/usr/local/n/versions/node", ["bin"])
@@ -117528,11 +117814,11 @@ function commonDirs() {
117528
117814
  }
117529
117815
  function onPath(binary) {
117530
117816
  const names2 = WINDOWS3 ? (process.env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).map((ext) => `${binary}${ext.toLowerCase()}`) : [binary];
117531
- return (process.env.PATH ?? "").split(path27.delimiter).filter(Boolean).flatMap((dir) => names2.map((name) => path27.join(dir, name)));
117817
+ return (process.env.PATH ?? "").split(path28.delimiter).filter(Boolean).flatMap((dir) => names2.map((name) => path28.join(dir, name)));
117532
117818
  }
117533
117819
  var isFile = (file2) => {
117534
117820
  try {
117535
- return fs26.statSync(file2).isFile();
117821
+ return fs27.statSync(file2).isFile();
117536
117822
  } catch {
117537
117823
  return false;
117538
117824
  }
@@ -117541,46 +117827,46 @@ function copyFiles(harness) {
117541
117827
  const pinned = harness.pinned?.();
117542
117828
  if (pinned && isFile(pinned)) return [{ file: pinned, entry: false }];
117543
117829
  const binary = commandBinary(harness.command);
117544
- const exe = (file2) => WINDOWS3 && !path27.extname(file2) ? [`${file2}.exe`, `${file2}.cmd`] : [file2];
117830
+ const exe = (file2) => WINDOWS3 && !path28.extname(file2) ? [`${file2}.exe`, `${file2}.cmd`] : [file2];
117545
117831
  const path_ = onPath(binary).filter(isFile);
117546
- const elsewhere = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) => path27.join(dir, binary))];
117832
+ const elsewhere = process.env.AI4KANBAN_PATH_ONLY ? [] : [...harness.installs?.() ?? [], ...commonDirs().map((dir) => path28.join(dir, binary))];
117547
117833
  const others = elsewhere.flatMap(exe).filter(isFile);
117548
117834
  const seen = /* @__PURE__ */ new Set();
117549
117835
  return [...path_, ...others].flatMap((file2, i) => {
117550
- const real = fs26.realpathSync.native(file2);
117836
+ const real = fs27.realpathSync.native(file2);
117551
117837
  if (seen.has(real)) return [];
117552
117838
  seen.add(real);
117553
117839
  return [{ file: file2, entry: i === 0 && path_.length > 0 }];
117554
117840
  });
117555
117841
  }
117556
117842
  var answers;
117557
- var answersFile = () => path27.join(machineHome(), "agent-copies.json");
117558
- function kept2() {
117843
+ var answersFile = () => path28.join(machineHome(), "agent-copies.json");
117844
+ function kept3() {
117559
117845
  if (answers) return answers;
117560
117846
  try {
117561
- answers = JSON.parse(fs26.readFileSync(answersFile(), "utf8"));
117847
+ answers = JSON.parse(fs27.readFileSync(answersFile(), "utf8"));
117562
117848
  } catch {
117563
117849
  answers = {};
117564
117850
  }
117565
117851
  return answers;
117566
117852
  }
117567
117853
  function keep(file2, answer) {
117568
- kept2()[file2] = answer;
117854
+ kept3()[file2] = answer;
117569
117855
  try {
117570
- fs26.mkdirSync(machineHome(), { recursive: true });
117856
+ fs27.mkdirSync(machineHome(), { recursive: true });
117571
117857
  const staged = `${answersFile()}.${process.pid}`;
117572
- fs26.writeFileSync(staged, JSON.stringify(answers));
117573
- fs26.renameSync(staged, answersFile());
117858
+ fs27.writeFileSync(staged, JSON.stringify(answers));
117859
+ fs27.renameSync(staged, answersFile());
117574
117860
  } catch {
117575
117861
  }
117576
117862
  }
117577
117863
  function keyOf(file2) {
117578
- const real = fs26.realpathSync.native(file2);
117579
- const stat = fs26.statSync(real);
117864
+ const real = fs27.realpathSync.native(file2);
117865
+ const stat = fs27.statSync(real);
117580
117866
  return `${real}|${stat.size}|${stat.mtimeMs}`;
117581
117867
  }
117582
117868
  function known(file2, maxAge) {
117583
- const answer = kept2()[file2];
117869
+ const answer = kept3()[file2];
117584
117870
  return answer && answer.key === keyOf(file2) && Date.now() - answer.at < maxAge ? answer : void 0;
117585
117871
  }
117586
117872
  function judge(code, status, stdout, stderr) {
@@ -117589,8 +117875,8 @@ function judge(code, status, stdout, stderr) {
117589
117875
  return { starts: true, version: status === 0 ? versionIn(stdout) ?? versionIn(stderr) : null };
117590
117876
  }
117591
117877
  function copyEnv(file2, given = process.env) {
117592
- if (!path27.isAbsolute(file2)) return given;
117593
- return { ...given, PATH: [path27.dirname(file2), given.PATH].filter(Boolean).join(path27.delimiter) };
117878
+ if (!path28.isAbsolute(file2)) return given;
117879
+ return { ...given, PATH: [path28.dirname(file2), given.PATH].filter(Boolean).join(path28.delimiter) };
117594
117880
  }
117595
117881
  var probeOptions = (file2) => ({ cwd: os4.tmpdir(), env: copyEnv(file2), windowsHide: true, shell: false });
117596
117882
  function probe(file2) {
@@ -117847,7 +118133,7 @@ function antigravityModels(output2) {
117847
118133
  }
117848
118134
  function args(argv, resume) {
117849
118135
  if (namesFlag(argv, ["--continue", "-c", "--conversation", "--remote-agent"])) throw new Error(translating() ? "\u8BF7\u901A\u8FC7 WildCrane \u9009\u62E9 Antigravity \u4F1A\u8BDD\uFF0C\u4E0D\u8981\u5728\u989D\u5916\u53C2\u6570\u4E2D\u6307\u5B9A\u4F1A\u8BDD\u6216\u8FDC\u7A0B\u6267\u884C\u3002" : "Antigravity: select a session through WildCrane, not extra arguments.");
117850
- if (resume && (!/^[a-f0-9-]{36}$/i.test(resume) || !fs27.existsSync(home2(".gemini", "antigravity-cli", "conversations", `${resume}.db`)))) throw new Error(translating() ? "Antigravity \u4F1A\u8BDD\u4E0D\u5B58\u5728\u3002\u8BF7\u5728\u672C\u673A\u6062\u590D\u539F\u4F1A\u8BDD\u540E\u7EED\u63A5\u3002" : "Antigravity session not found. Restore the original conversation on this computer before resuming.");
118136
+ if (resume && (!/^[a-f0-9-]{36}$/i.test(resume) || !fs28.existsSync(home2(".gemini", "antigravity-cli", "conversations", `${resume}.db`)))) throw new Error(translating() ? "Antigravity \u4F1A\u8BDD\u4E0D\u5B58\u5728\u3002\u8BF7\u5728\u672C\u673A\u6062\u590D\u539F\u4F1A\u8BDD\u540E\u7EED\u63A5\u3002" : "Antigravity session not found. Restore the original conversation on this computer before resuming.");
117851
118137
  const extra = resume ? ["--conversation", resume] : [];
117852
118138
  if (!namesFlag(argv, ["--output-format"])) extra.push("--output-format", "stream-json");
117853
118139
  if (!namesFlag(argv, ["--dangerously-skip-permissions"])) extra.push("--dangerously-skip-permissions");
@@ -117888,10 +118174,10 @@ var ANTIGRAVITY = {
117888
118174
 
117889
118175
  The task working directory is ${env2.PWD ?? process.cwd()}. Use it as the base for project files and commands. This additional workspace contains only language rules; do not write task output here.`;
117890
118176
  const hash = createHash3("sha256").update(rule).digest("hex").slice(0, 16);
117891
- const root2 = path28.join(machineHome(), "prompts", `antigravity-${hash}`);
117892
- const file2 = path28.join(root2, ".agents", "rules", "language.md");
117893
- fs27.mkdirSync(path28.dirname(file2), { recursive: true });
117894
- fs27.writeFileSync(file2, `---
118177
+ const root2 = path29.join(machineHome(), "prompts", `antigravity-${hash}`);
118178
+ const file2 = path29.join(root2, ".agents", "rules", "language.md");
118179
+ fs28.mkdirSync(path29.dirname(file2), { recursive: true });
118180
+ fs28.writeFileSync(file2, `---
117895
118181
  trigger: always_on
117896
118182
  ---
117897
118183
 
@@ -117994,7 +118280,7 @@ function checkHarnesses(harnesses) {
117994
118280
  }
117995
118281
 
117996
118282
  // ../cli/src/lib/agent/harnesses/claude-code.ts
117997
- import path29 from "node:path";
118283
+ import path30 from "node:path";
117998
118284
 
117999
118285
  // ../cli/src/lib/agent/harnesses/transient.ts
118000
118286
  var MANUAL = [
@@ -118053,15 +118339,15 @@ var userMessage = (prompt) => `${JSON.stringify({ type: "user", message: { role:
118053
118339
  `;
118054
118340
  function claudeOnWindows() {
118055
118341
  const [local, roaming] = [process.env.LOCALAPPDATA?.trim(), process.env.APPDATA?.trim()];
118056
- const packages = local ? path29.join(local, "Packages") : "";
118342
+ const packages = local ? path30.join(local, "Packages") : "";
118057
118343
  const data = [
118058
- ...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) => path29.join(packages, name, "LocalCache", "Roaming", "Claude")),
118059
- ...roaming ? [path29.join(roaming, "Claude")] : []
118344
+ ...folders(packages).filter((name) => /^(\w+\.)?Claude_/i.test(name)).sort().map((name) => path30.join(packages, name, "LocalCache", "Roaming", "Claude")),
118345
+ ...roaming ? [path30.join(roaming, "Claude")] : []
118060
118346
  ];
118061
118347
  return data.flatMap(
118062
- (dir) => latestIn(path29.join(dir, "claude-code")).flatMap((version) => [
118063
- path29.join(version, "claude.exe"),
118064
- ...folders(version).map((build) => path29.join(version, build, "claude.exe"))
118348
+ (dir) => latestIn(path30.join(dir, "claude-code")).flatMap((version) => [
118349
+ path30.join(version, "claude.exe"),
118350
+ ...folders(version).map((build) => path30.join(version, build, "claude.exe"))
118065
118351
  ])
118066
118352
  );
118067
118353
  }
@@ -118319,15 +118605,15 @@ var CLAUDE_CODE = {
118319
118605
  ...latestIn(home2(".local", "share", "claude", "versions")),
118320
118606
  // The copy Claude Desktop carries.
118321
118607
  ...process.platform === "win32" ? claudeOnWindows() : latestIn(home2("Library", "Application Support", "Claude", "claude-code")).flatMap(
118322
- (version) => folders(version).map((build) => path29.join(version, build, "claude.app", "Contents", "MacOS", "claude"))
118608
+ (version) => folders(version).map((build) => path30.join(version, build, "claude.app", "Contents", "MacOS", "claude"))
118323
118609
  )
118324
118610
  ],
118325
118611
  install: "npm install -g @anthropic-ai/claude-code"
118326
118612
  };
118327
118613
 
118328
118614
  // ../cli/src/lib/agent/harnesses/codex.ts
118329
- import fs28 from "node:fs";
118330
- import path30 from "node:path";
118615
+ import fs29 from "node:fs";
118616
+ import path31 from "node:path";
118331
118617
 
118332
118618
  // ../cli/src/lib/agent/worktree.ts
118333
118619
  import { spawnSync as spawnSync5 } from "node:child_process";
@@ -118374,10 +118660,10 @@ function codexExtraArgs(argv, cwd = REPO_ROOT) {
118374
118660
  }
118375
118661
  const flags = [...argv, ...extra];
118376
118662
  const workspaceWrite = flags.some((arg, i) => arg === "--full-auto" || arg === "--sandbox=workspace-write" || (arg === "--sandbox" || arg === "-s") && flags[i + 1] === "workspace-write");
118377
- if (workspaceWrite && path30.resolve(cwd) !== path30.resolve(REPO_ROOT)) {
118663
+ if (workspaceWrite && path31.resolve(cwd) !== path31.resolve(REPO_ROOT)) {
118378
118664
  for (const dir of [KANBAN, AKB_DIR]) {
118379
- const relative = path30.relative(cwd, dir);
118380
- if (relative === ".." || relative.startsWith(`..${path30.sep}`) || path30.isAbsolute(relative)) {
118665
+ const relative = path31.relative(cwd, dir);
118666
+ if (relative === ".." || relative.startsWith(`..${path31.sep}`) || path31.isAbsolute(relative)) {
118381
118667
  extra.push("--add-dir", dir);
118382
118668
  }
118383
118669
  }
@@ -118400,7 +118686,7 @@ function envRoot(name) {
118400
118686
  }
118401
118687
  function modified(file2) {
118402
118688
  try {
118403
- return fs28.statSync(file2).mtimeMs;
118689
+ return fs29.statSync(file2).mtimeMs;
118404
118690
  } catch {
118405
118691
  return 0;
118406
118692
  }
@@ -118426,28 +118712,28 @@ function codexOnWindows() {
118426
118712
  const local = envRoot("LOCALAPPDATA");
118427
118713
  const profile = envRoot("USERPROFILE");
118428
118714
  const programs = envRoot("ProgramFiles");
118429
- const cache = local ? path30.join(local, "OpenAI", "Codex", "bin") : "";
118430
- const releases = profile ? path30.join(profile, ".codex", "packages", "standalone", "releases") : "";
118431
- const packages = programs ? path30.join(programs, "WindowsApps") : "";
118715
+ const cache = local ? path31.join(local, "OpenAI", "Codex", "bin") : "";
118716
+ const releases = profile ? path31.join(profile, ".codex", "packages", "standalone", "releases") : "";
118717
+ const packages = programs ? path31.join(programs, "WindowsApps") : "";
118432
118718
  return [
118433
118719
  // Desktop's relocated CLI cache: a folder per build hash, newest file first.
118434
- ...byNewest(folders(cache).map((name) => path30.join(cache, name, "codex.exe"))),
118720
+ ...byNewest(folders(cache).map((name) => path31.join(cache, name, "codex.exe"))),
118435
118721
  // The separate standalone launcher, at a path with nothing variable in it.
118436
- ...local ? [path30.join(local, "Programs", "OpenAI", "Codex", "bin", "codex.exe")] : [],
118722
+ ...local ? [path31.join(local, "Programs", "OpenAI", "Codex", "bin", "codex.exe")] : [],
118437
118723
  // That launcher's release payload: a folder per version and target.
118438
118724
  ...byVersion(folders(releases).filter(ourArch)).map(
118439
- (name) => path30.join(releases, name, "bin", "codex.exe")
118725
+ (name) => path31.join(releases, name, "bin", "codex.exe")
118440
118726
  ),
118441
118727
  // Desktop's own MSIX package.
118442
118728
  ...byVersion(folders(packages).filter((name) => name.startsWith("OpenAI.Codex_")).filter(ourArch)).map(
118443
- (name) => path30.join(packages, name, "app", "resources", "codex.exe")
118729
+ (name) => path31.join(packages, name, "app", "resources", "codex.exe")
118444
118730
  )
118445
118731
  ];
118446
118732
  }
118447
118733
  function codexInstalls() {
118448
118734
  const chosen = process.env.CODEX_INSTALL_DIR?.trim();
118449
118735
  return [
118450
- ...chosen ? [path30.join(chosen, "codex")] : [],
118736
+ ...chosen ? [path31.join(chosen, "codex")] : [],
118451
118737
  ...process.platform === "win32" ? codexOnWindows() : [
118452
118738
  // macOS, where Codex now lives in the merged app — `codex-cli/bin/` since 26.928…
118453
118739
  "/Applications/ChatGPT.app/Contents/Resources/codex-cli/bin/codex",
@@ -118493,7 +118779,7 @@ var CODEX = {
118493
118779
  systemPrompt(text3, argv) {
118494
118780
  if (namesFlag(argv, ["developer_instructions", "model_instructions_file"])) return {};
118495
118781
  try {
118496
- const config = fs28.readFileSync(path30.join(process.env.CODEX_HOME || home2(".codex"), "config.toml"), "utf8");
118782
+ const config = fs29.readFileSync(path31.join(process.env.CODEX_HOME || home2(".codex"), "config.toml"), "utf8");
118497
118783
  if (/^\s*(?:developer_instructions|model_instructions_file)\s*=/m.test(config)) return {};
118498
118784
  } catch {
118499
118785
  }
@@ -118739,24 +119025,24 @@ var CURSOR = {
118739
119025
  };
118740
119026
 
118741
119027
  // ../cli/src/lib/agent/harnesses/dsh.ts
118742
- import fs29 from "node:fs";
118743
- import path31 from "node:path";
119028
+ import fs30 from "node:fs";
119029
+ import path32 from "node:path";
118744
119030
  function dshHome(argv) {
118745
119031
  const binary = argv[0];
118746
119032
  if (!binary) return void 0;
118747
- const names2 = process.platform === "win32" && !path31.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
118748
- const candidates = binary.includes("/") || binary.includes("\\") ? names2 : (process.env.PATH ?? "").split(path31.delimiter).filter(Boolean).flatMap((dir2) => names2.map((name) => path31.join(dir2, name)));
119033
+ const names2 = process.platform === "win32" && !path32.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
119034
+ const candidates = binary.includes("/") || binary.includes("\\") ? names2 : (process.env.PATH ?? "").split(path32.delimiter).filter(Boolean).flatMap((dir2) => names2.map((name) => path32.join(dir2, name)));
118749
119035
  let dir;
118750
119036
  try {
118751
- const found = candidates.find((candidate) => fs29.existsSync(candidate));
119037
+ const found = candidates.find((candidate) => fs30.existsSync(candidate));
118752
119038
  if (!found) return void 0;
118753
- const script = /\.cmd$/i.test(found) ? shimTarget(fs29.readFileSync(found, "utf8"), found)?.script : void 0;
118754
- dir = path31.dirname(fs29.realpathSync(script ?? found));
119039
+ const script = /\.cmd$/i.test(found) ? shimTarget(fs30.readFileSync(found, "utf8"), found)?.script : void 0;
119040
+ dir = path32.dirname(fs30.realpathSync(script ?? found));
118755
119041
  } catch {
118756
119042
  return void 0;
118757
119043
  }
118758
- for (let up = path31.dirname(dir); dir !== up; up = path31.dirname(dir)) {
118759
- if (fs29.existsSync(path31.join(dir, "package.json"))) return dir;
119044
+ for (let up = path32.dirname(dir); dir !== up; up = path32.dirname(dir)) {
119045
+ if (fs30.existsSync(path32.join(dir, "package.json"))) return dir;
118760
119046
  dir = up;
118761
119047
  }
118762
119048
  return void 0;
@@ -119365,7 +119651,7 @@ var DEFAULT_HARNESS = HARNESSES[0];
119365
119651
  checkHarnesses(HARNESSES);
119366
119652
 
119367
119653
  // ../cli/src/lib/agent/run-settings.ts
119368
- import path32 from "node:path";
119654
+ import path33 from "node:path";
119369
119655
 
119370
119656
  // ../cli/src/lib/agent/providers.ts
119371
119657
  function providerSetting(settings) {
@@ -119468,7 +119754,7 @@ function languageEnv(given) {
119468
119754
  try {
119469
119755
  const config = JSON.parse(env2.OPENCODE_CONFIG_CONTENT ?? "{}");
119470
119756
  if (Array.isArray(config.instructions)) {
119471
- config.instructions = config.instructions.filter((file2) => typeof file2 !== "string" || path32.dirname(file2) !== path32.join(machineHome(), "prompts") || !/^opencode-language(?:-[a-f0-9]{16})?\.md$/.test(path32.basename(file2)));
119757
+ config.instructions = config.instructions.filter((file2) => typeof file2 !== "string" || path33.dirname(file2) !== path33.join(machineHome(), "prompts") || !/^opencode-language(?:-[a-f0-9]{16})?\.md$/.test(path33.basename(file2)));
119472
119758
  env2.OPENCODE_CONFIG_CONTENT = JSON.stringify(config);
119473
119759
  }
119474
119760
  } catch {
@@ -119484,7 +119770,7 @@ function withSystemLanguage(harness, argv, env2, language) {
119484
119770
  const note = language === "zh" ? "\u8BED\u8A00\u89C4\u5219\u672A\u80FD\u66F4\u65B0\uFF1A\u8FDE\u63A5\u5668\u3001\u5DF2\u6709\u4F1A\u8BDD\u6216\u81EA\u8BBE\u7CFB\u7EDF\u63D0\u793A\u8BCD\u4E0D\u652F\u6301\u6CE8\u5165\u3002\u8BF7\u81EA\u884C\u53E6\u5F00\u652F\u6301\u7684\u4F1A\u8BDD\u4EE5\u91C7\u7528\u65B0\u89C4\u5219\u3002" : "Language rules could not be updated: the connector, existing session, or custom system prompt prevents injection. Open a supported new session to apply them.";
119485
119771
  return { argv, env: env2, note };
119486
119772
  }
119487
- const at2 = /^node(?:\.exe)?$/.test(path32.basename(argv[0])) && argv[1] && !argv[1].startsWith("-") ? 2 : 1;
119773
+ const at2 = /^node(?:\.exe)?$/.test(path33.basename(argv[0])) && argv[1] && !argv[1].startsWith("-") ? 2 : 1;
119488
119774
  return { argv: [...argv.slice(0, at2), ...added?.args ?? [], ...argv.slice(at2)], env: { ...env2, ...added?.env } };
119489
119775
  }
119490
119776
 
@@ -119596,14 +119882,14 @@ var listed = (harness) => async () => (harness.models?.() ?? []).map((id) => ({
119596
119882
  var readModels = (name) => (MODELS[name] ?? listed(HARNESSES2[name]))().catch(() => []);
119597
119883
  var MODELS = {
119598
119884
  "claude-code": async () => {
119599
- const cached2 = claudeModels(path33.join(process.env.CLAUDE_CONFIG_DIR || path33.join(os5.homedir(), ".claude"), "cache", "model-catalog"));
119885
+ const cached2 = claudeModels(path34.join(process.env.CLAUDE_CONFIG_DIR || path34.join(os5.homedir(), ".claude"), "cache", "model-catalog"));
119600
119886
  return cached2.length ? cached2 : [
119601
119887
  { id: "opus", name: "Opus" },
119602
119888
  { id: "sonnet", name: "Sonnet" },
119603
119889
  { id: "haiku", name: "Haiku" }
119604
119890
  ];
119605
119891
  },
119606
- codex: async () => codexModels(path33.join(process.env.CODEX_HOME || path33.join(os5.homedir(), ".codex"), "models_cache.json")),
119892
+ codex: async () => codexModels(path34.join(process.env.CODEX_HOME || path34.join(os5.homedir(), ".codex"), "models_cache.json")),
119607
119893
  opencode: async () => opencodeModels(await output(commandOf(HARNESSES2.opencode)[0], ["models"])),
119608
119894
  cursor: () => cursorModels(),
119609
119895
  antigravity: async () => antigravityModels(await output(commandOf(HARNESSES2.antigravity)[0], ["models"]))
@@ -119663,7 +119949,7 @@ function output(command, args2) {
119663
119949
  }
119664
119950
  function codexModels(file2) {
119665
119951
  try {
119666
- const cache = JSON.parse(fs30.readFileSync(file2, "utf8"));
119952
+ const cache = JSON.parse(fs31.readFileSync(file2, "utf8"));
119667
119953
  if (!Array.isArray(cache.models)) return [];
119668
119954
  return cache.models.flatMap(
119669
119955
  (m) => m.visibility === "list" && typeof m.slug === "string" && m.slug ? [{ id: m.slug, name: typeof m.display_name === "string" && m.display_name ? m.display_name : m.slug }] : []
@@ -119675,13 +119961,13 @@ function codexModels(file2) {
119675
119961
  function claudeModels(dir) {
119676
119962
  let files;
119677
119963
  try {
119678
- files = fs30.readdirSync(dir).filter((f2) => f2.endsWith(".json"));
119964
+ files = fs31.readdirSync(dir).filter((f2) => f2.endsWith(".json"));
119679
119965
  } catch {
119680
119966
  return [];
119681
119967
  }
119682
119968
  const catalogs = files.flatMap((f2) => {
119683
119969
  try {
119684
- const data = obj(JSON.parse(fs30.readFileSync(path33.join(dir, f2), "utf8")));
119970
+ const data = obj(JSON.parse(fs31.readFileSync(path34.join(dir, f2), "utf8")));
119685
119971
  const catalog = obj(data.catalog);
119686
119972
  const surface = str2(catalog.surface);
119687
119973
  return surface === "cc" || surface === "ccd" ? [{ surface, at: Number(data.fetchedAt) || 0, config: obj(catalog.config) }] : [];
@@ -119727,8 +120013,8 @@ function probeLogin(binary, harness) {
119727
120013
  }
119728
120014
 
119729
120015
  // src/triage.ts
119730
- import fs31 from "node:fs";
119731
- import path34 from "node:path";
120016
+ import fs32 from "node:fs";
120017
+ import path35 from "node:path";
119732
120018
 
119733
120019
  // ../cli/src/lib/signals/identity.ts
119734
120020
  import { createHash as createHash4 } from "node:crypto";
@@ -119742,8 +120028,8 @@ function slugify(s) {
119742
120028
  }
119743
120029
 
119744
120030
  // src/triage.ts
119745
- var triageDir = (board) => path34.join(board, "triage");
119746
- var rejectedDir = (board) => path34.join(board, ".archive", REJECTIONS_TO_REVIEW);
120031
+ var triageDir = (board) => path35.join(board, "triage");
120032
+ var rejectedDir = (board) => path35.join(board, ".archive", REJECTIONS_TO_REVIEW);
119747
120033
  var SCRATCH = ["dismissed", "archived"];
119748
120034
  var stamp2 = (at2) => formatStamp(at2 ? new Date(at2) : /* @__PURE__ */ new Date());
119749
120035
  function slugOf(title) {
@@ -119752,7 +120038,7 @@ function slugOf(title) {
119752
120038
  function freeName(dir, title) {
119753
120039
  const stem = slugOf(title);
119754
120040
  let name = `${stem}.md`;
119755
- for (let n = 2; fs31.existsSync(path34.join(dir, name)); n++) name = `${stem}-${n}.md`;
120041
+ for (let n = 2; fs32.existsSync(path35.join(dir, name)); n++) name = `${stem}-${n}.md`;
119756
120042
  return name;
119757
120043
  }
119758
120044
  function itemText(item, fields = {}) {
@@ -119772,17 +120058,17 @@ ${item.text.trim()}
119772
120058
  `;
119773
120059
  }
119774
120060
  function writeItem(dir, item, fields = {}) {
119775
- fs31.mkdirSync(dir, { recursive: true });
120061
+ fs32.mkdirSync(dir, { recursive: true });
119776
120062
  const name = freeName(dir, item.title);
119777
- fs31.writeFileSync(path34.join(dir, name), itemText(item, item.studio ? { studio: studioName(item.studio), ...fields } : fields));
120063
+ fs32.writeFileSync(path35.join(dir, name), itemText(item, item.studio ? { studio: studioName(item.studio), ...fields } : fields));
119778
120064
  return name;
119779
120065
  }
119780
120066
  function layOut(board, rejections) {
119781
120067
  clearLaid(board);
119782
120068
  const dir = rejectedDir(board);
119783
- fs31.mkdirSync(dir, { recursive: true });
120069
+ fs32.mkdirSync(dir, { recursive: true });
119784
120070
  for (const t of rejections.tasks) {
119785
- fs31.writeFileSync(path34.join(dir, `${t.number}-${slugify(t.title)}.md`), [
120071
+ fs32.writeFileSync(path35.join(dir, `${t.number}-${slugify(t.title)}.md`), [
119786
120072
  "---",
119787
120073
  `title: ${yamlScalar(t.title)}`,
119788
120074
  "status: todo",
@@ -119797,25 +120083,25 @@ function layOut(board, rejections) {
119797
120083
  ].join("\n"));
119798
120084
  }
119799
120085
  for (const item of rejections.triage) {
119800
- const sub = path34.join(triageDir(board), item.state === "dismissed" ? "dismissed" : "archived");
120086
+ const sub = path35.join(triageDir(board), item.state === "dismissed" ? "dismissed" : "archived");
119801
120087
  const fields = item.state === "dismissed" ? { dismissed_at: stamp2(item.dismissed_at), dismissed_by: "user", ...item.dismissed_reason ? { dismissed_reason: item.dismissed_reason } : {} } : {};
119802
120088
  writeItem(sub, item, fields);
119803
120089
  }
119804
120090
  return { tasks: rejections.tasks.map((t) => t.id), triage: rejections.triage.map((i) => i.id) };
119805
120091
  }
119806
120092
  function clearLaid(board) {
119807
- fs31.rmSync(rejectedDir(board), { recursive: true, force: true });
119808
- for (const sub of SCRATCH) fs31.rmSync(path34.join(triageDir(board), sub), { recursive: true, force: true });
120093
+ fs32.rmSync(rejectedDir(board), { recursive: true, force: true });
120094
+ for (const sub of SCRATCH) fs32.rmSync(path35.join(triageDir(board), sub), { recursive: true, force: true });
119809
120095
  }
119810
120096
 
119811
120097
  // ../cli/src/lib/skill/hook.ts
119812
120098
  import { spawnSync as spawnSync6 } from "node:child_process";
119813
- import fs32 from "node:fs";
119814
- import path35 from "node:path";
120099
+ import fs33 from "node:fs";
120100
+ import path36 from "node:path";
119815
120101
  var MARKER_LINE = /^# ai4kanban commit guard\b/m;
119816
120102
  var read2 = (file2) => {
119817
120103
  try {
119818
- return fs32.readFileSync(file2, "utf8");
120104
+ return fs33.readFileSync(file2, "utf8");
119819
120105
  } catch {
119820
120106
  return null;
119821
120107
  }
@@ -119827,15 +120113,15 @@ function hooksDir(root2) {
119827
120113
  windowsHide: true
119828
120114
  });
119829
120115
  if (out.error || out.status !== 0 || !out.stdout.trim()) return null;
119830
- return path35.resolve(root2, out.stdout.trim());
120116
+ return path36.resolve(root2, out.stdout.trim());
119831
120117
  }
119832
120118
  function installCommitHook(root2, _board) {
119833
120119
  const dir = hooksDir(root2);
119834
120120
  if (!dir) return {};
119835
- const file2 = path35.join(dir, "pre-commit");
119836
- if (fs32.lstatSync(file2, { throwIfNoEntry: false })?.isSymbolicLink()) return {};
120121
+ const file2 = path36.join(dir, "pre-commit");
120122
+ if (fs33.lstatSync(file2, { throwIfNoEntry: false })?.isSymbolicLink()) return {};
119837
120123
  const source = read2(file2);
119838
- if (source && MARKER_LINE.test(source)) fs32.unlinkSync(file2);
120124
+ if (source && MARKER_LINE.test(source)) fs33.unlinkSync(file2);
119839
120125
  return {};
119840
120126
  }
119841
120127
 
@@ -119872,7 +120158,7 @@ function runtimeCosts(runs, job) {
119872
120158
  }
119873
120159
  function reviewOf2(file2) {
119874
120160
  try {
119875
- const meta = parseFrontmatter(fs33.readFileSync(file2, "utf8")).meta;
120161
+ const meta = parseFrontmatter(fs34.readFileSync(file2, "utf8")).meta;
119876
120162
  return meta ? reviewOf(meta) : null;
119877
120163
  } catch {
119878
120164
  return null;
@@ -119880,15 +120166,15 @@ function reviewOf2(file2) {
119880
120166
  }
119881
120167
  function asks(file2) {
119882
120168
  try {
119883
- return (parseFrontmatter(fs33.readFileSync(file2, "utf8")).meta?.questions ?? []).length > 0;
120169
+ return (parseFrontmatter(fs34.readFileSync(file2, "utf8")).meta?.questions ?? []).length > 0;
119884
120170
  } catch {
119885
120171
  return false;
119886
120172
  }
119887
120173
  }
119888
120174
  function mcpConfig(servers, file2) {
119889
120175
  if (!Object.keys(servers).length) return null;
119890
- fs33.mkdirSync(path36.dirname(file2), { recursive: true });
119891
- fs33.writeFileSync(file2, `${JSON.stringify({ mcpServers: servers }, null, 2)}
120176
+ fs34.mkdirSync(path37.dirname(file2), { recursive: true });
120177
+ fs34.writeFileSync(file2, `${JSON.stringify({ mcpServers: servers }, null, 2)}
119892
120178
  `);
119893
120179
  return file2;
119894
120180
  }
@@ -119922,7 +120208,7 @@ function deliveryEnding(ws, id, asked = false) {
119922
120208
  if (!id) return null;
119923
120209
  let held5;
119924
120210
  try {
119925
- held5 = JSON.parse(fs33.readFileSync(path36.join(ws.board, "deliveries", `${path36.basename(id)}.json`), "utf8"));
120211
+ held5 = JSON.parse(fs34.readFileSync(path37.join(ws.board, "deliveries", `${path37.basename(id)}.json`), "utf8"));
119926
120212
  } catch {
119927
120213
  return null;
119928
120214
  }
@@ -119934,16 +120220,16 @@ function deliveryEnding(ws, id, asked = false) {
119934
120220
  return null;
119935
120221
  }
119936
120222
  function checkoutsOf(ws, id) {
119937
- const dir = path36.join(ws.board, "deliveries");
120223
+ const dir = path37.join(ws.board, "deliveries");
119938
120224
  let names2;
119939
120225
  try {
119940
- names2 = fs33.readdirSync(dir).filter((n) => n.endsWith(".json"));
120226
+ names2 = fs34.readdirSync(dir).filter((n) => n.endsWith(".json"));
119941
120227
  } catch {
119942
120228
  return [];
119943
120229
  }
119944
120230
  return names2.flatMap((n) => {
119945
120231
  try {
119946
- const held5 = JSON.parse(fs33.readFileSync(path36.join(dir, n), "utf8"));
120232
+ const held5 = JSON.parse(fs34.readFileSync(path37.join(dir, n), "utf8"));
119947
120233
  return held5.cardId === id && held5.deliveryId ? [held5.deliveryId] : [];
119948
120234
  } catch {
119949
120235
  return [];
@@ -119957,7 +120243,7 @@ var RESUME_REFUSED = {
119957
120243
  deliveryRunGoing: "\u4E0A\u6B21\u7684\u8FD0\u884C\u8FD8\u6CA1\u505C\u4E0B\uFF0C\u8BF7\u7A0D\u540E\u518D\u70B9\u300C\u7EED\u8DD1\u300D\u3002",
119958
120244
  deliveryCardGone: "\u8FD9\u5F20\u5361\u5DF2\u4E0D\u5728\u770B\u677F\u4E0A\uFF0C\u6CA1\u6709\u53EF\u7EED\u8DD1\u7684\u5185\u5BB9\uFF0C\u8BF7\u70B9\u300C\u91CD\u65B0\u53D1\u8D77\u300D\u3002"
119959
120245
  };
119960
- var isArchived = (ws, id) => path36.relative(ws.board, findCard(ws.board, id) ?? ws.board).split(path36.sep)[0] === ".archive";
120246
+ var isArchived = (ws, id) => path37.relative(ws.board, findCard(ws.board, id) ?? ws.board).split(path37.sep)[0] === ".archive";
119961
120247
  var refusal2 = (ran) => ran.last.replace(/^akb( raw)?: /, "").slice(0, 300) || "akb stopped with an error.";
119962
120248
  var reasonOf = (text3) => (text3 ?? "").split("\n").map((l2) => l2.trim()).filter((l2) => l2 && !/^at\s/.test(l2)).join("\n").slice(0, 300) || void 0;
119963
120249
  function logLines(show, event2) {
@@ -120027,7 +120313,7 @@ async function setUp(job, ws, deps, io) {
120027
120313
  const runtime = job.runtime;
120028
120314
  const missing = unavailable(runtime, await deps.runtimes());
120029
120315
  if (missing) return missing;
120030
- if (!fs33.existsSync(path36.join(ws.board, "config.md"))) {
120316
+ if (!fs34.existsSync(path37.join(ws.board, "config.md"))) {
120031
120317
  const init = await akb(["raw", "init"]);
120032
120318
  if (init.code !== 0) return refusal2(init);
120033
120319
  }
@@ -120044,7 +120330,7 @@ async function setUp(job, ws, deps, io) {
120044
120330
  const used = await akb(["raw", "agent", "use", runtime]);
120045
120331
  if (used.code !== 0) return refusal2(used);
120046
120332
  const servers = mcpServersOf(ws);
120047
- const mcpFile = path36.join(ws.board, ".sync", `${ws.task}.mcp.json`);
120333
+ const mcpFile = path37.join(ws.board, ".sync", `${ws.task}.mcp.json`);
120048
120334
  const takes = new Set(settingKeys(runtime));
120049
120335
  const given = job.settings ?? {};
120050
120336
  const values = valuesOf(runtime, job.model, given, servers, mcpFile);
@@ -120167,19 +120453,19 @@ async function runAgent(job, ws, deps, io) {
120167
120453
  }
120168
120454
  function writeTranscript(job, dir) {
120169
120455
  if (!job.transcript) return "";
120170
- const file2 = path36.join(dir, "discussion.md");
120171
- fs33.mkdirSync(dir, { recursive: true });
120172
- fs33.writeFileSync(file2, `${job.transcript}
120456
+ const file2 = path37.join(dir, "discussion.md");
120457
+ fs34.mkdirSync(dir, { recursive: true });
120458
+ fs34.writeFileSync(file2, `${job.transcript}
120173
120459
  `);
120174
120460
  return file2;
120175
120461
  }
120176
120462
  function pictures(job, ws, id) {
120177
120463
  const dir = cardAssetsDir(ws, id);
120178
120464
  if (!job.attachments.length || !dir) return "";
120179
- fs33.mkdirSync(dir, { recursive: true });
120465
+ fs34.mkdirSync(dir, { recursive: true });
120180
120466
  return job.attachments.map((a2, i) => {
120181
- const file2 = `${i + 1}-${path36.basename(a2.name).replace(/[^\w.-]+/g, "-")}`;
120182
- fs33.writeFileSync(path36.join(dir, file2), Buffer.from(a2.content, "base64"));
120467
+ const file2 = `${i + 1}-${path37.basename(a2.name).replace(/[^\w.-]+/g, "-")}`;
120468
+ fs34.writeFileSync(path37.join(dir, file2), Buffer.from(a2.content, "base64"));
120183
120469
  return `
120184
120470
  <Asset src=".assets/${id}/${file2}" label="${a2.name.replace(/["<>]/g, "") || file2}" />
120185
120471
  `;
@@ -120187,7 +120473,7 @@ function pictures(job, ws, id) {
120187
120473
  }
120188
120474
  function cardFlags(ws, fields) {
120189
120475
  if (!fields) return [];
120190
- const open = (keys) => (keys ?? []).map((k2) => Number(/(\d+)$/.exec(k2)?.[1])).filter((n) => n > 0 && n !== ws.number && findCard(ws.board, n)?.startsWith(path36.join(ws.board, "todo") + path36.sep));
120476
+ const open = (keys) => (keys ?? []).map((k2) => Number(/(\d+)$/.exec(k2)?.[1])).filter((n) => n > 0 && n !== ws.number && findCard(ws.board, n)?.startsWith(path37.join(ws.board, "todo") + path37.sep));
120191
120477
  const lists = [["--modules", fields.modules ?? []], ["--related", open(fields.related)], ["--blocked-by", open(fields.blocked_by)]];
120192
120478
  return [
120193
120479
  ...fields.priority ? ["--priority", fields.priority] : [],
@@ -120218,10 +120504,10 @@ async function runFlow(job, ws, deps, io) {
120218
120504
  said = { title: task.value.title?.trim() ?? "", request: task.value.request?.trim() ?? "" };
120219
120505
  }
120220
120506
  const title = said.title || "Untitled";
120221
- const body = path36.join(ws.board, ".sync", `${ws.task}.request.md`);
120222
- fs33.mkdirSync(path36.dirname(body), { recursive: true });
120507
+ const body = path37.join(ws.board, ".sync", `${ws.task}.request.md`);
120508
+ fs34.mkdirSync(path37.dirname(body), { recursive: true });
120223
120509
  if (!ws.number) return fail("This task has no number yet.");
120224
- fs33.writeFileSync(body, `${said.request || title}
120510
+ fs34.writeFileSync(body, `${said.request || title}
120225
120511
  ${pictures(job, ws, ws.number)}`);
120226
120512
  const created = await withBoard(ws, async (push2) => {
120227
120513
  const card2 = made(await akb([
@@ -120238,7 +120524,7 @@ ${pictures(job, ws, ws.number)}`);
120238
120524
  ...cardFlags(ws, flow.metadata),
120239
120525
  "--json"
120240
120526
  ]));
120241
- fs33.rmSync(body, { force: true });
120527
+ fs34.rmSync(body, { force: true });
120242
120528
  if (!card2.ok) return card2;
120243
120529
  const sent = await push2({ id: job.id, machineId: deps.machineId });
120244
120530
  if (!sent.ok) return { ok: false, error: sent.error };
@@ -120259,7 +120545,7 @@ ${pictures(job, ws, ws.number)}`);
120259
120545
  if (io.lost()) return fail("");
120260
120546
  return await workOn(card);
120261
120547
  } finally {
120262
- fs33.rmSync(path36.join(ws.board, ".sync", `${ws.task}.discussion`), { recursive: true, force: true });
120548
+ fs34.rmSync(path37.join(ws.board, ".sync", `${ws.task}.discussion`), { recursive: true, force: true });
120263
120549
  const left = working.get(key) - 1;
120264
120550
  if (left) working.set(key, left);
120265
120551
  else working.delete(key);
@@ -120304,7 +120590,7 @@ ${pictures(job, ws, ws.number)}`);
120304
120590
  const resolved = await akb(["raw", "card", "resolve", String(id2), "--follow", "--events", "--json", "--", text3], true);
120305
120591
  if (io.lost()) return fail("");
120306
120592
  const file2 = findCard(ws.board, id2);
120307
- rejected = !!file2 && path36.relative(ws.board, file2).split(path36.sep)[0] === ".archive" && parseFrontmatter(fs33.readFileSync(file2, "utf8")).meta?.rejected === true;
120593
+ rejected = !!file2 && path37.relative(ws.board, file2).split(path37.sep)[0] === ".archive" && parseFrontmatter(fs34.readFileSync(file2, "utf8")).meta?.rejected === true;
120308
120594
  if (rejected) ran = resolved;
120309
120595
  else if (resolved.code !== 0) note = text3;
120310
120596
  }
@@ -120353,7 +120639,7 @@ ${pictures(job, ws, ws.number)}`);
120353
120639
  }
120354
120640
  function carryArgs(verb) {
120355
120641
  if (!["refine", "resolve", "revise", "implement"].includes(verb)) return [];
120356
- const transcript = writeTranscript(job, path36.join(ws.board, ".sync", `${ws.task}.discussion`));
120642
+ const transcript = writeTranscript(job, path37.join(ws.board, ".sync", `${ws.task}.discussion`));
120357
120643
  return [
120358
120644
  ...job.resume ? ["--session", job.resume, ...job.fork ? ["--fork"] : []] : [],
120359
120645
  ...transcript ? ["--transcript", transcript] : []
@@ -120372,8 +120658,8 @@ async function confirmFlowStopped(ws, job, deps) {
120372
120658
  }
120373
120659
 
120374
120660
  // src/recovery.ts
120375
- import fs34 from "node:fs";
120376
- import path37 from "node:path";
120661
+ import fs35 from "node:fs";
120662
+ import path38 from "node:path";
120377
120663
 
120378
120664
  // ../cli/src/lib/agent/retry.ts
120379
120665
  var RETRY_WINDOW_MS = 15 * 6e4;
@@ -120387,10 +120673,10 @@ function backoffMs(attempt, random = Math.random) {
120387
120673
 
120388
120674
  // src/recovery.ts
120389
120675
  var UNCERTAIN = "\u66F4\u65B0\u4E2D\u65AD\u65F6\u6709\u64CD\u4F5C\u7ED3\u679C\u5C1A\u672A\u786E\u8BA4\uFF0C\u8BF7\u68C0\u67E5\u5DF2\u6709\u7ED3\u679C\u540E\u518D\u7EED\u8DD1\u3002";
120390
- var fileOf = (id) => path37.join(runnerHome(), "checkpoints", `${encodeURIComponent(id)}.json`);
120676
+ var fileOf = (id) => path38.join(runnerHome(), "checkpoints", `${encodeURIComponent(id)}.json`);
120391
120677
  function readCheckpoint(id) {
120392
120678
  try {
120393
- const held5 = JSON.parse(fs34.readFileSync(fileOf(id), "utf8"));
120679
+ const held5 = JSON.parse(fs35.readFileSync(fileOf(id), "utf8"));
120394
120680
  if (!held5 || !Array.isArray(held5.pending) || !held5.pending.every((id2) => typeof id2 === "string")) throw new Error("\u8FDB\u5EA6\u683C\u5F0F\u9519\u8BEF");
120395
120681
  return held5;
120396
120682
  } catch (e2) {
@@ -120400,12 +120686,12 @@ function readCheckpoint(id) {
120400
120686
  }
120401
120687
  function saveCheckpoint(id, checkpoint) {
120402
120688
  const file2 = fileOf(id);
120403
- fs34.mkdirSync(path37.dirname(file2), { recursive: true, mode: 448 });
120404
- fs34.writeFileSync(`${file2}.tmp`, JSON.stringify(checkpoint), { mode: 384 });
120405
- fs34.renameSync(`${file2}.tmp`, file2);
120689
+ fs35.mkdirSync(path38.dirname(file2), { recursive: true, mode: 448 });
120690
+ fs35.writeFileSync(`${file2}.tmp`, JSON.stringify(checkpoint), { mode: 384 });
120691
+ fs35.renameSync(`${file2}.tmp`, file2);
120406
120692
  }
120407
120693
  function clearCheckpoint(id) {
120408
- fs34.rmSync(fileOf(id), { force: true });
120694
+ fs35.rmSync(fileOf(id), { force: true });
120409
120695
  }
120410
120696
  function checkpointEvent(checkpoint, event2) {
120411
120697
  if (event2.kind === "phase" && event2.data.phase === "submitted") checkpoint.submitted = true;
@@ -120464,9 +120750,101 @@ function replySpent(checkpoint, runtime) {
120464
120750
  };
120465
120751
  }
120466
120752
 
120753
+ // src/conversation-progress.ts
120754
+ function conversationProgress(attempt, send3, valid, unconfirmed) {
120755
+ const state = { attempt, phases: {} };
120756
+ let pending = false;
120757
+ let cancelled = false;
120758
+ let running;
120759
+ let timer;
120760
+ let sentAt = 0;
120761
+ let finishing = false;
120762
+ let urgent = false;
120763
+ const flush = () => {
120764
+ clearTimeout(timer);
120765
+ timer = void 0;
120766
+ if (running || cancelled || !valid()) return;
120767
+ running = (async () => {
120768
+ while (pending && !cancelled && valid()) {
120769
+ if (!urgent && !finishing && performance.now() - sentAt < 5e3) {
120770
+ timer = setTimeout(flush, 5e3 - (performance.now() - sentAt));
120771
+ break;
120772
+ }
120773
+ pending = false;
120774
+ urgent = false;
120775
+ sentAt = performance.now();
120776
+ try {
120777
+ await send3({ ...state, phases: { ...state.phases } });
120778
+ } catch {
120779
+ if (!cancelled && valid()) unconfirmed();
120780
+ }
120781
+ }
120782
+ })().finally(() => {
120783
+ running = void 0;
120784
+ if (pending && !cancelled && valid()) timer ??= setTimeout(flush, urgent || finishing ? 0 : Math.max(0, 5e3 - (performance.now() - sentAt)));
120785
+ });
120786
+ };
120787
+ return {
120788
+ active: () => !cancelled && valid(),
120789
+ observe(event2, at2) {
120790
+ if (cancelled || !valid()) return;
120791
+ let immediate = false;
120792
+ if (event2.kind === "phase" && CONVERSATION_PHASES.includes(event2.data.phase)) {
120793
+ state.phases[event2.data.phase] ??= at2;
120794
+ const rank = CONVERSATION_PHASES.indexOf(event2.data.phase);
120795
+ if (rank > CONVERSATION_PHASES.indexOf(state.phase)) {
120796
+ state.phase = event2.data.phase;
120797
+ immediate = true;
120798
+ }
120799
+ }
120800
+ const content = ["message", "tool_call", "tool_call_update", "plan"].includes(event2.kind) || event2.kind === "phase" && !!event2.data.contentAt;
120801
+ if (content) {
120802
+ immediate ||= !state.firstContentAt;
120803
+ state.firstContentAt ??= at2;
120804
+ state.contentAt = at2;
120805
+ }
120806
+ if (!content && !immediate) return;
120807
+ urgent ||= immediate;
120808
+ pending = true;
120809
+ if (running) return;
120810
+ if (immediate || finishing) {
120811
+ clearTimeout(timer);
120812
+ timer = setTimeout(flush, 0);
120813
+ } else timer ??= setTimeout(flush, Math.max(0, 5e3 - (performance.now() - sentAt)));
120814
+ },
120815
+ async drain(ms) {
120816
+ finishing = true;
120817
+ const empty = async () => {
120818
+ while ((pending || running) && !cancelled && valid()) {
120819
+ flush();
120820
+ await running;
120821
+ }
120822
+ };
120823
+ let timeout;
120824
+ const done = await Promise.race([
120825
+ empty().then(() => true),
120826
+ new Promise((resolve2) => {
120827
+ timeout = setTimeout(() => resolve2(false), ms);
120828
+ })
120829
+ ]);
120830
+ clearTimeout(timeout);
120831
+ if (!done) {
120832
+ unconfirmed();
120833
+ cancelled = true;
120834
+ pending = false;
120835
+ }
120836
+ },
120837
+ cancel() {
120838
+ cancelled = true;
120839
+ pending = false;
120840
+ clearTimeout(timer);
120841
+ }
120842
+ };
120843
+ }
120844
+
120467
120845
  // src/reply-images.ts
120468
- import fs35 from "node:fs";
120469
- import path38 from "node:path";
120846
+ import fs36 from "node:fs";
120847
+ import path39 from "node:path";
120470
120848
  import os6 from "node:os";
120471
120849
  import { fileURLToPath as fileURLToPath3 } from "node:url";
120472
120850
  import { createHash as createHash5 } from "node:crypto";
@@ -120484,16 +120862,16 @@ function imageMime(bytes2) {
120484
120862
 
120485
120863
  // src/reply-images.ts
120486
120864
  var inside = (root2, file2) => {
120487
- const p2 = path38.relative(root2, file2);
120488
- return p2 !== ".." && !p2.startsWith(`..${path38.sep}`) && !path38.isAbsolute(p2);
120865
+ const p2 = path39.relative(root2, file2);
120866
+ return p2 !== ".." && !p2.startsWith(`..${path39.sep}`) && !path39.isAbsolute(p2);
120489
120867
  };
120490
120868
  function collectReplyImages(parts, cwd) {
120491
120869
  const files = /* @__PURE__ */ new Map();
120492
120870
  const tools = [];
120493
120871
  const output2 = [];
120494
- const roots = [cwd, path38.join(process.env.CODEX_HOME?.trim() || path38.join(os6.homedir(), ".codex"), "generated_images")].flatMap((p2) => {
120872
+ const roots = [cwd, path39.join(process.env.CODEX_HOME?.trim() || path39.join(os6.homedir(), ".codex"), "generated_images")].flatMap((p2) => {
120495
120873
  try {
120496
- return [fs35.realpathSync(p2)];
120874
+ return [fs36.realpathSync(p2)];
120497
120875
  } catch {
120498
120876
  return [];
120499
120877
  }
@@ -120501,17 +120879,17 @@ function collectReplyImages(parts, cwd) {
120501
120879
  const registered = new Set(parts.flatMap((p2) => {
120502
120880
  if (p2.type !== "image" || !p2.registered || !p2.path) return [];
120503
120881
  try {
120504
- const file2 = p2.path.startsWith("file:") ? fileURLToPath3(p2.path) : path38.resolve(cwd, p2.path);
120505
- if (!fs35.lstatSync(file2).isFile()) return [];
120506
- const real = fs35.realpathSync(file2);
120507
- const fd = fs35.openSync(real, fs35.constants.O_RDONLY | (fs35.constants.O_NOFOLLOW ?? 0));
120882
+ const file2 = p2.path.startsWith("file:") ? fileURLToPath3(p2.path) : path39.resolve(cwd, p2.path);
120883
+ if (!fs36.lstatSync(file2).isFile()) return [];
120884
+ const real = fs36.realpathSync(file2);
120885
+ const fd = fs36.openSync(real, fs36.constants.O_RDONLY | (fs36.constants.O_NOFOLLOW ?? 0));
120508
120886
  try {
120509
- const stat = fs35.fstatSync(fd);
120887
+ const stat = fs36.fstatSync(fd);
120510
120888
  if (!stat.isFile() || stat.size > ASSET_FILE_LIMIT) return [];
120511
- const mime = imageMime(fs35.readFileSync(fd));
120889
+ const mime = imageMime(fs36.readFileSync(fd));
120512
120890
  return mime && (!p2.mime || p2.mime === mime) ? [real] : [];
120513
120891
  } finally {
120514
- fs35.closeSync(fd);
120892
+ fs36.closeSync(fd);
120515
120893
  }
120516
120894
  } catch {
120517
120895
  return [];
@@ -120527,16 +120905,16 @@ function collectReplyImages(parts, cwd) {
120527
120905
  if (!p2.path) throw Error();
120528
120906
  const source = p2.path.startsWith("file:") ? fileURLToPath3(p2.path) : decodeURIComponent(p2.path);
120529
120907
  if (/^[a-z][a-z0-9+.-]*:/i.test(source) && !/^[A-Za-z]:[\\/]/.test(source)) throw Error();
120530
- const real = fs35.realpathSync(path38.resolve(cwd, source));
120908
+ const real = fs36.realpathSync(path39.resolve(cwd, source));
120531
120909
  if (!/\.(png|jpe?g|gif|webp)$/i.test(source) && !registered.has(real)) throw Error();
120532
120910
  if (!roots.some((root2) => inside(root2, real)) && !registered.has(real)) throw Error();
120533
- const fd = fs35.openSync(real, fs35.constants.O_RDONLY | (fs35.constants.O_NOFOLLOW ?? 0));
120911
+ const fd = fs36.openSync(real, fs36.constants.O_RDONLY | (fs36.constants.O_NOFOLLOW ?? 0));
120534
120912
  try {
120535
- const stat = fs35.fstatSync(fd);
120913
+ const stat = fs36.fstatSync(fd);
120536
120914
  if (!stat.isFile() || stat.size > ASSET_FILE_LIMIT) throw Error();
120537
- bytes2 = fs35.readFileSync(fd);
120915
+ bytes2 = fs36.readFileSync(fd);
120538
120916
  } finally {
120539
- fs35.closeSync(fd);
120917
+ fs36.closeSync(fd);
120540
120918
  }
120541
120919
  }
120542
120920
  return bytes2;
@@ -120622,8 +121000,8 @@ async function saveReplyImages(parts, cwd, upload2) {
120622
121000
  // src/handoff.ts
120623
121001
  import { execFileSync as execFileSync2 } from "node:child_process";
120624
121002
  import crypto5 from "node:crypto";
120625
- import fs36 from "node:fs";
120626
- import path39 from "node:path";
121003
+ import fs37 from "node:fs";
121004
+ import path40 from "node:path";
120627
121005
  var gitRead = (cwd, args2) => {
120628
121006
  try {
120629
121007
  return execFileSync2("git", ["-C", cwd, ...args2], {
@@ -120640,8 +121018,8 @@ var digest = (value) => crypto5.createHash("sha256").update(value).digest("hex")
120640
121018
  function authorizedFolder(folder) {
120641
121019
  if (!folder) return null;
120642
121020
  try {
120643
- const real = fs36.realpathSync(folder);
120644
- return allowedProjects().some((root2) => real === root2 || real.startsWith(root2 + path39.sep)) ? real : null;
121021
+ const real = fs37.realpathSync(folder);
121022
+ return allowedProjects().some((root2) => real === root2 || real.startsWith(root2 + path40.sep)) ? real : null;
120645
121023
  } catch {
120646
121024
  return null;
120647
121025
  }
@@ -120651,9 +121029,9 @@ function progressFolder(job, folder) {
120651
121029
  if (!token) return folder;
120652
121030
  if (!/^[a-zA-Z0-9-]{1,80}$/.test(token)) return null;
120653
121031
  try {
120654
- const dir = fs36.realpathSync(path39.join(folder, ".akb", "handoffs", token));
120655
- if (!dir.startsWith(fs36.realpathSync(folder) + path39.sep)) return null;
120656
- const marker = JSON.parse(fs36.readFileSync(path39.join(dir, ".akb", "handoff.json"), "utf8"));
121032
+ const dir = fs37.realpathSync(path40.join(folder, ".akb", "handoffs", token));
121033
+ if (!dir.startsWith(fs37.realpathSync(folder) + path40.sep)) return null;
121034
+ const marker = JSON.parse(fs37.readFileSync(path40.join(dir, ".akb", "handoff.json"), "utf8"));
120657
121035
  return marker.task === job.task && marker.isolation === token ? dir : null;
120658
121036
  } catch {
120659
121037
  return null;
@@ -120661,38 +121039,38 @@ function progressFolder(job, folder) {
120661
121039
  }
120662
121040
  function progressEvidence(job, folder) {
120663
121041
  try {
120664
- const board = path39.join(folder, ".akb", "kanban");
120665
- const deliveries = path39.join(board, "deliveries");
120666
- const rows = fs36.readdirSync(deliveries).filter((name) => name.endsWith(".json")).map((name) => JSON.parse(fs36.readFileSync(path39.join(deliveries, name), "utf8"))).filter((row2) => row2.cardId === job.number).sort((a2, b2) => (b2.startedAt ?? 0) - (a2.startedAt ?? 0));
121042
+ const board = path40.join(folder, ".akb", "kanban");
121043
+ const deliveries = path40.join(board, "deliveries");
121044
+ const rows = fs37.readdirSync(deliveries).filter((name) => name.endsWith(".json")).map((name) => JSON.parse(fs37.readFileSync(path40.join(deliveries, name), "utf8"))).filter((row2) => row2.cardId === job.number).sort((a2, b2) => (b2.startedAt ?? 0) - (a2.startedAt ?? 0));
120667
121045
  const row = rows[0];
120668
121046
  if (!row?.deliveryId) return null;
120669
- const tree = fs36.realpathSync(path39.resolve(folder, row.worktree ?? "."));
120670
- if (tree !== fs36.realpathSync(folder) && !tree.startsWith(fs36.realpathSync(folder) + path39.sep)) return null;
121047
+ const tree = fs37.realpathSync(path40.resolve(folder, row.worktree ?? "."));
121048
+ if (tree !== fs37.realpathSync(folder) && !tree.startsWith(fs37.realpathSync(folder) + path40.sep)) return null;
120671
121049
  const inventory = gitRead(tree, ["worktree", "list", "--porcelain"]);
120672
121050
  const related = (inventory ?? "").split("\n\n").flatMap((entry) => {
120673
121051
  const branch = /^branch refs\/heads\/(.+)$/m.exec(entry)?.[1];
120674
121052
  const dir = /^worktree (.+)$/m.exec(entry)?.[1];
120675
- return branch?.startsWith(`card/${job.number}/`) && dir && dir !== tree && dir.startsWith(fs36.realpathSync(folder) + path39.sep) ? [dir] : [];
121053
+ return branch?.startsWith(`card/${job.number}/`) && dir && dir !== tree && dir.startsWith(fs37.realpathSync(folder) + path40.sep) ? [dir] : [];
120676
121054
  });
120677
121055
  const filesIn = (tree2) => {
120678
121056
  const changed = [];
120679
121057
  const walk = (dir, prefix = "") => {
120680
- for (const entry of fs36.readdirSync(dir, { withFileTypes: true })) {
121058
+ for (const entry of fs37.readdirSync(dir, { withFileTypes: true })) {
120681
121059
  if ([".git", ".akb", "node_modules", ".claude", ".agents"].includes(entry.name)) continue;
120682
121060
  const name = prefix + entry.name;
120683
- if (entry.isDirectory()) walk(path39.join(dir, entry.name), name + "/");
121061
+ if (entry.isDirectory()) walk(path40.join(dir, entry.name), name + "/");
120684
121062
  else changed.push(name);
120685
121063
  }
120686
121064
  };
120687
121065
  walk(tree2);
120688
121066
  changed.sort();
120689
121067
  return changed.map((name) => {
120690
- const file2 = path39.join(tree2, name);
121068
+ const file2 = path40.join(tree2, name);
120691
121069
  try {
120692
- const stat = fs36.lstatSync(file2);
120693
- if (stat.isSymbolicLink()) return [name, "link", digest(fs36.readlinkSync(file2))];
121070
+ const stat = fs37.lstatSync(file2);
121071
+ if (stat.isSymbolicLink()) return [name, "link", digest(fs37.readlinkSync(file2))];
120694
121072
  if (!stat.isFile()) throw new Error("\u65E0\u6CD5\u9A8C\u8BC1\u6587\u4EF6\u7C7B\u578B");
120695
- return [name, stat.mode & 511, digest(fs36.readFileSync(file2))];
121073
+ return [name, stat.mode & 511, digest(fs37.readFileSync(file2))];
120696
121074
  } catch (e2) {
120697
121075
  if (e2.code === "ENOENT") return [name, "deleted"];
120698
121076
  throw e2;
@@ -120729,60 +121107,60 @@ function progressEvidence(job, folder) {
120729
121107
  function restartFolder(job, folder) {
120730
121108
  const token = job.handoff?.isolation ?? job.id;
120731
121109
  if (!/^[a-zA-Z0-9-]{1,80}$/.test(token)) throw new Error("\u9694\u79BB\u76EE\u5F55\u7F16\u53F7\u65E0\u6548\u3002");
120732
- const dir = path39.join(folder, ".akb", "handoffs", token);
120733
- const marker = path39.join(dir, ".akb", "handoff.json");
120734
- for (const parent of [path39.join(folder, ".akb"), path39.dirname(dir), dir]) {
120735
- if (fs36.lstatSync(parent, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("\u9694\u79BB\u76EE\u5F55\u4E0D\u80FD\u901A\u8FC7\u7B26\u53F7\u94FE\u63A5\u521B\u5EFA\u3002");
121110
+ const dir = path40.join(folder, ".akb", "handoffs", token);
121111
+ const marker = path40.join(dir, ".akb", "handoff.json");
121112
+ for (const parent of [path40.join(folder, ".akb"), path40.dirname(dir), dir]) {
121113
+ if (fs37.lstatSync(parent, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("\u9694\u79BB\u76EE\u5F55\u4E0D\u80FD\u901A\u8FC7\u7B26\u53F7\u94FE\u63A5\u521B\u5EFA\u3002");
120736
121114
  }
120737
- if (fs36.existsSync(dir)) {
121115
+ if (fs37.existsSync(dir)) {
120738
121116
  if (job.handoff?.recovering) {
120739
121117
  try {
120740
- const saved = JSON.parse(fs36.readFileSync(marker, "utf8"));
121118
+ const saved = JSON.parse(fs37.readFileSync(marker, "utf8"));
120741
121119
  if (saved.task === job.task && saved.isolation === token) return dir;
120742
121120
  } catch {
120743
121121
  }
120744
121122
  }
120745
121123
  throw new Error("\u91CD\u542F\u76EE\u5F55\u5DF2\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5\u3002");
120746
121124
  }
120747
- fs36.mkdirSync(path39.dirname(dir), { recursive: true });
120748
- fs36.mkdirSync(dir);
120749
- for (const entry of fs36.readdirSync(folder)) {
121125
+ fs37.mkdirSync(path40.dirname(dir), { recursive: true });
121126
+ fs37.mkdirSync(dir);
121127
+ for (const entry of fs37.readdirSync(folder)) {
120750
121128
  if ([".akb", ".git", "node_modules", ".claude", ".agents"].includes(entry)) continue;
120751
- fs36.cpSync(path39.join(folder, entry), path39.join(dir, entry), { recursive: true, verbatimSymlinks: true });
121129
+ fs37.cpSync(path40.join(folder, entry), path40.join(dir, entry), { recursive: true, verbatimSymlinks: true });
120752
121130
  }
120753
- if (fs36.lstatSync(path39.dirname(marker), { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("\u9694\u79BB\u6807\u8BB0\u76EE\u5F55\u65E0\u6548\u3002");
120754
- fs36.mkdirSync(path39.dirname(marker), { recursive: true });
120755
- fs36.writeFileSync(marker, JSON.stringify({ task: job.task, isolation: token }), { flag: "wx" });
121131
+ if (fs37.lstatSync(path40.dirname(marker), { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("\u9694\u79BB\u6807\u8BB0\u76EE\u5F55\u65E0\u6548\u3002");
121132
+ fs37.mkdirSync(path40.dirname(marker), { recursive: true });
121133
+ fs37.writeFileSync(marker, JSON.stringify({ task: job.task, isolation: token }), { flag: "wx" });
120756
121134
  return dir;
120757
121135
  }
120758
121136
 
120759
121137
  // src/jobs.ts
120760
121138
  import { spawn as spawn4 } from "node:child_process";
120761
- import fs41 from "node:fs";
120762
- import path44 from "node:path";
121139
+ import fs42 from "node:fs";
121140
+ import path45 from "node:path";
120763
121141
 
120764
121142
  // ../cli/src/lib/agent/catalog.ts
120765
- import fs37 from "node:fs";
120766
- import path40 from "node:path";
121143
+ import fs38 from "node:fs";
121144
+ import path41 from "node:path";
120767
121145
  var CATALOGUE = "https://models.dev/api.json";
120768
121146
  var FRESH_FOR_MS = 24 * 60 * 6e4;
120769
121147
  var ANSWER_BY_MS = 2e4;
120770
121148
  function cacheFile() {
120771
- return path40.join(machineHome(), "models-dev.json");
121149
+ return path41.join(machineHome(), "models-dev.json");
120772
121150
  }
120773
121151
  var held3;
120774
121152
  function readCache() {
120775
121153
  const file2 = cacheFile();
120776
121154
  let stamp3;
120777
121155
  try {
120778
- const stat = fs37.statSync(file2);
121156
+ const stat = fs38.statSync(file2);
120779
121157
  stamp3 = `${stat.mtimeMs}:${stat.size}`;
120780
121158
  } catch {
120781
121159
  return void 0;
120782
121160
  }
120783
121161
  if (held3?.stamp === stamp3) return held3.cached;
120784
121162
  try {
120785
- const data = JSON.parse(fs37.readFileSync(file2, "utf8"));
121163
+ const data = JSON.parse(fs38.readFileSync(file2, "utf8"));
120786
121164
  if (!data || typeof data.limits !== "object" || !data.limits) return void 0;
120787
121165
  const cached2 = {
120788
121166
  fetchedAt: typeof data.fetchedAt === "number" ? data.fetchedAt : 0,
@@ -120821,8 +121199,8 @@ function refreshCatalog() {
120821
121199
  const limits = limitsIn(await answer.json());
120822
121200
  if (Object.keys(limits).length === 0) return;
120823
121201
  const file2 = cacheFile();
120824
- fs37.mkdirSync(path40.dirname(file2), { recursive: true });
120825
- fs37.writeFileSync(file2, JSON.stringify({ fetchedAt: Date.now(), limits }));
121202
+ fs38.mkdirSync(path41.dirname(file2), { recursive: true });
121203
+ fs38.writeFileSync(file2, JSON.stringify({ fetchedAt: Date.now(), limits }));
120826
121204
  } catch {
120827
121205
  }
120828
121206
  })();
@@ -120913,14 +121291,14 @@ async function replyApprovalBridge(task, number, approve) {
120913
121291
  }
120914
121292
 
120915
121293
  // src/akb-version.ts
120916
- import fs38 from "node:fs";
120917
- import path41 from "node:path";
120918
- var stateFile = () => path41.join(akbHome(), "state.json");
120919
- var akbVersionDir = (version) => path41.join(akbHome(), version);
120920
- var entryOf = (dir) => path41.join(dir, "bin", "ai4kanban.mjs");
121294
+ import fs39 from "node:fs";
121295
+ import path42 from "node:path";
121296
+ var stateFile = () => path42.join(akbHome(), "state.json");
121297
+ var akbVersionDir = (version) => path42.join(akbHome(), version);
121298
+ var entryOf = (dir) => path42.join(dir, "bin", "ai4kanban.mjs");
120921
121299
  function readAkbState() {
120922
121300
  try {
120923
- const held5 = JSON.parse(fs38.readFileSync(stateFile(), "utf8"));
121301
+ const held5 = JSON.parse(fs39.readFileSync(stateFile(), "utf8"));
120924
121302
  return { current: held5.current ?? null, bad: held5.bad ?? [] };
120925
121303
  } catch {
120926
121304
  return { current: null, bad: [] };
@@ -120928,12 +121306,12 @@ function readAkbState() {
120928
121306
  }
120929
121307
  function contractOf(dir) {
120930
121308
  try {
120931
- return JSON.parse(fs38.readFileSync(path41.join(dir, "package.json"), "utf8")).akbContract ?? null;
121309
+ return JSON.parse(fs39.readFileSync(path42.join(dir, "package.json"), "utf8")).akbContract ?? null;
120932
121310
  } catch {
120933
121311
  return null;
120934
121312
  }
120935
121313
  }
120936
- var usable = (dir) => fs38.existsSync(entryOf(dir)) && contractOf(dir) === AKB_CONTRACT;
121314
+ var usable = (dir) => fs39.existsSync(entryOf(dir)) && contractOf(dir) === AKB_CONTRACT;
120937
121315
  function currentAkb() {
120938
121316
  const { current: current2 } = readAkbState();
120939
121317
  if (!current2) return bundledAkb();
@@ -120941,32 +121319,32 @@ function currentAkb() {
120941
121319
  if (!usable(dir)) return bundledAkb();
120942
121320
  try {
120943
121321
  const now = /* @__PURE__ */ new Date();
120944
- fs38.utimesSync(dir, now, now);
121322
+ fs39.utimesSync(dir, now, now);
120945
121323
  } catch {
120946
121324
  }
120947
- return { command: process.execPath, args: akbArgs(entryOf(dir)), version: current2, shim: path41.join(dir, "shim") };
121325
+ return { command: process.execPath, args: akbArgs(entryOf(dir)), version: current2, shim: path42.join(dir, "shim") };
120948
121326
  }
120949
121327
 
120950
121328
  // src/chats.ts
120951
- import fs40 from "node:fs";
120952
- import path43 from "node:path";
121329
+ import fs41 from "node:fs";
121330
+ import path44 from "node:path";
120953
121331
 
120954
121332
  // ../cli/src/lib/shared/chats.ts
120955
121333
  var CHAT_KEEP_DAYS = 30;
120956
121334
 
120957
121335
  // ../cli/src/lib/agent/task-chats.ts
120958
- import fs39 from "node:fs";
120959
- import path42 from "node:path";
121336
+ import fs40 from "node:fs";
121337
+ import path43 from "node:path";
120960
121338
  var TASK = /^[\w-]{1,100}$/;
120961
- var taskChatsDir = (home4 = machineHome()) => path42.join(home4, "chats");
121339
+ var taskChatsDir = (home4 = machineHome()) => path43.join(home4, "chats");
120962
121340
  function taskChatFile(task, home4) {
120963
121341
  if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
120964
- return path42.join(taskChatsDir(home4), `${task}.jsonl`);
121342
+ return path43.join(taskChatsDir(home4), `${task}.jsonl`);
120965
121343
  }
120966
121344
  function readTaskChat(task, home4) {
120967
121345
  let text3;
120968
121346
  try {
120969
- text3 = fs39.readFileSync(taskChatFile(task, home4), "utf8");
121347
+ text3 = fs40.readFileSync(taskChatFile(task, home4), "utf8");
120970
121348
  } catch {
120971
121349
  return [];
120972
121350
  }
@@ -120986,18 +121364,18 @@ function readTaskChat(task, home4) {
120986
121364
  var DAY_MS = 24 * 60 * 6e4;
120987
121365
  var KEEP_MS2 = CHAT_KEEP_DAYS * DAY_MS;
120988
121366
  var home3 = () => runnerHome();
120989
- var reviewedFile = () => path43.join(taskChatsDir(home3()), "reviewed.json");
121367
+ var reviewedFile = () => path44.join(taskChatsDir(home3()), "reviewed.json");
120990
121368
  function readReviewed() {
120991
121369
  try {
120992
- const held5 = JSON.parse(fs40.readFileSync(reviewedFile(), "utf8"));
121370
+ const held5 = JSON.parse(fs41.readFileSync(reviewedFile(), "utf8"));
120993
121371
  return { checkedAt: Number(held5.checkedAt) || 0, tasks: held5.tasks ?? {} };
120994
121372
  } catch {
120995
121373
  return { checkedAt: 0, tasks: {} };
120996
121374
  }
120997
121375
  }
120998
121376
  function writeReviewed(reviewed) {
120999
- fs40.mkdirSync(path43.dirname(reviewedFile()), { recursive: true });
121000
- fs40.writeFileSync(reviewedFile(), `${JSON.stringify(reviewed, null, 2)}
121377
+ fs41.mkdirSync(path44.dirname(reviewedFile()), { recursive: true });
121378
+ fs41.writeFileSync(reviewedFile(), `${JSON.stringify(reviewed, null, 2)}
121001
121379
  `);
121002
121380
  }
121003
121381
  function keepChat(job, reply, at2 = Date.now()) {
@@ -121007,16 +121385,16 @@ function keepChat(job, reply, at2 = Date.now()) {
121007
121385
  { id: job.id, role: "agent", text: reply, at: at2, runtime: job.runtime, model: job.model ?? null }
121008
121386
  ];
121009
121387
  const file2 = taskChatFile(job.task, home3());
121010
- fs40.mkdirSync(path43.dirname(file2), { recursive: true });
121011
- fs40.appendFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
121388
+ fs41.mkdirSync(path44.dirname(file2), { recursive: true });
121389
+ fs41.appendFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
121012
121390
  `).join(""));
121013
121391
  }
121014
121392
  function keepCloudChat(task, messages) {
121015
121393
  const file2 = taskChatFile(task, home3());
121016
- if (!messages.length) return fs40.rmSync(file2, { force: true });
121394
+ if (!messages.length) return fs41.rmSync(file2, { force: true });
121017
121395
  const lines = messages.map((m) => ({ id: m.id, role: m.role, text: m.body, at: Date.parse(m.created_at) || Date.now() }));
121018
- fs40.mkdirSync(path43.dirname(file2), { recursive: true });
121019
- fs40.writeFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
121396
+ fs41.mkdirSync(path44.dirname(file2), { recursive: true });
121397
+ fs41.writeFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
121020
121398
  `).join(""));
121021
121399
  }
121022
121400
  async function keepDecisions(task, read4) {
@@ -121034,8 +121412,8 @@ async function keepDecisions(task, read4) {
121034
121412
  const ids = new Set(comments.map((c2) => c2.id));
121035
121413
  const lines = [...readTaskChat(task, home3()).filter((l2) => !ids.has(l2.id)), ...comments].sort((a2, b2) => a2.at - b2.at);
121036
121414
  const file2 = taskChatFile(task, home3());
121037
- fs40.mkdirSync(path43.dirname(file2), { recursive: true });
121038
- fs40.writeFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
121415
+ fs41.mkdirSync(path44.dirname(file2), { recursive: true });
121416
+ fs41.writeFileSync(file2, lines.map((l2) => `${JSON.stringify(l2)}
121039
121417
  `).join(""));
121040
121418
  }
121041
121419
  var lastOf = (task) => readTaskChat(task, home3()).at(-1);
@@ -121115,32 +121493,32 @@ var defaultDeps = (machineId) => ({
121115
121493
  akb: currentAkb,
121116
121494
  runtimes: detectRuntimes
121117
121495
  });
121118
- var ownFolder = () => path44.join(runnerHome(), "work");
121496
+ var ownFolder = () => path45.join(runnerHome(), "work");
121119
121497
  function folderFor(job) {
121120
121498
  if (!job.projectDir) {
121121
- const cwd = path44.join(ownFolder(), job.id);
121122
- fs41.mkdirSync(cwd, { recursive: true });
121499
+ const cwd = path45.join(ownFolder(), job.id);
121500
+ fs42.mkdirSync(cwd, { recursive: true });
121123
121501
  return { cwd };
121124
121502
  }
121125
121503
  const real = realpath2(job.projectDir);
121126
- if (real && allowedProjects().some((root2) => real === root2 || real.startsWith(root2 + path44.sep))) return { cwd: real };
121504
+ if (real && allowedProjects().some((root2) => real === root2 || real.startsWith(root2 + path45.sep))) return { cwd: real };
121127
121505
  return { refused: `This Runner is not allowed to work in ${job.projectDir}.` };
121128
121506
  }
121129
121507
  function realpath2(p2) {
121130
121508
  try {
121131
- return fs41.realpathSync(p2);
121509
+ return fs42.realpathSync(p2);
121132
121510
  } catch {
121133
121511
  return null;
121134
121512
  }
121135
121513
  }
121136
- var attachmentsOf = (job) => path44.join(runnerHome(), "attachments", job.id);
121514
+ var attachmentsOf = (job) => path45.join(runnerHome(), "attachments", job.id);
121137
121515
  function writeAttachments(job) {
121138
121516
  if (!job.attachments.length) return "";
121139
121517
  const dir = attachmentsOf(job);
121140
- fs41.mkdirSync(dir, { recursive: true });
121518
+ fs42.mkdirSync(dir, { recursive: true });
121141
121519
  const files = job.attachments.map((a2) => {
121142
- const file2 = path44.join(dir, path44.basename(a2.name));
121143
- fs41.writeFileSync(file2, Buffer.from(a2.content, "base64"));
121520
+ const file2 = path45.join(dir, path45.basename(a2.name));
121521
+ fs42.writeFileSync(file2, Buffer.from(a2.content, "base64"));
121144
121522
  return file2;
121145
121523
  });
121146
121524
  return `
@@ -121177,6 +121555,8 @@ function toWire(events, first) {
121177
121555
  var leaseNow = () => ({ at: Date.now(), monotonic: performance.now() });
121178
121556
  function streamOut(deps, id, lease) {
121179
121557
  const wire = [];
121558
+ let firstContent = false;
121559
+ let bufferedChars = 0;
121180
121560
  let firstSeq = null;
121181
121561
  let pending = [];
121182
121562
  let size = 0;
@@ -121239,7 +121619,7 @@ function streamOut(deps, id, lease) {
121239
121619
  const ws = log.ws;
121240
121620
  if (!ws || ws.readyState !== WebSocket.OPEN || log.after === null) return;
121241
121621
  const after = log.after;
121242
- const unsent = log.watched ? wire.filter((e2) => e2.seq > after) : [];
121622
+ const unsent2 = log.watched ? wire.filter((e2) => e2.seq > after) : [];
121243
121623
  let batch = [];
121244
121624
  let chars = 0;
121245
121625
  const out = () => {
@@ -121247,14 +121627,14 @@ function streamOut(deps, id, lease) {
121247
121627
  batch = [];
121248
121628
  chars = 0;
121249
121629
  };
121250
- for (const e2 of unsent) {
121630
+ for (const e2 of unsent2) {
121251
121631
  const n = JSON.stringify(e2).length;
121252
121632
  if (batch.length === BATCH_EVENTS || chars + n > BATCH_CHARS) out();
121253
121633
  batch.push(e2);
121254
121634
  chars += n;
121255
121635
  }
121256
121636
  out();
121257
- if (unsent.length) log.after = unsent[unsent.length - 1].seq;
121637
+ if (unsent2.length) log.after = unsent2[unsent2.length - 1].seq;
121258
121638
  if (ending) ws.send(JSON.stringify({ type: "end" }));
121259
121639
  };
121260
121640
  const flush = () => {
@@ -121311,9 +121691,16 @@ function streamOut(deps, id, lease) {
121311
121691
  const event2 = (e2) => {
121312
121692
  if (!valid()) return;
121313
121693
  if (e2.kind === "message") messages.push(e2.data.text);
121314
- pending.push(Object.assign({}, e2, { data: { ...e2.data, eventAt: (/* @__PURE__ */ new Date()).toISOString() } }));
121315
- size += JSON.stringify(e2.data).length;
121316
- if (log.watched && size >= FLUSH_CHARS) flush();
121694
+ const content = ["message", "tool_call", "tool_call_update", "plan"].includes(e2.kind) || e2.kind === "phase" && !!e2.data.contentAt;
121695
+ const immediate = e2.kind === "phase" || content && !firstContent;
121696
+ firstContent ||= content;
121697
+ const stamped = Object.assign({}, e2, { data: { ...e2.data, eventAt: "eventAt" in e2.data ? e2.data.eventAt : (/* @__PURE__ */ new Date()).toISOString() } });
121698
+ const chars = JSON.stringify(stamped).length;
121699
+ if (bufferedChars + chars > 16 * 1024 * 1024) return;
121700
+ bufferedChars += chars;
121701
+ pending.push(stamped);
121702
+ size += chars;
121703
+ if (immediate || log.watched && size >= FLUSH_CHARS) flush();
121317
121704
  };
121318
121705
  const flusher = setInterval(() => {
121319
121706
  if (log.watched && pending.length && Date.now() - flushedAt >= deps.flushMs) flush();
@@ -121423,12 +121810,12 @@ async function runJob(id, deps, track = () => {
121423
121810
  const releases = [];
121424
121811
  try {
121425
121812
  const akb = deps.akb();
121426
- releases.push(hold(path44.dirname(akb.shim)));
121813
+ releases.push(hold(path45.dirname(akb.shim)));
121427
121814
  releases.push(hold(akb.shim));
121428
121815
  await runClaimed(job, { ...deps, akb }, track, (dir) => releases.push(hold(dir)), lease);
121429
121816
  } finally {
121430
121817
  for (const release2 of releases) release2();
121431
- fs41.rmSync(attachmentsOf(job), { recursive: true, force: true });
121818
+ fs42.rmSync(attachmentsOf(job), { recursive: true, force: true });
121432
121819
  }
121433
121820
  }
121434
121821
  async function runClaimed(job, deps, track, keep2, lease, replyStream) {
@@ -121436,6 +121823,7 @@ async function runClaimed(job, deps, track, keep2, lease, replyStream) {
121436
121823
  try {
121437
121824
  await runClaimedStep(job, deps, track, keep2, lease, scope, replyStream);
121438
121825
  } finally {
121826
+ scope.progress?.cancel();
121439
121827
  scope.bridge?.close();
121440
121828
  scope.preview?.close();
121441
121829
  }
@@ -121582,12 +121970,10 @@ async function runClaimedStep(job, deps, track, keep2, lease, scope, replyStream
121582
121970
  if (job.discussion && job.projectDir && folder) {
121583
121971
  const board = openDiscussionFolder(job, folder.cwd);
121584
121972
  keep2(board.cwd);
121585
- const pulled = await pull(board, deps.machineId);
121586
- if (!pulled.ok) throw new Error(pulled.error);
121587
121973
  discussed = board.board;
121588
121974
  }
121589
121975
  if (job.discussion) {
121590
- const wrote = recovering && fs41.existsSync(goalsFileOf(job)) ? { file: goalsFileOf(job) } : await writeGoals({ ...job, discussion: job.discussion }, deps.api.listStudios);
121976
+ const wrote = await writeGoals({ ...job, discussion: job.discussion }, deps.api.listStudios, recovering);
121591
121977
  if ("error" in wrote) throw new Error(wrote.error);
121592
121978
  goalFile = wrote.file;
121593
121979
  }
@@ -121634,9 +122020,20 @@ ${prompt}` : prompt;
121634
122020
  if (deps.authorize && !await deps.authorize(job)) return finishClaimed("failed", "\u9879\u76EE\u76EE\u5F55\u6388\u6743\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u786E\u8BA4\u540E\u91CD\u8BD5\u3002");
121635
122021
  if (!held4(deps, lease)) return;
121636
122022
  if (reply) {
121637
- const renewed = await deps.api.renewJob(deps.machineId, id);
121638
- if (!renewed.ok || !renewed.value.renewed) return;
121639
- if (renewed.value.stop) return finishClaimed("stopped", "", { stopped: true });
122023
+ for (let check = 0; ; check++) {
122024
+ const requestedAt = leaseNow();
122025
+ const renewed = await deps.api.renewJob(deps.machineId, id);
122026
+ if (!renewed.ok || !renewed.value.renewed || !held4(deps, lease)) return;
122027
+ if (renewed.value.stop) return finishClaimed("stopped", "", { stopped: true });
122028
+ Object.assign(lease, requestedAt);
122029
+ if (!job.discussion || !renewed.value.catalog || renewed.value.catalog.version === job.discussion.catalog?.version && renewed.value.catalog.account === job.discussion.catalog.account) break;
122030
+ if (check >= 2) return finishClaimed("failed", "The studio catalog keeps changing. Try again.");
122031
+ job.discussion.catalog = renewed.value.catalog;
122032
+ const wrote = await writeGoals({ ...job, discussion: job.discussion }, deps.api.listStudios, true);
122033
+ if ("error" in wrote) return finishClaimed("failed", wrote.error);
122034
+ goalFile = wrote.file;
122035
+ if (deps.authorize && !await deps.authorize(job)) return finishClaimed("failed", "\u9879\u76EE\u76EE\u5F55\u6388\u6743\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u786E\u8BA4\u540E\u91CD\u8BD5\u3002");
122036
+ }
121640
122037
  }
121641
122038
  const stream = replyStream ?? streamOut(deps, id, lease);
121642
122039
  if (run3?.startNote) stream.out(`${run3.startNote}
@@ -121657,24 +122054,23 @@ ${prompt}` : prompt;
121657
122054
  return { ...rest, ...replySpent(checkpoint, job.runtime) };
121658
122055
  };
121659
122056
  let replyProgress = false;
121660
- let evidence = Promise.resolve();
121661
- let lastEvidence = 0;
122057
+ const account = readSession()?.subject;
122058
+ const generation = accountGeneration();
122059
+ const evidence = scope.progress = conversationProgress(checkpoint.retry?.attempt ?? 1, async (progress) => {
122060
+ const result = await deps.api.renewJob(deps.machineId, id, { ...progress, ...job.claim ? { claim: job.claim } : {} });
122061
+ if (!evidence.active()) return;
122062
+ if (!result.ok) throw new Error(result.error);
122063
+ if (!result.value.renewed) await stream.stop();
122064
+ else if (result.value.stop) stream.requestStop();
122065
+ }, () => reply && progressValid(), () => stream.out("[chat-progress] Evidence was not confirmed.\n"));
122066
+ const progressValid = () => !stream.asked() && !stream.lost() && readSession()?.subject === account && accountGeneration() === generation;
121662
122067
  const subagents = trackSubagents();
121663
122068
  const remember = (event2) => {
121664
122069
  if (["message", "tool_call", "tool_call_update"].includes(event2.kind)) replyProgress = true;
121665
122070
  if (stream.lost()) return;
121666
- const content = ["message", "tool_call", "tool_call_update", "plan"].includes(event2.kind) || event2.kind === "phase" && !!event2.data.contentAt;
121667
- if (reply && (event2.kind === "phase" && !event2.data.contentAt || content && Date.now() - lastEvidence >= 5e3)) {
121668
- if (content) lastEvidence = Date.now();
121669
- const progress = { attempt: checkpoint.retry?.attempt ?? 1, ...event2.kind === "phase" ? { phase: event2.data.phase } : {}, ...content ? { contentAt: (/* @__PURE__ */ new Date()).toISOString() } : {} };
121670
- evidence = evidence.then(async () => {
121671
- if (stream.asked() || stream.lost()) return;
121672
- const result = await deps.api.renewJob(deps.machineId, id, progress);
121673
- if (result.ok && !result.value.renewed) await stream.stop();
121674
- else if (result.ok && result.value.stop) stream.requestStop();
121675
- }).catch(() => {
121676
- });
121677
- }
122071
+ const at2 = (/* @__PURE__ */ new Date()).toISOString();
122072
+ event2 = Object.assign({}, event2, { data: { ...event2.data, eventAt: at2 } });
122073
+ evidence.observe(event2, at2);
121678
122074
  subagents.event(event2);
121679
122075
  checkpointEvent(checkpoint, event2);
121680
122076
  const session = run3?.session();
@@ -121711,6 +122107,7 @@ ${prompt}` : prompt;
121711
122107
  checkpoint.updating = true;
121712
122108
  persist();
121713
122109
  stream.event({ kind: "log", data: { text: "[chat-recovery] running" } });
122110
+ evidence.cancel();
121714
122111
  await runClaimed({ ...job, manualRecovery: false, retryReplay: safe3 }, deps, track, keep2, lease, stream);
121715
122112
  await stream.end();
121716
122113
  return true;
@@ -121829,6 +122226,7 @@ ${prompt}` : prompt;
121829
122226
  checkpoint.started = false;
121830
122227
  if (checkpoint.retry) checkpoint.retry.attempt++;
121831
122228
  persist();
122229
+ evidence.cancel();
121832
122230
  await runClaimed({ ...job, resume: null, fork: false, sessionFallback: true }, deps, track, keep2, lease, stream);
121833
122231
  await stream.end();
121834
122232
  return;
@@ -121838,7 +122236,7 @@ ${prompt}` : prompt;
121838
122236
  persist();
121839
122237
  }
121840
122238
  if (await retry2(end.ok ? void 0 : end.error)) return;
121841
- await evidence;
122239
+ await evidence.drain(deps.endMs);
121842
122240
  const stopped3 = await stopReply(id, deps.stopMs);
121843
122241
  stop(child);
121844
122242
  if (stream.asked() && (!stopped3 || !await stream.confirmed())) {
@@ -122094,8 +122492,8 @@ async function runTest(job, deps, lease) {
122094
122492
  const report2 = (await deps.runtimes()).find((r2) => r2.name === job.runtime);
122095
122493
  if (!report2?.installed) return finish2("failed", "not_installed");
122096
122494
  if (report2.loggedIn === false) return finish2("failed", "signed_out");
122097
- const cwd = path44.join(ownFolder(), "test");
122098
- fs41.mkdirSync(cwd, { recursive: true });
122495
+ const cwd = path45.join(ownFolder(), "test");
122496
+ fs42.mkdirSync(cwd, { recursive: true });
122099
122497
  const run3 = deps.plan(job.runtime, job.prompt, cwd, null, job.model, settingsOf(job));
122100
122498
  const startedAt = Date.now();
122101
122499
  if (run3.converse) {
@@ -122183,32 +122581,13 @@ Previews that cannot be drawn:
122183
122581
  ${undrawn2.map((l2) => `- ${l2}`).join("\n")}` : "");
122184
122582
  }
122185
122583
 
122186
- // src/settings-control.ts
122187
- import fs42 from "node:fs";
122188
- import path45 from "node:path";
122189
- var directory = () => path45.join(runnerHome(), "executors");
122190
- var epochFile = () => path45.join(runnerHome(), "account-generation");
122191
- function accountGeneration() {
122192
- try {
122193
- return fs42.readFileSync(epochFile(), "utf8");
122194
- } catch {
122195
- return "";
122196
- }
122197
- }
122198
- function executorRecord() {
122199
- fs42.mkdirSync(directory(), { recursive: true, mode: 448 });
122200
- const file2 = path45.join(directory(), `${process.pid}.json`);
122201
- fs42.writeFileSync(file2, "{}", { mode: 384 });
122202
- return () => fs42.rmSync(file2, { force: true });
122203
- }
122204
-
122205
122584
  // src/flow-worker.ts
122206
122585
  var FLOW_MARK = "WILDCRANE_FLOW_WORKER";
122207
122586
  var directory2 = () => path46.join(runnerHome(), "flow-workers");
122208
122587
  var fileOf2 = (id) => path46.join(directory2(), `${encodeURIComponent(id)}.json`);
122209
122588
  var stopFile = (id) => `${fileOf2(id)}.stop`;
122210
122589
  var flowWorkerEntry = fileURLToPath4(new URL("./flow-worker-main.mjs", import.meta.url));
122211
- var canKeepFlow = (job) => !!job.task && !!job.flow && ["create", "refine", "implement"].includes(job.flow.verb) && !job.agent && !job.review && !job.discussion && !job.test && !job.secret;
122590
+ var canKeepFlow = (job) => !!job.task && !!job.flow && ["create", "refine", "implement", "preview"].includes(job.flow.verb) && !job.agent && !job.review && !job.discussion && !job.test && !job.secret;
122212
122591
  function read3(id) {
122213
122592
  try {
122214
122593
  return JSON.parse(fs43.readFileSync(fileOf2(id), "utf8"));