wildcrane 0.11.84 → 0.11.86
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 +1079 -629
- 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.86 — 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)
|
|
@@ -16692,12 +16692,12 @@ function toJSONSchema(input2, params) {
|
|
|
16692
16692
|
processSchema(schema, ctx2);
|
|
16693
16693
|
}
|
|
16694
16694
|
const schemas = {};
|
|
16695
|
-
const
|
|
16695
|
+
const external2 = {
|
|
16696
16696
|
registry: registry2,
|
|
16697
16697
|
uri: params?.uri,
|
|
16698
16698
|
defs
|
|
16699
16699
|
};
|
|
16700
|
-
ctx2.external =
|
|
16700
|
+
ctx2.external = external2;
|
|
16701
16701
|
for (const entry of registry2._idmap.entries()) {
|
|
16702
16702
|
const [key, schema] = entry;
|
|
16703
16703
|
extractDefs(ctx2, schema);
|
|
@@ -22373,6 +22373,36 @@ var init_language = __esm({
|
|
|
22373
22373
|
});
|
|
22374
22374
|
|
|
22375
22375
|
// src/lib/agent/retry.ts
|
|
22376
|
+
function clipSummary(text5) {
|
|
22377
|
+
const clean = text5.replace(/\s+/g, " ").trim();
|
|
22378
|
+
return clean.length > MAX_SUMMARY_CHARS ? `${clean.slice(0, MAX_SUMMARY_CHARS - 1)}\u2026` : clean;
|
|
22379
|
+
}
|
|
22380
|
+
function clipDetail(text5) {
|
|
22381
|
+
if (!text5) return void 0;
|
|
22382
|
+
const trimmed2 = text5.trim();
|
|
22383
|
+
if (!trimmed2) return void 0;
|
|
22384
|
+
return trimmed2.length > MAX_DETAIL_CHARS ? `${trimmed2.slice(0, MAX_DETAIL_CHARS - 1)}\u2026` : trimmed2;
|
|
22385
|
+
}
|
|
22386
|
+
function makeFailure(source2, rawSummary, options) {
|
|
22387
|
+
const summary2 = clipSummary(rawSummary) || "Execution failed.";
|
|
22388
|
+
const rawDetail = options?.detail?.trim() || (rawSummary.trim().length > summary2.length || rawSummary.includes("\n") ? rawSummary.trim() : void 0);
|
|
22389
|
+
const detail = clipDetail(rawDetail);
|
|
22390
|
+
return {
|
|
22391
|
+
...options?.code ? { code: options.code } : {},
|
|
22392
|
+
source: source2,
|
|
22393
|
+
summary: summary2,
|
|
22394
|
+
...detail && detail !== summary2 ? { detail } : {},
|
|
22395
|
+
...typeof options?.retryAfterMs === "number" && Number.isFinite(options.retryAfterMs) && options.retryAfterMs >= 0 ? { retryAfterMs: options.retryAfterMs } : {}
|
|
22396
|
+
};
|
|
22397
|
+
}
|
|
22398
|
+
function isSessionMissingText(text5) {
|
|
22399
|
+
return !!text5 && SESSION_MISSING_RE.test(text5);
|
|
22400
|
+
}
|
|
22401
|
+
function isSessionMissingFailure(failure2) {
|
|
22402
|
+
if (!failure2) return false;
|
|
22403
|
+
if (failure2.code === "session_not_found" || failure2.code === "session_mismatch") return true;
|
|
22404
|
+
return isSessionMissingText(failure2.summary) || isSessionMissingText(failure2.detail);
|
|
22405
|
+
}
|
|
22376
22406
|
function agentRecovery(evidence) {
|
|
22377
22407
|
if (!evidence.stopped) return "unsafe";
|
|
22378
22408
|
if (evidence.completed) return "report";
|
|
@@ -22380,63 +22410,142 @@ function agentRecovery(evidence) {
|
|
|
22380
22410
|
if (evidence.session) return "resume";
|
|
22381
22411
|
return evidence.replayable ? "replay" : "unsafe";
|
|
22382
22412
|
}
|
|
22413
|
+
function retryContinuePrompt(failure2, attempt2, maxAttempts = MAX_RETRY_ATTEMPTS) {
|
|
22414
|
+
const head2 = attempt2 ? `Previous attempt (${attempt2}/${maxAttempts}) failed [${failure2.source}${failure2.code ? `:${failure2.code}` : ""}]: ${failure2.summary}` : `Previous execution failed [${failure2.source}${failure2.code ? `:${failure2.code}` : ""}]: ${failure2.summary}`;
|
|
22415
|
+
const parts = [head2];
|
|
22416
|
+
if (failure2.detail && failure2.detail !== failure2.summary) parts.push(`Diagnostics:
|
|
22417
|
+
${failure2.detail}`);
|
|
22418
|
+
parts.push(recoveryPrompt);
|
|
22419
|
+
return parts.join("\n\n");
|
|
22420
|
+
}
|
|
22383
22421
|
function backoffMs(attempt2, random = Math.random) {
|
|
22384
22422
|
const step = Math.min(CAP_MS, BASE_MS * 2 ** Math.max(0, attempt2 - 2));
|
|
22385
22423
|
return Math.round(step * (1 - 0.25 * random()));
|
|
22386
22424
|
}
|
|
22387
22425
|
function planRetry(failure2, attempt2, now = Date.now(), backoff = backoffMs, task = false) {
|
|
22388
|
-
if (!Number.isSafeInteger(attempt2) || attempt2 < 1
|
|
22389
|
-
const of =
|
|
22426
|
+
if (!Number.isSafeInteger(attempt2) || attempt2 < 1) return { pause: "unsafe" };
|
|
22427
|
+
const of = MAX_RETRY_ATTEMPTS;
|
|
22390
22428
|
if (attempt2 >= of) return { pause: "limit" };
|
|
22391
22429
|
const delay3 = failure2.retryAfterMs;
|
|
22392
22430
|
const valid = delay3 !== void 0 && !Number.isNaN(delay3) && delay3 >= 0;
|
|
22393
|
-
const
|
|
22431
|
+
const immediate = failure2.source === "validation" || failure2.source === "sync";
|
|
22432
|
+
const wait = valid ? delay3 : immediate ? 0 : backoff(attempt2 + 1);
|
|
22394
22433
|
const cap = task && failure2.code === "rate_limited" && valid ? 24 * 60 * 6e4 : CAP_MS;
|
|
22395
|
-
if (wait > cap) return { pause: "
|
|
22434
|
+
if (wait > cap) return { pause: "wait_too_long" };
|
|
22396
22435
|
return { plan: { at: now + wait, of, failure: failure2 } };
|
|
22397
22436
|
}
|
|
22437
|
+
function normalizeSource(raw) {
|
|
22438
|
+
if (SOURCES.has(raw)) return raw;
|
|
22439
|
+
if (raw === "provider" || raw === "harness") return "runtime";
|
|
22440
|
+
if (raw === "invariant") return "runner";
|
|
22441
|
+
return "runtime";
|
|
22442
|
+
}
|
|
22398
22443
|
function readFailure(raw) {
|
|
22399
22444
|
if (!raw || typeof raw !== "object") return;
|
|
22400
|
-
const
|
|
22401
|
-
|
|
22402
|
-
|
|
22445
|
+
const r = raw;
|
|
22446
|
+
const rawSummary = typeof r.summary === "string" && r.summary.trim() ? r.summary : typeof r.reason === "string" && r.reason.trim() ? r.reason : "";
|
|
22447
|
+
if (!rawSummary) return;
|
|
22448
|
+
const code = typeof r.code === "string" && r.code.trim() ? r.code.trim() : void 0;
|
|
22449
|
+
const detail = typeof r.detail === "string" ? clipDetail(r.detail) : void 0;
|
|
22450
|
+
const retryAfterMs2 = typeof r.retryAfterMs === "number" && Number.isFinite(r.retryAfterMs) && r.retryAfterMs >= 0 ? r.retryAfterMs : void 0;
|
|
22451
|
+
return {
|
|
22452
|
+
...code ? { code } : {},
|
|
22453
|
+
source: normalizeSource(r.source),
|
|
22454
|
+
summary: clipSummary(rawSummary),
|
|
22455
|
+
...detail && detail !== clipSummary(rawSummary) ? { detail } : {},
|
|
22456
|
+
...retryAfterMs2 !== void 0 ? { retryAfterMs: retryAfterMs2 } : {}
|
|
22457
|
+
};
|
|
22458
|
+
}
|
|
22459
|
+
function readRetryRuntime(raw) {
|
|
22460
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
22461
|
+
const r = raw;
|
|
22462
|
+
if (typeof r.connector !== "string" || !r.connector.trim()) return void 0;
|
|
22463
|
+
return {
|
|
22464
|
+
connector: r.connector.trim(),
|
|
22465
|
+
name: typeof r.name === "string" && r.name.trim() ? r.name.trim() : null,
|
|
22466
|
+
model: typeof r.model === "string" && r.model.trim() ? r.model.trim() : null
|
|
22467
|
+
};
|
|
22468
|
+
}
|
|
22469
|
+
function readRetryRecord(raw) {
|
|
22470
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
22471
|
+
const r = raw;
|
|
22472
|
+
const attempt2 = r.attempt;
|
|
22473
|
+
const summary2 = typeof r.summary === "string" ? clipSummary(r.summary) : "";
|
|
22474
|
+
const at = typeof r.at === "string" && r.at.trim() ? r.at.trim() : "";
|
|
22475
|
+
if (typeof attempt2 !== "number" || !Number.isInteger(attempt2) || attempt2 < 1 || !summary2 || !at) return void 0;
|
|
22476
|
+
const runtime = readRetryRuntime(r.runtime);
|
|
22477
|
+
const detail = typeof r.detail === "string" ? clipDetail(r.detail) : void 0;
|
|
22478
|
+
const code = typeof r.code === "string" && r.code.trim() ? r.code.trim() : void 0;
|
|
22479
|
+
const sessionAction = SESSION_ACTIONS.has(r.sessionAction) ? r.sessionAction : void 0;
|
|
22480
|
+
return {
|
|
22481
|
+
attempt: attempt2,
|
|
22482
|
+
source: normalizeSource(r.source),
|
|
22483
|
+
...runtime ? { runtime } : {},
|
|
22484
|
+
summary: summary2,
|
|
22485
|
+
...detail && detail !== summary2 ? { detail } : {},
|
|
22486
|
+
...code ? { code } : {},
|
|
22487
|
+
...sessionAction ? { sessionAction } : {},
|
|
22488
|
+
at
|
|
22489
|
+
};
|
|
22490
|
+
}
|
|
22491
|
+
function readRetryHistory(raw) {
|
|
22492
|
+
if (!Array.isArray(raw)) return void 0;
|
|
22493
|
+
const records = raw.flatMap((entry) => {
|
|
22494
|
+
const parsed = readRetryRecord(entry);
|
|
22495
|
+
return parsed ? [parsed] : [];
|
|
22496
|
+
});
|
|
22497
|
+
return records.length ? records : void 0;
|
|
22498
|
+
}
|
|
22499
|
+
function readRetryPause(raw) {
|
|
22500
|
+
if (raw === "wait-too-long") return "wait_too_long";
|
|
22501
|
+
if (raw === "needs-review") return "limit";
|
|
22502
|
+
if (raw === "limit" || raw === "wait_too_long" || raw === "unsafe" || raw === "authorization" || raw === "stopped") return raw;
|
|
22503
|
+
return void 0;
|
|
22403
22504
|
}
|
|
22404
22505
|
function readRetryPlan(raw, attempt2, task = false) {
|
|
22405
22506
|
if (!raw || typeof raw !== "object") return;
|
|
22406
|
-
const { at, of, failure: rawFailure } = raw;
|
|
22507
|
+
const { at, of, failure: rawFailure, sessionAction } = raw;
|
|
22407
22508
|
const failure2 = readFailure(rawFailure);
|
|
22408
22509
|
if (!failure2 || typeof at !== "number" || !Number.isFinite(at)) return;
|
|
22409
22510
|
const decision = planRetry(failure2, attempt2, Date.now(), backoffMs, task);
|
|
22410
|
-
if ("plan" in decision && of === decision.plan.of)
|
|
22511
|
+
if ("plan" in decision && of === decision.plan.of) {
|
|
22512
|
+
return { at, of, failure: failure2, ...SESSION_ACTIONS.has(sessionAction) ? { sessionAction } : {} };
|
|
22513
|
+
}
|
|
22411
22514
|
}
|
|
22412
22515
|
function pauseLine(pause2, zh = translating()) {
|
|
22413
22516
|
switch (pause2) {
|
|
22414
|
-
case "needs-review":
|
|
22415
|
-
return zh ? "\u5DF2\u6682\u505C\uFF0C\u8BF7\u68C0\u67E5\u5931\u8D25\u539F\u56E0\u540E\u7EED\u8DD1\u3002" : "Paused. Review the failure before resuming.";
|
|
22416
22517
|
case "limit":
|
|
22417
22518
|
return zh ? "\u5DF2\u8FBE\u5230\u81EA\u52A8\u91CD\u8BD5\u6B21\u6570\u4E0A\u9650\u3002" : "The automatic retry limit was reached.";
|
|
22418
|
-
case "
|
|
22519
|
+
case "wait_too_long":
|
|
22419
22520
|
return zh ? "\u6240\u9700\u7B49\u5F85\u65F6\u95F4\u8D85\u8FC7\u4E24\u5206\u949F\uFF0C\u5DF2\u6682\u505C\u3002" : "Paused because the required wait exceeds two minutes.";
|
|
22420
22521
|
case "unsafe":
|
|
22421
22522
|
return zh ? "\u65E0\u6CD5\u786E\u8BA4\u53EF\u4EE5\u5B89\u5168\u7EED\u8DD1\uFF0C\u8BF7\u5148\u6838\u5BF9\u5DF2\u6709\u8FDB\u5EA6\u548C\u64CD\u4F5C\u7ED3\u679C\u3002" : "Check saved progress and operation results before resuming safely.";
|
|
22422
22523
|
case "authorization":
|
|
22423
22524
|
return zh ? "\u65E0\u6CD5\u786E\u8BA4\u7EED\u8DD1\u6388\u6743\uFF0C\u5DF2\u6682\u505C\u3002" : "Paused because authorization to resume could not be confirmed.";
|
|
22525
|
+
case "stopped":
|
|
22526
|
+
return zh ? "\u6267\u884C\u5DF2\u505C\u6B62\u3002" : "Execution stopped.";
|
|
22424
22527
|
}
|
|
22425
22528
|
}
|
|
22426
22529
|
function retryLine(plan, attempt2, now = Date.now()) {
|
|
22427
22530
|
const seconds = Math.max(0, Math.ceil((plan.at - now) / 1e3));
|
|
22428
|
-
return `${plan.failure.
|
|
22531
|
+
return `${plan.failure.summary} \u2014 retrying ${seconds ? `in ${seconds}s` : "now"} (attempt ${attempt2 + 1} of ${plan.of}).`;
|
|
22429
22532
|
}
|
|
22430
22533
|
function syncRepairPrompt(reason) {
|
|
22431
22534
|
return `The Harness could not synchronize the saved result. Correct the diagnostics below, verify the original result and its attachments, then continue from the saved work. Preserve completed work and archive state. Read the task review before changing an approved output and revise its stage first.
|
|
22432
22535
|
|
|
22433
22536
|
${reason}`;
|
|
22434
22537
|
}
|
|
22435
|
-
var recoveryPrompt, BASE_MS, CAP_MS;
|
|
22538
|
+
var MAX_RETRY_ATTEMPTS, MAX_SUMMARY_CHARS, MAX_DETAIL_CHARS, SOURCES, SESSION_ACTIONS, SESSION_MISSING_RE, recoveryPrompt, BASE_MS, CAP_MS;
|
|
22436
22539
|
var init_retry = __esm({
|
|
22437
22540
|
"src/lib/agent/retry.ts"() {
|
|
22438
22541
|
"use strict";
|
|
22439
22542
|
init_language();
|
|
22543
|
+
MAX_RETRY_ATTEMPTS = 4;
|
|
22544
|
+
MAX_SUMMARY_CHARS = 300;
|
|
22545
|
+
MAX_DETAIL_CHARS = 4e3;
|
|
22546
|
+
SOURCES = /* @__PURE__ */ new Set(["runtime", "runner", "sync", "validation"]);
|
|
22547
|
+
SESSION_ACTIONS = /* @__PURE__ */ new Set(["resume", "reset_replay", "pause_unsafe"]);
|
|
22548
|
+
SESSION_MISSING_RE = /no rollout found for thread id|no conversation found with session id|session[_\s-]*not[_\s-]*found|session[_\s-]*mismatch|(?:session|thread|conversation)\s+\S+\s+not\s+found|unknown\s+(?:session|thread)|did not resume the requested conversation|did not return the requested session/i;
|
|
22440
22549
|
recoveryPrompt = "Continue the interrupted turn in this session. Check the current state and the results of previous operations first. Preserve completed work and user decisions. Do not repeat an operation whose result has already taken effect.";
|
|
22441
22550
|
BASE_MS = 15e3;
|
|
22442
22551
|
CAP_MS = 12e4;
|
|
@@ -22723,8 +22832,8 @@ var init_package = __esm({
|
|
|
22723
22832
|
"package.json"() {
|
|
22724
22833
|
package_default = {
|
|
22725
22834
|
name: "wildcrane",
|
|
22726
|
-
version: "0.11.
|
|
22727
|
-
akbContract:
|
|
22835
|
+
version: "0.11.86",
|
|
22836
|
+
akbContract: 29,
|
|
22728
22837
|
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.",
|
|
22729
22838
|
keywords: [
|
|
22730
22839
|
"kanban",
|
|
@@ -24342,7 +24451,7 @@ function createAntigravityRenderer(expectedSession, cwd = process.cwd()) {
|
|
|
24342
24451
|
const events = createEventCollector();
|
|
24343
24452
|
const fail = (reason, code = "provider_failed") => {
|
|
24344
24453
|
failure2 = failureHint(reason);
|
|
24345
|
-
classified = { code,
|
|
24454
|
+
classified = makeFailure("runtime", failure2, { code, detail: reason });
|
|
24346
24455
|
events.error(failure2);
|
|
24347
24456
|
};
|
|
24348
24457
|
const reader = createLineReader((line) => {
|
|
@@ -24497,7 +24606,7 @@ ${imageError(target, reason || str2(step.state))}
|
|
|
24497
24606
|
},
|
|
24498
24607
|
failure: () => failure2 || imageFailure,
|
|
24499
24608
|
terminalFailure: () => terminal && !!classified,
|
|
24500
|
-
executionFailure: () => classified ?? (imageFailure ? { code: "image_read_failed",
|
|
24609
|
+
executionFailure: () => classified ?? (imageFailure ? makeFailure("runtime", imageFailure, { code: "image_read_failed", detail: imageFailure }) : void 0),
|
|
24501
24610
|
events: events.events,
|
|
24502
24611
|
activity: events.activity
|
|
24503
24612
|
};
|
|
@@ -24506,6 +24615,7 @@ var CONTEXT_LOOK_EVERY_MS, KINDS, zero, usageOf, add, imagePath;
|
|
|
24506
24615
|
var init_antigravity = __esm({
|
|
24507
24616
|
"src/lib/agent/wire/antigravity.ts"() {
|
|
24508
24617
|
"use strict";
|
|
24618
|
+
init_retry();
|
|
24509
24619
|
init_prices();
|
|
24510
24620
|
init_language();
|
|
24511
24621
|
init_events();
|
|
@@ -24752,13 +24862,9 @@ var init_check = __esm({
|
|
|
24752
24862
|
function executionFailure(error62) {
|
|
24753
24863
|
if (error62 instanceof ExecutionError) return error62.failure;
|
|
24754
24864
|
const code = str2(obj2(error62).code);
|
|
24755
|
-
const
|
|
24756
|
-
|
|
24757
|
-
|
|
24758
|
-
level: NETWORK.has(code) ? 2 : 3,
|
|
24759
|
-
source: "harness",
|
|
24760
|
-
reason
|
|
24761
|
-
};
|
|
24865
|
+
const raw = error62 instanceof Error ? error62.message : String(error62);
|
|
24866
|
+
const resolvedCode = isSessionMissingText(raw) ? "session_not_found" : NETWORK.has(code) ? "connection_lost" : code === "ENOENT" ? "executable_missing" : "execution_failed";
|
|
24867
|
+
return makeFailure("runner", raw, { code: resolvedCode, detail: raw });
|
|
24762
24868
|
}
|
|
24763
24869
|
function retryAfterMs(value, now = Date.now()) {
|
|
24764
24870
|
if (typeof value !== "string") return;
|
|
@@ -24768,37 +24874,48 @@ function retryAfterMs(value, now = Date.now()) {
|
|
|
24768
24874
|
const date5 = Date.parse(header);
|
|
24769
24875
|
if (Number.isFinite(date5)) return Math.max(0, date5 - now);
|
|
24770
24876
|
}
|
|
24771
|
-
function providerFailure(error62, reason) {
|
|
24877
|
+
function providerFailure(error62, reason, detail) {
|
|
24772
24878
|
const info = obj2(error62);
|
|
24773
24879
|
const status = typeof info.status === "number" ? info.status : void 0;
|
|
24774
24880
|
const headers = obj2(info.headers);
|
|
24775
24881
|
const wait = retryAfterMs(headers["retry-after"] ?? headers["Retry-After"]);
|
|
24776
|
-
const
|
|
24777
|
-
|
|
24778
|
-
if (
|
|
24779
|
-
return
|
|
24882
|
+
const rawCode = info.code ?? info.type;
|
|
24883
|
+
const fullDetail = detail || reason;
|
|
24884
|
+
if (rawCode === "session_not_found" || isSessionMissingText(reason) || isSessionMissingText(fullDetail)) {
|
|
24885
|
+
return makeFailure("runtime", reason, { code: "session_not_found", detail: fullDetail });
|
|
24886
|
+
}
|
|
24887
|
+
if (status === 401 || status === 403 || ["authentication_error", "permission_error", "invalid_request_error"].includes(str2(rawCode))) {
|
|
24888
|
+
return makeFailure("runtime", reason, { code: "provider_refused", detail: fullDetail });
|
|
24889
|
+
}
|
|
24890
|
+
if (status === 429 || rawCode === "rate_limit_error") {
|
|
24891
|
+
return makeFailure("runtime", reason, { code: "rate_limited", detail: fullDetail, retryAfterMs: wait });
|
|
24892
|
+
}
|
|
24893
|
+
if (TEMPORARY_HTTP.has(status ?? 0) || rawCode === "overloaded_error") {
|
|
24894
|
+
return makeFailure("runtime", reason, { code: "service_overloaded", detail: fullDetail, retryAfterMs: wait });
|
|
24895
|
+
}
|
|
24896
|
+
if (NETWORK.has(str2(rawCode))) {
|
|
24897
|
+
return makeFailure("runtime", reason, { code: "connection_lost", detail: fullDetail, retryAfterMs: wait });
|
|
24780
24898
|
}
|
|
24781
|
-
|
|
24782
|
-
if (TEMPORARY_HTTP.has(status ?? 0) || code === "overloaded_error") return { code: "service_overloaded", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
24783
|
-
if (NETWORK.has(str2(code))) return { code: "connection_lost", source: "provider", level: 2, reason, retryAfterMs: wait };
|
|
24784
|
-
return { code: "provider_failed", source: "provider", level: 3, reason };
|
|
24899
|
+
return makeFailure("runtime", reason, { code: "provider_failed", detail: fullDetail, retryAfterMs: wait });
|
|
24785
24900
|
}
|
|
24786
24901
|
function codexFailure(raw, fallback) {
|
|
24787
24902
|
const error62 = obj2(raw);
|
|
24788
24903
|
const failure2 = readFailure(error62.wildcraneFailure);
|
|
24789
|
-
if (failure2
|
|
24904
|
+
if (failure2) return failure2;
|
|
24790
24905
|
const reason = str2(error62.message) || fallback;
|
|
24906
|
+
const additional = str2(error62.additionalDetails);
|
|
24907
|
+
const detail = [reason, additional].filter(Boolean).join("\n");
|
|
24791
24908
|
const info = error62.codexErrorInfo;
|
|
24792
|
-
if (info === "serverOverloaded") return providerFailure({ ...error62, type: "overloaded_error" }, reason);
|
|
24793
|
-
if (info === "rateLimitExceeded") return providerFailure({ ...error62, type: "rate_limit_error" }, reason);
|
|
24909
|
+
if (info === "serverOverloaded") return providerFailure({ ...error62, type: "overloaded_error" }, reason, detail);
|
|
24910
|
+
if (info === "rateLimitExceeded") return providerFailure({ ...error62, type: "rate_limit_error" }, reason, detail);
|
|
24794
24911
|
const types = obj2(info);
|
|
24795
24912
|
for (const kind of ["httpConnectionFailed", "responseStreamConnectionFailed", "responseStreamDisconnected", "responseTooManyFailedAttempts"]) {
|
|
24796
24913
|
if (!(kind in types)) continue;
|
|
24797
24914
|
const status = obj2(types[kind]).httpStatusCode;
|
|
24798
|
-
if (typeof status === "number") return providerFailure({ ...error62, status }, reason);
|
|
24799
|
-
if (kind !== "responseTooManyFailedAttempts") return providerFailure({ ...error62, code: "ECONNRESET" }, reason);
|
|
24915
|
+
if (typeof status === "number") return providerFailure({ ...error62, status }, reason, detail);
|
|
24916
|
+
if (kind !== "responseTooManyFailedAttempts") return providerFailure({ ...error62, code: "ECONNRESET" }, reason, detail);
|
|
24800
24917
|
}
|
|
24801
|
-
return providerFailure(error62, reason);
|
|
24918
|
+
return providerFailure(error62, reason, detail);
|
|
24802
24919
|
}
|
|
24803
24920
|
var ExecutionError, NETWORK, TEMPORARY_HTTP;
|
|
24804
24921
|
var init_failures = __esm({
|
|
@@ -24808,7 +24925,7 @@ var init_failures = __esm({
|
|
|
24808
24925
|
init_json();
|
|
24809
24926
|
ExecutionError = class extends Error {
|
|
24810
24927
|
constructor(failure2) {
|
|
24811
|
-
super(failure2.
|
|
24928
|
+
super(failure2.summary);
|
|
24812
24929
|
this.failure = failure2;
|
|
24813
24930
|
}
|
|
24814
24931
|
failure;
|
|
@@ -24954,7 +25071,12 @@ function createStreamRenderer() {
|
|
|
24954
25071
|
const turnUsage = usageOf2(ev.usage);
|
|
24955
25072
|
if (turnUsage) usage3 = usage3 ? addUsage(usage3, turnUsage) : turnUsage;
|
|
24956
25073
|
failure2 = ev.is_error === true ? whyItFailed(ev) : void 0;
|
|
24957
|
-
classified = failure2 ? ev.subtype === "error_max_structured_output_retries" ?
|
|
25074
|
+
classified = failure2 ? ev.subtype === "error_max_structured_output_retries" ? makeFailure("validation", failure2, { code: "validation_failed", detail: failure2 }) : (() => {
|
|
25075
|
+
const base = apiFailure ?? providerFailure(ev.error, failure2, failure2);
|
|
25076
|
+
const summary2 = clipSummary(failure2);
|
|
25077
|
+
const detail = clipDetail(failure2);
|
|
25078
|
+
return { ...base, summary: summary2, ...detail && detail !== summary2 ? { detail } : {} };
|
|
25079
|
+
})() : void 0;
|
|
24958
25080
|
apiFailure = void 0;
|
|
24959
25081
|
if (failure2) events.error(failure2);
|
|
24960
25082
|
turns.push({
|
|
@@ -25012,6 +25134,7 @@ var ARG_KEYS, TOOL_KINDS2, SUBAGENT_TOOLS, USER_FIXES, addUsage;
|
|
|
25012
25134
|
var init_claude_stream = __esm({
|
|
25013
25135
|
"src/lib/agent/wire/claude-stream.ts"() {
|
|
25014
25136
|
"use strict";
|
|
25137
|
+
init_retry();
|
|
25015
25138
|
init_failures();
|
|
25016
25139
|
init_events();
|
|
25017
25140
|
init_json();
|
|
@@ -25440,7 +25563,7 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
25440
25563
|
return "";
|
|
25441
25564
|
// 最终失败保留;连接提示只在没有后续成功完成时才作为失败。
|
|
25442
25565
|
case "turn.failed": {
|
|
25443
|
-
const said2 = str2(obj2(ev.error).message) || failure2?.
|
|
25566
|
+
const said2 = str2(obj2(ev.error).message) || failure2?.summary || "Codex execution failed.";
|
|
25444
25567
|
failure2 = codexFailure(ev.error, said2);
|
|
25445
25568
|
events.error(said2);
|
|
25446
25569
|
return `[error] ${said2}
|
|
@@ -25495,7 +25618,7 @@ function createCodexStreamRenderer(carried = false) {
|
|
|
25495
25618
|
},
|
|
25496
25619
|
costIncomplete: () => childSpend(subagents, since).costIncomplete || childSpend(subagents, since).costUsd !== void 0 && priceUsd(facts?.provider, turn2()?.model ?? facts?.model, own2()) === void 0 || void 0,
|
|
25497
25620
|
resumeId: () => threadId,
|
|
25498
|
-
failure: () => failure2?.
|
|
25621
|
+
failure: () => failure2?.summary ?? background.failure(),
|
|
25499
25622
|
executionFailure: () => failure2,
|
|
25500
25623
|
background: () => subagents.size ? background.count() : void 0,
|
|
25501
25624
|
events: events.events,
|
|
@@ -25884,7 +26007,7 @@ function connect(stdout, stdin, onCall, dialect = {}) {
|
|
|
25884
26007
|
} else pending.ok(obj2(msg.result));
|
|
25885
26008
|
}
|
|
25886
26009
|
});
|
|
25887
|
-
stdout.on("close", () => closed2(new ExecutionError({ code: "connection_lost",
|
|
26010
|
+
stdout.on("close", () => closed2(new ExecutionError({ code: "connection_lost", source: "runtime", summary: "The agent closed the connection." })));
|
|
25888
26011
|
stdout.on("error", (err) => closed2(new ExecutionError(executionFailure(err))));
|
|
25889
26012
|
stdin.on("error", (err) => closed2(new ExecutionError(executionFailure(err))));
|
|
25890
26013
|
return {
|
|
@@ -26161,7 +26284,7 @@ async function oneTurn(io, options) {
|
|
|
26161
26284
|
} catch (e) {
|
|
26162
26285
|
const reason = e instanceof Error ? e.message : String(e);
|
|
26163
26286
|
const failure2 = e instanceof RpcError ? providerFailure(e.data, reason) : executionFailure(e);
|
|
26164
|
-
if (
|
|
26287
|
+
if (!(e instanceof RpcError) || obj2(e.data).code !== "session_not_found") throw e;
|
|
26165
26288
|
if (!io.restartPrompt) throw new ExecutionError(failure2);
|
|
26166
26289
|
const fresh = await bounded(newSession(rpc, io.cwd, mcpServers), preparingUntil - Date.now(), "ACP session/new timed out.");
|
|
26167
26290
|
opened = fresh.opened;
|
|
@@ -26209,7 +26332,7 @@ async function oneTurn(io, options) {
|
|
|
26209
26332
|
`);
|
|
26210
26333
|
events.error(why2);
|
|
26211
26334
|
emit();
|
|
26212
|
-
return { ok: false, result, error: why2, failure: { code: stopReason2
|
|
26335
|
+
return { ok: false, result, error: why2, failure: makeFailure("runtime", why2, { code: stopReason2 }), usage: usage3, context, costUsd };
|
|
26213
26336
|
}
|
|
26214
26337
|
emit();
|
|
26215
26338
|
return { ok: true, result, usage: usage3, context, costUsd };
|
|
@@ -26277,6 +26400,7 @@ var PROTOCOL_VERSION, CLIENT_CAPABILITIES, RESTARTED, TICKS_PER_USD, STOPPED;
|
|
|
26277
26400
|
var init_acp = __esm({
|
|
26278
26401
|
"src/lib/agent/wire/acp.ts"() {
|
|
26279
26402
|
"use strict";
|
|
26403
|
+
init_retry();
|
|
26280
26404
|
init_failures();
|
|
26281
26405
|
init_acp_cost();
|
|
26282
26406
|
init_conversation();
|
|
@@ -26581,7 +26705,7 @@ function event(envelope2, parts, tail, live, ended) {
|
|
|
26581
26705
|
case "turn.failed": {
|
|
26582
26706
|
const error62 = obj2(payload.error);
|
|
26583
26707
|
const failure2 = providerFailure(error62, str2(error62.message) || "the turn failed");
|
|
26584
|
-
return ended({ ok: false, error: failure2.
|
|
26708
|
+
return ended({ ok: false, error: failure2.summary, failure: failure2 });
|
|
26585
26709
|
}
|
|
26586
26710
|
case "session.closed":
|
|
26587
26711
|
return ended({ ok: false, error: str2(payload.reason) || "the agent closed the session" });
|
|
@@ -26674,6 +26798,18 @@ function createIdleWatchdog(expired, busy = () => false, milliseconds = IDLE_TIM
|
|
|
26674
26798
|
check2();
|
|
26675
26799
|
return;
|
|
26676
26800
|
}
|
|
26801
|
+
if (e.kind === "retry") {
|
|
26802
|
+
if (e.data.state === "waiting" || e.data.state === "retrying") {
|
|
26803
|
+
recoveringAt ??= now();
|
|
26804
|
+
const target = e.data.nextRetryAt ? Date.parse(e.data.nextRetryAt) : NaN;
|
|
26805
|
+
const waitUntil = Number.isFinite(target) ? Math.max(target + 3e4, now() + PROVIDER_RETRY_MS.announcement) : now() + PROVIDER_RETRY_MS.announcement;
|
|
26806
|
+
retryUntil = Math.min(waitUntil, recoveringAt + PROVIDER_RETRY_MS.episode);
|
|
26807
|
+
} else {
|
|
26808
|
+
touch();
|
|
26809
|
+
}
|
|
26810
|
+
check2();
|
|
26811
|
+
return;
|
|
26812
|
+
}
|
|
26677
26813
|
if (e.kind === "log" || e.kind === "context") return;
|
|
26678
26814
|
if (e.kind === "phase" && !e.data.contentAt) return;
|
|
26679
26815
|
const key = e.kind === "tool_call" || e.kind === "tool_call_update" ? `${e.kind}:${e.data.toolCallId}` : e.kind;
|
|
@@ -26701,7 +26837,7 @@ var init_idle = __esm({
|
|
|
26701
26837
|
IDLE_MS = 5 * 6e4;
|
|
26702
26838
|
IDLE_TIMEOUT = { milliseconds: IDLE_MS };
|
|
26703
26839
|
IDLE_ERROR = "No response for 5 minutes (idle timeout).";
|
|
26704
|
-
IDLE_FAILURE = { code: "idle_timeout",
|
|
26840
|
+
IDLE_FAILURE = { code: "idle_timeout", source: "runtime", summary: IDLE_ERROR };
|
|
26705
26841
|
PROVIDER_RETRY_MS = { announcement: 10 * 6e4, episode: 30 * 6e4 };
|
|
26706
26842
|
}
|
|
26707
26843
|
});
|
|
@@ -27062,12 +27198,12 @@ async function run(io, options, count3) {
|
|
|
27062
27198
|
const costUsd = cost === void 0 ? child.costUsd : cost + (child.costUsd ?? 0);
|
|
27063
27199
|
const failure2 = error62 || (cleanup.status === "unconfirmed" ? cleanup.detail : void 0) || work.work().filter((w) => !w.intentionalStop && ["failed", "interrupted"].includes(w.status)).map((w) => w.result || `Background work ${w.id} ${w.status}.`).join("\n") || void 0;
|
|
27064
27200
|
if (failure2) io.event?.({ kind: "error", data: { text: failure2 } });
|
|
27065
|
-
resolve2({ ok: !failure2, error: failure2, failure: failure2 ? classified ?? { code: "execution_failed",
|
|
27201
|
+
resolve2({ ok: !failure2, error: failure2, failure: failure2 ? classified ?? makeFailure("runtime", failure2, { code: "execution_failed", detail: failure2 }) : void 0, cleanup, result: renderer.result(), replyParts: renderer.replyParts?.(), usage: combinedUsage, context, costUsd, costIncomplete: child.costIncomplete || cost === void 0 && child.costUsd !== void 0 || void 0 });
|
|
27066
27202
|
};
|
|
27067
27203
|
const closed2 = () => {
|
|
27068
27204
|
const reason = "Codex connection closed before all work and results finished.";
|
|
27069
27205
|
if (work.work().some((w) => ["running", "unknown"].includes(w.status))) note("Connection lost; managed cleanup is unconfirmed.");
|
|
27070
|
-
end2(reason, { code: "connection_lost",
|
|
27206
|
+
end2(reason, makeFailure("runtime", reason, { code: "connection_lost", detail: reason }));
|
|
27071
27207
|
};
|
|
27072
27208
|
const inputFailed = (e) => {
|
|
27073
27209
|
if (work.work().some((w) => ["running", "unknown"].includes(w.status))) note("Connection input failed; managed cleanup is unconfirmed.");
|
|
@@ -27106,7 +27242,7 @@ async function run(io, options, count3) {
|
|
|
27106
27242
|
} catch (error62) {
|
|
27107
27243
|
if (!ended) note(error62 instanceof Error ? error62.message : String(error62));
|
|
27108
27244
|
}
|
|
27109
|
-
if (!ended) end2(IDLE_FAILURE.
|
|
27245
|
+
if (!ended) end2(IDLE_FAILURE.summary, IDLE_FAILURE);
|
|
27110
27246
|
};
|
|
27111
27247
|
io.idleSignal?.addEventListener("abort", idle, { once: true });
|
|
27112
27248
|
const childUpdates = () => {
|
|
@@ -27366,10 +27502,24 @@ async function run(io, options, count3) {
|
|
|
27366
27502
|
const failure2 = codexFailure(p.error, "Codex failed.");
|
|
27367
27503
|
if (p.willRetry === true && submitted && active3 && !idling) {
|
|
27368
27504
|
status = "retrying";
|
|
27369
|
-
io.log(`[Codex recovery] ${failure2.code}: ${failure2.
|
|
27505
|
+
io.log(`[Codex recovery] ${failure2.code ?? "error"}: ${failure2.summary}
|
|
27370
27506
|
`);
|
|
27371
27507
|
io.event?.({ kind: "status", data: { state: "retrying", source: "codex", code: failure2.code } });
|
|
27372
|
-
|
|
27508
|
+
io.event?.({
|
|
27509
|
+
kind: "retry",
|
|
27510
|
+
data: {
|
|
27511
|
+
state: "retrying",
|
|
27512
|
+
source: "runtime",
|
|
27513
|
+
runtime: { connector: "codex", name: null, model: model ?? null },
|
|
27514
|
+
attempt: 1,
|
|
27515
|
+
maxAttempts: MAX_RETRY_ATTEMPTS,
|
|
27516
|
+
summary: failure2.summary,
|
|
27517
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
27518
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
27519
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
27520
|
+
}
|
|
27521
|
+
});
|
|
27522
|
+
} else if (p.willRetry !== true) end2(failure2.summary, failure2);
|
|
27373
27523
|
}
|
|
27374
27524
|
if (msg.method === "turn/completed") {
|
|
27375
27525
|
const turn2 = obj2(p.turn);
|
|
@@ -27383,7 +27533,7 @@ async function run(io, options, count3) {
|
|
|
27383
27533
|
if (idling) return;
|
|
27384
27534
|
if (turn2.status !== "completed") {
|
|
27385
27535
|
const reason = str2(obj2(turn2.error).message) || `Codex turn ${str2(turn2.status)}.`;
|
|
27386
|
-
const failure2 = turn2.status === "failed" ? codexFailure(turn2.error, reason) : { code: "turn_stopped",
|
|
27536
|
+
const failure2 = turn2.status === "failed" ? codexFailure(turn2.error, reason) : makeFailure("runtime", reason, { code: "turn_stopped", detail: reason });
|
|
27387
27537
|
end2(reason, failure2);
|
|
27388
27538
|
return;
|
|
27389
27539
|
}
|
|
@@ -27420,11 +27570,15 @@ async function run(io, options, count3) {
|
|
|
27420
27570
|
try {
|
|
27421
27571
|
response = await bounded(rpc.call(method, params), preparingUntil - Date.now(), `Codex ${method} timed out.`);
|
|
27422
27572
|
} catch (error62) {
|
|
27573
|
+
if (mode === "fork" && error62 instanceof RpcError && error62.code === -32600 && error62.message === `no rollout found for thread id ${params.threadId}`) {
|
|
27574
|
+
end2(error62.message, { code: "codex_fork_source_missing", source: "runtime", summary: error62.message, detail: error62.message });
|
|
27575
|
+
return done;
|
|
27576
|
+
}
|
|
27423
27577
|
const failure2 = error62 instanceof RpcError ? codexFailure(error62.data, error62.message) : void 0;
|
|
27424
|
-
if (mode !== "fork" || failure2?.
|
|
27578
|
+
if (mode !== "fork" || failure2?.code !== "codex_source_busy") throw error62;
|
|
27425
27579
|
if (!waiting) {
|
|
27426
27580
|
waiting = true;
|
|
27427
|
-
io.event?.({ kind: "log", data: { text: failure2.
|
|
27581
|
+
io.event?.({ kind: "log", data: { text: failure2.summary } });
|
|
27428
27582
|
}
|
|
27429
27583
|
io.activity?.();
|
|
27430
27584
|
await delay(500, void 0, { signal: io.signal });
|
|
@@ -27450,7 +27604,7 @@ async function run(io, options, count3) {
|
|
|
27450
27604
|
await start(io.prompt, options.images);
|
|
27451
27605
|
} catch (e) {
|
|
27452
27606
|
const failure2 = e instanceof RpcError ? codexFailure(e.data, e.message) : executionFailure(e);
|
|
27453
|
-
end2(failure2.
|
|
27607
|
+
end2(failure2.summary, failure2);
|
|
27454
27608
|
}
|
|
27455
27609
|
return done;
|
|
27456
27610
|
}
|
|
@@ -27459,6 +27613,7 @@ var init_codex = __esm({
|
|
|
27459
27613
|
"src/lib/agent/wire/codex.ts"() {
|
|
27460
27614
|
"use strict";
|
|
27461
27615
|
init_idle();
|
|
27616
|
+
init_retry();
|
|
27462
27617
|
init_failures();
|
|
27463
27618
|
init_conversation();
|
|
27464
27619
|
init_codex_background();
|
|
@@ -29130,6 +29285,22 @@ var init_settings2 = __esm({
|
|
|
29130
29285
|
});
|
|
29131
29286
|
|
|
29132
29287
|
// src/lib/agent/runtimes.ts
|
|
29288
|
+
import fs27 from "node:fs";
|
|
29289
|
+
function executionRuntimes() {
|
|
29290
|
+
const encoded = process.env[EXECUTION_RUNTIMES_ENV];
|
|
29291
|
+
return encoded ? JSON.parse(encoded) : void 0;
|
|
29292
|
+
}
|
|
29293
|
+
function readRuntimeCredentials(file2) {
|
|
29294
|
+
try {
|
|
29295
|
+
return configBlock(JSON.parse(fs27.readFileSync(file2, "utf8")));
|
|
29296
|
+
} catch {
|
|
29297
|
+
return {};
|
|
29298
|
+
}
|
|
29299
|
+
}
|
|
29300
|
+
function runRuntimeById(id2) {
|
|
29301
|
+
const scope = executionRuntimes();
|
|
29302
|
+
return scope ? [scope.default, ...Object.values(scope.picks)].find((row) => row.id === id2) : runtimeById(id2);
|
|
29303
|
+
}
|
|
29133
29304
|
function readRuntimes(cfg = safeConfig()) {
|
|
29134
29305
|
const saved = Array.isArray(cfg.runtimes) ? cfg.runtimes.map(parseRuntime).filter(isRuntime) : null;
|
|
29135
29306
|
const list3 = saved?.length ? dedupe(saved) : [];
|
|
@@ -29244,7 +29415,7 @@ function writePicks(cfg, picks, list3 = readRuntimes(cfg)) {
|
|
|
29244
29415
|
if (Object.keys(block).length) cfg.agentRuntime = block;
|
|
29245
29416
|
else delete cfg.agentRuntime;
|
|
29246
29417
|
}
|
|
29247
|
-
var GLOBAL_ID, GLOBAL_NAME, isRuntime, runtimeSecretVar, keepsPick, noRuntime, noHarness;
|
|
29418
|
+
var GLOBAL_ID, GLOBAL_NAME, EXECUTION_RUNTIMES_ENV, isRuntime, runtimeSecretVar, keepsPick, noRuntime, noHarness;
|
|
29248
29419
|
var init_runtimes = __esm({
|
|
29249
29420
|
"src/lib/agent/runtimes.ts"() {
|
|
29250
29421
|
"use strict";
|
|
@@ -29253,6 +29424,7 @@ var init_runtimes = __esm({
|
|
|
29253
29424
|
init_types3();
|
|
29254
29425
|
GLOBAL_ID = "global";
|
|
29255
29426
|
GLOBAL_NAME = "Global default";
|
|
29427
|
+
EXECUTION_RUNTIMES_ENV = "AI4KANBAN_EXECUTION_RUNTIMES";
|
|
29256
29428
|
isRuntime = (r) => r !== null;
|
|
29257
29429
|
runtimeSecretVar = (env2, runtime) => runtime.secretRefs?.[env2] ?? secretVar(env2, runtime.id);
|
|
29258
29430
|
keepsPick = (id2) => !!id2 && id2 !== GLOBAL_ID;
|
|
@@ -29273,11 +29445,11 @@ var init_slug = __esm({
|
|
|
29273
29445
|
});
|
|
29274
29446
|
|
|
29275
29447
|
// src/lib/validate.ts
|
|
29276
|
-
import
|
|
29448
|
+
import fs28 from "node:fs";
|
|
29277
29449
|
import path30 from "node:path";
|
|
29278
29450
|
function moduleNames() {
|
|
29279
|
-
if (!
|
|
29280
|
-
return moduleNamesFrom(
|
|
29451
|
+
if (!fs28.existsSync(MODULES_MD)) return null;
|
|
29452
|
+
return moduleNamesFrom(fs28.readFileSync(MODULES_MD, "utf8"));
|
|
29281
29453
|
}
|
|
29282
29454
|
function validModules(mods) {
|
|
29283
29455
|
const known2 = moduleNames();
|
|
@@ -29312,7 +29484,7 @@ function dependencyCycle(id2, dep) {
|
|
|
29312
29484
|
const found2 = locate(at);
|
|
29313
29485
|
if (!found2) return null;
|
|
29314
29486
|
const file2 = found2.kind === "group" ? path30.join(found2.target, "root.md") : found2.target;
|
|
29315
|
-
const nexts = parseFrontmatter(
|
|
29487
|
+
const nexts = parseFrontmatter(fs28.readFileSync(file2, "utf8")).meta?.blocked_by ?? [];
|
|
29316
29488
|
if (found2.kind === "group") nexts.push(...groupMembers(found2.target));
|
|
29317
29489
|
for (const next of nexts) {
|
|
29318
29490
|
const rest2 = walk3(next);
|
|
@@ -29340,7 +29512,7 @@ var init_validate = __esm({
|
|
|
29340
29512
|
});
|
|
29341
29513
|
|
|
29342
29514
|
// src/lib/memory.ts
|
|
29343
|
-
import
|
|
29515
|
+
import fs29 from "node:fs";
|
|
29344
29516
|
import path31 from "node:path";
|
|
29345
29517
|
function scaffoldProjectMemory() {
|
|
29346
29518
|
const board2 = scaffoldMemoryDir(MEMORY, setOf(BOARD_MEMORY_FILES));
|
|
@@ -29348,13 +29520,13 @@ function scaffoldProjectMemory() {
|
|
|
29348
29520
|
return board2 ?? planner;
|
|
29349
29521
|
}
|
|
29350
29522
|
function scaffoldMemoryDir(dir, set2) {
|
|
29351
|
-
const existed =
|
|
29352
|
-
|
|
29523
|
+
const existed = fs29.existsSync(dir);
|
|
29524
|
+
fs29.mkdirSync(dir, { recursive: true });
|
|
29353
29525
|
const made = [];
|
|
29354
29526
|
for (const [name, body] of Object.entries(set2)) {
|
|
29355
29527
|
const file2 = path31.join(dir, name);
|
|
29356
|
-
if (!
|
|
29357
|
-
|
|
29528
|
+
if (!fs29.existsSync(file2)) {
|
|
29529
|
+
fs29.writeFileSync(file2, body);
|
|
29358
29530
|
made.push(name);
|
|
29359
29531
|
}
|
|
29360
29532
|
}
|
|
@@ -29364,7 +29536,7 @@ function scaffoldMemoryDir(dir, set2) {
|
|
|
29364
29536
|
function plannerModules() {
|
|
29365
29537
|
let dirs2;
|
|
29366
29538
|
try {
|
|
29367
|
-
dirs2 =
|
|
29539
|
+
dirs2 = fs29.readdirSync(agentMemoryDir(PLANNER), { withFileTypes: true }).filter((e) => e.isDirectory() && isModule(e.name)).map((e) => e.name);
|
|
29368
29540
|
} catch {
|
|
29369
29541
|
return [];
|
|
29370
29542
|
}
|
|
@@ -29376,7 +29548,7 @@ function memoryDirectories(board2) {
|
|
|
29376
29548
|
const walk3 = (dir, depth3, scoped = true) => {
|
|
29377
29549
|
let entries2;
|
|
29378
29550
|
try {
|
|
29379
|
-
entries2 =
|
|
29551
|
+
entries2 = fs29.readdirSync(dir, { withFileTypes: true });
|
|
29380
29552
|
} catch {
|
|
29381
29553
|
return [];
|
|
29382
29554
|
}
|
|
@@ -29390,7 +29562,7 @@ function memoryDirectories(board2) {
|
|
|
29390
29562
|
...walk3(path31.join(root2, "previews"), 3),
|
|
29391
29563
|
...walk3(path31.join(root2, "studios"), 1, false),
|
|
29392
29564
|
path31.join(root2, "agents", PLANNER)
|
|
29393
|
-
].filter((dir) =>
|
|
29565
|
+
].filter((dir) => fs29.existsSync(dir)).map((dir) => `${dir}/`);
|
|
29394
29566
|
}
|
|
29395
29567
|
var PLANNER, PLANNER_MEMORY_FILES, BOARD_MEMORY_FILES, STARTERS, setOf, RESERVED_MEMORY_DIR, STUDIO_MEMORY_DIR, agentMemoryDir, agentMemoryFile, writtenMemoryNames, memoryNamesOf, agentMemoryFiles, RESERVED_MODULE_NAMES, isModule, moduleMemoryFile, plannerCopies;
|
|
29396
29568
|
var init_memory = __esm({
|
|
@@ -29439,7 +29611,7 @@ edits here do not last.
|
|
|
29439
29611
|
agentMemoryFile = (agent, name) => path31.join(agentMemoryDir(agent), name);
|
|
29440
29612
|
writtenMemoryNames = (agent) => {
|
|
29441
29613
|
try {
|
|
29442
|
-
return
|
|
29614
|
+
return fs29.readdirSync(agentMemoryDir(agent), { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name).sort();
|
|
29443
29615
|
} catch {
|
|
29444
29616
|
return [];
|
|
29445
29617
|
}
|
|
@@ -29451,7 +29623,7 @@ edits here do not last.
|
|
|
29451
29623
|
moduleMemoryFile = (module, name) => path31.join(agentMemoryDir(PLANNER), module, name);
|
|
29452
29624
|
plannerCopies = (name) => [
|
|
29453
29625
|
agentMemoryFile(PLANNER, name),
|
|
29454
|
-
...plannerModules().map((m) => moduleMemoryFile(m, name)).filter((file2) =>
|
|
29626
|
+
...plannerModules().map((m) => moduleMemoryFile(m, name)).filter((file2) => fs29.existsSync(file2))
|
|
29455
29627
|
];
|
|
29456
29628
|
}
|
|
29457
29629
|
});
|
|
@@ -43122,14 +43294,14 @@ var require_parser = __commonJS({
|
|
|
43122
43294
|
case "scalar":
|
|
43123
43295
|
case "single-quoted-scalar":
|
|
43124
43296
|
case "double-quoted-scalar": {
|
|
43125
|
-
const
|
|
43297
|
+
const fs91 = this.flowScalar(this.type);
|
|
43126
43298
|
if (atNextItem || it.value) {
|
|
43127
|
-
map3.items.push({ start, key:
|
|
43299
|
+
map3.items.push({ start, key: fs91, sep: [] });
|
|
43128
43300
|
this.onKeyLine = true;
|
|
43129
43301
|
} else if (it.sep) {
|
|
43130
|
-
this.stack.push(
|
|
43302
|
+
this.stack.push(fs91);
|
|
43131
43303
|
} else {
|
|
43132
|
-
Object.assign(it, { key:
|
|
43304
|
+
Object.assign(it, { key: fs91, sep: [] });
|
|
43133
43305
|
this.onKeyLine = true;
|
|
43134
43306
|
}
|
|
43135
43307
|
return;
|
|
@@ -43257,13 +43429,13 @@ var require_parser = __commonJS({
|
|
|
43257
43429
|
case "scalar":
|
|
43258
43430
|
case "single-quoted-scalar":
|
|
43259
43431
|
case "double-quoted-scalar": {
|
|
43260
|
-
const
|
|
43432
|
+
const fs91 = this.flowScalar(this.type);
|
|
43261
43433
|
if (!it || it.value)
|
|
43262
|
-
fc.items.push({ start: [], key:
|
|
43434
|
+
fc.items.push({ start: [], key: fs91, sep: [] });
|
|
43263
43435
|
else if (it.sep)
|
|
43264
|
-
this.stack.push(
|
|
43436
|
+
this.stack.push(fs91);
|
|
43265
43437
|
else
|
|
43266
|
-
Object.assign(it, { key:
|
|
43438
|
+
Object.assign(it, { key: fs91, sep: [] });
|
|
43267
43439
|
return;
|
|
43268
43440
|
}
|
|
43269
43441
|
case "flow-map-end":
|
|
@@ -43949,10 +44121,10 @@ var init_studio_files = __esm({
|
|
|
43949
44121
|
});
|
|
43950
44122
|
|
|
43951
44123
|
// src/lib/agent/studio-folder.ts
|
|
43952
|
-
import
|
|
44124
|
+
import fs30 from "node:fs";
|
|
43953
44125
|
import path32 from "node:path";
|
|
43954
44126
|
function filesOf(dir, base = dir) {
|
|
43955
|
-
return
|
|
44127
|
+
return fs30.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".")).flatMap((e) => {
|
|
43956
44128
|
const full = path32.join(dir, e.name);
|
|
43957
44129
|
if (e.isSymbolicLink()) throw new Error(`${full}: symbolic links are not allowed`);
|
|
43958
44130
|
return e.isDirectory() ? filesOf(full, base) : [path32.relative(base, full).split(path32.sep).join("/")];
|
|
@@ -43960,7 +44132,7 @@ function filesOf(dir, base = dir) {
|
|
|
43960
44132
|
}
|
|
43961
44133
|
function readStudioFile(dir, file2) {
|
|
43962
44134
|
const full = path32.join(dir, file2);
|
|
43963
|
-
return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path32.extname(file2)]};base64,${
|
|
44135
|
+
return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path32.extname(file2)]};base64,${fs30.readFileSync(full).toString("base64")}` : fs30.readFileSync(full, "utf8");
|
|
43964
44136
|
}
|
|
43965
44137
|
var MIME, readStudioFolder;
|
|
43966
44138
|
var init_studio_folder = __esm({
|
|
@@ -43974,7 +44146,7 @@ var init_studio_folder = __esm({
|
|
|
43974
44146
|
|
|
43975
44147
|
// ../official/pack.ts
|
|
43976
44148
|
import crypto2 from "node:crypto";
|
|
43977
|
-
import
|
|
44149
|
+
import fs31 from "node:fs";
|
|
43978
44150
|
import path33 from "node:path";
|
|
43979
44151
|
import { fileURLToPath } from "node:url";
|
|
43980
44152
|
function packOfficial(root2 = OFFICIAL, loose = false) {
|
|
@@ -44006,32 +44178,32 @@ var init_pack = __esm({
|
|
|
44006
44178
|
init_studio_folder();
|
|
44007
44179
|
init_studio_files();
|
|
44008
44180
|
OFFICIAL = path33.dirname(fileURLToPath(import.meta.url));
|
|
44009
|
-
dirs = (dir) =>
|
|
44181
|
+
dirs = (dir) => fs31.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
44010
44182
|
hashOf = (files) => crypto2.createHash("sha256").update(hashInput(files)).digest("hex");
|
|
44011
44183
|
}
|
|
44012
44184
|
});
|
|
44013
44185
|
|
|
44014
44186
|
// src/lib/agent/cloud-studios.ts
|
|
44015
|
-
import
|
|
44187
|
+
import fs32 from "node:fs";
|
|
44016
44188
|
import path34 from "node:path";
|
|
44017
44189
|
function readJson(file2) {
|
|
44018
44190
|
try {
|
|
44019
|
-
return JSON.parse(
|
|
44191
|
+
return JSON.parse(fs32.readFileSync(file2, "utf8"));
|
|
44020
44192
|
} catch {
|
|
44021
44193
|
return null;
|
|
44022
44194
|
}
|
|
44023
44195
|
}
|
|
44024
44196
|
function writeJson(file2, value) {
|
|
44025
|
-
|
|
44197
|
+
fs32.mkdirSync(path34.dirname(file2), { recursive: true });
|
|
44026
44198
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
44027
|
-
|
|
44199
|
+
fs32.writeFileSync(tmp, `${JSON.stringify(value)}
|
|
44028
44200
|
`);
|
|
44029
|
-
|
|
44201
|
+
fs32.renameSync(tmp, file2);
|
|
44030
44202
|
}
|
|
44031
44203
|
function heldStudioName(name) {
|
|
44032
44204
|
let files;
|
|
44033
44205
|
try {
|
|
44034
|
-
files =
|
|
44206
|
+
files = fs32.readdirSync(path34.join(root(), "versions"));
|
|
44035
44207
|
} catch {
|
|
44036
44208
|
return "";
|
|
44037
44209
|
}
|
|
@@ -44042,7 +44214,7 @@ function heldStudioName(name) {
|
|
|
44042
44214
|
}
|
|
44043
44215
|
function saveVersion(held4) {
|
|
44044
44216
|
const file2 = versionFile(held4.id, held4.version);
|
|
44045
|
-
if (!
|
|
44217
|
+
if (!fs32.existsSync(file2)) writeJson(file2, { id: held4.id, version: held4.version, name: held4.name, names: held4.names, files: held4.files });
|
|
44046
44218
|
}
|
|
44047
44219
|
function savePin(task, held4) {
|
|
44048
44220
|
saveVersion(held4);
|
|
@@ -44247,7 +44419,7 @@ var init_studio_file = __esm({
|
|
|
44247
44419
|
});
|
|
44248
44420
|
|
|
44249
44421
|
// src/lib/agent/studios.ts
|
|
44250
|
-
import
|
|
44422
|
+
import fs33 from "node:fs";
|
|
44251
44423
|
import path35 from "node:path";
|
|
44252
44424
|
function noStudioMessage(id2) {
|
|
44253
44425
|
const name = heldStudioName(id2 ?? "") || id2;
|
|
@@ -44260,7 +44432,7 @@ function knownStudio(id2) {
|
|
|
44260
44432
|
}
|
|
44261
44433
|
function userStudioRules(flow) {
|
|
44262
44434
|
try {
|
|
44263
|
-
return
|
|
44435
|
+
return fs33.readFileSync(studioRuleFile(flow.id), "utf8").trim();
|
|
44264
44436
|
} catch {
|
|
44265
44437
|
return "";
|
|
44266
44438
|
}
|
|
@@ -44270,7 +44442,7 @@ function cardMeta(id2) {
|
|
|
44270
44442
|
const found2 = locate(id2) ?? locateArchived(id2);
|
|
44271
44443
|
if (!found2) return null;
|
|
44272
44444
|
const file2 = found2.kind === "group" ? path35.join(found2.target, "root.md") : found2.target;
|
|
44273
|
-
return parseFrontmatter(
|
|
44445
|
+
return parseFrontmatter(fs33.readFileSync(file2, "utf8")).meta;
|
|
44274
44446
|
} catch {
|
|
44275
44447
|
return null;
|
|
44276
44448
|
}
|
|
@@ -44934,7 +45106,7 @@ var init_parse3 = __esm({
|
|
|
44934
45106
|
});
|
|
44935
45107
|
|
|
44936
45108
|
// src/lib/agents/catalog.ts
|
|
44937
|
-
import
|
|
45109
|
+
import fs34 from "node:fs";
|
|
44938
45110
|
import path37 from "node:path";
|
|
44939
45111
|
function readCatalog() {
|
|
44940
45112
|
const agents = [];
|
|
@@ -44992,7 +45164,7 @@ function readBundled(folder2) {
|
|
|
44992
45164
|
function projectFolders(root2) {
|
|
44993
45165
|
let entries2;
|
|
44994
45166
|
try {
|
|
44995
|
-
entries2 =
|
|
45167
|
+
entries2 = fs34.readdirSync(root2, { withFileTypes: true });
|
|
44996
45168
|
} catch {
|
|
44997
45169
|
return [];
|
|
44998
45170
|
}
|
|
@@ -45003,9 +45175,9 @@ function agentFileReader(dir) {
|
|
|
45003
45175
|
const target = path37.resolve(dir, relative);
|
|
45004
45176
|
if (target !== dir && !target.startsWith(dir + path37.sep)) return null;
|
|
45005
45177
|
try {
|
|
45006
|
-
const real2 =
|
|
45007
|
-
if (!real2.startsWith(
|
|
45008
|
-
return
|
|
45178
|
+
const real2 = fs34.realpathSync(target);
|
|
45179
|
+
if (!real2.startsWith(fs34.realpathSync(dir) + path37.sep)) return null;
|
|
45180
|
+
return fs34.readFileSync(real2, "utf8");
|
|
45009
45181
|
} catch {
|
|
45010
45182
|
return null;
|
|
45011
45183
|
}
|
|
@@ -45014,7 +45186,7 @@ function agentFileReader(dir) {
|
|
|
45014
45186
|
function walkFolder(dir, prefix) {
|
|
45015
45187
|
let entries2;
|
|
45016
45188
|
try {
|
|
45017
|
-
entries2 =
|
|
45189
|
+
entries2 = fs34.readdirSync(dir, { withFileTypes: true });
|
|
45018
45190
|
} catch {
|
|
45019
45191
|
return [];
|
|
45020
45192
|
}
|
|
@@ -45125,7 +45297,7 @@ var init_candidate = __esm({
|
|
|
45125
45297
|
|
|
45126
45298
|
// src/lib/agent/launch.ts
|
|
45127
45299
|
import { spawn as spawn2 } from "node:child_process";
|
|
45128
|
-
import
|
|
45300
|
+
import fs35 from "node:fs";
|
|
45129
45301
|
import path38 from "node:path";
|
|
45130
45302
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
45131
45303
|
function boardArgs() {
|
|
@@ -45138,8 +45310,8 @@ function watcherEnv(env2 = process.env) {
|
|
|
45138
45310
|
}
|
|
45139
45311
|
function spawnWatcher(sessionId) {
|
|
45140
45312
|
if (!BUILT) return void 0;
|
|
45141
|
-
|
|
45142
|
-
const out =
|
|
45313
|
+
fs35.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
45314
|
+
const out = fs35.openSync(path38.join(SESSIONS_DIR, `${sessionId}.watch.log`), "a");
|
|
45143
45315
|
try {
|
|
45144
45316
|
const child = spawn2(process.execPath, [SELF, "__watch", sessionId, ...boardArgs()], {
|
|
45145
45317
|
cwd: REPO_ROOT,
|
|
@@ -45155,7 +45327,7 @@ function spawnWatcher(sessionId) {
|
|
|
45155
45327
|
return void 0;
|
|
45156
45328
|
} finally {
|
|
45157
45329
|
try {
|
|
45158
|
-
|
|
45330
|
+
fs35.closeSync(out);
|
|
45159
45331
|
} catch {
|
|
45160
45332
|
}
|
|
45161
45333
|
}
|
|
@@ -45172,11 +45344,11 @@ var init_launch = __esm({
|
|
|
45172
45344
|
});
|
|
45173
45345
|
|
|
45174
45346
|
// src/lib/agent/command.ts
|
|
45175
|
-
import
|
|
45347
|
+
import fs36 from "node:fs";
|
|
45176
45348
|
import path39 from "node:path";
|
|
45177
45349
|
function selfCommand() {
|
|
45178
45350
|
const bin = path39.resolve(path39.dirname(SELF), "..", "bin", "ai4kanban.mjs");
|
|
45179
|
-
const file2 =
|
|
45351
|
+
const file2 = fs36.existsSync(bin) ? bin : SELF;
|
|
45180
45352
|
const inside2 = rel(file2);
|
|
45181
45353
|
const shortHop = !inside2.startsWith("..") && !path39.isAbsolute(inside2) && inside2.split(/[\\/]/).length <= 3;
|
|
45182
45354
|
return `node ${shortHop ? inside2 : file2}`;
|
|
@@ -45190,7 +45362,7 @@ function boardCommandFor(_cardId) {
|
|
|
45190
45362
|
}
|
|
45191
45363
|
function absoluteSelf() {
|
|
45192
45364
|
const bin = path39.resolve(path39.dirname(SELF), "..", "bin", "ai4kanban.mjs");
|
|
45193
|
-
return
|
|
45365
|
+
return fs36.existsSync(bin) ? bin : SELF;
|
|
45194
45366
|
}
|
|
45195
45367
|
function commandNote(command) {
|
|
45196
45368
|
if (command === "akb") return "";
|
|
@@ -45206,13 +45378,13 @@ var init_command = __esm({
|
|
|
45206
45378
|
});
|
|
45207
45379
|
|
|
45208
45380
|
// src/lib/agent/outputs.ts
|
|
45209
|
-
import
|
|
45381
|
+
import fs37 from "node:fs";
|
|
45210
45382
|
import path40 from "node:path";
|
|
45211
45383
|
function cardBody(cardId2) {
|
|
45212
45384
|
const found2 = locate(cardId2) ?? locateArchived(cardId2);
|
|
45213
45385
|
if (!found2) return "";
|
|
45214
45386
|
try {
|
|
45215
|
-
return
|
|
45387
|
+
return fs37.readFileSync(found2.kind === "group" ? path40.join(found2.target, "root.md") : found2.target, "utf8");
|
|
45216
45388
|
} catch {
|
|
45217
45389
|
return "";
|
|
45218
45390
|
}
|
|
@@ -45246,20 +45418,20 @@ var init_outputs = __esm({
|
|
|
45246
45418
|
});
|
|
45247
45419
|
|
|
45248
45420
|
// src/lib/agent/log.ts
|
|
45249
|
-
import
|
|
45421
|
+
import fs38 from "node:fs";
|
|
45250
45422
|
import path41 from "node:path";
|
|
45251
45423
|
function pruneLogs() {
|
|
45252
45424
|
try {
|
|
45253
|
-
const runs =
|
|
45425
|
+
const runs = fs38.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith(".log") && !f.endsWith(".watch.log")).map((f) => ({ id: f.slice(0, -".log".length), t: fs38.statSync(path41.join(SESSIONS_DIR, f)).mtimeMs })).sort((a, b) => b.t - a.t);
|
|
45254
45426
|
const kept2 = new Set(runs.slice(0, KEEP_LOGS).map((r) => r.id));
|
|
45255
45427
|
const drop = new Set(runs.slice(KEEP_LOGS).map((r) => r.id));
|
|
45256
|
-
for (const f of
|
|
45428
|
+
for (const f of fs38.readdirSync(SESSIONS_DIR)) {
|
|
45257
45429
|
const dot = f.indexOf(".");
|
|
45258
45430
|
const id2 = dot === -1 ? f : f.slice(0, dot);
|
|
45259
45431
|
const stray = f.endsWith(".images") && !kept2.has(id2) && !drop.has(id2) && stale2(f);
|
|
45260
45432
|
if (!stray && !drop.has(id2)) continue;
|
|
45261
45433
|
try {
|
|
45262
|
-
|
|
45434
|
+
fs38.rmSync(path41.join(SESSIONS_DIR, f), { recursive: true, force: true });
|
|
45263
45435
|
} catch {
|
|
45264
45436
|
}
|
|
45265
45437
|
}
|
|
@@ -45268,7 +45440,7 @@ function pruneLogs() {
|
|
|
45268
45440
|
}
|
|
45269
45441
|
function stale2(name) {
|
|
45270
45442
|
try {
|
|
45271
|
-
return Date.now() -
|
|
45443
|
+
return Date.now() - fs38.statSync(path41.join(SESSIONS_DIR, name)).mtimeMs > STRAY_MS;
|
|
45272
45444
|
} catch {
|
|
45273
45445
|
return false;
|
|
45274
45446
|
}
|
|
@@ -45295,13 +45467,13 @@ function asContext(v) {
|
|
|
45295
45467
|
function readLogTail(logPath, maxBytes = TAIL_BYTES) {
|
|
45296
45468
|
let fd;
|
|
45297
45469
|
try {
|
|
45298
|
-
const size =
|
|
45470
|
+
const size = fs38.statSync(logPath).size;
|
|
45299
45471
|
const start = Math.max(0, size - maxBytes);
|
|
45300
45472
|
const len = size - start;
|
|
45301
45473
|
if (len === 0) return "";
|
|
45302
|
-
fd =
|
|
45474
|
+
fd = fs38.openSync(logPath, "r");
|
|
45303
45475
|
const buf = Buffer.alloc(len);
|
|
45304
|
-
|
|
45476
|
+
fs38.readSync(fd, buf, 0, len, start);
|
|
45305
45477
|
let text5 = buf.toString("utf8");
|
|
45306
45478
|
if (start > 0) {
|
|
45307
45479
|
const nl = text5.indexOf("\n");
|
|
@@ -45313,7 +45485,7 @@ function readLogTail(logPath, maxBytes = TAIL_BYTES) {
|
|
|
45313
45485
|
} finally {
|
|
45314
45486
|
if (fd !== void 0) {
|
|
45315
45487
|
try {
|
|
45316
|
-
|
|
45488
|
+
fs38.closeSync(fd);
|
|
45317
45489
|
} catch {
|
|
45318
45490
|
}
|
|
45319
45491
|
}
|
|
@@ -45404,7 +45576,7 @@ ${DURATION_MARKER} ${Math.max(0, ms)}
|
|
|
45404
45576
|
});
|
|
45405
45577
|
|
|
45406
45578
|
// src/lib/agent/store.ts
|
|
45407
|
-
import
|
|
45579
|
+
import fs39 from "node:fs";
|
|
45408
45580
|
import path42 from "node:path";
|
|
45409
45581
|
function logPathIn(held4, sessionId) {
|
|
45410
45582
|
return typeof held4 === "string" && held4.startsWith(SESSIONS_DIR + path42.sep) ? held4 : logPathOf(sessionId);
|
|
@@ -45412,7 +45584,7 @@ function logPathIn(held4, sessionId) {
|
|
|
45412
45584
|
function parseStore() {
|
|
45413
45585
|
let data;
|
|
45414
45586
|
try {
|
|
45415
|
-
data = JSON.parse(
|
|
45587
|
+
data = JSON.parse(fs39.readFileSync(SESSIONS, "utf8"));
|
|
45416
45588
|
} catch {
|
|
45417
45589
|
return { runs: [], deliveries: [], marks: {} };
|
|
45418
45590
|
}
|
|
@@ -45446,7 +45618,8 @@ function parseStore() {
|
|
|
45446
45618
|
error: typeof entry.error === "string" ? entry.error : void 0,
|
|
45447
45619
|
failure: readFailure(entry.failure),
|
|
45448
45620
|
validationFailure: readFailure(entry.validationFailure),
|
|
45449
|
-
retryPause: entry.retryPause,
|
|
45621
|
+
retryPause: readRetryPause(entry.retryPause),
|
|
45622
|
+
retryHistory: readRetryHistory(entry.retryHistory),
|
|
45450
45623
|
blocker: readBlocker(entry.blocker),
|
|
45451
45624
|
// A run that never reported a cost shows none, rather than a zero it didn't earn.
|
|
45452
45625
|
costUsd: typeof entry.costUsd === "number" && entry.costUsd >= 0 ? entry.costUsd : void 0,
|
|
@@ -45766,16 +45939,16 @@ function writeStore(store) {
|
|
|
45766
45939
|
marks: store.marks,
|
|
45767
45940
|
...store.refined ? { refined: store.refined } : {}
|
|
45768
45941
|
};
|
|
45769
|
-
|
|
45942
|
+
fs39.mkdirSync(path42.dirname(SESSIONS), { recursive: true });
|
|
45770
45943
|
const tmp = `${SESSIONS}.tmp`;
|
|
45771
|
-
|
|
45772
|
-
|
|
45944
|
+
fs39.writeFileSync(tmp, JSON.stringify(kept2, null, 2) + "\n");
|
|
45945
|
+
fs39.renameSync(tmp, SESSIONS);
|
|
45773
45946
|
forgetFileMemos();
|
|
45774
45947
|
}
|
|
45775
45948
|
function prune(runs, deliveries) {
|
|
45776
45949
|
const held4 = new Set(deliveries.filter(holdsCheckout).map((d) => d.deliveryId));
|
|
45777
45950
|
const live = runs.filter((r) => r.status === "running");
|
|
45778
|
-
const finished = runs.filter((r) => r.status !== "running" && (
|
|
45951
|
+
const finished = runs.filter((r) => r.status !== "running" && (fs39.existsSync(r.logPath) || r.deliveryId && held4.has(r.deliveryId))).sort((a, b) => b.startedAt - a.startedAt).slice(0, KEEP_RUNS);
|
|
45779
45952
|
const spared = runs.filter(
|
|
45780
45953
|
(r) => r.status !== "running" && !finished.includes(r) && (!!r.discardedCards?.length || r.deliveryId && held4.has(r.deliveryId))
|
|
45781
45954
|
);
|
|
@@ -45872,11 +46045,11 @@ var init_store = __esm({
|
|
|
45872
46045
|
});
|
|
45873
46046
|
|
|
45874
46047
|
// src/lib/agent/commit-mode.ts
|
|
45875
|
-
import
|
|
46048
|
+
import fs40 from "node:fs";
|
|
45876
46049
|
function recordedIds() {
|
|
45877
46050
|
try {
|
|
45878
46051
|
return new Set(
|
|
45879
|
-
|
|
46052
|
+
fs40.readdirSync(DELIVERIES).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -".json".length))
|
|
45880
46053
|
);
|
|
45881
46054
|
} catch {
|
|
45882
46055
|
return /* @__PURE__ */ new Set();
|
|
@@ -45909,7 +46082,7 @@ var init_commit_mode = __esm({
|
|
|
45909
46082
|
init_worktree();
|
|
45910
46083
|
ID_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
|
|
45911
46084
|
ID_LENGTH = 8;
|
|
45912
|
-
deliveryCwd = (delivery) => delivery.worktree &&
|
|
46085
|
+
deliveryCwd = (delivery) => delivery.worktree && fs40.existsSync(worktreeDir(delivery.worktree)) ? worktreeDir(delivery.worktree) : REPO_ROOT;
|
|
45913
46086
|
}
|
|
45914
46087
|
});
|
|
45915
46088
|
|
|
@@ -46003,12 +46176,12 @@ var init_runner = __esm({
|
|
|
46003
46176
|
});
|
|
46004
46177
|
|
|
46005
46178
|
// src/lib/agent/rules.ts
|
|
46006
|
-
import
|
|
46179
|
+
import fs41 from "node:fs";
|
|
46007
46180
|
import path43 from "node:path";
|
|
46008
46181
|
function ruleFile(agent) {
|
|
46009
46182
|
if (!agent || hiddenRole(agent)) return "";
|
|
46010
46183
|
try {
|
|
46011
|
-
return
|
|
46184
|
+
return fs41.readFileSync(rulePath(agent), "utf8").trim();
|
|
46012
46185
|
} catch {
|
|
46013
46186
|
return "";
|
|
46014
46187
|
}
|
|
@@ -46073,7 +46246,7 @@ var init_rules2 = __esm({
|
|
|
46073
46246
|
});
|
|
46074
46247
|
|
|
46075
46248
|
// src/lib/agent/deliveries.ts
|
|
46076
|
-
import
|
|
46249
|
+
import fs42 from "node:fs";
|
|
46077
46250
|
import path44 from "node:path";
|
|
46078
46251
|
function writeAudit(delivery, runs) {
|
|
46079
46252
|
const known2 = new Map(readAudit(delivery.deliveryId)?.sessions.map((s) => [s.sessionId, s]) ?? []);
|
|
@@ -46103,10 +46276,10 @@ function writeAudit(delivery, runs) {
|
|
|
46103
46276
|
}
|
|
46104
46277
|
function writeAuditFile(record2) {
|
|
46105
46278
|
try {
|
|
46106
|
-
|
|
46279
|
+
fs42.mkdirSync(DELIVERIES, { recursive: true });
|
|
46107
46280
|
const tmp = `${auditPath(record2.deliveryId)}.tmp`;
|
|
46108
|
-
|
|
46109
|
-
|
|
46281
|
+
fs42.writeFileSync(tmp, JSON.stringify(record2, null, 2) + "\n");
|
|
46282
|
+
fs42.renameSync(tmp, auditPath(record2.deliveryId));
|
|
46110
46283
|
return true;
|
|
46111
46284
|
} catch {
|
|
46112
46285
|
return false;
|
|
@@ -46114,7 +46287,7 @@ function writeAuditFile(record2) {
|
|
|
46114
46287
|
}
|
|
46115
46288
|
function readAudit(deliveryId) {
|
|
46116
46289
|
try {
|
|
46117
|
-
const data = JSON.parse(
|
|
46290
|
+
const data = JSON.parse(fs42.readFileSync(auditPath(deliveryId), "utf8"));
|
|
46118
46291
|
return { sessions: Array.isArray(data?.sessions) ? data.sessions : [] };
|
|
46119
46292
|
} catch {
|
|
46120
46293
|
return null;
|
|
@@ -46129,7 +46302,7 @@ function syncAudit(deliveryId, just) {
|
|
|
46129
46302
|
}
|
|
46130
46303
|
function wholeAudit(file2) {
|
|
46131
46304
|
try {
|
|
46132
|
-
const data = JSON.parse(
|
|
46305
|
+
const data = JSON.parse(fs42.readFileSync(file2, "utf8"));
|
|
46133
46306
|
return typeof data?.deliveryId === "string" && Array.isArray(data.sessions) ? data : null;
|
|
46134
46307
|
} catch {
|
|
46135
46308
|
return null;
|
|
@@ -46142,7 +46315,7 @@ function activeAudit(file2) {
|
|
|
46142
46315
|
function allAudits() {
|
|
46143
46316
|
let names2;
|
|
46144
46317
|
try {
|
|
46145
|
-
names2 =
|
|
46318
|
+
names2 = fs42.readdirSync(DELIVERIES);
|
|
46146
46319
|
} catch {
|
|
46147
46320
|
return [];
|
|
46148
46321
|
}
|
|
@@ -46271,7 +46444,7 @@ function resumeRecord(id2, execution) {
|
|
|
46271
46444
|
const found2 = namedDelivery(id2) ?? endedDelivery(id2);
|
|
46272
46445
|
if (!found2) return { ok: false, ...unknownDelivery(id2) };
|
|
46273
46446
|
const file2 = found2.cardId === null ? null : cardFile(found2.cardId);
|
|
46274
|
-
const restored = file2 && parseFrontmatter(
|
|
46447
|
+
const restored = file2 && parseFrontmatter(fs42.readFileSync(file2, "utf8")).meta?.restored;
|
|
46275
46448
|
if (restored && Date.parse(restored) > found2.startedAt) return { ok: false, ...unknownDelivery(id2) };
|
|
46276
46449
|
if (found2.status === "finished") return { ok: true, delivery: found2 };
|
|
46277
46450
|
const refused = resumeRefusal(found2);
|
|
@@ -46317,7 +46490,7 @@ function approvedRequirements(cardId2) {
|
|
|
46317
46490
|
const file2 = found2.kind === "group" ? path44.join(found2.target, "root.md") : found2.target;
|
|
46318
46491
|
let text5;
|
|
46319
46492
|
try {
|
|
46320
|
-
text5 =
|
|
46493
|
+
text5 = fs42.readFileSync(file2, "utf8");
|
|
46321
46494
|
} catch {
|
|
46322
46495
|
return "";
|
|
46323
46496
|
}
|
|
@@ -46328,7 +46501,7 @@ function cardMeta2(cardId2) {
|
|
|
46328
46501
|
const found2 = locate(cardId2);
|
|
46329
46502
|
if (!found2) return null;
|
|
46330
46503
|
const file2 = found2.kind === "group" ? path44.join(found2.target, "root.md") : found2.target;
|
|
46331
|
-
return parseFrontmatter(
|
|
46504
|
+
return parseFrontmatter(fs42.readFileSync(file2, "utf8")).meta;
|
|
46332
46505
|
} catch {
|
|
46333
46506
|
return null;
|
|
46334
46507
|
}
|
|
@@ -46486,7 +46659,7 @@ var init_deliveries = __esm({
|
|
|
46486
46659
|
activeAudits = () => allAudits().filter((a) => a.status === "active");
|
|
46487
46660
|
auditRow = (audit) => readDeliveryRow({ ...audit, sessions: audit.sessions.map((s) => s.sessionId) });
|
|
46488
46661
|
lastSessionRunning = (audit) => audit.sessions[audit.sessions.length - 1]?.status === "running";
|
|
46489
|
-
localAudit = (audit) => worktreeExists(audit.worktree) || audit.sessions.some((session) => path44.resolve(REPO_ROOT, session.log) === logPathOf(session.sessionId) &&
|
|
46662
|
+
localAudit = (audit) => worktreeExists(audit.worktree) || audit.sessions.some((session) => path44.resolve(REPO_ROOT, session.log) === logPathOf(session.sessionId) && fs42.existsSync(logPathOf(session.sessionId)));
|
|
46490
46663
|
unknownDelivery = (id2) => refusal("deliveryNotFound", `no delivery here answers to "${id2}"`, { id: id2 });
|
|
46491
46664
|
isResumable = (delivery) => !resumeRefusal(delivery);
|
|
46492
46665
|
cardStatus = (cardId2) => cardMeta2(cardId2)?.status || "todo";
|
|
@@ -46817,14 +46990,15 @@ function startableBinary(binary, harness, pinned2 = false) {
|
|
|
46817
46990
|
const note = brokenEntryNote(copy2, own2, harness);
|
|
46818
46991
|
return { binary: spawnName(copy2, own2), ...note ? { note } : {} };
|
|
46819
46992
|
}
|
|
46820
|
-
function readBlock2(harness, block, argv, runtimeId, secretRefs = {}) {
|
|
46993
|
+
function readBlock2(harness, block, argv, runtimeId, secretRefs = {}, executionSecrets) {
|
|
46821
46994
|
const values = {};
|
|
46822
46995
|
const ignored = [];
|
|
46823
46996
|
const secretsSet = [];
|
|
46824
|
-
const env2 = harness.settings.some((s) => s.kind === "secret") ? readEnvFile() : {};
|
|
46997
|
+
const env2 = !executionSecrets && harness.settings.some((s) => s.kind === "secret") ? readEnvFile() : {};
|
|
46825
46998
|
for (const setting of harness.settings) {
|
|
46826
46999
|
if (setting.kind === "secret") {
|
|
46827
|
-
|
|
47000
|
+
const value2 = executionSecrets ? executionSecrets[setting.key] : setting.env && env2[secretRefs[setting.env] ?? secretVar(setting.env, runtimeId)];
|
|
47001
|
+
if (value2) secretsSet.push(setting.key);
|
|
46828
47002
|
continue;
|
|
46829
47003
|
}
|
|
46830
47004
|
const value = block[setting.key]?.trim() ?? "";
|
|
@@ -46841,11 +47015,8 @@ function readBlock2(harness, block, argv, runtimeId, secretRefs = {}) {
|
|
|
46841
47015
|
}
|
|
46842
47016
|
function onOwnEndpoint(runtimeId) {
|
|
46843
47017
|
try {
|
|
46844
|
-
|
|
46845
|
-
|
|
46846
|
-
if (!runtime || !harness) return false;
|
|
46847
|
-
const { values, secretsSet } = readBlock2(harness, runtime.settings, [], runtime.id, runtime.secretRefs);
|
|
46848
|
-
return !!activeProviderOf({ harness, values, secretsSet })?.needs.includes("baseUrl");
|
|
47018
|
+
if (!runtimeId || !runRuntimeById(runtimeId)) return false;
|
|
47019
|
+
return !!activeProviderOf(resolveHarness({ pin: runtimeId }))?.needs.includes("baseUrl");
|
|
46849
47020
|
} catch {
|
|
46850
47021
|
return true;
|
|
46851
47022
|
}
|
|
@@ -46854,12 +47025,15 @@ function resolveHarness(ask2 = {}) {
|
|
|
46854
47025
|
const cfg = safeConfig();
|
|
46855
47026
|
const staleCommand = typeof cfg.command === "string" && cfg.command.trim() ? true : void 0;
|
|
46856
47027
|
const agent = ask2.agent ?? "";
|
|
46857
|
-
const
|
|
46858
|
-
const
|
|
47028
|
+
const execution = executionRuntimes();
|
|
47029
|
+
const scoped = execution && [execution.default, ...Object.values(execution.picks)];
|
|
47030
|
+
const list3 = scoped ?? readRuntimes(cfg);
|
|
46859
47031
|
const owner = agent ? runtimeOwner(agent) : "";
|
|
46860
|
-
const picked = owner ? runtimeOfAgent(owner,
|
|
47032
|
+
const picked = owner ? execution ? execution.picks[owner]?.id : runtimeOfAgent(owner, readAgentRuntime(cfg)) : void 0;
|
|
46861
47033
|
const asked = ask2.pin ?? picked;
|
|
46862
47034
|
const runtime = pickRuntime(list3, asked, ask2.harness);
|
|
47035
|
+
const credentialId = scoped?.find((row) => row === runtime)?.credentialId;
|
|
47036
|
+
const executionSecrets = execution && (credentialId ? readRuntimeCredentials(execution.credentialsFile)[credentialId] ?? {} : {});
|
|
46863
47037
|
const unknownAgentRuntime = picked && !ask2.pin && !list3.some((r) => r.id === picked || r.harness === picked) ? picked : void 0;
|
|
46864
47038
|
const known2 = harnessByName(runtime.harness);
|
|
46865
47039
|
const harness = known2 ?? DEFAULT_HARNESS;
|
|
@@ -46869,7 +47043,8 @@ function resolveHarness(ask2 = {}) {
|
|
|
46869
47043
|
runtime.settings,
|
|
46870
47044
|
splitCommand(command),
|
|
46871
47045
|
runtime.id,
|
|
46872
|
-
runtime.secretRefs
|
|
47046
|
+
runtime.secretRefs,
|
|
47047
|
+
executionSecrets
|
|
46873
47048
|
);
|
|
46874
47049
|
return {
|
|
46875
47050
|
runtime,
|
|
@@ -46880,6 +47055,7 @@ function resolveHarness(ask2 = {}) {
|
|
|
46880
47055
|
unknownAgentRuntime,
|
|
46881
47056
|
values,
|
|
46882
47057
|
secretsSet,
|
|
47058
|
+
executionSecrets,
|
|
46883
47059
|
ignored,
|
|
46884
47060
|
unknownName: known2 ? void 0 : runtime.harness || void 0,
|
|
46885
47061
|
staleCommand
|
|
@@ -46923,6 +47099,7 @@ function settingSaveError(key, value, ask2 = {}) {
|
|
|
46923
47099
|
}
|
|
46924
47100
|
function runEnv2(resolved, cwd = REPO_ROOT) {
|
|
46925
47101
|
const { harness, runtime } = resolved;
|
|
47102
|
+
if (resolved.executionSecrets) return settingEnv(harness, resolved, resolved.executionSecrets, cwd);
|
|
46926
47103
|
const file2 = readEnvFile();
|
|
46927
47104
|
const secrets = {};
|
|
46928
47105
|
for (const setting of harness.settings) {
|
|
@@ -46952,7 +47129,7 @@ function planResume(session, agent, own2 = {}) {
|
|
|
46952
47129
|
if (!harnessByName(harnessName)) return null;
|
|
46953
47130
|
const resolved = resolveHarness({ agent, ...own2, harness: harnessName });
|
|
46954
47131
|
const { harness, command, runtime } = resolved;
|
|
46955
|
-
if (!harness.resumes) return null;
|
|
47132
|
+
if (!harness.resumes || resolved.executionSecrets && !runtime.id) return null;
|
|
46956
47133
|
const argv = splitCommand(command);
|
|
46957
47134
|
return {
|
|
46958
47135
|
harness: harness.name,
|
|
@@ -46971,7 +47148,7 @@ function planFork(session, agent, own2 = {}, sessionId = randomUUID5()) {
|
|
|
46971
47148
|
if (!harnessByName(harnessName)) return null;
|
|
46972
47149
|
const resolved = resolveHarness({ agent, ...own2, harness: harnessName });
|
|
46973
47150
|
const { harness, command, runtime } = resolved;
|
|
46974
|
-
if (!harness.forkArgs || harness.name !== harnessName) return null;
|
|
47151
|
+
if (!harness.forkArgs || harness.name !== harnessName || resolved.executionSecrets && !runtime.id) return null;
|
|
46975
47152
|
const argv = splitCommand(command);
|
|
46976
47153
|
return {
|
|
46977
47154
|
harness: harness.name,
|
|
@@ -47199,31 +47376,31 @@ var init_resolve = __esm({
|
|
|
47199
47376
|
});
|
|
47200
47377
|
|
|
47201
47378
|
// src/lib/agent/pictures.ts
|
|
47202
|
-
import
|
|
47379
|
+
import fs43 from "node:fs";
|
|
47203
47380
|
import path46 from "node:path";
|
|
47204
47381
|
function claimRunPictures(box, sessionId, names2 = []) {
|
|
47205
47382
|
if (!box || !freeBox(box) || names2.length === 0) return [];
|
|
47206
47383
|
const from = pictureBox(box);
|
|
47207
47384
|
const to = pictureBox(sessionId);
|
|
47208
47385
|
try {
|
|
47209
|
-
|
|
47210
|
-
|
|
47386
|
+
fs43.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
47387
|
+
fs43.renameSync(from, to);
|
|
47211
47388
|
} catch {
|
|
47212
47389
|
return [];
|
|
47213
47390
|
}
|
|
47214
|
-
return names2.filter(pictureName).map((name) => path46.join(to, name)).filter((file2) =>
|
|
47391
|
+
return names2.filter(pictureName).map((name) => path46.join(to, name)).filter((file2) => fs43.existsSync(file2));
|
|
47215
47392
|
}
|
|
47216
47393
|
function returnRunPictures(sessionId, box) {
|
|
47217
47394
|
if (!box || !boxId(box)) return;
|
|
47218
47395
|
try {
|
|
47219
|
-
|
|
47396
|
+
fs43.renameSync(pictureBox(sessionId), pictureBox(box));
|
|
47220
47397
|
} catch {
|
|
47221
47398
|
}
|
|
47222
47399
|
}
|
|
47223
47400
|
function moveRunPictures(from, to, files = []) {
|
|
47224
47401
|
if (files.length === 0) return [];
|
|
47225
47402
|
try {
|
|
47226
|
-
|
|
47403
|
+
fs43.renameSync(pictureBox(from), pictureBox(to));
|
|
47227
47404
|
} catch {
|
|
47228
47405
|
return files;
|
|
47229
47406
|
}
|
|
@@ -47236,7 +47413,7 @@ var init_pictures = __esm({
|
|
|
47236
47413
|
init_paths();
|
|
47237
47414
|
pictureName = (name) => /^[0-9a-f-]{36}\.[a-z0-9]{2,5}$/.test(name);
|
|
47238
47415
|
boxId = (box) => /^[0-9a-f-]{36}$/.test(box);
|
|
47239
|
-
freeBox = (box) => boxId(box) && !
|
|
47416
|
+
freeBox = (box) => boxId(box) && !fs43.existsSync(path46.join(SESSIONS_DIR, `${box}.log`));
|
|
47240
47417
|
pictureBox = (box) => path46.join(SESSIONS_DIR, `${box}.images`);
|
|
47241
47418
|
}
|
|
47242
47419
|
});
|
|
@@ -47338,7 +47515,7 @@ var init_facts = __esm({
|
|
|
47338
47515
|
});
|
|
47339
47516
|
|
|
47340
47517
|
// src/lib/view/archive.ts
|
|
47341
|
-
import
|
|
47518
|
+
import fs44 from "node:fs";
|
|
47342
47519
|
import path47 from "node:path";
|
|
47343
47520
|
function archivedId(file2) {
|
|
47344
47521
|
const own2 = idPrefix(path47.basename(file2));
|
|
@@ -47347,7 +47524,7 @@ function archivedId(file2) {
|
|
|
47347
47524
|
function readFile(file2) {
|
|
47348
47525
|
const id2 = archivedId(file2);
|
|
47349
47526
|
if (id2 === null) return null;
|
|
47350
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
47527
|
+
const { meta: meta3, body } = parseFrontmatter(fs44.readFileSync(file2, "utf8"));
|
|
47351
47528
|
if (!meta3) return null;
|
|
47352
47529
|
return {
|
|
47353
47530
|
row: {
|
|
@@ -47363,7 +47540,7 @@ function readFile(file2) {
|
|
|
47363
47540
|
}
|
|
47364
47541
|
function readArchive() {
|
|
47365
47542
|
const relPath = rel(ARCHIVE).split(path47.sep).join("/");
|
|
47366
|
-
if (!
|
|
47543
|
+
if (!fs44.existsSync(ARCHIVE)) return { relPath, cards: [] };
|
|
47367
47544
|
const cards = walkMd(ARCHIVE).map(readFile).filter((found2) => found2 !== null).map((found2) => found2.row);
|
|
47368
47545
|
cards.sort((a, b) => b.id - a.id);
|
|
47369
47546
|
return { relPath, cards };
|
|
@@ -47718,16 +47895,16 @@ var init_prompts = __esm({
|
|
|
47718
47895
|
|
|
47719
47896
|
// src/lib/agent/stop.ts
|
|
47720
47897
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
47721
|
-
import
|
|
47898
|
+
import fs45 from "node:fs";
|
|
47722
47899
|
function markedInProc(entry, strict = false, since) {
|
|
47723
47900
|
const pids = [];
|
|
47724
|
-
for (const name of
|
|
47901
|
+
for (const name of fs45.readdirSync("/proc")) {
|
|
47725
47902
|
if (!/^\d+$/.test(name)) continue;
|
|
47726
47903
|
try {
|
|
47727
|
-
if (
|
|
47904
|
+
if (fs45.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
|
|
47728
47905
|
} catch (error62) {
|
|
47729
47906
|
if (strict && !["ENOENT", "ESRCH"].includes(error62.code ?? "")) {
|
|
47730
|
-
const stat =
|
|
47907
|
+
const stat = fs45.statSync(`/proc/${name}`, { throwIfNoEntry: false });
|
|
47731
47908
|
if (stat?.uid === process.getuid?.() && !startedBefore(Number(name), since)) throw error62;
|
|
47732
47909
|
}
|
|
47733
47910
|
}
|
|
@@ -47937,7 +48114,7 @@ var init_creation_lock = __esm({
|
|
|
47937
48114
|
|
|
47938
48115
|
// src/lib/agent/sessions.ts
|
|
47939
48116
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
47940
|
-
import
|
|
48117
|
+
import fs46 from "node:fs";
|
|
47941
48118
|
import path50 from "node:path";
|
|
47942
48119
|
function reap(runs, reaped = [], restore = []) {
|
|
47943
48120
|
let changed = false;
|
|
@@ -47964,7 +48141,7 @@ function reap(runs, reaped = [], restore = []) {
|
|
|
47964
48141
|
}
|
|
47965
48142
|
function stampDuration(run3, endedAt) {
|
|
47966
48143
|
try {
|
|
47967
|
-
|
|
48144
|
+
fs46.appendFileSync(run3.logPath, durationLine(endedAt - run3.startedAt));
|
|
47968
48145
|
} catch {
|
|
47969
48146
|
}
|
|
47970
48147
|
}
|
|
@@ -47978,7 +48155,7 @@ function cardNow(cardId2) {
|
|
|
47978
48155
|
try {
|
|
47979
48156
|
const file2 = cardFile(cardId2);
|
|
47980
48157
|
if (!file2) return null;
|
|
47981
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
48158
|
+
const { meta: meta3 } = parseFrontmatter(fs46.readFileSync(file2, "utf8"));
|
|
47982
48159
|
if (!meta3) return null;
|
|
47983
48160
|
return { status: meta3.status || "todo", questions: meta3.questions.length, title: meta3.title };
|
|
47984
48161
|
} catch {
|
|
@@ -48223,7 +48400,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said2) {
|
|
|
48223
48400
|
if (retired) return retired;
|
|
48224
48401
|
if (req.deliveryId && findDelivery(req.deliveryId)?.scheduled) return retiredStudioRun("scheduled");
|
|
48225
48402
|
const cardId2 = Number.isInteger(req.id) ? req.id : null;
|
|
48226
|
-
if (req.runtime && !
|
|
48403
|
+
if (req.runtime && !runRuntimeById(req.runtime)) {
|
|
48227
48404
|
const runtimes = readRuntimes().map((r) => r.id).join(", ");
|
|
48228
48405
|
return refusal("runtimeNotFound", `this board has no runtime called "${req.runtime}". It has: ${runtimes}.`, {
|
|
48229
48406
|
id: req.runtime,
|
|
@@ -48246,7 +48423,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said2) {
|
|
|
48246
48423
|
const parent = req.action === "sub" && req.parentId ? peekRun(req.parentId) : void 0;
|
|
48247
48424
|
const cwd = parent?.cwd ?? deliveryCwd(start ?? joining ?? {});
|
|
48248
48425
|
const plan = said2 ? { ...said2.plan(cwd, sessionId), note: null } : planRun(sessionId, cwd, agentForRun(req), req.runtime ? { pin: req.runtime } : {});
|
|
48249
|
-
const away = plan.runtime ?
|
|
48426
|
+
const away = plan.runtime ? runRuntimeById(plan.runtime)?.away : void 0;
|
|
48250
48427
|
if (away) return refusal("runtimeAway", away, { id: plan.runtime });
|
|
48251
48428
|
if (plan.note) notes = [...notes, plan.note];
|
|
48252
48429
|
const record2 = {
|
|
@@ -48317,7 +48494,16 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said2) {
|
|
|
48317
48494
|
}
|
|
48318
48495
|
function planningSession(cardId2, cwd = REPO_ROOT) {
|
|
48319
48496
|
const here = (dir) => !dir || path50.resolve(dir) === cwd;
|
|
48320
|
-
const
|
|
48497
|
+
const safeToContinue = (r) => {
|
|
48498
|
+
if (r.status === "done") return true;
|
|
48499
|
+
if (r.status !== "stopped" && r.status !== "error" && r.status !== "interrupted") return false;
|
|
48500
|
+
if (r.pendingWrites || r.cleanup?.status === "unconfirmed") return false;
|
|
48501
|
+
if (isSessionMissingFailure(r.failure)) return false;
|
|
48502
|
+
const root2 = r.agentPid ? { pid: r.agentPid, since: r.agentStartedAt ?? r.startedAt, identity: r.agentIdentity } : void 0;
|
|
48503
|
+
const stopped2 = r.managedProcess ? connectionStopped(root2) : processesStopped(runMark(r.sessionId, r.agentStartedAt ?? r.startedAt), root2);
|
|
48504
|
+
return stopped2;
|
|
48505
|
+
};
|
|
48506
|
+
const planned = readRuns().filter((r) => r.status !== "running" && r.cardId === cardId2 && PLANNING.has(r.action)).sort((a, b) => b.startedAt - a.startedAt).find((r) => safeToContinue(r) && !!resumeSessionId(r));
|
|
48321
48507
|
if (!planned) return { none: "unrecorded" };
|
|
48322
48508
|
if (!here(planned.cwd)) return { none: "elsewhere" };
|
|
48323
48509
|
const resumeId = resumeSessionId(planned);
|
|
@@ -48405,14 +48591,15 @@ async function openResume(id2, options) {
|
|
|
48405
48591
|
const automatic = typeof options === "object" && options.automatic === true;
|
|
48406
48592
|
const pending = !forced && prev.status !== "stopped" ? prev.retry?.pending : void 0;
|
|
48407
48593
|
if (automatic && !pending) return refusal("runContinued", "The automatic retry is no longer pending.");
|
|
48408
|
-
const
|
|
48594
|
+
const resetReplay = pending?.sessionAction === "reset_replay";
|
|
48595
|
+
const session = forced || resetReplay ? void 0 : resumeSessionId(prev);
|
|
48409
48596
|
if (pending || requireSession) {
|
|
48410
48597
|
const root2 = prev.agentPid ? { pid: prev.agentPid, since: prev.agentStartedAt ?? prev.startedAt, identity: prev.agentIdentity } : void 0;
|
|
48411
48598
|
const stopped2 = prev.managedProcess ? connectionStopped(root2) : processesStopped(runMark(prev.sessionId, prev.agentStartedAt), root2);
|
|
48412
48599
|
const recovery = agentRecovery({
|
|
48413
48600
|
stopped: stopped2,
|
|
48414
48601
|
session,
|
|
48415
|
-
replayable: !requireSession && neverStarted(prev),
|
|
48602
|
+
replayable: !requireSession && (neverStarted(prev) || resetReplay),
|
|
48416
48603
|
unconfirmedCleanup: prev.pendingWrites || prev.cleanup?.status === "unconfirmed" || prev.managedProcess && (pending?.failure ?? prev.failure)?.code === "idle_timeout" && !idleStopConfirmed(prev.cleanup, session)
|
|
48417
48604
|
});
|
|
48418
48605
|
if (recovery === "unsafe") {
|
|
@@ -48427,10 +48614,10 @@ async function openResume(id2, options) {
|
|
|
48427
48614
|
const sessionId = randomUUID6();
|
|
48428
48615
|
let plan;
|
|
48429
48616
|
let fresh;
|
|
48430
|
-
if (!forced && prev.harness === "antigravity" && !session && !neverStarted(prev)) {
|
|
48617
|
+
if (!forced && !resetReplay && prev.harness === "antigravity" && !session && !neverStarted(prev)) {
|
|
48431
48618
|
return refusal("runNoSession", "Antigravity did not record a conversation ID before interruption. The original session cannot be resumed.");
|
|
48432
48619
|
}
|
|
48433
|
-
if (!session && !forced && prev.cardId !== null && !neverStarted(prev)) return refusal("runNoSession", "The original session is unavailable. Explicitly take over the saved task in a new session.");
|
|
48620
|
+
if (!session && !forced && !resetReplay && prev.cardId !== null && !neverStarted(prev)) return refusal("runNoSession", "The original session is unavailable. Explicitly take over the saved task in a new session.");
|
|
48434
48621
|
if (session) {
|
|
48435
48622
|
plan = planResume({ harness: prev.harness, resumeId: session, cwd }, prev.agent, prev.runtime ? { pin: prev.runtime } : {});
|
|
48436
48623
|
} else {
|
|
@@ -48451,12 +48638,12 @@ async function openResume(id2, options) {
|
|
|
48451
48638
|
if ("error" in opened) return opened;
|
|
48452
48639
|
if (!opened.spec.prompt && buildResume) opened.spec.prompt = buildResume;
|
|
48453
48640
|
if (build?.notes?.trim()) opened.spec.prompt = [opened.spec.prompt || resumePrompt(prev.deliveryId, prev.action), build.notes.trim()].join("\n\n");
|
|
48454
|
-
if (session &&
|
|
48641
|
+
if (session && requireSession && !pending) opened.spec.prompt = [recoveryPrompt, opened.spec.prompt].filter(Boolean).join("\n\n");
|
|
48455
48642
|
if (build || buildResume || pending || requireSession) writeSpec(opened.spec);
|
|
48456
48643
|
return opened;
|
|
48457
48644
|
}
|
|
48458
48645
|
async function planRetry2(prev, ask2, sessionId, cwd) {
|
|
48459
|
-
const runtime = prev.runtime &&
|
|
48646
|
+
const runtime = prev.runtime && runRuntimeById(prev.runtime) ? prev.runtime : void 0;
|
|
48460
48647
|
const { note, ...plan } = planRun(sessionId, cwd, prev.agent ?? agentForRun(ask2), {
|
|
48461
48648
|
...runtime ? { pin: runtime } : {},
|
|
48462
48649
|
...shipsHarness(prev.harness) ? { harness: prev.harness } : {}
|
|
@@ -48506,6 +48693,7 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh, automatic = fa
|
|
|
48506
48693
|
},
|
|
48507
48694
|
failure: automatic ? prev.retry?.pending?.failure : void 0,
|
|
48508
48695
|
retry: prev.retry ? { ...prev.retry, pending: void 0, launching: automatic ? true : void 0 } : void 0,
|
|
48696
|
+
...prev.retryHistory?.length ? { retryHistory: prev.retryHistory } : {},
|
|
48509
48697
|
logPath: logPathOf(sessionId),
|
|
48510
48698
|
specAgent: prev.specAgent,
|
|
48511
48699
|
cards: prev.cards,
|
|
@@ -48570,14 +48758,14 @@ function askForRefine(sessionId, ask2) {
|
|
|
48570
48758
|
}
|
|
48571
48759
|
function clearAsks(sessionId) {
|
|
48572
48760
|
try {
|
|
48573
|
-
|
|
48761
|
+
fs46.unlinkSync(asksPathOf(sessionId));
|
|
48574
48762
|
} catch {
|
|
48575
48763
|
}
|
|
48576
48764
|
}
|
|
48577
48765
|
function readAsks(sessionId) {
|
|
48578
48766
|
let data;
|
|
48579
48767
|
try {
|
|
48580
|
-
data = JSON.parse(
|
|
48768
|
+
data = JSON.parse(fs46.readFileSync(asksPathOf(sessionId), "utf8"));
|
|
48581
48769
|
} catch {
|
|
48582
48770
|
return { refines: [] };
|
|
48583
48771
|
}
|
|
@@ -48594,10 +48782,10 @@ function readAsks(sessionId) {
|
|
|
48594
48782
|
return { refines: refines.filter((a) => !discarded.has(a.cardId)) };
|
|
48595
48783
|
}
|
|
48596
48784
|
function writeAsks(sessionId, file2) {
|
|
48597
|
-
|
|
48785
|
+
fs46.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
48598
48786
|
const tmp = `${asksPathOf(sessionId)}.tmp`;
|
|
48599
|
-
|
|
48600
|
-
|
|
48787
|
+
fs46.writeFileSync(tmp, JSON.stringify(file2, null, 2) + "\n");
|
|
48788
|
+
fs46.renameSync(tmp, asksPathOf(sessionId));
|
|
48601
48789
|
}
|
|
48602
48790
|
function markSpawned(sessionId, pid) {
|
|
48603
48791
|
patch(sessionId, (r) => {
|
|
@@ -48624,6 +48812,7 @@ async function closeRun(sessionId, res) {
|
|
|
48624
48812
|
if (res.error) run3.error = res.error;
|
|
48625
48813
|
run3.failure = res.failure;
|
|
48626
48814
|
run3.retryPause = res.retryPause;
|
|
48815
|
+
if (res.retryHistory?.length) run3.retryHistory = res.retryHistory;
|
|
48627
48816
|
if (run3.retry) {
|
|
48628
48817
|
delete run3.retry.launching;
|
|
48629
48818
|
if (res.status === "stopped") delete run3.retry.pending;
|
|
@@ -48752,7 +48941,7 @@ async function reconcileCardDelivery(cardId2) {
|
|
|
48752
48941
|
result = withStore((store) => {
|
|
48753
48942
|
reap(store.runs, reaped, restore);
|
|
48754
48943
|
const file2 = cardFile(cardId2);
|
|
48755
|
-
const restoredRaw = file2 ? parseFrontmatter(
|
|
48944
|
+
const restoredRaw = file2 ? parseFrontmatter(fs46.readFileSync(file2, "utf8")).meta?.restored : void 0;
|
|
48756
48945
|
const restoredAt = restoredRaw ? Date.parse(restoredRaw) : Number.NaN;
|
|
48757
48946
|
const merged = /* @__PURE__ */ new Map();
|
|
48758
48947
|
for (const audit of cardAudits(cardId2)) merged.set(audit.deliveryId, audit);
|
|
@@ -48880,12 +49069,12 @@ async function resumeDelivery(id2) {
|
|
|
48880
49069
|
return { ok: true, deliveryId: delivery.deliveryId, carryOn };
|
|
48881
49070
|
}
|
|
48882
49071
|
function writeSpec(spec) {
|
|
48883
|
-
|
|
48884
|
-
|
|
49072
|
+
fs46.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
49073
|
+
fs46.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
|
|
48885
49074
|
}
|
|
48886
49075
|
function readSpec(sessionId) {
|
|
48887
49076
|
try {
|
|
48888
|
-
const spec = JSON.parse(
|
|
49077
|
+
const spec = JSON.parse(fs46.readFileSync(specPathOf(sessionId), "utf8"));
|
|
48889
49078
|
return spec && Array.isArray(spec.plan?.argv) ? spec : null;
|
|
48890
49079
|
} catch {
|
|
48891
49080
|
return null;
|
|
@@ -48893,7 +49082,7 @@ function readSpec(sessionId) {
|
|
|
48893
49082
|
}
|
|
48894
49083
|
function dropSpec(sessionId) {
|
|
48895
49084
|
try {
|
|
48896
|
-
|
|
49085
|
+
fs46.unlinkSync(specPathOf(sessionId));
|
|
48897
49086
|
} catch {
|
|
48898
49087
|
}
|
|
48899
49088
|
}
|
|
@@ -48903,18 +49092,18 @@ async function acquireIndexLock(giveUp) {
|
|
|
48903
49092
|
for (; ; ) {
|
|
48904
49093
|
if (giveUp()) return null;
|
|
48905
49094
|
try {
|
|
48906
|
-
|
|
48907
|
-
|
|
48908
|
-
return () =>
|
|
49095
|
+
fs46.mkdirSync(INDEX_LOCK2, { recursive: false });
|
|
49096
|
+
fs46.writeFileSync(holder, String(process.pid));
|
|
49097
|
+
return () => fs46.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
48909
49098
|
} catch (err) {
|
|
48910
49099
|
const code = err.code;
|
|
48911
49100
|
if (code === "ENOENT") {
|
|
48912
|
-
|
|
49101
|
+
fs46.mkdirSync(path50.dirname(INDEX_LOCK2), { recursive: true });
|
|
48913
49102
|
continue;
|
|
48914
49103
|
}
|
|
48915
49104
|
if (code !== "EEXIST") throw err;
|
|
48916
49105
|
if (!pidAlive(Number(readHolder(holder)))) {
|
|
48917
|
-
|
|
49106
|
+
fs46.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
48918
49107
|
continue;
|
|
48919
49108
|
}
|
|
48920
49109
|
if (Date.now() > until) return null;
|
|
@@ -48924,7 +49113,7 @@ async function acquireIndexLock(giveUp) {
|
|
|
48924
49113
|
}
|
|
48925
49114
|
function readHolder(file2) {
|
|
48926
49115
|
try {
|
|
48927
|
-
return
|
|
49116
|
+
return fs46.readFileSync(file2, "utf8").trim();
|
|
48928
49117
|
} catch {
|
|
48929
49118
|
return String(process.pid);
|
|
48930
49119
|
}
|
|
@@ -49063,7 +49252,7 @@ var init_sources = __esm({
|
|
|
49063
49252
|
});
|
|
49064
49253
|
|
|
49065
49254
|
// src/lib/signals/inbox.ts
|
|
49066
|
-
import
|
|
49255
|
+
import fs47 from "node:fs";
|
|
49067
49256
|
import path51 from "node:path";
|
|
49068
49257
|
function metaPair(key, value) {
|
|
49069
49258
|
const name = typeof key === "string" ? key.trim() : "";
|
|
@@ -49095,7 +49284,7 @@ ${signal2.summary.trim()}
|
|
|
49095
49284
|
function parse3(file2, lenient = false) {
|
|
49096
49285
|
let text5;
|
|
49097
49286
|
try {
|
|
49098
|
-
text5 =
|
|
49287
|
+
text5 = fs47.readFileSync(file2, "utf8");
|
|
49099
49288
|
} catch {
|
|
49100
49289
|
return null;
|
|
49101
49290
|
}
|
|
@@ -49150,13 +49339,13 @@ function freeName(dir, wanted) {
|
|
|
49150
49339
|
const ext = path51.extname(wanted);
|
|
49151
49340
|
const stem = wanted.slice(0, wanted.length - ext.length);
|
|
49152
49341
|
let name = wanted;
|
|
49153
|
-
for (let n = 2;
|
|
49342
|
+
for (let n = 2; fs47.existsSync(path51.join(dir, name)); n++) name = `${stem}-${n}${ext}`;
|
|
49154
49343
|
return name;
|
|
49155
49344
|
}
|
|
49156
49345
|
function readFolder(dir, lenient = false) {
|
|
49157
49346
|
let entries2;
|
|
49158
49347
|
try {
|
|
49159
|
-
entries2 =
|
|
49348
|
+
entries2 = fs47.readdirSync(dir, { withFileTypes: true });
|
|
49160
49349
|
} catch {
|
|
49161
49350
|
return [];
|
|
49162
49351
|
}
|
|
@@ -49168,7 +49357,7 @@ function readInbox() {
|
|
|
49168
49357
|
return signals;
|
|
49169
49358
|
}
|
|
49170
49359
|
function writeSignal(incoming, importedAt, slug = "") {
|
|
49171
|
-
|
|
49360
|
+
fs47.mkdirSync(TRIAGE, { recursive: true });
|
|
49172
49361
|
const signal2 = {
|
|
49173
49362
|
...incoming,
|
|
49174
49363
|
importedAt,
|
|
@@ -49181,11 +49370,11 @@ function writeSignal(incoming, importedAt, slug = "") {
|
|
|
49181
49370
|
relPath: ""
|
|
49182
49371
|
};
|
|
49183
49372
|
const file2 = path51.join(TRIAGE, freeName(TRIAGE, fileName(signal2.title, slug)));
|
|
49184
|
-
|
|
49373
|
+
fs47.writeFileSync(file2, serialize({ ...signal2, relPath: boardRel(file2) }));
|
|
49185
49374
|
return { ...signal2, relPath: boardRel(file2) };
|
|
49186
49375
|
}
|
|
49187
49376
|
function stamp3(file2, fields2) {
|
|
49188
|
-
const text5 =
|
|
49377
|
+
const text5 = fs47.readFileSync(file2, "utf8");
|
|
49189
49378
|
const lines = text5.split("\n");
|
|
49190
49379
|
const close = lines.indexOf("---", 1);
|
|
49191
49380
|
if (close < 0) return;
|
|
@@ -49194,13 +49383,13 @@ function stamp3(file2, fields2) {
|
|
|
49194
49383
|
return !key || fields2[key[1]] === void 0;
|
|
49195
49384
|
});
|
|
49196
49385
|
const added = Object.entries(fields2).flatMap(([key, value]) => value === null ? [] : [`${key}: ${yamlScalar(value)}`]);
|
|
49197
|
-
|
|
49386
|
+
fs47.writeFileSync(file2, ["---", ...kept2, ...added, ...lines.slice(close)].join("\n"));
|
|
49198
49387
|
}
|
|
49199
49388
|
function moveSignal(from, into, fields2) {
|
|
49200
|
-
if (!
|
|
49201
|
-
|
|
49389
|
+
if (!fs47.existsSync(from)) return "";
|
|
49390
|
+
fs47.mkdirSync(into, { recursive: true });
|
|
49202
49391
|
const at = path51.join(into, freeName(into, path51.basename(from)));
|
|
49203
|
-
|
|
49392
|
+
fs47.renameSync(from, at);
|
|
49204
49393
|
stamp3(at, fields2);
|
|
49205
49394
|
return boardRel(at);
|
|
49206
49395
|
}
|
|
@@ -49236,6 +49425,54 @@ var init_inbox = __esm({
|
|
|
49236
49425
|
}
|
|
49237
49426
|
});
|
|
49238
49427
|
|
|
49428
|
+
// src/lib/question-ops.ts
|
|
49429
|
+
function questionPositions(raw, count3, flag) {
|
|
49430
|
+
const ns = String(raw).split(",").map((s) => s.trim()).filter((s) => s.length > 0).map(Number);
|
|
49431
|
+
if (ns.length === 0 || ns.some((n) => !Number.isInteger(n) || n < 1)) {
|
|
49432
|
+
throw new QuestionOpError(`--${flag} needs one or more 1-based question numbers (e.g. 1 or 1,3)`);
|
|
49433
|
+
}
|
|
49434
|
+
const over = ns.find((n) => n > count3);
|
|
49435
|
+
if (over !== void 0) throw new QuestionOpError(`the card has ${count3} open question(s) \u2014 there's no question ${over}`);
|
|
49436
|
+
return ns;
|
|
49437
|
+
}
|
|
49438
|
+
function applyQuestionOps(start, ops, asker) {
|
|
49439
|
+
let questions = [...start];
|
|
49440
|
+
const changes = [];
|
|
49441
|
+
const closed2 = [];
|
|
49442
|
+
const positions = (op, flag) => questionPositions(op.ns ?? String(op.n), questions.length, flag);
|
|
49443
|
+
for (const op of ops) {
|
|
49444
|
+
if (op.kind === "clear") {
|
|
49445
|
+
closed2.push(...questions);
|
|
49446
|
+
questions = [];
|
|
49447
|
+
changes.push("cleared");
|
|
49448
|
+
} else if (op.kind === "drop") {
|
|
49449
|
+
const ns = positions(op, "drop");
|
|
49450
|
+
closed2.push(...ns.map((n) => questions[n - 1]));
|
|
49451
|
+
questions = questions.filter((_, i) => !ns.includes(i + 1));
|
|
49452
|
+
changes.push(`dropped ${ns.join(",")}`);
|
|
49453
|
+
} else if (op.kind === "append") {
|
|
49454
|
+
const agent = op.question.agent ?? asker;
|
|
49455
|
+
questions.push(agent ? { ...op.question, agent } : op.question);
|
|
49456
|
+
changes.push("appended");
|
|
49457
|
+
} else {
|
|
49458
|
+
const [n] = positions(op, "update");
|
|
49459
|
+
const agent = op.question.agent ?? questions[n - 1].agent;
|
|
49460
|
+
questions[n - 1] = { ...op.question, ...agent ? { agent } : {} };
|
|
49461
|
+
changes.push(`rewrote ${n}`);
|
|
49462
|
+
}
|
|
49463
|
+
}
|
|
49464
|
+
return { questions, changes, closed: closed2 };
|
|
49465
|
+
}
|
|
49466
|
+
var QUESTION_EDIT_LIMITS, QuestionOpError;
|
|
49467
|
+
var init_question_ops = __esm({
|
|
49468
|
+
"src/lib/question-ops.ts"() {
|
|
49469
|
+
"use strict";
|
|
49470
|
+
QUESTION_EDIT_LIMITS = { operations: 50, text: 4e3, options: 20, option: 200 };
|
|
49471
|
+
QuestionOpError = class extends Error {
|
|
49472
|
+
};
|
|
49473
|
+
}
|
|
49474
|
+
});
|
|
49475
|
+
|
|
49239
49476
|
// src/lib/questions.ts
|
|
49240
49477
|
function newDraft(flag, value) {
|
|
49241
49478
|
const text5 = value.trim();
|
|
@@ -49290,7 +49527,7 @@ function missingChoices(text5) {
|
|
|
49290
49527
|
`"${text5}" needs choices to tick \u2014 add 2 or more --option "a \u2014 why". The user always gets a free-text choice too, so never write one yourself.`
|
|
49291
49528
|
);
|
|
49292
49529
|
}
|
|
49293
|
-
function readQuestionOps(typed) {
|
|
49530
|
+
function readQuestionOps(typed, compatibility = false) {
|
|
49294
49531
|
const ops = [];
|
|
49295
49532
|
for (let i = 0; i < typed.length; i++) {
|
|
49296
49533
|
const [key, value] = typed[i];
|
|
@@ -49316,71 +49553,40 @@ function readQuestionOps(typed) {
|
|
|
49316
49553
|
if (!ops.length) {
|
|
49317
49554
|
die('update-questions needs at least one op: --append ".." | --update <n> ".." | --drop n[,n...] | --clear');
|
|
49318
49555
|
}
|
|
49556
|
+
if (!compatibility && ops.length > QUESTION_EDIT_LIMITS.operations) {
|
|
49557
|
+
die(`Submit at most ${QUESTION_EDIT_LIMITS.operations} edits at a time.`);
|
|
49558
|
+
}
|
|
49319
49559
|
for (const op of ops) {
|
|
49320
49560
|
if (op.draft) {
|
|
49561
|
+
if (!compatibility) validateQuestionEdit(op.draft);
|
|
49321
49562
|
op.question = finalizeDraft(op.draft);
|
|
49322
49563
|
delete op.draft;
|
|
49323
49564
|
}
|
|
49324
49565
|
}
|
|
49325
49566
|
return ops;
|
|
49326
49567
|
}
|
|
49568
|
+
function validateQuestionEdit(draft) {
|
|
49569
|
+
const { text: text5, option, options } = QUESTION_EDIT_LIMITS;
|
|
49570
|
+
if (Buffer.byteLength(draft.question) > text5) die(`Question text must be at most ${text5} bytes.`);
|
|
49571
|
+
if (draft.options.length > options) die(`A question can have at most ${options} choices.`);
|
|
49572
|
+
if (draft.options.some((choice) => Buffer.byteLength(choice) > option)) die(`Each choice must be at most ${option} bytes.`);
|
|
49573
|
+
if (draft.recommended.length > 1) die("A question takes at most one --recommended-option.");
|
|
49574
|
+
if (draft.agent && (draft.agent.length > 64 || !AGENT_NAME.test(draft.agent))) {
|
|
49575
|
+
die("--agent must be at most 64 characters with lowercase letters or digits joined by hyphens.");
|
|
49576
|
+
}
|
|
49577
|
+
}
|
|
49327
49578
|
var init_questions = __esm({
|
|
49328
49579
|
"src/lib/questions.ts"() {
|
|
49329
49580
|
"use strict";
|
|
49330
49581
|
init_paths();
|
|
49582
|
+
init_parse3();
|
|
49583
|
+
init_question_ops();
|
|
49331
49584
|
init_question_block();
|
|
49332
49585
|
init_question_block();
|
|
49333
49586
|
init_rules();
|
|
49334
49587
|
}
|
|
49335
49588
|
});
|
|
49336
49589
|
|
|
49337
|
-
// src/lib/question-ops.ts
|
|
49338
|
-
function questionPositions(raw, count3, flag) {
|
|
49339
|
-
const ns = String(raw).split(",").map((s) => s.trim()).filter((s) => s.length > 0).map(Number);
|
|
49340
|
-
if (ns.length === 0 || ns.some((n) => !Number.isInteger(n) || n < 1)) {
|
|
49341
|
-
throw new QuestionOpError(`--${flag} needs one or more 1-based question numbers (e.g. 1 or 1,3)`);
|
|
49342
|
-
}
|
|
49343
|
-
const over = ns.find((n) => n > count3);
|
|
49344
|
-
if (over !== void 0) throw new QuestionOpError(`the card has ${count3} open question(s) \u2014 there's no question ${over}`);
|
|
49345
|
-
return ns;
|
|
49346
|
-
}
|
|
49347
|
-
function applyQuestionOps(start, ops, asker) {
|
|
49348
|
-
let questions = [...start];
|
|
49349
|
-
const changes = [];
|
|
49350
|
-
const closed2 = [];
|
|
49351
|
-
const positions = (op, flag) => questionPositions(op.ns ?? String(op.n), questions.length, flag);
|
|
49352
|
-
for (const op of ops) {
|
|
49353
|
-
if (op.kind === "clear") {
|
|
49354
|
-
closed2.push(...questions);
|
|
49355
|
-
questions = [];
|
|
49356
|
-
changes.push("cleared");
|
|
49357
|
-
} else if (op.kind === "drop") {
|
|
49358
|
-
const ns = positions(op, "drop");
|
|
49359
|
-
closed2.push(...ns.map((n) => questions[n - 1]));
|
|
49360
|
-
questions = questions.filter((_, i) => !ns.includes(i + 1));
|
|
49361
|
-
changes.push(`dropped ${ns.join(",")}`);
|
|
49362
|
-
} else if (op.kind === "append") {
|
|
49363
|
-
const agent = op.question.agent ?? asker;
|
|
49364
|
-
questions.push(agent ? { ...op.question, agent } : op.question);
|
|
49365
|
-
changes.push("appended");
|
|
49366
|
-
} else {
|
|
49367
|
-
const [n] = positions(op, "update");
|
|
49368
|
-
const agent = op.question.agent ?? questions[n - 1].agent;
|
|
49369
|
-
questions[n - 1] = { ...op.question, ...agent ? { agent } : {} };
|
|
49370
|
-
changes.push(`rewrote ${n}`);
|
|
49371
|
-
}
|
|
49372
|
-
}
|
|
49373
|
-
return { questions, changes, closed: closed2 };
|
|
49374
|
-
}
|
|
49375
|
-
var QuestionOpError;
|
|
49376
|
-
var init_question_ops = __esm({
|
|
49377
|
-
"src/lib/question-ops.ts"() {
|
|
49378
|
-
"use strict";
|
|
49379
|
-
QuestionOpError = class extends Error {
|
|
49380
|
-
};
|
|
49381
|
-
}
|
|
49382
|
-
});
|
|
49383
|
-
|
|
49384
49590
|
// src/lib/source.ts
|
|
49385
49591
|
function parseSourceRef(raw) {
|
|
49386
49592
|
const text5 = raw.trim();
|
|
@@ -49431,12 +49637,12 @@ var init_studio_cards = __esm({
|
|
|
49431
49637
|
});
|
|
49432
49638
|
|
|
49433
49639
|
// src/lib/readme.ts
|
|
49434
|
-
import
|
|
49640
|
+
import fs48 from "node:fs";
|
|
49435
49641
|
import path52 from "node:path";
|
|
49436
49642
|
function stripReadmeRefs(target) {
|
|
49437
|
-
if (!
|
|
49643
|
+
if (!fs48.existsSync(README)) return [];
|
|
49438
49644
|
const needle = target.kind === "group" ? `](${target.rel}/` : `](${target.rel})`;
|
|
49439
|
-
const lines =
|
|
49645
|
+
const lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49440
49646
|
const out = [];
|
|
49441
49647
|
const removed = [];
|
|
49442
49648
|
let i = 0;
|
|
@@ -49458,20 +49664,20 @@ function stripReadmeRefs(target) {
|
|
|
49458
49664
|
out.push(line);
|
|
49459
49665
|
i++;
|
|
49460
49666
|
}
|
|
49461
|
-
if (removed.length)
|
|
49667
|
+
if (removed.length) fs48.writeFileSync(README, out.join("\n"));
|
|
49462
49668
|
return removed;
|
|
49463
49669
|
}
|
|
49464
49670
|
function addReadmeRef(id2, title, relPath) {
|
|
49465
|
-
if (!
|
|
49671
|
+
if (!fs48.existsSync(README)) return false;
|
|
49466
49672
|
const link2 = relPath.split(path52.sep).join("/");
|
|
49467
49673
|
const bullet = `- [#${id2} ${title}](${link2})`;
|
|
49468
49674
|
const heading = `## ${TASKS_HEADING}`;
|
|
49469
|
-
let lines =
|
|
49675
|
+
let lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49470
49676
|
const hi = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
|
|
49471
49677
|
if (hi === -1) {
|
|
49472
49678
|
while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
|
|
49473
49679
|
lines.push("", heading, "", bullet);
|
|
49474
|
-
|
|
49680
|
+
fs48.writeFileSync(README, lines.join("\n") + "\n");
|
|
49475
49681
|
return true;
|
|
49476
49682
|
}
|
|
49477
49683
|
let end2 = hi + 1;
|
|
@@ -49485,15 +49691,15 @@ function addReadmeRef(id2, title, relPath) {
|
|
|
49485
49691
|
const at = lastBullet !== -1 ? lastBullet + 1 : lines[hi + 1] === "" ? hi + 2 : hi + 1;
|
|
49486
49692
|
lines.splice(at, 0, bullet);
|
|
49487
49693
|
}
|
|
49488
|
-
|
|
49694
|
+
fs48.writeFileSync(README, lines.join("\n"));
|
|
49489
49695
|
return true;
|
|
49490
49696
|
}
|
|
49491
49697
|
function repointReadmeLink(id2, oldRel, newRel, title) {
|
|
49492
|
-
if (!
|
|
49698
|
+
if (!fs48.existsSync(README)) return false;
|
|
49493
49699
|
const oldLink = oldRel.split(path52.sep).join("/");
|
|
49494
49700
|
const newLink = newRel.split(path52.sep).join("/");
|
|
49495
49701
|
const linkRe = new RegExp(`\\[#${id2}\\b[^\\]]*\\]\\(${escapeRegex2(oldLink)}\\)`);
|
|
49496
|
-
const lines =
|
|
49702
|
+
const lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49497
49703
|
let changed = false;
|
|
49498
49704
|
for (let i = 0; i < lines.length; i++) {
|
|
49499
49705
|
if (!lines[i].includes(`](${oldLink})`)) continue;
|
|
@@ -49503,7 +49709,7 @@ function repointReadmeLink(id2, oldRel, newRel, title) {
|
|
|
49503
49709
|
changed = true;
|
|
49504
49710
|
}
|
|
49505
49711
|
}
|
|
49506
|
-
if (changed)
|
|
49712
|
+
if (changed) fs48.writeFileSync(README, lines.join("\n"));
|
|
49507
49713
|
return changed;
|
|
49508
49714
|
}
|
|
49509
49715
|
var isTableRow, isBulletStart, bulletIndent, TASKS_HEADING, escapeRegex2;
|
|
@@ -50042,6 +50248,37 @@ var init_manifest = __esm({
|
|
|
50042
50248
|
}
|
|
50043
50249
|
});
|
|
50044
50250
|
|
|
50251
|
+
// ../artifact-sdk/src/internal/file-references.ts
|
|
50252
|
+
function splitFileReference(src) {
|
|
50253
|
+
const end2 = src.search(/[?#]/);
|
|
50254
|
+
return end2 < 0 ? [src, ""] : [src.slice(0, end2), src.slice(end2)];
|
|
50255
|
+
}
|
|
50256
|
+
function relativeFileReference(src, owner) {
|
|
50257
|
+
const parts = owner.split("/").slice(0, -1);
|
|
50258
|
+
for (const part of src.split("/")) {
|
|
50259
|
+
if (part === ".." && parts.length && parts.at(-1) !== "..") parts.pop();
|
|
50260
|
+
else if (part && part !== ".") parts.push(part);
|
|
50261
|
+
}
|
|
50262
|
+
return parts.join("/");
|
|
50263
|
+
}
|
|
50264
|
+
var CSS, fileManifest;
|
|
50265
|
+
var init_file_references = __esm({
|
|
50266
|
+
"../artifact-sdk/src/internal/file-references.ts"() {
|
|
50267
|
+
"use strict";
|
|
50268
|
+
init_manifest();
|
|
50269
|
+
CSS = {
|
|
50270
|
+
name: "css",
|
|
50271
|
+
types: ["css"],
|
|
50272
|
+
references: [
|
|
50273
|
+
{ text: `@import\\s+["']([^"']+)["']` },
|
|
50274
|
+
{ text: `url\\(\\s*["']?([^"')]+?)["']?\\s*\\)` }
|
|
50275
|
+
],
|
|
50276
|
+
skip: ["/\\*[\\s\\S]*?\\*/"]
|
|
50277
|
+
};
|
|
50278
|
+
fileManifest = (type, name) => type === "asset" && /\.css$/i.test(name) ? CSS : manifestOf(type);
|
|
50279
|
+
}
|
|
50280
|
+
});
|
|
50281
|
+
|
|
50045
50282
|
// ../artifact-sdk/src/internal/collect.ts
|
|
50046
50283
|
function collect(body, card, host2) {
|
|
50047
50284
|
return collectSources(bodyReferences(body), card, host2);
|
|
@@ -50051,7 +50288,7 @@ function collectSources(sources2, card, host2) {
|
|
|
50051
50288
|
const active3 = /* @__PURE__ */ new Set();
|
|
50052
50289
|
const out = [];
|
|
50053
50290
|
const visit2 = (src, types, owner, partial2 = false) => {
|
|
50054
|
-
const path88 = src
|
|
50291
|
+
const [path88] = splitFileReference(src);
|
|
50055
50292
|
let resolved;
|
|
50056
50293
|
try {
|
|
50057
50294
|
resolved = host2.resolve(path88, owner);
|
|
@@ -50101,13 +50338,13 @@ function collectSources(sources2, card, host2) {
|
|
|
50101
50338
|
} else {
|
|
50102
50339
|
node2.kind = textKind(extOf(file2), types);
|
|
50103
50340
|
try {
|
|
50104
|
-
if (
|
|
50341
|
+
if (fileManifest(node2.kind, file2)?.references) node2.data = host2.read(file2);
|
|
50105
50342
|
} catch (error62) {
|
|
50106
50343
|
node2.problems.push({ src: file2, message: why(error62) });
|
|
50107
50344
|
}
|
|
50108
50345
|
}
|
|
50109
50346
|
node2.error = node2.problems[0]?.message;
|
|
50110
|
-
if (!node2.error) for (const ref of referencesOf(
|
|
50347
|
+
if (!node2.error) for (const ref of referencesOf(fileManifest(node2.kind, file2), node2.data)) child(ref, file2);
|
|
50111
50348
|
} else {
|
|
50112
50349
|
for (const ref of host2.retained(key, types)) child(ref, card);
|
|
50113
50350
|
}
|
|
@@ -50134,6 +50371,7 @@ var extOf, why, textKind, kindAt;
|
|
|
50134
50371
|
var init_collect = __esm({
|
|
50135
50372
|
"../artifact-sdk/src/internal/collect.ts"() {
|
|
50136
50373
|
"use strict";
|
|
50374
|
+
init_file_references();
|
|
50137
50375
|
init_manifest();
|
|
50138
50376
|
init_references();
|
|
50139
50377
|
extOf = (file2) => /\.[^./\\]+$/.exec(file2)?.[0].toLowerCase() ?? "";
|
|
@@ -50147,16 +50385,16 @@ var init_collect = __esm({
|
|
|
50147
50385
|
});
|
|
50148
50386
|
|
|
50149
50387
|
// src/lib/dress-page.ts
|
|
50150
|
-
import
|
|
50388
|
+
import fs49 from "node:fs";
|
|
50151
50389
|
import path53 from "node:path";
|
|
50152
50390
|
function dressPage(file2) {
|
|
50153
50391
|
const folder2 = path53.dirname(file2);
|
|
50154
|
-
const html =
|
|
50392
|
+
const html = fs49.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
|
|
50155
50393
|
const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
|
|
50156
50394
|
if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
|
|
50157
50395
|
const at2 = path53.resolve(folder2, href);
|
|
50158
|
-
if (!at2.startsWith(folder2 + path53.sep) || !
|
|
50159
|
-
const css =
|
|
50396
|
+
if (!at2.startsWith(folder2 + path53.sep) || !fs49.existsSync(at2)) return tag;
|
|
50397
|
+
const css = fs49.readFileSync(at2, "utf8").replace(/url\(\s*(["']?)([^"')]+?)\1\s*\)/gi, (whole2, quote, src) => /^(?:[a-z][\w+.-]*:|\/|#)/i.test(src) ? whole2 : `url(${quote}${path53.relative(folder2, path53.resolve(path53.dirname(at2), src)).split(path53.sep).join("/")}${quote})`);
|
|
50160
50398
|
return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
|
|
50161
50399
|
});
|
|
50162
50400
|
const at = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
|
|
@@ -50169,25 +50407,25 @@ var init_dress_page = __esm({
|
|
|
50169
50407
|
isHtmlFile = (file2) => /\.html?$/i.test(file2);
|
|
50170
50408
|
CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:; font-src data: blob:; worker-src 'none'; base-uri 'none'; form-action 'none'";
|
|
50171
50409
|
head = `<meta http-equiv="Content-Security-Policy" content="${CSP}"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><style>html{overflow-x:hidden;overscroll-behavior:contain}</style>`;
|
|
50172
|
-
referenceText = (file2) => isHtmlFile(file2) ? dressPage(file2) :
|
|
50410
|
+
referenceText = (file2) => isHtmlFile(file2) ? dressPage(file2) : fs49.readFileSync(file2, "utf8");
|
|
50173
50411
|
}
|
|
50174
50412
|
});
|
|
50175
50413
|
|
|
50176
50414
|
// src/lib/preview-files.ts
|
|
50177
|
-
import
|
|
50415
|
+
import fs50 from "node:fs";
|
|
50178
50416
|
import path54 from "node:path";
|
|
50179
50417
|
function resolver(card, id2) {
|
|
50180
50418
|
const roots = [KANBAN, path54.join(ASSETS, String(id2))];
|
|
50181
|
-
const real2 = (p) =>
|
|
50419
|
+
const real2 = (p) => fs50.existsSync(p) ? fs50.realpathSync(p) : p;
|
|
50182
50420
|
const inside2 = (p) => roots.some((root2) => p.startsWith(real2(root2) + path54.sep));
|
|
50183
50421
|
return (src, owner) => {
|
|
50184
50422
|
if (/^[a-z][\w+.-]*:/i.test(src) || src.startsWith("#") || src.startsWith("//")) return null;
|
|
50185
50423
|
if (path54.isAbsolute(src)) throw new Error("an absolute path; name it relative to the file");
|
|
50186
50424
|
const held4 = /^\.assets\//.exec(src);
|
|
50187
50425
|
const file2 = held4 ? path54.resolve(ASSETS, src.slice(held4[0].length)) : path54.resolve(path54.dirname(owner), src);
|
|
50188
|
-
if (!inside2(path54.resolve(file2)) ||
|
|
50189
|
-
if (!
|
|
50190
|
-
return { key:
|
|
50426
|
+
if (!inside2(path54.resolve(file2)) || fs50.existsSync(file2) && !inside2(fs50.realpathSync(file2))) throw new Error(`outside this card's files (${rel(KANBAN)}, .assets/${id2}/)`);
|
|
50427
|
+
if (!fs50.statSync(file2, { throwIfNoEntry: false })?.isFile()) throw new Error("no such file");
|
|
50428
|
+
return { key: fs50.realpathSync(file2), file: file2 };
|
|
50191
50429
|
};
|
|
50192
50430
|
}
|
|
50193
50431
|
function validatePreviewFiles(card, id2, text5) {
|
|
@@ -50230,7 +50468,7 @@ var init_preview_files = __esm({
|
|
|
50230
50468
|
});
|
|
50231
50469
|
|
|
50232
50470
|
// src/lib/spec-contract.ts
|
|
50233
|
-
import
|
|
50471
|
+
import fs51 from "node:fs";
|
|
50234
50472
|
import path55 from "node:path";
|
|
50235
50473
|
function scanCardLines(lines, start = 0) {
|
|
50236
50474
|
const visible = lines.map(() => "");
|
|
@@ -50264,11 +50502,11 @@ function scanCardLines(lines, start = 0) {
|
|
|
50264
50502
|
}
|
|
50265
50503
|
function snapshotSpecs() {
|
|
50266
50504
|
const out = /* @__PURE__ */ new Map();
|
|
50267
|
-
if (!
|
|
50505
|
+
if (!fs51.existsSync(TODO)) return out;
|
|
50268
50506
|
for (const file2 of walkMd(TODO)) {
|
|
50269
50507
|
if (isLegacyRecurring(path55.relative(TODO, file2))) continue;
|
|
50270
50508
|
const id2 = idPrefix(path55.basename(file2) === "root.md" ? path55.basename(path55.dirname(file2)) : path55.basename(file2));
|
|
50271
|
-
if (id2 !== null) out.set(file2, { id: id2, text:
|
|
50509
|
+
if (id2 !== null) out.set(file2, { id: id2, text: fs51.readFileSync(file2, "utf8") });
|
|
50272
50510
|
}
|
|
50273
50511
|
return out;
|
|
50274
50512
|
}
|
|
@@ -50462,9 +50700,9 @@ function setEnd(lines, at) {
|
|
|
50462
50700
|
}
|
|
50463
50701
|
function inside(dir, name) {
|
|
50464
50702
|
try {
|
|
50465
|
-
const root2 =
|
|
50466
|
-
const real2 =
|
|
50467
|
-
return real2.startsWith(root2 + path55.sep) &&
|
|
50703
|
+
const root2 = fs51.realpathSync(dir);
|
|
50704
|
+
const real2 = fs51.realpathSync(path55.join(dir, name));
|
|
50705
|
+
return real2.startsWith(root2 + path55.sep) && fs51.statSync(real2).isFile() ? real2 : null;
|
|
50468
50706
|
} catch {
|
|
50469
50707
|
return null;
|
|
50470
50708
|
}
|
|
@@ -50497,7 +50735,7 @@ function compareProblem(attrs, id2) {
|
|
|
50497
50735
|
const shots = (message) => ({ rule: "compare-shots", message });
|
|
50498
50736
|
const json2 = (file2) => {
|
|
50499
50737
|
try {
|
|
50500
|
-
return file2.endsWith(".json") ? JSON.parse(
|
|
50738
|
+
return file2.endsWith(".json") ? JSON.parse(fs51.readFileSync(file2, "utf8")) : null;
|
|
50501
50739
|
} catch {
|
|
50502
50740
|
return null;
|
|
50503
50741
|
}
|
|
@@ -50522,7 +50760,7 @@ function compareProblem(attrs, id2) {
|
|
|
50522
50760
|
const file2 = inside(dir, named2.name);
|
|
50523
50761
|
if (!file2) return { message: `Compare shots ${at} names no file in this card's asset folder. Write the JSON there or fix the path.` };
|
|
50524
50762
|
try {
|
|
50525
|
-
return { data: JSON.parse(
|
|
50763
|
+
return { data: JSON.parse(fs51.readFileSync(file2, "utf8")) };
|
|
50526
50764
|
} catch {
|
|
50527
50765
|
return { message: `${at} is not valid JSON.` };
|
|
50528
50766
|
}
|
|
@@ -50577,7 +50815,7 @@ var init_spec_contract = __esm({
|
|
|
50577
50815
|
});
|
|
50578
50816
|
|
|
50579
50817
|
// src/lib/reconcile.ts
|
|
50580
|
-
import
|
|
50818
|
+
import fs52 from "node:fs";
|
|
50581
50819
|
import path56 from "node:path";
|
|
50582
50820
|
function liveIds() {
|
|
50583
50821
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -50593,7 +50831,7 @@ function indexableCards() {
|
|
|
50593
50831
|
const out = [];
|
|
50594
50832
|
for (const dir of walkDirs(TODO)) {
|
|
50595
50833
|
const id2 = idPrefix(path56.basename(dir));
|
|
50596
|
-
if (id2 != null &&
|
|
50834
|
+
if (id2 != null && fs52.existsSync(path56.join(dir, "root.md"))) {
|
|
50597
50835
|
out.push({ id: id2, rel: path56.join(path56.relative(TODO, dir), "root.md").split(path56.sep).join("/") });
|
|
50598
50836
|
}
|
|
50599
50837
|
}
|
|
@@ -50610,7 +50848,7 @@ function indexableCards() {
|
|
|
50610
50848
|
}
|
|
50611
50849
|
function readmeComplaints(fix) {
|
|
50612
50850
|
const said2 = [];
|
|
50613
|
-
const lines =
|
|
50851
|
+
const lines = fs52.readFileSync(README, "utf8").split("\n");
|
|
50614
50852
|
const indexed = /* @__PURE__ */ new Set();
|
|
50615
50853
|
let fixed = 0;
|
|
50616
50854
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -50619,7 +50857,7 @@ function readmeComplaints(fix) {
|
|
|
50619
50857
|
const id2 = Number(m[1]);
|
|
50620
50858
|
const linkPath = m[2];
|
|
50621
50859
|
indexed.add(id2);
|
|
50622
|
-
if (
|
|
50860
|
+
if (fs52.existsSync(path56.join(TODO, linkPath))) continue;
|
|
50623
50861
|
const found2 = locate(id2);
|
|
50624
50862
|
if (!found2) {
|
|
50625
50863
|
said2.push(`README links #${id2} \u2192 ${linkPath}, but no card with that id exists (removed by hand?). Drop the entry or restore the file.`);
|
|
@@ -50635,7 +50873,7 @@ function readmeComplaints(fix) {
|
|
|
50635
50873
|
said2.push(`README link #${id2} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
|
|
50636
50874
|
fixed++;
|
|
50637
50875
|
}
|
|
50638
|
-
if (fixed)
|
|
50876
|
+
if (fixed) fs52.writeFileSync(README, lines.join("\n"));
|
|
50639
50877
|
for (const c of indexableCards()) {
|
|
50640
50878
|
if (!indexed.has(c.id)) {
|
|
50641
50879
|
said2.push(`card ${c.rel} (#${c.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
|
|
@@ -50651,7 +50889,7 @@ function crossRefComplaints() {
|
|
|
50651
50889
|
if (base === "README.md") continue;
|
|
50652
50890
|
const ownerId = base === "root.md" ? idPrefix(path56.basename(path56.dirname(file2))) : idPrefix(base);
|
|
50653
50891
|
if (ownerId == null) continue;
|
|
50654
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
50892
|
+
const { meta: meta3 } = parseFrontmatter(fs52.readFileSync(file2, "utf8"));
|
|
50655
50893
|
if (!meta3) continue;
|
|
50656
50894
|
for (const field2 of ["blocked_by", "related"]) {
|
|
50657
50895
|
for (const ref of meta3[field2] || []) {
|
|
@@ -50664,7 +50902,7 @@ function crossRefComplaints() {
|
|
|
50664
50902
|
return said2;
|
|
50665
50903
|
}
|
|
50666
50904
|
function reconcileBoard() {
|
|
50667
|
-
if (!
|
|
50905
|
+
if (!fs52.existsSync(README)) return;
|
|
50668
50906
|
for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
|
|
50669
50907
|
}
|
|
50670
50908
|
var README_LINK;
|
|
@@ -50680,7 +50918,7 @@ var init_reconcile = __esm({
|
|
|
50680
50918
|
});
|
|
50681
50919
|
|
|
50682
50920
|
// src/commands/card.ts
|
|
50683
|
-
import
|
|
50921
|
+
import fs53 from "node:fs";
|
|
50684
50922
|
import path57 from "node:path";
|
|
50685
50923
|
function defaultBody(summary2 = "<\u7528\u4E00\u5C0F\u6BB5\u8BDD\u5148\u8BB2\u53D1\u751F\u4E86\u4EC0\u4E48\u3001\u7528\u6237\u9047\u5230\u4EC0\u4E48\uFF0C\u518D\u8BB2\u8FD9\u5F20\u5361\u8981\u8FBE\u5230\u7684\u7ED3\u679C\u3002>") {
|
|
50686
50924
|
return [
|
|
@@ -50707,7 +50945,7 @@ function bodyFromFile(opts) {
|
|
|
50707
50945
|
if (opts.body === false) die("pass --body-file or --no-body, not both");
|
|
50708
50946
|
let text5;
|
|
50709
50947
|
try {
|
|
50710
|
-
text5 =
|
|
50948
|
+
text5 = fs53.readFileSync(opts.bodyFile, "utf8");
|
|
50711
50949
|
} catch {
|
|
50712
50950
|
die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
|
|
50713
50951
|
}
|
|
@@ -50779,12 +51017,12 @@ function cmdCreate(opts) {
|
|
|
50779
51017
|
return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
|
|
50780
51018
|
}
|
|
50781
51019
|
if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
|
|
50782
|
-
if (
|
|
51020
|
+
if (fs53.existsSync(file2)) die(`${rel(file2)} already exists \u2014 pick a different --slug`);
|
|
50783
51021
|
countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
|
|
50784
51022
|
const meta3 = { title, priority, status: "todo", blocked_by, related, modules, studio, previews, triage, source: source2, questions };
|
|
50785
51023
|
const scaffolded = !written && opts.body !== false;
|
|
50786
51024
|
const body = written ?? (scaffolded ? defaultBody() : "");
|
|
50787
|
-
|
|
51025
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n\n" + body);
|
|
50788
51026
|
const indexed = addReadmeRef(start, title, fileRel);
|
|
50789
51027
|
say(start);
|
|
50790
51028
|
say(
|
|
@@ -50837,7 +51075,7 @@ function cmdUpdate(id2, flags) {
|
|
|
50837
51075
|
const found2 = locate(id2);
|
|
50838
51076
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
50839
51077
|
const file2 = found2.kind === "group" ? path57.join(found2.target, "root.md") : found2.target;
|
|
50840
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51078
|
+
const { meta: meta3, body } = parseFrontmatter(fs53.readFileSync(file2, "utf8"));
|
|
50841
51079
|
if (!meta3) die(`${rel(file2)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
|
|
50842
51080
|
if (flags.blockedBy !== void 0 && flags.addBlockedBy !== void 0) die("--blocked-by replaces the list and --add-blocked-by appends to it \u2014 pass one");
|
|
50843
51081
|
if (flags.related !== void 0 && flags.addRelated !== void 0) die("--related replaces the list and --add-related appends to it \u2014 pass one");
|
|
@@ -50913,9 +51151,9 @@ function cmdUpdate(id2, flags) {
|
|
|
50913
51151
|
const destRel = path57.join(path57.dirname(curRel), base);
|
|
50914
51152
|
const dest = path57.join(TODO, destRel);
|
|
50915
51153
|
const moving = dest !== file2;
|
|
50916
|
-
if (moving &&
|
|
50917
|
-
|
|
50918
|
-
if (moving)
|
|
51154
|
+
if (moving && fs53.existsSync(dest)) die(`${rel(dest)} already exists`);
|
|
51155
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n" + body);
|
|
51156
|
+
if (moving) fs53.renameSync(file2, dest);
|
|
50919
51157
|
if (isSubtask) {
|
|
50920
51158
|
if (moving || changes.includes("title")) repointReadmeLink(id2, curRel, destRel, meta3.title);
|
|
50921
51159
|
if (moving) changes.push(`renamed \u2192 ${destRel.split(path57.sep).join("/")}`);
|
|
@@ -50931,14 +51169,16 @@ function cmdUpdate(id2, flags) {
|
|
|
50931
51169
|
return { id: id2, changes, file: rel(dest) };
|
|
50932
51170
|
}
|
|
50933
51171
|
function cmdUpdateQuestions(id2, input2) {
|
|
50934
|
-
|
|
51172
|
+
return updateCardQuestions(id2, readQuestionOps(input2.ops ?? [], true), true);
|
|
51173
|
+
}
|
|
51174
|
+
function updateCardQuestions(id2, ops, compatibility = false) {
|
|
50935
51175
|
const found2 = locate(id2);
|
|
50936
51176
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
50937
51177
|
const file2 = found2.kind === "group" ? path57.join(found2.target, "root.md") : found2.target;
|
|
50938
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51178
|
+
const { meta: meta3, body } = parseFrontmatter(fs53.readFileSync(file2, "utf8"));
|
|
50939
51179
|
if (!meta3) die(`${rel(file2)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
|
|
50940
51180
|
for (const op of ops) {
|
|
50941
|
-
if (!op.question?.agent) continue;
|
|
51181
|
+
if (!compatibility || !op.question?.agent) continue;
|
|
50942
51182
|
const agent = findSpecAgent(op.question.agent);
|
|
50943
51183
|
if (!agent) die(`--agent "${op.question.agent}" is not an agent on this board`, { kind: "no-such-spec-agent", specAgent: op.question.agent });
|
|
50944
51184
|
op.question.agent = agent.name;
|
|
@@ -50957,7 +51197,7 @@ function cmdUpdateQuestions(id2, input2) {
|
|
|
50957
51197
|
meta3.status = "todo";
|
|
50958
51198
|
changes.push("status\u2192todo (open questions)");
|
|
50959
51199
|
}
|
|
50960
|
-
|
|
51200
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n" + body);
|
|
50961
51201
|
const closed2 = activeDelivery(id2) ? "questions_closed_verify" : "questions_closed_user";
|
|
50962
51202
|
for (const _ of done.closed) countBoardEvent(closed2);
|
|
50963
51203
|
say(`updated #${id2} questions: ${changes.join(", ")} (${open4} open)`);
|
|
@@ -51016,7 +51256,7 @@ var init_config_template = __esm({
|
|
|
51016
51256
|
});
|
|
51017
51257
|
|
|
51018
51258
|
// src/commands/init.ts
|
|
51019
|
-
import
|
|
51259
|
+
import fs54 from "node:fs";
|
|
51020
51260
|
function boardReadme() {
|
|
51021
51261
|
return `# Board
|
|
51022
51262
|
|
|
@@ -51029,20 +51269,20 @@ _(none)_
|
|
|
51029
51269
|
`;
|
|
51030
51270
|
}
|
|
51031
51271
|
function writeConfigIfMissing() {
|
|
51032
|
-
if (
|
|
51033
|
-
|
|
51034
|
-
|
|
51272
|
+
if (fs54.existsSync(CONFIG)) return false;
|
|
51273
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51274
|
+
fs54.writeFileSync(CONFIG, CONFIG_TEMPLATE);
|
|
51035
51275
|
return true;
|
|
51036
51276
|
}
|
|
51037
51277
|
function writeModulesIfMissing() {
|
|
51038
|
-
if (
|
|
51039
|
-
|
|
51040
|
-
|
|
51278
|
+
if (fs54.existsSync(MODULES_MD)) return false;
|
|
51279
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51280
|
+
fs54.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
|
|
51041
51281
|
return true;
|
|
51042
51282
|
}
|
|
51043
51283
|
function writeGitignoreIfMissing() {
|
|
51044
|
-
|
|
51045
|
-
const text5 =
|
|
51284
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51285
|
+
const text5 = fs54.existsSync(KANBAN_GITIGNORE) ? fs54.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
|
|
51046
51286
|
const has = (rule) => text5.split("\n").some((line) => line.trim() === rule.line);
|
|
51047
51287
|
const missing = IGNORE_RULES.filter((rule) => !has(rule));
|
|
51048
51288
|
if (!missing.length) return false;
|
|
@@ -51050,23 +51290,23 @@ function writeGitignoreIfMissing() {
|
|
|
51050
51290
|
${rule.line}
|
|
51051
51291
|
`).join("");
|
|
51052
51292
|
const separator = !text5 || text5.endsWith("\n") ? "" : "\n";
|
|
51053
|
-
|
|
51293
|
+
fs54.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
|
|
51054
51294
|
return true;
|
|
51055
51295
|
}
|
|
51056
51296
|
function writeSkeletonIfMissing() {
|
|
51057
51297
|
const added = [];
|
|
51058
|
-
if (!
|
|
51059
|
-
|
|
51298
|
+
if (!fs54.existsSync(TODO)) {
|
|
51299
|
+
fs54.mkdirSync(TODO, { recursive: true });
|
|
51060
51300
|
added.push(`${rel(TODO)}/`);
|
|
51061
51301
|
}
|
|
51062
|
-
if (!
|
|
51063
|
-
|
|
51302
|
+
if (!fs54.existsSync(README)) {
|
|
51303
|
+
fs54.writeFileSync(README, boardReadme());
|
|
51064
51304
|
added.push(rel(README));
|
|
51065
51305
|
}
|
|
51066
51306
|
return added;
|
|
51067
51307
|
}
|
|
51068
51308
|
function cmdInit() {
|
|
51069
|
-
if (
|
|
51309
|
+
if (fs54.existsSync(KANBAN)) {
|
|
51070
51310
|
const added = [
|
|
51071
51311
|
...writeSkeletonIfMissing(),
|
|
51072
51312
|
writeConfigIfMissing() && rel(CONFIG),
|
|
@@ -51083,8 +51323,8 @@ function cmdInit() {
|
|
|
51083
51323
|
}
|
|
51084
51324
|
return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
|
|
51085
51325
|
}
|
|
51086
|
-
|
|
51087
|
-
|
|
51326
|
+
fs54.mkdirSync(TODO, { recursive: true });
|
|
51327
|
+
fs54.writeFileSync(README, boardReadme());
|
|
51088
51328
|
writeConfigIfMissing();
|
|
51089
51329
|
scaffoldProjectMemory();
|
|
51090
51330
|
writeModulesIfMissing();
|
|
@@ -51119,15 +51359,15 @@ _(not filled in yet \u2014 build the map from the repo before tagging a card.)_
|
|
|
51119
51359
|
});
|
|
51120
51360
|
|
|
51121
51361
|
// src/lib/card-age.ts
|
|
51122
|
-
import
|
|
51362
|
+
import fs55 from "node:fs";
|
|
51123
51363
|
import path58 from "node:path";
|
|
51124
51364
|
function staleAfterIn(config2) {
|
|
51125
51365
|
const days = Number(LINE.exec(config2)?.[1]);
|
|
51126
51366
|
return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
|
|
51127
51367
|
}
|
|
51128
51368
|
function staleAfter() {
|
|
51129
|
-
if (!
|
|
51130
|
-
return staleAfterIn(
|
|
51369
|
+
if (!fs55.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
|
|
51370
|
+
return staleAfterIn(fs55.readFileSync(CONFIG, "utf8"));
|
|
51131
51371
|
}
|
|
51132
51372
|
function todoPathspec(top) {
|
|
51133
51373
|
const from = path58.relative(real(top), real(TODO));
|
|
@@ -51184,7 +51424,7 @@ var init_card_age = __esm({
|
|
|
51184
51424
|
gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
|
|
51185
51425
|
real = (p) => {
|
|
51186
51426
|
try {
|
|
51187
|
-
return
|
|
51427
|
+
return fs55.realpathSync(p);
|
|
51188
51428
|
} catch {
|
|
51189
51429
|
return path58.resolve(p);
|
|
51190
51430
|
}
|
|
@@ -51220,7 +51460,7 @@ var init_card_holds = __esm({
|
|
|
51220
51460
|
});
|
|
51221
51461
|
|
|
51222
51462
|
// src/commands/list.ts
|
|
51223
|
-
import
|
|
51463
|
+
import fs56 from "node:fs";
|
|
51224
51464
|
import path59 from "node:path";
|
|
51225
51465
|
function summaryLine(body) {
|
|
51226
51466
|
const lines = body.split("\n");
|
|
@@ -51243,7 +51483,7 @@ function openRows() {
|
|
|
51243
51483
|
const id2 = isRoot ? idPrefix(path59.basename(path59.dirname(file2))) : idPrefix(base);
|
|
51244
51484
|
if (id2 == null) continue;
|
|
51245
51485
|
if (isLegacyRecurring(path59.relative(TODO, file2))) continue;
|
|
51246
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51486
|
+
const { meta: meta3, body } = parseFrontmatter(fs56.readFileSync(file2, "utf8"));
|
|
51247
51487
|
rows.push({
|
|
51248
51488
|
id: id2,
|
|
51249
51489
|
file: file2,
|
|
@@ -51285,7 +51525,7 @@ function cmdStale(rows, all2, scope, mod) {
|
|
|
51285
51525
|
}
|
|
51286
51526
|
function archivedFiles() {
|
|
51287
51527
|
const files = /* @__PURE__ */ new Map();
|
|
51288
|
-
if (!
|
|
51528
|
+
if (!fs56.existsSync(ARCHIVE)) return files;
|
|
51289
51529
|
for (const file2 of walkMd(ARCHIVE)) {
|
|
51290
51530
|
const id2 = idPrefix(path59.basename(file2));
|
|
51291
51531
|
if (id2 !== null) files.set(id2, file2);
|
|
@@ -51293,7 +51533,7 @@ function archivedFiles() {
|
|
|
51293
51533
|
for (const dir of walkDirs(ARCHIVE)) {
|
|
51294
51534
|
const id2 = idPrefix(path59.basename(dir));
|
|
51295
51535
|
const root2 = path59.join(dir, "root.md");
|
|
51296
|
-
if (id2 !== null &&
|
|
51536
|
+
if (id2 !== null && fs56.existsSync(root2)) files.set(id2, root2);
|
|
51297
51537
|
}
|
|
51298
51538
|
return files;
|
|
51299
51539
|
}
|
|
@@ -51391,10 +51631,10 @@ var init_list = __esm({
|
|
|
51391
51631
|
});
|
|
51392
51632
|
|
|
51393
51633
|
// src/lib/group-close.ts
|
|
51394
|
-
import
|
|
51634
|
+
import fs57 from "node:fs";
|
|
51395
51635
|
function groupCloses(rootFile) {
|
|
51396
51636
|
try {
|
|
51397
|
-
return groupCloseOf(
|
|
51637
|
+
return groupCloseOf(fs57.readFileSync(rootFile, "utf8"));
|
|
51398
51638
|
} catch {
|
|
51399
51639
|
return false;
|
|
51400
51640
|
}
|
|
@@ -51407,7 +51647,7 @@ var init_group_close = __esm({
|
|
|
51407
51647
|
});
|
|
51408
51648
|
|
|
51409
51649
|
// src/commands/remove.ts
|
|
51410
|
-
import
|
|
51650
|
+
import fs58 from "node:fs";
|
|
51411
51651
|
import path60 from "node:path";
|
|
51412
51652
|
function leavingIds(id2, found2) {
|
|
51413
51653
|
const ids = /* @__PURE__ */ new Set([id2]);
|
|
@@ -51424,10 +51664,10 @@ function findMentions(ids) {
|
|
|
51424
51664
|
const hits = [];
|
|
51425
51665
|
const re = new RegExp(ids.map((id2) => `#${id2}(?!\\d)`).join("|"));
|
|
51426
51666
|
for (const dir of [TODO, MEMORY]) {
|
|
51427
|
-
if (!
|
|
51667
|
+
if (!fs58.existsSync(dir)) continue;
|
|
51428
51668
|
for (const file2 of walkMd(dir)) {
|
|
51429
51669
|
if (path60.basename(file2) === "README.md") continue;
|
|
51430
|
-
const lines =
|
|
51670
|
+
const lines = fs58.readFileSync(file2, "utf8").split("\n");
|
|
51431
51671
|
const fmEnd = frontmatterEnd(lines);
|
|
51432
51672
|
lines.forEach((line, i) => {
|
|
51433
51673
|
if (!re.test(line)) return;
|
|
@@ -51457,10 +51697,10 @@ function stampLeaving(cards, rejection) {
|
|
|
51457
51697
|
const day = formatDay();
|
|
51458
51698
|
const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() || workspaceTask() ? "agent" : "user" } : rejection && { reason: rejection.reason };
|
|
51459
51699
|
for (const card of cards) {
|
|
51460
|
-
if (!
|
|
51461
|
-
const text5 =
|
|
51700
|
+
if (!fs58.existsSync(card.file)) continue;
|
|
51701
|
+
const text5 = fs58.readFileSync(card.file, "utf8");
|
|
51462
51702
|
const stamped = stampLeavingIn(text5, day, stamp4);
|
|
51463
|
-
if (stamped !== text5)
|
|
51703
|
+
if (stamped !== text5) fs58.writeFileSync(card.file, stamped);
|
|
51464
51704
|
}
|
|
51465
51705
|
}
|
|
51466
51706
|
function agentDecisions(text5) {
|
|
@@ -51490,14 +51730,14 @@ function removeCard(id2, metric, options) {
|
|
|
51490
51730
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
51491
51731
|
const dest = options.cleanupDiscarded && locateArchived(id2) ? null : archiveDest(found2);
|
|
51492
51732
|
const cardFile3 = found2.kind === "group" ? path60.join(found2.target, "root.md") : found2.target;
|
|
51493
|
-
const cardText =
|
|
51733
|
+
const cardText = fs58.existsSync(cardFile3) ? fs58.readFileSync(cardFile3, "utf8") : "";
|
|
51494
51734
|
const { meta: cardMeta3 } = parseFrontmatter(cardText);
|
|
51495
51735
|
const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f) => f !== cardFile3).map((f) => rel(f)).sort() : [];
|
|
51496
51736
|
const leftIds = leavingIds(id2, found2);
|
|
51497
51737
|
const leaving = leavingCards(id2, found2);
|
|
51498
51738
|
if (options.archivingTask) {
|
|
51499
51739
|
for (const card of leaving) {
|
|
51500
|
-
const meta3 = parseFrontmatter(
|
|
51740
|
+
const meta3 = parseFrontmatter(fs58.readFileSync(card.file, "utf8")).meta;
|
|
51501
51741
|
if (!meta3 || meta3.rejected) die(`#${card.id} is not eligible for archive.`, { kind: "conflict" });
|
|
51502
51742
|
if (meta3.questions.length) die(`Resolve the open questions on #${card.id} before archiving.`, { kind: "conflict" });
|
|
51503
51743
|
if (card.id !== id2 && (activeDelivery(card.id) || creationRefusal(card.id, cardCreation(card.id), "archive", false))) {
|
|
@@ -51531,10 +51771,10 @@ function removeCard(id2, metric, options) {
|
|
|
51531
51771
|
const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
|
|
51532
51772
|
if (dest) {
|
|
51533
51773
|
stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
|
|
51534
|
-
|
|
51535
|
-
|
|
51774
|
+
fs58.mkdirSync(ARCHIVE, { recursive: true });
|
|
51775
|
+
fs58.renameSync(found2.target, dest);
|
|
51536
51776
|
} else {
|
|
51537
|
-
|
|
51777
|
+
fs58.rmSync(found2.target, { recursive: true, force: true });
|
|
51538
51778
|
}
|
|
51539
51779
|
const removedRefs = stripReadmeRefs(found2);
|
|
51540
51780
|
let marked2 = null;
|
|
@@ -51590,7 +51830,7 @@ function closeGroup(rootFile) {
|
|
|
51590
51830
|
say(`
|
|
51591
51831
|
every subtask line on #${rootId} is resolved \u2014 closing the group:`);
|
|
51592
51832
|
try {
|
|
51593
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51833
|
+
const { meta: meta3, body } = parseFrontmatter(fs58.readFileSync(rootFile, "utf8"));
|
|
51594
51834
|
const res = cmdRemove(rootId, "completed", { closing: true });
|
|
51595
51835
|
return {
|
|
51596
51836
|
id: rootId,
|
|
@@ -51634,7 +51874,7 @@ next \u2014 what the script can't do:
|
|
|
51634
51874
|
}
|
|
51635
51875
|
if (mentions.some((m) => m.where !== "body")) {
|
|
51636
51876
|
say(" A mention in frontmatter is the script's to rewrite, not yours:");
|
|
51637
|
-
say(' `update-questions <
|
|
51877
|
+
say(' `akb task update-questions <task> --update <n> "..."` (see help).');
|
|
51638
51878
|
}
|
|
51639
51879
|
return note;
|
|
51640
51880
|
}
|
|
@@ -51654,7 +51894,7 @@ function recoveredArchiveHandoff(id2, source2) {
|
|
|
51654
51894
|
const found2 = locateArchived(id2);
|
|
51655
51895
|
if (!found2) throw new Error(`No archived card #${id2} was found.`);
|
|
51656
51896
|
const file2 = found2.kind === "group" ? path60.join(found2.target, "root.md") : found2.target;
|
|
51657
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
51897
|
+
const { meta: meta3 } = parseFrontmatter(fs58.readFileSync(file2, "utf8"));
|
|
51658
51898
|
stripReadmeRefs(source2 ?? found2);
|
|
51659
51899
|
const root2 = source2?.kind === "file" ? enclosingGroupRoot(source2.target) : null;
|
|
51660
51900
|
if (root2) markSubtask(root2, id2, "tick");
|
|
@@ -51773,7 +52013,7 @@ var init_bundled2 = __esm({
|
|
|
51773
52013
|
});
|
|
51774
52014
|
|
|
51775
52015
|
// src/lib/memories.ts
|
|
51776
|
-
import
|
|
52016
|
+
import fs59 from "node:fs";
|
|
51777
52017
|
import path61 from "node:path";
|
|
51778
52018
|
function readMemory(text5, builtIn, folder2) {
|
|
51779
52019
|
const { meta: meta3, body } = splitFrontmatter(text5);
|
|
@@ -51805,14 +52045,14 @@ function globalMemories() {
|
|
|
51805
52045
|
}
|
|
51806
52046
|
let folders2 = [];
|
|
51807
52047
|
try {
|
|
51808
|
-
folders2 =
|
|
52048
|
+
folders2 = fs59.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
51809
52049
|
} catch {
|
|
51810
52050
|
}
|
|
51811
52051
|
for (const name of folders2) {
|
|
51812
52052
|
if (name in BUNDLED_MEMORY_FILES || name === RESERVED_MEMORY_DIR || name === STUDIO_MEMORY_DIR) continue;
|
|
51813
52053
|
const file2 = path61.join(MEMORY, name, GLOBAL_MEMORY_FILE);
|
|
51814
|
-
if (!
|
|
51815
|
-
const memory = readMemory(
|
|
52054
|
+
if (!fs59.existsSync(file2)) continue;
|
|
52055
|
+
const memory = readMemory(fs59.readFileSync(file2, "utf8"), false, name);
|
|
51816
52056
|
if (memory) out.push(memory);
|
|
51817
52057
|
}
|
|
51818
52058
|
return out;
|
|
@@ -51853,7 +52093,7 @@ var init_memory_file = __esm({
|
|
|
51853
52093
|
});
|
|
51854
52094
|
|
|
51855
52095
|
// src/commands/inspect.ts
|
|
51856
|
-
import
|
|
52096
|
+
import fs60 from "node:fs";
|
|
51857
52097
|
import os4 from "node:os";
|
|
51858
52098
|
import path62 from "node:path";
|
|
51859
52099
|
function cmdInspect(id2) {
|
|
@@ -51861,7 +52101,7 @@ function cmdInspect(id2) {
|
|
|
51861
52101
|
const unavailable = [];
|
|
51862
52102
|
function read5(source2, file3, empty) {
|
|
51863
52103
|
try {
|
|
51864
|
-
return JSON.parse(
|
|
52104
|
+
return JSON.parse(fs60.readFileSync(file3, "utf8"));
|
|
51865
52105
|
} catch (error62) {
|
|
51866
52106
|
if (error62.code === "ENOENT") return empty;
|
|
51867
52107
|
findings.push({ source: source2, message: String(error62) });
|
|
@@ -51883,7 +52123,7 @@ function cmdInspect(id2) {
|
|
|
51883
52123
|
const file2 = found2.kind === "group" ? path62.join(found2.target, "root.md") : found2.target;
|
|
51884
52124
|
let card = null;
|
|
51885
52125
|
try {
|
|
51886
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
52126
|
+
const { meta: meta3, body } = parseFrontmatter(fs60.readFileSync(file2, "utf8"));
|
|
51887
52127
|
if (!meta3) throw Error("The card frontmatter could not be parsed.");
|
|
51888
52128
|
card = { path: rel(file2), questions: meta3.questions, todos: [...body.matchAll(/^\s*[-*]\s+\[([ xX])\]\s+(.*)$/gm)].map((m) => ({ text: m[2], done: m[1] !== " " })) };
|
|
51889
52129
|
} catch (error62) {
|
|
@@ -51896,7 +52136,7 @@ function cmdInspect(id2) {
|
|
|
51896
52136
|
const records = [];
|
|
51897
52137
|
const directory = path62.join(KANBAN, "deliveries");
|
|
51898
52138
|
try {
|
|
51899
|
-
for (const name of
|
|
52139
|
+
for (const name of fs60.readdirSync(directory).filter((name2) => name2.endsWith(".json"))) {
|
|
51900
52140
|
const held5 = read5("delivery", path62.join(directory, name), null);
|
|
51901
52141
|
if (held5?.cardId === id2) records.push(held5);
|
|
51902
52142
|
}
|
|
@@ -51950,7 +52190,7 @@ function cmdValidate(id2) {
|
|
|
51950
52190
|
const reason = errors.length ? formatContractErrors(errors) : void 0;
|
|
51951
52191
|
const session = insideRun();
|
|
51952
52192
|
if (session) patch(session, (run3) => {
|
|
51953
|
-
run3.validationFailure = reason ? { code: "validation_failed",
|
|
52193
|
+
run3.validationFailure = reason ? makeFailure("validation", reason, { code: "validation_failed", detail: reason }) : void 0;
|
|
51954
52194
|
});
|
|
51955
52195
|
if (reason) die(reason, { kind: "spec-contract", errors });
|
|
51956
52196
|
say(`Spec format valid (${cards.length} card${cards.length === 1 ? "" : "s"}).`);
|
|
@@ -51959,6 +52199,7 @@ function cmdValidate(id2) {
|
|
|
51959
52199
|
var init_validate2 = __esm({
|
|
51960
52200
|
"src/commands/validate.ts"() {
|
|
51961
52201
|
"use strict";
|
|
52202
|
+
init_retry();
|
|
51962
52203
|
init_env();
|
|
51963
52204
|
init_sessions();
|
|
51964
52205
|
init_io();
|
|
@@ -51968,7 +52209,7 @@ var init_validate2 = __esm({
|
|
|
51968
52209
|
});
|
|
51969
52210
|
|
|
51970
52211
|
// src/lib/card-sources.ts
|
|
51971
|
-
import
|
|
52212
|
+
import fs61 from "node:fs";
|
|
51972
52213
|
import path63 from "node:path";
|
|
51973
52214
|
function planById(id2) {
|
|
51974
52215
|
const found2 = readPlan(`plans/${id2}-.md`);
|
|
@@ -51980,7 +52221,7 @@ function cardLink(id2) {
|
|
|
51980
52221
|
if (!found2) return null;
|
|
51981
52222
|
try {
|
|
51982
52223
|
const file2 = found2.kind === "group" ? path63.join(found2.target, "root.md") : found2.target;
|
|
51983
|
-
const title = parseFrontmatter(
|
|
52224
|
+
const title = parseFrontmatter(fs61.readFileSync(file2, "utf8")).meta?.title ?? "";
|
|
51984
52225
|
return { kind: "card", ref: String(id2), title, ...open4 ? {} : { archived: true } };
|
|
51985
52226
|
} catch {
|
|
51986
52227
|
return null;
|
|
@@ -52043,7 +52284,7 @@ var init_card_sources = __esm({
|
|
|
52043
52284
|
});
|
|
52044
52285
|
|
|
52045
52286
|
// src/lib/view/read.ts
|
|
52046
|
-
import
|
|
52287
|
+
import fs62 from "node:fs";
|
|
52047
52288
|
import path64 from "node:path";
|
|
52048
52289
|
function readCard(file2, relFromTodo) {
|
|
52049
52290
|
const id2 = idPrefix(path64.basename(relFromTodo));
|
|
@@ -52056,7 +52297,7 @@ function readCard(file2, relFromTodo) {
|
|
|
52056
52297
|
return buildCard(id2, file2, relFromTodo);
|
|
52057
52298
|
}
|
|
52058
52299
|
function buildCard(id2, file2, relFromTodo) {
|
|
52059
|
-
const text5 =
|
|
52300
|
+
const text5 = fs62.readFileSync(file2, "utf8");
|
|
52060
52301
|
const { meta: meta3, body } = parseFrontmatter(text5);
|
|
52061
52302
|
if (!meta3) return null;
|
|
52062
52303
|
const relPath = relFromTodo.split(path64.sep).join("/");
|
|
@@ -52067,7 +52308,7 @@ function buildCard(id2, file2, relFromTodo) {
|
|
|
52067
52308
|
// Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
|
|
52068
52309
|
// read here and a card read by the contract agree on what version this is.
|
|
52069
52310
|
revision: revisionOf(text5),
|
|
52070
|
-
updatedAt:
|
|
52311
|
+
updatedAt: fs62.statSync(file2).mtime.toISOString(),
|
|
52071
52312
|
relPath,
|
|
52072
52313
|
title: meta3.title,
|
|
52073
52314
|
priority: meta3.priority,
|
|
@@ -52089,7 +52330,7 @@ function buildCard(id2, file2, relFromTodo) {
|
|
|
52089
52330
|
function readGroup(folderName) {
|
|
52090
52331
|
const groupDir = path64.join(TODO, folderName);
|
|
52091
52332
|
const rootFile = path64.join(groupDir, "root.md");
|
|
52092
|
-
if (!
|
|
52333
|
+
if (!fs62.existsSync(rootFile)) return null;
|
|
52093
52334
|
const root2 = readCard(rootFile, path64.join(folderName, "root.md"));
|
|
52094
52335
|
if (!root2) return null;
|
|
52095
52336
|
root2.isGroup = true;
|
|
@@ -52097,7 +52338,7 @@ function readGroup(folderName) {
|
|
|
52097
52338
|
root2.subtaskLines = { total, resolved };
|
|
52098
52339
|
const subCards = [];
|
|
52099
52340
|
const recurse = (dir, relDir) => {
|
|
52100
|
-
for (const entry of
|
|
52341
|
+
for (const entry of fs62.readdirSync(dir, { withFileTypes: true })) {
|
|
52101
52342
|
const childRel = path64.join(relDir, entry.name);
|
|
52102
52343
|
if (entry.isDirectory()) {
|
|
52103
52344
|
recurse(path64.join(dir, entry.name), childRel);
|
|
@@ -52124,9 +52365,9 @@ function readGroup(folderName) {
|
|
|
52124
52365
|
}
|
|
52125
52366
|
function standaloneCards(dirRel) {
|
|
52126
52367
|
const dir = dirRel ? path64.join(TODO, dirRel) : TODO;
|
|
52127
|
-
if (!
|
|
52368
|
+
if (!fs62.existsSync(dir)) return [];
|
|
52128
52369
|
const cards = [];
|
|
52129
|
-
for (const entry of
|
|
52370
|
+
for (const entry of fs62.readdirSync(dir, { withFileTypes: true })) {
|
|
52130
52371
|
if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
|
|
52131
52372
|
const c = readCard(path64.join(dir, entry.name), path64.join(dirRel, entry.name));
|
|
52132
52373
|
if (c) cards.push(c);
|
|
@@ -52140,7 +52381,7 @@ function collectCards() {
|
|
|
52140
52381
|
const top = standaloneCards("");
|
|
52141
52382
|
board2.push(...top);
|
|
52142
52383
|
every.push(...top);
|
|
52143
|
-
for (const entry of
|
|
52384
|
+
for (const entry of fs62.readdirSync(TODO, { withFileTypes: true })) {
|
|
52144
52385
|
if (!entry.isDirectory()) continue;
|
|
52145
52386
|
if (isGroupFolder(entry.name)) {
|
|
52146
52387
|
const g = readGroup(entry.name);
|
|
@@ -52172,7 +52413,7 @@ function findCard(id2) {
|
|
|
52172
52413
|
}
|
|
52173
52414
|
function attachSources(card) {
|
|
52174
52415
|
try {
|
|
52175
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
52416
|
+
const { meta: meta3, body } = parseFrontmatter(fs62.readFileSync(path64.join(TODO, card.relPath), "utf8"));
|
|
52176
52417
|
const sources2 = meta3 ? cardSources(meta3, body) : [];
|
|
52177
52418
|
if (sources2.length) card.sources = sources2;
|
|
52178
52419
|
} catch {
|
|
@@ -52546,7 +52787,7 @@ var init_project_agent = __esm({
|
|
|
52546
52787
|
|
|
52547
52788
|
// src/lib/agent/creation.ts
|
|
52548
52789
|
import crypto3 from "node:crypto";
|
|
52549
|
-
import
|
|
52790
|
+
import fs63 from "node:fs";
|
|
52550
52791
|
import path65 from "node:path";
|
|
52551
52792
|
function creationError(error62, triage) {
|
|
52552
52793
|
const zh = readLanguage() === "zh";
|
|
@@ -52578,7 +52819,7 @@ ${slot}`).digest("hex");
|
|
|
52578
52819
|
function readCreation(file2, said2) {
|
|
52579
52820
|
return withCreationLock(() => {
|
|
52580
52821
|
try {
|
|
52581
|
-
const held4 = JSON.parse(
|
|
52822
|
+
const held4 = JSON.parse(fs63.readFileSync(file2, "utf8"));
|
|
52582
52823
|
if (!held4.said || typeof held4.said.title !== "string") throw new Error("Invalid creation journal");
|
|
52583
52824
|
return held4;
|
|
52584
52825
|
} catch (error62) {
|
|
@@ -52590,10 +52831,10 @@ function readCreation(file2, said2) {
|
|
|
52590
52831
|
});
|
|
52591
52832
|
}
|
|
52592
52833
|
function saveCreation(file2, journal) {
|
|
52593
|
-
|
|
52834
|
+
fs63.mkdirSync(path65.dirname(file2), { recursive: true });
|
|
52594
52835
|
const temp = `${file2}.${crypto3.randomUUID()}.tmp`;
|
|
52595
|
-
|
|
52596
|
-
|
|
52836
|
+
fs63.writeFileSync(temp, JSON.stringify(journal));
|
|
52837
|
+
fs63.renameSync(temp, file2);
|
|
52597
52838
|
}
|
|
52598
52839
|
function archiveCreation(source2, id2) {
|
|
52599
52840
|
if (readArchived().some((s) => s.sourceId === source2 && s.cardId === id2)) return;
|
|
@@ -53739,7 +53980,7 @@ var require_command = __commonJS({
|
|
|
53739
53980
|
var EventEmitter = __require("node:events").EventEmitter;
|
|
53740
53981
|
var childProcess = __require("node:child_process");
|
|
53741
53982
|
var path88 = __require("node:path");
|
|
53742
|
-
var
|
|
53983
|
+
var fs91 = __require("node:fs");
|
|
53743
53984
|
var process2 = __require("node:process");
|
|
53744
53985
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
53745
53986
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -54720,7 +54961,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54720
54961
|
* @param {string} subcommandName
|
|
54721
54962
|
*/
|
|
54722
54963
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
54723
|
-
if (
|
|
54964
|
+
if (fs91.existsSync(executableFile)) return;
|
|
54724
54965
|
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";
|
|
54725
54966
|
const executableMissing = `'${executableFile}' does not exist
|
|
54726
54967
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -54739,10 +54980,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54739
54980
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
54740
54981
|
function findFile(baseDir, baseName) {
|
|
54741
54982
|
const localBin = path88.resolve(baseDir, baseName);
|
|
54742
|
-
if (
|
|
54983
|
+
if (fs91.existsSync(localBin)) return localBin;
|
|
54743
54984
|
if (sourceExt.includes(path88.extname(baseName))) return void 0;
|
|
54744
54985
|
const foundExt = sourceExt.find(
|
|
54745
|
-
(ext) =>
|
|
54986
|
+
(ext) => fs91.existsSync(`${localBin}${ext}`)
|
|
54746
54987
|
);
|
|
54747
54988
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
54748
54989
|
return void 0;
|
|
@@ -54754,7 +54995,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54754
54995
|
if (this._scriptPath) {
|
|
54755
54996
|
let resolvedScriptPath;
|
|
54756
54997
|
try {
|
|
54757
|
-
resolvedScriptPath =
|
|
54998
|
+
resolvedScriptPath = fs91.realpathSync(this._scriptPath);
|
|
54758
54999
|
} catch {
|
|
54759
55000
|
resolvedScriptPath = this._scriptPath;
|
|
54760
55001
|
}
|
|
@@ -56090,7 +56331,7 @@ var init_shared2 = __esm({
|
|
|
56090
56331
|
});
|
|
56091
56332
|
|
|
56092
56333
|
// src/lib/agents/shared-memory.ts
|
|
56093
|
-
import
|
|
56334
|
+
import fs64 from "node:fs";
|
|
56094
56335
|
import path66 from "node:path";
|
|
56095
56336
|
function sharedMemory(board2) {
|
|
56096
56337
|
const declared = /* @__PURE__ */ new Map();
|
|
@@ -56099,7 +56340,7 @@ function sharedMemory(board2) {
|
|
|
56099
56340
|
const read5 = parseSpecAgent(text5, folder2, (relative) => {
|
|
56100
56341
|
if (builtIn) return shippedAgentFiles()[`${folder2}/${relative}`] ?? null;
|
|
56101
56342
|
try {
|
|
56102
|
-
return
|
|
56343
|
+
return fs64.readFileSync(path66.join(board2, "agents", folder2, relative), "utf8");
|
|
56103
56344
|
} catch {
|
|
56104
56345
|
return null;
|
|
56105
56346
|
}
|
|
@@ -56113,13 +56354,13 @@ function sharedMemory(board2) {
|
|
|
56113
56354
|
const root2 = path66.join(board2, "agents");
|
|
56114
56355
|
let folders2 = [];
|
|
56115
56356
|
try {
|
|
56116
|
-
folders2 =
|
|
56357
|
+
folders2 = fs64.readdirSync(root2, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
56117
56358
|
} catch {
|
|
56118
56359
|
}
|
|
56119
56360
|
for (const folder2 of folders2.sort()) {
|
|
56120
56361
|
let text5 = null;
|
|
56121
56362
|
try {
|
|
56122
|
-
text5 =
|
|
56363
|
+
text5 = fs64.readFileSync(path66.join(root2, folder2, "AGENT.md"), "utf8");
|
|
56123
56364
|
} catch {
|
|
56124
56365
|
}
|
|
56125
56366
|
take(folder2, text5, false);
|
|
@@ -56145,30 +56386,30 @@ var init_shared_memory = __esm({
|
|
|
56145
56386
|
|
|
56146
56387
|
// src/lib/shared/board-conflicts.ts
|
|
56147
56388
|
import crypto4 from "node:crypto";
|
|
56148
|
-
import
|
|
56389
|
+
import fs65 from "node:fs";
|
|
56149
56390
|
import path67 from "node:path";
|
|
56150
56391
|
function atomicJson(file2, data) {
|
|
56151
|
-
|
|
56392
|
+
fs65.mkdirSync(path67.dirname(file2), { recursive: true });
|
|
56152
56393
|
const temp = `${file2}.${crypto4.randomUUID()}.tmp`;
|
|
56153
|
-
const fd =
|
|
56394
|
+
const fd = fs65.openSync(temp, "wx", 384);
|
|
56154
56395
|
try {
|
|
56155
|
-
|
|
56156
|
-
|
|
56396
|
+
fs65.writeFileSync(fd, JSON.stringify(data));
|
|
56397
|
+
fs65.fsyncSync(fd);
|
|
56157
56398
|
} finally {
|
|
56158
|
-
|
|
56399
|
+
fs65.closeSync(fd);
|
|
56159
56400
|
}
|
|
56160
|
-
|
|
56401
|
+
fs65.renameSync(temp, file2);
|
|
56161
56402
|
}
|
|
56162
56403
|
function boardTextAt(board2, name) {
|
|
56163
56404
|
if (!isBoardPath(name)) throw new BoardError(`Invalid board path: ${name}`, { kind: "invalid-usage" });
|
|
56164
56405
|
const file2 = path67.join(board2, name);
|
|
56165
56406
|
let ancestor = file2;
|
|
56166
|
-
while (!
|
|
56167
|
-
const real2 = path67.resolve(
|
|
56168
|
-
if (!real2.startsWith(
|
|
56169
|
-
if ((
|
|
56407
|
+
while (!fs65.existsSync(ancestor) && path67.dirname(ancestor) !== ancestor) ancestor = path67.dirname(ancestor);
|
|
56408
|
+
const real2 = path67.resolve(fs65.realpathSync(ancestor), path67.relative(ancestor, file2));
|
|
56409
|
+
if (!real2.startsWith(fs65.realpathSync(board2) + path67.sep)) throw new BoardError(`Link outside the board: ${name}`, { kind: "invalid-usage" });
|
|
56410
|
+
if ((fs65.statSync(file2, { throwIfNoEntry: false })?.size ?? 0) > BOARD_FILE_LIMIT) throw new BoardError(`${name} exceeds the board file limit.`, { kind: "cloud-refused" });
|
|
56170
56411
|
try {
|
|
56171
|
-
return
|
|
56412
|
+
return fs65.readFileSync(file2, "utf8");
|
|
56172
56413
|
} catch (e) {
|
|
56173
56414
|
if (e.code === "ENOENT") return null;
|
|
56174
56415
|
throw e;
|
|
@@ -56179,9 +56420,9 @@ function save2(board2, record2) {
|
|
|
56179
56420
|
}
|
|
56180
56421
|
function read2(board2, id2) {
|
|
56181
56422
|
const file2 = fileOf(board2, id2);
|
|
56182
|
-
if (!
|
|
56423
|
+
if (!fs65.existsSync(file2)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
|
|
56183
56424
|
try {
|
|
56184
|
-
const r = JSON.parse(
|
|
56425
|
+
const r = JSON.parse(fs65.readFileSync(file2, "utf8"));
|
|
56185
56426
|
if (r.id !== id2 || !r.project || !["open", "unconfirmed", "resolved"].includes(r.state) || !Array.isArray(r.files) || !r.files.length) throw Error();
|
|
56186
56427
|
const names2 = /* @__PURE__ */ new Set();
|
|
56187
56428
|
for (const f of r.files) {
|
|
@@ -56203,7 +56444,7 @@ function read2(board2, id2) {
|
|
|
56203
56444
|
function conflictRecords(board2) {
|
|
56204
56445
|
let names2;
|
|
56205
56446
|
try {
|
|
56206
|
-
names2 =
|
|
56447
|
+
names2 = fs65.readdirSync(folder(board2));
|
|
56207
56448
|
} catch (e) {
|
|
56208
56449
|
if (e.code === "ENOENT") return [];
|
|
56209
56450
|
throw e;
|
|
@@ -56292,7 +56533,7 @@ function confirmLocal(board2, r) {
|
|
|
56292
56533
|
const draft = r.draft;
|
|
56293
56534
|
const root2 = stateRootOf(board2);
|
|
56294
56535
|
const file2 = path67.join(root2, ".akb", "base.json");
|
|
56295
|
-
const base = JSON.parse(
|
|
56536
|
+
const base = JSON.parse(fs65.readFileSync(file2, "utf8"));
|
|
56296
56537
|
if (base.project && base.project !== r.project) refuse(r, "The project binding changed.", "cloud-refused");
|
|
56297
56538
|
base.deleted ??= {};
|
|
56298
56539
|
for (const [i, f] of r.files.entries()) {
|
|
@@ -56309,10 +56550,10 @@ function confirmLocal(board2, r) {
|
|
|
56309
56550
|
}
|
|
56310
56551
|
if (boardTextAt(board2, f.path) !== draft.working[i]) continue;
|
|
56311
56552
|
const local = path67.join(board2, f.path);
|
|
56312
|
-
if (sent.content === null)
|
|
56553
|
+
if (sent.content === null) fs65.rmSync(local, { force: true });
|
|
56313
56554
|
else {
|
|
56314
|
-
|
|
56315
|
-
|
|
56555
|
+
fs65.mkdirSync(path67.dirname(local), { recursive: true });
|
|
56556
|
+
fs65.writeFileSync(local, sent.content);
|
|
56316
56557
|
}
|
|
56317
56558
|
}
|
|
56318
56559
|
atomicJson(file2, base);
|
|
@@ -56471,13 +56712,26 @@ var init_board_conflicts2 = __esm({
|
|
|
56471
56712
|
}
|
|
56472
56713
|
});
|
|
56473
56714
|
|
|
56715
|
+
// src/lib/cli/question-options.ts
|
|
56716
|
+
function withQuestionOptions(command, ops) {
|
|
56717
|
+
const inOrder = ordered(ops);
|
|
56718
|
+
return command.option("--append <text>", "append a new question", inOrder("append")).option("--update <n> <text...>", "rewrite question <n>", inOrder("update")).option("--drop <positions>", "remove questions, e.g. 1 or 1,3", inOrder("drop")).option("--clear", "remove every open question", inOrder("clear")).option("--option <text>", "a choice for the preceding append or update", inOrder("option")).option("--recommended-option <text>", "a choice selected by default", inOrder("recommended-option")).option("--mode <mode>", "single (default) or multi", inOrder("mode")).addOption(new Option("--agent <name>").hideHelp().argParser(inOrder("agent")));
|
|
56719
|
+
}
|
|
56720
|
+
var init_question_options = __esm({
|
|
56721
|
+
"src/lib/cli/question-options.ts"() {
|
|
56722
|
+
"use strict";
|
|
56723
|
+
init_esm();
|
|
56724
|
+
init_shared2();
|
|
56725
|
+
}
|
|
56726
|
+
});
|
|
56727
|
+
|
|
56474
56728
|
// src/lib/cli/board.ts
|
|
56475
56729
|
var board_exports = {};
|
|
56476
56730
|
__export(board_exports, {
|
|
56477
56731
|
buildBoardProgram: () => buildBoardProgram
|
|
56478
56732
|
});
|
|
56479
56733
|
import crypto5 from "node:crypto";
|
|
56480
|
-
import
|
|
56734
|
+
import fs66 from "node:fs";
|
|
56481
56735
|
import path68 from "node:path";
|
|
56482
56736
|
async function dispatch(move, cmd, args2, opts, cli) {
|
|
56483
56737
|
const ctx = ctxOf(cmd, cli.program);
|
|
@@ -56498,7 +56752,7 @@ async function dispatch(move, cmd, args2, opts, cli) {
|
|
|
56498
56752
|
}
|
|
56499
56753
|
let resolution;
|
|
56500
56754
|
try {
|
|
56501
|
-
resolution = JSON.parse(
|
|
56755
|
+
resolution = JSON.parse(fs66.readFileSync(String(opts.file), "utf8"));
|
|
56502
56756
|
} catch {
|
|
56503
56757
|
throw new BoardError("Cannot read the UTF-8 JSON resolution file.", { kind: "invalid-usage" });
|
|
56504
56758
|
}
|
|
@@ -56539,7 +56793,7 @@ async function cloudCard(task, opts) {
|
|
|
56539
56793
|
let request2;
|
|
56540
56794
|
if (typeof opts.bodyFile === "string") {
|
|
56541
56795
|
try {
|
|
56542
|
-
request2 =
|
|
56796
|
+
request2 = fs66.readFileSync(opts.bodyFile, "utf8");
|
|
56543
56797
|
} catch {
|
|
56544
56798
|
}
|
|
56545
56799
|
}
|
|
@@ -56620,10 +56874,7 @@ function buildBoardProgram(cli) {
|
|
|
56620
56874
|
await dispatch("update", this, [String(id2)], this.opts(), cli);
|
|
56621
56875
|
});
|
|
56622
56876
|
const questionOps = [];
|
|
56623
|
-
|
|
56624
|
-
move("update-questions").argument("<id>", ID, cardId).summary("patch a card's open questions: append, rewrite, drop, skip, or clear").description(
|
|
56625
|
-
"Patch the open-question list in place. Ops apply in the order they were typed, and a position is read against the list as it stands when its op runs. Positions are 1-based. A question handed to the user always carries choices to tick \u2014 follow `akb guide update-questions`. --option, --recommended-option and --mode attach to the --append or --update before them."
|
|
56626
|
-
).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")).addOption(new Option("--agent <name>").hideHelp().argParser(opInOrder("agent"))).action(async function(id2) {
|
|
56877
|
+
withQuestionOptions(withShared(program2.command("update-questions", { hidden: true })).argument("<id>", ID, cardId).summary("edit open questions on a local card (compatibility)").description("For older Runner instructions. Use akb task update-questions.\nSee akb guide update-questions."), questionOps).action(async function(id2) {
|
|
56627
56878
|
await dispatch("update-questions", this, [String(id2)], { ops: questionOps }, cli);
|
|
56628
56879
|
});
|
|
56629
56880
|
move("inspect").argument("<id>", ID, cardId).summary("read task facts, saved work and execution references").action(async function(id2) {
|
|
@@ -56701,12 +56952,13 @@ var init_board2 = __esm({
|
|
|
56701
56952
|
init_agent2();
|
|
56702
56953
|
init_board_conflicts();
|
|
56703
56954
|
init_board_conflicts2();
|
|
56955
|
+
init_question_options();
|
|
56704
56956
|
ID = "the card's id";
|
|
56705
56957
|
}
|
|
56706
56958
|
});
|
|
56707
56959
|
|
|
56708
56960
|
// src/lib/board-cli.ts
|
|
56709
|
-
import
|
|
56961
|
+
import fs67 from "node:fs";
|
|
56710
56962
|
import path69 from "node:path";
|
|
56711
56963
|
function useBoard(found2, dirNamed, readOnly = false) {
|
|
56712
56964
|
if (!found2.named && found2.board === path69.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
|
|
@@ -56718,7 +56970,7 @@ function useBoard(found2, dirNamed, readOnly = false) {
|
|
|
56718
56970
|
}
|
|
56719
56971
|
function whole(found2, move) {
|
|
56720
56972
|
if (move === MAKES_A_BOARD) return found2;
|
|
56721
|
-
if (!
|
|
56973
|
+
if (!fs67.existsSync(path69.join(found2.board, "todo"))) {
|
|
56722
56974
|
die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
|
|
56723
56975
|
kind: "board-incomplete",
|
|
56724
56976
|
dir: found2.root
|
|
@@ -56732,7 +56984,7 @@ function findBoardUpward(from, move) {
|
|
|
56732
56984
|
if (hasBoard(dir)) return { root: dir, board: path69.join(dir, "docs", "kanban") };
|
|
56733
56985
|
if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
|
|
56734
56986
|
const kept2 = path69.join(dir, ".akb", "kanban");
|
|
56735
|
-
if (move !== MAKES_A_BOARD &&
|
|
56987
|
+
if (move !== MAKES_A_BOARD && fs67.existsSync(path69.join(kept2, "todo"))) return { root: dir, board: kept2 };
|
|
56736
56988
|
const up = path69.dirname(dir);
|
|
56737
56989
|
if (up === dir) return null;
|
|
56738
56990
|
dir = up;
|
|
@@ -56742,10 +56994,10 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
56742
56994
|
const named2 = board2 ?? boardFromEnv();
|
|
56743
56995
|
if (named2) {
|
|
56744
56996
|
const folder2 = path69.resolve(cwd, named2);
|
|
56745
|
-
if (!
|
|
56997
|
+
if (!fs67.existsSync(folder2) && move !== MAKES_A_BOARD) {
|
|
56746
56998
|
die(`no such folder: ${folder2}`, { kind: "no-such-folder", dir: folder2 });
|
|
56747
56999
|
}
|
|
56748
|
-
if (
|
|
57000
|
+
if (fs67.existsSync(folder2) && !isBoardDir(folder2) && move !== MAKES_A_BOARD) {
|
|
56749
57001
|
die(`${folder2} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
|
|
56750
57002
|
kind: "no-board",
|
|
56751
57003
|
dir: folder2
|
|
@@ -56755,9 +57007,9 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
56755
57007
|
}
|
|
56756
57008
|
if (dir !== null) {
|
|
56757
57009
|
const root2 = path69.resolve(dir);
|
|
56758
|
-
if (!
|
|
57010
|
+
if (!fs67.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
|
|
56759
57011
|
const kept2 = path69.join(root2, ".akb", "kanban");
|
|
56760
|
-
if (!hasBoard(root2) && move !== MAKES_A_BOARD &&
|
|
57012
|
+
if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs67.existsSync(path69.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
|
|
56761
57013
|
if (!hasBoard(root2) && move !== MAKES_A_BOARD) {
|
|
56762
57014
|
die(`no board in ${root2} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
|
|
56763
57015
|
kind: "no-board",
|
|
@@ -56848,8 +57100,8 @@ var init_board_cli = __esm({
|
|
|
56848
57100
|
init_io();
|
|
56849
57101
|
init_card_studio_backfill();
|
|
56850
57102
|
MAKES_A_BOARD = "init";
|
|
56851
|
-
hasBoard = (dir) =>
|
|
56852
|
-
isBoardDir = (dir) =>
|
|
57103
|
+
hasBoard = (dir) => fs67.existsSync(path69.join(dir, "docs", "kanban"));
|
|
57104
|
+
isBoardDir = (dir) => fs67.existsSync(path69.join(dir, "todo")) && fs67.existsSync(path69.join(dir, "config.md"));
|
|
56853
57105
|
boardFromEnv = () => {
|
|
56854
57106
|
const named2 = process.env.AI4KANBAN_BOARD?.trim();
|
|
56855
57107
|
return named2 ? named2 : null;
|
|
@@ -56858,11 +57110,11 @@ var init_board_cli = __esm({
|
|
|
56858
57110
|
});
|
|
56859
57111
|
|
|
56860
57112
|
// src/lib/cloud/task-operation.ts
|
|
56861
|
-
import
|
|
57113
|
+
import fs68 from "node:fs";
|
|
56862
57114
|
import path70 from "node:path";
|
|
56863
57115
|
function readRemoval(board2, task) {
|
|
56864
57116
|
try {
|
|
56865
|
-
const value = JSON.parse(
|
|
57117
|
+
const value = JSON.parse(fs68.readFileSync(removalFile(board2, task), "utf8"));
|
|
56866
57118
|
if (["pending", "confirmed", "rejected"].includes(value.status) && typeof value.reason === "string" && typeof value.discard === "boolean") return value;
|
|
56867
57119
|
} catch {
|
|
56868
57120
|
}
|
|
@@ -56871,8 +57123,8 @@ function readRemoval(board2, task) {
|
|
|
56871
57123
|
function writeRemoval(board2, task, removal) {
|
|
56872
57124
|
const file2 = removalFile(board2, task);
|
|
56873
57125
|
const temp = `${file2}.${process.pid}.tmp`;
|
|
56874
|
-
|
|
56875
|
-
|
|
57126
|
+
fs68.writeFileSync(temp, JSON.stringify(removal) + "\n");
|
|
57127
|
+
fs68.renameSync(temp, file2);
|
|
56876
57128
|
}
|
|
56877
57129
|
var removalFile;
|
|
56878
57130
|
var init_task_operation = __esm({
|
|
@@ -56928,10 +57180,10 @@ var init_avatar = __esm({
|
|
|
56928
57180
|
});
|
|
56929
57181
|
|
|
56930
57182
|
// src/lib/cloud/pro.ts
|
|
56931
|
-
import
|
|
57183
|
+
import fs69 from "node:fs";
|
|
56932
57184
|
import path71 from "node:path";
|
|
56933
57185
|
function forgetPro() {
|
|
56934
|
-
|
|
57186
|
+
fs69.rmSync(heldFile(), { force: true });
|
|
56935
57187
|
}
|
|
56936
57188
|
var FRESH_MS2, GRACE_MS, heldFile;
|
|
56937
57189
|
var init_pro = __esm({
|
|
@@ -57037,7 +57289,7 @@ var init_account = __esm({
|
|
|
57037
57289
|
});
|
|
57038
57290
|
|
|
57039
57291
|
// src/commands/cloud.ts
|
|
57040
|
-
import
|
|
57292
|
+
import fs70 from "node:fs";
|
|
57041
57293
|
import path72 from "node:path";
|
|
57042
57294
|
async function cmdCloud(args2, program2) {
|
|
57043
57295
|
const [sub] = args2;
|
|
@@ -57113,7 +57365,7 @@ async function cloudImage(opts, program2) {
|
|
|
57113
57365
|
const type = REF_TYPES[path72.extname(file2).toLowerCase()];
|
|
57114
57366
|
if (!type) usage(`--ref ${file2}: use a PNG, JPEG or WebP file.`, line);
|
|
57115
57367
|
try {
|
|
57116
|
-
return `data:${type};base64,${
|
|
57368
|
+
return `data:${type};base64,${fs70.readFileSync(file2).toString("base64")}`;
|
|
57117
57369
|
} catch (e) {
|
|
57118
57370
|
usage(`--ref ${file2}: ${e instanceof Error ? e.message : String(e)}`, line);
|
|
57119
57371
|
}
|
|
@@ -57237,8 +57489,8 @@ usage: ${g.usage}` }, { bare: true, exitCode: 2 });
|
|
|
57237
57489
|
refuse2(g.failed, g.fallback, { code: error62.kind, message: error62.message, retryable: true });
|
|
57238
57490
|
}
|
|
57239
57491
|
const out = g.outFor?.(res, g.out) ?? g.out;
|
|
57240
|
-
|
|
57241
|
-
|
|
57492
|
+
fs70.mkdirSync(path72.dirname(path72.resolve(out)), { recursive: true });
|
|
57493
|
+
fs70.writeFileSync(out, bytes2);
|
|
57242
57494
|
say(`${out} (${g.label(res)})`);
|
|
57243
57495
|
return { out };
|
|
57244
57496
|
}
|
|
@@ -57300,7 +57552,7 @@ var init_cloud = __esm({
|
|
|
57300
57552
|
});
|
|
57301
57553
|
|
|
57302
57554
|
// src/commands/task.ts
|
|
57303
|
-
import
|
|
57555
|
+
import fs71 from "node:fs";
|
|
57304
57556
|
import os5 from "node:os";
|
|
57305
57557
|
import path73 from "node:path";
|
|
57306
57558
|
async function cloud(method, route2, body, signal2) {
|
|
@@ -57359,7 +57611,7 @@ function linked(location) {
|
|
|
57359
57611
|
return link2.ok ? link2.value : null;
|
|
57360
57612
|
}
|
|
57361
57613
|
for (let dir = path73.resolve(cwd, location.dir ?? "."); ; dir = path73.dirname(dir)) {
|
|
57362
|
-
if (
|
|
57614
|
+
if (fs71.existsSync(path73.join(dir, ".akb", "base.json"))) {
|
|
57363
57615
|
const link2 = linkedProject("", dir);
|
|
57364
57616
|
return link2.ok ? link2.value : null;
|
|
57365
57617
|
}
|
|
@@ -57466,7 +57718,7 @@ async function taskReview(id2, opts = {}, location = {}) {
|
|
|
57466
57718
|
if (opts.review !== void 0) {
|
|
57467
57719
|
fields2 = { operation: "plan", review_flow: opts.review };
|
|
57468
57720
|
} else if (opts.file !== void 0) {
|
|
57469
|
-
fields2 = { operation: "plan", review_plan: parseReviewPlan(JSON.parse(
|
|
57721
|
+
fields2 = { operation: "plan", review_plan: parseReviewPlan(JSON.parse(fs71.readFileSync(opts.file, "utf8"))) };
|
|
57470
57722
|
} else if (opts.reviseFrom !== void 0) {
|
|
57471
57723
|
fields2 = { operation: "revise", stage: opts.reviseFrom };
|
|
57472
57724
|
} else if (opts.previewDefinitionsFile !== void 0) {
|
|
@@ -57475,7 +57727,7 @@ async function taskReview(id2, opts = {}, location = {}) {
|
|
|
57475
57727
|
if (!opts.stage || !["running", "done"].includes(opts.status)) die("--stage and --status running|done are required.");
|
|
57476
57728
|
fields2 = { operation: "status", stage: opts.stage, status: opts.status };
|
|
57477
57729
|
}
|
|
57478
|
-
if (opts.previewDefinitionsFile !== void 0) fields2.preview_definitions = previewDefinitionsSchema.parse(JSON.parse(
|
|
57730
|
+
if (opts.previewDefinitionsFile !== void 0) fields2.preview_definitions = previewDefinitionsSchema.parse(JSON.parse(fs71.readFileSync(opts.previewDefinitionsFile, "utf8")));
|
|
57479
57731
|
task = await cloud("POST", `/v1/tasks/${enc(ref)}/review`, { ...fields2, review_revision });
|
|
57480
57732
|
}
|
|
57481
57733
|
say(JSON.stringify(task.review, null, 2));
|
|
@@ -57499,13 +57751,43 @@ async function taskApprove(id2, comment, opts = {}, location = {}) {
|
|
|
57499
57751
|
}
|
|
57500
57752
|
async function taskUpdateQuestions(id2, typed, location = {}) {
|
|
57501
57753
|
const ops = readQuestionOps(typed);
|
|
57754
|
+
const current = executionOf() ? workspaceTask() : null;
|
|
57502
57755
|
const ref = await taskRef(id2, location);
|
|
57503
|
-
const
|
|
57504
|
-
const
|
|
57756
|
+
const selected = current && !ref.startsWith("task_") ? requireTask(await cloud("GET", `/v1/tasks/${enc(ref)}`)) : null;
|
|
57757
|
+
const target = selected?.id ?? ref;
|
|
57758
|
+
if (current && target === current) {
|
|
57759
|
+
const board2 = runnerTaskBoard(location);
|
|
57760
|
+
const unavailable = () => refuse3("Cannot find the current task\u2019s local card on its Runner board.", "local_card_unavailable");
|
|
57761
|
+
if (!board2) return unavailable();
|
|
57762
|
+
return withSyncLock(board2, async () => {
|
|
57763
|
+
const project2 = runnerProject(board2);
|
|
57764
|
+
const mapped = localTaskRecord(board2, current);
|
|
57765
|
+
if (!mapped || !project2 || selected && (selected.project !== project2 || numberOf(selected.key) !== mapped.number)) {
|
|
57766
|
+
return unavailable();
|
|
57767
|
+
}
|
|
57768
|
+
const root2 = projectRootOf(board2);
|
|
57769
|
+
useBoard({ board: board2, root: root2, named: true }, false, true);
|
|
57770
|
+
return withBoardLock(() => {
|
|
57771
|
+
const run3 = insideRun();
|
|
57772
|
+
const runCard = run3 ? peekRun(run3)?.cardId : null;
|
|
57773
|
+
if (runCard != null && runCard !== mapped.number || !fs71.existsSync(path73.join(board2, "todo")) || !locate(mapped.number)) {
|
|
57774
|
+
return unavailable();
|
|
57775
|
+
}
|
|
57776
|
+
return updateCardQuestions(mapped.number, ops);
|
|
57777
|
+
});
|
|
57778
|
+
});
|
|
57779
|
+
}
|
|
57780
|
+
const card = requireResponse(
|
|
57781
|
+
await cloud("GET", `/v1/tasks/${enc(target)}/card`),
|
|
57782
|
+
"the card body and version",
|
|
57783
|
+
(value) => hasText(value.body) && Number.isSafeInteger(value.version) && value.version >= 0
|
|
57784
|
+
);
|
|
57785
|
+
const meta3 = parseFrontmatter(card.body).meta;
|
|
57786
|
+
if (!meta3) return refuse3("The card has no frontmatter.", "bad_request");
|
|
57505
57787
|
let changes;
|
|
57506
57788
|
let open4;
|
|
57507
57789
|
try {
|
|
57508
|
-
const done = applyQuestionOps(questions, ops);
|
|
57790
|
+
const done = applyQuestionOps(meta3.questions, ops);
|
|
57509
57791
|
changes = done.changes;
|
|
57510
57792
|
open4 = done.questions.length;
|
|
57511
57793
|
} catch (e) {
|
|
@@ -57517,22 +57799,27 @@ async function taskUpdateQuestions(id2, typed, location = {}) {
|
|
|
57517
57799
|
if (op.kind === "append") return { append: q };
|
|
57518
57800
|
if (op.kind === "update") return { update: op.n, question: q };
|
|
57519
57801
|
if (op.kind === "drop") return { drop: questionPositions(op.ns, Infinity, "drop") };
|
|
57520
|
-
|
|
57521
|
-
return die(`akb task update-questions has no --${op.kind}; --drop removes a question`);
|
|
57802
|
+
return { clear: true };
|
|
57522
57803
|
});
|
|
57523
|
-
const task = await cloud("PATCH", `/v1/tasks/${enc(
|
|
57804
|
+
const task = await cloud("PATCH", `/v1/tasks/${enc(target)}/questions`, { base_version: card.version, ops: body });
|
|
57524
57805
|
say(`updated ${task.key} questions: ${changes.join(", ")} (${open4} open)`);
|
|
57525
57806
|
return { ...task, changes, open: open4 };
|
|
57526
57807
|
}
|
|
57527
|
-
function
|
|
57528
|
-
const task = workspaceTask();
|
|
57808
|
+
function runnerTaskBoard(location) {
|
|
57529
57809
|
const runnerBoard = process.env.AI4KANBAN_BOARD?.trim();
|
|
57530
|
-
if (!
|
|
57810
|
+
if (!runnerBoard) return null;
|
|
57531
57811
|
const cwd = location.cwd ?? process.cwd();
|
|
57532
|
-
const board2 = path73.resolve(cwd, location.board ?? runnerBoard);
|
|
57533
57812
|
try {
|
|
57534
|
-
|
|
57535
|
-
|
|
57813
|
+
const board2 = path73.resolve(cwd, location.board ?? runnerBoard);
|
|
57814
|
+
return fs71.realpathSync(board2) === fs71.realpathSync(path73.resolve(cwd, runnerBoard)) && runnerProject(board2) ? board2 : null;
|
|
57815
|
+
} catch {
|
|
57816
|
+
return null;
|
|
57817
|
+
}
|
|
57818
|
+
}
|
|
57819
|
+
function localTaskRecord(board2, task) {
|
|
57820
|
+
if (!/^task_[\w-]+$/.test(task)) return null;
|
|
57821
|
+
try {
|
|
57822
|
+
const record2 = JSON.parse(fs71.readFileSync(path73.join(board2, ".sync", task + ".json"), "utf8"));
|
|
57536
57823
|
if (record2.task === task && Number.isSafeInteger(record2.number) && record2.number > 0 && !record2.deleted) {
|
|
57537
57824
|
return { board: board2, task, number: record2.number };
|
|
57538
57825
|
}
|
|
@@ -57540,6 +57827,12 @@ function localTaskTarget(location) {
|
|
|
57540
57827
|
}
|
|
57541
57828
|
return null;
|
|
57542
57829
|
}
|
|
57830
|
+
function localTaskTarget(location) {
|
|
57831
|
+
const task = workspaceTask();
|
|
57832
|
+
if (!task || !executionOf()) return null;
|
|
57833
|
+
const board2 = runnerTaskBoard(location);
|
|
57834
|
+
return board2 ? localTaskRecord(board2, task) : null;
|
|
57835
|
+
}
|
|
57543
57836
|
function linkedBoard(location) {
|
|
57544
57837
|
const cwd = location.cwd ?? process.cwd();
|
|
57545
57838
|
const named2 = location.board ?? process.env.AI4KANBAN_BOARD;
|
|
@@ -57559,7 +57852,7 @@ function operationStatus(result) {
|
|
|
57559
57852
|
}
|
|
57560
57853
|
function archiveReceipt(board2, task, file2) {
|
|
57561
57854
|
try {
|
|
57562
|
-
const base = JSON.parse(
|
|
57855
|
+
const base = JSON.parse(fs71.readFileSync(path73.join(board2, "..", "base.json"), "utf8"));
|
|
57563
57856
|
const receipt = base.archiveReceipts?.[task];
|
|
57564
57857
|
const root2 = `projects/${runnerProject(board2)}/`;
|
|
57565
57858
|
const synced = receipt && base.files?.[root2 + receipt.path];
|
|
@@ -57568,7 +57861,7 @@ function archiveReceipt(board2, task, file2) {
|
|
|
57568
57861
|
if (synced && (!file2 || receipt.path === file2) && synced.seq === receipt.seq && (assets?.seq ?? 0) === receipt.assets_seq) {
|
|
57569
57862
|
const local = (name) => {
|
|
57570
57863
|
try {
|
|
57571
|
-
return
|
|
57864
|
+
return fs71.readFileSync(path73.join(board2, name), "utf8");
|
|
57572
57865
|
} catch {
|
|
57573
57866
|
return null;
|
|
57574
57867
|
}
|
|
@@ -57593,7 +57886,7 @@ async function taskArchive(asked, location = {}) {
|
|
|
57593
57886
|
const existing = locateArchived(local.number);
|
|
57594
57887
|
if (!existing) return null;
|
|
57595
57888
|
const file2 = existing.kind === "group" ? path73.join(existing.target, "root.md") : existing.target;
|
|
57596
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
57889
|
+
const { meta: meta3 } = parseFrontmatter(fs71.readFileSync(file2, "utf8"));
|
|
57597
57890
|
if (!meta3?.archived || meta3.rejected) return refuse3("This task is not eligible for archive.", "conflict");
|
|
57598
57891
|
return {
|
|
57599
57892
|
receipt: { archived_to: path73.relative(local.board, existing.target) },
|
|
@@ -57736,6 +58029,7 @@ var init_task = __esm({
|
|
|
57736
58029
|
init_board_files();
|
|
57737
58030
|
init_board_conflicts();
|
|
57738
58031
|
init_remove();
|
|
58032
|
+
init_card();
|
|
57739
58033
|
init_io();
|
|
57740
58034
|
init_response();
|
|
57741
58035
|
init_paths();
|
|
@@ -57794,20 +58088,20 @@ var init_goal = __esm({
|
|
|
57794
58088
|
});
|
|
57795
58089
|
|
|
57796
58090
|
// src/lib/goal-draft.ts
|
|
57797
|
-
import
|
|
58091
|
+
import fs72 from "node:fs";
|
|
57798
58092
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
57799
58093
|
function readGoalDraft(file2) {
|
|
57800
|
-
return decodeGoals(JSON.parse(
|
|
58094
|
+
return decodeGoals(JSON.parse(fs72.readFileSync(file2, "utf8")));
|
|
57801
58095
|
}
|
|
57802
58096
|
function writeGoalDraft(file2, { goals, ...draft }, field2) {
|
|
57803
58097
|
const entries2 = field2 === "goals" ? goals : goals.map(({ task, ...goal }) => ({ ...goal, task: task?.key ? task : task?.id ?? null }));
|
|
57804
58098
|
const temporary = `${file2}.${randomUUID7()}.tmp`;
|
|
57805
58099
|
try {
|
|
57806
|
-
|
|
58100
|
+
fs72.writeFileSync(temporary, `${JSON.stringify({ ...draft, [field2]: entries2 }, null, 2)}
|
|
57807
58101
|
`, { mode: 384, flag: "wx" });
|
|
57808
|
-
|
|
58102
|
+
fs72.renameSync(temporary, file2);
|
|
57809
58103
|
} finally {
|
|
57810
|
-
|
|
58104
|
+
fs72.rmSync(temporary, { force: true });
|
|
57811
58105
|
}
|
|
57812
58106
|
}
|
|
57813
58107
|
var goalDraftPath;
|
|
@@ -57820,7 +58114,7 @@ var init_goal_draft = __esm({
|
|
|
57820
58114
|
});
|
|
57821
58115
|
|
|
57822
58116
|
// src/commands/goal.ts
|
|
57823
|
-
import
|
|
58117
|
+
import fs73 from "node:fs";
|
|
57824
58118
|
function loadGoals() {
|
|
57825
58119
|
const file2 = goalDraftPath();
|
|
57826
58120
|
if (!file2) die("Goals exist only inside a WildCrane goal discussion.");
|
|
@@ -57852,7 +58146,7 @@ function splitBody2(text5) {
|
|
|
57852
58146
|
}
|
|
57853
58147
|
function readBody(bodyFile) {
|
|
57854
58148
|
if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
|
|
57855
|
-
const text5 =
|
|
58149
|
+
const text5 = fs73.readFileSync(bodyFile, "utf8");
|
|
57856
58150
|
if (!text5.trim()) die("The goal must not be empty.");
|
|
57857
58151
|
return splitBody2(text5);
|
|
57858
58152
|
}
|
|
@@ -57918,7 +58212,7 @@ function cmdGoalStudios(held4 = loadGoals().held) {
|
|
|
57918
58212
|
return { studios: held4.studios.map((w) => ({ ...w, id: shortStudioId(w.id) })) };
|
|
57919
58213
|
}
|
|
57920
58214
|
function goalDefinitions(opts, previous = []) {
|
|
57921
|
-
return opts.previewDefinitionsFile === void 0 ? previous : previewDefinitionsSchema.parse(JSON.parse(
|
|
58215
|
+
return opts.previewDefinitionsFile === void 0 ? previous : previewDefinitionsSchema.parse(JSON.parse(fs73.readFileSync(opts.previewDefinitionsFile, "utf8")));
|
|
57922
58216
|
}
|
|
57923
58217
|
function goalCatalog(held4, studio, definitions) {
|
|
57924
58218
|
const builtIn = held4.studios.find((w) => w.id === studio)?.previews;
|
|
@@ -57931,7 +58225,7 @@ function goalReview(held4, studio, opts, previous, definitions) {
|
|
|
57931
58225
|
if (opts.reviewFile !== void 0) die("Use either --review or --review-file.");
|
|
57932
58226
|
return parseReviewFlow(opts.review, catalog);
|
|
57933
58227
|
}
|
|
57934
|
-
const value = opts.reviewFile === void 0 ? readReviewPlan(previous) : JSON.parse(
|
|
58228
|
+
const value = opts.reviewFile === void 0 ? readReviewPlan(previous) : JSON.parse(fs73.readFileSync(opts.reviewFile, "utf8"));
|
|
57935
58229
|
const saved = opts.reviewFile === void 0 && opts.previewDefinitionsFile === void 0 && opts.studio === void 0;
|
|
57936
58230
|
return validateReviewPreviews(parseReviewPlan(value), catalog, { saved });
|
|
57937
58231
|
}
|
|
@@ -57961,7 +58255,7 @@ var init_goal2 = __esm({
|
|
|
57961
58255
|
});
|
|
57962
58256
|
|
|
57963
58257
|
// src/commands/goal-cloud.ts
|
|
57964
|
-
import
|
|
58258
|
+
import fs74 from "node:fs";
|
|
57965
58259
|
import os6 from "node:os";
|
|
57966
58260
|
import path74 from "node:path";
|
|
57967
58261
|
import crypto6 from "node:crypto";
|
|
@@ -57995,17 +58289,17 @@ async function discussion() {
|
|
|
57995
58289
|
const machineFile2 = path74.join(home3, "machine.json");
|
|
57996
58290
|
let machine;
|
|
57997
58291
|
try {
|
|
57998
|
-
machine = JSON.parse(
|
|
58292
|
+
machine = JSON.parse(fs74.readFileSync(machineFile2, "utf8")).id;
|
|
57999
58293
|
} catch {
|
|
58000
58294
|
machine = crypto6.randomUUID();
|
|
58001
|
-
|
|
58002
|
-
|
|
58295
|
+
fs74.mkdirSync(home3, { recursive: true });
|
|
58296
|
+
fs74.writeFileSync(machineFile2, JSON.stringify({ id: machine }));
|
|
58003
58297
|
}
|
|
58004
58298
|
const held4 = await request("GET", `/v1/runner/folders?machine=${encodeURIComponent(machine)}`);
|
|
58005
|
-
const cwd =
|
|
58299
|
+
const cwd = fs74.realpathSync(process.cwd());
|
|
58006
58300
|
const folder2 = held4.folders.filter((f) => {
|
|
58007
58301
|
try {
|
|
58008
|
-
const dir =
|
|
58302
|
+
const dir = fs74.realpathSync(f.path);
|
|
58009
58303
|
return cwd === dir || cwd.startsWith(dir + path74.sep);
|
|
58010
58304
|
} catch {
|
|
58011
58305
|
return false;
|
|
@@ -58319,7 +58613,7 @@ var init_agent = __esm({
|
|
|
58319
58613
|
|
|
58320
58614
|
// src/commands/cloud-template.ts
|
|
58321
58615
|
import { createHash as createHash5 } from "node:crypto";
|
|
58322
|
-
import
|
|
58616
|
+
import fs75 from "node:fs";
|
|
58323
58617
|
import path75 from "node:path";
|
|
58324
58618
|
function usage2(problem, line) {
|
|
58325
58619
|
die(`${problem}
|
|
@@ -58384,9 +58678,9 @@ async function downloadEntries(name, kind, files, to, fallback) {
|
|
|
58384
58678
|
if (file2.sha256 && createHash5("sha256").update(bytes2).digest("hex") !== file2.sha256) refuse4(T.corrupt, fallback, invalidResponse(expected));
|
|
58385
58679
|
fetched.push({ out, bytes: bytes2 });
|
|
58386
58680
|
}
|
|
58387
|
-
if (fetched.length)
|
|
58681
|
+
if (fetched.length) fs75.mkdirSync(to, { recursive: true });
|
|
58388
58682
|
return fetched.map(({ out, bytes: bytes2 }) => {
|
|
58389
|
-
|
|
58683
|
+
fs75.writeFileSync(out, bytes2);
|
|
58390
58684
|
say(out);
|
|
58391
58685
|
return out;
|
|
58392
58686
|
});
|
|
@@ -58459,7 +58753,7 @@ async function templateGet(name, opts, program2) {
|
|
|
58459
58753
|
}
|
|
58460
58754
|
fetched.push({ out, bytes: bytes2 });
|
|
58461
58755
|
}
|
|
58462
|
-
const taken = fetched.filter((f) =>
|
|
58756
|
+
const taken = fetched.filter((f) => fs75.existsSync(f.out)).map((f) => path75.relative(to, f.out));
|
|
58463
58757
|
if (taken.length > 0) {
|
|
58464
58758
|
refuse4({
|
|
58465
58759
|
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`,
|
|
@@ -58467,8 +58761,8 @@ async function templateGet(name, opts, program2) {
|
|
|
58467
58761
|
});
|
|
58468
58762
|
}
|
|
58469
58763
|
for (const f of fetched) {
|
|
58470
|
-
|
|
58471
|
-
|
|
58764
|
+
fs75.mkdirSync(path75.dirname(f.out), { recursive: true });
|
|
58765
|
+
fs75.writeFileSync(f.out, f.bytes);
|
|
58472
58766
|
}
|
|
58473
58767
|
say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
|
|
58474
58768
|
Fetched ${name}: ${fetched.length} files into ${to}`);
|
|
@@ -58490,13 +58784,13 @@ async function templateSource(name, opts) {
|
|
|
58490
58784
|
async function templatePublish(dir, opts) {
|
|
58491
58785
|
const root2 = path75.resolve(dir);
|
|
58492
58786
|
const manifest = path75.join(root2, "template.md");
|
|
58493
|
-
if (!
|
|
58494
|
-
const meta3 = readTemplateMeta(
|
|
58787
|
+
if (!fs75.existsSync(manifest)) invalid2("\u6587\u4EF6\u5939\u9876\u5C42\u7F3A\u5C11 template.md\u3002", "template.md is missing from the folder\u2019s top level.");
|
|
58788
|
+
const meta3 = readTemplateMeta(fs75.readFileSync(manifest, "utf8"));
|
|
58495
58789
|
const files = walk2(root2);
|
|
58496
|
-
const total = files.reduce((sum, f) => sum +
|
|
58790
|
+
const total = files.reduce((sum, f) => sum + fs75.statSync(path75.join(root2, f)).size, 0);
|
|
58497
58791
|
if (total > MAX_BYTES2) invalid2("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
|
|
58498
58792
|
for (const extra of [...opts.preview, ...opts.evidence]) {
|
|
58499
|
-
if (!
|
|
58793
|
+
if (!fs75.existsSync(extra)) invalid2(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
|
|
58500
58794
|
if (path75.resolve(extra).startsWith(root2 + path75.sep)) {
|
|
58501
58795
|
invalid2(
|
|
58502
58796
|
`${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`,
|
|
@@ -58509,7 +58803,7 @@ async function templatePublish(dir, opts) {
|
|
|
58509
58803
|
}
|
|
58510
58804
|
const form = new FormData();
|
|
58511
58805
|
form.set("meta", JSON.stringify({ ...meta3, replace: !!opts.replace }));
|
|
58512
|
-
const add2 = (kind, name, file2) => form.append(`${kind}:${name}`, new Blob([
|
|
58806
|
+
const add2 = (kind, name, file2) => form.append(`${kind}:${name}`, new Blob([fs75.readFileSync(file2)]), path75.basename(name));
|
|
58513
58807
|
for (const f of files) add2("files", f, path75.join(root2, f));
|
|
58514
58808
|
for (const f of opts.preview) add2("previews", path75.basename(f), f);
|
|
58515
58809
|
for (const f of opts.evidence) add2("evidence", path75.basename(f), f);
|
|
@@ -58537,10 +58831,10 @@ Deleted ${name} from the catalog.`);
|
|
|
58537
58831
|
}
|
|
58538
58832
|
async function templateShowcase(name, dir) {
|
|
58539
58833
|
const file2 = path75.join(dir, "showcase.json");
|
|
58540
|
-
if (!
|
|
58834
|
+
if (!fs75.existsSync(file2)) invalid2(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
|
|
58541
58835
|
let meta3;
|
|
58542
58836
|
try {
|
|
58543
|
-
meta3 = JSON.parse(
|
|
58837
|
+
meta3 = JSON.parse(fs75.readFileSync(file2, "utf8"));
|
|
58544
58838
|
} catch {
|
|
58545
58839
|
return invalid2("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
|
|
58546
58840
|
}
|
|
@@ -58553,8 +58847,8 @@ async function templateShowcase(name, dir) {
|
|
|
58553
58847
|
form.set("meta", JSON.stringify(meta3));
|
|
58554
58848
|
for (const p of new Set(named2)) {
|
|
58555
58849
|
const at = path75.join(dir, p);
|
|
58556
|
-
if (!
|
|
58557
|
-
form.append(`media:${p}`, new Blob([
|
|
58850
|
+
if (!fs75.existsSync(at)) invalid2(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at}\u3002`, `${at} does not exist.`);
|
|
58851
|
+
form.append(`media:${p}`, new Blob([fs75.readFileSync(at)]), p);
|
|
58558
58852
|
}
|
|
58559
58853
|
const done = requireResponse(
|
|
58560
58854
|
await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form })),
|
|
@@ -58567,7 +58861,7 @@ Updated ${name}'s showcase: ${done.files} files.`);
|
|
|
58567
58861
|
}
|
|
58568
58862
|
function walk2(root2, sub = "") {
|
|
58569
58863
|
const out = [];
|
|
58570
|
-
for (const entry of
|
|
58864
|
+
for (const entry of fs75.readdirSync(path75.join(root2, sub), { withFileTypes: true })) {
|
|
58571
58865
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
58572
58866
|
const rel3 = sub ? `${sub}/${entry.name}` : entry.name;
|
|
58573
58867
|
if (entry.isDirectory()) out.push(...walk2(root2, rel3));
|
|
@@ -62784,7 +63078,7 @@ var init_archive2 = __esm({
|
|
|
62784
63078
|
var board_default;
|
|
62785
63079
|
var init_board3 = __esm({
|
|
62786
63080
|
"src/guide/board.md"() {
|
|
62787
|
-
board_default = "# How this board works\n\nThese rules apply to every card studio. Read them once; each studio's guide covers\nthe remaining details.\n\n## Layout\n\n```\ndocs/kanban/\n\u251C\u2500\u2500 todo/ open tasks\n\u2502 \u251C\u2500\u2500 README.md the index \u2014 read it first\n\u2502 \u2514\u2500\u2500 <id>-<slug>.md\n\u2502 one card per file; a group keeps its cards in one folder\n\u251C\u2500\u2500 rules/ `studios/<studio>.md` \u2014 Studio notes, set with `akb studio rule`\n\u2502 `<agent>.md` \u2014 project background-task instructions, set with\n\u2502 `akb studio instructions`\n\u251C\u2500\u2500 triage/ items waiting to be sorted, one file each \u2014 not cards. Only\n\u2502 \u2502 Cloud's sort or Refine idea on the web's Triage page turns one\n\u2502 \u2502 into a card; `akb raw triage check <source-id>` finds an existing one\n\u2502 \u251C\u2500\u2500 archived/ items a card was made of\n\u2502 \u251C\u2500\u2500 dismissed/ items ignored, with the reason\n\u2502 \u2514\u2500\u2500 files/ dropped-in files\n\u2514\u2500\u2500 modules.md one line per module \u2014 `akb guide module-map` writes it\n```\n\n## Task ID\n\nEvery task's id is the number at the front of its filename (`04-plan-cap-enforcement.md` \u2192\nid 4): its Cloud task's number (`WC-4`). Only Cloud assigns one.\n\n## Never hand-write a card's frontmatter\n\n`akb raw update`, `update-questions` and `akb raw conflict resolve` manage
|
|
63081
|
+
board_default = "# How this board works\n\nThese rules apply to every card studio. Read them once; each studio's guide covers\nthe remaining details.\n\n## Layout\n\n```\ndocs/kanban/\n\u251C\u2500\u2500 todo/ open tasks\n\u2502 \u251C\u2500\u2500 README.md the index \u2014 read it first\n\u2502 \u2514\u2500\u2500 <id>-<slug>.md\n\u2502 one card per file; a group keeps its cards in one folder\n\u251C\u2500\u2500 rules/ `studios/<studio>.md` \u2014 Studio notes, set with `akb studio rule`\n\u2502 `<agent>.md` \u2014 project background-task instructions, set with\n\u2502 `akb studio instructions`\n\u251C\u2500\u2500 triage/ items waiting to be sorted, one file each \u2014 not cards. Only\n\u2502 \u2502 Cloud's sort or Refine idea on the web's Triage page turns one\n\u2502 \u2502 into a card; `akb raw triage check <source-id>` finds an existing one\n\u2502 \u251C\u2500\u2500 archived/ items a card was made of\n\u2502 \u251C\u2500\u2500 dismissed/ items ignored, with the reason\n\u2502 \u2514\u2500\u2500 files/ dropped-in files\n\u2514\u2500\u2500 modules.md one line per module \u2014 `akb guide module-map` writes it\n```\n\n## Task ID\n\nEvery task's id is the number at the front of its filename (`04-plan-cap-enforcement.md` \u2192\nid 4): its Cloud task's number (`WC-4`). Only Cloud assigns one.\n\n## Never hand-write a card's frontmatter\n\n`akb raw update`, `akb task update-questions` and `akb raw conflict resolve` manage a card's frontmatter,\nincluding its `previews`. Edit only the card's **body** by hand. `akb raw help`\nlists all operations; `akb raw help <move>` explains one operation.\n\n## Content conflicts\n\nFor synchronization conflicts, follow `akb guide resolve-conflict`.\n\n## Inside a board run\n\nA board run carries `KANBAN_RUN` in its environment. Never unset or bypass it (for example\n`env -u KANBAN_RUN`): when a command only prints a flow, follow the printed flow.\n\n## Group task\n\nA group lives in `todo/<id>-<slug>/`: `root.md` tracks the whole job and each subtask is its\nown card beside it; `akb guide add-task` says how to build one. The root's `## Todo` lists the\nsubtasks, one line each ending in `#<subid>`: archiving a subtask ticks its line, rejecting\none strikes it through, and resolving the last line archives the root in the same run, with\nany open question or unticked todo of its own. A board a Runner keeps leaves that close to\nCloud, which waits for the root to be queued with no step on it. A root listing no subtasks is\nonly closed by hand.\n\n## Task context\n\nContinue from the task's saved discussion, results and approved requirements. Follow explicit\nproject and Studio rules. Read relevant memory on demand; do not write memory in task runs.\n";
|
|
62788
63082
|
}
|
|
62789
63083
|
});
|
|
62790
63084
|
|
|
@@ -62792,7 +63086,7 @@ var init_board3 = __esm({
|
|
|
62792
63086
|
var card_chat_default;
|
|
62793
63087
|
var init_card_chat = __esm({
|
|
62794
63088
|
"src/guide/card-chat.md"() {
|
|
62795
|
-
card_chat_default = '# Answer a card\'s conversation\n\nRead the task\u2019s review plan and work only on unlocked stages. An empty plan needs no extra approval; an undecided plan allows planning only.\n\n- **Where the task stands**: read `akb task show <id>` and `akb task review <id>`.\n- **Button labels**: name actions by their labels on the page, in the user\'s language: "Approve" or "Approve, start \u2026" (\u6279\u51C6 / \u6279\u51C6\uFF0C\u5F00\u59CB\u2026), "Resume" (\u7EED\u8DD1), "Start again" (\u91CD\u65B0\u53D1\u8D77).\n\n- **Change requirements or drafts**: when the user changes the scope, expected behavior, or draft, use `akb raw card revise <id> --print "<change>"`.\n- **Record an answer**: when the user answers an open question on the card, use `akb raw card resolve <id> --print`.\n- **Manage open questions**: when a decision needs the user\'s input, follow `akb guide update-questions` and use `akb
|
|
63089
|
+
card_chat_default = '# Answer a card\'s conversation\n\nRead the task\u2019s review plan and work only on unlocked stages. An empty plan needs no extra approval; an undecided plan allows planning only.\n\n- **Where the task stands**: read `akb task show <id>` and `akb task review <id>`.\n- **Button labels**: name actions by their labels on the page, in the user\'s language: "Approve" or "Approve, start \u2026" (\u6279\u51C6 / \u6279\u51C6\uFF0C\u5F00\u59CB\u2026), "Resume" (\u7EED\u8DD1), "Start again" (\u91CD\u65B0\u53D1\u8D77).\n\n- **Change requirements or drafts**: when the user changes the scope, expected behavior, or draft, use `akb raw card revise <id> --print "<change>"`.\n- **Record an answer**: when the user answers an open question on the card, use `akb raw card resolve <id> --print`.\n- **Manage open questions**: when a decision needs the user\'s input, follow `akb guide update-questions` and use `akb task update-questions <task>` to edit the question list.\n- **Change card fields**: when the user changes metadata such as priority, modules, or dependencies, use `akb raw update <id>`.\n- **Previews**: prepare or revise only requested outputs, using the task-bound Studio\u2019s Preview instructions and supplied component documentation. Before changing approved output, invalidate its stage with `akb task review <id> --revise-from <stage> --revision <n>`. Preserve unrelated work.\n- **Create a separate task**: when the user asks to capture work unrelated to this card, follow `akb guide add-task`.\n- **Split this card**: when the user asks to break this card\'s outcome into subtasks, follow the group procedure in `akb guide add-task`.\n- **Change a studio**: use `akb guide update-studio` for shared Studio instructions; a correction to this card\'s draft alone stays on this card.\n- **Check card edits**: after writing a card, run `akb raw validate <id>` and fix what it reports.\n- **Anything else**: for a request this guide does not cover, read `akb help` once, then the matching command\'s `--help`.\n\nReply in plain, natural language. Do not write memory, including through any flow this conversation starts.\n\n- **Approve**: only on an explicit request, use `akb task approve <id> --stage <stage> --revision <reviewed revision>`. In a reply this commits after successful synchronization. Finish the reply without further edits or waiting. Never substitute the latest revision for the one reviewed.\n- **Change the plan**: submit a complete replacement with `akb task review <id> --file <json> --revision <n>`. It takes effect immediately. Answers to questions never approve work.\n';
|
|
62796
63090
|
}
|
|
62797
63091
|
});
|
|
62798
63092
|
|
|
@@ -62832,7 +63126,7 @@ var init_follow_up = __esm({
|
|
|
62832
63126
|
var implement_default;
|
|
62833
63127
|
var init_implement = __esm({
|
|
62834
63128
|
"src/guide/implement.md"() {
|
|
62835
|
-
implement_default = "# Implement the approved requirements\n\nBuild the approved requirements without reopening settled decisions or unrelated questions; without a card, create none.\n\nFor Git deliveries, adapt the approved work to the current target branch and preserve its\nbehavior and removals unless the task's core intent requires changing them. Stop the\naffected work and use `akb guide update-questions` only if those changes conflict with the\ntask's core intent.\n\nDo not push, publish or deploy.\n\nOnce a task meets its Studio's delivery conditions, follow `akb guide archive` to record\ndelivery completion before ending the run.\n\n- **Verification**: run required and minimal representative checks, reuse valid results, distinguish defects from environment or tool limits, stop retries that add no evidence, and finish when acceptance is proven.\n- **Authorization**: carry approval for necessary in-scope operations across tools and stages without asking again.\n- **Blockers**: resolve routine problems and use `akb guide update-questions` only for user-action blockers or out-of-scope decisions, stating attempts, impact and recommendation while continuing independent work.\n- **Defer**: follow `akb guide follow-up` for unrelated work and keep it from blocking delivery.\n- **Decisions**: record material, reversible build decisions under `## Worth noting after implementation`.\n";
|
|
63129
|
+
implement_default = "# Implement the approved requirements\n\nBuild the approved requirements without reopening settled decisions or unrelated questions; without a card, create none.\n\nBefore implementing a Cloud task, read its recent chat with `akb task chat <task>`.\nRead older messages as needed. Use relevant clarifications within the scope of\nthe current card and approved plan.\n\nFor Git deliveries, adapt the approved work to the current target branch and preserve its\nbehavior and removals unless the task's core intent requires changing them. Stop the\naffected work and use `akb guide update-questions` only if those changes conflict with the\ntask's core intent.\n\nDo not push, publish or deploy.\n\nOnce a task meets its Studio's delivery conditions, follow `akb guide archive` to record\ndelivery completion before ending the run.\n\n- **Verification**: run required and minimal representative checks, reuse valid results, distinguish defects from environment or tool limits, stop retries that add no evidence, and finish when acceptance is proven.\n- **Authorization**: carry approval for necessary in-scope operations across tools and stages without asking again.\n- **Blockers**: resolve routine problems and use `akb guide update-questions` only for user-action blockers or out-of-scope decisions, stating attempts, impact and recommendation while continuing independent work.\n- **Defer**: follow `akb guide follow-up` for unrelated work and keep it from blocking delivery.\n- **Decisions**: record material, reversible build decisions under `## Worth noting after implementation`.\n";
|
|
62836
63130
|
}
|
|
62837
63131
|
});
|
|
62838
63132
|
|
|
@@ -62888,7 +63182,7 @@ var init_reflect = __esm({
|
|
|
62888
63182
|
var resolve_default;
|
|
62889
63183
|
var init_resolve2 = __esm({
|
|
62890
63184
|
"src/guide/resolve.md"() {
|
|
62891
|
-
resolve_default = '# Resolve questions\n\nApply the answers the user supplied to existing open questions. Leave every unanswered\nquestion unchanged. While applying answers, do not research, choose for the user, raise\nanother question, or change project code.\n\n## Apply each answer\n\n1. Match each supplied answer to its open question. If the answer is missing or unclear,\n leave that question open.\n2. Follow `akb guide writing`. Merge the answer into the existing decision, keep only the\n selected choice, remove obsolete or contradictory text, preserve completed work, and add\n newly required work as unchecked todos. When the answer changes an agent\'s section, read\n that agent\'s rules first, as "Preview ownership" there says.\
|
|
63185
|
+
resolve_default = '# Resolve questions\n\nApply the answers the user supplied to existing open questions. Leave every unanswered\nquestion unchanged. While applying answers, do not research, choose for the user, raise\nanother question, or change project code.\n\n## Apply each answer\n\n1. Match each supplied answer to its open question. If the answer is missing or unclear,\n leave that question open.\n2. Follow `akb guide writing`. Merge the answer into the existing decision, keep only the\n selected choice, remove obsolete or contradictory text, preserve completed work, and add\n newly required work as unchecked todos. When the answer changes an agent\'s section, read\n that agent\'s rules first, as "Preview ownership" there says.\n\nWhen an answer accepts a step the user was asked to review and asks for no changes, tick that\nstep\'s review todo; an answer asking for changes leaves it unticked.\n\nWhen an answer chooses to discard the card, first run `akb raw delivery cancel <delivery>` if a\ndelivery is in flight, then `akb task remove <id> "<why>" --discard`, and stop. Skip every\nremaining step of this guide.\n\nWhen an answer sends an agent\'s (`agent:`) section back for rework that the user must confirm\nagain, keep or `--update` the question instead of dropping it. Once no question is left for\nthat agent, request each matching agent listed below it whose section is missing or says it\nis waiting.\n\nWhen an answer selects one of several options in a Preview block, remove the rejected\noptions and their spec-tmp files.\n\n## Say what the answers did to a build in flight\n\nA delivery builds the card as it was approved when it started, and applying answers is the\nonly thing that rewrites that card underneath it. You read the question and you wrote the\nanswer, so you are the only one who can tell a confirmation from a change \u2014 the board reads\nyour conclusion and never the card\'s text.\n\n```text\nakb raw delivery answered <delivery> --unchanged "<why>"\nakb raw delivery answered <delivery> --changed "<why>"\n```\n\n- **Record it before you drop the questions**: dropping the last one is what puts the board\n back in motion, and until the conclusion is written the build does not land.\n- **Judge the meaning, not the words**: confirming an option that is already built, writing\n down a decision the card already carries, and tidying prose are all `--unchanged`.\n Adding, dropping or changing a requirement is `--changed`.\n- **A wrong implementation confirmed is still a change**: an answer that blesses work\n contradicting the approved copy is `--changed`, however finished that work is.\n- **One conclusion per round**: it covers every answer you applied in this session. The\n delivery a `--changed` reopens starts on the card as it then reads, with none of its own.\n\n`akb raw card implement <id> --print` prints the delivery\'s id and the copy it is building.\nNothing to record when no delivery is in flight.\n\n## Curate the human half\n\nPut each answer `akb guide writing` places in `Worth noting` in that section; put other\nnecessary lasting decisions below the boundary.\n\nRe-read the whole human half against the same rule. Remove or move down entries that\nfail it, repeat scope, or overlap another entry. Merge entries governed by one decision. One to\nthree independent items is normal; every additional item needs distinct user-facing stakes.\n\n## Close the answered questions\n\nSave the body and any delivery conclusion first. Drop only the questions whose answers\nare fully applied. Runner synchronizes the updated body and question list together.\n\n```text\nakb task update-questions <task> --drop <n[,n...]>\n```\n\n## Refine\n\nIf any question remains open, stop and leave the card waiting. When a delivery is in flight,\nnever refine \u2014 even if `--changed` updated requirements, execution resumes directly from the\nupdated card.\n\nOnce no question is left and no delivery is building the card, refine it in this session by\n`akb guide refine`, which decides readiness:\n\n- **Partial**: when the card was refined before, revisit only what the answers changed.\n- **Full**: when the answers reshape the card or its `## Scope` is still the creation scaffold.\n';
|
|
62892
63186
|
}
|
|
62893
63187
|
});
|
|
62894
63188
|
|
|
@@ -62912,7 +63206,7 @@ var init_revise = __esm({
|
|
|
62912
63206
|
var update_questions_default;
|
|
62913
63207
|
var init_update_questions = __esm({
|
|
62914
63208
|
"src/guide/update-questions.md"() {
|
|
62915
|
-
update_questions_default = '# Decide what to ask the user\n\nA decision is a choice the work needs made. A question is a decision handed to the user:\nproject evidence cannot settle it, it materially affects what the user gets, and it has at\nleast two coherent options.\n\n### The material-decision test\n\nAsk when the tradeoff materially changes the delivered result, the accepted scope, the user\'s\nrisk, or a meaningful ongoing cost, and a reasonable reviewer may reject it; a studio\'s rules\nadd what else counts. Settle everything else yourself. Leave the question open and stop only\nthe work that depends on it. An obstacle only the user can clear is a question too: say what\ncannot proceed and offer ways forward.\n\n- **Write for users**: each option\'s outcome and main cost, your recommendation ticked; no\n card ids, agent names, or board jargon.\n- **Options**: exclusive unless they genuinely combine (`--mode multi`); never write an\n "other" option, the user always gets one.\n- **Not a question**: where a fix goes (`akb guide follow-up`).\n\n```text\nakb
|
|
63209
|
+
update_questions_default = '# Decide what to ask the user\n\nA decision is a choice the work needs made. A question is a decision handed to the user:\nproject evidence cannot settle it, it materially affects what the user gets, and it has at\nleast two coherent options.\n\n### The material-decision test\n\nAsk when the tradeoff materially changes the delivered result, the accepted scope, the user\'s\nrisk, or a meaningful ongoing cost, and a reasonable reviewer may reject it; a studio\'s rules\nadd what else counts. Settle everything else yourself. Leave the question open and stop only\nthe work that depends on it. An obstacle only the user can clear is a question too: say what\ncannot proceed and offer ways forward.\n\n- **Write for users**: each option\'s outcome and main cost, your recommendation ticked; no\n card ids, agent names, or board jargon.\n- **Options**: exclusive unless they genuinely combine (`--mode multi`); never write an\n "other" option, the user always gets one.\n- **Not a question**: where a fix goes (`akb guide follow-up`).\n\n```text\nakb task update-questions <task> \\\n --append "Which behavior should apply?" \\\n --recommended-option "A \u2014 outcome and cost" \\\n --option "B \u2014 outcome and cost"\n```\n\nUse the current task\'s key, ID, or project number. Runner saves the current card locally\nand synchronizes it with the rest of the card. For a Cloud version conflict, read the card\nagain and check the question positions before resubmitting.\n';
|
|
62916
63210
|
}
|
|
62917
63211
|
});
|
|
62918
63212
|
|
|
@@ -62944,7 +63238,7 @@ var init_write_prompt = __esm({
|
|
|
62944
63238
|
var writing_default;
|
|
62945
63239
|
var init_writing = __esm({
|
|
62946
63240
|
"src/guide/writing.md"() {
|
|
62947
|
-
writing_default = '# Write a card\n\nA card has a **human half** for review and a folded **agent half** for implementation.\nUse this order and keep the English section titles and empty scaffold sections:\n\n```text\n<One short paragraph: the problem and the intended result.>\n\n## Worth noting <- user\'s answers first, then material decisions; empty if none\n- **<decision>**: <chosen behavior and main cost in one sentence>\n\n## Worth noting after implementation\n- **<decision>**: <chosen behavior and main cost in one sentence>\n <- settled by the build; omit when empty; no logs or open questions\n\n<Preview id="<id>"> <- requested deliverable\n<result Markdown and assets>\n</Preview>\n\n<!-- agent --> <- folded content starts here\n\n## Scope <- requirements, not rationale\n### Done when <- acceptance checklist, when supplied\n- [ ] <observable result>\n\n## Todo <- implementation only; finish planning before writing steps\n- [ ] <one build step>\n\n## Decided by the agent <- other decisions and non-obvious findings the build needs\n- **<decision>**: <answer and required action>\n### Overruled by the user <- superseded decisions, always last\n```\n\n- **Decisions**: use the material-decision test in `akb guide update-questions` for Worth noting;\n merge entries governed by one policy and keep only the decision and its main cost.\n- **Delivery boundary**: Worth noting after implementation never changes approved scope or\n blocks an ongoing delivery; the build must fix deviations or refer them to the user.\n- **Preview sections**: use matching Preview tags and a stable Studio ID; keep the ID when revising.\n The app supplies localized titles and icons. Group files of one deliverable with Set.\n- **Previews**: read the relevant Studio `<Preview>` block and needed references before revising\n its section and assets in place.\n- **Preview presentation**: at every review point, show the deliverable directly; omit surrounding\n introductions, summaries and notes unless requested or needed for review, keeping necessary\n context brief and stating it once.\n- **Preserve work**: leave checked todos and supplied Done when checklists unchanged; append a\n todo to reverse completed work, and move user-overruled decisions to Overruled by the user\n until the card leaves no room to repeat them.\n- **Writing**: write clear behavior and necessary tradeoffs for a fresh reader, keep the human\n half self-contained, and state each fact once.\n- **Agent half**: keep only implementation-critical information not stated elsewhere; omit\n process logs and routine implementation planning, and leave unneeded sections empty.\n- **Frontmatter**: never edit frontmatter by hand; use `akb raw update` or `update-questions`.\n- **Validate**: run `akb raw validate <id>` after edits and fix every reported file and line.\n';
|
|
63241
|
+
writing_default = '# Write a card\n\nA card has a **human half** for review and a folded **agent half** for implementation.\nUse this order and keep the English section titles and empty scaffold sections:\n\n```text\n<One short paragraph: the problem and the intended result.>\n\n## Worth noting <- user\'s answers first, then material decisions; empty if none\n- **<decision>**: <chosen behavior and main cost in one sentence>\n\n## Worth noting after implementation\n- **<decision>**: <chosen behavior and main cost in one sentence>\n <- settled by the build; omit when empty; no logs or open questions\n\n<Preview id="<id>"> <- requested deliverable\n<result Markdown and assets>\n</Preview>\n\n<!-- agent --> <- folded content starts here\n\n## Scope <- requirements, not rationale\n### Done when <- acceptance checklist, when supplied\n- [ ] <observable result>\n\n## Todo <- implementation only; finish planning before writing steps\n- [ ] <one build step>\n\n## Decided by the agent <- other decisions and non-obvious findings the build needs\n- **<decision>**: <answer and required action>\n### Overruled by the user <- superseded decisions, always last\n```\n\n- **Decisions**: use the material-decision test in `akb guide update-questions` for Worth noting;\n merge entries governed by one policy and keep only the decision and its main cost.\n- **Delivery boundary**: Worth noting after implementation never changes approved scope or\n blocks an ongoing delivery; the build must fix deviations or refer them to the user.\n- **Preview sections**: use matching Preview tags and a stable Studio ID; keep the ID when revising.\n The app supplies localized titles and icons. Group files of one deliverable with Set.\n- **Previews**: read the relevant Studio `<Preview>` block and needed references before revising\n its section and assets in place.\n- **Preview presentation**: at every review point, show the deliverable directly; omit surrounding\n introductions, summaries and notes unless requested or needed for review, keeping necessary\n context brief and stating it once.\n- **Preserve work**: leave checked todos and supplied Done when checklists unchanged; append a\n todo to reverse completed work, and move user-overruled decisions to Overruled by the user\n until the card leaves no room to repeat them.\n- **Writing**: write clear behavior and necessary tradeoffs for a fresh reader, keep the human\n half self-contained, and state each fact once.\n- **Agent half**: keep only implementation-critical information not stated elsewhere; omit\n process logs and routine implementation planning, and leave unneeded sections empty.\n- **Frontmatter**: never edit frontmatter by hand; use `akb raw update` or `akb task update-questions`.\n- **Validate**: run `akb raw validate <id>` after edits and fix every reported file and line.\n';
|
|
62948
63242
|
}
|
|
62949
63243
|
});
|
|
62950
63244
|
|
|
@@ -63058,7 +63352,7 @@ var init_guide2 = __esm({
|
|
|
63058
63352
|
|
|
63059
63353
|
// src/commands/studio.ts
|
|
63060
63354
|
import crypto7 from "node:crypto";
|
|
63061
|
-
import
|
|
63355
|
+
import fs76 from "node:fs";
|
|
63062
63356
|
import path76 from "node:path";
|
|
63063
63357
|
function cmdStudioList() {
|
|
63064
63358
|
if (!studiosReachable().ok) die(NEEDS_CLOUD, "needs-cloud");
|
|
@@ -63077,7 +63371,7 @@ function cmdStudioDiagram(_id, _card, _folder) {
|
|
|
63077
63371
|
}
|
|
63078
63372
|
function cmdStudioValidate(folder2) {
|
|
63079
63373
|
const dir = path76.resolve(folder2);
|
|
63080
|
-
if (!
|
|
63374
|
+
if (!fs76.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) die(`${folder2} is not a folder`, "bad-args");
|
|
63081
63375
|
const files = readStudioFolder(dir);
|
|
63082
63376
|
let builtin = false;
|
|
63083
63377
|
try {
|
|
@@ -63099,7 +63393,7 @@ async function cmdStudioPull(id2, folder2) {
|
|
|
63099
63393
|
found(id2);
|
|
63100
63394
|
}
|
|
63101
63395
|
const dir = path76.resolve(folder2 ?? id2);
|
|
63102
|
-
if (
|
|
63396
|
+
if (fs76.existsSync(dir) && fs76.readdirSync(dir).length) die(`${folder2 ?? id2} is not empty`, "bad-args");
|
|
63103
63397
|
const read5 = await call("GET", `/v1/studios/${encodeURIComponent(cloudId)}`);
|
|
63104
63398
|
const { version: version2, files } = requireResponse(
|
|
63105
63399
|
cloudOk(read5, read5.ok || read5.code !== "not_found" ? void 0 : "no-such-studio"),
|
|
@@ -63108,9 +63402,9 @@ async function cmdStudioPull(id2, folder2) {
|
|
|
63108
63402
|
);
|
|
63109
63403
|
for (const [file2, text5] of Object.entries({ ...files, [VERSION_FILE]: versionText(cloudId, version2) })) {
|
|
63110
63404
|
const full = path76.join(dir, ...file2.split("/"));
|
|
63111
|
-
|
|
63405
|
+
fs76.mkdirSync(path76.dirname(full), { recursive: true });
|
|
63112
63406
|
const data = isAboutFile(file2) && !file2.endsWith(".md") && /^data:[^;]+;base64,/.exec(text5);
|
|
63113
|
-
|
|
63407
|
+
fs76.writeFileSync(full, data ? Buffer.from(text5.slice(data[0].length), "base64") : text5);
|
|
63114
63408
|
}
|
|
63115
63409
|
const shown = folder2 ?? `./${id2}`;
|
|
63116
63410
|
say(`Pulled ${id2} v${version2} into ${shown}.`);
|
|
@@ -63126,13 +63420,13 @@ async function publishFolder(dir, route2, body, requestId) {
|
|
|
63126
63420
|
const hash3 = crypto7.createHash("sha256").update(JSON.stringify({ route: route2, files: body.files, workspace: body.workspace })).digest("hex");
|
|
63127
63421
|
let held4;
|
|
63128
63422
|
try {
|
|
63129
|
-
held4 = JSON.parse(
|
|
63423
|
+
held4 = JSON.parse(fs76.readFileSync(pendingFile, "utf8"));
|
|
63130
63424
|
} catch {
|
|
63131
63425
|
}
|
|
63132
63426
|
if (requestId && held4?.requestId === requestId && held4.hash !== hash3) die("This request ID already names different files; use a new request ID.", "bad-args");
|
|
63133
63427
|
const replay = held4?.hash === hash3 && held4.route === route2 && (!requestId || held4.requestId === requestId) && (body.expectedVersion === held4.body.expectedVersion || body.expectedVersion === held4.resultVersion);
|
|
63134
63428
|
const pending = replay ? held4 : { requestId: requestId ?? crypto7.randomUUID(), hash: hash3, body, route: route2 };
|
|
63135
|
-
|
|
63429
|
+
fs76.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
63136
63430
|
const res = await call(route2 === "/v1/studios" ? "POST" : "PATCH", route2, pending.body, pending.requestId);
|
|
63137
63431
|
const { id: id2, version: version2 } = requireResponse(
|
|
63138
63432
|
cloudOk(res, !res.ok && ["version_conflict", "conflict"].includes(res.code ?? "") ? "studio-moved" : void 0),
|
|
@@ -63140,8 +63434,8 @@ async function publishFolder(dir, route2, body, requestId) {
|
|
|
63140
63434
|
(value) => hasText(value.id) && /^wf_[\w-]+$/.test(value.id) && isStudioVersion(value.version) && (pending.body.expectedVersion === void 0 || route2 === `/v1/studios/${encodeURIComponent(value.id)}` && value.version === pending.body.expectedVersion + 1)
|
|
63141
63435
|
);
|
|
63142
63436
|
pending.resultVersion = version2;
|
|
63143
|
-
|
|
63144
|
-
|
|
63437
|
+
fs76.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
63438
|
+
fs76.writeFileSync(path76.join(dir, VERSION_FILE), versionText(id2, version2));
|
|
63145
63439
|
say(`Saved ${studioName(id2)} v${version2}. New tasks take it.`);
|
|
63146
63440
|
return { id: id2, version: version2, changed: true, requestId: pending.requestId };
|
|
63147
63441
|
}
|
|
@@ -63156,14 +63450,14 @@ async function cmdStudioPush(folder2, opts) {
|
|
|
63156
63450
|
const dir = path76.resolve(folder2);
|
|
63157
63451
|
let pulled = null;
|
|
63158
63452
|
try {
|
|
63159
|
-
pulled = JSON.parse(
|
|
63453
|
+
pulled = JSON.parse(fs76.readFileSync(path76.join(dir, VERSION_FILE), "utf8"));
|
|
63160
63454
|
} catch {
|
|
63161
63455
|
}
|
|
63162
63456
|
if (!pulled?.id || !Number.isInteger(pulled.version) || pulled.version < 1) die(`${folder2} has no valid version.json; pull again.`, "bad-args");
|
|
63163
63457
|
const { id: id2, version: version2 } = pulled;
|
|
63164
63458
|
if (id2.startsWith("wf_builtin_")) die("Copy this studio before editing it.", "studio-read-only");
|
|
63165
63459
|
const files = publicationFiles(dir);
|
|
63166
|
-
if (!
|
|
63460
|
+
if (!fs76.existsSync(path76.join(dir, ".publication.json")) && !opts.requestId) {
|
|
63167
63461
|
const now = await call("GET", `/v1/studios/${encodeURIComponent(id2)}`);
|
|
63168
63462
|
if (now.ok && now.value.version === version2 && isStudioFiles(now.value.files) && JSON.stringify(files) === JSON.stringify(Object.fromEntries(Object.entries(now.value.files).filter(([f]) => f !== VERSION_FILE).sort()))) {
|
|
63169
63463
|
say(`${studioName(id2)} is unchanged (v${version2}).`);
|
|
@@ -63186,7 +63480,7 @@ function noteText({ file: file2, text: text5 }) {
|
|
|
63186
63480
|
if (file2 !== void 0 && text5 !== void 0) die("pass --file or --text, not both", "bad-args");
|
|
63187
63481
|
if (file2 !== void 0) {
|
|
63188
63482
|
try {
|
|
63189
|
-
return
|
|
63483
|
+
return fs76.readFileSync(file2, "utf8").trim();
|
|
63190
63484
|
} catch {
|
|
63191
63485
|
die(`can't read ${file2}`, "bad-args");
|
|
63192
63486
|
}
|
|
@@ -63372,7 +63666,12 @@ var init_progress = __esm({
|
|
|
63372
63666
|
});
|
|
63373
63667
|
|
|
63374
63668
|
// src/lib/agent/complete.ts
|
|
63375
|
-
import
|
|
63669
|
+
import fs77 from "node:fs";
|
|
63670
|
+
function checkRecordedResult(receipt, commit, branch) {
|
|
63671
|
+
if (receipt.commit === commit && receipt.branch === branch) return;
|
|
63672
|
+
const describe4 = (hash3, target) => hash3 ? `${hash3} on ${target}` : "no Git result";
|
|
63673
|
+
throw new Error(`This step already recorded a different result. Recorded: ${describe4(receipt.commit, receipt.branch)}. Reported: ${describe4(commit, branch)}.`);
|
|
63674
|
+
}
|
|
63376
63675
|
function completeDelivery(named2, result = {}) {
|
|
63377
63676
|
const commit = result.commit?.toLowerCase();
|
|
63378
63677
|
const branch = result.branch;
|
|
@@ -63395,13 +63694,13 @@ function completeDelivery(named2, result = {}) {
|
|
|
63395
63694
|
const run3 = store.runs.find((r) => r.sessionId === sessionId);
|
|
63396
63695
|
const current = store.runs.filter((r) => r.deliveryId === delivery2.deliveryId && ["implement", "scheduled"].includes(r.action)).pop();
|
|
63397
63696
|
const liveCard = delivery2.cardId === null ? null : cardFile(delivery2.cardId);
|
|
63398
|
-
const restored = liveCard && parseFrontmatter(
|
|
63697
|
+
const restored = liveCard && parseFrontmatter(fs77.readFileSync(liveCard, "utf8")).meta?.restored;
|
|
63399
63698
|
if (restored && Date.parse(restored) > (run3?.startedAt ?? 0)) throw new Error("This delivery predates task restoration.");
|
|
63400
63699
|
if (!run3 || run3.deliveryId !== delivery2.deliveryId) throw new Error("This run does not own the delivery.");
|
|
63401
63700
|
const pending = receipts[deliveryStep(delivery2)];
|
|
63402
63701
|
const previous = receipts.find((c) => c.sessionId === sessionId || c.resumedSessions?.includes(sessionId));
|
|
63403
63702
|
if (previous) {
|
|
63404
|
-
|
|
63703
|
+
checkRecordedResult(previous, commit, branch);
|
|
63405
63704
|
if (!previous.finished && previous.step === deliveryStep(delivery2) && (delivery2.status !== "active" || run3 !== current || run3.status !== "running")) {
|
|
63406
63705
|
throw new Error("Only the current owning run can finish pending completion.");
|
|
63407
63706
|
}
|
|
@@ -63412,7 +63711,7 @@ function completeDelivery(named2, result = {}) {
|
|
|
63412
63711
|
}
|
|
63413
63712
|
if (answerOutcome(delivery2) === "changed") throw new Error("The approved requirements were superseded. Continue with the updated delivery.");
|
|
63414
63713
|
if (pending && run3 === current) {
|
|
63415
|
-
|
|
63714
|
+
checkRecordedResult(pending, commit, branch);
|
|
63416
63715
|
pending.resumedSessions = [...pending.resumedSessions ?? [], sessionId];
|
|
63417
63716
|
return { delivery: delivery2, receipt: pending };
|
|
63418
63717
|
}
|
|
@@ -63503,7 +63802,7 @@ function startSubRun(parentId, prompt, runtime) {
|
|
|
63503
63802
|
const parent = peekRun(parentId);
|
|
63504
63803
|
if (!parent || parent.status !== "running") return refusal("runNotFound", `run ${parentId.slice(0, 8)} is not running here`, { id: parentId });
|
|
63505
63804
|
if (parent.action === "sub") return refusal("subRunNested", "a sub-run cannot start sub-runs of its own");
|
|
63506
|
-
const inherited = parent.runtime &&
|
|
63805
|
+
const inherited = parent.runtime && runRuntimeById(parent.runtime) ? parent.runtime : void 0;
|
|
63507
63806
|
return open3(
|
|
63508
63807
|
{
|
|
63509
63808
|
action: "sub",
|
|
@@ -63566,7 +63865,7 @@ var init_start = __esm({
|
|
|
63566
63865
|
});
|
|
63567
63866
|
|
|
63568
63867
|
// src/lib/agent/task-chats.ts
|
|
63569
|
-
import
|
|
63868
|
+
import fs78 from "node:fs";
|
|
63570
63869
|
import path77 from "node:path";
|
|
63571
63870
|
function taskChatFile(task, home3) {
|
|
63572
63871
|
if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
|
|
@@ -63575,7 +63874,7 @@ function taskChatFile(task, home3) {
|
|
|
63575
63874
|
function readTaskChat(task, home3) {
|
|
63576
63875
|
let text5;
|
|
63577
63876
|
try {
|
|
63578
|
-
text5 =
|
|
63877
|
+
text5 = fs78.readFileSync(taskChatFile(task, home3), "utf8");
|
|
63579
63878
|
} catch {
|
|
63580
63879
|
return [];
|
|
63581
63880
|
}
|
|
@@ -63601,7 +63900,7 @@ var init_task_chats = __esm({
|
|
|
63601
63900
|
});
|
|
63602
63901
|
|
|
63603
63902
|
// src/lib/agent/memory-review.ts
|
|
63604
|
-
import
|
|
63903
|
+
import fs79 from "node:fs";
|
|
63605
63904
|
import path78 from "node:path";
|
|
63606
63905
|
function taskChatsToReview(tasks) {
|
|
63607
63906
|
const out = [];
|
|
@@ -63625,7 +63924,7 @@ function readArchived2(id2) {
|
|
|
63625
63924
|
if (!found2) return null;
|
|
63626
63925
|
try {
|
|
63627
63926
|
const file2 = found2.kind === "group" ? path78.join(found2.target, "root.md") : found2.target;
|
|
63628
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
63927
|
+
const { meta: meta3, body } = parseFrontmatter(fs79.readFileSync(file2, "utf8"));
|
|
63629
63928
|
if (!meta3) return null;
|
|
63630
63929
|
return { id: id2, title: meta3.title, modules: meta3.modules ?? [], studio: meta3.studio ?? "", previews: meta3.previews ?? [], rejected: meta3.rejected, body };
|
|
63631
63930
|
} catch {
|
|
@@ -63686,18 +63985,18 @@ var init_memory_review = __esm({
|
|
|
63686
63985
|
});
|
|
63687
63986
|
|
|
63688
63987
|
// src/lib/agent/dismissal-review.ts
|
|
63689
|
-
import
|
|
63988
|
+
import fs80 from "node:fs";
|
|
63690
63989
|
import path79 from "node:path";
|
|
63691
63990
|
function rejectionsToReview() {
|
|
63692
63991
|
const scratch = process.env.AI4KANBAN_REJECTION_INPUT;
|
|
63693
63992
|
const dir = path79.join(scratch ? path79.join(scratch, ".archive") : ARCHIVE, REJECTIONS_TO_REVIEW);
|
|
63694
|
-
if (!
|
|
63993
|
+
if (!fs80.existsSync(dir)) return [];
|
|
63695
63994
|
const found2 = [];
|
|
63696
63995
|
for (const file2 of walkMd(dir)) {
|
|
63697
63996
|
const id2 = archivedId(file2);
|
|
63698
63997
|
if (id2 === null) continue;
|
|
63699
63998
|
try {
|
|
63700
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
63999
|
+
const { meta: meta3 } = parseFrontmatter(fs80.readFileSync(file2, "utf8"));
|
|
63701
64000
|
if (!meta3?.rejected || meta3.rejected_by !== "user" || !meta3.rejected_reason.trim()) continue;
|
|
63702
64001
|
found2.push({ id: id2, title: meta3.title, file: rel(file2), reason: meta3.rejected_reason.trim(), rejectedAt: meta3.rejected_at });
|
|
63703
64002
|
} catch {
|
|
@@ -63719,7 +64018,7 @@ function citedSources(text5) {
|
|
|
63719
64018
|
const ids = /* @__PURE__ */ new Set();
|
|
63720
64019
|
for (const line of text5.split("\n")) {
|
|
63721
64020
|
if (!/^\s*[-*]\s/.test(line)) continue;
|
|
63722
|
-
const m = line.match(
|
|
64021
|
+
const m = line.match(SOURCES2);
|
|
63723
64022
|
for (const id2 of m?.[1].split(",") ?? []) if (id2.trim()) ids.add(id2.trim());
|
|
63724
64023
|
}
|
|
63725
64024
|
return [...ids];
|
|
@@ -63727,7 +64026,7 @@ function citedSources(text5) {
|
|
|
63727
64026
|
function withdrawnSources() {
|
|
63728
64027
|
const cited = [...new Set(plannerCopies("rejected.md").flatMap((file2) => {
|
|
63729
64028
|
try {
|
|
63730
|
-
return citedSources(
|
|
64029
|
+
return citedSources(fs80.readFileSync(file2, "utf8"));
|
|
63731
64030
|
} catch {
|
|
63732
64031
|
return [];
|
|
63733
64032
|
}
|
|
@@ -63738,7 +64037,7 @@ function withdrawnSources() {
|
|
|
63738
64037
|
const restored = new Set([...readInbox(), ...readArchived(scratch ? path79.join(scratch, "triage", "archived") : void 0)].map((s) => s.sourceId));
|
|
63739
64038
|
return cited.filter((id2) => restored.has(id2) && !dismissed.has(id2));
|
|
63740
64039
|
}
|
|
63741
|
-
var reviewDismissed,
|
|
64040
|
+
var reviewDismissed, SOURCES2;
|
|
63742
64041
|
var init_dismissal_review = __esm({
|
|
63743
64042
|
"src/lib/agent/dismissal-review.ts"() {
|
|
63744
64043
|
"use strict";
|
|
@@ -63752,12 +64051,12 @@ var init_dismissal_review = __esm({
|
|
|
63752
64051
|
const scratch = process.env.AI4KANBAN_REJECTION_INPUT;
|
|
63753
64052
|
return readAllDismissed(scratch ? path79.join(scratch, "triage", "dismissed") : void 0);
|
|
63754
64053
|
};
|
|
63755
|
-
|
|
64054
|
+
SOURCES2 = /\(([^()]+)\)\s*$/;
|
|
63756
64055
|
}
|
|
63757
64056
|
});
|
|
63758
64057
|
|
|
63759
64058
|
// src/lib/agent/flow.ts
|
|
63760
|
-
import
|
|
64059
|
+
import fs81 from "node:fs";
|
|
63761
64060
|
import path80 from "node:path";
|
|
63762
64061
|
function readCard2(id2, home3 = "board") {
|
|
63763
64062
|
const pending = activeDelivery(id2)?.completions?.some((c) => !c.finished);
|
|
@@ -63771,7 +64070,7 @@ function readCard2(id2, home3 = "board") {
|
|
|
63771
64070
|
const file2 = found2.kind === "group" ? path80.join(found2.target, "root.md") : found2.target;
|
|
63772
64071
|
let text5;
|
|
63773
64072
|
try {
|
|
63774
|
-
text5 =
|
|
64073
|
+
text5 = fs81.readFileSync(file2, "utf8");
|
|
63775
64074
|
} catch {
|
|
63776
64075
|
die(`#${id2} is on the board but ${rel(file2)} can't be read.`, { kind: "card-unreadable", id: id2 });
|
|
63777
64076
|
}
|
|
@@ -64426,13 +64725,32 @@ var init_coding_previews = __esm({
|
|
|
64426
64725
|
|
|
64427
64726
|
// src/lib/agent/approved-ui.ts
|
|
64428
64727
|
import path81 from "node:path";
|
|
64728
|
+
function approvedUiSource(pins, src, owner) {
|
|
64729
|
+
const [ref] = splitFileReference(src);
|
|
64730
|
+
if (artifactId.test(ref)) {
|
|
64731
|
+
const version2 = approvedUiPin(pins, ref).version;
|
|
64732
|
+
const names2 = Object.keys(pins).filter((name) => {
|
|
64733
|
+
const pin = approvedUiPin(pins, name);
|
|
64734
|
+
return pin.artifact === ref && (version2 === void 0 || pin.version === version2);
|
|
64735
|
+
});
|
|
64736
|
+
return names2.find((name) => !artifactId.test(name)) ?? names2[0] ?? ref;
|
|
64737
|
+
}
|
|
64738
|
+
const local = owner && !ref.startsWith(".assets/") ? relativeFileReference(ref, owner) : ref;
|
|
64739
|
+
return [local, src, ref, path81.posix.normalize(local)].find((key) => Object.hasOwn(pins, key)) ?? local;
|
|
64740
|
+
}
|
|
64741
|
+
function approvedUiPin(pins, source2) {
|
|
64742
|
+
return object2(Object.hasOwn(pins, source2) ? pins[source2] : void 0);
|
|
64743
|
+
}
|
|
64744
|
+
function validUiPin(pin) {
|
|
64745
|
+
return !pin.error && pin.status !== "pending" && pin.status !== "failed" && typeof pin.artifact === "string" && artifactId.test(pin.artifact) && typeof pin.version === "number" && Number.isSafeInteger(pin.version) && pin.version > 0;
|
|
64746
|
+
}
|
|
64429
64747
|
function approvedUiPreviews(review) {
|
|
64430
64748
|
if (reviewAuthorization(review).kind !== "delivery") return [];
|
|
64431
64749
|
const result = [];
|
|
64432
|
-
for (const node2 of review.plan ?? []) {
|
|
64750
|
+
for (const [index, node2] of (review.plan ?? []).entries()) {
|
|
64433
64751
|
const stage = review.stages.find((stage2) => stage2.id === node2.id);
|
|
64434
64752
|
const snapshot2 = stage?.snapshot;
|
|
64435
|
-
if (!stage || !snapshot2) continue;
|
|
64753
|
+
if (node2.kind === "work" || !stage || !snapshot2) continue;
|
|
64436
64754
|
const evidence = object2(snapshot2.evidence);
|
|
64437
64755
|
const content = object2(evidence.content);
|
|
64438
64756
|
const frozenPreviews = Array.isArray(snapshot2.previews) ? snapshot2.previews.filter(isObject2) : [];
|
|
@@ -64440,17 +64758,17 @@ function approvedUiPreviews(review) {
|
|
|
64440
64758
|
const preview = object2(content[id2]);
|
|
64441
64759
|
const body = typeof preview.body === "string" ? preview.body : typeof snapshot2.body === "string" ? parsePreviewBlocks(snapshot2.body).blocks.find((block) => block.id === id2)?.instructions : void 0;
|
|
64442
64760
|
if (!body) continue;
|
|
64443
|
-
const pins = { ...object2(frozenPreviews.find((preview2) => preview2.id === id2)?.assets), ...object2(evidence.assets) };
|
|
64761
|
+
const pins = { ...object2(evidence.dependencies), ...object2(frozenPreviews.find((preview2) => preview2.id === id2)?.assets), ...object2(evidence.assets) };
|
|
64444
64762
|
const files = /* @__PURE__ */ new Map();
|
|
64445
|
-
const add2 = (src, label2, device) => {
|
|
64446
|
-
|
|
64447
|
-
const
|
|
64448
|
-
if (
|
|
64763
|
+
const add2 = (src, label2, device, required2 = true) => {
|
|
64764
|
+
if (external.test(src)) return;
|
|
64765
|
+
const source2 = approvedUiSource(pins, src);
|
|
64766
|
+
if (!required2 && !Object.hasOwn(pins, source2) && !/\.(?:html?|tsx)$/i.test(source2)) return;
|
|
64449
64767
|
const name = label2.trim() || path81.posix.basename(src);
|
|
64450
64768
|
const key = JSON.stringify([src, name]);
|
|
64451
64769
|
let file2 = files.get(key);
|
|
64452
64770
|
if (!file2) {
|
|
64453
|
-
file2 = { src,
|
|
64771
|
+
file2 = { src, source: source2, label: name, devices: /* @__PURE__ */ new Set() };
|
|
64454
64772
|
files.set(key, file2);
|
|
64455
64773
|
}
|
|
64456
64774
|
file2.devices.add(device === "mobile" ? "Mobile" : device === "desktop" ? "Desktop" : "Device unspecified");
|
|
@@ -64470,33 +64788,53 @@ function approvedUiPreviews(review) {
|
|
|
64470
64788
|
}
|
|
64471
64789
|
}
|
|
64472
64790
|
const listed = new Set([...files.values()].map((file2) => file2.src));
|
|
64473
|
-
for (const src of bodySources(body)) if (!listed.has(src)) add2(src, "");
|
|
64474
|
-
result.push(
|
|
64791
|
+
for (const src of bodySources(body)) if (!listed.has(src)) add2(src, "", void 0, false);
|
|
64792
|
+
if (files.size) result.push({
|
|
64793
|
+
id: id2,
|
|
64794
|
+
revision: stage.revision,
|
|
64795
|
+
directory: `review-${stage.revision}-${index}/${id2}`,
|
|
64796
|
+
body,
|
|
64797
|
+
pins,
|
|
64798
|
+
files: [...files.values()]
|
|
64799
|
+
});
|
|
64475
64800
|
}
|
|
64476
64801
|
}
|
|
64477
64802
|
return result;
|
|
64478
64803
|
}
|
|
64479
|
-
function approvedUiFile(directory,
|
|
64480
|
-
const
|
|
64481
|
-
|
|
64482
|
-
|
|
64483
|
-
|
|
64484
|
-
|
|
64485
|
-
|
|
64486
|
-
|
|
64804
|
+
function approvedUiFile(directory, preview, source2) {
|
|
64805
|
+
const parts = path81.posix.normalize(splitFileReference(source2)[0]).split("/");
|
|
64806
|
+
let parents = 0;
|
|
64807
|
+
while (parts[0] === "..") {
|
|
64808
|
+
parts.shift();
|
|
64809
|
+
parents++;
|
|
64810
|
+
}
|
|
64811
|
+
const rendered = /\.tsx$/i.test(parts.at(-1) ?? "");
|
|
64812
|
+
if (rendered) parts[parts.length - 1] = parts.at(-1).replace(/\.tsx$/i, ".html");
|
|
64813
|
+
const safe2 = parts.map((part) => !part || part === "." ? "%00" : part.replace(/[\\:*?"<>|%\x00-\x1f]/g, (char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`));
|
|
64814
|
+
return path81.join(directory, preview.directory, `${rendered ? "rendered" : "files"}-${parents}`, ...safe2);
|
|
64815
|
+
}
|
|
64816
|
+
function approvedUiPrompt(review, directory, includeBody = false) {
|
|
64817
|
+
const previews = approvedUiPreviews(review);
|
|
64818
|
+
if (!previews.length) return "";
|
|
64487
64819
|
return [
|
|
64488
64820
|
"Approved UI previews",
|
|
64489
64821
|
APPROVED_UI_RULE,
|
|
64490
|
-
|
|
64491
|
-
|
|
64492
|
-
|
|
64493
|
-
|
|
64822
|
+
...previews.flatMap((preview) => [
|
|
64823
|
+
...includeBody ? [preview.body] : [],
|
|
64824
|
+
preview.files.flatMap((file2) => {
|
|
64825
|
+
const pin = approvedUiPin(preview.pins, file2.source);
|
|
64826
|
+
if (!validUiPin(pin)) return [];
|
|
64827
|
+
const ref = directory ? `frozen file: \`${approvedUiFile(directory, preview, file2.source)}\`` : `artifact ${pin.artifact}, version ${pin.version}`;
|
|
64828
|
+
return [`- ${file2.label} \xB7 ${[...file2.devices].join(" / ")} \xB7 Review revision ${preview.revision} \xB7 ${file2.src} \xB7 ${ref}`];
|
|
64829
|
+
}).join("\n")
|
|
64830
|
+
])
|
|
64494
64831
|
].join("\n\n");
|
|
64495
64832
|
}
|
|
64496
|
-
var APPROVED_UI_DIR_ENV, APPROVED_UI_RULE, UI_PREVIEW, historicalUiIds, object2;
|
|
64833
|
+
var APPROVED_UI_DIR_ENV, APPROVED_UI_RULE, UI_PREVIEW, historicalUiIds, object2, artifactId, external;
|
|
64497
64834
|
var init_approved_ui = __esm({
|
|
64498
64835
|
"src/lib/agent/approved-ui.ts"() {
|
|
64499
64836
|
"use strict";
|
|
64837
|
+
init_file_references();
|
|
64500
64838
|
init_references();
|
|
64501
64839
|
init_tags();
|
|
64502
64840
|
init_coding_previews();
|
|
@@ -64507,6 +64845,8 @@ var init_approved_ui = __esm({
|
|
|
64507
64845
|
UI_PREVIEW = "ui-design";
|
|
64508
64846
|
historicalUiIds = Object.keys(CODING_PREVIEWS).filter((id2) => id2 !== UI_PREVIEW && CODING_PREVIEWS[id2] === UI_PREVIEW);
|
|
64509
64847
|
object2 = (value) => isObject2(value) ? value : {};
|
|
64848
|
+
artifactId = /^art_[a-z0-9]+$/i;
|
|
64849
|
+
external = /^(?:[a-z][\w+.-]*:|\/|#)/i;
|
|
64510
64850
|
}
|
|
64511
64851
|
});
|
|
64512
64852
|
|
|
@@ -64575,7 +64915,7 @@ __export(watch_exports, {
|
|
|
64575
64915
|
watchRun: () => watchRun
|
|
64576
64916
|
});
|
|
64577
64917
|
import { spawn as spawn3 } from "node:child_process";
|
|
64578
|
-
import
|
|
64918
|
+
import fs82 from "node:fs";
|
|
64579
64919
|
async function watchRun(sessionId, resume = startResume, retryBackoff = backoffMs) {
|
|
64580
64920
|
const spec = readSpec(sessionId);
|
|
64581
64921
|
const run3 = peekRun(sessionId);
|
|
@@ -64611,20 +64951,24 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64611
64951
|
const record2 = claimed ?? run3;
|
|
64612
64952
|
const sub = record2.action === "sub";
|
|
64613
64953
|
if (claim2) await setCardStatus(claim2.cardId, claim2.status);
|
|
64614
|
-
|
|
64615
|
-
const logFile =
|
|
64954
|
+
fs82.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
64955
|
+
const logFile = fs82.createWriteStream(record2.logPath, { flags: "a" });
|
|
64616
64956
|
logFile.on("error", () => {
|
|
64617
64957
|
});
|
|
64618
|
-
const eventsFile =
|
|
64958
|
+
const eventsFile = fs82.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
|
|
64619
64959
|
eventsFile.on("error", () => {
|
|
64620
64960
|
});
|
|
64621
64961
|
let observeActivity = (_e) => {
|
|
64622
64962
|
};
|
|
64623
64963
|
const pendingOperations = /* @__PURE__ */ new Set();
|
|
64964
|
+
let hadEffects = false;
|
|
64624
64965
|
const event2 = (e) => {
|
|
64625
64966
|
observeActivity(e);
|
|
64626
64967
|
const hadPending = pendingOperations.size > 0;
|
|
64627
|
-
if (e.kind === "tool_call" && !["read", "search", "fetch"].includes(e.data.kind)
|
|
64968
|
+
if (e.kind === "tool_call" && !["read", "search", "fetch"].includes(e.data.kind)) {
|
|
64969
|
+
hadEffects = true;
|
|
64970
|
+
if (!["completed", "failed"].includes(e.data.status)) pendingOperations.add(e.data.toolCallId);
|
|
64971
|
+
}
|
|
64628
64972
|
if ((e.kind === "tool_call" || e.kind === "tool_call_update") && ["completed", "failed"].includes(e.data.status ?? "")) pendingOperations.delete(e.data.toolCallId);
|
|
64629
64973
|
if (record2.cloudExecution && hadPending !== pendingOperations.size > 0) {
|
|
64630
64974
|
patch(sessionId, (run4) => {
|
|
@@ -64634,6 +64978,11 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64634
64978
|
eventsFile.write(`${JSON.stringify(e)}
|
|
64635
64979
|
`);
|
|
64636
64980
|
};
|
|
64981
|
+
const runtimeInfo = () => ({
|
|
64982
|
+
connector: record2.harness,
|
|
64983
|
+
name: record2.runtime ? runtimeById(record2.runtime)?.name ?? null : null,
|
|
64984
|
+
model: peekRun(sessionId)?.model ?? record2.model ?? null
|
|
64985
|
+
});
|
|
64637
64986
|
const log = {
|
|
64638
64987
|
write(text5) {
|
|
64639
64988
|
logFile.write(text5);
|
|
@@ -64662,11 +65011,14 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64662
65011
|
const review = reviewContext?.review;
|
|
64663
65012
|
const boundary = review && reviewBoundary(savedPreviews ? { ...review, stages: review.stages.map((stage) => ({ ...stage, snapshot: null })) } : review, reviewContext.assigned);
|
|
64664
65013
|
const coding = record2.action === "implement" && studioForRun({ id: record2.cardId ?? void 0, deliveryId: record2.deliveryId }) === "coding";
|
|
64665
|
-
const
|
|
65014
|
+
const uiDirectory = process.env[APPROVED_UI_DIR_ENV];
|
|
65015
|
+
const approvedUi = review && coding && (!savedPreviews || uiDirectory) ? approvedUiPrompt(review, uiDirectory, !!savedPreviews) : "";
|
|
65016
|
+
const savedPrompt = savedPreviews ? [
|
|
64666
65017
|
`Read the saved task Previews and their pinned files in \`${savedPreviews}\`. Use these saved versions for the requirements they cover and verify the delivery against them.`,
|
|
64667
|
-
...coding && review?.plan?.some((node2) => node2.previews.includes("ui-design")) ? [APPROVED_UI_RULE] : []
|
|
64668
|
-
].join("\n") :
|
|
64669
|
-
const
|
|
65018
|
+
...coding && !approvedUi && review?.plan?.some((node2) => node2.previews.includes("ui-design")) ? [APPROVED_UI_RULE] : []
|
|
65019
|
+
].join("\n") : "";
|
|
65020
|
+
const retryDiag = record2.retry ? record2.failure ? retryContinuePrompt(record2.failure, record2.retry.attempt, record2.retry.of) : `Previous execution failed: ${record2.retry.reason}. Check existing results before continuing; do not repeat completed operations.` : "";
|
|
65021
|
+
const prompt = [process.env.AI4KANBAN_SYNC_DIAGNOSTIC ? syncRepairPrompt(process.env.AI4KANBAN_SYNC_DIAGNOSTIC) : "", retryDiag, conflictPrompt(KANBAN), boundary, basePrompt, resumedStudio, savedPrompt, approvedUi, recoveryPrompt2, discardedCardsPrompt(record2.discardedCards)].filter(Boolean).join("\n\n");
|
|
64670
65022
|
const before = markBoard();
|
|
64671
65023
|
const takes = active3.images;
|
|
64672
65024
|
active3.renderer?.setRequiredImages?.(record2.pictures ?? []);
|
|
@@ -64694,11 +65046,29 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64694
65046
|
letGo();
|
|
64695
65047
|
return 1;
|
|
64696
65048
|
}
|
|
64697
|
-
if (record2.retry?.launching)
|
|
64698
|
-
|
|
64699
|
-
r
|
|
64700
|
-
|
|
64701
|
-
|
|
65049
|
+
if (record2.retry?.launching) {
|
|
65050
|
+
const nextAttempt = record2.retry.attempt + 1;
|
|
65051
|
+
patch(sessionId, (r) => {
|
|
65052
|
+
if (!r.retry?.launching) return;
|
|
65053
|
+
r.retry.attempt++;
|
|
65054
|
+
delete r.retry.launching;
|
|
65055
|
+
});
|
|
65056
|
+
event2({
|
|
65057
|
+
kind: "retry",
|
|
65058
|
+
data: {
|
|
65059
|
+
state: "retrying",
|
|
65060
|
+
source: record2.failure?.source ?? "runtime",
|
|
65061
|
+
runtime: runtimeInfo(),
|
|
65062
|
+
attempt: nextAttempt,
|
|
65063
|
+
maxAttempts: record2.retry.of,
|
|
65064
|
+
summary: record2.failure?.summary ?? record2.retry.reason,
|
|
65065
|
+
...record2.failure?.detail ? { detail: record2.failure.detail } : {},
|
|
65066
|
+
...record2.failure?.code ? { code: record2.failure.code } : {},
|
|
65067
|
+
sessionAction: record2.resumedFrom ? "resume" : "reset_replay",
|
|
65068
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
65069
|
+
}
|
|
65070
|
+
});
|
|
65071
|
+
}
|
|
64702
65072
|
try {
|
|
64703
65073
|
const start = spawnable(cmd, client || stdinPrompt ? args2 : [...args2, prompt], {
|
|
64704
65074
|
// Where this run works: the project, or — inside a delivery with a worktree of its
|
|
@@ -64882,34 +65252,79 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64882
65252
|
const rendered = renderer?.failure?.() ?? (!taskCompleted && renderer?.background?.() ? "The agent exited with unfinished background tasks." : void 0);
|
|
64883
65253
|
const said2 = spawnError ?? (silent ? silenceSaid(silenceFor) : spoken?.error ?? rendered);
|
|
64884
65254
|
const failed2 = code !== 0 || spoken?.ok === false || !!rendered || silent || !!blocker;
|
|
64885
|
-
const failure2 = failed2 && !asked ? silent ? {
|
|
65255
|
+
const failure2 = failed2 && !asked ? silent ? makeFailure("runtime", said2 ?? IDLE_FAILURE.summary, { code: IDLE_FAILURE.code, detail: said2 ?? IDLE_FAILURE.summary }) : spawnFailure ?? spoken?.failure ?? renderer?.executionFailure?.() ?? (!blocker ? held4.validationFailure : void 0) ?? makeFailure("runtime", said2 ?? blocker?.cause ?? `Agent exited with code ${code}.`, {
|
|
65256
|
+
code: blocker ? "execution_blocked" : "execution_failed",
|
|
65257
|
+
detail: said2 ?? blocker?.cause ?? `Agent exited with code ${code}.`
|
|
65258
|
+
}) : void 0;
|
|
64886
65259
|
const result = spoken ? spoken.result : renderer?.result();
|
|
64887
65260
|
let retryPause;
|
|
64888
65261
|
let retrying = false;
|
|
65262
|
+
let retryHistory = held4.retryHistory ? [...held4.retryHistory] : void 0;
|
|
65263
|
+
let sessionAction;
|
|
64889
65264
|
if (failure2 && !sub && !taskCompleted) {
|
|
64890
65265
|
const attempt2 = held4.retry?.attempt ?? 1;
|
|
64891
|
-
const
|
|
64892
|
-
|
|
64893
|
-
|
|
64894
|
-
|
|
64895
|
-
|
|
64896
|
-
|
|
64897
|
-
|
|
64898
|
-
|
|
64899
|
-
|
|
64900
|
-
|
|
64901
|
-
|
|
64902
|
-
|
|
64903
|
-
|
|
64904
|
-
|
|
64905
|
-
|
|
64906
|
-
|
|
64907
|
-
|
|
64908
|
-
|
|
65266
|
+
const missingSession = isSessionMissingFailure(failure2);
|
|
65267
|
+
const mark = runMark(sessionId, agentStartedAt);
|
|
65268
|
+
const root2 = child.pid ? { pid: child.pid, since: agentStartedAt, identity: held4.agentIdentity } : void 0;
|
|
65269
|
+
const stopped3 = () => client?.managedProcess ? connectionStopped(root2) : processesStopped(mark, root2);
|
|
65270
|
+
const until = Date.now() + STOP_GRACE_MS + STOP_CLOSE_MS;
|
|
65271
|
+
while (!stopped3() && Date.now() < until) await sleep4(100);
|
|
65272
|
+
const isStopped = stopped3();
|
|
65273
|
+
const session = structured && !spawnFailure && !missingSession ? resumeSessionId(held4) : void 0;
|
|
65274
|
+
const unconfirmedCleanup = pendingOperations.size > 0 || !!blocker || spoken?.cleanup?.status === "unconfirmed" || failure2.code === "codex_ownership_unconfirmed" || client?.managedProcess && silent && (uncertainAtIdle || !idleStopConfirmed(spoken?.cleanup, session));
|
|
65275
|
+
const canResetReplay = isStopped && !unconfirmedCleanup && !pendingOperations.size && (held4.unspawned === true || structured && !hadEffects && !record2.resumedFrom);
|
|
65276
|
+
const recovery = missingSession ? canResetReplay ? "replay" : "unsafe" : agentRecovery({
|
|
65277
|
+
stopped: isStopped,
|
|
65278
|
+
session,
|
|
65279
|
+
replayable: canResetReplay,
|
|
65280
|
+
unconfirmedCleanup
|
|
65281
|
+
});
|
|
65282
|
+
sessionAction = recovery === "unsafe" ? "pause_unsafe" : recovery === "replay" ? "reset_replay" : "resume";
|
|
65283
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
65284
|
+
const retryRecord = {
|
|
65285
|
+
attempt: attempt2,
|
|
65286
|
+
source: failure2.source,
|
|
65287
|
+
runtime: runtimeInfo(),
|
|
65288
|
+
summary: failure2.summary,
|
|
65289
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
65290
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
65291
|
+
sessionAction,
|
|
65292
|
+
at: nowIso
|
|
65293
|
+
};
|
|
65294
|
+
retryHistory = [...retryHistory ?? [], retryRecord];
|
|
65295
|
+
if (recovery === "unsafe") {
|
|
65296
|
+
retryPause = "unsafe";
|
|
65297
|
+
} else {
|
|
65298
|
+
const decision = planRetry(failure2, attempt2, Date.now(), retryBackoff, !!held4.cloudExecution);
|
|
65299
|
+
if ("pause" in decision) {
|
|
65300
|
+
retryPause = decision.pause;
|
|
65301
|
+
} else {
|
|
65302
|
+
const pending = { ...decision.plan, sessionAction };
|
|
64909
65303
|
patch(sessionId, (r) => {
|
|
64910
65304
|
r.failure = failure2;
|
|
64911
|
-
r.error = said2 ?? failure2.
|
|
64912
|
-
r.
|
|
65305
|
+
r.error = said2 ?? failure2.summary;
|
|
65306
|
+
r.retryHistory = retryHistory;
|
|
65307
|
+
if (sessionAction === "reset_replay") {
|
|
65308
|
+
r.resumeId = void 0;
|
|
65309
|
+
r.unspawned = true;
|
|
65310
|
+
}
|
|
65311
|
+
r.retry = { attempt: attempt2, of: pending.of, reason: failure2.summary, at: pending.at, since: held4.retry?.since ?? held4.startedAt, pending };
|
|
65312
|
+
});
|
|
65313
|
+
event2({
|
|
65314
|
+
kind: "retry",
|
|
65315
|
+
data: {
|
|
65316
|
+
state: "waiting",
|
|
65317
|
+
source: failure2.source,
|
|
65318
|
+
runtime: runtimeInfo(),
|
|
65319
|
+
attempt: attempt2 + 1,
|
|
65320
|
+
maxAttempts: pending.of,
|
|
65321
|
+
summary: failure2.summary,
|
|
65322
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
65323
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
65324
|
+
nextRetryAt: new Date(pending.at).toISOString(),
|
|
65325
|
+
sessionAction,
|
|
65326
|
+
at: nowIso
|
|
65327
|
+
}
|
|
64913
65328
|
});
|
|
64914
65329
|
log.write(`
|
|
64915
65330
|
[board] ${retryLine(pending, attempt2)}
|
|
@@ -64918,11 +65333,44 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64918
65333
|
retrying = true;
|
|
64919
65334
|
}
|
|
64920
65335
|
}
|
|
65336
|
+
if (retryPause && !stoppedByUser()) {
|
|
65337
|
+
event2({
|
|
65338
|
+
kind: "retry",
|
|
65339
|
+
data: {
|
|
65340
|
+
state: "paused",
|
|
65341
|
+
source: failure2.source,
|
|
65342
|
+
runtime: runtimeInfo(),
|
|
65343
|
+
attempt: attempt2,
|
|
65344
|
+
maxAttempts: held4.retry?.of ?? MAX_RETRY_ATTEMPTS,
|
|
65345
|
+
summary: failure2.summary,
|
|
65346
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
65347
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
65348
|
+
sessionAction,
|
|
65349
|
+
at: nowIso
|
|
65350
|
+
}
|
|
65351
|
+
});
|
|
65352
|
+
}
|
|
64921
65353
|
}
|
|
64922
65354
|
asked ||= stoppedByUser();
|
|
64923
65355
|
retrying &&= !asked;
|
|
64924
|
-
const error62 = asked ? void 0 : joinNotes(said2 ?? failure2?.
|
|
65356
|
+
const error62 = asked ? void 0 : joinNotes(said2 ?? failure2?.summary, retryPause ? pauseLine(retryPause) : void 0);
|
|
64925
65357
|
const status = asked ? "stopped" : failed2 || code !== 0 ? "error" : "done";
|
|
65358
|
+
if (status === "done" && !sub && retryHistory?.length) {
|
|
65359
|
+
const lastRetry = retryHistory[retryHistory.length - 1];
|
|
65360
|
+
event2({
|
|
65361
|
+
kind: "retry",
|
|
65362
|
+
data: {
|
|
65363
|
+
state: "recovered",
|
|
65364
|
+
source: lastRetry.source,
|
|
65365
|
+
runtime: runtimeInfo(),
|
|
65366
|
+
attempt: held4.retry?.attempt ?? retryHistory.length + 1,
|
|
65367
|
+
maxAttempts: held4.retry?.of ?? MAX_RETRY_ATTEMPTS,
|
|
65368
|
+
summary: lastRetry.summary,
|
|
65369
|
+
...lastRetry.code ? { code: lastRetry.code } : {},
|
|
65370
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
65371
|
+
}
|
|
65372
|
+
});
|
|
65373
|
+
}
|
|
64926
65374
|
const reported = spoken ? spoken.costUsd : renderer?.costUsd?.();
|
|
64927
65375
|
const totals = reportsSessionTotal(record2.harness);
|
|
64928
65376
|
const sessionTotal = totals ? reported : void 0;
|
|
@@ -64985,6 +65433,7 @@ ${result}
|
|
|
64985
65433
|
error: error62,
|
|
64986
65434
|
failure: failure2,
|
|
64987
65435
|
retryPause,
|
|
65436
|
+
retryHistory,
|
|
64988
65437
|
note,
|
|
64989
65438
|
errorWhy,
|
|
64990
65439
|
noteWhy,
|
|
@@ -65177,6 +65626,7 @@ var init_watch = __esm({
|
|
|
65177
65626
|
init_idle();
|
|
65178
65627
|
init_codex_background_types();
|
|
65179
65628
|
init_retry();
|
|
65629
|
+
init_runtimes();
|
|
65180
65630
|
init_failures();
|
|
65181
65631
|
init_execution();
|
|
65182
65632
|
init_refine2();
|
|
@@ -65191,7 +65641,7 @@ var init_watch = __esm({
|
|
|
65191
65641
|
});
|
|
65192
65642
|
|
|
65193
65643
|
// src/commands/run.ts
|
|
65194
|
-
import
|
|
65644
|
+
import fs83 from "node:fs";
|
|
65195
65645
|
import path82 from "node:path";
|
|
65196
65646
|
async function cmdStartRun(action, args2, opts, program2 = "akb") {
|
|
65197
65647
|
const { req, follow: follow2, print } = readRequest(action, args2, opts);
|
|
@@ -65418,7 +65868,7 @@ async function cmdSubStart(words, opts) {
|
|
|
65418
65868
|
let prompt = words.join(" ");
|
|
65419
65869
|
if (opts.file) {
|
|
65420
65870
|
try {
|
|
65421
|
-
prompt =
|
|
65871
|
+
prompt = fs83.readFileSync(path82.resolve(opts.file), "utf8");
|
|
65422
65872
|
} catch {
|
|
65423
65873
|
die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
|
|
65424
65874
|
}
|
|
@@ -65767,12 +66217,12 @@ var init_config3 = __esm({
|
|
|
65767
66217
|
});
|
|
65768
66218
|
|
|
65769
66219
|
// src/lib/signals/migrate.ts
|
|
65770
|
-
import
|
|
66220
|
+
import fs84 from "node:fs";
|
|
65771
66221
|
import path83 from "node:path";
|
|
65772
66222
|
function readHandled() {
|
|
65773
66223
|
let text5;
|
|
65774
66224
|
try {
|
|
65775
|
-
text5 =
|
|
66225
|
+
text5 = fs84.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
|
|
65776
66226
|
} catch {
|
|
65777
66227
|
return [];
|
|
65778
66228
|
}
|
|
@@ -65789,45 +66239,45 @@ function readHandled() {
|
|
|
65789
66239
|
return held4;
|
|
65790
66240
|
}
|
|
65791
66241
|
function lift(from, into) {
|
|
65792
|
-
|
|
65793
|
-
|
|
66242
|
+
fs84.mkdirSync(into, { recursive: true });
|
|
66243
|
+
fs84.renameSync(from, path83.join(into, freeName(into, path83.basename(from))));
|
|
65794
66244
|
}
|
|
65795
66245
|
function repoint(dir, from, into) {
|
|
65796
66246
|
let entries2;
|
|
65797
66247
|
try {
|
|
65798
|
-
entries2 =
|
|
66248
|
+
entries2 = fs84.readdirSync(dir, { withFileTypes: true });
|
|
65799
66249
|
} catch {
|
|
65800
66250
|
return;
|
|
65801
66251
|
}
|
|
65802
66252
|
for (const entry of entries2) {
|
|
65803
66253
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
65804
66254
|
const file2 = path83.join(dir, entry.name);
|
|
65805
|
-
const text5 =
|
|
65806
|
-
if (text5.includes(from))
|
|
66255
|
+
const text5 = fs84.readFileSync(file2, "utf8");
|
|
66256
|
+
if (text5.includes(from)) fs84.writeFileSync(file2, text5.split(from).join(into));
|
|
65807
66257
|
}
|
|
65808
66258
|
}
|
|
65809
66259
|
function dropIfEmpty(dir) {
|
|
65810
66260
|
try {
|
|
65811
|
-
|
|
66261
|
+
fs84.rmdirSync(dir);
|
|
65812
66262
|
} catch {
|
|
65813
66263
|
}
|
|
65814
66264
|
}
|
|
65815
66265
|
function liftInbox() {
|
|
65816
|
-
if (!
|
|
66266
|
+
if (!fs84.existsSync(SIGNALS_OLD_INBOX)) return;
|
|
65817
66267
|
const oldFiles = path83.join(SIGNALS_OLD_INBOX, "files");
|
|
65818
|
-
if (
|
|
65819
|
-
for (const entry of
|
|
66268
|
+
if (fs84.existsSync(oldFiles)) {
|
|
66269
|
+
for (const entry of fs84.readdirSync(oldFiles, { withFileTypes: true })) {
|
|
65820
66270
|
if (entry.isFile()) lift(path83.join(oldFiles, entry.name), SIGNALS_FILES);
|
|
65821
66271
|
}
|
|
65822
66272
|
dropIfEmpty(oldFiles);
|
|
65823
66273
|
}
|
|
65824
66274
|
const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
|
|
65825
|
-
for (const entry of
|
|
66275
|
+
for (const entry of fs84.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
|
|
65826
66276
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
65827
66277
|
const from = path83.join(SIGNALS_OLD_INBOX, entry.name);
|
|
65828
66278
|
const item = parse3(from);
|
|
65829
66279
|
if (item && held4.has(item.sourceId)) {
|
|
65830
|
-
|
|
66280
|
+
fs84.rmSync(from, { force: true });
|
|
65831
66281
|
continue;
|
|
65832
66282
|
}
|
|
65833
66283
|
if (item) held4.add(item.sourceId);
|
|
@@ -65839,7 +66289,7 @@ function liftInbox() {
|
|
|
65839
66289
|
dropIfEmpty(SIGNALS_OLD_INBOX);
|
|
65840
66290
|
}
|
|
65841
66291
|
function liftHandled() {
|
|
65842
|
-
if (!
|
|
66292
|
+
if (!fs84.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
65843
66293
|
const lines = readHandled();
|
|
65844
66294
|
const held4 = /* @__PURE__ */ new Set([
|
|
65845
66295
|
...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
|
|
@@ -65849,7 +66299,7 @@ function liftHandled() {
|
|
|
65849
66299
|
for (const { sourceId, when } of lines) {
|
|
65850
66300
|
if (held4.has(sourceId)) continue;
|
|
65851
66301
|
held4.add(sourceId);
|
|
65852
|
-
|
|
66302
|
+
fs84.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
|
|
65853
66303
|
const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
|
|
65854
66304
|
const front = [
|
|
65855
66305
|
"---",
|
|
@@ -65859,13 +66309,13 @@ function liftHandled() {
|
|
|
65859
66309
|
"---",
|
|
65860
66310
|
""
|
|
65861
66311
|
];
|
|
65862
|
-
|
|
66312
|
+
fs84.writeFileSync(path83.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
|
|
65863
66313
|
`);
|
|
65864
66314
|
}
|
|
65865
|
-
|
|
66315
|
+
fs84.rmSync(SIGNALS_OLD_HANDLED, { force: true });
|
|
65866
66316
|
}
|
|
65867
66317
|
function migrateTriage() {
|
|
65868
|
-
if (!
|
|
66318
|
+
if (!fs84.existsSync(SIGNALS_OLD_INBOX) && !fs84.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
65869
66319
|
try {
|
|
65870
66320
|
liftInbox();
|
|
65871
66321
|
liftHandled();
|
|
@@ -65933,7 +66383,7 @@ var init_identity2 = __esm({
|
|
|
65933
66383
|
});
|
|
65934
66384
|
|
|
65935
66385
|
// src/lib/signals/add.ts
|
|
65936
|
-
import
|
|
66386
|
+
import fs85 from "node:fs";
|
|
65937
66387
|
import path84 from "node:path";
|
|
65938
66388
|
import { createHash as createHash8 } from "node:crypto";
|
|
65939
66389
|
function linkTitle(url2) {
|
|
@@ -65992,8 +66442,8 @@ ${incoming.summary}`);
|
|
|
65992
66442
|
if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
|
|
65993
66443
|
try {
|
|
65994
66444
|
if (keep2) {
|
|
65995
|
-
|
|
65996
|
-
|
|
66445
|
+
fs85.mkdirSync(SIGNALS_FILES, { recursive: true });
|
|
66446
|
+
fs85.writeFileSync(keep2.at, keep2.data);
|
|
65997
66447
|
}
|
|
65998
66448
|
return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
|
|
65999
66449
|
} catch (e) {
|
|
@@ -66104,7 +66554,7 @@ var init_signals = __esm({
|
|
|
66104
66554
|
});
|
|
66105
66555
|
|
|
66106
66556
|
// src/commands/triage.ts
|
|
66107
|
-
import
|
|
66557
|
+
import fs86 from "node:fs";
|
|
66108
66558
|
async function cmdTriageAdd(opts) {
|
|
66109
66559
|
const title = (opts.title ?? "").trim();
|
|
66110
66560
|
if (!title) die('say what it is: --title "<one line>"', { kind: "needs-input" });
|
|
@@ -66114,7 +66564,7 @@ async function cmdTriageAdd(opts) {
|
|
|
66114
66564
|
let body = opts.text;
|
|
66115
66565
|
if (opts.file !== void 0) {
|
|
66116
66566
|
try {
|
|
66117
|
-
body =
|
|
66567
|
+
body = fs86.readFileSync(opts.file, "utf8");
|
|
66118
66568
|
} catch {
|
|
66119
66569
|
die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
|
|
66120
66570
|
}
|
|
@@ -66168,21 +66618,21 @@ var init_previews = __esm({
|
|
|
66168
66618
|
});
|
|
66169
66619
|
|
|
66170
66620
|
// src/commands/studio-preview.ts
|
|
66171
|
-
import
|
|
66621
|
+
import fs87 from "node:fs";
|
|
66172
66622
|
import path85 from "node:path";
|
|
66173
66623
|
import { createHash as createHash9, randomUUID as randomUUID9 } from "node:crypto";
|
|
66174
66624
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
66175
66625
|
function readFolder2(folder2, baseline = false) {
|
|
66176
|
-
const root2 =
|
|
66626
|
+
const root2 = fs87.realpathSync(folder2);
|
|
66177
66627
|
let count3 = 0, total = 0;
|
|
66178
66628
|
const scan = (dir) => {
|
|
66179
|
-
for (const e of
|
|
66629
|
+
for (const e of fs87.readdirSync(dir, { withFileTypes: true })) {
|
|
66180
66630
|
if (e.name.startsWith(".")) continue;
|
|
66181
66631
|
const file2 = path85.join(dir, e.name);
|
|
66182
66632
|
if (e.isSymbolicLink()) throw Error(`${file2}: symbolic links are not allowed`);
|
|
66183
66633
|
if (e.isDirectory()) scan(file2);
|
|
66184
66634
|
else {
|
|
66185
|
-
const size =
|
|
66635
|
+
const size = fs87.statSync(file2).size;
|
|
66186
66636
|
total += size;
|
|
66187
66637
|
if (++count3 > FILE_LIMITS.count || size > FILE_LIMITS.file || total > FILE_LIMITS.total) throw Error(`${file2}: Studio file limit exceeded`);
|
|
66188
66638
|
}
|
|
@@ -66196,8 +66646,8 @@ function readFolder2(folder2, baseline = false) {
|
|
|
66196
66646
|
}
|
|
66197
66647
|
function unified(before, after2, file2, folder2) {
|
|
66198
66648
|
const a = path85.join(folder2, "a"), b = path85.join(folder2, "b");
|
|
66199
|
-
|
|
66200
|
-
|
|
66649
|
+
fs87.writeFileSync(a, before ?? "");
|
|
66650
|
+
fs87.writeFileSync(b, after2 ?? "");
|
|
66201
66651
|
const result = spawnSync7("git", ["diff", "--no-index", "--text", "--no-ext-diff", "--no-color", "--unified=3", before === null ? "/dev/null" : a, after2 === null ? "/dev/null" : b], { encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
|
|
66202
66652
|
if (result.error || result.status !== 0 && result.status !== 1) throw Error(`${file2}: ${result.error?.message ?? result.stderr}`);
|
|
66203
66653
|
const lines = result.stdout.split("\n"), start = lines.findIndex((l) => l.startsWith("--- "));
|
|
@@ -66213,12 +66663,12 @@ async function cmdStudioPreview(id2, opts) {
|
|
|
66213
66663
|
const draft = readFolder2(path85.resolve(opts.folder)), base = opts.base === "empty" ? null : readFolder2(path85.resolve(opts.base), true);
|
|
66214
66664
|
const version2 = readVersion2(draft.files), baseVersion = base && readVersion2(base.files);
|
|
66215
66665
|
if (base ? !version2 || !baseVersion || JSON.stringify(version2) !== JSON.stringify(baseVersion) : version2 !== null) throw Error("version.json: existing Studios need matching baseline and draft versions; use --base empty only for a new Studio without version.json");
|
|
66216
|
-
|
|
66666
|
+
fs87.mkdirSync(staging, { recursive: true });
|
|
66217
66667
|
const review = { version: 2, base: base && baseVersion ? { ...baseVersion, fingerprint: base.fingerprint } : null, fingerprint: draft.fingerprint, files: [] };
|
|
66218
66668
|
const save3 = (file2, bytes2) => {
|
|
66219
66669
|
const target = path85.join(staging, file2);
|
|
66220
|
-
|
|
66221
|
-
|
|
66670
|
+
fs87.mkdirSync(path85.dirname(target), { recursive: true });
|
|
66671
|
+
fs87.writeFileSync(target, bytes2);
|
|
66222
66672
|
return file2;
|
|
66223
66673
|
};
|
|
66224
66674
|
const paths = [.../* @__PURE__ */ new Set([...Object.keys(base?.files ?? {}), ...Object.keys(draft.files)])].filter((p) => p !== VERSION_FILE).sort();
|
|
@@ -66226,16 +66676,16 @@ async function cmdStudioPreview(id2, opts) {
|
|
|
66226
66676
|
const before = base?.files[file2] ?? null, after2 = draft.files[file2] ?? null;
|
|
66227
66677
|
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)) } : {} });
|
|
66228
66678
|
}
|
|
66229
|
-
for (const p of ["a", "b"])
|
|
66679
|
+
for (const p of ["a", "b"]) fs87.rmSync(path85.join(staging, p), { force: true });
|
|
66230
66680
|
if (!parseReview(review)) throw Error("generated review is invalid");
|
|
66231
66681
|
save3("review.json", JSON.stringify(review, null, 2) + "\n");
|
|
66232
|
-
|
|
66233
|
-
if (
|
|
66234
|
-
|
|
66682
|
+
fs87.mkdirSync(path85.dirname(destination), { recursive: true });
|
|
66683
|
+
if (fs87.existsSync(destination)) {
|
|
66684
|
+
fs87.renameSync(destination, backup);
|
|
66235
66685
|
moved = true;
|
|
66236
66686
|
}
|
|
66237
|
-
|
|
66238
|
-
|
|
66687
|
+
fs87.renameSync(staging, destination);
|
|
66688
|
+
fs87.rmSync(backup, { recursive: true, force: true });
|
|
66239
66689
|
const tag = `<Studio src=".assets/${id2}/studio-review/review.json" />`;
|
|
66240
66690
|
const prefix = `.assets/${id2}/studio-review/`;
|
|
66241
66691
|
const attachments = review.files.filter((f) => f.path !== "STUDIO.md" && f.diff);
|
|
@@ -66249,11 +66699,11 @@ ${items}
|
|
|
66249
66699
|
say([tag, files].filter(Boolean).join("\n\n"));
|
|
66250
66700
|
return { file: path85.join(destination, "review.json"), tag, files };
|
|
66251
66701
|
} catch (error62) {
|
|
66252
|
-
if (moved && !
|
|
66702
|
+
if (moved && !fs87.existsSync(destination)) fs87.renameSync(backup, destination);
|
|
66253
66703
|
if (error62 && typeof error62 === "object" && "kind" in error62) throw error62;
|
|
66254
66704
|
die(error62 instanceof Error ? error62.message : String(error62), "bad-args");
|
|
66255
66705
|
} finally {
|
|
66256
|
-
|
|
66706
|
+
fs87.rmSync(staging, { recursive: true, force: true });
|
|
66257
66707
|
}
|
|
66258
66708
|
}
|
|
66259
66709
|
var readVersion2;
|
|
@@ -66484,8 +66934,7 @@ function declareRuns(program2, cli) {
|
|
|
66484
66934
|
await boardless(this, cli, (_, location) => taskReview(id2, this.opts(), location));
|
|
66485
66935
|
});
|
|
66486
66936
|
const questionOps = [];
|
|
66487
|
-
|
|
66488
|
-
withShared(task.command("update-questions")).argument("<task>").summary("edit the task's open questions, like `raw update-questions`").description("Positions are 1-based, in the order of the card\u2019s `questions:` (`akb task show`). --option, --recommended-option and --mode attach to the --append or --update before them.").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 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")).addOption(new Option("--agent <name>").hideHelp().argParser(opInOrder("agent"))).action(async function(id2) {
|
|
66937
|
+
withQuestionOptions(withShared(task.command("update-questions")).argument("<task>").summary("append, rewrite, or remove open questions").description("Edit the current Runner task locally for synchronization, or save another task in Cloud. Edits apply in order at 1-based positions. Choices and mode apply to the preceding --append or --update.\nSee akb guide update-questions."), questionOps).action(async function(id2) {
|
|
66489
66938
|
await boardless(this, cli, (_, location) => taskUpdateQuestions(id2, questionOps, location));
|
|
66490
66939
|
});
|
|
66491
66940
|
withShared(task.command("chat")).argument("<task>").argument("[message...]").summary("read task chat history, follow or stop its reply, or send a message").description("Without a message, read the last 20 messages and the chat reply state separately from task execution. --follow tracks only the reply present at the start; Ctrl+C disconnects locally. --stop stops only that reply. --follow --json emits JSON Lines; other modes return one JSON object.").option("--limit <n>", "show the last n messages, oldest first (default: 20)", intInRange(1, Number.MAX_SAFE_INTEGER)).option("--all", "show all retained messages").option("--follow", "follow this reply to its result, then exit").option("--stop", "request stopping only the current chat reply").addHelpText("after", '\nExamples:\n akb task chat WC-12\n akb task chat 12 --all --json\n akb task chat 12 --follow --json\n akb task chat 12 --stop\n akb task chat 12 "Revise the draft"').action(async function(id2, message) {
|
|
@@ -66821,6 +67270,7 @@ var init_agent2 = __esm({
|
|
|
66821
67270
|
init_agent_check();
|
|
66822
67271
|
init_harnesses();
|
|
66823
67272
|
init_moved();
|
|
67273
|
+
init_question_options();
|
|
66824
67274
|
init_shared2();
|
|
66825
67275
|
REVIEW_FLOW_HELP = `
|
|
66826
67276
|
Review examples
|
|
@@ -66838,14 +67288,14 @@ Review examples
|
|
|
66838
67288
|
});
|
|
66839
67289
|
|
|
66840
67290
|
// src/kanban.ts
|
|
66841
|
-
import
|
|
67291
|
+
import fs90 from "node:fs";
|
|
66842
67292
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
66843
67293
|
|
|
66844
67294
|
// src/lib/cli/akb.ts
|
|
66845
67295
|
init_agent2();
|
|
66846
67296
|
|
|
66847
67297
|
// src/lib/cli/setup.ts
|
|
66848
|
-
import
|
|
67298
|
+
import fs89 from "node:fs";
|
|
66849
67299
|
import path87 from "node:path";
|
|
66850
67300
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
66851
67301
|
|
|
@@ -66854,7 +67304,7 @@ init_board_cli();
|
|
|
66854
67304
|
init_config_template();
|
|
66855
67305
|
init_io();
|
|
66856
67306
|
init_version();
|
|
66857
|
-
import
|
|
67307
|
+
import fs88 from "node:fs";
|
|
66858
67308
|
import path86 from "node:path";
|
|
66859
67309
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
66860
67310
|
var NAME = "wildcrane";
|
|
@@ -66876,7 +67326,7 @@ var Report = class {
|
|
|
66876
67326
|
for (const line of this.notes) say(` ! ${line}`);
|
|
66877
67327
|
}
|
|
66878
67328
|
};
|
|
66879
|
-
var read4 = (file2) =>
|
|
67329
|
+
var read4 = (file2) => fs88.existsSync(file2) ? fs88.readFileSync(file2, "utf8") : null;
|
|
66880
67330
|
async function boardMove(root2, args2, board2) {
|
|
66881
67331
|
const where = board2 ? ["--board", board2] : ["--dir", root2];
|
|
66882
67332
|
const code = await runBoard([...args2, ...where], { program: "akb raw", cwd: root2 });
|
|
@@ -66899,8 +67349,8 @@ async function cmdUpdate2(ctx) {
|
|
|
66899
67349
|
async function repairBoard(root2, report3, named2) {
|
|
66900
67350
|
const legacy = path86.join(root2, "docs", "kanban");
|
|
66901
67351
|
const kept2 = path86.join(root2, ".akb", "kanban");
|
|
66902
|
-
const board2 = named2 ?? (
|
|
66903
|
-
if (!
|
|
67352
|
+
const board2 = named2 ?? (fs88.existsSync(legacy) ? legacy : kept2);
|
|
67353
|
+
if (!fs88.existsSync(board2)) {
|
|
66904
67354
|
report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
|
|
66905
67355
|
return false;
|
|
66906
67356
|
}
|
|
@@ -66976,7 +67426,7 @@ function declareSetup(program2, cli) {
|
|
|
66976
67426
|
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");
|
|
66977
67427
|
const where = (cmd) => {
|
|
66978
67428
|
const dir = path87.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
|
|
66979
|
-
if (!
|
|
67429
|
+
if (!fs89.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
|
|
66980
67430
|
return dir;
|
|
66981
67431
|
};
|
|
66982
67432
|
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() {
|
|
@@ -67027,7 +67477,7 @@ function invokedDirectly() {
|
|
|
67027
67477
|
const entry = process.argv[1];
|
|
67028
67478
|
if (!entry) return false;
|
|
67029
67479
|
try {
|
|
67030
|
-
return
|
|
67480
|
+
return fs90.realpathSync(entry) === fs90.realpathSync(SELF2);
|
|
67031
67481
|
} catch {
|
|
67032
67482
|
return false;
|
|
67033
67483
|
}
|