wildcrane 0.11.10 → 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.
- package/dist/kanban.mjs +995 -883
- package/package.json +1 -1
package/dist/kanban.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// ai4kanban 0.11.
|
|
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
|
|
1172
|
-
var
|
|
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 (
|
|
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 =
|
|
2172
|
-
if (
|
|
2173
|
-
if (sourceExt.includes(
|
|
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) =>
|
|
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 =
|
|
2187
|
+
resolvedScriptPath = fs87.realpathSync(this._scriptPath);
|
|
2188
2188
|
} catch {
|
|
2189
2189
|
resolvedScriptPath = this._scriptPath;
|
|
2190
2190
|
}
|
|
2191
|
-
executableDir =
|
|
2192
|
-
|
|
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 =
|
|
2199
|
+
const legacyName = path87.basename(
|
|
2200
2200
|
this._scriptPath,
|
|
2201
|
-
|
|
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(
|
|
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 =
|
|
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(
|
|
3074
|
-
if (
|
|
3075
|
-
this._executableDir =
|
|
3073
|
+
executableDir(path88) {
|
|
3074
|
+
if (path88 === void 0) return this._executableDir;
|
|
3075
|
+
this._executableDir = path88;
|
|
3076
3076
|
return this;
|
|
3077
3077
|
}
|
|
3078
3078
|
/**
|
|
@@ -5478,7 +5478,7 @@ var init_package = __esm({
|
|
|
5478
5478
|
"package.json"() {
|
|
5479
5479
|
package_default = {
|
|
5480
5480
|
name: "wildcrane",
|
|
5481
|
-
version: "0.11.
|
|
5481
|
+
version: "0.11.11",
|
|
5482
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: [
|
|
@@ -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
|
|
8320
|
+
const path87 = join(dir, name);
|
|
8321
8321
|
try {
|
|
8322
|
-
const at = statSync(
|
|
8323
|
-
if (!newest2 || at > newest2.at) newest2 = { path:
|
|
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
|
|
8332
|
-
if (!
|
|
8331
|
+
const path87 = findRollout(threadId);
|
|
8332
|
+
if (!path87) return void 0;
|
|
8333
8333
|
let raw;
|
|
8334
8334
|
try {
|
|
8335
|
-
raw = readFileSync(
|
|
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
|
|
8464
|
-
return
|
|
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:
|
|
8723
|
+
for (const { path: path87, main } of wireFiles(entry.sessionDir)) {
|
|
8724
8724
|
let raw;
|
|
8725
8725
|
try {
|
|
8726
|
-
raw = readFileSync2(
|
|
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
|
|
9008
|
-
return
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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) =>
|
|
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) =>
|
|
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 =
|
|
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
|
|
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 =
|
|
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(
|
|
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) =>
|
|
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
|
|
15739
|
-
import
|
|
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
|
|
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
|
-
|
|
16025
|
+
fs40.rmSync(rulePath(agent), { force: true });
|
|
15759
16026
|
return { ok: true };
|
|
15760
16027
|
}
|
|
15761
|
-
|
|
15762
|
-
|
|
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(
|
|
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)
|
|
16088
|
+
if (parts.length) fs40.writeFileSync(rulePath(owner.name), `${parts.join("\n\n")}
|
|
15822
16089
|
`);
|
|
15823
|
-
for (const flow of from)
|
|
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 =
|
|
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 (!
|
|
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))
|
|
16118
|
+
if (carried && !kept2.includes(carried)) fs40.writeFileSync(rulePath(now), `${[kept2, carried].filter(Boolean).join("\n\n")}
|
|
15852
16119
|
`);
|
|
15853
|
-
|
|
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) =>
|
|
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
|
|
15956
|
-
import
|
|
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" ?
|
|
15967
|
-
const title = parseFrontmatter(
|
|
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) =>
|
|
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
|
|
16034
|
-
import
|
|
16300
|
+
import fs42 from "node:fs";
|
|
16301
|
+
import path46 from "node:path";
|
|
16035
16302
|
function readCard(file, relFromTodo) {
|
|
16036
|
-
const id = idPrefix(
|
|
16303
|
+
const id = idPrefix(path46.basename(relFromTodo));
|
|
16037
16304
|
if (id === null) {
|
|
16038
|
-
const parts = relFromTodo.split(
|
|
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 =
|
|
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(
|
|
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:
|
|
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 =
|
|
16080
|
-
const rootFile =
|
|
16081
|
-
if (!
|
|
16082
|
-
const root = readCard(rootFile,
|
|
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
|
|
16090
|
-
const childRel =
|
|
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(
|
|
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(
|
|
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 ?
|
|
16116
|
-
if (!
|
|
16382
|
+
const dir = dirRel ? path46.join(TODO, dirRel) : TODO;
|
|
16383
|
+
if (!fs42.existsSync(dir)) return [];
|
|
16117
16384
|
const cards = [];
|
|
16118
|
-
for (const entry of
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
16353
|
-
import
|
|
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
|
-
|
|
16648
|
+
fs43.mkdirSync(DELIVERIES, { recursive: true });
|
|
16382
16649
|
const tmp = `${auditPath(record.deliveryId)}.tmp`;
|
|
16383
|
-
|
|
16384
|
-
|
|
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(
|
|
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(
|
|
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 =
|
|
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(
|
|
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
|
|
16805
|
+
const path87 = delivery.worktree ?? "";
|
|
16539
16806
|
return refusal(
|
|
16540
16807
|
"deliveryWorktreeGone",
|
|
16541
|
-
`delivery ${id}'s worktree ${
|
|
16542
|
-
{ id, task, path:
|
|
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
|
|
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" ?
|
|
16946
|
+
const file = found2.kind === "group" ? path47.join(found2.target, "root.md") : found2.target;
|
|
16676
16947
|
let text5;
|
|
16677
16948
|
try {
|
|
16678
|
-
text5 =
|
|
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" ?
|
|
16709
|
-
return parseFrontmatter(
|
|
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) =>
|
|
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/
|
|
16996
|
-
|
|
16997
|
-
|
|
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
|
|
17060
|
-
import
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
|
17923
|
+
return fs45.realpathSync(dir);
|
|
17608
17924
|
} catch {
|
|
17609
|
-
return
|
|
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
|
|
17619
|
-
import
|
|
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
|
-
|
|
17626
|
-
|
|
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) =>
|
|
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
|
-
|
|
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
|
-
|
|
17958
|
+
fs46.renameSync(pictureBox(from), pictureBox(to));
|
|
17643
17959
|
} catch {
|
|
17644
17960
|
return files2;
|
|
17645
17961
|
}
|
|
17646
|
-
return files2.map((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) && !
|
|
17656
|
-
pictureBox = (box2) =>
|
|
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
|
|
17662
|
-
import
|
|
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:
|
|
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 =
|
|
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 =
|
|
17699
|
-
if (!
|
|
17700
|
-
const memory = readMemory(
|
|
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
|
|
17757
|
-
import
|
|
18072
|
+
import fs48 from "node:fs";
|
|
18073
|
+
import path52 from "node:path";
|
|
17758
18074
|
function archivedId(file) {
|
|
17759
|
-
const own = idPrefix(
|
|
17760
|
-
return own !== null ? own : idPrefix(
|
|
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(
|
|
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(
|
|
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(
|
|
17781
|
-
if (!
|
|
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
|
|
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" ?
|
|
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" ?
|
|
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" ?
|
|
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) : "";
|
|
@@ -18212,290 +18528,83 @@ ${shared}` : ""
|
|
|
18212
18528
|
return [
|
|
18213
18529
|
`${kb}. Task ${req.id} ${named2} has been approved: write the previews that were waiting on that Approve from the card as it stands.`,
|
|
18214
18530
|
req.notes ? `Extra notes: ${req.notes}` : "",
|
|
18215
|
-
`Don't ask me questions with human-in-the-loop. Leave any questions as open questions.`
|
|
18216
|
-
].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
|
-
}
|
|
18531
|
+
`Don't ask me questions with human-in-the-loop. Leave any questions as open questions.`
|
|
18532
|
+
].filter(Boolean).join(" ");
|
|
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
|
|
18459
|
-
if (!
|
|
18460
|
-
|
|
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
|
|
18473
|
-
var
|
|
18474
|
-
"src/lib/agent/
|
|
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
|
-
|
|
18478
|
-
|
|
18479
|
-
|
|
18480
|
-
|
|
18481
|
-
|
|
18482
|
-
|
|
18483
|
-
|
|
18484
|
-
|
|
18485
|
-
|
|
18486
|
-
|
|
18487
|
-
|
|
18488
|
-
|
|
18489
|
-
|
|
18490
|
-
|
|
18491
|
-
|
|
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
|
|
18498
|
-
import
|
|
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
|
-
|
|
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(
|
|
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" ?
|
|
18778
|
+
const file = filed.kind === "group" ? path54.join(filed.target, "root.md") : filed.target;
|
|
18670
18779
|
try {
|
|
18671
|
-
return !!parseFrontmatter(
|
|
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 ||
|
|
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" };
|
|
@@ -19147,8 +19256,8 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
|
|
|
19147
19256
|
clearAsks(prev.sessionId);
|
|
19148
19257
|
try {
|
|
19149
19258
|
if (prev.action !== "create") {
|
|
19150
|
-
|
|
19151
|
-
|
|
19259
|
+
fs49.unlinkSync(prev.logPath);
|
|
19260
|
+
fs49.rmSync(eventsPathOf(prev.sessionId), { force: true });
|
|
19152
19261
|
}
|
|
19153
19262
|
} catch {
|
|
19154
19263
|
}
|
|
@@ -19172,8 +19281,8 @@ function forgetRun(sessionId) {
|
|
|
19172
19281
|
if (!gone) return;
|
|
19173
19282
|
clearAsks(sessionId);
|
|
19174
19283
|
try {
|
|
19175
|
-
|
|
19176
|
-
|
|
19284
|
+
fs49.unlinkSync(gone.logPath);
|
|
19285
|
+
fs49.rmSync(eventsPathOf(gone.sessionId), { force: true });
|
|
19177
19286
|
} catch {
|
|
19178
19287
|
}
|
|
19179
19288
|
}
|
|
@@ -19202,14 +19311,14 @@ function noteSpecRefusals(sessionId, refused) {
|
|
|
19202
19311
|
}
|
|
19203
19312
|
function clearAsks(sessionId) {
|
|
19204
19313
|
try {
|
|
19205
|
-
|
|
19314
|
+
fs49.unlinkSync(asksPathOf(sessionId));
|
|
19206
19315
|
} catch {
|
|
19207
19316
|
}
|
|
19208
19317
|
}
|
|
19209
19318
|
function readAsks(sessionId) {
|
|
19210
19319
|
let data;
|
|
19211
19320
|
try {
|
|
19212
|
-
data = JSON.parse(
|
|
19321
|
+
data = JSON.parse(fs49.readFileSync(asksPathOf(sessionId), "utf8"));
|
|
19213
19322
|
} catch {
|
|
19214
19323
|
return { asks: [], refines: [], refused: [] };
|
|
19215
19324
|
}
|
|
@@ -19236,10 +19345,10 @@ function readAsks(sessionId) {
|
|
|
19236
19345
|
return { asks: asks.filter((a) => !discarded.has(a.cardId)), refines: refines.filter((a) => !discarded.has(a.cardId)), refused };
|
|
19237
19346
|
}
|
|
19238
19347
|
function writeAsks(sessionId, file) {
|
|
19239
|
-
|
|
19348
|
+
fs49.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
19240
19349
|
const tmp = `${asksPathOf(sessionId)}.tmp`;
|
|
19241
|
-
|
|
19242
|
-
|
|
19350
|
+
fs49.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n");
|
|
19351
|
+
fs49.renameSync(tmp, asksPathOf(sessionId));
|
|
19243
19352
|
}
|
|
19244
19353
|
function markSpawned(sessionId, pid) {
|
|
19245
19354
|
patch(sessionId, (r) => {
|
|
@@ -19327,7 +19436,10 @@ async function cancelDelivery(id) {
|
|
|
19327
19436
|
if (!id.trim()) return { ok: false, ...refusal("deliveryUnnamed", "name the delivery to cancel", { action: "cancel" }) };
|
|
19328
19437
|
const delivery = namedDelivery(id);
|
|
19329
19438
|
if (!delivery) return { ok: false, ...unknownDelivery(id) };
|
|
19330
|
-
if (delivery.status !== "active")
|
|
19439
|
+
if (delivery.status !== "active") {
|
|
19440
|
+
tidyCheckout(delivery.deliveryId);
|
|
19441
|
+
return { ok: true, deliveryId: delivery.deliveryId };
|
|
19442
|
+
}
|
|
19331
19443
|
endDelivery(delivery.deliveryId, "cancelled");
|
|
19332
19444
|
const live = readRuns().find((r) => r.status === "running" && r.deliveryId === delivery.deliveryId && r.action !== "sub");
|
|
19333
19445
|
if (live) await stopRun(live.sessionId);
|
|
@@ -19393,12 +19505,12 @@ async function discardDelivery(id) {
|
|
|
19393
19505
|
return { ok: true, deliveryId: delivery.deliveryId };
|
|
19394
19506
|
}
|
|
19395
19507
|
function writeSpec(spec) {
|
|
19396
|
-
|
|
19397
|
-
|
|
19508
|
+
fs49.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
19509
|
+
fs49.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
|
|
19398
19510
|
}
|
|
19399
19511
|
function readSpec(sessionId) {
|
|
19400
19512
|
try {
|
|
19401
|
-
const spec = JSON.parse(
|
|
19513
|
+
const spec = JSON.parse(fs49.readFileSync(specPathOf(sessionId), "utf8"));
|
|
19402
19514
|
return spec && Array.isArray(spec.plan?.argv) ? spec : null;
|
|
19403
19515
|
} catch {
|
|
19404
19516
|
return null;
|
|
@@ -19406,28 +19518,28 @@ function readSpec(sessionId) {
|
|
|
19406
19518
|
}
|
|
19407
19519
|
function dropSpec(sessionId) {
|
|
19408
19520
|
try {
|
|
19409
|
-
|
|
19521
|
+
fs49.unlinkSync(specPathOf(sessionId));
|
|
19410
19522
|
} catch {
|
|
19411
19523
|
}
|
|
19412
19524
|
}
|
|
19413
19525
|
async function acquireIndexLock(giveUp) {
|
|
19414
19526
|
const until = Date.now() + INDEX_WAIT_MS;
|
|
19415
|
-
const holder =
|
|
19527
|
+
const holder = path54.join(INDEX_LOCK2, "holder");
|
|
19416
19528
|
for (; ; ) {
|
|
19417
19529
|
if (giveUp()) return null;
|
|
19418
19530
|
try {
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
return () =>
|
|
19531
|
+
fs49.mkdirSync(INDEX_LOCK2, { recursive: false });
|
|
19532
|
+
fs49.writeFileSync(holder, String(process.pid));
|
|
19533
|
+
return () => fs49.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
19422
19534
|
} catch (err) {
|
|
19423
19535
|
const code = err.code;
|
|
19424
19536
|
if (code === "ENOENT") {
|
|
19425
|
-
|
|
19537
|
+
fs49.mkdirSync(path54.dirname(INDEX_LOCK2), { recursive: true });
|
|
19426
19538
|
continue;
|
|
19427
19539
|
}
|
|
19428
19540
|
if (code !== "EEXIST") throw err;
|
|
19429
19541
|
if (!pidAlive(Number(readHolder(holder)))) {
|
|
19430
|
-
|
|
19542
|
+
fs49.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
19431
19543
|
continue;
|
|
19432
19544
|
}
|
|
19433
19545
|
if (Date.now() > until) return null;
|
|
@@ -19437,7 +19549,7 @@ async function acquireIndexLock(giveUp) {
|
|
|
19437
19549
|
}
|
|
19438
19550
|
function readHolder(file) {
|
|
19439
19551
|
try {
|
|
19440
|
-
return
|
|
19552
|
+
return fs49.readFileSync(file, "utf8").trim();
|
|
19441
19553
|
} catch {
|
|
19442
19554
|
return String(process.pid);
|
|
19443
19555
|
}
|
|
@@ -19528,8 +19640,8 @@ var init_sessions = __esm({
|
|
|
19528
19640
|
conflict: "implementing",
|
|
19529
19641
|
hook: "implementing"
|
|
19530
19642
|
};
|
|
19531
|
-
specPathOf = (sessionId) =>
|
|
19532
|
-
asksPathOf = (sessionId) =>
|
|
19643
|
+
specPathOf = (sessionId) => path54.join(SESSIONS_DIR, `${sessionId}.plan.json`);
|
|
19644
|
+
asksPathOf = (sessionId) => path54.join(SESSIONS_DIR, `${sessionId}.asks.json`);
|
|
19533
19645
|
carriesSession = (r) => !!(r.resumedFrom || r.continues && !r.continues.fork);
|
|
19534
19646
|
canPickUp = (r) => (r.status === "error" || r.status === "interrupted" || r.status === "stopped") && !(r.action === "create" && readRuns().some((next) => next.resumedFrom === r.sessionId));
|
|
19535
19647
|
neverStarted = (r) => r.unspawned === true || !!r.errorWhy?.some((why) => why.kind === "notInstalled");
|
|
@@ -19663,8 +19775,8 @@ var init_questions = __esm({
|
|
|
19663
19775
|
});
|
|
19664
19776
|
|
|
19665
19777
|
// src/lib/agent/workflow-cards.ts
|
|
19666
|
-
import
|
|
19667
|
-
import
|
|
19778
|
+
import fs50 from "node:fs";
|
|
19779
|
+
import path55 from "node:path";
|
|
19668
19780
|
function cardsOnWorkflow(id) {
|
|
19669
19781
|
const wanted = id || DEFAULT_WORKFLOW;
|
|
19670
19782
|
const ids = [];
|
|
@@ -19675,12 +19787,12 @@ function cardsOnWorkflow(id) {
|
|
|
19675
19787
|
return [];
|
|
19676
19788
|
}
|
|
19677
19789
|
for (const file of files2) {
|
|
19678
|
-
const base =
|
|
19679
|
-
const card = base === "root.md" ? idPrefix(
|
|
19790
|
+
const base = path55.basename(file);
|
|
19791
|
+
const card = base === "root.md" ? idPrefix(path55.basename(path55.dirname(file))) : idPrefix(base);
|
|
19680
19792
|
if (card === null) continue;
|
|
19681
19793
|
let meta;
|
|
19682
19794
|
try {
|
|
19683
|
-
meta = parseFrontmatter(
|
|
19795
|
+
meta = parseFrontmatter(fs50.readFileSync(file, "utf8")).meta;
|
|
19684
19796
|
} catch {
|
|
19685
19797
|
continue;
|
|
19686
19798
|
}
|
|
@@ -19738,12 +19850,12 @@ var init_workflow_cards = __esm({
|
|
|
19738
19850
|
});
|
|
19739
19851
|
|
|
19740
19852
|
// src/lib/readme.ts
|
|
19741
|
-
import
|
|
19742
|
-
import
|
|
19853
|
+
import fs51 from "node:fs";
|
|
19854
|
+
import path56 from "node:path";
|
|
19743
19855
|
function stripReadmeRefs(target) {
|
|
19744
|
-
if (!
|
|
19856
|
+
if (!fs51.existsSync(README)) return [];
|
|
19745
19857
|
const needle = target.kind === "group" ? `](${target.rel}/` : `](${target.rel})`;
|
|
19746
|
-
const lines =
|
|
19858
|
+
const lines = fs51.readFileSync(README, "utf8").split("\n");
|
|
19747
19859
|
const out = [];
|
|
19748
19860
|
const removed = [];
|
|
19749
19861
|
let i = 0;
|
|
@@ -19765,20 +19877,20 @@ function stripReadmeRefs(target) {
|
|
|
19765
19877
|
out.push(line);
|
|
19766
19878
|
i++;
|
|
19767
19879
|
}
|
|
19768
|
-
if (removed.length)
|
|
19880
|
+
if (removed.length) fs51.writeFileSync(README, out.join("\n"));
|
|
19769
19881
|
return removed;
|
|
19770
19882
|
}
|
|
19771
19883
|
function addReadmeRef(id, title, relPath) {
|
|
19772
|
-
if (!
|
|
19773
|
-
const link2 = relPath.split(
|
|
19884
|
+
if (!fs51.existsSync(README)) return false;
|
|
19885
|
+
const link2 = relPath.split(path56.sep).join("/");
|
|
19774
19886
|
const bullet = `- [#${id} ${title}](${link2})`;
|
|
19775
19887
|
const heading = `## ${TASKS_HEADING}`;
|
|
19776
|
-
let lines =
|
|
19888
|
+
let lines = fs51.readFileSync(README, "utf8").split("\n");
|
|
19777
19889
|
const hi = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
|
|
19778
19890
|
if (hi === -1) {
|
|
19779
19891
|
while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
|
|
19780
19892
|
lines.push("", heading, "", bullet);
|
|
19781
|
-
|
|
19893
|
+
fs51.writeFileSync(README, lines.join("\n") + "\n");
|
|
19782
19894
|
return true;
|
|
19783
19895
|
}
|
|
19784
19896
|
let end2 = hi + 1;
|
|
@@ -19792,15 +19904,15 @@ function addReadmeRef(id, title, relPath) {
|
|
|
19792
19904
|
const at = lastBullet !== -1 ? lastBullet + 1 : lines[hi + 1] === "" ? hi + 2 : hi + 1;
|
|
19793
19905
|
lines.splice(at, 0, bullet);
|
|
19794
19906
|
}
|
|
19795
|
-
|
|
19907
|
+
fs51.writeFileSync(README, lines.join("\n"));
|
|
19796
19908
|
return true;
|
|
19797
19909
|
}
|
|
19798
19910
|
function repointReadmeLink(id, oldRel, newRel, title) {
|
|
19799
|
-
if (!
|
|
19800
|
-
const oldLink = oldRel.split(
|
|
19801
|
-
const newLink = newRel.split(
|
|
19911
|
+
if (!fs51.existsSync(README)) return false;
|
|
19912
|
+
const oldLink = oldRel.split(path56.sep).join("/");
|
|
19913
|
+
const newLink = newRel.split(path56.sep).join("/");
|
|
19802
19914
|
const linkRe = new RegExp(`\\[#${id}\\b[^\\]]*\\]\\(${escapeRegex(oldLink)}\\)`);
|
|
19803
|
-
const lines =
|
|
19915
|
+
const lines = fs51.readFileSync(README, "utf8").split("\n");
|
|
19804
19916
|
let changed = false;
|
|
19805
19917
|
for (let i = 0; i < lines.length; i++) {
|
|
19806
19918
|
if (!lines[i].includes(`](${oldLink})`)) continue;
|
|
@@ -19810,7 +19922,7 @@ function repointReadmeLink(id, oldRel, newRel, title) {
|
|
|
19810
19922
|
changed = true;
|
|
19811
19923
|
}
|
|
19812
19924
|
}
|
|
19813
|
-
if (changed)
|
|
19925
|
+
if (changed) fs51.writeFileSync(README, lines.join("\n"));
|
|
19814
19926
|
return changed;
|
|
19815
19927
|
}
|
|
19816
19928
|
var isTableRow, isBulletStart, bulletIndent, TASKS_HEADING, escapeRegex;
|
|
@@ -19827,14 +19939,14 @@ var init_readme = __esm({
|
|
|
19827
19939
|
});
|
|
19828
19940
|
|
|
19829
19941
|
// src/lib/reconcile.ts
|
|
19830
|
-
import
|
|
19831
|
-
import
|
|
19942
|
+
import fs52 from "node:fs";
|
|
19943
|
+
import path57 from "node:path";
|
|
19832
19944
|
function liveIds() {
|
|
19833
19945
|
const ids = /* @__PURE__ */ new Set();
|
|
19834
19946
|
for (const file of walkMd(TODO)) {
|
|
19835
|
-
const base =
|
|
19947
|
+
const base = path57.basename(file);
|
|
19836
19948
|
if (base === "README.md") continue;
|
|
19837
|
-
const id = base === "root.md" ? idPrefix(
|
|
19949
|
+
const id = base === "root.md" ? idPrefix(path57.basename(path57.dirname(file))) : idPrefix(base);
|
|
19838
19950
|
if (id != null) ids.add(id);
|
|
19839
19951
|
}
|
|
19840
19952
|
return ids;
|
|
@@ -19842,16 +19954,16 @@ function liveIds() {
|
|
|
19842
19954
|
function indexableCards() {
|
|
19843
19955
|
const out = [];
|
|
19844
19956
|
for (const dir of walkDirs(TODO)) {
|
|
19845
|
-
const id = idPrefix(
|
|
19846
|
-
if (id != null &&
|
|
19847
|
-
out.push({ id, rel:
|
|
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("/") });
|
|
19848
19960
|
}
|
|
19849
19961
|
}
|
|
19850
19962
|
for (const file of walkMd(TODO)) {
|
|
19851
|
-
const base =
|
|
19963
|
+
const base = path57.basename(file);
|
|
19852
19964
|
if (base === "README.md" || base === "root.md") continue;
|
|
19853
|
-
const relTODO =
|
|
19854
|
-
const segs = relTODO.split(
|
|
19965
|
+
const relTODO = path57.relative(TODO, file);
|
|
19966
|
+
const segs = relTODO.split(path57.sep);
|
|
19855
19967
|
if (segs.length !== 1) continue;
|
|
19856
19968
|
const id = idPrefix(base);
|
|
19857
19969
|
if (id != null) out.push({ id, rel: segs.join("/") });
|
|
@@ -19860,7 +19972,7 @@ function indexableCards() {
|
|
|
19860
19972
|
}
|
|
19861
19973
|
function readmeComplaints(fix) {
|
|
19862
19974
|
const said3 = [];
|
|
19863
|
-
const lines =
|
|
19975
|
+
const lines = fs52.readFileSync(README, "utf8").split("\n");
|
|
19864
19976
|
const indexed = /* @__PURE__ */ new Set();
|
|
19865
19977
|
let fixed = 0;
|
|
19866
19978
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -19869,13 +19981,13 @@ function readmeComplaints(fix) {
|
|
|
19869
19981
|
const id = Number(m[1]);
|
|
19870
19982
|
const linkPath = m[2];
|
|
19871
19983
|
indexed.add(id);
|
|
19872
|
-
if (
|
|
19984
|
+
if (fs52.existsSync(path57.join(TODO, linkPath))) continue;
|
|
19873
19985
|
const found2 = locate(id);
|
|
19874
19986
|
if (!found2) {
|
|
19875
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.`);
|
|
19876
19988
|
continue;
|
|
19877
19989
|
}
|
|
19878
|
-
const want = (found2.kind === "group" ?
|
|
19990
|
+
const want = (found2.kind === "group" ? path57.join(found2.rel, "root.md") : found2.rel).split(path57.sep).join("/");
|
|
19879
19991
|
if (want === linkPath) continue;
|
|
19880
19992
|
if (!fix) {
|
|
19881
19993
|
said3.push(`README links #${id} \u2192 ${linkPath}, which isn't there any more; the card is at ${want}.`);
|
|
@@ -19885,7 +19997,7 @@ function readmeComplaints(fix) {
|
|
|
19885
19997
|
said3.push(`README link #${id} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
|
|
19886
19998
|
fixed++;
|
|
19887
19999
|
}
|
|
19888
|
-
if (fixed)
|
|
20000
|
+
if (fixed) fs52.writeFileSync(README, lines.join("\n"));
|
|
19889
20001
|
for (const c of indexableCards()) {
|
|
19890
20002
|
if (!indexed.has(c.id)) {
|
|
19891
20003
|
said3.push(`card ${c.rel} (#${c.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
|
|
@@ -19897,11 +20009,11 @@ function crossRefComplaints() {
|
|
|
19897
20009
|
const said3 = [];
|
|
19898
20010
|
const live = liveIds();
|
|
19899
20011
|
for (const file of walkMd(TODO)) {
|
|
19900
|
-
const base =
|
|
20012
|
+
const base = path57.basename(file);
|
|
19901
20013
|
if (base === "README.md") continue;
|
|
19902
|
-
const ownerId = base === "root.md" ? idPrefix(
|
|
20014
|
+
const ownerId = base === "root.md" ? idPrefix(path57.basename(path57.dirname(file))) : idPrefix(base);
|
|
19903
20015
|
if (ownerId == null) continue;
|
|
19904
|
-
const { meta } = parseFrontmatter(
|
|
20016
|
+
const { meta } = parseFrontmatter(fs52.readFileSync(file, "utf8"));
|
|
19905
20017
|
if (!meta) continue;
|
|
19906
20018
|
for (const field2 of ["blocked_by", "related"]) {
|
|
19907
20019
|
for (const ref of meta[field2] || []) {
|
|
@@ -19914,11 +20026,11 @@ function crossRefComplaints() {
|
|
|
19914
20026
|
return said3;
|
|
19915
20027
|
}
|
|
19916
20028
|
function reconcileBoard() {
|
|
19917
|
-
if (!
|
|
20029
|
+
if (!fs52.existsSync(README)) return;
|
|
19918
20030
|
for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
|
|
19919
20031
|
}
|
|
19920
20032
|
function boardComplaints() {
|
|
19921
|
-
if (!
|
|
20033
|
+
if (!fs52.existsSync(README)) return [];
|
|
19922
20034
|
try {
|
|
19923
20035
|
return [...readmeComplaints(false), ...crossRefComplaints()];
|
|
19924
20036
|
} catch {
|
|
@@ -19938,8 +20050,8 @@ var init_reconcile = __esm({
|
|
|
19938
20050
|
});
|
|
19939
20051
|
|
|
19940
20052
|
// src/commands/card.ts
|
|
19941
|
-
import
|
|
19942
|
-
import
|
|
20053
|
+
import fs53 from "node:fs";
|
|
20054
|
+
import path58 from "node:path";
|
|
19943
20055
|
function defaultBody() {
|
|
19944
20056
|
return [
|
|
19945
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>",
|
|
@@ -19965,7 +20077,7 @@ function bodyFromFile(opts) {
|
|
|
19965
20077
|
if (opts.body === false) die("pass --body-file or --no-body, not both");
|
|
19966
20078
|
let text5;
|
|
19967
20079
|
try {
|
|
19968
|
-
text5 =
|
|
20080
|
+
text5 = fs53.readFileSync(opts.bodyFile, "utf8");
|
|
19969
20081
|
} catch {
|
|
19970
20082
|
die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
|
|
19971
20083
|
}
|
|
@@ -19997,20 +20109,20 @@ function cmdCreate(opts) {
|
|
|
19997
20109
|
const start = opts.id;
|
|
19998
20110
|
const slug2 = slugify(opts.slug !== void 0 ? opts.slug : title);
|
|
19999
20111
|
const fileRel = `${start}-${slug2}.md`;
|
|
20000
|
-
const file =
|
|
20112
|
+
const file = path58.join(TODO, fileRel);
|
|
20001
20113
|
const held4 = locate(start) ?? locateArchived(start);
|
|
20002
|
-
if (held4 &&
|
|
20114
|
+
if (held4 && path58.basename(held4.target) === `${start}-${slug2}.md`) {
|
|
20003
20115
|
say(start);
|
|
20004
20116
|
say(` ${rel(held4.target)} was already written`);
|
|
20005
20117
|
return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
|
|
20006
20118
|
}
|
|
20007
20119
|
if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
|
|
20008
|
-
if (
|
|
20120
|
+
if (fs53.existsSync(file)) die(`${rel(file)} already exists \u2014 pick a different --slug`);
|
|
20009
20121
|
countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
|
|
20010
20122
|
const meta = { title, priority, status: "todo", blocked_by, related, modules, workflow, triage, source, questions };
|
|
20011
20123
|
const scaffolded = !written && opts.body !== false;
|
|
20012
20124
|
const body = written ?? (scaffolded ? defaultBody() : "");
|
|
20013
|
-
|
|
20125
|
+
fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n\n" + body);
|
|
20014
20126
|
const indexed = addReadmeRef(start, title, fileRel);
|
|
20015
20127
|
say(start);
|
|
20016
20128
|
say(
|
|
@@ -20048,8 +20160,8 @@ function cmdUpdate(id, flags) {
|
|
|
20048
20160
|
if (creating) die(creating, { kind: "card-being-created", id });
|
|
20049
20161
|
const found2 = locate(id);
|
|
20050
20162
|
if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
|
|
20051
|
-
const file = found2.kind === "group" ?
|
|
20052
|
-
const { meta, body } = parseFrontmatter(
|
|
20163
|
+
const file = found2.kind === "group" ? path58.join(found2.target, "root.md") : found2.target;
|
|
20164
|
+
const { meta, body } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
|
|
20053
20165
|
if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
|
|
20054
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");
|
|
20055
20167
|
if (flags.related !== void 0 && flags.addRelated !== void 0) die("--related replaces the list and --add-related appends to it \u2014 pass one");
|
|
@@ -20129,26 +20241,26 @@ function cmdUpdate(id, flags) {
|
|
|
20129
20241
|
meta.status = "todo";
|
|
20130
20242
|
changes.push("status\u2192todo (open questions)");
|
|
20131
20243
|
}
|
|
20132
|
-
const curRel =
|
|
20244
|
+
const curRel = path58.relative(TODO, file);
|
|
20133
20245
|
const isSubtask = found2.kind === "file" && enclosingGroupRoot(file) !== null;
|
|
20134
|
-
let base =
|
|
20246
|
+
let base = path58.basename(file);
|
|
20135
20247
|
if (flags.slug !== void 0) {
|
|
20136
20248
|
if (found2.kind === "group") die("renaming a group root by script is not supported");
|
|
20137
20249
|
base = `${id}-${slugify(flags.slug)}.md`;
|
|
20138
20250
|
}
|
|
20139
|
-
const destRel =
|
|
20140
|
-
const dest =
|
|
20251
|
+
const destRel = path58.join(path58.dirname(curRel), base);
|
|
20252
|
+
const dest = path58.join(TODO, destRel);
|
|
20141
20253
|
const moving = dest !== file;
|
|
20142
|
-
if (moving &&
|
|
20143
|
-
|
|
20144
|
-
if (moving)
|
|
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);
|
|
20145
20257
|
if (isSubtask) {
|
|
20146
20258
|
if (moving || changes.includes("title")) repointReadmeLink(id, curRel, destRel, meta.title);
|
|
20147
|
-
if (moving) changes.push(`renamed \u2192 ${destRel.split(
|
|
20259
|
+
if (moving) changes.push(`renamed \u2192 ${destRel.split(path58.sep).join("/")}`);
|
|
20148
20260
|
} else if (moving) {
|
|
20149
20261
|
stripReadmeRefs({ kind: "file", rel: curRel });
|
|
20150
20262
|
addReadmeRef(id, meta.title, destRel);
|
|
20151
|
-
changes.push(`renamed \u2192 ${destRel.split(
|
|
20263
|
+
changes.push(`renamed \u2192 ${destRel.split(path58.sep).join("/")}`);
|
|
20152
20264
|
} else if (changes.includes("title")) {
|
|
20153
20265
|
stripReadmeRefs({ kind: "file", rel: curRel });
|
|
20154
20266
|
addReadmeRef(id, meta.title, curRel);
|
|
@@ -20160,8 +20272,8 @@ function cmdUpdateQuestions(id, input) {
|
|
|
20160
20272
|
const ops = readQuestionOps(input.ops ?? []);
|
|
20161
20273
|
const found2 = locate(id);
|
|
20162
20274
|
if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
|
|
20163
|
-
const file = found2.kind === "group" ?
|
|
20164
|
-
const { meta, body } = parseFrontmatter(
|
|
20275
|
+
const file = found2.kind === "group" ? path58.join(found2.target, "root.md") : found2.target;
|
|
20276
|
+
const { meta, body } = parseFrontmatter(fs53.readFileSync(file, "utf8"));
|
|
20165
20277
|
if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
|
|
20166
20278
|
if (insideRun() && ops.some((op) => op.kind === "skip" || op.kind === "unskip")) {
|
|
20167
20279
|
die("only the user skips or reopens a question \u2014 a run leaves questions for them to answer");
|
|
@@ -20234,7 +20346,7 @@ function cmdUpdateQuestions(id, input) {
|
|
|
20234
20346
|
meta.status = "todo";
|
|
20235
20347
|
changes.push("status\u2192todo (open questions)");
|
|
20236
20348
|
}
|
|
20237
|
-
|
|
20349
|
+
fs53.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
|
|
20238
20350
|
for (const kind of closed2) countBoardEvent(kind);
|
|
20239
20351
|
settleDelivery2(id, skipped, unskipped);
|
|
20240
20352
|
say(
|
|
@@ -20308,13 +20420,13 @@ var init_config_template = __esm({
|
|
|
20308
20420
|
});
|
|
20309
20421
|
|
|
20310
20422
|
// src/lib/agent/local.ts
|
|
20311
|
-
import
|
|
20312
|
-
import
|
|
20423
|
+
import fs54 from "node:fs";
|
|
20424
|
+
import path59 from "node:path";
|
|
20313
20425
|
function takeLocalModels(board2) {
|
|
20314
|
-
const file =
|
|
20426
|
+
const file = path59.join(board2, ".local.json");
|
|
20315
20427
|
let held4;
|
|
20316
20428
|
try {
|
|
20317
|
-
held4 = configBlock(JSON.parse(
|
|
20429
|
+
held4 = configBlock(JSON.parse(fs54.readFileSync(file, "utf8")));
|
|
20318
20430
|
} catch {
|
|
20319
20431
|
return {};
|
|
20320
20432
|
}
|
|
@@ -20332,7 +20444,7 @@ function takeLocalModels(board2) {
|
|
|
20332
20444
|
}
|
|
20333
20445
|
if (!Object.keys(agents).length) return out;
|
|
20334
20446
|
delete held4.agents;
|
|
20335
|
-
|
|
20447
|
+
fs54.writeFileSync(file, JSON.stringify(held4, null, 2) + "\n");
|
|
20336
20448
|
return out;
|
|
20337
20449
|
}
|
|
20338
20450
|
var LOCAL_IGNORE_LINE;
|
|
@@ -20393,12 +20505,12 @@ var init_identity2 = __esm({
|
|
|
20393
20505
|
});
|
|
20394
20506
|
|
|
20395
20507
|
// src/lib/signals/migrate.ts
|
|
20396
|
-
import
|
|
20397
|
-
import
|
|
20508
|
+
import fs55 from "node:fs";
|
|
20509
|
+
import path60 from "node:path";
|
|
20398
20510
|
function readHandled() {
|
|
20399
20511
|
let text5;
|
|
20400
20512
|
try {
|
|
20401
|
-
text5 =
|
|
20513
|
+
text5 = fs55.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
|
|
20402
20514
|
} catch {
|
|
20403
20515
|
return [];
|
|
20404
20516
|
}
|
|
@@ -20415,57 +20527,57 @@ function readHandled() {
|
|
|
20415
20527
|
return held4;
|
|
20416
20528
|
}
|
|
20417
20529
|
function lift(from, into) {
|
|
20418
|
-
|
|
20419
|
-
|
|
20530
|
+
fs55.mkdirSync(into, { recursive: true });
|
|
20531
|
+
fs55.renameSync(from, path60.join(into, freeName(into, path60.basename(from))));
|
|
20420
20532
|
}
|
|
20421
20533
|
function repoint(dir, from, into) {
|
|
20422
20534
|
let entries;
|
|
20423
20535
|
try {
|
|
20424
|
-
entries =
|
|
20536
|
+
entries = fs55.readdirSync(dir, { withFileTypes: true });
|
|
20425
20537
|
} catch {
|
|
20426
20538
|
return;
|
|
20427
20539
|
}
|
|
20428
20540
|
for (const entry of entries) {
|
|
20429
20541
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
20430
|
-
const file =
|
|
20431
|
-
const text5 =
|
|
20432
|
-
if (text5.includes(from))
|
|
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));
|
|
20433
20545
|
}
|
|
20434
20546
|
}
|
|
20435
20547
|
function dropIfEmpty2(dir) {
|
|
20436
20548
|
try {
|
|
20437
|
-
|
|
20549
|
+
fs55.rmdirSync(dir);
|
|
20438
20550
|
} catch {
|
|
20439
20551
|
}
|
|
20440
20552
|
}
|
|
20441
20553
|
function liftInbox() {
|
|
20442
|
-
if (!
|
|
20443
|
-
const oldFiles =
|
|
20444
|
-
if (
|
|
20445
|
-
for (const entry of
|
|
20446
|
-
if (entry.isFile()) lift(
|
|
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);
|
|
20447
20559
|
}
|
|
20448
20560
|
dropIfEmpty2(oldFiles);
|
|
20449
20561
|
}
|
|
20450
20562
|
const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
|
|
20451
|
-
for (const entry of
|
|
20563
|
+
for (const entry of fs55.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
|
|
20452
20564
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
20453
|
-
const from =
|
|
20565
|
+
const from = path60.join(SIGNALS_OLD_INBOX, entry.name);
|
|
20454
20566
|
const item = parse(from);
|
|
20455
20567
|
if (item && held4.has(item.sourceId)) {
|
|
20456
|
-
|
|
20568
|
+
fs55.rmSync(from, { force: true });
|
|
20457
20569
|
continue;
|
|
20458
20570
|
}
|
|
20459
20571
|
if (item) held4.add(item.sourceId);
|
|
20460
20572
|
lift(from, TRIAGE);
|
|
20461
20573
|
}
|
|
20462
|
-
const wasAt = asWritten(
|
|
20574
|
+
const wasAt = asWritten(path60.join(SIGNALS_OLD_INBOX, "files"));
|
|
20463
20575
|
const nowAt = asWritten(SIGNALS_FILES);
|
|
20464
20576
|
for (const dir of [TRIAGE, SIGNALS_ARCHIVED, SIGNALS_DISMISSED]) repoint(dir, wasAt, nowAt);
|
|
20465
20577
|
dropIfEmpty2(SIGNALS_OLD_INBOX);
|
|
20466
20578
|
}
|
|
20467
20579
|
function liftHandled() {
|
|
20468
|
-
if (!
|
|
20580
|
+
if (!fs55.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
20469
20581
|
const lines = readHandled();
|
|
20470
20582
|
const held4 = /* @__PURE__ */ new Set([
|
|
20471
20583
|
...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
|
|
@@ -20475,7 +20587,7 @@ function liftHandled() {
|
|
|
20475
20587
|
for (const { sourceId, when } of lines) {
|
|
20476
20588
|
if (held4.has(sourceId)) continue;
|
|
20477
20589
|
held4.add(sourceId);
|
|
20478
|
-
|
|
20590
|
+
fs55.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
|
|
20479
20591
|
const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
|
|
20480
20592
|
const front = [
|
|
20481
20593
|
"---",
|
|
@@ -20485,13 +20597,13 @@ function liftHandled() {
|
|
|
20485
20597
|
"---",
|
|
20486
20598
|
""
|
|
20487
20599
|
];
|
|
20488
|
-
|
|
20600
|
+
fs55.writeFileSync(path60.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
|
|
20489
20601
|
`);
|
|
20490
20602
|
}
|
|
20491
|
-
|
|
20603
|
+
fs55.rmSync(SIGNALS_OLD_HANDLED, { force: true });
|
|
20492
20604
|
}
|
|
20493
20605
|
function migrateTriage() {
|
|
20494
|
-
if (!
|
|
20606
|
+
if (!fs55.existsSync(SIGNALS_OLD_INBOX) && !fs55.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
20495
20607
|
try {
|
|
20496
20608
|
liftInbox();
|
|
20497
20609
|
liftHandled();
|
|
@@ -20506,13 +20618,13 @@ var init_migrate = __esm({
|
|
|
20506
20618
|
init_yaml();
|
|
20507
20619
|
init_inbox();
|
|
20508
20620
|
HANDLED_LINE = /^-\s+(.+?)\s+—\s+(.+)$/;
|
|
20509
|
-
asWritten = (dir) => `${rel(dir).split(
|
|
20621
|
+
asWritten = (dir) => `${rel(dir).split(path60.sep).join("/")}/`;
|
|
20510
20622
|
}
|
|
20511
20623
|
});
|
|
20512
20624
|
|
|
20513
20625
|
// src/lib/signals/add.ts
|
|
20514
|
-
import
|
|
20515
|
-
import
|
|
20626
|
+
import fs56 from "node:fs";
|
|
20627
|
+
import path61 from "node:path";
|
|
20516
20628
|
import { createHash as createHash3 } from "node:crypto";
|
|
20517
20629
|
function linkTitle(url) {
|
|
20518
20630
|
let at;
|
|
@@ -20525,7 +20637,7 @@ function linkTitle(url) {
|
|
|
20525
20637
|
return oneLine(where) || url.slice(0, TITLE_MAX);
|
|
20526
20638
|
}
|
|
20527
20639
|
function asText(file) {
|
|
20528
|
-
const ext =
|
|
20640
|
+
const ext = path61.extname(file.name).toLowerCase();
|
|
20529
20641
|
if (!file.type.startsWith("text/") && file.type !== "application/json" && !TEXT_EXTENSIONS.has(ext)) return null;
|
|
20530
20642
|
try {
|
|
20531
20643
|
const text5 = new TextDecoder("utf-8", { fatal: true }).decode(file.data);
|
|
@@ -20535,9 +20647,9 @@ function asText(file) {
|
|
|
20535
20647
|
}
|
|
20536
20648
|
}
|
|
20537
20649
|
function fileName2(name, data) {
|
|
20538
|
-
const base =
|
|
20539
|
-
const ext =
|
|
20540
|
-
const word =
|
|
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";
|
|
20541
20653
|
const hash2 = createHash3("sha256").update(data).digest("hex").slice(0, 8);
|
|
20542
20654
|
return `${word}-${hash2}${ext}`;
|
|
20543
20655
|
}
|
|
@@ -20546,9 +20658,9 @@ function addToInbox(drop) {
|
|
|
20546
20658
|
const typed = (drop.text ?? "").trim();
|
|
20547
20659
|
const file = drop.file;
|
|
20548
20660
|
if (!typed && !file) return { ok: false, error: "nothing to add \u2014 paste a link or some text, or drop a file." };
|
|
20549
|
-
if (file && file.data.length === 0) return { ok: false, error: `${
|
|
20661
|
+
if (file && file.data.length === 0) return { ok: false, error: `${path61.basename(file.name)} is empty.` };
|
|
20550
20662
|
if (file && file.data.length > MAX_BYTES) {
|
|
20551
|
-
return { ok: false, error: `${
|
|
20663
|
+
return { ok: false, error: `${path61.basename(file.name)} is over ${MAX_BYTES / 1024 / 1024} MB \u2014 too big for the board.` };
|
|
20552
20664
|
}
|
|
20553
20665
|
const read4 = describe(typed, file);
|
|
20554
20666
|
const keep2 = read4.keep;
|
|
@@ -20570,8 +20682,8 @@ ${incoming.summary}`);
|
|
|
20570
20682
|
if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
|
|
20571
20683
|
try {
|
|
20572
20684
|
if (keep2) {
|
|
20573
|
-
|
|
20574
|
-
|
|
20685
|
+
fs56.mkdirSync(SIGNALS_FILES, { recursive: true });
|
|
20686
|
+
fs56.writeFileSync(keep2.at, keep2.data);
|
|
20575
20687
|
}
|
|
20576
20688
|
return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
|
|
20577
20689
|
} catch (e) {
|
|
@@ -20585,7 +20697,7 @@ function describe(typed, file) {
|
|
|
20585
20697
|
return only ? [only] : [];
|
|
20586
20698
|
};
|
|
20587
20699
|
if (file) {
|
|
20588
|
-
const name =
|
|
20700
|
+
const name = path61.basename(file.name);
|
|
20589
20701
|
const text5 = asText(file);
|
|
20590
20702
|
const note = typed ? `
|
|
20591
20703
|
|
|
@@ -20597,7 +20709,7 @@ ${typed}` : "";
|
|
|
20597
20709
|
const at = keepAt(file);
|
|
20598
20710
|
return {
|
|
20599
20711
|
incoming: {
|
|
20600
|
-
title:
|
|
20712
|
+
title: path61.basename(name, path61.extname(name)) || name,
|
|
20601
20713
|
summary: `${name} \u2014 ${boardRel2(at)}${note}`,
|
|
20602
20714
|
...named2
|
|
20603
20715
|
},
|
|
@@ -20635,73 +20747,73 @@ var init_add = __esm({
|
|
|
20635
20747
|
MAX_BYTES = 25 * 1024 * 1024;
|
|
20636
20748
|
TITLE_MAX = 120;
|
|
20637
20749
|
TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".md", ".markdown", ".txt", ".text", ".csv", ".json", ".yml", ".yaml", ".log"]);
|
|
20638
|
-
boardRel2 = (file) => rel(file).split(
|
|
20750
|
+
boardRel2 = (file) => rel(file).split(path61.sep).join("/");
|
|
20639
20751
|
oneLine = (text5) => {
|
|
20640
20752
|
const first = text5.split("\n").find((line) => line.trim()) ?? "";
|
|
20641
20753
|
const clean = first.replace(/^#+\s*/, "").trim();
|
|
20642
20754
|
return clean.length > TITLE_MAX ? `${clean.slice(0, TITLE_MAX - 1).trimEnd()}\u2026` : clean;
|
|
20643
20755
|
};
|
|
20644
|
-
keepAt = (file) =>
|
|
20756
|
+
keepAt = (file) => path61.join(SIGNALS_FILES, fileName2(file.name, file.data));
|
|
20645
20757
|
}
|
|
20646
20758
|
});
|
|
20647
20759
|
|
|
20648
20760
|
// src/lib/recurring.ts
|
|
20649
|
-
import
|
|
20650
|
-
import
|
|
20761
|
+
import fs57 from "node:fs";
|
|
20762
|
+
import path62 from "node:path";
|
|
20651
20763
|
function migratePruneMemoryCard() {
|
|
20652
20764
|
const dir = recurringDir();
|
|
20653
20765
|
let names4;
|
|
20654
20766
|
try {
|
|
20655
|
-
names4 =
|
|
20767
|
+
names4 = fs57.readdirSync(dir);
|
|
20656
20768
|
} catch {
|
|
20657
20769
|
return null;
|
|
20658
20770
|
}
|
|
20659
20771
|
const name = names4.find((entry) => entry.endsWith(`-${PRUNE_SLUG}.md`));
|
|
20660
20772
|
if (!name) return null;
|
|
20661
|
-
const file =
|
|
20773
|
+
const file = path62.join(dir, name);
|
|
20662
20774
|
try {
|
|
20663
|
-
const { meta } = parseFrontmatter(
|
|
20775
|
+
const { meta } = parseFrontmatter(fs57.readFileSync(file, "utf8"));
|
|
20664
20776
|
const cadence = meta?.cadence;
|
|
20665
20777
|
if (typeof cadence === "string") adoptMemoryPruneCadence(cadence);
|
|
20666
20778
|
} catch {
|
|
20667
20779
|
}
|
|
20668
|
-
|
|
20780
|
+
fs57.rmSync(file, { force: true });
|
|
20669
20781
|
return rel(file);
|
|
20670
20782
|
}
|
|
20671
20783
|
function legacyCards() {
|
|
20672
20784
|
const dir = recurringDir();
|
|
20673
|
-
if (!
|
|
20785
|
+
if (!fs57.existsSync(dir)) return [];
|
|
20674
20786
|
const cards = [];
|
|
20675
|
-
for (const entry of
|
|
20787
|
+
for (const entry of fs57.readdirSync(dir, { withFileTypes: true })) {
|
|
20676
20788
|
const id = idPrefix(entry.name);
|
|
20677
20789
|
if (id === null) continue;
|
|
20678
|
-
const full =
|
|
20790
|
+
const full = path62.join(dir, entry.name);
|
|
20679
20791
|
const slug2 = entry.name.replace(/\.md$/, "").replace(/^\d+-?/, "");
|
|
20680
20792
|
if (entry.isFile() && entry.name.endsWith(".md")) cards.push({ id, slug: slug2, file: full });
|
|
20681
|
-
else if (entry.isDirectory() &&
|
|
20682
|
-
cards.push({ id, slug: slug2, file:
|
|
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 });
|
|
20683
20795
|
}
|
|
20684
20796
|
}
|
|
20685
20797
|
return cards.sort((a, b) => a.id - b.id);
|
|
20686
20798
|
}
|
|
20687
20799
|
function mergeInto2(from, to, skip = []) {
|
|
20688
|
-
|
|
20689
|
-
for (const entry of
|
|
20800
|
+
fs57.mkdirSync(to, { recursive: true });
|
|
20801
|
+
for (const entry of fs57.readdirSync(from, { withFileTypes: true })) {
|
|
20690
20802
|
if (skip.includes(entry.name)) continue;
|
|
20691
|
-
const source =
|
|
20692
|
-
const target =
|
|
20693
|
-
if (!
|
|
20694
|
-
else if (entry.isDirectory() &&
|
|
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);
|
|
20695
20807
|
}
|
|
20696
|
-
if (isEmpty(from))
|
|
20808
|
+
if (isEmpty(from)) fs57.rmSync(from, { recursive: true, force: true });
|
|
20697
20809
|
}
|
|
20698
20810
|
function moveSideFolders() {
|
|
20699
20811
|
const dir = recurringDir();
|
|
20700
|
-
for (const entry of
|
|
20812
|
+
for (const entry of fs57.readdirSync(dir, { withFileTypes: true })) {
|
|
20701
20813
|
if (!entry.isDirectory() || idPrefix(entry.name) !== null) continue;
|
|
20702
|
-
const from =
|
|
20703
|
-
if (isEmpty(from))
|
|
20704
|
-
else mergeInto2(from,
|
|
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));
|
|
20705
20817
|
}
|
|
20706
20818
|
}
|
|
20707
20819
|
function sections(body) {
|
|
@@ -20751,8 +20863,8 @@ function agentName(card, text5) {
|
|
|
20751
20863
|
const known2 = /* @__PURE__ */ new Set([...specAgentCatalog().agents.map((a) => a.name), ...ROLE_NAMES]);
|
|
20752
20864
|
for (const name of [slug2, `${slug2}-${card.id}`]) {
|
|
20753
20865
|
if (!AGENT_NAME.test(name)) continue;
|
|
20754
|
-
const file =
|
|
20755
|
-
const written =
|
|
20866
|
+
const file = path62.join(AGENTS, name, AGENT_FILE3);
|
|
20867
|
+
const written = fs57.existsSync(file) ? fs57.readFileSync(file, "utf8") : null;
|
|
20756
20868
|
if (written === text5(name)) return name;
|
|
20757
20869
|
if (written === null && !known2.has(name)) return name;
|
|
20758
20870
|
}
|
|
@@ -20769,11 +20881,11 @@ ${q.options.map((o) => `- ${o}`).join("\n")}` : "";
|
|
|
20769
20881
|
function removeCard(card) {
|
|
20770
20882
|
dropCrossRefs(card.id);
|
|
20771
20883
|
const target = card.folder ?? card.file;
|
|
20772
|
-
stripReadmeRefs({ kind: card.folder ? "group" : "file", rel:
|
|
20773
|
-
|
|
20884
|
+
stripReadmeRefs({ kind: card.folder ? "group" : "file", rel: path62.relative(TODO, target).split(path62.sep).join("/") });
|
|
20885
|
+
fs57.rmSync(target, { recursive: true, force: true });
|
|
20774
20886
|
}
|
|
20775
20887
|
function migrateCard(card) {
|
|
20776
|
-
const { meta, body } = parseFrontmatter(
|
|
20888
|
+
const { meta, body } = parseFrontmatter(fs57.readFileSync(card.file, "utf8"));
|
|
20777
20889
|
if (!meta) throw new Error("its frontmatter cannot be read");
|
|
20778
20890
|
const raw = meta;
|
|
20779
20891
|
const said3 = (key) => typeof raw[key] === "string" ? raw[key].trim() : "";
|
|
@@ -20783,19 +20895,19 @@ function migrateCard(card) {
|
|
|
20783
20895
|
if (!flow) throw new Error("this board has no workflow to put it in");
|
|
20784
20896
|
const text5 = (name2) => agentText(name2, meta.title || card.slug, body);
|
|
20785
20897
|
const name = agentName(card, text5);
|
|
20786
|
-
const dir =
|
|
20787
|
-
const file =
|
|
20788
|
-
const madeDir = !
|
|
20789
|
-
const wrote = !
|
|
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);
|
|
20790
20902
|
try {
|
|
20791
|
-
|
|
20792
|
-
if (wrote)
|
|
20903
|
+
fs57.mkdirSync(dir, { recursive: true });
|
|
20904
|
+
if (wrote) fs57.writeFileSync(file, text5(name));
|
|
20793
20905
|
const adopted = adoptWorkflowScheduled(flow.id, name, { cadence, lastRun });
|
|
20794
20906
|
if (!adopted.ok) throw new Error(adopted.error);
|
|
20795
20907
|
questionsToTriage(meta, name);
|
|
20796
20908
|
} catch (e) {
|
|
20797
|
-
if (madeDir)
|
|
20798
|
-
else if (wrote)
|
|
20909
|
+
if (madeDir) fs57.rmSync(dir, { recursive: true, force: true });
|
|
20910
|
+
else if (wrote) fs57.rmSync(file, { force: true });
|
|
20799
20911
|
throw e;
|
|
20800
20912
|
}
|
|
20801
20913
|
if (card.folder) mergeInto2(card.folder, dir, ["root.md"]);
|
|
@@ -20805,7 +20917,7 @@ function migrateCard(card) {
|
|
|
20805
20917
|
function migrateRecurringCards() {
|
|
20806
20918
|
const done2 = { agents: [], removed: [], failed: [] };
|
|
20807
20919
|
const dir = recurringDir();
|
|
20808
|
-
if (!
|
|
20920
|
+
if (!fs57.existsSync(dir)) return done2;
|
|
20809
20921
|
migratePruneMemoryCard();
|
|
20810
20922
|
moveSideFolders();
|
|
20811
20923
|
for (const card of legacyCards()) {
|
|
@@ -20818,7 +20930,7 @@ function migrateRecurringCards() {
|
|
|
20818
20930
|
done2.failed.push({ card: rel(card.file), why: e instanceof Error ? e.message : String(e) });
|
|
20819
20931
|
}
|
|
20820
20932
|
}
|
|
20821
|
-
if (isEmpty(dir))
|
|
20933
|
+
if (isEmpty(dir)) fs57.rmSync(dir, { recursive: true, force: true });
|
|
20822
20934
|
return done2;
|
|
20823
20935
|
}
|
|
20824
20936
|
function recurringMigrationLines(done2) {
|
|
@@ -20851,14 +20963,14 @@ var init_recurring = __esm({
|
|
|
20851
20963
|
PRUNE_SLUG = "prune-the-memory";
|
|
20852
20964
|
FETCH_SLUG = "fetch-triage-items";
|
|
20853
20965
|
AGENT_FILE3 = "AGENT.md";
|
|
20854
|
-
recurringDir = () =>
|
|
20855
|
-
isEmpty = (dir) =>
|
|
20966
|
+
recurringDir = () => path62.join(TODO, LEGACY_RECURRING);
|
|
20967
|
+
isEmpty = (dir) => fs57.readdirSync(dir).every((name) => name === ".DS_Store");
|
|
20856
20968
|
SECTION = /^##\s+(.+?)\s*$/;
|
|
20857
20969
|
}
|
|
20858
20970
|
});
|
|
20859
20971
|
|
|
20860
20972
|
// src/commands/init.ts
|
|
20861
|
-
import
|
|
20973
|
+
import fs58 from "node:fs";
|
|
20862
20974
|
function boardReadme() {
|
|
20863
20975
|
return `# Board
|
|
20864
20976
|
|
|
@@ -20871,20 +20983,20 @@ _(none)_
|
|
|
20871
20983
|
`;
|
|
20872
20984
|
}
|
|
20873
20985
|
function writeConfigIfMissing() {
|
|
20874
|
-
if (
|
|
20875
|
-
|
|
20876
|
-
|
|
20986
|
+
if (fs58.existsSync(CONFIG)) return false;
|
|
20987
|
+
fs58.mkdirSync(KANBAN, { recursive: true });
|
|
20988
|
+
fs58.writeFileSync(CONFIG, CONFIG_TEMPLATE);
|
|
20877
20989
|
return true;
|
|
20878
20990
|
}
|
|
20879
20991
|
function writeModulesIfMissing() {
|
|
20880
|
-
if (
|
|
20881
|
-
|
|
20882
|
-
|
|
20992
|
+
if (fs58.existsSync(MODULES_MD)) return false;
|
|
20993
|
+
fs58.mkdirSync(KANBAN, { recursive: true });
|
|
20994
|
+
fs58.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
|
|
20883
20995
|
return true;
|
|
20884
20996
|
}
|
|
20885
20997
|
function writeGitignoreIfMissing() {
|
|
20886
|
-
|
|
20887
|
-
const text5 =
|
|
20998
|
+
fs58.mkdirSync(KANBAN, { recursive: true });
|
|
20999
|
+
const text5 = fs58.existsSync(KANBAN_GITIGNORE) ? fs58.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
|
|
20888
21000
|
const has = (rule) => text5.split("\n").some((line) => line.trim() === rule.line);
|
|
20889
21001
|
const missing = IGNORE_RULES.filter((rule) => !has(rule));
|
|
20890
21002
|
if (!missing.length) return false;
|
|
@@ -20892,37 +21004,37 @@ function writeGitignoreIfMissing() {
|
|
|
20892
21004
|
${rule.line}
|
|
20893
21005
|
`).join("");
|
|
20894
21006
|
const separator = !text5 || text5.endsWith("\n") ? "" : "\n";
|
|
20895
|
-
|
|
21007
|
+
fs58.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
|
|
20896
21008
|
return true;
|
|
20897
21009
|
}
|
|
20898
21010
|
function writeSkeletonIfMissing() {
|
|
20899
21011
|
const added = [];
|
|
20900
|
-
if (!
|
|
20901
|
-
|
|
21012
|
+
if (!fs58.existsSync(TODO)) {
|
|
21013
|
+
fs58.mkdirSync(TODO, { recursive: true });
|
|
20902
21014
|
added.push(`${rel(TODO)}/`);
|
|
20903
21015
|
}
|
|
20904
|
-
if (!
|
|
20905
|
-
|
|
21016
|
+
if (!fs58.existsSync(README)) {
|
|
21017
|
+
fs58.writeFileSync(README, boardReadme());
|
|
20906
21018
|
added.push(rel(README));
|
|
20907
21019
|
}
|
|
20908
21020
|
return added;
|
|
20909
21021
|
}
|
|
20910
21022
|
function retireReleases() {
|
|
20911
21023
|
const done2 = [];
|
|
20912
|
-
if (
|
|
20913
|
-
|
|
21024
|
+
if (fs58.existsSync(RELEASES)) {
|
|
21025
|
+
fs58.rmSync(RELEASES);
|
|
20914
21026
|
done2.push(`deleted ${rel(RELEASES)}`);
|
|
20915
21027
|
}
|
|
20916
21028
|
let cards = 0;
|
|
20917
21029
|
for (const dir of [TODO, ARCHIVE]) {
|
|
20918
|
-
if (!
|
|
21030
|
+
if (!fs58.existsSync(dir)) continue;
|
|
20919
21031
|
for (const file of walkMd(dir)) {
|
|
20920
|
-
const text5 =
|
|
21032
|
+
const text5 = fs58.readFileSync(file, "utf8");
|
|
20921
21033
|
const end2 = text5.startsWith("---\n") ? text5.indexOf("\n---", 3) : -1;
|
|
20922
21034
|
if (end2 < 0) continue;
|
|
20923
21035
|
const head = text5.slice(0, end2).replace(/\nrelease:[^\n]*/, "");
|
|
20924
21036
|
if (head.length === end2) continue;
|
|
20925
|
-
|
|
21037
|
+
fs58.writeFileSync(file, head + text5.slice(end2));
|
|
20926
21038
|
cards++;
|
|
20927
21039
|
}
|
|
20928
21040
|
}
|
|
@@ -20930,7 +21042,7 @@ function retireReleases() {
|
|
|
20930
21042
|
return done2.join(", ");
|
|
20931
21043
|
}
|
|
20932
21044
|
function cmdInit() {
|
|
20933
|
-
if (
|
|
21045
|
+
if (fs58.existsSync(KANBAN)) {
|
|
20934
21046
|
const added = [
|
|
20935
21047
|
...writeSkeletonIfMissing(),
|
|
20936
21048
|
writeConfigIfMissing() && rel(CONFIG),
|
|
@@ -20965,8 +21077,8 @@ function cmdInit() {
|
|
|
20965
21077
|
}
|
|
20966
21078
|
return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
|
|
20967
21079
|
}
|
|
20968
|
-
|
|
20969
|
-
|
|
21080
|
+
fs58.mkdirSync(TODO, { recursive: true });
|
|
21081
|
+
fs58.writeFileSync(README, boardReadme());
|
|
20970
21082
|
writeConfigIfMissing();
|
|
20971
21083
|
scaffoldProjectMemory();
|
|
20972
21084
|
writeModulesIfMissing();
|
|
@@ -21055,25 +21167,25 @@ var init_scheduled = __esm({
|
|
|
21055
21167
|
});
|
|
21056
21168
|
|
|
21057
21169
|
// src/lib/card-age.ts
|
|
21058
|
-
import
|
|
21059
|
-
import
|
|
21170
|
+
import fs59 from "node:fs";
|
|
21171
|
+
import path63 from "node:path";
|
|
21060
21172
|
function staleAfterIn(config) {
|
|
21061
21173
|
const days = Number(LINE.exec(config)?.[1]);
|
|
21062
21174
|
return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
|
|
21063
21175
|
}
|
|
21064
21176
|
function staleAfter() {
|
|
21065
|
-
if (!
|
|
21066
|
-
return staleAfterIn(
|
|
21177
|
+
if (!fs59.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
|
|
21178
|
+
return staleAfterIn(fs59.readFileSync(CONFIG, "utf8"));
|
|
21067
21179
|
}
|
|
21068
21180
|
function todoPathspec(top) {
|
|
21069
|
-
const from =
|
|
21070
|
-
if (!from || from.startsWith("..") ||
|
|
21071
|
-
return from.split(
|
|
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("/");
|
|
21072
21184
|
}
|
|
21073
21185
|
function cardFile2(spec, printed) {
|
|
21074
21186
|
const p = unquotePath(printed);
|
|
21075
21187
|
if (!p.startsWith(`${spec}/`)) return null;
|
|
21076
|
-
return
|
|
21188
|
+
return path63.join(TODO, ...p.slice(spec.length + 1).split("/"));
|
|
21077
21189
|
}
|
|
21078
21190
|
function dirtyCards(top, spec) {
|
|
21079
21191
|
const out = git(["status", "--porcelain", "--untracked-files=all", "--", spec], top);
|
|
@@ -21120,9 +21232,9 @@ var init_card_age = __esm({
|
|
|
21120
21232
|
gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
|
|
21121
21233
|
real = (p) => {
|
|
21122
21234
|
try {
|
|
21123
|
-
return
|
|
21235
|
+
return fs59.realpathSync(p);
|
|
21124
21236
|
} catch {
|
|
21125
|
-
return
|
|
21237
|
+
return path63.resolve(p);
|
|
21126
21238
|
}
|
|
21127
21239
|
};
|
|
21128
21240
|
unquotePath = (line) => {
|
|
@@ -21157,8 +21269,8 @@ var init_card_holds = __esm({
|
|
|
21157
21269
|
});
|
|
21158
21270
|
|
|
21159
21271
|
// src/commands/list.ts
|
|
21160
|
-
import
|
|
21161
|
-
import
|
|
21272
|
+
import fs60 from "node:fs";
|
|
21273
|
+
import path64 from "node:path";
|
|
21162
21274
|
function summaryLine(body) {
|
|
21163
21275
|
const lines = body.split("\n");
|
|
21164
21276
|
let i = 0;
|
|
@@ -21174,13 +21286,13 @@ function summaryLine(body) {
|
|
|
21174
21286
|
function openRows() {
|
|
21175
21287
|
const rows = [];
|
|
21176
21288
|
for (const file of walkMd(TODO)) {
|
|
21177
|
-
const base =
|
|
21289
|
+
const base = path64.basename(file);
|
|
21178
21290
|
if (base === "README.md") continue;
|
|
21179
21291
|
const isRoot = base === "root.md";
|
|
21180
|
-
const id = isRoot ? idPrefix(
|
|
21292
|
+
const id = isRoot ? idPrefix(path64.basename(path64.dirname(file))) : idPrefix(base);
|
|
21181
21293
|
if (id == null) continue;
|
|
21182
|
-
if (isLegacyRecurring(
|
|
21183
|
-
const { meta, body } = parseFrontmatter(
|
|
21294
|
+
if (isLegacyRecurring(path64.relative(TODO, file))) continue;
|
|
21295
|
+
const { meta, body } = parseFrontmatter(fs60.readFileSync(file, "utf8"));
|
|
21184
21296
|
rows.push({
|
|
21185
21297
|
id,
|
|
21186
21298
|
file,
|
|
@@ -21222,15 +21334,15 @@ function cmdStale(rows, all2, scope, mod) {
|
|
|
21222
21334
|
}
|
|
21223
21335
|
function archivedFiles() {
|
|
21224
21336
|
const files2 = /* @__PURE__ */ new Map();
|
|
21225
|
-
if (!
|
|
21337
|
+
if (!fs60.existsSync(ARCHIVE)) return files2;
|
|
21226
21338
|
for (const file of walkMd(ARCHIVE)) {
|
|
21227
|
-
const id = idPrefix(
|
|
21339
|
+
const id = idPrefix(path64.basename(file));
|
|
21228
21340
|
if (id !== null) files2.set(id, file);
|
|
21229
21341
|
}
|
|
21230
21342
|
for (const dir of walkDirs(ARCHIVE)) {
|
|
21231
|
-
const id = idPrefix(
|
|
21232
|
-
const root =
|
|
21233
|
-
if (id !== null &&
|
|
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);
|
|
21234
21346
|
}
|
|
21235
21347
|
return files2;
|
|
21236
21348
|
}
|
|
@@ -21341,14 +21453,14 @@ var init_list = __esm({
|
|
|
21341
21453
|
});
|
|
21342
21454
|
|
|
21343
21455
|
// src/commands/misc.ts
|
|
21344
|
-
import
|
|
21345
|
-
import
|
|
21456
|
+
import fs61 from "node:fs";
|
|
21457
|
+
import path65 from "node:path";
|
|
21346
21458
|
function extractOldMeta(text5, file) {
|
|
21347
21459
|
const grab = (re) => {
|
|
21348
21460
|
const m = text5.match(re);
|
|
21349
21461
|
return m ? m[1].trim() : null;
|
|
21350
21462
|
};
|
|
21351
|
-
const title = grab(/^#\s+(.+)$/m) || slugify(
|
|
21463
|
+
const title = grab(/^#\s+(.+)$/m) || slugify(path65.basename(file, ".md").replace(/^\d+-/, "")).replace(/-/g, " ");
|
|
21352
21464
|
const norm = (raw) => {
|
|
21353
21465
|
const v = (raw || "").toLowerCase();
|
|
21354
21466
|
return LEVELS.includes(v) ? v : "med";
|
|
@@ -21375,11 +21487,11 @@ function stripOldHeader(text5) {
|
|
|
21375
21487
|
}
|
|
21376
21488
|
function cmdMigrate(opts) {
|
|
21377
21489
|
const dry = opts.dryRun === true;
|
|
21378
|
-
const files2 = walkMd(TODO).filter((f) =>
|
|
21490
|
+
const files2 = walkMd(TODO).filter((f) => path65.basename(f) !== "README.md");
|
|
21379
21491
|
let changed = 0;
|
|
21380
21492
|
let skipped = 0;
|
|
21381
21493
|
for (const file of files2) {
|
|
21382
|
-
const text5 =
|
|
21494
|
+
const text5 = fs61.readFileSync(file, "utf8");
|
|
21383
21495
|
if (text5.trimStart().startsWith("---")) {
|
|
21384
21496
|
skipped++;
|
|
21385
21497
|
continue;
|
|
@@ -21388,7 +21500,7 @@ function cmdMigrate(opts) {
|
|
|
21388
21500
|
const out = serializeFrontmatter(meta) + "\n\n" + stripOldHeader(text5).replace(/^\n+/, "");
|
|
21389
21501
|
if (dry) say(`would migrate ${rel(file)} (priority=${meta.priority})`);
|
|
21390
21502
|
else {
|
|
21391
|
-
|
|
21503
|
+
fs61.writeFileSync(file, out.endsWith("\n") ? out : out + "\n");
|
|
21392
21504
|
say(`migrated ${rel(file)}`);
|
|
21393
21505
|
}
|
|
21394
21506
|
changed++;
|
|
@@ -21409,10 +21521,10 @@ var init_misc = __esm({
|
|
|
21409
21521
|
});
|
|
21410
21522
|
|
|
21411
21523
|
// src/lib/group-close.ts
|
|
21412
|
-
import
|
|
21524
|
+
import fs62 from "node:fs";
|
|
21413
21525
|
function groupCloses(rootFile) {
|
|
21414
21526
|
try {
|
|
21415
|
-
return groupCloseOf(
|
|
21527
|
+
return groupCloseOf(fs62.readFileSync(rootFile, "utf8"));
|
|
21416
21528
|
} catch {
|
|
21417
21529
|
return false;
|
|
21418
21530
|
}
|
|
@@ -21425,12 +21537,12 @@ var init_group_close = __esm({
|
|
|
21425
21537
|
});
|
|
21426
21538
|
|
|
21427
21539
|
// src/commands/remove.ts
|
|
21428
|
-
import
|
|
21429
|
-
import
|
|
21540
|
+
import fs63 from "node:fs";
|
|
21541
|
+
import path66 from "node:path";
|
|
21430
21542
|
function leavingIds(id, found2) {
|
|
21431
21543
|
const ids = /* @__PURE__ */ new Set([id]);
|
|
21432
21544
|
if (found2.kind === "group") {
|
|
21433
|
-
const names4 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f) =>
|
|
21545
|
+
const names4 = [...walkMd(found2.target), ...walkDirs(found2.target)].map((f) => path66.basename(f));
|
|
21434
21546
|
for (const name of names4) {
|
|
21435
21547
|
const n = idPrefix(name);
|
|
21436
21548
|
if (n !== null) ids.add(n);
|
|
@@ -21442,10 +21554,10 @@ function findMentions(ids) {
|
|
|
21442
21554
|
const hits = [];
|
|
21443
21555
|
const re = new RegExp(ids.map((id) => `#${id}(?!\\d)`).join("|"));
|
|
21444
21556
|
for (const dir of [TODO, MEMORY]) {
|
|
21445
|
-
if (!
|
|
21557
|
+
if (!fs63.existsSync(dir)) continue;
|
|
21446
21558
|
for (const file of walkMd(dir)) {
|
|
21447
|
-
if (
|
|
21448
|
-
const lines =
|
|
21559
|
+
if (path66.basename(file) === "README.md") continue;
|
|
21560
|
+
const lines = fs63.readFileSync(file, "utf8").split("\n");
|
|
21449
21561
|
const fmEnd = frontmatterEnd(lines);
|
|
21450
21562
|
lines.forEach((line, i) => {
|
|
21451
21563
|
if (!re.test(line)) return;
|
|
@@ -21461,12 +21573,12 @@ function findMentions(ids) {
|
|
|
21461
21573
|
return hits;
|
|
21462
21574
|
}
|
|
21463
21575
|
function leavingCards(id, found2) {
|
|
21464
|
-
const own = found2.kind === "group" ?
|
|
21576
|
+
const own = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
|
|
21465
21577
|
const cards = [{ id, file: own }];
|
|
21466
21578
|
if (found2.kind !== "group") return cards;
|
|
21467
21579
|
for (const file of walkMd(found2.target)) {
|
|
21468
21580
|
if (file === own) continue;
|
|
21469
|
-
const n = idPrefix(
|
|
21581
|
+
const n = idPrefix(path66.basename(file));
|
|
21470
21582
|
if (n !== null) cards.push({ id: n, file });
|
|
21471
21583
|
}
|
|
21472
21584
|
return cards;
|
|
@@ -21475,10 +21587,10 @@ function stampLeaving(cards, rejection) {
|
|
|
21475
21587
|
const day = formatDay();
|
|
21476
21588
|
const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() ? "agent" : "user" } : rejection && { reason: rejection.reason };
|
|
21477
21589
|
for (const card of cards) {
|
|
21478
|
-
if (!
|
|
21479
|
-
const text5 =
|
|
21590
|
+
if (!fs63.existsSync(card.file)) continue;
|
|
21591
|
+
const text5 = fs63.readFileSync(card.file, "utf8");
|
|
21480
21592
|
const stamped = stampLeavingIn(text5, day, stamp4);
|
|
21481
|
-
if (stamped !== text5)
|
|
21593
|
+
if (stamped !== text5) fs63.writeFileSync(card.file, stamped);
|
|
21482
21594
|
}
|
|
21483
21595
|
}
|
|
21484
21596
|
function unfinishedDelivery(id) {
|
|
@@ -21494,7 +21606,7 @@ function unfinishedDelivery(id) {
|
|
|
21494
21606
|
}[gap];
|
|
21495
21607
|
return `#${id} is not finished: ${what}.`;
|
|
21496
21608
|
}
|
|
21497
|
-
const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !
|
|
21609
|
+
const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs63.existsSync(path66.join(ASSETS, src.slice(".assets/".length))));
|
|
21498
21610
|
return missing ? `#${id} is not finished: ${missing} is not on this machine.` : null;
|
|
21499
21611
|
}
|
|
21500
21612
|
function agentDecisions(text5) {
|
|
@@ -21521,8 +21633,8 @@ function removeCard2(id, metric, options) {
|
|
|
21521
21633
|
const unfinished = metric === "completed" ? unfinishedDelivery(id) : null;
|
|
21522
21634
|
if (unfinished) die(unfinished, { kind: "plan-delivery-unfinished" });
|
|
21523
21635
|
const dest = options.cleanupDiscarded && locateArchived(id) ? null : archiveDest(found2);
|
|
21524
|
-
const cardFile3 = found2.kind === "group" ?
|
|
21525
|
-
const cardText =
|
|
21636
|
+
const cardFile3 = found2.kind === "group" ? path66.join(found2.target, "root.md") : found2.target;
|
|
21637
|
+
const cardText = fs63.existsSync(cardFile3) ? fs63.readFileSync(cardFile3, "utf8") : "";
|
|
21526
21638
|
const { meta: cardMeta3 } = parseFrontmatter(cardText);
|
|
21527
21639
|
const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f) => f !== cardFile3).map((f) => rel(f)).sort() : [];
|
|
21528
21640
|
const leftIds = leavingIds(id, found2);
|
|
@@ -21553,10 +21665,10 @@ function removeCard2(id, metric, options) {
|
|
|
21553
21665
|
const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
|
|
21554
21666
|
if (dest) {
|
|
21555
21667
|
stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
|
|
21556
|
-
|
|
21557
|
-
|
|
21668
|
+
fs63.mkdirSync(ARCHIVE, { recursive: true });
|
|
21669
|
+
fs63.renameSync(found2.target, dest);
|
|
21558
21670
|
} else {
|
|
21559
|
-
|
|
21671
|
+
fs63.rmSync(found2.target, { recursive: true, force: true });
|
|
21560
21672
|
}
|
|
21561
21673
|
const removedRefs = stripReadmeRefs(found2);
|
|
21562
21674
|
let marked2 = null;
|
|
@@ -21605,14 +21717,14 @@ function removeCard2(id, metric, options) {
|
|
|
21605
21717
|
};
|
|
21606
21718
|
}
|
|
21607
21719
|
function closeGroup(rootFile) {
|
|
21608
|
-
const rootId = idPrefix(
|
|
21720
|
+
const rootId = idPrefix(path66.basename(path66.dirname(rootFile)));
|
|
21609
21721
|
if (rootId === null) return null;
|
|
21610
21722
|
if (runnerProject(KANBAN)) return null;
|
|
21611
21723
|
if (!groupCloses(rootFile)) return null;
|
|
21612
21724
|
say(`
|
|
21613
21725
|
every subtask line on #${rootId} is resolved \u2014 closing the group:`);
|
|
21614
21726
|
try {
|
|
21615
|
-
const { meta, body } = parseFrontmatter(
|
|
21727
|
+
const { meta, body } = parseFrontmatter(fs63.readFileSync(rootFile, "utf8"));
|
|
21616
21728
|
const res = cmdRemove(rootId, "completed", { closing: true });
|
|
21617
21729
|
return {
|
|
21618
21730
|
id: rootId,
|
|
@@ -21669,7 +21781,7 @@ function cleanupDiscardedCards(sessionId) {
|
|
|
21669
21781
|
if (card.pending) throw new Error(`Discarding #${card.id} did not finish. Retry the discard.`);
|
|
21670
21782
|
while (locate(card.id)) cmdRemove(card.id, "rejected", { discard: true, cleanupDiscarded: true });
|
|
21671
21783
|
dropCrossRefs(card.id);
|
|
21672
|
-
stripReadmeRefs({ kind: "file", rel:
|
|
21784
|
+
stripReadmeRefs({ kind: "file", rel: path66.relative(TODO, path66.resolve(REPO_ROOT, card.path)).split(path66.sep).join("/") });
|
|
21673
21785
|
}
|
|
21674
21786
|
return discarded.map((c) => c.id);
|
|
21675
21787
|
});
|
|
@@ -21755,8 +21867,8 @@ var init_memory_file = __esm({
|
|
|
21755
21867
|
});
|
|
21756
21868
|
|
|
21757
21869
|
// src/commands/rule.ts
|
|
21758
|
-
import
|
|
21759
|
-
import
|
|
21870
|
+
import fs64 from "node:fs";
|
|
21871
|
+
import path67 from "node:path";
|
|
21760
21872
|
function cmdRule(askedName, flags) {
|
|
21761
21873
|
const agent = askedName.trim();
|
|
21762
21874
|
if (!agentRoster().some((a) => a.name === agent)) {
|
|
@@ -21765,7 +21877,7 @@ function cmdRule(askedName, flags) {
|
|
|
21765
21877
|
const rule = readRuleText(flags.file, flags.text);
|
|
21766
21878
|
const res = setAgentRule(agent, rule);
|
|
21767
21879
|
if (!res.ok) die(res.error);
|
|
21768
|
-
const file = rel(
|
|
21880
|
+
const file = rel(path67.join(RULES, `${agent}.md`));
|
|
21769
21881
|
say(rule ? `wrote the \`${agent}\` rule (${file})` : `cleared the \`${agent}\` rule`);
|
|
21770
21882
|
return { agent, file, cleared: !rule };
|
|
21771
21883
|
}
|
|
@@ -21773,7 +21885,7 @@ function readRuleText(file, text5) {
|
|
|
21773
21885
|
if (file !== void 0 && text5 !== void 0) die("pass --file or --text, not both");
|
|
21774
21886
|
if (file !== void 0) {
|
|
21775
21887
|
try {
|
|
21776
|
-
return
|
|
21888
|
+
return fs64.readFileSync(file, "utf8").trim();
|
|
21777
21889
|
} catch {
|
|
21778
21890
|
die(`can't read ${file} \u2014 write the rule to a file, then pass its path`);
|
|
21779
21891
|
}
|
|
@@ -21900,22 +22012,22 @@ var init_storyboard = __esm({
|
|
|
21900
22012
|
});
|
|
21901
22013
|
|
|
21902
22014
|
// src/lib/spec-contract.ts
|
|
21903
|
-
import
|
|
21904
|
-
import
|
|
22015
|
+
import fs65 from "node:fs";
|
|
22016
|
+
import path68 from "node:path";
|
|
21905
22017
|
function snapshotSpecs() {
|
|
21906
22018
|
const out = /* @__PURE__ */ new Map();
|
|
21907
|
-
if (!
|
|
22019
|
+
if (!fs65.existsSync(TODO)) return out;
|
|
21908
22020
|
for (const file of walkMd(TODO)) {
|
|
21909
|
-
if (isLegacyRecurring(
|
|
21910
|
-
const id = idPrefix(
|
|
21911
|
-
if (id !== null) out.set(file, { id, text:
|
|
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") });
|
|
21912
22024
|
}
|
|
21913
22025
|
return out;
|
|
21914
22026
|
}
|
|
21915
22027
|
function enclosingGroups(file) {
|
|
21916
22028
|
const ids = [];
|
|
21917
22029
|
for (let root = enclosingGroupRoot(file); root; root = enclosingGroupRoot(root)) {
|
|
21918
|
-
const id = idPrefix(
|
|
22030
|
+
const id = idPrefix(path68.basename(path68.dirname(root)));
|
|
21919
22031
|
if (id !== null) ids.push(id);
|
|
21920
22032
|
}
|
|
21921
22033
|
return ids;
|
|
@@ -22084,9 +22196,9 @@ function validateSpec(file, text5, id) {
|
|
|
22084
22196
|
}
|
|
22085
22197
|
function inside(dir, name) {
|
|
22086
22198
|
try {
|
|
22087
|
-
const root =
|
|
22088
|
-
const real2 =
|
|
22089
|
-
return real2.startsWith(root +
|
|
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;
|
|
22090
22202
|
} catch {
|
|
22091
22203
|
return null;
|
|
22092
22204
|
}
|
|
@@ -22104,7 +22216,7 @@ function variantsProblem(raw, src, id) {
|
|
|
22104
22216
|
if (files2.length < 2 || !files2.every((f) => typeof f === "string" && f)) return `variants needs at least two labels, each naming a file. ${shape}`;
|
|
22105
22217
|
if (!files2.includes(src)) return `src="${src}" is not one of the variants. Set src to the version shown first.`;
|
|
22106
22218
|
if (id === void 0) return null;
|
|
22107
|
-
const dir =
|
|
22219
|
+
const dir = path68.join(ASSETS, String(id));
|
|
22108
22220
|
for (const f of files2) {
|
|
22109
22221
|
const parts = f.split("/");
|
|
22110
22222
|
if (parts.length !== 3 || parts[0] !== ".assets" || parts[1] !== String(id) || !inside(dir, parts[2])) {
|
|
@@ -22114,7 +22226,7 @@ function variantsProblem(raw, src, id) {
|
|
|
22114
22226
|
return null;
|
|
22115
22227
|
}
|
|
22116
22228
|
function compareProblem(attrs, id) {
|
|
22117
|
-
const dir =
|
|
22229
|
+
const dir = path68.join(ASSETS, String(id));
|
|
22118
22230
|
const src = (message) => ({ rule: "compare-src", message });
|
|
22119
22231
|
const shots = (message) => ({ rule: "compare-shots", message });
|
|
22120
22232
|
for (const side of ["a", "b"]) {
|
|
@@ -22134,7 +22246,7 @@ function compareProblem(attrs, id) {
|
|
|
22134
22246
|
const file = inside(dir, named2.name);
|
|
22135
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.` };
|
|
22136
22248
|
try {
|
|
22137
|
-
return { data: JSON.parse(
|
|
22249
|
+
return { data: JSON.parse(fs65.readFileSync(file, "utf8")) };
|
|
22138
22250
|
} catch {
|
|
22139
22251
|
return { message: `${at} is not valid JSON.` };
|
|
22140
22252
|
}
|
|
@@ -22154,7 +22266,7 @@ function compareProblem(attrs, id) {
|
|
|
22154
22266
|
}
|
|
22155
22267
|
function validateStoryboards(file, id, text5) {
|
|
22156
22268
|
const errors = [];
|
|
22157
|
-
const dir =
|
|
22269
|
+
const dir = path68.join(ASSETS, String(id));
|
|
22158
22270
|
for (const marker of storyboardMarkers(text5)) {
|
|
22159
22271
|
const named2 = assetName(marker.src, id, ["json"]);
|
|
22160
22272
|
const add = (message) => errors.push({ file: rel(file), line: marker.line, rule: "storyboard-src", message });
|
|
@@ -22303,8 +22415,8 @@ var init_mockups = __esm({
|
|
|
22303
22415
|
});
|
|
22304
22416
|
|
|
22305
22417
|
// src/commands/spec-write.ts
|
|
22306
|
-
import
|
|
22307
|
-
import
|
|
22418
|
+
import fs66 from "node:fs";
|
|
22419
|
+
import path69 from "node:path";
|
|
22308
22420
|
function cmdSpecWrite(id, askedName, flags) {
|
|
22309
22421
|
const agent = findSpecAgent(askedName);
|
|
22310
22422
|
if (!agent) die(notAnAgent(askedName), { kind: "no-such-spec-agent", specAgent: askedName });
|
|
@@ -22312,11 +22424,11 @@ function cmdSpecWrite(id, askedName, flags) {
|
|
|
22312
22424
|
const section = readSection(flags.file, flags.text);
|
|
22313
22425
|
const found2 = locate(id);
|
|
22314
22426
|
if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
|
|
22315
|
-
const file = found2.kind === "group" ?
|
|
22316
|
-
const { meta, body } = parseFrontmatter(
|
|
22427
|
+
const file = found2.kind === "group" ? path69.join(found2.target, "root.md") : found2.target;
|
|
22428
|
+
const { meta, body } = parseFrontmatter(fs66.readFileSync(file, "utf8"));
|
|
22317
22429
|
if (!meta) die(`${rel(file)} has no frontmatter \u2014 run \`migrate\` first`);
|
|
22318
22430
|
const { body: next, replaced } = splice(body, name, section);
|
|
22319
|
-
|
|
22431
|
+
fs66.writeFileSync(file, serializeFrontmatter(meta) + "\n" + next);
|
|
22320
22432
|
say(`${replaced ? "rewrote" : "wrote"} the \`${name}\` section on #${id} (${rel(file)})`);
|
|
22321
22433
|
return { id, specAgent: name, replaced, file: rel(file) };
|
|
22322
22434
|
}
|
|
@@ -22325,7 +22437,7 @@ function readSection(file, text5) {
|
|
|
22325
22437
|
let raw;
|
|
22326
22438
|
if (file !== void 0) {
|
|
22327
22439
|
try {
|
|
22328
|
-
raw =
|
|
22440
|
+
raw = fs66.readFileSync(file, "utf8");
|
|
22329
22441
|
} catch {
|
|
22330
22442
|
die(`can't read ${file} \u2014 write your section to a file, then pass its path`);
|
|
22331
22443
|
}
|
|
@@ -22791,11 +22903,11 @@ var init_shared = __esm({
|
|
|
22791
22903
|
});
|
|
22792
22904
|
|
|
22793
22905
|
// src/commands/goal.ts
|
|
22794
|
-
import
|
|
22906
|
+
import fs67 from "node:fs";
|
|
22795
22907
|
function load() {
|
|
22796
22908
|
const file = goalsFile();
|
|
22797
22909
|
if (!file) die("Goals exist only inside a WildCrane goal discussion.");
|
|
22798
|
-
const held4 = JSON.parse(
|
|
22910
|
+
const held4 = JSON.parse(fs67.readFileSync(file, "utf8"));
|
|
22799
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.");
|
|
22800
22912
|
const goals = held4.goals ?? held4.ideas;
|
|
22801
22913
|
if (!Array.isArray(goals)) die("The goals array is missing or invalid.");
|
|
@@ -22820,7 +22932,7 @@ function splitBody2(text5) {
|
|
|
22820
22932
|
}
|
|
22821
22933
|
function readBody(bodyFile) {
|
|
22822
22934
|
if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
|
|
22823
|
-
const text5 =
|
|
22935
|
+
const text5 = fs67.readFileSync(bodyFile, "utf8");
|
|
22824
22936
|
if (!text5.trim()) die("The goal must not be empty.");
|
|
22825
22937
|
return splitBody2(text5);
|
|
22826
22938
|
}
|
|
@@ -22832,7 +22944,7 @@ function named(held4, id) {
|
|
|
22832
22944
|
function cmdGoal(args, opts) {
|
|
22833
22945
|
const sub = args[0] ?? "";
|
|
22834
22946
|
const { file, held: held4 } = load();
|
|
22835
|
-
const write2 = () =>
|
|
22947
|
+
const write2 = () => fs67.writeFileSync(file, `${JSON.stringify({ workflows: held4.workflows, ideas: held4.goals }, null, 2)}
|
|
22836
22948
|
`);
|
|
22837
22949
|
if (sub === "new") {
|
|
22838
22950
|
const title = opts.title?.trim();
|
|
@@ -22902,8 +23014,8 @@ __export(board_exports, {
|
|
|
22902
23014
|
buildBoardProgram: () => buildBoardProgram
|
|
22903
23015
|
});
|
|
22904
23016
|
import crypto4 from "node:crypto";
|
|
22905
|
-
import
|
|
22906
|
-
import
|
|
23017
|
+
import fs68 from "node:fs";
|
|
23018
|
+
import path70 from "node:path";
|
|
22907
23019
|
async function dispatch(move2, cmd, args, opts, cli) {
|
|
22908
23020
|
const ctx = ctxOf(cmd, cli.program);
|
|
22909
23021
|
const data = await runAction(ctx, {}, async () => {
|
|
@@ -22942,7 +23054,7 @@ async function cloudCard(task, opts) {
|
|
|
22942
23054
|
let request;
|
|
22943
23055
|
if (typeof opts.bodyFile === "string") {
|
|
22944
23056
|
try {
|
|
22945
|
-
request =
|
|
23057
|
+
request = fs68.readFileSync(opts.bodyFile, "utf8");
|
|
22946
23058
|
} catch {
|
|
22947
23059
|
}
|
|
22948
23060
|
}
|
|
@@ -22972,7 +23084,7 @@ async function cloudCard(task, opts) {
|
|
|
22972
23084
|
const file = creationReceipt(`${checked.value}:${requestId}`, slot);
|
|
22973
23085
|
const journal = readCreation(file, said3);
|
|
22974
23086
|
if (!journal.made) {
|
|
22975
|
-
const key = `akb-${
|
|
23087
|
+
const key = `akb-${path70.basename(file, ".json").slice(0, 40)}`;
|
|
22976
23088
|
const made = await createProjectTask(checked.value, journal.said, key);
|
|
22977
23089
|
if (!made.ok) throw new BoardError(creationError(`Cloud did not make the task: ${made.error}`, triage), { kind: "refused" });
|
|
22978
23090
|
journal.made = made.value;
|
|
@@ -23117,16 +23229,16 @@ var init_board2 = __esm({
|
|
|
23117
23229
|
});
|
|
23118
23230
|
|
|
23119
23231
|
// src/lib/board-cli.ts
|
|
23120
|
-
import
|
|
23121
|
-
import
|
|
23232
|
+
import fs69 from "node:fs";
|
|
23233
|
+
import path71 from "node:path";
|
|
23122
23234
|
function useBoard(found2, dirNamed) {
|
|
23123
|
-
if (!found2.named && found2.board ===
|
|
23235
|
+
if (!found2.named && found2.board === path71.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
|
|
23124
23236
|
else setBoardDir(found2.board, found2.root);
|
|
23125
23237
|
useProjectState();
|
|
23126
23238
|
}
|
|
23127
23239
|
function whole(found2, move2) {
|
|
23128
23240
|
if (move2 === MAKES_A_BOARD) return found2;
|
|
23129
|
-
if (!
|
|
23241
|
+
if (!fs69.existsSync(path71.join(found2.board, "todo"))) {
|
|
23130
23242
|
die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
|
|
23131
23243
|
kind: "board-incomplete",
|
|
23132
23244
|
dir: found2.root
|
|
@@ -23135,13 +23247,13 @@ function whole(found2, move2) {
|
|
|
23135
23247
|
return found2;
|
|
23136
23248
|
}
|
|
23137
23249
|
function findBoardUpward(from, move2) {
|
|
23138
|
-
let dir =
|
|
23250
|
+
let dir = path71.resolve(from);
|
|
23139
23251
|
for (; ; ) {
|
|
23140
|
-
if (hasBoard(dir)) return { root: dir, board:
|
|
23252
|
+
if (hasBoard(dir)) return { root: dir, board: path71.join(dir, "docs", "kanban") };
|
|
23141
23253
|
if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
|
|
23142
|
-
const kept2 =
|
|
23143
|
-
if (move2 !== MAKES_A_BOARD &&
|
|
23144
|
-
const up =
|
|
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);
|
|
23145
23257
|
if (up === dir) return null;
|
|
23146
23258
|
dir = up;
|
|
23147
23259
|
}
|
|
@@ -23149,11 +23261,11 @@ function findBoardUpward(from, move2) {
|
|
|
23149
23261
|
function resolveBoard(move2, { board: board2, dir, cwd, installHint }) {
|
|
23150
23262
|
const named2 = board2 ?? boardFromEnv();
|
|
23151
23263
|
if (named2) {
|
|
23152
|
-
const folder =
|
|
23153
|
-
if (!
|
|
23264
|
+
const folder = path71.resolve(cwd, named2);
|
|
23265
|
+
if (!fs69.existsSync(folder) && move2 !== MAKES_A_BOARD) {
|
|
23154
23266
|
die(`no such folder: ${folder}`, { kind: "no-such-folder", dir: folder });
|
|
23155
23267
|
}
|
|
23156
|
-
if (
|
|
23268
|
+
if (fs69.existsSync(folder) && !isBoardDir(folder) && move2 !== MAKES_A_BOARD) {
|
|
23157
23269
|
die(`${folder} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
|
|
23158
23270
|
kind: "no-board",
|
|
23159
23271
|
dir: folder
|
|
@@ -23162,24 +23274,24 @@ function resolveBoard(move2, { board: board2, dir, cwd, installHint }) {
|
|
|
23162
23274
|
return { root: projectRootOf(folder), board: folder, named: true };
|
|
23163
23275
|
}
|
|
23164
23276
|
if (dir !== null) {
|
|
23165
|
-
const root =
|
|
23166
|
-
if (!
|
|
23167
|
-
const kept2 =
|
|
23168
|
-
if (!hasBoard(root) && move2 !== MAKES_A_BOARD &&
|
|
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);
|
|
23169
23281
|
if (!hasBoard(root) && move2 !== MAKES_A_BOARD) {
|
|
23170
23282
|
die(`no board in ${root} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
|
|
23171
23283
|
kind: "no-board",
|
|
23172
23284
|
dir: root
|
|
23173
23285
|
});
|
|
23174
23286
|
}
|
|
23175
|
-
return whole({ root, board:
|
|
23287
|
+
return whole({ root, board: path71.join(root, "docs", "kanban") }, move2);
|
|
23176
23288
|
}
|
|
23177
23289
|
const found2 = findBoardUpward(cwd, move2);
|
|
23178
23290
|
if (found2) return whole(found2, move2);
|
|
23179
|
-
if (move2 === MAKES_A_BOARD) return { root:
|
|
23291
|
+
if (move2 === MAKES_A_BOARD) return { root: path71.resolve(cwd), board: path71.join(path71.resolve(cwd), "docs", "kanban") };
|
|
23180
23292
|
die(
|
|
23181
|
-
`no board here. Looked in ${
|
|
23182
|
-
{ kind: "no-board", dir:
|
|
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) }
|
|
23183
23295
|
);
|
|
23184
23296
|
}
|
|
23185
23297
|
function editDistance(a, b) {
|
|
@@ -23261,8 +23373,8 @@ var init_board_cli = __esm({
|
|
|
23261
23373
|
init_io();
|
|
23262
23374
|
init_pointer();
|
|
23263
23375
|
MAKES_A_BOARD = "init";
|
|
23264
|
-
hasBoard = (dir) =>
|
|
23265
|
-
isBoardDir = (dir) =>
|
|
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"));
|
|
23266
23378
|
boardFromEnv = () => {
|
|
23267
23379
|
const named2 = process.env.AI4KANBAN_BOARD?.trim();
|
|
23268
23380
|
return named2 ? named2 : null;
|
|
@@ -23529,8 +23641,8 @@ var init_guide = __esm({
|
|
|
23529
23641
|
});
|
|
23530
23642
|
|
|
23531
23643
|
// src/lib/agent/approve.ts
|
|
23532
|
-
import
|
|
23533
|
-
import
|
|
23644
|
+
import fs75 from "node:fs";
|
|
23645
|
+
import path77 from "node:path";
|
|
23534
23646
|
function approvalRequest(req) {
|
|
23535
23647
|
const id = req.id;
|
|
23536
23648
|
const card = id === void 0 ? null : findCard(id);
|
|
@@ -23548,12 +23660,12 @@ function advancePhase(id) {
|
|
|
23548
23660
|
const card = findCard(id);
|
|
23549
23661
|
const found2 = locate(id);
|
|
23550
23662
|
if (!card || !found2 || !awaitingApproval(card)) return { error: `#${id} is no longer waiting on approval.` };
|
|
23551
|
-
const file = found2.kind === "group" ?
|
|
23552
|
-
const { meta, body } = parseFrontmatter(
|
|
23663
|
+
const file = found2.kind === "group" ? path77.join(found2.target, "root.md") : found2.target;
|
|
23664
|
+
const { meta, body } = parseFrontmatter(fs75.readFileSync(file, "utf8"));
|
|
23553
23665
|
if (!meta) return { error: `#${id} has no frontmatter` };
|
|
23554
23666
|
meta.phase = card.stage + 1;
|
|
23555
23667
|
meta.status = "todo";
|
|
23556
|
-
|
|
23668
|
+
fs75.writeFileSync(file, serializeFrontmatter(meta) + "\n" + body);
|
|
23557
23669
|
return null;
|
|
23558
23670
|
}
|
|
23559
23671
|
var init_approve = __esm({
|
|
@@ -23677,16 +23789,16 @@ var init_start = __esm({
|
|
|
23677
23789
|
});
|
|
23678
23790
|
|
|
23679
23791
|
// src/lib/agent/task-chats.ts
|
|
23680
|
-
import
|
|
23681
|
-
import
|
|
23792
|
+
import fs76 from "node:fs";
|
|
23793
|
+
import path78 from "node:path";
|
|
23682
23794
|
function taskChatFile(task, home3) {
|
|
23683
23795
|
if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
|
|
23684
|
-
return
|
|
23796
|
+
return path78.join(taskChatsDir(home3), `${task}.jsonl`);
|
|
23685
23797
|
}
|
|
23686
23798
|
function readTaskChat(task, home3) {
|
|
23687
23799
|
let text5;
|
|
23688
23800
|
try {
|
|
23689
|
-
text5 =
|
|
23801
|
+
text5 = fs76.readFileSync(taskChatFile(task, home3), "utf8");
|
|
23690
23802
|
} catch {
|
|
23691
23803
|
return [];
|
|
23692
23804
|
}
|
|
@@ -23707,13 +23819,13 @@ var init_task_chats = __esm({
|
|
|
23707
23819
|
"use strict";
|
|
23708
23820
|
init_home();
|
|
23709
23821
|
TASK = /^[\w-]{1,100}$/;
|
|
23710
|
-
taskChatsDir = (home3 = machineHome()) =>
|
|
23822
|
+
taskChatsDir = (home3 = machineHome()) => path78.join(home3, "chats");
|
|
23711
23823
|
}
|
|
23712
23824
|
});
|
|
23713
23825
|
|
|
23714
23826
|
// src/lib/agent/memory-review.ts
|
|
23715
|
-
import
|
|
23716
|
-
import
|
|
23827
|
+
import fs77 from "node:fs";
|
|
23828
|
+
import path79 from "node:path";
|
|
23717
23829
|
function taskChatsToReview(tasks) {
|
|
23718
23830
|
const out = [];
|
|
23719
23831
|
for (const ref of [...new Set(tasks)]) {
|
|
@@ -23735,8 +23847,8 @@ function readArchived2(id) {
|
|
|
23735
23847
|
const found2 = Number.isInteger(id) && id > 0 ? locateArchived(id) : null;
|
|
23736
23848
|
if (!found2) return null;
|
|
23737
23849
|
try {
|
|
23738
|
-
const file = found2.kind === "group" ?
|
|
23739
|
-
const { meta, body } = parseFrontmatter(
|
|
23850
|
+
const file = found2.kind === "group" ? path79.join(found2.target, "root.md") : found2.target;
|
|
23851
|
+
const { meta, body } = parseFrontmatter(fs77.readFileSync(file, "utf8"));
|
|
23740
23852
|
if (!meta) return null;
|
|
23741
23853
|
return { id, title: meta.title, modules: meta.modules ?? [], rejected: meta.rejected, body };
|
|
23742
23854
|
} catch {
|
|
@@ -23805,17 +23917,17 @@ var init_memory_review = __esm({
|
|
|
23805
23917
|
});
|
|
23806
23918
|
|
|
23807
23919
|
// src/lib/agent/dismissal-review.ts
|
|
23808
|
-
import
|
|
23809
|
-
import
|
|
23920
|
+
import fs78 from "node:fs";
|
|
23921
|
+
import path80 from "node:path";
|
|
23810
23922
|
function rejectionsToReview() {
|
|
23811
|
-
const dir =
|
|
23812
|
-
if (!
|
|
23923
|
+
const dir = path80.join(ARCHIVE, REJECTIONS_TO_REVIEW);
|
|
23924
|
+
if (!fs78.existsSync(dir)) return [];
|
|
23813
23925
|
const found2 = [];
|
|
23814
23926
|
for (const file of walkMd(dir)) {
|
|
23815
23927
|
const id = archivedId(file);
|
|
23816
23928
|
if (id === null) continue;
|
|
23817
23929
|
try {
|
|
23818
|
-
const { meta } = parseFrontmatter(
|
|
23930
|
+
const { meta } = parseFrontmatter(fs78.readFileSync(file, "utf8"));
|
|
23819
23931
|
if (!meta?.rejected || meta.rejected_by !== "user" || !meta.rejected_reason.trim()) continue;
|
|
23820
23932
|
found2.push({ id, title: meta.title, file: rel(file), reason: meta.rejected_reason.trim(), rejectedAt: meta.rejected_at });
|
|
23821
23933
|
} catch {
|
|
@@ -23845,7 +23957,7 @@ function citedSources(text5) {
|
|
|
23845
23957
|
function withdrawnSources() {
|
|
23846
23958
|
const cited = [...new Set(plannerCopies("rejected.md").flatMap((file) => {
|
|
23847
23959
|
try {
|
|
23848
|
-
return citedSources(
|
|
23960
|
+
return citedSources(fs78.readFileSync(file, "utf8"));
|
|
23849
23961
|
} catch {
|
|
23850
23962
|
return [];
|
|
23851
23963
|
}
|
|
@@ -23870,8 +23982,8 @@ var init_dismissal_review = __esm({
|
|
|
23870
23982
|
});
|
|
23871
23983
|
|
|
23872
23984
|
// src/lib/agent/flow.ts
|
|
23873
|
-
import
|
|
23874
|
-
import
|
|
23985
|
+
import fs79 from "node:fs";
|
|
23986
|
+
import path81 from "node:path";
|
|
23875
23987
|
function readCard2(id, home3 = "board") {
|
|
23876
23988
|
const found2 = home3 === "archive" ? locateArchived(id) : locate(id);
|
|
23877
23989
|
if (!found2) {
|
|
@@ -23880,10 +23992,10 @@ function readCard2(id, home3 = "board") {
|
|
|
23880
23992
|
{ kind: "card-not-found", id }
|
|
23881
23993
|
);
|
|
23882
23994
|
}
|
|
23883
|
-
const file = found2.kind === "group" ?
|
|
23995
|
+
const file = found2.kind === "group" ? path81.join(found2.target, "root.md") : found2.target;
|
|
23884
23996
|
let text5;
|
|
23885
23997
|
try {
|
|
23886
|
-
text5 =
|
|
23998
|
+
text5 = fs79.readFileSync(file, "utf8");
|
|
23887
23999
|
} catch {
|
|
23888
24000
|
die(`#${id} is on the board but ${rel(file)} can't be read.`, { kind: "card-unreadable", id });
|
|
23889
24001
|
}
|
|
@@ -24007,7 +24119,7 @@ function workspaceField(delivery) {
|
|
|
24007
24119
|
if (!delivery?.worktree) return [];
|
|
24008
24120
|
return field("workspace", [
|
|
24009
24121
|
`write code in ${delivery.worktree} \u2014 this delivery's own worktree, on branch ${delivery.branch}.`,
|
|
24010
|
-
|
|
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.`,
|
|
24011
24123
|
`every board command names the project's own copy: \`${boardCommandFor()} <command>\`.`,
|
|
24012
24124
|
`${rel(REPO_ROOT)} is the project \u2014 the card, the memory files and the docs are changed there, not here.`
|
|
24013
24125
|
]);
|
|
@@ -24751,7 +24863,7 @@ __export(watch_exports, {
|
|
|
24751
24863
|
watchRun: () => watchRun
|
|
24752
24864
|
});
|
|
24753
24865
|
import { spawn as spawn4 } from "node:child_process";
|
|
24754
|
-
import
|
|
24866
|
+
import fs80 from "node:fs";
|
|
24755
24867
|
async function watchRun(sessionId, resume = startResume) {
|
|
24756
24868
|
const spec = readSpec(sessionId);
|
|
24757
24869
|
const run2 = peekRun(sessionId);
|
|
@@ -24787,11 +24899,11 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
24787
24899
|
const record = claimed ?? run2;
|
|
24788
24900
|
const sub = record.action === "sub";
|
|
24789
24901
|
if (claim) await setCardStatus(claim.cardId, claim.status);
|
|
24790
|
-
|
|
24791
|
-
const logFile =
|
|
24902
|
+
fs80.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
24903
|
+
const logFile = fs80.createWriteStream(record.logPath, { flags: "a" });
|
|
24792
24904
|
logFile.on("error", () => {
|
|
24793
24905
|
});
|
|
24794
|
-
const eventsFile =
|
|
24906
|
+
const eventsFile = fs80.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
|
|
24795
24907
|
eventsFile.on("error", () => {
|
|
24796
24908
|
});
|
|
24797
24909
|
const event2 = (e) => eventsFile.write(`${JSON.stringify(e)}
|
|
@@ -25380,7 +25492,7 @@ var init_watch = __esm({
|
|
|
25380
25492
|
});
|
|
25381
25493
|
|
|
25382
25494
|
// src/kanban.ts
|
|
25383
|
-
import
|
|
25495
|
+
import fs86 from "node:fs";
|
|
25384
25496
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
25385
25497
|
|
|
25386
25498
|
// src/lib/cli/agent.ts
|
|
@@ -25869,8 +25981,8 @@ async function testAgent(args) {
|
|
|
25869
25981
|
}
|
|
25870
25982
|
|
|
25871
25983
|
// src/commands/cloud.ts
|
|
25872
|
-
import
|
|
25873
|
-
import
|
|
25984
|
+
import fs71 from "node:fs";
|
|
25985
|
+
import path73 from "node:path";
|
|
25874
25986
|
|
|
25875
25987
|
// src/lib/cloud/avatar.ts
|
|
25876
25988
|
init_session();
|
|
@@ -25918,13 +26030,13 @@ init_config();
|
|
|
25918
26030
|
init_home();
|
|
25919
26031
|
init_config();
|
|
25920
26032
|
init_session();
|
|
25921
|
-
import
|
|
25922
|
-
import
|
|
26033
|
+
import fs70 from "node:fs";
|
|
26034
|
+
import path72 from "node:path";
|
|
25923
26035
|
var FRESH_MS = 10 * 6e4;
|
|
25924
26036
|
var GRACE_MS = 7 * 24 * 60 * 6e4;
|
|
25925
|
-
var heldFile = () =>
|
|
26037
|
+
var heldFile = () => path72.join(machineHome(), "pro.json");
|
|
25926
26038
|
function forgetPro() {
|
|
25927
|
-
|
|
26039
|
+
fs70.rmSync(heldFile(), { force: true });
|
|
25928
26040
|
}
|
|
25929
26041
|
|
|
25930
26042
|
// src/lib/cloud/account.ts
|
|
@@ -26101,10 +26213,10 @@ async function cloudImage(opts, program2) {
|
|
|
26101
26213
|
const prompt = opts.prompt.trim();
|
|
26102
26214
|
if (!prompt) usage("Missing the prompt.", line);
|
|
26103
26215
|
const references = opts.refs.map((file) => {
|
|
26104
|
-
const type = REF_TYPES[
|
|
26216
|
+
const type = REF_TYPES[path73.extname(file).toLowerCase()];
|
|
26105
26217
|
if (!type) usage(`--ref ${file}: use a PNG, JPEG or WebP file.`, line);
|
|
26106
26218
|
try {
|
|
26107
|
-
return `data:${type};base64,${
|
|
26219
|
+
return `data:${type};base64,${fs71.readFileSync(file).toString("base64")}`;
|
|
26108
26220
|
} catch (e) {
|
|
26109
26221
|
usage(`--ref ${file}: ${e instanceof Error ? e.message : String(e)}`, line);
|
|
26110
26222
|
}
|
|
@@ -26210,31 +26322,31 @@ async function generate(g) {
|
|
|
26210
26322
|
refuse(g.failed, g.fallback);
|
|
26211
26323
|
}
|
|
26212
26324
|
const out = g.outFor?.(res, g.out) ?? g.out;
|
|
26213
|
-
|
|
26214
|
-
|
|
26325
|
+
fs71.mkdirSync(path73.dirname(path73.resolve(out)), { recursive: true });
|
|
26326
|
+
fs71.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
|
|
26215
26327
|
say(`${out} (${g.label(res)})`);
|
|
26216
26328
|
return { out };
|
|
26217
26329
|
}
|
|
26218
26330
|
|
|
26219
26331
|
// src/commands/cloud-import.ts
|
|
26220
26332
|
import crypto5 from "node:crypto";
|
|
26221
|
-
import
|
|
26222
|
-
import
|
|
26333
|
+
import fs73 from "node:fs";
|
|
26334
|
+
import path75 from "node:path";
|
|
26223
26335
|
|
|
26224
26336
|
// ../cloud/src/board-files.ts
|
|
26225
26337
|
var ROOTS = ["todo/", ".archive/", "memory/", "workflows/", "triage/", "assets/", "rules/"];
|
|
26226
26338
|
var SETTINGS = ["modules.md", "config.md"];
|
|
26227
|
-
var isSettingsPath = (
|
|
26339
|
+
var isSettingsPath = (path87) => SETTINGS.includes(path87) || /^rules\/(?:workflows\/)?[^/]+\.md$/.test(path87);
|
|
26228
26340
|
var BOARD_FILE_LIMIT = 256 * 1024;
|
|
26229
|
-
function isBoardPath(
|
|
26230
|
-
if (!
|
|
26231
|
-
if (
|
|
26232
|
-
if (
|
|
26233
|
-
if (
|
|
26234
|
-
if (SETTINGS.includes(
|
|
26235
|
-
if (
|
|
26236
|
-
if (
|
|
26237
|
-
return ROOTS.some((root) =>
|
|
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");
|
|
26238
26350
|
}
|
|
26239
26351
|
var workflowFolder = (id) => id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
26240
26352
|
|
|
@@ -26338,8 +26450,8 @@ init_bundled();
|
|
|
26338
26450
|
// src/lib/agents/shared-memory.ts
|
|
26339
26451
|
init_bundled();
|
|
26340
26452
|
init_parse();
|
|
26341
|
-
import
|
|
26342
|
-
import
|
|
26453
|
+
import fs72 from "node:fs";
|
|
26454
|
+
import path74 from "node:path";
|
|
26343
26455
|
function sharedMemory(board2) {
|
|
26344
26456
|
const declared = /* @__PURE__ */ new Map();
|
|
26345
26457
|
const take = (folder, text5, builtIn) => {
|
|
@@ -26351,16 +26463,16 @@ function sharedMemory(board2) {
|
|
|
26351
26463
|
const at = /^([^/]+)\/AGENT\.md$/.exec(key);
|
|
26352
26464
|
if (at) take(at[1], text5, true);
|
|
26353
26465
|
}
|
|
26354
|
-
const root =
|
|
26466
|
+
const root = path74.join(board2, "agents");
|
|
26355
26467
|
let folders2 = [];
|
|
26356
26468
|
try {
|
|
26357
|
-
folders2 =
|
|
26469
|
+
folders2 = fs72.readdirSync(root, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
26358
26470
|
} catch {
|
|
26359
26471
|
}
|
|
26360
26472
|
for (const folder of folders2.sort()) {
|
|
26361
26473
|
let text5 = null;
|
|
26362
26474
|
try {
|
|
26363
|
-
text5 =
|
|
26475
|
+
text5 = fs72.readFileSync(path74.join(root, folder, "AGENT.md"), "utf8");
|
|
26364
26476
|
} catch {
|
|
26365
26477
|
}
|
|
26366
26478
|
take(folder, text5, false);
|
|
@@ -26449,24 +26561,24 @@ async function findProject(asked) {
|
|
|
26449
26561
|
}
|
|
26450
26562
|
throw new Refused(`No project of yours has the id or prefix "${asked}".`, "not_found");
|
|
26451
26563
|
}
|
|
26452
|
-
var read = (file) =>
|
|
26564
|
+
var read = (file) => fs73.readFileSync(file, "utf8");
|
|
26453
26565
|
var bytes2 = (text5) => Buffer.byteLength(text5, "utf8");
|
|
26454
26566
|
function files(dir) {
|
|
26455
|
-
if (!
|
|
26567
|
+
if (!fs73.existsSync(dir)) return [];
|
|
26456
26568
|
const out = [];
|
|
26457
|
-
for (const entry of
|
|
26569
|
+
for (const entry of fs73.readdirSync(dir, { withFileTypes: true })) {
|
|
26458
26570
|
if (entry.name.startsWith(".")) continue;
|
|
26459
|
-
const full =
|
|
26571
|
+
const full = path75.join(dir, entry.name);
|
|
26460
26572
|
if (entry.isDirectory()) out.push(...files(full));
|
|
26461
26573
|
else if (entry.isFile()) out.push(full);
|
|
26462
26574
|
}
|
|
26463
26575
|
return out;
|
|
26464
26576
|
}
|
|
26465
|
-
var posix2 = (p) => p.split(
|
|
26577
|
+
var posix2 = (p) => p.split(path75.sep).join("/");
|
|
26466
26578
|
function openCards() {
|
|
26467
26579
|
const out = [];
|
|
26468
26580
|
for (const file of walkMd(TODO)) {
|
|
26469
|
-
const rel2 = posix2(
|
|
26581
|
+
const rel2 = posix2(path75.relative(TODO, file));
|
|
26470
26582
|
if (rel2 === "README.md") continue;
|
|
26471
26583
|
const parts = rel2.split("/");
|
|
26472
26584
|
const text5 = read(file);
|
|
@@ -26500,14 +26612,14 @@ function bodyProblems(text5) {
|
|
|
26500
26612
|
return out;
|
|
26501
26613
|
}
|
|
26502
26614
|
function packWorkflow(flow) {
|
|
26503
|
-
const own =
|
|
26615
|
+
const own = path75.join(WORKFLOWS, flow.id);
|
|
26504
26616
|
const out = {};
|
|
26505
|
-
for (const file of files(own)) out[posix2(
|
|
26617
|
+
for (const file of files(own)) out[posix2(path75.relative(own, file))] = read(file);
|
|
26506
26618
|
const named2 = [...flow.previews, ...flow.land, ...flow.scheduled].map((h) => h.agent).filter((a) => !LAND_ROLES.includes(a));
|
|
26507
26619
|
for (const agent of new Set(named2)) {
|
|
26508
|
-
const dir =
|
|
26509
|
-
if (
|
|
26510
|
-
for (const file of files(dir)) out[`agents/${agent}/${posix2(
|
|
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);
|
|
26511
26623
|
continue;
|
|
26512
26624
|
}
|
|
26513
26625
|
for (const [key, text5] of Object.entries(BUNDLED_AGENT_FILES)) {
|
|
@@ -26559,8 +26671,8 @@ function draftsOf(text5) {
|
|
|
26559
26671
|
const at = /^\.(assets|mockups)\/(.+)$/.exec(name);
|
|
26560
26672
|
if (!at) continue;
|
|
26561
26673
|
const base = at[1] === "assets" ? ASSETS : MOCKUPS;
|
|
26562
|
-
const file =
|
|
26563
|
-
if (file.startsWith(base +
|
|
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);
|
|
26564
26676
|
}
|
|
26565
26677
|
return [...out].map(([name, file]) => ({ name, file }));
|
|
26566
26678
|
}
|
|
@@ -26594,9 +26706,9 @@ async function uploadDrafts(task, drafts) {
|
|
|
26594
26706
|
const assets = {};
|
|
26595
26707
|
for (const { name, file } of drafts) {
|
|
26596
26708
|
if (!card.body.includes(name)) continue;
|
|
26597
|
-
const ext =
|
|
26709
|
+
const ext = path75.extname(file).toLowerCase();
|
|
26598
26710
|
const type = TYPES[ext] ?? "application/octet-stream";
|
|
26599
|
-
const data =
|
|
26711
|
+
const data = fs73.readFileSync(file);
|
|
26600
26712
|
const artifact = await api("POST", `/v1/tasks/${task}/artifacts`, { type: kindOf(ext), name: name.slice(0, 200) });
|
|
26601
26713
|
const upload = await api("POST", `/v1/artifacts/${artifact.id}/uploads`, { content_type: type, size: Math.max(data.length, 1) });
|
|
26602
26714
|
await api("PUT", `/v1/uploads/${upload.id}`, void 0, { bytes: data, type });
|
|
@@ -26639,10 +26751,10 @@ usage: ${program2} cloud import --project <id or prefix> [--dry-run]`, { kind: "
|
|
|
26639
26751
|
async function run(asked, dryRun) {
|
|
26640
26752
|
const project = await findProject(asked);
|
|
26641
26753
|
const cloudFlows = await all(`/v1/workflows?workspace=${encodeURIComponent(project.workspace)}`);
|
|
26642
|
-
const board2 = crypto5.createHash("sha256").update(
|
|
26754
|
+
const board2 = crypto5.createHash("sha256").update(fs73.realpathSync(KANBAN)).digest("hex").slice(0, 16);
|
|
26643
26755
|
const cards = openCards();
|
|
26644
26756
|
const problems = [];
|
|
26645
|
-
const where = (file) => posix2(
|
|
26757
|
+
const where = (file) => posix2(path75.relative(KANBAN, file));
|
|
26646
26758
|
const own = workflows().filter((w) => !w.builtIn);
|
|
26647
26759
|
const packed = /* @__PURE__ */ new Map();
|
|
26648
26760
|
for (const flow of own) {
|
|
@@ -26669,7 +26781,7 @@ async function run(asked, dryRun) {
|
|
|
26669
26781
|
const root = `projects/${project.id}/`;
|
|
26670
26782
|
const boardFiles = [];
|
|
26671
26783
|
for (const file of [...files(MEMORY), ...files(RULES), CONFIG, MODULES_MD]) {
|
|
26672
|
-
if (!
|
|
26784
|
+
if (!fs73.existsSync(file)) continue;
|
|
26673
26785
|
const rel2 = where(file);
|
|
26674
26786
|
if (!isBoardPath(rel2)) continue;
|
|
26675
26787
|
const content = read(file);
|
|
@@ -26780,16 +26892,16 @@ async function run(asked, dryRun) {
|
|
|
26780
26892
|
}
|
|
26781
26893
|
function leftLocal(own) {
|
|
26782
26894
|
const out = [];
|
|
26783
|
-
const count4 = (dir) =>
|
|
26895
|
+
const count4 = (dir) => fs73.existsSync(dir) ? walkMd(dir).length : 0;
|
|
26784
26896
|
const archived = count4(ARCHIVE);
|
|
26785
26897
|
if (archived) out.push(`.archive/ (${archived})`);
|
|
26786
26898
|
const triage = count4(TRIAGE);
|
|
26787
26899
|
if (triage) out.push(`triage/ (${triage})`);
|
|
26788
|
-
if (
|
|
26789
|
-
if (
|
|
26900
|
+
if (fs73.existsSync(DELIVERIES)) out.push("deliveries/");
|
|
26901
|
+
if (fs73.existsSync(path75.join(KANBAN, "metrics.csv"))) out.push("metrics.csv");
|
|
26790
26902
|
const named2 = new Set(own.flatMap((w) => [...w.previews, ...w.land, ...w.scheduled].map((h) => h.agent)));
|
|
26791
|
-
if (
|
|
26792
|
-
for (const e of
|
|
26903
|
+
if (fs73.existsSync(AGENTS)) {
|
|
26904
|
+
for (const e of fs73.readdirSync(AGENTS, { withFileTypes: true })) {
|
|
26793
26905
|
if (e.isDirectory() && !e.name.startsWith(".") && !named2.has(e.name)) out.push(`agents/${e.name}/`);
|
|
26794
26906
|
}
|
|
26795
26907
|
}
|
|
@@ -26807,8 +26919,8 @@ init_session();
|
|
|
26807
26919
|
init_io();
|
|
26808
26920
|
init_paths();
|
|
26809
26921
|
import { createHash as createHash4 } from "node:crypto";
|
|
26810
|
-
import
|
|
26811
|
-
import
|
|
26922
|
+
import fs74 from "node:fs";
|
|
26923
|
+
import path76 from "node:path";
|
|
26812
26924
|
var SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
26813
26925
|
var CAPTURED = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
26814
26926
|
var MAX_BYTES3 = 50 * 1024 * 1024;
|
|
@@ -26907,10 +27019,10 @@ This template has no preview.`);
|
|
|
26907
27019
|
const written = [];
|
|
26908
27020
|
for (const p of previews) {
|
|
26909
27021
|
const bytes3 = Buffer.from(await (await ask(`/${at}/previews/${route(p.path)}`, {}, WITHOUT)).arrayBuffer());
|
|
26910
|
-
const file =
|
|
26911
|
-
const out =
|
|
26912
|
-
|
|
26913
|
-
|
|
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);
|
|
26914
27026
|
written.push(out);
|
|
26915
27027
|
say(out);
|
|
26916
27028
|
}
|
|
@@ -26923,15 +27035,15 @@ async function templateGet(name, opts, program2) {
|
|
|
26923
27035
|
const { template } = await asJson(await ask(`/${at}`, {}, WITHOUT));
|
|
26924
27036
|
const fetched = [];
|
|
26925
27037
|
for (const f of template.files) {
|
|
26926
|
-
const out =
|
|
26927
|
-
if (!out.startsWith(
|
|
27038
|
+
const out = path76.resolve(to, f.path);
|
|
27039
|
+
if (!out.startsWith(path76.resolve(to) + path76.sep)) refuse2(T.corrupt, WITHOUT);
|
|
26928
27040
|
const bytes3 = Buffer.from(await (await ask(`/${at}/files/${route(f.path)}`, {}, WITHOUT)).arrayBuffer());
|
|
26929
27041
|
if (bytes3.byteLength !== f.size || createHash4("sha256").update(bytes3).digest("hex") !== f.sha256) {
|
|
26930
27042
|
refuse2(T.corrupt, WITHOUT);
|
|
26931
27043
|
}
|
|
26932
27044
|
fetched.push({ out, bytes: bytes3 });
|
|
26933
27045
|
}
|
|
26934
|
-
const taken = fetched.filter((f) =>
|
|
27046
|
+
const taken = fetched.filter((f) => fs74.existsSync(f.out)).map((f) => path76.relative(to, f.out));
|
|
26935
27047
|
if (taken.length > 0) {
|
|
26936
27048
|
refuse2({
|
|
26937
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`,
|
|
@@ -26939,8 +27051,8 @@ async function templateGet(name, opts, program2) {
|
|
|
26939
27051
|
});
|
|
26940
27052
|
}
|
|
26941
27053
|
for (const f of fetched) {
|
|
26942
|
-
|
|
26943
|
-
|
|
27054
|
+
fs74.mkdirSync(path76.dirname(f.out), { recursive: true });
|
|
27055
|
+
fs74.writeFileSync(f.out, f.bytes);
|
|
26944
27056
|
}
|
|
26945
27057
|
say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
|
|
26946
27058
|
Fetched ${name}: ${fetched.length} files into ${to}`);
|
|
@@ -26958,25 +27070,25 @@ async function templateSource(name, opts) {
|
|
|
26958
27070
|
say(`evidence: ${e.path}`);
|
|
26959
27071
|
continue;
|
|
26960
27072
|
}
|
|
26961
|
-
const out =
|
|
26962
|
-
|
|
26963
|
-
|
|
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()));
|
|
26964
27076
|
written.push(out);
|
|
26965
27077
|
say(out);
|
|
26966
27078
|
}
|
|
26967
27079
|
return { name, source, evidence: written.length > 0 ? written : evidence.map((e) => e.path) };
|
|
26968
27080
|
}
|
|
26969
27081
|
async function templatePublish(dir, opts) {
|
|
26970
|
-
const root =
|
|
26971
|
-
const manifest =
|
|
26972
|
-
if (!
|
|
26973
|
-
const meta = readTemplateMeta(
|
|
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"));
|
|
26974
27086
|
const files2 = walk2(root);
|
|
26975
|
-
const total = files2.reduce((sum, f) => sum +
|
|
27087
|
+
const total = files2.reduce((sum, f) => sum + fs74.statSync(path76.join(root, f)).size, 0);
|
|
26976
27088
|
if (total > MAX_BYTES3) invalid("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
|
|
26977
27089
|
for (const extra of [...opts.preview, ...opts.evidence]) {
|
|
26978
|
-
if (!
|
|
26979
|
-
if (
|
|
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)) {
|
|
26980
27092
|
invalid(
|
|
26981
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`,
|
|
26982
27094
|
`${extra} is inside the template folder; keep previews and evidence outside it.`
|
|
@@ -26988,10 +27100,10 @@ async function templatePublish(dir, opts) {
|
|
|
26988
27100
|
}
|
|
26989
27101
|
const form = new FormData();
|
|
26990
27102
|
form.set("meta", JSON.stringify({ ...meta, replace: !!opts.replace }));
|
|
26991
|
-
const add = (kind, name, file) => form.append(`${kind}:${name}`, new Blob([
|
|
26992
|
-
for (const f of files2) add("files", f,
|
|
26993
|
-
for (const f of opts.preview) add("previews",
|
|
26994
|
-
for (const f of opts.evidence) add("evidence",
|
|
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);
|
|
26995
27107
|
const done2 = await asJson(await ask("", { method: "POST", body: form }));
|
|
26996
27108
|
say(
|
|
26997
27109
|
done2.replaced ? `\u5DF2\u66FF\u6362 ${done2.name}\uFF1A${files2.length} \u4E2A\u6587\u4EF6\u3002
|
|
@@ -27007,11 +27119,11 @@ Deleted ${name} from the catalog.`);
|
|
|
27007
27119
|
return { name, deleted: true };
|
|
27008
27120
|
}
|
|
27009
27121
|
async function templateShowcase(name, dir) {
|
|
27010
|
-
const file =
|
|
27011
|
-
if (!
|
|
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}.`);
|
|
27012
27124
|
let meta;
|
|
27013
27125
|
try {
|
|
27014
|
-
meta = JSON.parse(
|
|
27126
|
+
meta = JSON.parse(fs74.readFileSync(file, "utf8"));
|
|
27015
27127
|
} catch {
|
|
27016
27128
|
return invalid("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
|
|
27017
27129
|
}
|
|
@@ -27023,9 +27135,9 @@ async function templateShowcase(name, dir) {
|
|
|
27023
27135
|
const form = new FormData();
|
|
27024
27136
|
form.set("meta", JSON.stringify(meta));
|
|
27025
27137
|
for (const p of new Set(named2)) {
|
|
27026
|
-
const at =
|
|
27027
|
-
if (!
|
|
27028
|
-
form.append(`media:${p}`, new Blob([
|
|
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);
|
|
27029
27141
|
}
|
|
27030
27142
|
const done2 = await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form }));
|
|
27031
27143
|
say(`\u5DF2\u66F4\u65B0 ${name} \u7684\u5C55\u793A\u8D44\u6599\uFF1A${done2.files} \u4E2A\u6587\u4EF6\u3002
|
|
@@ -27034,7 +27146,7 @@ Updated ${name}'s showcase: ${done2.files} files.`);
|
|
|
27034
27146
|
}
|
|
27035
27147
|
function walk2(root, sub = "") {
|
|
27036
27148
|
const out = [];
|
|
27037
|
-
for (const entry of
|
|
27149
|
+
for (const entry of fs74.readdirSync(path76.join(root, sub), { withFileTypes: true })) {
|
|
27038
27150
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
27039
27151
|
const rel2 = sub ? `${sub}/${entry.name}` : entry.name;
|
|
27040
27152
|
if (entry.isDirectory()) out.push(...walk2(root, rel2));
|
|
@@ -27319,7 +27431,7 @@ init_opencode();
|
|
|
27319
27431
|
init_locate();
|
|
27320
27432
|
init_store();
|
|
27321
27433
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
27322
|
-
import
|
|
27434
|
+
import path82 from "node:path";
|
|
27323
27435
|
var AGENTS2 = {
|
|
27324
27436
|
claude: "claude-code",
|
|
27325
27437
|
codex: "codex",
|
|
@@ -27334,10 +27446,10 @@ var AGENTS2 = {
|
|
|
27334
27446
|
var RUNTIMES = /* @__PURE__ */ new Set(["node", "bun", "deno"]);
|
|
27335
27447
|
function agentOf2(args) {
|
|
27336
27448
|
const words = args.trim().split(/\s+/);
|
|
27337
|
-
const first =
|
|
27449
|
+
const first = path82.basename(words[0] ?? "");
|
|
27338
27450
|
const script = RUNTIMES.has(first) ? words[1] ?? "" : words[0] ?? "";
|
|
27339
27451
|
if (script.includes("/@anthropic-ai/claude-code/")) return "claude-code";
|
|
27340
|
-
return AGENTS2[
|
|
27452
|
+
return AGENTS2[path82.basename(script).replace(/\.(m?js|cjs|exe)$/, "")];
|
|
27341
27453
|
}
|
|
27342
27454
|
function processChain() {
|
|
27343
27455
|
if (process.platform === "win32") return [];
|
|
@@ -27401,8 +27513,8 @@ init_tasks();
|
|
|
27401
27513
|
init_read();
|
|
27402
27514
|
init_rules();
|
|
27403
27515
|
init_board();
|
|
27404
|
-
import
|
|
27405
|
-
import
|
|
27516
|
+
import fs81 from "node:fs";
|
|
27517
|
+
import path83 from "node:path";
|
|
27406
27518
|
var FOLLOW_MS = 400;
|
|
27407
27519
|
async function cmdStartRun(action, args, opts, program2 = "akb") {
|
|
27408
27520
|
const { req, follow: follow2, print } = readRequest(action, args, opts);
|
|
@@ -27692,7 +27804,7 @@ async function cmdSubStart(words, opts) {
|
|
|
27692
27804
|
let prompt = words.join(" ");
|
|
27693
27805
|
if (opts.file) {
|
|
27694
27806
|
try {
|
|
27695
|
-
prompt =
|
|
27807
|
+
prompt = fs81.readFileSync(path83.resolve(opts.file), "utf8");
|
|
27696
27808
|
} catch {
|
|
27697
27809
|
die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
|
|
27698
27810
|
}
|
|
@@ -27983,7 +28095,7 @@ async function cmdWatch(sessionId) {
|
|
|
27983
28095
|
// src/commands/triage.ts
|
|
27984
28096
|
init_scheduled();
|
|
27985
28097
|
init_workflows();
|
|
27986
|
-
import
|
|
28098
|
+
import fs83 from "node:fs";
|
|
27987
28099
|
|
|
27988
28100
|
// src/lib/signals/index.ts
|
|
27989
28101
|
init_cards();
|
|
@@ -27993,16 +28105,16 @@ init_yaml();
|
|
|
27993
28105
|
// src/lib/signals/config.ts
|
|
27994
28106
|
init_settings2();
|
|
27995
28107
|
init_paths();
|
|
27996
|
-
import
|
|
27997
|
-
import
|
|
28108
|
+
import fs82 from "node:fs";
|
|
28109
|
+
import path84 from "node:path";
|
|
27998
28110
|
var TOKEN_KEY = "TRIAGE_ENDPOINT_TOKEN";
|
|
27999
28111
|
var ENDPOINT_SETTING = "Triage endpoint";
|
|
28000
28112
|
var LINE2 = /^- \*\*Triage endpoint\*\*\s*[—-]\s*(.+)$/m;
|
|
28001
|
-
var boardRel3 = (file) => rel(file).split(
|
|
28113
|
+
var boardRel3 = (file) => rel(file).split(path84.sep).join("/");
|
|
28002
28114
|
function signalEndpoint() {
|
|
28003
28115
|
let text5;
|
|
28004
28116
|
try {
|
|
28005
|
-
text5 =
|
|
28117
|
+
text5 = fs82.readFileSync(CONFIG, "utf8");
|
|
28006
28118
|
} catch {
|
|
28007
28119
|
return "";
|
|
28008
28120
|
}
|
|
@@ -28178,7 +28290,7 @@ async function cmdTriageAdd(opts) {
|
|
|
28178
28290
|
let body = opts.text;
|
|
28179
28291
|
if (opts.file !== void 0) {
|
|
28180
28292
|
try {
|
|
28181
|
-
body =
|
|
28293
|
+
body = fs83.readFileSync(opts.file, "utf8");
|
|
28182
28294
|
} catch {
|
|
28183
28295
|
die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
|
|
28184
28296
|
}
|
|
@@ -28742,8 +28854,8 @@ function declareAgent(program2, cli) {
|
|
|
28742
28854
|
}
|
|
28743
28855
|
|
|
28744
28856
|
// src/lib/cli/setup.ts
|
|
28745
|
-
import
|
|
28746
|
-
import
|
|
28857
|
+
import fs85 from "node:fs";
|
|
28858
|
+
import path86 from "node:path";
|
|
28747
28859
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
28748
28860
|
|
|
28749
28861
|
// src/commands/update.ts
|
|
@@ -28757,8 +28869,8 @@ init_paths();
|
|
|
28757
28869
|
init_memory();
|
|
28758
28870
|
init_yaml2();
|
|
28759
28871
|
init_version();
|
|
28760
|
-
import
|
|
28761
|
-
import
|
|
28872
|
+
import fs84 from "node:fs";
|
|
28873
|
+
import path85 from "node:path";
|
|
28762
28874
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
28763
28875
|
var NAME = "wildcrane";
|
|
28764
28876
|
var REPO = "https://github.com/ai4kanban/ai4kanban";
|
|
@@ -28780,10 +28892,10 @@ var Report = class {
|
|
|
28780
28892
|
for (const line of this.notes) say(` ! ${line}`);
|
|
28781
28893
|
}
|
|
28782
28894
|
};
|
|
28783
|
-
var read3 = (file) =>
|
|
28895
|
+
var read3 = (file) => fs84.existsSync(file) ? fs84.readFileSync(file, "utf8") : null;
|
|
28784
28896
|
function statOf(p) {
|
|
28785
28897
|
try {
|
|
28786
|
-
return
|
|
28898
|
+
return fs84.lstatSync(p);
|
|
28787
28899
|
} catch {
|
|
28788
28900
|
return null;
|
|
28789
28901
|
}
|
|
@@ -28808,10 +28920,10 @@ async function cmdUpdate2(ctx) {
|
|
|
28808
28920
|
return { updated: ctx.dir, from, to: SKILL_VERSION };
|
|
28809
28921
|
}
|
|
28810
28922
|
async function repairBoard(root, report3, named2) {
|
|
28811
|
-
const legacy =
|
|
28812
|
-
const kept2 =
|
|
28813
|
-
const board2 = named2 ?? (
|
|
28814
|
-
if (!
|
|
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)) {
|
|
28815
28927
|
report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
|
|
28816
28928
|
return false;
|
|
28817
28929
|
}
|
|
@@ -28842,20 +28954,20 @@ function moveRuntimes(root, board2, report3) {
|
|
|
28842
28954
|
}
|
|
28843
28955
|
}
|
|
28844
28956
|
function moveLegacyMemory(board2, report3) {
|
|
28845
|
-
const memory =
|
|
28957
|
+
const memory = path85.join(board2, "memory");
|
|
28846
28958
|
const moved = [];
|
|
28847
28959
|
for (const name of MEMORY_FILES) {
|
|
28848
|
-
const from =
|
|
28960
|
+
const from = path85.join(board2, name);
|
|
28849
28961
|
const st = statOf(from);
|
|
28850
28962
|
if (!st || !st.isFile()) continue;
|
|
28851
|
-
|
|
28852
|
-
const to =
|
|
28963
|
+
fs84.mkdirSync(memory, { recursive: true });
|
|
28964
|
+
const to = path85.join(memory, name);
|
|
28853
28965
|
const there = read3(to);
|
|
28854
28966
|
if (there === null) {
|
|
28855
|
-
|
|
28967
|
+
fs84.renameSync(from, to);
|
|
28856
28968
|
moved.push(name);
|
|
28857
28969
|
} else if (there === read3(from)) {
|
|
28858
|
-
|
|
28970
|
+
fs84.rmSync(from);
|
|
28859
28971
|
moved.push(name);
|
|
28860
28972
|
} else {
|
|
28861
28973
|
report3.notes.push(`both docs/kanban/${name} and docs/kanban/memory/${name} exist and differ \u2014 merge them by hand`);
|
|
@@ -28864,23 +28976,23 @@ function moveLegacyMemory(board2, report3) {
|
|
|
28864
28976
|
if (moved.length) report3.did.push(`moved the memory set into docs/kanban/memory/: ${moved.join(", ")}`);
|
|
28865
28977
|
}
|
|
28866
28978
|
function dropRecordFile(board2) {
|
|
28867
|
-
const file =
|
|
28868
|
-
if (!
|
|
28869
|
-
|
|
28979
|
+
const file = path85.join(board2, "record.csv");
|
|
28980
|
+
if (!fs84.existsSync(file)) return null;
|
|
28981
|
+
fs84.rmSync(file);
|
|
28870
28982
|
return "removed docs/kanban/record.csv (the planning scores it fed are gone)";
|
|
28871
28983
|
}
|
|
28872
28984
|
function dropModuleGoals(board2, report3) {
|
|
28873
|
-
const memory =
|
|
28874
|
-
if (!
|
|
28875
|
-
const root = read3(
|
|
28985
|
+
const memory = path85.join(board2, "memory");
|
|
28986
|
+
if (!fs84.existsSync(memory)) return;
|
|
28987
|
+
const root = read3(path85.join(memory, "goal.md"));
|
|
28876
28988
|
let dropped = 0;
|
|
28877
|
-
for (const entry of
|
|
28989
|
+
for (const entry of fs84.readdirSync(memory, { withFileTypes: true })) {
|
|
28878
28990
|
if (!entry.isDirectory()) continue;
|
|
28879
|
-
const file =
|
|
28991
|
+
const file = path85.join(memory, entry.name, "goal.md");
|
|
28880
28992
|
const text5 = read3(file);
|
|
28881
28993
|
if (text5 === null) continue;
|
|
28882
28994
|
if (text5 === root || text5.includes(UNFILLED) || !goalWords(text5)) {
|
|
28883
|
-
|
|
28995
|
+
fs84.rmSync(file);
|
|
28884
28996
|
dropped++;
|
|
28885
28997
|
} else {
|
|
28886
28998
|
report3.notes.push(
|
|
@@ -28902,10 +29014,10 @@ var PLAN_LEADS = {
|
|
|
28902
29014
|
var GONE_LEADS = ["software-planner", "planner"];
|
|
28903
29015
|
function planLeads(board2) {
|
|
28904
29016
|
const leads = { ...PLAN_LEADS };
|
|
28905
|
-
const root =
|
|
28906
|
-
for (const entry of
|
|
29017
|
+
const root = path85.join(board2, "workflows");
|
|
29018
|
+
for (const entry of fs84.existsSync(root) ? fs84.readdirSync(root, { withFileTypes: true }) : []) {
|
|
28907
29019
|
if (!entry.isDirectory()) continue;
|
|
28908
|
-
const meta = splitFrontmatter(read3(
|
|
29020
|
+
const meta = splitFrontmatter(read3(path85.join(root, entry.name, "WORKFLOW.md")) ?? "").meta;
|
|
28909
29021
|
const stages = meta === null ? void 0 : parseYamlBlock(meta).stages;
|
|
28910
29022
|
const plan = stages && typeof stages === "object" && !Array.isArray(stages) ? stages.plan : void 0;
|
|
28911
29023
|
const lead = plan && typeof plan === "object" && !Array.isArray(plan) && typeof plan.lead === "string" ? plan.lead.trim() : "";
|
|
@@ -28914,30 +29026,30 @@ function planLeads(board2) {
|
|
|
28914
29026
|
return leads;
|
|
28915
29027
|
}
|
|
28916
29028
|
function movePlanRules(board2, report3) {
|
|
28917
|
-
const rules =
|
|
29029
|
+
const rules = path85.join(board2, "rules");
|
|
28918
29030
|
const moved = [];
|
|
28919
29031
|
for (const [id, leads] of Object.entries(planLeads(board2))) {
|
|
28920
29032
|
for (const lead of leads) {
|
|
28921
|
-
const from =
|
|
29033
|
+
const from = path85.join(rules, `${lead}.md`);
|
|
28922
29034
|
const rule = read3(from)?.trim();
|
|
28923
29035
|
if (!rule) continue;
|
|
28924
|
-
const to =
|
|
29036
|
+
const to = path85.join(rules, "workflows", `${id}.md`);
|
|
28925
29037
|
const there = read3(to)?.trim() ?? "";
|
|
28926
29038
|
if (!there.includes(rule)) {
|
|
28927
|
-
|
|
28928
|
-
|
|
29039
|
+
fs84.mkdirSync(path85.dirname(to), { recursive: true });
|
|
29040
|
+
fs84.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
|
|
28929
29041
|
`);
|
|
28930
29042
|
moved.push(`${lead} \u2192 ${id}`);
|
|
28931
29043
|
}
|
|
28932
29044
|
}
|
|
28933
29045
|
}
|
|
28934
|
-
for (const lead of GONE_LEADS)
|
|
29046
|
+
for (const lead of GONE_LEADS) fs84.rmSync(path85.join(rules, `${lead}.md`), { force: true });
|
|
28935
29047
|
if (moved.length) report3.did.push(`made each plan agent's rule its workflow's card rule (docs/kanban/rules/workflows/): ${moved.join(", ")}`);
|
|
28936
29048
|
}
|
|
28937
29049
|
function noteOldWorkflows(board2, report3) {
|
|
28938
29050
|
const old = (dir, file, keys) => {
|
|
28939
|
-
const root =
|
|
28940
|
-
return (
|
|
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}`);
|
|
28941
29053
|
};
|
|
28942
29054
|
const files2 = [...old("workflows", "WORKFLOW.md", /^(stages|delivers):/m), ...old("agents", "AGENT.md", /^\s+(hook|lead):/m)];
|
|
28943
29055
|
if (files2.length) {
|
|
@@ -28947,7 +29059,7 @@ function noteOldWorkflows(board2, report3) {
|
|
|
28947
29059
|
}
|
|
28948
29060
|
}
|
|
28949
29061
|
function checkConfig(board2, report3) {
|
|
28950
|
-
const current = read3(
|
|
29062
|
+
const current = read3(path85.join(board2, "config.md"));
|
|
28951
29063
|
if (!current) return;
|
|
28952
29064
|
const added = missingConfigKeys(current);
|
|
28953
29065
|
if (added.length) {
|
|
@@ -28957,7 +29069,7 @@ function checkConfig(board2, report3) {
|
|
|
28957
29069
|
}
|
|
28958
29070
|
}
|
|
28959
29071
|
function checkModules(board2, report3) {
|
|
28960
|
-
const map2 = read3(
|
|
29072
|
+
const map2 = read3(path85.join(board2, "modules.md"));
|
|
28961
29073
|
if (map2 && map2.includes(UNFILLED)) {
|
|
28962
29074
|
report3.notes.push(
|
|
28963
29075
|
"docs/kanban/modules.md is still blank \u2014 write it from the repo (`akb guide module-map`)"
|
|
@@ -29011,14 +29123,14 @@ function declareSetup(program2, cli) {
|
|
|
29011
29123
|
program2.version(SKILL_VERSION, "-v, --version", "print this version").addHelpText("beforeAll", spelled(cli.program));
|
|
29012
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");
|
|
29013
29125
|
const where = (cmd) => {
|
|
29014
|
-
const dir =
|
|
29015
|
-
if (!
|
|
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 });
|
|
29016
29128
|
return dir;
|
|
29017
29129
|
};
|
|
29018
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() {
|
|
29019
29131
|
const dir = where(this);
|
|
29020
29132
|
const named2 = this.optsWithGlobals().board ?? process.env.AI4KANBAN_BOARD?.trim();
|
|
29021
|
-
const board2 = named2 ?
|
|
29133
|
+
const board2 = named2 ? path86.resolve(cli.cwd, named2) : null;
|
|
29022
29134
|
await runAction(ctxOf(this, cli.program), {}, () => cmdUpdate2({ dir, program: cli.program, board: board2 }));
|
|
29023
29135
|
});
|
|
29024
29136
|
program2.command("__rules", { hidden: true }).action(function() {
|
|
@@ -29062,7 +29174,7 @@ function invokedDirectly() {
|
|
|
29062
29174
|
const entry = process.argv[1];
|
|
29063
29175
|
if (!entry) return false;
|
|
29064
29176
|
try {
|
|
29065
|
-
return
|
|
29177
|
+
return fs86.realpathSync(entry) === fs86.realpathSync(SELF2);
|
|
29066
29178
|
} catch {
|
|
29067
29179
|
return false;
|
|
29068
29180
|
}
|