agent-lyceum 0.47.0 → 0.48.0
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/cli.js +8 -0
- package/dist/decision-log.d.ts +15 -0
- package/dist/decision-log.js +78 -0
- package/dist/policy.d.ts +2 -0
- package/dist/policy.js +4 -0
- package/dist/prompt.js +2 -2
- package/dist/records.d.ts +2 -0
- package/dist/records.js +13 -1
- package/dist/web-console.d.ts +21 -1
- package/dist/web-console.js +49 -1
- package/package.json +1 -1
- package/web/dist/public/assets/index-B8vglxAK.js +86 -0
- package/web/dist/public/assets/index-C9JUgWik.css +2 -0
- package/web/dist/public/index.html +2 -2
- package/web/dist/server/api.js +11 -0
- package/web/dist/public/assets/index-B6zfKBBo.css +0 -2
- package/web/dist/public/assets/index-DR70f29d.js +0 -86
package/dist/cli.js
CHANGED
|
@@ -34,6 +34,7 @@ import { onlyAgent, soloProject } from "./solo.js";
|
|
|
34
34
|
import { DEMO_PROJECT, DEMO_TASK, defaultDemoDir, detectRuntime, prepareDemo } from "./demo.js";
|
|
35
35
|
import { claudeQuota, codexQuota, cursorQuota } from "./quota.js";
|
|
36
36
|
import { summarizeProgress } from "./summarize.js";
|
|
37
|
+
import { saveRunDecisions } from "./decision-log.js";
|
|
37
38
|
import { createConsoleDeps } from "./web-console.js";
|
|
38
39
|
const program = new Command();
|
|
39
40
|
program
|
|
@@ -537,6 +538,7 @@ program
|
|
|
537
538
|
const plan = planRunCleanup(pr, full, { keepWorktrees: opts.keepWorktrees });
|
|
538
539
|
console.log("Dry run: nothing is deleted.");
|
|
539
540
|
showPlan(plan);
|
|
541
|
+
console.log(" would keep the run's ## Decisions in the project's decision log (shared/common/decision-log/)");
|
|
540
542
|
if (plan.refusals.length)
|
|
541
543
|
refuse(plan);
|
|
542
544
|
return;
|
|
@@ -547,6 +549,12 @@ program
|
|
|
547
549
|
if (plan.refusals.length)
|
|
548
550
|
refuse(plan);
|
|
549
551
|
showPlan(plan);
|
|
552
|
+
// The run folder (and its report) is about to go: keep the decisions first, and stop if they cannot be kept.
|
|
553
|
+
const kept = saveRunDecisions(pr, full);
|
|
554
|
+
if (kept.status === "saved")
|
|
555
|
+
console.log(` kept decisions -> ${kept.file}`);
|
|
556
|
+
else if (kept.status === "none")
|
|
557
|
+
console.log(` no decisions to keep (${kept.reason})`);
|
|
550
558
|
const report = executeRunCleanup(plan);
|
|
551
559
|
if (report.failed.length) {
|
|
552
560
|
for (const f of report.failed)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResolvedProject } from "./config.js";
|
|
2
|
+
export type DecisionLogResult = {
|
|
3
|
+
status: "saved" | "exists" | "none";
|
|
4
|
+
id?: string;
|
|
5
|
+
file?: string;
|
|
6
|
+
reason?: string;
|
|
7
|
+
};
|
|
8
|
+
/** Where the entry for a run goes: one stable file per run, so saving twice is harmless. */
|
|
9
|
+
export declare function decisionLogId(runId: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Keep what a run decided before `clear` deletes the run folder: its `## Decisions` (and `## Not done` as consequences) with the
|
|
12
|
+
* task as context. Never overwrites an existing entry. Returns `none` when the run reported no decision.
|
|
13
|
+
* Throws when the entry cannot be written, so the caller can stop before deleting anything.
|
|
14
|
+
*/
|
|
15
|
+
export declare function saveRunDecisions(project: ResolvedProject, runId: string): DecisionLogResult;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { decisionLogDir } from "./policy.js";
|
|
4
|
+
/** Body of the `## <name>` section of a done report, up to the next `## ` heading. */
|
|
5
|
+
function section(text, name) {
|
|
6
|
+
const m = new RegExp(`^##[ \\t]+${name}[ \\t]*\\r?\\n([\\s\\S]*?)(?=^##[ \\t]|(?![\\s\\S]))`, "m").exec(text);
|
|
7
|
+
return (m?.[1] ?? "").trim();
|
|
8
|
+
}
|
|
9
|
+
/** "None", "無" and the like are not a decision. */
|
|
10
|
+
function isEmpty(body) {
|
|
11
|
+
return body === "" || /^(none|n\/a|無|没有|沒有)[.。]?$/i.test(body.replace(/^[-*]\s*/, "").trim());
|
|
12
|
+
}
|
|
13
|
+
const oneLine = (s) => s.replace(/\s+/g, " ").trim();
|
|
14
|
+
/** Where the entry for a run goes: one stable file per run, so saving twice is harmless. */
|
|
15
|
+
export function decisionLogId(runId) {
|
|
16
|
+
return `run-${runId.toLowerCase().replace(/[^a-z0-9-]/g, "").slice(0, 28)}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Keep what a run decided before `clear` deletes the run folder: its `## Decisions` (and `## Not done` as consequences) with the
|
|
20
|
+
* task as context. Never overwrites an existing entry. Returns `none` when the run reported no decision.
|
|
21
|
+
* Throws when the entry cannot be written, so the caller can stop before deleting anything.
|
|
22
|
+
*/
|
|
23
|
+
export function saveRunDecisions(project, runId) {
|
|
24
|
+
const runDir = path.join(project.paths.runs, runId);
|
|
25
|
+
let result;
|
|
26
|
+
try {
|
|
27
|
+
result = fs.readFileSync(path.join(runDir, "result.md"), "utf8");
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { status: "none", reason: "no result.md" };
|
|
31
|
+
}
|
|
32
|
+
const decisions = section(result, "Decisions");
|
|
33
|
+
if (isEmpty(decisions))
|
|
34
|
+
return { status: "none", reason: "the report lists no decisions" };
|
|
35
|
+
let summary = "";
|
|
36
|
+
let started = "";
|
|
37
|
+
try {
|
|
38
|
+
const state = JSON.parse(fs.readFileSync(path.join(runDir, "state.json"), "utf8"));
|
|
39
|
+
summary = state.task_summary ?? "";
|
|
40
|
+
started = state.started_at ?? "";
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// The report is enough to keep.
|
|
44
|
+
}
|
|
45
|
+
const heading = /^#\s+(.+)$/m.exec(result)?.[1]?.trim();
|
|
46
|
+
const title = oneLine(heading || summary || runId).slice(0, 200);
|
|
47
|
+
const date = /^\d{4}-\d{2}-\d{2}/.exec(started)?.[0] ?? new Date().toISOString().slice(0, 10);
|
|
48
|
+
const outcome = /^\*\*Outcome:\*\*\s*(\S+)/m.exec(result)?.[1];
|
|
49
|
+
const notDone = section(result, "Not done");
|
|
50
|
+
const id = decisionLogId(runId);
|
|
51
|
+
const file = path.join(decisionLogDir(project), `${id}.md`);
|
|
52
|
+
const text = [
|
|
53
|
+
"---",
|
|
54
|
+
"status: active",
|
|
55
|
+
`date: ${date}`,
|
|
56
|
+
`title: ${JSON.stringify(title)}`,
|
|
57
|
+
`run: ${JSON.stringify(runId)}`,
|
|
58
|
+
...(outcome ? [`outcome: ${outcome}`] : []),
|
|
59
|
+
"---",
|
|
60
|
+
"## Context",
|
|
61
|
+
summary.trim() || title,
|
|
62
|
+
"",
|
|
63
|
+
"## Decision",
|
|
64
|
+
decisions,
|
|
65
|
+
...(isEmpty(notDone) ? [] : ["", "## Consequences", notDone]),
|
|
66
|
+
"",
|
|
67
|
+
].join("\n");
|
|
68
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
69
|
+
try {
|
|
70
|
+
fs.writeFileSync(file, text, { flag: "wx" });
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
if (e.code === "EEXIST")
|
|
74
|
+
return { status: "exists", id, file };
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
return { status: "saved", id, file };
|
|
78
|
+
}
|
package/dist/policy.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface WritePolicy {
|
|
|
25
25
|
export declare function commonFile(project: ResolvedProject): string;
|
|
26
26
|
/** Durable decisions and lessons of the project, one file per entry. Only the lead may write them. `.archive/` is tidy's output, never shown in prompts. */
|
|
27
27
|
export declare function recordsDir(project: ResolvedProject): string;
|
|
28
|
+
/** Decisions kept from cleared runs (see decision-log.ts). Not a record kind: never shown in prompts and not counted against the records budget. */
|
|
29
|
+
export declare function decisionLogDir(project: ResolvedProject): string;
|
|
28
30
|
export declare function recordsKindDir(project: ResolvedProject, kind: "decisions" | "lessons"): string;
|
|
29
31
|
/**
|
|
30
32
|
* Proposals of lessons and decisions written by agents that run alone (spec 30). A sibling of `shared/`, not under `records/`:
|
package/dist/policy.js
CHANGED
|
@@ -9,6 +9,10 @@ export function commonFile(project) {
|
|
|
9
9
|
export function recordsDir(project) {
|
|
10
10
|
return path.join(project.paths.shared, "common", "records");
|
|
11
11
|
}
|
|
12
|
+
/** Decisions kept from cleared runs (see decision-log.ts). Not a record kind: never shown in prompts and not counted against the records budget. */
|
|
13
|
+
export function decisionLogDir(project) {
|
|
14
|
+
return path.join(project.paths.shared, "common", "decision-log");
|
|
15
|
+
}
|
|
12
16
|
export function recordsKindDir(project, kind) {
|
|
13
17
|
return path.join(recordsDir(project), kind);
|
|
14
18
|
}
|
package/dist/prompt.js
CHANGED
|
@@ -135,7 +135,7 @@ export function buildSoloSystemPrompt(project, agent) {
|
|
|
135
135
|
? "Do the task you are given. Your final reply text is printed to the user as your answer, so end with the answer or a short report of what you did; nothing else is delivered."
|
|
136
136
|
: "");
|
|
137
137
|
if (!isCall) {
|
|
138
|
-
lines.push("## Finishing", `When the job is finished, create a Markdown file (any name ending in \`.md\`) directly inside \`${outboxDir(project, agent.name)}\` with this exact shape:`, "", "```", "---", "type: done", "subject: <short subject>", "outcome: completed|partial|blocked|failed", "---", "", "## Result", "## Files", "## Verification", "## Not done", "```", "", "That ends the run. `## Result` is the actual deliverable or conclusion (not just \"done\"), `## Files` the paths you created or changed, `## Verification` what you ran or checked and what it showed, `## Decisions` the choices you made that the task did not specify and the assumptions you relied on (or `None`), `## Not done` anything skipped or unverified (or `None`). Only `completed` means success and it needs all five headings; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A summary in your reply text is never delivered: without a `done` mail the run ends as idle with no report. " + OPEN_PR_RULE);
|
|
138
|
+
lines.push("## Finishing", `When the job is finished, create a Markdown file (any name ending in \`.md\`) directly inside \`${outboxDir(project, agent.name)}\` with this exact shape:`, "", "```", "---", "type: done", "subject: <short subject>", "outcome: completed|partial|blocked|failed", "---", "", "## Result", "## Files", "## Verification", "## Not done", "```", "", "That ends the run. `## Result` is the actual deliverable or conclusion (not just \"done\"), `## Files` the paths you created or changed, `## Verification` what you ran or checked and what it showed, `## Decisions` the choices you made that the task did not specify and the assumptions you relied on (or `None`), one entry per choice: what you chose, then what you rejected and why; leave follow-ups to `## Not done`, `## Not done` anything skipped or unverified (or `None`). Only `completed` means success and it needs all five headings; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A summary in your reply text is never delivered: without a `done` mail the run ends as idle with no report. " + OPEN_PR_RULE);
|
|
139
139
|
}
|
|
140
140
|
const shared = sharedDir(project);
|
|
141
141
|
if (!isCall && shared)
|
|
@@ -276,7 +276,7 @@ export function buildSystemPrompt(project, agent) {
|
|
|
276
276
|
: `Report results to the lead by mail; the lead decides what happens next.`, isLead
|
|
277
277
|
? "Each wake-up handles one message, except that several `reply`/`failure` messages waiting together are handed to you in one wake-up: weigh them together, then decide the next step once."
|
|
278
278
|
: "Each wake-up handles one message, except that consecutive `reply`/`failure` messages on the same thread may be handed to you together: handle them together. Do the work it asks, then send the replies that are needed, then stop.", "Mail that repeats an earlier mail of yours to the same agent (same type, same text) is not sent again; you are told, and should wait for the answer or ask for something different instead of resending.", "", "## Message format", "The body of every `task` and `reply` must contain these `##` headings, exactly as written (write `None` under a heading if there is nothing to say).", "A `task` or `reply` missing a heading is sent back to you (at most twice per sender + type + subject); after that it is delivered with a warning flagged to the recipient.", "", `- \`task\`: ${REQUIRED_SECTIONS.task.map((h) => `\`## ${h}\``).join(", ")} (Upstream = id of the mail this task derives from, or \`None\`).`, `- \`reply\`: ${REQUIRED_SECTIONS.reply.map((h) => `\`## ${h}\``).join(", ")}.`, isLead
|
|
279
|
-
? "- `done`: your final report to the user (shown when the run ends, saved as `result.md`). Its frontmatter must contain `outcome: completed|partial|blocked|failed`, and the body the headings `## Result` (the actual deliverable or conclusion, not just \"done\"), `## Files` (paths created or changed), `## Verification` (what you ran or checked, and what it showed), `## Decisions` (choices you made that the task did not specify and assumptions you relied on, or `None`) and `## Not done` (anything skipped or unverified, or `None`). Only `completed` means success, and it needs all five headings and every checklist step ticked; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked, say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A `done` that breaks this is sent back to you and does not end the run. " + OPEN_PR_RULE
|
|
279
|
+
? "- `done`: your final report to the user (shown when the run ends, saved as `result.md`). Its frontmatter must contain `outcome: completed|partial|blocked|failed`, and the body the headings `## Result` (the actual deliverable or conclusion, not just \"done\"), `## Files` (paths created or changed), `## Verification` (what you ran or checked, and what it showed), `## Decisions` (choices you made that the task did not specify and assumptions you relied on, or `None`; one entry per choice: what you chose, then what you rejected and why; leave follow-ups to `## Not done`) and `## Not done` (anything skipped or unverified, or `None`). Only `completed` means success, and it needs all five headings and every checklist step ticked; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked, say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A `done` that breaks this is sent back to you and does not end the run. " + OPEN_PR_RULE
|
|
280
280
|
: "- `done` has no required headings.", ...(agent.canAskUser
|
|
281
281
|
? [
|
|
282
282
|
"",
|
package/dist/records.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface ProjectRecord {
|
|
|
19
19
|
}
|
|
20
20
|
/** Every `*.md` entry of one kind, sorted by id. Entries that cannot be parsed are listed with `invalid` set; a missing folder is an empty list. */
|
|
21
21
|
export declare function listRecords(project: ResolvedProject, kind: RecordKind): ProjectRecord[];
|
|
22
|
+
/** Decisions kept from cleared runs, same file format as a record. A missing or symlinked folder is an empty list. */
|
|
23
|
+
export declare function listDecisionLog(project: ResolvedProject): ProjectRecord[];
|
|
22
24
|
/** Entries shown in prompts: `status: active` and not named in another entry's `supersedes`. */
|
|
23
25
|
export declare function effectiveActive(records: ProjectRecord[]): ProjectRecord[];
|
|
24
26
|
/** The kinds whose effective-active entries take more than the budget: what `done` and `proposals review` refuse to leave behind. */
|
package/dist/records.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parse as parseYaml } from "yaml";
|
|
4
4
|
import { readRegularFileNoFollow } from "./fs-util.js";
|
|
5
|
-
import { recordsDir, recordsKindDir } from "./policy.js";
|
|
5
|
+
import { decisionLogDir, recordsDir, recordsKindDir } from "./policy.js";
|
|
6
6
|
export const RECORD_KINDS = ["decisions", "lessons"];
|
|
7
7
|
/** Cap of one kind's effective-active entries in a prompt (and, for `done`, the most they may add up to). */
|
|
8
8
|
export const RECORDS_BUDGET = 12 * 1024;
|
|
@@ -83,6 +83,18 @@ export function listRecords(project, kind) {
|
|
|
83
83
|
.sort()
|
|
84
84
|
.map((n) => parseEntry(kind, path.join(dir, n)));
|
|
85
85
|
}
|
|
86
|
+
/** Decisions kept from cleared runs, same file format as a record. A missing or symlinked folder is an empty list. */
|
|
87
|
+
export function listDecisionLog(project) {
|
|
88
|
+
const dir = decisionLogDir(project);
|
|
89
|
+
try {
|
|
90
|
+
if (!fs.lstatSync(dir).isDirectory())
|
|
91
|
+
return [];
|
|
92
|
+
return fs.readdirSync(dir).filter((n) => n.endsWith(".md")).sort().map((n) => parseEntry("decisions", path.join(dir, n)));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
86
98
|
/** Entries shown in prompts: `status: active` and not named in another entry's `supersedes`. */
|
|
87
99
|
export function effectiveActive(records) {
|
|
88
100
|
const replaced = new Set();
|
package/dist/web-console.d.ts
CHANGED
|
@@ -6,7 +6,24 @@ export type ReportItem = {
|
|
|
6
6
|
outcome?: string;
|
|
7
7
|
created?: string;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
export type DecisionItem = {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
status: "active" | "superseded";
|
|
13
|
+
date: string;
|
|
14
|
+
run?: string;
|
|
15
|
+
supersedes: string[];
|
|
16
|
+
supersededBy: string[];
|
|
17
|
+
invalid?: string;
|
|
18
|
+
};
|
|
19
|
+
export type DecisionGroup = {
|
|
20
|
+
project: string;
|
|
21
|
+
decisions: DecisionItem[];
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
export type DecisionDoc = DecisionItem & {
|
|
25
|
+
markdown: string;
|
|
26
|
+
};
|
|
10
27
|
export declare function createConsoleDeps(home: string, cliFile: string): {
|
|
11
28
|
home: string;
|
|
12
29
|
cli: {
|
|
@@ -35,6 +52,9 @@ export declare function createConsoleDeps(home: string, cliFile: string): {
|
|
|
35
52
|
title: string;
|
|
36
53
|
markdown: string;
|
|
37
54
|
} | undefined;
|
|
55
|
+
/** Decisions of every registered project, read-only. They live outside the run folders, so they survive `clear`. */
|
|
56
|
+
listDecisions(): DecisionGroup[];
|
|
57
|
+
readDecision(project: string, id: string): DecisionDoc | undefined;
|
|
38
58
|
saveAnswers(project: string, runId: string, answers: Record<string, string>, assumeDefaults: boolean): {
|
|
39
59
|
complete: boolean;
|
|
40
60
|
problems: string[];
|
package/dist/web-console.js
CHANGED
|
@@ -2,9 +2,11 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { prepareAnswers } from "./ask-answer.js";
|
|
4
4
|
import { readAskReply, writeAskReply } from "./ask-reply.js";
|
|
5
|
-
import { listProjects } from "./config.js";
|
|
5
|
+
import { listProjects, resolveProject } from "./config.js";
|
|
6
6
|
import { parseRaw } from "./mailbox.js";
|
|
7
7
|
import { NAME_RE, projectPaths } from "./paths.js";
|
|
8
|
+
import { listDecisionLog, listRecords } from "./records.js";
|
|
9
|
+
const DECISION_ID_RE = /^[a-z0-9-]{1,120}$/;
|
|
8
10
|
const REPORT_ID_RE = /^(result|done-\d{1,4}|mail-[0-9a-f]{8})$/;
|
|
9
11
|
const AGENT_MAIL_TYPES = new Set(["reply", "done", "failure"]);
|
|
10
12
|
function headingOf(text) {
|
|
@@ -42,6 +44,25 @@ function agentMails(runDir) {
|
|
|
42
44
|
return out;
|
|
43
45
|
}
|
|
44
46
|
/** What the web page's command console needs from this side of the package (`web/` cannot import `src/`). Same shape as `ConsoleDeps` in `web/src/server/api.ts`. */
|
|
47
|
+
/** An entry is "active" only while its own status says so and no other entry supersedes it. */
|
|
48
|
+
function allDecisions(project) {
|
|
49
|
+
const records = listRecords(project, "decisions");
|
|
50
|
+
const seen = new Set(records.map((r) => r.id));
|
|
51
|
+
return [...records, ...listDecisionLog(project).filter((r) => !seen.has(r.id))];
|
|
52
|
+
}
|
|
53
|
+
function decisionItems(records) {
|
|
54
|
+
const by = new Map();
|
|
55
|
+
for (const r of records)
|
|
56
|
+
for (const id of r.supersedes)
|
|
57
|
+
if (id !== r.id)
|
|
58
|
+
by.set(id, [...(by.get(id) ?? []), r.id]);
|
|
59
|
+
return records
|
|
60
|
+
.map((r) => {
|
|
61
|
+
const supersededBy = by.get(r.id) ?? [];
|
|
62
|
+
return { id: r.id, title: r.title, status: r.status === "active" && supersededBy.length === 0 ? "active" : "superseded", date: r.date, ...(r.run ? { run: r.run } : {}), supersedes: r.supersedes, supersededBy, ...(r.invalid ? { invalid: r.invalid } : {}) };
|
|
63
|
+
})
|
|
64
|
+
.sort((a, b) => b.date.localeCompare(a.date) || b.id.localeCompare(a.id));
|
|
65
|
+
}
|
|
45
66
|
export function createConsoleDeps(home, cliFile) {
|
|
46
67
|
const projectDir = (name) => listProjects(home).find((p) => p.name === name)?.dir;
|
|
47
68
|
const runDirOf = (project, runId) => {
|
|
@@ -107,6 +128,33 @@ export function createConsoleDeps(home, cliFile) {
|
|
|
107
128
|
const markdown = fs.readFileSync(file, "utf8");
|
|
108
129
|
return { id, title: headingOf(markdown) ?? id, markdown };
|
|
109
130
|
},
|
|
131
|
+
/** Decisions of every registered project, read-only. They live outside the run folders, so they survive `clear`. */
|
|
132
|
+
listDecisions() {
|
|
133
|
+
return listProjects(home)
|
|
134
|
+
.map((p) => p.name)
|
|
135
|
+
.sort((a, b) => a.localeCompare(b))
|
|
136
|
+
.map((project) => {
|
|
137
|
+
try {
|
|
138
|
+
return { project, decisions: decisionItems(allDecisions(resolveProject(home, project))) };
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return { project, decisions: [], error: "讀不到這個專案的設定。" };
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
readDecision(project, id) {
|
|
146
|
+
if (!NAME_RE.test(project) || !DECISION_ID_RE.test(id) || !projectDir(project))
|
|
147
|
+
return undefined;
|
|
148
|
+
try {
|
|
149
|
+
const records = allDecisions(resolveProject(home, project));
|
|
150
|
+
const item = decisionItems(records).find((d) => d.id === id);
|
|
151
|
+
const record = records.find((r) => r.id === id);
|
|
152
|
+
return item && record ? { ...item, markdown: record.body } : undefined;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
110
158
|
saveAnswers(project, runId, answers, assumeDefaults) {
|
|
111
159
|
const dir = runDirOf(project, runId);
|
|
112
160
|
const reply = dir ? readAskReply(dir) : undefined;
|