wildcrane 0.11.9 → 0.11.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/kanban.mjs +1008 -890
  2. package/package.json +2 -2
package/dist/kanban.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // ai4kanban 0.11.9 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
2
+ // ai4kanban 0.11.11 — built from the CLI's TypeScript sources by cli/scripts/build.mjs.
3
3
  // Do not edit: every change belongs in cli/src/, and a build overwrites this file.
4
4
  import { createRequire as __ai4kanbanRequire } from 'node:module'
5
5
  const require = __ai4kanbanRequire(import.meta.url)
@@ -1168,8 +1168,8 @@ var require_command = __commonJS({
1168
1168
  "node_modules/commander/lib/command.js"(exports) {
1169
1169
  var EventEmitter = __require("node:events").EventEmitter;
1170
1170
  var childProcess = __require("node:child_process");
1171
- var path85 = __require("node:path");
1172
- var fs86 = __require("node:fs");
1171
+ var path87 = __require("node:path");
1172
+ var fs87 = __require("node:fs");
1173
1173
  var process2 = __require("node:process");
1174
1174
  var { Argument: Argument2, humanReadableArgName } = require_argument();
1175
1175
  var { CommanderError: CommanderError2 } = require_error();
@@ -2150,7 +2150,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2150
2150
  * @param {string} subcommandName
2151
2151
  */
2152
2152
  _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
2153
- if (fs86.existsSync(executableFile)) return;
2153
+ if (fs87.existsSync(executableFile)) return;
2154
2154
  const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
2155
2155
  const executableMissing = `'${executableFile}' does not exist
2156
2156
  - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
@@ -2168,11 +2168,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2168
2168
  let launchWithNode = false;
2169
2169
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
2170
2170
  function findFile(baseDir, baseName) {
2171
- const localBin = path85.resolve(baseDir, baseName);
2172
- if (fs86.existsSync(localBin)) return localBin;
2173
- if (sourceExt.includes(path85.extname(baseName))) return void 0;
2171
+ const localBin = path87.resolve(baseDir, baseName);
2172
+ if (fs87.existsSync(localBin)) return localBin;
2173
+ if (sourceExt.includes(path87.extname(baseName))) return void 0;
2174
2174
  const foundExt = sourceExt.find(
2175
- (ext) => fs86.existsSync(`${localBin}${ext}`)
2175
+ (ext) => fs87.existsSync(`${localBin}${ext}`)
2176
2176
  );
2177
2177
  if (foundExt) return `${localBin}${foundExt}`;
2178
2178
  return void 0;
@@ -2184,21 +2184,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
2184
2184
  if (this._scriptPath) {
2185
2185
  let resolvedScriptPath;
2186
2186
  try {
2187
- resolvedScriptPath = fs86.realpathSync(this._scriptPath);
2187
+ resolvedScriptPath = fs87.realpathSync(this._scriptPath);
2188
2188
  } catch {
2189
2189
  resolvedScriptPath = this._scriptPath;
2190
2190
  }
2191
- executableDir = path85.resolve(
2192
- path85.dirname(resolvedScriptPath),
2191
+ executableDir = path87.resolve(
2192
+ path87.dirname(resolvedScriptPath),
2193
2193
  executableDir
2194
2194
  );
2195
2195
  }
2196
2196
  if (executableDir) {
2197
2197
  let localFile = findFile(executableDir, executableFile);
2198
2198
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
2199
- const legacyName = path85.basename(
2199
+ const legacyName = path87.basename(
2200
2200
  this._scriptPath,
2201
- path85.extname(this._scriptPath)
2201
+ path87.extname(this._scriptPath)
2202
2202
  );
2203
2203
  if (legacyName !== this._name) {
2204
2204
  localFile = findFile(
@@ -2209,7 +2209,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2209
2209
  }
2210
2210
  executableFile = localFile || executableFile;
2211
2211
  }
2212
- launchWithNode = sourceExt.includes(path85.extname(executableFile));
2212
+ launchWithNode = sourceExt.includes(path87.extname(executableFile));
2213
2213
  let proc;
2214
2214
  if (process2.platform !== "win32") {
2215
2215
  if (launchWithNode) {
@@ -3056,7 +3056,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3056
3056
  * @return {Command}
3057
3057
  */
3058
3058
  nameFromFilename(filename) {
3059
- this._name = path85.basename(filename, path85.extname(filename));
3059
+ this._name = path87.basename(filename, path87.extname(filename));
3060
3060
  return this;
3061
3061
  }
3062
3062
  /**
@@ -3070,9 +3070,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3070
3070
  * @param {string} [path]
3071
3071
  * @return {(string|null|Command)}
3072
3072
  */
3073
- executableDir(path86) {
3074
- if (path86 === void 0) return this._executableDir;
3075
- this._executableDir = path86;
3073
+ executableDir(path88) {
3074
+ if (path88 === void 0) return this._executableDir;
3075
+ this._executableDir = path88;
3076
3076
  return this;
3077
3077
  }
3078
3078
  /**
@@ -5478,8 +5478,8 @@ var init_package = __esm({
5478
5478
  "package.json"() {
5479
5479
  package_default = {
5480
5480
  name: "wildcrane",
5481
- version: "0.11.9",
5482
- akbContract: 4,
5481
+ version: "0.11.11",
5482
+ akbContract: 5,
5483
5483
  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.",
5484
5484
  keywords: [
5485
5485
  "kanban",
@@ -8317,10 +8317,10 @@ function findRollout(threadId) {
8317
8317
  }
8318
8318
  for (const name of names4) {
8319
8319
  if (!name.startsWith("rollout-") || !name.endsWith(tail2)) continue;
8320
- const path85 = join(dir, name);
8320
+ const path87 = join(dir, name);
8321
8321
  try {
8322
- const at = statSync(path85).mtimeMs;
8323
- if (!newest2 || at > newest2.at) newest2 = { path: path85, at };
8322
+ const at = statSync(path87).mtimeMs;
8323
+ if (!newest2 || at > newest2.at) newest2 = { path: path87, at };
8324
8324
  } catch {
8325
8325
  }
8326
8326
  }
@@ -8328,11 +8328,11 @@ function findRollout(threadId) {
8328
8328
  return newest2?.path;
8329
8329
  }
8330
8330
  function readCodexRunFacts(threadId) {
8331
- const path85 = findRollout(threadId);
8332
- if (!path85) return void 0;
8331
+ const path87 = findRollout(threadId);
8332
+ if (!path87) return void 0;
8333
8333
  let raw;
8334
8334
  try {
8335
- raw = readFileSync(path85, "utf8");
8335
+ raw = readFileSync(path87, "utf8");
8336
8336
  } catch {
8337
8337
  return void 0;
8338
8338
  }
@@ -8460,8 +8460,8 @@ function renderCompleted(item) {
8460
8460
  const changes = Array.isArray(item.changes) ? item.changes : [];
8461
8461
  return changes.map((raw) => {
8462
8462
  const change2 = obj(raw);
8463
- const path85 = str2(change2.path);
8464
- return path85 ? `\u23FA ${str2(change2.kind) || "change"}(${path85})
8463
+ const path87 = str2(change2.path);
8464
+ return path87 ? `\u23FA ${str2(change2.kind) || "change"}(${path87})
8465
8465
  ` : "";
8466
8466
  }).join("");
8467
8467
  }
@@ -8720,10 +8720,10 @@ function readKimiRunFacts(sessionId) {
8720
8720
  const total = { input: 0, cacheCreation: 0, cacheRead: 0, output: 0 };
8721
8721
  let model;
8722
8722
  let holding = 0;
8723
- for (const { path: path85, main } of wireFiles(entry.sessionDir)) {
8723
+ for (const { path: path87, main } of wireFiles(entry.sessionDir)) {
8724
8724
  let raw;
8725
8725
  try {
8726
- raw = readFileSync2(path85, "utf8");
8726
+ raw = readFileSync2(path87, "utf8");
8727
8727
  } catch {
8728
8728
  continue;
8729
8729
  }
@@ -9004,8 +9004,8 @@ var init_tail = __esm({
9004
9004
  import fs24 from "node:fs";
9005
9005
  function whereHint(update2, title) {
9006
9006
  const locations = Array.isArray(update2.locations) ? update2.locations : [];
9007
- const path85 = str2(obj(locations[0]).path);
9008
- return path85 && !title.includes(path85) ? hint(path85) : "";
9007
+ const path87 = str2(obj(locations[0]).path);
9008
+ return path87 && !title.includes(path87) ? hint(path87) : "";
9009
9009
  }
9010
9010
  function saidBy(update2) {
9011
9011
  const content = Array.isArray(update2.content) ? update2.content : [];
@@ -9948,27 +9948,40 @@ import crypto3 from "node:crypto";
9948
9948
  import fs25 from "node:fs";
9949
9949
  import os4 from "node:os";
9950
9950
  import path28 from "node:path";
9951
+ function spawnGit(args, options) {
9952
+ const out = spawnSync3("git", args, {
9953
+ ...options,
9954
+ encoding: "utf8",
9955
+ stdio: ["ignore", "pipe", "pipe"],
9956
+ timeout: gitLimits.timeoutMs,
9957
+ killSignal: "SIGKILL"
9958
+ });
9959
+ if (out.error?.code === "ETIMEDOUT") throw new GitTimeoutError(`Git ${args[0]} timed out after ${gitLimits.timeoutMs / 1e3}s; the command was killed.`);
9960
+ return out;
9961
+ }
9951
9962
  function git(args, cwd = REPO_ROOT) {
9952
9963
  try {
9953
- const out = spawnSync3("git", args, { cwd, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true });
9964
+ const out = spawnGit(args, { cwd, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true });
9954
9965
  if (out.error || out.status !== 0) return null;
9955
9966
  return out.stdout;
9956
- } catch {
9967
+ } catch (error) {
9968
+ if (error instanceof GitTimeoutError) throw error;
9957
9969
  return null;
9958
9970
  }
9959
9971
  }
9960
9972
  function gitDiff(args, cwd = REPO_ROOT) {
9961
9973
  try {
9962
- const out = spawnSync3("git", args, { cwd, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true });
9974
+ const out = spawnGit(args, { cwd, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true });
9963
9975
  if (out.error || out.status !== 0 && out.status !== 1) return null;
9964
9976
  return out.stdout;
9965
- } catch {
9977
+ } catch (error) {
9978
+ if (error instanceof GitTimeoutError) throw error;
9966
9979
  return null;
9967
9980
  }
9968
9981
  }
9969
9982
  function tryGit(args, cwd = REPO_ROOT, env2) {
9970
9983
  try {
9971
- const out = spawnSync3("git", args, {
9984
+ const out = spawnGit(args, {
9972
9985
  cwd,
9973
9986
  encoding: "utf8",
9974
9987
  maxBuffer: MAX_OUTPUT,
@@ -9979,6 +9992,7 @@ function tryGit(args, cwd = REPO_ROOT, env2) {
9979
9992
  if (out.status !== 0) return { ok: false, why: (out.stderr || out.stdout || "").trim() };
9980
9993
  return { ok: true };
9981
9994
  } catch (e) {
9995
+ if (e instanceof GitTimeoutError) throw e;
9982
9996
  return { ok: false, why: e instanceof Error ? e.message : String(e) };
9983
9997
  }
9984
9998
  }
@@ -9987,7 +10001,7 @@ function boardManagedPaths() {
9987
10001
  }
9988
10002
  function outsideBoardForAdd(cwd = REPO_ROOT) {
9989
10003
  const kept2 = boardManagedPaths().filter(
9990
- (p) => spawnSync3("git", ["check-ignore", "-q", p], { cwd, windowsHide: true }).status !== 0
10004
+ (p) => spawnGit(["check-ignore", "-q", p], { cwd, windowsHide: true }).status !== 0
9991
10005
  );
9992
10006
  return ["--", ".", ...kept2.map((p) => `:(exclude)${p}`)];
9993
10007
  }
@@ -10107,10 +10121,10 @@ function treeMark(base, cwd = REPO_ROOT) {
10107
10121
  const index = path28.join(ensureAkbDir(), `index-${process.pid}-${Date.now()}`);
10108
10122
  try {
10109
10123
  const env2 = { ...process.env, GIT_INDEX_FILE: index };
10110
- const run2 = (args) => spawnSync3("git", args, { cwd, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true, env: env2 }).status === 0;
10124
+ const run2 = (args) => spawnGit(args, { cwd, encoding: "utf8", maxBuffer: MAX_OUTPUT, windowsHide: true, env: env2 }).status === 0;
10111
10125
  if (!run2(["read-tree", base])) return null;
10112
10126
  if (!run2(["add", "-A", ...outsideBoardForAdd(cwd)])) return null;
10113
- const tree = spawnSync3("git", ["write-tree"], {
10127
+ const tree = spawnGit(["write-tree"], {
10114
10128
  cwd,
10115
10129
  encoding: "utf8",
10116
10130
  maxBuffer: MAX_OUTPUT,
@@ -10118,7 +10132,8 @@ function treeMark(base, cwd = REPO_ROOT) {
10118
10132
  env: env2
10119
10133
  });
10120
10134
  return tree.status === 0 ? tree.stdout.trim() || null : null;
10121
- } catch {
10135
+ } catch (error) {
10136
+ if (error instanceof GitTimeoutError) throw error;
10122
10137
  return null;
10123
10138
  } finally {
10124
10139
  try {
@@ -10129,23 +10144,26 @@ function treeMark(base, cwd = REPO_ROOT) {
10129
10144
  }
10130
10145
  function reverseApplies(patch2, ref, cwd = REPO_ROOT) {
10131
10146
  if (!patch2.trim()) return false;
10132
- const index = path28.join(os4.tmpdir(), `akb-apply-${process.pid}-${Date.now()}.index`);
10147
+ const folder = fs25.mkdtempSync(path28.join(os4.tmpdir(), `akb-apply-${process.pid}-`));
10148
+ const index = path28.join(folder, "index");
10149
+ const patchFile = path28.join(folder, "patch");
10133
10150
  const env2 = { GIT_INDEX_FILE: index };
10134
10151
  try {
10152
+ fs25.writeFileSync(patchFile, patch2);
10135
10153
  if (!tryGit(["read-tree", ref], cwd, env2).ok) return false;
10136
- const out = spawnSync3("git", ["apply", "--cached", "--reverse", "--check", "-"], {
10154
+ const out = spawnGit(["apply", "--cached", "--reverse", "--check", patchFile], {
10137
10155
  cwd,
10138
- input: patch2,
10139
10156
  encoding: "utf8",
10140
10157
  maxBuffer: MAX_OUTPUT,
10141
10158
  windowsHide: true,
10142
10159
  env: { ...process.env, ...env2 }
10143
10160
  });
10144
10161
  return !out.error && out.status === 0;
10145
- } catch {
10162
+ } catch (error) {
10163
+ if (error instanceof GitTimeoutError) throw error;
10146
10164
  return false;
10147
10165
  } finally {
10148
- fs25.rmSync(index, { force: true });
10166
+ fs25.rmSync(folder, { recursive: true, force: true });
10149
10167
  }
10150
10168
  }
10151
10169
  function squashOnto(dir, base, message) {
@@ -10227,12 +10245,15 @@ function moveBranchRef(branch, commit, expect) {
10227
10245
  if (branchTip(branch) !== expect) return { moved: true };
10228
10246
  return { ok: false, error: `couldn't move ${branch} to ${commit.slice(0, 12)}: ${done2.why ?? "git refused"}` };
10229
10247
  }
10230
- var MAX_OUTPUT, scripted, posix, outsideBoard, deliveryBranch, deliveryWorktree, worktreeDir, inGitRepo, headCommit, worktreeExists, branchExists, pruneWorktreeMetadata, branchTip, isAncestor, changedPaths, branchPatch, lastCommitTouching, continueRebase, abortRebase, conflictedPaths, headingKind;
10248
+ var MAX_OUTPUT, gitLimits, GitTimeoutError, scripted, posix, outsideBoard, deliveryBranch, deliveryWorktree, worktreeDir, inGitRepo, headCommit, worktreeExists, branchExists, pruneWorktreeMetadata, branchTip, isAncestor, changedPaths, branchPatch, lastCommitTouching, continueRebase, abortRebase, conflictedPaths, headingKind;
10231
10249
  var init_worktree = __esm({
10232
10250
  "src/lib/agent/worktree.ts"() {
10233
10251
  "use strict";
10234
10252
  init_paths();
10235
10253
  MAX_OUTPUT = 64 * 1024 * 1024;
10254
+ gitLimits = { timeoutMs: 3e4 };
10255
+ GitTimeoutError = class extends Error {
10256
+ };
10236
10257
  scripted = (args, cwd) => tryGit(["-c", "core.hooksPath=/dev/null", ...args], cwd, { GIT_EDITOR: "true", GIT_SEQUENCE_EDITOR: "true" });
10237
10258
  posix = (p) => p.split(path28.sep).join("/");
10238
10259
  outsideBoard = () => [
@@ -10249,7 +10270,7 @@ var init_worktree = __esm({
10249
10270
  branchExists = (branch) => !!branch && git(["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]) !== null;
10250
10271
  pruneWorktreeMetadata = () => void git(["worktree", "prune"]);
10251
10272
  branchTip = (branch) => git(["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`])?.trim() || null;
10252
- isAncestor = (older, newer, cwd = REPO_ROOT) => spawnSync3("git", ["merge-base", "--is-ancestor", older, newer], { cwd, windowsHide: true }).status === 0;
10273
+ isAncestor = (older, newer, cwd = REPO_ROOT) => spawnGit(["merge-base", "--is-ancestor", older, newer], { cwd, windowsHide: true }).status === 0;
10253
10274
  changedPaths = (base, branch, cwd = REPO_ROOT) => {
10254
10275
  const out = git(["diff", "--name-only", base, branch, ...outsideBoard()], cwd);
10255
10276
  return out === null ? null : out.split("\n").filter(Boolean);
@@ -15547,6 +15568,252 @@ var init_complete = __esm({
15547
15568
  }
15548
15569
  });
15549
15570
 
15571
+ // src/lib/agent/stop.ts
15572
+ import { spawnSync as spawnSync4 } from "node:child_process";
15573
+ import { randomUUID as randomUUID5 } from "node:crypto";
15574
+ import fs39 from "node:fs";
15575
+ import os6 from "node:os";
15576
+ import path43 from "node:path";
15577
+ function markedInProc(entry, strict = false) {
15578
+ const pids = [];
15579
+ for (const name of fs39.readdirSync("/proc")) {
15580
+ if (!/^\d+$/.test(name)) continue;
15581
+ try {
15582
+ if (fs39.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
15583
+ } catch (error) {
15584
+ if (strict && !["ENOENT", "ESRCH"].includes(error.code ?? "")) {
15585
+ const stat = fs39.statSync(`/proc/${name}`, { throwIfNoEntry: false });
15586
+ if (stat?.uid === process.getuid?.()) throw error;
15587
+ }
15588
+ }
15589
+ }
15590
+ return pids;
15591
+ }
15592
+ function markedInPs(entry, roots) {
15593
+ const ps = spawnSync4("ps", ["-A", "-E", "-ww", "-o", "pid=,ppid=,command="], {
15594
+ encoding: "utf8",
15595
+ maxBuffer: 64 * 1024 * 1024,
15596
+ timeout: 5e3
15597
+ });
15598
+ if (ps.status !== 0 || !ps.stdout) throw new Error("\u65E0\u6CD5\u67E5\u8BE2\u8FDB\u7A0B\u6811\u3002");
15599
+ const children = /* @__PURE__ */ new Map();
15600
+ const listed2 = /* @__PURE__ */ new Set();
15601
+ const found2 = /* @__PURE__ */ new Set();
15602
+ for (const line of ps.stdout.split("\n")) {
15603
+ const m = /^\s*(\d+)\s+(\d+)\s(.*)$/.exec(line);
15604
+ if (!m) continue;
15605
+ const pid = Number(m[1]);
15606
+ const ppid = Number(m[2]);
15607
+ listed2.add(pid);
15608
+ children.set(ppid, [...children.get(ppid) ?? [], pid]);
15609
+ if (`${m[3]} `.includes(` ${entry} `)) found2.add(pid);
15610
+ }
15611
+ const queue = [...found2, ...roots.filter((pid) => listed2.has(pid))];
15612
+ for (const pid of queue) {
15613
+ found2.add(pid);
15614
+ for (const child of children.get(pid) ?? []) if (!found2.has(child)) queue.push(child);
15615
+ }
15616
+ return [...found2];
15617
+ }
15618
+ function marked(mark, roots = []) {
15619
+ if (WINDOWS3 || !mark.value) return [];
15620
+ const entry = `${mark.name}=${mark.value}`;
15621
+ try {
15622
+ const pids = process.platform === "linux" ? markedInProc(entry) : markedInPs(entry, roots);
15623
+ return pids.filter((pid) => pid !== process.pid);
15624
+ } catch {
15625
+ return [];
15626
+ }
15627
+ }
15628
+ function signal(pids, sig) {
15629
+ for (const pid of pids) {
15630
+ try {
15631
+ process.kill(pid, sig);
15632
+ } catch {
15633
+ }
15634
+ }
15635
+ }
15636
+ function stopWatchers(sessions, onlyPid, stillOwns = () => true, startedBefore) {
15637
+ if (sessions ? !sessions.length : onlyPid === void 0) return [];
15638
+ const command = WINDOWS3 ? "powershell.exe" : "ps";
15639
+ const args = WINDOWS3 ? ["-NoProfile", "-NonInteractive", "-Command", "Get-CimInstance Win32_Process | Select-Object ProcessId,CommandLine,@{Name='StartedAt';Expression={([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds()}} | ConvertTo-Json -Compress"] : ["-A", "-ww", "-o", "pid=,lstart=,command="];
15640
+ const out = spawnSync4(command, args, { encoding: "utf8", timeout: 5e3, maxBuffer: 16 * 1024 * 1024, windowsHide: true, env: { ...process.env, LC_ALL: "C" } });
15641
+ if (out.status !== 0) return [];
15642
+ let procs;
15643
+ try {
15644
+ procs = WINDOWS3 ? [].concat(JSON.parse(out.stdout)).map((p) => ({ pid: p.ProcessId, command: p.CommandLine ?? "", startedAt: p.StartedAt })) : out.stdout.split("\n").flatMap((line) => {
15645
+ const m = /^\s*(\d+)\s+(\S+\s+\S+\s+\d+\s+\d+:\d+:\d+\s+\d{4})\s+(.*)$/.exec(line);
15646
+ return m ? [{ pid: Number(m[1]), command: m[3], startedAt: Date.parse(m[2]) }] : [];
15647
+ });
15648
+ } catch {
15649
+ return [];
15650
+ }
15651
+ const known2 = sessions && new Set(sessions);
15652
+ const stopped2 = [];
15653
+ for (const proc of procs) {
15654
+ if (proc.pid === process.pid || onlyPid !== void 0 && proc.pid !== onlyPid) continue;
15655
+ if (startedBefore !== void 0 && (!Number.isFinite(proc.startedAt) || proc.startedAt > startedBefore)) continue;
15656
+ const match = /^"?[^\n]*?\bnode(?:\.exe)?"?\s+(?:"[^\n"]+\.mjs"|\S+\.mjs)\s+__watch\s+(\S+)(?:\s|$)/.exec(proc.command);
15657
+ const args2 = `${proc.command} `;
15658
+ const names4 = (flag, value) => args2.includes(` ${flag} ${value} `) || args2.includes(` ${flag} "${value}" `);
15659
+ const board2 = names4("--board", KANBAN) || KANBAN === path43.join(REPO_ROOT, "docs", "kanban") && names4("--dir", REPO_ROOT);
15660
+ if (!match || known2 && !known2.has(match[1]) || !board2 || !stillOwns()) continue;
15661
+ if (WINDOWS3) {
15662
+ if (killTreeOnWindows(proc.pid)) stopped2.push(proc.pid);
15663
+ } else {
15664
+ try {
15665
+ process.kill(-proc.pid, "SIGKILL");
15666
+ stopped2.push(proc.pid);
15667
+ } catch {
15668
+ }
15669
+ }
15670
+ }
15671
+ return stopped2;
15672
+ }
15673
+ function startedUnder(list, root, since) {
15674
+ const self = list.procs.find((p) => p.pid === root);
15675
+ const from = since ?? self?.startedAt;
15676
+ if (from === void 0 || list.bootedAt > from) return [];
15677
+ if (self && self.startedAt > from) return [];
15678
+ const found2 = self ? [root] : [];
15679
+ const seen = /* @__PURE__ */ new Set([root]);
15680
+ const queue = [{ pid: root, startedAt: from }];
15681
+ for (const parent of queue) {
15682
+ for (const p of list.procs) {
15683
+ if (p.ppid !== parent.pid || seen.has(p.pid) || p.startedAt < parent.startedAt) continue;
15684
+ seen.add(p.pid);
15685
+ found2.push(p.pid);
15686
+ queue.push(p);
15687
+ }
15688
+ }
15689
+ return found2.reverse();
15690
+ }
15691
+ function readProcList(out) {
15692
+ const procs = [];
15693
+ let bootedAt;
15694
+ for (const line of out.split(/\r?\n/)) {
15695
+ const boot = /^boot (\d+)$/.exec(line.trim());
15696
+ if (boot) bootedAt = Number(boot[1]);
15697
+ const m = /^(\d+) (\d+) (\d+)$/.exec(line.trim());
15698
+ if (m) procs.push({ pid: Number(m[1]), ppid: Number(m[2]), startedAt: Number(m[3]) });
15699
+ }
15700
+ return bootedAt !== void 0 && procs.length ? { procs, bootedAt } : void 0;
15701
+ }
15702
+ function procsOnWindows() {
15703
+ const ps = spawnSync4("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", LIST_PROCS], {
15704
+ encoding: "utf8",
15705
+ maxBuffer: 64 * 1024 * 1024,
15706
+ timeout: 5e3,
15707
+ windowsHide: true
15708
+ });
15709
+ return ps.status === 0 && ps.stdout ? readProcList(ps.stdout) : void 0;
15710
+ }
15711
+ function killUnderOnWindows(pid, since) {
15712
+ if (!WINDOWS3 || !pid) return;
15713
+ const list = procsOnWindows();
15714
+ if (!list) return;
15715
+ const pids = startedUnder(list, pid, since).filter((p) => p !== process.pid);
15716
+ if (!pids.length) return;
15717
+ spawnSync4("taskkill", ["/F", ...pids.flatMap((p) => ["/PID", String(p)])], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
15718
+ }
15719
+ function killMarked(mark, agent) {
15720
+ if (WINDOWS3) {
15721
+ if (agent) killUnderOnWindows(agent.pid, agent.since);
15722
+ return;
15723
+ }
15724
+ signal(marked(mark), "SIGKILL");
15725
+ }
15726
+ function killTreeOnWindows(pid) {
15727
+ if (!WINDOWS3 || !pid) return false;
15728
+ const out = spawnSync4("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
15729
+ return out.status === 0;
15730
+ }
15731
+ function later(ms, fn) {
15732
+ const t = setTimeout(fn, ms);
15733
+ if (typeof t.unref === "function") t.unref();
15734
+ }
15735
+ function endAgent(child, mark, graceMs) {
15736
+ const term = (sig) => {
15737
+ try {
15738
+ child.kill(sig);
15739
+ } catch {
15740
+ }
15741
+ };
15742
+ if (killTreeOnWindows(child.pid)) return;
15743
+ killUnderOnWindows(child.pid);
15744
+ const seen = new Set(marked(mark, child.pid ? [child.pid] : []));
15745
+ term("SIGTERM");
15746
+ signal([...seen].filter((pid) => pid !== child.pid), "SIGTERM");
15747
+ const round = (left) => {
15748
+ const pids = marked(mark, [...seen]);
15749
+ signal(pids, "SIGKILL");
15750
+ for (const pid of pids) seen.add(pid);
15751
+ if (pids.length && left > 1) later(KILL_ROUND_MS, () => round(left - 1));
15752
+ };
15753
+ later(graceMs, () => {
15754
+ term("SIGKILL");
15755
+ round(KILL_ROUNDS);
15756
+ });
15757
+ }
15758
+ function killRunning() {
15759
+ for (const [child, mark] of running) {
15760
+ if (killTreeOnWindows(child.pid)) continue;
15761
+ killUnderOnWindows(child.pid);
15762
+ signal(marked(mark, child.pid ? [child.pid] : []), "SIGKILL");
15763
+ try {
15764
+ child.kill("SIGKILL");
15765
+ } catch {
15766
+ }
15767
+ }
15768
+ running.clear();
15769
+ }
15770
+ function unlisten() {
15771
+ for (const [sig, fn] of listening) process.removeListener(sig, fn);
15772
+ listening.clear();
15773
+ }
15774
+ function onQuit(sig) {
15775
+ killRunning();
15776
+ unlisten();
15777
+ if (process.listenerCount(sig) === 0) process.exit(128 + os6.constants.signals[sig]);
15778
+ }
15779
+ function trackAgent(child, mark) {
15780
+ if (!child.pid) return;
15781
+ running.set(child, mark);
15782
+ child.once("close", () => {
15783
+ running.delete(child);
15784
+ if (!running.size) unlisten();
15785
+ });
15786
+ for (const sig of QUIT_SIGNALS) {
15787
+ if (listening.has(sig) || sig === "SIGINT" && interruptIsTheCallers) continue;
15788
+ const fn = () => onQuit(sig);
15789
+ listening.set(sig, fn);
15790
+ process.on(sig, fn);
15791
+ }
15792
+ }
15793
+ var runMark, stopMark, markEnv, WINDOWS3, KILL_ROUND_MS, KILL_ROUNDS, LIST_PROCS, running, QUIT_SIGNALS, listening, interruptIsTheCallers;
15794
+ var init_stop = __esm({
15795
+ "src/lib/agent/stop.ts"() {
15796
+ "use strict";
15797
+ init_env();
15798
+ init_paths();
15799
+ runMark = (sessionId) => ({ name: RUN_ENV, value: sessionId });
15800
+ stopMark = () => ({ name: STOP_ENV, value: randomUUID5() });
15801
+ markEnv = (env2, mark) => ({ ...env2, [mark.name]: mark.value });
15802
+ WINDOWS3 = process.platform === "win32";
15803
+ KILL_ROUND_MS = 300;
15804
+ KILL_ROUNDS = 3;
15805
+ LIST_PROCS = [
15806
+ "$ErrorActionPreference = 'Stop'",
15807
+ "Get-CimInstance Win32_Process | ForEach-Object { if ($_.CreationDate) { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } }",
15808
+ "'boot {0}' -f ([DateTimeOffset](Get-CimInstance Win32_OperatingSystem).LastBootUpTime).ToUnixTimeMilliseconds()"
15809
+ ].join("; ");
15810
+ running = /* @__PURE__ */ new Map();
15811
+ QUIT_SIGNALS = ["SIGTERM", "SIGINT", "SIGHUP"];
15812
+ listening = /* @__PURE__ */ new Map();
15813
+ interruptIsTheCallers = false;
15814
+ }
15815
+ });
15816
+
15550
15817
  // src/lib/agent/pause.ts
15551
15818
  function deliveryState(delivery, questions) {
15552
15819
  const landing = delivery.landing;
@@ -15735,12 +16002,12 @@ var init_runner = __esm({
15735
16002
  });
15736
16003
 
15737
16004
  // src/lib/agent/rules.ts
15738
- import fs39 from "node:fs";
15739
- import path43 from "node:path";
16005
+ import fs40 from "node:fs";
16006
+ import path44 from "node:path";
15740
16007
  function ruleFile(agent) {
15741
16008
  if (!agent || hiddenRole(agent)) return "";
15742
16009
  try {
15743
- return fs39.readFileSync(rulePath(agent), "utf8").trim();
16010
+ return fs40.readFileSync(rulePath(agent), "utf8").trim();
15744
16011
  } catch {
15745
16012
  return "";
15746
16013
  }
@@ -15755,11 +16022,11 @@ function setAgentRule(agent, text5) {
15755
16022
  const rule = String(text5 ?? "").trim();
15756
16023
  try {
15757
16024
  if (!rule) {
15758
- fs39.rmSync(rulePath(agent), { force: true });
16025
+ fs40.rmSync(rulePath(agent), { force: true });
15759
16026
  return { ok: true };
15760
16027
  }
15761
- fs39.mkdirSync(RULES, { recursive: true });
15762
- fs39.writeFileSync(rulePath(agent), `${rule}
16028
+ fs40.mkdirSync(RULES, { recursive: true });
16029
+ fs40.writeFileSync(rulePath(agent), `${rule}
15763
16030
  `);
15764
16031
  return { ok: true };
15765
16032
  } catch (err) {
@@ -15807,7 +16074,7 @@ function migrateFlowRules() {
15807
16074
  adoptRenamedRules();
15808
16075
  let here;
15809
16076
  try {
15810
- here = new Set(fs39.readdirSync(RULES));
16077
+ here = new Set(fs40.readdirSync(RULES));
15811
16078
  } catch {
15812
16079
  return [];
15813
16080
  }
@@ -15818,9 +16085,9 @@ function migrateFlowRules() {
15818
16085
  if (!from.length) continue;
15819
16086
  const parts = [ruleFile(owner.name), ...from.map(ruleFile)].filter(Boolean);
15820
16087
  try {
15821
- if (parts.length) fs39.writeFileSync(rulePath(owner.name), `${parts.join("\n\n")}
16088
+ if (parts.length) fs40.writeFileSync(rulePath(owner.name), `${parts.join("\n\n")}
15822
16089
  `);
15823
- for (const flow of from) fs39.rmSync(rulePath(flow), { force: true });
16090
+ for (const flow of from) fs40.rmSync(rulePath(flow), { force: true });
15824
16091
  } catch (err) {
15825
16092
  notes.push(`could not move the ${from.join(", ")} rule(s) onto \`${owner.name}\`: ${String(err)}`);
15826
16093
  continue;
@@ -15834,7 +16101,7 @@ function migrateFlowRules() {
15834
16101
  function adoptRenamedRules() {
15835
16102
  let here;
15836
16103
  try {
15837
- here = fs39.readdirSync(RULES);
16104
+ here = fs40.readdirSync(RULES);
15838
16105
  } catch {
15839
16106
  return;
15840
16107
  }
@@ -15844,13 +16111,13 @@ function adoptRenamedRules() {
15844
16111
  const now = RENAMED_ROLES[was] ?? canonicalSpecAgent(was);
15845
16112
  if (now === was) continue;
15846
16113
  try {
15847
- if (!fs39.existsSync(rulePath(now))) fs39.renameSync(rulePath(was), rulePath(now));
16114
+ if (!fs40.existsSync(rulePath(now))) fs40.renameSync(rulePath(was), rulePath(now));
15848
16115
  else if (FOLDED_SPEC_AGENTS.has(was)) {
15849
16116
  const kept2 = ruleFile(now);
15850
16117
  const carried = ruleFile(was);
15851
- if (carried && !kept2.includes(carried)) fs39.writeFileSync(rulePath(now), `${[kept2, carried].filter(Boolean).join("\n\n")}
16118
+ if (carried && !kept2.includes(carried)) fs40.writeFileSync(rulePath(now), `${[kept2, carried].filter(Boolean).join("\n\n")}
15852
16119
  `);
15853
- fs39.rmSync(rulePath(was), { force: true });
16120
+ fs40.rmSync(rulePath(was), { force: true });
15854
16121
  }
15855
16122
  } catch {
15856
16123
  }
@@ -15867,7 +16134,7 @@ var init_rules2 = __esm({
15867
16134
  init_runner();
15868
16135
  init_workflows();
15869
16136
  init_types3();
15870
- rulePath = (agent) => path43.join(RULES, `${agent}.md`);
16137
+ rulePath = (agent) => path44.join(RULES, `${agent}.md`);
15871
16138
  notOnTheRoster = (name) => `"${name}" is not an agent on this board. It has: ${agentNames().join(", ")}.`;
15872
16139
  flowForRequest = (req) => req.refineRound !== void 0 && REFINE_ACTIONS.has(req.action) ? flowByCommand("refine") : flowByAction(req.action);
15873
16140
  ruleOwnerSays = (owner) => `\`${owner.name}\` agent carries one rule of its own${owner.role ? ", on every flow it runs" : ""}`;
@@ -15952,8 +16219,8 @@ var init_source = __esm({
15952
16219
  });
15953
16220
 
15954
16221
  // src/lib/card-sources.ts
15955
- import fs40 from "node:fs";
15956
- import path44 from "node:path";
16222
+ import fs41 from "node:fs";
16223
+ import path45 from "node:path";
15957
16224
  function planById(id) {
15958
16225
  const found2 = readPlan(`plans/${id}-.md`);
15959
16226
  return found2?.text.trim() ? found2 : null;
@@ -15963,8 +16230,8 @@ function cardLink(id) {
15963
16230
  const found2 = open3 ?? locateArchived(id);
15964
16231
  if (!found2) return null;
15965
16232
  try {
15966
- const file = found2.kind === "group" ? path44.join(found2.target, "root.md") : found2.target;
15967
- const title = parseFrontmatter(fs40.readFileSync(file, "utf8")).meta?.title ?? "";
16233
+ const file = found2.kind === "group" ? path45.join(found2.target, "root.md") : found2.target;
16234
+ const title = parseFrontmatter(fs41.readFileSync(file, "utf8")).meta?.title ?? "";
15968
16235
  return { kind: "card", ref: String(id), title, ...open3 ? {} : { archived: true } };
15969
16236
  } catch {
15970
16237
  return null;
@@ -15989,7 +16256,7 @@ function link(ref, items) {
15989
16256
  if (ref.kind === "plan") return planLink(ref.id);
15990
16257
  if (ref.kind === "card") return cardLink(ref.id);
15991
16258
  if (ref.kind === "url") return urlLink(ref.url);
15992
- const item = items().find((signal2) => path44.basename(signal2.relPath) === ref.file);
16259
+ const item = items().find((signal2) => path45.basename(signal2.relPath) === ref.file);
15993
16260
  return item ? itemLink(item) : null;
15994
16261
  }
15995
16262
  function cardSources(meta, body) {
@@ -16030,12 +16297,12 @@ var init_card_sources = __esm({
16030
16297
  });
16031
16298
 
16032
16299
  // src/lib/view/read.ts
16033
- import fs41 from "node:fs";
16034
- import path45 from "node:path";
16300
+ import fs42 from "node:fs";
16301
+ import path46 from "node:path";
16035
16302
  function readCard(file, relFromTodo) {
16036
- const id = idPrefix(path45.basename(relFromTodo));
16303
+ const id = idPrefix(path46.basename(relFromTodo));
16037
16304
  if (id === null) {
16038
- const parts = relFromTodo.split(path45.sep);
16305
+ const parts = relFromTodo.split(path46.sep);
16039
16306
  const folderId = idPrefix(parts[parts.length - 2] || "");
16040
16307
  if (folderId === null) return null;
16041
16308
  return buildCard(folderId, file, relFromTodo);
@@ -16043,10 +16310,10 @@ function readCard(file, relFromTodo) {
16043
16310
  return buildCard(id, file, relFromTodo);
16044
16311
  }
16045
16312
  function buildCard(id, file, relFromTodo) {
16046
- const text5 = fs41.readFileSync(file, "utf8");
16313
+ const text5 = fs42.readFileSync(file, "utf8");
16047
16314
  const { meta, body } = parseFrontmatter(text5);
16048
16315
  if (!meta) return null;
16049
- const relPath = relFromTodo.split(path45.sep).join("/");
16316
+ const relPath = relFromTodo.split(path46.sep).join("/");
16050
16317
  const flow = workflowFor(meta.workflow);
16051
16318
  const plan = !!meta.workflow && archivesOnApproval(flow);
16052
16319
  const stages = cardStages(meta, flow).length;
@@ -16055,7 +16322,7 @@ function buildCard(id, file, relFromTodo) {
16055
16322
  // Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
16056
16323
  // read here and a card read by the contract agree on what version this is.
16057
16324
  revision: revisionOf(text5),
16058
- updatedAt: fs41.statSync(file).mtime.toISOString(),
16325
+ updatedAt: fs42.statSync(file).mtime.toISOString(),
16059
16326
  relPath,
16060
16327
  title: meta.title,
16061
16328
  priority: meta.priority,
@@ -16076,22 +16343,22 @@ function buildCard(id, file, relFromTodo) {
16076
16343
  };
16077
16344
  }
16078
16345
  function readGroup2(folderName) {
16079
- const groupDir = path45.join(TODO, folderName);
16080
- const rootFile = path45.join(groupDir, "root.md");
16081
- if (!fs41.existsSync(rootFile)) return null;
16082
- const root = readCard(rootFile, path45.join(folderName, "root.md"));
16346
+ const groupDir = path46.join(TODO, folderName);
16347
+ const rootFile = path46.join(groupDir, "root.md");
16348
+ if (!fs42.existsSync(rootFile)) return null;
16349
+ const root = readCard(rootFile, path46.join(folderName, "root.md"));
16083
16350
  if (!root) return null;
16084
16351
  root.isGroup = true;
16085
16352
  const { total, resolved: resolved2 } = subtaskLines(root.body);
16086
16353
  root.subtaskLines = { total, resolved: resolved2 };
16087
16354
  const subCards = [];
16088
16355
  const recurse = (dir, relDir) => {
16089
- for (const entry of fs41.readdirSync(dir, { withFileTypes: true })) {
16090
- const childRel = path45.join(relDir, entry.name);
16356
+ for (const entry of fs42.readdirSync(dir, { withFileTypes: true })) {
16357
+ const childRel = path46.join(relDir, entry.name);
16091
16358
  if (entry.isDirectory()) {
16092
- recurse(path45.join(dir, entry.name), childRel);
16359
+ recurse(path46.join(dir, entry.name), childRel);
16093
16360
  } else if (entry.name.endsWith(".md") && entry.name !== "README.md" && entry.name !== "root.md") {
16094
- const c = readCard(path45.join(dir, entry.name), childRel);
16361
+ const c = readCard(path46.join(dir, entry.name), childRel);
16095
16362
  if (c) {
16096
16363
  c.parent = { id: root.id, title: root.title };
16097
16364
  subCards.push(c);
@@ -16112,12 +16379,12 @@ function readGroup2(folderName) {
16112
16379
  return { root, subCards };
16113
16380
  }
16114
16381
  function standaloneCards(dirRel) {
16115
- const dir = dirRel ? path45.join(TODO, dirRel) : TODO;
16116
- if (!fs41.existsSync(dir)) return [];
16382
+ const dir = dirRel ? path46.join(TODO, dirRel) : TODO;
16383
+ if (!fs42.existsSync(dir)) return [];
16117
16384
  const cards = [];
16118
- for (const entry of fs41.readdirSync(dir, { withFileTypes: true })) {
16385
+ for (const entry of fs42.readdirSync(dir, { withFileTypes: true })) {
16119
16386
  if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
16120
- const c = readCard(path45.join(dir, entry.name), path45.join(dirRel, entry.name));
16387
+ const c = readCard(path46.join(dir, entry.name), path46.join(dirRel, entry.name));
16121
16388
  if (c) cards.push(c);
16122
16389
  }
16123
16390
  }
@@ -16129,7 +16396,7 @@ function collectCards() {
16129
16396
  const top = standaloneCards("");
16130
16397
  board2.push(...top);
16131
16398
  every.push(...top);
16132
- for (const entry of fs41.readdirSync(TODO, { withFileTypes: true })) {
16399
+ for (const entry of fs42.readdirSync(TODO, { withFileTypes: true })) {
16133
16400
  if (!entry.isDirectory()) continue;
16134
16401
  if (isGroupFolder(entry.name)) {
16135
16402
  const g = readGroup2(entry.name);
@@ -16161,7 +16428,7 @@ function findCard(id) {
16161
16428
  }
16162
16429
  function attachSources(card) {
16163
16430
  try {
16164
- const { meta, body } = parseFrontmatter(fs41.readFileSync(path45.join(TODO, card.relPath), "utf8"));
16431
+ const { meta, body } = parseFrontmatter(fs42.readFileSync(path46.join(TODO, card.relPath), "utf8"));
16165
16432
  const sources = meta ? cardSources(meta, body) : [];
16166
16433
  if (sources.length) card.sources = sources;
16167
16434
  } catch {
@@ -16349,8 +16616,8 @@ var init_review = __esm({
16349
16616
  });
16350
16617
 
16351
16618
  // src/lib/agent/deliveries.ts
16352
- import fs42 from "node:fs";
16353
- import path46 from "node:path";
16619
+ import fs43 from "node:fs";
16620
+ import path47 from "node:path";
16354
16621
  function writeAudit(delivery, runs) {
16355
16622
  const known2 = new Map(readAudit(delivery.deliveryId)?.sessions.map((s) => [s.sessionId, s]) ?? []);
16356
16623
  const sessions = delivery.sessions.flatMap((id) => {
@@ -16378,10 +16645,10 @@ function writeAudit(delivery, runs) {
16378
16645
  }
16379
16646
  function writeAuditFile(record) {
16380
16647
  try {
16381
- fs42.mkdirSync(DELIVERIES, { recursive: true });
16648
+ fs43.mkdirSync(DELIVERIES, { recursive: true });
16382
16649
  const tmp = `${auditPath(record.deliveryId)}.tmp`;
16383
- fs42.writeFileSync(tmp, JSON.stringify(record, null, 2) + "\n");
16384
- fs42.renameSync(tmp, auditPath(record.deliveryId));
16650
+ fs43.writeFileSync(tmp, JSON.stringify(record, null, 2) + "\n");
16651
+ fs43.renameSync(tmp, auditPath(record.deliveryId));
16385
16652
  return true;
16386
16653
  } catch {
16387
16654
  return false;
@@ -16389,7 +16656,7 @@ function writeAuditFile(record) {
16389
16656
  }
16390
16657
  function readAudit(deliveryId) {
16391
16658
  try {
16392
- const data = JSON.parse(fs42.readFileSync(auditPath(deliveryId), "utf8"));
16659
+ const data = JSON.parse(fs43.readFileSync(auditPath(deliveryId), "utf8"));
16393
16660
  return { sessions: Array.isArray(data?.sessions) ? data.sessions : [] };
16394
16661
  } catch {
16395
16662
  return null;
@@ -16404,7 +16671,7 @@ function syncAudit(deliveryId, just) {
16404
16671
  }
16405
16672
  function wholeAudit(file) {
16406
16673
  try {
16407
- const data = JSON.parse(fs42.readFileSync(file, "utf8"));
16674
+ const data = JSON.parse(fs43.readFileSync(file, "utf8"));
16408
16675
  return typeof data?.deliveryId === "string" && Array.isArray(data.sessions) ? data : null;
16409
16676
  } catch {
16410
16677
  return null;
@@ -16417,14 +16684,14 @@ function activeAudit(file) {
16417
16684
  function allAudits() {
16418
16685
  let names4;
16419
16686
  try {
16420
- names4 = fs42.readdirSync(DELIVERIES);
16687
+ names4 = fs43.readdirSync(DELIVERIES);
16421
16688
  } catch {
16422
16689
  return [];
16423
16690
  }
16424
16691
  const out = [];
16425
16692
  for (const name of names4) {
16426
16693
  if (!name.endsWith(".json")) continue;
16427
- const audit = wholeAudit(path46.join(DELIVERIES, name));
16694
+ const audit = wholeAudit(path47.join(DELIVERIES, name));
16428
16695
  if (audit) out.push(audit);
16429
16696
  }
16430
16697
  return out;
@@ -16535,11 +16802,11 @@ function resumeRefusal(delivery, store) {
16535
16802
  );
16536
16803
  }
16537
16804
  if (!worktreeExists(delivery.worktree)) {
16538
- const path85 = delivery.worktree ?? "";
16805
+ const path87 = delivery.worktree ?? "";
16539
16806
  return refusal(
16540
16807
  "deliveryWorktreeGone",
16541
- `delivery ${id}'s worktree ${path85} is gone, so there is nothing to carry on. ${rebuild}`,
16542
- { id, task, path: path85, command: discard }
16808
+ `delivery ${id}'s worktree ${path87} is gone, so there is nothing to carry on. ${rebuild}`,
16809
+ { id, task, path: path87, command: discard }
16543
16810
  );
16544
16811
  }
16545
16812
  if (!branchExists(delivery.branch)) {
@@ -16592,11 +16859,12 @@ function tidyCheckout(deliveryId) {
16592
16859
  const store = readStore();
16593
16860
  const row = store.deliveries.find((d) => d.deliveryId === deliveryId) ?? auditOnly(deliveryId);
16594
16861
  if (!row || row.status === "active") return NOTHING;
16595
- if (!row.worktree && !row.branch) return NOTHING;
16596
- if (isResumable(row)) return { removed: false, kept: true };
16597
16862
  if (store.runs.some((r) => r.deliveryId === deliveryId && runIsLive(r))) {
16598
16863
  return { removed: false, kept: false, error: `a run of delivery ${deliveryId} is still going`, reason: "deliveryRunGoing", args: { id: deliveryId } };
16599
16864
  }
16865
+ if (row.status !== "finished" || Date.now() - (row.endedAt ?? 0) > 3e4) stopWatchers(row.sessions);
16866
+ if (!row.worktree && !row.branch) return NOTHING;
16867
+ if (isResumable(row)) return { removed: false, kept: true };
16600
16868
  const removed = removeWorktree(row.worktree, row.branch, true);
16601
16869
  if (!removed.ok) return { removed: false, kept: false, error: removed.error };
16602
16870
  forgetCheckout(deliveryId);
@@ -16619,7 +16887,10 @@ function forgetCheckout(deliveryId) {
16619
16887
  function sweepCheckouts() {
16620
16888
  const seen = /* @__PURE__ */ new Set();
16621
16889
  const complaints = [];
16622
- const rows = [...readStore().deliveries, ...allAudits().flatMap((a) => auditRow(a) ?? [])];
16890
+ const store = readStore();
16891
+ const rows = [...store.deliveries, ...allAudits().flatMap((a) => auditRow(a) ?? [])];
16892
+ const ended = rows.filter((row) => row.status !== "active" && (row.status !== "finished" || Date.now() - (row.endedAt ?? 0) > 3e4) && !store.runs.some((r) => r.deliveryId === row.deliveryId && runIsLive(r)));
16893
+ stopWatchers([...new Set(ended.flatMap((row) => row.sessions))]);
16623
16894
  for (const row of rows) {
16624
16895
  if (seen.has(row.deliveryId) || row.status === "active" || !row.worktree) continue;
16625
16896
  seen.add(row.deliveryId);
@@ -16672,10 +16943,10 @@ function carryOnFrom(deliveryId) {
16672
16943
  function approvedRequirements(cardId2) {
16673
16944
  const found2 = locate(cardId2);
16674
16945
  if (!found2) return "";
16675
- const file = found2.kind === "group" ? path46.join(found2.target, "root.md") : found2.target;
16946
+ const file = found2.kind === "group" ? path47.join(found2.target, "root.md") : found2.target;
16676
16947
  let text5;
16677
16948
  try {
16678
- text5 = fs42.readFileSync(file, "utf8");
16949
+ text5 = fs43.readFileSync(file, "utf8");
16679
16950
  } catch {
16680
16951
  return "";
16681
16952
  }
@@ -16705,8 +16976,8 @@ function cardMeta2(cardId2) {
16705
16976
  try {
16706
16977
  const found2 = locate(cardId2);
16707
16978
  if (!found2) return null;
16708
- const file = found2.kind === "group" ? path46.join(found2.target, "root.md") : found2.target;
16709
- return parseFrontmatter(fs42.readFileSync(file, "utf8")).meta;
16979
+ const file = found2.kind === "group" ? path47.join(found2.target, "root.md") : found2.target;
16980
+ return parseFrontmatter(fs43.readFileSync(file, "utf8")).meta;
16710
16981
  } catch {
16711
16982
  return null;
16712
16983
  }
@@ -16955,6 +17226,7 @@ var init_deliveries = __esm({
16955
17226
  init_complete();
16956
17227
  init_outputs();
16957
17228
  init_env();
17229
+ init_stop();
16958
17230
  init_flows();
16959
17231
  init_pause();
16960
17232
  init_rules2();
@@ -16964,7 +17236,7 @@ var init_deliveries = __esm({
16964
17236
  init_store();
16965
17237
  init_types3();
16966
17238
  init_worktree();
16967
- auditPath = (deliveryId) => path46.join(DELIVERIES, `${deliveryId}.json`);
17239
+ auditPath = (deliveryId) => path47.join(DELIVERIES, `${deliveryId}.json`);
16968
17240
  activeAudits = () => allAudits().filter((a) => a.status === "active");
16969
17241
  auditRow = (audit) => readDeliveryRow({ ...audit, sessions: audit.sessions.map((s) => s.sessionId) });
16970
17242
  lastSessionRunning = (audit) => audit.sessions[audit.sessions.length - 1]?.status === "running";
@@ -16992,9 +17264,44 @@ var init_deliveries = __esm({
16992
17264
  }
16993
17265
  });
16994
17266
 
16995
- // src/lib/agent/answers.ts
16996
- function answerOutcome(delivery) {
16997
- return pendingAnswers(delivery).some((a) => a.outcome === "changed") ? "changed" : "unchanged";
17267
+ // src/lib/agent/landing-lock.ts
17268
+ import fs44 from "node:fs";
17269
+ import path48 from "node:path";
17270
+ function lockLanding() {
17271
+ const dir = path48.join(SESSIONS_DIR, ".landing.lock");
17272
+ try {
17273
+ const entries = fs44.readdirSync(dir);
17274
+ const token3 = entries.length === 1 ? entries[0] : "";
17275
+ const match = /^(\d+)-[a-f0-9-]{36}$/.exec(token3);
17276
+ const stat = fs44.statSync(dir);
17277
+ if (match && Date.now() - stat.mtimeMs > landingLimits.staleMs) {
17278
+ stopWatchers(void 0, Number(match[1]), () => {
17279
+ const now = fs44.readdirSync(dir);
17280
+ return now.length === 1 && now[0] === token3 && Date.now() - fs44.statSync(dir).mtimeMs > landingLimits.staleMs;
17281
+ }, stat.birthtimeMs || stat.mtimeMs);
17282
+ }
17283
+ } catch {
17284
+ }
17285
+ return tryLock(dir);
17286
+ }
17287
+ function renewLandingLock() {
17288
+ const now = /* @__PURE__ */ new Date();
17289
+ fs44.utimesSync(path48.join(SESSIONS_DIR, ".landing.lock"), now, now);
17290
+ }
17291
+ var landingLimits;
17292
+ var init_landing_lock = __esm({
17293
+ "src/lib/agent/landing-lock.ts"() {
17294
+ "use strict";
17295
+ init_lock();
17296
+ init_paths();
17297
+ init_stop();
17298
+ landingLimits = { staleMs: 5 * 6e4 };
17299
+ }
17300
+ });
17301
+
17302
+ // src/lib/agent/answers.ts
17303
+ function answerOutcome(delivery) {
17304
+ return pendingAnswers(delivery).some((a) => a.outcome === "changed") ? "changed" : "unchanged";
16998
17305
  }
16999
17306
  function takeUnchanged(delivery) {
17000
17307
  if (!pendingAnswers(delivery).some((a) => a.outcome === "unchanged")) return;
@@ -17056,8 +17363,8 @@ var init_retry = __esm({
17056
17363
  });
17057
17364
 
17058
17365
  // src/lib/agent/landing.ts
17059
- import fs43 from "node:fs";
17060
- import path47 from "node:path";
17366
+ import fs45 from "node:fs";
17367
+ import path49 from "node:path";
17061
17368
  function waitingOut(delivery, now = Date.now()) {
17062
17369
  const landing = delivery.landing;
17063
17370
  if (!landing) return false;
@@ -17193,8 +17500,9 @@ function noteQueue(held4) {
17193
17500
  }
17194
17501
  async function advanceLanding() {
17195
17502
  let release;
17503
+ let current;
17196
17504
  try {
17197
- release = tryLock(path47.join(SESSIONS_DIR, ".landing.lock"));
17505
+ release = lockLanding();
17198
17506
  if (!release) return null;
17199
17507
  const owed = await owedRestart();
17200
17508
  if (owed) return owed;
@@ -17209,11 +17517,19 @@ async function advanceLanding() {
17209
17517
  return null;
17210
17518
  }
17211
17519
  tried.add(picked.deliveryId);
17520
+ current = picked;
17521
+ renewLandingLock();
17212
17522
  const step = await landStep(picked);
17213
17523
  if (step.start) return step.start;
17214
17524
  if (!step.done) return null;
17215
17525
  }
17216
- } catch {
17526
+ } catch (error) {
17527
+ if (current && error instanceof GitTimeoutError) {
17528
+ giveUpSlot(current, error.message);
17529
+ patchLanding(current.deliveryId, (landing) => {
17530
+ landing.retryAt = Date.now() + 3e4;
17531
+ });
17532
+ }
17217
17533
  return null;
17218
17534
  } finally {
17219
17535
  release?.();
@@ -17530,7 +17846,7 @@ async function settleAlreadyLanded(delivery) {
17530
17846
  return true;
17531
17847
  }
17532
17848
  function repairLanding() {
17533
- const release = tryLock(path47.join(SESSIONS_DIR, ".landing.lock"));
17849
+ const release = lockLanding();
17534
17850
  if (!release) return [];
17535
17851
  try {
17536
17852
  return repairIdleLanding();
@@ -17563,7 +17879,7 @@ var init_landing = __esm({
17563
17879
  init_execution();
17564
17880
  init_board();
17565
17881
  init_io();
17566
- init_lock();
17882
+ init_landing_lock();
17567
17883
  init_paths();
17568
17884
  init_answers();
17569
17885
  init_commit_mode();
@@ -17604,9 +17920,9 @@ var init_landing = __esm({
17604
17920
  sameDir = (a, b) => {
17605
17921
  const real2 = (dir) => {
17606
17922
  try {
17607
- return fs43.realpathSync(dir);
17923
+ return fs45.realpathSync(dir);
17608
17924
  } catch {
17609
- return path47.resolve(dir);
17925
+ return path49.resolve(dir);
17610
17926
  }
17611
17927
  };
17612
17928
  return real2(a) === real2(b);
@@ -17615,35 +17931,35 @@ var init_landing = __esm({
17615
17931
  });
17616
17932
 
17617
17933
  // src/lib/agent/pictures.ts
17618
- import fs44 from "node:fs";
17619
- import path48 from "node:path";
17934
+ import fs46 from "node:fs";
17935
+ import path50 from "node:path";
17620
17936
  function claimRunPictures(box2, sessionId, names4 = []) {
17621
17937
  if (!box2 || !freeBox(box2) || names4.length === 0) return [];
17622
17938
  const from = pictureBox(box2);
17623
17939
  const to = pictureBox(sessionId);
17624
17940
  try {
17625
- fs44.mkdirSync(SESSIONS_DIR, { recursive: true });
17626
- fs44.renameSync(from, to);
17941
+ fs46.mkdirSync(SESSIONS_DIR, { recursive: true });
17942
+ fs46.renameSync(from, to);
17627
17943
  } catch {
17628
17944
  return [];
17629
17945
  }
17630
- return names4.filter(pictureName).map((name) => path48.join(to, name)).filter((file) => fs44.existsSync(file));
17946
+ return names4.filter(pictureName).map((name) => path50.join(to, name)).filter((file) => fs46.existsSync(file));
17631
17947
  }
17632
17948
  function returnRunPictures(sessionId, box2) {
17633
17949
  if (!box2 || !boxId(box2)) return;
17634
17950
  try {
17635
- fs44.renameSync(pictureBox(sessionId), pictureBox(box2));
17951
+ fs46.renameSync(pictureBox(sessionId), pictureBox(box2));
17636
17952
  } catch {
17637
17953
  }
17638
17954
  }
17639
17955
  function moveRunPictures(from, to, files2 = []) {
17640
17956
  if (files2.length === 0) return [];
17641
17957
  try {
17642
- fs44.renameSync(pictureBox(from), pictureBox(to));
17958
+ fs46.renameSync(pictureBox(from), pictureBox(to));
17643
17959
  } catch {
17644
17960
  return files2;
17645
17961
  }
17646
- return files2.map((file) => path48.join(pictureBox(to), path48.basename(file)));
17962
+ return files2.map((file) => path50.join(pictureBox(to), path50.basename(file)));
17647
17963
  }
17648
17964
  var pictureName, boxId, freeBox, pictureBox;
17649
17965
  var init_pictures = __esm({
@@ -17652,14 +17968,14 @@ var init_pictures = __esm({
17652
17968
  init_paths();
17653
17969
  pictureName = (name) => /^[0-9a-f-]{36}\.[a-z0-9]{2,5}$/.test(name);
17654
17970
  boxId = (box2) => /^[0-9a-f-]{36}$/.test(box2);
17655
- freeBox = (box2) => boxId(box2) && !fs44.existsSync(path48.join(SESSIONS_DIR, `${box2}.log`));
17656
- pictureBox = (box2) => path48.join(SESSIONS_DIR, `${box2}.images`);
17971
+ freeBox = (box2) => boxId(box2) && !fs46.existsSync(path50.join(SESSIONS_DIR, `${box2}.log`));
17972
+ pictureBox = (box2) => path50.join(SESSIONS_DIR, `${box2}.images`);
17657
17973
  }
17658
17974
  });
17659
17975
 
17660
17976
  // src/lib/memories.ts
17661
- import fs45 from "node:fs";
17662
- import path49 from "node:path";
17977
+ import fs47 from "node:fs";
17978
+ import path51 from "node:path";
17663
17979
  function readMemory(text5, builtIn, folder) {
17664
17980
  const { meta, body } = splitFrontmatter(text5);
17665
17981
  if (meta === null) return null;
@@ -17679,7 +17995,7 @@ function readMemory(text5, builtIn, folder) {
17679
17995
  rules: body.trim(),
17680
17996
  text: text5,
17681
17997
  builtIn,
17682
- dir: path49.join(MEMORY, folder)
17998
+ dir: path51.join(MEMORY, folder)
17683
17999
  };
17684
18000
  }
17685
18001
  function globalMemories() {
@@ -17690,14 +18006,14 @@ function globalMemories() {
17690
18006
  }
17691
18007
  let folders2 = [];
17692
18008
  try {
17693
- folders2 = fs45.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
18009
+ folders2 = fs47.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
17694
18010
  } catch {
17695
18011
  }
17696
18012
  for (const name of folders2) {
17697
18013
  if (name in BUNDLED_MEMORY_FILES || name === RESERVED_MEMORY_DIR) continue;
17698
- const file = path49.join(MEMORY, name, GLOBAL_MEMORY_FILE);
17699
- if (!fs45.existsSync(file)) continue;
17700
- const memory = readMemory(fs45.readFileSync(file, "utf8"), false, name);
18014
+ const file = path51.join(MEMORY, name, GLOBAL_MEMORY_FILE);
18015
+ if (!fs47.existsSync(file)) continue;
18016
+ const memory = readMemory(fs47.readFileSync(file, "utf8"), false, name);
17701
18017
  if (memory) out.push(memory);
17702
18018
  }
17703
18019
  return out;
@@ -17753,16 +18069,16 @@ var init_facts = __esm({
17753
18069
  });
17754
18070
 
17755
18071
  // src/lib/view/archive.ts
17756
- import fs46 from "node:fs";
17757
- import path50 from "node:path";
18072
+ import fs48 from "node:fs";
18073
+ import path52 from "node:path";
17758
18074
  function archivedId(file) {
17759
- const own = idPrefix(path50.basename(file));
17760
- return own !== null ? own : idPrefix(path50.basename(path50.dirname(file)));
18075
+ const own = idPrefix(path52.basename(file));
18076
+ return own !== null ? own : idPrefix(path52.basename(path52.dirname(file)));
17761
18077
  }
17762
18078
  function readFile(file) {
17763
18079
  const id = archivedId(file);
17764
18080
  if (id === null) return null;
17765
- const { meta, body } = parseFrontmatter(fs46.readFileSync(file, "utf8"));
18081
+ const { meta, body } = parseFrontmatter(fs48.readFileSync(file, "utf8"));
17766
18082
  if (!meta) return null;
17767
18083
  return {
17768
18084
  row: {
@@ -17770,15 +18086,15 @@ function readFile(file) {
17770
18086
  title: meta.title,
17771
18087
  archived: meta.archived,
17772
18088
  rejected: meta.rejected,
17773
- relPath: rel(file).split(path50.sep).join("/")
18089
+ relPath: rel(file).split(path52.sep).join("/")
17774
18090
  },
17775
18091
  body: body.replace(/^\n+/, "").replace(/\s+$/, ""),
17776
18092
  meta
17777
18093
  };
17778
18094
  }
17779
18095
  function readArchive() {
17780
- const relPath = rel(ARCHIVE).split(path50.sep).join("/");
17781
- if (!fs46.existsSync(ARCHIVE)) return { relPath, cards: [] };
18096
+ const relPath = rel(ARCHIVE).split(path52.sep).join("/");
18097
+ if (!fs48.existsSync(ARCHIVE)) return { relPath, cards: [] };
17782
18098
  const cards = walkMd(ARCHIVE).map(readFile).filter((found2) => found2 !== null).map((found2) => found2.row);
17783
18099
  cards.sort((a, b) => b.id - a.id);
17784
18100
  return { relPath, cards };
@@ -17793,7 +18109,7 @@ var init_archive = __esm({
17793
18109
  });
17794
18110
 
17795
18111
  // src/lib/agent/prompts.ts
17796
- import path51 from "node:path";
18112
+ import path53 from "node:path";
17797
18113
  function resumePrompt(deliveryId, cardId2, action) {
17798
18114
  if (!deliveryId) return RESUME_PROMPT;
17799
18115
  if (action === "conflict") {
@@ -17837,7 +18153,7 @@ function buildAsk(rawReq, notes = []) {
17837
18153
  }
17838
18154
  function cardFileOf(id) {
17839
18155
  const found2 = id === void 0 ? null : locate(id);
17840
- return found2 ? found2.kind === "group" ? path51.join(found2.target, "root.md") : found2.target : "";
18156
+ return found2 ? found2.kind === "group" ? path53.join(found2.target, "root.md") : found2.target : "";
17841
18157
  }
17842
18158
  function realPaths(text5, req) {
17843
18159
  if (req.action !== "scheduled" && req.action !== "sub") return text5;
@@ -17930,7 +18246,7 @@ function frozenRules(req) {
17930
18246
  function archivedCardFile(id) {
17931
18247
  const found2 = locateArchived(id);
17932
18248
  if (!found2) return `${rel(ARCHIVE)}/`;
17933
- return rel(found2.kind === "group" ? path51.join(found2.target, "root.md") : found2.target);
18249
+ return rel(found2.kind === "group" ? path53.join(found2.target, "root.md") : found2.target);
17934
18250
  }
17935
18251
  function shippedLines(cardId2) {
17936
18252
  const delivery = endedDelivery(`${cardId2}`);
@@ -18101,7 +18417,7 @@ function actionPrompt(req, command, notes) {
18101
18417
  case "spec": {
18102
18418
  const agent = findSpecAgent(req.specAgent ?? "");
18103
18419
  const found2 = req.id === void 0 ? null : locate(req.id);
18104
- const cardFile3 = found2 ? rel(found2.kind === "group" ? path51.join(found2.target, "root.md") : found2.target) : `task #${req.id}`;
18420
+ const cardFile3 = found2 ? rel(found2.kind === "group" ? path53.join(found2.target, "root.md") : found2.target) : `task #${req.id}`;
18105
18421
  const own = agent ? specAgentInstructions(agent) : null;
18106
18422
  if (own) notes.push(...own.notes);
18107
18423
  const memory = agent ? agentMemoryBlock(agent) : "";
@@ -18214,288 +18530,81 @@ ${shared}` : ""
18214
18530
  req.notes ? `Extra notes: ${req.notes}` : "",
18215
18531
  `Don't ask me questions with human-in-the-loop. Leave any questions as open questions.`
18216
18532
  ].filter(Boolean).join(" ");
18217
- case "resolve":
18218
- return [
18219
- `${kb}. Apply my answers to the open questions on task ${req.id} ${named2} following \`akb guide resolve\`.`,
18220
- carriedNote(req),
18221
- answeredNote(req.id, command),
18222
- req.notes ? `Extra notes: ${req.notes}` : ""
18223
- ].filter(Boolean).join(" ");
18224
- }
18225
- }
18226
- function discardedCardsPrompt(cards = []) {
18227
- if (!cards.length) return "";
18228
- return "The user discarded the cards listed below. Their absence is intentional. Do not restore or recreate them, including under new IDs or filenames. Continue the remaining work from the current board, preserving the other cards.\n\n" + cards.map((c) => `- #${c.id}: ${c.path}`).join("\n");
18229
- }
18230
- var RESUME_PROMPT, DELIVERY_RESUME, DELIVERY_RESUME_CARD, RESTARTABLE, RESTART_LEAD, restartable, NO_IMPLEMENT, BOARD_FOLDER, CARD_FILE, PROJECT_FOLDER, PLANNING_FOR, SPEC_SELECTOR_FOR, reflectedCards;
18231
- var init_prompts = __esm({
18232
- "src/lib/agent/prompts.ts"() {
18233
- "use strict";
18234
- init_cards();
18235
- init_memory();
18236
- init_memories();
18237
- init_paths();
18238
- init_agents();
18239
- init_command();
18240
- init_deliveries();
18241
- init_env();
18242
- init_facts();
18243
- init_outputs();
18244
- init_archive();
18245
- init_flows();
18246
- init_resolve();
18247
- init_runner();
18248
- init_workflows();
18249
- init_catalog2();
18250
- init_roles();
18251
- init_rules2();
18252
- init_settings2();
18253
- init_types3();
18254
- RESUME_PROMPT = [
18255
- `Continue. The previous run ended before it finished the task.`,
18256
- `Pick up where you left off and carry it through.`
18257
- ].join(" ");
18258
- DELIVERY_RESUME = [
18259
- `Continue delivery %s. The previous run ended before the delivery finished.`,
18260
- `Re-enter the flow from the top and check each step's precondition before you do it \u2014 work that is already done is done, so do not repeat it.`
18261
- ].join(" ");
18262
- DELIVERY_RESUME_CARD = `Build the card as the delivery holds it, not as the file reads now: \`%c\` prints the approved copy.`;
18263
- RESTARTABLE = /* @__PURE__ */ new Set([
18264
- "implement",
18265
- "clarify",
18266
- "resolve",
18267
- "approve",
18268
- "archive",
18269
- "spec",
18270
- "conflict",
18271
- "scheduled"
18272
- ]);
18273
- RESTART_LEAD = [
18274
- `The session you were continuing is gone, and this one holds nothing of it.`,
18275
- `Do the task below from the top, checking each step's precondition before you do it \u2014 work an earlier run already finished is done, so don't repeat it.`
18276
- ].join(" ");
18277
- restartable = (run2) => (run2.cardId !== null || !!run2.deliveryId) && RESTARTABLE.has(run2.action);
18278
- NO_IMPLEMENT = `(Unless the request explicitly asks for implementation, don't implement it; revising the card's drafts is not implementing.)`;
18279
- BOARD_FOLDER = "<board folder>";
18280
- CARD_FILE = "<card file>";
18281
- PROJECT_FOLDER = "<project folder>";
18282
- PLANNING_FOR = /* @__PURE__ */ new Set(["create", "clarify", "resolve", "approve", "edit"]);
18283
- SPEC_SELECTOR_FOR = /* @__PURE__ */ new Set(["clarify", "resolve", "approve", "edit"]);
18284
- reflectedCards = (req) => req.cards ?? (req.id !== void 0 ? [req.id] : []);
18285
- }
18286
- });
18287
-
18288
- // src/lib/agent/stop.ts
18289
- import { spawnSync as spawnSync4 } from "node:child_process";
18290
- import { randomUUID as randomUUID5 } from "node:crypto";
18291
- import fs47 from "node:fs";
18292
- import os6 from "node:os";
18293
- function markedInProc(entry, strict = false) {
18294
- const pids = [];
18295
- for (const name of fs47.readdirSync("/proc")) {
18296
- if (!/^\d+$/.test(name)) continue;
18297
- try {
18298
- if (fs47.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
18299
- } catch (error) {
18300
- if (strict && !["ENOENT", "ESRCH"].includes(error.code ?? "")) {
18301
- const stat = fs47.statSync(`/proc/${name}`, { throwIfNoEntry: false });
18302
- if (stat?.uid === process.getuid?.()) throw error;
18303
- }
18304
- }
18305
- }
18306
- return pids;
18307
- }
18308
- function markedInPs(entry, roots) {
18309
- const ps = spawnSync4("ps", ["-A", "-E", "-ww", "-o", "pid=,ppid=,command="], {
18310
- encoding: "utf8",
18311
- maxBuffer: 64 * 1024 * 1024,
18312
- timeout: 5e3
18313
- });
18314
- if (ps.status !== 0 || !ps.stdout) throw new Error("\u65E0\u6CD5\u67E5\u8BE2\u8FDB\u7A0B\u6811\u3002");
18315
- const children = /* @__PURE__ */ new Map();
18316
- const listed2 = /* @__PURE__ */ new Set();
18317
- const found2 = /* @__PURE__ */ new Set();
18318
- for (const line of ps.stdout.split("\n")) {
18319
- const m = /^\s*(\d+)\s+(\d+)\s(.*)$/.exec(line);
18320
- if (!m) continue;
18321
- const pid = Number(m[1]);
18322
- const ppid = Number(m[2]);
18323
- listed2.add(pid);
18324
- children.set(ppid, [...children.get(ppid) ?? [], pid]);
18325
- if (`${m[3]} `.includes(` ${entry} `)) found2.add(pid);
18326
- }
18327
- const queue = [...found2, ...roots.filter((pid) => listed2.has(pid))];
18328
- for (const pid of queue) {
18329
- found2.add(pid);
18330
- for (const child of children.get(pid) ?? []) if (!found2.has(child)) queue.push(child);
18331
- }
18332
- return [...found2];
18333
- }
18334
- function marked(mark, roots = []) {
18335
- if (WINDOWS3 || !mark.value) return [];
18336
- const entry = `${mark.name}=${mark.value}`;
18337
- try {
18338
- const pids = process.platform === "linux" ? markedInProc(entry) : markedInPs(entry, roots);
18339
- return pids.filter((pid) => pid !== process.pid);
18340
- } catch {
18341
- return [];
18342
- }
18343
- }
18344
- function signal(pids, sig) {
18345
- for (const pid of pids) {
18346
- try {
18347
- process.kill(pid, sig);
18348
- } catch {
18349
- }
18350
- }
18351
- }
18352
- function startedUnder(list, root, since) {
18353
- const self = list.procs.find((p) => p.pid === root);
18354
- const from = since ?? self?.startedAt;
18355
- if (from === void 0 || list.bootedAt > from) return [];
18356
- if (self && self.startedAt > from) return [];
18357
- const found2 = self ? [root] : [];
18358
- const seen = /* @__PURE__ */ new Set([root]);
18359
- const queue = [{ pid: root, startedAt: from }];
18360
- for (const parent of queue) {
18361
- for (const p of list.procs) {
18362
- if (p.ppid !== parent.pid || seen.has(p.pid) || p.startedAt < parent.startedAt) continue;
18363
- seen.add(p.pid);
18364
- found2.push(p.pid);
18365
- queue.push(p);
18366
- }
18367
- }
18368
- return found2.reverse();
18369
- }
18370
- function readProcList(out) {
18371
- const procs = [];
18372
- let bootedAt;
18373
- for (const line of out.split(/\r?\n/)) {
18374
- const boot = /^boot (\d+)$/.exec(line.trim());
18375
- if (boot) bootedAt = Number(boot[1]);
18376
- const m = /^(\d+) (\d+) (\d+)$/.exec(line.trim());
18377
- if (m) procs.push({ pid: Number(m[1]), ppid: Number(m[2]), startedAt: Number(m[3]) });
18378
- }
18379
- return bootedAt !== void 0 && procs.length ? { procs, bootedAt } : void 0;
18380
- }
18381
- function procsOnWindows() {
18382
- const ps = spawnSync4("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", LIST_PROCS], {
18383
- encoding: "utf8",
18384
- maxBuffer: 64 * 1024 * 1024,
18385
- timeout: 5e3,
18386
- windowsHide: true
18387
- });
18388
- return ps.status === 0 && ps.stdout ? readProcList(ps.stdout) : void 0;
18389
- }
18390
- function killUnderOnWindows(pid, since) {
18391
- if (!WINDOWS3 || !pid) return;
18392
- const list = procsOnWindows();
18393
- if (!list) return;
18394
- const pids = startedUnder(list, pid, since).filter((p) => p !== process.pid);
18395
- if (!pids.length) return;
18396
- spawnSync4("taskkill", ["/F", ...pids.flatMap((p) => ["/PID", String(p)])], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
18397
- }
18398
- function killMarked(mark, agent) {
18399
- if (WINDOWS3) {
18400
- if (agent) killUnderOnWindows(agent.pid, agent.since);
18401
- return;
18402
- }
18403
- signal(marked(mark), "SIGKILL");
18404
- }
18405
- function killTreeOnWindows(pid) {
18406
- if (!WINDOWS3 || !pid) return false;
18407
- const out = spawnSync4("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
18408
- return out.status === 0;
18409
- }
18410
- function later(ms, fn) {
18411
- const t = setTimeout(fn, ms);
18412
- if (typeof t.unref === "function") t.unref();
18413
- }
18414
- function endAgent(child, mark, graceMs) {
18415
- const term = (sig) => {
18416
- try {
18417
- child.kill(sig);
18418
- } catch {
18419
- }
18420
- };
18421
- if (killTreeOnWindows(child.pid)) return;
18422
- killUnderOnWindows(child.pid);
18423
- const seen = new Set(marked(mark, child.pid ? [child.pid] : []));
18424
- term("SIGTERM");
18425
- signal([...seen].filter((pid) => pid !== child.pid), "SIGTERM");
18426
- const round = (left) => {
18427
- const pids = marked(mark, [...seen]);
18428
- signal(pids, "SIGKILL");
18429
- for (const pid of pids) seen.add(pid);
18430
- if (pids.length && left > 1) later(KILL_ROUND_MS, () => round(left - 1));
18431
- };
18432
- later(graceMs, () => {
18433
- term("SIGKILL");
18434
- round(KILL_ROUNDS);
18435
- });
18436
- }
18437
- function killRunning() {
18438
- for (const [child, mark] of running) {
18439
- if (killTreeOnWindows(child.pid)) continue;
18440
- killUnderOnWindows(child.pid);
18441
- signal(marked(mark, child.pid ? [child.pid] : []), "SIGKILL");
18442
- try {
18443
- child.kill("SIGKILL");
18444
- } catch {
18445
- }
18533
+ case "resolve":
18534
+ return [
18535
+ `${kb}. Apply my answers to the open questions on task ${req.id} ${named2} following \`akb guide resolve\`.`,
18536
+ carriedNote(req),
18537
+ answeredNote(req.id, command),
18538
+ req.notes ? `Extra notes: ${req.notes}` : ""
18539
+ ].filter(Boolean).join(" ");
18446
18540
  }
18447
- running.clear();
18448
- }
18449
- function unlisten() {
18450
- for (const [sig, fn] of listening) process.removeListener(sig, fn);
18451
- listening.clear();
18452
- }
18453
- function onQuit(sig) {
18454
- killRunning();
18455
- unlisten();
18456
- if (process.listenerCount(sig) === 0) process.exit(128 + os6.constants.signals[sig]);
18457
18541
  }
18458
- function trackAgent(child, mark) {
18459
- if (!child.pid) return;
18460
- running.set(child, mark);
18461
- child.once("close", () => {
18462
- running.delete(child);
18463
- if (!running.size) unlisten();
18464
- });
18465
- for (const sig of QUIT_SIGNALS) {
18466
- if (listening.has(sig) || sig === "SIGINT" && interruptIsTheCallers) continue;
18467
- const fn = () => onQuit(sig);
18468
- listening.set(sig, fn);
18469
- process.on(sig, fn);
18470
- }
18542
+ function discardedCardsPrompt(cards = []) {
18543
+ if (!cards.length) return "";
18544
+ return "The user discarded the cards listed below. Their absence is intentional. Do not restore or recreate them, including under new IDs or filenames. Continue the remaining work from the current board, preserving the other cards.\n\n" + cards.map((c) => `- #${c.id}: ${c.path}`).join("\n");
18471
18545
  }
18472
- var runMark, stopMark, markEnv, WINDOWS3, KILL_ROUND_MS, KILL_ROUNDS, LIST_PROCS, running, QUIT_SIGNALS, listening, interruptIsTheCallers;
18473
- var init_stop = __esm({
18474
- "src/lib/agent/stop.ts"() {
18546
+ var RESUME_PROMPT, DELIVERY_RESUME, DELIVERY_RESUME_CARD, RESTARTABLE, RESTART_LEAD, restartable, NO_IMPLEMENT, BOARD_FOLDER, CARD_FILE, PROJECT_FOLDER, PLANNING_FOR, SPEC_SELECTOR_FOR, reflectedCards;
18547
+ var init_prompts = __esm({
18548
+ "src/lib/agent/prompts.ts"() {
18475
18549
  "use strict";
18550
+ init_cards();
18551
+ init_memory();
18552
+ init_memories();
18553
+ init_paths();
18554
+ init_agents();
18555
+ init_command();
18556
+ init_deliveries();
18476
18557
  init_env();
18477
- runMark = (sessionId) => ({ name: RUN_ENV, value: sessionId });
18478
- stopMark = () => ({ name: STOP_ENV, value: randomUUID5() });
18479
- markEnv = (env2, mark) => ({ ...env2, [mark.name]: mark.value });
18480
- WINDOWS3 = process.platform === "win32";
18481
- KILL_ROUND_MS = 300;
18482
- KILL_ROUNDS = 3;
18483
- LIST_PROCS = [
18484
- "$ErrorActionPreference = 'Stop'",
18485
- "Get-CimInstance Win32_Process | ForEach-Object { if ($_.CreationDate) { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } }",
18486
- "'boot {0}' -f ([DateTimeOffset](Get-CimInstance Win32_OperatingSystem).LastBootUpTime).ToUnixTimeMilliseconds()"
18487
- ].join("; ");
18488
- running = /* @__PURE__ */ new Map();
18489
- QUIT_SIGNALS = ["SIGTERM", "SIGINT", "SIGHUP"];
18490
- listening = /* @__PURE__ */ new Map();
18491
- interruptIsTheCallers = false;
18558
+ init_facts();
18559
+ init_outputs();
18560
+ init_archive();
18561
+ init_flows();
18562
+ init_resolve();
18563
+ init_runner();
18564
+ init_workflows();
18565
+ init_catalog2();
18566
+ init_roles();
18567
+ init_rules2();
18568
+ init_settings2();
18569
+ init_types3();
18570
+ RESUME_PROMPT = [
18571
+ `Continue. The previous run ended before it finished the task.`,
18572
+ `Pick up where you left off and carry it through.`
18573
+ ].join(" ");
18574
+ DELIVERY_RESUME = [
18575
+ `Continue delivery %s. The previous run ended before the delivery finished.`,
18576
+ `Re-enter the flow from the top and check each step's precondition before you do it \u2014 work that is already done is done, so do not repeat it.`
18577
+ ].join(" ");
18578
+ DELIVERY_RESUME_CARD = `Build the card as the delivery holds it, not as the file reads now: \`%c\` prints the approved copy.`;
18579
+ RESTARTABLE = /* @__PURE__ */ new Set([
18580
+ "implement",
18581
+ "clarify",
18582
+ "resolve",
18583
+ "approve",
18584
+ "archive",
18585
+ "spec",
18586
+ "conflict",
18587
+ "scheduled"
18588
+ ]);
18589
+ RESTART_LEAD = [
18590
+ `The session you were continuing is gone, and this one holds nothing of it.`,
18591
+ `Do the task below from the top, checking each step's precondition before you do it \u2014 work an earlier run already finished is done, so don't repeat it.`
18592
+ ].join(" ");
18593
+ restartable = (run2) => (run2.cardId !== null || !!run2.deliveryId) && RESTARTABLE.has(run2.action);
18594
+ NO_IMPLEMENT = `(Unless the request explicitly asks for implementation, don't implement it; revising the card's drafts is not implementing.)`;
18595
+ BOARD_FOLDER = "<board folder>";
18596
+ CARD_FILE = "<card file>";
18597
+ PROJECT_FOLDER = "<project folder>";
18598
+ PLANNING_FOR = /* @__PURE__ */ new Set(["create", "clarify", "resolve", "approve", "edit"]);
18599
+ SPEC_SELECTOR_FOR = /* @__PURE__ */ new Set(["clarify", "resolve", "approve", "edit"]);
18600
+ reflectedCards = (req) => req.cards ?? (req.id !== void 0 ? [req.id] : []);
18492
18601
  }
18493
18602
  });
18494
18603
 
18495
18604
  // src/lib/agent/sessions.ts
18496
18605
  import { randomUUID as randomUUID6 } from "node:crypto";
18497
- import fs48 from "node:fs";
18498
- import path52 from "node:path";
18606
+ import fs49 from "node:fs";
18607
+ import path54 from "node:path";
18499
18608
  function reap(runs, reaped = [], restore = []) {
18500
18609
  let changed = false;
18501
18610
  const now = Date.now();
@@ -18515,7 +18624,7 @@ function reap(runs, reaped = [], restore = []) {
18515
18624
  }
18516
18625
  function stampDuration(run2, endedAt) {
18517
18626
  try {
18518
- fs48.appendFileSync(run2.logPath, durationLine(endedAt - run2.startedAt));
18627
+ fs49.appendFileSync(run2.logPath, durationLine(endedAt - run2.startedAt));
18519
18628
  } catch {
18520
18629
  }
18521
18630
  }
@@ -18529,7 +18638,7 @@ function cardNow(cardId2) {
18529
18638
  try {
18530
18639
  const file = cardFile(cardId2);
18531
18640
  if (!file) return null;
18532
- const { meta } = parseFrontmatter(fs48.readFileSync(file, "utf8"));
18641
+ const { meta } = parseFrontmatter(fs49.readFileSync(file, "utf8"));
18533
18642
  if (!meta) return null;
18534
18643
  return { status: meta.status || "todo", questions: openOf(meta.questions).length, title: meta.title };
18535
18644
  } catch {
@@ -18666,9 +18775,9 @@ function leftBoardOnLanding(id) {
18666
18775
  function archivedRejected(id) {
18667
18776
  const filed = locateArchived(id);
18668
18777
  if (!filed) return null;
18669
- const file = filed.kind === "group" ? path52.join(filed.target, "root.md") : filed.target;
18778
+ const file = filed.kind === "group" ? path54.join(filed.target, "root.md") : filed.target;
18670
18779
  try {
18671
- return !!parseFrontmatter(fs48.readFileSync(file, "utf8")).meta?.rejected;
18780
+ return !!parseFrontmatter(fs49.readFileSync(file, "utf8")).meta?.rejected;
18672
18781
  } catch {
18673
18782
  return false;
18674
18783
  }
@@ -18925,7 +19034,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said3) {
18925
19034
  return { run: record, spec };
18926
19035
  }
18927
19036
  function planningSession(cardId2, cwd = REPO_ROOT) {
18928
- const here = (dir) => !dir || path52.resolve(dir) === cwd;
19037
+ const here = (dir) => !dir || path54.resolve(dir) === cwd;
18929
19038
  const ended = readRuns().filter((r) => r.status === "done").sort((a, b) => b.startedAt - a.startedAt);
18930
19039
  const of = (run3, fork) => {
18931
19040
  if (!here(run3.cwd)) return { none: "elsewhere" };
@@ -18994,7 +19103,7 @@ function requestOf(record) {
18994
19103
  pictures: record.pictures
18995
19104
  };
18996
19105
  }
18997
- async function openResume(id) {
19106
+ async function openResume(id, requireSession = false) {
18998
19107
  const restore = [];
18999
19108
  const runs = withRuns((all2) => {
19000
19109
  reap(all2, [], restore);
@@ -19014,6 +19123,9 @@ async function openResume(id) {
19014
19123
  if (refused) return refused;
19015
19124
  }
19016
19125
  const retrying = lacksSession(prev);
19126
+ if (requireSession && !resumeSessionId(prev)) {
19127
+ return refusal("runNoSession", "the original conversation cannot be resumed; no new conversation was started");
19128
+ }
19017
19129
  const ask2 = retrying && prev.status !== "stopped" ? retryAsk(prev) : void 0;
19018
19130
  if (retrying && !ask2) return refusal("runNoSession", "that run never reported a session id to continue by");
19019
19131
  const ended = endedDeliveryRefusal(prev);
@@ -19144,8 +19256,8 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
19144
19256
  clearAsks(prev.sessionId);
19145
19257
  try {
19146
19258
  if (prev.action !== "create") {
19147
- fs48.unlinkSync(prev.logPath);
19148
- fs48.rmSync(eventsPathOf(prev.sessionId), { force: true });
19259
+ fs49.unlinkSync(prev.logPath);
19260
+ fs49.rmSync(eventsPathOf(prev.sessionId), { force: true });
19149
19261
  }
19150
19262
  } catch {
19151
19263
  }
@@ -19169,8 +19281,8 @@ function forgetRun(sessionId) {
19169
19281
  if (!gone) return;
19170
19282
  clearAsks(sessionId);
19171
19283
  try {
19172
- fs48.unlinkSync(gone.logPath);
19173
- fs48.rmSync(eventsPathOf(gone.sessionId), { force: true });
19284
+ fs49.unlinkSync(gone.logPath);
19285
+ fs49.rmSync(eventsPathOf(gone.sessionId), { force: true });
19174
19286
  } catch {
19175
19287
  }
19176
19288
  }
@@ -19199,14 +19311,14 @@ function noteSpecRefusals(sessionId, refused) {
19199
19311
  }
19200
19312
  function clearAsks(sessionId) {
19201
19313
  try {
19202
- fs48.unlinkSync(asksPathOf(sessionId));
19314
+ fs49.unlinkSync(asksPathOf(sessionId));
19203
19315
  } catch {
19204
19316
  }
19205
19317
  }
19206
19318
  function readAsks(sessionId) {
19207
19319
  let data;
19208
19320
  try {
19209
- data = JSON.parse(fs48.readFileSync(asksPathOf(sessionId), "utf8"));
19321
+ data = JSON.parse(fs49.readFileSync(asksPathOf(sessionId), "utf8"));
19210
19322
  } catch {
19211
19323
  return { asks: [], refines: [], refused: [] };
19212
19324
  }
@@ -19233,10 +19345,10 @@ function readAsks(sessionId) {
19233
19345
  return { asks: asks.filter((a) => !discarded.has(a.cardId)), refines: refines.filter((a) => !discarded.has(a.cardId)), refused };
19234
19346
  }
19235
19347
  function writeAsks(sessionId, file) {
19236
- fs48.mkdirSync(SESSIONS_DIR, { recursive: true });
19348
+ fs49.mkdirSync(SESSIONS_DIR, { recursive: true });
19237
19349
  const tmp = `${asksPathOf(sessionId)}.tmp`;
19238
- fs48.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n");
19239
- fs48.renameSync(tmp, asksPathOf(sessionId));
19350
+ fs49.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n");
19351
+ fs49.renameSync(tmp, asksPathOf(sessionId));
19240
19352
  }
19241
19353
  function markSpawned(sessionId, pid) {
19242
19354
  patch(sessionId, (r) => {
@@ -19324,7 +19436,10 @@ async function cancelDelivery(id) {
19324
19436
  if (!id.trim()) return { ok: false, ...refusal("deliveryUnnamed", "name the delivery to cancel", { action: "cancel" }) };
19325
19437
  const delivery = namedDelivery(id);
19326
19438
  if (!delivery) return { ok: false, ...unknownDelivery(id) };
19327
- if (delivery.status !== "active") return { ok: true, deliveryId: delivery.deliveryId };
19439
+ if (delivery.status !== "active") {
19440
+ tidyCheckout(delivery.deliveryId);
19441
+ return { ok: true, deliveryId: delivery.deliveryId };
19442
+ }
19328
19443
  endDelivery(delivery.deliveryId, "cancelled");
19329
19444
  const live = readRuns().find((r) => r.status === "running" && r.deliveryId === delivery.deliveryId && r.action !== "sub");
19330
19445
  if (live) await stopRun(live.sessionId);
@@ -19390,12 +19505,12 @@ async function discardDelivery(id) {
19390
19505
  return { ok: true, deliveryId: delivery.deliveryId };
19391
19506
  }
19392
19507
  function writeSpec(spec) {
19393
- fs48.mkdirSync(SESSIONS_DIR, { recursive: true });
19394
- fs48.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
19508
+ fs49.mkdirSync(SESSIONS_DIR, { recursive: true });
19509
+ fs49.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
19395
19510
  }
19396
19511
  function readSpec(sessionId) {
19397
19512
  try {
19398
- const spec = JSON.parse(fs48.readFileSync(specPathOf(sessionId), "utf8"));
19513
+ const spec = JSON.parse(fs49.readFileSync(specPathOf(sessionId), "utf8"));
19399
19514
  return spec && Array.isArray(spec.plan?.argv) ? spec : null;
19400
19515
  } catch {
19401
19516
  return null;
@@ -19403,28 +19518,28 @@ function readSpec(sessionId) {
19403
19518
  }
19404
19519
  function dropSpec(sessionId) {
19405
19520
  try {
19406
- fs48.unlinkSync(specPathOf(sessionId));
19521
+ fs49.unlinkSync(specPathOf(sessionId));
19407
19522
  } catch {
19408
19523
  }
19409
19524
  }
19410
19525
  async function acquireIndexLock(giveUp) {
19411
19526
  const until = Date.now() + INDEX_WAIT_MS;
19412
- const holder = path52.join(INDEX_LOCK2, "holder");
19527
+ const holder = path54.join(INDEX_LOCK2, "holder");
19413
19528
  for (; ; ) {
19414
19529
  if (giveUp()) return null;
19415
19530
  try {
19416
- fs48.mkdirSync(INDEX_LOCK2, { recursive: false });
19417
- fs48.writeFileSync(holder, String(process.pid));
19418
- return () => fs48.rmSync(INDEX_LOCK2, { recursive: true, force: true });
19531
+ fs49.mkdirSync(INDEX_LOCK2, { recursive: false });
19532
+ fs49.writeFileSync(holder, String(process.pid));
19533
+ return () => fs49.rmSync(INDEX_LOCK2, { recursive: true, force: true });
19419
19534
  } catch (err) {
19420
19535
  const code = err.code;
19421
19536
  if (code === "ENOENT") {
19422
- fs48.mkdirSync(path52.dirname(INDEX_LOCK2), { recursive: true });
19537
+ fs49.mkdirSync(path54.dirname(INDEX_LOCK2), { recursive: true });
19423
19538
  continue;
19424
19539
  }
19425
19540
  if (code !== "EEXIST") throw err;
19426
19541
  if (!pidAlive(Number(readHolder(holder)))) {
19427
- fs48.rmSync(INDEX_LOCK2, { recursive: true, force: true });
19542
+ fs49.rmSync(INDEX_LOCK2, { recursive: true, force: true });
19428
19543
  continue;
19429
19544
  }
19430
19545
  if (Date.now() > until) return null;
@@ -19434,7 +19549,7 @@ async function acquireIndexLock(giveUp) {
19434
19549
  }
19435
19550
  function readHolder(file) {
19436
19551
  try {
19437
- return fs48.readFileSync(file, "utf8").trim();
19552
+ return fs49.readFileSync(file, "utf8").trim();
19438
19553
  } catch {
19439
19554
  return String(process.pid);
19440
19555
  }
@@ -19525,8 +19640,8 @@ var init_sessions = __esm({
19525
19640
  conflict: "implementing",
19526
19641
  hook: "implementing"
19527
19642
  };
19528
- specPathOf = (sessionId) => path52.join(SESSIONS_DIR, `${sessionId}.plan.json`);
19529
- asksPathOf = (sessionId) => path52.join(SESSIONS_DIR, `${sessionId}.asks.json`);
19643
+ specPathOf = (sessionId) => path54.join(SESSIONS_DIR, `${sessionId}.plan.json`);
19644
+ asksPathOf = (sessionId) => path54.join(SESSIONS_DIR, `${sessionId}.asks.json`);
19530
19645
  carriesSession = (r) => !!(r.resumedFrom || r.continues && !r.continues.fork);
19531
19646
  canPickUp = (r) => (r.status === "error" || r.status === "interrupted" || r.status === "stopped") && !(r.action === "create" && readRuns().some((next) => next.resumedFrom === r.sessionId));
19532
19647
  neverStarted = (r) => r.unspawned === true || !!r.errorWhy?.some((why) => why.kind === "notInstalled");
@@ -19660,8 +19775,8 @@ var init_questions = __esm({
19660
19775
  });
19661
19776
 
19662
19777
  // src/lib/agent/workflow-cards.ts
19663
- import fs49 from "node:fs";
19664
- import path53 from "node:path";
19778
+ import fs50 from "node:fs";
19779
+ import path55 from "node:path";
19665
19780
  function cardsOnWorkflow(id) {
19666
19781
  const wanted = id || DEFAULT_WORKFLOW;
19667
19782
  const ids = [];
@@ -19672,12 +19787,12 @@ function cardsOnWorkflow(id) {
19672
19787
  return [];
19673
19788
  }
19674
19789
  for (const file of files2) {
19675
- const base = path53.basename(file);
19676
- const card = base === "root.md" ? idPrefix(path53.basename(path53.dirname(file))) : idPrefix(base);
19790
+ const base = path55.basename(file);
19791
+ const card = base === "root.md" ? idPrefix(path55.basename(path55.dirname(file))) : idPrefix(base);
19677
19792
  if (card === null) continue;
19678
19793
  let meta;
19679
19794
  try {
19680
- meta = parseFrontmatter(fs49.readFileSync(file, "utf8")).meta;
19795
+ meta = parseFrontmatter(fs50.readFileSync(file, "utf8")).meta;
19681
19796
  } catch {
19682
19797
  continue;
19683
19798
  }
@@ -19735,12 +19850,12 @@ var init_workflow_cards = __esm({
19735
19850
  });
19736
19851
 
19737
19852
  // src/lib/readme.ts
19738
- import fs50 from "node:fs";
19739
- import path54 from "node:path";
19853
+ import fs51 from "node:fs";
19854
+ import path56 from "node:path";
19740
19855
  function stripReadmeRefs(target) {
19741
- if (!fs50.existsSync(README)) return [];
19856
+ if (!fs51.existsSync(README)) return [];
19742
19857
  const needle = target.kind === "group" ? `](${target.rel}/` : `](${target.rel})`;
19743
- const lines = fs50.readFileSync(README, "utf8").split("\n");
19858
+ const lines = fs51.readFileSync(README, "utf8").split("\n");
19744
19859
  const out = [];
19745
19860
  const removed = [];
19746
19861
  let i = 0;
@@ -19762,20 +19877,20 @@ function stripReadmeRefs(target) {
19762
19877
  out.push(line);
19763
19878
  i++;
19764
19879
  }
19765
- if (removed.length) fs50.writeFileSync(README, out.join("\n"));
19880
+ if (removed.length) fs51.writeFileSync(README, out.join("\n"));
19766
19881
  return removed;
19767
19882
  }
19768
19883
  function addReadmeRef(id, title, relPath) {
19769
- if (!fs50.existsSync(README)) return false;
19770
- const link2 = relPath.split(path54.sep).join("/");
19884
+ if (!fs51.existsSync(README)) return false;
19885
+ const link2 = relPath.split(path56.sep).join("/");
19771
19886
  const bullet = `- [#${id} ${title}](${link2})`;
19772
19887
  const heading = `## ${TASKS_HEADING}`;
19773
- let lines = fs50.readFileSync(README, "utf8").split("\n");
19888
+ let lines = fs51.readFileSync(README, "utf8").split("\n");
19774
19889
  const hi = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
19775
19890
  if (hi === -1) {
19776
19891
  while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
19777
19892
  lines.push("", heading, "", bullet);
19778
- fs50.writeFileSync(README, lines.join("\n") + "\n");
19893
+ fs51.writeFileSync(README, lines.join("\n") + "\n");
19779
19894
  return true;
19780
19895
  }
19781
19896
  let end2 = hi + 1;
@@ -19789,15 +19904,15 @@ function addReadmeRef(id, title, relPath) {
19789
19904
  const at = lastBullet !== -1 ? lastBullet + 1 : lines[hi + 1] === "" ? hi + 2 : hi + 1;
19790
19905
  lines.splice(at, 0, bullet);
19791
19906
  }
19792
- fs50.writeFileSync(README, lines.join("\n"));
19907
+ fs51.writeFileSync(README, lines.join("\n"));
19793
19908
  return true;
19794
19909
  }
19795
19910
  function repointReadmeLink(id, oldRel, newRel, title) {
19796
- if (!fs50.existsSync(README)) return false;
19797
- const oldLink = oldRel.split(path54.sep).join("/");
19798
- const newLink = newRel.split(path54.sep).join("/");
19911
+ if (!fs51.existsSync(README)) return false;
19912
+ const oldLink = oldRel.split(path56.sep).join("/");
19913
+ const newLink = newRel.split(path56.sep).join("/");
19799
19914
  const linkRe = new RegExp(`\\[#${id}\\b[^\\]]*\\]\\(${escapeRegex(oldLink)}\\)`);
19800
- const lines = fs50.readFileSync(README, "utf8").split("\n");
19915
+ const lines = fs51.readFileSync(README, "utf8").split("\n");
19801
19916
  let changed = false;
19802
19917
  for (let i = 0; i < lines.length; i++) {
19803
19918
  if (!lines[i].includes(`](${oldLink})`)) continue;
@@ -19807,7 +19922,7 @@ function repointReadmeLink(id, oldRel, newRel, title) {
19807
19922
  changed = true;
19808
19923
  }
19809
19924
  }
19810
- if (changed) fs50.writeFileSync(README, lines.join("\n"));
19925
+ if (changed) fs51.writeFileSync(README, lines.join("\n"));
19811
19926
  return changed;
19812
19927
  }
19813
19928
  var isTableRow, isBulletStart, bulletIndent, TASKS_HEADING, escapeRegex;
@@ -19824,14 +19939,14 @@ var init_readme = __esm({
19824
19939
  });
19825
19940
 
19826
19941
  // src/lib/reconcile.ts
19827
- import fs51 from "node:fs";
19828
- import path55 from "node:path";
19942
+ import fs52 from "node:fs";
19943
+ import path57 from "node:path";
19829
19944
  function liveIds() {
19830
19945
  const ids = /* @__PURE__ */ new Set();
19831
19946
  for (const file of walkMd(TODO)) {
19832
- const base = path55.basename(file);
19947
+ const base = path57.basename(file);
19833
19948
  if (base === "README.md") continue;
19834
- const id = base === "root.md" ? idPrefix(path55.basename(path55.dirname(file))) : idPrefix(base);
19949
+ const id = base === "root.md" ? idPrefix(path57.basename(path57.dirname(file))) : idPrefix(base);
19835
19950
  if (id != null) ids.add(id);
19836
19951
  }
19837
19952
  return ids;
@@ -19839,16 +19954,16 @@ function liveIds() {
19839
19954
  function indexableCards() {
19840
19955
  const out = [];
19841
19956
  for (const dir of walkDirs(TODO)) {
19842
- const id = idPrefix(path55.basename(dir));
19843
- if (id != null && fs51.existsSync(path55.join(dir, "root.md"))) {
19844
- out.push({ id, rel: path55.join(path55.relative(TODO, dir), "root.md").split(path55.sep).join("/") });
19957
+ const id = idPrefix(path57.basename(dir));
19958
+ if (id != null && fs52.existsSync(path57.join(dir, "root.md"))) {
19959
+ out.push({ id, rel: path57.join(path57.relative(TODO, dir), "root.md").split(path57.sep).join("/") });
19845
19960
  }
19846
19961
  }
19847
19962
  for (const file of walkMd(TODO)) {
19848
- const base = path55.basename(file);
19963
+ const base = path57.basename(file);
19849
19964
  if (base === "README.md" || base === "root.md") continue;
19850
- const relTODO = path55.relative(TODO, file);
19851
- const segs = relTODO.split(path55.sep);
19965
+ const relTODO = path57.relative(TODO, file);
19966
+ const segs = relTODO.split(path57.sep);
19852
19967
  if (segs.length !== 1) continue;
19853
19968
  const id = idPrefix(base);
19854
19969
  if (id != null) out.push({ id, rel: segs.join("/") });
@@ -19857,7 +19972,7 @@ function indexableCards() {
19857
19972
  }
19858
19973
  function readmeComplaints(fix) {
19859
19974
  const said3 = [];
19860
- const lines = fs51.readFileSync(README, "utf8").split("\n");
19975
+ const lines = fs52.readFileSync(README, "utf8").split("\n");
19861
19976
  const indexed = /* @__PURE__ */ new Set();
19862
19977
  let fixed = 0;
19863
19978
  for (let i = 0; i < lines.length; i++) {
@@ -19866,13 +19981,13 @@ function readmeComplaints(fix) {
19866
19981
  const id = Number(m[1]);
19867
19982
  const linkPath = m[2];
19868
19983
  indexed.add(id);
19869
- if (fs51.existsSync(path55.join(TODO, linkPath))) continue;
19984
+ if (fs52.existsSync(path57.join(TODO, linkPath))) continue;
19870
19985
  const found2 = locate(id);
19871
19986
  if (!found2) {
19872
19987
  said3.push(`README links #${id} \u2192 ${linkPath}, but no card with that id exists (removed by hand?). Drop the entry or restore the file.`);
19873
19988
  continue;
19874
19989
  }
19875
- const want = (found2.kind === "group" ? path55.join(found2.rel, "root.md") : found2.rel).split(path55.sep).join("/");
19990
+ const want = (found2.kind === "group" ? path57.join(found2.rel, "root.md") : found2.rel).split(path57.sep).join("/");
19876
19991
  if (want === linkPath) continue;
19877
19992
  if (!fix) {
19878
19993
  said3.push(`README links #${id} \u2192 ${linkPath}, which isn't there any more; the card is at ${want}.`);
@@ -19882,7 +19997,7 @@ function readmeComplaints(fix) {
19882
19997
  said3.push(`README link #${id} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
19883
19998
  fixed++;
19884
19999
  }
19885
- if (fixed) fs51.writeFileSync(README, lines.join("\n"));
20000
+ if (fixed) fs52.writeFileSync(README, lines.join("\n"));
19886
20001
  for (const c of indexableCards()) {
19887
20002
  if (!indexed.has(c.id)) {
19888
20003
  said3.push(`card ${c.rel} (#${c.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
@@ -19894,11 +20009,11 @@ function crossRefComplaints() {
19894
20009
  const said3 = [];
19895
20010
  const live = liveIds();
19896
20011
  for (const file of walkMd(TODO)) {
19897
- const base = path55.basename(file);
20012
+ const base = path57.basename(file);
19898
20013
  if (base === "README.md") continue;
19899
- const ownerId = base === "root.md" ? idPrefix(path55.basename(path55.dirname(file))) : idPrefix(base);
20014
+ const ownerId = base === "root.md" ? idPrefix(path57.basename(path57.dirname(file))) : idPrefix(base);
19900
20015
  if (ownerId == null) continue;
19901
- const { meta } = parseFrontmatter(fs51.readFileSync(file, "utf8"));
20016
+ const { meta } = parseFrontmatter(fs52.readFileSync(file, "utf8"));
19902
20017
  if (!meta) continue;
19903
20018
  for (const field2 of ["blocked_by", "related"]) {
19904
20019
  for (const ref of meta[field2] || []) {
@@ -19911,11 +20026,11 @@ function crossRefComplaints() {
19911
20026
  return said3;
19912
20027
  }
19913
20028
  function reconcileBoard() {
19914
- if (!fs51.existsSync(README)) return;
20029
+ if (!fs52.existsSync(README)) return;
19915
20030
  for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
19916
20031
  }
19917
20032
  function boardComplaints() {
19918
- if (!fs51.existsSync(README)) return [];
20033
+ if (!fs52.existsSync(README)) return [];
19919
20034
  try {
19920
20035
  return [...readmeComplaints(false), ...crossRefComplaints()];
19921
20036
  } catch {
@@ -19935,8 +20050,8 @@ var init_reconcile = __esm({
19935
20050
  });
19936
20051
 
19937
20052
  // src/commands/card.ts
19938
- import fs52 from "node:fs";
19939
- import path56 from "node:path";
20053
+ import fs53 from "node:fs";
20054
+ import path58 from "node:path";
19940
20055
  function defaultBody() {
19941
20056
  return [
19942
20057
  "<\u7528\u4E00\u5C0F\u6BB5\u8BDD\u5148\u8BB2\u53D1\u751F\u4E86\u4EC0\u4E48\u3001\u7528\u6237\u9047\u5230\u4EC0\u4E48\uFF0C\u518D\u8BB2\u8FD9\u5F20\u5361\u8981\u8FBE\u5230\u7684\u7ED3\u679C\u3002>",
@@ -19962,7 +20077,7 @@ function bodyFromFile(opts) {
19962
20077
  if (opts.body === false) die("pass --body-file or --no-body, not both");
19963
20078
  let text5;
19964
20079
  try {
19965
- text5 = fs52.readFileSync(opts.bodyFile, "utf8");
20080
+ text5 = fs53.readFileSync(opts.bodyFile, "utf8");
19966
20081
  } catch {
19967
20082
  die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
19968
20083
  }
@@ -19994,20 +20109,20 @@ function cmdCreate(opts) {
19994
20109
  const start = opts.id;
19995
20110
  const slug2 = slugify(opts.slug !== void 0 ? opts.slug : title);
19996
20111
  const fileRel = `${start}-${slug2}.md`;
19997
- const file = path56.join(TODO, fileRel);
20112
+ const file = path58.join(TODO, fileRel);
19998
20113
  const held4 = locate(start) ?? locateArchived(start);
19999
- if (held4 && path56.basename(held4.target) === `${start}-${slug2}.md`) {
20114
+ if (held4 && path58.basename(held4.target) === `${start}-${slug2}.md`) {
20000
20115
  say(start);
20001
20116
  say(` ${rel(held4.target)} was already written`);
20002
20117
  return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
20003
20118
  }
20004
20119
  if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
20005
- if (fs52.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
20120
+ if (fs53.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
20006
20121
  countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
20007
20122
  const meta = { title, priority, status: "todo", blocked_by, related, modules, workflow, triage, source, questions };
20008
20123
  const scaffolded = !written && opts.body !== false;
20009
20124
  const body = written ?? (scaffolded ? defaultBody() : "");
20010
- fs52.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
20125
+ fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
20011
20126
  const indexed = addReadmeRef(start, title, fileRel);
20012
20127
  say(start);
20013
20128
  say(
@@ -20045,8 +20160,8 @@ function cmdUpdate(id, flags) {
20045
20160
  if (creating) die(creating, { kind: "card-being-created", id });
20046
20161
  const found2 = locate(id);
20047
20162
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
20048
- const file = found2.kind === "group" ? path56.join(found2.target, "root.md") : found2.target;
20049
- const { meta, body } = parseFrontmatter(fs52.readFileSync(file, "utf8"));
20163
+ const file = found2.kind === "group" ? path58.join(found2.target, "root.md") : found2.target;
20164
+ const { meta, body } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
20050
20165
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
20051
20166
  if (flags.blockedBy !== void 0 && flags.addBlockedBy !== void 0) die("--blocked-by replaces the list and --add-blocked-by appends to it \u2014 pass one");
20052
20167
  if (flags.related !== void 0 && flags.addRelated !== void 0) die("--related replaces the list and --add-related appends to it \u2014 pass one");
@@ -20126,26 +20241,26 @@ function cmdUpdate(id, flags) {
20126
20241
  meta.status = "todo";
20127
20242
  changes.push("status\u2192todo (open questions)");
20128
20243
  }
20129
- const curRel = path56.relative(TODO, file);
20244
+ const curRel = path58.relative(TODO, file);
20130
20245
  const isSubtask = found2.kind === "file" && enclosingGroupRoot(file) !== null;
20131
- let base = path56.basename(file);
20246
+ let base = path58.basename(file);
20132
20247
  if (flags.slug !== void 0) {
20133
20248
  if (found2.kind === "group") die("renaming a group root by script is not supported");
20134
20249
  base = `${id}-${slugify(flags.slug)}.md`;
20135
20250
  }
20136
- const destRel = path56.join(path56.dirname(curRel), base);
20137
- const dest = path56.join(TODO, destRel);
20251
+ const destRel = path58.join(path58.dirname(curRel), base);
20252
+ const dest = path58.join(TODO, destRel);
20138
20253
  const moving = dest !== file;
20139
- if (moving && fs52.existsSync(dest)) die(`${rel(dest)} already exists`);
20140
- fs52.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20141
- if (moving) fs52.renameSync(file, dest);
20254
+ if (moving && fs53.existsSync(dest)) die(`${rel(dest)} already exists`);
20255
+ fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20256
+ if (moving) fs53.renameSync(file, dest);
20142
20257
  if (isSubtask) {
20143
20258
  if (moving || changes.includes("title")) repointReadmeLink(id, curRel, destRel, meta.title);
20144
- if (moving) changes.push(`renamed \u2192 ${destRel.split(path56.sep).join("/")}`);
20259
+ if (moving) changes.push(`renamed \u2192 ${destRel.split(path58.sep).join("/")}`);
20145
20260
  } else if (moving) {
20146
20261
  stripReadmeRefs({ kind: "file", rel: curRel });
20147
20262
  addReadmeRef(id, meta.title, destRel);
20148
- changes.push(`renamed \u2192 ${destRel.split(path56.sep).join("/")}`);
20263
+ changes.push(`renamed \u2192 ${destRel.split(path58.sep).join("/")}`);
20149
20264
  } else if (changes.includes("title")) {
20150
20265
  stripReadmeRefs({ kind: "file", rel: curRel });
20151
20266
  addReadmeRef(id, meta.title, curRel);
@@ -20157,8 +20272,8 @@ function cmdUpdateQuestions(id, input) {
20157
20272
  const ops = readQuestionOps(input.ops ?? []);
20158
20273
  const found2 = locate(id);
20159
20274
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
20160
- const file = found2.kind === "group" ? path56.join(found2.target, "root.md") : found2.target;
20161
- const { meta, body } = parseFrontmatter(fs52.readFileSync(file, "utf8"));
20275
+ const file = found2.kind === "group" ? path58.join(found2.target, "root.md") : found2.target;
20276
+ const { meta, body } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
20162
20277
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
20163
20278
  if (insideRun() && ops.some((op) => op.kind === "skip" || op.kind === "unskip")) {
20164
20279
  die("only the user skips or reopens a question \u2014 a run leaves questions for them to answer");
@@ -20231,7 +20346,7 @@ function cmdUpdateQuestions(id, input) {
20231
20346
  meta.status = "todo";
20232
20347
  changes.push("status\u2192todo (open questions)");
20233
20348
  }
20234
- fs52.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20349
+ fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
20235
20350
  for (const kind of closed2) countBoardEvent(kind);
20236
20351
  settleDelivery2(id, skipped, unskipped);
20237
20352
  say(
@@ -20305,13 +20420,13 @@ var init_config_template = __esm({
20305
20420
  });
20306
20421
 
20307
20422
  // src/lib/agent/local.ts
20308
- import fs53 from "node:fs";
20309
- import path57 from "node:path";
20423
+ import fs54 from "node:fs";
20424
+ import path59 from "node:path";
20310
20425
  function takeLocalModels(board2) {
20311
- const file = path57.join(board2, ".local.json");
20426
+ const file = path59.join(board2, ".local.json");
20312
20427
  let held4;
20313
20428
  try {
20314
- held4 = configBlock(JSON.parse(fs53.readFileSync(file, "utf8")));
20429
+ held4 = configBlock(JSON.parse(fs54.readFileSync(file, "utf8")));
20315
20430
  } catch {
20316
20431
  return {};
20317
20432
  }
@@ -20329,7 +20444,7 @@ function takeLocalModels(board2) {
20329
20444
  }
20330
20445
  if (!Object.keys(agents).length) return out;
20331
20446
  delete held4.agents;
20332
- fs53.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
20447
+ fs54.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
20333
20448
  return out;
20334
20449
  }
20335
20450
  var LOCAL_IGNORE_LINE;
@@ -20390,12 +20505,12 @@ var init_identity2 = __esm({
20390
20505
  });
20391
20506
 
20392
20507
  // src/lib/signals/migrate.ts
20393
- import fs54 from "node:fs";
20394
- import path58 from "node:path";
20508
+ import fs55 from "node:fs";
20509
+ import path60 from "node:path";
20395
20510
  function readHandled() {
20396
20511
  let text5;
20397
20512
  try {
20398
- text5 = fs54.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
20513
+ text5 = fs55.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
20399
20514
  } catch {
20400
20515
  return [];
20401
20516
  }
@@ -20412,57 +20527,57 @@ function readHandled() {
20412
20527
  return held4;
20413
20528
  }
20414
20529
  function lift(from, into) {
20415
- fs54.mkdirSync(into, { recursive: true });
20416
- fs54.renameSync(from, path58.join(into, freeName(into, path58.basename(from))));
20530
+ fs55.mkdirSync(into, { recursive: true });
20531
+ fs55.renameSync(from, path60.join(into, freeName(into, path60.basename(from))));
20417
20532
  }
20418
20533
  function repoint(dir, from, into) {
20419
20534
  let entries;
20420
20535
  try {
20421
- entries = fs54.readdirSync(dir, { withFileTypes: true });
20536
+ entries = fs55.readdirSync(dir, { withFileTypes: true });
20422
20537
  } catch {
20423
20538
  return;
20424
20539
  }
20425
20540
  for (const entry of entries) {
20426
20541
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
20427
- const file = path58.join(dir, entry.name);
20428
- const text5 = fs54.readFileSync(file, "utf8");
20429
- if (text5.includes(from)) fs54.writeFileSync(file, text5.split(from).join(into));
20542
+ const file = path60.join(dir, entry.name);
20543
+ const text5 = fs55.readFileSync(file, "utf8");
20544
+ if (text5.includes(from)) fs55.writeFileSync(file, text5.split(from).join(into));
20430
20545
  }
20431
20546
  }
20432
20547
  function dropIfEmpty2(dir) {
20433
20548
  try {
20434
- fs54.rmdirSync(dir);
20549
+ fs55.rmdirSync(dir);
20435
20550
  } catch {
20436
20551
  }
20437
20552
  }
20438
20553
  function liftInbox() {
20439
- if (!fs54.existsSync(SIGNALS_OLD_INBOX)) return;
20440
- const oldFiles = path58.join(SIGNALS_OLD_INBOX, "files");
20441
- if (fs54.existsSync(oldFiles)) {
20442
- for (const entry of fs54.readdirSync(oldFiles, { withFileTypes: true })) {
20443
- if (entry.isFile()) lift(path58.join(oldFiles, entry.name), SIGNALS_FILES);
20554
+ if (!fs55.existsSync(SIGNALS_OLD_INBOX)) return;
20555
+ const oldFiles = path60.join(SIGNALS_OLD_INBOX, "files");
20556
+ if (fs55.existsSync(oldFiles)) {
20557
+ for (const entry of fs55.readdirSync(oldFiles, { withFileTypes: true })) {
20558
+ if (entry.isFile()) lift(path60.join(oldFiles, entry.name), SIGNALS_FILES);
20444
20559
  }
20445
20560
  dropIfEmpty2(oldFiles);
20446
20561
  }
20447
20562
  const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
20448
- for (const entry of fs54.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
20563
+ for (const entry of fs55.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
20449
20564
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
20450
- const from = path58.join(SIGNALS_OLD_INBOX, entry.name);
20565
+ const from = path60.join(SIGNALS_OLD_INBOX, entry.name);
20451
20566
  const item = parse(from);
20452
20567
  if (item && held4.has(item.sourceId)) {
20453
- fs54.rmSync(from, { force: true });
20568
+ fs55.rmSync(from, { force: true });
20454
20569
  continue;
20455
20570
  }
20456
20571
  if (item) held4.add(item.sourceId);
20457
20572
  lift(from, TRIAGE);
20458
20573
  }
20459
- const wasAt = asWritten(path58.join(SIGNALS_OLD_INBOX, "files"));
20574
+ const wasAt = asWritten(path60.join(SIGNALS_OLD_INBOX, "files"));
20460
20575
  const nowAt = asWritten(SIGNALS_FILES);
20461
20576
  for (const dir of [TRIAGE, SIGNALS_ARCHIVED, SIGNALS_DISMISSED]) repoint(dir, wasAt, nowAt);
20462
20577
  dropIfEmpty2(SIGNALS_OLD_INBOX);
20463
20578
  }
20464
20579
  function liftHandled() {
20465
- if (!fs54.existsSync(SIGNALS_OLD_HANDLED)) return;
20580
+ if (!fs55.existsSync(SIGNALS_OLD_HANDLED)) return;
20466
20581
  const lines = readHandled();
20467
20582
  const held4 = /* @__PURE__ */ new Set([
20468
20583
  ...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
@@ -20472,7 +20587,7 @@ function liftHandled() {
20472
20587
  for (const { sourceId, when } of lines) {
20473
20588
  if (held4.has(sourceId)) continue;
20474
20589
  held4.add(sourceId);
20475
- fs54.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
20590
+ fs55.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
20476
20591
  const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
20477
20592
  const front = [
20478
20593
  "---",
@@ -20482,13 +20597,13 @@ function liftHandled() {
20482
20597
  "---",
20483
20598
  ""
20484
20599
  ];
20485
- fs54.writeFileSync(path58.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
20600
+ fs55.writeFileSync(path60.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
20486
20601
  `);
20487
20602
  }
20488
- fs54.rmSync(SIGNALS_OLD_HANDLED, { force: true });
20603
+ fs55.rmSync(SIGNALS_OLD_HANDLED, { force: true });
20489
20604
  }
20490
20605
  function migrateTriage() {
20491
- if (!fs54.existsSync(SIGNALS_OLD_INBOX) && !fs54.existsSync(SIGNALS_OLD_HANDLED)) return;
20606
+ if (!fs55.existsSync(SIGNALS_OLD_INBOX) && !fs55.existsSync(SIGNALS_OLD_HANDLED)) return;
20492
20607
  try {
20493
20608
  liftInbox();
20494
20609
  liftHandled();
@@ -20503,13 +20618,13 @@ var init_migrate = __esm({
20503
20618
  init_yaml();
20504
20619
  init_inbox();
20505
20620
  HANDLED_LINE = /^-\s+(.+?)\s+—\s+(.+)$/;
20506
- asWritten = (dir) => `${rel(dir).split(path58.sep).join("/")}/`;
20621
+ asWritten = (dir) => `${rel(dir).split(path60.sep).join("/")}/`;
20507
20622
  }
20508
20623
  });
20509
20624
 
20510
20625
  // src/lib/signals/add.ts
20511
- import fs55 from "node:fs";
20512
- import path59 from "node:path";
20626
+ import fs56 from "node:fs";
20627
+ import path61 from "node:path";
20513
20628
  import { createHash as createHash3 } from "node:crypto";
20514
20629
  function linkTitle(url) {
20515
20630
  let at;
@@ -20522,7 +20637,7 @@ function linkTitle(url) {
20522
20637
  return oneLine(where) || url.slice(0, TITLE_MAX);
20523
20638
  }
20524
20639
  function asText(file) {
20525
- const ext = path59.extname(file.name).toLowerCase();
20640
+ const ext = path61.extname(file.name).toLowerCase();
20526
20641
  if (!file.type.startsWith("text/") && file.type !== "application/json" && !TEXT_EXTENSIONS.has(ext)) return null;
20527
20642
  try {
20528
20643
  const text5 = new TextDecoder("utf-8", { fatal: true }).decode(file.data);
@@ -20532,9 +20647,9 @@ function asText(file) {
20532
20647
  }
20533
20648
  }
20534
20649
  function fileName2(name, data) {
20535
- const base = path59.basename(name);
20536
- const ext = path59.extname(base).toLowerCase().slice(0, 12);
20537
- const word = path59.basename(base, path59.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
20650
+ const base = path61.basename(name);
20651
+ const ext = path61.extname(base).toLowerCase().slice(0, 12);
20652
+ const word = path61.basename(base, path61.extname(base)).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "file";
20538
20653
  const hash2 = createHash3("sha256").update(data).digest("hex").slice(0, 8);
20539
20654
  return `${word}-${hash2}${ext}`;
20540
20655
  }
@@ -20543,9 +20658,9 @@ function addToInbox(drop) {
20543
20658
  const typed = (drop.text ?? "").trim();
20544
20659
  const file = drop.file;
20545
20660
  if (!typed && !file) return { ok: false, error: "nothing to add \u2014 paste a link or some text, or drop a file." };
20546
- if (file && file.data.length === 0) return { ok: false, error: `${path59.basename(file.name)} is empty.` };
20661
+ if (file && file.data.length === 0) return { ok: false, error: `${path61.basename(file.name)} is empty.` };
20547
20662
  if (file && file.data.length > MAX_BYTES) {
20548
- return { ok: false, error: `${path59.basename(file.name)} is over ${MAX_BYTES / 1024 / 1024} MB \u2014 too big for the board.` };
20663
+ return { ok: false, error: `${path61.basename(file.name)} is over ${MAX_BYTES / 1024 / 1024} MB \u2014 too big for the board.` };
20549
20664
  }
20550
20665
  const read4 = describe(typed, file);
20551
20666
  const keep2 = read4.keep;
@@ -20567,8 +20682,8 @@ ${incoming.summary}`);
20567
20682
  if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
20568
20683
  try {
20569
20684
  if (keep2) {
20570
- fs55.mkdirSync(SIGNALS_FILES, { recursive: true });
20571
- fs55.writeFileSync(keep2.at, keep2.data);
20685
+ fs56.mkdirSync(SIGNALS_FILES, { recursive: true });
20686
+ fs56.writeFileSync(keep2.at, keep2.data);
20572
20687
  }
20573
20688
  return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
20574
20689
  } catch (e) {
@@ -20582,7 +20697,7 @@ function describe(typed, file) {
20582
20697
  return only ? [only] : [];
20583
20698
  };
20584
20699
  if (file) {
20585
- const name = path59.basename(file.name);
20700
+ const name = path61.basename(file.name);
20586
20701
  const text5 = asText(file);
20587
20702
  const note = typed ? `
20588
20703
 
@@ -20594,7 +20709,7 @@ ${typed}` : "";
20594
20709
  const at = keepAt(file);
20595
20710
  return {
20596
20711
  incoming: {
20597
- title: path59.basename(name, path59.extname(name)) || name,
20712
+ title: path61.basename(name, path61.extname(name)) || name,
20598
20713
  summary: `${name} \u2014 ${boardRel2(at)}${note}`,
20599
20714
  ...named2
20600
20715
  },
@@ -20632,73 +20747,73 @@ var init_add = __esm({
20632
20747
  MAX_BYTES = 25 * 1024 * 1024;
20633
20748
  TITLE_MAX = 120;
20634
20749
  TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".markdown", ".txt", ".text", ".csv", ".json", ".yml", ".yaml", ".log"]);
20635
- boardRel2 = (file) => rel(file).split(path59.sep).join("/");
20750
+ boardRel2 = (file) => rel(file).split(path61.sep).join("/");
20636
20751
  oneLine = (text5) => {
20637
20752
  const first = text5.split("\n").find((line) => line.trim()) ?? "";
20638
20753
  const clean = first.replace(/^#+\s*/, "").trim();
20639
20754
  return clean.length > TITLE_MAX ? `${clean.slice(0, TITLE_MAX - 1).trimEnd()}\u2026` : clean;
20640
20755
  };
20641
- keepAt = (file) => path59.join(SIGNALS_FILES, fileName2(file.name, file.data));
20756
+ keepAt = (file) => path61.join(SIGNALS_FILES, fileName2(file.name, file.data));
20642
20757
  }
20643
20758
  });
20644
20759
 
20645
20760
  // src/lib/recurring.ts
20646
- import fs56 from "node:fs";
20647
- import path60 from "node:path";
20761
+ import fs57 from "node:fs";
20762
+ import path62 from "node:path";
20648
20763
  function migratePruneMemoryCard() {
20649
20764
  const dir = recurringDir();
20650
20765
  let names4;
20651
20766
  try {
20652
- names4 = fs56.readdirSync(dir);
20767
+ names4 = fs57.readdirSync(dir);
20653
20768
  } catch {
20654
20769
  return null;
20655
20770
  }
20656
20771
  const name = names4.find((entry) => entry.endsWith(`-${PRUNE_SLUG}.md`));
20657
20772
  if (!name) return null;
20658
- const file = path60.join(dir, name);
20773
+ const file = path62.join(dir, name);
20659
20774
  try {
20660
- const { meta } = parseFrontmatter(fs56.readFileSync(file, "utf8"));
20775
+ const { meta } = parseFrontmatter(fs57.readFileSync(file, "utf8"));
20661
20776
  const cadence = meta?.cadence;
20662
20777
  if (typeof cadence === "string") adoptMemoryPruneCadence(cadence);
20663
20778
  } catch {
20664
20779
  }
20665
- fs56.rmSync(file, { force: true });
20780
+ fs57.rmSync(file, { force: true });
20666
20781
  return rel(file);
20667
20782
  }
20668
20783
  function legacyCards() {
20669
20784
  const dir = recurringDir();
20670
- if (!fs56.existsSync(dir)) return [];
20785
+ if (!fs57.existsSync(dir)) return [];
20671
20786
  const cards = [];
20672
- for (const entry of fs56.readdirSync(dir, { withFileTypes: true })) {
20787
+ for (const entry of fs57.readdirSync(dir, { withFileTypes: true })) {
20673
20788
  const id = idPrefix(entry.name);
20674
20789
  if (id === null) continue;
20675
- const full = path60.join(dir, entry.name);
20790
+ const full = path62.join(dir, entry.name);
20676
20791
  const slug2 = entry.name.replace(/\.md$/, "").replace(/^\d+-?/, "");
20677
20792
  if (entry.isFile() && entry.name.endsWith(".md")) cards.push({ id, slug: slug2, file: full });
20678
- else if (entry.isDirectory() && fs56.existsSync(path60.join(full, "root.md"))) {
20679
- cards.push({ id, slug: slug2, file: path60.join(full, "root.md"), folder: full });
20793
+ else if (entry.isDirectory() && fs57.existsSync(path62.join(full, "root.md"))) {
20794
+ cards.push({ id, slug: slug2, file: path62.join(full, "root.md"), folder: full });
20680
20795
  }
20681
20796
  }
20682
20797
  return cards.sort((a, b) => a.id - b.id);
20683
20798
  }
20684
20799
  function mergeInto2(from, to, skip = []) {
20685
- fs56.mkdirSync(to, { recursive: true });
20686
- for (const entry of fs56.readdirSync(from, { withFileTypes: true })) {
20800
+ fs57.mkdirSync(to, { recursive: true });
20801
+ for (const entry of fs57.readdirSync(from, { withFileTypes: true })) {
20687
20802
  if (skip.includes(entry.name)) continue;
20688
- const source = path60.join(from, entry.name);
20689
- const target = path60.join(to, entry.name);
20690
- if (!fs56.existsSync(target)) fs56.renameSync(source, target);
20691
- else if (entry.isDirectory() && fs56.statSync(target).isDirectory()) mergeInto2(source, target);
20803
+ const source = path62.join(from, entry.name);
20804
+ const target = path62.join(to, entry.name);
20805
+ if (!fs57.existsSync(target)) fs57.renameSync(source, target);
20806
+ else if (entry.isDirectory() && fs57.statSync(target).isDirectory()) mergeInto2(source, target);
20692
20807
  }
20693
- if (isEmpty(from)) fs56.rmSync(from, { recursive: true, force: true });
20808
+ if (isEmpty(from)) fs57.rmSync(from, { recursive: true, force: true });
20694
20809
  }
20695
20810
  function moveSideFolders() {
20696
20811
  const dir = recurringDir();
20697
- for (const entry of fs56.readdirSync(dir, { withFileTypes: true })) {
20812
+ for (const entry of fs57.readdirSync(dir, { withFileTypes: true })) {
20698
20813
  if (!entry.isDirectory() || idPrefix(entry.name) !== null) continue;
20699
- const from = path60.join(dir, entry.name);
20700
- if (isEmpty(from)) fs56.rmSync(from, { recursive: true, force: true });
20701
- else mergeInto2(from, path60.join(AGENTS, entry.name));
20814
+ const from = path62.join(dir, entry.name);
20815
+ if (isEmpty(from)) fs57.rmSync(from, { recursive: true, force: true });
20816
+ else mergeInto2(from, path62.join(AGENTS, entry.name));
20702
20817
  }
20703
20818
  }
20704
20819
  function sections(body) {
@@ -20748,8 +20863,8 @@ function agentName(card, text5) {
20748
20863
  const known2 = /* @__PURE__ */ new Set([...specAgentCatalog().agents.map((a) => a.name), ...ROLE_NAMES]);
20749
20864
  for (const name of [slug2, `${slug2}-${card.id}`]) {
20750
20865
  if (!AGENT_NAME.test(name)) continue;
20751
- const file = path60.join(AGENTS, name, AGENT_FILE3);
20752
- const written = fs56.existsSync(file) ? fs56.readFileSync(file, "utf8") : null;
20866
+ const file = path62.join(AGENTS, name, AGENT_FILE3);
20867
+ const written = fs57.existsSync(file) ? fs57.readFileSync(file, "utf8") : null;
20753
20868
  if (written === text5(name)) return name;
20754
20869
  if (written === null && !known2.has(name)) return name;
20755
20870
  }
@@ -20766,11 +20881,11 @@ ${q.options.map((o) => `- ${o}`).join("\n")}` : "";
20766
20881
  function removeCard(card) {
20767
20882
  dropCrossRefs(card.id);
20768
20883
  const target = card.folder ?? card.file;
20769
- stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path60.relative(TODO, target).split(path60.sep).join("/") });
20770
- fs56.rmSync(target, { recursive: true, force: true });
20884
+ stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path62.relative(TODO, target).split(path62.sep).join("/") });
20885
+ fs57.rmSync(target, { recursive: true, force: true });
20771
20886
  }
20772
20887
  function migrateCard(card) {
20773
- const { meta, body } = parseFrontmatter(fs56.readFileSync(card.file, "utf8"));
20888
+ const { meta, body } = parseFrontmatter(fs57.readFileSync(card.file, "utf8"));
20774
20889
  if (!meta) throw new Error("its frontmatter cannot be read");
20775
20890
  const raw = meta;
20776
20891
  const said3 = (key) => typeof raw[key] === "string" ? raw[key].trim() : "";
@@ -20780,19 +20895,19 @@ function migrateCard(card) {
20780
20895
  if (!flow) throw new Error("this board has no workflow to put it in");
20781
20896
  const text5 = (name2) => agentText(name2, meta.title || card.slug, body);
20782
20897
  const name = agentName(card, text5);
20783
- const dir = path60.join(AGENTS, name);
20784
- const file = path60.join(dir, AGENT_FILE3);
20785
- const madeDir = !fs56.existsSync(dir);
20786
- const wrote = !fs56.existsSync(file);
20898
+ const dir = path62.join(AGENTS, name);
20899
+ const file = path62.join(dir, AGENT_FILE3);
20900
+ const madeDir = !fs57.existsSync(dir);
20901
+ const wrote = !fs57.existsSync(file);
20787
20902
  try {
20788
- fs56.mkdirSync(dir, { recursive: true });
20789
- if (wrote) fs56.writeFileSync(file, text5(name));
20903
+ fs57.mkdirSync(dir, { recursive: true });
20904
+ if (wrote) fs57.writeFileSync(file, text5(name));
20790
20905
  const adopted = adoptWorkflowScheduled(flow.id, name, { cadence, lastRun });
20791
20906
  if (!adopted.ok) throw new Error(adopted.error);
20792
20907
  questionsToTriage(meta, name);
20793
20908
  } catch (e) {
20794
- if (madeDir) fs56.rmSync(dir, { recursive: true, force: true });
20795
- else if (wrote) fs56.rmSync(file, { force: true });
20909
+ if (madeDir) fs57.rmSync(dir, { recursive: true, force: true });
20910
+ else if (wrote) fs57.rmSync(file, { force: true });
20796
20911
  throw e;
20797
20912
  }
20798
20913
  if (card.folder) mergeInto2(card.folder, dir, ["root.md"]);
@@ -20802,7 +20917,7 @@ function migrateCard(card) {
20802
20917
  function migrateRecurringCards() {
20803
20918
  const done2 = { agents: [], removed: [], failed: [] };
20804
20919
  const dir = recurringDir();
20805
- if (!fs56.existsSync(dir)) return done2;
20920
+ if (!fs57.existsSync(dir)) return done2;
20806
20921
  migratePruneMemoryCard();
20807
20922
  moveSideFolders();
20808
20923
  for (const card of legacyCards()) {
@@ -20815,7 +20930,7 @@ function migrateRecurringCards() {
20815
20930
  done2.failed.push({ card: rel(card.file), why: e instanceof Error ? e.message : String(e) });
20816
20931
  }
20817
20932
  }
20818
- if (isEmpty(dir)) fs56.rmSync(dir, { recursive: true, force: true });
20933
+ if (isEmpty(dir)) fs57.rmSync(dir, { recursive: true, force: true });
20819
20934
  return done2;
20820
20935
  }
20821
20936
  function recurringMigrationLines(done2) {
@@ -20848,14 +20963,14 @@ var init_recurring = __esm({
20848
20963
  PRUNE_SLUG = "prune-the-memory";
20849
20964
  FETCH_SLUG = "fetch-triage-items";
20850
20965
  AGENT_FILE3 = "AGENT.md";
20851
- recurringDir = () => path60.join(TODO, LEGACY_RECURRING);
20852
- isEmpty = (dir) => fs56.readdirSync(dir).every((name) => name === ".DS_Store");
20966
+ recurringDir = () => path62.join(TODO, LEGACY_RECURRING);
20967
+ isEmpty = (dir) => fs57.readdirSync(dir).every((name) => name === ".DS_Store");
20853
20968
  SECTION = /^##\s+(.+?)\s*$/;
20854
20969
  }
20855
20970
  });
20856
20971
 
20857
20972
  // src/commands/init.ts
20858
- import fs57 from "node:fs";
20973
+ import fs58 from "node:fs";
20859
20974
  function boardReadme() {
20860
20975
  return `# Board
20861
20976
 
@@ -20868,20 +20983,20 @@ _(none)_
20868
20983
  `;
20869
20984
  }
20870
20985
  function writeConfigIfMissing() {
20871
- if (fs57.existsSync(CONFIG)) return false;
20872
- fs57.mkdirSync(KANBAN, { recursive: true });
20873
- fs57.writeFileSync(CONFIG, CONFIG_TEMPLATE);
20986
+ if (fs58.existsSync(CONFIG)) return false;
20987
+ fs58.mkdirSync(KANBAN, { recursive: true });
20988
+ fs58.writeFileSync(CONFIG, CONFIG_TEMPLATE);
20874
20989
  return true;
20875
20990
  }
20876
20991
  function writeModulesIfMissing() {
20877
- if (fs57.existsSync(MODULES_MD)) return false;
20878
- fs57.mkdirSync(KANBAN, { recursive: true });
20879
- fs57.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
20992
+ if (fs58.existsSync(MODULES_MD)) return false;
20993
+ fs58.mkdirSync(KANBAN, { recursive: true });
20994
+ fs58.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
20880
20995
  return true;
20881
20996
  }
20882
20997
  function writeGitignoreIfMissing() {
20883
- fs57.mkdirSync(KANBAN, { recursive: true });
20884
- const text5 = fs57.existsSync(KANBAN_GITIGNORE) ? fs57.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
20998
+ fs58.mkdirSync(KANBAN, { recursive: true });
20999
+ const text5 = fs58.existsSync(KANBAN_GITIGNORE) ? fs58.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
20885
21000
  const has = (rule) => text5.split("\n").some((line) => line.trim() === rule.line);
20886
21001
  const missing = IGNORE_RULES.filter((rule) => !has(rule));
20887
21002
  if (!missing.length) return false;
@@ -20889,37 +21004,37 @@ function writeGitignoreIfMissing() {
20889
21004
  ${rule.line}
20890
21005
  `).join("");
20891
21006
  const separator = !text5 || text5.endsWith("\n") ? "" : "\n";
20892
- fs57.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
21007
+ fs58.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
20893
21008
  return true;
20894
21009
  }
20895
21010
  function writeSkeletonIfMissing() {
20896
21011
  const added = [];
20897
- if (!fs57.existsSync(TODO)) {
20898
- fs57.mkdirSync(TODO, { recursive: true });
21012
+ if (!fs58.existsSync(TODO)) {
21013
+ fs58.mkdirSync(TODO, { recursive: true });
20899
21014
  added.push(`${rel(TODO)}/`);
20900
21015
  }
20901
- if (!fs57.existsSync(README)) {
20902
- fs57.writeFileSync(README, boardReadme());
21016
+ if (!fs58.existsSync(README)) {
21017
+ fs58.writeFileSync(README, boardReadme());
20903
21018
  added.push(rel(README));
20904
21019
  }
20905
21020
  return added;
20906
21021
  }
20907
21022
  function retireReleases() {
20908
21023
  const done2 = [];
20909
- if (fs57.existsSync(RELEASES)) {
20910
- fs57.rmSync(RELEASES);
21024
+ if (fs58.existsSync(RELEASES)) {
21025
+ fs58.rmSync(RELEASES);
20911
21026
  done2.push(`deleted ${rel(RELEASES)}`);
20912
21027
  }
20913
21028
  let cards = 0;
20914
21029
  for (const dir of [TODO, ARCHIVE]) {
20915
- if (!fs57.existsSync(dir)) continue;
21030
+ if (!fs58.existsSync(dir)) continue;
20916
21031
  for (const file of walkMd(dir)) {
20917
- const text5 = fs57.readFileSync(file, "utf8");
21032
+ const text5 = fs58.readFileSync(file, "utf8");
20918
21033
  const end2 = text5.startsWith("---\n") ? text5.indexOf("\n---", 3) : -1;
20919
21034
  if (end2 < 0) continue;
20920
21035
  const head = text5.slice(0, end2).replace(/\nrelease:[^\n]*/, "");
20921
21036
  if (head.length === end2) continue;
20922
- fs57.writeFileSync(file, head + text5.slice(end2));
21037
+ fs58.writeFileSync(file, head + text5.slice(end2));
20923
21038
  cards++;
20924
21039
  }
20925
21040
  }
@@ -20927,7 +21042,7 @@ function retireReleases() {
20927
21042
  return done2.join(", ");
20928
21043
  }
20929
21044
  function cmdInit() {
20930
- if (fs57.existsSync(KANBAN)) {
21045
+ if (fs58.existsSync(KANBAN)) {
20931
21046
  const added = [
20932
21047
  ...writeSkeletonIfMissing(),
20933
21048
  writeConfigIfMissing() && rel(CONFIG),
@@ -20962,8 +21077,8 @@ function cmdInit() {
20962
21077
  }
20963
21078
  return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
20964
21079
  }
20965
- fs57.mkdirSync(TODO, { recursive: true });
20966
- fs57.writeFileSync(README, boardReadme());
21080
+ fs58.mkdirSync(TODO, { recursive: true });
21081
+ fs58.writeFileSync(README, boardReadme());
20967
21082
  writeConfigIfMissing();
20968
21083
  scaffoldProjectMemory();
20969
21084
  writeModulesIfMissing();
@@ -21052,25 +21167,25 @@ var init_scheduled = __esm({
21052
21167
  });
21053
21168
 
21054
21169
  // src/lib/card-age.ts
21055
- import fs58 from "node:fs";
21056
- import path61 from "node:path";
21170
+ import fs59 from "node:fs";
21171
+ import path63 from "node:path";
21057
21172
  function staleAfterIn(config) {
21058
21173
  const days = Number(LINE.exec(config)?.[1]);
21059
21174
  return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
21060
21175
  }
21061
21176
  function staleAfter() {
21062
- if (!fs58.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
21063
- return staleAfterIn(fs58.readFileSync(CONFIG, "utf8"));
21177
+ if (!fs59.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
21178
+ return staleAfterIn(fs59.readFileSync(CONFIG, "utf8"));
21064
21179
  }
21065
21180
  function todoPathspec(top) {
21066
- const from = path61.relative(real(top), real(TODO));
21067
- if (!from || from.startsWith("..") || path61.isAbsolute(from)) return null;
21068
- return from.split(path61.sep).join("/");
21181
+ const from = path63.relative(real(top), real(TODO));
21182
+ if (!from || from.startsWith("..") || path63.isAbsolute(from)) return null;
21183
+ return from.split(path63.sep).join("/");
21069
21184
  }
21070
21185
  function cardFile2(spec, printed) {
21071
21186
  const p = unquotePath(printed);
21072
21187
  if (!p.startsWith(`${spec}/`)) return null;
21073
- return path61.join(TODO, ...p.slice(spec.length + 1).split("/"));
21188
+ return path63.join(TODO, ...p.slice(spec.length + 1).split("/"));
21074
21189
  }
21075
21190
  function dirtyCards(top, spec) {
21076
21191
  const out = git(["status", "--porcelain", "--untracked-files=all", "--", spec], top);
@@ -21117,9 +21232,9 @@ var init_card_age = __esm({
21117
21232
  gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
21118
21233
  real = (p) => {
21119
21234
  try {
21120
- return fs58.realpathSync(p);
21235
+ return fs59.realpathSync(p);
21121
21236
  } catch {
21122
- return path61.resolve(p);
21237
+ return path63.resolve(p);
21123
21238
  }
21124
21239
  };
21125
21240
  unquotePath = (line) => {
@@ -21154,8 +21269,8 @@ var init_card_holds = __esm({
21154
21269
  });
21155
21270
 
21156
21271
  // src/commands/list.ts
21157
- import fs59 from "node:fs";
21158
- import path62 from "node:path";
21272
+ import fs60 from "node:fs";
21273
+ import path64 from "node:path";
21159
21274
  function summaryLine(body) {
21160
21275
  const lines = body.split("\n");
21161
21276
  let i = 0;
@@ -21171,13 +21286,13 @@ function summaryLine(body) {
21171
21286
  function openRows() {
21172
21287
  const rows = [];
21173
21288
  for (const file of walkMd(TODO)) {
21174
- const base = path62.basename(file);
21289
+ const base = path64.basename(file);
21175
21290
  if (base === "README.md") continue;
21176
21291
  const isRoot = base === "root.md";
21177
- const id = isRoot ? idPrefix(path62.basename(path62.dirname(file))) : idPrefix(base);
21292
+ const id = isRoot ? idPrefix(path64.basename(path64.dirname(file))) : idPrefix(base);
21178
21293
  if (id == null) continue;
21179
- if (isLegacyRecurring(path62.relative(TODO, file))) continue;
21180
- const { meta, body } = parseFrontmatter(fs59.readFileSync(file, "utf8"));
21294
+ if (isLegacyRecurring(path64.relative(TODO, file))) continue;
21295
+ const { meta, body } = parseFrontmatter(fs60.readFileSync(file, "utf8"));
21181
21296
  rows.push({
21182
21297
  id,
21183
21298
  file,
@@ -21219,15 +21334,15 @@ function cmdStale(rows, all2, scope, mod) {
21219
21334
  }
21220
21335
  function archivedFiles() {
21221
21336
  const files2 = /* @__PURE__ */ new Map();
21222
- if (!fs59.existsSync(ARCHIVE)) return files2;
21337
+ if (!fs60.existsSync(ARCHIVE)) return files2;
21223
21338
  for (const file of walkMd(ARCHIVE)) {
21224
- const id = idPrefix(path62.basename(file));
21339
+ const id = idPrefix(path64.basename(file));
21225
21340
  if (id !== null) files2.set(id, file);
21226
21341
  }
21227
21342
  for (const dir of walkDirs(ARCHIVE)) {
21228
- const id = idPrefix(path62.basename(dir));
21229
- const root = path62.join(dir, "root.md");
21230
- if (id !== null && fs59.existsSync(root)) files2.set(id, root);
21343
+ const id = idPrefix(path64.basename(dir));
21344
+ const root = path64.join(dir, "root.md");
21345
+ if (id !== null && fs60.existsSync(root)) files2.set(id, root);
21231
21346
  }
21232
21347
  return files2;
21233
21348
  }
@@ -21338,14 +21453,14 @@ var init_list = __esm({
21338
21453
  });
21339
21454
 
21340
21455
  // src/commands/misc.ts
21341
- import fs60 from "node:fs";
21342
- import path63 from "node:path";
21456
+ import fs61 from "node:fs";
21457
+ import path65 from "node:path";
21343
21458
  function extractOldMeta(text5, file) {
21344
21459
  const grab = (re) => {
21345
21460
  const m = text5.match(re);
21346
21461
  return m ? m[1].trim() : null;
21347
21462
  };
21348
- const title = grab(/^#\s+(.+)$/m) || slugify(path63.basename(file, ".md").replace(/^\d+-/, "")).replace(/-/g, " ");
21463
+ const title = grab(/^#\s+(.+)$/m) || slugify(path65.basename(file, ".md").replace(/^\d+-/, "")).replace(/-/g, " ");
21349
21464
  const norm = (raw) => {
21350
21465
  const v = (raw || "").toLowerCase();
21351
21466
  return LEVELS.includes(v) ? v : "med";
@@ -21372,11 +21487,11 @@ function stripOldHeader(text5) {
21372
21487
  }
21373
21488
  function cmdMigrate(opts) {
21374
21489
  const dry = opts.dryRun === true;
21375
- const files2 = walkMd(TODO).filter((f) => path63.basename(f) !== "README.md");
21490
+ const files2 = walkMd(TODO).filter((f) => path65.basename(f) !== "README.md");
21376
21491
  let changed = 0;
21377
21492
  let skipped = 0;
21378
21493
  for (const file of files2) {
21379
- const text5 = fs60.readFileSync(file, "utf8");
21494
+ const text5 = fs61.readFileSync(file, "utf8");
21380
21495
  if (text5.trimStart().startsWith("---")) {
21381
21496
  skipped++;
21382
21497
  continue;
@@ -21385,7 +21500,7 @@ function cmdMigrate(opts) {
21385
21500
  const out = serializeFrontmatter(meta) + "\n\n" + stripOldHeader(text5).replace(/^\n+/, "");
21386
21501
  if (dry) say(`would migrate ${rel(file)} (priority=${meta.priority})`);
21387
21502
  else {
21388
- fs60.writeFileSync(file, out.endsWith("\n") ? out : out + "\n");
21503
+ fs61.writeFileSync(file, out.endsWith("\n") ? out : out + "\n");
21389
21504
  say(`migrated ${rel(file)}`);
21390
21505
  }
21391
21506
  changed++;
@@ -21406,10 +21521,10 @@ var init_misc = __esm({
21406
21521
  });
21407
21522
 
21408
21523
  // src/lib/group-close.ts
21409
- import fs61 from "node:fs";
21524
+ import fs62 from "node:fs";
21410
21525
  function groupCloses(rootFile) {
21411
21526
  try {
21412
- return groupCloseOf(fs61.readFileSync(rootFile, "utf8"));
21527
+ return groupCloseOf(fs62.readFileSync(rootFile, "utf8"));
21413
21528
  } catch {
21414
21529
  return false;
21415
21530
  }
@@ -21422,12 +21537,12 @@ var init_group_close = __esm({
21422
21537
  });
21423
21538
 
21424
21539
  // src/commands/remove.ts
21425
- import fs62 from "node:fs";
21426
- import path64 from "node:path";
21540
+ import fs63 from "node:fs";
21541
+ import path66 from "node:path";
21427
21542
  function leavingIds(id, found2) {
21428
21543
  const ids = /* @__PURE__ */ new Set([id]);
21429
21544
  if (found2.kind === "group") {
21430
- const names4 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f) => path64.basename(f));
21545
+ const names4 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f) => path66.basename(f));
21431
21546
  for (const name of names4) {
21432
21547
  const n = idPrefix(name);
21433
21548
  if (n !== null) ids.add(n);
@@ -21439,10 +21554,10 @@ function findMentions(ids) {
21439
21554
  const hits = [];
21440
21555
  const re = new RegExp(ids.map((id) => `#${id}(?!\\d)`).join("|"));
21441
21556
  for (const dir of [TODO, MEMORY]) {
21442
- if (!fs62.existsSync(dir)) continue;
21557
+ if (!fs63.existsSync(dir)) continue;
21443
21558
  for (const file of walkMd(dir)) {
21444
- if (path64.basename(file) === "README.md") continue;
21445
- const lines = fs62.readFileSync(file, "utf8").split("\n");
21559
+ if (path66.basename(file) === "README.md") continue;
21560
+ const lines = fs63.readFileSync(file, "utf8").split("\n");
21446
21561
  const fmEnd = frontmatterEnd(lines);
21447
21562
  lines.forEach((line, i) => {
21448
21563
  if (!re.test(line)) return;
@@ -21458,12 +21573,12 @@ function findMentions(ids) {
21458
21573
  return hits;
21459
21574
  }
21460
21575
  function leavingCards(id, found2) {
21461
- const own = found2.kind === "group" ? path64.join(found2.target, "root.md") : found2.target;
21576
+ const own = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
21462
21577
  const cards = [{ id, file: own }];
21463
21578
  if (found2.kind !== "group") return cards;
21464
21579
  for (const file of walkMd(found2.target)) {
21465
21580
  if (file === own) continue;
21466
- const n = idPrefix(path64.basename(file));
21581
+ const n = idPrefix(path66.basename(file));
21467
21582
  if (n !== null) cards.push({ id: n, file });
21468
21583
  }
21469
21584
  return cards;
@@ -21472,10 +21587,10 @@ function stampLeaving(cards, rejection) {
21472
21587
  const day = formatDay();
21473
21588
  const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() ? "agent" : "user" } : rejection && { reason: rejection.reason };
21474
21589
  for (const card of cards) {
21475
- if (!fs62.existsSync(card.file)) continue;
21476
- const text5 = fs62.readFileSync(card.file, "utf8");
21590
+ if (!fs63.existsSync(card.file)) continue;
21591
+ const text5 = fs63.readFileSync(card.file, "utf8");
21477
21592
  const stamped = stampLeavingIn(text5, day, stamp4);
21478
- if (stamped !== text5) fs62.writeFileSync(card.file, stamped);
21593
+ if (stamped !== text5) fs63.writeFileSync(card.file, stamped);
21479
21594
  }
21480
21595
  }
21481
21596
  function unfinishedDelivery(id) {
@@ -21491,7 +21606,7 @@ function unfinishedDelivery(id) {
21491
21606
  }[gap];
21492
21607
  return `#${id} is not finished: ${what}.`;
21493
21608
  }
21494
- const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs62.existsSync(path64.join(ASSETS, src.slice(".assets/".length))));
21609
+ const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs63.existsSync(path66.join(ASSETS, src.slice(".assets/".length))));
21495
21610
  return missing ? `#${id} is not finished: ${missing} is not on this machine.` : null;
21496
21611
  }
21497
21612
  function agentDecisions(text5) {
@@ -21518,8 +21633,8 @@ function removeCard2(id, metric, options) {
21518
21633
  const unfinished = metric === "completed" ? unfinishedDelivery(id) : null;
21519
21634
  if (unfinished) die(unfinished, { kind: "plan-delivery-unfinished" });
21520
21635
  const dest = options.cleanupDiscarded && locateArchived(id) ? null : archiveDest(found2);
21521
- const cardFile3 = found2.kind === "group" ? path64.join(found2.target, "root.md") : found2.target;
21522
- const cardText = fs62.existsSync(cardFile3) ? fs62.readFileSync(cardFile3, "utf8") : "";
21636
+ const cardFile3 = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
21637
+ const cardText = fs63.existsSync(cardFile3) ? fs63.readFileSync(cardFile3, "utf8") : "";
21523
21638
  const { meta: cardMeta3 } = parseFrontmatter(cardText);
21524
21639
  const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f) => f !== cardFile3).map((f) => rel(f)).sort() : [];
21525
21640
  const leftIds = leavingIds(id, found2);
@@ -21550,10 +21665,10 @@ function removeCard2(id, metric, options) {
21550
21665
  const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
21551
21666
  if (dest) {
21552
21667
  stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
21553
- fs62.mkdirSync(ARCHIVE, { recursive: true });
21554
- fs62.renameSync(found2.target, dest);
21668
+ fs63.mkdirSync(ARCHIVE, { recursive: true });
21669
+ fs63.renameSync(found2.target, dest);
21555
21670
  } else {
21556
- fs62.rmSync(found2.target, { recursive: true, force: true });
21671
+ fs63.rmSync(found2.target, { recursive: true, force: true });
21557
21672
  }
21558
21673
  const removedRefs = stripReadmeRefs(found2);
21559
21674
  let marked2 = null;
@@ -21602,14 +21717,14 @@ function removeCard2(id, metric, options) {
21602
21717
  };
21603
21718
  }
21604
21719
  function closeGroup(rootFile) {
21605
- const rootId = idPrefix(path64.basename(path64.dirname(rootFile)));
21720
+ const rootId = idPrefix(path66.basename(path66.dirname(rootFile)));
21606
21721
  if (rootId === null) return null;
21607
21722
  if (runnerProject(KANBAN)) return null;
21608
21723
  if (!groupCloses(rootFile)) return null;
21609
21724
  say(`
21610
21725
  every subtask line on #${rootId} is resolved \u2014 closing the group:`);
21611
21726
  try {
21612
- const { meta, body } = parseFrontmatter(fs62.readFileSync(rootFile, "utf8"));
21727
+ const { meta, body } = parseFrontmatter(fs63.readFileSync(rootFile, "utf8"));
21613
21728
  const res = cmdRemove(rootId, "completed", { closing: true });
21614
21729
  return {
21615
21730
  id: rootId,
@@ -21666,7 +21781,7 @@ function cleanupDiscardedCards(sessionId) {
21666
21781
  if (card.pending) throw new Error(`Discarding #${card.id} did not finish. Retry the discard.`);
21667
21782
  while (locate(card.id)) cmdRemove(card.id, "rejected", { discard: true, cleanupDiscarded: true });
21668
21783
  dropCrossRefs(card.id);
21669
- stripReadmeRefs({ kind: "file", rel: path64.relative(TODO, path64.resolve(REPO_ROOT, card.path)).split(path64.sep).join("/") });
21784
+ stripReadmeRefs({ kind: "file", rel: path66.relative(TODO, path66.resolve(REPO_ROOT, card.path)).split(path66.sep).join("/") });
21670
21785
  }
21671
21786
  return discarded.map((c) => c.id);
21672
21787
  });
@@ -21752,8 +21867,8 @@ var init_memory_file = __esm({
21752
21867
  });
21753
21868
 
21754
21869
  // src/commands/rule.ts
21755
- import fs63 from "node:fs";
21756
- import path65 from "node:path";
21870
+ import fs64 from "node:fs";
21871
+ import path67 from "node:path";
21757
21872
  function cmdRule(askedName, flags) {
21758
21873
  const agent = askedName.trim();
21759
21874
  if (!agentRoster().some((a) => a.name === agent)) {
@@ -21762,7 +21877,7 @@ function cmdRule(askedName, flags) {
21762
21877
  const rule = readRuleText(flags.file, flags.text);
21763
21878
  const res = setAgentRule(agent, rule);
21764
21879
  if (!res.ok) die(res.error);
21765
- const file = rel(path65.join(RULES, `${agent}.md`));
21880
+ const file = rel(path67.join(RULES, `${agent}.md`));
21766
21881
  say(rule ? `wrote the \`${agent}\` rule (${file})` : `cleared the \`${agent}\` rule`);
21767
21882
  return { agent, file, cleared: !rule };
21768
21883
  }
@@ -21770,7 +21885,7 @@ function readRuleText(file, text5) {
21770
21885
  if (file !== void 0 && text5 !== void 0) die("pass --file or --text, not both");
21771
21886
  if (file !== void 0) {
21772
21887
  try {
21773
- return fs63.readFileSync(file, "utf8").trim();
21888
+ return fs64.readFileSync(file, "utf8").trim();
21774
21889
  } catch {
21775
21890
  die(`can't read ${file} \u2014 write the rule to a file, then pass its path`);
21776
21891
  }
@@ -21897,22 +22012,22 @@ var init_storyboard = __esm({
21897
22012
  });
21898
22013
 
21899
22014
  // src/lib/spec-contract.ts
21900
- import fs64 from "node:fs";
21901
- import path66 from "node:path";
22015
+ import fs65 from "node:fs";
22016
+ import path68 from "node:path";
21902
22017
  function snapshotSpecs() {
21903
22018
  const out = /* @__PURE__ */ new Map();
21904
- if (!fs64.existsSync(TODO)) return out;
22019
+ if (!fs65.existsSync(TODO)) return out;
21905
22020
  for (const file of walkMd(TODO)) {
21906
- if (isLegacyRecurring(path66.relative(TODO, file))) continue;
21907
- const id = idPrefix(path66.basename(file) === "root.md" ? path66.basename(path66.dirname(file)) : path66.basename(file));
21908
- if (id !== null) out.set(file, { id, text: fs64.readFileSync(file, "utf8") });
22021
+ if (isLegacyRecurring(path68.relative(TODO, file))) continue;
22022
+ const id = idPrefix(path68.basename(file) === "root.md" ? path68.basename(path68.dirname(file)) : path68.basename(file));
22023
+ if (id !== null) out.set(file, { id, text: fs65.readFileSync(file, "utf8") });
21909
22024
  }
21910
22025
  return out;
21911
22026
  }
21912
22027
  function enclosingGroups(file) {
21913
22028
  const ids = [];
21914
22029
  for (let root = enclosingGroupRoot(file); root; root = enclosingGroupRoot(root)) {
21915
- const id = idPrefix(path66.basename(path66.dirname(root)));
22030
+ const id = idPrefix(path68.basename(path68.dirname(root)));
21916
22031
  if (id !== null) ids.push(id);
21917
22032
  }
21918
22033
  return ids;
@@ -22081,9 +22196,9 @@ function validateSpec(file, text5, id) {
22081
22196
  }
22082
22197
  function inside(dir, name) {
22083
22198
  try {
22084
- const root = fs64.realpathSync(dir);
22085
- const real2 = fs64.realpathSync(path66.join(dir, name));
22086
- return real2.startsWith(root + path66.sep) && fs64.statSync(real2).isFile() ? real2 : null;
22199
+ const root = fs65.realpathSync(dir);
22200
+ const real2 = fs65.realpathSync(path68.join(dir, name));
22201
+ return real2.startsWith(root + path68.sep) && fs65.statSync(real2).isFile() ? real2 : null;
22087
22202
  } catch {
22088
22203
  return null;
22089
22204
  }
@@ -22101,7 +22216,7 @@ function variantsProblem(raw, src, id) {
22101
22216
  if (files2.length < 2 || !files2.every((f) => typeof f === "string" && f)) return `variants needs at least two labels, each naming a file. ${shape}`;
22102
22217
  if (!files2.includes(src)) return `src="${src}" is not one of the variants. Set src to the version shown first.`;
22103
22218
  if (id === void 0) return null;
22104
- const dir = path66.join(ASSETS, String(id));
22219
+ const dir = path68.join(ASSETS, String(id));
22105
22220
  for (const f of files2) {
22106
22221
  const parts = f.split("/");
22107
22222
  if (parts.length !== 3 || parts[0] !== ".assets" || parts[1] !== String(id) || !inside(dir, parts[2])) {
@@ -22111,7 +22226,7 @@ function variantsProblem(raw, src, id) {
22111
22226
  return null;
22112
22227
  }
22113
22228
  function compareProblem(attrs, id) {
22114
- const dir = path66.join(ASSETS, String(id));
22229
+ const dir = path68.join(ASSETS, String(id));
22115
22230
  const src = (message) => ({ rule: "compare-src", message });
22116
22231
  const shots = (message) => ({ rule: "compare-shots", message });
22117
22232
  for (const side of ["a", "b"]) {
@@ -22131,7 +22246,7 @@ function compareProblem(attrs, id) {
22131
22246
  const file = inside(dir, named2.name);
22132
22247
  if (!file) return { message: `Compare shots ${at} names no file in this card's asset folder. Write the JSON there or fix the path.` };
22133
22248
  try {
22134
- return { data: JSON.parse(fs64.readFileSync(file, "utf8")) };
22249
+ return { data: JSON.parse(fs65.readFileSync(file, "utf8")) };
22135
22250
  } catch {
22136
22251
  return { message: `${at} is not valid JSON.` };
22137
22252
  }
@@ -22151,7 +22266,7 @@ function compareProblem(attrs, id) {
22151
22266
  }
22152
22267
  function validateStoryboards(file, id, text5) {
22153
22268
  const errors = [];
22154
- const dir = path66.join(ASSETS, String(id));
22269
+ const dir = path68.join(ASSETS, String(id));
22155
22270
  for (const marker of storyboardMarkers(text5)) {
22156
22271
  const named2 = assetName(marker.src, id, ["json"]);
22157
22272
  const add = (message) => errors.push({ file: rel(file), line: marker.line, rule: "storyboard-src", message });
@@ -22300,8 +22415,8 @@ var init_mockups = __esm({
22300
22415
  });
22301
22416
 
22302
22417
  // src/commands/spec-write.ts
22303
- import fs65 from "node:fs";
22304
- import path67 from "node:path";
22418
+ import fs66 from "node:fs";
22419
+ import path69 from "node:path";
22305
22420
  function cmdSpecWrite(id, askedName, flags) {
22306
22421
  const agent = findSpecAgent(askedName);
22307
22422
  if (!agent) die(notAnAgent(askedName), { kind: "no-such-spec-agent", specAgent: askedName });
@@ -22309,11 +22424,11 @@ function cmdSpecWrite(id, askedName, flags) {
22309
22424
  const section = readSection(flags.file, flags.text);
22310
22425
  const found2 = locate(id);
22311
22426
  if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
22312
- const file = found2.kind === "group" ? path67.join(found2.target, "root.md") : found2.target;
22313
- const { meta, body } = parseFrontmatter(fs65.readFileSync(file, "utf8"));
22427
+ const file = found2.kind === "group" ? path69.join(found2.target, "root.md") : found2.target;
22428
+ const { meta, body } = parseFrontmatter(fs66.readFileSync(file, "utf8"));
22314
22429
  if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
22315
22430
  const { body: next, replaced } = splice(body, name, section);
22316
- fs65.writeFileSync(file, serializeFrontmatter(meta) + "\n" + next);
22431
+ fs66.writeFileSync(file, serializeFrontmatter(meta) + "\n" + next);
22317
22432
  say(`${replaced ? "rewrote" : "wrote"} the \`${name}\` section on #${id} (${rel(file)})`);
22318
22433
  return { id, specAgent: name, replaced, file: rel(file) };
22319
22434
  }
@@ -22322,7 +22437,7 @@ function readSection(file, text5) {
22322
22437
  let raw;
22323
22438
  if (file !== void 0) {
22324
22439
  try {
22325
- raw = fs65.readFileSync(file, "utf8");
22440
+ raw = fs66.readFileSync(file, "utf8");
22326
22441
  } catch {
22327
22442
  die(`can't read ${file} \u2014 write your section to a file, then pass its path`);
22328
22443
  }
@@ -22516,7 +22631,7 @@ function localBoard() {
22516
22631
  const no = checkWrite({ board: true }, env2, boardRevision());
22517
22632
  if (no) return no;
22518
22633
  const res = await resumeDelivery(deliveryId);
22519
- if (!res.ok) return opRefused(new Error(res.error || "the delivery could not be carried on"));
22634
+ if (!res.ok) return { ...opRefused(new Error(res.error || "the delivery could not be carried on")), reason: res.reason, args: res.args };
22520
22635
  return opOk(boardRevision(), { deliveryId: res.deliveryId, landed: res.landed, carryOn: res.carryOn });
22521
22636
  },
22522
22637
  async discardDelivery(deliveryId, env2) {
@@ -22788,11 +22903,11 @@ var init_shared = __esm({
22788
22903
  });
22789
22904
 
22790
22905
  // src/commands/goal.ts
22791
- import fs66 from "node:fs";
22906
+ import fs67 from "node:fs";
22792
22907
  function load() {
22793
22908
  const file = goalsFile();
22794
22909
  if (!file) die("Goals exist only inside a WildCrane goal discussion.");
22795
- const held4 = JSON.parse(fs66.readFileSync(file, "utf8"));
22910
+ const held4 = JSON.parse(fs67.readFileSync(file, "utf8"));
22796
22911
  if (held4.goals !== void 0 && held4.ideas !== void 0 && JSON.stringify(held4.goals) !== JSON.stringify(held4.ideas)) die("goals and ideas do not match.");
22797
22912
  const goals = held4.goals ?? held4.ideas;
22798
22913
  if (!Array.isArray(goals)) die("The goals array is missing or invalid.");
@@ -22817,7 +22932,7 @@ function splitBody2(text5) {
22817
22932
  }
22818
22933
  function readBody(bodyFile) {
22819
22934
  if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
22820
- const text5 = fs66.readFileSync(bodyFile, "utf8");
22935
+ const text5 = fs67.readFileSync(bodyFile, "utf8");
22821
22936
  if (!text5.trim()) die("The goal must not be empty.");
22822
22937
  return splitBody2(text5);
22823
22938
  }
@@ -22829,7 +22944,7 @@ function named(held4, id) {
22829
22944
  function cmdGoal(args, opts) {
22830
22945
  const sub = args[0] ?? "";
22831
22946
  const { file, held: held4 } = load();
22832
- const write2 = () => fs66.writeFileSync(file, `${JSON.stringify({ workflows: held4.workflows, ideas: held4.goals }, null, 2)}
22947
+ const write2 = () => fs67.writeFileSync(file, `${JSON.stringify({ workflows: held4.workflows, ideas: held4.goals }, null, 2)}
22833
22948
  `);
22834
22949
  if (sub === "new") {
22835
22950
  const title = opts.title?.trim();
@@ -22899,8 +23014,8 @@ __export(board_exports, {
22899
23014
  buildBoardProgram: () => buildBoardProgram
22900
23015
  });
22901
23016
  import crypto4 from "node:crypto";
22902
- import fs67 from "node:fs";
22903
- import path68 from "node:path";
23017
+ import fs68 from "node:fs";
23018
+ import path70 from "node:path";
22904
23019
  async function dispatch(move2, cmd, args, opts, cli) {
22905
23020
  const ctx = ctxOf(cmd, cli.program);
22906
23021
  const data = await runAction(ctx, {}, async () => {
@@ -22939,7 +23054,7 @@ async function cloudCard(task, opts) {
22939
23054
  let request;
22940
23055
  if (typeof opts.bodyFile === "string") {
22941
23056
  try {
22942
- request = fs67.readFileSync(opts.bodyFile, "utf8");
23057
+ request = fs68.readFileSync(opts.bodyFile, "utf8");
22943
23058
  } catch {
22944
23059
  }
22945
23060
  }
@@ -22969,7 +23084,7 @@ async function cloudCard(task, opts) {
22969
23084
  const file = creationReceipt(`${checked.value}:${requestId}`, slot);
22970
23085
  const journal = readCreation(file, said3);
22971
23086
  if (!journal.made) {
22972
- const key = `akb-${path68.basename(file, ".json").slice(0, 40)}`;
23087
+ const key = `akb-${path70.basename(file, ".json").slice(0, 40)}`;
22973
23088
  const made = await createProjectTask(checked.value, journal.said, key);
22974
23089
  if (!made.ok) throw new BoardError(creationError(`Cloud did not make the task: ${made.error}`, triage), { kind: "refused" });
22975
23090
  journal.made = made.value;
@@ -23114,16 +23229,16 @@ var init_board2 = __esm({
23114
23229
  });
23115
23230
 
23116
23231
  // src/lib/board-cli.ts
23117
- import fs68 from "node:fs";
23118
- import path69 from "node:path";
23232
+ import fs69 from "node:fs";
23233
+ import path71 from "node:path";
23119
23234
  function useBoard(found2, dirNamed) {
23120
- if (!found2.named && found2.board === path69.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
23235
+ if (!found2.named && found2.board === path71.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
23121
23236
  else setBoardDir(found2.board, found2.root);
23122
23237
  useProjectState();
23123
23238
  }
23124
23239
  function whole(found2, move2) {
23125
23240
  if (move2 === MAKES_A_BOARD) return found2;
23126
- if (!fs68.existsSync(path69.join(found2.board, "todo"))) {
23241
+ if (!fs69.existsSync(path71.join(found2.board, "todo"))) {
23127
23242
  die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
23128
23243
  kind: "board-incomplete",
23129
23244
  dir: found2.root
@@ -23132,13 +23247,13 @@ function whole(found2, move2) {
23132
23247
  return found2;
23133
23248
  }
23134
23249
  function findBoardUpward(from, move2) {
23135
- let dir = path69.resolve(from);
23250
+ let dir = path71.resolve(from);
23136
23251
  for (; ; ) {
23137
- if (hasBoard(dir)) return { root: dir, board: path69.join(dir, "docs", "kanban") };
23252
+ if (hasBoard(dir)) return { root: dir, board: path71.join(dir, "docs", "kanban") };
23138
23253
  if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
23139
- const kept2 = path69.join(dir, ".akb", "kanban");
23140
- if (move2 !== MAKES_A_BOARD && fs68.existsSync(path69.join(kept2, "todo"))) return { root: dir, board: kept2 };
23141
- const up = path69.dirname(dir);
23254
+ const kept2 = path71.join(dir, ".akb", "kanban");
23255
+ if (move2 !== MAKES_A_BOARD && fs69.existsSync(path71.join(kept2, "todo"))) return { root: dir, board: kept2 };
23256
+ const up = path71.dirname(dir);
23142
23257
  if (up === dir) return null;
23143
23258
  dir = up;
23144
23259
  }
@@ -23146,11 +23261,11 @@ function findBoardUpward(from, move2) {
23146
23261
  function resolveBoard(move2, { board: board2, dir, cwd, installHint }) {
23147
23262
  const named2 = board2 ?? boardFromEnv();
23148
23263
  if (named2) {
23149
- const folder = path69.resolve(cwd, named2);
23150
- if (!fs68.existsSync(folder) && move2 !== MAKES_A_BOARD) {
23264
+ const folder = path71.resolve(cwd, named2);
23265
+ if (!fs69.existsSync(folder) && move2 !== MAKES_A_BOARD) {
23151
23266
  die(`no such folder: ${folder}`, { kind: "no-such-folder", dir: folder });
23152
23267
  }
23153
- if (fs68.existsSync(folder) && !isBoardDir(folder) && move2 !== MAKES_A_BOARD) {
23268
+ if (fs69.existsSync(folder) && !isBoardDir(folder) && move2 !== MAKES_A_BOARD) {
23154
23269
  die(`${folder} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
23155
23270
  kind: "no-board",
23156
23271
  dir: folder
@@ -23159,24 +23274,24 @@ function resolveBoard(move2, { board: board2, dir, cwd, installHint }) {
23159
23274
  return { root: projectRootOf(folder), board: folder, named: true };
23160
23275
  }
23161
23276
  if (dir !== null) {
23162
- const root = path69.resolve(dir);
23163
- if (!fs68.existsSync(root)) die(`no such folder: ${root}`, { kind: "no-such-folder", dir: root });
23164
- const kept2 = path69.join(root, ".akb", "kanban");
23165
- if (!hasBoard(root) && move2 !== MAKES_A_BOARD && fs68.existsSync(path69.join(kept2, "todo"))) return whole({ root, board: kept2 }, move2);
23277
+ const root = path71.resolve(dir);
23278
+ if (!fs69.existsSync(root)) die(`no such folder: ${root}`, { kind: "no-such-folder", dir: root });
23279
+ const kept2 = path71.join(root, ".akb", "kanban");
23280
+ if (!hasBoard(root) && move2 !== MAKES_A_BOARD && fs69.existsSync(path71.join(kept2, "todo"))) return whole({ root, board: kept2 }, move2);
23166
23281
  if (!hasBoard(root) && move2 !== MAKES_A_BOARD) {
23167
23282
  die(`no board in ${root} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
23168
23283
  kind: "no-board",
23169
23284
  dir: root
23170
23285
  });
23171
23286
  }
23172
- return whole({ root, board: path69.join(root, "docs", "kanban") }, move2);
23287
+ return whole({ root, board: path71.join(root, "docs", "kanban") }, move2);
23173
23288
  }
23174
23289
  const found2 = findBoardUpward(cwd, move2);
23175
23290
  if (found2) return whole(found2, move2);
23176
- if (move2 === MAKES_A_BOARD) return { root: path69.resolve(cwd), board: path69.join(path69.resolve(cwd), "docs", "kanban") };
23291
+ if (move2 === MAKES_A_BOARD) return { root: path71.resolve(cwd), board: path71.join(path71.resolve(cwd), "docs", "kanban") };
23177
23292
  die(
23178
- `no board here. Looked in ${path69.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
23179
- { kind: "no-board", dir: path69.resolve(cwd) }
23293
+ `no board here. Looked in ${path71.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
23294
+ { kind: "no-board", dir: path71.resolve(cwd) }
23180
23295
  );
23181
23296
  }
23182
23297
  function editDistance(a, b) {
@@ -23258,8 +23373,8 @@ var init_board_cli = __esm({
23258
23373
  init_io();
23259
23374
  init_pointer();
23260
23375
  MAKES_A_BOARD = "init";
23261
- hasBoard = (dir) => fs68.existsSync(path69.join(dir, "docs", "kanban"));
23262
- isBoardDir = (dir) => fs68.existsSync(path69.join(dir, "todo")) && fs68.existsSync(path69.join(dir, "config.md"));
23376
+ hasBoard = (dir) => fs69.existsSync(path71.join(dir, "docs", "kanban"));
23377
+ isBoardDir = (dir) => fs69.existsSync(path71.join(dir, "todo")) && fs69.existsSync(path71.join(dir, "config.md"));
23263
23378
  boardFromEnv = () => {
23264
23379
  const named2 = process.env.AI4KANBAN_BOARD?.trim();
23265
23380
  return named2 ? named2 : null;
@@ -23526,8 +23641,8 @@ var init_guide = __esm({
23526
23641
  });
23527
23642
 
23528
23643
  // src/lib/agent/approve.ts
23529
- import fs74 from "node:fs";
23530
- import path75 from "node:path";
23644
+ import fs75 from "node:fs";
23645
+ import path77 from "node:path";
23531
23646
  function approvalRequest(req) {
23532
23647
  const id = req.id;
23533
23648
  const card = id === void 0 ? null : findCard(id);
@@ -23545,12 +23660,12 @@ function advancePhase(id) {
23545
23660
  const card = findCard(id);
23546
23661
  const found2 = locate(id);
23547
23662
  if (!card || !found2 || !awaitingApproval(card)) return { error: `#${id} is no longer waiting on approval.` };
23548
- const file = found2.kind === "group" ? path75.join(found2.target, "root.md") : found2.target;
23549
- const { meta, body } = parseFrontmatter(fs74.readFileSync(file, "utf8"));
23663
+ const file = found2.kind === "group" ? path77.join(found2.target, "root.md") : found2.target;
23664
+ const { meta, body } = parseFrontmatter(fs75.readFileSync(file, "utf8"));
23550
23665
  if (!meta) return { error: `#${id} has no frontmatter` };
23551
23666
  meta.phase = card.stage + 1;
23552
23667
  meta.status = "todo";
23553
- fs74.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
23668
+ fs75.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
23554
23669
  return null;
23555
23670
  }
23556
23671
  var init_approve = __esm({
@@ -23648,8 +23763,8 @@ function open2(req, sessionId) {
23648
23763
  markSpawned(run2.sessionId, pid);
23649
23764
  return { run: run2, spawned: pid !== void 0 };
23650
23765
  }
23651
- async function startResume(id) {
23652
- const opened = await openResume(id);
23766
+ async function startResume(id, requireSession = false) {
23767
+ const opened = await openResume(id, requireSession);
23653
23768
  if ("error" in opened) return opened;
23654
23769
  const pid = spawnWatcher(opened.run.sessionId);
23655
23770
  markSpawned(opened.run.sessionId, pid);
@@ -23674,16 +23789,16 @@ var init_start = __esm({
23674
23789
  });
23675
23790
 
23676
23791
  // src/lib/agent/task-chats.ts
23677
- import fs75 from "node:fs";
23678
- import path76 from "node:path";
23792
+ import fs76 from "node:fs";
23793
+ import path78 from "node:path";
23679
23794
  function taskChatFile(task, home3) {
23680
23795
  if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
23681
- return path76.join(taskChatsDir(home3), `${task}.jsonl`);
23796
+ return path78.join(taskChatsDir(home3), `${task}.jsonl`);
23682
23797
  }
23683
23798
  function readTaskChat(task, home3) {
23684
23799
  let text5;
23685
23800
  try {
23686
- text5 = fs75.readFileSync(taskChatFile(task, home3), "utf8");
23801
+ text5 = fs76.readFileSync(taskChatFile(task, home3), "utf8");
23687
23802
  } catch {
23688
23803
  return [];
23689
23804
  }
@@ -23704,13 +23819,13 @@ var init_task_chats = __esm({
23704
23819
  "use strict";
23705
23820
  init_home();
23706
23821
  TASK = /^[\w-]{1,100}$/;
23707
- taskChatsDir = (home3 = machineHome()) => path76.join(home3, "chats");
23822
+ taskChatsDir = (home3 = machineHome()) => path78.join(home3, "chats");
23708
23823
  }
23709
23824
  });
23710
23825
 
23711
23826
  // src/lib/agent/memory-review.ts
23712
- import fs76 from "node:fs";
23713
- import path77 from "node:path";
23827
+ import fs77 from "node:fs";
23828
+ import path79 from "node:path";
23714
23829
  function taskChatsToReview(tasks) {
23715
23830
  const out = [];
23716
23831
  for (const ref of [...new Set(tasks)]) {
@@ -23732,8 +23847,8 @@ function readArchived2(id) {
23732
23847
  const found2 = Number.isInteger(id) && id > 0 ? locateArchived(id) : null;
23733
23848
  if (!found2) return null;
23734
23849
  try {
23735
- const file = found2.kind === "group" ? path77.join(found2.target, "root.md") : found2.target;
23736
- const { meta, body } = parseFrontmatter(fs76.readFileSync(file, "utf8"));
23850
+ const file = found2.kind === "group" ? path79.join(found2.target, "root.md") : found2.target;
23851
+ const { meta, body } = parseFrontmatter(fs77.readFileSync(file, "utf8"));
23737
23852
  if (!meta) return null;
23738
23853
  return { id, title: meta.title, modules: meta.modules ?? [], rejected: meta.rejected, body };
23739
23854
  } catch {
@@ -23802,17 +23917,17 @@ var init_memory_review = __esm({
23802
23917
  });
23803
23918
 
23804
23919
  // src/lib/agent/dismissal-review.ts
23805
- import fs77 from "node:fs";
23806
- import path78 from "node:path";
23920
+ import fs78 from "node:fs";
23921
+ import path80 from "node:path";
23807
23922
  function rejectionsToReview() {
23808
- const dir = path78.join(ARCHIVE, REJECTIONS_TO_REVIEW);
23809
- if (!fs77.existsSync(dir)) return [];
23923
+ const dir = path80.join(ARCHIVE, REJECTIONS_TO_REVIEW);
23924
+ if (!fs78.existsSync(dir)) return [];
23810
23925
  const found2 = [];
23811
23926
  for (const file of walkMd(dir)) {
23812
23927
  const id = archivedId(file);
23813
23928
  if (id === null) continue;
23814
23929
  try {
23815
- const { meta } = parseFrontmatter(fs77.readFileSync(file, "utf8"));
23930
+ const { meta } = parseFrontmatter(fs78.readFileSync(file, "utf8"));
23816
23931
  if (!meta?.rejected || meta.rejected_by !== "user" || !meta.rejected_reason.trim()) continue;
23817
23932
  found2.push({ id, title: meta.title, file: rel(file), reason: meta.rejected_reason.trim(), rejectedAt: meta.rejected_at });
23818
23933
  } catch {
@@ -23842,7 +23957,7 @@ function citedSources(text5) {
23842
23957
  function withdrawnSources() {
23843
23958
  const cited = [...new Set(plannerCopies("rejected.md").flatMap((file) => {
23844
23959
  try {
23845
- return citedSources(fs77.readFileSync(file, "utf8"));
23960
+ return citedSources(fs78.readFileSync(file, "utf8"));
23846
23961
  } catch {
23847
23962
  return [];
23848
23963
  }
@@ -23867,8 +23982,8 @@ var init_dismissal_review = __esm({
23867
23982
  });
23868
23983
 
23869
23984
  // src/lib/agent/flow.ts
23870
- import fs78 from "node:fs";
23871
- import path79 from "node:path";
23985
+ import fs79 from "node:fs";
23986
+ import path81 from "node:path";
23872
23987
  function readCard2(id, home3 = "board") {
23873
23988
  const found2 = home3 === "archive" ? locateArchived(id) : locate(id);
23874
23989
  if (!found2) {
@@ -23877,10 +23992,10 @@ function readCard2(id, home3 = "board") {
23877
23992
  { kind: "card-not-found", id }
23878
23993
  );
23879
23994
  }
23880
- const file = found2.kind === "group" ? path79.join(found2.target, "root.md") : found2.target;
23995
+ const file = found2.kind === "group" ? path81.join(found2.target, "root.md") : found2.target;
23881
23996
  let text5;
23882
23997
  try {
23883
- text5 = fs78.readFileSync(file, "utf8");
23998
+ text5 = fs79.readFileSync(file, "utf8");
23884
23999
  } catch {
23885
24000
  die(`#${id} is on the board but ${rel(file)} can't be read.`, { kind: "card-unreadable", id });
23886
24001
  }
@@ -24004,7 +24119,7 @@ function workspaceField(delivery) {
24004
24119
  if (!delivery?.worktree) return [];
24005
24120
  return field("workspace", [
24006
24121
  `write code in ${delivery.worktree} \u2014 this delivery's own worktree, on branch ${delivery.branch}.`,
24007
- path79.resolve(process.cwd()).startsWith(worktreeDir(delivery.worktree)) ? `it is your working folder already; the board's own files are NOT in it and never go on that branch.` : `cd into it first \u2014 you are in the project checkout, and code written here is not part of this build. The board's own files are NOT in it and never go on that branch.`,
24122
+ path81.resolve(process.cwd()).startsWith(worktreeDir(delivery.worktree)) ? `it is your working folder already; the board's own files are NOT in it and never go on that branch.` : `cd into it first \u2014 you are in the project checkout, and code written here is not part of this build. The board's own files are NOT in it and never go on that branch.`,
24008
24123
  `every board command names the project's own copy: \`${boardCommandFor()} <command>\`.`,
24009
24124
  `${rel(REPO_ROOT)} is the project \u2014 the card, the memory files and the docs are changed there, not here.`
24010
24125
  ]);
@@ -24748,7 +24863,7 @@ __export(watch_exports, {
24748
24863
  watchRun: () => watchRun
24749
24864
  });
24750
24865
  import { spawn as spawn4 } from "node:child_process";
24751
- import fs79 from "node:fs";
24866
+ import fs80 from "node:fs";
24752
24867
  async function watchRun(sessionId, resume = startResume) {
24753
24868
  const spec = readSpec(sessionId);
24754
24869
  const run2 = peekRun(sessionId);
@@ -24784,11 +24899,11 @@ async function watchRun(sessionId, resume = startResume) {
24784
24899
  const record = claimed ?? run2;
24785
24900
  const sub = record.action === "sub";
24786
24901
  if (claim) await setCardStatus(claim.cardId, claim.status);
24787
- fs79.mkdirSync(SESSIONS_DIR, { recursive: true });
24788
- const logFile = fs79.createWriteStream(record.logPath, { flags: "a" });
24902
+ fs80.mkdirSync(SESSIONS_DIR, { recursive: true });
24903
+ const logFile = fs80.createWriteStream(record.logPath, { flags: "a" });
24789
24904
  logFile.on("error", () => {
24790
24905
  });
24791
- const eventsFile = fs79.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
24906
+ const eventsFile = fs80.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
24792
24907
  eventsFile.on("error", () => {
24793
24908
  });
24794
24909
  const event2 = (e) => eventsFile.write(`${JSON.stringify(e)}
@@ -25377,7 +25492,7 @@ var init_watch = __esm({
25377
25492
  });
25378
25493
 
25379
25494
  // src/kanban.ts
25380
- import fs85 from "node:fs";
25495
+ import fs86 from "node:fs";
25381
25496
  import { fileURLToPath as fileURLToPath3 } from "node:url";
25382
25497
 
25383
25498
  // src/lib/cli/agent.ts
@@ -25866,8 +25981,8 @@ async function testAgent(args) {
25866
25981
  }
25867
25982
 
25868
25983
  // src/commands/cloud.ts
25869
- import fs70 from "node:fs";
25870
- import path71 from "node:path";
25984
+ import fs71 from "node:fs";
25985
+ import path73 from "node:path";
25871
25986
 
25872
25987
  // src/lib/cloud/avatar.ts
25873
25988
  init_session();
@@ -25915,13 +26030,13 @@ init_config();
25915
26030
  init_home();
25916
26031
  init_config();
25917
26032
  init_session();
25918
- import fs69 from "node:fs";
25919
- import path70 from "node:path";
26033
+ import fs70 from "node:fs";
26034
+ import path72 from "node:path";
25920
26035
  var FRESH_MS = 10 * 6e4;
25921
26036
  var GRACE_MS = 7 * 24 * 60 * 6e4;
25922
- var heldFile = () => path70.join(machineHome(), "pro.json");
26037
+ var heldFile = () => path72.join(machineHome(), "pro.json");
25923
26038
  function forgetPro() {
25924
- fs69.rmSync(heldFile(), { force: true });
26039
+ fs70.rmSync(heldFile(), { force: true });
25925
26040
  }
25926
26041
 
25927
26042
  // src/lib/cloud/account.ts
@@ -26098,10 +26213,10 @@ async function cloudImage(opts, program2) {
26098
26213
  const prompt = opts.prompt.trim();
26099
26214
  if (!prompt) usage("Missing the prompt.", line);
26100
26215
  const references = opts.refs.map((file) => {
26101
- const type = REF_TYPES[path71.extname(file).toLowerCase()];
26216
+ const type = REF_TYPES[path73.extname(file).toLowerCase()];
26102
26217
  if (!type) usage(`--ref ${file}: use a PNG, JPEG or WebP file.`, line);
26103
26218
  try {
26104
- return `data:${type};base64,${fs70.readFileSync(file).toString("base64")}`;
26219
+ return `data:${type};base64,${fs71.readFileSync(file).toString("base64")}`;
26105
26220
  } catch (e) {
26106
26221
  usage(`--ref ${file}: ${e instanceof Error ? e.message : String(e)}`, line);
26107
26222
  }
@@ -26207,31 +26322,31 @@ async function generate(g) {
26207
26322
  refuse(g.failed, g.fallback);
26208
26323
  }
26209
26324
  const out = g.outFor?.(res, g.out) ?? g.out;
26210
- fs70.mkdirSync(path71.dirname(path71.resolve(out)), { recursive: true });
26211
- fs70.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
26325
+ fs71.mkdirSync(path73.dirname(path73.resolve(out)), { recursive: true });
26326
+ fs71.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
26212
26327
  say(`${out} (${g.label(res)})`);
26213
26328
  return { out };
26214
26329
  }
26215
26330
 
26216
26331
  // src/commands/cloud-import.ts
26217
26332
  import crypto5 from "node:crypto";
26218
- import fs72 from "node:fs";
26219
- import path73 from "node:path";
26333
+ import fs73 from "node:fs";
26334
+ import path75 from "node:path";
26220
26335
 
26221
26336
  // ../cloud/src/board-files.ts
26222
26337
  var ROOTS = ["todo/", ".archive/", "memory/", "workflows/", "triage/", "assets/", "rules/"];
26223
26338
  var SETTINGS = ["modules.md", "config.md"];
26224
- var isSettingsPath = (path85) => SETTINGS.includes(path85) || /^rules\/(?:workflows\/)?[^/]+\.md$/.test(path85);
26339
+ var isSettingsPath = (path87) => SETTINGS.includes(path87) || /^rules\/(?:workflows\/)?[^/]+\.md$/.test(path87);
26225
26340
  var BOARD_FILE_LIMIT = 256 * 1024;
26226
- function isBoardPath(path85) {
26227
- if (!path85 || path85.length > 500 || path85.startsWith("/") || path85.includes("\\") || path85.includes("\0")) return false;
26228
- if (path85.split("/").some((part) => !part || part === "." || part === "..")) return false;
26229
- if (path85 === "todo/README.md" || path85.split("/").includes(".sync")) return false;
26230
- if (path85.startsWith("workflows/")) return true;
26231
- if (SETTINGS.includes(path85)) return true;
26232
- if (path85.startsWith("rules/")) return isSettingsPath(path85);
26233
- if (path85.startsWith("assets/")) return path85.endsWith(".json");
26234
- return ROOTS.some((root) => path85.startsWith(root)) && path85.endsWith(".md");
26341
+ function isBoardPath(path87) {
26342
+ if (!path87 || path87.length > 500 || path87.startsWith("/") || path87.includes("\\") || path87.includes("\0")) return false;
26343
+ if (path87.split("/").some((part) => !part || part === "." || part === "..")) return false;
26344
+ if (path87 === "todo/README.md" || path87.split("/").includes(".sync")) return false;
26345
+ if (path87.startsWith("workflows/")) return true;
26346
+ if (SETTINGS.includes(path87)) return true;
26347
+ if (path87.startsWith("rules/")) return isSettingsPath(path87);
26348
+ if (path87.startsWith("assets/")) return path87.endsWith(".json");
26349
+ return ROOTS.some((root) => path87.startsWith(root)) && path87.endsWith(".md");
26235
26350
  }
26236
26351
  var workflowFolder = (id) => id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
26237
26352
 
@@ -26335,8 +26450,8 @@ init_bundled();
26335
26450
  // src/lib/agents/shared-memory.ts
26336
26451
  init_bundled();
26337
26452
  init_parse();
26338
- import fs71 from "node:fs";
26339
- import path72 from "node:path";
26453
+ import fs72 from "node:fs";
26454
+ import path74 from "node:path";
26340
26455
  function sharedMemory(board2) {
26341
26456
  const declared = /* @__PURE__ */ new Map();
26342
26457
  const take = (folder, text5, builtIn) => {
@@ -26348,16 +26463,16 @@ function sharedMemory(board2) {
26348
26463
  const at = /^([^/]+)\/AGENT\.md$/.exec(key);
26349
26464
  if (at) take(at[1], text5, true);
26350
26465
  }
26351
- const root = path72.join(board2, "agents");
26466
+ const root = path74.join(board2, "agents");
26352
26467
  let folders2 = [];
26353
26468
  try {
26354
- folders2 = fs71.readdirSync(root, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
26469
+ folders2 = fs72.readdirSync(root, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
26355
26470
  } catch {
26356
26471
  }
26357
26472
  for (const folder of folders2.sort()) {
26358
26473
  let text5 = null;
26359
26474
  try {
26360
- text5 = fs71.readFileSync(path72.join(root, folder, "AGENT.md"), "utf8");
26475
+ text5 = fs72.readFileSync(path74.join(root, folder, "AGENT.md"), "utf8");
26361
26476
  } catch {
26362
26477
  }
26363
26478
  take(folder, text5, false);
@@ -26446,24 +26561,24 @@ async function findProject(asked) {
26446
26561
  }
26447
26562
  throw new Refused(`No project of yours has the id or prefix "${asked}".`, "not_found");
26448
26563
  }
26449
- var read = (file) => fs72.readFileSync(file, "utf8");
26564
+ var read = (file) => fs73.readFileSync(file, "utf8");
26450
26565
  var bytes2 = (text5) => Buffer.byteLength(text5, "utf8");
26451
26566
  function files(dir) {
26452
- if (!fs72.existsSync(dir)) return [];
26567
+ if (!fs73.existsSync(dir)) return [];
26453
26568
  const out = [];
26454
- for (const entry of fs72.readdirSync(dir, { withFileTypes: true })) {
26569
+ for (const entry of fs73.readdirSync(dir, { withFileTypes: true })) {
26455
26570
  if (entry.name.startsWith(".")) continue;
26456
- const full = path73.join(dir, entry.name);
26571
+ const full = path75.join(dir, entry.name);
26457
26572
  if (entry.isDirectory()) out.push(...files(full));
26458
26573
  else if (entry.isFile()) out.push(full);
26459
26574
  }
26460
26575
  return out;
26461
26576
  }
26462
- var posix2 = (p) => p.split(path73.sep).join("/");
26577
+ var posix2 = (p) => p.split(path75.sep).join("/");
26463
26578
  function openCards() {
26464
26579
  const out = [];
26465
26580
  for (const file of walkMd(TODO)) {
26466
- const rel2 = posix2(path73.relative(TODO, file));
26581
+ const rel2 = posix2(path75.relative(TODO, file));
26467
26582
  if (rel2 === "README.md") continue;
26468
26583
  const parts = rel2.split("/");
26469
26584
  const text5 = read(file);
@@ -26497,14 +26612,14 @@ function bodyProblems(text5) {
26497
26612
  return out;
26498
26613
  }
26499
26614
  function packWorkflow(flow) {
26500
- const own = path73.join(WORKFLOWS, flow.id);
26615
+ const own = path75.join(WORKFLOWS, flow.id);
26501
26616
  const out = {};
26502
- for (const file of files(own)) out[posix2(path73.relative(own, file))] = read(file);
26617
+ for (const file of files(own)) out[posix2(path75.relative(own, file))] = read(file);
26503
26618
  const named2 = [...flow.previews, ...flow.land, ...flow.scheduled].map((h) => h.agent).filter((a) => !LAND_ROLES.includes(a));
26504
26619
  for (const agent of new Set(named2)) {
26505
- const dir = path73.join(AGENTS, agent);
26506
- if (fs72.existsSync(path73.join(dir, "AGENT.md"))) {
26507
- for (const file of files(dir)) out[`agents/${agent}/${posix2(path73.relative(dir, file))}`] = read(file);
26620
+ const dir = path75.join(AGENTS, agent);
26621
+ if (fs73.existsSync(path75.join(dir, "AGENT.md"))) {
26622
+ for (const file of files(dir)) out[`agents/${agent}/${posix2(path75.relative(dir, file))}`] = read(file);
26508
26623
  continue;
26509
26624
  }
26510
26625
  for (const [key, text5] of Object.entries(BUNDLED_AGENT_FILES)) {
@@ -26556,8 +26671,8 @@ function draftsOf(text5) {
26556
26671
  const at = /^\.(assets|mockups)\/(.+)$/.exec(name);
26557
26672
  if (!at) continue;
26558
26673
  const base = at[1] === "assets" ? ASSETS : MOCKUPS;
26559
- const file = path73.resolve(base, at[2]);
26560
- if (file.startsWith(base + path73.sep) && fs72.statSync(file, { throwIfNoEntry: false })?.isFile()) out.set(name, file);
26674
+ const file = path75.resolve(base, at[2]);
26675
+ if (file.startsWith(base + path75.sep) && fs73.statSync(file, { throwIfNoEntry: false })?.isFile()) out.set(name, file);
26561
26676
  }
26562
26677
  return [...out].map(([name, file]) => ({ name, file }));
26563
26678
  }
@@ -26591,9 +26706,9 @@ async function uploadDrafts(task, drafts) {
26591
26706
  const assets = {};
26592
26707
  for (const { name, file } of drafts) {
26593
26708
  if (!card.body.includes(name)) continue;
26594
- const ext = path73.extname(file).toLowerCase();
26709
+ const ext = path75.extname(file).toLowerCase();
26595
26710
  const type = TYPES[ext] ?? "application/octet-stream";
26596
- const data = fs72.readFileSync(file);
26711
+ const data = fs73.readFileSync(file);
26597
26712
  const artifact = await api("POST", `/v1/tasks/${task}/artifacts`, { type: kindOf(ext), name: name.slice(0, 200) });
26598
26713
  const upload = await api("POST", `/v1/artifacts/${artifact.id}/uploads`, { content_type: type, size: Math.max(data.length, 1) });
26599
26714
  await api("PUT", `/v1/uploads/${upload.id}`, void 0, { bytes: data, type });
@@ -26636,10 +26751,10 @@ usage: ${program2} cloud import --project <id or prefix> [--dry-run]`, { kind: "
26636
26751
  async function run(asked, dryRun) {
26637
26752
  const project = await findProject(asked);
26638
26753
  const cloudFlows = await all(`/v1/workflows?workspace=${encodeURIComponent(project.workspace)}`);
26639
- const board2 = crypto5.createHash("sha256").update(fs72.realpathSync(KANBAN)).digest("hex").slice(0, 16);
26754
+ const board2 = crypto5.createHash("sha256").update(fs73.realpathSync(KANBAN)).digest("hex").slice(0, 16);
26640
26755
  const cards = openCards();
26641
26756
  const problems = [];
26642
- const where = (file) => posix2(path73.relative(KANBAN, file));
26757
+ const where = (file) => posix2(path75.relative(KANBAN, file));
26643
26758
  const own = workflows().filter((w) => !w.builtIn);
26644
26759
  const packed = /* @__PURE__ */ new Map();
26645
26760
  for (const flow of own) {
@@ -26666,7 +26781,7 @@ async function run(asked, dryRun) {
26666
26781
  const root = `projects/${project.id}/`;
26667
26782
  const boardFiles = [];
26668
26783
  for (const file of [...files(MEMORY), ...files(RULES), CONFIG, MODULES_MD]) {
26669
- if (!fs72.existsSync(file)) continue;
26784
+ if (!fs73.existsSync(file)) continue;
26670
26785
  const rel2 = where(file);
26671
26786
  if (!isBoardPath(rel2)) continue;
26672
26787
  const content = read(file);
@@ -26777,16 +26892,16 @@ async function run(asked, dryRun) {
26777
26892
  }
26778
26893
  function leftLocal(own) {
26779
26894
  const out = [];
26780
- const count4 = (dir) => fs72.existsSync(dir) ? walkMd(dir).length : 0;
26895
+ const count4 = (dir) => fs73.existsSync(dir) ? walkMd(dir).length : 0;
26781
26896
  const archived = count4(ARCHIVE);
26782
26897
  if (archived) out.push(`.archive/ (${archived})`);
26783
26898
  const triage = count4(TRIAGE);
26784
26899
  if (triage) out.push(`triage/ (${triage})`);
26785
- if (fs72.existsSync(DELIVERIES)) out.push("deliveries/");
26786
- if (fs72.existsSync(path73.join(KANBAN, "metrics.csv"))) out.push("metrics.csv");
26900
+ if (fs73.existsSync(DELIVERIES)) out.push("deliveries/");
26901
+ if (fs73.existsSync(path75.join(KANBAN, "metrics.csv"))) out.push("metrics.csv");
26787
26902
  const named2 = new Set(own.flatMap((w) => [...w.previews, ...w.land, ...w.scheduled].map((h) => h.agent)));
26788
- if (fs72.existsSync(AGENTS)) {
26789
- for (const e of fs72.readdirSync(AGENTS, { withFileTypes: true })) {
26903
+ if (fs73.existsSync(AGENTS)) {
26904
+ for (const e of fs73.readdirSync(AGENTS, { withFileTypes: true })) {
26790
26905
  if (e.isDirectory() && !e.name.startsWith(".") && !named2.has(e.name)) out.push(`agents/${e.name}/`);
26791
26906
  }
26792
26907
  }
@@ -26804,8 +26919,8 @@ init_session();
26804
26919
  init_io();
26805
26920
  init_paths();
26806
26921
  import { createHash as createHash4 } from "node:crypto";
26807
- import fs73 from "node:fs";
26808
- import path74 from "node:path";
26922
+ import fs74 from "node:fs";
26923
+ import path76 from "node:path";
26809
26924
  var SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
26810
26925
  var CAPTURED = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
26811
26926
  var MAX_BYTES3 = 50 * 1024 * 1024;
@@ -26904,10 +27019,10 @@ This template has no preview.`);
26904
27019
  const written = [];
26905
27020
  for (const p of previews) {
26906
27021
  const bytes3 = Buffer.from(await (await ask(`/${at}/previews/${route(p.path)}`, {}, WITHOUT)).arrayBuffer());
26907
- const file = path74.basename(p.path);
26908
- const out = path74.join(opts.to, file.startsWith(`${name}-`) ? file : `${name}-${file}`);
26909
- fs73.mkdirSync(opts.to, { recursive: true });
26910
- fs73.writeFileSync(out, bytes3);
27022
+ const file = path76.basename(p.path);
27023
+ const out = path76.join(opts.to, file.startsWith(`${name}-`) ? file : `${name}-${file}`);
27024
+ fs74.mkdirSync(opts.to, { recursive: true });
27025
+ fs74.writeFileSync(out, bytes3);
26911
27026
  written.push(out);
26912
27027
  say(out);
26913
27028
  }
@@ -26920,15 +27035,15 @@ async function templateGet(name, opts, program2) {
26920
27035
  const { template } = await asJson(await ask(`/${at}`, {}, WITHOUT));
26921
27036
  const fetched = [];
26922
27037
  for (const f of template.files) {
26923
- const out = path74.resolve(to, f.path);
26924
- if (!out.startsWith(path74.resolve(to) + path74.sep)) refuse2(T.corrupt, WITHOUT);
27038
+ const out = path76.resolve(to, f.path);
27039
+ if (!out.startsWith(path76.resolve(to) + path76.sep)) refuse2(T.corrupt, WITHOUT);
26925
27040
  const bytes3 = Buffer.from(await (await ask(`/${at}/files/${route(f.path)}`, {}, WITHOUT)).arrayBuffer());
26926
27041
  if (bytes3.byteLength !== f.size || createHash4("sha256").update(bytes3).digest("hex") !== f.sha256) {
26927
27042
  refuse2(T.corrupt, WITHOUT);
26928
27043
  }
26929
27044
  fetched.push({ out, bytes: bytes3 });
26930
27045
  }
26931
- const taken = fetched.filter((f) => fs73.existsSync(f.out)).map((f) => path74.relative(to, f.out));
27046
+ const taken = fetched.filter((f) => fs74.existsSync(f.out)).map((f) => path76.relative(to, f.out));
26932
27047
  if (taken.length > 0) {
26933
27048
  refuse2({
26934
27049
  zh: `\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u6709\u540C\u540D\u6587\u4EF6\uFF1A${taken.join("\u3001")}\u3002\u8BF7\u6362\u4E00\u4E2A\u6587\u4EF6\u5939\uFF0C\u6216\u5148\u79FB\u8D70\u8FD9\u4E9B\u6587\u4EF6\u3002`,
@@ -26936,8 +27051,8 @@ async function templateGet(name, opts, program2) {
26936
27051
  });
26937
27052
  }
26938
27053
  for (const f of fetched) {
26939
- fs73.mkdirSync(path74.dirname(f.out), { recursive: true });
26940
- fs73.writeFileSync(f.out, f.bytes);
27054
+ fs74.mkdirSync(path76.dirname(f.out), { recursive: true });
27055
+ fs74.writeFileSync(f.out, f.bytes);
26941
27056
  }
26942
27057
  say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
26943
27058
  Fetched ${name}: ${fetched.length} files into ${to}`);
@@ -26955,25 +27070,25 @@ async function templateSource(name, opts) {
26955
27070
  say(`evidence: ${e.path}`);
26956
27071
  continue;
26957
27072
  }
26958
- const out = path74.join(opts.to, `${name}-${path74.basename(e.path)}`);
26959
- fs73.mkdirSync(opts.to, { recursive: true });
26960
- fs73.writeFileSync(out, Buffer.from(await (await ask(`/${at}/evidence/${route(e.path)}`)).arrayBuffer()));
27073
+ const out = path76.join(opts.to, `${name}-${path76.basename(e.path)}`);
27074
+ fs74.mkdirSync(opts.to, { recursive: true });
27075
+ fs74.writeFileSync(out, Buffer.from(await (await ask(`/${at}/evidence/${route(e.path)}`)).arrayBuffer()));
26961
27076
  written.push(out);
26962
27077
  say(out);
26963
27078
  }
26964
27079
  return { name, source, evidence: written.length > 0 ? written : evidence.map((e) => e.path) };
26965
27080
  }
26966
27081
  async function templatePublish(dir, opts) {
26967
- const root = path74.resolve(dir);
26968
- const manifest = path74.join(root, "template.md");
26969
- if (!fs73.existsSync(manifest)) invalid("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
26970
- const meta = readTemplateMeta(fs73.readFileSync(manifest, "utf8"));
27082
+ const root = path76.resolve(dir);
27083
+ const manifest = path76.join(root, "template.md");
27084
+ if (!fs74.existsSync(manifest)) invalid("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
27085
+ const meta = readTemplateMeta(fs74.readFileSync(manifest, "utf8"));
26971
27086
  const files2 = walk2(root);
26972
- const total = files2.reduce((sum, f) => sum + fs73.statSync(path74.join(root, f)).size, 0);
27087
+ const total = files2.reduce((sum, f) => sum + fs74.statSync(path76.join(root, f)).size, 0);
26973
27088
  if (total > MAX_BYTES3) invalid("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
26974
27089
  for (const extra of [...opts.preview, ...opts.evidence]) {
26975
- if (!fs73.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
26976
- if (path74.resolve(extra).startsWith(root + path74.sep)) {
27090
+ if (!fs74.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
27091
+ if (path76.resolve(extra).startsWith(root + path76.sep)) {
26977
27092
  invalid(
26978
27093
  `${extra} \u5728\u6A21\u677F\u6587\u4EF6\u5939\u5185\uFF1B\u9884\u89C8\u56FE\u4E0E\u6765\u6E90\u51ED\u8BC1\u9700\u653E\u5728\u6A21\u677F\u6587\u4EF6\u5939\u4E4B\u5916\u3002`,
26979
27094
  `${extra} is inside the template folder; keep previews and evidence outside it.`
@@ -26985,10 +27100,10 @@ async function templatePublish(dir, opts) {
26985
27100
  }
26986
27101
  const form = new FormData();
26987
27102
  form.set("meta", JSON.stringify({ ...meta, replace: !!opts.replace }));
26988
- const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([fs73.readFileSync(file)]), path74.basename(name));
26989
- for (const f of files2) add("files", f, path74.join(root, f));
26990
- for (const f of opts.preview) add("previews", path74.basename(f), f);
26991
- for (const f of opts.evidence) add("evidence", path74.basename(f), f);
27103
+ const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([fs74.readFileSync(file)]), path76.basename(name));
27104
+ for (const f of files2) add("files", f, path76.join(root, f));
27105
+ for (const f of opts.preview) add("previews", path76.basename(f), f);
27106
+ for (const f of opts.evidence) add("evidence", path76.basename(f), f);
26992
27107
  const done2 = await asJson(await ask("", { method: "POST", body: form }));
26993
27108
  say(
26994
27109
  done2.replaced ? `\u5DF2\u66FF\u6362 ${done2.name}\uFF1A${files2.length} \u4E2A\u6587\u4EF6\u3002
@@ -27004,11 +27119,11 @@ Deleted ${name} from the catalog.`);
27004
27119
  return { name, deleted: true };
27005
27120
  }
27006
27121
  async function templateShowcase(name, dir) {
27007
- const file = path74.join(dir, "showcase.json");
27008
- if (!fs73.existsSync(file)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
27122
+ const file = path76.join(dir, "showcase.json");
27123
+ if (!fs74.existsSync(file)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
27009
27124
  let meta;
27010
27125
  try {
27011
- meta = JSON.parse(fs73.readFileSync(file, "utf8"));
27126
+ meta = JSON.parse(fs74.readFileSync(file, "utf8"));
27012
27127
  } catch {
27013
27128
  return invalid("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
27014
27129
  }
@@ -27020,9 +27135,9 @@ async function templateShowcase(name, dir) {
27020
27135
  const form = new FormData();
27021
27136
  form.set("meta", JSON.stringify(meta));
27022
27137
  for (const p of new Set(named2)) {
27023
- const at = path74.join(dir, p);
27024
- if (!fs73.existsSync(at)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at}\u3002`, `${at} does not exist.`);
27025
- form.append(`media:${p}`, new Blob([fs73.readFileSync(at)]), p);
27138
+ const at = path76.join(dir, p);
27139
+ if (!fs74.existsSync(at)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at}\u3002`, `${at} does not exist.`);
27140
+ form.append(`media:${p}`, new Blob([fs74.readFileSync(at)]), p);
27026
27141
  }
27027
27142
  const done2 = await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form }));
27028
27143
  say(`\u5DF2\u66F4\u65B0 ${name} \u7684\u5C55\u793A\u8D44\u6599\uFF1A${done2.files} \u4E2A\u6587\u4EF6\u3002
@@ -27031,7 +27146,7 @@ Updated ${name}'s showcase: ${done2.files} files.`);
27031
27146
  }
27032
27147
  function walk2(root, sub = "") {
27033
27148
  const out = [];
27034
- for (const entry of fs73.readdirSync(path74.join(root, sub), { withFileTypes: true })) {
27149
+ for (const entry of fs74.readdirSync(path76.join(root, sub), { withFileTypes: true })) {
27035
27150
  if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
27036
27151
  const rel2 = sub ? `${sub}/${entry.name}` : entry.name;
27037
27152
  if (entry.isDirectory()) out.push(...walk2(root, rel2));
@@ -27316,7 +27431,7 @@ init_opencode();
27316
27431
  init_locate();
27317
27432
  init_store();
27318
27433
  import { spawnSync as spawnSync5 } from "node:child_process";
27319
- import path80 from "node:path";
27434
+ import path82 from "node:path";
27320
27435
  var AGENTS2 = {
27321
27436
  claude: "claude-code",
27322
27437
  codex: "codex",
@@ -27331,10 +27446,10 @@ var AGENTS2 = {
27331
27446
  var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun", "deno"]);
27332
27447
  function agentOf2(args) {
27333
27448
  const words = args.trim().split(/\s+/);
27334
- const first = path80.basename(words[0] ?? "");
27449
+ const first = path82.basename(words[0] ?? "");
27335
27450
  const script = RUNTIMES.has(first) ? words[1] ?? "" : words[0] ?? "";
27336
27451
  if (script.includes("/@anthropic-ai/claude-code/")) return "claude-code";
27337
- return AGENTS2[path80.basename(script).replace(/\.(m?js|cjs|exe)$/, "")];
27452
+ return AGENTS2[path82.basename(script).replace(/\.(m?js|cjs|exe)$/, "")];
27338
27453
  }
27339
27454
  function processChain() {
27340
27455
  if (process.platform === "win32") return [];
@@ -27398,8 +27513,8 @@ init_tasks();
27398
27513
  init_read();
27399
27514
  init_rules();
27400
27515
  init_board();
27401
- import fs80 from "node:fs";
27402
- import path81 from "node:path";
27516
+ import fs81 from "node:fs";
27517
+ import path83 from "node:path";
27403
27518
  var FOLLOW_MS = 400;
27404
27519
  async function cmdStartRun(action, args, opts, program2 = "akb") {
27405
27520
  const { req, follow: follow2, print } = readRequest(action, args, opts);
@@ -27589,13 +27704,13 @@ function readRequest(action, args, opts) {
27589
27704
  return { req, follow: follow2, print };
27590
27705
  }
27591
27706
  async function cmdResume(id, opts) {
27592
- const opened = await startResume(id ?? "last");
27707
+ const opened = await startResume(id ?? "last", opts.requireSession);
27593
27708
  if ("error" in opened) die(opened.error, { kind: "run-refused" });
27594
27709
  const { run: run2 } = opened;
27595
27710
  if (!opened.spawned) die(`couldn't start a process for run ${run2.sessionId}`, { kind: "spawn-failed" });
27596
27711
  const within = run2.deliveryId ? ` in delivery ${run2.deliveryId}` : "";
27597
27712
  say(run2.resumedFrom ? `continuing ${short(run2.resumedFrom)} \u2014 run ${run2.sessionId}${within}` : `trying again \u2014 run ${run2.sessionId}${within}`);
27598
- if (opts.follow === true) return await followStarted(run2.sessionId, "akb");
27713
+ if (opts.follow === true) return await followStarted(run2.sessionId, "akb", opts.events === true);
27599
27714
  return { sessionId: run2.sessionId, resumedFrom: run2.resumedFrom };
27600
27715
  }
27601
27716
  async function cmdCancel(named2) {
@@ -27609,7 +27724,10 @@ async function cmdCancel(named2) {
27609
27724
  }
27610
27725
  async function cmdResumeDelivery(named2) {
27611
27726
  const res = await resumeBoardDelivery(named2);
27612
- if (!res.ok) die(res.error ?? "that delivery could not be carried on", { kind: "run-refused" });
27727
+ if (!res.ok) die(res.error ?? "that delivery could not be carried on", {
27728
+ kind: "run-refused",
27729
+ ...res.kind === "refused" ? { reason: res.reason, args: res.args } : {}
27730
+ });
27613
27731
  if (res.landed) {
27614
27732
  say(`delivery ${res.deliveryId} is done \u2014 its changes were already on the target branch.`);
27615
27733
  return { deliveryId: res.deliveryId, landed: true };
@@ -27686,7 +27804,7 @@ async function cmdSubStart(words, opts) {
27686
27804
  let prompt = words.join(" ");
27687
27805
  if (opts.file) {
27688
27806
  try {
27689
- prompt = fs80.readFileSync(path81.resolve(opts.file), "utf8");
27807
+ prompt = fs81.readFileSync(path83.resolve(opts.file), "utf8");
27690
27808
  } catch {
27691
27809
  die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
27692
27810
  }
@@ -27977,7 +28095,7 @@ async function cmdWatch(sessionId) {
27977
28095
  // src/commands/triage.ts
27978
28096
  init_scheduled();
27979
28097
  init_workflows();
27980
- import fs82 from "node:fs";
28098
+ import fs83 from "node:fs";
27981
28099
 
27982
28100
  // src/lib/signals/index.ts
27983
28101
  init_cards();
@@ -27987,16 +28105,16 @@ init_yaml();
27987
28105
  // src/lib/signals/config.ts
27988
28106
  init_settings2();
27989
28107
  init_paths();
27990
- import fs81 from "node:fs";
27991
- import path82 from "node:path";
28108
+ import fs82 from "node:fs";
28109
+ import path84 from "node:path";
27992
28110
  var TOKEN_KEY = "TRIAGE_ENDPOINT_TOKEN";
27993
28111
  var ENDPOINT_SETTING = "Triage endpoint";
27994
28112
  var LINE2 = /^- \*\*Triage endpoint\*\*\s*[—-]\s*(.+)$/m;
27995
- var boardRel3 = (file) => rel(file).split(path82.sep).join("/");
28113
+ var boardRel3 = (file) => rel(file).split(path84.sep).join("/");
27996
28114
  function signalEndpoint() {
27997
28115
  let text5;
27998
28116
  try {
27999
- text5 = fs81.readFileSync(CONFIG, "utf8");
28117
+ text5 = fs82.readFileSync(CONFIG, "utf8");
28000
28118
  } catch {
28001
28119
  return "";
28002
28120
  }
@@ -28172,7 +28290,7 @@ async function cmdTriageAdd(opts) {
28172
28290
  let body = opts.text;
28173
28291
  if (opts.file !== void 0) {
28174
28292
  try {
28175
- body = fs82.readFileSync(opts.file, "utf8");
28293
+ body = fs83.readFileSync(opts.file, "utf8");
28176
28294
  } catch {
28177
28295
  die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
28178
28296
  }
@@ -28604,7 +28722,7 @@ function declareRunning(run2, cli) {
28604
28722
  });
28605
28723
  verb("resume").argument("[id]", RUN_ID, String).summary("continue a run that failed, was cut off or was stopped").description(
28606
28724
  "The one command that reaches past the board: it picks the coding agent's own session back up \u2014 the conversation it was having, with everything it had already read \u2014 while the board counts the work as a fresh run. Before resuming a creation with no card, check sign-in, project access and connection. A refusal starts no run and leaves triage unchanged. Keep the triage source and request identity; reuse any task already created in Cloud. Repairing an existing card creates no other task. Example: akb run resume abc12345"
28607
- ).option("-f, --follow", "watch its log instead of returning").action(async function(...vals) {
28725
+ ).option("-f, --follow", "watch its log instead of returning").option("--events", "with --follow: print its structured events, one JSON object per line").option("--require-session", "refuse if the original conversation cannot be resumed").action(async function(...vals) {
28608
28726
  const [id] = positional(vals);
28609
28727
  await onBoard2(this, cli, () => cmdResume(id, this.opts()));
28610
28728
  });
@@ -28736,8 +28854,8 @@ function declareAgent(program2, cli) {
28736
28854
  }
28737
28855
 
28738
28856
  // src/lib/cli/setup.ts
28739
- import fs84 from "node:fs";
28740
- import path84 from "node:path";
28857
+ import fs85 from "node:fs";
28858
+ import path86 from "node:path";
28741
28859
  import { fileURLToPath as fileURLToPath2 } from "node:url";
28742
28860
 
28743
28861
  // src/commands/update.ts
@@ -28751,8 +28869,8 @@ init_paths();
28751
28869
  init_memory();
28752
28870
  init_yaml2();
28753
28871
  init_version();
28754
- import fs83 from "node:fs";
28755
- import path83 from "node:path";
28872
+ import fs84 from "node:fs";
28873
+ import path85 from "node:path";
28756
28874
  import { spawnSync as spawnSync6 } from "node:child_process";
28757
28875
  var NAME = "wildcrane";
28758
28876
  var REPO = "https://github.com/ai4kanban/ai4kanban";
@@ -28774,10 +28892,10 @@ var Report = class {
28774
28892
  for (const line of this.notes) say(` ! ${line}`);
28775
28893
  }
28776
28894
  };
28777
- var read3 = (file) => fs83.existsSync(file) ? fs83.readFileSync(file, "utf8") : null;
28895
+ var read3 = (file) => fs84.existsSync(file) ? fs84.readFileSync(file, "utf8") : null;
28778
28896
  function statOf(p) {
28779
28897
  try {
28780
- return fs83.lstatSync(p);
28898
+ return fs84.lstatSync(p);
28781
28899
  } catch {
28782
28900
  return null;
28783
28901
  }
@@ -28802,10 +28920,10 @@ async function cmdUpdate2(ctx) {
28802
28920
  return { updated: ctx.dir, from, to: SKILL_VERSION };
28803
28921
  }
28804
28922
  async function repairBoard(root, report3, named2) {
28805
- const legacy = path83.join(root, "docs", "kanban");
28806
- const kept2 = path83.join(root, ".akb", "kanban");
28807
- const board2 = named2 ?? (fs83.existsSync(legacy) ? legacy : kept2);
28808
- if (!fs83.existsSync(board2)) {
28923
+ const legacy = path85.join(root, "docs", "kanban");
28924
+ const kept2 = path85.join(root, ".akb", "kanban");
28925
+ const board2 = named2 ?? (fs84.existsSync(legacy) ? legacy : kept2);
28926
+ if (!fs84.existsSync(board2)) {
28809
28927
  report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
28810
28928
  return false;
28811
28929
  }
@@ -28836,20 +28954,20 @@ function moveRuntimes(root, board2, report3) {
28836
28954
  }
28837
28955
  }
28838
28956
  function moveLegacyMemory(board2, report3) {
28839
- const memory = path83.join(board2, "memory");
28957
+ const memory = path85.join(board2, "memory");
28840
28958
  const moved = [];
28841
28959
  for (const name of MEMORY_FILES) {
28842
- const from = path83.join(board2, name);
28960
+ const from = path85.join(board2, name);
28843
28961
  const st = statOf(from);
28844
28962
  if (!st || !st.isFile()) continue;
28845
- fs83.mkdirSync(memory, { recursive: true });
28846
- const to = path83.join(memory, name);
28963
+ fs84.mkdirSync(memory, { recursive: true });
28964
+ const to = path85.join(memory, name);
28847
28965
  const there = read3(to);
28848
28966
  if (there === null) {
28849
- fs83.renameSync(from, to);
28967
+ fs84.renameSync(from, to);
28850
28968
  moved.push(name);
28851
28969
  } else if (there === read3(from)) {
28852
- fs83.rmSync(from);
28970
+ fs84.rmSync(from);
28853
28971
  moved.push(name);
28854
28972
  } else {
28855
28973
  report3.notes.push(`both docs/kanban/${name} and docs/kanban/memory/${name} exist and differ \u2014 merge them by hand`);
@@ -28858,23 +28976,23 @@ function moveLegacyMemory(board2, report3) {
28858
28976
  if (moved.length) report3.did.push(`moved the memory set into docs/kanban/memory/: ${moved.join(", ")}`);
28859
28977
  }
28860
28978
  function dropRecordFile(board2) {
28861
- const file = path83.join(board2, "record.csv");
28862
- if (!fs83.existsSync(file)) return null;
28863
- fs83.rmSync(file);
28979
+ const file = path85.join(board2, "record.csv");
28980
+ if (!fs84.existsSync(file)) return null;
28981
+ fs84.rmSync(file);
28864
28982
  return "removed docs/kanban/record.csv (the planning scores it fed are gone)";
28865
28983
  }
28866
28984
  function dropModuleGoals(board2, report3) {
28867
- const memory = path83.join(board2, "memory");
28868
- if (!fs83.existsSync(memory)) return;
28869
- const root = read3(path83.join(memory, "goal.md"));
28985
+ const memory = path85.join(board2, "memory");
28986
+ if (!fs84.existsSync(memory)) return;
28987
+ const root = read3(path85.join(memory, "goal.md"));
28870
28988
  let dropped = 0;
28871
- for (const entry of fs83.readdirSync(memory, { withFileTypes: true })) {
28989
+ for (const entry of fs84.readdirSync(memory, { withFileTypes: true })) {
28872
28990
  if (!entry.isDirectory()) continue;
28873
- const file = path83.join(memory, entry.name, "goal.md");
28991
+ const file = path85.join(memory, entry.name, "goal.md");
28874
28992
  const text5 = read3(file);
28875
28993
  if (text5 === null) continue;
28876
28994
  if (text5 === root || text5.includes(UNFILLED) || !goalWords(text5)) {
28877
- fs83.rmSync(file);
28995
+ fs84.rmSync(file);
28878
28996
  dropped++;
28879
28997
  } else {
28880
28998
  report3.notes.push(
@@ -28896,10 +29014,10 @@ var PLAN_LEADS = {
28896
29014
  var GONE_LEADS = ["software-planner", "planner"];
28897
29015
  function planLeads(board2) {
28898
29016
  const leads = { ...PLAN_LEADS };
28899
- const root = path83.join(board2, "workflows");
28900
- for (const entry of fs83.existsSync(root) ? fs83.readdirSync(root, { withFileTypes: true }) : []) {
29017
+ const root = path85.join(board2, "workflows");
29018
+ for (const entry of fs84.existsSync(root) ? fs84.readdirSync(root, { withFileTypes: true }) : []) {
28901
29019
  if (!entry.isDirectory()) continue;
28902
- const meta = splitFrontmatter(read3(path83.join(root, entry.name, "WORKFLOW.md")) ?? "").meta;
29020
+ const meta = splitFrontmatter(read3(path85.join(root, entry.name, "WORKFLOW.md")) ?? "").meta;
28903
29021
  const stages = meta === null ? void 0 : parseYamlBlock(meta).stages;
28904
29022
  const plan = stages && typeof stages === "object" && !Array.isArray(stages) ? stages.plan : void 0;
28905
29023
  const lead = plan && typeof plan === "object" && !Array.isArray(plan) && typeof plan.lead === "string" ? plan.lead.trim() : "";
@@ -28908,30 +29026,30 @@ function planLeads(board2) {
28908
29026
  return leads;
28909
29027
  }
28910
29028
  function movePlanRules(board2, report3) {
28911
- const rules = path83.join(board2, "rules");
29029
+ const rules = path85.join(board2, "rules");
28912
29030
  const moved = [];
28913
29031
  for (const [id, leads] of Object.entries(planLeads(board2))) {
28914
29032
  for (const lead of leads) {
28915
- const from = path83.join(rules, `${lead}.md`);
29033
+ const from = path85.join(rules, `${lead}.md`);
28916
29034
  const rule = read3(from)?.trim();
28917
29035
  if (!rule) continue;
28918
- const to = path83.join(rules, "workflows", `${id}.md`);
29036
+ const to = path85.join(rules, "workflows", `${id}.md`);
28919
29037
  const there = read3(to)?.trim() ?? "";
28920
29038
  if (!there.includes(rule)) {
28921
- fs83.mkdirSync(path83.dirname(to), { recursive: true });
28922
- fs83.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
29039
+ fs84.mkdirSync(path85.dirname(to), { recursive: true });
29040
+ fs84.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
28923
29041
  `);
28924
29042
  moved.push(`${lead} \u2192 ${id}`);
28925
29043
  }
28926
29044
  }
28927
29045
  }
28928
- for (const lead of GONE_LEADS) fs83.rmSync(path83.join(rules, `${lead}.md`), { force: true });
29046
+ for (const lead of GONE_LEADS) fs84.rmSync(path85.join(rules, `${lead}.md`), { force: true });
28929
29047
  if (moved.length) report3.did.push(`made each plan agent's rule its workflow's card rule (docs/kanban/rules/workflows/): ${moved.join(", ")}`);
28930
29048
  }
28931
29049
  function noteOldWorkflows(board2, report3) {
28932
29050
  const old = (dir, file, keys) => {
28933
- const root = path83.join(board2, dir);
28934
- return (fs83.existsSync(root) ? fs83.readdirSync(root, { withFileTypes: true }) : []).filter((e) => e.isDirectory() && keys.test(splitFrontmatter(read3(path83.join(root, e.name, file)) ?? "").meta ?? "")).map((e) => `docs/kanban/${dir}/${e.name}/${file}`);
29051
+ const root = path85.join(board2, dir);
29052
+ return (fs84.existsSync(root) ? fs84.readdirSync(root, { withFileTypes: true }) : []).filter((e) => e.isDirectory() && keys.test(splitFrontmatter(read3(path85.join(root, e.name, file)) ?? "").meta ?? "")).map((e) => `docs/kanban/${dir}/${e.name}/${file}`);
28935
29053
  };
28936
29054
  const files2 = [...old("workflows", "WORKFLOW.md", /^(stages|delivers):/m), ...old("agents", "AGENT.md", /^\s+(hook|lead):/m)];
28937
29055
  if (files2.length) {
@@ -28941,7 +29059,7 @@ function noteOldWorkflows(board2, report3) {
28941
29059
  }
28942
29060
  }
28943
29061
  function checkConfig(board2, report3) {
28944
- const current = read3(path83.join(board2, "config.md"));
29062
+ const current = read3(path85.join(board2, "config.md"));
28945
29063
  if (!current) return;
28946
29064
  const added = missingConfigKeys(current);
28947
29065
  if (added.length) {
@@ -28951,7 +29069,7 @@ function checkConfig(board2, report3) {
28951
29069
  }
28952
29070
  }
28953
29071
  function checkModules(board2, report3) {
28954
- const map2 = read3(path83.join(board2, "modules.md"));
29072
+ const map2 = read3(path85.join(board2, "modules.md"));
28955
29073
  if (map2 && map2.includes(UNFILLED)) {
28956
29074
  report3.notes.push(
28957
29075
  "docs/kanban/modules.md is still blank \u2014 write it from the repo (`akb guide module-map`)"
@@ -29005,14 +29123,14 @@ function declareSetup(program2, cli) {
29005
29123
  program2.version(SKILL_VERSION, "-v, --version", "print this version").addHelpText("beforeAll", spelled(cli.program));
29006
29124
  const dirOption = (cmd) => cmd.option("--dir <path>", "the project to work on (default: the current folder)").option("--json", "answer as one JSON object instead of prose");
29007
29125
  const where = (cmd) => {
29008
- const dir = path84.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
29009
- if (!fs84.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
29126
+ const dir = path86.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
29127
+ if (!fs85.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
29010
29128
  return dir;
29011
29129
  };
29012
29130
  dirOption(program2.command("update")).summary("\u4FEE\u590D\u5DF2\u6709\u770B\u677F\u5E76\u68C0\u67E5 CLI \u65B0\u7248\u672C").description("\u4FEE\u590D\u5DF2\u6709\u770B\u677F\u5E76\u63D0\u793A CLI \u5347\u7EA7\u547D\u4EE4\u3002\u6CA1\u6709\u770B\u677F\u65F6\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002").action(async function() {
29013
29131
  const dir = where(this);
29014
29132
  const named2 = this.optsWithGlobals().board ?? process.env.AI4KANBAN_BOARD?.trim();
29015
- const board2 = named2 ? path84.resolve(cli.cwd, named2) : null;
29133
+ const board2 = named2 ? path86.resolve(cli.cwd, named2) : null;
29016
29134
  await runAction(ctxOf(this, cli.program), {}, () => cmdUpdate2({ dir, program: cli.program, board: board2 }));
29017
29135
  });
29018
29136
  program2.command("__rules", { hidden: true }).action(function() {
@@ -29056,7 +29174,7 @@ function invokedDirectly() {
29056
29174
  const entry = process.argv[1];
29057
29175
  if (!entry) return false;
29058
29176
  try {
29059
- return fs85.realpathSync(entry) === fs85.realpathSync(SELF2);
29177
+ return fs86.realpathSync(entry) === fs86.realpathSync(SELF2);
29060
29178
  } catch {
29061
29179
  return false;
29062
29180
  }