wildcrane 0.11.57 → 0.11.58
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 +745 -862
- package/package.json +2 -2
package/dist/kanban.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// ai4kanban 0.11.
|
|
2
|
+
// ai4kanban 0.11.58 — 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)
|
|
@@ -506,27 +506,30 @@ __export(preview_stages_exports, {
|
|
|
506
506
|
submitPreviewStage: () => submitPreviewStage
|
|
507
507
|
});
|
|
508
508
|
function selectPreviewStages(progress, ids) {
|
|
509
|
-
if (progress.stages.length) throw Error("The stage selection is frozen. Revise the task to change its scope.");
|
|
510
509
|
const wanted = new Set(ids);
|
|
511
510
|
if (!ids.length || wanted.size !== ids.length || ids.some((id) => !progress.definitions.some((stage) => stage.id === id))) throw Error("Choose a nonempty list of unique known stage IDs.");
|
|
512
|
-
const chosen = progress.definitions.
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
511
|
+
const chosen = ids.map((id) => progress.definitions.find((stage) => stage.id === id));
|
|
512
|
+
if (progress.stages.length) {
|
|
513
|
+
if (JSON.stringify(progress.stages.map((stage) => stage.id)) === JSON.stringify(ids)) return;
|
|
514
|
+
progress.archivedSelections = [...progress.archivedSelections ?? [], structuredClone(progress.stages)];
|
|
515
|
+
progress.generation++;
|
|
516
|
+
}
|
|
517
|
+
progress.stages = chosen.map((stage, i) => structuredClone(progress.stages.find((held4) => held4.id === stage.id) ?? { ...stage, status: i === 0 ? "running" : "pending", version: null }));
|
|
518
|
+
progress.currentStageId = progress.stages.find((stage) => !["confirmed", "ready"].includes(stage.status))?.id ?? chosen.at(-1).id;
|
|
516
519
|
}
|
|
517
520
|
function previewBaseline(progress, stageId, execution) {
|
|
518
521
|
const stage = progress.stages.find((stage2) => stage2.id === stageId);
|
|
519
|
-
if (progress.currentStageId !== stageId || !stage
|
|
522
|
+
if (progress.currentStageId !== stageId || !stage) throw Error("Unknown current stage.");
|
|
520
523
|
progress.execution = execution;
|
|
521
524
|
delete progress.failure;
|
|
522
|
-
stage.status = "running";
|
|
525
|
+
if (!["awaiting_confirmation", "ready", "confirmed"].includes(stage.status)) stage.status = "running";
|
|
523
526
|
return { definitionRevision: progress.definitionRevision, generation: progress.generation, stageId, execution };
|
|
524
527
|
}
|
|
525
528
|
function submitPreviewStage(progress, baseline, body, assets) {
|
|
526
529
|
const stage = progress.stages.find((stage2) => stage2.id === baseline.stageId);
|
|
527
530
|
if (baseline.definitionRevision !== progress.definitionRevision || baseline.generation !== progress.generation || baseline.execution !== progress.execution || progress.currentStageId !== baseline.stageId || !stage) throw Error("This execution is outdated. Reload the task.");
|
|
528
531
|
if (["awaiting_confirmation", "ready"].includes(stage.status) && stage.artifact) return stage.artifact;
|
|
529
|
-
if (stage.status !== "running"
|
|
532
|
+
if (stage.status !== "running") throw Error("This stage is not the current execution.");
|
|
530
533
|
const artifact = { stageId: stage.id, version: (stage.version ?? 0) + 1, body, assets: structuredClone(assets) };
|
|
531
534
|
stage.history = [...stage.history ?? [], artifact];
|
|
532
535
|
stage.version = artifact.version;
|
|
@@ -577,10 +580,13 @@ function beginPreviewRevision(progress, execution) {
|
|
|
577
580
|
progress.execution = execution;
|
|
578
581
|
}
|
|
579
582
|
function choosePreviewRevision(progress, from, execution) {
|
|
580
|
-
if (
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
583
|
+
if (progress.execution !== execution) throw Error("This execution is outdated. Reload the task.");
|
|
584
|
+
const saved = progress.revisionBase ?? progress.stages;
|
|
585
|
+
const at2 = saved.findIndex((stage) => stage.id === from);
|
|
586
|
+
if (at2 < 0) throw Error("Unknown stage.");
|
|
587
|
+
progress.archivedSelections = [...progress.archivedSelections ?? [], structuredClone(saved)];
|
|
588
|
+
progress.stages = structuredClone(saved);
|
|
589
|
+
progress.generation++;
|
|
584
590
|
for (const stage of progress.stages.slice(at2)) {
|
|
585
591
|
stage.status = "stale";
|
|
586
592
|
delete stage.confirmation;
|
|
@@ -3352,10 +3358,10 @@ function findRollout(threadId) {
|
|
|
3352
3358
|
}
|
|
3353
3359
|
for (const name of names3) {
|
|
3354
3360
|
if (!name.startsWith("rollout-") || !name.endsWith(tail)) continue;
|
|
3355
|
-
const
|
|
3361
|
+
const path91 = join2(dir, name);
|
|
3356
3362
|
try {
|
|
3357
|
-
const at2 = statSync2(
|
|
3358
|
-
if (!newest2 || at2 > newest2.at) newest2 = { path:
|
|
3363
|
+
const at2 = statSync2(path91).mtimeMs;
|
|
3364
|
+
if (!newest2 || at2 > newest2.at) newest2 = { path: path91, at: at2 };
|
|
3359
3365
|
} catch {
|
|
3360
3366
|
}
|
|
3361
3367
|
}
|
|
@@ -3363,11 +3369,11 @@ function findRollout(threadId) {
|
|
|
3363
3369
|
return newest2?.path;
|
|
3364
3370
|
}
|
|
3365
3371
|
function readCodexRunFacts(threadId) {
|
|
3366
|
-
const
|
|
3367
|
-
if (!
|
|
3372
|
+
const path91 = findRollout(threadId);
|
|
3373
|
+
if (!path91) return void 0;
|
|
3368
3374
|
let raw;
|
|
3369
3375
|
try {
|
|
3370
|
-
raw = readFileSync2(
|
|
3376
|
+
raw = readFileSync2(path91, "utf8");
|
|
3371
3377
|
} catch {
|
|
3372
3378
|
return void 0;
|
|
3373
3379
|
}
|
|
@@ -3493,8 +3499,8 @@ function renderCompleted(item) {
|
|
|
3493
3499
|
const changes = Array.isArray(item.changes) ? item.changes : [];
|
|
3494
3500
|
return changes.map((raw) => {
|
|
3495
3501
|
const change2 = obj2(raw);
|
|
3496
|
-
const
|
|
3497
|
-
return
|
|
3502
|
+
const path91 = str2(change2.path);
|
|
3503
|
+
return path91 ? `\u23FA ${str2(change2.kind) || "change"}(${path91})
|
|
3498
3504
|
` : "";
|
|
3499
3505
|
}).join("");
|
|
3500
3506
|
}
|
|
@@ -3829,10 +3835,10 @@ function readKimiRunFacts(sessionId) {
|
|
|
3829
3835
|
const total = { input: 0, cacheCreation: 0, cacheRead: 0, output: 0 };
|
|
3830
3836
|
let model;
|
|
3831
3837
|
let holding = 0;
|
|
3832
|
-
for (const { path:
|
|
3838
|
+
for (const { path: path91, main } of wireFiles(entry.sessionDir)) {
|
|
3833
3839
|
let raw;
|
|
3834
3840
|
try {
|
|
3835
|
-
raw = readFileSync3(
|
|
3841
|
+
raw = readFileSync3(path91, "utf8");
|
|
3836
3842
|
} catch {
|
|
3837
3843
|
continue;
|
|
3838
3844
|
}
|
|
@@ -4206,8 +4212,8 @@ var init_package = __esm({
|
|
|
4206
4212
|
"package.json"() {
|
|
4207
4213
|
package_default = {
|
|
4208
4214
|
name: "wildcrane",
|
|
4209
|
-
version: "0.11.
|
|
4210
|
-
akbContract:
|
|
4215
|
+
version: "0.11.58",
|
|
4216
|
+
akbContract: 16,
|
|
4211
4217
|
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.",
|
|
4212
4218
|
keywords: [
|
|
4213
4219
|
"kanban",
|
|
@@ -4283,8 +4289,8 @@ var init_version = __esm({
|
|
|
4283
4289
|
import fs16 from "node:fs";
|
|
4284
4290
|
function whereHint(update2, title) {
|
|
4285
4291
|
const locations = Array.isArray(update2.locations) ? update2.locations : [];
|
|
4286
|
-
const
|
|
4287
|
-
return
|
|
4292
|
+
const path91 = str2(obj2(locations[0]).path);
|
|
4293
|
+
return path91 && !title.includes(path91) ? hint(path91) : "";
|
|
4288
4294
|
}
|
|
4289
4295
|
function saidBy(update2) {
|
|
4290
4296
|
const content = Array.isArray(update2.content) ? update2.content : [];
|
|
@@ -5437,7 +5443,7 @@ async function run(io, options, tasks) {
|
|
|
5437
5443
|
startupTimer = setTimeout(() => {
|
|
5438
5444
|
if (!started) io.event?.({ kind: "log", data: { text: "[conversation] start_unconfirmed" } });
|
|
5439
5445
|
}, CONVERSATION_MS.start);
|
|
5440
|
-
await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text5 }, ...images.map((
|
|
5446
|
+
await bounded(rpc.call("turn/start", { threadId, input: [{ type: "text", text: text5 }, ...images.map((path91) => ({ type: "localImage", path: path91 }))] }), CONVERSATION_MS.start, "Codex turn/start timed out; submission outcome is unknown.").catch((error) => {
|
|
5441
5447
|
if (!started) throw error;
|
|
5442
5448
|
});
|
|
5443
5449
|
};
|
|
@@ -8413,8 +8419,8 @@ var init_file_limits = __esm({
|
|
|
8413
8419
|
});
|
|
8414
8420
|
|
|
8415
8421
|
// src/lib/shared/board-files.ts
|
|
8416
|
-
function studioRenamed(
|
|
8417
|
-
const to =
|
|
8422
|
+
function studioRenamed(path91, content) {
|
|
8423
|
+
const to = path91.replace(/^(rules\/)?workflows\//, "$1studios/").replace(/^(studios\/[^/]+)\/WORKFLOW\.md$/, "$1/STUDIO.md");
|
|
8418
8424
|
if (!to.endsWith(".md")) return { path: to, content };
|
|
8419
8425
|
if (to.startsWith("studios/")) return { path: to, content: content.replace(/^(icon:\s*["']?)workflow(-kit)?(["']?\s*)$/gm, "$1studio$2$3") };
|
|
8420
8426
|
const front = /^(?:todo|triage)\//.test(to) ? /^---\r?\n[\s\S]*?\r?\n---/.exec(content)?.[0] : void 0;
|
|
@@ -8915,7 +8921,7 @@ function diagramFrom(files) {
|
|
|
8915
8921
|
if ("problem" in read3) return null;
|
|
8916
8922
|
return studioDiagram(read3.def, (name) => {
|
|
8917
8923
|
const text5 = files[`agents/${name}/AGENT.md`];
|
|
8918
|
-
const parsed = text5 === void 0 ? null : parseSpecAgent(text5, name, (
|
|
8924
|
+
const parsed = text5 === void 0 ? null : parseSpecAgent(text5, name, (path91) => files[`agents/${name}/${path91}`] ?? null, false);
|
|
8919
8925
|
return parsed && "agent" in parsed ? parsed.agent : null;
|
|
8920
8926
|
});
|
|
8921
8927
|
}
|
|
@@ -11065,7 +11071,6 @@ var init_candidate = __esm({
|
|
|
11065
11071
|
|
|
11066
11072
|
// src/lib/agent/outputs.ts
|
|
11067
11073
|
import fs32 from "node:fs";
|
|
11068
|
-
import os4 from "node:os";
|
|
11069
11074
|
import path36 from "node:path";
|
|
11070
11075
|
function cardBody(cardId2) {
|
|
11071
11076
|
const found2 = locate(cardId2) ?? locateArchived(cardId2);
|
|
@@ -11089,23 +11094,11 @@ function recordedOutputs(delivery) {
|
|
|
11089
11094
|
}
|
|
11090
11095
|
return out;
|
|
11091
11096
|
}
|
|
11092
|
-
|
|
11093
|
-
const outputs = recordedOutputs(delivery);
|
|
11094
|
-
if (!outputs.length) {
|
|
11095
|
-
return { reason: "output", why: "the card records no output file", paths: [] };
|
|
11096
|
-
}
|
|
11097
|
-
const missing = outputs.filter((f2) => !fs32.existsSync(resolveOutput(f2)));
|
|
11098
|
-
if (missing.length) {
|
|
11099
|
-
return { reason: "output", why: `recorded output files are missing: ${missing.join(", ")}`, paths: missing };
|
|
11100
|
-
}
|
|
11101
|
-
return void 0;
|
|
11102
|
-
}
|
|
11103
|
-
var TODO2, todos, plannedTodos, looksLikePath, resolveOutput;
|
|
11097
|
+
var TODO2, todos, plannedTodos, looksLikePath;
|
|
11104
11098
|
var init_outputs = __esm({
|
|
11105
11099
|
"src/lib/agent/outputs.ts"() {
|
|
11106
11100
|
"use strict";
|
|
11107
11101
|
init_cards();
|
|
11108
|
-
init_paths();
|
|
11109
11102
|
TODO2 = /^\s*[-*]\s+\[([ xX])\]\s+(.*)$/;
|
|
11110
11103
|
todos = (cardId2) => cardBody(cardId2).split("\n").flatMap((line) => {
|
|
11111
11104
|
const m = TODO2.exec(line);
|
|
@@ -11113,12 +11106,6 @@ var init_outputs = __esm({
|
|
|
11113
11106
|
});
|
|
11114
11107
|
plannedTodos = (cardId2) => todos(cardId2).map((t) => t.text);
|
|
11115
11108
|
looksLikePath = (token2) => !/\s/.test(token2) && !token2.includes("://") && !token2.startsWith("-") && token2.includes("/");
|
|
11116
|
-
resolveOutput = (file2) => {
|
|
11117
|
-
if (file2.startsWith("~/")) return path36.join(os4.homedir(), file2.slice(2));
|
|
11118
|
-
if (path36.isAbsolute(file2)) return file2;
|
|
11119
|
-
if (file2.startsWith(".assets/")) return path36.join(ASSETS, file2.slice(".assets/".length));
|
|
11120
|
-
return path36.join(REPO_ROOT, file2);
|
|
11121
|
-
};
|
|
11122
11109
|
}
|
|
11123
11110
|
});
|
|
11124
11111
|
|
|
@@ -11264,7 +11251,7 @@ function nextDeliveryRun(deliveryId) {
|
|
|
11264
11251
|
for (const delivery of store.deliveries) {
|
|
11265
11252
|
if (deliveryId && delivery.deliveryId !== deliveryId) continue;
|
|
11266
11253
|
if (delivery.status !== "active" || delivery.cardId === null) continue;
|
|
11267
|
-
if (
|
|
11254
|
+
if (store.runs.some((r2) => r2.deliveryId === delivery.deliveryId && r2.status === "running")) continue;
|
|
11268
11255
|
if (answerOutcome(delivery) === "changed") {
|
|
11269
11256
|
const superseded = withStore((live) => {
|
|
11270
11257
|
const row = live.deliveries.find((d2) => d2.deliveryId === delivery.deliveryId);
|
|
@@ -11640,28 +11627,14 @@ function resumeRefusal(delivery, store) {
|
|
|
11640
11627
|
const id = delivery.deliveryId;
|
|
11641
11628
|
const what = delivery.cardId === null ? "the build" : `#${delivery.cardId}`;
|
|
11642
11629
|
const task = delivery.cardId === null ? "" : String(delivery.cardId);
|
|
11643
|
-
if (delivery.status === "active") {
|
|
11644
|
-
return refusal("deliveryActive", `delivery ${id} has not ended \u2014 it is still in flight on ${what}.`, { id, task });
|
|
11645
|
-
}
|
|
11646
|
-
if (delivery.status === "finished") {
|
|
11647
|
-
return refusal("deliveryFinished", `delivery ${id} finished; resume carries on one that ended abnormally.`, { id });
|
|
11648
|
-
}
|
|
11649
11630
|
if (delivery.status === "cancelled") {
|
|
11650
11631
|
return refusal("deliveryCancelled", `delivery ${id} was cancelled, and its files were preserved. Start ${what} again.`, { id, task });
|
|
11651
11632
|
}
|
|
11652
11633
|
if (delivery.cardId === null) return void 0;
|
|
11653
11634
|
const card = String(delivery.cardId);
|
|
11654
|
-
const pendingArchive = delivery.completions?.some((c2) => !c2.finished && c2.step + 1 >= (delivery.studio?.land?.length ?? 1));
|
|
11655
|
-
if (cardOnBoard(delivery.cardId) === false && !(pendingArchive && locateArchived(delivery.cardId))) {
|
|
11656
|
-
return refusal(
|
|
11657
|
-
"deliveryCardGone",
|
|
11658
|
-
`#${card} is no longer on the board, so delivery ${id} has nothing left to finish.`,
|
|
11659
|
-
{ id, card }
|
|
11660
|
-
);
|
|
11661
|
-
}
|
|
11662
11635
|
const live = store ?? readStore();
|
|
11663
11636
|
const holder = activeIn(live, delivery.cardId);
|
|
11664
|
-
if (holder) {
|
|
11637
|
+
if (holder && holder.deliveryId !== id) {
|
|
11665
11638
|
const command = `${boardCommand()} raw delivery cancel ${holder.deliveryId}`;
|
|
11666
11639
|
return refusal(
|
|
11667
11640
|
"deliveryHeld",
|
|
@@ -11681,16 +11654,10 @@ function resumeRefusal(delivery, store) {
|
|
|
11681
11654
|
}
|
|
11682
11655
|
return void 0;
|
|
11683
11656
|
}
|
|
11684
|
-
function cardOnBoard(cardId2) {
|
|
11685
|
-
try {
|
|
11686
|
-
return !!locate(cardId2);
|
|
11687
|
-
} catch {
|
|
11688
|
-
return void 0;
|
|
11689
|
-
}
|
|
11690
|
-
}
|
|
11691
11657
|
function resumeRecord(id, execution) {
|
|
11692
11658
|
const found2 = namedDelivery(id) ?? endedDelivery(id);
|
|
11693
11659
|
if (!found2) return { ok: false, ...unknownDelivery(id) };
|
|
11660
|
+
if (found2.status === "finished") return { ok: true, delivery: found2 };
|
|
11694
11661
|
const refused = resumeRefusal(found2);
|
|
11695
11662
|
if (refused && found2.status !== "active") return { ok: false, ...refused };
|
|
11696
11663
|
const out = withStore((store) => {
|
|
@@ -11704,6 +11671,7 @@ function resumeRecord(id, execution) {
|
|
|
11704
11671
|
return { ok: false, ...refusal("deliveryRunGoing", "the delivery still has a running agent; stop it before continuing") };
|
|
11705
11672
|
}
|
|
11706
11673
|
} else if (again) return { ok: false, ...again };
|
|
11674
|
+
if (row.status === "finished") return { ok: true, delivery: row };
|
|
11707
11675
|
const at2 = Date.now();
|
|
11708
11676
|
const resumed = {
|
|
11709
11677
|
...row,
|
|
@@ -13410,7 +13378,7 @@ function kindOf2(ext) {
|
|
|
13410
13378
|
if (type.startsWith("image/")) return "image";
|
|
13411
13379
|
return type.startsWith("video/") || type.startsWith("audio/") ? "video" : "asset";
|
|
13412
13380
|
}
|
|
13413
|
-
var STORYBOARD, STUDIO, ARRANGED, ASSET, isObject, TYPES;
|
|
13381
|
+
var STORYBOARD, STUDIO, ARRANGED, ASSET, isObject, bodySources, TYPES;
|
|
13414
13382
|
var init_references = __esm({
|
|
13415
13383
|
"../artifact-sdk/src/internal/references.ts"() {
|
|
13416
13384
|
"use strict";
|
|
@@ -13419,6 +13387,7 @@ var init_references = __esm({
|
|
|
13419
13387
|
ARRANGED = ["storyboard", "compare", "spritesheet", "studio"];
|
|
13420
13388
|
ASSET = ["spritesheet", "asset"];
|
|
13421
13389
|
isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
13390
|
+
bodySources = (body) => [...new Set(bodyReferences(body).map((r2) => r2.src))];
|
|
13422
13391
|
TYPES = {
|
|
13423
13392
|
".png": "image/png",
|
|
13424
13393
|
".jpg": "image/jpeg",
|
|
@@ -13570,14 +13539,14 @@ function collectSources(sources2, card, host2) {
|
|
|
13570
13539
|
const active2 = /* @__PURE__ */ new Set();
|
|
13571
13540
|
const out = [];
|
|
13572
13541
|
const visit = (src, types, owner, partial = false) => {
|
|
13573
|
-
const
|
|
13542
|
+
const path91 = src.replace(/[?#].*$/, "");
|
|
13574
13543
|
let resolved2;
|
|
13575
13544
|
try {
|
|
13576
|
-
resolved2 = host2.resolve(
|
|
13545
|
+
resolved2 = host2.resolve(path91, owner);
|
|
13577
13546
|
} catch (error) {
|
|
13578
13547
|
if (owner !== card) return { key: null, error: why(error) };
|
|
13579
13548
|
if (!nodes.has(src)) {
|
|
13580
|
-
const node2 = { key: src, file: null, kind: kindAt(
|
|
13549
|
+
const node2 = { key: src, file: null, kind: kindAt(path91, types), error: why(error), problems: [], dependencies: /* @__PURE__ */ new Map(), aliases: /* @__PURE__ */ new Set([src]) };
|
|
13581
13550
|
nodes.set(src, node2);
|
|
13582
13551
|
out.push(node2);
|
|
13583
13552
|
}
|
|
@@ -14063,7 +14032,7 @@ function validateStoryboards(file2, id, text5) {
|
|
|
14063
14032
|
function formatContractErrors(errors) {
|
|
14064
14033
|
return ["Spec format validation failed. Fix these errors without changing the planned behavior:", ...errors.map((e2) => `${e2.file}:${e2.line} [${e2.rule}] ${e2.message}`)].join("\n");
|
|
14065
14034
|
}
|
|
14066
|
-
var ASSET_LINE, BLOCK_LINE
|
|
14035
|
+
var ASSET_LINE, BLOCK_LINE;
|
|
14067
14036
|
var init_spec_contract = __esm({
|
|
14068
14037
|
"src/lib/spec-contract.ts"() {
|
|
14069
14038
|
"use strict";
|
|
@@ -14076,8 +14045,6 @@ var init_spec_contract = __esm({
|
|
|
14076
14045
|
init_validate();
|
|
14077
14046
|
ASSET_LINE = /^\s*<(?:Asset|Mockup)\b[^<>]*\/>\s*$/;
|
|
14078
14047
|
BLOCK_LINE = /^\s*<(?:Asset\b|Mockup\b|Set\b|\/Set>)/;
|
|
14079
|
-
boardCheckErrors = (errors) => ["Board check failed. Fix these errors without changing the planned behavior:", ...errors.map((e2) => `${e2.file}:${e2.line} [${e2.rule}] ${e2.message}`)].join("\n");
|
|
14080
|
-
boardProblems = (errors) => ["Board problems:", ...errors.map((e2) => `- ${e2.message}`)].join("\n");
|
|
14081
14048
|
}
|
|
14082
14049
|
});
|
|
14083
14050
|
|
|
@@ -14172,14 +14139,6 @@ function reconcileBoard() {
|
|
|
14172
14139
|
if (!fs44.existsSync(README)) return;
|
|
14173
14140
|
for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
|
|
14174
14141
|
}
|
|
14175
|
-
function boardComplaints() {
|
|
14176
|
-
if (!fs44.existsSync(README)) return [];
|
|
14177
|
-
try {
|
|
14178
|
-
return [...readmeComplaints(false), ...crossRefComplaints()];
|
|
14179
|
-
} catch {
|
|
14180
|
-
return [];
|
|
14181
|
-
}
|
|
14182
|
-
}
|
|
14183
14142
|
var README_LINK;
|
|
14184
14143
|
var init_reconcile = __esm({
|
|
14185
14144
|
"src/lib/reconcile.ts"() {
|
|
@@ -15672,22 +15631,6 @@ function stampLeaving(cards, rejection) {
|
|
|
15672
15631
|
if (stamped !== text5) fs54.writeFileSync(card.file, stamped);
|
|
15673
15632
|
}
|
|
15674
15633
|
}
|
|
15675
|
-
function unfinishedDelivery(id) {
|
|
15676
|
-
const card = findCard(id);
|
|
15677
|
-
if (card?.deliversIn !== "plan") return null;
|
|
15678
|
-
const gap = planDeliveryGap(card);
|
|
15679
|
-
if (gap) {
|
|
15680
|
-
const what = {
|
|
15681
|
-
questions: "it still has open questions",
|
|
15682
|
-
deliverable: "no finished deliverable is on the card",
|
|
15683
|
-
command: "no ticked todo records where it was delivered or the command that rebuilds it",
|
|
15684
|
-
todos: "not every todo is ticked"
|
|
15685
|
-
}[gap];
|
|
15686
|
-
return `#${id} is not finished: ${what}.`;
|
|
15687
|
-
}
|
|
15688
|
-
const missing = planDeliverables(card.body).filter((src) => src.startsWith(".assets/")).find((src) => !fs54.existsSync(path56.join(ASSETS, src.slice(".assets/".length))));
|
|
15689
|
-
return missing ? `#${id} is not finished: ${missing} is not on this machine.` : null;
|
|
15690
|
-
}
|
|
15691
15634
|
function agentDecisions(text5) {
|
|
15692
15635
|
let section = null;
|
|
15693
15636
|
const counts = { stood: 0, overruled: 0 };
|
|
@@ -15713,8 +15656,6 @@ function removeCard2(id, metric, options) {
|
|
|
15713
15656
|
if (creating) die(creating, { kind: "card-being-created" });
|
|
15714
15657
|
const found2 = locate(id);
|
|
15715
15658
|
if (!found2) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
|
|
15716
|
-
const unfinished = metric === "completed" ? unfinishedDelivery(id) : null;
|
|
15717
|
-
if (unfinished) die(unfinished, { kind: "plan-delivery-unfinished" });
|
|
15718
15659
|
const dest = options.cleanupDiscarded && locateArchived(id) ? null : archiveDest(found2);
|
|
15719
15660
|
const cardFile3 = found2.kind === "group" ? path56.join(found2.target, "root.md") : found2.target;
|
|
15720
15661
|
const cardText = fs54.existsSync(cardFile3) ? fs54.readFileSync(cardFile3, "utf8") : "";
|
|
@@ -15900,7 +15841,6 @@ var init_remove = __esm({
|
|
|
15900
15841
|
init_creation_lock();
|
|
15901
15842
|
init_lock();
|
|
15902
15843
|
init_rules();
|
|
15903
|
-
init_read();
|
|
15904
15844
|
init_cadence();
|
|
15905
15845
|
init_paths();
|
|
15906
15846
|
init_io();
|
|
@@ -16135,6 +16075,96 @@ var init_memory_file = __esm({
|
|
|
16135
16075
|
}
|
|
16136
16076
|
});
|
|
16137
16077
|
|
|
16078
|
+
// src/commands/inspect.ts
|
|
16079
|
+
import fs57 from "node:fs";
|
|
16080
|
+
import os4 from "node:os";
|
|
16081
|
+
import path59 from "node:path";
|
|
16082
|
+
function cmdInspect(id) {
|
|
16083
|
+
const findings = [];
|
|
16084
|
+
const unavailable = [];
|
|
16085
|
+
function read3(source2, file3, empty) {
|
|
16086
|
+
try {
|
|
16087
|
+
return JSON.parse(fs57.readFileSync(file3, "utf8"));
|
|
16088
|
+
} catch (error) {
|
|
16089
|
+
if (error.code === "ENOENT") return empty;
|
|
16090
|
+
findings.push({ source: source2, message: String(error) });
|
|
16091
|
+
unavailable.push(source2);
|
|
16092
|
+
return empty;
|
|
16093
|
+
}
|
|
16094
|
+
}
|
|
16095
|
+
function fact(source2, get, empty) {
|
|
16096
|
+
try {
|
|
16097
|
+
return get();
|
|
16098
|
+
} catch (error) {
|
|
16099
|
+
findings.push({ source: source2, message: String(error) });
|
|
16100
|
+
unavailable.push(source2);
|
|
16101
|
+
return empty;
|
|
16102
|
+
}
|
|
16103
|
+
}
|
|
16104
|
+
const found2 = locate(id) ?? locateArchived(id);
|
|
16105
|
+
if (!found2) return die(`no task with id ${id}`, { kind: "card-not-found", id });
|
|
16106
|
+
const file2 = found2.kind === "group" ? path59.join(found2.target, "root.md") : found2.target;
|
|
16107
|
+
let card = null;
|
|
16108
|
+
try {
|
|
16109
|
+
const { meta, body } = parseFrontmatter(fs57.readFileSync(file2, "utf8"));
|
|
16110
|
+
if (!meta) throw Error("The card frontmatter could not be parsed.");
|
|
16111
|
+
card = { path: rel(file2), questions: meta.questions, todos: [...body.matchAll(/^\s*[-*]\s+\[([ xX])\]\s+(.*)$/gm)].map((m) => ({ text: m[2], done: m[1] !== " " })) };
|
|
16112
|
+
} catch (error) {
|
|
16113
|
+
findings.push({ source: "card", message: String(error) });
|
|
16114
|
+
unavailable.push("card");
|
|
16115
|
+
}
|
|
16116
|
+
const progress = read3("previews", path59.join(BOARD_STATE, "previews", `${id}.json`), {});
|
|
16117
|
+
const store = read3("runs", SESSIONS, {});
|
|
16118
|
+
const runs = fact("runs", () => (store.runs ?? []).filter((run4) => run4.cardId === id).slice(-10).reverse().map((run4) => ({ id: run4.sessionId, status: run4.status, sessionRecorded: run4.harness ? !!(run4.resumeId || run4.continues?.resumeId) : null })), []);
|
|
16119
|
+
const records = [];
|
|
16120
|
+
const directory = path59.join(KANBAN, "deliveries");
|
|
16121
|
+
try {
|
|
16122
|
+
for (const name of fs57.readdirSync(directory).filter((name2) => name2.endsWith(".json"))) {
|
|
16123
|
+
const held5 = read3("delivery", path59.join(directory, name), null);
|
|
16124
|
+
if (held5?.cardId === id) records.push(held5);
|
|
16125
|
+
}
|
|
16126
|
+
} catch (error) {
|
|
16127
|
+
if (error.code !== "ENOENT") {
|
|
16128
|
+
findings.push({ source: "delivery", message: String(error) });
|
|
16129
|
+
unavailable.push("delivery");
|
|
16130
|
+
}
|
|
16131
|
+
}
|
|
16132
|
+
records.push(...fact("delivery", () => (store.deliveries ?? []).filter((held5) => held5.cardId === id), []));
|
|
16133
|
+
const held4 = [...new Map(records.map((held5) => [held5.deliveryId, held5])).values()].sort((a2, b2) => b2.startedAt - a2.startedAt)[0];
|
|
16134
|
+
const job = executionOf()?.job;
|
|
16135
|
+
const checkpoint = job ? read3("recovery", path59.join(process.env.WILDCRANE_HOME || os4.homedir() + "/.wildcrane", "checkpoints", `${encodeURIComponent(job)}.json`), null) : null;
|
|
16136
|
+
const delivery = fact("delivery", () => held4 ? { id: held4.deliveryId, status: held4.status, directory: held4.worktree ?? REPO_ROOT, completedSteps: (held4.completions ?? []).map((c2) => c2.step) } : null, null);
|
|
16137
|
+
const recovery = fact("recovery", () => checkpoint ? { pendingOperations: checkpoint.pending ?? [], submitted: checkpoint.submitted ?? null } : null, null);
|
|
16138
|
+
const result = {
|
|
16139
|
+
id,
|
|
16140
|
+
card,
|
|
16141
|
+
previews: fact("previews", () => Object.entries(progress).map(([agent, p2]) => ({
|
|
16142
|
+
agent,
|
|
16143
|
+
currentStageId: p2.currentStageId,
|
|
16144
|
+
stages: p2.stages.map(({ id: id2, status, version }) => ({ id: id2, status, version })),
|
|
16145
|
+
artifact: p2.displayedArtifact ? { stageId: p2.displayedArtifact.stageId, version: p2.displayedArtifact.version, section: `## By \`${agent}\` agent`, files: [.../* @__PURE__ */ new Set([...Object.keys(p2.displayedArtifact.assets).filter((key) => key !== "folder"), ...bodySources(p2.displayedArtifact.body)])].filter((file3) => !path59.isAbsolute(file3) && !/^[a-z][\w+.-]*:/i.test(file3)) } : null
|
|
16146
|
+
})), []),
|
|
16147
|
+
delivery,
|
|
16148
|
+
runs,
|
|
16149
|
+
recovery,
|
|
16150
|
+
findings,
|
|
16151
|
+
unavailable: [...new Set(unavailable)]
|
|
16152
|
+
};
|
|
16153
|
+
say(JSON.stringify(result, null, 2));
|
|
16154
|
+
return result;
|
|
16155
|
+
}
|
|
16156
|
+
var init_inspect = __esm({
|
|
16157
|
+
"src/commands/inspect.ts"() {
|
|
16158
|
+
"use strict";
|
|
16159
|
+
init_cards();
|
|
16160
|
+
init_frontmatter();
|
|
16161
|
+
init_io();
|
|
16162
|
+
init_paths();
|
|
16163
|
+
init_execution();
|
|
16164
|
+
init_references();
|
|
16165
|
+
}
|
|
16166
|
+
});
|
|
16167
|
+
|
|
16138
16168
|
// src/commands/validate.ts
|
|
16139
16169
|
function cmdValidate(id) {
|
|
16140
16170
|
const cards = [...snapshotSpecs()].filter(([, card]) => id === void 0 || card.id === id);
|
|
@@ -16202,11 +16232,11 @@ var init_ops = __esm({
|
|
|
16202
16232
|
});
|
|
16203
16233
|
|
|
16204
16234
|
// src/lib/view/stamp.ts
|
|
16205
|
-
import
|
|
16206
|
-
import
|
|
16235
|
+
import fs58 from "node:fs";
|
|
16236
|
+
import path60 from "node:path";
|
|
16207
16237
|
function boardStamp() {
|
|
16208
16238
|
const parts = [];
|
|
16209
|
-
for (const dir of [TODO, MEMORY, ASSETS, MOCKUPS,
|
|
16239
|
+
for (const dir of [TODO, MEMORY, ASSETS, MOCKUPS, path60.join(KANBAN, ".mockups")]) walk(dir, parts, 0);
|
|
16210
16240
|
for (const file2 of [MODULES_MD, ARCHIVE_MD, CONFIG]) {
|
|
16211
16241
|
stamp3(file2, parts);
|
|
16212
16242
|
}
|
|
@@ -16216,19 +16246,19 @@ function walk(dir, parts, depth3) {
|
|
|
16216
16246
|
if (depth3 > MAX_DEPTH) return;
|
|
16217
16247
|
let entries;
|
|
16218
16248
|
try {
|
|
16219
|
-
entries =
|
|
16249
|
+
entries = fs58.readdirSync(dir, { withFileTypes: true });
|
|
16220
16250
|
} catch {
|
|
16221
16251
|
return;
|
|
16222
16252
|
}
|
|
16223
16253
|
for (const entry of entries.sort((a2, b2) => a2.name.localeCompare(b2.name))) {
|
|
16224
|
-
const full =
|
|
16254
|
+
const full = path60.join(dir, entry.name);
|
|
16225
16255
|
if (entry.isDirectory()) walk(full, parts, depth3 + 1);
|
|
16226
16256
|
else stamp3(full, parts);
|
|
16227
16257
|
}
|
|
16228
16258
|
}
|
|
16229
16259
|
function stamp3(file2, parts) {
|
|
16230
16260
|
try {
|
|
16231
|
-
const s =
|
|
16261
|
+
const s = fs58.statSync(file2);
|
|
16232
16262
|
parts.push(`${file2}:${s.size}:${Math.round(s.mtimeMs)}`);
|
|
16233
16263
|
} catch {
|
|
16234
16264
|
}
|
|
@@ -16260,8 +16290,8 @@ var init_contract = __esm({
|
|
|
16260
16290
|
});
|
|
16261
16291
|
|
|
16262
16292
|
// src/lib/board/revision.ts
|
|
16263
|
-
import
|
|
16264
|
-
import
|
|
16293
|
+
import fs59 from "node:fs";
|
|
16294
|
+
import path61 from "node:path";
|
|
16265
16295
|
function revisionOf(text5) {
|
|
16266
16296
|
let h3 = 2166136261;
|
|
16267
16297
|
for (let i = 0; i < text5.length; i++) {
|
|
@@ -16273,13 +16303,13 @@ function revisionOf(text5) {
|
|
|
16273
16303
|
function cardFile2(id) {
|
|
16274
16304
|
const found2 = locate(id);
|
|
16275
16305
|
if (!found2) return null;
|
|
16276
|
-
return found2.kind === "group" ?
|
|
16306
|
+
return found2.kind === "group" ? path61.join(found2.target, "root.md") : found2.target;
|
|
16277
16307
|
}
|
|
16278
16308
|
function cardRevision(id) {
|
|
16279
16309
|
const file2 = cardFile2(id);
|
|
16280
16310
|
if (!file2) return NO_REVISION;
|
|
16281
16311
|
try {
|
|
16282
|
-
return revisionOf(
|
|
16312
|
+
return revisionOf(fs59.readFileSync(file2, "utf8"));
|
|
16283
16313
|
} catch {
|
|
16284
16314
|
return NO_REVISION;
|
|
16285
16315
|
}
|
|
@@ -16331,7 +16361,7 @@ function localBoard() {
|
|
|
16331
16361
|
}
|
|
16332
16362
|
const provider = {
|
|
16333
16363
|
kind: "local",
|
|
16334
|
-
readCards: () => Promise.resolve(
|
|
16364
|
+
readCards: () => Promise.resolve(allCards()),
|
|
16335
16365
|
// ---- the writer lease ---------------------------------------------------
|
|
16336
16366
|
// Local grants every lease, an unknown card included: a single machine's board is
|
|
16337
16367
|
// already serialized by the writing lock, so there is nothing here to fence off — and
|
|
@@ -16428,6 +16458,7 @@ var init_local2 = __esm({
|
|
|
16428
16458
|
init_agent_file();
|
|
16429
16459
|
init_studio_file2();
|
|
16430
16460
|
init_memory_file();
|
|
16461
|
+
init_inspect();
|
|
16431
16462
|
init_validate2();
|
|
16432
16463
|
init_io();
|
|
16433
16464
|
init_lock();
|
|
@@ -16436,6 +16467,7 @@ var init_local2 = __esm({
|
|
|
16436
16467
|
init_revision();
|
|
16437
16468
|
as = (opts) => opts;
|
|
16438
16469
|
MOVES = {
|
|
16470
|
+
inspect: ({ args: args2 }) => cmdInspect(Number(args2[0])),
|
|
16439
16471
|
validate: ({ args: args2 }) => cmdValidate(args2[0] === void 0 ? void 0 : Number(args2[0])),
|
|
16440
16472
|
init: () => cmdInit(),
|
|
16441
16473
|
create: ({ opts }) => cmdCreate(as(opts)),
|
|
@@ -16449,7 +16481,7 @@ var init_local2 = __esm({
|
|
|
16449
16481
|
"memory-file": ({ args: args2 }) => cmdMemoryFile(args2[0] ?? "")
|
|
16450
16482
|
};
|
|
16451
16483
|
BOARD_MOVES = new Set(Object.keys(MOVES));
|
|
16452
|
-
READ_ONLY_MOVES = /* @__PURE__ */ new Set(["list", "validate", "file", "agent-file", "memory-file"]);
|
|
16484
|
+
READ_ONLY_MOVES = /* @__PURE__ */ new Set(["inspect", "list", "validate", "file", "agent-file", "memory-file"]);
|
|
16453
16485
|
leases = /* @__PURE__ */ new Map();
|
|
16454
16486
|
leaseCounter = 0;
|
|
16455
16487
|
}
|
|
@@ -16480,14 +16512,14 @@ var init_board = __esm({
|
|
|
16480
16512
|
});
|
|
16481
16513
|
|
|
16482
16514
|
// src/lib/plans.ts
|
|
16483
|
-
import
|
|
16484
|
-
import
|
|
16515
|
+
import fs60 from "node:fs";
|
|
16516
|
+
import path62 from "node:path";
|
|
16485
16517
|
function planFile(rel2) {
|
|
16486
16518
|
if (!/^plans\/(archive\/)?[^/\\]+\.md$/.test(rel2)) return null;
|
|
16487
16519
|
const dir = isArchivedPlan(rel2) ? PLANS_ARCHIVE : PLANS;
|
|
16488
16520
|
const name = rel2.replace(/^plans\/(archive\/)?/, "");
|
|
16489
16521
|
if (!name || name.includes("/") || !name.endsWith(".md")) return null;
|
|
16490
|
-
return
|
|
16522
|
+
return path62.join(dir, name);
|
|
16491
16523
|
}
|
|
16492
16524
|
function readPlan(rel2) {
|
|
16493
16525
|
const file2 = planFile(rel2);
|
|
@@ -16495,12 +16527,12 @@ function readPlan(rel2) {
|
|
|
16495
16527
|
let text5 = "";
|
|
16496
16528
|
let found2 = rel2;
|
|
16497
16529
|
try {
|
|
16498
|
-
text5 =
|
|
16530
|
+
text5 = fs60.readFileSync(file2, "utf8");
|
|
16499
16531
|
} catch {
|
|
16500
16532
|
const moved = renamedPlan(rel2);
|
|
16501
16533
|
if (moved) {
|
|
16502
16534
|
found2 = moved;
|
|
16503
|
-
text5 =
|
|
16535
|
+
text5 = fs60.readFileSync(planFile(moved), "utf8");
|
|
16504
16536
|
}
|
|
16505
16537
|
}
|
|
16506
16538
|
return { path: found2, text: text5, lines: text5.trim() ? text5.trimEnd().split("\n").length : 0 };
|
|
@@ -16515,13 +16547,13 @@ function renamedPlan(rel2) {
|
|
|
16515
16547
|
]) {
|
|
16516
16548
|
let names3;
|
|
16517
16549
|
try {
|
|
16518
|
-
names3 =
|
|
16550
|
+
names3 = fs60.readdirSync(dir);
|
|
16519
16551
|
} catch {
|
|
16520
16552
|
continue;
|
|
16521
16553
|
}
|
|
16522
16554
|
for (const n of names3) {
|
|
16523
16555
|
if (!n.startsWith(`${id}-`) || !n.endsWith(".md")) continue;
|
|
16524
|
-
found2.push({ rel: `${prefix}${n}`, at:
|
|
16556
|
+
found2.push({ rel: `${prefix}${n}`, at: fs60.statSync(path62.join(dir, n)).mtimeMs });
|
|
16525
16557
|
}
|
|
16526
16558
|
}
|
|
16527
16559
|
if (!found2.length) return null;
|
|
@@ -16530,7 +16562,7 @@ function renamedPlan(rel2) {
|
|
|
16530
16562
|
function planFromText(text5) {
|
|
16531
16563
|
const legacy2 = `${legacyProjectStateDir(KANBAN)}/`;
|
|
16532
16564
|
if (text5.startsWith(legacy2)) text5 = text5.slice(legacy2.length);
|
|
16533
|
-
const local = `${
|
|
16565
|
+
const local = `${path62.dirname(PLANS)}/`;
|
|
16534
16566
|
if (text5.startsWith(local)) text5 = text5.slice(local.length);
|
|
16535
16567
|
if (text5.startsWith(`${KANBAN}/`)) text5 = text5.slice(KANBAN.length + 1);
|
|
16536
16568
|
const here = `${boardPath()}/`;
|
|
@@ -16589,36 +16621,58 @@ var init_roster = __esm({
|
|
|
16589
16621
|
}
|
|
16590
16622
|
});
|
|
16591
16623
|
|
|
16624
|
+
// src/lib/agent/own-cost.ts
|
|
16625
|
+
function ownCost(total, before) {
|
|
16626
|
+
if (total === void 0 || before === null) return void 0;
|
|
16627
|
+
if (before === void 0 || total < before) return total;
|
|
16628
|
+
return total >= before ? total - before : void 0;
|
|
16629
|
+
}
|
|
16630
|
+
function lastSessionTotal(id, runs) {
|
|
16631
|
+
let best;
|
|
16632
|
+
const take = (at2, usd) => {
|
|
16633
|
+
if (typeof usd === "number" && usd >= 0 && (!best || at2 >= best.at)) best = { at: at2, usd };
|
|
16634
|
+
};
|
|
16635
|
+
for (const r2 of runs) if (r2.resumeId === id || r2.sessionId === id) take(r2.endedAt ?? r2.startedAt, r2.sessionCostUsd);
|
|
16636
|
+
return best?.usd ?? null;
|
|
16637
|
+
}
|
|
16638
|
+
var reportsSessionTotal;
|
|
16639
|
+
var init_own_cost = __esm({
|
|
16640
|
+
"src/lib/agent/own-cost.ts"() {
|
|
16641
|
+
"use strict";
|
|
16642
|
+
reportsSessionTotal = (harness) => harness === "claude-code";
|
|
16643
|
+
}
|
|
16644
|
+
});
|
|
16645
|
+
|
|
16592
16646
|
// src/lib/agent/pictures.ts
|
|
16593
|
-
import
|
|
16594
|
-
import
|
|
16647
|
+
import fs61 from "node:fs";
|
|
16648
|
+
import path63 from "node:path";
|
|
16595
16649
|
function claimRunPictures(box2, sessionId, names3 = []) {
|
|
16596
16650
|
if (!box2 || !freeBox(box2) || names3.length === 0) return [];
|
|
16597
16651
|
const from = pictureBox(box2);
|
|
16598
16652
|
const to = pictureBox(sessionId);
|
|
16599
16653
|
try {
|
|
16600
|
-
|
|
16601
|
-
|
|
16654
|
+
fs61.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
16655
|
+
fs61.renameSync(from, to);
|
|
16602
16656
|
} catch {
|
|
16603
16657
|
return [];
|
|
16604
16658
|
}
|
|
16605
|
-
return names3.filter(pictureName).map((name) =>
|
|
16659
|
+
return names3.filter(pictureName).map((name) => path63.join(to, name)).filter((file2) => fs61.existsSync(file2));
|
|
16606
16660
|
}
|
|
16607
16661
|
function returnRunPictures(sessionId, box2) {
|
|
16608
16662
|
if (!box2 || !boxId(box2)) return;
|
|
16609
16663
|
try {
|
|
16610
|
-
|
|
16664
|
+
fs61.renameSync(pictureBox(sessionId), pictureBox(box2));
|
|
16611
16665
|
} catch {
|
|
16612
16666
|
}
|
|
16613
16667
|
}
|
|
16614
16668
|
function moveRunPictures(from, to, files = []) {
|
|
16615
16669
|
if (files.length === 0) return [];
|
|
16616
16670
|
try {
|
|
16617
|
-
|
|
16671
|
+
fs61.renameSync(pictureBox(from), pictureBox(to));
|
|
16618
16672
|
} catch {
|
|
16619
16673
|
return files;
|
|
16620
16674
|
}
|
|
16621
|
-
return files.map((file2) =>
|
|
16675
|
+
return files.map((file2) => path63.join(pictureBox(to), path63.basename(file2)));
|
|
16622
16676
|
}
|
|
16623
16677
|
var pictureName, boxId, freeBox, pictureBox;
|
|
16624
16678
|
var init_pictures = __esm({
|
|
@@ -16627,8 +16681,8 @@ var init_pictures = __esm({
|
|
|
16627
16681
|
init_paths();
|
|
16628
16682
|
pictureName = (name) => /^[0-9a-f-]{36}\.[a-z0-9]{2,5}$/.test(name);
|
|
16629
16683
|
boxId = (box2) => /^[0-9a-f-]{36}$/.test(box2);
|
|
16630
|
-
freeBox = (box2) => boxId(box2) && !
|
|
16631
|
-
pictureBox = (box2) =>
|
|
16684
|
+
freeBox = (box2) => boxId(box2) && !fs61.existsSync(path63.join(SESSIONS_DIR, `${box2}.log`));
|
|
16685
|
+
pictureBox = (box2) => path63.join(SESSIONS_DIR, `${box2}.images`);
|
|
16632
16686
|
}
|
|
16633
16687
|
});
|
|
16634
16688
|
|
|
@@ -16748,16 +16802,16 @@ var init_facts = __esm({
|
|
|
16748
16802
|
});
|
|
16749
16803
|
|
|
16750
16804
|
// src/lib/view/archive.ts
|
|
16751
|
-
import
|
|
16752
|
-
import
|
|
16805
|
+
import fs62 from "node:fs";
|
|
16806
|
+
import path64 from "node:path";
|
|
16753
16807
|
function archivedId(file2) {
|
|
16754
|
-
const own = idPrefix(
|
|
16755
|
-
return own !== null ? own : idPrefix(
|
|
16808
|
+
const own = idPrefix(path64.basename(file2));
|
|
16809
|
+
return own !== null ? own : idPrefix(path64.basename(path64.dirname(file2)));
|
|
16756
16810
|
}
|
|
16757
16811
|
function readFile(file2) {
|
|
16758
16812
|
const id = archivedId(file2);
|
|
16759
16813
|
if (id === null) return null;
|
|
16760
|
-
const { meta, body } = parseFrontmatter(
|
|
16814
|
+
const { meta, body } = parseFrontmatter(fs62.readFileSync(file2, "utf8"));
|
|
16761
16815
|
if (!meta) return null;
|
|
16762
16816
|
return {
|
|
16763
16817
|
row: {
|
|
@@ -16765,15 +16819,15 @@ function readFile(file2) {
|
|
|
16765
16819
|
title: meta.title,
|
|
16766
16820
|
archived: meta.archived,
|
|
16767
16821
|
rejected: meta.rejected,
|
|
16768
|
-
relPath: rel(file2).split(
|
|
16822
|
+
relPath: rel(file2).split(path64.sep).join("/")
|
|
16769
16823
|
},
|
|
16770
16824
|
body: body.replace(/^\n+/, "").replace(/\s+$/, ""),
|
|
16771
16825
|
meta
|
|
16772
16826
|
};
|
|
16773
16827
|
}
|
|
16774
16828
|
function readArchive() {
|
|
16775
|
-
const relPath = rel(ARCHIVE).split(
|
|
16776
|
-
if (!
|
|
16829
|
+
const relPath = rel(ARCHIVE).split(path64.sep).join("/");
|
|
16830
|
+
if (!fs62.existsSync(ARCHIVE)) return { relPath, cards: [] };
|
|
16777
16831
|
const cards = walkMd(ARCHIVE).map(readFile).filter((found2) => found2 !== null).map((found2) => found2.row);
|
|
16778
16832
|
cards.sort((a2, b2) => b2.id - a2.id);
|
|
16779
16833
|
return { relPath, cards };
|
|
@@ -16788,7 +16842,7 @@ var init_archive = __esm({
|
|
|
16788
16842
|
});
|
|
16789
16843
|
|
|
16790
16844
|
// src/lib/agent/prompts.ts
|
|
16791
|
-
import
|
|
16845
|
+
import path65 from "node:path";
|
|
16792
16846
|
function stopReason(deliveryId) {
|
|
16793
16847
|
const delivery = findDelivery(deliveryId);
|
|
16794
16848
|
if (!delivery) return void 0;
|
|
@@ -16819,13 +16873,6 @@ ${approved}`;
|
|
|
16819
16873
|
}
|
|
16820
16874
|
return `Follow \`akb guide implement\`: create no card and build exactly this approved requirement and nothing more \u2014 "${approved}".`;
|
|
16821
16875
|
}
|
|
16822
|
-
function contractRepairPrompt(req, errors) {
|
|
16823
|
-
return boardText([
|
|
16824
|
-
"The task left the board broken. Fix only the errors below. Preserve planned behavior and completed work; do not repeat the task or request other agents.",
|
|
16825
|
-
errors,
|
|
16826
|
-
ruleBlock(req, frozenRules(req))
|
|
16827
|
-
].filter(Boolean).join("\n\n"));
|
|
16828
|
-
}
|
|
16829
16876
|
function restartPrompt(req, deliveryId) {
|
|
16830
16877
|
if (req.id === void 0 && !req.deliveryId && !deliveryId) return void 0;
|
|
16831
16878
|
if (deliveryId && req.action === "implement") return [RESTART_LEAD, `Continue delivery ${deliveryId}. ${deliveryRequirements(deliveryId, req.id ?? null)}`.trim()].join("\n\n");
|
|
@@ -16849,7 +16896,7 @@ ${text5}` : "";
|
|
|
16849
16896
|
}
|
|
16850
16897
|
function cardFileOf(id) {
|
|
16851
16898
|
const found2 = id === void 0 ? null : locate(id);
|
|
16852
|
-
return found2 ? found2.kind === "group" ?
|
|
16899
|
+
return found2 ? found2.kind === "group" ? path65.join(found2.target, "root.md") : found2.target : "";
|
|
16853
16900
|
}
|
|
16854
16901
|
function realPaths(text5, req) {
|
|
16855
16902
|
if (req.action !== "scheduled" && req.action !== "sub") return text5;
|
|
@@ -16947,7 +16994,7 @@ function frozenRules(req) {
|
|
|
16947
16994
|
function archivedCardFile(id) {
|
|
16948
16995
|
const found2 = locateArchived(id);
|
|
16949
16996
|
if (!found2) return `${rel(ARCHIVE)}/`;
|
|
16950
|
-
return rel(found2.kind === "group" ?
|
|
16997
|
+
return rel(found2.kind === "group" ? path65.join(found2.target, "root.md") : found2.target);
|
|
16951
16998
|
}
|
|
16952
16999
|
function shippedLines(cardId2) {
|
|
16953
17000
|
const delivery = endedDelivery(`${cardId2}`);
|
|
@@ -16981,7 +17028,12 @@ function roster(req) {
|
|
|
16981
17028
|
}
|
|
16982
17029
|
function buildRun(req) {
|
|
16983
17030
|
const notes = [...migrateFlowRules(), ...req.specAgent ? foldedSettingsNotes(req.specAgent) : []];
|
|
16984
|
-
|
|
17031
|
+
let prompt = buildPrompt(req, notes);
|
|
17032
|
+
if (req.action === "spec" && req.id !== void 0 && req.specAgent) {
|
|
17033
|
+
const stage = realPaths(boardText(previewStagePrompt(req.id, req.specAgent, boardCommand())), req);
|
|
17034
|
+
if (stage) prompt = prompt.replace(stage, "");
|
|
17035
|
+
}
|
|
17036
|
+
return { prompt, notes };
|
|
16985
17037
|
}
|
|
16986
17038
|
function answeredNote(cardId2, command) {
|
|
16987
17039
|
const delivery = cardId2 === void 0 ? void 0 : activeDelivery(cardId2);
|
|
@@ -17090,7 +17142,7 @@ function actionPrompt(req, command, notes) {
|
|
|
17090
17142
|
case "spec": {
|
|
17091
17143
|
const agent = findSpecAgent(req.specAgent ?? "");
|
|
17092
17144
|
const found2 = req.id === void 0 ? null : locate(req.id);
|
|
17093
|
-
const cardFile3 = found2 ? rel(found2.kind === "group" ?
|
|
17145
|
+
const cardFile3 = found2 ? rel(found2.kind === "group" ? path65.join(found2.target, "root.md") : found2.target) : `task #${req.id}`;
|
|
17094
17146
|
const own = agent ? specAgentInstructions(agent) : null;
|
|
17095
17147
|
if (own) notes.push(...own.notes);
|
|
17096
17148
|
const memory = agent ? agentMemoryBlock(agent) : "";
|
|
@@ -17236,8 +17288,7 @@ var init_prompts = __esm({
|
|
|
17236
17288
|
init_store();
|
|
17237
17289
|
init_types3();
|
|
17238
17290
|
RESUME_PROMPT = [
|
|
17239
|
-
`Continue
|
|
17240
|
-
`Pick up where you left off and carry it through.`
|
|
17291
|
+
`Continue work.`
|
|
17241
17292
|
].join(" ");
|
|
17242
17293
|
DELIVERY_RESUME = `Continue delivery %s. %r`;
|
|
17243
17294
|
DELIVERY_RESUME_CARD = `Build the card as the delivery holds it, not as the file reads now: \`%c\` prints the approved copy.`;
|
|
@@ -17252,8 +17303,7 @@ var init_prompts = __esm({
|
|
|
17252
17303
|
"scheduled"
|
|
17253
17304
|
]);
|
|
17254
17305
|
RESTART_LEAD = [
|
|
17255
|
-
`
|
|
17256
|
-
`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.`
|
|
17306
|
+
`Continue work.`
|
|
17257
17307
|
].join(" ");
|
|
17258
17308
|
restartable = (run4) => (run4.cardId !== null || !!run4.deliveryId) && RESTARTABLE.has(run4.action);
|
|
17259
17309
|
NO_IMPLEMENT = `(Unless the request explicitly asks for implementation, don't implement it; revising the card's drafts is not implementing.)`;
|
|
@@ -17268,16 +17318,16 @@ var init_prompts = __esm({
|
|
|
17268
17318
|
|
|
17269
17319
|
// src/lib/agent/stop.ts
|
|
17270
17320
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
17271
|
-
import
|
|
17321
|
+
import fs63 from "node:fs";
|
|
17272
17322
|
function markedInProc(entry, strict = false, since) {
|
|
17273
17323
|
const pids = [];
|
|
17274
|
-
for (const name of
|
|
17324
|
+
for (const name of fs63.readdirSync("/proc")) {
|
|
17275
17325
|
if (!/^\d+$/.test(name)) continue;
|
|
17276
17326
|
try {
|
|
17277
|
-
if (
|
|
17327
|
+
if (fs63.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
|
|
17278
17328
|
} catch (error) {
|
|
17279
17329
|
if (strict && !["ENOENT", "ESRCH"].includes(error.code ?? "")) {
|
|
17280
|
-
const stat =
|
|
17330
|
+
const stat = fs63.statSync(`/proc/${name}`, { throwIfNoEntry: false });
|
|
17281
17331
|
if (stat?.uid === process.getuid?.() && !startedBefore(Number(name), since)) throw error;
|
|
17282
17332
|
}
|
|
17283
17333
|
}
|
|
@@ -17502,8 +17552,8 @@ __export(sessions_exports, {
|
|
|
17502
17552
|
withRuns: () => withRuns
|
|
17503
17553
|
});
|
|
17504
17554
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
17505
|
-
import
|
|
17506
|
-
import
|
|
17555
|
+
import fs64 from "node:fs";
|
|
17556
|
+
import path66 from "node:path";
|
|
17507
17557
|
function reap(runs, reaped = [], restore = []) {
|
|
17508
17558
|
let changed = false;
|
|
17509
17559
|
const now = Date.now();
|
|
@@ -17523,7 +17573,7 @@ function reap(runs, reaped = [], restore = []) {
|
|
|
17523
17573
|
}
|
|
17524
17574
|
function stampDuration(run4, endedAt) {
|
|
17525
17575
|
try {
|
|
17526
|
-
|
|
17576
|
+
fs64.appendFileSync(run4.logPath, durationLine(endedAt - run4.startedAt));
|
|
17527
17577
|
} catch {
|
|
17528
17578
|
}
|
|
17529
17579
|
}
|
|
@@ -17537,7 +17587,7 @@ function cardNow(cardId2) {
|
|
|
17537
17587
|
try {
|
|
17538
17588
|
const file2 = cardFile2(cardId2);
|
|
17539
17589
|
if (!file2) return null;
|
|
17540
|
-
const { meta } = parseFrontmatter(
|
|
17590
|
+
const { meta } = parseFrontmatter(fs64.readFileSync(file2, "utf8"));
|
|
17541
17591
|
if (!meta) return null;
|
|
17542
17592
|
return { status: meta.status || "todo", questions: meta.questions.length, title: meta.title };
|
|
17543
17593
|
} catch {
|
|
@@ -17608,7 +17658,7 @@ function resumeSessionId(run4) {
|
|
|
17608
17658
|
return resumesUnder(run4.harness) && !neverStarted(run4) ? resumeIdOf(run4) : void 0;
|
|
17609
17659
|
}
|
|
17610
17660
|
function endedDeliveryRefusal(r2, refusals) {
|
|
17611
|
-
if (!r2.deliveryId
|
|
17661
|
+
if (!r2.deliveryId) return void 0;
|
|
17612
17662
|
if (refusals?.has(r2.deliveryId)) return refusals.get(r2.deliveryId);
|
|
17613
17663
|
const delivery = findDelivery(r2.deliveryId);
|
|
17614
17664
|
const ended = delivery && delivery.status !== "active" && (delivery.status !== "failed" || delivery.worktree);
|
|
@@ -17618,8 +17668,7 @@ function endedDeliveryRefusal(r2, refusals) {
|
|
|
17618
17668
|
return why2;
|
|
17619
17669
|
}
|
|
17620
17670
|
function retryAsk(r2) {
|
|
17621
|
-
if (
|
|
17622
|
-
if (r2.formatRepair && !neverStarted(r2)) return void 0;
|
|
17671
|
+
if (isRetired(r2.action)) return void 0;
|
|
17623
17672
|
const id = r2.cardId ?? void 0;
|
|
17624
17673
|
const base = {
|
|
17625
17674
|
action: r2.action,
|
|
@@ -17648,7 +17697,7 @@ function retryAsk(r2) {
|
|
|
17648
17697
|
}
|
|
17649
17698
|
}
|
|
17650
17699
|
function toView(r2, gone, refusals) {
|
|
17651
|
-
const cardOffBoard = r2.cardId !== null && !!gone?.has(r2.cardId);
|
|
17700
|
+
const cardOffBoard = r2.status !== "done" && r2.cardId !== null && !!gone?.has(r2.cardId);
|
|
17652
17701
|
const open3 = r2.action !== "sub" && canPickUp(r2) && !endedDeliveryRefusal(r2, refusals);
|
|
17653
17702
|
const session = !lacksSession(r2);
|
|
17654
17703
|
return {
|
|
@@ -17670,9 +17719,9 @@ function leftBoardOnLanding(id) {
|
|
|
17670
17719
|
function archivedRejected(id) {
|
|
17671
17720
|
const filed = locateArchived(id);
|
|
17672
17721
|
if (!filed) return null;
|
|
17673
|
-
const file2 = filed.kind === "group" ?
|
|
17722
|
+
const file2 = filed.kind === "group" ? path66.join(filed.target, "root.md") : filed.target;
|
|
17674
17723
|
try {
|
|
17675
|
-
return !!parseFrontmatter(
|
|
17724
|
+
return !!parseFrontmatter(fs64.readFileSync(file2, "utf8")).meta?.rejected;
|
|
17676
17725
|
} catch {
|
|
17677
17726
|
return false;
|
|
17678
17727
|
}
|
|
@@ -17922,7 +17971,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID4(), said2) {
|
|
|
17922
17971
|
return { run: record, spec };
|
|
17923
17972
|
}
|
|
17924
17973
|
function planningSession(cardId2, cwd = REPO_ROOT) {
|
|
17925
|
-
const here = (dir) => !dir ||
|
|
17974
|
+
const here = (dir) => !dir || path66.resolve(dir) === cwd;
|
|
17926
17975
|
const planned = readRuns().filter((r2) => r2.status === "done" && r2.cardId === cardId2 && PLANNING.has(r2.action)).sort((a2, b2) => b2.startedAt - a2.startedAt)[0];
|
|
17927
17976
|
if (!planned) return { none: "unrecorded" };
|
|
17928
17977
|
if (!here(planned.cwd)) return { none: "elsewhere" };
|
|
@@ -17975,6 +18024,7 @@ function requestOf(record) {
|
|
|
17975
18024
|
// the CLI actually spawned takes it.
|
|
17976
18025
|
runtime: record.runtime,
|
|
17977
18026
|
specAgent: record.specAgent,
|
|
18027
|
+
notes: record.input,
|
|
17978
18028
|
...record.action === "scheduled" ? { studio: record.studio } : {},
|
|
17979
18029
|
triage: record.triage,
|
|
17980
18030
|
cards: record.cards,
|
|
@@ -17984,8 +18034,8 @@ function requestOf(record) {
|
|
|
17984
18034
|
};
|
|
17985
18035
|
}
|
|
17986
18036
|
async function openResume(id, options) {
|
|
17987
|
-
const build = typeof options === "object" ? options : void 0;
|
|
17988
|
-
const
|
|
18037
|
+
const build = typeof options === "object" && options.deliveryId ? { deliveryId: options.deliveryId, notes: options.notes } : void 0;
|
|
18038
|
+
const forced = typeof options === "object" && options.fresh;
|
|
17989
18039
|
const restore = [];
|
|
17990
18040
|
const runs = withRuns((all2) => {
|
|
17991
18041
|
reap(all2, [], restore);
|
|
@@ -18003,14 +18053,6 @@ async function openResume(id, options) {
|
|
|
18003
18053
|
if (build && (prev.action !== "implement" || prev.deliveryId !== build.deliveryId || delivery?.status !== "active")) {
|
|
18004
18054
|
return refusal("deliveryTakenOver", "\u539F\u6784\u5EFA\u4E0D\u5C5E\u4E8E\u5F53\u524D\u5F85\u7EED\u8DD1\u7684\u4EA4\u4ED8\uFF0C\u4E0D\u4F1A\u542F\u52A8\u65B0\u4F1A\u8BDD\u3002", { id: build.deliveryId });
|
|
18005
18055
|
}
|
|
18006
|
-
const completedBuild = prev.status === "done" && prev.action === "implement" && delivery?.status === "active" && prev.deliveryId === delivery.deliveryId;
|
|
18007
|
-
if (!canPickUp(prev) && !completedBuild) return refusal("runNotResumable", "only a failed, interrupted or stopped run can be continued");
|
|
18008
|
-
const retrying = lacksSession(prev);
|
|
18009
|
-
if (requireSession && (!resumeSessionId(prev) || !resumesUnder(prev.harness))) {
|
|
18010
|
-
return refusal("runNoSession", "\u539F\u6784\u5EFA\u6CA1\u6709\u53EF\u6062\u590D\u7684\u4F1A\u8BDD\u6807\u8BC6\uFF0C\u6216\u539F Agent \u4E0D\u652F\u6301\u7EED\u8DD1\uFF1B\u672C\u6B21\u672A\u542F\u52A8\u65B0\u4F1A\u8BDD\u3002");
|
|
18011
|
-
}
|
|
18012
|
-
const ask2 = retrying && prev.status !== "stopped" ? retryAsk(prev) : void 0;
|
|
18013
|
-
if (retrying && !ask2) return refusal("runNoSession", "that run never reported a session id to continue by");
|
|
18014
18056
|
const ended = endedDeliveryRefusal(prev);
|
|
18015
18057
|
if (ended) return ended;
|
|
18016
18058
|
const resuming = prev.deliveryId ? findDelivery(prev.deliveryId) : void 0;
|
|
@@ -18018,24 +18060,17 @@ async function openResume(id, options) {
|
|
|
18018
18060
|
const sessionId = randomUUID4();
|
|
18019
18061
|
let plan;
|
|
18020
18062
|
let fresh;
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18063
|
+
const session = forced ? void 0 : resumeSessionId(prev);
|
|
18064
|
+
if (session) {
|
|
18065
|
+
plan = planResume({ harness: prev.harness, resumeId: session, cwd }, prev.agent, prev.runtime ? { pin: prev.runtime } : {});
|
|
18066
|
+
} else {
|
|
18067
|
+
const ask2 = retryAsk(prev) ?? requestOf(prev);
|
|
18025
18068
|
const started = await planRetry(prev, ask2, sessionId, cwd);
|
|
18026
18069
|
if ("error" in started) return started;
|
|
18027
18070
|
({ plan, fresh } = started);
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
prev.agent,
|
|
18032
|
-
prev.runtime ? { pin: prev.runtime } : {}
|
|
18033
|
-
);
|
|
18034
|
-
} else {
|
|
18035
|
-
const prompt = restartPrompt({ ...requestOf(prev), runtime: void 0 }, prev.deliveryId);
|
|
18036
|
-
const started = prompt ? planRun(sessionId, cwd, prev.agent) : null;
|
|
18037
|
-
plan = started;
|
|
18038
|
-
if (started && prompt) fresh = { prompt, notes: started.note ? [started.note] : [] };
|
|
18071
|
+
const restart = prev.action === "spec" ? void 0 : restartPrompt({ ...requestOf(prev), runtime: plan.runtime }, prev.deliveryId);
|
|
18072
|
+
fresh.prompt = restart ?? ["Continue work.", fresh.prompt].join("\n\n");
|
|
18073
|
+
if (!lacksSession(prev) && !forced) fresh.retry = false;
|
|
18039
18074
|
}
|
|
18040
18075
|
if (!plan) {
|
|
18041
18076
|
const agent = prev.harness || "the agent that started it";
|
|
@@ -18044,7 +18079,6 @@ async function openResume(id, options) {
|
|
|
18044
18079
|
const buildResume = prev.action === "implement" && prev.deliveryId ? resumePrompt(prev.deliveryId, prev.action) : void 0;
|
|
18045
18080
|
const opened = await resumeHeld(prev, plan, sessionId, resuming, fresh);
|
|
18046
18081
|
if ("error" in opened) return opened;
|
|
18047
|
-
if (build) opened.spec.notes = [...opened.spec.notes ?? [], "\u7EE7\u7EED\u539F\u6784\u5EFA\u4F1A\u8BDD\uFF1B\u82E5\u539F\u4F1A\u8BDD\u4E0D\u53EF\u7528\uFF0C\u672C\u6B21\u4E0D\u4F1A\u65B0\u5EFA\u4F1A\u8BDD\u3002"];
|
|
18048
18082
|
if (!opened.spec.prompt && buildResume) opened.spec.prompt = buildResume;
|
|
18049
18083
|
if (build?.notes?.trim()) opened.spec.prompt = [opened.spec.prompt || resumePrompt(prev.deliveryId, prev.action), build.notes.trim()].join("\n\n");
|
|
18050
18084
|
if (build || buildResume) writeSpec(opened.spec);
|
|
@@ -18071,10 +18105,9 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
|
|
|
18071
18105
|
action: prev.action,
|
|
18072
18106
|
status: "running",
|
|
18073
18107
|
startedAt: Date.now(),
|
|
18074
|
-
//
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
...retry2 ? { input: prev.input, studio: prev.studio } : {},
|
|
18108
|
+
// Keep the original ask available if a later resume loses its session.
|
|
18109
|
+
input: prev.input,
|
|
18110
|
+
studio: prev.studio,
|
|
18078
18111
|
harness: plan.harness,
|
|
18079
18112
|
runtime: plan.runtime,
|
|
18080
18113
|
agent: plan.agent,
|
|
@@ -18087,8 +18120,7 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
|
|
|
18087
18120
|
resumeId: plan.resumeId ?? void 0,
|
|
18088
18121
|
resumedFrom: prev.sessionId,
|
|
18089
18122
|
// Taken now: the run being continued is dropped once this one starts (#1483).
|
|
18090
|
-
sessionCostFrom: prev.sessionCostUsd ?? prev.sessionCostFrom,
|
|
18091
|
-
formatRepair: prev.formatRepair ? { ...prev.formatRepair, attempt: prev.formatRepair.attempt + 1 } : void 0,
|
|
18123
|
+
sessionCostFrom: reportsSessionTotal(prev.harness) ? prev.sessionCostUsd ?? prev.sessionCostFrom : void 0,
|
|
18092
18124
|
// The retry chain carries on rather than starting over (#525): this run IS the attempt
|
|
18093
18125
|
// the failed one scheduled, so its count and its window come with it.
|
|
18094
18126
|
retry: prev.retry
|
|
@@ -18110,22 +18142,12 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
|
|
|
18110
18142
|
return refusal("discardUnfinished", "A card discard did not finish. Retry discarding it before resuming creation.");
|
|
18111
18143
|
}
|
|
18112
18144
|
record.discardedCards = latest.discardedCards;
|
|
18113
|
-
const discarded = new Set(record.discardedCards?.map((c2) => c2.id) ?? []);
|
|
18114
|
-
if (record.formatRepair && discarded.size) {
|
|
18115
|
-
const repair = record.formatRepair;
|
|
18116
|
-
repair.cardIds = repair.cardIds.filter((id) => !discarded.has(id));
|
|
18117
|
-
repair.changedIds = repair.changedIds.filter((id) => !discarded.has(id));
|
|
18118
|
-
repair.existingIds = repair.existingIds.filter((id) => !discarded.has(id));
|
|
18119
|
-
repair.errors = repair.errors.split("\n").filter((line) => !record.discardedCards.some((c2) => line.includes(c2.path) || new RegExp(`Task #${c2.id}(?![0-9])`).test(line))).join("\n");
|
|
18120
|
-
if (!repair.cardIds.length) record.formatRepair = void 0;
|
|
18121
|
-
}
|
|
18122
18145
|
const heldCreation = all2.find((r2) => runIsLive(r2) && (r2.cardId !== null && (latest.createdCardIds ?? []).includes(r2.cardId) || (r2.createdCardIds ?? []).some((id) => (latest.createdCardIds ?? []).includes(id))));
|
|
18123
18146
|
if (heldCreation) return refusal("creationHeld", "A card from this creation is already being worked on. Wait for that run to finish.");
|
|
18124
18147
|
const locked = lockedBy(all2, prev.action, prev.cardId, prev.discard);
|
|
18125
18148
|
if (locked) return locked;
|
|
18126
18149
|
all2.push(record);
|
|
18127
18150
|
const delivery = store.deliveries.find((d2) => d2.deliveryId === prev.deliveryId && d2.status === "active");
|
|
18128
|
-
if (!delivery && record.formatRepair) record.deliveryId = prev.deliveryId;
|
|
18129
18151
|
if (delivery) {
|
|
18130
18152
|
delivery.sessions.push(record.sessionId);
|
|
18131
18153
|
delivery.steps.push({ step: "resume", at: record.startedAt });
|
|
@@ -18141,11 +18163,6 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh) {
|
|
|
18141
18163
|
const inherited = readAsks(prev.sessionId);
|
|
18142
18164
|
if (inherited.asks.length || inherited.refines.length) writeAsks(sessionId, inherited);
|
|
18143
18165
|
clearAsks(prev.sessionId);
|
|
18144
|
-
try {
|
|
18145
|
-
fs63.unlinkSync(prev.logPath);
|
|
18146
|
-
fs63.rmSync(eventsPathOf(prev.sessionId), { force: true });
|
|
18147
|
-
} catch {
|
|
18148
|
-
}
|
|
18149
18166
|
if (retry2 && prev.pictures?.length) {
|
|
18150
18167
|
record.pictures = moveRunPictures(prev.sessionId, sessionId, prev.pictures);
|
|
18151
18168
|
patch(sessionId, (r2) => {
|
|
@@ -18166,8 +18183,8 @@ function forgetRun(sessionId) {
|
|
|
18166
18183
|
if (!gone) return;
|
|
18167
18184
|
clearAsks(sessionId);
|
|
18168
18185
|
try {
|
|
18169
|
-
|
|
18170
|
-
|
|
18186
|
+
fs64.unlinkSync(gone.logPath);
|
|
18187
|
+
fs64.rmSync(eventsPathOf(gone.sessionId), { force: true });
|
|
18171
18188
|
} catch {
|
|
18172
18189
|
}
|
|
18173
18190
|
}
|
|
@@ -18196,14 +18213,14 @@ function noteSpecRefusals(sessionId, refused) {
|
|
|
18196
18213
|
}
|
|
18197
18214
|
function clearAsks(sessionId) {
|
|
18198
18215
|
try {
|
|
18199
|
-
|
|
18216
|
+
fs64.unlinkSync(asksPathOf(sessionId));
|
|
18200
18217
|
} catch {
|
|
18201
18218
|
}
|
|
18202
18219
|
}
|
|
18203
18220
|
function readAsks(sessionId) {
|
|
18204
18221
|
let data;
|
|
18205
18222
|
try {
|
|
18206
|
-
data = JSON.parse(
|
|
18223
|
+
data = JSON.parse(fs64.readFileSync(asksPathOf(sessionId), "utf8"));
|
|
18207
18224
|
} catch {
|
|
18208
18225
|
return { asks: [], refines: [], refused: [] };
|
|
18209
18226
|
}
|
|
@@ -18230,10 +18247,10 @@ function readAsks(sessionId) {
|
|
|
18230
18247
|
return { asks: asks.filter((a2) => !discarded.has(a2.cardId)), refines: refines.filter((a2) => !discarded.has(a2.cardId)), refused };
|
|
18231
18248
|
}
|
|
18232
18249
|
function writeAsks(sessionId, file2) {
|
|
18233
|
-
|
|
18250
|
+
fs64.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
18234
18251
|
const tmp = `${asksPathOf(sessionId)}.tmp`;
|
|
18235
|
-
|
|
18236
|
-
|
|
18252
|
+
fs64.writeFileSync(tmp, JSON.stringify(file2, null, 2) + "\n");
|
|
18253
|
+
fs64.renameSync(tmp, asksPathOf(sessionId));
|
|
18237
18254
|
}
|
|
18238
18255
|
function markSpawned(sessionId, pid) {
|
|
18239
18256
|
patch(sessionId, (r2) => {
|
|
@@ -18358,18 +18375,19 @@ async function resumeDelivery(id) {
|
|
|
18358
18375
|
const put = resumeRecord(id, execution);
|
|
18359
18376
|
if (!put.ok) return put;
|
|
18360
18377
|
const delivery = put.delivery;
|
|
18378
|
+
if (delivery.status === "finished") return { ok: true, deliveryId: delivery.deliveryId, landed: true };
|
|
18361
18379
|
const carryOn = carryOnFrom(delivery.deliveryId);
|
|
18362
18380
|
if (delivery.cardId !== null) await setCardStatus(delivery.cardId, "implementing");
|
|
18363
18381
|
syncAudit(delivery.deliveryId);
|
|
18364
18382
|
return { ok: true, deliveryId: delivery.deliveryId, carryOn };
|
|
18365
18383
|
}
|
|
18366
18384
|
function writeSpec(spec) {
|
|
18367
|
-
|
|
18368
|
-
|
|
18385
|
+
fs64.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
18386
|
+
fs64.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
|
|
18369
18387
|
}
|
|
18370
18388
|
function readSpec(sessionId) {
|
|
18371
18389
|
try {
|
|
18372
|
-
const spec = JSON.parse(
|
|
18390
|
+
const spec = JSON.parse(fs64.readFileSync(specPathOf(sessionId), "utf8"));
|
|
18373
18391
|
return spec && Array.isArray(spec.plan?.argv) ? spec : null;
|
|
18374
18392
|
} catch {
|
|
18375
18393
|
return null;
|
|
@@ -18377,28 +18395,28 @@ function readSpec(sessionId) {
|
|
|
18377
18395
|
}
|
|
18378
18396
|
function dropSpec(sessionId) {
|
|
18379
18397
|
try {
|
|
18380
|
-
|
|
18398
|
+
fs64.unlinkSync(specPathOf(sessionId));
|
|
18381
18399
|
} catch {
|
|
18382
18400
|
}
|
|
18383
18401
|
}
|
|
18384
18402
|
async function acquireIndexLock(giveUp) {
|
|
18385
18403
|
const until = Date.now() + INDEX_WAIT_MS;
|
|
18386
|
-
const holder =
|
|
18404
|
+
const holder = path66.join(INDEX_LOCK2, "holder");
|
|
18387
18405
|
for (; ; ) {
|
|
18388
18406
|
if (giveUp()) return null;
|
|
18389
18407
|
try {
|
|
18390
|
-
|
|
18391
|
-
|
|
18392
|
-
return () =>
|
|
18408
|
+
fs64.mkdirSync(INDEX_LOCK2, { recursive: false });
|
|
18409
|
+
fs64.writeFileSync(holder, String(process.pid));
|
|
18410
|
+
return () => fs64.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
18393
18411
|
} catch (err) {
|
|
18394
18412
|
const code = err.code;
|
|
18395
18413
|
if (code === "ENOENT") {
|
|
18396
|
-
|
|
18414
|
+
fs64.mkdirSync(path66.dirname(INDEX_LOCK2), { recursive: true });
|
|
18397
18415
|
continue;
|
|
18398
18416
|
}
|
|
18399
18417
|
if (code !== "EEXIST") throw err;
|
|
18400
18418
|
if (!pidAlive(Number(readHolder(holder)))) {
|
|
18401
|
-
|
|
18419
|
+
fs64.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
18402
18420
|
continue;
|
|
18403
18421
|
}
|
|
18404
18422
|
if (Date.now() > until) return null;
|
|
@@ -18408,7 +18426,7 @@ async function acquireIndexLock(giveUp) {
|
|
|
18408
18426
|
}
|
|
18409
18427
|
function readHolder(file2) {
|
|
18410
18428
|
try {
|
|
18411
|
-
return
|
|
18429
|
+
return fs64.readFileSync(file2, "utf8").trim();
|
|
18412
18430
|
} catch {
|
|
18413
18431
|
return String(process.pid);
|
|
18414
18432
|
}
|
|
@@ -18432,6 +18450,7 @@ var init_sessions = __esm({
|
|
|
18432
18450
|
init_deliveries();
|
|
18433
18451
|
init_flows();
|
|
18434
18452
|
init_commit_mode();
|
|
18453
|
+
init_own_cost();
|
|
18435
18454
|
init_log();
|
|
18436
18455
|
init_resolve();
|
|
18437
18456
|
init_pictures();
|
|
@@ -18493,8 +18512,8 @@ var init_sessions = __esm({
|
|
|
18493
18512
|
implement: "implementing",
|
|
18494
18513
|
hook: "implementing"
|
|
18495
18514
|
};
|
|
18496
|
-
specPathOf = (sessionId) =>
|
|
18497
|
-
asksPathOf = (sessionId) =>
|
|
18515
|
+
specPathOf = (sessionId) => path66.join(SESSIONS_DIR, `${sessionId}.plan.json`);
|
|
18516
|
+
asksPathOf = (sessionId) => path66.join(SESSIONS_DIR, `${sessionId}.asks.json`);
|
|
18498
18517
|
carriesSession = (r2) => !!(r2.resumedFrom || r2.continues && !r2.continues.fork);
|
|
18499
18518
|
canPickUp = (r2) => r2.status === "error" || r2.status === "interrupted" || r2.status === "stopped";
|
|
18500
18519
|
neverStarted = (r2) => r2.unspawned === true || !!r2.errorWhy?.some((why2) => why2.kind === "notInstalled");
|
|
@@ -18521,8 +18540,8 @@ var init_sessions = __esm({
|
|
|
18521
18540
|
});
|
|
18522
18541
|
|
|
18523
18542
|
// src/lib/card-sources.ts
|
|
18524
|
-
import
|
|
18525
|
-
import
|
|
18543
|
+
import fs65 from "node:fs";
|
|
18544
|
+
import path67 from "node:path";
|
|
18526
18545
|
function planById(id) {
|
|
18527
18546
|
const found2 = readPlan(`plans/${id}-.md`);
|
|
18528
18547
|
return found2?.text.trim() ? found2 : null;
|
|
@@ -18532,8 +18551,8 @@ function cardLink(id) {
|
|
|
18532
18551
|
const found2 = open3 ?? locateArchived(id);
|
|
18533
18552
|
if (!found2) return null;
|
|
18534
18553
|
try {
|
|
18535
|
-
const file2 = found2.kind === "group" ?
|
|
18536
|
-
const title = parseFrontmatter(
|
|
18554
|
+
const file2 = found2.kind === "group" ? path67.join(found2.target, "root.md") : found2.target;
|
|
18555
|
+
const title = parseFrontmatter(fs65.readFileSync(file2, "utf8")).meta?.title ?? "";
|
|
18537
18556
|
return { kind: "card", ref: String(id), title, ...open3 ? {} : { archived: true } };
|
|
18538
18557
|
} catch {
|
|
18539
18558
|
return null;
|
|
@@ -18558,7 +18577,7 @@ function link(ref, items) {
|
|
|
18558
18577
|
if (ref.kind === "plan") return planLink(ref.id);
|
|
18559
18578
|
if (ref.kind === "card") return cardLink(ref.id);
|
|
18560
18579
|
if (ref.kind === "url") return urlLink(ref.url);
|
|
18561
|
-
const item = items().find((signal2) =>
|
|
18580
|
+
const item = items().find((signal2) => path67.basename(signal2.relPath) === ref.file);
|
|
18562
18581
|
return item ? itemLink(item) : null;
|
|
18563
18582
|
}
|
|
18564
18583
|
function cardSources(meta, body) {
|
|
@@ -18599,12 +18618,12 @@ var init_card_sources = __esm({
|
|
|
18599
18618
|
});
|
|
18600
18619
|
|
|
18601
18620
|
// src/lib/view/read.ts
|
|
18602
|
-
import
|
|
18603
|
-
import
|
|
18621
|
+
import fs66 from "node:fs";
|
|
18622
|
+
import path68 from "node:path";
|
|
18604
18623
|
function readCard(file2, relFromTodo) {
|
|
18605
|
-
const id = idPrefix(
|
|
18624
|
+
const id = idPrefix(path68.basename(relFromTodo));
|
|
18606
18625
|
if (id === null) {
|
|
18607
|
-
const parts = relFromTodo.split(
|
|
18626
|
+
const parts = relFromTodo.split(path68.sep);
|
|
18608
18627
|
const folderId = idPrefix(parts[parts.length - 2] || "");
|
|
18609
18628
|
if (folderId === null) return null;
|
|
18610
18629
|
return buildCard(folderId, file2, relFromTodo);
|
|
@@ -18612,10 +18631,10 @@ function readCard(file2, relFromTodo) {
|
|
|
18612
18631
|
return buildCard(id, file2, relFromTodo);
|
|
18613
18632
|
}
|
|
18614
18633
|
function buildCard(id, file2, relFromTodo) {
|
|
18615
|
-
const text5 =
|
|
18634
|
+
const text5 = fs66.readFileSync(file2, "utf8");
|
|
18616
18635
|
const { meta, body } = parseFrontmatter(text5);
|
|
18617
18636
|
if (!meta) return null;
|
|
18618
|
-
const relPath = relFromTodo.split(
|
|
18637
|
+
const relPath = relFromTodo.split(path68.sep).join("/");
|
|
18619
18638
|
const flow = studioFor(meta.studio);
|
|
18620
18639
|
const plan = !!meta.studio && archivesOnApproval(flow);
|
|
18621
18640
|
const stages = cardStages(meta, flow).length;
|
|
@@ -18624,7 +18643,7 @@ function buildCard(id, file2, relFromTodo) {
|
|
|
18624
18643
|
// Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
|
|
18625
18644
|
// read here and a card read by the contract agree on what version this is.
|
|
18626
18645
|
revision: revisionOf(text5),
|
|
18627
|
-
updatedAt:
|
|
18646
|
+
updatedAt: fs66.statSync(file2).mtime.toISOString(),
|
|
18628
18647
|
relPath,
|
|
18629
18648
|
title: meta.title,
|
|
18630
18649
|
priority: meta.priority,
|
|
@@ -18645,22 +18664,22 @@ function buildCard(id, file2, relFromTodo) {
|
|
|
18645
18664
|
};
|
|
18646
18665
|
}
|
|
18647
18666
|
function readGroup2(folderName) {
|
|
18648
|
-
const groupDir =
|
|
18649
|
-
const rootFile =
|
|
18650
|
-
if (!
|
|
18651
|
-
const root2 = readCard(rootFile,
|
|
18667
|
+
const groupDir = path68.join(TODO, folderName);
|
|
18668
|
+
const rootFile = path68.join(groupDir, "root.md");
|
|
18669
|
+
if (!fs66.existsSync(rootFile)) return null;
|
|
18670
|
+
const root2 = readCard(rootFile, path68.join(folderName, "root.md"));
|
|
18652
18671
|
if (!root2) return null;
|
|
18653
18672
|
root2.isGroup = true;
|
|
18654
18673
|
const { total, resolved: resolved2 } = subtaskLines(root2.body);
|
|
18655
18674
|
root2.subtaskLines = { total, resolved: resolved2 };
|
|
18656
18675
|
const subCards = [];
|
|
18657
18676
|
const recurse = (dir, relDir) => {
|
|
18658
|
-
for (const entry of
|
|
18659
|
-
const childRel =
|
|
18677
|
+
for (const entry of fs66.readdirSync(dir, { withFileTypes: true })) {
|
|
18678
|
+
const childRel = path68.join(relDir, entry.name);
|
|
18660
18679
|
if (entry.isDirectory()) {
|
|
18661
|
-
recurse(
|
|
18680
|
+
recurse(path68.join(dir, entry.name), childRel);
|
|
18662
18681
|
} else if (entry.name.endsWith(".md") && entry.name !== "README.md" && entry.name !== "root.md") {
|
|
18663
|
-
const c2 = readCard(
|
|
18682
|
+
const c2 = readCard(path68.join(dir, entry.name), childRel);
|
|
18664
18683
|
if (c2) {
|
|
18665
18684
|
c2.parent = { id: root2.id, title: root2.title };
|
|
18666
18685
|
subCards.push(c2);
|
|
@@ -18681,12 +18700,12 @@ function readGroup2(folderName) {
|
|
|
18681
18700
|
return { root: root2, subCards };
|
|
18682
18701
|
}
|
|
18683
18702
|
function standaloneCards(dirRel) {
|
|
18684
|
-
const dir = dirRel ?
|
|
18685
|
-
if (!
|
|
18703
|
+
const dir = dirRel ? path68.join(TODO, dirRel) : TODO;
|
|
18704
|
+
if (!fs66.existsSync(dir)) return [];
|
|
18686
18705
|
const cards = [];
|
|
18687
|
-
for (const entry of
|
|
18706
|
+
for (const entry of fs66.readdirSync(dir, { withFileTypes: true })) {
|
|
18688
18707
|
if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
|
|
18689
|
-
const c2 = readCard(
|
|
18708
|
+
const c2 = readCard(path68.join(dir, entry.name), path68.join(dirRel, entry.name));
|
|
18690
18709
|
if (c2) cards.push(c2);
|
|
18691
18710
|
}
|
|
18692
18711
|
}
|
|
@@ -18698,7 +18717,7 @@ function collectCards() {
|
|
|
18698
18717
|
const top = standaloneCards("");
|
|
18699
18718
|
board2.push(...top);
|
|
18700
18719
|
every.push(...top);
|
|
18701
|
-
for (const entry of
|
|
18720
|
+
for (const entry of fs66.readdirSync(TODO, { withFileTypes: true })) {
|
|
18702
18721
|
if (!entry.isDirectory()) continue;
|
|
18703
18722
|
if (isGroupFolder(entry.name)) {
|
|
18704
18723
|
const g3 = readGroup2(entry.name);
|
|
@@ -18730,7 +18749,7 @@ function findCard(id) {
|
|
|
18730
18749
|
}
|
|
18731
18750
|
function attachSources(card) {
|
|
18732
18751
|
try {
|
|
18733
|
-
const { meta, body } = parseFrontmatter(
|
|
18752
|
+
const { meta, body } = parseFrontmatter(fs66.readFileSync(path68.join(TODO, card.relPath), "utf8"));
|
|
18734
18753
|
const sources2 = meta ? cardSources(meta, body) : [];
|
|
18735
18754
|
if (sources2.length) card.sources = sources2;
|
|
18736
18755
|
} catch {
|
|
@@ -18813,7 +18832,7 @@ function attachDiscard(card, active2) {
|
|
|
18813
18832
|
resumable: holder.status !== "active" && isResumable(holder)
|
|
18814
18833
|
};
|
|
18815
18834
|
}
|
|
18816
|
-
function
|
|
18835
|
+
function allCards() {
|
|
18817
18836
|
return collectCards().every;
|
|
18818
18837
|
}
|
|
18819
18838
|
var init_read = __esm({
|
|
@@ -18834,25 +18853,25 @@ var init_read = __esm({
|
|
|
18834
18853
|
});
|
|
18835
18854
|
|
|
18836
18855
|
// src/lib/agent/preview-progress.ts
|
|
18837
|
-
import
|
|
18838
|
-
import
|
|
18856
|
+
import fs67 from "node:fs";
|
|
18857
|
+
import path69 from "node:path";
|
|
18839
18858
|
import { createHash as createHash7, randomUUID as randomUUID5 } from "node:crypto";
|
|
18840
18859
|
function readPreviewProgress(id) {
|
|
18841
18860
|
try {
|
|
18842
|
-
return JSON.parse(
|
|
18861
|
+
return JSON.parse(fs67.readFileSync(file(id), "utf8"));
|
|
18843
18862
|
} catch (error) {
|
|
18844
18863
|
if (error.code === "ENOENT") return {};
|
|
18845
18864
|
throw error;
|
|
18846
18865
|
}
|
|
18847
18866
|
}
|
|
18848
18867
|
function updatePreviewProgress(id, change2) {
|
|
18849
|
-
|
|
18868
|
+
fs67.mkdirSync(path69.dirname(file(id)), { recursive: true });
|
|
18850
18869
|
return withLock(`${file(id)}.lock`, "updating preview progress", () => {
|
|
18851
18870
|
const all2 = readPreviewProgress(id);
|
|
18852
18871
|
const result = change2(all2);
|
|
18853
18872
|
const temp = `${file(id)}.${process.pid}.tmp`;
|
|
18854
|
-
|
|
18855
|
-
|
|
18873
|
+
fs67.writeFileSync(temp, JSON.stringify(all2) + "\n");
|
|
18874
|
+
fs67.renameSync(temp, file(id));
|
|
18856
18875
|
return result;
|
|
18857
18876
|
});
|
|
18858
18877
|
}
|
|
@@ -18862,7 +18881,7 @@ function freezePreviewProgress(id, name) {
|
|
|
18862
18881
|
const agent = findSpecAgent(name);
|
|
18863
18882
|
if (!agent) return null;
|
|
18864
18883
|
const studio = studioFiles(cardStudioId(id)) ?? {};
|
|
18865
|
-
const protocol = Object.entries(studio).some(([
|
|
18884
|
+
const protocol = Object.entries(studio).some(([path91, text5]) => path91.endsWith("/AGENT.md") && /^[ \t]+stages:/m.test(text5.split(/\r?\n---/)[0]));
|
|
18866
18885
|
if (!agent.stages && !protocol) return null;
|
|
18867
18886
|
const definitions = agent.stages ?? [{ id: "preview", title: { en: "Preview", zh: "\u6210\u679C" }, instructions: "preview.md" }];
|
|
18868
18887
|
const files = Object.fromEntries(agent.files.map((file2) => [file2, agent.file(file2)]).filter((entry) => entry[1] !== null));
|
|
@@ -18876,38 +18895,32 @@ function freezePreviewProgress(id, name) {
|
|
|
18876
18895
|
function previewStagePrompt(id, name, command) {
|
|
18877
18896
|
const progress = freezePreviewProgress(id, name);
|
|
18878
18897
|
if (!progress) return "";
|
|
18879
|
-
if (progress.revisionBase) return `
|
|
18880
|
-
if (!progress.stages.length) return `
|
|
18898
|
+
if (progress.revisionBase) return `Revise from the first affected stage: ${command} raw previews ${name} ${id} --revise-from <stage-id>. Saved stages: ${JSON.stringify(progress.revisionBase.map(({ id: id2, title, status, artifact }) => ({ id: id2, title, status, artifact })))}`;
|
|
18899
|
+
if (!progress.stages.length) return `Stages:
|
|
18881
18900
|
${JSON.stringify(progress.definitions)}
|
|
18882
|
-
|
|
18901
|
+
Select with: ${command} raw previews ${name} ${id} --stages <id,...>.`;
|
|
18883
18902
|
const current = progress.stages.find((stage) => stage.id === progress.currentStageId);
|
|
18884
|
-
if (current
|
|
18903
|
+
if (!current) return `Saved stages: ${JSON.stringify(progress.stages)}
|
|
18904
|
+
Select with: ${command} raw previews ${name} ${id} --stages <id,...>.`;
|
|
18905
|
+
if (current.status === "awaiting_confirmation" || previewReady(progress)) return "The submitted preview is awaiting review.";
|
|
18885
18906
|
return [
|
|
18886
18907
|
`Selected stages: ${progress.stages.map((stage) => stage.id).join(", ")}. Current stage: ${current.id}.`,
|
|
18887
|
-
progress.files[current.instructions],
|
|
18908
|
+
progress.files[current.instructions] === progress.body ? "" : progress.files[current.instructions],
|
|
18888
18909
|
...name === "ui-designer" ? [current.id === "copywriting" ? legacyPreviewMemory("copywriting") : current.id === "illustration" ? legacyPreviewMemory("illustrator") : ""] : [],
|
|
18889
18910
|
...progress.stages.filter((stage) => stage.status === "confirmed").map((stage) => `Confirmed ${stage.id} v${stage.version}:
|
|
18890
18911
|
${stage.artifact?.body ?? ""}`),
|
|
18891
|
-
`
|
|
18912
|
+
`Submit with: ${command} raw previews ${name} ${id} --submit --stage ${current.id}.`
|
|
18892
18913
|
].join("\n\n");
|
|
18893
18914
|
}
|
|
18894
|
-
async function assertPreviewTask(id) {
|
|
18895
|
-
if (!process.env[PREVIEW_BRIDGE_ENV]) return;
|
|
18896
|
-
const task = workspaceTask();
|
|
18897
|
-
if (!task) throw Error("The preview bridge needs its current task.");
|
|
18898
|
-
const source2 = await call("GET", `/v1/tasks/${encodeURIComponent(task)}`);
|
|
18899
|
-
if (!source2.ok) throw Error(source2.error);
|
|
18900
|
-
if (numberOf(source2.value.key) !== id) throw Error("Only the current task can prepare previews from this session.");
|
|
18901
|
-
}
|
|
18902
18915
|
function previewOwner(id, name, inside2 = insideRun()) {
|
|
18903
18916
|
const found2 = locate(id);
|
|
18904
18917
|
if (!found2) throw Error("The task is no longer open.");
|
|
18905
|
-
const card = found2.kind === "group" ?
|
|
18906
|
-
const { meta } = parseFrontmatter(
|
|
18918
|
+
const card = found2.kind === "group" ? path69.join(found2.target, "root.md") : found2.target;
|
|
18919
|
+
const { meta } = parseFrontmatter(fs67.readFileSync(card, "utf8"));
|
|
18907
18920
|
if (!specAgentAssigned(name, meta?.studio) || !meta?.previews?.some((agent) => canonicalSpecAgent(agent) === name)) throw Error("Choose this preview agent on the task first.");
|
|
18908
18921
|
if (inside2) {
|
|
18909
18922
|
const run4 = readRuns().find((run5) => run5.sessionId === inside2);
|
|
18910
|
-
if (!run4 || run4.status !== "running" || run4.cardId !== id
|
|
18923
|
+
if (!run4 || run4.status !== "running" || run4.cardId !== id) throw Error("Only the active task session can prepare its selected previews.");
|
|
18911
18924
|
return `run:${inside2}`;
|
|
18912
18925
|
}
|
|
18913
18926
|
const execution = executionOf();
|
|
@@ -18916,21 +18929,21 @@ function previewOwner(id, name, inside2 = insideRun()) {
|
|
|
18916
18929
|
}
|
|
18917
18930
|
function readContext(file2) {
|
|
18918
18931
|
try {
|
|
18919
|
-
return JSON.parse(
|
|
18932
|
+
return JSON.parse(fs67.readFileSync(file2, "utf8"));
|
|
18920
18933
|
} catch (error) {
|
|
18921
18934
|
if (error.code === "ENOENT") return void 0;
|
|
18922
18935
|
throw error;
|
|
18923
18936
|
}
|
|
18924
18937
|
}
|
|
18925
18938
|
function writeJson2(file2, value) {
|
|
18926
|
-
|
|
18939
|
+
fs67.mkdirSync(path69.dirname(file2), { recursive: true });
|
|
18927
18940
|
const temp = `${file2}.${process.pid}.tmp`;
|
|
18928
|
-
|
|
18929
|
-
|
|
18941
|
+
fs67.writeFileSync(temp, JSON.stringify(value) + "\n");
|
|
18942
|
+
fs67.renameSync(temp, file2);
|
|
18930
18943
|
}
|
|
18931
18944
|
function previewRun(id, name) {
|
|
18932
18945
|
const context = readContext(contextFile(id, name, previewOwner(id, name)));
|
|
18933
|
-
if (!context?.active) throw
|
|
18946
|
+
if (!context?.active) throw new PreviewContextMissing("This preview has no saved execution context.");
|
|
18934
18947
|
const progress = readPreviewProgress(id)[name];
|
|
18935
18948
|
if (progress?.execution && progress.execution !== context.sessionId && !progress.execution.endsWith(`:${context.sessionId}`)) throw Error("This execution is outdated. Reload the task.");
|
|
18936
18949
|
return context;
|
|
@@ -18950,7 +18963,7 @@ function selectLocalPreview(id, name, ids) {
|
|
|
18950
18963
|
function previewSection(body, name) {
|
|
18951
18964
|
const lines = body.split("\n");
|
|
18952
18965
|
const start = lines.findIndex((line) => specHeadingRe(name).test(line));
|
|
18953
|
-
if (start < 0)
|
|
18966
|
+
if (start < 0) return "";
|
|
18954
18967
|
const end2 = lines.findIndex((line, index) => index > start && (/^## /.test(line) || line.trim() === "<!-- agent -->"));
|
|
18955
18968
|
return lines.slice(start + 1, end2 < 0 ? void 0 : end2).join("\n").trim();
|
|
18956
18969
|
}
|
|
@@ -18959,12 +18972,15 @@ function submitLocalPreview(id, name, stage, baseline) {
|
|
|
18959
18972
|
const card = findCard(id);
|
|
18960
18973
|
if (!card) throw Error("The task is no longer open.");
|
|
18961
18974
|
const body = previewSection(card.body, name);
|
|
18962
|
-
const problems = validatePreviewFiles(path68.join(TODO, card.relPath), id, body);
|
|
18963
|
-
if (problems.length) throw Error(problems.map((problem) => problem.message).join("\n"));
|
|
18964
18975
|
const snapshot = randomUUID5();
|
|
18965
|
-
const source2 =
|
|
18966
|
-
const dest =
|
|
18967
|
-
if (
|
|
18976
|
+
const source2 = path69.join(ASSETS, String(id));
|
|
18977
|
+
const dest = path69.join(BOARD_STATE, "previews", "assets", String(id), snapshot);
|
|
18978
|
+
if (fs67.existsSync(source2) && fs67.lstatSync(source2).isSymbolicLink()) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18979
|
+
if (fs67.existsSync(source2)) fs67.cpSync(source2, dest, { recursive: true, dereference: true, filter: (file2) => {
|
|
18980
|
+
const real2 = fs67.realpathSync(file2);
|
|
18981
|
+
if (real2 !== fs67.realpathSync(source2) && !real2.startsWith(fs67.realpathSync(source2) + path69.sep)) throw Error("Preview assets must stay inside this task\u2019s asset folder.");
|
|
18982
|
+
return true;
|
|
18983
|
+
} });
|
|
18968
18984
|
return updatePreviewProgress(id, (all2) => {
|
|
18969
18985
|
const progress = all2[name];
|
|
18970
18986
|
if (!progress) throw Error("Select the stages first.");
|
|
@@ -18977,22 +18993,17 @@ function savePreviewBaseline(id, name, run4, baseline) {
|
|
|
18977
18993
|
writeJson2(baselineFile(id, name, run4), baseline);
|
|
18978
18994
|
}
|
|
18979
18995
|
function readPreviewBaseline(id, name, run4) {
|
|
18980
|
-
return JSON.parse(
|
|
18996
|
+
return JSON.parse(fs67.readFileSync(baselineFile(id, name, run4), "utf8"));
|
|
18981
18997
|
}
|
|
18982
18998
|
async function activatePreviewRun(id, name, run4, request2 = "") {
|
|
18983
|
-
await assertPreviewTask(id);
|
|
18984
18999
|
const owner = previewOwner(id, name, run4 ?? insideRun());
|
|
18985
19000
|
const file2 = contextFile(id, name, owner);
|
|
18986
19001
|
const held4 = readContext(file2);
|
|
18987
19002
|
const context = held4 && held4.request === request2 ? held4 : { sessionId: run4 ?? randomUUID5(), request: request2 };
|
|
18988
|
-
if (held4?.active && held4.sessionId === context.sessionId) {
|
|
18989
|
-
const progress = readPreviewProgress(id)[name];
|
|
18990
|
-
if (progress?.execution && progress.execution !== context.sessionId && !progress.execution.endsWith(`:${context.sessionId}`)) throw Error("This execution is outdated. Reload the task.");
|
|
18991
|
-
}
|
|
18992
19003
|
writeJson2(file2, context);
|
|
18993
19004
|
run4 = context.sessionId;
|
|
18994
19005
|
const { previewBridge: previewBridge2 } = await Promise.resolve().then(() => (init_preview(), preview_exports));
|
|
18995
|
-
const remote2 = await previewBridge2(name, "start", { run: run4 });
|
|
19006
|
+
const remote2 = await previewBridge2(name, "start", { run: run4, cardId: id });
|
|
18996
19007
|
if (remote2) {
|
|
18997
19008
|
if (remote2.progress) updatePreviewProgress(id, (all2) => {
|
|
18998
19009
|
all2[name] = remote2.progress;
|
|
@@ -19003,12 +19014,6 @@ async function activatePreviewRun(id, name, run4, request2 = "") {
|
|
|
19003
19014
|
updatePreviewProgress(id, (all2) => {
|
|
19004
19015
|
const progress = all2[name];
|
|
19005
19016
|
if (!progress) return;
|
|
19006
|
-
const current = progress.stages.find((stage) => stage.id === progress.currentStageId);
|
|
19007
|
-
if (held4?.active && held4.sessionId === run4 && progress.execution && progress.execution !== run4) throw Error("This execution is outdated. Reload the task.");
|
|
19008
|
-
if (current && ["awaiting_confirmation", "ready"].includes(current.status)) {
|
|
19009
|
-
if (progress.execution === run4) return;
|
|
19010
|
-
beginPreviewRevision(progress, run4);
|
|
19011
|
-
}
|
|
19012
19017
|
if (progress.currentStageId && !progress.revisionBase) savePreviewBaseline(id, name, run4, previewBaseline(progress, progress.currentStageId, run4));
|
|
19013
19018
|
else progress.execution = run4;
|
|
19014
19019
|
});
|
|
@@ -19023,13 +19028,13 @@ function frozenPreviewFile(agent, relative) {
|
|
|
19023
19028
|
function legacyPreviewMemory(agent) {
|
|
19024
19029
|
const folder = agentMemoryDir(agent);
|
|
19025
19030
|
try {
|
|
19026
|
-
return
|
|
19027
|
-
${
|
|
19031
|
+
return fs67.readdirSync(folder).filter((name) => name.endsWith(".md")).map((name) => `Existing ${agent} preferences (${name}):
|
|
19032
|
+
${fs67.readFileSync(path69.join(folder, name), "utf8")}`).join("\n\n");
|
|
19028
19033
|
} catch {
|
|
19029
19034
|
return "";
|
|
19030
19035
|
}
|
|
19031
19036
|
}
|
|
19032
|
-
var file, contextFile, baselineFile;
|
|
19037
|
+
var file, contextFile, PreviewContextMissing, baselineFile;
|
|
19033
19038
|
var init_preview_progress = __esm({
|
|
19034
19039
|
"src/lib/agent/preview-progress.ts"() {
|
|
19035
19040
|
"use strict";
|
|
@@ -19046,19 +19051,18 @@ var init_preview_progress = __esm({
|
|
|
19046
19051
|
init_cards();
|
|
19047
19052
|
init_frontmatter();
|
|
19048
19053
|
init_execution();
|
|
19049
|
-
init_tasks();
|
|
19050
|
-
init_preview();
|
|
19051
|
-
init_preview_files();
|
|
19052
19054
|
init_preview_stages();
|
|
19053
|
-
file = (id) =>
|
|
19054
|
-
contextFile = (id, name, owner) =>
|
|
19055
|
-
|
|
19055
|
+
file = (id) => path69.join(BOARD_STATE, "previews", `${id}.json`);
|
|
19056
|
+
contextFile = (id, name, owner) => path69.join(BOARD_STATE, "previews", "contexts", String(id), name, `${createHash7("sha256").update(owner).digest("hex")}.json`);
|
|
19057
|
+
PreviewContextMissing = class extends Error {
|
|
19058
|
+
};
|
|
19059
|
+
baselineFile = (id, name, run4) => path69.join(BOARD_STATE, "previews", "runs", String(id), name, `${run4}.json`);
|
|
19056
19060
|
}
|
|
19057
19061
|
});
|
|
19058
19062
|
|
|
19059
19063
|
// src/lib/agent/approve.ts
|
|
19060
|
-
import
|
|
19061
|
-
import
|
|
19064
|
+
import fs68 from "node:fs";
|
|
19065
|
+
import path70 from "node:path";
|
|
19062
19066
|
function approvalRequest(req) {
|
|
19063
19067
|
const id = req.id;
|
|
19064
19068
|
const card = id === void 0 ? null : findCard(id);
|
|
@@ -19076,12 +19080,12 @@ function advancePhase(id) {
|
|
|
19076
19080
|
const card = findCard(id);
|
|
19077
19081
|
const found2 = locate(id);
|
|
19078
19082
|
if (!card || !found2 || !awaitingApproval(card)) return { error: `#${id} is no longer waiting on approval.` };
|
|
19079
|
-
const file2 = found2.kind === "group" ?
|
|
19080
|
-
const { meta, body } = parseFrontmatter(
|
|
19083
|
+
const file2 = found2.kind === "group" ? path70.join(found2.target, "root.md") : found2.target;
|
|
19084
|
+
const { meta, body } = parseFrontmatter(fs68.readFileSync(file2, "utf8"));
|
|
19081
19085
|
if (!meta) return { error: `#${id} has no frontmatter` };
|
|
19082
19086
|
meta.phase = card.stage + 1;
|
|
19083
19087
|
meta.status = "todo";
|
|
19084
|
-
|
|
19088
|
+
fs68.writeFileSync(file2, serializeFrontmatter(meta) + "\n" + body);
|
|
19085
19089
|
return null;
|
|
19086
19090
|
}
|
|
19087
19091
|
var init_approve = __esm({
|
|
@@ -19124,8 +19128,7 @@ function studioRefusal(req) {
|
|
|
19124
19128
|
if (archivesOnApproval(flow) && req.action === "implement") {
|
|
19125
19129
|
return refusal("planDelivered", `#${req.id} lands nothing, so its last approval archives it rather than building it.`, { card: String(req.id) });
|
|
19126
19130
|
}
|
|
19127
|
-
|
|
19128
|
-
return problem ?? null;
|
|
19131
|
+
return null;
|
|
19129
19132
|
}
|
|
19130
19133
|
async function scheduledRefusal(req) {
|
|
19131
19134
|
if (req.action !== "scheduled" || req.deliveryId || !req.studio || !req.specAgent) return null;
|
|
@@ -19324,10 +19327,10 @@ var init_avatar = __esm({
|
|
|
19324
19327
|
});
|
|
19325
19328
|
|
|
19326
19329
|
// src/lib/cloud/pro.ts
|
|
19327
|
-
import
|
|
19328
|
-
import
|
|
19330
|
+
import fs69 from "node:fs";
|
|
19331
|
+
import path71 from "node:path";
|
|
19329
19332
|
function forgetPro() {
|
|
19330
|
-
|
|
19333
|
+
fs69.rmSync(heldFile(), { force: true });
|
|
19331
19334
|
}
|
|
19332
19335
|
var FRESH_MS2, GRACE_MS, heldFile;
|
|
19333
19336
|
var init_pro = __esm({
|
|
@@ -19338,7 +19341,7 @@ var init_pro = __esm({
|
|
|
19338
19341
|
init_session();
|
|
19339
19342
|
FRESH_MS2 = 10 * 6e4;
|
|
19340
19343
|
GRACE_MS = 7 * 24 * 60 * 6e4;
|
|
19341
|
-
heldFile = () =>
|
|
19344
|
+
heldFile = () => path71.join(machineHome(), "pro.json");
|
|
19342
19345
|
}
|
|
19343
19346
|
});
|
|
19344
19347
|
|
|
@@ -19429,8 +19432,8 @@ var init_account = __esm({
|
|
|
19429
19432
|
});
|
|
19430
19433
|
|
|
19431
19434
|
// src/commands/cloud.ts
|
|
19432
|
-
import
|
|
19433
|
-
import
|
|
19435
|
+
import fs70 from "node:fs";
|
|
19436
|
+
import path72 from "node:path";
|
|
19434
19437
|
async function cmdCloud(args2, program2) {
|
|
19435
19438
|
const [sub] = args2;
|
|
19436
19439
|
if (sub === "sign-out") {
|
|
@@ -19492,10 +19495,10 @@ async function cloudImage(opts, program2) {
|
|
|
19492
19495
|
const prompt = opts.prompt.trim();
|
|
19493
19496
|
if (!prompt) usage("Missing the prompt.", line);
|
|
19494
19497
|
const references = opts.refs.map((file2) => {
|
|
19495
|
-
const type = REF_TYPES[
|
|
19498
|
+
const type = REF_TYPES[path72.extname(file2).toLowerCase()];
|
|
19496
19499
|
if (!type) usage(`--ref ${file2}: use a PNG, JPEG or WebP file.`, line);
|
|
19497
19500
|
try {
|
|
19498
|
-
return `data:${type};base64,${
|
|
19501
|
+
return `data:${type};base64,${fs70.readFileSync(file2).toString("base64")}`;
|
|
19499
19502
|
} catch (e2) {
|
|
19500
19503
|
usage(`--ref ${file2}: ${e2 instanceof Error ? e2.message : String(e2)}`, line);
|
|
19501
19504
|
}
|
|
@@ -19603,8 +19606,8 @@ async function generate(g3) {
|
|
|
19603
19606
|
refuse(g3.failed, g3.fallback);
|
|
19604
19607
|
}
|
|
19605
19608
|
const out = g3.outFor?.(res, g3.out) ?? g3.out;
|
|
19606
|
-
|
|
19607
|
-
|
|
19609
|
+
fs70.mkdirSync(path72.dirname(path72.resolve(out)), { recursive: true });
|
|
19610
|
+
fs70.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
|
|
19608
19611
|
say(`${out} (${g3.label(res)})`);
|
|
19609
19612
|
return { out };
|
|
19610
19613
|
}
|
|
@@ -19652,11 +19655,11 @@ var init_cloud = __esm({
|
|
|
19652
19655
|
});
|
|
19653
19656
|
|
|
19654
19657
|
// src/commands/task.ts
|
|
19655
|
-
import
|
|
19658
|
+
import fs71 from "node:fs";
|
|
19656
19659
|
import os5 from "node:os";
|
|
19657
|
-
import
|
|
19660
|
+
import path73 from "node:path";
|
|
19658
19661
|
async function cloud(method, route2, body) {
|
|
19659
|
-
process.env.AI4KANBAN_HOME ??= process.env.WILDCRANE_HOME ||
|
|
19662
|
+
process.env.AI4KANBAN_HOME ??= process.env.WILDCRANE_HOME || path73.join(os5.homedir(), ".wildcrane");
|
|
19660
19663
|
const token2 = await accessToken();
|
|
19661
19664
|
if (!token2.ok) return refuse2(SAID[token2.reason].en, token2.reason.replace("-", "_"));
|
|
19662
19665
|
let response;
|
|
@@ -19686,12 +19689,12 @@ async function all(route2) {
|
|
|
19686
19689
|
return rows;
|
|
19687
19690
|
}
|
|
19688
19691
|
function linked() {
|
|
19689
|
-
for (let dir = process.cwd(); ; dir =
|
|
19690
|
-
if (
|
|
19692
|
+
for (let dir = process.cwd(); ; dir = path73.dirname(dir)) {
|
|
19693
|
+
if (fs71.existsSync(path73.join(dir, ".akb", "base.json"))) {
|
|
19691
19694
|
const link2 = linkedProject("", dir);
|
|
19692
19695
|
return link2.ok ? link2.value : null;
|
|
19693
19696
|
}
|
|
19694
|
-
if (
|
|
19697
|
+
if (path73.dirname(dir) === dir) return null;
|
|
19695
19698
|
}
|
|
19696
19699
|
}
|
|
19697
19700
|
async function project(asked) {
|
|
@@ -19835,11 +19838,11 @@ var init_task = __esm({
|
|
|
19835
19838
|
});
|
|
19836
19839
|
|
|
19837
19840
|
// src/commands/goal.ts
|
|
19838
|
-
import
|
|
19841
|
+
import fs72 from "node:fs";
|
|
19839
19842
|
function loadGoals() {
|
|
19840
19843
|
const file2 = goalsFile();
|
|
19841
19844
|
if (!file2) die("Goals exist only inside a WildCrane goal discussion.");
|
|
19842
|
-
const held4 = JSON.parse(
|
|
19845
|
+
const held4 = JSON.parse(fs72.readFileSync(file2, "utf8"));
|
|
19843
19846
|
if (held4.goals !== void 0 && held4.ideas !== void 0 && JSON.stringify(held4.goals) !== JSON.stringify(held4.ideas)) die("goals and ideas do not match.");
|
|
19844
19847
|
const goals = held4.goals ?? held4.ideas;
|
|
19845
19848
|
if (!Array.isArray(goals)) die("The goals array is missing or invalid.");
|
|
@@ -19869,7 +19872,7 @@ function splitBody2(text5) {
|
|
|
19869
19872
|
}
|
|
19870
19873
|
function readBody(bodyFile) {
|
|
19871
19874
|
if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
|
|
19872
|
-
const text5 =
|
|
19875
|
+
const text5 = fs72.readFileSync(bodyFile, "utf8");
|
|
19873
19876
|
if (!text5.trim()) die("The goal must not be empty.");
|
|
19874
19877
|
return splitBody2(text5);
|
|
19875
19878
|
}
|
|
@@ -19881,7 +19884,7 @@ function named(held4, id) {
|
|
|
19881
19884
|
function cmdGoal(args2, opts) {
|
|
19882
19885
|
const sub = args2[0] ?? "";
|
|
19883
19886
|
const { file: file2, held: held4 } = loadGoals();
|
|
19884
|
-
const write2 = () =>
|
|
19887
|
+
const write2 = () => fs72.writeFileSync(file2, `${JSON.stringify({ ...held4, goals: void 0, ideas: held4.goals }, null, 2)}
|
|
19885
19888
|
`);
|
|
19886
19889
|
if (sub === "new") {
|
|
19887
19890
|
const title = opts.title?.trim();
|
|
@@ -19969,9 +19972,9 @@ var init_goal = __esm({
|
|
|
19969
19972
|
});
|
|
19970
19973
|
|
|
19971
19974
|
// src/commands/goal-cloud.ts
|
|
19972
|
-
import
|
|
19975
|
+
import fs73 from "node:fs";
|
|
19973
19976
|
import os6 from "node:os";
|
|
19974
|
-
import
|
|
19977
|
+
import path74 from "node:path";
|
|
19975
19978
|
import crypto3 from "node:crypto";
|
|
19976
19979
|
function hostSession() {
|
|
19977
19980
|
const { CLAUDE_CODE_SESSION_ID: claude, CODEX_THREAD_ID: codex, CURSOR_CONVERSATION_ID: cursor, KIMI_SESSION_ID: kimi, WILDCRANE_DISCUSSION: discussion2 } = process.env;
|
|
@@ -20000,24 +20003,24 @@ function goalsOf(d2) {
|
|
|
20000
20003
|
async function discussion() {
|
|
20001
20004
|
const session = hostSession();
|
|
20002
20005
|
if (!session) die("Goals exist only inside a WildCrane goal discussion.");
|
|
20003
|
-
const home3 = process.env.WILDCRANE_HOME ||
|
|
20006
|
+
const home3 = process.env.WILDCRANE_HOME || path74.join(os6.homedir(), ".wildcrane");
|
|
20004
20007
|
process.env.AI4KANBAN_HOME ??= home3;
|
|
20005
20008
|
if (session.host === "discussion") return request("GET", `/v1/discussions/${encodeURIComponent(session.id)}`);
|
|
20006
|
-
const machineFile2 =
|
|
20009
|
+
const machineFile2 = path74.join(home3, "machine.json");
|
|
20007
20010
|
let machine;
|
|
20008
20011
|
try {
|
|
20009
|
-
machine = JSON.parse(
|
|
20012
|
+
machine = JSON.parse(fs73.readFileSync(machineFile2, "utf8")).id;
|
|
20010
20013
|
} catch {
|
|
20011
20014
|
machine = crypto3.randomUUID();
|
|
20012
|
-
|
|
20013
|
-
|
|
20015
|
+
fs73.mkdirSync(home3, { recursive: true });
|
|
20016
|
+
fs73.writeFileSync(machineFile2, JSON.stringify({ id: machine }));
|
|
20014
20017
|
}
|
|
20015
20018
|
const held4 = await request("GET", `/v1/runner/folders?machine=${encodeURIComponent(machine)}`);
|
|
20016
|
-
const cwd =
|
|
20019
|
+
const cwd = fs73.realpathSync(process.cwd());
|
|
20017
20020
|
const folder = held4.folders.filter((f2) => {
|
|
20018
20021
|
try {
|
|
20019
|
-
const dir =
|
|
20020
|
-
return cwd === dir || cwd.startsWith(dir +
|
|
20022
|
+
const dir = fs73.realpathSync(f2.path);
|
|
20023
|
+
return cwd === dir || cwd.startsWith(dir + path74.sep);
|
|
20021
20024
|
} catch {
|
|
20022
20025
|
return false;
|
|
20023
20026
|
}
|
|
@@ -20026,16 +20029,16 @@ async function discussion() {
|
|
|
20026
20029
|
}
|
|
20027
20030
|
async function withGoalDiscussion(action, save3 = false) {
|
|
20028
20031
|
const d2 = await discussion();
|
|
20029
|
-
const dir =
|
|
20030
|
-
const file2 =
|
|
20032
|
+
const dir = fs73.mkdtempSync(path74.join(os6.tmpdir(), "akb-goals-"));
|
|
20033
|
+
const file2 = path74.join(dir, "goals.json");
|
|
20031
20034
|
const before = process.env.KANBAN_GOALS;
|
|
20032
20035
|
try {
|
|
20033
20036
|
const previous = goalsOf(d2);
|
|
20034
|
-
|
|
20037
|
+
fs73.writeFileSync(file2, JSON.stringify({ workspace: d2.workspace, studios: await studios2(d2.workspace), ideas: previous.map((g3) => ({ ...g3, task: typeof g3.task === "object" && g3.task ? g3.task.id : g3.task })) }));
|
|
20035
20038
|
process.env.KANBAN_GOALS = file2;
|
|
20036
20039
|
const result = save3 ? await quietlyAsync(async () => action()) : await action();
|
|
20037
20040
|
if (save3) {
|
|
20038
|
-
const goals = JSON.parse(
|
|
20041
|
+
const goals = JSON.parse(fs73.readFileSync(file2, "utf8")).ideas;
|
|
20039
20042
|
const saved = await request("PUT", `/v1/discussions/${d2.id}/draft`, { expectedVersion: d2.version, goals: goals.filter((g3) => !g3.dropped) });
|
|
20040
20043
|
const savedGoals = goalsOf(saved);
|
|
20041
20044
|
const fresh = goals.filter((g3) => !g3.dropped && !previous.some((p2) => p2.id === g3.id));
|
|
@@ -20054,7 +20057,7 @@ async function withGoalDiscussion(action, save3 = false) {
|
|
|
20054
20057
|
} finally {
|
|
20055
20058
|
if (before === void 0) delete process.env.KANBAN_GOALS;
|
|
20056
20059
|
else process.env.KANBAN_GOALS = before;
|
|
20057
|
-
|
|
20060
|
+
fs73.rmSync(dir, { recursive: true, force: true });
|
|
20058
20061
|
}
|
|
20059
20062
|
}
|
|
20060
20063
|
async function queryPreviews(studio, workspace2) {
|
|
@@ -21203,8 +21206,8 @@ var require_command = __commonJS({
|
|
|
21203
21206
|
"node_modules/commander/lib/command.js"(exports) {
|
|
21204
21207
|
var EventEmitter = __require("node:events").EventEmitter;
|
|
21205
21208
|
var childProcess = __require("node:child_process");
|
|
21206
|
-
var
|
|
21207
|
-
var
|
|
21209
|
+
var path91 = __require("node:path");
|
|
21210
|
+
var fs93 = __require("node:fs");
|
|
21208
21211
|
var process2 = __require("node:process");
|
|
21209
21212
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
21210
21213
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -22185,7 +22188,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22185
22188
|
* @param {string} subcommandName
|
|
22186
22189
|
*/
|
|
22187
22190
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
22188
|
-
if (
|
|
22191
|
+
if (fs93.existsSync(executableFile)) return;
|
|
22189
22192
|
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";
|
|
22190
22193
|
const executableMissing = `'${executableFile}' does not exist
|
|
22191
22194
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -22203,11 +22206,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22203
22206
|
let launchWithNode = false;
|
|
22204
22207
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
22205
22208
|
function findFile(baseDir, baseName) {
|
|
22206
|
-
const localBin =
|
|
22207
|
-
if (
|
|
22208
|
-
if (sourceExt.includes(
|
|
22209
|
+
const localBin = path91.resolve(baseDir, baseName);
|
|
22210
|
+
if (fs93.existsSync(localBin)) return localBin;
|
|
22211
|
+
if (sourceExt.includes(path91.extname(baseName))) return void 0;
|
|
22209
22212
|
const foundExt = sourceExt.find(
|
|
22210
|
-
(ext) =>
|
|
22213
|
+
(ext) => fs93.existsSync(`${localBin}${ext}`)
|
|
22211
22214
|
);
|
|
22212
22215
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
22213
22216
|
return void 0;
|
|
@@ -22219,21 +22222,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22219
22222
|
if (this._scriptPath) {
|
|
22220
22223
|
let resolvedScriptPath;
|
|
22221
22224
|
try {
|
|
22222
|
-
resolvedScriptPath =
|
|
22225
|
+
resolvedScriptPath = fs93.realpathSync(this._scriptPath);
|
|
22223
22226
|
} catch {
|
|
22224
22227
|
resolvedScriptPath = this._scriptPath;
|
|
22225
22228
|
}
|
|
22226
|
-
executableDir =
|
|
22227
|
-
|
|
22229
|
+
executableDir = path91.resolve(
|
|
22230
|
+
path91.dirname(resolvedScriptPath),
|
|
22228
22231
|
executableDir
|
|
22229
22232
|
);
|
|
22230
22233
|
}
|
|
22231
22234
|
if (executableDir) {
|
|
22232
22235
|
let localFile = findFile(executableDir, executableFile);
|
|
22233
22236
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
22234
|
-
const legacyName =
|
|
22237
|
+
const legacyName = path91.basename(
|
|
22235
22238
|
this._scriptPath,
|
|
22236
|
-
|
|
22239
|
+
path91.extname(this._scriptPath)
|
|
22237
22240
|
);
|
|
22238
22241
|
if (legacyName !== this._name) {
|
|
22239
22242
|
localFile = findFile(
|
|
@@ -22244,7 +22247,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22244
22247
|
}
|
|
22245
22248
|
executableFile = localFile || executableFile;
|
|
22246
22249
|
}
|
|
22247
|
-
launchWithNode = sourceExt.includes(
|
|
22250
|
+
launchWithNode = sourceExt.includes(path91.extname(executableFile));
|
|
22248
22251
|
let proc;
|
|
22249
22252
|
if (process2.platform !== "win32") {
|
|
22250
22253
|
if (launchWithNode) {
|
|
@@ -23091,7 +23094,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23091
23094
|
* @return {Command}
|
|
23092
23095
|
*/
|
|
23093
23096
|
nameFromFilename(filename) {
|
|
23094
|
-
this._name =
|
|
23097
|
+
this._name = path91.basename(filename, path91.extname(filename));
|
|
23095
23098
|
return this;
|
|
23096
23099
|
}
|
|
23097
23100
|
/**
|
|
@@ -23105,9 +23108,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23105
23108
|
* @param {string} [path]
|
|
23106
23109
|
* @return {(string|null|Command)}
|
|
23107
23110
|
*/
|
|
23108
|
-
executableDir(
|
|
23109
|
-
if (
|
|
23110
|
-
this._executableDir =
|
|
23111
|
+
executableDir(path92) {
|
|
23112
|
+
if (path92 === void 0) return this._executableDir;
|
|
23113
|
+
this._executableDir = path92;
|
|
23111
23114
|
return this;
|
|
23112
23115
|
}
|
|
23113
23116
|
/**
|
|
@@ -23404,11 +23407,11 @@ var init_esm = __esm({
|
|
|
23404
23407
|
});
|
|
23405
23408
|
|
|
23406
23409
|
// src/lib/cloud/pointer.ts
|
|
23407
|
-
import
|
|
23408
|
-
import
|
|
23410
|
+
import fs74 from "node:fs";
|
|
23411
|
+
import path75 from "node:path";
|
|
23409
23412
|
function hasRetiredPointer(root2) {
|
|
23410
23413
|
try {
|
|
23411
|
-
const held4 = JSON.parse(
|
|
23414
|
+
const held4 = JSON.parse(fs74.readFileSync(path75.join(root2, POINTER_FILE), "utf8"));
|
|
23412
23415
|
return typeof held4.workspace === "string" && held4.workspace.trim() !== "";
|
|
23413
23416
|
} catch {
|
|
23414
23417
|
return false;
|
|
@@ -23423,39 +23426,39 @@ var init_pointer = __esm({
|
|
|
23423
23426
|
});
|
|
23424
23427
|
|
|
23425
23428
|
// src/lib/card-studio-backfill.ts
|
|
23426
|
-
import
|
|
23427
|
-
import
|
|
23429
|
+
import fs75 from "node:fs";
|
|
23430
|
+
import path76 from "node:path";
|
|
23428
23431
|
function renameToStudio() {
|
|
23429
23432
|
if (!KANBAN || !BOARD_STATE) return;
|
|
23430
|
-
const mark =
|
|
23433
|
+
const mark = path76.join(BOARD_STATE, RENAMED);
|
|
23431
23434
|
try {
|
|
23432
|
-
if (
|
|
23433
|
-
for (const [from, to] of [[
|
|
23434
|
-
if (
|
|
23435
|
+
if (fs75.existsSync(mark)) return;
|
|
23436
|
+
for (const [from, to] of [[path76.join(KANBAN, "workflows"), STUDIOS], [path76.join(RULES, "workflows"), path76.join(RULES, "studios")]]) {
|
|
23437
|
+
if (fs75.existsSync(from) && !fs75.existsSync(to)) fs75.renameSync(from, to);
|
|
23435
23438
|
}
|
|
23436
|
-
for (const file2 of [STUDIOS, TODO, TRIAGE].flatMap((dir) =>
|
|
23437
|
-
const at2 =
|
|
23438
|
-
const text5 =
|
|
23439
|
+
for (const file2 of [STUDIOS, TODO, TRIAGE].flatMap((dir) => fs75.existsSync(dir) ? walkMd(dir) : [])) {
|
|
23440
|
+
const at2 = path76.relative(KANBAN, file2).split(path76.sep).join("/");
|
|
23441
|
+
const text5 = fs75.readFileSync(file2, "utf8");
|
|
23439
23442
|
const to = studioRenamed(at2, text5);
|
|
23440
23443
|
if (to.path === at2 && to.content === text5) continue;
|
|
23441
|
-
const target =
|
|
23442
|
-
if (target !== file2 &&
|
|
23443
|
-
|
|
23444
|
-
if (target !== file2)
|
|
23444
|
+
const target = path76.join(KANBAN, to.path);
|
|
23445
|
+
if (target !== file2 && fs75.existsSync(target)) continue;
|
|
23446
|
+
fs75.writeFileSync(target, to.content);
|
|
23447
|
+
if (target !== file2) fs75.rmSync(file2);
|
|
23445
23448
|
}
|
|
23446
|
-
|
|
23447
|
-
|
|
23449
|
+
fs75.mkdirSync(BOARD_STATE, { recursive: true });
|
|
23450
|
+
fs75.writeFileSync(mark, "");
|
|
23448
23451
|
} catch {
|
|
23449
23452
|
}
|
|
23450
23453
|
}
|
|
23451
23454
|
function backfillCardStudios() {
|
|
23452
23455
|
renameToStudio();
|
|
23453
23456
|
if (!TODO || !BOARD_STATE) return;
|
|
23454
|
-
const mark =
|
|
23457
|
+
const mark = path76.join(BOARD_STATE, MARK);
|
|
23455
23458
|
try {
|
|
23456
|
-
if (
|
|
23459
|
+
if (fs75.existsSync(mark) || !fs75.existsSync(TODO)) return;
|
|
23457
23460
|
for (const file2 of walkMd(TODO)) {
|
|
23458
|
-
const text5 =
|
|
23461
|
+
const text5 = fs75.readFileSync(file2, "utf8");
|
|
23459
23462
|
if (!text5.startsWith("---\n")) continue;
|
|
23460
23463
|
const end2 = text5.indexOf("\n---", 3);
|
|
23461
23464
|
if (end2 < 0) continue;
|
|
@@ -23463,11 +23466,11 @@ function backfillCardStudios() {
|
|
|
23463
23466
|
if (!/\ntitle:/.test(head2) || /\nstudio:/.test(head2)) continue;
|
|
23464
23467
|
const modules = /\nmodules:[^\n]*/.exec(head2);
|
|
23465
23468
|
const at2 = modules ? modules.index + modules[0].length : end2;
|
|
23466
|
-
|
|
23469
|
+
fs75.writeFileSync(file2, `${text5.slice(0, at2)}
|
|
23467
23470
|
studio: coding${text5.slice(at2)}`);
|
|
23468
23471
|
}
|
|
23469
|
-
|
|
23470
|
-
|
|
23472
|
+
fs75.mkdirSync(BOARD_STATE, { recursive: true });
|
|
23473
|
+
fs75.writeFileSync(mark, "");
|
|
23471
23474
|
} catch {
|
|
23472
23475
|
}
|
|
23473
23476
|
}
|
|
@@ -23504,8 +23507,8 @@ var init_created_cards = __esm({
|
|
|
23504
23507
|
|
|
23505
23508
|
// src/lib/agent/creation.ts
|
|
23506
23509
|
import crypto4 from "node:crypto";
|
|
23507
|
-
import
|
|
23508
|
-
import
|
|
23510
|
+
import fs76 from "node:fs";
|
|
23511
|
+
import path77 from "node:path";
|
|
23509
23512
|
function creationError(error, triage) {
|
|
23510
23513
|
const zh = readLanguage() === "zh";
|
|
23511
23514
|
const messages = {
|
|
@@ -23531,12 +23534,12 @@ ${zh ? `\u539F\u6761\u76EE\u4ECD\u5728 triage\uFF1A${triage}\u3002${unreachable
|
|
|
23531
23534
|
function creationReceipt(request2, slot) {
|
|
23532
23535
|
const hash2 = crypto4.createHash("sha256").update(`${request2}
|
|
23533
23536
|
${slot}`).digest("hex");
|
|
23534
|
-
return
|
|
23537
|
+
return path77.join(projectStateDir(KANBAN, REPO_ROOT), "creations", `${hash2}.json`);
|
|
23535
23538
|
}
|
|
23536
23539
|
function readCreation(file2, said2) {
|
|
23537
23540
|
return withCreationLock(() => {
|
|
23538
23541
|
try {
|
|
23539
|
-
const held4 = JSON.parse(
|
|
23542
|
+
const held4 = JSON.parse(fs76.readFileSync(file2, "utf8"));
|
|
23540
23543
|
if (!held4.said || typeof held4.said.title !== "string") throw new Error("Invalid creation journal");
|
|
23541
23544
|
return held4;
|
|
23542
23545
|
} catch (error) {
|
|
@@ -23548,10 +23551,10 @@ function readCreation(file2, said2) {
|
|
|
23548
23551
|
});
|
|
23549
23552
|
}
|
|
23550
23553
|
function saveCreation(file2, journal) {
|
|
23551
|
-
|
|
23554
|
+
fs76.mkdirSync(path77.dirname(file2), { recursive: true });
|
|
23552
23555
|
const temp = `${file2}.${crypto4.randomUUID()}.tmp`;
|
|
23553
|
-
|
|
23554
|
-
|
|
23556
|
+
fs76.writeFileSync(temp, JSON.stringify(journal));
|
|
23557
|
+
fs76.renameSync(temp, file2);
|
|
23555
23558
|
}
|
|
23556
23559
|
function archiveCreation(source2, id) {
|
|
23557
23560
|
if (readArchived().some((s) => s.sourceId === source2 && s.cardId === id)) return;
|
|
@@ -23565,7 +23568,7 @@ function archiveCreation(source2, id) {
|
|
|
23565
23568
|
function triageFile(sourceId) {
|
|
23566
23569
|
const found2 = [...readInbox(), ...readAllDismissed(), ...readArchived()].find((s) => s.sourceId === sourceId.trim());
|
|
23567
23570
|
if (!found2) throw new BoardError(`nothing in triage is ${sourceId}`, { kind: "refused" });
|
|
23568
|
-
return
|
|
23571
|
+
return path77.basename(found2.relPath, ".md");
|
|
23569
23572
|
}
|
|
23570
23573
|
var init_creation = __esm({
|
|
23571
23574
|
"src/lib/agent/creation.ts"() {
|
|
@@ -23733,14 +23736,14 @@ __export(board_exports, {
|
|
|
23733
23736
|
buildBoardProgram: () => buildBoardProgram
|
|
23734
23737
|
});
|
|
23735
23738
|
import crypto5 from "node:crypto";
|
|
23736
|
-
import
|
|
23737
|
-
import
|
|
23739
|
+
import fs77 from "node:fs";
|
|
23740
|
+
import path78 from "node:path";
|
|
23738
23741
|
async function dispatch(move, cmd, args2, opts, cli) {
|
|
23739
23742
|
const ctx = ctxOf(cmd, cli.program);
|
|
23740
23743
|
const data = await runAction(ctx, {}, async () => {
|
|
23741
23744
|
const found2 = resolveBoard(move, { board: ctx.board, dir: ctx.dir, cwd: cli.cwd, installHint: cli.installHint });
|
|
23742
|
-
useBoard(found2, ctx.dir !== null);
|
|
23743
|
-
await syncStudios();
|
|
23745
|
+
useBoard(found2, ctx.dir !== null, move === "inspect");
|
|
23746
|
+
if (move !== "inspect") await syncStudios();
|
|
23744
23747
|
const root2 = found2.root;
|
|
23745
23748
|
sayIfRetiredPointer(root2);
|
|
23746
23749
|
const creating = move === "create" && insideRun() ? peekRun(insideRun()) : void 0;
|
|
@@ -23774,7 +23777,7 @@ async function cloudCard(task, opts) {
|
|
|
23774
23777
|
let request2;
|
|
23775
23778
|
if (typeof opts.bodyFile === "string") {
|
|
23776
23779
|
try {
|
|
23777
|
-
request2 =
|
|
23780
|
+
request2 = fs77.readFileSync(opts.bodyFile, "utf8");
|
|
23778
23781
|
} catch {
|
|
23779
23782
|
}
|
|
23780
23783
|
}
|
|
@@ -23804,7 +23807,7 @@ async function cloudCard(task, opts) {
|
|
|
23804
23807
|
const file2 = creationReceipt(`${checked.value}:${requestId}`, slot);
|
|
23805
23808
|
const journal = readCreation(file2, said2);
|
|
23806
23809
|
if (!journal.made) {
|
|
23807
|
-
const key = `akb-${
|
|
23810
|
+
const key = `akb-${path78.basename(file2, ".json").slice(0, 40)}`;
|
|
23808
23811
|
const made = await createProjectTask(checked.value, journal.said, key);
|
|
23809
23812
|
if (!made.ok) throw new BoardError(creationError(`Cloud did not make the task: ${made.error}`, triage), { kind: "refused" });
|
|
23810
23813
|
journal.made = made.value;
|
|
@@ -23851,6 +23854,9 @@ function buildBoardProgram(cli) {
|
|
|
23851
23854
|
).option("--append <text>", "add one question to the end", opInOrder("append")).option("--update <n> <text...>", "rewrite question <n> whole", opInOrder("update")).option("--drop <positions>", "remove answered questions, e.g. 1 or 1,3", opInOrder("drop")).option("--clear", "remove every open question", opInOrder("clear")).option("--option <text>", "a choice for the op before it", opInOrder("option")).option("--recommended-option <text>", "a choice for the op before it, ticked to start", opInOrder("recommended-option")).option("--mode <mode>", "how many choices the op before it takes: single | multi", opInOrder("mode")).option("--agent <name>", "the preview agent whose section the op before it is about", opInOrder("agent")).action(async function(id) {
|
|
23852
23855
|
await dispatch("update-questions", this, [String(id)], { ops: questionOps }, cli);
|
|
23853
23856
|
});
|
|
23857
|
+
move("inspect").argument("<id>", ID, cardId).summary("read task facts, saved work and execution references").action(async function(id) {
|
|
23858
|
+
await dispatch("inspect", this, [String(id)], this.opts(), cli);
|
|
23859
|
+
});
|
|
23854
23860
|
move("validate").argument("[id]", ID, cardId).summary("validate card format and report file, line, and repair instructions").description("Check one card, or every open card when no id is given. Reads only; exits non-zero with detailed errors until the format is valid.").action(async function(id) {
|
|
23855
23861
|
await dispatch("validate", this, id === void 0 ? [] : [String(id)], this.opts(), cli);
|
|
23856
23862
|
});
|
|
@@ -23933,17 +23939,19 @@ var init_board2 = __esm({
|
|
|
23933
23939
|
});
|
|
23934
23940
|
|
|
23935
23941
|
// src/lib/board-cli.ts
|
|
23936
|
-
import
|
|
23937
|
-
import
|
|
23938
|
-
function useBoard(found2, dirNamed) {
|
|
23939
|
-
if (!found2.named && found2.board ===
|
|
23942
|
+
import fs78 from "node:fs";
|
|
23943
|
+
import path79 from "node:path";
|
|
23944
|
+
function useBoard(found2, dirNamed, readOnly = false) {
|
|
23945
|
+
if (!found2.named && found2.board === path79.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
|
|
23940
23946
|
else setBoardDir(found2.board, found2.root);
|
|
23941
|
-
|
|
23942
|
-
|
|
23947
|
+
if (!readOnly) {
|
|
23948
|
+
useProjectState();
|
|
23949
|
+
backfillCardStudios();
|
|
23950
|
+
}
|
|
23943
23951
|
}
|
|
23944
23952
|
function whole(found2, move) {
|
|
23945
23953
|
if (move === MAKES_A_BOARD) return found2;
|
|
23946
|
-
if (!
|
|
23954
|
+
if (!fs78.existsSync(path79.join(found2.board, "todo"))) {
|
|
23947
23955
|
die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
|
|
23948
23956
|
kind: "board-incomplete",
|
|
23949
23957
|
dir: found2.root
|
|
@@ -23952,13 +23960,13 @@ function whole(found2, move) {
|
|
|
23952
23960
|
return found2;
|
|
23953
23961
|
}
|
|
23954
23962
|
function findBoardUpward(from, move) {
|
|
23955
|
-
let dir =
|
|
23963
|
+
let dir = path79.resolve(from);
|
|
23956
23964
|
for (; ; ) {
|
|
23957
|
-
if (hasBoard(dir)) return { root: dir, board:
|
|
23965
|
+
if (hasBoard(dir)) return { root: dir, board: path79.join(dir, "docs", "kanban") };
|
|
23958
23966
|
if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
|
|
23959
|
-
const kept2 =
|
|
23960
|
-
if (move !== MAKES_A_BOARD &&
|
|
23961
|
-
const up =
|
|
23967
|
+
const kept2 = path79.join(dir, ".akb", "kanban");
|
|
23968
|
+
if (move !== MAKES_A_BOARD && fs78.existsSync(path79.join(kept2, "todo"))) return { root: dir, board: kept2 };
|
|
23969
|
+
const up = path79.dirname(dir);
|
|
23962
23970
|
if (up === dir) return null;
|
|
23963
23971
|
dir = up;
|
|
23964
23972
|
}
|
|
@@ -23966,11 +23974,11 @@ function findBoardUpward(from, move) {
|
|
|
23966
23974
|
function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
23967
23975
|
const named2 = board2 ?? boardFromEnv();
|
|
23968
23976
|
if (named2) {
|
|
23969
|
-
const folder =
|
|
23970
|
-
if (!
|
|
23977
|
+
const folder = path79.resolve(cwd, named2);
|
|
23978
|
+
if (!fs78.existsSync(folder) && move !== MAKES_A_BOARD) {
|
|
23971
23979
|
die(`no such folder: ${folder}`, { kind: "no-such-folder", dir: folder });
|
|
23972
23980
|
}
|
|
23973
|
-
if (
|
|
23981
|
+
if (fs78.existsSync(folder) && !isBoardDir(folder) && move !== MAKES_A_BOARD) {
|
|
23974
23982
|
die(`${folder} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
|
|
23975
23983
|
kind: "no-board",
|
|
23976
23984
|
dir: folder
|
|
@@ -23979,24 +23987,24 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
23979
23987
|
return { root: projectRootOf(folder), board: folder, named: true };
|
|
23980
23988
|
}
|
|
23981
23989
|
if (dir !== null) {
|
|
23982
|
-
const root2 =
|
|
23983
|
-
if (!
|
|
23984
|
-
const kept2 =
|
|
23985
|
-
if (!hasBoard(root2) && move !== MAKES_A_BOARD &&
|
|
23990
|
+
const root2 = path79.resolve(dir);
|
|
23991
|
+
if (!fs78.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
|
|
23992
|
+
const kept2 = path79.join(root2, ".akb", "kanban");
|
|
23993
|
+
if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs78.existsSync(path79.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
|
|
23986
23994
|
if (!hasBoard(root2) && move !== MAKES_A_BOARD) {
|
|
23987
23995
|
die(`no board in ${root2} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
|
|
23988
23996
|
kind: "no-board",
|
|
23989
23997
|
dir: root2
|
|
23990
23998
|
});
|
|
23991
23999
|
}
|
|
23992
|
-
return whole({ root: root2, board:
|
|
24000
|
+
return whole({ root: root2, board: path79.join(root2, "docs", "kanban") }, move);
|
|
23993
24001
|
}
|
|
23994
24002
|
const found2 = findBoardUpward(cwd, move);
|
|
23995
24003
|
if (found2) return whole(found2, move);
|
|
23996
|
-
if (move === MAKES_A_BOARD) return { root:
|
|
24004
|
+
if (move === MAKES_A_BOARD) return { root: path79.resolve(cwd), board: path79.join(path79.resolve(cwd), "docs", "kanban") };
|
|
23997
24005
|
die(
|
|
23998
|
-
`no board here. Looked in ${
|
|
23999
|
-
{ kind: "no-board", dir:
|
|
24006
|
+
`no board here. Looked in ${path79.resolve(cwd)} and every folder above it for docs/kanban/. ${installHint}\uFF0C\u6216\u7528 --board \u6307\u5B9A\u5DF2\u6709\u770B\u677F\u3002`,
|
|
24007
|
+
{ kind: "no-board", dir: path79.resolve(cwd) }
|
|
24000
24008
|
);
|
|
24001
24009
|
}
|
|
24002
24010
|
function editDistance(a2, b2) {
|
|
@@ -24079,8 +24087,8 @@ var init_board_cli = __esm({
|
|
|
24079
24087
|
init_pointer();
|
|
24080
24088
|
init_card_studio_backfill();
|
|
24081
24089
|
MAKES_A_BOARD = "init";
|
|
24082
|
-
hasBoard = (dir) =>
|
|
24083
|
-
isBoardDir = (dir) =>
|
|
24090
|
+
hasBoard = (dir) => fs78.existsSync(path79.join(dir, "docs", "kanban"));
|
|
24091
|
+
isBoardDir = (dir) => fs78.existsSync(path79.join(dir, "todo")) && fs78.existsSync(path79.join(dir, "config.md"));
|
|
24084
24092
|
boardFromEnv = () => {
|
|
24085
24093
|
const named2 = process.env.AI4KANBAN_BOARD?.trim();
|
|
24086
24094
|
return named2 ? named2 : null;
|
|
@@ -24324,8 +24332,8 @@ var init_agent = __esm({
|
|
|
24324
24332
|
|
|
24325
24333
|
// src/commands/cloud-template.ts
|
|
24326
24334
|
import { createHash as createHash8 } from "node:crypto";
|
|
24327
|
-
import
|
|
24328
|
-
import
|
|
24335
|
+
import fs79 from "node:fs";
|
|
24336
|
+
import path80 from "node:path";
|
|
24329
24337
|
function usage2(problem, line) {
|
|
24330
24338
|
die(`${problem}
|
|
24331
24339
|
usage: ${line}`, { kind: "bad-args", bare: true, exitCode: 2 });
|
|
@@ -24402,10 +24410,10 @@ This template has no preview.`);
|
|
|
24402
24410
|
const written = [];
|
|
24403
24411
|
for (const p2 of previews) {
|
|
24404
24412
|
const bytes2 = Buffer.from(await (await ask(`/${at2}/previews/${route(p2.path)}`, {}, WITHOUT)).arrayBuffer());
|
|
24405
|
-
const file2 =
|
|
24406
|
-
const out =
|
|
24407
|
-
|
|
24408
|
-
|
|
24413
|
+
const file2 = path80.basename(p2.path);
|
|
24414
|
+
const out = path80.join(opts.to, file2.startsWith(`${name}-`) ? file2 : `${name}-${file2}`);
|
|
24415
|
+
fs79.mkdirSync(opts.to, { recursive: true });
|
|
24416
|
+
fs79.writeFileSync(out, bytes2);
|
|
24409
24417
|
written.push(out);
|
|
24410
24418
|
say(out);
|
|
24411
24419
|
}
|
|
@@ -24418,15 +24426,15 @@ async function templateGet(name, opts, program2) {
|
|
|
24418
24426
|
const { template } = await asJson(await ask(`/${at2}`, {}, WITHOUT));
|
|
24419
24427
|
const fetched = [];
|
|
24420
24428
|
for (const f2 of template.files) {
|
|
24421
|
-
const out =
|
|
24422
|
-
if (!out.startsWith(
|
|
24429
|
+
const out = path80.resolve(to, f2.path);
|
|
24430
|
+
if (!out.startsWith(path80.resolve(to) + path80.sep)) refuse3(T.corrupt, WITHOUT);
|
|
24423
24431
|
const bytes2 = Buffer.from(await (await ask(`/${at2}/files/${route(f2.path)}`, {}, WITHOUT)).arrayBuffer());
|
|
24424
24432
|
if (bytes2.byteLength !== f2.size || createHash8("sha256").update(bytes2).digest("hex") !== f2.sha256) {
|
|
24425
24433
|
refuse3(T.corrupt, WITHOUT);
|
|
24426
24434
|
}
|
|
24427
24435
|
fetched.push({ out, bytes: bytes2 });
|
|
24428
24436
|
}
|
|
24429
|
-
const taken = fetched.filter((f2) =>
|
|
24437
|
+
const taken = fetched.filter((f2) => fs79.existsSync(f2.out)).map((f2) => path80.relative(to, f2.out));
|
|
24430
24438
|
if (taken.length > 0) {
|
|
24431
24439
|
refuse3({
|
|
24432
24440
|
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`,
|
|
@@ -24434,8 +24442,8 @@ async function templateGet(name, opts, program2) {
|
|
|
24434
24442
|
});
|
|
24435
24443
|
}
|
|
24436
24444
|
for (const f2 of fetched) {
|
|
24437
|
-
|
|
24438
|
-
|
|
24445
|
+
fs79.mkdirSync(path80.dirname(f2.out), { recursive: true });
|
|
24446
|
+
fs79.writeFileSync(f2.out, f2.bytes);
|
|
24439
24447
|
}
|
|
24440
24448
|
say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
|
|
24441
24449
|
Fetched ${name}: ${fetched.length} files into ${to}`);
|
|
@@ -24452,25 +24460,25 @@ async function templateSource(name, opts) {
|
|
|
24452
24460
|
say(`evidence: ${e2.path}`);
|
|
24453
24461
|
continue;
|
|
24454
24462
|
}
|
|
24455
|
-
const out =
|
|
24456
|
-
|
|
24457
|
-
|
|
24463
|
+
const out = path80.join(opts.to, `${name}-${path80.basename(e2.path)}`);
|
|
24464
|
+
fs79.mkdirSync(opts.to, { recursive: true });
|
|
24465
|
+
fs79.writeFileSync(out, Buffer.from(await (await ask(`/${at2}/evidence/${route(e2.path)}`)).arrayBuffer()));
|
|
24458
24466
|
written.push(out);
|
|
24459
24467
|
say(out);
|
|
24460
24468
|
}
|
|
24461
24469
|
return { name, source: source2, evidence: written.length > 0 ? written : evidence.map((e2) => e2.path) };
|
|
24462
24470
|
}
|
|
24463
24471
|
async function templatePublish(dir, opts) {
|
|
24464
|
-
const root2 =
|
|
24465
|
-
const manifest =
|
|
24466
|
-
if (!
|
|
24467
|
-
const meta = readTemplateMeta(
|
|
24472
|
+
const root2 = path80.resolve(dir);
|
|
24473
|
+
const manifest = path80.join(root2, "template.md");
|
|
24474
|
+
if (!fs79.existsSync(manifest)) invalid("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
|
|
24475
|
+
const meta = readTemplateMeta(fs79.readFileSync(manifest, "utf8"));
|
|
24468
24476
|
const files = walk2(root2);
|
|
24469
|
-
const total = files.reduce((sum, f2) => sum +
|
|
24477
|
+
const total = files.reduce((sum, f2) => sum + fs79.statSync(path80.join(root2, f2)).size, 0);
|
|
24470
24478
|
if (total > MAX_BYTES3) invalid("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
|
|
24471
24479
|
for (const extra of [...opts.preview, ...opts.evidence]) {
|
|
24472
|
-
if (!
|
|
24473
|
-
if (
|
|
24480
|
+
if (!fs79.existsSync(extra)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
|
|
24481
|
+
if (path80.resolve(extra).startsWith(root2 + path80.sep)) {
|
|
24474
24482
|
invalid(
|
|
24475
24483
|
`${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`,
|
|
24476
24484
|
`${extra} is inside the template folder; keep previews and evidence outside it.`
|
|
@@ -24482,10 +24490,10 @@ async function templatePublish(dir, opts) {
|
|
|
24482
24490
|
}
|
|
24483
24491
|
const form = new FormData();
|
|
24484
24492
|
form.set("meta", JSON.stringify({ ...meta, replace: !!opts.replace }));
|
|
24485
|
-
const add2 = (kind, name, file2) => form.append(`${kind}:${name}`, new Blob([
|
|
24486
|
-
for (const f2 of files) add2("files", f2,
|
|
24487
|
-
for (const f2 of opts.preview) add2("previews",
|
|
24488
|
-
for (const f2 of opts.evidence) add2("evidence",
|
|
24493
|
+
const add2 = (kind, name, file2) => form.append(`${kind}:${name}`, new Blob([fs79.readFileSync(file2)]), path80.basename(name));
|
|
24494
|
+
for (const f2 of files) add2("files", f2, path80.join(root2, f2));
|
|
24495
|
+
for (const f2 of opts.preview) add2("previews", path80.basename(f2), f2);
|
|
24496
|
+
for (const f2 of opts.evidence) add2("evidence", path80.basename(f2), f2);
|
|
24489
24497
|
const done = await asJson(await ask("", { method: "POST", body: form }));
|
|
24490
24498
|
say(
|
|
24491
24499
|
done.replaced ? `\u5DF2\u66FF\u6362 ${done.name}\uFF1A${files.length} \u4E2A\u6587\u4EF6\u3002
|
|
@@ -24501,11 +24509,11 @@ Deleted ${name} from the catalog.`);
|
|
|
24501
24509
|
return { name, deleted: true };
|
|
24502
24510
|
}
|
|
24503
24511
|
async function templateShowcase(name, dir) {
|
|
24504
|
-
const file2 =
|
|
24505
|
-
if (!
|
|
24512
|
+
const file2 = path80.join(dir, "showcase.json");
|
|
24513
|
+
if (!fs79.existsSync(file2)) invalid(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
|
|
24506
24514
|
let meta;
|
|
24507
24515
|
try {
|
|
24508
|
-
meta = JSON.parse(
|
|
24516
|
+
meta = JSON.parse(fs79.readFileSync(file2, "utf8"));
|
|
24509
24517
|
} catch {
|
|
24510
24518
|
return invalid("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
|
|
24511
24519
|
}
|
|
@@ -24517,9 +24525,9 @@ async function templateShowcase(name, dir) {
|
|
|
24517
24525
|
const form = new FormData();
|
|
24518
24526
|
form.set("meta", JSON.stringify(meta));
|
|
24519
24527
|
for (const p2 of new Set(named2)) {
|
|
24520
|
-
const at2 =
|
|
24521
|
-
if (!
|
|
24522
|
-
form.append(`media:${p2}`, new Blob([
|
|
24528
|
+
const at2 = path80.join(dir, p2);
|
|
24529
|
+
if (!fs79.existsSync(at2)) invalid(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at2}\u3002`, `${at2} does not exist.`);
|
|
24530
|
+
form.append(`media:${p2}`, new Blob([fs79.readFileSync(at2)]), p2);
|
|
24523
24531
|
}
|
|
24524
24532
|
const done = await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form }));
|
|
24525
24533
|
say(`\u5DF2\u66F4\u65B0 ${name} \u7684\u5C55\u793A\u8D44\u6599\uFF1A${done.files} \u4E2A\u6587\u4EF6\u3002
|
|
@@ -24528,7 +24536,7 @@ Updated ${name}'s showcase: ${done.files} files.`);
|
|
|
24528
24536
|
}
|
|
24529
24537
|
function walk2(root2, sub = "") {
|
|
24530
24538
|
const out = [];
|
|
24531
|
-
for (const entry of
|
|
24539
|
+
for (const entry of fs79.readdirSync(path80.join(root2, sub), { withFileTypes: true })) {
|
|
24532
24540
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
24533
24541
|
const rel2 = sub ? `${sub}/${entry.name}` : entry.name;
|
|
24534
24542
|
if (entry.isDirectory()) out.push(...walk2(root2, rel2));
|
|
@@ -24761,7 +24769,7 @@ var init_follow_up = __esm({
|
|
|
24761
24769
|
var implement_default;
|
|
24762
24770
|
var init_implement = __esm({
|
|
24763
24771
|
"src/guide/implement.md"() {
|
|
24764
|
-
implement_default = "# Implement the approved requirements\n\nBuild the approved card or plan directly. Preserve settled decisions and unrelated questions;\ndo not replace or contradict the approved requirements. With no card, build only the given\nrequirement and create no card.\n\n- **
|
|
24772
|
+
implement_default = "# Implement the approved requirements\n\nBuild the approved card or plan directly. Preserve settled decisions and unrelated questions;\ndo not replace or contradict the approved requirements. With no card, build only the given\nrequirement and create no card.\n\n- **Authorization**: approval covers the necessary operations within the agreed scope and\n constraints; carry it across commands, tools and stages without repeated confirmation.\n- **User-action blockers**: resolve routine choices and problems yourself; ask only when\n reasonable investigation leaves a blocker requiring user action or a decision beyond the\n approved scope. On a card, use `akb guide update-questions`, stating what you tried, what\n is blocked and your recommendation; continue independent work.\n- **Defer what can wait**: follow `akb guide follow-up` for work this build does not require;\n never ask about it or let it block this build.\n- **Decisions made while building**: record an answered material decision the user could\n reasonably reverse under `## Worth noting after implementation` on the card.\n";
|
|
24765
24773
|
}
|
|
24766
24774
|
});
|
|
24767
24775
|
|
|
@@ -24833,7 +24841,7 @@ var init_revise = __esm({
|
|
|
24833
24841
|
var preview_agent_default;
|
|
24834
24842
|
var init_preview_agent = __esm({
|
|
24835
24843
|
"src/guide/preview-agent.md"() {
|
|
24836
|
-
preview_agent_default = '# Be a preview agent\n\nYou are one preview agent on a card. Change only your own part: the ``## By `<agent-name>`\nagent`` section your instructions cover, its assets, your memory, and any file your\ninstructions tell you to write.\n\n- **Write**: edit your section in place above `<!-- agent -->`; do not duplicate it. Use\n `###` for subheadings.\n- **
|
|
24844
|
+
preview_agent_default = '# Be a preview agent\n\nYou are one preview agent on a card. Change only your own part: the ``## By `<agent-name>`\nagent`` section your instructions cover, its assets, your memory, and any file your\ninstructions tell you to write.\n\n- **Write**: edit your section in place above `<!-- agent -->`; do not duplicate it. Use\n `###` for subheadings.\n- **Rework**: when your section exists, redo only what the user names or an upstream change\n affects, and keep the rest, including its IDs, as it is.\n- **Components**: use the Preview Components documentation supplied with your run to show your Preview.\n- **Long drafts**: put a draft over about 20 lines in `<board-state>/assets/<card id>/<name>.md`\n and show it with `<Asset src=".assets/<card id>/<name>.md">`; a shorter one goes in a code block.\n- **Memory**: `docs/kanban/memory/agents/<agent-name>/` is yours; keep only the files your\n instructions name, and edit one directly when you learn something lasting. Edit your\n studio\'s memory only as its rules say.\n- **User decisions**: follow `akb guide update-questions`; leave at most one open question,\n pointing to your section, appended with `--agent <agent-name>`.\n';
|
|
24837
24845
|
}
|
|
24838
24846
|
});
|
|
24839
24847
|
|
|
@@ -24991,8 +24999,8 @@ var init_guide2 = __esm({
|
|
|
24991
24999
|
|
|
24992
25000
|
// src/commands/studio.ts
|
|
24993
25001
|
import crypto6 from "node:crypto";
|
|
24994
|
-
import
|
|
24995
|
-
import
|
|
25002
|
+
import fs80 from "node:fs";
|
|
25003
|
+
import path81 from "node:path";
|
|
24996
25004
|
function cmdStudioList() {
|
|
24997
25005
|
if (!studiosReachable().ok) die(NEEDS_CLOUD, "needs-cloud");
|
|
24998
25006
|
const offline2 = studiosOffline();
|
|
@@ -25021,7 +25029,7 @@ function cmdStudioList() {
|
|
|
25021
25029
|
};
|
|
25022
25030
|
}
|
|
25023
25031
|
function cmdStudioDiagram(id, card, folder) {
|
|
25024
|
-
const files = folder ? readStudioFolder(
|
|
25032
|
+
const files = folder ? readStudioFolder(path81.resolve(folder)) : null;
|
|
25025
25033
|
const local = files ? parseStudioFile("studio", files[STUDIO_FILE] ?? "", STUDIO_FILE) : null;
|
|
25026
25034
|
if (local && "problem" in local) die(local.problem, "bad-studio");
|
|
25027
25035
|
const flow = local && "def" in local ? local.def : found(id);
|
|
@@ -25031,17 +25039,17 @@ function cmdStudioDiagram(id, card, folder) {
|
|
|
25031
25039
|
const agent = findSpecAgent(name);
|
|
25032
25040
|
return agent ? { ...agent, after: agentAfter(name) } : null;
|
|
25033
25041
|
});
|
|
25034
|
-
const file2 =
|
|
25035
|
-
|
|
25036
|
-
|
|
25042
|
+
const file2 = path81.join(ASSETS, String(cardId2), "studio.json");
|
|
25043
|
+
fs80.mkdirSync(path81.dirname(file2), { recursive: true });
|
|
25044
|
+
fs80.writeFileSync(file2, `${JSON.stringify(diagram, null, 2)}
|
|
25037
25045
|
`);
|
|
25038
25046
|
const tag = `<Studio src=".assets/${cardId2}/studio.json" label="${flow.name.replace(/"/g, "")}" />`;
|
|
25039
25047
|
say(tag);
|
|
25040
25048
|
return { file: file2, tag, diagram };
|
|
25041
25049
|
}
|
|
25042
25050
|
function cmdStudioValidate(folder) {
|
|
25043
|
-
const dir =
|
|
25044
|
-
if (!
|
|
25051
|
+
const dir = path81.resolve(folder);
|
|
25052
|
+
if (!fs80.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) die(`${folder} is not a folder`, "bad-args");
|
|
25045
25053
|
const files = readStudioFolder(dir);
|
|
25046
25054
|
const read3 = parseStudioFile("studio", files[STUDIO_FILE] ?? "", STUDIO_FILE);
|
|
25047
25055
|
const def = "def" in read3 ? read3.def : null;
|
|
@@ -25069,16 +25077,16 @@ function cmdStudioValidate(folder) {
|
|
|
25069
25077
|
async function cmdStudioPull(id, folder) {
|
|
25070
25078
|
const cloudId = cloudIdOf(id);
|
|
25071
25079
|
if (!cloudId) found(id);
|
|
25072
|
-
const dir =
|
|
25073
|
-
if (
|
|
25080
|
+
const dir = path81.resolve(folder ?? id);
|
|
25081
|
+
if (fs80.existsSync(dir) && fs80.readdirSync(dir).length) die(`${folder ?? id} is not empty`, "bad-args");
|
|
25074
25082
|
const read3 = await call("GET", `/v1/studios/${encodeURIComponent(cloudId)}`);
|
|
25075
25083
|
if (!read3.ok) die(read3.error, read3.code === "not_found" ? "no-such-studio" : "cloud-refused");
|
|
25076
25084
|
const { version, files } = read3.value;
|
|
25077
25085
|
for (const [file2, text5] of Object.entries({ ...files, [VERSION_FILE]: versionText(cloudId, version) })) {
|
|
25078
|
-
const full =
|
|
25079
|
-
|
|
25086
|
+
const full = path81.join(dir, ...file2.split("/"));
|
|
25087
|
+
fs80.mkdirSync(path81.dirname(full), { recursive: true });
|
|
25080
25088
|
const data = isAboutFile(file2) && !file2.endsWith(".md") && /^data:[^;]+;base64,/.exec(text5);
|
|
25081
|
-
|
|
25089
|
+
fs80.writeFileSync(full, data ? Buffer.from(text5.slice(data[0].length), "base64") : text5);
|
|
25082
25090
|
}
|
|
25083
25091
|
const shown = folder ?? `./${id}`;
|
|
25084
25092
|
say(`Pulled ${id} v${version} into ${shown}.`);
|
|
@@ -25090,45 +25098,45 @@ function publicationFiles(dir) {
|
|
|
25090
25098
|
return checked.files;
|
|
25091
25099
|
}
|
|
25092
25100
|
async function publishFolder(dir, route2, body, requestId) {
|
|
25093
|
-
const pendingFile =
|
|
25101
|
+
const pendingFile = path81.join(dir, ".publication.json");
|
|
25094
25102
|
const hash2 = crypto6.createHash("sha256").update(JSON.stringify({ route: route2, files: body.files, workspace: body.workspace })).digest("hex");
|
|
25095
25103
|
let held4;
|
|
25096
25104
|
try {
|
|
25097
|
-
held4 = JSON.parse(
|
|
25105
|
+
held4 = JSON.parse(fs80.readFileSync(pendingFile, "utf8"));
|
|
25098
25106
|
} catch {
|
|
25099
25107
|
}
|
|
25100
25108
|
if (requestId && held4?.requestId === requestId && held4.hash !== hash2) die("This request ID already names different files; use a new request ID.", "bad-args");
|
|
25101
25109
|
const replay = held4?.hash === hash2 && held4.route === route2 && (!requestId || held4.requestId === requestId) && (body.expectedVersion === held4.body.expectedVersion || body.expectedVersion === held4.resultVersion);
|
|
25102
25110
|
const pending = replay ? held4 : { requestId: requestId ?? crypto6.randomUUID(), hash: hash2, body, route: route2 };
|
|
25103
|
-
|
|
25111
|
+
fs80.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
25104
25112
|
const res = await call(route2 === "/v1/studios" ? "POST" : "PATCH", route2, pending.body, pending.requestId);
|
|
25105
25113
|
if (!res.ok) die(res.error, res.code === "version_conflict" || res.code === "conflict" ? "studio-moved" : "cloud-refused");
|
|
25106
25114
|
const { id, version } = res.value;
|
|
25107
25115
|
pending.resultVersion = version;
|
|
25108
|
-
|
|
25109
|
-
|
|
25116
|
+
fs80.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
25117
|
+
fs80.writeFileSync(path81.join(dir, VERSION_FILE), versionText(id, version));
|
|
25110
25118
|
say(`Saved ${studioName(id)} v${version}. New tasks take it.`);
|
|
25111
25119
|
return { id, version, changed: true, requestId: pending.requestId };
|
|
25112
25120
|
}
|
|
25113
25121
|
async function cmdStudioCreate(folder, opts) {
|
|
25114
25122
|
if (!opts.requestId) die("--request-id is required", "bad-args");
|
|
25115
|
-
const dir =
|
|
25123
|
+
const dir = path81.resolve(folder);
|
|
25116
25124
|
const files = publicationFiles(dir);
|
|
25117
25125
|
const workspace2 = opts.workspace ?? (await cloudScope()).workspace;
|
|
25118
25126
|
return publishFolder(dir, "/v1/studios", { files, workspace: workspace2 }, opts.requestId);
|
|
25119
25127
|
}
|
|
25120
25128
|
async function cmdStudioPush(folder, opts) {
|
|
25121
|
-
const dir =
|
|
25129
|
+
const dir = path81.resolve(folder);
|
|
25122
25130
|
let pulled = null;
|
|
25123
25131
|
try {
|
|
25124
|
-
pulled = JSON.parse(
|
|
25132
|
+
pulled = JSON.parse(fs80.readFileSync(path81.join(dir, VERSION_FILE), "utf8"));
|
|
25125
25133
|
} catch {
|
|
25126
25134
|
}
|
|
25127
25135
|
if (!pulled?.id || !Number.isInteger(pulled.version) || pulled.version < 1) die(`${folder} has no valid version.json; pull again.`, "bad-args");
|
|
25128
25136
|
const { id, version } = pulled;
|
|
25129
25137
|
if (id.startsWith("wf_builtin_")) die("Copy this studio before editing it.", "studio-read-only");
|
|
25130
25138
|
const files = publicationFiles(dir);
|
|
25131
|
-
if (!
|
|
25139
|
+
if (!fs80.existsSync(path81.join(dir, ".publication.json")) && !opts.requestId) {
|
|
25132
25140
|
const now = await call("GET", `/v1/studios/${encodeURIComponent(id)}`);
|
|
25133
25141
|
if (now.ok && now.value.version === version && JSON.stringify(files) === JSON.stringify(Object.fromEntries(Object.entries(now.value.files).filter(([f2]) => f2 !== VERSION_FILE).sort()))) {
|
|
25134
25142
|
say(`${studioName(id)} is unchanged (v${version}).`);
|
|
@@ -25147,7 +25155,7 @@ function noteText({ file: file2, text: text5 }) {
|
|
|
25147
25155
|
if (file2 !== void 0 && text5 !== void 0) die("pass --file or --text, not both", "bad-args");
|
|
25148
25156
|
if (file2 !== void 0) {
|
|
25149
25157
|
try {
|
|
25150
|
-
return
|
|
25158
|
+
return fs80.readFileSync(file2, "utf8").trim();
|
|
25151
25159
|
} catch {
|
|
25152
25160
|
die(`can't read ${file2}`, "bad-args");
|
|
25153
25161
|
}
|
|
@@ -25287,7 +25295,6 @@ function completeDelivery(named2, result = {}) {
|
|
|
25287
25295
|
throw new Error("Only the current owning run can complete this delivery.");
|
|
25288
25296
|
}
|
|
25289
25297
|
if (answerOutcome(delivery2) === "changed") throw new Error("The approved requirements were superseded. Continue with the updated delivery.");
|
|
25290
|
-
if (delivery2.cardId !== null && openQuestions(delivery2.cardId)) throw new Error("Answer the open questions before completing.");
|
|
25291
25298
|
if (pending && run4 === current) {
|
|
25292
25299
|
if (pending.commit !== commit || pending.branch !== branch) throw new Error("This step already recorded a different result.");
|
|
25293
25300
|
pending.resumedSessions = [...pending.resumedSessions ?? [], sessionId];
|
|
@@ -25296,15 +25303,8 @@ function completeDelivery(named2, result = {}) {
|
|
|
25296
25303
|
const agent = delivery2.scheduled?.agent ?? deliveryAgents(delivery2)[deliveryStep(delivery2)]?.agent;
|
|
25297
25304
|
if (!agent) throw new Error("No studio step remains to complete.");
|
|
25298
25305
|
if (delivery2.cardId !== null && !locate(delivery2.cardId)) throw new Error("The card is missing before completion.");
|
|
25299
|
-
const finalStep = !!delivery2.scheduled || receipts.length + 1 >= deliveryAgents(delivery2).length;
|
|
25300
|
-
const card = delivery2.cardId === null ? void 0 : findCard(delivery2.cardId);
|
|
25301
|
-
if (finalStep && card && /[-*]\s+\[ \]/.test(card.body)) throw new Error("Complete every Todo before finishing the delivery.");
|
|
25302
25306
|
const merges = specAgentCatalog().agents.find((a2) => a2.name === agent)?.merges;
|
|
25303
25307
|
if (merges && !commit && delivery2.base) throw new Error(`\`${agent}\` must report its merged commit and target branch.`);
|
|
25304
|
-
if (delivery2.studio?.needsArtifact && !delivery2.scheduled) {
|
|
25305
|
-
const stop = filesStop(delivery2);
|
|
25306
|
-
if (stop) throw new Error(stop.why);
|
|
25307
|
-
}
|
|
25308
25308
|
const receipt2 = { sessionId, step: receipts.length, at: Date.now(), commit, branch, finished: false };
|
|
25309
25309
|
receipts.push(receipt2);
|
|
25310
25310
|
return { delivery: delivery2, receipt: receipt2 };
|
|
@@ -25313,12 +25313,6 @@ function completeDelivery(named2, result = {}) {
|
|
|
25313
25313
|
syncAudit(delivery.deliveryId);
|
|
25314
25314
|
const final = !!delivery.scheduled || receipt.step + 1 >= deliveryAgents(delivery).length;
|
|
25315
25315
|
if (final && !receipt.finished) {
|
|
25316
|
-
if (delivery.studio?.needsArtifact && !delivery.scheduled) {
|
|
25317
|
-
const stop = filesStop(delivery);
|
|
25318
|
-
if (stop) throw new Error(stop.why);
|
|
25319
|
-
}
|
|
25320
|
-
const card = delivery.cardId === null ? void 0 : findCard(delivery.cardId);
|
|
25321
|
-
if (card && /[-*]\s+\[ \]/.test(card.body)) throw new Error("Complete every Todo before finishing the delivery.");
|
|
25322
25316
|
let handoff = receipt.handoff;
|
|
25323
25317
|
if (delivery.cardId !== null) {
|
|
25324
25318
|
const source2 = locate(delivery.cardId);
|
|
@@ -25360,8 +25354,6 @@ var init_complete = __esm({
|
|
|
25360
25354
|
init_progress();
|
|
25361
25355
|
init_answers();
|
|
25362
25356
|
init_env();
|
|
25363
|
-
init_outputs();
|
|
25364
|
-
init_read();
|
|
25365
25357
|
init_store();
|
|
25366
25358
|
init_studios();
|
|
25367
25359
|
init_catalog();
|
|
@@ -25369,16 +25361,16 @@ var init_complete = __esm({
|
|
|
25369
25361
|
});
|
|
25370
25362
|
|
|
25371
25363
|
// src/lib/agent/task-chats.ts
|
|
25372
|
-
import
|
|
25373
|
-
import
|
|
25364
|
+
import fs81 from "node:fs";
|
|
25365
|
+
import path82 from "node:path";
|
|
25374
25366
|
function taskChatFile(task, home3) {
|
|
25375
25367
|
if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
|
|
25376
|
-
return
|
|
25368
|
+
return path82.join(taskChatsDir(home3), `${task}.jsonl`);
|
|
25377
25369
|
}
|
|
25378
25370
|
function readTaskChat(task, home3) {
|
|
25379
25371
|
let text5;
|
|
25380
25372
|
try {
|
|
25381
|
-
text5 =
|
|
25373
|
+
text5 = fs81.readFileSync(taskChatFile(task, home3), "utf8");
|
|
25382
25374
|
} catch {
|
|
25383
25375
|
return [];
|
|
25384
25376
|
}
|
|
@@ -25399,13 +25391,13 @@ var init_task_chats = __esm({
|
|
|
25399
25391
|
"use strict";
|
|
25400
25392
|
init_home();
|
|
25401
25393
|
TASK = /^[\w-]{1,100}$/;
|
|
25402
|
-
taskChatsDir = (home3 = machineHome()) =>
|
|
25394
|
+
taskChatsDir = (home3 = machineHome()) => path82.join(home3, "chats");
|
|
25403
25395
|
}
|
|
25404
25396
|
});
|
|
25405
25397
|
|
|
25406
25398
|
// src/lib/agent/memory-review.ts
|
|
25407
|
-
import
|
|
25408
|
-
import
|
|
25399
|
+
import fs82 from "node:fs";
|
|
25400
|
+
import path83 from "node:path";
|
|
25409
25401
|
function taskChatsToReview(tasks) {
|
|
25410
25402
|
const out = [];
|
|
25411
25403
|
for (const ref of [...new Set(tasks)]) {
|
|
@@ -25427,8 +25419,8 @@ function readArchived2(id) {
|
|
|
25427
25419
|
const found2 = Number.isInteger(id) && id > 0 ? locateArchived(id) : null;
|
|
25428
25420
|
if (!found2) return null;
|
|
25429
25421
|
try {
|
|
25430
|
-
const file2 = found2.kind === "group" ?
|
|
25431
|
-
const { meta, body } = parseFrontmatter(
|
|
25422
|
+
const file2 = found2.kind === "group" ? path83.join(found2.target, "root.md") : found2.target;
|
|
25423
|
+
const { meta, body } = parseFrontmatter(fs82.readFileSync(file2, "utf8"));
|
|
25432
25424
|
if (!meta) return null;
|
|
25433
25425
|
return { id, title: meta.title, modules: meta.modules ?? [], rejected: meta.rejected, body };
|
|
25434
25426
|
} catch {
|
|
@@ -25497,17 +25489,17 @@ var init_memory_review = __esm({
|
|
|
25497
25489
|
});
|
|
25498
25490
|
|
|
25499
25491
|
// src/lib/agent/dismissal-review.ts
|
|
25500
|
-
import
|
|
25501
|
-
import
|
|
25492
|
+
import fs83 from "node:fs";
|
|
25493
|
+
import path84 from "node:path";
|
|
25502
25494
|
function rejectionsToReview() {
|
|
25503
|
-
const dir =
|
|
25504
|
-
if (!
|
|
25495
|
+
const dir = path84.join(ARCHIVE, REJECTIONS_TO_REVIEW);
|
|
25496
|
+
if (!fs83.existsSync(dir)) return [];
|
|
25505
25497
|
const found2 = [];
|
|
25506
25498
|
for (const file2 of walkMd(dir)) {
|
|
25507
25499
|
const id = archivedId(file2);
|
|
25508
25500
|
if (id === null) continue;
|
|
25509
25501
|
try {
|
|
25510
|
-
const { meta } = parseFrontmatter(
|
|
25502
|
+
const { meta } = parseFrontmatter(fs83.readFileSync(file2, "utf8"));
|
|
25511
25503
|
if (!meta?.rejected || meta.rejected_by !== "user" || !meta.rejected_reason.trim()) continue;
|
|
25512
25504
|
found2.push({ id, title: meta.title, file: rel(file2), reason: meta.rejected_reason.trim(), rejectedAt: meta.rejected_at });
|
|
25513
25505
|
} catch {
|
|
@@ -25537,7 +25529,7 @@ function citedSources(text5) {
|
|
|
25537
25529
|
function withdrawnSources() {
|
|
25538
25530
|
const cited = [...new Set(plannerCopies("rejected.md").flatMap((file2) => {
|
|
25539
25531
|
try {
|
|
25540
|
-
return citedSources(
|
|
25532
|
+
return citedSources(fs83.readFileSync(file2, "utf8"));
|
|
25541
25533
|
} catch {
|
|
25542
25534
|
return [];
|
|
25543
25535
|
}
|
|
@@ -25562,8 +25554,8 @@ var init_dismissal_review = __esm({
|
|
|
25562
25554
|
});
|
|
25563
25555
|
|
|
25564
25556
|
// src/lib/agent/flow.ts
|
|
25565
|
-
import
|
|
25566
|
-
import
|
|
25557
|
+
import fs84 from "node:fs";
|
|
25558
|
+
import path85 from "node:path";
|
|
25567
25559
|
function readCard2(id, home3 = "board") {
|
|
25568
25560
|
const pending = activeDelivery(id)?.completions?.some((c2) => !c2.finished);
|
|
25569
25561
|
const found2 = home3 === "archive" ? locateArchived(id) : locate(id) ?? (pending ? locateArchived(id) : null);
|
|
@@ -25573,10 +25565,10 @@ function readCard2(id, home3 = "board") {
|
|
|
25573
25565
|
{ kind: "card-not-found", id }
|
|
25574
25566
|
);
|
|
25575
25567
|
}
|
|
25576
|
-
const file2 = found2.kind === "group" ?
|
|
25568
|
+
const file2 = found2.kind === "group" ? path85.join(found2.target, "root.md") : found2.target;
|
|
25577
25569
|
let text5;
|
|
25578
25570
|
try {
|
|
25579
|
-
text5 =
|
|
25571
|
+
text5 = fs84.readFileSync(file2, "utf8");
|
|
25580
25572
|
} catch {
|
|
25581
25573
|
die(`#${id} is on the board but ${rel(file2)} can't be read.`, { kind: "card-unreadable", id });
|
|
25582
25574
|
}
|
|
@@ -26085,7 +26077,7 @@ var init_stage_end = __esm({
|
|
|
26085
26077
|
import { createHash as createHash9 } from "node:crypto";
|
|
26086
26078
|
function markBoard() {
|
|
26087
26079
|
try {
|
|
26088
|
-
return new Map(
|
|
26080
|
+
return new Map(allCards().map((card) => [card.id, wroteOf(card)]));
|
|
26089
26081
|
} catch {
|
|
26090
26082
|
return /* @__PURE__ */ new Map();
|
|
26091
26083
|
}
|
|
@@ -26146,7 +26138,7 @@ function refinementAfter(action, cardId2, flowId) {
|
|
|
26146
26138
|
function refinesAfter(action, changed, before) {
|
|
26147
26139
|
let cards;
|
|
26148
26140
|
try {
|
|
26149
|
-
cards =
|
|
26141
|
+
cards = allCards();
|
|
26150
26142
|
} catch {
|
|
26151
26143
|
return [];
|
|
26152
26144
|
}
|
|
@@ -26249,34 +26241,12 @@ var init_refine2 = __esm({
|
|
|
26249
26241
|
}
|
|
26250
26242
|
});
|
|
26251
26243
|
|
|
26252
|
-
// src/lib/agent/own-cost.ts
|
|
26253
|
-
function ownCost(total, before) {
|
|
26254
|
-
if (total === void 0 || before === null) return void 0;
|
|
26255
|
-
if (before === void 0 || total < before) return total;
|
|
26256
|
-
return total >= before ? total - before : void 0;
|
|
26257
|
-
}
|
|
26258
|
-
function lastSessionTotal(id, runs) {
|
|
26259
|
-
let best;
|
|
26260
|
-
const take = (at2, usd) => {
|
|
26261
|
-
if (typeof usd === "number" && usd >= 0 && (!best || at2 >= best.at)) best = { at: at2, usd };
|
|
26262
|
-
};
|
|
26263
|
-
for (const r2 of runs) if (r2.resumeId === id || r2.sessionId === id) take(r2.endedAt ?? r2.startedAt, r2.sessionCostUsd);
|
|
26264
|
-
return best?.usd ?? null;
|
|
26265
|
-
}
|
|
26266
|
-
var reportsSessionTotal;
|
|
26267
|
-
var init_own_cost = __esm({
|
|
26268
|
-
"src/lib/agent/own-cost.ts"() {
|
|
26269
|
-
"use strict";
|
|
26270
|
-
reportsSessionTotal = (harness) => harness === "claude-code";
|
|
26271
|
-
}
|
|
26272
|
-
});
|
|
26273
|
-
|
|
26274
26244
|
// src/lib/agent/follow.ts
|
|
26275
26245
|
function specRunsAfter(asks) {
|
|
26276
26246
|
if (!asks.length) return [];
|
|
26277
26247
|
let cards;
|
|
26278
26248
|
try {
|
|
26279
|
-
cards =
|
|
26249
|
+
cards = allCards();
|
|
26280
26250
|
} catch {
|
|
26281
26251
|
return [];
|
|
26282
26252
|
}
|
|
@@ -26392,7 +26362,7 @@ __export(watch_exports, {
|
|
|
26392
26362
|
watchRun: () => watchRun
|
|
26393
26363
|
});
|
|
26394
26364
|
import { spawn as spawn3 } from "node:child_process";
|
|
26395
|
-
import
|
|
26365
|
+
import fs85 from "node:fs";
|
|
26396
26366
|
async function watchRun(sessionId, resume = startResume) {
|
|
26397
26367
|
const spec = readSpec(sessionId);
|
|
26398
26368
|
const run4 = peekRun(sessionId);
|
|
@@ -26428,11 +26398,11 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
26428
26398
|
const record = claimed ?? run4;
|
|
26429
26399
|
const sub = record.action === "sub";
|
|
26430
26400
|
if (claim) await setCardStatus(claim.cardId, claim.status);
|
|
26431
|
-
|
|
26432
|
-
const logFile =
|
|
26401
|
+
fs85.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
26402
|
+
const logFile = fs85.createWriteStream(record.logPath, { flags: "a" });
|
|
26433
26403
|
logFile.on("error", () => {
|
|
26434
26404
|
});
|
|
26435
|
-
const eventsFile =
|
|
26405
|
+
const eventsFile = fs85.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
|
|
26436
26406
|
eventsFile.on("error", () => {
|
|
26437
26407
|
});
|
|
26438
26408
|
const pendingOperations = /* @__PURE__ */ new Set();
|
|
@@ -26468,11 +26438,9 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
26468
26438
|
}
|
|
26469
26439
|
}
|
|
26470
26440
|
const stagePrompt = record.action === "spec" && record.cardId !== null && record.specAgent ? previewStagePrompt(record.cardId, record.specAgent, boardCommandFor(record.cardId)) : "";
|
|
26471
|
-
const basePrompt = record.
|
|
26472
|
-
const prompt = [basePrompt, stagePrompt, discardedCardsPrompt(record.discardedCards)].filter(Boolean).join("\n\n");
|
|
26441
|
+
const basePrompt = record.resumedFrom ? spec.prompt || resumePrompt(record.deliveryId, record.action) : spec.prompt;
|
|
26442
|
+
const prompt = [basePrompt, basePrompt.includes(stagePrompt) ? "" : stagePrompt, discardedCardsPrompt(record.discardedCards)].filter(Boolean).join("\n\n");
|
|
26473
26443
|
const before = markBoard();
|
|
26474
|
-
const sources2 = snapshotSpecs();
|
|
26475
|
-
const wasBroken = new Set(boardComplaints());
|
|
26476
26444
|
const takes = active2.images;
|
|
26477
26445
|
const shots = takes?.as === "args" ? (record.pictures ?? []).flatMap((file2) => takes.args(file2)) : [];
|
|
26478
26446
|
const [cmd, ...args2] = [...active2.argv, ...shots];
|
|
@@ -26481,7 +26449,7 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
26481
26449
|
const silenceMs = silenceFor * 6e4;
|
|
26482
26450
|
void refreshCatalog();
|
|
26483
26451
|
const client = active2.client;
|
|
26484
|
-
const restartBase = !client
|
|
26452
|
+
const restartBase = !client ? void 0 : record.resumedFrom ? restartPrompt(requestOf(record), record.deliveryId) : record.continues && !record.continues.fork ? spec.prompt : void 0;
|
|
26485
26453
|
const restart = restartBase ? [restartBase, discardedCardsPrompt(record.discardedCards)].filter(Boolean).join("\n\n") : void 0;
|
|
26486
26454
|
const stdinPrompt = client ? void 0 : active2.stdinPrompt;
|
|
26487
26455
|
const stdio = [client || stdinPrompt ? "pipe" : "ignore", "pipe", "pipe"];
|
|
@@ -26701,82 +26669,9 @@ async function watchRun(sessionId, resume = startResume) {
|
|
|
26701
26669
|
const totalCost = sessionTotal === void 0 ? reported : ownCost(sessionTotal, totalFrom);
|
|
26702
26670
|
const usage3 = spoken ? spoken.usage : renderer?.usage?.();
|
|
26703
26671
|
if (spoken) gotContext(spoken.context);
|
|
26704
|
-
|
|
26705
|
-
const
|
|
26706
|
-
const
|
|
26707
|
-
let formatErrors = [];
|
|
26708
|
-
let broken = [];
|
|
26709
|
-
if (!sub) {
|
|
26710
|
-
try {
|
|
26711
|
-
const discarded = new Set(cleanupDiscardedCards(sessionId));
|
|
26712
|
-
for (const [file2, card] of sources2) if (discarded.has(card.id)) sources2.delete(file2);
|
|
26713
|
-
for (const id of discarded) required.delete(id);
|
|
26714
|
-
const current = snapshotSpecs();
|
|
26715
|
-
const onBoard3 = (id) => [...current.values()].some((card) => card.id === id);
|
|
26716
|
-
const departed = /* @__PURE__ */ new Set();
|
|
26717
|
-
const rejected = /* @__PURE__ */ new Set();
|
|
26718
|
-
const missing = (id) => {
|
|
26719
|
-
if (discarded.has(id) || onBoard3(id)) return false;
|
|
26720
|
-
if (leftBoardRejected(id)) {
|
|
26721
|
-
rejected.add(id);
|
|
26722
|
-
return false;
|
|
26723
|
-
}
|
|
26724
|
-
if (leftBoardOnLanding(id)) {
|
|
26725
|
-
departed.add(id);
|
|
26726
|
-
return false;
|
|
26727
|
-
}
|
|
26728
|
-
return true;
|
|
26729
|
-
};
|
|
26730
|
-
for (const id of [...required]) if (!onBoard3(id) && !missing(id)) required.delete(id);
|
|
26731
|
-
for (const [file2, card] of current) {
|
|
26732
|
-
if (card.id === record.cardId || !heldElsewhere.has(card.id) && sources2.get(file2)?.text !== card.text) required.add(card.id);
|
|
26733
|
-
}
|
|
26734
|
-
for (const id of record.formatRepair?.cardIds ?? []) {
|
|
26735
|
-
if (missing(id)) {
|
|
26736
|
-
formatErrors.push({ file: rel(TODO), line: 1, rule: "missing-card", message: `Task #${id} disappeared. Restore its card file.` });
|
|
26737
|
-
}
|
|
26738
|
-
}
|
|
26739
|
-
if (record.cardId !== null && !["archive", "reject"].includes(record.action) && [...sources2.values()].some((card) => card.id === record.cardId) && missing(record.cardId)) {
|
|
26740
|
-
required.add(record.cardId);
|
|
26741
|
-
formatErrors.push({ file: rel(TODO), line: 1, rule: "missing-card", message: `Task #${record.cardId} disappeared. Restore its card file; this run must not delete it.` });
|
|
26742
|
-
}
|
|
26743
|
-
if (repairable) {
|
|
26744
|
-
const owed = new Set(record.formatRepair?.broken ?? []);
|
|
26745
|
-
broken = boardComplaints().filter((line) => owed.has(line) || !wasBroken.has(line));
|
|
26746
|
-
formatErrors.push(...broken.map((line) => ({ file: rel(TODO), line: 1, rule: "board-broken", message: `${line} Take a card off the board with \`${boardCommand()} raw archive <id>\` or \`${boardCommand()} raw reject <id>\`, never by deleting its file.` })));
|
|
26747
|
-
}
|
|
26748
|
-
for (const id of departed) log.write(`
|
|
26749
|
-
[board] Task #${id} left the board with its landing; there is nothing to restore.
|
|
26750
|
-
`);
|
|
26751
|
-
for (const id of rejected) log.write(`
|
|
26752
|
-
[board] Task #${id} was rejected; there is nothing to restore.
|
|
26753
|
-
`);
|
|
26754
|
-
} catch (error) {
|
|
26755
|
-
formatErrors = [{ file: rel(TODO), line: 1, rule: "read-error", message: `Cannot validate the card files: ${String(error)}. Restore readable Markdown files and retry.` }];
|
|
26756
|
-
}
|
|
26757
|
-
}
|
|
26758
|
-
const contractError = formatErrors.length ? boardCheckErrors(formatErrors) : void 0;
|
|
26759
|
-
const repairing = !!contractError && repairable && (record.formatRepair?.attempt ?? 0) < MAX_FORMAT_REPAIRS;
|
|
26760
|
-
const problems = formatErrors.length && !repairing ? boardProblems(formatErrors) : void 0;
|
|
26761
|
-
if (contractError) {
|
|
26762
|
-
log.write(`
|
|
26763
|
-
[validation] ${contractError}
|
|
26764
|
-
`);
|
|
26765
|
-
if (status === "done") status = "error";
|
|
26766
|
-
if (record.cardId !== null && !record.deliveryId) await setCardStatus(record.cardId, "todo");
|
|
26767
|
-
}
|
|
26768
|
-
const changed = sub ? [] : [.../* @__PURE__ */ new Set([...record.formatRepair?.changedIds ?? [], ...claimChanges(before, sessionId)])].filter((id) => !peekRun(sessionId)?.discardedCards?.some((c2) => c2.id === id));
|
|
26769
|
-
const original = record.formatRepair ? new Map(record.formatRepair.existingIds.map((id) => [id, ""])) : before;
|
|
26770
|
-
patch(sessionId, (r2) => {
|
|
26771
|
-
r2.formatRepair = contractError ? {
|
|
26772
|
-
attempt: record.formatRepair?.attempt ?? 0,
|
|
26773
|
-
errors: contractError,
|
|
26774
|
-
...broken.length ? { broken } : {},
|
|
26775
|
-
cardIds: [...required],
|
|
26776
|
-
changedIds: changed,
|
|
26777
|
-
existingIds: [...original.keys()]
|
|
26778
|
-
} : void 0;
|
|
26779
|
-
});
|
|
26672
|
+
if (!sub) cleanupDiscardedCards(sessionId);
|
|
26673
|
+
const changed = sub ? [] : claimChanges(before, sessionId).filter((id) => !peekRun(sessionId)?.discardedCards?.some((c2) => c2.id === id));
|
|
26674
|
+
const original = before;
|
|
26780
26675
|
logFile.write(durationLine(endedAt - record.startedAt));
|
|
26781
26676
|
if (totalCost !== void 0) logFile.write(costLine(totalCost));
|
|
26782
26677
|
if (usage3) logFile.write(usageLine(usage3));
|
|
@@ -26795,13 +26690,6 @@ ${result}
|
|
|
26795
26690
|
if (usage3) r2.usage = usage3;
|
|
26796
26691
|
if (result) r2.result = result;
|
|
26797
26692
|
});
|
|
26798
|
-
if (status === "done" && record.action === "spec" && record.cardId !== null && record.specAgent) {
|
|
26799
|
-
const progress = readPreviewProgress(record.cardId)[record.specAgent];
|
|
26800
|
-
if (progress && !["awaiting_confirmation", "ready"].includes(progress.stages.find((stage) => stage.id === progress.currentStageId)?.status ?? "")) {
|
|
26801
|
-
status = "error";
|
|
26802
|
-
failure = "The preview agent exited without submitting its current stage.";
|
|
26803
|
-
}
|
|
26804
|
-
}
|
|
26805
26693
|
if (status !== "done" && record.action === "spec" && record.cardId !== null && record.specAgent) {
|
|
26806
26694
|
updatePreviewProgress(record.cardId, (all2) => {
|
|
26807
26695
|
const progress = all2[record.specAgent];
|
|
@@ -26814,7 +26702,6 @@ ${result}
|
|
|
26814
26702
|
const noteWhy = status === "done" ? settled?.stalledWhy ?? [] : [];
|
|
26815
26703
|
const saidOurs = !asked && silent && !spawnError;
|
|
26816
26704
|
const errorWhy = [
|
|
26817
|
-
...problems ? [{ kind: "format" }] : [],
|
|
26818
26705
|
...spawnWhy ? [spawnWhy] : [],
|
|
26819
26706
|
...saidOurs ? [waited ? { kind: "backgroundSilent", args: { n: String(BACKGROUND_WAIT.minutes / 60) } } : { kind: "silent", args: { n: String(silenceFor) } }] : []
|
|
26820
26707
|
];
|
|
@@ -26840,24 +26727,13 @@ ${result}
|
|
|
26840
26727
|
// What went wrong, in whoever's words know: ours when the command wouldn't start or
|
|
26841
26728
|
// when it went quiet, the agent's own when the conversation ended badly or its
|
|
26842
26729
|
// stream said so. That cause leads; a card it left half-written follows.
|
|
26843
|
-
error:
|
|
26844
|
-
spawnError ?? (asked ? void 0 : silent ? quietSaid : spoken?.error ?? failure),
|
|
26845
|
-
problems
|
|
26846
|
-
),
|
|
26730
|
+
error: spawnError ?? (asked ? void 0 : silent ? quietSaid : spoken?.error ?? failure),
|
|
26847
26731
|
note,
|
|
26848
26732
|
errorWhy,
|
|
26849
26733
|
noteWhy,
|
|
26850
26734
|
endedAt
|
|
26851
26735
|
});
|
|
26852
26736
|
letGo();
|
|
26853
|
-
if (repairing) {
|
|
26854
|
-
const next = await resume(sessionId);
|
|
26855
|
-
if ("error" in next) patch(sessionId, (r2) => {
|
|
26856
|
-
r2.error = `${boardProblems(formatErrors)}
|
|
26857
|
-
Cannot resume board repair: ${next.error}`;
|
|
26858
|
-
r2.errorWhy = [{ kind: "format" }, { kind: "repairUnstarted", refusals: [next] }];
|
|
26859
|
-
});
|
|
26860
|
-
}
|
|
26861
26737
|
if (retrying) {
|
|
26862
26738
|
const next = await resume(sessionId);
|
|
26863
26739
|
if ("error" in next) patch(sessionId, (r2) => {
|
|
@@ -26865,9 +26741,10 @@ Cannot resume board repair: ${next.error}`;
|
|
|
26865
26741
|
r2.errorWhy = [...r2.errorWhy ?? [], { kind: "retryUnstarted", refusals: [next] }];
|
|
26866
26742
|
});
|
|
26867
26743
|
}
|
|
26868
|
-
|
|
26869
|
-
|
|
26870
|
-
|
|
26744
|
+
const missingSession = record.resumedFrom && !/auth|unauthorized|forbidden|login|log.in/i.test(failure ?? spoken?.error ?? "") && /(?:no (?:conversation|session|thread) found|(?:session|conversation|thread)[^\n]*(?:not found|does not exist))/i.test(failure ?? spoken?.error ?? "");
|
|
26745
|
+
if (status === "error" && !asked && (lost || missingSession)) {
|
|
26746
|
+
const next = missingSession ? await startResume(sessionId, { deliveryId: record.deliveryId, fresh: true }) : await startRun(spec.again);
|
|
26747
|
+
if (!missingSession && !("error" in next)) forgetRun(sessionId);
|
|
26871
26748
|
}
|
|
26872
26749
|
if (status === "done") queueCompleted(before.keys());
|
|
26873
26750
|
if (status === "done") await followUp(sessionId, record.flowId, settled?.runs ?? []);
|
|
@@ -27034,7 +26911,7 @@ function catchModel(sessionId, model) {
|
|
|
27034
26911
|
});
|
|
27035
26912
|
return true;
|
|
27036
26913
|
}
|
|
27037
|
-
var STOP_GRACE_MS, STOP_CLOSE_MS, STOP_FINISH_MS, silenceSaid,
|
|
26914
|
+
var STOP_GRACE_MS, STOP_CLOSE_MS, STOP_FINISH_MS, silenceSaid, joinNotes;
|
|
27038
26915
|
var init_watch = __esm({
|
|
27039
26916
|
"src/lib/agent/watch.ts"() {
|
|
27040
26917
|
"use strict";
|
|
@@ -27043,14 +26920,11 @@ var init_watch = __esm({
|
|
|
27043
26920
|
init_progress();
|
|
27044
26921
|
init_deliveries();
|
|
27045
26922
|
init_paths();
|
|
27046
|
-
init_reconcile();
|
|
27047
|
-
init_spec_contract();
|
|
27048
26923
|
init_store();
|
|
27049
26924
|
init_own_cost();
|
|
27050
26925
|
init_remove();
|
|
27051
26926
|
init_prompts();
|
|
27052
26927
|
init_catalog2();
|
|
27053
|
-
init_command();
|
|
27054
26928
|
init_settings2();
|
|
27055
26929
|
init_flow();
|
|
27056
26930
|
init_spawnable();
|
|
@@ -27066,19 +26940,17 @@ var init_watch = __esm({
|
|
|
27066
26940
|
init_refine2();
|
|
27067
26941
|
init_sessions();
|
|
27068
26942
|
init_start();
|
|
27069
|
-
init_types3();
|
|
27070
26943
|
STOP_GRACE_MS = 5e3;
|
|
27071
26944
|
STOP_CLOSE_MS = 2e3;
|
|
27072
26945
|
STOP_FINISH_MS = 1e4;
|
|
27073
26946
|
silenceSaid = (minutes) => `the agent said nothing for ${minutes} minute${minutes === 1 ? "" : "s"}, so the run was ended.`;
|
|
27074
|
-
MAX_FORMAT_REPAIRS = 3;
|
|
27075
26947
|
joinNotes = (...parts) => parts.filter(Boolean).join("\n\n") || void 0;
|
|
27076
26948
|
}
|
|
27077
26949
|
});
|
|
27078
26950
|
|
|
27079
26951
|
// src/commands/run.ts
|
|
27080
|
-
import
|
|
27081
|
-
import
|
|
26952
|
+
import fs86 from "node:fs";
|
|
26953
|
+
import path86 from "node:path";
|
|
27082
26954
|
async function cmdStartRun(action, args2, opts, program2 = "akb") {
|
|
27083
26955
|
if (action === "approve" && (opts.preview || opts.previewStage || opts.previewVersion || opts.definitionRevision)) return confirmLocalPreview(Number(args2[0]), opts);
|
|
27084
26956
|
const { req, follow: follow2, print } = readRequest(action, args2, opts);
|
|
@@ -27237,6 +27109,12 @@ function readRequest(action, args2, opts) {
|
|
|
27237
27109
|
return { req, follow: follow2, print };
|
|
27238
27110
|
}
|
|
27239
27111
|
async function cmdResume(id, opts) {
|
|
27112
|
+
const previous = await getRun(id ?? "last");
|
|
27113
|
+
const completed = previous?.deliveryId ? findDelivery(previous.deliveryId) : void 0;
|
|
27114
|
+
if (completed?.status === "finished" && completed.completions?.some((receipt) => receipt.finished)) {
|
|
27115
|
+
say(`delivery ${completed.deliveryId} is complete.`);
|
|
27116
|
+
return { sessionId: previous.sessionId, resumedFrom: previous.resumedFrom, delivery: deliveryOutcome(completed.deliveryId) };
|
|
27117
|
+
}
|
|
27240
27118
|
const opened = await startResume(id ?? "last", opts.requireSession);
|
|
27241
27119
|
if ("error" in opened) die(opened.error, { kind: "run-refused", ..."reason" in opened ? { reason: opened.reason } : {} });
|
|
27242
27120
|
const { run: run4 } = opened;
|
|
@@ -27258,6 +27136,7 @@ async function cmdResumeDelivery(named2) {
|
|
|
27258
27136
|
kind: "run-refused",
|
|
27259
27137
|
...res.kind === "refused" ? { reason: res.reason, args: res.args } : {}
|
|
27260
27138
|
});
|
|
27139
|
+
if (res.landed) return { deliveryId: res.deliveryId, landed: true };
|
|
27261
27140
|
const delivery = findDelivery(res.deliveryId);
|
|
27262
27141
|
const started = await startRun({
|
|
27263
27142
|
action: "implement",
|
|
@@ -27299,7 +27178,7 @@ async function cmdSubStart(words, opts) {
|
|
|
27299
27178
|
let prompt = words.join(" ");
|
|
27300
27179
|
if (opts.file) {
|
|
27301
27180
|
try {
|
|
27302
|
-
prompt =
|
|
27181
|
+
prompt = fs86.readFileSync(path86.resolve(opts.file), "utf8");
|
|
27303
27182
|
} catch {
|
|
27304
27183
|
die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
|
|
27305
27184
|
}
|
|
@@ -27437,7 +27316,7 @@ async function followRun(sessionId, already = "", program2 = "akb", events = fal
|
|
|
27437
27316
|
const deliveryId = first.deliveryId ?? last.deliveryId;
|
|
27438
27317
|
const delivery = deliveryId ? deliveryOutcome(deliveryId) : void 0;
|
|
27439
27318
|
if (delivery) say(`delivery ${delivery.id}: ${delivery.line}`);
|
|
27440
|
-
const failed = last.status !== "done" ? `run ${short(last.sessionId)} ended ${last.status}${last.error ? `: ${last.error}` : ""}` :
|
|
27319
|
+
const failed = last.status !== "done" ? `run ${short(last.sessionId)} ended ${last.status}${last.error ? `: ${last.error}` : ""}` : void 0;
|
|
27441
27320
|
const held4 = peekRun(last.sessionId);
|
|
27442
27321
|
const agentSession = held4 ? resumeSessionId(held4) : void 0;
|
|
27443
27322
|
return {
|
|
@@ -27668,7 +27547,7 @@ var init_signals = __esm({
|
|
|
27668
27547
|
});
|
|
27669
27548
|
|
|
27670
27549
|
// src/commands/triage.ts
|
|
27671
|
-
import
|
|
27550
|
+
import fs87 from "node:fs";
|
|
27672
27551
|
async function cmdTriageAdd(opts) {
|
|
27673
27552
|
const title = (opts.title ?? "").trim();
|
|
27674
27553
|
if (!title) die('say what it is: --title "<one line>"', { kind: "needs-input" });
|
|
@@ -27678,7 +27557,7 @@ async function cmdTriageAdd(opts) {
|
|
|
27678
27557
|
let body = opts.text;
|
|
27679
27558
|
if (opts.file !== void 0) {
|
|
27680
27559
|
try {
|
|
27681
|
-
body =
|
|
27560
|
+
body = fs87.readFileSync(opts.file, "utf8");
|
|
27682
27561
|
} catch {
|
|
27683
27562
|
die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
|
|
27684
27563
|
}
|
|
@@ -27745,10 +27624,16 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
27745
27624
|
if (!locate(id)) die(`no task with id ${id} under ${rel(TODO)}`, { kind: "card-not-found", id });
|
|
27746
27625
|
if (opts.stages !== void 0 || opts.submit || opts.reviseFrom) {
|
|
27747
27626
|
try {
|
|
27748
|
-
|
|
27749
|
-
|
|
27627
|
+
let run5;
|
|
27628
|
+
try {
|
|
27629
|
+
run5 = previewRun(id, name);
|
|
27630
|
+
} catch (error) {
|
|
27631
|
+
if (!(error instanceof PreviewContextMissing)) throw error;
|
|
27632
|
+
await activatePreviewRun(id, name);
|
|
27633
|
+
run5 = previewRun(id, name);
|
|
27634
|
+
}
|
|
27750
27635
|
const ids = opts.stages?.split(",").map((id2) => id2.trim());
|
|
27751
|
-
const result = await previewBridge(name, ids ? "select" : opts.reviseFrom ? "revise" : "submit", { run: run5.sessionId, ...ids ? { stages: ids } : opts.reviseFrom ? { stageId: opts.reviseFrom } : { baseline: readPreviewBaseline(id, name, run5.sessionId), stageId: opts.stage } });
|
|
27636
|
+
const result = await previewBridge(name, ids ? "select" : opts.reviseFrom ? "revise" : "submit", { run: run5.sessionId, cardId: id, ...ids ? { stages: ids } : opts.reviseFrom ? { stageId: opts.reviseFrom } : { baseline: readPreviewBaseline(id, name, run5.sessionId), stageId: opts.stage } });
|
|
27752
27637
|
if (result?.progress) {
|
|
27753
27638
|
updatePreviewProgress(id, (all2) => {
|
|
27754
27639
|
all2[name] = result.progress;
|
|
@@ -27782,12 +27667,6 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
27782
27667
|
const req = { action: "spec", id, title: titleOf(id), specAgent: name, notes };
|
|
27783
27668
|
const inside2 = insideRun();
|
|
27784
27669
|
if (!inside2 && process.env[PREVIEW_BRIDGE_ENV]) opts.follow = true;
|
|
27785
|
-
if (inside2 && readRuns().find((r2) => r2.sessionId === inside2)?.action === "spec") {
|
|
27786
|
-
die(
|
|
27787
|
-
"a preview agent does not ask for another preview agent \u2014 answer the part you own and leave the rest of the card to the session planning it.",
|
|
27788
|
-
{ kind: "spec-agent-recursion", specAgent: name }
|
|
27789
|
-
);
|
|
27790
|
-
}
|
|
27791
27670
|
if (opts.print === true) {
|
|
27792
27671
|
try {
|
|
27793
27672
|
await activatePreviewRun(id, name, void 0, notes);
|
|
@@ -27796,6 +27675,12 @@ async function cmdSpec(opts, program2 = "akb") {
|
|
|
27796
27675
|
}
|
|
27797
27676
|
return printFlow(req, program2);
|
|
27798
27677
|
}
|
|
27678
|
+
if (inside2 && readRuns().find((r2) => r2.sessionId === inside2)?.action === "spec") {
|
|
27679
|
+
die(
|
|
27680
|
+
"a preview agent does not ask for another preview agent \u2014 answer the part you own and leave the rest of the card to the session planning it.",
|
|
27681
|
+
{ kind: "spec-agent-recursion", specAgent: name }
|
|
27682
|
+
);
|
|
27683
|
+
}
|
|
27799
27684
|
const live = readRuns().find(
|
|
27800
27685
|
(r2) => r2.status === "running" && r2.action === "spec" && r2.cardId === id && r2.specAgent === name
|
|
27801
27686
|
);
|
|
@@ -69059,8 +68944,8 @@ var require_JSXTransformer = __commonJS({
|
|
|
69059
68944
|
}
|
|
69060
68945
|
if (this.isAutomaticRuntime) {
|
|
69061
68946
|
if (this.importProcessor) {
|
|
69062
|
-
for (const [
|
|
69063
|
-
prefix += `var ${resolvedName} = require("${
|
|
68947
|
+
for (const [path91, resolvedName] of Object.entries(this.cjsAutomaticModuleNameResolutions)) {
|
|
68948
|
+
prefix += `var ${resolvedName} = require("${path91}");`;
|
|
69064
68949
|
}
|
|
69065
68950
|
} else {
|
|
69066
68951
|
const { createElement: createElementResolution, ...otherResolutions } = this.esmAutomaticImportNameResolutions;
|
|
@@ -69253,11 +69138,11 @@ var require_JSXTransformer = __commonJS({
|
|
|
69253
69138
|
}
|
|
69254
69139
|
claimAutoImportedName(funcName, importPathSuffix) {
|
|
69255
69140
|
if (this.importProcessor) {
|
|
69256
|
-
const
|
|
69257
|
-
if (!this.cjsAutomaticModuleNameResolutions[
|
|
69258
|
-
this.cjsAutomaticModuleNameResolutions[
|
|
69141
|
+
const path91 = this.jsxImportSource + importPathSuffix;
|
|
69142
|
+
if (!this.cjsAutomaticModuleNameResolutions[path91]) {
|
|
69143
|
+
this.cjsAutomaticModuleNameResolutions[path91] = this.importProcessor.getFreeIdentifierForPath(path91);
|
|
69259
69144
|
}
|
|
69260
|
-
return `${this.cjsAutomaticModuleNameResolutions[
|
|
69145
|
+
return `${this.cjsAutomaticModuleNameResolutions[path91]}.${funcName}`;
|
|
69261
69146
|
} else {
|
|
69262
69147
|
if (!this.esmAutomaticImportNameResolutions[funcName]) {
|
|
69263
69148
|
this.esmAutomaticImportNameResolutions[funcName] = this.nameManager.claimFreeName(
|
|
@@ -69693,7 +69578,7 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69693
69578
|
*/
|
|
69694
69579
|
pruneTypeOnlyImports() {
|
|
69695
69580
|
this.nonTypeIdentifiers = _getNonTypeIdentifiers.getNonTypeIdentifiers.call(void 0, this.tokens, this.options);
|
|
69696
|
-
for (const [
|
|
69581
|
+
for (const [path91, importInfo] of this.importInfoByPath.entries()) {
|
|
69697
69582
|
if (importInfo.hasBareImport || importInfo.hasStarExport || importInfo.exportStarNames.length > 0 || importInfo.namedExports.length > 0) {
|
|
69698
69583
|
continue;
|
|
69699
69584
|
}
|
|
@@ -69703,7 +69588,7 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69703
69588
|
...importInfo.namedImports.map(({ localName }) => localName)
|
|
69704
69589
|
];
|
|
69705
69590
|
if (names3.every((name) => this.shouldAutomaticallyElideImportedName(name))) {
|
|
69706
|
-
this.importsToReplace.set(
|
|
69591
|
+
this.importsToReplace.set(path91, "");
|
|
69707
69592
|
}
|
|
69708
69593
|
}
|
|
69709
69594
|
}
|
|
@@ -69711,7 +69596,7 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69711
69596
|
return this.isTypeScriptTransformEnabled && !this.keepUnusedImports && !this.nonTypeIdentifiers.has(name);
|
|
69712
69597
|
}
|
|
69713
69598
|
generateImportReplacements() {
|
|
69714
|
-
for (const [
|
|
69599
|
+
for (const [path91, importInfo] of this.importInfoByPath.entries()) {
|
|
69715
69600
|
const {
|
|
69716
69601
|
defaultNames,
|
|
69717
69602
|
wildcardNames,
|
|
@@ -69721,17 +69606,17 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69721
69606
|
hasStarExport
|
|
69722
69607
|
} = importInfo;
|
|
69723
69608
|
if (defaultNames.length === 0 && wildcardNames.length === 0 && namedImports.length === 0 && namedExports.length === 0 && exportStarNames.length === 0 && !hasStarExport) {
|
|
69724
|
-
this.importsToReplace.set(
|
|
69609
|
+
this.importsToReplace.set(path91, `require('${path91}');`);
|
|
69725
69610
|
continue;
|
|
69726
69611
|
}
|
|
69727
|
-
const primaryImportName = this.getFreeIdentifierForPath(
|
|
69612
|
+
const primaryImportName = this.getFreeIdentifierForPath(path91);
|
|
69728
69613
|
let secondaryImportName;
|
|
69729
69614
|
if (this.enableLegacyTypeScriptModuleInterop) {
|
|
69730
69615
|
secondaryImportName = primaryImportName;
|
|
69731
69616
|
} else {
|
|
69732
|
-
secondaryImportName = wildcardNames.length > 0 ? wildcardNames[0] : this.getFreeIdentifierForPath(
|
|
69617
|
+
secondaryImportName = wildcardNames.length > 0 ? wildcardNames[0] : this.getFreeIdentifierForPath(path91);
|
|
69733
69618
|
}
|
|
69734
|
-
let requireCode = `var ${primaryImportName} = require('${
|
|
69619
|
+
let requireCode = `var ${primaryImportName} = require('${path91}');`;
|
|
69735
69620
|
if (wildcardNames.length > 0) {
|
|
69736
69621
|
for (const wildcardName of wildcardNames) {
|
|
69737
69622
|
const moduleExpr = this.enableLegacyTypeScriptModuleInterop ? primaryImportName : `${this.helperManager.getHelperName("interopRequireWildcard")}(${primaryImportName})`;
|
|
@@ -69759,7 +69644,7 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69759
69644
|
"createStarExport"
|
|
69760
69645
|
)}(${primaryImportName});`;
|
|
69761
69646
|
}
|
|
69762
|
-
this.importsToReplace.set(
|
|
69647
|
+
this.importsToReplace.set(path91, requireCode);
|
|
69763
69648
|
for (const defaultName of defaultNames) {
|
|
69764
69649
|
this.identifierReplacements.set(defaultName, `${secondaryImportName}.default`);
|
|
69765
69650
|
}
|
|
@@ -69768,8 +69653,8 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69768
69653
|
}
|
|
69769
69654
|
}
|
|
69770
69655
|
}
|
|
69771
|
-
getFreeIdentifierForPath(
|
|
69772
|
-
const components =
|
|
69656
|
+
getFreeIdentifierForPath(path91) {
|
|
69657
|
+
const components = path91.split("/");
|
|
69773
69658
|
const lastComponent = components[components.length - 1];
|
|
69774
69659
|
const baseName = lastComponent.replace(/\W/g, "");
|
|
69775
69660
|
return this.nameManager.claimFreeName(`_${baseName}`);
|
|
@@ -69814,8 +69699,8 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69814
69699
|
if (!this.tokens.matches1AtIndex(index, _types.TokenType.string)) {
|
|
69815
69700
|
throw new Error("Expected string token at the end of import statement.");
|
|
69816
69701
|
}
|
|
69817
|
-
const
|
|
69818
|
-
const importInfo = this.getImportInfo(
|
|
69702
|
+
const path91 = this.tokens.stringValueAtIndex(index);
|
|
69703
|
+
const importInfo = this.getImportInfo(path91);
|
|
69819
69704
|
importInfo.defaultNames.push(...defaultNames);
|
|
69820
69705
|
importInfo.wildcardNames.push(...wildcardNames);
|
|
69821
69706
|
importInfo.namedImports.push(...namedImports);
|
|
@@ -69882,8 +69767,8 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69882
69767
|
if (!this.tokens.matches1AtIndex(index, _types.TokenType.string)) {
|
|
69883
69768
|
throw new Error("Expected string token at the end of import statement.");
|
|
69884
69769
|
}
|
|
69885
|
-
const
|
|
69886
|
-
const importInfo = this.getImportInfo(
|
|
69770
|
+
const path91 = this.tokens.stringValueAtIndex(index);
|
|
69771
|
+
const importInfo = this.getImportInfo(path91);
|
|
69887
69772
|
importInfo.namedExports.push(...namedImports);
|
|
69888
69773
|
}
|
|
69889
69774
|
preprocessExportStarAtIndex(index) {
|
|
@@ -69898,8 +69783,8 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69898
69783
|
if (!this.tokens.matches1AtIndex(index, _types.TokenType.string)) {
|
|
69899
69784
|
throw new Error("Expected string token at the end of star export statement.");
|
|
69900
69785
|
}
|
|
69901
|
-
const
|
|
69902
|
-
const importInfo = this.getImportInfo(
|
|
69786
|
+
const path91 = this.tokens.stringValueAtIndex(index);
|
|
69787
|
+
const importInfo = this.getImportInfo(path91);
|
|
69903
69788
|
if (exportedName !== null) {
|
|
69904
69789
|
importInfo.exportStarNames.push(exportedName);
|
|
69905
69790
|
} else {
|
|
@@ -69939,8 +69824,8 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69939
69824
|
* Get a mutable import info object for this path, creating one if it doesn't
|
|
69940
69825
|
* exist yet.
|
|
69941
69826
|
*/
|
|
69942
|
-
getImportInfo(
|
|
69943
|
-
const existingInfo = this.importInfoByPath.get(
|
|
69827
|
+
getImportInfo(path91) {
|
|
69828
|
+
const existingInfo = this.importInfoByPath.get(path91);
|
|
69944
69829
|
if (existingInfo) {
|
|
69945
69830
|
return existingInfo;
|
|
69946
69831
|
}
|
|
@@ -69953,7 +69838,7 @@ var require_CJSImportProcessor = __commonJS({
|
|
|
69953
69838
|
exportStarNames: [],
|
|
69954
69839
|
hasStarExport: false
|
|
69955
69840
|
};
|
|
69956
|
-
this.importInfoByPath.set(
|
|
69841
|
+
this.importInfoByPath.set(path91, newInfo);
|
|
69957
69842
|
return newInfo;
|
|
69958
69843
|
}
|
|
69959
69844
|
addExportBinding(localName, exportedName) {
|
|
@@ -70533,16 +70418,16 @@ var require_resolve_uri_umd = __commonJS({
|
|
|
70533
70418
|
}
|
|
70534
70419
|
function parseFileUrl(input) {
|
|
70535
70420
|
const match = fileRegex.exec(input);
|
|
70536
|
-
const
|
|
70537
|
-
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(
|
|
70421
|
+
const path91 = match[2];
|
|
70422
|
+
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path91) ? path91 : "/" + path91, match[3] || "", match[4] || "");
|
|
70538
70423
|
}
|
|
70539
|
-
function makeUrl(scheme, user, host2, port,
|
|
70424
|
+
function makeUrl(scheme, user, host2, port, path91, query, hash2) {
|
|
70540
70425
|
return {
|
|
70541
70426
|
scheme,
|
|
70542
70427
|
user,
|
|
70543
70428
|
host: host2,
|
|
70544
70429
|
port,
|
|
70545
|
-
path:
|
|
70430
|
+
path: path91,
|
|
70546
70431
|
query,
|
|
70547
70432
|
hash: hash2,
|
|
70548
70433
|
type: 7
|
|
@@ -70572,11 +70457,11 @@ var require_resolve_uri_umd = __commonJS({
|
|
|
70572
70457
|
url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
|
|
70573
70458
|
return url;
|
|
70574
70459
|
}
|
|
70575
|
-
function stripPathFilename(
|
|
70576
|
-
if (
|
|
70577
|
-
return
|
|
70578
|
-
const index =
|
|
70579
|
-
return
|
|
70460
|
+
function stripPathFilename(path91) {
|
|
70461
|
+
if (path91.endsWith("/.."))
|
|
70462
|
+
return path91;
|
|
70463
|
+
const index = path91.lastIndexOf("/");
|
|
70464
|
+
return path91.slice(0, index + 1);
|
|
70580
70465
|
}
|
|
70581
70466
|
function mergePaths(url, base) {
|
|
70582
70467
|
normalizePath(base, base.type);
|
|
@@ -70614,14 +70499,14 @@ var require_resolve_uri_umd = __commonJS({
|
|
|
70614
70499
|
pieces[pointer++] = piece;
|
|
70615
70500
|
positive++;
|
|
70616
70501
|
}
|
|
70617
|
-
let
|
|
70502
|
+
let path91 = "";
|
|
70618
70503
|
for (let i = 1; i < pointer; i++) {
|
|
70619
|
-
|
|
70504
|
+
path91 += "/" + pieces[i];
|
|
70620
70505
|
}
|
|
70621
|
-
if (!
|
|
70622
|
-
|
|
70506
|
+
if (!path91 || addTrailingSlash && !path91.endsWith("/..")) {
|
|
70507
|
+
path91 += "/";
|
|
70623
70508
|
}
|
|
70624
|
-
url.path =
|
|
70509
|
+
url.path = path91;
|
|
70625
70510
|
}
|
|
70626
70511
|
function resolve2(input, base) {
|
|
70627
70512
|
if (!input && !base)
|
|
@@ -70662,13 +70547,13 @@ var require_resolve_uri_umd = __commonJS({
|
|
|
70662
70547
|
case 3:
|
|
70663
70548
|
return queryHash;
|
|
70664
70549
|
case 4: {
|
|
70665
|
-
const
|
|
70666
|
-
if (!
|
|
70550
|
+
const path91 = url.path.slice(1);
|
|
70551
|
+
if (!path91)
|
|
70667
70552
|
return queryHash || ".";
|
|
70668
|
-
if (isRelative(base || input) && !isRelative(
|
|
70669
|
-
return "./" +
|
|
70553
|
+
if (isRelative(base || input) && !isRelative(path91)) {
|
|
70554
|
+
return "./" + path91 + queryHash;
|
|
70670
70555
|
}
|
|
70671
|
-
return
|
|
70556
|
+
return path91 + queryHash;
|
|
70672
70557
|
}
|
|
70673
70558
|
case 5:
|
|
70674
70559
|
return url.path + queryHash;
|
|
@@ -70767,10 +70652,10 @@ var require_trace_mapping_umd = __commonJS({
|
|
|
70767
70652
|
module2.exports = __toCommonJS(trace_mapping_exports);
|
|
70768
70653
|
var import_sourcemap_codec = __toESM2(require_sourcemap_codec());
|
|
70769
70654
|
var import_resolve_uri = __toESM2(require_resolve_uri());
|
|
70770
|
-
function stripFilename(
|
|
70771
|
-
if (!
|
|
70772
|
-
const index =
|
|
70773
|
-
return
|
|
70655
|
+
function stripFilename(path91) {
|
|
70656
|
+
if (!path91) return "";
|
|
70657
|
+
const index = path91.lastIndexOf("/");
|
|
70658
|
+
return path91.slice(0, index + 1);
|
|
70774
70659
|
}
|
|
70775
70660
|
function resolver2(mapUrl, sourceRoot) {
|
|
70776
70661
|
const from = stripFilename(mapUrl);
|
|
@@ -71978,9 +71863,9 @@ var require_util2 = __commonJS({
|
|
|
71978
71863
|
/** @class */
|
|
71979
71864
|
(function(_super) {
|
|
71980
71865
|
__extends(VError2, _super);
|
|
71981
|
-
function VError2(
|
|
71866
|
+
function VError2(path91, message) {
|
|
71982
71867
|
var _this = _super.call(this, message) || this;
|
|
71983
|
-
_this.path =
|
|
71868
|
+
_this.path = path91;
|
|
71984
71869
|
Object.setPrototypeOf(_this, VError2.prototype);
|
|
71985
71870
|
return _this;
|
|
71986
71871
|
}
|
|
@@ -72040,26 +71925,26 @@ var require_util2 = __commonJS({
|
|
|
72040
71925
|
(_b = this._messages).push.apply(_b, best._messages);
|
|
72041
71926
|
}
|
|
72042
71927
|
};
|
|
72043
|
-
DetailContext2.prototype.getError = function(
|
|
71928
|
+
DetailContext2.prototype.getError = function(path91) {
|
|
72044
71929
|
var msgParts = [];
|
|
72045
71930
|
for (var i = this._propNames.length - 1; i >= 0; i--) {
|
|
72046
71931
|
var p2 = this._propNames[i];
|
|
72047
|
-
|
|
71932
|
+
path91 += typeof p2 === "number" ? "[" + p2 + "]" : p2 ? "." + p2 : "";
|
|
72048
71933
|
var m = this._messages[i];
|
|
72049
71934
|
if (m) {
|
|
72050
|
-
msgParts.push(
|
|
71935
|
+
msgParts.push(path91 + " " + m);
|
|
72051
71936
|
}
|
|
72052
71937
|
}
|
|
72053
|
-
return new VError(
|
|
71938
|
+
return new VError(path91, msgParts.join("; "));
|
|
72054
71939
|
};
|
|
72055
|
-
DetailContext2.prototype.getErrorDetail = function(
|
|
71940
|
+
DetailContext2.prototype.getErrorDetail = function(path91) {
|
|
72056
71941
|
var details = [];
|
|
72057
71942
|
for (var i = this._propNames.length - 1; i >= 0; i--) {
|
|
72058
71943
|
var p2 = this._propNames[i];
|
|
72059
|
-
|
|
71944
|
+
path91 += typeof p2 === "number" ? "[" + p2 + "]" : p2 ? "." + p2 : "";
|
|
72060
71945
|
var message = this._messages[i];
|
|
72061
71946
|
if (message) {
|
|
72062
|
-
details.push({ path:
|
|
71947
|
+
details.push({ path: path91, message });
|
|
72063
71948
|
}
|
|
72064
71949
|
}
|
|
72065
71950
|
var detail = null;
|
|
@@ -72872,8 +72757,8 @@ var require_dist = __commonJS({
|
|
|
72872
72757
|
this.checkerPlain = this.ttype.getChecker(suite, false);
|
|
72873
72758
|
this.checkerStrict = this.ttype.getChecker(suite, true);
|
|
72874
72759
|
}
|
|
72875
|
-
Checker2.prototype.setReportedPath = function(
|
|
72876
|
-
this._path =
|
|
72760
|
+
Checker2.prototype.setReportedPath = function(path91) {
|
|
72761
|
+
this._path = path91;
|
|
72877
72762
|
};
|
|
72878
72763
|
Checker2.prototype.check = function(value) {
|
|
72879
72764
|
return this._doCheck(this.checkerPlain, value);
|
|
@@ -78306,9 +78191,9 @@ var require_CJSImportTransformer = __commonJS({
|
|
|
78306
78191
|
if (shouldElideImport) {
|
|
78307
78192
|
this.tokens.removeToken();
|
|
78308
78193
|
} else {
|
|
78309
|
-
const
|
|
78310
|
-
this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(
|
|
78311
|
-
this.tokens.appendCode(this.importProcessor.claimImportCode(
|
|
78194
|
+
const path91 = this.tokens.stringValue();
|
|
78195
|
+
this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path91));
|
|
78196
|
+
this.tokens.appendCode(this.importProcessor.claimImportCode(path91));
|
|
78312
78197
|
}
|
|
78313
78198
|
_removeMaybeImportAttributes.removeMaybeImportAttributes.call(void 0, this.tokens);
|
|
78314
78199
|
if (this.tokens.matches1(_types.TokenType.semi)) {
|
|
@@ -78888,8 +78773,8 @@ var require_CJSImportTransformer = __commonJS({
|
|
|
78888
78773
|
}
|
|
78889
78774
|
if (this.tokens.matchesContextual(_keywords.ContextualKeyword._from)) {
|
|
78890
78775
|
this.tokens.removeToken();
|
|
78891
|
-
const
|
|
78892
|
-
this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(
|
|
78776
|
+
const path91 = this.tokens.stringValue();
|
|
78777
|
+
this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path91));
|
|
78893
78778
|
_removeMaybeImportAttributes.removeMaybeImportAttributes.call(void 0, this.tokens);
|
|
78894
78779
|
} else {
|
|
78895
78780
|
this.tokens.appendCode(exportStatements.join(" "));
|
|
@@ -78903,8 +78788,8 @@ var require_CJSImportTransformer = __commonJS({
|
|
|
78903
78788
|
while (!this.tokens.matches1(_types.TokenType.string)) {
|
|
78904
78789
|
this.tokens.removeToken();
|
|
78905
78790
|
}
|
|
78906
|
-
const
|
|
78907
|
-
this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(
|
|
78791
|
+
const path91 = this.tokens.stringValue();
|
|
78792
|
+
this.tokens.replaceTokenTrimmingLeftWhitespace(this.importProcessor.claimImportCode(path91));
|
|
78908
78793
|
_removeMaybeImportAttributes.removeMaybeImportAttributes.call(void 0, this.tokens);
|
|
78909
78794
|
if (this.tokens.matches1(_types.TokenType.semi)) {
|
|
78910
78795
|
this.tokens.removeToken();
|
|
@@ -108758,9 +108643,9 @@ var init_bundle_mjs = __esm({
|
|
|
108758
108643
|
processClassesRecursively(value, getPart(classPartObject, key), classGroupId, theme);
|
|
108759
108644
|
}
|
|
108760
108645
|
};
|
|
108761
|
-
getPart = (classPartObject,
|
|
108646
|
+
getPart = (classPartObject, path91) => {
|
|
108762
108647
|
let current = classPartObject;
|
|
108763
|
-
const parts =
|
|
108648
|
+
const parts = path91.split(CLASS_PART_SEPARATOR);
|
|
108764
108649
|
const len = parts.length;
|
|
108765
108650
|
for (let i = 0; i < len; i++) {
|
|
108766
108651
|
const part = parts[i];
|
|
@@ -112010,8 +111895,8 @@ var init_dist = __esm({
|
|
|
112010
111895
|
});
|
|
112011
111896
|
|
|
112012
111897
|
// src/lib/draw-mockup.ts
|
|
112013
|
-
import
|
|
112014
|
-
import
|
|
111898
|
+
import fs88 from "node:fs";
|
|
111899
|
+
import path87 from "node:path";
|
|
112015
111900
|
import vm from "node:vm";
|
|
112016
111901
|
async function loadPackage(id) {
|
|
112017
111902
|
if (id === "react") return import_react3.default;
|
|
@@ -112024,23 +111909,23 @@ async function loadPackage(id) {
|
|
|
112024
111909
|
return { __esModule: true, ...await load() };
|
|
112025
111910
|
}
|
|
112026
111911
|
function resolveFile(id, from, folder) {
|
|
112027
|
-
const at2 =
|
|
112028
|
-
if (at2 !== folder && !at2.startsWith(folder +
|
|
112029
|
-
const tries =
|
|
112030
|
-
const file2 = tries.find((f2) =>
|
|
111912
|
+
const at2 = path87.resolve(path87.dirname(from), id);
|
|
111913
|
+
if (at2 !== folder && !at2.startsWith(folder + path87.sep)) throw new Error(`${id} is outside the mockup's folder`);
|
|
111914
|
+
const tries = path87.extname(at2) ? [at2] : [...CODE_EXTS.map((e2) => at2 + e2), ...CODE_EXTS.map((e2) => path87.join(at2, `index${e2}`))];
|
|
111915
|
+
const file2 = tries.find((f2) => fs88.statSync(f2, { throwIfNoEntry: false })?.isFile());
|
|
112031
111916
|
if (!file2) throw new Error(`no such file: ${id}`);
|
|
112032
|
-
if (!
|
|
111917
|
+
if (!fs88.realpathSync(file2).startsWith(fs88.realpathSync(folder) + path87.sep)) throw new Error(`${id} is outside the mockup's folder`);
|
|
112033
111918
|
return file2;
|
|
112034
111919
|
}
|
|
112035
111920
|
async function readGraph(entry) {
|
|
112036
|
-
const folder =
|
|
111921
|
+
const folder = path87.dirname(entry);
|
|
112037
111922
|
const graph = { code: /* @__PURE__ */ new Map(), links: /* @__PURE__ */ new Map(), sheets: [], packages: /* @__PURE__ */ new Map() };
|
|
112038
111923
|
const walk3 = async (file2) => {
|
|
112039
111924
|
if (graph.code.has(file2)) return;
|
|
112040
111925
|
if (graph.code.size >= MAX_FILES) throw new Error(`a mockup imports more than ${MAX_FILES} files`);
|
|
112041
111926
|
let location = file2;
|
|
112042
111927
|
try {
|
|
112043
|
-
const js = (0, import_sucrase.transform)(
|
|
111928
|
+
const js = (0, import_sucrase.transform)(fs88.readFileSync(file2, "utf8"), { transforms: ["typescript", "jsx", "imports"], jsxRuntime: "automatic", production: true, filePath: file2 }).code;
|
|
112044
111929
|
graph.code.set(file2, js);
|
|
112045
111930
|
const link2 = /* @__PURE__ */ new Map();
|
|
112046
111931
|
graph.links.set(file2, link2);
|
|
@@ -112054,7 +111939,7 @@ async function readGraph(entry) {
|
|
|
112054
111939
|
const target = resolveFile(id, file2, folder);
|
|
112055
111940
|
link2.set(id, target);
|
|
112056
111941
|
if (!target.endsWith(".css")) await walk3(target);
|
|
112057
|
-
else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content:
|
|
111942
|
+
else if (!graph.sheets.some((s) => s.path === target)) graph.sheets.push({ path: target, content: fs88.readFileSync(target, "utf8") });
|
|
112058
111943
|
}
|
|
112059
111944
|
} catch (error) {
|
|
112060
111945
|
throw new Error(`${location}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -112071,13 +111956,13 @@ function run2(script, context, name, deadline, lineOffset = 0) {
|
|
|
112071
111956
|
async function tailwindFor(markup, sheets, folder) {
|
|
112072
111957
|
const source2 = sheets.length ? sheets.map((s) => s.content).join("\n") : '@import "tailwindcss";';
|
|
112073
111958
|
const compiler = await rc(source2, {
|
|
112074
|
-
base: sheets.length ?
|
|
111959
|
+
base: sheets.length ? path87.dirname(sheets[0].path) : "/",
|
|
112075
111960
|
loadStylesheet: async (id, from) => {
|
|
112076
111961
|
if (id === "tailwindcss" || id.startsWith("tailwindcss/")) return { path: "tailwindcss/index.css", base: "/", content: tailwindcss_default };
|
|
112077
111962
|
if (!id.startsWith(".")) throw new Error(`a mockup cannot import ${id}`);
|
|
112078
|
-
const at2 =
|
|
112079
|
-
if (!
|
|
112080
|
-
return { path: at2, base:
|
|
111963
|
+
const at2 = path87.resolve(from, id);
|
|
111964
|
+
if (!fs88.realpathSync(at2).startsWith(fs88.realpathSync(folder) + path87.sep)) throw new Error(`${id} is outside the mockup's folder`);
|
|
111965
|
+
return { path: at2, base: path87.dirname(at2), content: fs88.readFileSync(at2, "utf8") };
|
|
112081
111966
|
}
|
|
112082
111967
|
});
|
|
112083
111968
|
const classes = [...markup.matchAll(/class="([^"]*)"/g)].flatMap((m) => m[1].split(/\s+/));
|
|
@@ -112126,7 +112011,7 @@ ${graph.code.get(file2)}
|
|
|
112126
112011
|
if (typeof Component !== "function") throw new Error("the mockup has no default export to draw");
|
|
112127
112012
|
sandbox.__draw = () => (0, import_server.renderToStaticMarkup)(import_react3.default.createElement(Component));
|
|
112128
112013
|
const markup = run2("__draw()", context, entry, deadline);
|
|
112129
|
-
const css = (await tailwindFor(markup, graph.sheets,
|
|
112014
|
+
const css = (await tailwindFor(markup, graph.sheets, path87.dirname(entry))).replace(/<\/style/gi, "<\\/style");
|
|
112130
112015
|
return `<!doctype html><html><head>${head}<style>${css}</style></head><body>${markup}</body></html>`;
|
|
112131
112016
|
}
|
|
112132
112017
|
var import_react3, JSX, import_server, import_sucrase, DRAW_MS, MAX_FILES, CODE_EXTS, REQUIRES, NOTHING, NEXT_LINK, NEXT_IMAGE, NEXT_NAVIGATION, PACKAGES, MOCKUP_IMPORTS;
|
|
@@ -112187,21 +112072,21 @@ var init_draw_mockup = __esm({
|
|
|
112187
112072
|
});
|
|
112188
112073
|
|
|
112189
112074
|
// src/commands/studio-preview.ts
|
|
112190
|
-
import
|
|
112191
|
-
import
|
|
112075
|
+
import fs89 from "node:fs";
|
|
112076
|
+
import path88 from "node:path";
|
|
112192
112077
|
import { createHash as createHash10, randomUUID as randomUUID8 } from "node:crypto";
|
|
112193
112078
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
112194
112079
|
function readFolder2(folder) {
|
|
112195
|
-
const root2 =
|
|
112080
|
+
const root2 = fs89.realpathSync(folder);
|
|
112196
112081
|
let count3 = 0, total = 0;
|
|
112197
112082
|
const scan = (dir) => {
|
|
112198
|
-
for (const e2 of
|
|
112083
|
+
for (const e2 of fs89.readdirSync(dir, { withFileTypes: true })) {
|
|
112199
112084
|
if (e2.name.startsWith(".")) continue;
|
|
112200
|
-
const file2 =
|
|
112085
|
+
const file2 = path88.join(dir, e2.name);
|
|
112201
112086
|
if (e2.isSymbolicLink()) throw Error(`${file2}: symbolic links are not allowed`);
|
|
112202
112087
|
if (e2.isDirectory()) scan(file2);
|
|
112203
112088
|
else {
|
|
112204
|
-
const size =
|
|
112089
|
+
const size = fs89.statSync(file2).size;
|
|
112205
112090
|
total += size;
|
|
112206
112091
|
if (++count3 > FILE_LIMITS.count || size > FILE_LIMITS.file || total > FILE_LIMITS.total) throw Error(`${file2}: Studio file limit exceeded`);
|
|
112207
112092
|
}
|
|
@@ -112223,9 +112108,9 @@ function agentsOf2(held4) {
|
|
|
112223
112108
|
});
|
|
112224
112109
|
}
|
|
112225
112110
|
function unified(before, after2, file2, folder) {
|
|
112226
|
-
const a2 =
|
|
112227
|
-
|
|
112228
|
-
|
|
112111
|
+
const a2 = path88.join(folder, "a"), b2 = path88.join(folder, "b");
|
|
112112
|
+
fs89.writeFileSync(a2, before ?? "");
|
|
112113
|
+
fs89.writeFileSync(b2, after2 ?? "");
|
|
112229
112114
|
const result = spawnSync6("git", ["diff", "--no-index", "--text", "--no-ext-diff", "--no-color", "--unified=3", before === null ? "/dev/null" : a2, after2 === null ? "/dev/null" : b2], { encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
|
|
112230
112115
|
if (result.error || result.status !== 0 && result.status !== 1) throw Error(`${file2}: ${result.error?.message ?? result.stderr}`);
|
|
112231
112116
|
const lines = result.stdout.split("\n"), start = lines.findIndex((l2) => l2.startsWith("--- "));
|
|
@@ -112235,20 +112120,20 @@ ${start < 0 ? "" : lines.slice(start + 2).join("\n")}`;
|
|
|
112235
112120
|
}
|
|
112236
112121
|
async function cmdStudioPreview(id, opts) {
|
|
112237
112122
|
if (!locate(id)) die(`no card ${id}`, "no-such-card");
|
|
112238
|
-
const destination =
|
|
112123
|
+
const destination = path88.join(ASSETS, String(id), "studio-review"), staging = `${destination}.${randomUUID8()}.tmp`, backup = `${destination}.${randomUUID8()}.previous`;
|
|
112239
112124
|
let moved = false;
|
|
112240
112125
|
try {
|
|
112241
|
-
const draft = readFolder2(
|
|
112126
|
+
const draft = readFolder2(path88.resolve(opts.folder)), base = opts.base === "empty" ? null : readFolder2(path88.resolve(opts.base));
|
|
112242
112127
|
const version = readVersion2(draft.files), baseVersion = base && readVersion2(base.files);
|
|
112243
112128
|
if (base ? !version || !baseVersion || JSON.stringify(version) !== JSON.stringify(baseVersion) : version !== null) throw Error("version.json: existing Studios need matching baseline and draft versions; use --base empty only for a new Studio without version.json");
|
|
112244
112129
|
const agents = [...agentsOf2(draft)];
|
|
112245
112130
|
for (const a2 of base ? agentsOf2(base) : []) if (!agents.some((b2) => b2.agent === a2.agent)) agents.push(a2);
|
|
112246
|
-
|
|
112131
|
+
fs89.mkdirSync(staging, { recursive: true });
|
|
112247
112132
|
const review = { version: 2, base: base && baseVersion ? { ...baseVersion, fingerprint: base.fingerprint } : null, fingerprint: draft.fingerprint, agents, files: [], results: [] };
|
|
112248
112133
|
const save3 = (file2, bytes2) => {
|
|
112249
|
-
const target =
|
|
112250
|
-
|
|
112251
|
-
|
|
112134
|
+
const target = path88.join(staging, file2);
|
|
112135
|
+
fs89.mkdirSync(path88.dirname(target), { recursive: true });
|
|
112136
|
+
fs89.writeFileSync(target, bytes2);
|
|
112252
112137
|
return file2;
|
|
112253
112138
|
};
|
|
112254
112139
|
const paths = [.../* @__PURE__ */ new Set([...Object.keys(base?.files ?? {}), ...Object.keys(draft.files)])].filter((p2) => p2 !== VERSION_FILE).sort();
|
|
@@ -112256,30 +112141,30 @@ async function cmdStudioPreview(id, opts) {
|
|
|
112256
112141
|
const before = base?.files[file2] ?? null, after2 = draft.files[file2] ?? null;
|
|
112257
112142
|
review.files.push({ path: file2, before: before === null ? null : save3(`files/${i}/before.txt`, before), after: after2 === null ? null : save3(`files/${i}/after.txt`, after2), ...before !== after2 ? { diff: save3(`files/${i}/change.diff`, unified(before, after2, file2, staging)) } : {} });
|
|
112258
112143
|
}
|
|
112259
|
-
for (const p2 of ["a", "b"])
|
|
112144
|
+
for (const p2 of ["a", "b"]) fs89.rmSync(path88.join(staging, p2), { force: true });
|
|
112260
112145
|
if (opts.results) {
|
|
112261
|
-
const manifest =
|
|
112262
|
-
const results = JSON.parse(
|
|
112146
|
+
const manifest = fs89.realpathSync(opts.results), root2 = path88.dirname(manifest);
|
|
112147
|
+
const results = JSON.parse(fs89.readFileSync(manifest, "utf8")), bad = resultProblem(results, new Set(agents.map((a2) => a2.agent)));
|
|
112263
112148
|
if (bad) throw Error(`${opts.results}: invalid ${bad}`);
|
|
112264
112149
|
const rendered = /* @__PURE__ */ new Map();
|
|
112265
112150
|
const textOf = (file2) => {
|
|
112266
|
-
const raw = rendered.get(file2) ??
|
|
112151
|
+
const raw = rendered.get(file2) ?? fs89.readFileSync(file2, "utf8");
|
|
112267
112152
|
if (/\.(html|tsx)$/i.test(file2)) for (const ref of referencesOf(manifestOf("html"), raw, true)) {
|
|
112268
112153
|
if (/^(?:data:|#)/i.test(ref.src)) continue;
|
|
112269
112154
|
if (/^(?:[a-z][\w+.-]*:|\/)/i.test(ref.src)) throw Error(`${file2}: external result dependency ${ref.src}`);
|
|
112270
|
-
const target =
|
|
112271
|
-
if (!within(root2, target) ||
|
|
112155
|
+
const target = path88.resolve(path88.dirname(file2), ref.src.replace(/[?#].*$/, ""));
|
|
112156
|
+
if (!within(root2, target) || fs89.existsSync(target) && !within(root2, fs89.realpathSync(target))) throw Error(`${file2}: outside result folder: ${ref.src}`);
|
|
112272
112157
|
}
|
|
112273
112158
|
return rendered.get(file2) ?? referenceText(file2);
|
|
112274
112159
|
};
|
|
112275
112160
|
const collectResults = () => collectSources(referencesOf(manifestOf("studio"), { results }), manifest, {
|
|
112276
112161
|
resolve: (src, owner) => {
|
|
112277
112162
|
if (/^(?:[a-z][\w+.-]*:|\/|#)/i.test(src)) throw Error(`${src}: only local result files are allowed`);
|
|
112278
|
-
const target =
|
|
112163
|
+
const target = path88.resolve(path88.dirname(owner), src);
|
|
112279
112164
|
if (!within(root2, target)) throw Error(`${src}: outside result folder`);
|
|
112280
|
-
const real2 =
|
|
112281
|
-
if (!within(root2, real2) || !
|
|
112282
|
-
if (
|
|
112165
|
+
const real2 = fs89.realpathSync(target);
|
|
112166
|
+
if (!within(root2, real2) || !fs89.statSync(real2).isFile()) throw Error(`${src}: outside result folder or not a file`);
|
|
112167
|
+
if (fs89.statSync(real2).size > ASSET_FILE_LIMIT) throw Error(`${src}: over 100 MiB`);
|
|
112283
112168
|
return { key: real2, file: real2 };
|
|
112284
112169
|
},
|
|
112285
112170
|
read: textOf,
|
|
@@ -112295,33 +112180,33 @@ async function cmdStudioPreview(id, opts) {
|
|
|
112295
112180
|
}
|
|
112296
112181
|
if (graph.length > 2e3) throw Error(`${opts.results}: too many result dependencies`);
|
|
112297
112182
|
for (const node of graph) if (node.error || node.problems.length) throw Error(`${node.file}: ${node.error ?? node.problems[0].message}`);
|
|
112298
|
-
const names3 = new Map(graph.map((n, i) => [n.key, `results/${i}${rendered.has(n.file) ? ".html" :
|
|
112299
|
-
const resolve2 = (src, owner) => names3.get(
|
|
112183
|
+
const names3 = new Map(graph.map((n, i) => [n.key, `results/${i}${rendered.has(n.file) ? ".html" : path88.extname(n.file)}`]));
|
|
112184
|
+
const resolve2 = (src, owner) => names3.get(fs89.realpathSync(path88.resolve(path88.dirname(owner), src.replace(/[?#].*$/, ""))));
|
|
112300
112185
|
for (const node of graph) {
|
|
112301
112186
|
const own = names3.get(node.key);
|
|
112302
|
-
const content = node.data === void 0 ?
|
|
112187
|
+
const content = node.data === void 0 ? fs89.readFileSync(node.file) : mapReferences(manifestOf(node.kind), node.data, (src) => path88.posix.relative(path88.posix.dirname(own), resolve2(src, node.file)));
|
|
112303
112188
|
save3(own, typeof content === "string" || Buffer.isBuffer(content) ? content : JSON.stringify(content));
|
|
112304
112189
|
}
|
|
112305
112190
|
review.results = mapReferences(manifestOf("studio"), { results }, (src) => resolve2(src, manifest)).results;
|
|
112306
112191
|
}
|
|
112307
112192
|
if (!parseReview(review)) throw Error("generated review is invalid");
|
|
112308
112193
|
save3("review.json", JSON.stringify(review, null, 2) + "\n");
|
|
112309
|
-
|
|
112310
|
-
if (
|
|
112311
|
-
|
|
112194
|
+
fs89.mkdirSync(path88.dirname(destination), { recursive: true });
|
|
112195
|
+
if (fs89.existsSync(destination)) {
|
|
112196
|
+
fs89.renameSync(destination, backup);
|
|
112312
112197
|
moved = true;
|
|
112313
112198
|
}
|
|
112314
|
-
|
|
112315
|
-
|
|
112199
|
+
fs89.renameSync(staging, destination);
|
|
112200
|
+
fs89.rmSync(backup, { recursive: true, force: true });
|
|
112316
112201
|
const tag = `<Studio src=".assets/${id}/studio-review/review.json" />`;
|
|
112317
112202
|
say(tag);
|
|
112318
|
-
return { file:
|
|
112203
|
+
return { file: path88.join(destination, "review.json"), tag };
|
|
112319
112204
|
} catch (error) {
|
|
112320
|
-
if (moved && !
|
|
112205
|
+
if (moved && !fs89.existsSync(destination)) fs89.renameSync(backup, destination);
|
|
112321
112206
|
if (error && typeof error === "object" && "kind" in error) throw error;
|
|
112322
112207
|
die(error instanceof Error ? error.message : String(error), "bad-args");
|
|
112323
112208
|
} finally {
|
|
112324
|
-
|
|
112209
|
+
fs89.rmSync(staging, { recursive: true, force: true });
|
|
112325
112210
|
}
|
|
112326
112211
|
}
|
|
112327
112212
|
var within, readVersion2;
|
|
@@ -112340,7 +112225,7 @@ var init_studio_preview = __esm({
|
|
|
112340
112225
|
init_cards();
|
|
112341
112226
|
init_paths();
|
|
112342
112227
|
init_io();
|
|
112343
|
-
within = (root2, file2) => file2.startsWith(root2 +
|
|
112228
|
+
within = (root2, file2) => file2.startsWith(root2 + path88.sep);
|
|
112344
112229
|
readVersion2 = (files) => {
|
|
112345
112230
|
if (files[VERSION_FILE] === void 0) return null;
|
|
112346
112231
|
try {
|
|
@@ -112742,9 +112627,7 @@ function declareRunning(run4, cli) {
|
|
|
112742
112627
|
const [id] = positional(vals);
|
|
112743
112628
|
await onBoard2(this, cli, () => cmdStop(id));
|
|
112744
112629
|
});
|
|
112745
|
-
verb("resume").argument("[id]", RUN_ID, String).summary("continue a run
|
|
112746
|
-
"The one command that reaches past the board: it picks the coding agent's own session back up \u2014 the conversation it was having, with everything it had already read \u2014 while the board counts the work as a fresh run. Before resuming a creation with no card, check sign-in, project access and connection. A refusal starts no run and leaves triage unchanged. Keep the triage source and request identity; reuse any task already created in Cloud. Repairing an existing card creates no other task. Example: akb raw run resume abc12345"
|
|
112747
|
-
).option("-f, --follow", "watch its log instead of returning").option("--events", "with --follow: print its structured events, one JSON object per line").option("--require-session", "refuse if the original conversation cannot be resumed").action(async function(...vals) {
|
|
112630
|
+
verb("resume").argument("[id]", RUN_ID, String).summary("continue a run from its saved work").description("Reuse its session when available; otherwise continue the original task in the same directory. Preserve task, delivery, triage source and request identities.").option("-f, --follow", "watch its log instead of returning").option("--events", "with --follow: print its structured events, one JSON object per line").option("--require-session", "legacy option; missing sessions still use the saved task context").action(async function(...vals) {
|
|
112748
112631
|
const [id] = positional(vals);
|
|
112749
112632
|
await onBoard2(this, cli, () => cmdResume(id, this.opts()));
|
|
112750
112633
|
});
|
|
@@ -112891,15 +112774,15 @@ var init_agent2 = __esm({
|
|
|
112891
112774
|
});
|
|
112892
112775
|
|
|
112893
112776
|
// src/kanban.ts
|
|
112894
|
-
import
|
|
112777
|
+
import fs92 from "node:fs";
|
|
112895
112778
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
112896
112779
|
|
|
112897
112780
|
// src/lib/cli/akb.ts
|
|
112898
112781
|
init_agent2();
|
|
112899
112782
|
|
|
112900
112783
|
// src/lib/cli/setup.ts
|
|
112901
|
-
import
|
|
112902
|
-
import
|
|
112784
|
+
import fs91 from "node:fs";
|
|
112785
|
+
import path90 from "node:path";
|
|
112903
112786
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
112904
112787
|
|
|
112905
112788
|
// src/commands/update.ts
|
|
@@ -112913,8 +112796,8 @@ init_paths();
|
|
|
112913
112796
|
init_memory();
|
|
112914
112797
|
init_yaml2();
|
|
112915
112798
|
init_version();
|
|
112916
|
-
import
|
|
112917
|
-
import
|
|
112799
|
+
import fs90 from "node:fs";
|
|
112800
|
+
import path89 from "node:path";
|
|
112918
112801
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
112919
112802
|
var NAME = "wildcrane";
|
|
112920
112803
|
var REPO = "https://github.com/wildcrane-ai/wildcrane";
|
|
@@ -112936,10 +112819,10 @@ var Report = class {
|
|
|
112936
112819
|
for (const line of this.notes) say(` ! ${line}`);
|
|
112937
112820
|
}
|
|
112938
112821
|
};
|
|
112939
|
-
var read2 = (file2) =>
|
|
112822
|
+
var read2 = (file2) => fs90.existsSync(file2) ? fs90.readFileSync(file2, "utf8") : null;
|
|
112940
112823
|
function statOf(p2) {
|
|
112941
112824
|
try {
|
|
112942
|
-
return
|
|
112825
|
+
return fs90.lstatSync(p2);
|
|
112943
112826
|
} catch {
|
|
112944
112827
|
return null;
|
|
112945
112828
|
}
|
|
@@ -112964,10 +112847,10 @@ async function cmdUpdate2(ctx) {
|
|
|
112964
112847
|
return { updated: ctx.dir, from, to: SKILL_VERSION };
|
|
112965
112848
|
}
|
|
112966
112849
|
async function repairBoard(root2, report3, named2) {
|
|
112967
|
-
const legacy2 =
|
|
112968
|
-
const kept2 =
|
|
112969
|
-
const board2 = named2 ?? (
|
|
112970
|
-
if (!
|
|
112850
|
+
const legacy2 = path89.join(root2, "docs", "kanban");
|
|
112851
|
+
const kept2 = path89.join(root2, ".akb", "kanban");
|
|
112852
|
+
const board2 = named2 ?? (fs90.existsSync(legacy2) ? legacy2 : kept2);
|
|
112853
|
+
if (!fs90.existsSync(board2)) {
|
|
112971
112854
|
report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
|
|
112972
112855
|
return false;
|
|
112973
112856
|
}
|
|
@@ -112998,20 +112881,20 @@ function moveRuntimes(root2, board2, report3) {
|
|
|
112998
112881
|
}
|
|
112999
112882
|
}
|
|
113000
112883
|
function moveLegacyMemory(board2, report3) {
|
|
113001
|
-
const memory =
|
|
112884
|
+
const memory = path89.join(board2, "memory");
|
|
113002
112885
|
const moved = [];
|
|
113003
112886
|
for (const name of MEMORY_FILES) {
|
|
113004
|
-
const from =
|
|
112887
|
+
const from = path89.join(board2, name);
|
|
113005
112888
|
const st2 = statOf(from);
|
|
113006
112889
|
if (!st2 || !st2.isFile()) continue;
|
|
113007
|
-
|
|
113008
|
-
const to =
|
|
112890
|
+
fs90.mkdirSync(memory, { recursive: true });
|
|
112891
|
+
const to = path89.join(memory, name);
|
|
113009
112892
|
const there = read2(to);
|
|
113010
112893
|
if (there === null) {
|
|
113011
|
-
|
|
112894
|
+
fs90.renameSync(from, to);
|
|
113012
112895
|
moved.push(name);
|
|
113013
112896
|
} else if (there === read2(from)) {
|
|
113014
|
-
|
|
112897
|
+
fs90.rmSync(from);
|
|
113015
112898
|
moved.push(name);
|
|
113016
112899
|
} else {
|
|
113017
112900
|
report3.notes.push(`both docs/kanban/${name} and docs/kanban/memory/${name} exist and differ \u2014 merge them by hand`);
|
|
@@ -113020,23 +112903,23 @@ function moveLegacyMemory(board2, report3) {
|
|
|
113020
112903
|
if (moved.length) report3.did.push(`moved the memory set into docs/kanban/memory/: ${moved.join(", ")}`);
|
|
113021
112904
|
}
|
|
113022
112905
|
function dropRecordFile(board2) {
|
|
113023
|
-
const file2 =
|
|
113024
|
-
if (!
|
|
113025
|
-
|
|
112906
|
+
const file2 = path89.join(board2, "record.csv");
|
|
112907
|
+
if (!fs90.existsSync(file2)) return null;
|
|
112908
|
+
fs90.rmSync(file2);
|
|
113026
112909
|
return "removed docs/kanban/record.csv (the planning scores it fed are gone)";
|
|
113027
112910
|
}
|
|
113028
112911
|
function dropModuleGoals(board2, report3) {
|
|
113029
|
-
const memory =
|
|
113030
|
-
if (!
|
|
113031
|
-
const root2 = read2(
|
|
112912
|
+
const memory = path89.join(board2, "memory");
|
|
112913
|
+
if (!fs90.existsSync(memory)) return;
|
|
112914
|
+
const root2 = read2(path89.join(memory, "goal.md"));
|
|
113032
112915
|
let dropped = 0;
|
|
113033
|
-
for (const entry of
|
|
112916
|
+
for (const entry of fs90.readdirSync(memory, { withFileTypes: true })) {
|
|
113034
112917
|
if (!entry.isDirectory()) continue;
|
|
113035
|
-
const file2 =
|
|
112918
|
+
const file2 = path89.join(memory, entry.name, "goal.md");
|
|
113036
112919
|
const text5 = read2(file2);
|
|
113037
112920
|
if (text5 === null) continue;
|
|
113038
112921
|
if (text5 === root2 || text5.includes(UNFILLED) || !goalWords(text5)) {
|
|
113039
|
-
|
|
112922
|
+
fs90.rmSync(file2);
|
|
113040
112923
|
dropped++;
|
|
113041
112924
|
} else {
|
|
113042
112925
|
report3.notes.push(
|
|
@@ -113058,10 +112941,10 @@ var PLAN_LEADS = {
|
|
|
113058
112941
|
var GONE_LEADS = ["software-planner", "planner"];
|
|
113059
112942
|
function planLeads(board2) {
|
|
113060
112943
|
const leads = { ...PLAN_LEADS };
|
|
113061
|
-
const root2 =
|
|
113062
|
-
for (const entry of
|
|
112944
|
+
const root2 = path89.join(board2, "studios");
|
|
112945
|
+
for (const entry of fs90.existsSync(root2) ? fs90.readdirSync(root2, { withFileTypes: true }) : []) {
|
|
113063
112946
|
if (!entry.isDirectory()) continue;
|
|
113064
|
-
const meta = splitFrontmatter(read2(
|
|
112947
|
+
const meta = splitFrontmatter(read2(path89.join(root2, entry.name, "STUDIO.md")) ?? "").meta;
|
|
113065
112948
|
const stages = meta === null ? void 0 : parseYamlBlock(meta).stages;
|
|
113066
112949
|
const plan = stages && typeof stages === "object" && !Array.isArray(stages) ? stages.plan : void 0;
|
|
113067
112950
|
const lead = plan && typeof plan === "object" && !Array.isArray(plan) && typeof plan.lead === "string" ? plan.lead.trim() : "";
|
|
@@ -113070,30 +112953,30 @@ function planLeads(board2) {
|
|
|
113070
112953
|
return leads;
|
|
113071
112954
|
}
|
|
113072
112955
|
function movePlanRules(board2, report3) {
|
|
113073
|
-
const rules =
|
|
112956
|
+
const rules = path89.join(board2, "rules");
|
|
113074
112957
|
const moved = [];
|
|
113075
112958
|
for (const [id, leads] of Object.entries(planLeads(board2))) {
|
|
113076
112959
|
for (const lead of leads) {
|
|
113077
|
-
const from =
|
|
112960
|
+
const from = path89.join(rules, `${lead}.md`);
|
|
113078
112961
|
const rule = read2(from)?.trim();
|
|
113079
112962
|
if (!rule) continue;
|
|
113080
|
-
const to =
|
|
112963
|
+
const to = path89.join(rules, "studios", `${id}.md`);
|
|
113081
112964
|
const there = read2(to)?.trim() ?? "";
|
|
113082
112965
|
if (!there.includes(rule)) {
|
|
113083
|
-
|
|
113084
|
-
|
|
112966
|
+
fs90.mkdirSync(path89.dirname(to), { recursive: true });
|
|
112967
|
+
fs90.writeFileSync(to, `${[there, rule].filter(Boolean).join("\n\n")}
|
|
113085
112968
|
`);
|
|
113086
112969
|
moved.push(`${lead} \u2192 ${id}`);
|
|
113087
112970
|
}
|
|
113088
112971
|
}
|
|
113089
112972
|
}
|
|
113090
|
-
for (const lead of GONE_LEADS)
|
|
112973
|
+
for (const lead of GONE_LEADS) fs90.rmSync(path89.join(rules, `${lead}.md`), { force: true });
|
|
113091
112974
|
if (moved.length) report3.did.push(`made each plan agent's rule its studio's card rule (docs/kanban/rules/studios/): ${moved.join(", ")}`);
|
|
113092
112975
|
}
|
|
113093
112976
|
function noteOldStudios(board2, report3) {
|
|
113094
112977
|
const old = (dir, file2, keys) => {
|
|
113095
|
-
const root2 =
|
|
113096
|
-
return (
|
|
112978
|
+
const root2 = path89.join(board2, dir);
|
|
112979
|
+
return (fs90.existsSync(root2) ? fs90.readdirSync(root2, { withFileTypes: true }) : []).filter((e2) => e2.isDirectory() && keys.test(splitFrontmatter(read2(path89.join(root2, e2.name, file2)) ?? "").meta ?? "")).map((e2) => `docs/kanban/${dir}/${e2.name}/${file2}`);
|
|
113097
112980
|
};
|
|
113098
112981
|
const files = [...old("studios", "STUDIO.md", /^(stages|delivers):/m), ...old("agents", "AGENT.md", /^\s+(hook|lead):/m)];
|
|
113099
112982
|
if (files.length) {
|
|
@@ -113103,7 +112986,7 @@ function noteOldStudios(board2, report3) {
|
|
|
113103
112986
|
}
|
|
113104
112987
|
}
|
|
113105
112988
|
function checkConfig(board2, report3) {
|
|
113106
|
-
const current = read2(
|
|
112989
|
+
const current = read2(path89.join(board2, "config.md"));
|
|
113107
112990
|
if (!current) return;
|
|
113108
112991
|
const added = missingConfigKeys(current);
|
|
113109
112992
|
if (added.length) {
|
|
@@ -113113,7 +112996,7 @@ function checkConfig(board2, report3) {
|
|
|
113113
112996
|
}
|
|
113114
112997
|
}
|
|
113115
112998
|
function checkModules(board2, report3) {
|
|
113116
|
-
const map2 = read2(
|
|
112999
|
+
const map2 = read2(path89.join(board2, "modules.md"));
|
|
113117
113000
|
if (map2 && map2.includes(UNFILLED)) {
|
|
113118
113001
|
report3.notes.push(
|
|
113119
113002
|
"docs/kanban/modules.md is still blank \u2014 write it from the repo (`akb guide module-map`)"
|
|
@@ -113167,14 +113050,14 @@ function declareSetup(program2, cli) {
|
|
|
113167
113050
|
program2.version(SKILL_VERSION, "-v, --version", "print this version").addHelpText("beforeAll", spelled(cli.program));
|
|
113168
113051
|
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");
|
|
113169
113052
|
const where = (cmd) => {
|
|
113170
|
-
const dir =
|
|
113171
|
-
if (!
|
|
113053
|
+
const dir = path90.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
|
|
113054
|
+
if (!fs91.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
|
|
113172
113055
|
return dir;
|
|
113173
113056
|
};
|
|
113174
113057
|
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() {
|
|
113175
113058
|
const dir = where(this);
|
|
113176
113059
|
const named2 = this.optsWithGlobals().board ?? process.env.AI4KANBAN_BOARD?.trim();
|
|
113177
|
-
const board2 = named2 ?
|
|
113060
|
+
const board2 = named2 ? path90.resolve(cli.cwd, named2) : null;
|
|
113178
113061
|
await runAction(ctxOf(this, cli.program), {}, () => cmdUpdate2({ dir, program: cli.program, board: board2 }));
|
|
113179
113062
|
});
|
|
113180
113063
|
program2.command("__rules", { hidden: true }).action(function() {
|
|
@@ -113219,7 +113102,7 @@ function invokedDirectly() {
|
|
|
113219
113102
|
const entry = process.argv[1];
|
|
113220
113103
|
if (!entry) return false;
|
|
113221
113104
|
try {
|
|
113222
|
-
return
|
|
113105
|
+
return fs92.realpathSync(entry) === fs92.realpathSync(SELF2);
|
|
113223
113106
|
} catch {
|
|
113224
113107
|
return false;
|
|
113225
113108
|
}
|