wildcrane 0.11.85 → 0.11.87
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 +833 -526
- 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.87 — 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.87",
|
|
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 });
|
|
24780
24892
|
}
|
|
24781
|
-
if (
|
|
24782
|
-
|
|
24783
|
-
|
|
24784
|
-
|
|
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 });
|
|
24898
|
+
}
|
|
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
|
});
|
|
@@ -27010,6 +27146,7 @@ async function run(io, options, count3) {
|
|
|
27010
27146
|
const execution = randomUUID4();
|
|
27011
27147
|
let host2 = {};
|
|
27012
27148
|
let cleanup = { status: "confirmed", execution, kept: [] };
|
|
27149
|
+
let hostCleanup;
|
|
27013
27150
|
let settlement;
|
|
27014
27151
|
let replySnapshots = /* @__PURE__ */ new Map();
|
|
27015
27152
|
const visible = /* @__PURE__ */ new Set();
|
|
@@ -27062,15 +27199,15 @@ async function run(io, options, count3) {
|
|
|
27062
27199
|
const costUsd = cost === void 0 ? child.costUsd : cost + (child.costUsd ?? 0);
|
|
27063
27200
|
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
27201
|
if (failure2) io.event?.({ kind: "error", data: { text: failure2 } });
|
|
27065
|
-
resolve2({ ok: !failure2, error: failure2, failure: failure2 ? classified ?? { code: "execution_failed",
|
|
27202
|
+
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
27203
|
};
|
|
27067
27204
|
const closed2 = () => {
|
|
27068
27205
|
const reason = "Codex connection closed before all work and results finished.";
|
|
27069
|
-
if (work.work().some((w) => ["running", "unknown"].includes(w.status))) note("Connection lost; managed cleanup is unconfirmed.");
|
|
27070
|
-
end2(reason, { code: "connection_lost",
|
|
27206
|
+
if (hostCleanup !== "confirmed" && work.work().some((w) => ["running", "unknown"].includes(w.status))) note("Connection lost; managed cleanup is unconfirmed.");
|
|
27207
|
+
end2(reason, makeFailure("runtime", reason, { code: "connection_lost", detail: reason }));
|
|
27071
27208
|
};
|
|
27072
27209
|
const inputFailed = (e) => {
|
|
27073
|
-
if (work.work().some((w) => ["running", "unknown"].includes(w.status))) note("Connection input failed; managed cleanup is unconfirmed.");
|
|
27210
|
+
if (hostCleanup !== "confirmed" && work.work().some((w) => ["running", "unknown"].includes(w.status))) note("Connection input failed; managed cleanup is unconfirmed.");
|
|
27074
27211
|
end2(e.message, executionFailure(e));
|
|
27075
27212
|
};
|
|
27076
27213
|
io.stdout.once("close", closed2);
|
|
@@ -27106,7 +27243,7 @@ async function run(io, options, count3) {
|
|
|
27106
27243
|
} catch (error62) {
|
|
27107
27244
|
if (!ended) note(error62 instanceof Error ? error62.message : String(error62));
|
|
27108
27245
|
}
|
|
27109
|
-
if (!ended) end2(IDLE_FAILURE.
|
|
27246
|
+
if (!ended) end2(IDLE_FAILURE.summary, IDLE_FAILURE);
|
|
27110
27247
|
};
|
|
27111
27248
|
io.idleSignal?.addEventListener("abort", idle, { once: true });
|
|
27112
27249
|
const childUpdates = () => {
|
|
@@ -27293,6 +27430,14 @@ async function run(io, options, count3) {
|
|
|
27293
27430
|
return;
|
|
27294
27431
|
}
|
|
27295
27432
|
const p = obj2(msg.params);
|
|
27433
|
+
if (msg.method === "wildcrane/cleanup") {
|
|
27434
|
+
if (p.status === "confirmed") hostCleanup = "confirmed";
|
|
27435
|
+
else if (p.status === "unconfirmed") {
|
|
27436
|
+
hostCleanup = "unconfirmed";
|
|
27437
|
+
note(str2(p.diagnostic) || "Codex cleanup is unconfirmed.");
|
|
27438
|
+
}
|
|
27439
|
+
return;
|
|
27440
|
+
}
|
|
27296
27441
|
const source2 = str2(p.threadId);
|
|
27297
27442
|
if (!work.own(source2)) return;
|
|
27298
27443
|
if (msg.method === "item/commandExecution/terminalInteraction") {
|
|
@@ -27366,10 +27511,24 @@ async function run(io, options, count3) {
|
|
|
27366
27511
|
const failure2 = codexFailure(p.error, "Codex failed.");
|
|
27367
27512
|
if (p.willRetry === true && submitted && active3 && !idling) {
|
|
27368
27513
|
status = "retrying";
|
|
27369
|
-
io.log(`[Codex recovery] ${failure2.code}: ${failure2.
|
|
27514
|
+
io.log(`[Codex recovery] ${failure2.code ?? "error"}: ${failure2.summary}
|
|
27370
27515
|
`);
|
|
27371
27516
|
io.event?.({ kind: "status", data: { state: "retrying", source: "codex", code: failure2.code } });
|
|
27372
|
-
|
|
27517
|
+
io.event?.({
|
|
27518
|
+
kind: "retry",
|
|
27519
|
+
data: {
|
|
27520
|
+
state: "retrying",
|
|
27521
|
+
source: "runtime",
|
|
27522
|
+
runtime: { connector: "codex", name: null, model: model ?? null },
|
|
27523
|
+
attempt: 1,
|
|
27524
|
+
maxAttempts: MAX_RETRY_ATTEMPTS,
|
|
27525
|
+
summary: failure2.summary,
|
|
27526
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
27527
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
27528
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
27529
|
+
}
|
|
27530
|
+
});
|
|
27531
|
+
} else if (p.willRetry !== true) end2(failure2.summary, failure2);
|
|
27373
27532
|
}
|
|
27374
27533
|
if (msg.method === "turn/completed") {
|
|
27375
27534
|
const turn2 = obj2(p.turn);
|
|
@@ -27383,7 +27542,7 @@ async function run(io, options, count3) {
|
|
|
27383
27542
|
if (idling) return;
|
|
27384
27543
|
if (turn2.status !== "completed") {
|
|
27385
27544
|
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",
|
|
27545
|
+
const failure2 = turn2.status === "failed" ? codexFailure(turn2.error, reason) : makeFailure("runtime", reason, { code: "turn_stopped", detail: reason });
|
|
27387
27546
|
end2(reason, failure2);
|
|
27388
27547
|
return;
|
|
27389
27548
|
}
|
|
@@ -27420,11 +27579,15 @@ async function run(io, options, count3) {
|
|
|
27420
27579
|
try {
|
|
27421
27580
|
response = await bounded(rpc.call(method, params), preparingUntil - Date.now(), `Codex ${method} timed out.`);
|
|
27422
27581
|
} catch (error62) {
|
|
27582
|
+
if (mode === "fork" && error62 instanceof RpcError && error62.code === -32600 && error62.message === `no rollout found for thread id ${params.threadId}`) {
|
|
27583
|
+
end2(error62.message, { code: "codex_fork_source_missing", source: "runtime", summary: error62.message, detail: error62.message });
|
|
27584
|
+
return done;
|
|
27585
|
+
}
|
|
27423
27586
|
const failure2 = error62 instanceof RpcError ? codexFailure(error62.data, error62.message) : void 0;
|
|
27424
|
-
if (mode !== "fork" || failure2?.
|
|
27587
|
+
if (mode !== "fork" || failure2?.code !== "codex_source_busy") throw error62;
|
|
27425
27588
|
if (!waiting) {
|
|
27426
27589
|
waiting = true;
|
|
27427
|
-
io.event?.({ kind: "log", data: { text: failure2.
|
|
27590
|
+
io.event?.({ kind: "log", data: { text: failure2.summary } });
|
|
27428
27591
|
}
|
|
27429
27592
|
io.activity?.();
|
|
27430
27593
|
await delay(500, void 0, { signal: io.signal });
|
|
@@ -27450,7 +27613,7 @@ async function run(io, options, count3) {
|
|
|
27450
27613
|
await start(io.prompt, options.images);
|
|
27451
27614
|
} catch (e) {
|
|
27452
27615
|
const failure2 = e instanceof RpcError ? codexFailure(e.data, e.message) : executionFailure(e);
|
|
27453
|
-
end2(failure2.
|
|
27616
|
+
end2(failure2.summary, failure2);
|
|
27454
27617
|
}
|
|
27455
27618
|
return done;
|
|
27456
27619
|
}
|
|
@@ -27459,6 +27622,7 @@ var init_codex = __esm({
|
|
|
27459
27622
|
"src/lib/agent/wire/codex.ts"() {
|
|
27460
27623
|
"use strict";
|
|
27461
27624
|
init_idle();
|
|
27625
|
+
init_retry();
|
|
27462
27626
|
init_failures();
|
|
27463
27627
|
init_conversation();
|
|
27464
27628
|
init_codex_background();
|
|
@@ -29130,6 +29294,22 @@ var init_settings2 = __esm({
|
|
|
29130
29294
|
});
|
|
29131
29295
|
|
|
29132
29296
|
// src/lib/agent/runtimes.ts
|
|
29297
|
+
import fs27 from "node:fs";
|
|
29298
|
+
function executionRuntimes() {
|
|
29299
|
+
const encoded = process.env[EXECUTION_RUNTIMES_ENV];
|
|
29300
|
+
return encoded ? JSON.parse(encoded) : void 0;
|
|
29301
|
+
}
|
|
29302
|
+
function readRuntimeCredentials(file2) {
|
|
29303
|
+
try {
|
|
29304
|
+
return configBlock(JSON.parse(fs27.readFileSync(file2, "utf8")));
|
|
29305
|
+
} catch {
|
|
29306
|
+
return {};
|
|
29307
|
+
}
|
|
29308
|
+
}
|
|
29309
|
+
function runRuntimeById(id2) {
|
|
29310
|
+
const scope = executionRuntimes();
|
|
29311
|
+
return scope ? [scope.default, ...Object.values(scope.picks)].find((row) => row.id === id2) : runtimeById(id2);
|
|
29312
|
+
}
|
|
29133
29313
|
function readRuntimes(cfg = safeConfig()) {
|
|
29134
29314
|
const saved = Array.isArray(cfg.runtimes) ? cfg.runtimes.map(parseRuntime).filter(isRuntime) : null;
|
|
29135
29315
|
const list3 = saved?.length ? dedupe(saved) : [];
|
|
@@ -29244,7 +29424,7 @@ function writePicks(cfg, picks, list3 = readRuntimes(cfg)) {
|
|
|
29244
29424
|
if (Object.keys(block).length) cfg.agentRuntime = block;
|
|
29245
29425
|
else delete cfg.agentRuntime;
|
|
29246
29426
|
}
|
|
29247
|
-
var GLOBAL_ID, GLOBAL_NAME, isRuntime, runtimeSecretVar, keepsPick, noRuntime, noHarness;
|
|
29427
|
+
var GLOBAL_ID, GLOBAL_NAME, EXECUTION_RUNTIMES_ENV, isRuntime, runtimeSecretVar, keepsPick, noRuntime, noHarness;
|
|
29248
29428
|
var init_runtimes = __esm({
|
|
29249
29429
|
"src/lib/agent/runtimes.ts"() {
|
|
29250
29430
|
"use strict";
|
|
@@ -29253,6 +29433,7 @@ var init_runtimes = __esm({
|
|
|
29253
29433
|
init_types3();
|
|
29254
29434
|
GLOBAL_ID = "global";
|
|
29255
29435
|
GLOBAL_NAME = "Global default";
|
|
29436
|
+
EXECUTION_RUNTIMES_ENV = "AI4KANBAN_EXECUTION_RUNTIMES";
|
|
29256
29437
|
isRuntime = (r) => r !== null;
|
|
29257
29438
|
runtimeSecretVar = (env2, runtime) => runtime.secretRefs?.[env2] ?? secretVar(env2, runtime.id);
|
|
29258
29439
|
keepsPick = (id2) => !!id2 && id2 !== GLOBAL_ID;
|
|
@@ -29273,11 +29454,11 @@ var init_slug = __esm({
|
|
|
29273
29454
|
});
|
|
29274
29455
|
|
|
29275
29456
|
// src/lib/validate.ts
|
|
29276
|
-
import
|
|
29457
|
+
import fs28 from "node:fs";
|
|
29277
29458
|
import path30 from "node:path";
|
|
29278
29459
|
function moduleNames() {
|
|
29279
|
-
if (!
|
|
29280
|
-
return moduleNamesFrom(
|
|
29460
|
+
if (!fs28.existsSync(MODULES_MD)) return null;
|
|
29461
|
+
return moduleNamesFrom(fs28.readFileSync(MODULES_MD, "utf8"));
|
|
29281
29462
|
}
|
|
29282
29463
|
function validModules(mods) {
|
|
29283
29464
|
const known2 = moduleNames();
|
|
@@ -29312,7 +29493,7 @@ function dependencyCycle(id2, dep) {
|
|
|
29312
29493
|
const found2 = locate(at);
|
|
29313
29494
|
if (!found2) return null;
|
|
29314
29495
|
const file2 = found2.kind === "group" ? path30.join(found2.target, "root.md") : found2.target;
|
|
29315
|
-
const nexts = parseFrontmatter(
|
|
29496
|
+
const nexts = parseFrontmatter(fs28.readFileSync(file2, "utf8")).meta?.blocked_by ?? [];
|
|
29316
29497
|
if (found2.kind === "group") nexts.push(...groupMembers(found2.target));
|
|
29317
29498
|
for (const next of nexts) {
|
|
29318
29499
|
const rest2 = walk3(next);
|
|
@@ -29340,7 +29521,7 @@ var init_validate = __esm({
|
|
|
29340
29521
|
});
|
|
29341
29522
|
|
|
29342
29523
|
// src/lib/memory.ts
|
|
29343
|
-
import
|
|
29524
|
+
import fs29 from "node:fs";
|
|
29344
29525
|
import path31 from "node:path";
|
|
29345
29526
|
function scaffoldProjectMemory() {
|
|
29346
29527
|
const board2 = scaffoldMemoryDir(MEMORY, setOf(BOARD_MEMORY_FILES));
|
|
@@ -29348,13 +29529,13 @@ function scaffoldProjectMemory() {
|
|
|
29348
29529
|
return board2 ?? planner;
|
|
29349
29530
|
}
|
|
29350
29531
|
function scaffoldMemoryDir(dir, set2) {
|
|
29351
|
-
const existed =
|
|
29352
|
-
|
|
29532
|
+
const existed = fs29.existsSync(dir);
|
|
29533
|
+
fs29.mkdirSync(dir, { recursive: true });
|
|
29353
29534
|
const made = [];
|
|
29354
29535
|
for (const [name, body] of Object.entries(set2)) {
|
|
29355
29536
|
const file2 = path31.join(dir, name);
|
|
29356
|
-
if (!
|
|
29357
|
-
|
|
29537
|
+
if (!fs29.existsSync(file2)) {
|
|
29538
|
+
fs29.writeFileSync(file2, body);
|
|
29358
29539
|
made.push(name);
|
|
29359
29540
|
}
|
|
29360
29541
|
}
|
|
@@ -29364,7 +29545,7 @@ function scaffoldMemoryDir(dir, set2) {
|
|
|
29364
29545
|
function plannerModules() {
|
|
29365
29546
|
let dirs2;
|
|
29366
29547
|
try {
|
|
29367
|
-
dirs2 =
|
|
29548
|
+
dirs2 = fs29.readdirSync(agentMemoryDir(PLANNER), { withFileTypes: true }).filter((e) => e.isDirectory() && isModule(e.name)).map((e) => e.name);
|
|
29368
29549
|
} catch {
|
|
29369
29550
|
return [];
|
|
29370
29551
|
}
|
|
@@ -29376,7 +29557,7 @@ function memoryDirectories(board2) {
|
|
|
29376
29557
|
const walk3 = (dir, depth3, scoped = true) => {
|
|
29377
29558
|
let entries2;
|
|
29378
29559
|
try {
|
|
29379
|
-
entries2 =
|
|
29560
|
+
entries2 = fs29.readdirSync(dir, { withFileTypes: true });
|
|
29380
29561
|
} catch {
|
|
29381
29562
|
return [];
|
|
29382
29563
|
}
|
|
@@ -29390,7 +29571,7 @@ function memoryDirectories(board2) {
|
|
|
29390
29571
|
...walk3(path31.join(root2, "previews"), 3),
|
|
29391
29572
|
...walk3(path31.join(root2, "studios"), 1, false),
|
|
29392
29573
|
path31.join(root2, "agents", PLANNER)
|
|
29393
|
-
].filter((dir) =>
|
|
29574
|
+
].filter((dir) => fs29.existsSync(dir)).map((dir) => `${dir}/`);
|
|
29394
29575
|
}
|
|
29395
29576
|
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
29577
|
var init_memory = __esm({
|
|
@@ -29439,7 +29620,7 @@ edits here do not last.
|
|
|
29439
29620
|
agentMemoryFile = (agent, name) => path31.join(agentMemoryDir(agent), name);
|
|
29440
29621
|
writtenMemoryNames = (agent) => {
|
|
29441
29622
|
try {
|
|
29442
|
-
return
|
|
29623
|
+
return fs29.readdirSync(agentMemoryDir(agent), { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".md")).map((e) => e.name).sort();
|
|
29443
29624
|
} catch {
|
|
29444
29625
|
return [];
|
|
29445
29626
|
}
|
|
@@ -29451,7 +29632,7 @@ edits here do not last.
|
|
|
29451
29632
|
moduleMemoryFile = (module, name) => path31.join(agentMemoryDir(PLANNER), module, name);
|
|
29452
29633
|
plannerCopies = (name) => [
|
|
29453
29634
|
agentMemoryFile(PLANNER, name),
|
|
29454
|
-
...plannerModules().map((m) => moduleMemoryFile(m, name)).filter((file2) =>
|
|
29635
|
+
...plannerModules().map((m) => moduleMemoryFile(m, name)).filter((file2) => fs29.existsSync(file2))
|
|
29455
29636
|
];
|
|
29456
29637
|
}
|
|
29457
29638
|
});
|
|
@@ -43122,14 +43303,14 @@ var require_parser = __commonJS({
|
|
|
43122
43303
|
case "scalar":
|
|
43123
43304
|
case "single-quoted-scalar":
|
|
43124
43305
|
case "double-quoted-scalar": {
|
|
43125
|
-
const
|
|
43306
|
+
const fs91 = this.flowScalar(this.type);
|
|
43126
43307
|
if (atNextItem || it.value) {
|
|
43127
|
-
map3.items.push({ start, key:
|
|
43308
|
+
map3.items.push({ start, key: fs91, sep: [] });
|
|
43128
43309
|
this.onKeyLine = true;
|
|
43129
43310
|
} else if (it.sep) {
|
|
43130
|
-
this.stack.push(
|
|
43311
|
+
this.stack.push(fs91);
|
|
43131
43312
|
} else {
|
|
43132
|
-
Object.assign(it, { key:
|
|
43313
|
+
Object.assign(it, { key: fs91, sep: [] });
|
|
43133
43314
|
this.onKeyLine = true;
|
|
43134
43315
|
}
|
|
43135
43316
|
return;
|
|
@@ -43257,13 +43438,13 @@ var require_parser = __commonJS({
|
|
|
43257
43438
|
case "scalar":
|
|
43258
43439
|
case "single-quoted-scalar":
|
|
43259
43440
|
case "double-quoted-scalar": {
|
|
43260
|
-
const
|
|
43441
|
+
const fs91 = this.flowScalar(this.type);
|
|
43261
43442
|
if (!it || it.value)
|
|
43262
|
-
fc.items.push({ start: [], key:
|
|
43443
|
+
fc.items.push({ start: [], key: fs91, sep: [] });
|
|
43263
43444
|
else if (it.sep)
|
|
43264
|
-
this.stack.push(
|
|
43445
|
+
this.stack.push(fs91);
|
|
43265
43446
|
else
|
|
43266
|
-
Object.assign(it, { key:
|
|
43447
|
+
Object.assign(it, { key: fs91, sep: [] });
|
|
43267
43448
|
return;
|
|
43268
43449
|
}
|
|
43269
43450
|
case "flow-map-end":
|
|
@@ -43949,10 +44130,10 @@ var init_studio_files = __esm({
|
|
|
43949
44130
|
});
|
|
43950
44131
|
|
|
43951
44132
|
// src/lib/agent/studio-folder.ts
|
|
43952
|
-
import
|
|
44133
|
+
import fs30 from "node:fs";
|
|
43953
44134
|
import path32 from "node:path";
|
|
43954
44135
|
function filesOf(dir, base = dir) {
|
|
43955
|
-
return
|
|
44136
|
+
return fs30.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".")).flatMap((e) => {
|
|
43956
44137
|
const full = path32.join(dir, e.name);
|
|
43957
44138
|
if (e.isSymbolicLink()) throw new Error(`${full}: symbolic links are not allowed`);
|
|
43958
44139
|
return e.isDirectory() ? filesOf(full, base) : [path32.relative(base, full).split(path32.sep).join("/")];
|
|
@@ -43960,7 +44141,7 @@ function filesOf(dir, base = dir) {
|
|
|
43960
44141
|
}
|
|
43961
44142
|
function readStudioFile(dir, file2) {
|
|
43962
44143
|
const full = path32.join(dir, file2);
|
|
43963
|
-
return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path32.extname(file2)]};base64,${
|
|
44144
|
+
return isAboutFile(file2) && !file2.endsWith(".md") ? `data:${MIME[path32.extname(file2)]};base64,${fs30.readFileSync(full).toString("base64")}` : fs30.readFileSync(full, "utf8");
|
|
43964
44145
|
}
|
|
43965
44146
|
var MIME, readStudioFolder;
|
|
43966
44147
|
var init_studio_folder = __esm({
|
|
@@ -43974,7 +44155,7 @@ var init_studio_folder = __esm({
|
|
|
43974
44155
|
|
|
43975
44156
|
// ../official/pack.ts
|
|
43976
44157
|
import crypto2 from "node:crypto";
|
|
43977
|
-
import
|
|
44158
|
+
import fs31 from "node:fs";
|
|
43978
44159
|
import path33 from "node:path";
|
|
43979
44160
|
import { fileURLToPath } from "node:url";
|
|
43980
44161
|
function packOfficial(root2 = OFFICIAL, loose = false) {
|
|
@@ -44006,32 +44187,32 @@ var init_pack = __esm({
|
|
|
44006
44187
|
init_studio_folder();
|
|
44007
44188
|
init_studio_files();
|
|
44008
44189
|
OFFICIAL = path33.dirname(fileURLToPath(import.meta.url));
|
|
44009
|
-
dirs = (dir) =>
|
|
44190
|
+
dirs = (dir) => fs31.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
44010
44191
|
hashOf = (files) => crypto2.createHash("sha256").update(hashInput(files)).digest("hex");
|
|
44011
44192
|
}
|
|
44012
44193
|
});
|
|
44013
44194
|
|
|
44014
44195
|
// src/lib/agent/cloud-studios.ts
|
|
44015
|
-
import
|
|
44196
|
+
import fs32 from "node:fs";
|
|
44016
44197
|
import path34 from "node:path";
|
|
44017
44198
|
function readJson(file2) {
|
|
44018
44199
|
try {
|
|
44019
|
-
return JSON.parse(
|
|
44200
|
+
return JSON.parse(fs32.readFileSync(file2, "utf8"));
|
|
44020
44201
|
} catch {
|
|
44021
44202
|
return null;
|
|
44022
44203
|
}
|
|
44023
44204
|
}
|
|
44024
44205
|
function writeJson(file2, value) {
|
|
44025
|
-
|
|
44206
|
+
fs32.mkdirSync(path34.dirname(file2), { recursive: true });
|
|
44026
44207
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
44027
|
-
|
|
44208
|
+
fs32.writeFileSync(tmp, `${JSON.stringify(value)}
|
|
44028
44209
|
`);
|
|
44029
|
-
|
|
44210
|
+
fs32.renameSync(tmp, file2);
|
|
44030
44211
|
}
|
|
44031
44212
|
function heldStudioName(name) {
|
|
44032
44213
|
let files;
|
|
44033
44214
|
try {
|
|
44034
|
-
files =
|
|
44215
|
+
files = fs32.readdirSync(path34.join(root(), "versions"));
|
|
44035
44216
|
} catch {
|
|
44036
44217
|
return "";
|
|
44037
44218
|
}
|
|
@@ -44042,7 +44223,7 @@ function heldStudioName(name) {
|
|
|
44042
44223
|
}
|
|
44043
44224
|
function saveVersion(held4) {
|
|
44044
44225
|
const file2 = versionFile(held4.id, held4.version);
|
|
44045
|
-
if (!
|
|
44226
|
+
if (!fs32.existsSync(file2)) writeJson(file2, { id: held4.id, version: held4.version, name: held4.name, names: held4.names, files: held4.files });
|
|
44046
44227
|
}
|
|
44047
44228
|
function savePin(task, held4) {
|
|
44048
44229
|
saveVersion(held4);
|
|
@@ -44247,7 +44428,7 @@ var init_studio_file = __esm({
|
|
|
44247
44428
|
});
|
|
44248
44429
|
|
|
44249
44430
|
// src/lib/agent/studios.ts
|
|
44250
|
-
import
|
|
44431
|
+
import fs33 from "node:fs";
|
|
44251
44432
|
import path35 from "node:path";
|
|
44252
44433
|
function noStudioMessage(id2) {
|
|
44253
44434
|
const name = heldStudioName(id2 ?? "") || id2;
|
|
@@ -44260,7 +44441,7 @@ function knownStudio(id2) {
|
|
|
44260
44441
|
}
|
|
44261
44442
|
function userStudioRules(flow) {
|
|
44262
44443
|
try {
|
|
44263
|
-
return
|
|
44444
|
+
return fs33.readFileSync(studioRuleFile(flow.id), "utf8").trim();
|
|
44264
44445
|
} catch {
|
|
44265
44446
|
return "";
|
|
44266
44447
|
}
|
|
@@ -44270,7 +44451,7 @@ function cardMeta(id2) {
|
|
|
44270
44451
|
const found2 = locate(id2) ?? locateArchived(id2);
|
|
44271
44452
|
if (!found2) return null;
|
|
44272
44453
|
const file2 = found2.kind === "group" ? path35.join(found2.target, "root.md") : found2.target;
|
|
44273
|
-
return parseFrontmatter(
|
|
44454
|
+
return parseFrontmatter(fs33.readFileSync(file2, "utf8")).meta;
|
|
44274
44455
|
} catch {
|
|
44275
44456
|
return null;
|
|
44276
44457
|
}
|
|
@@ -44934,7 +45115,7 @@ var init_parse3 = __esm({
|
|
|
44934
45115
|
});
|
|
44935
45116
|
|
|
44936
45117
|
// src/lib/agents/catalog.ts
|
|
44937
|
-
import
|
|
45118
|
+
import fs34 from "node:fs";
|
|
44938
45119
|
import path37 from "node:path";
|
|
44939
45120
|
function readCatalog() {
|
|
44940
45121
|
const agents = [];
|
|
@@ -44992,7 +45173,7 @@ function readBundled(folder2) {
|
|
|
44992
45173
|
function projectFolders(root2) {
|
|
44993
45174
|
let entries2;
|
|
44994
45175
|
try {
|
|
44995
|
-
entries2 =
|
|
45176
|
+
entries2 = fs34.readdirSync(root2, { withFileTypes: true });
|
|
44996
45177
|
} catch {
|
|
44997
45178
|
return [];
|
|
44998
45179
|
}
|
|
@@ -45003,9 +45184,9 @@ function agentFileReader(dir) {
|
|
|
45003
45184
|
const target = path37.resolve(dir, relative);
|
|
45004
45185
|
if (target !== dir && !target.startsWith(dir + path37.sep)) return null;
|
|
45005
45186
|
try {
|
|
45006
|
-
const real2 =
|
|
45007
|
-
if (!real2.startsWith(
|
|
45008
|
-
return
|
|
45187
|
+
const real2 = fs34.realpathSync(target);
|
|
45188
|
+
if (!real2.startsWith(fs34.realpathSync(dir) + path37.sep)) return null;
|
|
45189
|
+
return fs34.readFileSync(real2, "utf8");
|
|
45009
45190
|
} catch {
|
|
45010
45191
|
return null;
|
|
45011
45192
|
}
|
|
@@ -45014,7 +45195,7 @@ function agentFileReader(dir) {
|
|
|
45014
45195
|
function walkFolder(dir, prefix) {
|
|
45015
45196
|
let entries2;
|
|
45016
45197
|
try {
|
|
45017
|
-
entries2 =
|
|
45198
|
+
entries2 = fs34.readdirSync(dir, { withFileTypes: true });
|
|
45018
45199
|
} catch {
|
|
45019
45200
|
return [];
|
|
45020
45201
|
}
|
|
@@ -45125,7 +45306,7 @@ var init_candidate = __esm({
|
|
|
45125
45306
|
|
|
45126
45307
|
// src/lib/agent/launch.ts
|
|
45127
45308
|
import { spawn as spawn2 } from "node:child_process";
|
|
45128
|
-
import
|
|
45309
|
+
import fs35 from "node:fs";
|
|
45129
45310
|
import path38 from "node:path";
|
|
45130
45311
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
45131
45312
|
function boardArgs() {
|
|
@@ -45138,8 +45319,8 @@ function watcherEnv(env2 = process.env) {
|
|
|
45138
45319
|
}
|
|
45139
45320
|
function spawnWatcher(sessionId) {
|
|
45140
45321
|
if (!BUILT) return void 0;
|
|
45141
|
-
|
|
45142
|
-
const out =
|
|
45322
|
+
fs35.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
45323
|
+
const out = fs35.openSync(path38.join(SESSIONS_DIR, `${sessionId}.watch.log`), "a");
|
|
45143
45324
|
try {
|
|
45144
45325
|
const child = spawn2(process.execPath, [SELF, "__watch", sessionId, ...boardArgs()], {
|
|
45145
45326
|
cwd: REPO_ROOT,
|
|
@@ -45155,7 +45336,7 @@ function spawnWatcher(sessionId) {
|
|
|
45155
45336
|
return void 0;
|
|
45156
45337
|
} finally {
|
|
45157
45338
|
try {
|
|
45158
|
-
|
|
45339
|
+
fs35.closeSync(out);
|
|
45159
45340
|
} catch {
|
|
45160
45341
|
}
|
|
45161
45342
|
}
|
|
@@ -45172,11 +45353,11 @@ var init_launch = __esm({
|
|
|
45172
45353
|
});
|
|
45173
45354
|
|
|
45174
45355
|
// src/lib/agent/command.ts
|
|
45175
|
-
import
|
|
45356
|
+
import fs36 from "node:fs";
|
|
45176
45357
|
import path39 from "node:path";
|
|
45177
45358
|
function selfCommand() {
|
|
45178
45359
|
const bin = path39.resolve(path39.dirname(SELF), "..", "bin", "ai4kanban.mjs");
|
|
45179
|
-
const file2 =
|
|
45360
|
+
const file2 = fs36.existsSync(bin) ? bin : SELF;
|
|
45180
45361
|
const inside2 = rel(file2);
|
|
45181
45362
|
const shortHop = !inside2.startsWith("..") && !path39.isAbsolute(inside2) && inside2.split(/[\\/]/).length <= 3;
|
|
45182
45363
|
return `node ${shortHop ? inside2 : file2}`;
|
|
@@ -45190,7 +45371,7 @@ function boardCommandFor(_cardId) {
|
|
|
45190
45371
|
}
|
|
45191
45372
|
function absoluteSelf() {
|
|
45192
45373
|
const bin = path39.resolve(path39.dirname(SELF), "..", "bin", "ai4kanban.mjs");
|
|
45193
|
-
return
|
|
45374
|
+
return fs36.existsSync(bin) ? bin : SELF;
|
|
45194
45375
|
}
|
|
45195
45376
|
function commandNote(command) {
|
|
45196
45377
|
if (command === "akb") return "";
|
|
@@ -45206,13 +45387,13 @@ var init_command = __esm({
|
|
|
45206
45387
|
});
|
|
45207
45388
|
|
|
45208
45389
|
// src/lib/agent/outputs.ts
|
|
45209
|
-
import
|
|
45390
|
+
import fs37 from "node:fs";
|
|
45210
45391
|
import path40 from "node:path";
|
|
45211
45392
|
function cardBody(cardId2) {
|
|
45212
45393
|
const found2 = locate(cardId2) ?? locateArchived(cardId2);
|
|
45213
45394
|
if (!found2) return "";
|
|
45214
45395
|
try {
|
|
45215
|
-
return
|
|
45396
|
+
return fs37.readFileSync(found2.kind === "group" ? path40.join(found2.target, "root.md") : found2.target, "utf8");
|
|
45216
45397
|
} catch {
|
|
45217
45398
|
return "";
|
|
45218
45399
|
}
|
|
@@ -45246,20 +45427,20 @@ var init_outputs = __esm({
|
|
|
45246
45427
|
});
|
|
45247
45428
|
|
|
45248
45429
|
// src/lib/agent/log.ts
|
|
45249
|
-
import
|
|
45430
|
+
import fs38 from "node:fs";
|
|
45250
45431
|
import path41 from "node:path";
|
|
45251
45432
|
function pruneLogs() {
|
|
45252
45433
|
try {
|
|
45253
|
-
const runs =
|
|
45434
|
+
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
45435
|
const kept2 = new Set(runs.slice(0, KEEP_LOGS).map((r) => r.id));
|
|
45255
45436
|
const drop = new Set(runs.slice(KEEP_LOGS).map((r) => r.id));
|
|
45256
|
-
for (const f of
|
|
45437
|
+
for (const f of fs38.readdirSync(SESSIONS_DIR)) {
|
|
45257
45438
|
const dot = f.indexOf(".");
|
|
45258
45439
|
const id2 = dot === -1 ? f : f.slice(0, dot);
|
|
45259
45440
|
const stray = f.endsWith(".images") && !kept2.has(id2) && !drop.has(id2) && stale2(f);
|
|
45260
45441
|
if (!stray && !drop.has(id2)) continue;
|
|
45261
45442
|
try {
|
|
45262
|
-
|
|
45443
|
+
fs38.rmSync(path41.join(SESSIONS_DIR, f), { recursive: true, force: true });
|
|
45263
45444
|
} catch {
|
|
45264
45445
|
}
|
|
45265
45446
|
}
|
|
@@ -45268,7 +45449,7 @@ function pruneLogs() {
|
|
|
45268
45449
|
}
|
|
45269
45450
|
function stale2(name) {
|
|
45270
45451
|
try {
|
|
45271
|
-
return Date.now() -
|
|
45452
|
+
return Date.now() - fs38.statSync(path41.join(SESSIONS_DIR, name)).mtimeMs > STRAY_MS;
|
|
45272
45453
|
} catch {
|
|
45273
45454
|
return false;
|
|
45274
45455
|
}
|
|
@@ -45295,13 +45476,13 @@ function asContext(v) {
|
|
|
45295
45476
|
function readLogTail(logPath, maxBytes = TAIL_BYTES) {
|
|
45296
45477
|
let fd;
|
|
45297
45478
|
try {
|
|
45298
|
-
const size =
|
|
45479
|
+
const size = fs38.statSync(logPath).size;
|
|
45299
45480
|
const start = Math.max(0, size - maxBytes);
|
|
45300
45481
|
const len = size - start;
|
|
45301
45482
|
if (len === 0) return "";
|
|
45302
|
-
fd =
|
|
45483
|
+
fd = fs38.openSync(logPath, "r");
|
|
45303
45484
|
const buf = Buffer.alloc(len);
|
|
45304
|
-
|
|
45485
|
+
fs38.readSync(fd, buf, 0, len, start);
|
|
45305
45486
|
let text5 = buf.toString("utf8");
|
|
45306
45487
|
if (start > 0) {
|
|
45307
45488
|
const nl = text5.indexOf("\n");
|
|
@@ -45313,7 +45494,7 @@ function readLogTail(logPath, maxBytes = TAIL_BYTES) {
|
|
|
45313
45494
|
} finally {
|
|
45314
45495
|
if (fd !== void 0) {
|
|
45315
45496
|
try {
|
|
45316
|
-
|
|
45497
|
+
fs38.closeSync(fd);
|
|
45317
45498
|
} catch {
|
|
45318
45499
|
}
|
|
45319
45500
|
}
|
|
@@ -45404,7 +45585,7 @@ ${DURATION_MARKER} ${Math.max(0, ms)}
|
|
|
45404
45585
|
});
|
|
45405
45586
|
|
|
45406
45587
|
// src/lib/agent/store.ts
|
|
45407
|
-
import
|
|
45588
|
+
import fs39 from "node:fs";
|
|
45408
45589
|
import path42 from "node:path";
|
|
45409
45590
|
function logPathIn(held4, sessionId) {
|
|
45410
45591
|
return typeof held4 === "string" && held4.startsWith(SESSIONS_DIR + path42.sep) ? held4 : logPathOf(sessionId);
|
|
@@ -45412,7 +45593,7 @@ function logPathIn(held4, sessionId) {
|
|
|
45412
45593
|
function parseStore() {
|
|
45413
45594
|
let data;
|
|
45414
45595
|
try {
|
|
45415
|
-
data = JSON.parse(
|
|
45596
|
+
data = JSON.parse(fs39.readFileSync(SESSIONS, "utf8"));
|
|
45416
45597
|
} catch {
|
|
45417
45598
|
return { runs: [], deliveries: [], marks: {} };
|
|
45418
45599
|
}
|
|
@@ -45446,7 +45627,8 @@ function parseStore() {
|
|
|
45446
45627
|
error: typeof entry.error === "string" ? entry.error : void 0,
|
|
45447
45628
|
failure: readFailure(entry.failure),
|
|
45448
45629
|
validationFailure: readFailure(entry.validationFailure),
|
|
45449
|
-
retryPause: entry.retryPause,
|
|
45630
|
+
retryPause: readRetryPause(entry.retryPause),
|
|
45631
|
+
retryHistory: readRetryHistory(entry.retryHistory),
|
|
45450
45632
|
blocker: readBlocker(entry.blocker),
|
|
45451
45633
|
// A run that never reported a cost shows none, rather than a zero it didn't earn.
|
|
45452
45634
|
costUsd: typeof entry.costUsd === "number" && entry.costUsd >= 0 ? entry.costUsd : void 0,
|
|
@@ -45766,16 +45948,16 @@ function writeStore(store) {
|
|
|
45766
45948
|
marks: store.marks,
|
|
45767
45949
|
...store.refined ? { refined: store.refined } : {}
|
|
45768
45950
|
};
|
|
45769
|
-
|
|
45951
|
+
fs39.mkdirSync(path42.dirname(SESSIONS), { recursive: true });
|
|
45770
45952
|
const tmp = `${SESSIONS}.tmp`;
|
|
45771
|
-
|
|
45772
|
-
|
|
45953
|
+
fs39.writeFileSync(tmp, JSON.stringify(kept2, null, 2) + "\n");
|
|
45954
|
+
fs39.renameSync(tmp, SESSIONS);
|
|
45773
45955
|
forgetFileMemos();
|
|
45774
45956
|
}
|
|
45775
45957
|
function prune(runs, deliveries) {
|
|
45776
45958
|
const held4 = new Set(deliveries.filter(holdsCheckout).map((d) => d.deliveryId));
|
|
45777
45959
|
const live = runs.filter((r) => r.status === "running");
|
|
45778
|
-
const finished = runs.filter((r) => r.status !== "running" && (
|
|
45960
|
+
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
45961
|
const spared = runs.filter(
|
|
45780
45962
|
(r) => r.status !== "running" && !finished.includes(r) && (!!r.discardedCards?.length || r.deliveryId && held4.has(r.deliveryId))
|
|
45781
45963
|
);
|
|
@@ -45872,11 +46054,11 @@ var init_store = __esm({
|
|
|
45872
46054
|
});
|
|
45873
46055
|
|
|
45874
46056
|
// src/lib/agent/commit-mode.ts
|
|
45875
|
-
import
|
|
46057
|
+
import fs40 from "node:fs";
|
|
45876
46058
|
function recordedIds() {
|
|
45877
46059
|
try {
|
|
45878
46060
|
return new Set(
|
|
45879
|
-
|
|
46061
|
+
fs40.readdirSync(DELIVERIES).filter((f) => f.endsWith(".json")).map((f) => f.slice(0, -".json".length))
|
|
45880
46062
|
);
|
|
45881
46063
|
} catch {
|
|
45882
46064
|
return /* @__PURE__ */ new Set();
|
|
@@ -45909,7 +46091,7 @@ var init_commit_mode = __esm({
|
|
|
45909
46091
|
init_worktree();
|
|
45910
46092
|
ID_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
|
|
45911
46093
|
ID_LENGTH = 8;
|
|
45912
|
-
deliveryCwd = (delivery) => delivery.worktree &&
|
|
46094
|
+
deliveryCwd = (delivery) => delivery.worktree && fs40.existsSync(worktreeDir(delivery.worktree)) ? worktreeDir(delivery.worktree) : REPO_ROOT;
|
|
45913
46095
|
}
|
|
45914
46096
|
});
|
|
45915
46097
|
|
|
@@ -46003,12 +46185,12 @@ var init_runner = __esm({
|
|
|
46003
46185
|
});
|
|
46004
46186
|
|
|
46005
46187
|
// src/lib/agent/rules.ts
|
|
46006
|
-
import
|
|
46188
|
+
import fs41 from "node:fs";
|
|
46007
46189
|
import path43 from "node:path";
|
|
46008
46190
|
function ruleFile(agent) {
|
|
46009
46191
|
if (!agent || hiddenRole(agent)) return "";
|
|
46010
46192
|
try {
|
|
46011
|
-
return
|
|
46193
|
+
return fs41.readFileSync(rulePath(agent), "utf8").trim();
|
|
46012
46194
|
} catch {
|
|
46013
46195
|
return "";
|
|
46014
46196
|
}
|
|
@@ -46073,7 +46255,7 @@ var init_rules2 = __esm({
|
|
|
46073
46255
|
});
|
|
46074
46256
|
|
|
46075
46257
|
// src/lib/agent/deliveries.ts
|
|
46076
|
-
import
|
|
46258
|
+
import fs42 from "node:fs";
|
|
46077
46259
|
import path44 from "node:path";
|
|
46078
46260
|
function writeAudit(delivery, runs) {
|
|
46079
46261
|
const known2 = new Map(readAudit(delivery.deliveryId)?.sessions.map((s) => [s.sessionId, s]) ?? []);
|
|
@@ -46103,10 +46285,10 @@ function writeAudit(delivery, runs) {
|
|
|
46103
46285
|
}
|
|
46104
46286
|
function writeAuditFile(record2) {
|
|
46105
46287
|
try {
|
|
46106
|
-
|
|
46288
|
+
fs42.mkdirSync(DELIVERIES, { recursive: true });
|
|
46107
46289
|
const tmp = `${auditPath(record2.deliveryId)}.tmp`;
|
|
46108
|
-
|
|
46109
|
-
|
|
46290
|
+
fs42.writeFileSync(tmp, JSON.stringify(record2, null, 2) + "\n");
|
|
46291
|
+
fs42.renameSync(tmp, auditPath(record2.deliveryId));
|
|
46110
46292
|
return true;
|
|
46111
46293
|
} catch {
|
|
46112
46294
|
return false;
|
|
@@ -46114,7 +46296,7 @@ function writeAuditFile(record2) {
|
|
|
46114
46296
|
}
|
|
46115
46297
|
function readAudit(deliveryId) {
|
|
46116
46298
|
try {
|
|
46117
|
-
const data = JSON.parse(
|
|
46299
|
+
const data = JSON.parse(fs42.readFileSync(auditPath(deliveryId), "utf8"));
|
|
46118
46300
|
return { sessions: Array.isArray(data?.sessions) ? data.sessions : [] };
|
|
46119
46301
|
} catch {
|
|
46120
46302
|
return null;
|
|
@@ -46129,7 +46311,7 @@ function syncAudit(deliveryId, just) {
|
|
|
46129
46311
|
}
|
|
46130
46312
|
function wholeAudit(file2) {
|
|
46131
46313
|
try {
|
|
46132
|
-
const data = JSON.parse(
|
|
46314
|
+
const data = JSON.parse(fs42.readFileSync(file2, "utf8"));
|
|
46133
46315
|
return typeof data?.deliveryId === "string" && Array.isArray(data.sessions) ? data : null;
|
|
46134
46316
|
} catch {
|
|
46135
46317
|
return null;
|
|
@@ -46142,7 +46324,7 @@ function activeAudit(file2) {
|
|
|
46142
46324
|
function allAudits() {
|
|
46143
46325
|
let names2;
|
|
46144
46326
|
try {
|
|
46145
|
-
names2 =
|
|
46327
|
+
names2 = fs42.readdirSync(DELIVERIES);
|
|
46146
46328
|
} catch {
|
|
46147
46329
|
return [];
|
|
46148
46330
|
}
|
|
@@ -46271,7 +46453,7 @@ function resumeRecord(id2, execution) {
|
|
|
46271
46453
|
const found2 = namedDelivery(id2) ?? endedDelivery(id2);
|
|
46272
46454
|
if (!found2) return { ok: false, ...unknownDelivery(id2) };
|
|
46273
46455
|
const file2 = found2.cardId === null ? null : cardFile(found2.cardId);
|
|
46274
|
-
const restored = file2 && parseFrontmatter(
|
|
46456
|
+
const restored = file2 && parseFrontmatter(fs42.readFileSync(file2, "utf8")).meta?.restored;
|
|
46275
46457
|
if (restored && Date.parse(restored) > found2.startedAt) return { ok: false, ...unknownDelivery(id2) };
|
|
46276
46458
|
if (found2.status === "finished") return { ok: true, delivery: found2 };
|
|
46277
46459
|
const refused = resumeRefusal(found2);
|
|
@@ -46317,7 +46499,7 @@ function approvedRequirements(cardId2) {
|
|
|
46317
46499
|
const file2 = found2.kind === "group" ? path44.join(found2.target, "root.md") : found2.target;
|
|
46318
46500
|
let text5;
|
|
46319
46501
|
try {
|
|
46320
|
-
text5 =
|
|
46502
|
+
text5 = fs42.readFileSync(file2, "utf8");
|
|
46321
46503
|
} catch {
|
|
46322
46504
|
return "";
|
|
46323
46505
|
}
|
|
@@ -46328,7 +46510,7 @@ function cardMeta2(cardId2) {
|
|
|
46328
46510
|
const found2 = locate(cardId2);
|
|
46329
46511
|
if (!found2) return null;
|
|
46330
46512
|
const file2 = found2.kind === "group" ? path44.join(found2.target, "root.md") : found2.target;
|
|
46331
|
-
return parseFrontmatter(
|
|
46513
|
+
return parseFrontmatter(fs42.readFileSync(file2, "utf8")).meta;
|
|
46332
46514
|
} catch {
|
|
46333
46515
|
return null;
|
|
46334
46516
|
}
|
|
@@ -46486,7 +46668,7 @@ var init_deliveries = __esm({
|
|
|
46486
46668
|
activeAudits = () => allAudits().filter((a) => a.status === "active");
|
|
46487
46669
|
auditRow = (audit) => readDeliveryRow({ ...audit, sessions: audit.sessions.map((s) => s.sessionId) });
|
|
46488
46670
|
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) &&
|
|
46671
|
+
localAudit = (audit) => worktreeExists(audit.worktree) || audit.sessions.some((session) => path44.resolve(REPO_ROOT, session.log) === logPathOf(session.sessionId) && fs42.existsSync(logPathOf(session.sessionId)));
|
|
46490
46672
|
unknownDelivery = (id2) => refusal("deliveryNotFound", `no delivery here answers to "${id2}"`, { id: id2 });
|
|
46491
46673
|
isResumable = (delivery) => !resumeRefusal(delivery);
|
|
46492
46674
|
cardStatus = (cardId2) => cardMeta2(cardId2)?.status || "todo";
|
|
@@ -46817,14 +46999,15 @@ function startableBinary(binary, harness, pinned2 = false) {
|
|
|
46817
46999
|
const note = brokenEntryNote(copy2, own2, harness);
|
|
46818
47000
|
return { binary: spawnName(copy2, own2), ...note ? { note } : {} };
|
|
46819
47001
|
}
|
|
46820
|
-
function readBlock2(harness, block, argv, runtimeId, secretRefs = {}) {
|
|
47002
|
+
function readBlock2(harness, block, argv, runtimeId, secretRefs = {}, executionSecrets) {
|
|
46821
47003
|
const values = {};
|
|
46822
47004
|
const ignored = [];
|
|
46823
47005
|
const secretsSet = [];
|
|
46824
|
-
const env2 = harness.settings.some((s) => s.kind === "secret") ? readEnvFile() : {};
|
|
47006
|
+
const env2 = !executionSecrets && harness.settings.some((s) => s.kind === "secret") ? readEnvFile() : {};
|
|
46825
47007
|
for (const setting of harness.settings) {
|
|
46826
47008
|
if (setting.kind === "secret") {
|
|
46827
|
-
|
|
47009
|
+
const value2 = executionSecrets ? executionSecrets[setting.key] : setting.env && env2[secretRefs[setting.env] ?? secretVar(setting.env, runtimeId)];
|
|
47010
|
+
if (value2) secretsSet.push(setting.key);
|
|
46828
47011
|
continue;
|
|
46829
47012
|
}
|
|
46830
47013
|
const value = block[setting.key]?.trim() ?? "";
|
|
@@ -46841,11 +47024,8 @@ function readBlock2(harness, block, argv, runtimeId, secretRefs = {}) {
|
|
|
46841
47024
|
}
|
|
46842
47025
|
function onOwnEndpoint(runtimeId) {
|
|
46843
47026
|
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");
|
|
47027
|
+
if (!runtimeId || !runRuntimeById(runtimeId)) return false;
|
|
47028
|
+
return !!activeProviderOf(resolveHarness({ pin: runtimeId }))?.needs.includes("baseUrl");
|
|
46849
47029
|
} catch {
|
|
46850
47030
|
return true;
|
|
46851
47031
|
}
|
|
@@ -46854,12 +47034,15 @@ function resolveHarness(ask2 = {}) {
|
|
|
46854
47034
|
const cfg = safeConfig();
|
|
46855
47035
|
const staleCommand = typeof cfg.command === "string" && cfg.command.trim() ? true : void 0;
|
|
46856
47036
|
const agent = ask2.agent ?? "";
|
|
46857
|
-
const
|
|
46858
|
-
const
|
|
47037
|
+
const execution = executionRuntimes();
|
|
47038
|
+
const scoped = execution && [execution.default, ...Object.values(execution.picks)];
|
|
47039
|
+
const list3 = scoped ?? readRuntimes(cfg);
|
|
46859
47040
|
const owner = agent ? runtimeOwner(agent) : "";
|
|
46860
|
-
const picked = owner ? runtimeOfAgent(owner,
|
|
47041
|
+
const picked = owner ? execution ? execution.picks[owner]?.id : runtimeOfAgent(owner, readAgentRuntime(cfg)) : void 0;
|
|
46861
47042
|
const asked = ask2.pin ?? picked;
|
|
46862
47043
|
const runtime = pickRuntime(list3, asked, ask2.harness);
|
|
47044
|
+
const credentialId = scoped?.find((row) => row === runtime)?.credentialId;
|
|
47045
|
+
const executionSecrets = execution && (credentialId ? readRuntimeCredentials(execution.credentialsFile)[credentialId] ?? {} : {});
|
|
46863
47046
|
const unknownAgentRuntime = picked && !ask2.pin && !list3.some((r) => r.id === picked || r.harness === picked) ? picked : void 0;
|
|
46864
47047
|
const known2 = harnessByName(runtime.harness);
|
|
46865
47048
|
const harness = known2 ?? DEFAULT_HARNESS;
|
|
@@ -46869,7 +47052,8 @@ function resolveHarness(ask2 = {}) {
|
|
|
46869
47052
|
runtime.settings,
|
|
46870
47053
|
splitCommand(command),
|
|
46871
47054
|
runtime.id,
|
|
46872
|
-
runtime.secretRefs
|
|
47055
|
+
runtime.secretRefs,
|
|
47056
|
+
executionSecrets
|
|
46873
47057
|
);
|
|
46874
47058
|
return {
|
|
46875
47059
|
runtime,
|
|
@@ -46880,6 +47064,7 @@ function resolveHarness(ask2 = {}) {
|
|
|
46880
47064
|
unknownAgentRuntime,
|
|
46881
47065
|
values,
|
|
46882
47066
|
secretsSet,
|
|
47067
|
+
executionSecrets,
|
|
46883
47068
|
ignored,
|
|
46884
47069
|
unknownName: known2 ? void 0 : runtime.harness || void 0,
|
|
46885
47070
|
staleCommand
|
|
@@ -46923,6 +47108,7 @@ function settingSaveError(key, value, ask2 = {}) {
|
|
|
46923
47108
|
}
|
|
46924
47109
|
function runEnv2(resolved, cwd = REPO_ROOT) {
|
|
46925
47110
|
const { harness, runtime } = resolved;
|
|
47111
|
+
if (resolved.executionSecrets) return settingEnv(harness, resolved, resolved.executionSecrets, cwd);
|
|
46926
47112
|
const file2 = readEnvFile();
|
|
46927
47113
|
const secrets = {};
|
|
46928
47114
|
for (const setting of harness.settings) {
|
|
@@ -46952,7 +47138,7 @@ function planResume(session, agent, own2 = {}) {
|
|
|
46952
47138
|
if (!harnessByName(harnessName)) return null;
|
|
46953
47139
|
const resolved = resolveHarness({ agent, ...own2, harness: harnessName });
|
|
46954
47140
|
const { harness, command, runtime } = resolved;
|
|
46955
|
-
if (!harness.resumes) return null;
|
|
47141
|
+
if (!harness.resumes || resolved.executionSecrets && !runtime.id) return null;
|
|
46956
47142
|
const argv = splitCommand(command);
|
|
46957
47143
|
return {
|
|
46958
47144
|
harness: harness.name,
|
|
@@ -46971,7 +47157,7 @@ function planFork(session, agent, own2 = {}, sessionId = randomUUID5()) {
|
|
|
46971
47157
|
if (!harnessByName(harnessName)) return null;
|
|
46972
47158
|
const resolved = resolveHarness({ agent, ...own2, harness: harnessName });
|
|
46973
47159
|
const { harness, command, runtime } = resolved;
|
|
46974
|
-
if (!harness.forkArgs || harness.name !== harnessName) return null;
|
|
47160
|
+
if (!harness.forkArgs || harness.name !== harnessName || resolved.executionSecrets && !runtime.id) return null;
|
|
46975
47161
|
const argv = splitCommand(command);
|
|
46976
47162
|
return {
|
|
46977
47163
|
harness: harness.name,
|
|
@@ -47199,31 +47385,31 @@ var init_resolve = __esm({
|
|
|
47199
47385
|
});
|
|
47200
47386
|
|
|
47201
47387
|
// src/lib/agent/pictures.ts
|
|
47202
|
-
import
|
|
47388
|
+
import fs43 from "node:fs";
|
|
47203
47389
|
import path46 from "node:path";
|
|
47204
47390
|
function claimRunPictures(box, sessionId, names2 = []) {
|
|
47205
47391
|
if (!box || !freeBox(box) || names2.length === 0) return [];
|
|
47206
47392
|
const from = pictureBox(box);
|
|
47207
47393
|
const to = pictureBox(sessionId);
|
|
47208
47394
|
try {
|
|
47209
|
-
|
|
47210
|
-
|
|
47395
|
+
fs43.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
47396
|
+
fs43.renameSync(from, to);
|
|
47211
47397
|
} catch {
|
|
47212
47398
|
return [];
|
|
47213
47399
|
}
|
|
47214
|
-
return names2.filter(pictureName).map((name) => path46.join(to, name)).filter((file2) =>
|
|
47400
|
+
return names2.filter(pictureName).map((name) => path46.join(to, name)).filter((file2) => fs43.existsSync(file2));
|
|
47215
47401
|
}
|
|
47216
47402
|
function returnRunPictures(sessionId, box) {
|
|
47217
47403
|
if (!box || !boxId(box)) return;
|
|
47218
47404
|
try {
|
|
47219
|
-
|
|
47405
|
+
fs43.renameSync(pictureBox(sessionId), pictureBox(box));
|
|
47220
47406
|
} catch {
|
|
47221
47407
|
}
|
|
47222
47408
|
}
|
|
47223
47409
|
function moveRunPictures(from, to, files = []) {
|
|
47224
47410
|
if (files.length === 0) return [];
|
|
47225
47411
|
try {
|
|
47226
|
-
|
|
47412
|
+
fs43.renameSync(pictureBox(from), pictureBox(to));
|
|
47227
47413
|
} catch {
|
|
47228
47414
|
return files;
|
|
47229
47415
|
}
|
|
@@ -47236,7 +47422,7 @@ var init_pictures = __esm({
|
|
|
47236
47422
|
init_paths();
|
|
47237
47423
|
pictureName = (name) => /^[0-9a-f-]{36}\.[a-z0-9]{2,5}$/.test(name);
|
|
47238
47424
|
boxId = (box) => /^[0-9a-f-]{36}$/.test(box);
|
|
47239
|
-
freeBox = (box) => boxId(box) && !
|
|
47425
|
+
freeBox = (box) => boxId(box) && !fs43.existsSync(path46.join(SESSIONS_DIR, `${box}.log`));
|
|
47240
47426
|
pictureBox = (box) => path46.join(SESSIONS_DIR, `${box}.images`);
|
|
47241
47427
|
}
|
|
47242
47428
|
});
|
|
@@ -47338,7 +47524,7 @@ var init_facts = __esm({
|
|
|
47338
47524
|
});
|
|
47339
47525
|
|
|
47340
47526
|
// src/lib/view/archive.ts
|
|
47341
|
-
import
|
|
47527
|
+
import fs44 from "node:fs";
|
|
47342
47528
|
import path47 from "node:path";
|
|
47343
47529
|
function archivedId(file2) {
|
|
47344
47530
|
const own2 = idPrefix(path47.basename(file2));
|
|
@@ -47347,7 +47533,7 @@ function archivedId(file2) {
|
|
|
47347
47533
|
function readFile(file2) {
|
|
47348
47534
|
const id2 = archivedId(file2);
|
|
47349
47535
|
if (id2 === null) return null;
|
|
47350
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
47536
|
+
const { meta: meta3, body } = parseFrontmatter(fs44.readFileSync(file2, "utf8"));
|
|
47351
47537
|
if (!meta3) return null;
|
|
47352
47538
|
return {
|
|
47353
47539
|
row: {
|
|
@@ -47363,7 +47549,7 @@ function readFile(file2) {
|
|
|
47363
47549
|
}
|
|
47364
47550
|
function readArchive() {
|
|
47365
47551
|
const relPath = rel(ARCHIVE).split(path47.sep).join("/");
|
|
47366
|
-
if (!
|
|
47552
|
+
if (!fs44.existsSync(ARCHIVE)) return { relPath, cards: [] };
|
|
47367
47553
|
const cards = walkMd(ARCHIVE).map(readFile).filter((found2) => found2 !== null).map((found2) => found2.row);
|
|
47368
47554
|
cards.sort((a, b) => b.id - a.id);
|
|
47369
47555
|
return { relPath, cards };
|
|
@@ -47718,16 +47904,16 @@ var init_prompts = __esm({
|
|
|
47718
47904
|
|
|
47719
47905
|
// src/lib/agent/stop.ts
|
|
47720
47906
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
47721
|
-
import
|
|
47907
|
+
import fs45 from "node:fs";
|
|
47722
47908
|
function markedInProc(entry, strict = false, since) {
|
|
47723
47909
|
const pids = [];
|
|
47724
|
-
for (const name of
|
|
47910
|
+
for (const name of fs45.readdirSync("/proc")) {
|
|
47725
47911
|
if (!/^\d+$/.test(name)) continue;
|
|
47726
47912
|
try {
|
|
47727
|
-
if (
|
|
47913
|
+
if (fs45.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
|
|
47728
47914
|
} catch (error62) {
|
|
47729
47915
|
if (strict && !["ENOENT", "ESRCH"].includes(error62.code ?? "")) {
|
|
47730
|
-
const stat =
|
|
47916
|
+
const stat = fs45.statSync(`/proc/${name}`, { throwIfNoEntry: false });
|
|
47731
47917
|
if (stat?.uid === process.getuid?.() && !startedBefore(Number(name), since)) throw error62;
|
|
47732
47918
|
}
|
|
47733
47919
|
}
|
|
@@ -47937,7 +48123,7 @@ var init_creation_lock = __esm({
|
|
|
47937
48123
|
|
|
47938
48124
|
// src/lib/agent/sessions.ts
|
|
47939
48125
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
47940
|
-
import
|
|
48126
|
+
import fs46 from "node:fs";
|
|
47941
48127
|
import path50 from "node:path";
|
|
47942
48128
|
function reap(runs, reaped = [], restore = []) {
|
|
47943
48129
|
let changed = false;
|
|
@@ -47964,7 +48150,7 @@ function reap(runs, reaped = [], restore = []) {
|
|
|
47964
48150
|
}
|
|
47965
48151
|
function stampDuration(run3, endedAt) {
|
|
47966
48152
|
try {
|
|
47967
|
-
|
|
48153
|
+
fs46.appendFileSync(run3.logPath, durationLine(endedAt - run3.startedAt));
|
|
47968
48154
|
} catch {
|
|
47969
48155
|
}
|
|
47970
48156
|
}
|
|
@@ -47978,7 +48164,7 @@ function cardNow(cardId2) {
|
|
|
47978
48164
|
try {
|
|
47979
48165
|
const file2 = cardFile(cardId2);
|
|
47980
48166
|
if (!file2) return null;
|
|
47981
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
48167
|
+
const { meta: meta3 } = parseFrontmatter(fs46.readFileSync(file2, "utf8"));
|
|
47982
48168
|
if (!meta3) return null;
|
|
47983
48169
|
return { status: meta3.status || "todo", questions: meta3.questions.length, title: meta3.title };
|
|
47984
48170
|
} catch {
|
|
@@ -48223,7 +48409,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said2) {
|
|
|
48223
48409
|
if (retired) return retired;
|
|
48224
48410
|
if (req.deliveryId && findDelivery(req.deliveryId)?.scheduled) return retiredStudioRun("scheduled");
|
|
48225
48411
|
const cardId2 = Number.isInteger(req.id) ? req.id : null;
|
|
48226
|
-
if (req.runtime && !
|
|
48412
|
+
if (req.runtime && !runRuntimeById(req.runtime)) {
|
|
48227
48413
|
const runtimes = readRuntimes().map((r) => r.id).join(", ");
|
|
48228
48414
|
return refusal("runtimeNotFound", `this board has no runtime called "${req.runtime}". It has: ${runtimes}.`, {
|
|
48229
48415
|
id: req.runtime,
|
|
@@ -48246,7 +48432,7 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said2) {
|
|
|
48246
48432
|
const parent = req.action === "sub" && req.parentId ? peekRun(req.parentId) : void 0;
|
|
48247
48433
|
const cwd = parent?.cwd ?? deliveryCwd(start ?? joining ?? {});
|
|
48248
48434
|
const plan = said2 ? { ...said2.plan(cwd, sessionId), note: null } : planRun(sessionId, cwd, agentForRun(req), req.runtime ? { pin: req.runtime } : {});
|
|
48249
|
-
const away = plan.runtime ?
|
|
48435
|
+
const away = plan.runtime ? runRuntimeById(plan.runtime)?.away : void 0;
|
|
48250
48436
|
if (away) return refusal("runtimeAway", away, { id: plan.runtime });
|
|
48251
48437
|
if (plan.note) notes = [...notes, plan.note];
|
|
48252
48438
|
const record2 = {
|
|
@@ -48317,7 +48503,16 @@ function openRun(req, prompt, notes = [], sessionId = randomUUID6(), said2) {
|
|
|
48317
48503
|
}
|
|
48318
48504
|
function planningSession(cardId2, cwd = REPO_ROOT) {
|
|
48319
48505
|
const here = (dir) => !dir || path50.resolve(dir) === cwd;
|
|
48320
|
-
const
|
|
48506
|
+
const safeToContinue = (r) => {
|
|
48507
|
+
if (r.status === "done") return true;
|
|
48508
|
+
if (r.status !== "stopped" && r.status !== "error" && r.status !== "interrupted") return false;
|
|
48509
|
+
if (r.pendingWrites || r.cleanup?.status === "unconfirmed") return false;
|
|
48510
|
+
if (isSessionMissingFailure(r.failure)) return false;
|
|
48511
|
+
const root2 = r.agentPid ? { pid: r.agentPid, since: r.agentStartedAt ?? r.startedAt, identity: r.agentIdentity } : void 0;
|
|
48512
|
+
const stopped2 = r.managedProcess ? connectionStopped(root2) : processesStopped(runMark(r.sessionId, r.agentStartedAt ?? r.startedAt), root2);
|
|
48513
|
+
return stopped2;
|
|
48514
|
+
};
|
|
48515
|
+
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
48516
|
if (!planned) return { none: "unrecorded" };
|
|
48322
48517
|
if (!here(planned.cwd)) return { none: "elsewhere" };
|
|
48323
48518
|
const resumeId = resumeSessionId(planned);
|
|
@@ -48405,14 +48600,15 @@ async function openResume(id2, options) {
|
|
|
48405
48600
|
const automatic = typeof options === "object" && options.automatic === true;
|
|
48406
48601
|
const pending = !forced && prev.status !== "stopped" ? prev.retry?.pending : void 0;
|
|
48407
48602
|
if (automatic && !pending) return refusal("runContinued", "The automatic retry is no longer pending.");
|
|
48408
|
-
const
|
|
48603
|
+
const resetReplay = pending?.sessionAction === "reset_replay";
|
|
48604
|
+
const session = forced || resetReplay ? void 0 : resumeSessionId(prev);
|
|
48409
48605
|
if (pending || requireSession) {
|
|
48410
48606
|
const root2 = prev.agentPid ? { pid: prev.agentPid, since: prev.agentStartedAt ?? prev.startedAt, identity: prev.agentIdentity } : void 0;
|
|
48411
48607
|
const stopped2 = prev.managedProcess ? connectionStopped(root2) : processesStopped(runMark(prev.sessionId, prev.agentStartedAt), root2);
|
|
48412
48608
|
const recovery = agentRecovery({
|
|
48413
48609
|
stopped: stopped2,
|
|
48414
48610
|
session,
|
|
48415
|
-
replayable: !requireSession && neverStarted(prev),
|
|
48611
|
+
replayable: !requireSession && (neverStarted(prev) || resetReplay),
|
|
48416
48612
|
unconfirmedCleanup: prev.pendingWrites || prev.cleanup?.status === "unconfirmed" || prev.managedProcess && (pending?.failure ?? prev.failure)?.code === "idle_timeout" && !idleStopConfirmed(prev.cleanup, session)
|
|
48417
48613
|
});
|
|
48418
48614
|
if (recovery === "unsafe") {
|
|
@@ -48427,10 +48623,10 @@ async function openResume(id2, options) {
|
|
|
48427
48623
|
const sessionId = randomUUID6();
|
|
48428
48624
|
let plan;
|
|
48429
48625
|
let fresh;
|
|
48430
|
-
if (!forced && prev.harness === "antigravity" && !session && !neverStarted(prev)) {
|
|
48626
|
+
if (!forced && !resetReplay && prev.harness === "antigravity" && !session && !neverStarted(prev)) {
|
|
48431
48627
|
return refusal("runNoSession", "Antigravity did not record a conversation ID before interruption. The original session cannot be resumed.");
|
|
48432
48628
|
}
|
|
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.");
|
|
48629
|
+
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
48630
|
if (session) {
|
|
48435
48631
|
plan = planResume({ harness: prev.harness, resumeId: session, cwd }, prev.agent, prev.runtime ? { pin: prev.runtime } : {});
|
|
48436
48632
|
} else {
|
|
@@ -48451,12 +48647,12 @@ async function openResume(id2, options) {
|
|
|
48451
48647
|
if ("error" in opened) return opened;
|
|
48452
48648
|
if (!opened.spec.prompt && buildResume) opened.spec.prompt = buildResume;
|
|
48453
48649
|
if (build?.notes?.trim()) opened.spec.prompt = [opened.spec.prompt || resumePrompt(prev.deliveryId, prev.action), build.notes.trim()].join("\n\n");
|
|
48454
|
-
if (session &&
|
|
48650
|
+
if (session && requireSession && !pending) opened.spec.prompt = [recoveryPrompt, opened.spec.prompt].filter(Boolean).join("\n\n");
|
|
48455
48651
|
if (build || buildResume || pending || requireSession) writeSpec(opened.spec);
|
|
48456
48652
|
return opened;
|
|
48457
48653
|
}
|
|
48458
48654
|
async function planRetry2(prev, ask2, sessionId, cwd) {
|
|
48459
|
-
const runtime = prev.runtime &&
|
|
48655
|
+
const runtime = prev.runtime && runRuntimeById(prev.runtime) ? prev.runtime : void 0;
|
|
48460
48656
|
const { note, ...plan } = planRun(sessionId, cwd, prev.agent ?? agentForRun(ask2), {
|
|
48461
48657
|
...runtime ? { pin: runtime } : {},
|
|
48462
48658
|
...shipsHarness(prev.harness) ? { harness: prev.harness } : {}
|
|
@@ -48506,6 +48702,7 @@ async function resumeHeld(prev, plan, sessionId, resuming, fresh, automatic = fa
|
|
|
48506
48702
|
},
|
|
48507
48703
|
failure: automatic ? prev.retry?.pending?.failure : void 0,
|
|
48508
48704
|
retry: prev.retry ? { ...prev.retry, pending: void 0, launching: automatic ? true : void 0 } : void 0,
|
|
48705
|
+
...prev.retryHistory?.length ? { retryHistory: prev.retryHistory } : {},
|
|
48509
48706
|
logPath: logPathOf(sessionId),
|
|
48510
48707
|
specAgent: prev.specAgent,
|
|
48511
48708
|
cards: prev.cards,
|
|
@@ -48570,14 +48767,14 @@ function askForRefine(sessionId, ask2) {
|
|
|
48570
48767
|
}
|
|
48571
48768
|
function clearAsks(sessionId) {
|
|
48572
48769
|
try {
|
|
48573
|
-
|
|
48770
|
+
fs46.unlinkSync(asksPathOf(sessionId));
|
|
48574
48771
|
} catch {
|
|
48575
48772
|
}
|
|
48576
48773
|
}
|
|
48577
48774
|
function readAsks(sessionId) {
|
|
48578
48775
|
let data;
|
|
48579
48776
|
try {
|
|
48580
|
-
data = JSON.parse(
|
|
48777
|
+
data = JSON.parse(fs46.readFileSync(asksPathOf(sessionId), "utf8"));
|
|
48581
48778
|
} catch {
|
|
48582
48779
|
return { refines: [] };
|
|
48583
48780
|
}
|
|
@@ -48594,10 +48791,10 @@ function readAsks(sessionId) {
|
|
|
48594
48791
|
return { refines: refines.filter((a) => !discarded.has(a.cardId)) };
|
|
48595
48792
|
}
|
|
48596
48793
|
function writeAsks(sessionId, file2) {
|
|
48597
|
-
|
|
48794
|
+
fs46.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
48598
48795
|
const tmp = `${asksPathOf(sessionId)}.tmp`;
|
|
48599
|
-
|
|
48600
|
-
|
|
48796
|
+
fs46.writeFileSync(tmp, JSON.stringify(file2, null, 2) + "\n");
|
|
48797
|
+
fs46.renameSync(tmp, asksPathOf(sessionId));
|
|
48601
48798
|
}
|
|
48602
48799
|
function markSpawned(sessionId, pid) {
|
|
48603
48800
|
patch(sessionId, (r) => {
|
|
@@ -48624,6 +48821,7 @@ async function closeRun(sessionId, res) {
|
|
|
48624
48821
|
if (res.error) run3.error = res.error;
|
|
48625
48822
|
run3.failure = res.failure;
|
|
48626
48823
|
run3.retryPause = res.retryPause;
|
|
48824
|
+
if (res.retryHistory?.length) run3.retryHistory = res.retryHistory;
|
|
48627
48825
|
if (run3.retry) {
|
|
48628
48826
|
delete run3.retry.launching;
|
|
48629
48827
|
if (res.status === "stopped") delete run3.retry.pending;
|
|
@@ -48752,7 +48950,7 @@ async function reconcileCardDelivery(cardId2) {
|
|
|
48752
48950
|
result = withStore((store) => {
|
|
48753
48951
|
reap(store.runs, reaped, restore);
|
|
48754
48952
|
const file2 = cardFile(cardId2);
|
|
48755
|
-
const restoredRaw = file2 ? parseFrontmatter(
|
|
48953
|
+
const restoredRaw = file2 ? parseFrontmatter(fs46.readFileSync(file2, "utf8")).meta?.restored : void 0;
|
|
48756
48954
|
const restoredAt = restoredRaw ? Date.parse(restoredRaw) : Number.NaN;
|
|
48757
48955
|
const merged = /* @__PURE__ */ new Map();
|
|
48758
48956
|
for (const audit of cardAudits(cardId2)) merged.set(audit.deliveryId, audit);
|
|
@@ -48880,12 +49078,12 @@ async function resumeDelivery(id2) {
|
|
|
48880
49078
|
return { ok: true, deliveryId: delivery.deliveryId, carryOn };
|
|
48881
49079
|
}
|
|
48882
49080
|
function writeSpec(spec) {
|
|
48883
|
-
|
|
48884
|
-
|
|
49081
|
+
fs46.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
49082
|
+
fs46.writeFileSync(specPathOf(spec.sessionId), JSON.stringify(spec, null, 2) + "\n");
|
|
48885
49083
|
}
|
|
48886
49084
|
function readSpec(sessionId) {
|
|
48887
49085
|
try {
|
|
48888
|
-
const spec = JSON.parse(
|
|
49086
|
+
const spec = JSON.parse(fs46.readFileSync(specPathOf(sessionId), "utf8"));
|
|
48889
49087
|
return spec && Array.isArray(spec.plan?.argv) ? spec : null;
|
|
48890
49088
|
} catch {
|
|
48891
49089
|
return null;
|
|
@@ -48893,7 +49091,7 @@ function readSpec(sessionId) {
|
|
|
48893
49091
|
}
|
|
48894
49092
|
function dropSpec(sessionId) {
|
|
48895
49093
|
try {
|
|
48896
|
-
|
|
49094
|
+
fs46.unlinkSync(specPathOf(sessionId));
|
|
48897
49095
|
} catch {
|
|
48898
49096
|
}
|
|
48899
49097
|
}
|
|
@@ -48903,18 +49101,18 @@ async function acquireIndexLock(giveUp) {
|
|
|
48903
49101
|
for (; ; ) {
|
|
48904
49102
|
if (giveUp()) return null;
|
|
48905
49103
|
try {
|
|
48906
|
-
|
|
48907
|
-
|
|
48908
|
-
return () =>
|
|
49104
|
+
fs46.mkdirSync(INDEX_LOCK2, { recursive: false });
|
|
49105
|
+
fs46.writeFileSync(holder, String(process.pid));
|
|
49106
|
+
return () => fs46.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
48909
49107
|
} catch (err) {
|
|
48910
49108
|
const code = err.code;
|
|
48911
49109
|
if (code === "ENOENT") {
|
|
48912
|
-
|
|
49110
|
+
fs46.mkdirSync(path50.dirname(INDEX_LOCK2), { recursive: true });
|
|
48913
49111
|
continue;
|
|
48914
49112
|
}
|
|
48915
49113
|
if (code !== "EEXIST") throw err;
|
|
48916
49114
|
if (!pidAlive(Number(readHolder(holder)))) {
|
|
48917
|
-
|
|
49115
|
+
fs46.rmSync(INDEX_LOCK2, { recursive: true, force: true });
|
|
48918
49116
|
continue;
|
|
48919
49117
|
}
|
|
48920
49118
|
if (Date.now() > until) return null;
|
|
@@ -48924,7 +49122,7 @@ async function acquireIndexLock(giveUp) {
|
|
|
48924
49122
|
}
|
|
48925
49123
|
function readHolder(file2) {
|
|
48926
49124
|
try {
|
|
48927
|
-
return
|
|
49125
|
+
return fs46.readFileSync(file2, "utf8").trim();
|
|
48928
49126
|
} catch {
|
|
48929
49127
|
return String(process.pid);
|
|
48930
49128
|
}
|
|
@@ -49063,7 +49261,7 @@ var init_sources = __esm({
|
|
|
49063
49261
|
});
|
|
49064
49262
|
|
|
49065
49263
|
// src/lib/signals/inbox.ts
|
|
49066
|
-
import
|
|
49264
|
+
import fs47 from "node:fs";
|
|
49067
49265
|
import path51 from "node:path";
|
|
49068
49266
|
function metaPair(key, value) {
|
|
49069
49267
|
const name = typeof key === "string" ? key.trim() : "";
|
|
@@ -49095,7 +49293,7 @@ ${signal2.summary.trim()}
|
|
|
49095
49293
|
function parse3(file2, lenient = false) {
|
|
49096
49294
|
let text5;
|
|
49097
49295
|
try {
|
|
49098
|
-
text5 =
|
|
49296
|
+
text5 = fs47.readFileSync(file2, "utf8");
|
|
49099
49297
|
} catch {
|
|
49100
49298
|
return null;
|
|
49101
49299
|
}
|
|
@@ -49150,13 +49348,13 @@ function freeName(dir, wanted) {
|
|
|
49150
49348
|
const ext = path51.extname(wanted);
|
|
49151
49349
|
const stem = wanted.slice(0, wanted.length - ext.length);
|
|
49152
49350
|
let name = wanted;
|
|
49153
|
-
for (let n = 2;
|
|
49351
|
+
for (let n = 2; fs47.existsSync(path51.join(dir, name)); n++) name = `${stem}-${n}${ext}`;
|
|
49154
49352
|
return name;
|
|
49155
49353
|
}
|
|
49156
49354
|
function readFolder(dir, lenient = false) {
|
|
49157
49355
|
let entries2;
|
|
49158
49356
|
try {
|
|
49159
|
-
entries2 =
|
|
49357
|
+
entries2 = fs47.readdirSync(dir, { withFileTypes: true });
|
|
49160
49358
|
} catch {
|
|
49161
49359
|
return [];
|
|
49162
49360
|
}
|
|
@@ -49168,7 +49366,7 @@ function readInbox() {
|
|
|
49168
49366
|
return signals;
|
|
49169
49367
|
}
|
|
49170
49368
|
function writeSignal(incoming, importedAt, slug = "") {
|
|
49171
|
-
|
|
49369
|
+
fs47.mkdirSync(TRIAGE, { recursive: true });
|
|
49172
49370
|
const signal2 = {
|
|
49173
49371
|
...incoming,
|
|
49174
49372
|
importedAt,
|
|
@@ -49181,11 +49379,11 @@ function writeSignal(incoming, importedAt, slug = "") {
|
|
|
49181
49379
|
relPath: ""
|
|
49182
49380
|
};
|
|
49183
49381
|
const file2 = path51.join(TRIAGE, freeName(TRIAGE, fileName(signal2.title, slug)));
|
|
49184
|
-
|
|
49382
|
+
fs47.writeFileSync(file2, serialize({ ...signal2, relPath: boardRel(file2) }));
|
|
49185
49383
|
return { ...signal2, relPath: boardRel(file2) };
|
|
49186
49384
|
}
|
|
49187
49385
|
function stamp3(file2, fields2) {
|
|
49188
|
-
const text5 =
|
|
49386
|
+
const text5 = fs47.readFileSync(file2, "utf8");
|
|
49189
49387
|
const lines = text5.split("\n");
|
|
49190
49388
|
const close = lines.indexOf("---", 1);
|
|
49191
49389
|
if (close < 0) return;
|
|
@@ -49194,13 +49392,13 @@ function stamp3(file2, fields2) {
|
|
|
49194
49392
|
return !key || fields2[key[1]] === void 0;
|
|
49195
49393
|
});
|
|
49196
49394
|
const added = Object.entries(fields2).flatMap(([key, value]) => value === null ? [] : [`${key}: ${yamlScalar(value)}`]);
|
|
49197
|
-
|
|
49395
|
+
fs47.writeFileSync(file2, ["---", ...kept2, ...added, ...lines.slice(close)].join("\n"));
|
|
49198
49396
|
}
|
|
49199
49397
|
function moveSignal(from, into, fields2) {
|
|
49200
|
-
if (!
|
|
49201
|
-
|
|
49398
|
+
if (!fs47.existsSync(from)) return "";
|
|
49399
|
+
fs47.mkdirSync(into, { recursive: true });
|
|
49202
49400
|
const at = path51.join(into, freeName(into, path51.basename(from)));
|
|
49203
|
-
|
|
49401
|
+
fs47.renameSync(from, at);
|
|
49204
49402
|
stamp3(at, fields2);
|
|
49205
49403
|
return boardRel(at);
|
|
49206
49404
|
}
|
|
@@ -49448,12 +49646,12 @@ var init_studio_cards = __esm({
|
|
|
49448
49646
|
});
|
|
49449
49647
|
|
|
49450
49648
|
// src/lib/readme.ts
|
|
49451
|
-
import
|
|
49649
|
+
import fs48 from "node:fs";
|
|
49452
49650
|
import path52 from "node:path";
|
|
49453
49651
|
function stripReadmeRefs(target) {
|
|
49454
|
-
if (!
|
|
49652
|
+
if (!fs48.existsSync(README)) return [];
|
|
49455
49653
|
const needle = target.kind === "group" ? `](${target.rel}/` : `](${target.rel})`;
|
|
49456
|
-
const lines =
|
|
49654
|
+
const lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49457
49655
|
const out = [];
|
|
49458
49656
|
const removed = [];
|
|
49459
49657
|
let i = 0;
|
|
@@ -49475,20 +49673,20 @@ function stripReadmeRefs(target) {
|
|
|
49475
49673
|
out.push(line);
|
|
49476
49674
|
i++;
|
|
49477
49675
|
}
|
|
49478
|
-
if (removed.length)
|
|
49676
|
+
if (removed.length) fs48.writeFileSync(README, out.join("\n"));
|
|
49479
49677
|
return removed;
|
|
49480
49678
|
}
|
|
49481
49679
|
function addReadmeRef(id2, title, relPath) {
|
|
49482
|
-
if (!
|
|
49680
|
+
if (!fs48.existsSync(README)) return false;
|
|
49483
49681
|
const link2 = relPath.split(path52.sep).join("/");
|
|
49484
49682
|
const bullet = `- [#${id2} ${title}](${link2})`;
|
|
49485
49683
|
const heading = `## ${TASKS_HEADING}`;
|
|
49486
|
-
let lines =
|
|
49684
|
+
let lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49487
49685
|
const hi = lines.findIndex((l) => l.trim().toLowerCase() === heading.toLowerCase());
|
|
49488
49686
|
if (hi === -1) {
|
|
49489
49687
|
while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
|
|
49490
49688
|
lines.push("", heading, "", bullet);
|
|
49491
|
-
|
|
49689
|
+
fs48.writeFileSync(README, lines.join("\n") + "\n");
|
|
49492
49690
|
return true;
|
|
49493
49691
|
}
|
|
49494
49692
|
let end2 = hi + 1;
|
|
@@ -49502,15 +49700,15 @@ function addReadmeRef(id2, title, relPath) {
|
|
|
49502
49700
|
const at = lastBullet !== -1 ? lastBullet + 1 : lines[hi + 1] === "" ? hi + 2 : hi + 1;
|
|
49503
49701
|
lines.splice(at, 0, bullet);
|
|
49504
49702
|
}
|
|
49505
|
-
|
|
49703
|
+
fs48.writeFileSync(README, lines.join("\n"));
|
|
49506
49704
|
return true;
|
|
49507
49705
|
}
|
|
49508
49706
|
function repointReadmeLink(id2, oldRel, newRel, title) {
|
|
49509
|
-
if (!
|
|
49707
|
+
if (!fs48.existsSync(README)) return false;
|
|
49510
49708
|
const oldLink = oldRel.split(path52.sep).join("/");
|
|
49511
49709
|
const newLink = newRel.split(path52.sep).join("/");
|
|
49512
49710
|
const linkRe = new RegExp(`\\[#${id2}\\b[^\\]]*\\]\\(${escapeRegex2(oldLink)}\\)`);
|
|
49513
|
-
const lines =
|
|
49711
|
+
const lines = fs48.readFileSync(README, "utf8").split("\n");
|
|
49514
49712
|
let changed = false;
|
|
49515
49713
|
for (let i = 0; i < lines.length; i++) {
|
|
49516
49714
|
if (!lines[i].includes(`](${oldLink})`)) continue;
|
|
@@ -49520,7 +49718,7 @@ function repointReadmeLink(id2, oldRel, newRel, title) {
|
|
|
49520
49718
|
changed = true;
|
|
49521
49719
|
}
|
|
49522
49720
|
}
|
|
49523
|
-
if (changed)
|
|
49721
|
+
if (changed) fs48.writeFileSync(README, lines.join("\n"));
|
|
49524
49722
|
return changed;
|
|
49525
49723
|
}
|
|
49526
49724
|
var isTableRow, isBulletStart, bulletIndent, TASKS_HEADING, escapeRegex2;
|
|
@@ -50196,16 +50394,16 @@ var init_collect = __esm({
|
|
|
50196
50394
|
});
|
|
50197
50395
|
|
|
50198
50396
|
// src/lib/dress-page.ts
|
|
50199
|
-
import
|
|
50397
|
+
import fs49 from "node:fs";
|
|
50200
50398
|
import path53 from "node:path";
|
|
50201
50399
|
function dressPage(file2) {
|
|
50202
50400
|
const folder2 = path53.dirname(file2);
|
|
50203
|
-
const html =
|
|
50401
|
+
const html = fs49.readFileSync(file2, "utf8").replace(/<link\b[^>]*>/gi, (tag) => {
|
|
50204
50402
|
const href = /\bhref\s*=\s*["']?([^"'\s>]+)/i.exec(tag)?.[1];
|
|
50205
50403
|
if (!/\brel\s*=\s*["']?stylesheet/i.test(tag) || !href || /^[a-z][\w+.-]*:|^\/\//i.test(href)) return tag;
|
|
50206
50404
|
const at2 = path53.resolve(folder2, href);
|
|
50207
|
-
if (!at2.startsWith(folder2 + path53.sep) || !
|
|
50208
|
-
const css =
|
|
50405
|
+
if (!at2.startsWith(folder2 + path53.sep) || !fs49.existsSync(at2)) return tag;
|
|
50406
|
+
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
50407
|
return `<style>${css.replace(/\r?\n/g, " ").replace(/<\/style/gi, "<\\/style")}</style>`;
|
|
50210
50408
|
});
|
|
50211
50409
|
const at = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype\b[^>]*>)?/i.exec(html)[0].length;
|
|
@@ -50218,25 +50416,25 @@ var init_dress_page = __esm({
|
|
|
50218
50416
|
isHtmlFile = (file2) => /\.html?$/i.test(file2);
|
|
50219
50417
|
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
50418
|
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) :
|
|
50419
|
+
referenceText = (file2) => isHtmlFile(file2) ? dressPage(file2) : fs49.readFileSync(file2, "utf8");
|
|
50222
50420
|
}
|
|
50223
50421
|
});
|
|
50224
50422
|
|
|
50225
50423
|
// src/lib/preview-files.ts
|
|
50226
|
-
import
|
|
50424
|
+
import fs50 from "node:fs";
|
|
50227
50425
|
import path54 from "node:path";
|
|
50228
50426
|
function resolver(card, id2) {
|
|
50229
50427
|
const roots = [KANBAN, path54.join(ASSETS, String(id2))];
|
|
50230
|
-
const real2 = (p) =>
|
|
50428
|
+
const real2 = (p) => fs50.existsSync(p) ? fs50.realpathSync(p) : p;
|
|
50231
50429
|
const inside2 = (p) => roots.some((root2) => p.startsWith(real2(root2) + path54.sep));
|
|
50232
50430
|
return (src, owner) => {
|
|
50233
50431
|
if (/^[a-z][\w+.-]*:/i.test(src) || src.startsWith("#") || src.startsWith("//")) return null;
|
|
50234
50432
|
if (path54.isAbsolute(src)) throw new Error("an absolute path; name it relative to the file");
|
|
50235
50433
|
const held4 = /^\.assets\//.exec(src);
|
|
50236
50434
|
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:
|
|
50435
|
+
if (!inside2(path54.resolve(file2)) || fs50.existsSync(file2) && !inside2(fs50.realpathSync(file2))) throw new Error(`outside this card's files (${rel(KANBAN)}, .assets/${id2}/)`);
|
|
50436
|
+
if (!fs50.statSync(file2, { throwIfNoEntry: false })?.isFile()) throw new Error("no such file");
|
|
50437
|
+
return { key: fs50.realpathSync(file2), file: file2 };
|
|
50240
50438
|
};
|
|
50241
50439
|
}
|
|
50242
50440
|
function validatePreviewFiles(card, id2, text5) {
|
|
@@ -50279,7 +50477,7 @@ var init_preview_files = __esm({
|
|
|
50279
50477
|
});
|
|
50280
50478
|
|
|
50281
50479
|
// src/lib/spec-contract.ts
|
|
50282
|
-
import
|
|
50480
|
+
import fs51 from "node:fs";
|
|
50283
50481
|
import path55 from "node:path";
|
|
50284
50482
|
function scanCardLines(lines, start = 0) {
|
|
50285
50483
|
const visible = lines.map(() => "");
|
|
@@ -50313,11 +50511,11 @@ function scanCardLines(lines, start = 0) {
|
|
|
50313
50511
|
}
|
|
50314
50512
|
function snapshotSpecs() {
|
|
50315
50513
|
const out = /* @__PURE__ */ new Map();
|
|
50316
|
-
if (!
|
|
50514
|
+
if (!fs51.existsSync(TODO)) return out;
|
|
50317
50515
|
for (const file2 of walkMd(TODO)) {
|
|
50318
50516
|
if (isLegacyRecurring(path55.relative(TODO, file2))) continue;
|
|
50319
50517
|
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:
|
|
50518
|
+
if (id2 !== null) out.set(file2, { id: id2, text: fs51.readFileSync(file2, "utf8") });
|
|
50321
50519
|
}
|
|
50322
50520
|
return out;
|
|
50323
50521
|
}
|
|
@@ -50511,9 +50709,9 @@ function setEnd(lines, at) {
|
|
|
50511
50709
|
}
|
|
50512
50710
|
function inside(dir, name) {
|
|
50513
50711
|
try {
|
|
50514
|
-
const root2 =
|
|
50515
|
-
const real2 =
|
|
50516
|
-
return real2.startsWith(root2 + path55.sep) &&
|
|
50712
|
+
const root2 = fs51.realpathSync(dir);
|
|
50713
|
+
const real2 = fs51.realpathSync(path55.join(dir, name));
|
|
50714
|
+
return real2.startsWith(root2 + path55.sep) && fs51.statSync(real2).isFile() ? real2 : null;
|
|
50517
50715
|
} catch {
|
|
50518
50716
|
return null;
|
|
50519
50717
|
}
|
|
@@ -50546,7 +50744,7 @@ function compareProblem(attrs, id2) {
|
|
|
50546
50744
|
const shots = (message) => ({ rule: "compare-shots", message });
|
|
50547
50745
|
const json2 = (file2) => {
|
|
50548
50746
|
try {
|
|
50549
|
-
return file2.endsWith(".json") ? JSON.parse(
|
|
50747
|
+
return file2.endsWith(".json") ? JSON.parse(fs51.readFileSync(file2, "utf8")) : null;
|
|
50550
50748
|
} catch {
|
|
50551
50749
|
return null;
|
|
50552
50750
|
}
|
|
@@ -50571,7 +50769,7 @@ function compareProblem(attrs, id2) {
|
|
|
50571
50769
|
const file2 = inside(dir, named2.name);
|
|
50572
50770
|
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
50771
|
try {
|
|
50574
|
-
return { data: JSON.parse(
|
|
50772
|
+
return { data: JSON.parse(fs51.readFileSync(file2, "utf8")) };
|
|
50575
50773
|
} catch {
|
|
50576
50774
|
return { message: `${at} is not valid JSON.` };
|
|
50577
50775
|
}
|
|
@@ -50626,7 +50824,7 @@ var init_spec_contract = __esm({
|
|
|
50626
50824
|
});
|
|
50627
50825
|
|
|
50628
50826
|
// src/lib/reconcile.ts
|
|
50629
|
-
import
|
|
50827
|
+
import fs52 from "node:fs";
|
|
50630
50828
|
import path56 from "node:path";
|
|
50631
50829
|
function liveIds() {
|
|
50632
50830
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -50642,7 +50840,7 @@ function indexableCards() {
|
|
|
50642
50840
|
const out = [];
|
|
50643
50841
|
for (const dir of walkDirs(TODO)) {
|
|
50644
50842
|
const id2 = idPrefix(path56.basename(dir));
|
|
50645
|
-
if (id2 != null &&
|
|
50843
|
+
if (id2 != null && fs52.existsSync(path56.join(dir, "root.md"))) {
|
|
50646
50844
|
out.push({ id: id2, rel: path56.join(path56.relative(TODO, dir), "root.md").split(path56.sep).join("/") });
|
|
50647
50845
|
}
|
|
50648
50846
|
}
|
|
@@ -50659,7 +50857,7 @@ function indexableCards() {
|
|
|
50659
50857
|
}
|
|
50660
50858
|
function readmeComplaints(fix) {
|
|
50661
50859
|
const said2 = [];
|
|
50662
|
-
const lines =
|
|
50860
|
+
const lines = fs52.readFileSync(README, "utf8").split("\n");
|
|
50663
50861
|
const indexed = /* @__PURE__ */ new Set();
|
|
50664
50862
|
let fixed = 0;
|
|
50665
50863
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -50668,7 +50866,7 @@ function readmeComplaints(fix) {
|
|
|
50668
50866
|
const id2 = Number(m[1]);
|
|
50669
50867
|
const linkPath = m[2];
|
|
50670
50868
|
indexed.add(id2);
|
|
50671
|
-
if (
|
|
50869
|
+
if (fs52.existsSync(path56.join(TODO, linkPath))) continue;
|
|
50672
50870
|
const found2 = locate(id2);
|
|
50673
50871
|
if (!found2) {
|
|
50674
50872
|
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 +50882,7 @@ function readmeComplaints(fix) {
|
|
|
50684
50882
|
said2.push(`README link #${id2} pointed at missing ${linkPath} \u2192 repointed to ${want}.`);
|
|
50685
50883
|
fixed++;
|
|
50686
50884
|
}
|
|
50687
|
-
if (fixed)
|
|
50885
|
+
if (fixed) fs52.writeFileSync(README, lines.join("\n"));
|
|
50688
50886
|
for (const c of indexableCards()) {
|
|
50689
50887
|
if (!indexed.has(c.id)) {
|
|
50690
50888
|
said2.push(`card ${c.rel} (#${c.id}) is not in the README index. Add it under "## ${TASKS_HEADING}".`);
|
|
@@ -50700,7 +50898,7 @@ function crossRefComplaints() {
|
|
|
50700
50898
|
if (base === "README.md") continue;
|
|
50701
50899
|
const ownerId = base === "root.md" ? idPrefix(path56.basename(path56.dirname(file2))) : idPrefix(base);
|
|
50702
50900
|
if (ownerId == null) continue;
|
|
50703
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
50901
|
+
const { meta: meta3 } = parseFrontmatter(fs52.readFileSync(file2, "utf8"));
|
|
50704
50902
|
if (!meta3) continue;
|
|
50705
50903
|
for (const field2 of ["blocked_by", "related"]) {
|
|
50706
50904
|
for (const ref of meta3[field2] || []) {
|
|
@@ -50713,7 +50911,7 @@ function crossRefComplaints() {
|
|
|
50713
50911
|
return said2;
|
|
50714
50912
|
}
|
|
50715
50913
|
function reconcileBoard() {
|
|
50716
|
-
if (!
|
|
50914
|
+
if (!fs52.existsSync(README)) return;
|
|
50717
50915
|
for (const line of [...readmeComplaints(true), ...crossRefComplaints()]) warn2(line);
|
|
50718
50916
|
}
|
|
50719
50917
|
var README_LINK;
|
|
@@ -50729,7 +50927,7 @@ var init_reconcile = __esm({
|
|
|
50729
50927
|
});
|
|
50730
50928
|
|
|
50731
50929
|
// src/commands/card.ts
|
|
50732
|
-
import
|
|
50930
|
+
import fs53 from "node:fs";
|
|
50733
50931
|
import path57 from "node:path";
|
|
50734
50932
|
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
50933
|
return [
|
|
@@ -50756,7 +50954,7 @@ function bodyFromFile(opts) {
|
|
|
50756
50954
|
if (opts.body === false) die("pass --body-file or --no-body, not both");
|
|
50757
50955
|
let text5;
|
|
50758
50956
|
try {
|
|
50759
|
-
text5 =
|
|
50957
|
+
text5 = fs53.readFileSync(opts.bodyFile, "utf8");
|
|
50760
50958
|
} catch {
|
|
50761
50959
|
die(`can't read ${opts.bodyFile} \u2014 write the body to a file, then pass its path`, { kind: "needs-input" });
|
|
50762
50960
|
}
|
|
@@ -50828,12 +51026,12 @@ function cmdCreate(opts) {
|
|
|
50828
51026
|
return { id: start, ids: [start], title, file: rel(held4.target), indexed: false };
|
|
50829
51027
|
}
|
|
50830
51028
|
if (held4) die(`#${start} is already a card here (${rel(held4.target)})`, { kind: "id-taken", id: start });
|
|
50831
|
-
if (
|
|
51029
|
+
if (fs53.existsSync(file2)) die(`${rel(file2)} already exists \u2014 pick a different --slug`);
|
|
50832
51030
|
countBoardEvent(triage ? "cards_created_proposed" : "cards_created_asked");
|
|
50833
51031
|
const meta3 = { title, priority, status: "todo", blocked_by, related, modules, studio, previews, triage, source: source2, questions };
|
|
50834
51032
|
const scaffolded = !written && opts.body !== false;
|
|
50835
51033
|
const body = written ?? (scaffolded ? defaultBody() : "");
|
|
50836
|
-
|
|
51034
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n\n" + body);
|
|
50837
51035
|
const indexed = addReadmeRef(start, title, fileRel);
|
|
50838
51036
|
say(start);
|
|
50839
51037
|
say(
|
|
@@ -50886,7 +51084,7 @@ function cmdUpdate(id2, flags) {
|
|
|
50886
51084
|
const found2 = locate(id2);
|
|
50887
51085
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
50888
51086
|
const file2 = found2.kind === "group" ? path57.join(found2.target, "root.md") : found2.target;
|
|
50889
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51087
|
+
const { meta: meta3, body } = parseFrontmatter(fs53.readFileSync(file2, "utf8"));
|
|
50890
51088
|
if (!meta3) die(`${rel(file2)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
|
|
50891
51089
|
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
51090
|
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 +51160,9 @@ function cmdUpdate(id2, flags) {
|
|
|
50962
51160
|
const destRel = path57.join(path57.dirname(curRel), base);
|
|
50963
51161
|
const dest = path57.join(TODO, destRel);
|
|
50964
51162
|
const moving = dest !== file2;
|
|
50965
|
-
if (moving &&
|
|
50966
|
-
|
|
50967
|
-
if (moving)
|
|
51163
|
+
if (moving && fs53.existsSync(dest)) die(`${rel(dest)} already exists`);
|
|
51164
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n" + body);
|
|
51165
|
+
if (moving) fs53.renameSync(file2, dest);
|
|
50968
51166
|
if (isSubtask) {
|
|
50969
51167
|
if (moving || changes.includes("title")) repointReadmeLink(id2, curRel, destRel, meta3.title);
|
|
50970
51168
|
if (moving) changes.push(`renamed \u2192 ${destRel.split(path57.sep).join("/")}`);
|
|
@@ -50986,7 +51184,7 @@ function updateCardQuestions(id2, ops, compatibility = false) {
|
|
|
50986
51184
|
const found2 = locate(id2);
|
|
50987
51185
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
50988
51186
|
const file2 = found2.kind === "group" ? path57.join(found2.target, "root.md") : found2.target;
|
|
50989
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51187
|
+
const { meta: meta3, body } = parseFrontmatter(fs53.readFileSync(file2, "utf8"));
|
|
50990
51188
|
if (!meta3) die(`${rel(file2)} has no frontmatter \u2014 recreate it with \`akb raw create\``);
|
|
50991
51189
|
for (const op of ops) {
|
|
50992
51190
|
if (!compatibility || !op.question?.agent) continue;
|
|
@@ -51008,7 +51206,7 @@ function updateCardQuestions(id2, ops, compatibility = false) {
|
|
|
51008
51206
|
meta3.status = "todo";
|
|
51009
51207
|
changes.push("status\u2192todo (open questions)");
|
|
51010
51208
|
}
|
|
51011
|
-
|
|
51209
|
+
fs53.writeFileSync(file2, serializeFrontmatter(meta3) + "\n" + body);
|
|
51012
51210
|
const closed2 = activeDelivery(id2) ? "questions_closed_verify" : "questions_closed_user";
|
|
51013
51211
|
for (const _ of done.closed) countBoardEvent(closed2);
|
|
51014
51212
|
say(`updated #${id2} questions: ${changes.join(", ")} (${open4} open)`);
|
|
@@ -51067,7 +51265,7 @@ var init_config_template = __esm({
|
|
|
51067
51265
|
});
|
|
51068
51266
|
|
|
51069
51267
|
// src/commands/init.ts
|
|
51070
|
-
import
|
|
51268
|
+
import fs54 from "node:fs";
|
|
51071
51269
|
function boardReadme() {
|
|
51072
51270
|
return `# Board
|
|
51073
51271
|
|
|
@@ -51080,20 +51278,20 @@ _(none)_
|
|
|
51080
51278
|
`;
|
|
51081
51279
|
}
|
|
51082
51280
|
function writeConfigIfMissing() {
|
|
51083
|
-
if (
|
|
51084
|
-
|
|
51085
|
-
|
|
51281
|
+
if (fs54.existsSync(CONFIG)) return false;
|
|
51282
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51283
|
+
fs54.writeFileSync(CONFIG, CONFIG_TEMPLATE);
|
|
51086
51284
|
return true;
|
|
51087
51285
|
}
|
|
51088
51286
|
function writeModulesIfMissing() {
|
|
51089
|
-
if (
|
|
51090
|
-
|
|
51091
|
-
|
|
51287
|
+
if (fs54.existsSync(MODULES_MD)) return false;
|
|
51288
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51289
|
+
fs54.writeFileSync(MODULES_MD, MODULES_TEMPLATE);
|
|
51092
51290
|
return true;
|
|
51093
51291
|
}
|
|
51094
51292
|
function writeGitignoreIfMissing() {
|
|
51095
|
-
|
|
51096
|
-
const text5 =
|
|
51293
|
+
fs54.mkdirSync(KANBAN, { recursive: true });
|
|
51294
|
+
const text5 = fs54.existsSync(KANBAN_GITIGNORE) ? fs54.readFileSync(KANBAN_GITIGNORE, "utf8") : "";
|
|
51097
51295
|
const has = (rule) => text5.split("\n").some((line) => line.trim() === rule.line);
|
|
51098
51296
|
const missing = IGNORE_RULES.filter((rule) => !has(rule));
|
|
51099
51297
|
if (!missing.length) return false;
|
|
@@ -51101,23 +51299,23 @@ function writeGitignoreIfMissing() {
|
|
|
51101
51299
|
${rule.line}
|
|
51102
51300
|
`).join("");
|
|
51103
51301
|
const separator = !text5 || text5.endsWith("\n") ? "" : "\n";
|
|
51104
|
-
|
|
51302
|
+
fs54.writeFileSync(KANBAN_GITIGNORE, `${text5}${separator}${block}`);
|
|
51105
51303
|
return true;
|
|
51106
51304
|
}
|
|
51107
51305
|
function writeSkeletonIfMissing() {
|
|
51108
51306
|
const added = [];
|
|
51109
|
-
if (!
|
|
51110
|
-
|
|
51307
|
+
if (!fs54.existsSync(TODO)) {
|
|
51308
|
+
fs54.mkdirSync(TODO, { recursive: true });
|
|
51111
51309
|
added.push(`${rel(TODO)}/`);
|
|
51112
51310
|
}
|
|
51113
|
-
if (!
|
|
51114
|
-
|
|
51311
|
+
if (!fs54.existsSync(README)) {
|
|
51312
|
+
fs54.writeFileSync(README, boardReadme());
|
|
51115
51313
|
added.push(rel(README));
|
|
51116
51314
|
}
|
|
51117
51315
|
return added;
|
|
51118
51316
|
}
|
|
51119
51317
|
function cmdInit() {
|
|
51120
|
-
if (
|
|
51318
|
+
if (fs54.existsSync(KANBAN)) {
|
|
51121
51319
|
const added = [
|
|
51122
51320
|
...writeSkeletonIfMissing(),
|
|
51123
51321
|
writeConfigIfMissing() && rel(CONFIG),
|
|
@@ -51134,8 +51332,8 @@ function cmdInit() {
|
|
|
51134
51332
|
}
|
|
51135
51333
|
return { board: rel(KANBAN), created: false, added, memory_paths: scaffolded.map((s) => rel(s.dir)) };
|
|
51136
51334
|
}
|
|
51137
|
-
|
|
51138
|
-
|
|
51335
|
+
fs54.mkdirSync(TODO, { recursive: true });
|
|
51336
|
+
fs54.writeFileSync(README, boardReadme());
|
|
51139
51337
|
writeConfigIfMissing();
|
|
51140
51338
|
scaffoldProjectMemory();
|
|
51141
51339
|
writeModulesIfMissing();
|
|
@@ -51170,15 +51368,15 @@ _(not filled in yet \u2014 build the map from the repo before tagging a card.)_
|
|
|
51170
51368
|
});
|
|
51171
51369
|
|
|
51172
51370
|
// src/lib/card-age.ts
|
|
51173
|
-
import
|
|
51371
|
+
import fs55 from "node:fs";
|
|
51174
51372
|
import path58 from "node:path";
|
|
51175
51373
|
function staleAfterIn(config2) {
|
|
51176
51374
|
const days = Number(LINE.exec(config2)?.[1]);
|
|
51177
51375
|
return Number.isInteger(days) && days > 0 ? days : STALE_AFTER_DEFAULT;
|
|
51178
51376
|
}
|
|
51179
51377
|
function staleAfter() {
|
|
51180
|
-
if (!
|
|
51181
|
-
return staleAfterIn(
|
|
51378
|
+
if (!fs55.existsSync(CONFIG)) return STALE_AFTER_DEFAULT;
|
|
51379
|
+
return staleAfterIn(fs55.readFileSync(CONFIG, "utf8"));
|
|
51182
51380
|
}
|
|
51183
51381
|
function todoPathspec(top) {
|
|
51184
51382
|
const from = path58.relative(real(top), real(TODO));
|
|
@@ -51235,7 +51433,7 @@ var init_card_age = __esm({
|
|
|
51235
51433
|
gitTop = () => git(["rev-parse", "--show-toplevel"])?.trim() || null;
|
|
51236
51434
|
real = (p) => {
|
|
51237
51435
|
try {
|
|
51238
|
-
return
|
|
51436
|
+
return fs55.realpathSync(p);
|
|
51239
51437
|
} catch {
|
|
51240
51438
|
return path58.resolve(p);
|
|
51241
51439
|
}
|
|
@@ -51271,7 +51469,7 @@ var init_card_holds = __esm({
|
|
|
51271
51469
|
});
|
|
51272
51470
|
|
|
51273
51471
|
// src/commands/list.ts
|
|
51274
|
-
import
|
|
51472
|
+
import fs56 from "node:fs";
|
|
51275
51473
|
import path59 from "node:path";
|
|
51276
51474
|
function summaryLine(body) {
|
|
51277
51475
|
const lines = body.split("\n");
|
|
@@ -51294,7 +51492,7 @@ function openRows() {
|
|
|
51294
51492
|
const id2 = isRoot ? idPrefix(path59.basename(path59.dirname(file2))) : idPrefix(base);
|
|
51295
51493
|
if (id2 == null) continue;
|
|
51296
51494
|
if (isLegacyRecurring(path59.relative(TODO, file2))) continue;
|
|
51297
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51495
|
+
const { meta: meta3, body } = parseFrontmatter(fs56.readFileSync(file2, "utf8"));
|
|
51298
51496
|
rows.push({
|
|
51299
51497
|
id: id2,
|
|
51300
51498
|
file: file2,
|
|
@@ -51336,7 +51534,7 @@ function cmdStale(rows, all2, scope, mod) {
|
|
|
51336
51534
|
}
|
|
51337
51535
|
function archivedFiles() {
|
|
51338
51536
|
const files = /* @__PURE__ */ new Map();
|
|
51339
|
-
if (!
|
|
51537
|
+
if (!fs56.existsSync(ARCHIVE)) return files;
|
|
51340
51538
|
for (const file2 of walkMd(ARCHIVE)) {
|
|
51341
51539
|
const id2 = idPrefix(path59.basename(file2));
|
|
51342
51540
|
if (id2 !== null) files.set(id2, file2);
|
|
@@ -51344,7 +51542,7 @@ function archivedFiles() {
|
|
|
51344
51542
|
for (const dir of walkDirs(ARCHIVE)) {
|
|
51345
51543
|
const id2 = idPrefix(path59.basename(dir));
|
|
51346
51544
|
const root2 = path59.join(dir, "root.md");
|
|
51347
|
-
if (id2 !== null &&
|
|
51545
|
+
if (id2 !== null && fs56.existsSync(root2)) files.set(id2, root2);
|
|
51348
51546
|
}
|
|
51349
51547
|
return files;
|
|
51350
51548
|
}
|
|
@@ -51442,10 +51640,10 @@ var init_list = __esm({
|
|
|
51442
51640
|
});
|
|
51443
51641
|
|
|
51444
51642
|
// src/lib/group-close.ts
|
|
51445
|
-
import
|
|
51643
|
+
import fs57 from "node:fs";
|
|
51446
51644
|
function groupCloses(rootFile) {
|
|
51447
51645
|
try {
|
|
51448
|
-
return groupCloseOf(
|
|
51646
|
+
return groupCloseOf(fs57.readFileSync(rootFile, "utf8"));
|
|
51449
51647
|
} catch {
|
|
51450
51648
|
return false;
|
|
51451
51649
|
}
|
|
@@ -51458,7 +51656,7 @@ var init_group_close = __esm({
|
|
|
51458
51656
|
});
|
|
51459
51657
|
|
|
51460
51658
|
// src/commands/remove.ts
|
|
51461
|
-
import
|
|
51659
|
+
import fs58 from "node:fs";
|
|
51462
51660
|
import path60 from "node:path";
|
|
51463
51661
|
function leavingIds(id2, found2) {
|
|
51464
51662
|
const ids = /* @__PURE__ */ new Set([id2]);
|
|
@@ -51475,10 +51673,10 @@ function findMentions(ids) {
|
|
|
51475
51673
|
const hits = [];
|
|
51476
51674
|
const re = new RegExp(ids.map((id2) => `#${id2}(?!\\d)`).join("|"));
|
|
51477
51675
|
for (const dir of [TODO, MEMORY]) {
|
|
51478
|
-
if (!
|
|
51676
|
+
if (!fs58.existsSync(dir)) continue;
|
|
51479
51677
|
for (const file2 of walkMd(dir)) {
|
|
51480
51678
|
if (path60.basename(file2) === "README.md") continue;
|
|
51481
|
-
const lines =
|
|
51679
|
+
const lines = fs58.readFileSync(file2, "utf8").split("\n");
|
|
51482
51680
|
const fmEnd = frontmatterEnd(lines);
|
|
51483
51681
|
lines.forEach((line, i) => {
|
|
51484
51682
|
if (!re.test(line)) return;
|
|
@@ -51508,10 +51706,10 @@ function stampLeaving(cards, rejection) {
|
|
|
51508
51706
|
const day = formatDay();
|
|
51509
51707
|
const stamp4 = rejection && !rejection.discard ? { reason: rejection.reason, at: (/* @__PURE__ */ new Date()).toISOString(), by: insideRun() || workspaceTask() ? "agent" : "user" } : rejection && { reason: rejection.reason };
|
|
51510
51708
|
for (const card of cards) {
|
|
51511
|
-
if (!
|
|
51512
|
-
const text5 =
|
|
51709
|
+
if (!fs58.existsSync(card.file)) continue;
|
|
51710
|
+
const text5 = fs58.readFileSync(card.file, "utf8");
|
|
51513
51711
|
const stamped = stampLeavingIn(text5, day, stamp4);
|
|
51514
|
-
if (stamped !== text5)
|
|
51712
|
+
if (stamped !== text5) fs58.writeFileSync(card.file, stamped);
|
|
51515
51713
|
}
|
|
51516
51714
|
}
|
|
51517
51715
|
function agentDecisions(text5) {
|
|
@@ -51541,14 +51739,14 @@ function removeCard(id2, metric, options) {
|
|
|
51541
51739
|
if (!found2) die(`no task with id ${id2} under ${rel(TODO)}`, { kind: "card-not-found", id: id2 });
|
|
51542
51740
|
const dest = options.cleanupDiscarded && locateArchived(id2) ? null : archiveDest(found2);
|
|
51543
51741
|
const cardFile3 = found2.kind === "group" ? path60.join(found2.target, "root.md") : found2.target;
|
|
51544
|
-
const cardText =
|
|
51742
|
+
const cardText = fs58.existsSync(cardFile3) ? fs58.readFileSync(cardFile3, "utf8") : "";
|
|
51545
51743
|
const { meta: cardMeta3 } = parseFrontmatter(cardText);
|
|
51546
51744
|
const alsoRemoved = found2.kind === "group" ? walkMd(found2.target).filter((f) => f !== cardFile3).map((f) => rel(f)).sort() : [];
|
|
51547
51745
|
const leftIds = leavingIds(id2, found2);
|
|
51548
51746
|
const leaving = leavingCards(id2, found2);
|
|
51549
51747
|
if (options.archivingTask) {
|
|
51550
51748
|
for (const card of leaving) {
|
|
51551
|
-
const meta3 = parseFrontmatter(
|
|
51749
|
+
const meta3 = parseFrontmatter(fs58.readFileSync(card.file, "utf8")).meta;
|
|
51552
51750
|
if (!meta3 || meta3.rejected) die(`#${card.id} is not eligible for archive.`, { kind: "conflict" });
|
|
51553
51751
|
if (meta3.questions.length) die(`Resolve the open questions on #${card.id} before archiving.`, { kind: "conflict" });
|
|
51554
51752
|
if (card.id !== id2 && (activeDelivery(card.id) || creationRefusal(card.id, cardCreation(card.id), "archive", false))) {
|
|
@@ -51582,10 +51780,10 @@ function removeCard(id2, metric, options) {
|
|
|
51582
51780
|
const groupRoot = found2.kind === "file" && !options.closing ? enclosingGroupRoot(found2.target) : null;
|
|
51583
51781
|
if (dest) {
|
|
51584
51782
|
stampLeaving(leaving, metric === "rejected" ? { reason: options.reason?.trim() ?? "", discard: options.discard === true } : null);
|
|
51585
|
-
|
|
51586
|
-
|
|
51783
|
+
fs58.mkdirSync(ARCHIVE, { recursive: true });
|
|
51784
|
+
fs58.renameSync(found2.target, dest);
|
|
51587
51785
|
} else {
|
|
51588
|
-
|
|
51786
|
+
fs58.rmSync(found2.target, { recursive: true, force: true });
|
|
51589
51787
|
}
|
|
51590
51788
|
const removedRefs = stripReadmeRefs(found2);
|
|
51591
51789
|
let marked2 = null;
|
|
@@ -51641,7 +51839,7 @@ function closeGroup(rootFile) {
|
|
|
51641
51839
|
say(`
|
|
51642
51840
|
every subtask line on #${rootId} is resolved \u2014 closing the group:`);
|
|
51643
51841
|
try {
|
|
51644
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
51842
|
+
const { meta: meta3, body } = parseFrontmatter(fs58.readFileSync(rootFile, "utf8"));
|
|
51645
51843
|
const res = cmdRemove(rootId, "completed", { closing: true });
|
|
51646
51844
|
return {
|
|
51647
51845
|
id: rootId,
|
|
@@ -51705,7 +51903,7 @@ function recoveredArchiveHandoff(id2, source2) {
|
|
|
51705
51903
|
const found2 = locateArchived(id2);
|
|
51706
51904
|
if (!found2) throw new Error(`No archived card #${id2} was found.`);
|
|
51707
51905
|
const file2 = found2.kind === "group" ? path60.join(found2.target, "root.md") : found2.target;
|
|
51708
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
51906
|
+
const { meta: meta3 } = parseFrontmatter(fs58.readFileSync(file2, "utf8"));
|
|
51709
51907
|
stripReadmeRefs(source2 ?? found2);
|
|
51710
51908
|
const root2 = source2?.kind === "file" ? enclosingGroupRoot(source2.target) : null;
|
|
51711
51909
|
if (root2) markSubtask(root2, id2, "tick");
|
|
@@ -51824,7 +52022,7 @@ var init_bundled2 = __esm({
|
|
|
51824
52022
|
});
|
|
51825
52023
|
|
|
51826
52024
|
// src/lib/memories.ts
|
|
51827
|
-
import
|
|
52025
|
+
import fs59 from "node:fs";
|
|
51828
52026
|
import path61 from "node:path";
|
|
51829
52027
|
function readMemory(text5, builtIn, folder2) {
|
|
51830
52028
|
const { meta: meta3, body } = splitFrontmatter(text5);
|
|
@@ -51856,14 +52054,14 @@ function globalMemories() {
|
|
|
51856
52054
|
}
|
|
51857
52055
|
let folders2 = [];
|
|
51858
52056
|
try {
|
|
51859
|
-
folders2 =
|
|
52057
|
+
folders2 = fs59.readdirSync(MEMORY, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
51860
52058
|
} catch {
|
|
51861
52059
|
}
|
|
51862
52060
|
for (const name of folders2) {
|
|
51863
52061
|
if (name in BUNDLED_MEMORY_FILES || name === RESERVED_MEMORY_DIR || name === STUDIO_MEMORY_DIR) continue;
|
|
51864
52062
|
const file2 = path61.join(MEMORY, name, GLOBAL_MEMORY_FILE);
|
|
51865
|
-
if (!
|
|
51866
|
-
const memory = readMemory(
|
|
52063
|
+
if (!fs59.existsSync(file2)) continue;
|
|
52064
|
+
const memory = readMemory(fs59.readFileSync(file2, "utf8"), false, name);
|
|
51867
52065
|
if (memory) out.push(memory);
|
|
51868
52066
|
}
|
|
51869
52067
|
return out;
|
|
@@ -51904,7 +52102,7 @@ var init_memory_file = __esm({
|
|
|
51904
52102
|
});
|
|
51905
52103
|
|
|
51906
52104
|
// src/commands/inspect.ts
|
|
51907
|
-
import
|
|
52105
|
+
import fs60 from "node:fs";
|
|
51908
52106
|
import os4 from "node:os";
|
|
51909
52107
|
import path62 from "node:path";
|
|
51910
52108
|
function cmdInspect(id2) {
|
|
@@ -51912,7 +52110,7 @@ function cmdInspect(id2) {
|
|
|
51912
52110
|
const unavailable = [];
|
|
51913
52111
|
function read5(source2, file3, empty) {
|
|
51914
52112
|
try {
|
|
51915
|
-
return JSON.parse(
|
|
52113
|
+
return JSON.parse(fs60.readFileSync(file3, "utf8"));
|
|
51916
52114
|
} catch (error62) {
|
|
51917
52115
|
if (error62.code === "ENOENT") return empty;
|
|
51918
52116
|
findings.push({ source: source2, message: String(error62) });
|
|
@@ -51934,7 +52132,7 @@ function cmdInspect(id2) {
|
|
|
51934
52132
|
const file2 = found2.kind === "group" ? path62.join(found2.target, "root.md") : found2.target;
|
|
51935
52133
|
let card = null;
|
|
51936
52134
|
try {
|
|
51937
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
52135
|
+
const { meta: meta3, body } = parseFrontmatter(fs60.readFileSync(file2, "utf8"));
|
|
51938
52136
|
if (!meta3) throw Error("The card frontmatter could not be parsed.");
|
|
51939
52137
|
card = { path: rel(file2), questions: meta3.questions, todos: [...body.matchAll(/^\s*[-*]\s+\[([ xX])\]\s+(.*)$/gm)].map((m) => ({ text: m[2], done: m[1] !== " " })) };
|
|
51940
52138
|
} catch (error62) {
|
|
@@ -51947,7 +52145,7 @@ function cmdInspect(id2) {
|
|
|
51947
52145
|
const records = [];
|
|
51948
52146
|
const directory = path62.join(KANBAN, "deliveries");
|
|
51949
52147
|
try {
|
|
51950
|
-
for (const name of
|
|
52148
|
+
for (const name of fs60.readdirSync(directory).filter((name2) => name2.endsWith(".json"))) {
|
|
51951
52149
|
const held5 = read5("delivery", path62.join(directory, name), null);
|
|
51952
52150
|
if (held5?.cardId === id2) records.push(held5);
|
|
51953
52151
|
}
|
|
@@ -52001,7 +52199,7 @@ function cmdValidate(id2) {
|
|
|
52001
52199
|
const reason = errors.length ? formatContractErrors(errors) : void 0;
|
|
52002
52200
|
const session = insideRun();
|
|
52003
52201
|
if (session) patch(session, (run3) => {
|
|
52004
|
-
run3.validationFailure = reason ? { code: "validation_failed",
|
|
52202
|
+
run3.validationFailure = reason ? makeFailure("validation", reason, { code: "validation_failed", detail: reason }) : void 0;
|
|
52005
52203
|
});
|
|
52006
52204
|
if (reason) die(reason, { kind: "spec-contract", errors });
|
|
52007
52205
|
say(`Spec format valid (${cards.length} card${cards.length === 1 ? "" : "s"}).`);
|
|
@@ -52010,6 +52208,7 @@ function cmdValidate(id2) {
|
|
|
52010
52208
|
var init_validate2 = __esm({
|
|
52011
52209
|
"src/commands/validate.ts"() {
|
|
52012
52210
|
"use strict";
|
|
52211
|
+
init_retry();
|
|
52013
52212
|
init_env();
|
|
52014
52213
|
init_sessions();
|
|
52015
52214
|
init_io();
|
|
@@ -52019,7 +52218,7 @@ var init_validate2 = __esm({
|
|
|
52019
52218
|
});
|
|
52020
52219
|
|
|
52021
52220
|
// src/lib/card-sources.ts
|
|
52022
|
-
import
|
|
52221
|
+
import fs61 from "node:fs";
|
|
52023
52222
|
import path63 from "node:path";
|
|
52024
52223
|
function planById(id2) {
|
|
52025
52224
|
const found2 = readPlan(`plans/${id2}-.md`);
|
|
@@ -52031,7 +52230,7 @@ function cardLink(id2) {
|
|
|
52031
52230
|
if (!found2) return null;
|
|
52032
52231
|
try {
|
|
52033
52232
|
const file2 = found2.kind === "group" ? path63.join(found2.target, "root.md") : found2.target;
|
|
52034
|
-
const title = parseFrontmatter(
|
|
52233
|
+
const title = parseFrontmatter(fs61.readFileSync(file2, "utf8")).meta?.title ?? "";
|
|
52035
52234
|
return { kind: "card", ref: String(id2), title, ...open4 ? {} : { archived: true } };
|
|
52036
52235
|
} catch {
|
|
52037
52236
|
return null;
|
|
@@ -52094,7 +52293,7 @@ var init_card_sources = __esm({
|
|
|
52094
52293
|
});
|
|
52095
52294
|
|
|
52096
52295
|
// src/lib/view/read.ts
|
|
52097
|
-
import
|
|
52296
|
+
import fs62 from "node:fs";
|
|
52098
52297
|
import path64 from "node:path";
|
|
52099
52298
|
function readCard(file2, relFromTodo) {
|
|
52100
52299
|
const id2 = idPrefix(path64.basename(relFromTodo));
|
|
@@ -52107,7 +52306,7 @@ function readCard(file2, relFromTodo) {
|
|
|
52107
52306
|
return buildCard(id2, file2, relFromTodo);
|
|
52108
52307
|
}
|
|
52109
52308
|
function buildCard(id2, file2, relFromTodo) {
|
|
52110
|
-
const text5 =
|
|
52309
|
+
const text5 = fs62.readFileSync(file2, "utf8");
|
|
52111
52310
|
const { meta: meta3, body } = parseFrontmatter(text5);
|
|
52112
52311
|
if (!meta3) return null;
|
|
52113
52312
|
const relPath = relFromTodo.split(path64.sep).join("/");
|
|
@@ -52118,7 +52317,7 @@ function buildCard(id2, file2, relFromTodo) {
|
|
|
52118
52317
|
// Derived from the file exactly as it is on disk (lib/board/revision.ts), so a card
|
|
52119
52318
|
// read here and a card read by the contract agree on what version this is.
|
|
52120
52319
|
revision: revisionOf(text5),
|
|
52121
|
-
updatedAt:
|
|
52320
|
+
updatedAt: fs62.statSync(file2).mtime.toISOString(),
|
|
52122
52321
|
relPath,
|
|
52123
52322
|
title: meta3.title,
|
|
52124
52323
|
priority: meta3.priority,
|
|
@@ -52140,7 +52339,7 @@ function buildCard(id2, file2, relFromTodo) {
|
|
|
52140
52339
|
function readGroup(folderName) {
|
|
52141
52340
|
const groupDir = path64.join(TODO, folderName);
|
|
52142
52341
|
const rootFile = path64.join(groupDir, "root.md");
|
|
52143
|
-
if (!
|
|
52342
|
+
if (!fs62.existsSync(rootFile)) return null;
|
|
52144
52343
|
const root2 = readCard(rootFile, path64.join(folderName, "root.md"));
|
|
52145
52344
|
if (!root2) return null;
|
|
52146
52345
|
root2.isGroup = true;
|
|
@@ -52148,7 +52347,7 @@ function readGroup(folderName) {
|
|
|
52148
52347
|
root2.subtaskLines = { total, resolved };
|
|
52149
52348
|
const subCards = [];
|
|
52150
52349
|
const recurse = (dir, relDir) => {
|
|
52151
|
-
for (const entry of
|
|
52350
|
+
for (const entry of fs62.readdirSync(dir, { withFileTypes: true })) {
|
|
52152
52351
|
const childRel = path64.join(relDir, entry.name);
|
|
52153
52352
|
if (entry.isDirectory()) {
|
|
52154
52353
|
recurse(path64.join(dir, entry.name), childRel);
|
|
@@ -52175,9 +52374,9 @@ function readGroup(folderName) {
|
|
|
52175
52374
|
}
|
|
52176
52375
|
function standaloneCards(dirRel) {
|
|
52177
52376
|
const dir = dirRel ? path64.join(TODO, dirRel) : TODO;
|
|
52178
|
-
if (!
|
|
52377
|
+
if (!fs62.existsSync(dir)) return [];
|
|
52179
52378
|
const cards = [];
|
|
52180
|
-
for (const entry of
|
|
52379
|
+
for (const entry of fs62.readdirSync(dir, { withFileTypes: true })) {
|
|
52181
52380
|
if (entry.isFile() && entry.name.endsWith(".md") && entry.name !== "README.md") {
|
|
52182
52381
|
const c = readCard(path64.join(dir, entry.name), path64.join(dirRel, entry.name));
|
|
52183
52382
|
if (c) cards.push(c);
|
|
@@ -52191,7 +52390,7 @@ function collectCards() {
|
|
|
52191
52390
|
const top = standaloneCards("");
|
|
52192
52391
|
board2.push(...top);
|
|
52193
52392
|
every.push(...top);
|
|
52194
|
-
for (const entry of
|
|
52393
|
+
for (const entry of fs62.readdirSync(TODO, { withFileTypes: true })) {
|
|
52195
52394
|
if (!entry.isDirectory()) continue;
|
|
52196
52395
|
if (isGroupFolder(entry.name)) {
|
|
52197
52396
|
const g = readGroup(entry.name);
|
|
@@ -52223,7 +52422,7 @@ function findCard(id2) {
|
|
|
52223
52422
|
}
|
|
52224
52423
|
function attachSources(card) {
|
|
52225
52424
|
try {
|
|
52226
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
52425
|
+
const { meta: meta3, body } = parseFrontmatter(fs62.readFileSync(path64.join(TODO, card.relPath), "utf8"));
|
|
52227
52426
|
const sources2 = meta3 ? cardSources(meta3, body) : [];
|
|
52228
52427
|
if (sources2.length) card.sources = sources2;
|
|
52229
52428
|
} catch {
|
|
@@ -52597,7 +52796,7 @@ var init_project_agent = __esm({
|
|
|
52597
52796
|
|
|
52598
52797
|
// src/lib/agent/creation.ts
|
|
52599
52798
|
import crypto3 from "node:crypto";
|
|
52600
|
-
import
|
|
52799
|
+
import fs63 from "node:fs";
|
|
52601
52800
|
import path65 from "node:path";
|
|
52602
52801
|
function creationError(error62, triage) {
|
|
52603
52802
|
const zh = readLanguage() === "zh";
|
|
@@ -52629,7 +52828,7 @@ ${slot}`).digest("hex");
|
|
|
52629
52828
|
function readCreation(file2, said2) {
|
|
52630
52829
|
return withCreationLock(() => {
|
|
52631
52830
|
try {
|
|
52632
|
-
const held4 = JSON.parse(
|
|
52831
|
+
const held4 = JSON.parse(fs63.readFileSync(file2, "utf8"));
|
|
52633
52832
|
if (!held4.said || typeof held4.said.title !== "string") throw new Error("Invalid creation journal");
|
|
52634
52833
|
return held4;
|
|
52635
52834
|
} catch (error62) {
|
|
@@ -52641,10 +52840,10 @@ function readCreation(file2, said2) {
|
|
|
52641
52840
|
});
|
|
52642
52841
|
}
|
|
52643
52842
|
function saveCreation(file2, journal) {
|
|
52644
|
-
|
|
52843
|
+
fs63.mkdirSync(path65.dirname(file2), { recursive: true });
|
|
52645
52844
|
const temp = `${file2}.${crypto3.randomUUID()}.tmp`;
|
|
52646
|
-
|
|
52647
|
-
|
|
52845
|
+
fs63.writeFileSync(temp, JSON.stringify(journal));
|
|
52846
|
+
fs63.renameSync(temp, file2);
|
|
52648
52847
|
}
|
|
52649
52848
|
function archiveCreation(source2, id2) {
|
|
52650
52849
|
if (readArchived().some((s) => s.sourceId === source2 && s.cardId === id2)) return;
|
|
@@ -53790,7 +53989,7 @@ var require_command = __commonJS({
|
|
|
53790
53989
|
var EventEmitter = __require("node:events").EventEmitter;
|
|
53791
53990
|
var childProcess = __require("node:child_process");
|
|
53792
53991
|
var path88 = __require("node:path");
|
|
53793
|
-
var
|
|
53992
|
+
var fs91 = __require("node:fs");
|
|
53794
53993
|
var process2 = __require("node:process");
|
|
53795
53994
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
53796
53995
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -54771,7 +54970,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54771
54970
|
* @param {string} subcommandName
|
|
54772
54971
|
*/
|
|
54773
54972
|
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
54774
|
-
if (
|
|
54973
|
+
if (fs91.existsSync(executableFile)) return;
|
|
54775
54974
|
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
54975
|
const executableMissing = `'${executableFile}' does not exist
|
|
54777
54976
|
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
@@ -54790,10 +54989,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54790
54989
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
54791
54990
|
function findFile(baseDir, baseName) {
|
|
54792
54991
|
const localBin = path88.resolve(baseDir, baseName);
|
|
54793
|
-
if (
|
|
54992
|
+
if (fs91.existsSync(localBin)) return localBin;
|
|
54794
54993
|
if (sourceExt.includes(path88.extname(baseName))) return void 0;
|
|
54795
54994
|
const foundExt = sourceExt.find(
|
|
54796
|
-
(ext) =>
|
|
54995
|
+
(ext) => fs91.existsSync(`${localBin}${ext}`)
|
|
54797
54996
|
);
|
|
54798
54997
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
54799
54998
|
return void 0;
|
|
@@ -54805,7 +55004,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
54805
55004
|
if (this._scriptPath) {
|
|
54806
55005
|
let resolvedScriptPath;
|
|
54807
55006
|
try {
|
|
54808
|
-
resolvedScriptPath =
|
|
55007
|
+
resolvedScriptPath = fs91.realpathSync(this._scriptPath);
|
|
54809
55008
|
} catch {
|
|
54810
55009
|
resolvedScriptPath = this._scriptPath;
|
|
54811
55010
|
}
|
|
@@ -56141,7 +56340,7 @@ var init_shared2 = __esm({
|
|
|
56141
56340
|
});
|
|
56142
56341
|
|
|
56143
56342
|
// src/lib/agents/shared-memory.ts
|
|
56144
|
-
import
|
|
56343
|
+
import fs64 from "node:fs";
|
|
56145
56344
|
import path66 from "node:path";
|
|
56146
56345
|
function sharedMemory(board2) {
|
|
56147
56346
|
const declared = /* @__PURE__ */ new Map();
|
|
@@ -56150,7 +56349,7 @@ function sharedMemory(board2) {
|
|
|
56150
56349
|
const read5 = parseSpecAgent(text5, folder2, (relative) => {
|
|
56151
56350
|
if (builtIn) return shippedAgentFiles()[`${folder2}/${relative}`] ?? null;
|
|
56152
56351
|
try {
|
|
56153
|
-
return
|
|
56352
|
+
return fs64.readFileSync(path66.join(board2, "agents", folder2, relative), "utf8");
|
|
56154
56353
|
} catch {
|
|
56155
56354
|
return null;
|
|
56156
56355
|
}
|
|
@@ -56164,13 +56363,13 @@ function sharedMemory(board2) {
|
|
|
56164
56363
|
const root2 = path66.join(board2, "agents");
|
|
56165
56364
|
let folders2 = [];
|
|
56166
56365
|
try {
|
|
56167
|
-
folders2 =
|
|
56366
|
+
folders2 = fs64.readdirSync(root2, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
56168
56367
|
} catch {
|
|
56169
56368
|
}
|
|
56170
56369
|
for (const folder2 of folders2.sort()) {
|
|
56171
56370
|
let text5 = null;
|
|
56172
56371
|
try {
|
|
56173
|
-
text5 =
|
|
56372
|
+
text5 = fs64.readFileSync(path66.join(root2, folder2, "AGENT.md"), "utf8");
|
|
56174
56373
|
} catch {
|
|
56175
56374
|
}
|
|
56176
56375
|
take(folder2, text5, false);
|
|
@@ -56196,30 +56395,30 @@ var init_shared_memory = __esm({
|
|
|
56196
56395
|
|
|
56197
56396
|
// src/lib/shared/board-conflicts.ts
|
|
56198
56397
|
import crypto4 from "node:crypto";
|
|
56199
|
-
import
|
|
56398
|
+
import fs65 from "node:fs";
|
|
56200
56399
|
import path67 from "node:path";
|
|
56201
56400
|
function atomicJson(file2, data) {
|
|
56202
|
-
|
|
56401
|
+
fs65.mkdirSync(path67.dirname(file2), { recursive: true });
|
|
56203
56402
|
const temp = `${file2}.${crypto4.randomUUID()}.tmp`;
|
|
56204
|
-
const fd =
|
|
56403
|
+
const fd = fs65.openSync(temp, "wx", 384);
|
|
56205
56404
|
try {
|
|
56206
|
-
|
|
56207
|
-
|
|
56405
|
+
fs65.writeFileSync(fd, JSON.stringify(data));
|
|
56406
|
+
fs65.fsyncSync(fd);
|
|
56208
56407
|
} finally {
|
|
56209
|
-
|
|
56408
|
+
fs65.closeSync(fd);
|
|
56210
56409
|
}
|
|
56211
|
-
|
|
56410
|
+
fs65.renameSync(temp, file2);
|
|
56212
56411
|
}
|
|
56213
56412
|
function boardTextAt(board2, name) {
|
|
56214
56413
|
if (!isBoardPath(name)) throw new BoardError(`Invalid board path: ${name}`, { kind: "invalid-usage" });
|
|
56215
56414
|
const file2 = path67.join(board2, name);
|
|
56216
56415
|
let ancestor = file2;
|
|
56217
|
-
while (!
|
|
56218
|
-
const real2 = path67.resolve(
|
|
56219
|
-
if (!real2.startsWith(
|
|
56220
|
-
if ((
|
|
56416
|
+
while (!fs65.existsSync(ancestor) && path67.dirname(ancestor) !== ancestor) ancestor = path67.dirname(ancestor);
|
|
56417
|
+
const real2 = path67.resolve(fs65.realpathSync(ancestor), path67.relative(ancestor, file2));
|
|
56418
|
+
if (!real2.startsWith(fs65.realpathSync(board2) + path67.sep)) throw new BoardError(`Link outside the board: ${name}`, { kind: "invalid-usage" });
|
|
56419
|
+
if ((fs65.statSync(file2, { throwIfNoEntry: false })?.size ?? 0) > BOARD_FILE_LIMIT) throw new BoardError(`${name} exceeds the board file limit.`, { kind: "cloud-refused" });
|
|
56221
56420
|
try {
|
|
56222
|
-
return
|
|
56421
|
+
return fs65.readFileSync(file2, "utf8");
|
|
56223
56422
|
} catch (e) {
|
|
56224
56423
|
if (e.code === "ENOENT") return null;
|
|
56225
56424
|
throw e;
|
|
@@ -56230,9 +56429,9 @@ function save2(board2, record2) {
|
|
|
56230
56429
|
}
|
|
56231
56430
|
function read2(board2, id2) {
|
|
56232
56431
|
const file2 = fileOf(board2, id2);
|
|
56233
|
-
if (!
|
|
56432
|
+
if (!fs65.existsSync(file2)) throw new BoardError("Unknown board conflict.", { kind: "conflict-not-found", id: id2 });
|
|
56234
56433
|
try {
|
|
56235
|
-
const r = JSON.parse(
|
|
56434
|
+
const r = JSON.parse(fs65.readFileSync(file2, "utf8"));
|
|
56236
56435
|
if (r.id !== id2 || !r.project || !["open", "unconfirmed", "resolved"].includes(r.state) || !Array.isArray(r.files) || !r.files.length) throw Error();
|
|
56237
56436
|
const names2 = /* @__PURE__ */ new Set();
|
|
56238
56437
|
for (const f of r.files) {
|
|
@@ -56254,7 +56453,7 @@ function read2(board2, id2) {
|
|
|
56254
56453
|
function conflictRecords(board2) {
|
|
56255
56454
|
let names2;
|
|
56256
56455
|
try {
|
|
56257
|
-
names2 =
|
|
56456
|
+
names2 = fs65.readdirSync(folder(board2));
|
|
56258
56457
|
} catch (e) {
|
|
56259
56458
|
if (e.code === "ENOENT") return [];
|
|
56260
56459
|
throw e;
|
|
@@ -56343,7 +56542,7 @@ function confirmLocal(board2, r) {
|
|
|
56343
56542
|
const draft = r.draft;
|
|
56344
56543
|
const root2 = stateRootOf(board2);
|
|
56345
56544
|
const file2 = path67.join(root2, ".akb", "base.json");
|
|
56346
|
-
const base = JSON.parse(
|
|
56545
|
+
const base = JSON.parse(fs65.readFileSync(file2, "utf8"));
|
|
56347
56546
|
if (base.project && base.project !== r.project) refuse(r, "The project binding changed.", "cloud-refused");
|
|
56348
56547
|
base.deleted ??= {};
|
|
56349
56548
|
for (const [i, f] of r.files.entries()) {
|
|
@@ -56360,10 +56559,10 @@ function confirmLocal(board2, r) {
|
|
|
56360
56559
|
}
|
|
56361
56560
|
if (boardTextAt(board2, f.path) !== draft.working[i]) continue;
|
|
56362
56561
|
const local = path67.join(board2, f.path);
|
|
56363
|
-
if (sent.content === null)
|
|
56562
|
+
if (sent.content === null) fs65.rmSync(local, { force: true });
|
|
56364
56563
|
else {
|
|
56365
|
-
|
|
56366
|
-
|
|
56564
|
+
fs65.mkdirSync(path67.dirname(local), { recursive: true });
|
|
56565
|
+
fs65.writeFileSync(local, sent.content);
|
|
56367
56566
|
}
|
|
56368
56567
|
}
|
|
56369
56568
|
atomicJson(file2, base);
|
|
@@ -56541,7 +56740,7 @@ __export(board_exports, {
|
|
|
56541
56740
|
buildBoardProgram: () => buildBoardProgram
|
|
56542
56741
|
});
|
|
56543
56742
|
import crypto5 from "node:crypto";
|
|
56544
|
-
import
|
|
56743
|
+
import fs66 from "node:fs";
|
|
56545
56744
|
import path68 from "node:path";
|
|
56546
56745
|
async function dispatch(move, cmd, args2, opts, cli) {
|
|
56547
56746
|
const ctx = ctxOf(cmd, cli.program);
|
|
@@ -56562,7 +56761,7 @@ async function dispatch(move, cmd, args2, opts, cli) {
|
|
|
56562
56761
|
}
|
|
56563
56762
|
let resolution;
|
|
56564
56763
|
try {
|
|
56565
|
-
resolution = JSON.parse(
|
|
56764
|
+
resolution = JSON.parse(fs66.readFileSync(String(opts.file), "utf8"));
|
|
56566
56765
|
} catch {
|
|
56567
56766
|
throw new BoardError("Cannot read the UTF-8 JSON resolution file.", { kind: "invalid-usage" });
|
|
56568
56767
|
}
|
|
@@ -56603,7 +56802,7 @@ async function cloudCard(task, opts) {
|
|
|
56603
56802
|
let request2;
|
|
56604
56803
|
if (typeof opts.bodyFile === "string") {
|
|
56605
56804
|
try {
|
|
56606
|
-
request2 =
|
|
56805
|
+
request2 = fs66.readFileSync(opts.bodyFile, "utf8");
|
|
56607
56806
|
} catch {
|
|
56608
56807
|
}
|
|
56609
56808
|
}
|
|
@@ -56768,7 +56967,7 @@ var init_board2 = __esm({
|
|
|
56768
56967
|
});
|
|
56769
56968
|
|
|
56770
56969
|
// src/lib/board-cli.ts
|
|
56771
|
-
import
|
|
56970
|
+
import fs67 from "node:fs";
|
|
56772
56971
|
import path69 from "node:path";
|
|
56773
56972
|
function useBoard(found2, dirNamed, readOnly = false) {
|
|
56774
56973
|
if (!found2.named && found2.board === path69.join(found2.root, "docs", "kanban")) setBoardRoot(found2.root, dirNamed);
|
|
@@ -56780,7 +56979,7 @@ function useBoard(found2, dirNamed, readOnly = false) {
|
|
|
56780
56979
|
}
|
|
56781
56980
|
function whole(found2, move) {
|
|
56782
56981
|
if (move === MAKES_A_BOARD) return found2;
|
|
56783
|
-
if (!
|
|
56982
|
+
if (!fs67.existsSync(path69.join(found2.board, "todo"))) {
|
|
56784
56983
|
die(`the board in ${found2.board} has no todo/ \u2014 run \`init\` to add what is missing.`, {
|
|
56785
56984
|
kind: "board-incomplete",
|
|
56786
56985
|
dir: found2.root
|
|
@@ -56794,7 +56993,7 @@ function findBoardUpward(from, move) {
|
|
|
56794
56993
|
if (hasBoard(dir)) return { root: dir, board: path69.join(dir, "docs", "kanban") };
|
|
56795
56994
|
if (isBoardDir(dir)) return { root: projectRootOf(dir), board: dir };
|
|
56796
56995
|
const kept2 = path69.join(dir, ".akb", "kanban");
|
|
56797
|
-
if (move !== MAKES_A_BOARD &&
|
|
56996
|
+
if (move !== MAKES_A_BOARD && fs67.existsSync(path69.join(kept2, "todo"))) return { root: dir, board: kept2 };
|
|
56798
56997
|
const up = path69.dirname(dir);
|
|
56799
56998
|
if (up === dir) return null;
|
|
56800
56999
|
dir = up;
|
|
@@ -56804,10 +57003,10 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
56804
57003
|
const named2 = board2 ?? boardFromEnv();
|
|
56805
57004
|
if (named2) {
|
|
56806
57005
|
const folder2 = path69.resolve(cwd, named2);
|
|
56807
|
-
if (!
|
|
57006
|
+
if (!fs67.existsSync(folder2) && move !== MAKES_A_BOARD) {
|
|
56808
57007
|
die(`no such folder: ${folder2}`, { kind: "no-such-folder", dir: folder2 });
|
|
56809
57008
|
}
|
|
56810
|
-
if (
|
|
57009
|
+
if (fs67.existsSync(folder2) && !isBoardDir(folder2) && move !== MAKES_A_BOARD) {
|
|
56811
57010
|
die(`${folder2} is not a board \u2014 it has no todo/ and config.md. ${installHint}\u3002`, {
|
|
56812
57011
|
kind: "no-board",
|
|
56813
57012
|
dir: folder2
|
|
@@ -56817,9 +57016,9 @@ function resolveBoard(move, { board: board2, dir, cwd, installHint }) {
|
|
|
56817
57016
|
}
|
|
56818
57017
|
if (dir !== null) {
|
|
56819
57018
|
const root2 = path69.resolve(dir);
|
|
56820
|
-
if (!
|
|
57019
|
+
if (!fs67.existsSync(root2)) die(`no such folder: ${root2}`, { kind: "no-such-folder", dir: root2 });
|
|
56821
57020
|
const kept2 = path69.join(root2, ".akb", "kanban");
|
|
56822
|
-
if (!hasBoard(root2) && move !== MAKES_A_BOARD &&
|
|
57021
|
+
if (!hasBoard(root2) && move !== MAKES_A_BOARD && fs67.existsSync(path69.join(kept2, "todo"))) return whole({ root: root2, board: kept2 }, move);
|
|
56823
57022
|
if (!hasBoard(root2) && move !== MAKES_A_BOARD) {
|
|
56824
57023
|
die(`no board in ${root2} \u2014 it has no docs/kanban/. ${installHint}\u3002`, {
|
|
56825
57024
|
kind: "no-board",
|
|
@@ -56910,8 +57109,8 @@ var init_board_cli = __esm({
|
|
|
56910
57109
|
init_io();
|
|
56911
57110
|
init_card_studio_backfill();
|
|
56912
57111
|
MAKES_A_BOARD = "init";
|
|
56913
|
-
hasBoard = (dir) =>
|
|
56914
|
-
isBoardDir = (dir) =>
|
|
57112
|
+
hasBoard = (dir) => fs67.existsSync(path69.join(dir, "docs", "kanban"));
|
|
57113
|
+
isBoardDir = (dir) => fs67.existsSync(path69.join(dir, "todo")) && fs67.existsSync(path69.join(dir, "config.md"));
|
|
56915
57114
|
boardFromEnv = () => {
|
|
56916
57115
|
const named2 = process.env.AI4KANBAN_BOARD?.trim();
|
|
56917
57116
|
return named2 ? named2 : null;
|
|
@@ -56920,11 +57119,11 @@ var init_board_cli = __esm({
|
|
|
56920
57119
|
});
|
|
56921
57120
|
|
|
56922
57121
|
// src/lib/cloud/task-operation.ts
|
|
56923
|
-
import
|
|
57122
|
+
import fs68 from "node:fs";
|
|
56924
57123
|
import path70 from "node:path";
|
|
56925
57124
|
function readRemoval(board2, task) {
|
|
56926
57125
|
try {
|
|
56927
|
-
const value = JSON.parse(
|
|
57126
|
+
const value = JSON.parse(fs68.readFileSync(removalFile(board2, task), "utf8"));
|
|
56928
57127
|
if (["pending", "confirmed", "rejected"].includes(value.status) && typeof value.reason === "string" && typeof value.discard === "boolean") return value;
|
|
56929
57128
|
} catch {
|
|
56930
57129
|
}
|
|
@@ -56933,8 +57132,8 @@ function readRemoval(board2, task) {
|
|
|
56933
57132
|
function writeRemoval(board2, task, removal) {
|
|
56934
57133
|
const file2 = removalFile(board2, task);
|
|
56935
57134
|
const temp = `${file2}.${process.pid}.tmp`;
|
|
56936
|
-
|
|
56937
|
-
|
|
57135
|
+
fs68.writeFileSync(temp, JSON.stringify(removal) + "\n");
|
|
57136
|
+
fs68.renameSync(temp, file2);
|
|
56938
57137
|
}
|
|
56939
57138
|
var removalFile;
|
|
56940
57139
|
var init_task_operation = __esm({
|
|
@@ -56990,10 +57189,10 @@ var init_avatar = __esm({
|
|
|
56990
57189
|
});
|
|
56991
57190
|
|
|
56992
57191
|
// src/lib/cloud/pro.ts
|
|
56993
|
-
import
|
|
57192
|
+
import fs69 from "node:fs";
|
|
56994
57193
|
import path71 from "node:path";
|
|
56995
57194
|
function forgetPro() {
|
|
56996
|
-
|
|
57195
|
+
fs69.rmSync(heldFile(), { force: true });
|
|
56997
57196
|
}
|
|
56998
57197
|
var FRESH_MS2, GRACE_MS, heldFile;
|
|
56999
57198
|
var init_pro = __esm({
|
|
@@ -57099,7 +57298,7 @@ var init_account = __esm({
|
|
|
57099
57298
|
});
|
|
57100
57299
|
|
|
57101
57300
|
// src/commands/cloud.ts
|
|
57102
|
-
import
|
|
57301
|
+
import fs70 from "node:fs";
|
|
57103
57302
|
import path72 from "node:path";
|
|
57104
57303
|
async function cmdCloud(args2, program2) {
|
|
57105
57304
|
const [sub] = args2;
|
|
@@ -57175,7 +57374,7 @@ async function cloudImage(opts, program2) {
|
|
|
57175
57374
|
const type = REF_TYPES[path72.extname(file2).toLowerCase()];
|
|
57176
57375
|
if (!type) usage(`--ref ${file2}: use a PNG, JPEG or WebP file.`, line);
|
|
57177
57376
|
try {
|
|
57178
|
-
return `data:${type};base64,${
|
|
57377
|
+
return `data:${type};base64,${fs70.readFileSync(file2).toString("base64")}`;
|
|
57179
57378
|
} catch (e) {
|
|
57180
57379
|
usage(`--ref ${file2}: ${e instanceof Error ? e.message : String(e)}`, line);
|
|
57181
57380
|
}
|
|
@@ -57299,8 +57498,8 @@ usage: ${g.usage}` }, { bare: true, exitCode: 2 });
|
|
|
57299
57498
|
refuse2(g.failed, g.fallback, { code: error62.kind, message: error62.message, retryable: true });
|
|
57300
57499
|
}
|
|
57301
57500
|
const out = g.outFor?.(res, g.out) ?? g.out;
|
|
57302
|
-
|
|
57303
|
-
|
|
57501
|
+
fs70.mkdirSync(path72.dirname(path72.resolve(out)), { recursive: true });
|
|
57502
|
+
fs70.writeFileSync(out, bytes2);
|
|
57304
57503
|
say(`${out} (${g.label(res)})`);
|
|
57305
57504
|
return { out };
|
|
57306
57505
|
}
|
|
@@ -57362,7 +57561,7 @@ var init_cloud = __esm({
|
|
|
57362
57561
|
});
|
|
57363
57562
|
|
|
57364
57563
|
// src/commands/task.ts
|
|
57365
|
-
import
|
|
57564
|
+
import fs71 from "node:fs";
|
|
57366
57565
|
import os5 from "node:os";
|
|
57367
57566
|
import path73 from "node:path";
|
|
57368
57567
|
async function cloud(method, route2, body, signal2) {
|
|
@@ -57421,7 +57620,7 @@ function linked(location) {
|
|
|
57421
57620
|
return link2.ok ? link2.value : null;
|
|
57422
57621
|
}
|
|
57423
57622
|
for (let dir = path73.resolve(cwd, location.dir ?? "."); ; dir = path73.dirname(dir)) {
|
|
57424
|
-
if (
|
|
57623
|
+
if (fs71.existsSync(path73.join(dir, ".akb", "base.json"))) {
|
|
57425
57624
|
const link2 = linkedProject("", dir);
|
|
57426
57625
|
return link2.ok ? link2.value : null;
|
|
57427
57626
|
}
|
|
@@ -57528,7 +57727,7 @@ async function taskReview(id2, opts = {}, location = {}) {
|
|
|
57528
57727
|
if (opts.review !== void 0) {
|
|
57529
57728
|
fields2 = { operation: "plan", review_flow: opts.review };
|
|
57530
57729
|
} else if (opts.file !== void 0) {
|
|
57531
|
-
fields2 = { operation: "plan", review_plan: parseReviewPlan(JSON.parse(
|
|
57730
|
+
fields2 = { operation: "plan", review_plan: parseReviewPlan(JSON.parse(fs71.readFileSync(opts.file, "utf8"))) };
|
|
57532
57731
|
} else if (opts.reviseFrom !== void 0) {
|
|
57533
57732
|
fields2 = { operation: "revise", stage: opts.reviseFrom };
|
|
57534
57733
|
} else if (opts.previewDefinitionsFile !== void 0) {
|
|
@@ -57537,7 +57736,7 @@ async function taskReview(id2, opts = {}, location = {}) {
|
|
|
57537
57736
|
if (!opts.stage || !["running", "done"].includes(opts.status)) die("--stage and --status running|done are required.");
|
|
57538
57737
|
fields2 = { operation: "status", stage: opts.stage, status: opts.status };
|
|
57539
57738
|
}
|
|
57540
|
-
if (opts.previewDefinitionsFile !== void 0) fields2.preview_definitions = previewDefinitionsSchema.parse(JSON.parse(
|
|
57739
|
+
if (opts.previewDefinitionsFile !== void 0) fields2.preview_definitions = previewDefinitionsSchema.parse(JSON.parse(fs71.readFileSync(opts.previewDefinitionsFile, "utf8")));
|
|
57541
57740
|
task = await cloud("POST", `/v1/tasks/${enc(ref)}/review`, { ...fields2, review_revision });
|
|
57542
57741
|
}
|
|
57543
57742
|
say(JSON.stringify(task.review, null, 2));
|
|
@@ -57580,7 +57779,7 @@ async function taskUpdateQuestions(id2, typed, location = {}) {
|
|
|
57580
57779
|
return withBoardLock(() => {
|
|
57581
57780
|
const run3 = insideRun();
|
|
57582
57781
|
const runCard = run3 ? peekRun(run3)?.cardId : null;
|
|
57583
|
-
if (runCard != null && runCard !== mapped.number || !
|
|
57782
|
+
if (runCard != null && runCard !== mapped.number || !fs71.existsSync(path73.join(board2, "todo")) || !locate(mapped.number)) {
|
|
57584
57783
|
return unavailable();
|
|
57585
57784
|
}
|
|
57586
57785
|
return updateCardQuestions(mapped.number, ops);
|
|
@@ -57621,7 +57820,7 @@ function runnerTaskBoard(location) {
|
|
|
57621
57820
|
const cwd = location.cwd ?? process.cwd();
|
|
57622
57821
|
try {
|
|
57623
57822
|
const board2 = path73.resolve(cwd, location.board ?? runnerBoard);
|
|
57624
|
-
return
|
|
57823
|
+
return fs71.realpathSync(board2) === fs71.realpathSync(path73.resolve(cwd, runnerBoard)) && runnerProject(board2) ? board2 : null;
|
|
57625
57824
|
} catch {
|
|
57626
57825
|
return null;
|
|
57627
57826
|
}
|
|
@@ -57629,7 +57828,7 @@ function runnerTaskBoard(location) {
|
|
|
57629
57828
|
function localTaskRecord(board2, task) {
|
|
57630
57829
|
if (!/^task_[\w-]+$/.test(task)) return null;
|
|
57631
57830
|
try {
|
|
57632
|
-
const record2 = JSON.parse(
|
|
57831
|
+
const record2 = JSON.parse(fs71.readFileSync(path73.join(board2, ".sync", task + ".json"), "utf8"));
|
|
57633
57832
|
if (record2.task === task && Number.isSafeInteger(record2.number) && record2.number > 0 && !record2.deleted) {
|
|
57634
57833
|
return { board: board2, task, number: record2.number };
|
|
57635
57834
|
}
|
|
@@ -57662,7 +57861,7 @@ function operationStatus(result) {
|
|
|
57662
57861
|
}
|
|
57663
57862
|
function archiveReceipt(board2, task, file2) {
|
|
57664
57863
|
try {
|
|
57665
|
-
const base = JSON.parse(
|
|
57864
|
+
const base = JSON.parse(fs71.readFileSync(path73.join(board2, "..", "base.json"), "utf8"));
|
|
57666
57865
|
const receipt = base.archiveReceipts?.[task];
|
|
57667
57866
|
const root2 = `projects/${runnerProject(board2)}/`;
|
|
57668
57867
|
const synced = receipt && base.files?.[root2 + receipt.path];
|
|
@@ -57671,7 +57870,7 @@ function archiveReceipt(board2, task, file2) {
|
|
|
57671
57870
|
if (synced && (!file2 || receipt.path === file2) && synced.seq === receipt.seq && (assets?.seq ?? 0) === receipt.assets_seq) {
|
|
57672
57871
|
const local = (name) => {
|
|
57673
57872
|
try {
|
|
57674
|
-
return
|
|
57873
|
+
return fs71.readFileSync(path73.join(board2, name), "utf8");
|
|
57675
57874
|
} catch {
|
|
57676
57875
|
return null;
|
|
57677
57876
|
}
|
|
@@ -57696,7 +57895,7 @@ async function taskArchive(asked, location = {}) {
|
|
|
57696
57895
|
const existing = locateArchived(local.number);
|
|
57697
57896
|
if (!existing) return null;
|
|
57698
57897
|
const file2 = existing.kind === "group" ? path73.join(existing.target, "root.md") : existing.target;
|
|
57699
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
57898
|
+
const { meta: meta3 } = parseFrontmatter(fs71.readFileSync(file2, "utf8"));
|
|
57700
57899
|
if (!meta3?.archived || meta3.rejected) return refuse3("This task is not eligible for archive.", "conflict");
|
|
57701
57900
|
return {
|
|
57702
57901
|
receipt: { archived_to: path73.relative(local.board, existing.target) },
|
|
@@ -57898,20 +58097,20 @@ var init_goal = __esm({
|
|
|
57898
58097
|
});
|
|
57899
58098
|
|
|
57900
58099
|
// src/lib/goal-draft.ts
|
|
57901
|
-
import
|
|
58100
|
+
import fs72 from "node:fs";
|
|
57902
58101
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
57903
58102
|
function readGoalDraft(file2) {
|
|
57904
|
-
return decodeGoals(JSON.parse(
|
|
58103
|
+
return decodeGoals(JSON.parse(fs72.readFileSync(file2, "utf8")));
|
|
57905
58104
|
}
|
|
57906
58105
|
function writeGoalDraft(file2, { goals, ...draft }, field2) {
|
|
57907
58106
|
const entries2 = field2 === "goals" ? goals : goals.map(({ task, ...goal }) => ({ ...goal, task: task?.key ? task : task?.id ?? null }));
|
|
57908
58107
|
const temporary = `${file2}.${randomUUID7()}.tmp`;
|
|
57909
58108
|
try {
|
|
57910
|
-
|
|
58109
|
+
fs72.writeFileSync(temporary, `${JSON.stringify({ ...draft, [field2]: entries2 }, null, 2)}
|
|
57911
58110
|
`, { mode: 384, flag: "wx" });
|
|
57912
|
-
|
|
58111
|
+
fs72.renameSync(temporary, file2);
|
|
57913
58112
|
} finally {
|
|
57914
|
-
|
|
58113
|
+
fs72.rmSync(temporary, { force: true });
|
|
57915
58114
|
}
|
|
57916
58115
|
}
|
|
57917
58116
|
var goalDraftPath;
|
|
@@ -57924,7 +58123,7 @@ var init_goal_draft = __esm({
|
|
|
57924
58123
|
});
|
|
57925
58124
|
|
|
57926
58125
|
// src/commands/goal.ts
|
|
57927
|
-
import
|
|
58126
|
+
import fs73 from "node:fs";
|
|
57928
58127
|
function loadGoals() {
|
|
57929
58128
|
const file2 = goalDraftPath();
|
|
57930
58129
|
if (!file2) die("Goals exist only inside a WildCrane goal discussion.");
|
|
@@ -57956,7 +58155,7 @@ function splitBody2(text5) {
|
|
|
57956
58155
|
}
|
|
57957
58156
|
function readBody(bodyFile) {
|
|
57958
58157
|
if (!bodyFile) die("--body-file is required; write the goal in a writable temporary file first.");
|
|
57959
|
-
const text5 =
|
|
58158
|
+
const text5 = fs73.readFileSync(bodyFile, "utf8");
|
|
57960
58159
|
if (!text5.trim()) die("The goal must not be empty.");
|
|
57961
58160
|
return splitBody2(text5);
|
|
57962
58161
|
}
|
|
@@ -58022,7 +58221,7 @@ function cmdGoalStudios(held4 = loadGoals().held) {
|
|
|
58022
58221
|
return { studios: held4.studios.map((w) => ({ ...w, id: shortStudioId(w.id) })) };
|
|
58023
58222
|
}
|
|
58024
58223
|
function goalDefinitions(opts, previous = []) {
|
|
58025
|
-
return opts.previewDefinitionsFile === void 0 ? previous : previewDefinitionsSchema.parse(JSON.parse(
|
|
58224
|
+
return opts.previewDefinitionsFile === void 0 ? previous : previewDefinitionsSchema.parse(JSON.parse(fs73.readFileSync(opts.previewDefinitionsFile, "utf8")));
|
|
58026
58225
|
}
|
|
58027
58226
|
function goalCatalog(held4, studio, definitions) {
|
|
58028
58227
|
const builtIn = held4.studios.find((w) => w.id === studio)?.previews;
|
|
@@ -58035,7 +58234,7 @@ function goalReview(held4, studio, opts, previous, definitions) {
|
|
|
58035
58234
|
if (opts.reviewFile !== void 0) die("Use either --review or --review-file.");
|
|
58036
58235
|
return parseReviewFlow(opts.review, catalog);
|
|
58037
58236
|
}
|
|
58038
|
-
const value = opts.reviewFile === void 0 ? readReviewPlan(previous) : JSON.parse(
|
|
58237
|
+
const value = opts.reviewFile === void 0 ? readReviewPlan(previous) : JSON.parse(fs73.readFileSync(opts.reviewFile, "utf8"));
|
|
58039
58238
|
const saved = opts.reviewFile === void 0 && opts.previewDefinitionsFile === void 0 && opts.studio === void 0;
|
|
58040
58239
|
return validateReviewPreviews(parseReviewPlan(value), catalog, { saved });
|
|
58041
58240
|
}
|
|
@@ -58065,7 +58264,7 @@ var init_goal2 = __esm({
|
|
|
58065
58264
|
});
|
|
58066
58265
|
|
|
58067
58266
|
// src/commands/goal-cloud.ts
|
|
58068
|
-
import
|
|
58267
|
+
import fs74 from "node:fs";
|
|
58069
58268
|
import os6 from "node:os";
|
|
58070
58269
|
import path74 from "node:path";
|
|
58071
58270
|
import crypto6 from "node:crypto";
|
|
@@ -58099,17 +58298,17 @@ async function discussion() {
|
|
|
58099
58298
|
const machineFile2 = path74.join(home3, "machine.json");
|
|
58100
58299
|
let machine;
|
|
58101
58300
|
try {
|
|
58102
|
-
machine = JSON.parse(
|
|
58301
|
+
machine = JSON.parse(fs74.readFileSync(machineFile2, "utf8")).id;
|
|
58103
58302
|
} catch {
|
|
58104
58303
|
machine = crypto6.randomUUID();
|
|
58105
|
-
|
|
58106
|
-
|
|
58304
|
+
fs74.mkdirSync(home3, { recursive: true });
|
|
58305
|
+
fs74.writeFileSync(machineFile2, JSON.stringify({ id: machine }));
|
|
58107
58306
|
}
|
|
58108
58307
|
const held4 = await request("GET", `/v1/runner/folders?machine=${encodeURIComponent(machine)}`);
|
|
58109
|
-
const cwd =
|
|
58308
|
+
const cwd = fs74.realpathSync(process.cwd());
|
|
58110
58309
|
const folder2 = held4.folders.filter((f) => {
|
|
58111
58310
|
try {
|
|
58112
|
-
const dir =
|
|
58311
|
+
const dir = fs74.realpathSync(f.path);
|
|
58113
58312
|
return cwd === dir || cwd.startsWith(dir + path74.sep);
|
|
58114
58313
|
} catch {
|
|
58115
58314
|
return false;
|
|
@@ -58423,7 +58622,7 @@ var init_agent = __esm({
|
|
|
58423
58622
|
|
|
58424
58623
|
// src/commands/cloud-template.ts
|
|
58425
58624
|
import { createHash as createHash5 } from "node:crypto";
|
|
58426
|
-
import
|
|
58625
|
+
import fs75 from "node:fs";
|
|
58427
58626
|
import path75 from "node:path";
|
|
58428
58627
|
function usage2(problem, line) {
|
|
58429
58628
|
die(`${problem}
|
|
@@ -58488,9 +58687,9 @@ async function downloadEntries(name, kind, files, to, fallback) {
|
|
|
58488
58687
|
if (file2.sha256 && createHash5("sha256").update(bytes2).digest("hex") !== file2.sha256) refuse4(T.corrupt, fallback, invalidResponse(expected));
|
|
58489
58688
|
fetched.push({ out, bytes: bytes2 });
|
|
58490
58689
|
}
|
|
58491
|
-
if (fetched.length)
|
|
58690
|
+
if (fetched.length) fs75.mkdirSync(to, { recursive: true });
|
|
58492
58691
|
return fetched.map(({ out, bytes: bytes2 }) => {
|
|
58493
|
-
|
|
58692
|
+
fs75.writeFileSync(out, bytes2);
|
|
58494
58693
|
say(out);
|
|
58495
58694
|
return out;
|
|
58496
58695
|
});
|
|
@@ -58563,7 +58762,7 @@ async function templateGet(name, opts, program2) {
|
|
|
58563
58762
|
}
|
|
58564
58763
|
fetched.push({ out, bytes: bytes2 });
|
|
58565
58764
|
}
|
|
58566
|
-
const taken = fetched.filter((f) =>
|
|
58765
|
+
const taken = fetched.filter((f) => fs75.existsSync(f.out)).map((f) => path75.relative(to, f.out));
|
|
58567
58766
|
if (taken.length > 0) {
|
|
58568
58767
|
refuse4({
|
|
58569
58768
|
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 +58770,8 @@ async function templateGet(name, opts, program2) {
|
|
|
58571
58770
|
});
|
|
58572
58771
|
}
|
|
58573
58772
|
for (const f of fetched) {
|
|
58574
|
-
|
|
58575
|
-
|
|
58773
|
+
fs75.mkdirSync(path75.dirname(f.out), { recursive: true });
|
|
58774
|
+
fs75.writeFileSync(f.out, f.bytes);
|
|
58576
58775
|
}
|
|
58577
58776
|
say(`\u5DF2\u53D6\u56DE ${name}\uFF1A${fetched.length} \u4E2A\u6587\u4EF6\uFF0C\u4F4D\u4E8E ${to}
|
|
58578
58777
|
Fetched ${name}: ${fetched.length} files into ${to}`);
|
|
@@ -58594,13 +58793,13 @@ async function templateSource(name, opts) {
|
|
|
58594
58793
|
async function templatePublish(dir, opts) {
|
|
58595
58794
|
const root2 = path75.resolve(dir);
|
|
58596
58795
|
const manifest = path75.join(root2, "template.md");
|
|
58597
|
-
if (!
|
|
58598
|
-
const meta3 = readTemplateMeta(
|
|
58796
|
+
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.");
|
|
58797
|
+
const meta3 = readTemplateMeta(fs75.readFileSync(manifest, "utf8"));
|
|
58599
58798
|
const files = walk2(root2);
|
|
58600
|
-
const total = files.reduce((sum, f) => sum +
|
|
58799
|
+
const total = files.reduce((sum, f) => sum + fs75.statSync(path75.join(root2, f)).size, 0);
|
|
58601
58800
|
if (total > MAX_BYTES2) invalid2("\u6A21\u677F\u6587\u4EF6\u5408\u8BA1\u8D85\u8FC7 50 MB\u3002", "the template\u2019s files exceed 50 MB.");
|
|
58602
58801
|
for (const extra of [...opts.preview, ...opts.evidence]) {
|
|
58603
|
-
if (!
|
|
58802
|
+
if (!fs75.existsSync(extra)) invalid2(`\u627E\u4E0D\u5230\u6587\u4EF6 ${extra}\u3002`, `${extra} does not exist.`);
|
|
58604
58803
|
if (path75.resolve(extra).startsWith(root2 + path75.sep)) {
|
|
58605
58804
|
invalid2(
|
|
58606
58805
|
`${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 +58812,7 @@ async function templatePublish(dir, opts) {
|
|
|
58613
58812
|
}
|
|
58614
58813
|
const form = new FormData();
|
|
58615
58814
|
form.set("meta", JSON.stringify({ ...meta3, replace: !!opts.replace }));
|
|
58616
|
-
const add2 = (kind, name, file2) => form.append(`${kind}:${name}`, new Blob([
|
|
58815
|
+
const add2 = (kind, name, file2) => form.append(`${kind}:${name}`, new Blob([fs75.readFileSync(file2)]), path75.basename(name));
|
|
58617
58816
|
for (const f of files) add2("files", f, path75.join(root2, f));
|
|
58618
58817
|
for (const f of opts.preview) add2("previews", path75.basename(f), f);
|
|
58619
58818
|
for (const f of opts.evidence) add2("evidence", path75.basename(f), f);
|
|
@@ -58641,10 +58840,10 @@ Deleted ${name} from the catalog.`);
|
|
|
58641
58840
|
}
|
|
58642
58841
|
async function templateShowcase(name, dir) {
|
|
58643
58842
|
const file2 = path75.join(dir, "showcase.json");
|
|
58644
|
-
if (!
|
|
58843
|
+
if (!fs75.existsSync(file2)) invalid2(`${dir} \u4E2D\u7F3A\u5C11 showcase.json\u3002`, `showcase.json is missing from ${dir}.`);
|
|
58645
58844
|
let meta3;
|
|
58646
58845
|
try {
|
|
58647
|
-
meta3 = JSON.parse(
|
|
58846
|
+
meta3 = JSON.parse(fs75.readFileSync(file2, "utf8"));
|
|
58648
58847
|
} catch {
|
|
58649
58848
|
return invalid2("showcase.json \u4E0D\u662F\u6709\u6548\u7684 JSON\u3002", "showcase.json is not valid JSON.");
|
|
58650
58849
|
}
|
|
@@ -58657,8 +58856,8 @@ async function templateShowcase(name, dir) {
|
|
|
58657
58856
|
form.set("meta", JSON.stringify(meta3));
|
|
58658
58857
|
for (const p of new Set(named2)) {
|
|
58659
58858
|
const at = path75.join(dir, p);
|
|
58660
|
-
if (!
|
|
58661
|
-
form.append(`media:${p}`, new Blob([
|
|
58859
|
+
if (!fs75.existsSync(at)) invalid2(`\u627E\u4E0D\u5230\u6587\u4EF6 ${at}\u3002`, `${at} does not exist.`);
|
|
58860
|
+
form.append(`media:${p}`, new Blob([fs75.readFileSync(at)]), p);
|
|
58662
58861
|
}
|
|
58663
58862
|
const done = requireResponse(
|
|
58664
58863
|
await asJson(await ask(`/${encodeURIComponent(name)}/showcase`, { method: "PUT", body: form })),
|
|
@@ -58671,7 +58870,7 @@ Updated ${name}'s showcase: ${done.files} files.`);
|
|
|
58671
58870
|
}
|
|
58672
58871
|
function walk2(root2, sub = "") {
|
|
58673
58872
|
const out = [];
|
|
58674
|
-
for (const entry of
|
|
58873
|
+
for (const entry of fs75.readdirSync(path75.join(root2, sub), { withFileTypes: true })) {
|
|
58675
58874
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
58676
58875
|
const rel3 = sub ? `${sub}/${entry.name}` : entry.name;
|
|
58677
58876
|
if (entry.isDirectory()) out.push(...walk2(root2, rel3));
|
|
@@ -63162,7 +63361,7 @@ var init_guide2 = __esm({
|
|
|
63162
63361
|
|
|
63163
63362
|
// src/commands/studio.ts
|
|
63164
63363
|
import crypto7 from "node:crypto";
|
|
63165
|
-
import
|
|
63364
|
+
import fs76 from "node:fs";
|
|
63166
63365
|
import path76 from "node:path";
|
|
63167
63366
|
function cmdStudioList() {
|
|
63168
63367
|
if (!studiosReachable().ok) die(NEEDS_CLOUD, "needs-cloud");
|
|
@@ -63181,7 +63380,7 @@ function cmdStudioDiagram(_id, _card, _folder) {
|
|
|
63181
63380
|
}
|
|
63182
63381
|
function cmdStudioValidate(folder2) {
|
|
63183
63382
|
const dir = path76.resolve(folder2);
|
|
63184
|
-
if (!
|
|
63383
|
+
if (!fs76.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) die(`${folder2} is not a folder`, "bad-args");
|
|
63185
63384
|
const files = readStudioFolder(dir);
|
|
63186
63385
|
let builtin = false;
|
|
63187
63386
|
try {
|
|
@@ -63203,7 +63402,7 @@ async function cmdStudioPull(id2, folder2) {
|
|
|
63203
63402
|
found(id2);
|
|
63204
63403
|
}
|
|
63205
63404
|
const dir = path76.resolve(folder2 ?? id2);
|
|
63206
|
-
if (
|
|
63405
|
+
if (fs76.existsSync(dir) && fs76.readdirSync(dir).length) die(`${folder2 ?? id2} is not empty`, "bad-args");
|
|
63207
63406
|
const read5 = await call("GET", `/v1/studios/${encodeURIComponent(cloudId)}`);
|
|
63208
63407
|
const { version: version2, files } = requireResponse(
|
|
63209
63408
|
cloudOk(read5, read5.ok || read5.code !== "not_found" ? void 0 : "no-such-studio"),
|
|
@@ -63212,9 +63411,9 @@ async function cmdStudioPull(id2, folder2) {
|
|
|
63212
63411
|
);
|
|
63213
63412
|
for (const [file2, text5] of Object.entries({ ...files, [VERSION_FILE]: versionText(cloudId, version2) })) {
|
|
63214
63413
|
const full = path76.join(dir, ...file2.split("/"));
|
|
63215
|
-
|
|
63414
|
+
fs76.mkdirSync(path76.dirname(full), { recursive: true });
|
|
63216
63415
|
const data = isAboutFile(file2) && !file2.endsWith(".md") && /^data:[^;]+;base64,/.exec(text5);
|
|
63217
|
-
|
|
63416
|
+
fs76.writeFileSync(full, data ? Buffer.from(text5.slice(data[0].length), "base64") : text5);
|
|
63218
63417
|
}
|
|
63219
63418
|
const shown = folder2 ?? `./${id2}`;
|
|
63220
63419
|
say(`Pulled ${id2} v${version2} into ${shown}.`);
|
|
@@ -63230,13 +63429,13 @@ async function publishFolder(dir, route2, body, requestId) {
|
|
|
63230
63429
|
const hash3 = crypto7.createHash("sha256").update(JSON.stringify({ route: route2, files: body.files, workspace: body.workspace })).digest("hex");
|
|
63231
63430
|
let held4;
|
|
63232
63431
|
try {
|
|
63233
|
-
held4 = JSON.parse(
|
|
63432
|
+
held4 = JSON.parse(fs76.readFileSync(pendingFile, "utf8"));
|
|
63234
63433
|
} catch {
|
|
63235
63434
|
}
|
|
63236
63435
|
if (requestId && held4?.requestId === requestId && held4.hash !== hash3) die("This request ID already names different files; use a new request ID.", "bad-args");
|
|
63237
63436
|
const replay = held4?.hash === hash3 && held4.route === route2 && (!requestId || held4.requestId === requestId) && (body.expectedVersion === held4.body.expectedVersion || body.expectedVersion === held4.resultVersion);
|
|
63238
63437
|
const pending = replay ? held4 : { requestId: requestId ?? crypto7.randomUUID(), hash: hash3, body, route: route2 };
|
|
63239
|
-
|
|
63438
|
+
fs76.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
63240
63439
|
const res = await call(route2 === "/v1/studios" ? "POST" : "PATCH", route2, pending.body, pending.requestId);
|
|
63241
63440
|
const { id: id2, version: version2 } = requireResponse(
|
|
63242
63441
|
cloudOk(res, !res.ok && ["version_conflict", "conflict"].includes(res.code ?? "") ? "studio-moved" : void 0),
|
|
@@ -63244,8 +63443,8 @@ async function publishFolder(dir, route2, body, requestId) {
|
|
|
63244
63443
|
(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
63444
|
);
|
|
63246
63445
|
pending.resultVersion = version2;
|
|
63247
|
-
|
|
63248
|
-
|
|
63446
|
+
fs76.writeFileSync(pendingFile, JSON.stringify(pending, null, 2) + "\n");
|
|
63447
|
+
fs76.writeFileSync(path76.join(dir, VERSION_FILE), versionText(id2, version2));
|
|
63249
63448
|
say(`Saved ${studioName(id2)} v${version2}. New tasks take it.`);
|
|
63250
63449
|
return { id: id2, version: version2, changed: true, requestId: pending.requestId };
|
|
63251
63450
|
}
|
|
@@ -63260,14 +63459,14 @@ async function cmdStudioPush(folder2, opts) {
|
|
|
63260
63459
|
const dir = path76.resolve(folder2);
|
|
63261
63460
|
let pulled = null;
|
|
63262
63461
|
try {
|
|
63263
|
-
pulled = JSON.parse(
|
|
63462
|
+
pulled = JSON.parse(fs76.readFileSync(path76.join(dir, VERSION_FILE), "utf8"));
|
|
63264
63463
|
} catch {
|
|
63265
63464
|
}
|
|
63266
63465
|
if (!pulled?.id || !Number.isInteger(pulled.version) || pulled.version < 1) die(`${folder2} has no valid version.json; pull again.`, "bad-args");
|
|
63267
63466
|
const { id: id2, version: version2 } = pulled;
|
|
63268
63467
|
if (id2.startsWith("wf_builtin_")) die("Copy this studio before editing it.", "studio-read-only");
|
|
63269
63468
|
const files = publicationFiles(dir);
|
|
63270
|
-
if (!
|
|
63469
|
+
if (!fs76.existsSync(path76.join(dir, ".publication.json")) && !opts.requestId) {
|
|
63271
63470
|
const now = await call("GET", `/v1/studios/${encodeURIComponent(id2)}`);
|
|
63272
63471
|
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
63472
|
say(`${studioName(id2)} is unchanged (v${version2}).`);
|
|
@@ -63290,7 +63489,7 @@ function noteText({ file: file2, text: text5 }) {
|
|
|
63290
63489
|
if (file2 !== void 0 && text5 !== void 0) die("pass --file or --text, not both", "bad-args");
|
|
63291
63490
|
if (file2 !== void 0) {
|
|
63292
63491
|
try {
|
|
63293
|
-
return
|
|
63492
|
+
return fs76.readFileSync(file2, "utf8").trim();
|
|
63294
63493
|
} catch {
|
|
63295
63494
|
die(`can't read ${file2}`, "bad-args");
|
|
63296
63495
|
}
|
|
@@ -63476,7 +63675,7 @@ var init_progress = __esm({
|
|
|
63476
63675
|
});
|
|
63477
63676
|
|
|
63478
63677
|
// src/lib/agent/complete.ts
|
|
63479
|
-
import
|
|
63678
|
+
import fs77 from "node:fs";
|
|
63480
63679
|
function checkRecordedResult(receipt, commit, branch) {
|
|
63481
63680
|
if (receipt.commit === commit && receipt.branch === branch) return;
|
|
63482
63681
|
const describe4 = (hash3, target) => hash3 ? `${hash3} on ${target}` : "no Git result";
|
|
@@ -63504,7 +63703,7 @@ function completeDelivery(named2, result = {}) {
|
|
|
63504
63703
|
const run3 = store.runs.find((r) => r.sessionId === sessionId);
|
|
63505
63704
|
const current = store.runs.filter((r) => r.deliveryId === delivery2.deliveryId && ["implement", "scheduled"].includes(r.action)).pop();
|
|
63506
63705
|
const liveCard = delivery2.cardId === null ? null : cardFile(delivery2.cardId);
|
|
63507
|
-
const restored = liveCard && parseFrontmatter(
|
|
63706
|
+
const restored = liveCard && parseFrontmatter(fs77.readFileSync(liveCard, "utf8")).meta?.restored;
|
|
63508
63707
|
if (restored && Date.parse(restored) > (run3?.startedAt ?? 0)) throw new Error("This delivery predates task restoration.");
|
|
63509
63708
|
if (!run3 || run3.deliveryId !== delivery2.deliveryId) throw new Error("This run does not own the delivery.");
|
|
63510
63709
|
const pending = receipts[deliveryStep(delivery2)];
|
|
@@ -63612,7 +63811,7 @@ function startSubRun(parentId, prompt, runtime) {
|
|
|
63612
63811
|
const parent = peekRun(parentId);
|
|
63613
63812
|
if (!parent || parent.status !== "running") return refusal("runNotFound", `run ${parentId.slice(0, 8)} is not running here`, { id: parentId });
|
|
63614
63813
|
if (parent.action === "sub") return refusal("subRunNested", "a sub-run cannot start sub-runs of its own");
|
|
63615
|
-
const inherited = parent.runtime &&
|
|
63814
|
+
const inherited = parent.runtime && runRuntimeById(parent.runtime) ? parent.runtime : void 0;
|
|
63616
63815
|
return open3(
|
|
63617
63816
|
{
|
|
63618
63817
|
action: "sub",
|
|
@@ -63675,7 +63874,7 @@ var init_start = __esm({
|
|
|
63675
63874
|
});
|
|
63676
63875
|
|
|
63677
63876
|
// src/lib/agent/task-chats.ts
|
|
63678
|
-
import
|
|
63877
|
+
import fs78 from "node:fs";
|
|
63679
63878
|
import path77 from "node:path";
|
|
63680
63879
|
function taskChatFile(task, home3) {
|
|
63681
63880
|
if (!TASK.test(task)) throw new Error(`${task} is not a task id.`);
|
|
@@ -63684,7 +63883,7 @@ function taskChatFile(task, home3) {
|
|
|
63684
63883
|
function readTaskChat(task, home3) {
|
|
63685
63884
|
let text5;
|
|
63686
63885
|
try {
|
|
63687
|
-
text5 =
|
|
63886
|
+
text5 = fs78.readFileSync(taskChatFile(task, home3), "utf8");
|
|
63688
63887
|
} catch {
|
|
63689
63888
|
return [];
|
|
63690
63889
|
}
|
|
@@ -63710,7 +63909,7 @@ var init_task_chats = __esm({
|
|
|
63710
63909
|
});
|
|
63711
63910
|
|
|
63712
63911
|
// src/lib/agent/memory-review.ts
|
|
63713
|
-
import
|
|
63912
|
+
import fs79 from "node:fs";
|
|
63714
63913
|
import path78 from "node:path";
|
|
63715
63914
|
function taskChatsToReview(tasks) {
|
|
63716
63915
|
const out = [];
|
|
@@ -63734,7 +63933,7 @@ function readArchived2(id2) {
|
|
|
63734
63933
|
if (!found2) return null;
|
|
63735
63934
|
try {
|
|
63736
63935
|
const file2 = found2.kind === "group" ? path78.join(found2.target, "root.md") : found2.target;
|
|
63737
|
-
const { meta: meta3, body } = parseFrontmatter(
|
|
63936
|
+
const { meta: meta3, body } = parseFrontmatter(fs79.readFileSync(file2, "utf8"));
|
|
63738
63937
|
if (!meta3) return null;
|
|
63739
63938
|
return { id: id2, title: meta3.title, modules: meta3.modules ?? [], studio: meta3.studio ?? "", previews: meta3.previews ?? [], rejected: meta3.rejected, body };
|
|
63740
63939
|
} catch {
|
|
@@ -63795,18 +63994,18 @@ var init_memory_review = __esm({
|
|
|
63795
63994
|
});
|
|
63796
63995
|
|
|
63797
63996
|
// src/lib/agent/dismissal-review.ts
|
|
63798
|
-
import
|
|
63997
|
+
import fs80 from "node:fs";
|
|
63799
63998
|
import path79 from "node:path";
|
|
63800
63999
|
function rejectionsToReview() {
|
|
63801
64000
|
const scratch = process.env.AI4KANBAN_REJECTION_INPUT;
|
|
63802
64001
|
const dir = path79.join(scratch ? path79.join(scratch, ".archive") : ARCHIVE, REJECTIONS_TO_REVIEW);
|
|
63803
|
-
if (!
|
|
64002
|
+
if (!fs80.existsSync(dir)) return [];
|
|
63804
64003
|
const found2 = [];
|
|
63805
64004
|
for (const file2 of walkMd(dir)) {
|
|
63806
64005
|
const id2 = archivedId(file2);
|
|
63807
64006
|
if (id2 === null) continue;
|
|
63808
64007
|
try {
|
|
63809
|
-
const { meta: meta3 } = parseFrontmatter(
|
|
64008
|
+
const { meta: meta3 } = parseFrontmatter(fs80.readFileSync(file2, "utf8"));
|
|
63810
64009
|
if (!meta3?.rejected || meta3.rejected_by !== "user" || !meta3.rejected_reason.trim()) continue;
|
|
63811
64010
|
found2.push({ id: id2, title: meta3.title, file: rel(file2), reason: meta3.rejected_reason.trim(), rejectedAt: meta3.rejected_at });
|
|
63812
64011
|
} catch {
|
|
@@ -63828,7 +64027,7 @@ function citedSources(text5) {
|
|
|
63828
64027
|
const ids = /* @__PURE__ */ new Set();
|
|
63829
64028
|
for (const line of text5.split("\n")) {
|
|
63830
64029
|
if (!/^\s*[-*]\s/.test(line)) continue;
|
|
63831
|
-
const m = line.match(
|
|
64030
|
+
const m = line.match(SOURCES2);
|
|
63832
64031
|
for (const id2 of m?.[1].split(",") ?? []) if (id2.trim()) ids.add(id2.trim());
|
|
63833
64032
|
}
|
|
63834
64033
|
return [...ids];
|
|
@@ -63836,7 +64035,7 @@ function citedSources(text5) {
|
|
|
63836
64035
|
function withdrawnSources() {
|
|
63837
64036
|
const cited = [...new Set(plannerCopies("rejected.md").flatMap((file2) => {
|
|
63838
64037
|
try {
|
|
63839
|
-
return citedSources(
|
|
64038
|
+
return citedSources(fs80.readFileSync(file2, "utf8"));
|
|
63840
64039
|
} catch {
|
|
63841
64040
|
return [];
|
|
63842
64041
|
}
|
|
@@ -63847,7 +64046,7 @@ function withdrawnSources() {
|
|
|
63847
64046
|
const restored = new Set([...readInbox(), ...readArchived(scratch ? path79.join(scratch, "triage", "archived") : void 0)].map((s) => s.sourceId));
|
|
63848
64047
|
return cited.filter((id2) => restored.has(id2) && !dismissed.has(id2));
|
|
63849
64048
|
}
|
|
63850
|
-
var reviewDismissed,
|
|
64049
|
+
var reviewDismissed, SOURCES2;
|
|
63851
64050
|
var init_dismissal_review = __esm({
|
|
63852
64051
|
"src/lib/agent/dismissal-review.ts"() {
|
|
63853
64052
|
"use strict";
|
|
@@ -63861,12 +64060,12 @@ var init_dismissal_review = __esm({
|
|
|
63861
64060
|
const scratch = process.env.AI4KANBAN_REJECTION_INPUT;
|
|
63862
64061
|
return readAllDismissed(scratch ? path79.join(scratch, "triage", "dismissed") : void 0);
|
|
63863
64062
|
};
|
|
63864
|
-
|
|
64063
|
+
SOURCES2 = /\(([^()]+)\)\s*$/;
|
|
63865
64064
|
}
|
|
63866
64065
|
});
|
|
63867
64066
|
|
|
63868
64067
|
// src/lib/agent/flow.ts
|
|
63869
|
-
import
|
|
64068
|
+
import fs81 from "node:fs";
|
|
63870
64069
|
import path80 from "node:path";
|
|
63871
64070
|
function readCard2(id2, home3 = "board") {
|
|
63872
64071
|
const pending = activeDelivery(id2)?.completions?.some((c) => !c.finished);
|
|
@@ -63880,7 +64079,7 @@ function readCard2(id2, home3 = "board") {
|
|
|
63880
64079
|
const file2 = found2.kind === "group" ? path80.join(found2.target, "root.md") : found2.target;
|
|
63881
64080
|
let text5;
|
|
63882
64081
|
try {
|
|
63883
|
-
text5 =
|
|
64082
|
+
text5 = fs81.readFileSync(file2, "utf8");
|
|
63884
64083
|
} catch {
|
|
63885
64084
|
die(`#${id2} is on the board but ${rel(file2)} can't be read.`, { kind: "card-unreadable", id: id2 });
|
|
63886
64085
|
}
|
|
@@ -64725,7 +64924,7 @@ __export(watch_exports, {
|
|
|
64725
64924
|
watchRun: () => watchRun
|
|
64726
64925
|
});
|
|
64727
64926
|
import { spawn as spawn3 } from "node:child_process";
|
|
64728
|
-
import
|
|
64927
|
+
import fs82 from "node:fs";
|
|
64729
64928
|
async function watchRun(sessionId, resume = startResume, retryBackoff = backoffMs) {
|
|
64730
64929
|
const spec = readSpec(sessionId);
|
|
64731
64930
|
const run3 = peekRun(sessionId);
|
|
@@ -64761,20 +64960,24 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64761
64960
|
const record2 = claimed ?? run3;
|
|
64762
64961
|
const sub = record2.action === "sub";
|
|
64763
64962
|
if (claim2) await setCardStatus(claim2.cardId, claim2.status);
|
|
64764
|
-
|
|
64765
|
-
const logFile =
|
|
64963
|
+
fs82.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
64964
|
+
const logFile = fs82.createWriteStream(record2.logPath, { flags: "a" });
|
|
64766
64965
|
logFile.on("error", () => {
|
|
64767
64966
|
});
|
|
64768
|
-
const eventsFile =
|
|
64967
|
+
const eventsFile = fs82.createWriteStream(eventsPathOf(sessionId), { flags: "a" });
|
|
64769
64968
|
eventsFile.on("error", () => {
|
|
64770
64969
|
});
|
|
64771
64970
|
let observeActivity = (_e) => {
|
|
64772
64971
|
};
|
|
64773
64972
|
const pendingOperations = /* @__PURE__ */ new Set();
|
|
64973
|
+
let hadEffects = false;
|
|
64774
64974
|
const event2 = (e) => {
|
|
64775
64975
|
observeActivity(e);
|
|
64776
64976
|
const hadPending = pendingOperations.size > 0;
|
|
64777
|
-
if (e.kind === "tool_call" && !["read", "search", "fetch"].includes(e.data.kind)
|
|
64977
|
+
if (e.kind === "tool_call" && !["read", "search", "fetch"].includes(e.data.kind)) {
|
|
64978
|
+
hadEffects = true;
|
|
64979
|
+
if (!["completed", "failed"].includes(e.data.status)) pendingOperations.add(e.data.toolCallId);
|
|
64980
|
+
}
|
|
64778
64981
|
if ((e.kind === "tool_call" || e.kind === "tool_call_update") && ["completed", "failed"].includes(e.data.status ?? "")) pendingOperations.delete(e.data.toolCallId);
|
|
64779
64982
|
if (record2.cloudExecution && hadPending !== pendingOperations.size > 0) {
|
|
64780
64983
|
patch(sessionId, (run4) => {
|
|
@@ -64784,6 +64987,11 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64784
64987
|
eventsFile.write(`${JSON.stringify(e)}
|
|
64785
64988
|
`);
|
|
64786
64989
|
};
|
|
64990
|
+
const runtimeInfo = () => ({
|
|
64991
|
+
connector: record2.harness,
|
|
64992
|
+
name: record2.runtime ? runtimeById(record2.runtime)?.name ?? null : null,
|
|
64993
|
+
model: peekRun(sessionId)?.model ?? record2.model ?? null
|
|
64994
|
+
});
|
|
64787
64995
|
const log = {
|
|
64788
64996
|
write(text5) {
|
|
64789
64997
|
logFile.write(text5);
|
|
@@ -64818,7 +65026,8 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64818
65026
|
`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
65027
|
...coding && !approvedUi && review?.plan?.some((node2) => node2.previews.includes("ui-design")) ? [APPROVED_UI_RULE] : []
|
|
64820
65028
|
].join("\n") : "";
|
|
64821
|
-
const
|
|
65029
|
+
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.` : "";
|
|
65030
|
+
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
65031
|
const before = markBoard();
|
|
64823
65032
|
const takes = active3.images;
|
|
64824
65033
|
active3.renderer?.setRequiredImages?.(record2.pictures ?? []);
|
|
@@ -64846,11 +65055,29 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
64846
65055
|
letGo();
|
|
64847
65056
|
return 1;
|
|
64848
65057
|
}
|
|
64849
|
-
if (record2.retry?.launching)
|
|
64850
|
-
|
|
64851
|
-
r
|
|
64852
|
-
|
|
64853
|
-
|
|
65058
|
+
if (record2.retry?.launching) {
|
|
65059
|
+
const nextAttempt = record2.retry.attempt + 1;
|
|
65060
|
+
patch(sessionId, (r) => {
|
|
65061
|
+
if (!r.retry?.launching) return;
|
|
65062
|
+
r.retry.attempt++;
|
|
65063
|
+
delete r.retry.launching;
|
|
65064
|
+
});
|
|
65065
|
+
event2({
|
|
65066
|
+
kind: "retry",
|
|
65067
|
+
data: {
|
|
65068
|
+
state: "retrying",
|
|
65069
|
+
source: record2.failure?.source ?? "runtime",
|
|
65070
|
+
runtime: runtimeInfo(),
|
|
65071
|
+
attempt: nextAttempt,
|
|
65072
|
+
maxAttempts: record2.retry.of,
|
|
65073
|
+
summary: record2.failure?.summary ?? record2.retry.reason,
|
|
65074
|
+
...record2.failure?.detail ? { detail: record2.failure.detail } : {},
|
|
65075
|
+
...record2.failure?.code ? { code: record2.failure.code } : {},
|
|
65076
|
+
sessionAction: record2.resumedFrom ? "resume" : "reset_replay",
|
|
65077
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
65078
|
+
}
|
|
65079
|
+
});
|
|
65080
|
+
}
|
|
64854
65081
|
try {
|
|
64855
65082
|
const start = spawnable(cmd, client || stdinPrompt ? args2 : [...args2, prompt], {
|
|
64856
65083
|
// Where this run works: the project, or — inside a delivery with a worktree of its
|
|
@@ -65034,34 +65261,79 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
65034
65261
|
const rendered = renderer?.failure?.() ?? (!taskCompleted && renderer?.background?.() ? "The agent exited with unfinished background tasks." : void 0);
|
|
65035
65262
|
const said2 = spawnError ?? (silent ? silenceSaid(silenceFor) : spoken?.error ?? rendered);
|
|
65036
65263
|
const failed2 = code !== 0 || spoken?.ok === false || !!rendered || silent || !!blocker;
|
|
65037
|
-
const failure2 = failed2 && !asked ? silent ? {
|
|
65264
|
+
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}.`, {
|
|
65265
|
+
code: blocker ? "execution_blocked" : "execution_failed",
|
|
65266
|
+
detail: said2 ?? blocker?.cause ?? `Agent exited with code ${code}.`
|
|
65267
|
+
}) : void 0;
|
|
65038
65268
|
const result = spoken ? spoken.result : renderer?.result();
|
|
65039
65269
|
let retryPause;
|
|
65040
65270
|
let retrying = false;
|
|
65271
|
+
let retryHistory = held4.retryHistory ? [...held4.retryHistory] : void 0;
|
|
65272
|
+
let sessionAction;
|
|
65041
65273
|
if (failure2 && !sub && !taskCompleted) {
|
|
65042
65274
|
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
|
-
|
|
65275
|
+
const missingSession = isSessionMissingFailure(failure2);
|
|
65276
|
+
const mark = runMark(sessionId, agentStartedAt);
|
|
65277
|
+
const root2 = child.pid ? { pid: child.pid, since: agentStartedAt, identity: held4.agentIdentity } : void 0;
|
|
65278
|
+
const stopped3 = () => client?.managedProcess ? connectionStopped(root2) : processesStopped(mark, root2);
|
|
65279
|
+
const until = Date.now() + STOP_GRACE_MS + STOP_CLOSE_MS;
|
|
65280
|
+
while (!stopped3() && Date.now() < until) await sleep4(100);
|
|
65281
|
+
const isStopped = stopped3();
|
|
65282
|
+
const session = structured && !spawnFailure && !missingSession ? resumeSessionId(held4) : void 0;
|
|
65283
|
+
const unconfirmedCleanup = pendingOperations.size > 0 || !!blocker || spoken?.cleanup?.status === "unconfirmed" || failure2.code === "codex_ownership_unconfirmed" || client?.managedProcess && silent && (uncertainAtIdle || !idleStopConfirmed(spoken?.cleanup, session));
|
|
65284
|
+
const canResetReplay = isStopped && !unconfirmedCleanup && !pendingOperations.size && (held4.unspawned === true || structured && !hadEffects && !record2.resumedFrom);
|
|
65285
|
+
const recovery = missingSession ? canResetReplay ? "replay" : "unsafe" : agentRecovery({
|
|
65286
|
+
stopped: isStopped,
|
|
65287
|
+
session,
|
|
65288
|
+
replayable: canResetReplay,
|
|
65289
|
+
unconfirmedCleanup
|
|
65290
|
+
});
|
|
65291
|
+
sessionAction = recovery === "unsafe" ? "pause_unsafe" : recovery === "replay" ? "reset_replay" : "resume";
|
|
65292
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
65293
|
+
const retryRecord = {
|
|
65294
|
+
attempt: attempt2,
|
|
65295
|
+
source: failure2.source,
|
|
65296
|
+
runtime: runtimeInfo(),
|
|
65297
|
+
summary: failure2.summary,
|
|
65298
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
65299
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
65300
|
+
sessionAction,
|
|
65301
|
+
at: nowIso
|
|
65302
|
+
};
|
|
65303
|
+
retryHistory = [...retryHistory ?? [], retryRecord];
|
|
65304
|
+
if (recovery === "unsafe") {
|
|
65305
|
+
retryPause = "unsafe";
|
|
65306
|
+
} else {
|
|
65307
|
+
const decision = planRetry(failure2, attempt2, Date.now(), retryBackoff, !!held4.cloudExecution);
|
|
65308
|
+
if ("pause" in decision) {
|
|
65309
|
+
retryPause = decision.pause;
|
|
65310
|
+
} else {
|
|
65311
|
+
const pending = { ...decision.plan, sessionAction };
|
|
65061
65312
|
patch(sessionId, (r) => {
|
|
65062
65313
|
r.failure = failure2;
|
|
65063
|
-
r.error = said2 ?? failure2.
|
|
65064
|
-
r.
|
|
65314
|
+
r.error = said2 ?? failure2.summary;
|
|
65315
|
+
r.retryHistory = retryHistory;
|
|
65316
|
+
if (sessionAction === "reset_replay") {
|
|
65317
|
+
r.resumeId = void 0;
|
|
65318
|
+
r.unspawned = true;
|
|
65319
|
+
}
|
|
65320
|
+
r.retry = { attempt: attempt2, of: pending.of, reason: failure2.summary, at: pending.at, since: held4.retry?.since ?? held4.startedAt, pending };
|
|
65321
|
+
});
|
|
65322
|
+
event2({
|
|
65323
|
+
kind: "retry",
|
|
65324
|
+
data: {
|
|
65325
|
+
state: "waiting",
|
|
65326
|
+
source: failure2.source,
|
|
65327
|
+
runtime: runtimeInfo(),
|
|
65328
|
+
attempt: attempt2 + 1,
|
|
65329
|
+
maxAttempts: pending.of,
|
|
65330
|
+
summary: failure2.summary,
|
|
65331
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
65332
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
65333
|
+
nextRetryAt: new Date(pending.at).toISOString(),
|
|
65334
|
+
sessionAction,
|
|
65335
|
+
at: nowIso
|
|
65336
|
+
}
|
|
65065
65337
|
});
|
|
65066
65338
|
log.write(`
|
|
65067
65339
|
[board] ${retryLine(pending, attempt2)}
|
|
@@ -65070,11 +65342,44 @@ async function watchRun(sessionId, resume = startResume, retryBackoff = backoffM
|
|
|
65070
65342
|
retrying = true;
|
|
65071
65343
|
}
|
|
65072
65344
|
}
|
|
65345
|
+
if (retryPause && !stoppedByUser()) {
|
|
65346
|
+
event2({
|
|
65347
|
+
kind: "retry",
|
|
65348
|
+
data: {
|
|
65349
|
+
state: "paused",
|
|
65350
|
+
source: failure2.source,
|
|
65351
|
+
runtime: runtimeInfo(),
|
|
65352
|
+
attempt: attempt2,
|
|
65353
|
+
maxAttempts: held4.retry?.of ?? MAX_RETRY_ATTEMPTS,
|
|
65354
|
+
summary: failure2.summary,
|
|
65355
|
+
...failure2.detail ? { detail: failure2.detail } : {},
|
|
65356
|
+
...failure2.code ? { code: failure2.code } : {},
|
|
65357
|
+
sessionAction,
|
|
65358
|
+
at: nowIso
|
|
65359
|
+
}
|
|
65360
|
+
});
|
|
65361
|
+
}
|
|
65073
65362
|
}
|
|
65074
65363
|
asked ||= stoppedByUser();
|
|
65075
65364
|
retrying &&= !asked;
|
|
65076
|
-
const error62 = asked ? void 0 : joinNotes(said2 ?? failure2?.
|
|
65365
|
+
const error62 = asked ? void 0 : joinNotes(said2 ?? failure2?.summary, retryPause ? pauseLine(retryPause) : void 0);
|
|
65077
65366
|
const status = asked ? "stopped" : failed2 || code !== 0 ? "error" : "done";
|
|
65367
|
+
if (status === "done" && !sub && retryHistory?.length) {
|
|
65368
|
+
const lastRetry = retryHistory[retryHistory.length - 1];
|
|
65369
|
+
event2({
|
|
65370
|
+
kind: "retry",
|
|
65371
|
+
data: {
|
|
65372
|
+
state: "recovered",
|
|
65373
|
+
source: lastRetry.source,
|
|
65374
|
+
runtime: runtimeInfo(),
|
|
65375
|
+
attempt: held4.retry?.attempt ?? retryHistory.length + 1,
|
|
65376
|
+
maxAttempts: held4.retry?.of ?? MAX_RETRY_ATTEMPTS,
|
|
65377
|
+
summary: lastRetry.summary,
|
|
65378
|
+
...lastRetry.code ? { code: lastRetry.code } : {},
|
|
65379
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
65380
|
+
}
|
|
65381
|
+
});
|
|
65382
|
+
}
|
|
65078
65383
|
const reported = spoken ? spoken.costUsd : renderer?.costUsd?.();
|
|
65079
65384
|
const totals = reportsSessionTotal(record2.harness);
|
|
65080
65385
|
const sessionTotal = totals ? reported : void 0;
|
|
@@ -65137,6 +65442,7 @@ ${result}
|
|
|
65137
65442
|
error: error62,
|
|
65138
65443
|
failure: failure2,
|
|
65139
65444
|
retryPause,
|
|
65445
|
+
retryHistory,
|
|
65140
65446
|
note,
|
|
65141
65447
|
errorWhy,
|
|
65142
65448
|
noteWhy,
|
|
@@ -65329,6 +65635,7 @@ var init_watch = __esm({
|
|
|
65329
65635
|
init_idle();
|
|
65330
65636
|
init_codex_background_types();
|
|
65331
65637
|
init_retry();
|
|
65638
|
+
init_runtimes();
|
|
65332
65639
|
init_failures();
|
|
65333
65640
|
init_execution();
|
|
65334
65641
|
init_refine2();
|
|
@@ -65343,7 +65650,7 @@ var init_watch = __esm({
|
|
|
65343
65650
|
});
|
|
65344
65651
|
|
|
65345
65652
|
// src/commands/run.ts
|
|
65346
|
-
import
|
|
65653
|
+
import fs83 from "node:fs";
|
|
65347
65654
|
import path82 from "node:path";
|
|
65348
65655
|
async function cmdStartRun(action, args2, opts, program2 = "akb") {
|
|
65349
65656
|
const { req, follow: follow2, print } = readRequest(action, args2, opts);
|
|
@@ -65570,7 +65877,7 @@ async function cmdSubStart(words, opts) {
|
|
|
65570
65877
|
let prompt = words.join(" ");
|
|
65571
65878
|
if (opts.file) {
|
|
65572
65879
|
try {
|
|
65573
|
-
prompt =
|
|
65880
|
+
prompt = fs83.readFileSync(path82.resolve(opts.file), "utf8");
|
|
65574
65881
|
} catch {
|
|
65575
65882
|
die(`--file: cannot read ${opts.file}`, { kind: "run-refused" });
|
|
65576
65883
|
}
|
|
@@ -65919,12 +66226,12 @@ var init_config3 = __esm({
|
|
|
65919
66226
|
});
|
|
65920
66227
|
|
|
65921
66228
|
// src/lib/signals/migrate.ts
|
|
65922
|
-
import
|
|
66229
|
+
import fs84 from "node:fs";
|
|
65923
66230
|
import path83 from "node:path";
|
|
65924
66231
|
function readHandled() {
|
|
65925
66232
|
let text5;
|
|
65926
66233
|
try {
|
|
65927
|
-
text5 =
|
|
66234
|
+
text5 = fs84.readFileSync(SIGNALS_OLD_HANDLED, "utf8");
|
|
65928
66235
|
} catch {
|
|
65929
66236
|
return [];
|
|
65930
66237
|
}
|
|
@@ -65941,45 +66248,45 @@ function readHandled() {
|
|
|
65941
66248
|
return held4;
|
|
65942
66249
|
}
|
|
65943
66250
|
function lift(from, into) {
|
|
65944
|
-
|
|
65945
|
-
|
|
66251
|
+
fs84.mkdirSync(into, { recursive: true });
|
|
66252
|
+
fs84.renameSync(from, path83.join(into, freeName(into, path83.basename(from))));
|
|
65946
66253
|
}
|
|
65947
66254
|
function repoint(dir, from, into) {
|
|
65948
66255
|
let entries2;
|
|
65949
66256
|
try {
|
|
65950
|
-
entries2 =
|
|
66257
|
+
entries2 = fs84.readdirSync(dir, { withFileTypes: true });
|
|
65951
66258
|
} catch {
|
|
65952
66259
|
return;
|
|
65953
66260
|
}
|
|
65954
66261
|
for (const entry of entries2) {
|
|
65955
66262
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
65956
66263
|
const file2 = path83.join(dir, entry.name);
|
|
65957
|
-
const text5 =
|
|
65958
|
-
if (text5.includes(from))
|
|
66264
|
+
const text5 = fs84.readFileSync(file2, "utf8");
|
|
66265
|
+
if (text5.includes(from)) fs84.writeFileSync(file2, text5.split(from).join(into));
|
|
65959
66266
|
}
|
|
65960
66267
|
}
|
|
65961
66268
|
function dropIfEmpty(dir) {
|
|
65962
66269
|
try {
|
|
65963
|
-
|
|
66270
|
+
fs84.rmdirSync(dir);
|
|
65964
66271
|
} catch {
|
|
65965
66272
|
}
|
|
65966
66273
|
}
|
|
65967
66274
|
function liftInbox() {
|
|
65968
|
-
if (!
|
|
66275
|
+
if (!fs84.existsSync(SIGNALS_OLD_INBOX)) return;
|
|
65969
66276
|
const oldFiles = path83.join(SIGNALS_OLD_INBOX, "files");
|
|
65970
|
-
if (
|
|
65971
|
-
for (const entry of
|
|
66277
|
+
if (fs84.existsSync(oldFiles)) {
|
|
66278
|
+
for (const entry of fs84.readdirSync(oldFiles, { withFileTypes: true })) {
|
|
65972
66279
|
if (entry.isFile()) lift(path83.join(oldFiles, entry.name), SIGNALS_FILES);
|
|
65973
66280
|
}
|
|
65974
66281
|
dropIfEmpty(oldFiles);
|
|
65975
66282
|
}
|
|
65976
66283
|
const held4 = new Set(readFolder(TRIAGE).map((signal2) => signal2.sourceId));
|
|
65977
|
-
for (const entry of
|
|
66284
|
+
for (const entry of fs84.readdirSync(SIGNALS_OLD_INBOX, { withFileTypes: true })) {
|
|
65978
66285
|
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
65979
66286
|
const from = path83.join(SIGNALS_OLD_INBOX, entry.name);
|
|
65980
66287
|
const item = parse3(from);
|
|
65981
66288
|
if (item && held4.has(item.sourceId)) {
|
|
65982
|
-
|
|
66289
|
+
fs84.rmSync(from, { force: true });
|
|
65983
66290
|
continue;
|
|
65984
66291
|
}
|
|
65985
66292
|
if (item) held4.add(item.sourceId);
|
|
@@ -65991,7 +66298,7 @@ function liftInbox() {
|
|
|
65991
66298
|
dropIfEmpty(SIGNALS_OLD_INBOX);
|
|
65992
66299
|
}
|
|
65993
66300
|
function liftHandled() {
|
|
65994
|
-
if (!
|
|
66301
|
+
if (!fs84.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
65995
66302
|
const lines = readHandled();
|
|
65996
66303
|
const held4 = /* @__PURE__ */ new Set([
|
|
65997
66304
|
...readFolder(TRIAGE).map((signal2) => signal2.sourceId),
|
|
@@ -66001,7 +66308,7 @@ function liftHandled() {
|
|
|
66001
66308
|
for (const { sourceId, when } of lines) {
|
|
66002
66309
|
if (held4.has(sourceId)) continue;
|
|
66003
66310
|
held4.add(sourceId);
|
|
66004
|
-
|
|
66311
|
+
fs84.mkdirSync(SIGNALS_DISMISSED, { recursive: true });
|
|
66005
66312
|
const name = freeName(SIGNALS_DISMISSED, fileName("", sourceId));
|
|
66006
66313
|
const front = [
|
|
66007
66314
|
"---",
|
|
@@ -66011,13 +66318,13 @@ function liftHandled() {
|
|
|
66011
66318
|
"---",
|
|
66012
66319
|
""
|
|
66013
66320
|
];
|
|
66014
|
-
|
|
66321
|
+
fs84.writeFileSync(path83.join(SIGNALS_DISMISSED, name), `${front.join("\n")}
|
|
66015
66322
|
`);
|
|
66016
66323
|
}
|
|
66017
|
-
|
|
66324
|
+
fs84.rmSync(SIGNALS_OLD_HANDLED, { force: true });
|
|
66018
66325
|
}
|
|
66019
66326
|
function migrateTriage() {
|
|
66020
|
-
if (!
|
|
66327
|
+
if (!fs84.existsSync(SIGNALS_OLD_INBOX) && !fs84.existsSync(SIGNALS_OLD_HANDLED)) return;
|
|
66021
66328
|
try {
|
|
66022
66329
|
liftInbox();
|
|
66023
66330
|
liftHandled();
|
|
@@ -66085,7 +66392,7 @@ var init_identity2 = __esm({
|
|
|
66085
66392
|
});
|
|
66086
66393
|
|
|
66087
66394
|
// src/lib/signals/add.ts
|
|
66088
|
-
import
|
|
66395
|
+
import fs85 from "node:fs";
|
|
66089
66396
|
import path84 from "node:path";
|
|
66090
66397
|
import { createHash as createHash8 } from "node:crypto";
|
|
66091
66398
|
function linkTitle(url2) {
|
|
@@ -66144,8 +66451,8 @@ ${incoming.summary}`);
|
|
|
66144
66451
|
if (seen.status === "pending" || seen.status === "archived") return { ok: false, error: `${sayHit(seen)}.` };
|
|
66145
66452
|
try {
|
|
66146
66453
|
if (keep2) {
|
|
66147
|
-
|
|
66148
|
-
|
|
66454
|
+
fs85.mkdirSync(SIGNALS_FILES, { recursive: true });
|
|
66455
|
+
fs85.writeFileSync(keep2.at, keep2.data);
|
|
66149
66456
|
}
|
|
66150
66457
|
return { ok: true, signal: writeSignal({ ...incoming, sourceId }, formatStamp(/* @__PURE__ */ new Date()), drop.slug) };
|
|
66151
66458
|
} catch (e) {
|
|
@@ -66256,7 +66563,7 @@ var init_signals = __esm({
|
|
|
66256
66563
|
});
|
|
66257
66564
|
|
|
66258
66565
|
// src/commands/triage.ts
|
|
66259
|
-
import
|
|
66566
|
+
import fs86 from "node:fs";
|
|
66260
66567
|
async function cmdTriageAdd(opts) {
|
|
66261
66568
|
const title = (opts.title ?? "").trim();
|
|
66262
66569
|
if (!title) die('say what it is: --title "<one line>"', { kind: "needs-input" });
|
|
@@ -66266,7 +66573,7 @@ async function cmdTriageAdd(opts) {
|
|
|
66266
66573
|
let body = opts.text;
|
|
66267
66574
|
if (opts.file !== void 0) {
|
|
66268
66575
|
try {
|
|
66269
|
-
body =
|
|
66576
|
+
body = fs86.readFileSync(opts.file, "utf8");
|
|
66270
66577
|
} catch {
|
|
66271
66578
|
die(`can't read ${opts.file} \u2014 write the item to a file, then pass its path`, { kind: "needs-input" });
|
|
66272
66579
|
}
|
|
@@ -66320,21 +66627,21 @@ var init_previews = __esm({
|
|
|
66320
66627
|
});
|
|
66321
66628
|
|
|
66322
66629
|
// src/commands/studio-preview.ts
|
|
66323
|
-
import
|
|
66630
|
+
import fs87 from "node:fs";
|
|
66324
66631
|
import path85 from "node:path";
|
|
66325
66632
|
import { createHash as createHash9, randomUUID as randomUUID9 } from "node:crypto";
|
|
66326
66633
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
66327
66634
|
function readFolder2(folder2, baseline = false) {
|
|
66328
|
-
const root2 =
|
|
66635
|
+
const root2 = fs87.realpathSync(folder2);
|
|
66329
66636
|
let count3 = 0, total = 0;
|
|
66330
66637
|
const scan = (dir) => {
|
|
66331
|
-
for (const e of
|
|
66638
|
+
for (const e of fs87.readdirSync(dir, { withFileTypes: true })) {
|
|
66332
66639
|
if (e.name.startsWith(".")) continue;
|
|
66333
66640
|
const file2 = path85.join(dir, e.name);
|
|
66334
66641
|
if (e.isSymbolicLink()) throw Error(`${file2}: symbolic links are not allowed`);
|
|
66335
66642
|
if (e.isDirectory()) scan(file2);
|
|
66336
66643
|
else {
|
|
66337
|
-
const size =
|
|
66644
|
+
const size = fs87.statSync(file2).size;
|
|
66338
66645
|
total += size;
|
|
66339
66646
|
if (++count3 > FILE_LIMITS.count || size > FILE_LIMITS.file || total > FILE_LIMITS.total) throw Error(`${file2}: Studio file limit exceeded`);
|
|
66340
66647
|
}
|
|
@@ -66348,8 +66655,8 @@ function readFolder2(folder2, baseline = false) {
|
|
|
66348
66655
|
}
|
|
66349
66656
|
function unified(before, after2, file2, folder2) {
|
|
66350
66657
|
const a = path85.join(folder2, "a"), b = path85.join(folder2, "b");
|
|
66351
|
-
|
|
66352
|
-
|
|
66658
|
+
fs87.writeFileSync(a, before ?? "");
|
|
66659
|
+
fs87.writeFileSync(b, after2 ?? "");
|
|
66353
66660
|
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
66661
|
if (result.error || result.status !== 0 && result.status !== 1) throw Error(`${file2}: ${result.error?.message ?? result.stderr}`);
|
|
66355
66662
|
const lines = result.stdout.split("\n"), start = lines.findIndex((l) => l.startsWith("--- "));
|
|
@@ -66365,12 +66672,12 @@ async function cmdStudioPreview(id2, opts) {
|
|
|
66365
66672
|
const draft = readFolder2(path85.resolve(opts.folder)), base = opts.base === "empty" ? null : readFolder2(path85.resolve(opts.base), true);
|
|
66366
66673
|
const version2 = readVersion2(draft.files), baseVersion = base && readVersion2(base.files);
|
|
66367
66674
|
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
|
-
|
|
66675
|
+
fs87.mkdirSync(staging, { recursive: true });
|
|
66369
66676
|
const review = { version: 2, base: base && baseVersion ? { ...baseVersion, fingerprint: base.fingerprint } : null, fingerprint: draft.fingerprint, files: [] };
|
|
66370
66677
|
const save3 = (file2, bytes2) => {
|
|
66371
66678
|
const target = path85.join(staging, file2);
|
|
66372
|
-
|
|
66373
|
-
|
|
66679
|
+
fs87.mkdirSync(path85.dirname(target), { recursive: true });
|
|
66680
|
+
fs87.writeFileSync(target, bytes2);
|
|
66374
66681
|
return file2;
|
|
66375
66682
|
};
|
|
66376
66683
|
const paths = [.../* @__PURE__ */ new Set([...Object.keys(base?.files ?? {}), ...Object.keys(draft.files)])].filter((p) => p !== VERSION_FILE).sort();
|
|
@@ -66378,16 +66685,16 @@ async function cmdStudioPreview(id2, opts) {
|
|
|
66378
66685
|
const before = base?.files[file2] ?? null, after2 = draft.files[file2] ?? null;
|
|
66379
66686
|
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
66687
|
}
|
|
66381
|
-
for (const p of ["a", "b"])
|
|
66688
|
+
for (const p of ["a", "b"]) fs87.rmSync(path85.join(staging, p), { force: true });
|
|
66382
66689
|
if (!parseReview(review)) throw Error("generated review is invalid");
|
|
66383
66690
|
save3("review.json", JSON.stringify(review, null, 2) + "\n");
|
|
66384
|
-
|
|
66385
|
-
if (
|
|
66386
|
-
|
|
66691
|
+
fs87.mkdirSync(path85.dirname(destination), { recursive: true });
|
|
66692
|
+
if (fs87.existsSync(destination)) {
|
|
66693
|
+
fs87.renameSync(destination, backup);
|
|
66387
66694
|
moved = true;
|
|
66388
66695
|
}
|
|
66389
|
-
|
|
66390
|
-
|
|
66696
|
+
fs87.renameSync(staging, destination);
|
|
66697
|
+
fs87.rmSync(backup, { recursive: true, force: true });
|
|
66391
66698
|
const tag = `<Studio src=".assets/${id2}/studio-review/review.json" />`;
|
|
66392
66699
|
const prefix = `.assets/${id2}/studio-review/`;
|
|
66393
66700
|
const attachments = review.files.filter((f) => f.path !== "STUDIO.md" && f.diff);
|
|
@@ -66401,11 +66708,11 @@ ${items}
|
|
|
66401
66708
|
say([tag, files].filter(Boolean).join("\n\n"));
|
|
66402
66709
|
return { file: path85.join(destination, "review.json"), tag, files };
|
|
66403
66710
|
} catch (error62) {
|
|
66404
|
-
if (moved && !
|
|
66711
|
+
if (moved && !fs87.existsSync(destination)) fs87.renameSync(backup, destination);
|
|
66405
66712
|
if (error62 && typeof error62 === "object" && "kind" in error62) throw error62;
|
|
66406
66713
|
die(error62 instanceof Error ? error62.message : String(error62), "bad-args");
|
|
66407
66714
|
} finally {
|
|
66408
|
-
|
|
66715
|
+
fs87.rmSync(staging, { recursive: true, force: true });
|
|
66409
66716
|
}
|
|
66410
66717
|
}
|
|
66411
66718
|
var readVersion2;
|
|
@@ -66990,14 +67297,14 @@ Review examples
|
|
|
66990
67297
|
});
|
|
66991
67298
|
|
|
66992
67299
|
// src/kanban.ts
|
|
66993
|
-
import
|
|
67300
|
+
import fs90 from "node:fs";
|
|
66994
67301
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
66995
67302
|
|
|
66996
67303
|
// src/lib/cli/akb.ts
|
|
66997
67304
|
init_agent2();
|
|
66998
67305
|
|
|
66999
67306
|
// src/lib/cli/setup.ts
|
|
67000
|
-
import
|
|
67307
|
+
import fs89 from "node:fs";
|
|
67001
67308
|
import path87 from "node:path";
|
|
67002
67309
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
67003
67310
|
|
|
@@ -67006,7 +67313,7 @@ init_board_cli();
|
|
|
67006
67313
|
init_config_template();
|
|
67007
67314
|
init_io();
|
|
67008
67315
|
init_version();
|
|
67009
|
-
import
|
|
67316
|
+
import fs88 from "node:fs";
|
|
67010
67317
|
import path86 from "node:path";
|
|
67011
67318
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
67012
67319
|
var NAME = "wildcrane";
|
|
@@ -67028,7 +67335,7 @@ var Report = class {
|
|
|
67028
67335
|
for (const line of this.notes) say(` ! ${line}`);
|
|
67029
67336
|
}
|
|
67030
67337
|
};
|
|
67031
|
-
var read4 = (file2) =>
|
|
67338
|
+
var read4 = (file2) => fs88.existsSync(file2) ? fs88.readFileSync(file2, "utf8") : null;
|
|
67032
67339
|
async function boardMove(root2, args2, board2) {
|
|
67033
67340
|
const where = board2 ? ["--board", board2] : ["--dir", root2];
|
|
67034
67341
|
const code = await runBoard([...args2, ...where], { program: "akb raw", cwd: root2 });
|
|
@@ -67051,8 +67358,8 @@ async function cmdUpdate2(ctx) {
|
|
|
67051
67358
|
async function repairBoard(root2, report3, named2) {
|
|
67052
67359
|
const legacy = path86.join(root2, "docs", "kanban");
|
|
67053
67360
|
const kept2 = path86.join(root2, ".akb", "kanban");
|
|
67054
|
-
const board2 = named2 ?? (
|
|
67055
|
-
if (!
|
|
67361
|
+
const board2 = named2 ?? (fs88.existsSync(legacy) ? legacy : kept2);
|
|
67362
|
+
if (!fs88.existsSync(board2)) {
|
|
67056
67363
|
report3.notes.push("\u672A\u627E\u5230\u770B\u677F\uFF0C\u8BF7\u901A\u8FC7\u63D2\u4EF6\u8FDE\u63A5\u4E91\u7AEF\u9879\u76EE\u3002");
|
|
67057
67364
|
return false;
|
|
67058
67365
|
}
|
|
@@ -67128,7 +67435,7 @@ function declareSetup(program2, cli) {
|
|
|
67128
67435
|
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
67436
|
const where = (cmd) => {
|
|
67130
67437
|
const dir = path87.resolve(String(cmd.optsWithGlobals().dir ?? cli.cwd));
|
|
67131
|
-
if (!
|
|
67438
|
+
if (!fs89.existsSync(dir)) throw new BoardError(`no such folder: ${dir}`, { kind: "no-such-folder", dir });
|
|
67132
67439
|
return dir;
|
|
67133
67440
|
};
|
|
67134
67441
|
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 +67486,7 @@ function invokedDirectly() {
|
|
|
67179
67486
|
const entry = process.argv[1];
|
|
67180
67487
|
if (!entry) return false;
|
|
67181
67488
|
try {
|
|
67182
|
-
return
|
|
67489
|
+
return fs90.realpathSync(entry) === fs90.realpathSync(SELF2);
|
|
67183
67490
|
} catch {
|
|
67184
67491
|
return false;
|
|
67185
67492
|
}
|