wildcrane 0.11.85 → 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 +822 -524
- 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)
|
|
@@ -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
|
}
|
|
@@ -49448,12 +49637,12 @@ var init_studio_cards = __esm({
|
|
|
49448
49637
|
});
|
|
49449
49638
|
|
|
49450
49639
|
// src/lib/readme.ts
|
|
49451
|
-
import
|
|
49640
|
+
import fs48 from "node:fs";
|
|
49452
49641
|
import path52 from "node:path";
|
|
49453
49642
|
function stripReadmeRefs(target) {
|
|
49454
|
-
if (!
|
|
49643
|
+
if (!fs48.existsSync(README)) return [];
|
|
49455
49644
|
const needle = target.kind === "group" ? `](${target.rel}/` : `](${target.rel})`;
|
|
49456
|
-
const lines =
|
|
49645
|
+
const lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49457
49646
|
const out = [];
|
|
49458
49647
|
const removed = [];
|
|
49459
49648
|
let i = 0;
|
|
@@ -49475,20 +49664,20 @@ function stripReadmeRefs(target) {
|
|
|
49475
49664
|
out.push(line);
|
|
49476
49665
|
i++;
|
|
49477
49666
|
}
|
|
49478
|
-
if (removed.length)
|
|
49667
|
+
if (removed.length) fs48.writeFileSync(README, out.join("\n"));
|
|
49479
49668
|
return removed;
|
|
49480
49669
|
}
|
|
49481
49670
|
function addReadmeRef(id2, title, relPath) {
|
|
49482
|
-
if (!
|
|
49671
|
+
if (!fs48.existsSync(README)) return false;
|
|
49483
49672
|
const link2 = relPath.split(path52.sep).join("/");
|
|
49484
49673
|
const bullet = `- [#${id2} ${title}](${link2})`;
|
|
49485
49674
|
const heading = `## ${TASKS_HEADING}`;
|
|
49486
|
-
let lines =
|
|
49675
|
+
let lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49487
49676
|
const hi = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
|
|
49488
49677
|
if (hi === -1) {
|
|
49489
49678
|
while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
|
|
49490
49679
|
lines.push("", heading, "", bullet);
|
|
49491
|
-
|
|
49680
|
+
fs48.writeFileSync(README, lines.join("\n") + "\n");
|
|
49492
49681
|
return true;
|
|
49493
49682
|
}
|
|
49494
49683
|
let end2 = hi + 1;
|
|
@@ -49502,15 +49691,15 @@ function addReadmeRef(id2, title, relPath) {
|
|
|
49502
49691
|
const at = lastBullet !== -1 ? lastBullet + 1 : lines[hi + 1] === "" ? hi + 2 : hi + 1;
|
|
49503
49692
|
lines.splice(at, 0, bullet);
|
|
49504
49693
|
}
|
|
49505
|
-
|
|
49694
|
+
fs48.writeFileSync(README, lines.join("\n"));
|
|
49506
49695
|
return true;
|
|
49507
49696
|
}
|
|
49508
49697
|
function repointReadmeLink(id2, oldRel, newRel, title) {
|
|
49509
|
-
if (!
|
|
49698
|
+
if (!fs48.existsSync(README)) return false;
|
|
49510
49699
|
const oldLink = oldRel.split(path52.sep).join("/");
|
|
49511
49700
|
const newLink = newRel.split(path52.sep).join("/");
|
|
49512
49701
|
const linkRe = new RegExp(`\\[#${id2}\\b[^\\]]*\\]\\(${escapeRegex2(oldLink)}\\)`);
|
|
49513
|
-
const lines =
|
|
49702
|
+
const lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49514
49703
|
let changed = false;
|
|
49515
49704
|
for (let i = 0; i < lines.length; i++) {
|
|
49516
49705
|
if (!lines[i].includes(`](${oldLink})`)) continue;
|
|
@@ -49520,7 +49709,7 @@ function repointReadmeLink(id2, oldRel, newRel, title) {
|
|
|
49520
49709
|
changed = true;
|
|
49521
49710
|
}
|
|
49522
49711
|
}
|
|
49523
|
-
if (changed)
|
|
49712
|
+
if (changed) fs48.writeFileSync(README, lines.join("\n"));
|
|
49524
49713
|
return changed;
|
|
49525
49714
|
}
|
|
49526
49715
|
var isTableRow, isBulletStart, bulletIndent, TASKS_HEADING, escapeRegex2;
|
|
@@ -50196,16 +50385,16 @@ var init_collect = __esm({
|
|
|
50196
50385
|
});
|
|
50197
50386
|
|
|
50198
50387
|
// src/lib/dress-page.ts
|
|
50199
|
-
import
|
|
50388
|
+
import fs49 from "node:fs";
|
|
50200
50389
|
import path53 from "node:path";
|
|
50201
50390
|
function dressPage(file2) {
|
|
50202
50391
|
const folder2 = path53.dirname(file2);
|
|
50203
|
-
const html =
|
|
50392
|
+
const html = fs49.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
|
|
50204
50393
|
const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
|
|
50205
50394
|
if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
|
|
50206
50395
|
const at2 = path53.resolve(folder2, href);
|
|
50207
|
-
if (!at2.startsWith(folder2 + path53.sep) || !
|
|
50208
|
-
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})`);
|
|
50209
50398
|
return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
|
|
50210
50399
|
});
|
|
50211
50400
|
const at = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
|
|
@@ -50218,25 +50407,25 @@ var init_dress_page = __esm({
|
|
|
50218
50407
|
isHtmlFile = (file2) => /\.html?$/i.test(file2);
|
|
50219
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'";
|
|
50220
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>`;
|
|
50221
|
-
referenceText = (file2) => isHtmlFile(file2) ? dressPage(file2) :
|
|
50410
|
+
referenceText = (file2) => isHtmlFile(file2) ? dressPage(file2) : fs49.readFileSync(file2, "utf8");
|
|
50222
50411
|
}
|
|
50223
50412
|
});
|
|
50224
50413
|
|
|
50225
50414
|
// src/lib/preview-files.ts
|
|
50226
|
-
import
|
|
50415
|
+
import fs50 from "node:fs";
|
|
50227
50416
|
import path54 from "node:path";
|
|
50228
50417
|
function resolver(card, id2) {
|
|
50229
50418
|
const roots = [KANBAN, path54.join(ASSETS, String(id2))];
|
|
50230
|
-
const real2 = (p) =>
|
|
50419
|
+
const real2 = (p) => fs50.existsSync(p) ? fs50.realpathSync(p) : p;
|
|
50231
50420
|
const inside2 = (p) => roots.some((root2) => p.startsWith(real2(root2) + path54.sep));
|
|
50232
50421
|
return (src, owner) => {
|
|
50233
50422
|
if (/^[a-z][\w+.-]*:/i.test(src) || src.startsWith("#") || src.startsWith("//")) return null;
|
|
50234
50423
|
if (path54.isAbsolute(src)) throw new Error("an absolute path; name it relative to the file");
|
|
50235
50424
|
const held4 = /^\.assets\//.exec(src);
|
|
50236
50425
|
const file2 = held4 ? path54.resolve(ASSETS, src.slice(held4[0].length)) : path54.resolve(path54.dirname(owner), src);
|
|
50237
|
-
if (!inside2(path54.resolve(file2)) ||
|
|
50238
|
-
if (!
|
|
50239
|
-
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 };
|
|
50240
50429
|
};
|
|
50241
50430
|
}
|
|
50242
50431
|
function validatePreviewFiles(card, id2, text5) {
|
|
@@ -50279,7 +50468,7 @@ var init_preview_files = __esm({
|
|
|
50279
50468
|
});
|
|
50280
50469
|
|
|
50281
50470
|
// src/lib/spec-contract.ts
|
|
50282
|
-
import
|
|
50471
|
+
import fs51 from "node:fs";
|
|
50283
50472
|
import path55 from "node:path";
|
|
50284
50473
|
function scanCardLines(lines, start = 0) {
|
|
50285
50474
|
const visible = lines.map(() => "");
|
|
@@ -50313,11 +50502,11 @@ function scanCardLines(lines, start = 0) {
|
|
|
50313
50502
|
}
|
|
50314
50503
|
function snapshotSpecs() {
|
|
50315
50504
|
const out = /* @__PURE__ */ new Map();
|
|
50316
|
-
if (!
|
|
50505
|
+
if (!fs51.existsSync(TODO)) return out;
|
|
50317
50506
|
for (const file2 of walkMd(TODO)) {
|
|
50318
50507
|
if (isLegacyRecurring(path55.relative(TODO, file2))) continue;
|
|
50319
50508
|
const id2 = idPrefix(path55.basename(file2) === "root.md" ? path55.basename(path55.dirname(file2)) : path55.basename(file2));
|
|
50320
|
-
if (id2 !== null) out.set(file2, { id: id2, text:
|
|
50509
|
+
if (id2 !== null) out.set(file2, { id: id2, text: fs51.readFileSync(file2, "utf8") });
|
|
50321
50510
|
}
|
|
50322
50511
|
return out;
|
|
50323
50512
|
}
|
|
@@ -50511,9 +50700,9 @@ function setEnd(lines, at) {
|
|
|
50511
50700
|
}
|
|
50512
50701
|
function inside(dir, name) {
|
|
50513
50702
|
try {
|
|
50514
|
-
const root2 =
|
|
50515
|
-
const real2 =
|
|
50516
|
-
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;
|
|
50517
50706
|
} catch {
|
|
50518
50707
|
return null;
|
|
50519
50708
|
}
|
|
@@ -50546,7 +50735,7 @@ function compareProblem(attrs, id2) {
|
|
|
50546
50735
|
const shots = (message) => ({ rule: "compare-shots", message });
|
|
50547
50736
|
const json2 = (file2) => {
|
|
50548
50737
|
try {
|
|
50549
|
-
return file2.endsWith(".json") ? JSON.parse(
|
|
50738
|
+
return file2.endsWith(".json") ? JSON.parse(fs51.readFileSync(file2, "utf8")) : null;
|
|
50550
50739
|
} catch {
|
|
50551
50740
|
return null;
|
|
50552
50741
|
}
|
|
@@ -50571,7 +50760,7 @@ function compareProblem(attrs, id2) {
|
|
|
50571
50760
|
const file2 = inside(dir, named2.name);
|
|
50572
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.` };
|
|
50573
50762
|
try {
|
|
50574
|
-
return { data: JSON.parse(
|
|
50763
|
+
return { data: JSON.parse(fs51.readFileSync(file2, "utf8")) };
|
|
50575
50764
|
} catch {
|
|
50576
50765
|
return { message: `${at} is not valid JSON.` };
|
|
50577
50766
|
}
|
|
@@ -50626,7 +50815,7 @@ var init_spec_contract = __esm({
|
|
|
50626
50815
|
});
|
|
50627
50816
|
|
|
50628
50817
|
// src/lib/reconcile.ts
|
|
50629
|
-
import
|
|
50818
|
+
import fs52 from "node:fs";
|
|
50630
50819
|
import path56 from "node:path";
|
|
50631
50820
|
function liveIds() {
|
|
50632
50821
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -50642,7 +50831,7 @@ function indexableCards() {
|
|
|
50642
50831
|
const out = [];
|
|
50643
50832
|
for (const dir of walkDirs(TODO)) {
|
|
50644
50833
|
const id2 = idPrefix(path56.basename(dir));
|
|
50645
|
-
if (id2 != null &&
|
|
50834
|
+
if (id2 != null && fs52.existsSync(path56.join(dir, "root.md"))) {
|
|
50646
50835
|
out.push({ id: id2, rel: path56.join(path56.relative(TODO, dir), "root.md").split(path56.sep).join("/") });
|
|
50647
50836
|
}
|
|
50648
50837
|
}
|
|
@@ -50659,7 +50848,7 @@ function indexableCards() {
|
|
|
50659
50848
|
}
|
|
50660
50849
|
function readmeComplaints(fix) {
|
|
50661
50850
|
const said2 = [];
|
|
50662
|
-
const lines =
|
|
50851
|
+
const lines = fs52.readFileSync(README, "utf8").split("\n");
|
|
50663
50852
|
const indexed = /* @__PURE__ */ new Set();
|
|
50664
50853
|
let fixed = 0;
|
|
50665
50854
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -50668,7 +50857,7 @@ function readmeComplaints(fix) {
|
|
|
50668
50857
|
const id2 = Number(m[1]);
|
|
50669
50858
|
const linkPath = m[2];
|
|
50670
50859
|
indexed.add(id2);
|
|
50671
|
-
if (
|
|
50860
|
+
if (fs52.existsSync(path56.join(TODO, linkPath))) continue;
|
|
50672
50861
|
const found2 = locate(id2);
|
|
50673
50862
|
if (!found2) {
|
|
50674
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.`);
|
|
@@ -50684,7 +50873,7 @@ function readmeComplaints(fix) {
|
|
|
50684
50873
|
said2.push(`README link #${id2} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
|
|
50685
50874
|
fixed++;
|
|
50686
50875
|
}
|
|
50687
|
-
if (fixed)
|
|
50876
|
+
if (fixed) fs52.writeFileSync(README, lines.join("\n"));
|
|
50688
50877
|
for (const c of indexableCards()) {
|
|
50689
50878
|
if (!indexed.has(c.id)) {
|
|
50690
50879
|
said2.push(`card ${c.rel} (#${c.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
|
|
@@ -50700,7 +50889,7 @@ function crossRefComplaints() {
|
|
|
50700
50889
|
if (base === "README.md") continue;
|
|
50701
50890
|
const ownerId = base === "root.md" ? idPrefix(path56.basename(path56.dirname(file2))) : idPrefix(base);
|
|
50702
50891
|
if (ownerId == null) continue;
|
|
50703
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
50892
|
+
const { meta: meta3 } = parseFrontmatter(fs52.readFileSync(file2, "utf8"));
|
|
50704
50893
|
if (!meta3) continue;
|
|
50705
50894
|
for (const field2 of ["blocked_by", "related"]) {
|
|
50706
50895
|
for (const ref of meta3[field2] || []) {
|
|
@@ -50713,7 +50902,7 @@ function crossRefComplaints() {
|
|
|
50713
50902
|
return said2;
|
|
50714
50903
|
}
|
|
50715
50904
|
function reconcileBoard() {
|
|
50716
|
-
if (!
|
|
50905
|
+
if (!fs52.existsSync(README)) return;
|
|
50717
50906
|
for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
|
|
50718
50907
|
}
|
|
50719
50908
|
var README_LINK;
|
|
@@ -50729,7 +50918,7 @@ var init_reconcile = __esm({
|
|
|
50729
50918
|
});
|
|
50730
50919
|
|
|
50731
50920
|
// src/commands/card.ts
|
|
50732
|
-
import
|
|
50921
|
+
import fs53 from "node:fs";
|
|
50733
50922
|
import path57 from "node:path";
|
|
50734
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>") {
|
|
50735
50924
|
return [
|
|
@@ -50756,7 +50945,7 @@ function bodyFromFile(opts) {
|
|
|
50756
50945
|
if (opts.body === false) die("pass --body-file or --no-body, not both");
|
|
50757
50946
|
let text5;
|
|
50758
50947
|
try {
|
|
50759
|
-
text5 =
|
|
50948
|
+
text5 = fs53.readFileSync(opts.bodyFile, "utf8");
|
|
50760
50949
|
} catch {
|
|
50761
50950
|
die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
|
|
50762
50951
|
}
|
|
@@ -50828,12 +51017,12 @@ function cmdCreate(opts) {
|
|
|
50828
51017
|
return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
|
|
50829
51018
|
}
|
|
50830
51019
|
if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
|
|
50831
|
-
if (
|
|
51020
|
+
if (fs53.existsSync(file2)) die(`${rel(file2)} already exists \u2014 pick a different --slug`);
|
|
50832
51021
|
countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
|
|
50833
51022
|
const meta3 = { title, priority, status: "todo", blocked_by, related, modules, studio, previews, triage, source: source2, questions };
|
|
50834
51023
|
const scaffolded = !written && opts.body !== false;
|
|
50835
51024
|
const body = written ?? (scaffolded ? defaultBody() : "");
|
|
50836
|
-
|
|
51025
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n\n" + body);
|
|
50837
51026
|
const indexed = addReadmeRef(start, title, fileRel);
|
|
50838
51027
|
say(start);
|
|
50839
51028
|
say(
|
|
@@ -50886,7 +51075,7 @@ function cmdUpdate(id2, flags) {
|
|
|
50886
51075
|
const found2 = locate(id2);
|
|
50887
51076
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
50888
51077
|
const file2 = found2.kind === "group" ? path57.join(found2.target, "root.md") : found2.target;
|
|
50889
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51078
|
+
const { meta: meta3, body } = parseFrontmatter(fs53.readFileSync(file2, "utf8"));
|
|
50890
51079
|
if (!meta3) die(`${rel(file2)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
|
|
50891
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");
|
|
50892
51081
|
if (flags.related !== void 0 && flags.addRelated !== void 0) die("--related replaces the list and --add-related appends to it \u2014 pass one");
|
|
@@ -50962,9 +51151,9 @@ function cmdUpdate(id2, flags) {
|
|
|
50962
51151
|
const destRel = path57.join(path57.dirname(curRel), base);
|
|
50963
51152
|
const dest = path57.join(TODO, destRel);
|
|
50964
51153
|
const moving = dest !== file2;
|
|
50965
|
-
if (moving &&
|
|
50966
|
-
|
|
50967
|
-
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);
|
|
50968
51157
|
if (isSubtask) {
|
|
50969
51158
|
if (moving || changes.includes("title")) repointReadmeLink(id2, curRel, destRel, meta3.title);
|
|
50970
51159
|
if (moving) changes.push(`renamed \u2192 ${destRel.split(path57.sep).join("/")}`);
|
|
@@ -50986,7 +51175,7 @@ function updateCardQuestions(id2, ops, compatibility = false) {
|
|
|
50986
51175
|
const found2 = locate(id2);
|
|
50987
51176
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
50988
51177
|
const file2 = found2.kind === "group" ? path57.join(found2.target, "root.md") : found2.target;
|
|
50989
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51178
|
+
const { meta: meta3, body } = parseFrontmatter(fs53.readFileSync(file2, "utf8"));
|
|
50990
51179
|
if (!meta3) die(`${rel(file2)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
|
|
50991
51180
|
for (const op of ops) {
|
|
50992
51181
|
if (!compatibility || !op.question?.agent) continue;
|
|
@@ -51008,7 +51197,7 @@ function updateCardQuestions(id2, ops, compatibility = false) {
|
|
|
51008
51197
|
meta3.status = "todo";
|
|
51009
51198
|
changes.push("status\u2192todo (open questions)");
|
|
51010
51199
|
}
|
|
51011
|
-
|
|
51200
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n" + body);
|
|
51012
51201
|
const closed2 = activeDelivery(id2) ? "questions_closed_verify" : "questions_closed_user";
|
|
51013
51202
|
for (const _ of done.closed) countBoardEvent(closed2);
|
|
51014
51203
|
say(`updated #${id2} questions: ${changes.join(", ")} (${open4} open)`);
|
|
@@ -51067,7 +51256,7 @@ var init_config_template = __esm({
|
|
|
51067
51256
|
});
|
|
51068
51257
|
|
|
51069
51258
|
// src/commands/init.ts
|
|
51070
|
-
import
|
|
51259
|
+
import fs54 from "node:fs";
|
|
51071
51260
|
function boardReadme() {
|
|
51072
51261
|
return `# Board
|
|
51073
51262
|
|
|
@@ -51080,20 +51269,20 @@ _(none)_
|
|
|
51080
51269
|
`;
|
|
51081
51270
|
}
|
|
51082
51271
|
function writeConfigIfMissing() {
|
|
51083
|
-
if (
|
|
51084
|
-
|
|
51085
|
-
|
|
51272
|
+
if (fs54.existsSync(CONFIG)) return false;
|
|
51273
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51274
|
+
fs54.writeFileSync(CONFIG, CONFIG_TEMPLATE);
|
|
51086
51275
|
return true;
|
|
51087
51276
|
}
|
|
51088
51277
|
function writeModulesIfMissing() {
|
|
51089
|
-
if (
|
|
51090
|
-
|
|
51091
|
-
|
|
51278
|
+
if (fs54.existsSync(MODULES_MD)) return false;
|
|
51279
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51280
|
+
fs54.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
|
|
51092
51281
|
return true;
|
|
51093
51282
|
}
|
|
51094
51283
|
function writeGitignoreIfMissing() {
|
|
51095
|
-
|
|
51096
|
-
const text5 =
|
|
51284
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51285
|
+
const text5 = fs54.existsSync(KANBAN_GITIGNORE) ? fs54.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
|
|
51097
51286
|
const has = (rule) => text5.split("\n").some((line) => line.trim() === rule.line);
|
|
51098
51287
|
const missing = IGNORE_RULES.filter((rule) => !has(rule));
|
|
51099
51288
|
if (!missing.length) return false;
|
|
@@ -51101,23 +51290,23 @@ function writeGitignoreIfMissing() {
|
|
|
51101
51290
|
${rule.line}
|
|
51102
51291
|
`).join("");
|
|
51103
51292
|
const separator = !text5 || text5.endsWith("\n") ? "" : "\n";
|
|
51104
|
-
|
|
51293
|
+
fs54.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
|
|
51105
51294
|
return true;
|
|
51106
51295
|
}
|
|
51107
51296
|
function writeSkeletonIfMissing() {
|
|
51108
51297
|
const added = [];
|
|
51109
|
-
if (!
|
|
51110
|
-
|
|
51298
|
+
if (!fs54.existsSync(TODO)) {
|
|
51299
|
+
fs54.mkdirSync(TODO, { recursive: true });
|
|
51111
51300
|
added.push(`${rel(TODO)}/`);
|
|
51112
51301
|
}
|
|
51113
|
-
if (!
|
|
51114
|
-
|
|
51302
|
+
if (!fs54.existsSync(README)) {
|
|
51303
|
+
fs54.writeFileSync(README, boardReadme());
|
|
51115
51304
|
added.push(rel(README));
|
|
51116
51305
|
}
|
|
51117
51306
|
return added;
|
|
51118
51307
|
}
|
|
51119
51308
|
function cmdInit() {
|
|
51120
|
-
if (
|
|
51309
|
+
if (fs54.existsSync(KANBAN)) {
|
|
51121
51310
|
const added = [
|
|
51122
51311
|
...writeSkeletonIfMissing(),
|
|
51123
51312
|
writeConfigIfMissing() && rel(CONFIG),
|
|
@@ -51134,8 +51323,8 @@ function cmdInit() {
|
|
|
51134
51323
|
}
|
|
51135
51324
|
return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
|
|
51136
51325
|
}
|
|
51137
|
-
|
|
51138
|
-
|
|
51326
|
+
fs54.mkdirSync(TODO, { recursive: true });
|
|
51327
|
+
fs54.writeFileSync(README, boardReadme());
|
|
51139
51328
|
writeConfigIfMissing();
|
|
51140
51329
|
scaffoldProjectMemory();
|
|
51141
51330
|
writeModulesIfMissing();
|
|
@@ -51170,15 +51359,15 @@ _(not filled in yet \u2014 build the map from the repo before tagging a card.)_
|
|
|
51170
51359
|
});
|
|
51171
51360
|
|
|
51172
51361
|
// src/lib/card-age.ts
|
|
51173
|
-
import
|
|
51362
|
+
import fs55 from "node:fs";
|
|
51174
51363
|
import path58 from "node:path";
|
|
51175
51364
|
function staleAfterIn(config2) {
|
|
51176
51365
|
const days = Number(LINE.exec(config2)?.[1]);
|
|
51177
51366
|
return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
|
|
51178
51367
|
}
|
|
51179
51368
|
function staleAfter() {
|
|
51180
|
-
if (!
|
|
51181
|
-
return staleAfterIn(
|
|
51369
|
+
if (!fs55.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
|
|
51370
|
+
return staleAfterIn(fs55.readFileSync(CONFIG, "utf8"));
|
|
51182
51371
|
}
|
|
51183
51372
|
function todoPathspec(top) {
|
|
51184
51373
|
const from = path58.relative(real(top), real(TODO));
|
|
@@ -51235,7 +51424,7 @@ var init_card_age = __esm({
|
|
|
51235
51424
|
gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
|
|
51236
51425
|
real = (p) => {
|
|
51237
51426
|
try {
|
|
51238
|
-
return
|
|
51427
|
+
return fs55.realpathSync(p);
|
|
51239
51428
|
} catch {
|
|
51240
51429
|
return path58.resolve(p);
|
|
51241
51430
|
}
|
|
@@ -51271,7 +51460,7 @@ var init_card_holds = __esm({
|
|
|
51271
51460
|
});
|
|
51272
51461
|
|
|
51273
51462
|
// src/commands/list.ts
|
|
51274
|
-
import
|
|
51463
|
+
import fs56 from "node:fs";
|
|
51275
51464
|
import path59 from "node:path";
|
|
51276
51465
|
function summaryLine(body) {
|
|
51277
51466
|
const lines = body.split("\n");
|
|
@@ -51294,7 +51483,7 @@ function openRows() {
|
|
|
51294
51483
|
const id2 = isRoot ? idPrefix(path59.basename(path59.dirname(file2))) : idPrefix(base);
|
|
51295
51484
|
if (id2 == null) continue;
|
|
51296
51485
|
if (isLegacyRecurring(path59.relative(TODO, file2))) continue;
|
|
51297
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51486
|
+
const { meta: meta3, body } = parseFrontmatter(fs56.readFileSync(file2, "utf8"));
|
|
51298
51487
|
rows.push({
|
|
51299
51488
|
id: id2,
|
|
51300
51489
|
file: file2,
|
|
@@ -51336,7 +51525,7 @@ function cmdStale(rows, all2, scope, mod) {
|
|
|
51336
51525
|
}
|
|
51337
51526
|
function archivedFiles() {
|
|
51338
51527
|
const files = /* @__PURE__ */ new Map();
|
|
51339
|
-
if (!
|
|
51528
|
+
if (!fs56.existsSync(ARCHIVE)) return files;
|
|
51340
51529
|
for (const file2 of walkMd(ARCHIVE)) {
|
|
51341
51530
|
const id2 = idPrefix(path59.basename(file2));
|
|
51342
51531
|
if (id2 !== null) files.set(id2, file2);
|
|
@@ -51344,7 +51533,7 @@ function archivedFiles() {
|
|
|
51344
51533
|
for (const dir of walkDirs(ARCHIVE)) {
|
|
51345
51534
|
const id2 = idPrefix(path59.basename(dir));
|
|
51346
51535
|
const root2 = path59.join(dir, "root.md");
|
|
51347
|
-
if (id2 !== null &&
|
|
51536
|
+
if (id2 !== null && fs56.existsSync(root2)) files.set(id2, root2);
|
|
51348
51537
|
}
|
|
51349
51538
|
return files;
|
|
51350
51539
|
}
|
|
@@ -51442,10 +51631,10 @@ var init_list = __esm({
|
|
|
51442
51631
|
});
|
|
51443
51632
|
|
|
51444
51633
|
// src/lib/group-close.ts
|
|
51445
|
-
import
|
|
51634
|
+
import fs57 from "node:fs";
|
|
51446
51635
|
function groupCloses(rootFile) {
|
|
51447
51636
|
try {
|
|
51448
|
-
return groupCloseOf(
|
|
51637
|
+
return groupCloseOf(fs57.readFileSync(rootFile, "utf8"));
|
|
51449
51638
|
} catch {
|
|
51450
51639
|
return false;
|
|
51451
51640
|
}
|
|
@@ -51458,7 +51647,7 @@ var init_group_close = __esm({
|
|
|
51458
51647
|
});
|
|
51459
51648
|
|
|
51460
51649
|
// src/commands/remove.ts
|
|
51461
|
-
import
|
|
51650
|
+
import fs58 from "node:fs";
|
|
51462
51651
|
import path60 from "node:path";
|
|
51463
51652
|
function leavingIds(id2, found2) {
|
|
51464
51653
|
const ids = /* @__PURE__ */ new Set([id2]);
|
|
@@ -51475,10 +51664,10 @@ function findMentions(ids) {
|
|
|
51475
51664
|
const hits = [];
|
|
51476
51665
|
const re = new RegExp(ids.map((id2) => `#${id2}(?!\\d)`).join("|"));
|
|
51477
51666
|
for (const dir of [TODO, MEMORY]) {
|
|
51478
|
-
if (!
|
|
51667
|
+
if (!fs58.existsSync(dir)) continue;
|
|
51479
51668
|
for (const file2 of walkMd(dir)) {
|
|
51480
51669
|
if (path60.basename(file2) === "README.md") continue;
|
|
51481
|
-
const lines =
|
|
51670
|
+
const lines = fs58.readFileSync(file2, "utf8").split("\n");
|
|
51482
51671
|
const fmEnd = frontmatterEnd(lines);
|
|
51483
51672
|
lines.forEach((line, i) => {
|
|
51484
51673
|
if (!re.test(line)) return;
|
|
@@ -51508,10 +51697,10 @@ function stampLeaving(cards, rejection) {
|
|
|
51508
51697
|
const day = formatDay();
|
|
51509
51698
|
const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() || workspaceTask() ? "agent" : "user" } : rejection && { reason: rejection.reason };
|
|
51510
51699
|
for (const card of cards) {
|
|
51511
|
-
if (!
|
|
51512
|
-
const text5 =
|
|
51700
|
+
if (!fs58.existsSync(card.file)) continue;
|
|
51701
|
+
const text5 = fs58.readFileSync(card.file, "utf8");
|
|
51513
51702
|
const stamped = stampLeavingIn(text5, day, stamp4);
|
|
51514
|
-
if (stamped !== text5)
|
|
51703
|
+
if (stamped !== text5) fs58.writeFileSync(card.file, stamped);
|
|
51515
51704
|
}
|
|
51516
51705
|
}
|
|
51517
51706
|
function agentDecisions(text5) {
|
|
@@ -51541,14 +51730,14 @@ function removeCard(id2, metric, options) {
|
|
|
51541
51730
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
51542
51731
|
const dest = options.cleanupDiscarded && locateArchived(id2) ? null : archiveDest(found2);
|
|
51543
51732
|
const cardFile3 = found2.kind === "group" ? path60.join(found2.target, "root.md") : found2.target;
|
|
51544
|
-
const cardText =
|
|
51733
|
+
const cardText = fs58.existsSync(cardFile3) ? fs58.readFileSync(cardFile3, "utf8") : "";
|
|
51545
51734
|
const { meta: cardMeta3 } = parseFrontmatter(cardText);
|
|
51546
51735
|
const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f) => f !== cardFile3).map((f) => rel(f)).sort() : [];
|
|
51547
51736
|
const leftIds = leavingIds(id2, found2);
|
|
51548
51737
|
const leaving = leavingCards(id2, found2);
|
|
51549
51738
|
if (options.archivingTask) {
|
|
51550
51739
|
for (const card of leaving) {
|
|
51551
|
-
const meta3 = parseFrontmatter(
|
|
51740
|
+
const meta3 = parseFrontmatter(fs58.readFileSync(card.file, "utf8")).meta;
|
|
51552
51741
|
if (!meta3 || meta3.rejected) die(`#${card.id} is not eligible for archive.`, { kind: "conflict" });
|
|
51553
51742
|
if (meta3.questions.length) die(`Resolve the open questions on #${card.id} before archiving.`, { kind: "conflict" });
|
|
51554
51743
|
if (card.id !== id2 && (activeDelivery(card.id) || creationRefusal(card.id, cardCreation(card.id), "archive", false))) {
|
|
@@ -51582,10 +51771,10 @@ function removeCard(id2, metric, options) {
|
|
|
51582
51771
|
const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
|
|
51583
51772
|
if (dest) {
|
|
51584
51773
|
stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
|
|
51585
|
-
|
|
51586
|
-
|
|
51774
|
+
fs58.mkdirSync(ARCHIVE, { recursive: true });
|
|
51775
|
+
fs58.renameSync(found2.target, dest);
|
|
51587
51776
|
} else {
|
|
51588
|
-
|
|
51777
|
+
fs58.rmSync(found2.target, { recursive: true, force: true });
|
|
51589
51778
|
}
|
|
51590
51779
|
const removedRefs = stripReadmeRefs(found2);
|
|
51591
51780
|
let marked2 = null;
|
|
@@ -51641,7 +51830,7 @@ function closeGroup(rootFile) {
|
|
|
51641
51830
|
say(`
|
|
51642
51831
|
every subtask line on #${rootId} is resolved \u2014 closing the group:`);
|
|
51643
51832
|
try {
|
|
51644
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51833
|
+
const { meta: meta3, body } = parseFrontmatter(fs58.readFileSync(rootFile, "utf8"));
|
|
51645
51834
|
const res = cmdRemove(rootId, "completed", { closing: true });
|
|
51646
51835
|
return {
|
|
51647
51836
|
id: rootId,
|
|
@@ -51705,7 +51894,7 @@ function recoveredArchiveHandoff(id2, source2) {
|
|
|
51705
51894
|
const found2 = locateArchived(id2);
|
|
51706
51895
|
if (!found2) throw new Error(`No archived card #${id2} was found.`);
|
|
51707
51896
|
const file2 = found2.kind === "group" ? path60.join(found2.target, "root.md") : found2.target;
|
|
51708
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
51897
|
+
const { meta: meta3 } = parseFrontmatter(fs58.readFileSync(file2, "utf8"));
|
|
51709
51898
|
stripReadmeRefs(source2 ?? found2);
|
|
51710
51899
|
const root2 = source2?.kind === "file" ? enclosingGroupRoot(source2.target) : null;
|
|
51711
51900
|
if (root2) markSubtask(root2, id2, "tick");
|
|
@@ -51824,7 +52013,7 @@ var init_bundled2 = __esm({
|
|
|
51824
52013
|
});
|
|
51825
52014
|
|
|
51826
52015
|
// src/lib/memories.ts
|
|
51827
|
-
import
|
|
52016
|
+
import fs59 from "node:fs";
|
|
51828
52017
|
import path61 from "node:path";
|
|
51829
52018
|
function readMemory(text5, builtIn, folder2) {
|
|
51830
52019
|
const { meta: meta3, body } = splitFrontmatter(text5);
|
|
@@ -51856,14 +52045,14 @@ function globalMemories() {
|
|
|
51856
52045
|
}
|
|
51857
52046
|
let folders2 = [];
|
|
51858
52047
|
try {
|
|
51859
|
-
folders2 =
|
|
52048
|
+
folders2 = fs59.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
51860
52049
|
} catch {
|
|
51861
52050
|
}
|
|
51862
52051
|
for (const name of folders2) {
|
|
51863
52052
|
if (name in BUNDLED_MEMORY_FILES || name === RESERVED_MEMORY_DIR || name === STUDIO_MEMORY_DIR) continue;
|
|
51864
52053
|
const file2 = path61.join(MEMORY, name, GLOBAL_MEMORY_FILE);
|
|
51865
|
-
if (!
|
|
51866
|
-
const memory = readMemory(
|
|
52054
|
+
if (!fs59.existsSync(file2)) continue;
|
|
52055
|
+
const memory = readMemory(fs59.readFileSync(file2, "utf8"), false, name);
|
|
51867
52056
|
if (memory) out.push(memory);
|
|
51868
52057
|
}
|
|
51869
52058
|
return out;
|
|
@@ -51904,7 +52093,7 @@ var init_memory_file = __esm({
|
|
|
51904
52093
|
});
|
|
51905
52094
|
|
|
51906
52095
|
// src/commands/inspect.ts
|
|
51907
|
-
import
|
|
52096
|
+
import fs60 from "node:fs";
|
|
51908
52097
|
import os4 from "node:os";
|
|
51909
52098
|
import path62 from "node:path";
|
|
51910
52099
|
function cmdInspect(id2) {
|
|
@@ -51912,7 +52101,7 @@ function cmdInspect(id2) {
|
|
|
51912
52101
|
const unavailable = [];
|
|
51913
52102
|
function read5(source2, file3, empty) {
|
|
51914
52103
|
try {
|
|
51915
|
-
return JSON.parse(
|
|
52104
|
+
return JSON.parse(fs60.readFileSync(file3, "utf8"));
|
|
51916
52105
|
} catch (error62) {
|
|
51917
52106
|
if (error62.code === "ENOENT") return empty;
|
|
51918
52107
|
findings.push({ source: source2, message: String(error62) });
|
|
@@ -51934,7 +52123,7 @@ function cmdInspect(id2) {
|
|
|
51934
52123
|
const file2 = found2.kind === "group" ? path62.join(found2.target, "root.md") : found2.target;
|
|
51935
52124
|
let card = null;
|
|
51936
52125
|
try {
|
|
51937
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
52126
|
+
const { meta: meta3, body } = parseFrontmatter(fs60.readFileSync(file2, "utf8"));
|
|
51938
52127
|
if (!meta3) throw Error("The card frontmatter could not be parsed.");
|
|
51939
52128
|
card = { path: rel(file2), questions: meta3.questions, todos: [...body.matchAll(/^\s*[-*]\s+\[([ xX])\]\s+(.*)$/gm)].map((m) => ({ text: m[2], done: m[1] !== " " })) };
|
|
51940
52129
|
} catch (error62) {
|
|
@@ -51947,7 +52136,7 @@ function cmdInspect(id2) {
|
|
|
51947
52136
|
const records = [];
|
|
51948
52137
|
const directory = path62.join(KANBAN, "deliveries");
|
|
51949
52138
|
try {
|
|
51950
|
-
for (const name of
|
|
52139
|
+
for (const name of fs60.readdirSync(directory).filter((name2) => name2.endsWith(".json"))) {
|
|
51951
52140
|
const held5 = read5("delivery", path62.join(directory, name), null);
|
|
51952
52141
|
if (held5?.cardId === id2) records.push(held5);
|
|
51953
52142
|
}
|
|
@@ -52001,7 +52190,7 @@ function cmdValidate(id2) {
|
|
|
52001
52190
|
const reason = errors.length ? formatContractErrors(errors) : void 0;
|
|
52002
52191
|
const session = insideRun();
|
|
52003
52192
|
if (session) patch(session, (run3) => {
|
|
52004
|
-
run3.validationFailure = reason ? { code: "validation_failed",
|
|
52193
|
+
run3.validationFailure = reason ? makeFailure("validation", reason, { code: "validation_failed", detail: reason }) : void 0;
|
|
52005
52194
|
});
|
|
52006
52195
|
if (reason) die(reason, { kind: "spec-contract", errors });
|
|
52007
52196
|
say(`Spec format valid (${cards.length} card${cards.length === 1 ? "" : "s"}).`);
|
|
@@ -52010,6 +52199,7 @@ function cmdValidate(id2) {
|
|
|
52010
52199
|
var init_validate2 = __esm({
|
|
52011
52200
|
"src/commands/validate.ts"() {
|
|
52012
52201
|
"use strict";
|
|
52202
|
+
init_retry();
|
|
52013
52203
|
init_env();
|
|
52014
52204
|
init_sessions();
|
|
52015
52205
|
init_io();
|
|
@@ -52019,7 +52209,7 @@ var init_validate2 = __esm({
|
|
|
52019
52209
|
});
|
|
52020
52210
|
|
|
52021
52211
|
// src/lib/card-sources.ts
|
|
52022
|
-
import
|
|
52212
|
+
import fs61 from "node:fs";
|
|
52023
52213
|
import path63 from "node:path";
|
|
52024
52214
|
function planById(id2) {
|
|
52025
52215
|
const found2 = readPlan(`plans/${id2}-.md`);
|
|
@@ -52031,7 +52221,7 @@ function cardLink(id2) {
|
|
|
52031
52221
|
if (!found2) return null;
|
|
52032
52222
|
try {
|
|
52033
52223
|
const file2 = found2.kind === "group" ? path63.join(found2.target, "root.md") : found2.target;
|
|
52034
|
-
const title = parseFrontmatter(
|
|
52224
|
+
const title = parseFrontmatter(fs61.readFileSync(file2, "utf8")).meta?.title ?? "";
|
|
52035
52225
|
return { kind: "card", ref: String(id2), title, ...open4 ? {} : { archived: true } };
|
|
52036
52226
|
} catch {
|
|
52037
52227
|
return null;
|
|
@@ -52094,7 +52284,7 @@ var init_card_sources = __esm({
|
|
|
52094
52284
|
});
|
|
52095
52285
|
|
|
52096
52286
|
// src/lib/view/read.ts
|
|
52097
|
-
import
|
|
52287
|
+
import fs62 from "node:fs";
|
|
52098
52288
|
import path64 from "node:path";
|
|
52099
52289
|
function readCard(file2, relFromTodo) {
|
|
52100
52290
|
const id2 = idPrefix(path64.basename(relFromTodo));
|
|
@@ -52107,7 +52297,7 @@ function readCard(file2, relFromTodo) {
|
|
|
52107
52297
|
return buildCard(id2, file2, relFromTodo);
|
|
52108
52298
|
}
|
|
52109
52299
|
function buildCard(id2, file2, relFromTodo) {
|
|
52110
|
-
const text5 =
|
|
52300
|
+
const text5 = fs62.readFileSync(file2, "utf8");
|
|
52111
52301
|
const { meta: meta3, body } = parseFrontmatter(text5);
|
|
52112
52302
|
if (!meta3) return null;
|
|
52113
52303
|
const relPath = relFromTodo.split(path64.sep).join("/");
|
|
@@ -52118,7 +52308,7 @@ function buildCard(id2, file2, relFromTodo) {
|
|
|
52118
52308
|
// Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
|
|
52119
52309
|
// read here and a card read by the contract agree on what version this is.
|
|
52120
52310
|
revision: revisionOf(text5),
|
|
52121
|
-
updatedAt:
|
|
52311
|
+
updatedAt: fs62.statSync(file2).mtime.toISOString(),
|
|
52122
52312
|
relPath,
|
|
52123
52313
|
title: meta3.title,
|
|
52124
52314
|
priority: meta3.priority,
|
|
@@ -52140,7 +52330,7 @@ function buildCard(id2, file2, relFromTodo) {
|
|
|
52140
52330
|
function readGroup(folderName) {
|
|
52141
52331
|
const groupDir = path64.join(TODO, folderName);
|
|
52142
52332
|
const rootFile = path64.join(groupDir, "root.md");
|
|
52143
|
-
if (!
|
|
52333
|
+
if (!fs62.existsSync(rootFile)) return null;
|
|
52144
52334
|
const root2 = readCard(rootFile, path64.join(folderName, "root.md"));
|
|
52145
52335
|
if (!root2) return null;
|
|
52146
52336
|
root2.isGroup = true;
|
|
@@ -52148,7 +52338,7 @@ function readGroup(folderName) {
|
|
|
52148
52338
|
root2.subtaskLines = { total, resolved };
|
|
52149
52339
|
const subCards = [];
|
|
52150
52340
|
const recurse = (dir, relDir) => {
|
|
52151
|
-
for (const entry of
|
|
52341
|
+
for (const entry of fs62.readdirSync(dir, { withFileTypes: true })) {
|
|
52152
52342
|
const childRel = path64.join(relDir, entry.name);
|
|
52153
52343
|
if (entry.isDirectory()) {
|
|
52154
52344
|
recurse(path64.join(dir, entry.name), childRel);
|
|
@@ -52175,9 +52365,9 @@ function readGroup(folderName) {
|
|
|
52175
52365
|
}
|
|
52176
52366
|
function standaloneCards(dirRel) {
|
|
52177
52367
|
const dir = dirRel ? path64.join(TODO, dirRel) : TODO;
|
|
52178
|
-
if (!
|
|
52368
|
+
if (!fs62.existsSync(dir)) return [];
|
|
52179
52369
|
const cards = [];
|
|
52180
|
-
for (const entry of
|
|
52370
|
+
for (const entry of fs62.readdirSync(dir, { withFileTypes: true })) {
|
|
52181
52371
|
if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
|
|
52182
52372
|
const c = readCard(path64.join(dir, entry.name), path64.join(dirRel, entry.name));
|
|
52183
52373
|
if (c) cards.push(c);
|
|
@@ -52191,7 +52381,7 @@ function collectCards() {
|
|
|
52191
52381
|
const top = standaloneCards("");
|
|
52192
52382
|
board2.push(...top);
|
|
52193
52383
|
every.push(...top);
|
|
52194
|
-
for (const entry of
|
|
52384
|
+
for (const entry of fs62.readdirSync(TODO, { withFileTypes: true })) {
|
|
52195
52385
|
if (!entry.isDirectory()) continue;
|
|
52196
52386
|
if (isGroupFolder(entry.name)) {
|
|
52197
52387
|
const g = readGroup(entry.name);
|
|
@@ -52223,7 +52413,7 @@ function findCard(id2) {
|
|
|
52223
52413
|
}
|
|
52224
52414
|
function attachSources(card) {
|
|
52225
52415
|
try {
|
|
52226
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
52416
|
+
const { meta: meta3, body } = parseFrontmatter(fs62.readFileSync(path64.join(TODO, card.relPath), "utf8"));
|
|
52227
52417
|
const sources2 = meta3 ? cardSources(meta3, body) : [];
|
|
52228
52418
|
if (sources2.length) card.sources = sources2;
|
|
52229
52419
|
} catch {
|
|
@@ -52597,7 +52787,7 @@ var init_project_agent = __esm({
|
|
|
52597
52787
|
|
|
52598
52788
|
// src/lib/agent/creation.ts
|
|
52599
52789
|
import crypto3 from "node:crypto";
|
|
52600
|
-
import
|
|
52790
|
+
import fs63 from "node:fs";
|
|
52601
52791
|
import path65 from "node:path";
|
|
52602
52792
|
function creationError(error62, triage) {
|
|
52603
52793
|
const zh = readLanguage() === "zh";
|
|
@@ -52629,7 +52819,7 @@ ${slot}`).digest("hex");
|
|
|
52629
52819
|
function readCreation(file2, said2) {
|
|
52630
52820
|
return withCreationLock(() => {
|
|
52631
52821
|
try {
|
|
52632
|
-
const held4 = JSON.parse(
|
|
52822
|
+
const held4 = JSON.parse(fs63.readFileSync(file2, "utf8"));
|
|
52633
52823
|
if (!held4.said || typeof held4.said.title !== "string") throw new Error("Invalid creation journal");
|
|
52634
52824
|
return held4;
|
|
52635
52825
|
} catch (error62) {
|
|
@@ -52641,10 +52831,10 @@ function readCreation(file2, said2) {
|
|
|
52641
52831
|
});
|
|
52642
52832
|
}
|
|
52643
52833
|
function saveCreation(file2, journal) {
|
|
52644
|
-
|
|
52834
|
+
fs63.mkdirSync(path65.dirname(file2), { recursive: true });
|
|
52645
52835
|
const temp = `${file2}.${crypto3.randomUUID()}.tmp`;
|
|
52646
|
-
|
|
52647
|
-
|
|
52836
|
+
fs63.writeFileSync(temp, JSON.stringify(journal));
|
|
52837
|
+
fs63.renameSync(temp, file2);
|
|
52648
52838
|
}
|
|
52649
52839
|
function archiveCreation(source2, id2) {
|
|
52650
52840
|
if (readArchived().some((s) => s.sourceId === source2 && s.cardId === id2)) return;
|
|
@@ -53790,7 +53980,7 @@ var require_command = __commonJS({
|
|
|
53790
53980
|
var EventEmitter = __require("node:events").EventEmitter;
|
|
53791
53981
|
var childProcess = __require("node:child_process");
|
|
53792
53982
|
var path88 = __require("node:path");
|
|
53793
|
-
var
|
|
53983
|
+
var fs91 = __require("node:fs");
|
|
53794
53984
|
var process2 = __require("node:process");
|
|
53795
53985
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
53796
53986
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -54771,7 +54961,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54771
54961
|
* @param {string} subcommandName
|
|
54772
54962
|
*/
|
|
54773
54963
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
54774
|
-
if (
|
|
54964
|
+
if (fs91.existsSync(executableFile)) return;
|
|
54775
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";
|
|
54776
54966
|
const executableMissing = `'${executableFile}' does not exist
|
|
54777
54967
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -54790,10 +54980,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54790
54980
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
54791
54981
|
function findFile(baseDir, baseName) {
|
|
54792
54982
|
const localBin = path88.resolve(baseDir, baseName);
|
|
54793
|
-
if (
|
|
54983
|
+
if (fs91.existsSync(localBin)) return localBin;
|
|
54794
54984
|
if (sourceExt.includes(path88.extname(baseName))) return void 0;
|
|
54795
54985
|
const foundExt = sourceExt.find(
|
|
54796
|
-
(ext) =>
|
|
54986
|
+
(ext) => fs91.existsSync(`${localBin}${ext}`)
|
|
54797
54987
|
);
|
|
54798
54988
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
54799
54989
|
return void 0;
|
|
@@ -54805,7 +54995,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54805
54995
|
if (this._scriptPath) {
|
|
54806
54996
|
let resolvedScriptPath;
|
|
54807
54997
|
try {
|
|
54808
|
-
resolvedScriptPath =
|
|
54998
|
+
resolvedScriptPath = fs91.realpathSync(this._scriptPath);
|
|
54809
54999
|
} catch {
|
|
54810
55000
|
resolvedScriptPath = this._scriptPath;
|
|
54811
55001
|
}
|
|
@@ -56141,7 +56331,7 @@ var init_shared2 = __esm({
|
|
|
56141
56331
|
});
|
|
56142
56332
|
|
|
56143
56333
|
// src/lib/agents/shared-memory.ts
|
|
56144
|
-
import
|
|
56334
|
+
import fs64 from "node:fs";
|
|
56145
56335
|
import path66 from "node:path";
|
|
56146
56336
|
function sharedMemory(board2) {
|
|
56147
56337
|
const declared = /* @__PURE__ */ new Map();
|
|
@@ -56150,7 +56340,7 @@ function sharedMemory(board2) {
|
|
|
56150
56340
|
const read5 = parseSpecAgent(text5, folder2, (relative) => {
|
|
56151
56341
|
if (builtIn) return shippedAgentFiles()[`${folder2}/${relative}`] ?? null;
|
|
56152
56342
|
try {
|
|
56153
|
-
return
|
|
56343
|
+
return fs64.readFileSync(path66.join(board2, "agents", folder2, relative), "utf8");
|
|
56154
56344
|
} catch {
|
|
56155
56345
|
return null;
|
|
56156
56346
|
}
|
|
@@ -56164,13 +56354,13 @@ function sharedMemory(board2) {
|
|
|
56164
56354
|
const root2 = path66.join(board2, "agents");
|
|
56165
56355
|
let folders2 = [];
|
|
56166
56356
|
try {
|
|
56167
|
-
folders2 =
|
|
56357
|
+
folders2 = fs64.readdirSync(root2, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
56168
56358
|
} catch {
|
|
56169
56359
|
}
|
|
56170
56360
|
for (const folder2 of folders2.sort()) {
|
|
56171
56361
|
let text5 = null;
|
|
56172
56362
|
try {
|
|
56173
|
-
text5 =
|
|
56363
|
+
text5 = fs64.readFileSync(path66.join(root2, folder2, "AGENT.md"), "utf8");
|
|
56174
56364
|
} catch {
|
|
56175
56365
|
}
|
|
56176
56366
|
take(folder2, text5, false);
|
|
@@ -56196,30 +56386,30 @@ var init_shared_memory = __esm({
|
|
|
56196
56386
|
|
|
56197
56387
|
// src/lib/shared/board-conflicts.ts
|
|
56198
56388
|
import crypto4 from "node:crypto";
|
|
56199
|
-
import
|
|
56389
|
+
import fs65 from "node:fs";
|
|
56200
56390
|
import path67 from "node:path";
|
|
56201
56391
|
function atomicJson(file2, data) {
|
|
56202
|
-
|
|
56392
|
+
fs65.mkdirSync(path67.dirname(file2), { recursive: true });
|
|
56203
56393
|
const temp = `${file2}.${crypto4.randomUUID()}.tmp`;
|
|
56204
|
-
const fd =
|
|
56394
|
+
const fd = fs65.openSync(temp, "wx", 384);
|
|
56205
56395
|
try {
|
|
56206
|
-
|
|
56207
|
-
|
|
56396
|
+
fs65.writeFileSync(fd, JSON.stringify(data));
|
|
56397
|
+
fs65.fsyncSync(fd);
|
|
56208
56398
|
} finally {
|
|
56209
|
-
|
|
56399
|
+
fs65.closeSync(fd);
|
|
56210
56400
|
}
|
|
56211
|
-
|
|
56401
|
+
fs65.renameSync(temp, file2);
|
|
56212
56402
|
}
|
|
56213
56403
|
function boardTextAt(board2, name) {
|
|
56214
56404
|
if (!isBoardPath(name)) throw new BoardError(`Invalid board path: ${name}`, { kind: "invalid-usage" });
|
|
56215
56405
|
const file2 = path67.join(board2, name);
|
|
56216
56406
|
let ancestor = file2;
|
|
56217
|
-
while (!
|
|
56218
|
-
const real2 = path67.resolve(
|
|
56219
|
-
if (!real2.startsWith(
|
|
56220
|
-
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" });
|
|
56221
56411
|
try {
|
|
56222
|
-
return
|
|
56412
|
+
return fs65.readFileSync(file2, "utf8");
|
|
56223
56413
|
} catch (e) {
|
|
56224
56414
|
if (e.code === "ENOENT") return null;
|
|
56225
56415
|
throw e;
|
|
@@ -56230,9 +56420,9 @@ function save2(board2, record2) {
|
|
|
56230
56420
|
}
|
|
56231
56421
|
function read2(board2, id2) {
|
|
56232
56422
|
const file2 = fileOf(board2, id2);
|
|
56233
|
-
if (!
|
|
56423
|
+
if (!fs65.existsSync(file2)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
|
|
56234
56424
|
try {
|
|
56235
|
-
const r = JSON.parse(
|
|
56425
|
+
const r = JSON.parse(fs65.readFileSync(file2, "utf8"));
|
|
56236
56426
|
if (r.id !== id2 || !r.project || !["open", "unconfirmed", "resolved"].includes(r.state) || !Array.isArray(r.files) || !r.files.length) throw Error();
|
|
56237
56427
|
const names2 = /* @__PURE__ */ new Set();
|
|
56238
56428
|
for (const f of r.files) {
|
|
@@ -56254,7 +56444,7 @@ function read2(board2, id2) {
|
|
|
56254
56444
|
function conflictRecords(board2) {
|
|
56255
56445
|
let names2;
|
|
56256
56446
|
try {
|
|
56257
|
-
names2 =
|
|
56447
|
+
names2 = fs65.readdirSync(folder(board2));
|
|
56258
56448
|
} catch (e) {
|
|
56259
56449
|
if (e.code === "ENOENT") return [];
|
|
56260
56450
|
throw e;
|
|
@@ -56343,7 +56533,7 @@ function confirmLocal(board2, r) {
|
|
|
56343
56533
|
const draft = r.draft;
|
|
56344
56534
|
const root2 = stateRootOf(board2);
|
|
56345
56535
|
const file2 = path67.join(root2, ".akb", "base.json");
|
|
56346
|
-
const base = JSON.parse(
|
|
56536
|
+
const base = JSON.parse(fs65.readFileSync(file2, "utf8"));
|
|
56347
56537
|
if (base.project && base.project !== r.project) refuse(r, "The project binding changed.", "cloud-refused");
|
|
56348
56538
|
base.deleted ??= {};
|
|
56349
56539
|
for (const [i, f] of r.files.entries()) {
|
|
@@ -56360,10 +56550,10 @@ function confirmLocal(board2, r) {
|
|
|
56360
56550
|
}
|
|
56361
56551
|
if (boardTextAt(board2, f.path) !== draft.working[i]) continue;
|
|
56362
56552
|
const local = path67.join(board2, f.path);
|
|
56363
|
-
if (sent.content === null)
|
|
56553
|
+
if (sent.content === null) fs65.rmSync(local, { force: true });
|
|
56364
56554
|
else {
|
|
56365
|
-
|
|
56366
|
-
|
|
56555
|
+
fs65.mkdirSync(path67.dirname(local), { recursive: true });
|
|
56556
|
+
fs65.writeFileSync(local, sent.content);
|
|
56367
56557
|
}
|
|
56368
56558
|
}
|
|
56369
56559
|
atomicJson(file2, base);
|
|
@@ -56541,7 +56731,7 @@ __export(board_exports, {
|
|
|
56541
56731
|
buildBoardProgram: () => buildBoardProgram
|
|
56542
56732
|
});
|
|
56543
56733
|
import crypto5 from "node:crypto";
|
|
56544
|
-
import
|
|
56734
|
+
import fs66 from "node:fs";
|
|
56545
56735
|
import path68 from "node:path";
|
|
56546
56736
|
async function dispatch(move, cmd, args2, opts, cli) {
|
|
56547
56737
|
const ctx = ctxOf(cmd, cli.program);
|
|
@@ -56562,7 +56752,7 @@ async function dispatch(move, cmd, args2, opts, cli) {
|
|
|
56562
56752
|
}
|
|
56563
56753
|
let resolution;
|
|
56564
56754
|
try {
|
|
56565
|
-
resolution = JSON.parse(
|
|
56755
|
+
resolution = JSON.parse(fs66.readFileSync(String(opts.file), "utf8"));
|
|
56566
56756
|
} catch {
|
|
56567
56757
|
throw new BoardError("Cannot read the UTF-8 JSON resolution file.", { kind: "invalid-usage" });
|
|
56568
56758
|
}
|
|
@@ -56603,7 +56793,7 @@ async function cloudCard(task, opts) {
|
|
|
56603
56793
|
let request2;
|
|
56604
56794
|
if (typeof opts.bodyFile === "string") {
|
|
56605
56795
|
try {
|
|
56606
|
-
request2 =
|
|
56796
|
+
request2 = fs66.readFileSync(opts.bodyFile, "utf8");
|
|
56607
56797
|
} catch {
|
|
56608
56798
|
}
|
|
56609
56799
|
}
|
|
@@ -56768,7 +56958,7 @@ var init_board2 = __esm({
|
|
|
56768
56958
|
});
|
|
56769
56959
|
|
|
56770
56960
|
// src/lib/board-cli.ts
|
|
56771
|
-
import
|
|
56961
|
+
import fs67 from "node:fs";
|
|
56772
56962
|
import path69 from "node:path";
|
|
56773
56963
|
function useBoard(found2, dirNamed, readOnly = false) {
|
|
56774
56964
|
if (!found2.named && found2.board === path69.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
|
|
@@ -56780,7 +56970,7 @@ function useBoard(found2, dirNamed, readOnly = false) {
|
|
|
56780
56970
|
}
|
|
56781
56971
|
function whole(found2, move) {
|
|
56782
56972
|
if (move === MAKES_A_BOARD) return found2;
|
|
56783
|
-
if (!
|
|
56973
|
+
if (!fs67.existsSync(path69.join(found2.board, "todo"))) {
|
|
56784
56974
|
die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
|
|
56785
56975
|
kind: "board-incomplete",
|
|
56786
56976
|
dir: found2.root
|
|
@@ -56794,7 +56984,7 @@ function findBoardUpward(from, move) {
|
|
|
56794
56984
|
if (hasBoard(dir)) return { root: dir, board: path69.join(dir, "docs", "kanban") };
|
|
56795
56985
|
if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
|
|
56796
56986
|
const kept2 = path69.join(dir, ".akb", "kanban");
|
|
56797
|
-
if (move !== MAKES_A_BOARD &&
|
|
56987
|
+
if (move !== MAKES_A_BOARD && fs67.existsSync(path69.join(kept2, "todo"))) return { root: dir, board: kept2 };
|
|
56798
56988
|
const up = path69.dirname(dir);
|
|
56799
56989
|
if (up === dir) return null;
|
|
56800
56990
|
dir = up;
|
|
@@ -56804,10 +56994,10 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
56804
56994
|
const named2 = board2 ?? boardFromEnv();
|
|
56805
56995
|
if (named2) {
|
|
56806
56996
|
const folder2 = path69.resolve(cwd, named2);
|
|
56807
|
-
if (!
|
|
56997
|
+
if (!fs67.existsSync(folder2) && move !== MAKES_A_BOARD) {
|
|
56808
56998
|
die(`no such folder: ${folder2}`, { kind: "no-such-folder", dir: folder2 });
|
|
56809
56999
|
}
|
|
56810
|
-
if (
|
|
57000
|
+
if (fs67.existsSync(folder2) && !isBoardDir(folder2) && move !== MAKES_A_BOARD) {
|
|
56811
57001
|
die(`${folder2} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
|
|
56812
57002
|
kind: "no-board",
|
|
56813
57003
|
dir: folder2
|
|
@@ -56817,9 +57007,9 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
56817
57007
|
}
|
|
56818
57008
|
if (dir !== null) {
|
|
56819
57009
|
const root2 = path69.resolve(dir);
|
|
56820
|
-
if (!
|
|
57010
|
+
if (!fs67.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
|
|
56821
57011
|
const kept2 = path69.join(root2, ".akb", "kanban");
|
|
56822
|
-
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);
|
|
56823
57013
|
if (!hasBoard(root2) && move !== MAKES_A_BOARD) {
|
|
56824
57014
|
die(`no board in ${root2} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
|
|
56825
57015
|
kind: "no-board",
|
|
@@ -56910,8 +57100,8 @@ var init_board_cli = __esm({
|
|
|
56910
57100
|
init_io();
|
|
56911
57101
|
init_card_studio_backfill();
|
|
56912
57102
|
MAKES_A_BOARD = "init";
|
|
56913
|
-
hasBoard = (dir) =>
|
|
56914
|
-
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"));
|
|
56915
57105
|
boardFromEnv = () => {
|
|
56916
57106
|
const named2 = process.env.AI4KANBAN_BOARD?.trim();
|
|
56917
57107
|
return named2 ? named2 : null;
|
|
@@ -56920,11 +57110,11 @@ var init_board_cli = __esm({
|
|
|
56920
57110
|
});
|
|
56921
57111
|
|
|
56922
57112
|
// src/lib/cloud/task-operation.ts
|
|
56923
|
-
import
|
|
57113
|
+
import fs68 from "node:fs";
|
|
56924
57114
|
import path70 from "node:path";
|
|
56925
57115
|
function readRemoval(board2, task) {
|
|
56926
57116
|
try {
|
|
56927
|
-
const value = JSON.parse(
|
|
57117
|
+
const value = JSON.parse(fs68.readFileSync(removalFile(board2, task), "utf8"));
|
|
56928
57118
|
if (["pending", "confirmed", "rejected"].includes(value.status) && typeof value.reason === "string" && typeof value.discard === "boolean") return value;
|
|
56929
57119
|
} catch {
|
|
56930
57120
|
}
|
|
@@ -56933,8 +57123,8 @@ function readRemoval(board2, task) {
|
|
|
56933
57123
|
function writeRemoval(board2, task, removal) {
|
|
56934
57124
|
const file2 = removalFile(board2, task);
|
|
56935
57125
|
const temp = `${file2}.${process.pid}.tmp`;
|
|
56936
|
-
|
|
56937
|
-
|
|
57126
|
+
fs68.writeFileSync(temp, JSON.stringify(removal) + "\n");
|
|
57127
|
+
fs68.renameSync(temp, file2);
|
|
56938
57128
|
}
|
|
56939
57129
|
var removalFile;
|
|
56940
57130
|
var init_task_operation = __esm({
|
|
@@ -56990,10 +57180,10 @@ var init_avatar = __esm({
|
|
|
56990
57180
|
});
|
|
56991
57181
|
|
|
56992
57182
|
// src/lib/cloud/pro.ts
|
|
56993
|
-
import
|
|
57183
|
+
import fs69 from "node:fs";
|
|
56994
57184
|
import path71 from "node:path";
|
|
56995
57185
|
function forgetPro() {
|
|
56996
|
-
|
|
57186
|
+
fs69.rmSync(heldFile(), { force: true });
|
|
56997
57187
|
}
|
|
56998
57188
|
var FRESH_MS2, GRACE_MS, heldFile;
|
|
56999
57189
|
var init_pro = __esm({
|
|
@@ -57099,7 +57289,7 @@ var init_account = __esm({
|
|
|
57099
57289
|
});
|
|
57100
57290
|
|
|
57101
57291
|
// src/commands/cloud.ts
|
|
57102
|
-
import
|
|
57292
|
+
import fs70 from "node:fs";
|
|
57103
57293
|
import path72 from "node:path";
|
|
57104
57294
|
async function cmdCloud(args2, program2) {
|
|
57105
57295
|
const [sub] = args2;
|
|
@@ -57175,7 +57365,7 @@ async function cloudImage(opts, program2) {
|
|
|
57175
57365
|
const type = REF_TYPES[path72.extname(file2).toLowerCase()];
|
|
57176
57366
|
if (!type) usage(`--ref ${file2}: use a PNG, JPEG or WebP file.`, line);
|
|
57177
57367
|
try {
|
|
57178
|
-
return `data:${type};base64,${
|
|
57368
|
+
return `data:${type};base64,${fs70.readFileSync(file2).toString("base64")}`;
|
|
57179
57369
|
} catch (e) {
|
|
57180
57370
|
usage(`--ref ${file2}: ${e instanceof Error ? e.message : String(e)}`, line);
|
|
57181
57371
|
}
|
|
@@ -57299,8 +57489,8 @@ usage: ${g.usage}` }, { bare: true, exitCode: 2 });
|
|
|
57299
57489
|
refuse2(g.failed, g.fallback, { code: error62.kind, message: error62.message, retryable: true });
|
|
57300
57490
|
}
|
|
57301
57491
|
const out = g.outFor?.(res, g.out) ?? g.out;
|
|
57302
|
-
|
|
57303
|
-
|
|
57492
|
+
fs70.mkdirSync(path72.dirname(path72.resolve(out)), { recursive: true });
|
|
57493
|
+
fs70.writeFileSync(out, bytes2);
|
|
57304
57494
|
say(`${out} (${g.label(res)})`);
|
|
57305
57495
|
return { out };
|
|
57306
57496
|
}
|
|
@@ -57362,7 +57552,7 @@ var init_cloud = __esm({
|
|
|
57362
57552
|
});
|
|
57363
57553
|
|
|
57364
57554
|
// src/commands/task.ts
|
|
57365
|
-
import
|
|
57555
|
+
import fs71 from "node:fs";
|
|
57366
57556
|
import os5 from "node:os";
|
|
57367
57557
|
import path73 from "node:path";
|
|
57368
57558
|
async function cloud(method, route2, body, signal2) {
|
|
@@ -57421,7 +57611,7 @@ function linked(location) {
|
|
|
57421
57611
|
return link2.ok ? link2.value : null;
|
|
57422
57612
|
}
|
|
57423
57613
|
for (let dir = path73.resolve(cwd, location.dir ?? "."); ; dir = path73.dirname(dir)) {
|
|
57424
|
-
if (
|
|
57614
|
+
if (fs71.existsSync(path73.join(dir, ".akb", "base.json"))) {
|
|
57425
57615
|
const link2 = linkedProject("", dir);
|
|
57426
57616
|
return link2.ok ? link2.value : null;
|
|
57427
57617
|
}
|
|
@@ -57528,7 +57718,7 @@ async function taskReview(id2, opts = {}, location = {}) {
|
|
|
57528
57718
|
if (opts.review !== void 0) {
|
|
57529
57719
|
fields2 = { operation: "plan", review_flow: opts.review };
|
|
57530
57720
|
} else if (opts.file !== void 0) {
|
|
57531
|
-
fields2 = { operation: "plan", review_plan: parseReviewPlan(JSON.parse(
|
|
57721
|
+
fields2 = { operation: "plan", review_plan: parseReviewPlan(JSON.parse(fs71.readFileSync(opts.file, "utf8"))) };
|
|
57532
57722
|
} else if (opts.reviseFrom !== void 0) {
|
|
57533
57723
|
fields2 = { operation: "revise", stage: opts.reviseFrom };
|
|
57534
57724
|
} else if (opts.previewDefinitionsFile !== void 0) {
|
|
@@ -57537,7 +57727,7 @@ async function taskReview(id2, opts = {}, location = {}) {
|
|
|
57537
57727
|
if (!opts.stage || !["running", "done"].includes(opts.status)) die("--stage and --status running|done are required.");
|
|
57538
57728
|
fields2 = { operation: "status", stage: opts.stage, status: opts.status };
|
|
57539
57729
|
}
|
|
57540
|
-
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")));
|
|
57541
57731
|
task = await cloud("POST", `/v1/tasks/${enc(ref)}/review`, { ...fields2, review_revision });
|
|
57542
57732
|
}
|
|
57543
57733
|
say(JSON.stringify(task.review, null, 2));
|
|
@@ -57580,7 +57770,7 @@ async function taskUpdateQuestions(id2, typed, location = {}) {
|
|
|
57580
57770
|
return withBoardLock(() => {
|
|
57581
57771
|
const run3 = insideRun();
|
|
57582
57772
|
const runCard = run3 ? peekRun(run3)?.cardId : null;
|
|
57583
|
-
if (runCard != null && runCard !== mapped.number || !
|
|
57773
|
+
if (runCard != null && runCard !== mapped.number || !fs71.existsSync(path73.join(board2, "todo")) || !locate(mapped.number)) {
|
|
57584
57774
|
return unavailable();
|
|
57585
57775
|
}
|
|
57586
57776
|
return updateCardQuestions(mapped.number, ops);
|
|
@@ -57621,7 +57811,7 @@ function runnerTaskBoard(location) {
|
|
|
57621
57811
|
const cwd = location.cwd ?? process.cwd();
|
|
57622
57812
|
try {
|
|
57623
57813
|
const board2 = path73.resolve(cwd, location.board ?? runnerBoard);
|
|
57624
|
-
return
|
|
57814
|
+
return fs71.realpathSync(board2) === fs71.realpathSync(path73.resolve(cwd, runnerBoard)) && runnerProject(board2) ? board2 : null;
|
|
57625
57815
|
} catch {
|
|
57626
57816
|
return null;
|
|
57627
57817
|
}
|
|
@@ -57629,7 +57819,7 @@ function runnerTaskBoard(location) {
|
|
|
57629
57819
|
function localTaskRecord(board2, task) {
|
|
57630
57820
|
if (!/^task_[\w-]+$/.test(task)) return null;
|
|
57631
57821
|
try {
|
|
57632
|
-
const record2 = JSON.parse(
|
|
57822
|
+
const record2 = JSON.parse(fs71.readFileSync(path73.join(board2, ".sync", task + ".json"), "utf8"));
|
|
57633
57823
|
if (record2.task === task && Number.isSafeInteger(record2.number) && record2.number > 0 && !record2.deleted) {
|
|
57634
57824
|
return { board: board2, task, number: record2.number };
|
|
57635
57825
|
}
|
|
@@ -57662,7 +57852,7 @@ function operationStatus(result) {
|
|
|
57662
57852
|
}
|
|
57663
57853
|
function archiveReceipt(board2, task, file2) {
|
|
57664
57854
|
try {
|
|
57665
|
-
const base = JSON.parse(
|
|
57855
|
+
const base = JSON.parse(fs71.readFileSync(path73.join(board2, "..", "base.json"), "utf8"));
|
|
57666
57856
|
const receipt = base.archiveReceipts?.[task];
|
|
57667
57857
|
const root2 = `projects/${runnerProject(board2)}/`;
|
|
57668
57858
|
const synced = receipt && base.files?.[root2 + receipt.path];
|
|
@@ -57671,7 +57861,7 @@ function archiveReceipt(board2, task, file2) {
|
|
|
57671
57861
|
if (synced && (!file2 || receipt.path === file2) && synced.seq === receipt.seq && (assets?.seq ?? 0) === receipt.assets_seq) {
|
|
57672
57862
|
const local = (name) => {
|
|
57673
57863
|
try {
|
|
57674
|
-
return
|
|
57864
|
+
return fs71.readFileSync(path73.join(board2, name), "utf8");
|
|
57675
57865
|
} catch {
|
|
57676
57866
|
return null;
|
|
57677
57867
|
}
|
|
@@ -57696,7 +57886,7 @@ async function taskArchive(asked, location = {}) {
|
|
|
57696
57886
|
const existing = locateArchived(local.number);
|
|
57697
57887
|
if (!existing) return null;
|
|
57698
57888
|
const file2 = existing.kind === "group" ? path73.join(existing.target, "root.md") : existing.target;
|
|
57699
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
57889
|
+
const { meta: meta3 } = parseFrontmatter(fs71.readFileSync(file2, "utf8"));
|
|
57700
57890
|
if (!meta3?.archived || meta3.rejected) return refuse3("This task is not eligible for archive.", "conflict");
|
|
57701
57891
|
return {
|
|
57702
57892
|
receipt: { archived_to: path73.relative(local.board, existing.target) },
|
|
@@ -57898,20 +58088,20 @@ var init_goal = __esm({
|
|
|
57898
58088
|
});
|
|
57899
58089
|
|
|
57900
58090
|
// src/lib/goal-draft.ts
|
|
57901
|
-
import
|
|
58091
|
+
import fs72 from "node:fs";
|
|
57902
58092
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
57903
58093
|
function readGoalDraft(file2) {
|
|
57904
|
-
return decodeGoals(JSON.parse(
|
|
58094
|
+
return decodeGoals(JSON.parse(fs72.readFileSync(file2, "utf8")));
|
|
57905
58095
|
}
|
|
57906
58096
|
function writeGoalDraft(file2, { goals, ...draft }, field2) {
|
|
57907
58097
|
const entries2 = field2 === "goals" ? goals : goals.map(({ task, ...goal }) => ({ ...goal, task: task?.key ? task : task?.id ?? null }));
|
|
57908
58098
|
const temporary = `${file2}.${randomUUID7()}.tmp`;
|
|
57909
58099
|
try {
|
|
57910
|
-
|
|
58100
|
+
fs72.writeFileSync(temporary, `${JSON.stringify({ ...draft, [field2]: entries2 }, null, 2)}
|
|
57911
58101
|
`, { mode: 384, flag: "wx" });
|
|
57912
|
-
|
|
58102
|
+
fs72.renameSync(temporary, file2);
|
|
57913
58103
|
} finally {
|
|
57914
|
-
|
|
58104
|
+
fs72.rmSync(temporary, { force: true });
|
|
57915
58105
|
}
|
|
57916
58106
|
}
|
|
57917
58107
|
var goalDraftPath;
|
|
@@ -57924,7 +58114,7 @@ var init_goal_draft = __esm({
|
|
|
57924
58114
|
});
|
|
57925
58115
|
|
|
57926
58116
|
// src/commands/goal.ts
|
|
57927
|
-
import
|
|
58117
|
+
import fs73 from "node:fs";
|
|
57928
58118
|
function loadGoals() {
|
|
57929
58119
|
const file2 = goalDraftPath();
|
|
57930
58120
|
if (!file2) die("Goals exist only inside a WildCrane goal discussion.");
|
|
@@ -57956,7 +58146,7 @@ function splitBody2(text5) {
|
|
|
57956
58146
|
}
|
|
57957
58147
|
function readBody(bodyFile) {
|
|
57958
58148
|
if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
|
|
57959
|
-
const text5 =
|
|
58149
|
+
const text5 = fs73.readFileSync(bodyFile, "utf8");
|
|
57960
58150
|
if (!text5.trim()) die("The goal must not be empty.");
|
|
57961
58151
|
return splitBody2(text5);
|
|
57962
58152
|
}
|
|
@@ -58022,7 +58212,7 @@ function cmdGoalStudios(held4 = loadGoals().held) {
|
|
|
58022
58212
|
return { studios: held4.studios.map((w) => ({ ...w, id: shortStudioId(w.id) })) };
|
|
58023
58213
|
}
|
|
58024
58214
|
function goalDefinitions(opts, previous = []) {
|
|
58025
|
-
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")));
|
|
58026
58216
|
}
|
|
58027
58217
|
function goalCatalog(held4, studio, definitions) {
|
|
58028
58218
|
const builtIn = held4.studios.find((w) => w.id === studio)?.previews;
|
|
@@ -58035,7 +58225,7 @@ function goalReview(held4, studio, opts, previous, definitions) {
|
|
|
58035
58225
|
if (opts.reviewFile !== void 0) die("Use either --review or --review-file.");
|
|
58036
58226
|
return parseReviewFlow(opts.review, catalog);
|
|
58037
58227
|
}
|
|
58038
|
-
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"));
|
|
58039
58229
|
const saved = opts.reviewFile === void 0 && opts.previewDefinitionsFile === void 0 && opts.studio === void 0;
|
|
58040
58230
|
return validateReviewPreviews(parseReviewPlan(value), catalog, { saved });
|
|
58041
58231
|
}
|
|
@@ -58065,7 +58255,7 @@ var init_goal2 = __esm({
|
|
|
58065
58255
|
});
|
|
58066
58256
|
|
|
58067
58257
|
// src/commands/goal-cloud.ts
|
|
58068
|
-
import
|
|
58258
|
+
import fs74 from "node:fs";
|
|
58069
58259
|
import os6 from "node:os";
|
|
58070
58260
|
import path74 from "node:path";
|
|
58071
58261
|
import crypto6 from "node:crypto";
|
|
@@ -58099,17 +58289,17 @@ async function discussion() {
|
|
|
58099
58289
|
const machineFile2 = path74.join(home3, "machine.json");
|
|
58100
58290
|
let machine;
|
|
58101
58291
|
try {
|
|
58102
|
-
machine = JSON.parse(
|
|
58292
|
+
machine = JSON.parse(fs74.readFileSync(machineFile2, "utf8")).id;
|
|
58103
58293
|
} catch {
|
|
58104
58294
|
machine = crypto6.randomUUID();
|
|
58105
|
-
|
|
58106
|
-
|
|
58295
|
+
fs74.mkdirSync(home3, { recursive: true });
|
|
58296
|
+
fs74.writeFileSync(machineFile2, JSON.stringify({ id: machine }));
|
|
58107
58297
|
}
|
|
58108
58298
|
const held4 = await request("GET", `/v1/runner/folders?machine=${encodeURIComponent(machine)}`);
|
|
58109
|
-
const cwd =
|
|
58299
|
+
const cwd = fs74.realpathSync(process.cwd());
|
|
58110
58300
|
const folder2 = held4.folders.filter((f) => {
|
|
58111
58301
|
try {
|
|
58112
|
-
const dir =
|
|
58302
|
+
const dir = fs74.realpathSync(f.path);
|
|
58113
58303
|
return cwd === dir || cwd.startsWith(dir + path74.sep);
|
|
58114
58304
|
} catch {
|
|
58115
58305
|
return false;
|
|
@@ -58423,7 +58613,7 @@ var init_agent = __esm({
|
|
|
58423
58613
|
|
|
58424
58614
|
// src/commands/cloud-template.ts
|
|
58425
58615
|
import { createHash as createHash5 } from "node:crypto";
|
|
58426
|
-
import
|
|
58616
|
+
import fs75 from "node:fs";
|
|
58427
58617
|
import path75 from "node:path";
|
|
58428
58618
|
function usage2(problem, line) {
|
|
58429
58619
|
die(`${problem}
|
|
@@ -58488,9 +58678,9 @@ async function downloadEntries(name, kind, files, to, fallback) {
|
|
|
58488
58678
|
if (file2.sha256 && createHash5("sha256").update(bytes2).digest("hex") !== file2.sha256) refuse4(T.corrupt, fallback, invalidResponse(expected));
|
|
58489
58679
|
fetched.push({ out, bytes: bytes2 });
|
|
58490
58680
|
}
|
|
58491
|
-
if (fetched.length)
|
|
58681
|
+
if (fetched.length) fs75.mkdirSync(to, { recursive: true });
|
|
58492
58682
|
return fetched.map(({ out, bytes: bytes2 }) => {
|
|
58493
|
-
|
|
58683
|
+
fs75.writeFileSync(out, bytes2);
|
|
58494
58684
|
say(out);
|
|
58495
58685
|
return out;
|
|
58496
58686
|
});
|
|
@@ -58563,7 +58753,7 @@ async function templateGet(name, opts, program2) {
|
|
|
58563
58753
|
}
|
|
58564
58754
|
fetched.push({ out, bytes: bytes2 });
|
|
58565
58755
|
}
|
|
58566
|
-
const taken = fetched.filter((f) =>
|
|
58756
|
+
const taken = fetched.filter((f) => fs75.existsSync(f.out)).map((f) => path75.relative(to, f.out));
|
|
58567
58757
|
if (taken.length > 0) {
|
|
58568
58758
|
refuse4({
|
|
58569
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`,
|
|
@@ -58571,8 +58761,8 @@ async function templateGet(name, opts, program2) {
|
|
|
58571
58761
|
});
|
|
58572
58762
|
}
|
|
58573
58763
|
for (const f of fetched) {
|
|
58574
|
-
|
|
58575
|
-
|
|
58764
|
+
fs75.mkdirSync(path75.dirname(f.out), { recursive: true });
|
|
58765
|
+
fs75.writeFileSync(f.out, f.bytes);
|
|
58576
58766
|
}
|
|
58577
58767
|
say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
|
|
58578
58768
|
Fetched ${name}: ${fetched.length} files into ${to}`);
|
|
@@ -58594,13 +58784,13 @@ async function templateSource(name, opts) {
|
|
|
58594
58784
|
async function templatePublish(dir, opts) {
|
|
58595
58785
|
const root2 = path75.resolve(dir);
|
|
58596
58786
|
const manifest = path75.join(root2, "template.md");
|
|
58597
|
-
if (!
|
|
58598
|
-
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"));
|
|
58599
58789
|
const files = walk2(root2);
|
|
58600
|
-
const total = files.reduce((sum, f) => sum +
|
|
58790
|
+
const total = files.reduce((sum, f) => sum + fs75.statSync(path75.join(root2, f)).size, 0);
|
|
58601
58791
|
if (total > MAX_BYTES2) invalid2("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
|
|
58602
58792
|
for (const extra of [...opts.preview, ...opts.evidence]) {
|
|
58603
|
-
if (!
|
|
58793
|
+
if (!fs75.existsSync(extra)) invalid2(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
|
|
58604
58794
|
if (path75.resolve(extra).startsWith(root2 + path75.sep)) {
|
|
58605
58795
|
invalid2(
|
|
58606
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`,
|
|
@@ -58613,7 +58803,7 @@ async function templatePublish(dir, opts) {
|
|
|
58613
58803
|
}
|
|
58614
58804
|
const form = new FormData();
|
|
58615
58805
|
form.set("meta", JSON.stringify({ ...meta3, replace: !!opts.replace }));
|
|
58616
|
-
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));
|
|
58617
58807
|
for (const f of files) add2("files", f, path75.join(root2, f));
|
|
58618
58808
|
for (const f of opts.preview) add2("previews", path75.basename(f), f);
|
|
58619
58809
|
for (const f of opts.evidence) add2("evidence", path75.basename(f), f);
|
|
@@ -58641,10 +58831,10 @@ Deleted ${name} from the catalog.`);
|
|
|
58641
58831
|
}
|
|
58642
58832
|
async function templateShowcase(name, dir) {
|
|
58643
58833
|
const file2 = path75.join(dir, "showcase.json");
|
|
58644
|
-
if (!
|
|
58834
|
+
if (!fs75.existsSync(file2)) invalid2(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
|
|
58645
58835
|
let meta3;
|
|
58646
58836
|
try {
|
|
58647
|
-
meta3 = JSON.parse(
|
|
58837
|
+
meta3 = JSON.parse(fs75.readFileSync(file2, "utf8"));
|
|
58648
58838
|
} catch {
|
|
58649
58839
|
return invalid2("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
|
|
58650
58840
|
}
|
|
@@ -58657,8 +58847,8 @@ async function templateShowcase(name, dir) {
|
|
|
58657
58847
|
form.set("meta", JSON.stringify(meta3));
|
|
58658
58848
|
for (const p of new Set(named2)) {
|
|
58659
58849
|
const at = path75.join(dir, p);
|
|
58660
|
-
if (!
|
|
58661
|
-
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);
|
|
58662
58852
|
}
|
|
58663
58853
|
const done = requireResponse(
|
|
58664
58854
|
await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form })),
|
|
@@ -58671,7 +58861,7 @@ Updated ${name}'s showcase: ${done.files} files.`);
|
|
|
58671
58861
|
}
|
|
58672
58862
|
function walk2(root2, sub = "") {
|
|
58673
58863
|
const out = [];
|
|
58674
|
-
for (const entry of
|
|
58864
|
+
for (const entry of fs75.readdirSync(path75.join(root2, sub), { withFileTypes: true })) {
|
|
58675
58865
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
58676
58866
|
const rel3 = sub ? `${sub}/${entry.name}` : entry.name;
|
|
58677
58867
|
if (entry.isDirectory()) out.push(...walk2(root2, rel3));
|
|
@@ -63162,7 +63352,7 @@ var init_guide2 = __esm({
|
|
|
63162
63352
|
|
|
63163
63353
|
// src/commands/studio.ts
|
|
63164
63354
|
import crypto7 from "node:crypto";
|
|
63165
|
-
import
|
|
63355
|
+
import fs76 from "node:fs";
|
|
63166
63356
|
import path76 from "node:path";
|
|
63167
63357
|
function cmdStudioList() {
|
|
63168
63358
|
if (!studiosReachable().ok) die(NEEDS_CLOUD, "needs-cloud");
|
|
@@ -63181,7 +63371,7 @@ function cmdStudioDiagram(_id, _card, _folder) {
|
|
|
63181
63371
|
}
|
|
63182
63372
|
function cmdStudioValidate(folder2) {
|
|
63183
63373
|
const dir = path76.resolve(folder2);
|
|
63184
|
-
if (!
|
|
63374
|
+
if (!fs76.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) die(`${folder2} is not a folder`, "bad-args");
|
|
63185
63375
|
const files = readStudioFolder(dir);
|
|
63186
63376
|
let builtin = false;
|
|
63187
63377
|
try {
|
|
@@ -63203,7 +63393,7 @@ async function cmdStudioPull(id2, folder2) {
|
|
|
63203
63393
|
found(id2);
|
|
63204
63394
|
}
|
|
63205
63395
|
const dir = path76.resolve(folder2 ?? id2);
|
|
63206
|
-
if (
|
|
63396
|
+
if (fs76.existsSync(dir) && fs76.readdirSync(dir).length) die(`${folder2 ?? id2} is not empty`, "bad-args");
|
|
63207
63397
|
const read5 = await call("GET", `/v1/studios/${encodeURIComponent(cloudId)}`);
|
|
63208
63398
|
const { version: version2, files } = requireResponse(
|
|
63209
63399
|
cloudOk(read5, read5.ok || read5.code !== "not_found" ? void 0 : "no-such-studio"),
|
|
@@ -63212,9 +63402,9 @@ async function cmdStudioPull(id2, folder2) {
|
|
|
63212
63402
|
);
|
|
63213
63403
|
for (const [file2, text5] of Object.entries({ ...files, [VERSION_FILE]: versionText(cloudId, version2) })) {
|
|
63214
63404
|
const full = path76.join(dir, ...file2.split("/"));
|
|
63215
|
-
|
|
63405
|
+
fs76.mkdirSync(path76.dirname(full), { recursive: true });
|
|
63216
63406
|
const data = isAboutFile(file2) && !file2.endsWith(".md") && /^data:[^;]+;base64,/.exec(text5);
|
|
63217
|
-
|
|
63407
|
+
fs76.writeFileSync(full, data ? Buffer.from(text5.slice(data[0].length), "base64") : text5);
|
|
63218
63408
|
}
|
|
63219
63409
|
const shown = folder2 ?? `./${id2}`;
|
|
63220
63410
|
say(`Pulled ${id2} v${version2} into ${shown}.`);
|
|
@@ -63230,13 +63420,13 @@ async function publishFolder(dir, route2, body, requestId) {
|
|
|
63230
63420
|
const hash3 = crypto7.createHash("sha256").update(JSON.stringify({ route: route2, files: body.files, workspace: body.workspace })).digest("hex");
|
|
63231
63421
|
let held4;
|
|
63232
63422
|
try {
|
|
63233
|
-
held4 = JSON.parse(
|
|
63423
|
+
held4 = JSON.parse(fs76.readFileSync(pendingFile, "utf8"));
|
|
63234
63424
|
} catch {
|
|
63235
63425
|
}
|
|
63236
63426
|
if (requestId && held4?.requestId === requestId && held4.hash !== hash3) die("This request ID already names different files; use a new request ID.", "bad-args");
|
|
63237
63427
|
const replay = held4?.hash === hash3 && held4.route === route2 && (!requestId || held4.requestId === requestId) && (body.expectedVersion === held4.body.expectedVersion || body.expectedVersion === held4.resultVersion);
|
|
63238
63428
|
const pending = replay ? held4 : { requestId: requestId ?? crypto7.randomUUID(), hash: hash3, body, route: route2 };
|
|
63239
|
-
|
|
63429
|
+
fs76.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
63240
63430
|
const res = await call(route2 === "/v1/studios" ? "POST" : "PATCH", route2, pending.body, pending.requestId);
|
|
63241
63431
|
const { id: id2, version: version2 } = requireResponse(
|
|
63242
63432
|
cloudOk(res, !res.ok && ["version_conflict", "conflict"].includes(res.code ?? "") ? "studio-moved" : void 0),
|
|
@@ -63244,8 +63434,8 @@ async function publishFolder(dir, route2, body, requestId) {
|
|
|
63244
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)
|
|
63245
63435
|
);
|
|
63246
63436
|
pending.resultVersion = version2;
|
|
63247
|
-
|
|
63248
|
-
|
|
63437
|
+
fs76.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
63438
|
+
fs76.writeFileSync(path76.join(dir, VERSION_FILE), versionText(id2, version2));
|
|
63249
63439
|
say(`Saved ${studioName(id2)} v${version2}. New tasks take it.`);
|
|
63250
63440
|
return { id: id2, version: version2, changed: true, requestId: pending.requestId };
|
|
63251
63441
|
}
|
|
@@ -63260,14 +63450,14 @@ async function cmdStudioPush(folder2, opts) {
|
|
|
63260
63450
|
const dir = path76.resolve(folder2);
|
|
63261
63451
|
let pulled = null;
|
|
63262
63452
|
try {
|
|
63263
|
-
pulled = JSON.parse(
|
|
63453
|
+
pulled = JSON.parse(fs76.readFileSync(path76.join(dir, VERSION_FILE), "utf8"));
|
|
63264
63454
|
} catch {
|
|
63265
63455
|
}
|
|
63266
63456
|
if (!pulled?.id || !Number.isInteger(pulled.version) || pulled.version < 1) die(`${folder2} has no valid version.json; pull again.`, "bad-args");
|
|
63267
63457
|
const { id: id2, version: version2 } = pulled;
|
|
63268
63458
|
if (id2.startsWith("wf_builtin_")) die("Copy this studio before editing it.", "studio-read-only");
|
|
63269
63459
|
const files = publicationFiles(dir);
|
|
63270
|
-
if (!
|
|
63460
|
+
if (!fs76.existsSync(path76.join(dir, ".publication.json")) && !opts.requestId) {
|
|
63271
63461
|
const now = await call("GET", `/v1/studios/${encodeURIComponent(id2)}`);
|
|
63272
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()))) {
|
|
63273
63463
|
say(`${studioName(id2)} is unchanged (v${version2}).`);
|
|
@@ -63290,7 +63480,7 @@ function noteText({ file: file2, text: text5 }) {
|
|
|
63290
63480
|
if (file2 !== void 0 && text5 !== void 0) die("pass --file or --text, not both", "bad-args");
|
|
63291
63481
|
if (file2 !== void 0) {
|
|
63292
63482
|
try {
|
|
63293
|
-
return
|
|
63483
|
+
return fs76.readFileSync(file2, "utf8").trim();
|
|
63294
63484
|
} catch {
|
|
63295
63485
|
die(`can't read ${file2}`, "bad-args");
|
|
63296
63486
|
}
|
|
@@ -63476,7 +63666,7 @@ var init_progress = __esm({
|
|
|
63476
63666
|
});
|
|
63477
63667
|
|
|
63478
63668
|
// src/lib/agent/complete.ts
|
|
63479
|
-
import
|
|
63669
|
+
import fs77 from "node:fs";
|
|
63480
63670
|
function checkRecordedResult(receipt, commit, branch) {
|
|
63481
63671
|
if (receipt.commit === commit && receipt.branch === branch) return;
|
|
63482
63672
|
const describe4 = (hash3, target) => hash3 ? `${hash3} on ${target}` : "no Git result";
|
|
@@ -63504,7 +63694,7 @@ function completeDelivery(named2, result = {}) {
|
|
|
63504
63694
|
const run3 = store.runs.find((r) => r.sessionId === sessionId);
|
|
63505
63695
|
const current = store.runs.filter((r) => r.deliveryId === delivery2.deliveryId && ["implement", "scheduled"].includes(r.action)).pop();
|
|
63506
63696
|
const liveCard = delivery2.cardId === null ? null : cardFile(delivery2.cardId);
|
|
63507
|
-
const restored = liveCard && parseFrontmatter(
|
|
63697
|
+
const restored = liveCard && parseFrontmatter(fs77.readFileSync(liveCard, "utf8")).meta?.restored;
|
|
63508
63698
|
if (restored && Date.parse(restored) > (run3?.startedAt ?? 0)) throw new Error("This delivery predates task restoration.");
|
|
63509
63699
|
if (!run3 || run3.deliveryId !== delivery2.deliveryId) throw new Error("This run does not own the delivery.");
|
|
63510
63700
|
const pending = receipts[deliveryStep(delivery2)];
|
|
@@ -63612,7 +63802,7 @@ function startSubRun(parentId, prompt, runtime) {
|
|
|
63612
63802
|
const parent = peekRun(parentId);
|
|
63613
63803
|
if (!parent || parent.status !== "running") return refusal("runNotFound", `run ${parentId.slice(0, 8)} is not running here`, { id: parentId });
|
|
63614
63804
|
if (parent.action === "sub") return refusal("subRunNested", "a sub-run cannot start sub-runs of its own");
|
|
63615
|
-
const inherited = parent.runtime &&
|
|
63805
|
+
const inherited = parent.runtime && runRuntimeById(parent.runtime) ? parent.runtime : void 0;
|
|
63616
63806
|
return open3(
|
|
63617
63807
|
{
|
|
63618
63808
|
action: "sub",
|
|
@@ -63675,7 +63865,7 @@ var init_start = __esm({
|
|
|
63675
63865
|
});
|
|
63676
63866
|
|
|
63677
63867
|
// src/lib/agent/task-chats.ts
|
|
63678
|
-
import
|
|
63868
|
+
import fs78 from "node:fs";
|
|
63679
63869
|
import path77 from "node:path";
|
|
63680
63870
|
function taskChatFile(task, home3) {
|
|
63681
63871
|
if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
|
|
@@ -63684,7 +63874,7 @@ function taskChatFile(task, home3) {
|
|
|
63684
63874
|
function readTaskChat(task, home3) {
|
|
63685
63875
|
let text5;
|
|
63686
63876
|
try {
|
|
63687
|
-
text5 =
|
|
63877
|
+
text5 = fs78.readFileSync(taskChatFile(task, home3), "utf8");
|
|
63688
63878
|
} catch {
|
|
63689
63879
|
return [];
|
|
63690
63880
|
}
|
|
@@ -63710,7 +63900,7 @@ var init_task_chats = __esm({
|
|
|
63710
63900
|
});
|
|
63711
63901
|
|
|
63712
63902
|
// src/lib/agent/memory-review.ts
|
|
63713
|
-
import
|
|
63903
|
+
import fs79 from "node:fs";
|
|
63714
63904
|
import path78 from "node:path";
|
|
63715
63905
|
function taskChatsToReview(tasks) {
|
|
63716
63906
|
const out = [];
|
|
@@ -63734,7 +63924,7 @@ function readArchived2(id2) {
|
|
|
63734
63924
|
if (!found2) return null;
|
|
63735
63925
|
try {
|
|
63736
63926
|
const file2 = found2.kind === "group" ? path78.join(found2.target, "root.md") : found2.target;
|
|
63737
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
63927
|
+
const { meta: meta3, body } = parseFrontmatter(fs79.readFileSync(file2, "utf8"));
|
|
63738
63928
|
if (!meta3) return null;
|
|
63739
63929
|
return { id: id2, title: meta3.title, modules: meta3.modules ?? [], studio: meta3.studio ?? "", previews: meta3.previews ?? [], rejected: meta3.rejected, body };
|
|
63740
63930
|
} catch {
|
|
@@ -63795,18 +63985,18 @@ var init_memory_review = __esm({
|
|
|
63795
63985
|
});
|
|
63796
63986
|
|
|
63797
63987
|
// src/lib/agent/dismissal-review.ts
|
|
63798
|
-
import
|
|
63988
|
+
import fs80 from "node:fs";
|
|
63799
63989
|
import path79 from "node:path";
|
|
63800
63990
|
function rejectionsToReview() {
|
|
63801
63991
|
const scratch = process.env.AI4KANBAN_REJECTION_INPUT;
|
|
63802
63992
|
const dir = path79.join(scratch ? path79.join(scratch, ".archive") : ARCHIVE, REJECTIONS_TO_REVIEW);
|
|
63803
|
-
if (!
|
|
63993
|
+
if (!fs80.existsSync(dir)) return [];
|
|
63804
63994
|
const found2 = [];
|
|
63805
63995
|
for (const file2 of walkMd(dir)) {
|
|
63806
63996
|
const id2 = archivedId(file2);
|
|
63807
63997
|
if (id2 === null) continue;
|
|
63808
63998
|
try {
|
|
63809
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
63999
|
+
const { meta: meta3 } = parseFrontmatter(fs80.readFileSync(file2, "utf8"));
|
|
63810
64000
|
if (!meta3?.rejected || meta3.rejected_by !== "user" || !meta3.rejected_reason.trim()) continue;
|
|
63811
64001
|
found2.push({ id: id2, title: meta3.title, file: rel(file2), reason: meta3.rejected_reason.trim(), rejectedAt: meta3.rejected_at });
|
|
63812
64002
|
} catch {
|
|
@@ -63828,7 +64018,7 @@ function citedSources(text5) {
|
|
|
63828
64018
|
const ids = /* @__PURE__ */ new Set();
|
|
63829
64019
|
for (const line of text5.split("\n")) {
|
|
63830
64020
|
if (!/^\s*[-*]\s/.test(line)) continue;
|
|
63831
|
-
const m = line.match(
|
|
64021
|
+
const m = line.match(SOURCES2);
|
|
63832
64022
|
for (const id2 of m?.[1].split(",") ?? []) if (id2.trim()) ids.add(id2.trim());
|
|
63833
64023
|
}
|
|
63834
64024
|
return [...ids];
|
|
@@ -63836,7 +64026,7 @@ function citedSources(text5) {
|
|
|
63836
64026
|
function withdrawnSources() {
|
|
63837
64027
|
const cited = [...new Set(plannerCopies("rejected.md").flatMap((file2) => {
|
|
63838
64028
|
try {
|
|
63839
|
-
return citedSources(
|
|
64029
|
+
return citedSources(fs80.readFileSync(file2, "utf8"));
|
|
63840
64030
|
} catch {
|
|
63841
64031
|
return [];
|
|
63842
64032
|
}
|
|
@@ -63847,7 +64037,7 @@ function withdrawnSources() {
|
|
|
63847
64037
|
const restored = new Set([...readInbox(), ...readArchived(scratch ? path79.join(scratch, "triage", "archived") : void 0)].map((s) => s.sourceId));
|
|
63848
64038
|
return cited.filter((id2) => restored.has(id2) && !dismissed.has(id2));
|
|
63849
64039
|
}
|
|
63850
|
-
var reviewDismissed,
|
|
64040
|
+
var reviewDismissed, SOURCES2;
|
|
63851
64041
|
var init_dismissal_review = __esm({
|
|
63852
64042
|
"src/lib/agent/dismissal-review.ts"() {
|
|
63853
64043
|
"use strict";
|
|
@@ -63861,12 +64051,12 @@ var init_dismissal_review = __esm({
|
|
|
63861
64051
|
const scratch = process.env.AI4KANBAN_REJECTION_INPUT;
|
|
63862
64052
|
return readAllDismissed(scratch ? path79.join(scratch, "triage", "dismissed") : void 0);
|
|
63863
64053
|
};
|
|
63864
|
-
|
|
64054
|
+
SOURCES2 = /\(([^()]+)\)\s*$/;
|
|
63865
64055
|
}
|
|
63866
64056
|
});
|
|
63867
64057
|
|
|
63868
64058
|
// src/lib/agent/flow.ts
|
|
63869
|
-
import
|
|
64059
|
+
import fs81 from "node:fs";
|
|
63870
64060
|
import path80 from "node:path";
|
|
63871
64061
|
function readCard2(id2, home3 = "board") {
|
|
63872
64062
|
const pending = activeDelivery(id2)?.completions?.some((c) => !c.finished);
|
|
@@ -63880,7 +64070,7 @@ function readCard2(id2, home3 = "board") {
|
|
|
63880
64070
|
const file2 = found2.kind === "group" ? path80.join(found2.target, "root.md") : found2.target;
|
|
63881
64071
|
let text5;
|
|
63882
64072
|
try {
|
|
63883
|
-
text5 =
|
|
64073
|
+
text5 = fs81.readFileSync(file2, "utf8");
|
|
63884
64074
|
} catch {
|
|
63885
64075
|
die(`#${id2} is on the board but ${rel(file2)} can't be read.`, { kind: "card-unreadable", id: id2 });
|
|
63886
64076
|
}
|
|
@@ -64725,7 +64915,7 @@ __export(watch_exports, {
|
|
|
64725
64915
|
watchRun: () => watchRun
|
|
64726
64916
|
});
|
|
64727
64917
|
import { spawn as spawn3 } from "node:child_process";
|
|
64728
|
-
import
|
|
64918
|
+
import fs82 from "node:fs";
|
|
64729
64919
|
async function watchRun(sessionId, resume = startResume, retryBackoff = backoffMs) {
|
|
64730
64920
|
const spec = readSpec(sessionId);
|
|
64731
64921
|
const run3 = peekRun(sessionId);
|
|
@@ -64761,20 +64951,24 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64761
64951
|
const record2 = claimed ?? run3;
|
|
64762
64952
|
const sub = record2.action === "sub";
|
|
64763
64953
|
if (claim2) await setCardStatus(claim2.cardId, claim2.status);
|
|
64764
|
-
|
|
64765
|
-
const logFile =
|
|
64954
|
+
fs82.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
64955
|
+
const logFile = fs82.createWriteStream(record2.logPath, { flags: "a" });
|
|
64766
64956
|
logFile.on("error", () => {
|
|
64767
64957
|
});
|
|
64768
|
-
const eventsFile =
|
|
64958
|
+
const eventsFile = fs82.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
|
|
64769
64959
|
eventsFile.on("error", () => {
|
|
64770
64960
|
});
|
|
64771
64961
|
let observeActivity = (_e) => {
|
|
64772
64962
|
};
|
|
64773
64963
|
const pendingOperations = /* @__PURE__ */ new Set();
|
|
64964
|
+
let hadEffects = false;
|
|
64774
64965
|
const event2 = (e) => {
|
|
64775
64966
|
observeActivity(e);
|
|
64776
64967
|
const hadPending = pendingOperations.size > 0;
|
|
64777
|
-
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
|
+
}
|
|
64778
64972
|
if ((e.kind === "tool_call" || e.kind === "tool_call_update") && ["completed", "failed"].includes(e.data.status ?? "")) pendingOperations.delete(e.data.toolCallId);
|
|
64779
64973
|
if (record2.cloudExecution && hadPending !== pendingOperations.size > 0) {
|
|
64780
64974
|
patch(sessionId, (run4) => {
|
|
@@ -64784,6 +64978,11 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64784
64978
|
eventsFile.write(`${JSON.stringify(e)}
|
|
64785
64979
|
`);
|
|
64786
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
|
+
});
|
|
64787
64986
|
const log = {
|
|
64788
64987
|
write(text5) {
|
|
64789
64988
|
logFile.write(text5);
|
|
@@ -64818,7 +65017,8 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64818
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.`,
|
|
64819
65018
|
...coding && !approvedUi && review?.plan?.some((node2) => node2.previews.includes("ui-design")) ? [APPROVED_UI_RULE] : []
|
|
64820
65019
|
].join("\n") : "";
|
|
64821
|
-
const
|
|
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");
|
|
64822
65022
|
const before = markBoard();
|
|
64823
65023
|
const takes = active3.images;
|
|
64824
65024
|
active3.renderer?.setRequiredImages?.(record2.pictures ?? []);
|
|
@@ -64846,11 +65046,29 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64846
65046
|
letGo();
|
|
64847
65047
|
return 1;
|
|
64848
65048
|
}
|
|
64849
|
-
if (record2.retry?.launching)
|
|
64850
|
-
|
|
64851
|
-
r
|
|
64852
|
-
|
|
64853
|
-
|
|
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
|
+
}
|
|
64854
65072
|
try {
|
|
64855
65073
|
const start = spawnable(cmd, client || stdinPrompt ? args2 : [...args2, prompt], {
|
|
64856
65074
|
// Where this run works: the project, or — inside a delivery with a worktree of its
|
|
@@ -65034,34 +65252,79 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
65034
65252
|
const rendered = renderer?.failure?.() ?? (!taskCompleted && renderer?.background?.() ? "The agent exited with unfinished background tasks." : void 0);
|
|
65035
65253
|
const said2 = spawnError ?? (silent ? silenceSaid(silenceFor) : spoken?.error ?? rendered);
|
|
65036
65254
|
const failed2 = code !== 0 || spoken?.ok === false || !!rendered || silent || !!blocker;
|
|
65037
|
-
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;
|
|
65038
65259
|
const result = spoken ? spoken.result : renderer?.result();
|
|
65039
65260
|
let retryPause;
|
|
65040
65261
|
let retrying = false;
|
|
65262
|
+
let retryHistory = held4.retryHistory ? [...held4.retryHistory] : void 0;
|
|
65263
|
+
let sessionAction;
|
|
65041
65264
|
if (failure2 && !sub && !taskCompleted) {
|
|
65042
65265
|
const attempt2 = held4.retry?.attempt ?? 1;
|
|
65043
|
-
const
|
|
65044
|
-
|
|
65045
|
-
|
|
65046
|
-
|
|
65047
|
-
|
|
65048
|
-
|
|
65049
|
-
|
|
65050
|
-
|
|
65051
|
-
|
|
65052
|
-
|
|
65053
|
-
|
|
65054
|
-
|
|
65055
|
-
|
|
65056
|
-
|
|
65057
|
-
|
|
65058
|
-
|
|
65059
|
-
|
|
65060
|
-
|
|
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 };
|
|
65061
65303
|
patch(sessionId, (r) => {
|
|
65062
65304
|
r.failure = failure2;
|
|
65063
|
-
r.error = said2 ?? failure2.
|
|
65064
|
-
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
|
+
}
|
|
65065
65328
|
});
|
|
65066
65329
|
log.write(`
|
|
65067
65330
|
[board] ${retryLine(pending, attempt2)}
|
|
@@ -65070,11 +65333,44 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
65070
65333
|
retrying = true;
|
|
65071
65334
|
}
|
|
65072
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
|
+
}
|
|
65073
65353
|
}
|
|
65074
65354
|
asked ||= stoppedByUser();
|
|
65075
65355
|
retrying &&= !asked;
|
|
65076
|
-
const error62 = asked ? void 0 : joinNotes(said2 ?? failure2?.
|
|
65356
|
+
const error62 = asked ? void 0 : joinNotes(said2 ?? failure2?.summary, retryPause ? pauseLine(retryPause) : void 0);
|
|
65077
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
|
+
}
|
|
65078
65374
|
const reported = spoken ? spoken.costUsd : renderer?.costUsd?.();
|
|
65079
65375
|
const totals = reportsSessionTotal(record2.harness);
|
|
65080
65376
|
const sessionTotal = totals ? reported : void 0;
|
|
@@ -65137,6 +65433,7 @@ ${result}
|
|
|
65137
65433
|
error: error62,
|
|
65138
65434
|
failure: failure2,
|
|
65139
65435
|
retryPause,
|
|
65436
|
+
retryHistory,
|
|
65140
65437
|
note,
|
|
65141
65438
|
errorWhy,
|
|
65142
65439
|
noteWhy,
|
|
@@ -65329,6 +65626,7 @@ var init_watch = __esm({
|
|
|
65329
65626
|
init_idle();
|
|
65330
65627
|
init_codex_background_types();
|
|
65331
65628
|
init_retry();
|
|
65629
|
+
init_runtimes();
|
|
65332
65630
|
init_failures();
|
|
65333
65631
|
init_execution();
|
|
65334
65632
|
init_refine2();
|
|
@@ -65343,7 +65641,7 @@ var init_watch = __esm({
|
|
|
65343
65641
|
});
|
|
65344
65642
|
|
|
65345
65643
|
// src/commands/run.ts
|
|
65346
|
-
import
|
|
65644
|
+
import fs83 from "node:fs";
|
|
65347
65645
|
import path82 from "node:path";
|
|
65348
65646
|
async function cmdStartRun(action, args2, opts, program2 = "akb") {
|
|
65349
65647
|
const { req, follow: follow2, print } = readRequest(action, args2, opts);
|
|
@@ -65570,7 +65868,7 @@ async function cmdSubStart(words, opts) {
|
|
|
65570
65868
|
let prompt = words.join(" ");
|
|
65571
65869
|
if (opts.file) {
|
|
65572
65870
|
try {
|
|
65573
|
-
prompt =
|
|
65871
|
+
prompt = fs83.readFileSync(path82.resolve(opts.file), "utf8");
|
|
65574
65872
|
} catch {
|
|
65575
65873
|
die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
|
|
65576
65874
|
}
|
|
@@ -65919,12 +66217,12 @@ var init_config3 = __esm({
|
|
|
65919
66217
|
});
|
|
65920
66218
|
|
|
65921
66219
|
// src/lib/signals/migrate.ts
|
|
65922
|
-
import
|
|
66220
|
+
import fs84 from "node:fs";
|
|
65923
66221
|
import path83 from "node:path";
|
|
65924
66222
|
function readHandled() {
|
|
65925
66223
|
let text5;
|
|
65926
66224
|
try {
|
|
65927
|
-
text5 =
|
|
66225
|
+
text5 = fs84.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
|
|
65928
66226
|
} catch {
|
|
65929
66227
|
return [];
|
|
65930
66228
|
}
|
|
@@ -65941,45 +66239,45 @@ function readHandled() {
|
|
|
65941
66239
|
return held4;
|
|
65942
66240
|
}
|
|
65943
66241
|
function lift(from, into) {
|
|
65944
|
-
|
|
65945
|
-
|
|
66242
|
+
fs84.mkdirSync(into, { recursive: true });
|
|
66243
|
+
fs84.renameSync(from, path83.join(into, freeName(into, path83.basename(from))));
|
|
65946
66244
|
}
|
|
65947
66245
|
function repoint(dir, from, into) {
|
|
65948
66246
|
let entries2;
|
|
65949
66247
|
try {
|
|
65950
|
-
entries2 =
|
|
66248
|
+
entries2 = fs84.readdirSync(dir, { withFileTypes: true });
|
|
65951
66249
|
} catch {
|
|
65952
66250
|
return;
|
|
65953
66251
|
}
|
|
65954
66252
|
for (const entry of entries2) {
|
|
65955
66253
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
65956
66254
|
const file2 = path83.join(dir, entry.name);
|
|
65957
|
-
const text5 =
|
|
65958
|
-
if (text5.includes(from))
|
|
66255
|
+
const text5 = fs84.readFileSync(file2, "utf8");
|
|
66256
|
+
if (text5.includes(from)) fs84.writeFileSync(file2, text5.split(from).join(into));
|
|
65959
66257
|
}
|
|
65960
66258
|
}
|
|
65961
66259
|
function dropIfEmpty(dir) {
|
|
65962
66260
|
try {
|
|
65963
|
-
|
|
66261
|
+
fs84.rmdirSync(dir);
|
|
65964
66262
|
} catch {
|
|
65965
66263
|
}
|
|
65966
66264
|
}
|
|
65967
66265
|
function liftInbox() {
|
|
65968
|
-
if (!
|
|
66266
|
+
if (!fs84.existsSync(SIGNALS_OLD_INBOX)) return;
|
|
65969
66267
|
const oldFiles = path83.join(SIGNALS_OLD_INBOX, "files");
|
|
65970
|
-
if (
|
|
65971
|
-
for (const entry of
|
|
66268
|
+
if (fs84.existsSync(oldFiles)) {
|
|
66269
|
+
for (const entry of fs84.readdirSync(oldFiles, { withFileTypes: true })) {
|
|
65972
66270
|
if (entry.isFile()) lift(path83.join(oldFiles, entry.name), SIGNALS_FILES);
|
|
65973
66271
|
}
|
|
65974
66272
|
dropIfEmpty(oldFiles);
|
|
65975
66273
|
}
|
|
65976
66274
|
const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
|
|
65977
|
-
for (const entry of
|
|
66275
|
+
for (const entry of fs84.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
|
|
65978
66276
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
65979
66277
|
const from = path83.join(SIGNALS_OLD_INBOX, entry.name);
|
|
65980
66278
|
const item = parse3(from);
|
|
65981
66279
|
if (item && held4.has(item.sourceId)) {
|
|
65982
|
-
|
|
66280
|
+
fs84.rmSync(from, { force: true });
|
|
65983
66281
|
continue;
|
|
65984
66282
|
}
|
|
65985
66283
|
if (item) held4.add(item.sourceId);
|
|
@@ -65991,7 +66289,7 @@ function liftInbox() {
|
|
|
65991
66289
|
dropIfEmpty(SIGNALS_OLD_INBOX);
|
|
65992
66290
|
}
|
|
65993
66291
|
function liftHandled() {
|
|
65994
|
-
if (!
|
|
66292
|
+
if (!fs84.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
65995
66293
|
const lines = readHandled();
|
|
65996
66294
|
const held4 = /* @__PURE__ */ new Set([
|
|
65997
66295
|
...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
|
|
@@ -66001,7 +66299,7 @@ function liftHandled() {
|
|
|
66001
66299
|
for (const { sourceId, when } of lines) {
|
|
66002
66300
|
if (held4.has(sourceId)) continue;
|
|
66003
66301
|
held4.add(sourceId);
|
|
66004
|
-
|
|
66302
|
+
fs84.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
|
|
66005
66303
|
const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
|
|
66006
66304
|
const front = [
|
|
66007
66305
|
"---",
|
|
@@ -66011,13 +66309,13 @@ function liftHandled() {
|
|
|
66011
66309
|
"---",
|
|
66012
66310
|
""
|
|
66013
66311
|
];
|
|
66014
|
-
|
|
66312
|
+
fs84.writeFileSync(path83.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
|
|
66015
66313
|
`);
|
|
66016
66314
|
}
|
|
66017
|
-
|
|
66315
|
+
fs84.rmSync(SIGNALS_OLD_HANDLED, { force: true });
|
|
66018
66316
|
}
|
|
66019
66317
|
function migrateTriage() {
|
|
66020
|
-
if (!
|
|
66318
|
+
if (!fs84.existsSync(SIGNALS_OLD_INBOX) && !fs84.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
66021
66319
|
try {
|
|
66022
66320
|
liftInbox();
|
|
66023
66321
|
liftHandled();
|
|
@@ -66085,7 +66383,7 @@ var init_identity2 = __esm({
|
|
|
66085
66383
|
});
|
|
66086
66384
|
|
|
66087
66385
|
// src/lib/signals/add.ts
|
|
66088
|
-
import
|
|
66386
|
+
import fs85 from "node:fs";
|
|
66089
66387
|
import path84 from "node:path";
|
|
66090
66388
|
import { createHash as createHash8 } from "node:crypto";
|
|
66091
66389
|
function linkTitle(url2) {
|
|
@@ -66144,8 +66442,8 @@ ${incoming.summary}`);
|
|
|
66144
66442
|
if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
|
|
66145
66443
|
try {
|
|
66146
66444
|
if (keep2) {
|
|
66147
|
-
|
|
66148
|
-
|
|
66445
|
+
fs85.mkdirSync(SIGNALS_FILES, { recursive: true });
|
|
66446
|
+
fs85.writeFileSync(keep2.at, keep2.data);
|
|
66149
66447
|
}
|
|
66150
66448
|
return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
|
|
66151
66449
|
} catch (e) {
|
|
@@ -66256,7 +66554,7 @@ var init_signals = __esm({
|
|
|
66256
66554
|
});
|
|
66257
66555
|
|
|
66258
66556
|
// src/commands/triage.ts
|
|
66259
|
-
import
|
|
66557
|
+
import fs86 from "node:fs";
|
|
66260
66558
|
async function cmdTriageAdd(opts) {
|
|
66261
66559
|
const title = (opts.title ?? "").trim();
|
|
66262
66560
|
if (!title) die('say what it is: --title "<one line>"', { kind: "needs-input" });
|
|
@@ -66266,7 +66564,7 @@ async function cmdTriageAdd(opts) {
|
|
|
66266
66564
|
let body = opts.text;
|
|
66267
66565
|
if (opts.file !== void 0) {
|
|
66268
66566
|
try {
|
|
66269
|
-
body =
|
|
66567
|
+
body = fs86.readFileSync(opts.file, "utf8");
|
|
66270
66568
|
} catch {
|
|
66271
66569
|
die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
|
|
66272
66570
|
}
|
|
@@ -66320,21 +66618,21 @@ var init_previews = __esm({
|
|
|
66320
66618
|
});
|
|
66321
66619
|
|
|
66322
66620
|
// src/commands/studio-preview.ts
|
|
66323
|
-
import
|
|
66621
|
+
import fs87 from "node:fs";
|
|
66324
66622
|
import path85 from "node:path";
|
|
66325
66623
|
import { createHash as createHash9, randomUUID as randomUUID9 } from "node:crypto";
|
|
66326
66624
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
66327
66625
|
function readFolder2(folder2, baseline = false) {
|
|
66328
|
-
const root2 =
|
|
66626
|
+
const root2 = fs87.realpathSync(folder2);
|
|
66329
66627
|
let count3 = 0, total = 0;
|
|
66330
66628
|
const scan = (dir) => {
|
|
66331
|
-
for (const e of
|
|
66629
|
+
for (const e of fs87.readdirSync(dir, { withFileTypes: true })) {
|
|
66332
66630
|
if (e.name.startsWith(".")) continue;
|
|
66333
66631
|
const file2 = path85.join(dir, e.name);
|
|
66334
66632
|
if (e.isSymbolicLink()) throw Error(`${file2}: symbolic links are not allowed`);
|
|
66335
66633
|
if (e.isDirectory()) scan(file2);
|
|
66336
66634
|
else {
|
|
66337
|
-
const size =
|
|
66635
|
+
const size = fs87.statSync(file2).size;
|
|
66338
66636
|
total += size;
|
|
66339
66637
|
if (++count3 > FILE_LIMITS.count || size > FILE_LIMITS.file || total > FILE_LIMITS.total) throw Error(`${file2}: Studio file limit exceeded`);
|
|
66340
66638
|
}
|
|
@@ -66348,8 +66646,8 @@ function readFolder2(folder2, baseline = false) {
|
|
|
66348
66646
|
}
|
|
66349
66647
|
function unified(before, after2, file2, folder2) {
|
|
66350
66648
|
const a = path85.join(folder2, "a"), b = path85.join(folder2, "b");
|
|
66351
|
-
|
|
66352
|
-
|
|
66649
|
+
fs87.writeFileSync(a, before ?? "");
|
|
66650
|
+
fs87.writeFileSync(b, after2 ?? "");
|
|
66353
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 });
|
|
66354
66652
|
if (result.error || result.status !== 0 && result.status !== 1) throw Error(`${file2}: ${result.error?.message ?? result.stderr}`);
|
|
66355
66653
|
const lines = result.stdout.split("\n"), start = lines.findIndex((l) => l.startsWith("--- "));
|
|
@@ -66365,12 +66663,12 @@ async function cmdStudioPreview(id2, opts) {
|
|
|
66365
66663
|
const draft = readFolder2(path85.resolve(opts.folder)), base = opts.base === "empty" ? null : readFolder2(path85.resolve(opts.base), true);
|
|
66366
66664
|
const version2 = readVersion2(draft.files), baseVersion = base && readVersion2(base.files);
|
|
66367
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");
|
|
66368
|
-
|
|
66666
|
+
fs87.mkdirSync(staging, { recursive: true });
|
|
66369
66667
|
const review = { version: 2, base: base && baseVersion ? { ...baseVersion, fingerprint: base.fingerprint } : null, fingerprint: draft.fingerprint, files: [] };
|
|
66370
66668
|
const save3 = (file2, bytes2) => {
|
|
66371
66669
|
const target = path85.join(staging, file2);
|
|
66372
|
-
|
|
66373
|
-
|
|
66670
|
+
fs87.mkdirSync(path85.dirname(target), { recursive: true });
|
|
66671
|
+
fs87.writeFileSync(target, bytes2);
|
|
66374
66672
|
return file2;
|
|
66375
66673
|
};
|
|
66376
66674
|
const paths = [.../* @__PURE__ */ new Set([...Object.keys(base?.files ?? {}), ...Object.keys(draft.files)])].filter((p) => p !== VERSION_FILE).sort();
|
|
@@ -66378,16 +66676,16 @@ async function cmdStudioPreview(id2, opts) {
|
|
|
66378
66676
|
const before = base?.files[file2] ?? null, after2 = draft.files[file2] ?? null;
|
|
66379
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)) } : {} });
|
|
66380
66678
|
}
|
|
66381
|
-
for (const p of ["a", "b"])
|
|
66679
|
+
for (const p of ["a", "b"]) fs87.rmSync(path85.join(staging, p), { force: true });
|
|
66382
66680
|
if (!parseReview(review)) throw Error("generated review is invalid");
|
|
66383
66681
|
save3("review.json", JSON.stringify(review, null, 2) + "\n");
|
|
66384
|
-
|
|
66385
|
-
if (
|
|
66386
|
-
|
|
66682
|
+
fs87.mkdirSync(path85.dirname(destination), { recursive: true });
|
|
66683
|
+
if (fs87.existsSync(destination)) {
|
|
66684
|
+
fs87.renameSync(destination, backup);
|
|
66387
66685
|
moved = true;
|
|
66388
66686
|
}
|
|
66389
|
-
|
|
66390
|
-
|
|
66687
|
+
fs87.renameSync(staging, destination);
|
|
66688
|
+
fs87.rmSync(backup, { recursive: true, force: true });
|
|
66391
66689
|
const tag = `<Studio src=".assets/${id2}/studio-review/review.json" />`;
|
|
66392
66690
|
const prefix = `.assets/${id2}/studio-review/`;
|
|
66393
66691
|
const attachments = review.files.filter((f) => f.path !== "STUDIO.md" && f.diff);
|
|
@@ -66401,11 +66699,11 @@ ${items}
|
|
|
66401
66699
|
say([tag, files].filter(Boolean).join("\n\n"));
|
|
66402
66700
|
return { file: path85.join(destination, "review.json"), tag, files };
|
|
66403
66701
|
} catch (error62) {
|
|
66404
|
-
if (moved && !
|
|
66702
|
+
if (moved && !fs87.existsSync(destination)) fs87.renameSync(backup, destination);
|
|
66405
66703
|
if (error62 && typeof error62 === "object" && "kind" in error62) throw error62;
|
|
66406
66704
|
die(error62 instanceof Error ? error62.message : String(error62), "bad-args");
|
|
66407
66705
|
} finally {
|
|
66408
|
-
|
|
66706
|
+
fs87.rmSync(staging, { recursive: true, force: true });
|
|
66409
66707
|
}
|
|
66410
66708
|
}
|
|
66411
66709
|
var readVersion2;
|
|
@@ -66990,14 +67288,14 @@ Review examples
|
|
|
66990
67288
|
});
|
|
66991
67289
|
|
|
66992
67290
|
// src/kanban.ts
|
|
66993
|
-
import
|
|
67291
|
+
import fs90 from "node:fs";
|
|
66994
67292
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
66995
67293
|
|
|
66996
67294
|
// src/lib/cli/akb.ts
|
|
66997
67295
|
init_agent2();
|
|
66998
67296
|
|
|
66999
67297
|
// src/lib/cli/setup.ts
|
|
67000
|
-
import
|
|
67298
|
+
import fs89 from "node:fs";
|
|
67001
67299
|
import path87 from "node:path";
|
|
67002
67300
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
67003
67301
|
|
|
@@ -67006,7 +67304,7 @@ init_board_cli();
|
|
|
67006
67304
|
init_config_template();
|
|
67007
67305
|
init_io();
|
|
67008
67306
|
init_version();
|
|
67009
|
-
import
|
|
67307
|
+
import fs88 from "node:fs";
|
|
67010
67308
|
import path86 from "node:path";
|
|
67011
67309
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
67012
67310
|
var NAME = "wildcrane";
|
|
@@ -67028,7 +67326,7 @@ var Report = class {
|
|
|
67028
67326
|
for (const line of this.notes) say(` ! ${line}`);
|
|
67029
67327
|
}
|
|
67030
67328
|
};
|
|
67031
|
-
var read4 = (file2) =>
|
|
67329
|
+
var read4 = (file2) => fs88.existsSync(file2) ? fs88.readFileSync(file2, "utf8") : null;
|
|
67032
67330
|
async function boardMove(root2, args2, board2) {
|
|
67033
67331
|
const where = board2 ? ["--board", board2] : ["--dir", root2];
|
|
67034
67332
|
const code = await runBoard([...args2, ...where], { program: "akb raw", cwd: root2 });
|
|
@@ -67051,8 +67349,8 @@ async function cmdUpdate2(ctx) {
|
|
|
67051
67349
|
async function repairBoard(root2, report3, named2) {
|
|
67052
67350
|
const legacy = path86.join(root2, "docs", "kanban");
|
|
67053
67351
|
const kept2 = path86.join(root2, ".akb", "kanban");
|
|
67054
|
-
const board2 = named2 ?? (
|
|
67055
|
-
if (!
|
|
67352
|
+
const board2 = named2 ?? (fs88.existsSync(legacy) ? legacy : kept2);
|
|
67353
|
+
if (!fs88.existsSync(board2)) {
|
|
67056
67354
|
report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
|
|
67057
67355
|
return false;
|
|
67058
67356
|
}
|
|
@@ -67128,7 +67426,7 @@ function declareSetup(program2, cli) {
|
|
|
67128
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");
|
|
67129
67427
|
const where = (cmd) => {
|
|
67130
67428
|
const dir = path87.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
|
|
67131
|
-
if (!
|
|
67429
|
+
if (!fs89.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
|
|
67132
67430
|
return dir;
|
|
67133
67431
|
};
|
|
67134
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() {
|
|
@@ -67179,7 +67477,7 @@ function invokedDirectly() {
|
|
|
67179
67477
|
const entry = process.argv[1];
|
|
67180
67478
|
if (!entry) return false;
|
|
67181
67479
|
try {
|
|
67182
|
-
return
|
|
67480
|
+
return fs90.realpathSync(entry) === fs90.realpathSync(SELF2);
|
|
67183
67481
|
} catch {
|
|
67184
67482
|
return false;
|
|
67185
67483
|
}
|