agent-lyceum 0.45.0 → 0.46.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/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/dist/call.d.ts +8 -0
- package/dist/call.js +29 -7
- package/dist/cli.js +70 -5
- package/dist/config.d.ts +11 -0
- package/dist/doctor.js +12 -1
- package/dist/guard.d.ts +45 -2
- package/dist/guard.js +117 -10
- package/dist/mailbox.js +13 -3
- package/dist/memory-tidy.d.ts +51 -0
- package/dist/memory-tidy.js +184 -75
- package/dist/policy.d.ts +8 -0
- package/dist/policy.js +14 -0
- package/dist/project-lock.d.ts +4 -0
- package/dist/project-lock.js +1 -0
- package/dist/prompt.d.ts +31 -1
- package/dist/prompt.js +118 -10
- package/dist/proposals-review.d.ts +26 -0
- package/dist/proposals-review.js +94 -0
- package/dist/proposals.d.ts +88 -0
- package/dist/proposals.js +306 -0
- package/dist/records.d.ts +5 -0
- package/dist/records.js +4 -0
- package/dist/run-session.js +9 -4
- package/dist/status.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
import { readRegularFileNoFollow } from "./fs-util.js";
|
|
5
|
+
import { proposalsKindDir, recordsDir, recordsKindDir } from "./policy.js";
|
|
6
|
+
import { RECORD_KINDS } from "./records.js";
|
|
7
|
+
import { git, isGitRepo } from "./worktree.js";
|
|
8
|
+
export const PROPOSAL_KINDS = RECORD_KINDS;
|
|
9
|
+
/** One proposal file is at most this big; a larger one is "not in the right format" (D-11). */
|
|
10
|
+
export const PROPOSAL_MAX_BYTES = 8 * 1024;
|
|
11
|
+
/** The lead's prompt lists at most this many pending proposals (D-11). */
|
|
12
|
+
export const PENDING_SHOWN = 10;
|
|
13
|
+
const ID_RE = /^[a-z0-9-]+$/;
|
|
14
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
15
|
+
const SHA_RE = /^[0-9a-f]{7,40}$/;
|
|
16
|
+
/** The part of a run or call id that is unique: its first 8 lowercase letters or digits after the timestamp (D-10). */
|
|
17
|
+
export function shortIdOf(runId) {
|
|
18
|
+
const rest = runId.includes("-") ? runId.slice(runId.indexOf("-") + 1) : runId;
|
|
19
|
+
return rest.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 8);
|
|
20
|
+
}
|
|
21
|
+
/** The `status` in a proposal's frontmatter, or undefined when the text has none of the three values (or is not a proposal at all). */
|
|
22
|
+
export function proposalStatusOf(buf) {
|
|
23
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(buf.toString("utf8"));
|
|
24
|
+
if (!m)
|
|
25
|
+
return undefined;
|
|
26
|
+
try {
|
|
27
|
+
const fm = parseYaml(m[1]);
|
|
28
|
+
const st = fm && typeof fm === "object" ? fm.status : undefined;
|
|
29
|
+
return st === "proposed" || st === "accepted" || st === "rejected" ? st : undefined;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The id's own prefix: what comes before the first `-`. */
|
|
36
|
+
export const prefixOf = (id) => id.split("-")[0] ?? "";
|
|
37
|
+
const isoDate = (v) => {
|
|
38
|
+
// YAML parses an unquoted 2026-01-02 as a Date.
|
|
39
|
+
const d = v instanceof Date ? v.toISOString().slice(0, 10) : v;
|
|
40
|
+
return typeof d === "string" && DATE_RE.test(d) ? d : undefined;
|
|
41
|
+
};
|
|
42
|
+
const oneLine = (v) => (typeof v === "string" && v.trim() && !/[\r\n]/.test(v.trim()) ? v.trim() : undefined);
|
|
43
|
+
function parseEvidenceItem(item) {
|
|
44
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
45
|
+
return "an evidence entry must be a mapping (path, commit, mail or output)";
|
|
46
|
+
const keys = Object.keys(item);
|
|
47
|
+
if (keys.length !== 1)
|
|
48
|
+
return "an evidence entry must have exactly one of path, commit, mail, output";
|
|
49
|
+
const key = keys[0];
|
|
50
|
+
const val = item[key];
|
|
51
|
+
if (typeof val !== "string" || !val.trim())
|
|
52
|
+
return `evidence ${key} must be a non-empty string`;
|
|
53
|
+
const v = val.trim();
|
|
54
|
+
if (key === "commit")
|
|
55
|
+
return SHA_RE.test(v) ? { type: "commit", commit: v } : "evidence commit must be a hex sha (7 to 40 characters)";
|
|
56
|
+
if (key === "mail")
|
|
57
|
+
return { type: "mail", value: v };
|
|
58
|
+
if (key === "output")
|
|
59
|
+
return { type: "output", value: v };
|
|
60
|
+
if (key === "path") {
|
|
61
|
+
const m = /^(.+?)(?::(\d+))?(?:\s+@\s+([0-9a-f]{7,40}))?$/.exec(v);
|
|
62
|
+
if (!m)
|
|
63
|
+
return "evidence path must look like `file[:line] [@ <commit sha>]`";
|
|
64
|
+
const file = m[1].trim();
|
|
65
|
+
if (path.isAbsolute(file) || file.split(/[\\/]/).includes(".."))
|
|
66
|
+
return "evidence path must be relative to the repository and stay inside it";
|
|
67
|
+
return { type: "path", file, ...(m[2] ? { line: Number(m[2]) } : {}), ...(m[3] ? { commit: m[3] } : {}) };
|
|
68
|
+
}
|
|
69
|
+
return `unknown evidence kind "${key}"`;
|
|
70
|
+
}
|
|
71
|
+
export function parseProposal(kind, file) {
|
|
72
|
+
const id = path.basename(file, ".md");
|
|
73
|
+
const base = { kind, id, file, date: "", title: path.basename(file), proposedBy: "", run: "", evidence: [], supersedes: [], body: "", bytes: 0, problems: [] };
|
|
74
|
+
// Never open a symlink or a FIFO/device (spec 30, acceptance 11).
|
|
75
|
+
const buf = readRegularFileNoFollow(file);
|
|
76
|
+
if (!buf)
|
|
77
|
+
return { ...base, problems: ["not a readable regular file (symlinks and special files are never read)"] };
|
|
78
|
+
const bytes = buf.length;
|
|
79
|
+
const text = buf.toString("utf8");
|
|
80
|
+
const problems = [];
|
|
81
|
+
if (bytes > PROPOSAL_MAX_BYTES)
|
|
82
|
+
problems.push(`larger than ${PROPOSAL_MAX_BYTES} bytes`);
|
|
83
|
+
if (!ID_RE.test(id))
|
|
84
|
+
problems.push("file name must be lowercase letters, digits and -");
|
|
85
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n([\s\S]*))?$/.exec(text);
|
|
86
|
+
if (!m)
|
|
87
|
+
return { ...base, bytes, body: text.trim(), problems: [...problems, "missing frontmatter"] };
|
|
88
|
+
const body = (m[2] ?? "").trim();
|
|
89
|
+
let fm;
|
|
90
|
+
try {
|
|
91
|
+
fm = parseYaml(m[1]);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
return { ...base, bytes, body, problems: [...problems, `frontmatter is not valid YAML: ${e.message.split("\n")[0]}`] };
|
|
95
|
+
}
|
|
96
|
+
if (!fm || typeof fm !== "object" || Array.isArray(fm))
|
|
97
|
+
return { ...base, bytes, body, problems: [...problems, "frontmatter is not a mapping"] };
|
|
98
|
+
const f = fm;
|
|
99
|
+
const status = f.status === "proposed" || f.status === "accepted" || f.status === "rejected" ? f.status : undefined;
|
|
100
|
+
if (!status)
|
|
101
|
+
problems.push("status must be proposed, accepted or rejected");
|
|
102
|
+
const date = isoDate(f.date);
|
|
103
|
+
if (!date)
|
|
104
|
+
problems.push("date must be YYYY-MM-DD");
|
|
105
|
+
const title = oneLine(f.title);
|
|
106
|
+
if (!title)
|
|
107
|
+
problems.push("title must be one non-empty line");
|
|
108
|
+
const proposedBy = oneLine(f.proposed_by);
|
|
109
|
+
if (!proposedBy)
|
|
110
|
+
problems.push("proposed_by is required");
|
|
111
|
+
const run = oneLine(f.run);
|
|
112
|
+
if (!run)
|
|
113
|
+
problems.push("run is required");
|
|
114
|
+
const evidence = [];
|
|
115
|
+
if (!Array.isArray(f.evidence) || f.evidence.length === 0)
|
|
116
|
+
problems.push("evidence is required: at least one entry");
|
|
117
|
+
else
|
|
118
|
+
for (const item of f.evidence) {
|
|
119
|
+
const e = parseEvidenceItem(item);
|
|
120
|
+
if (typeof e === "string")
|
|
121
|
+
problems.push(e);
|
|
122
|
+
else
|
|
123
|
+
evidence.push(e);
|
|
124
|
+
}
|
|
125
|
+
let supersedes = [];
|
|
126
|
+
if (f.supersedes !== undefined) {
|
|
127
|
+
if (Array.isArray(f.supersedes) && f.supersedes.every((x) => typeof x === "string"))
|
|
128
|
+
supersedes = f.supersedes;
|
|
129
|
+
else
|
|
130
|
+
problems.push("supersedes must be a list of ids");
|
|
131
|
+
}
|
|
132
|
+
const repo = f.repo === undefined ? undefined : oneLine(f.repo);
|
|
133
|
+
if (f.repo !== undefined && (!repo || !path.isAbsolute(repo)))
|
|
134
|
+
problems.push("repo must be an absolute path");
|
|
135
|
+
const decided = f.decided === undefined ? undefined : isoDate(f.decided);
|
|
136
|
+
if (f.decided !== undefined && !decided)
|
|
137
|
+
problems.push("decided must be YYYY-MM-DD");
|
|
138
|
+
return {
|
|
139
|
+
kind,
|
|
140
|
+
id,
|
|
141
|
+
file,
|
|
142
|
+
...(status ? { status } : {}),
|
|
143
|
+
date: date ?? "",
|
|
144
|
+
title: title ?? path.basename(file),
|
|
145
|
+
proposedBy: proposedBy ?? "",
|
|
146
|
+
run: run ?? "",
|
|
147
|
+
evidence,
|
|
148
|
+
...(repo && path.isAbsolute(repo) ? { repo } : {}),
|
|
149
|
+
...(oneLine(f.scope) ? { scope: oneLine(f.scope) } : {}),
|
|
150
|
+
supersedes,
|
|
151
|
+
...(oneLine(f.reject_reason) ? { rejectReason: oneLine(f.reject_reason) } : {}),
|
|
152
|
+
...(oneLine(f.accepted_as) ? { acceptedAs: oneLine(f.accepted_as) } : {}),
|
|
153
|
+
...(decided ? { decided } : {}),
|
|
154
|
+
body,
|
|
155
|
+
bytes,
|
|
156
|
+
problems,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Every `*.md` proposal of one kind, sorted by id. A missing or symlinked folder lists nothing; `.archive/` is never read. */
|
|
160
|
+
export function listKindProposals(project, kind) {
|
|
161
|
+
const dir = proposalsKindDir(project, kind);
|
|
162
|
+
let names;
|
|
163
|
+
try {
|
|
164
|
+
// A symlinked proposals/ or kind folder could point outside the project: list nothing, never descend.
|
|
165
|
+
for (const d of [path.dirname(dir), dir])
|
|
166
|
+
if (!fs.lstatSync(d).isDirectory())
|
|
167
|
+
return [];
|
|
168
|
+
names = fs.readdirSync(dir);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
return names
|
|
174
|
+
.filter((n) => n.endsWith(".md"))
|
|
175
|
+
.sort()
|
|
176
|
+
.map((n) => parseProposal(kind, path.join(dir, n)));
|
|
177
|
+
}
|
|
178
|
+
export const listProposals = (project) => PROPOSAL_KINDS.flatMap((k) => listKindProposals(project, k));
|
|
179
|
+
/** Proposals waiting for the lead: `status: proposed`, or with no readable status (they are shown as "format problem", never lost). */
|
|
180
|
+
export const pendingProposals = (project) => listProposals(project).filter((p) => p.status === undefined || p.status === "proposed");
|
|
181
|
+
export function oldestPending(pending) {
|
|
182
|
+
const dates = pending.map((p) => p.date).filter(Boolean).sort();
|
|
183
|
+
return dates[0];
|
|
184
|
+
}
|
|
185
|
+
/** What `proposals list` shows: the counts, the pending ones with their evidence, and every decision that is not complete. Reads only. */
|
|
186
|
+
export function describeProposals(project) {
|
|
187
|
+
const all = listProposals(project);
|
|
188
|
+
if (all.length === 0)
|
|
189
|
+
return ["No proposals."];
|
|
190
|
+
const pending = pendingProposals(project);
|
|
191
|
+
const count = (s) => all.filter((p) => p.status === s).length;
|
|
192
|
+
const lines = [`${all.length} proposal(s): ${pending.length} pending, ${count("accepted")} accepted, ${count("rejected")} rejected${oldestPending(pending) ? `; oldest pending ${oldestPending(pending)}` : ""}.`];
|
|
193
|
+
for (const p of [...pending].sort((a, b) => a.date.localeCompare(b.date) || a.id.localeCompare(b.id))) {
|
|
194
|
+
const strength = p.problems.length ? `format problem: ${p.problems.join("; ")}` : (() => {
|
|
195
|
+
const c = checkEvidence(p, project.dir);
|
|
196
|
+
return c.strength === "verified" ? "evidence verified" : c.strength === "weak" ? "weak evidence (no commit)" : "no machine-verifiable evidence";
|
|
197
|
+
})();
|
|
198
|
+
lines.push(` pending ${p.file} — ${p.title} (${p.date || "no date"}) — ${strength}`);
|
|
199
|
+
}
|
|
200
|
+
for (const d of checkDecisions(all, project))
|
|
201
|
+
lines.push(` problem ${d.file}: ${d.problem}`);
|
|
202
|
+
return lines;
|
|
203
|
+
}
|
|
204
|
+
/** Whether `<kind>/<id>` is a record of the project, live or archived by a tidy (`.archive/<stamp>/<kind>/<id>.md`). */
|
|
205
|
+
function recordExists(project, ref) {
|
|
206
|
+
const m = /^(decisions|lessons)\/([a-z0-9-]+)$/.exec(ref);
|
|
207
|
+
if (!m)
|
|
208
|
+
return false;
|
|
209
|
+
const kind = m[1];
|
|
210
|
+
const id = m[2];
|
|
211
|
+
if (fs.existsSync(path.join(recordsKindDir(project, kind), `${id}.md`)))
|
|
212
|
+
return true;
|
|
213
|
+
const archive = path.join(recordsDir(project), ".archive");
|
|
214
|
+
try {
|
|
215
|
+
return fs.readdirSync(archive).some((stamp) => fs.existsSync(path.join(archive, stamp, kind, `${id}.md`)));
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Layer 1 of D-09: the lead's decisions are complete. Only decided proposals are looked at. An `accepted` one must be a
|
|
223
|
+
* whole proposal (format, evidence, a prefix that matches its run) with `accepted_as` pointing at a record and a `decided`
|
|
224
|
+
* date. A `rejected` one only needs `reject_reason` and `decided`, so the lead can reject a badly formed one without being
|
|
225
|
+
* sent back for it. Evidence that does not exist on disk is not checked here (layer 2, `checkEvidence`).
|
|
226
|
+
*/
|
|
227
|
+
export function checkDecisions(proposals, project) {
|
|
228
|
+
const out = [];
|
|
229
|
+
const add = (p, problem) => void out.push({ file: p.file, problem });
|
|
230
|
+
for (const p of proposals) {
|
|
231
|
+
if (p.status === "rejected") {
|
|
232
|
+
if (!p.rejectReason)
|
|
233
|
+
add(p, "rejected without reject_reason");
|
|
234
|
+
if (!p.decided)
|
|
235
|
+
add(p, "rejected without decided (YYYY-MM-DD)");
|
|
236
|
+
}
|
|
237
|
+
else if (p.status === "accepted") {
|
|
238
|
+
for (const problem of p.problems)
|
|
239
|
+
add(p, `accepted but ${problem}`);
|
|
240
|
+
if (p.run && shortIdOf(p.run) !== prefixOf(p.id))
|
|
241
|
+
add(p, "accepted but the file name prefix does not match its run");
|
|
242
|
+
if (!p.acceptedAs)
|
|
243
|
+
add(p, "accepted without accepted_as (<kind>/<id>)");
|
|
244
|
+
else if (!recordExists(project, p.acceptedAs))
|
|
245
|
+
add(p, `accepted_as ${p.acceptedAs} is not a record of the project`);
|
|
246
|
+
if (!p.decided)
|
|
247
|
+
add(p, "accepted without decided (YYYY-MM-DD)");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
const tryGit = (cwd, args) => {
|
|
253
|
+
try {
|
|
254
|
+
return git(cwd, args);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Layer 2 of D-09: does the evidence exist (30.7). `root` is the repository `path:` and `commit:` refer to (`project.dir`);
|
|
262
|
+
* a proposal's own `repo` takes its place, and when that is missing or not a git repository the evidence is only "weak".
|
|
263
|
+
* `mail:` and `output:` are format-only and never count as verified. Nothing here judges whether the lesson is right.
|
|
264
|
+
*/
|
|
265
|
+
export function checkEvidence(p, root) {
|
|
266
|
+
const notes = [];
|
|
267
|
+
const repo = p.repo ?? root;
|
|
268
|
+
const usable = fs.existsSync(repo) && isGitRepo(repo);
|
|
269
|
+
if (!usable) {
|
|
270
|
+
const had = p.evidence.some((e) => e.type === "path" || e.type === "commit");
|
|
271
|
+
return { strength: "none", notes: had ? [`the repository ${repo} is not available: evidence was not checked`] : ["no path or commit evidence"] };
|
|
272
|
+
}
|
|
273
|
+
let verified = false;
|
|
274
|
+
let weak = false;
|
|
275
|
+
for (const e of p.evidence) {
|
|
276
|
+
if (e.type === "commit") {
|
|
277
|
+
if (tryGit(repo, ["cat-file", "-t", `${e.commit}^{commit}`]) === "commit")
|
|
278
|
+
verified = true;
|
|
279
|
+
else
|
|
280
|
+
notes.push(`commit ${e.commit} does not exist`);
|
|
281
|
+
}
|
|
282
|
+
else if (e.type === "path") {
|
|
283
|
+
if (e.commit) {
|
|
284
|
+
const content = tryGit(repo, ["show", `${e.commit}:${e.file}`]);
|
|
285
|
+
if (content === undefined)
|
|
286
|
+
notes.push(`${e.file} does not exist at ${e.commit}`);
|
|
287
|
+
else if (e.line && e.line > lineCount(content))
|
|
288
|
+
notes.push(`${e.file} has fewer than ${e.line} lines at ${e.commit}`);
|
|
289
|
+
else
|
|
290
|
+
verified = true;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const full = path.join(repo, e.file);
|
|
294
|
+
const buf = readRegularFileNoFollow(full);
|
|
295
|
+
if (!buf)
|
|
296
|
+
notes.push(`${e.file} does not exist`);
|
|
297
|
+
else if (e.line && e.line > lineCount(buf.toString("utf8")))
|
|
298
|
+
notes.push(`${e.file} has fewer than ${e.line} lines`);
|
|
299
|
+
else
|
|
300
|
+
weak = true; // no commit: the line may have moved
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return { strength: verified ? "verified" : weak ? "weak" : "none", notes };
|
|
305
|
+
}
|
|
306
|
+
const lineCount = (s) => (s === "" ? 0 : s.replace(/\n$/, "").split("\n").length);
|
package/dist/records.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export interface ProjectRecord {
|
|
|
21
21
|
export declare function listRecords(project: ResolvedProject, kind: RecordKind): ProjectRecord[];
|
|
22
22
|
/** Entries shown in prompts: `status: active` and not named in another entry's `supersedes`. */
|
|
23
23
|
export declare function effectiveActive(records: ProjectRecord[]): ProjectRecord[];
|
|
24
|
+
/** The kinds whose effective-active entries take more than the budget: what `done` and `proposals review` refuse to leave behind. */
|
|
25
|
+
export declare function recordsOverBudget(project: ResolvedProject): {
|
|
26
|
+
kind: RecordKind;
|
|
27
|
+
bytes: number;
|
|
28
|
+
}[];
|
|
24
29
|
/** Bytes the effective-active entries of a kind take in a prompt (each rendered whole, as `buildRecordsView` does). */
|
|
25
30
|
export declare function activeRecordsBytes(project: ResolvedProject, kind: RecordKind): number;
|
|
26
31
|
/**
|
package/dist/records.js
CHANGED
|
@@ -98,6 +98,10 @@ function newestFirst(records) {
|
|
|
98
98
|
function renderEntry(r) {
|
|
99
99
|
return `## ${r.title} [${r.id}]${r.body ? `\n${r.body}` : ""}`;
|
|
100
100
|
}
|
|
101
|
+
/** The kinds whose effective-active entries take more than the budget: what `done` and `proposals review` refuse to leave behind. */
|
|
102
|
+
export function recordsOverBudget(project) {
|
|
103
|
+
return RECORD_KINDS.map((kind) => ({ kind, bytes: activeRecordsBytes(project, kind) })).filter((x) => x.bytes > RECORDS_BUDGET);
|
|
104
|
+
}
|
|
101
105
|
/** Bytes the effective-active entries of a kind take in a prompt (each rendered whole, as `buildRecordsView` does). */
|
|
102
106
|
export function activeRecordsBytes(project, kind) {
|
|
103
107
|
return Buffer.byteLength(effectiveActive(listRecords(project, kind)).map(renderEntry).join("\n\n"));
|
package/dist/run-session.js
CHANGED
|
@@ -6,7 +6,7 @@ import { agentForCandidate, candidatesFor, Cooldowns, defaultSleep, deferredAtte
|
|
|
6
6
|
import { compareWithLastRejection, repeatAction, repeatStopNote, stoppedInSegment, withRepeatLabel } from "./repeat-detect.js";
|
|
7
7
|
import { commandPassed, describeFailure, rejectionMessage, runVerify, verificationSection } from "./verify.js";
|
|
8
8
|
import { briefOf, digestOf, doneContract, mergeSteps, parseSteps } from "./format.js";
|
|
9
|
-
import { ProtectedGuard } from "./guard.js";
|
|
9
|
+
import { otherCallPrefixes, ProtectedGuard, runsStartedAfter } from "./guard.js";
|
|
10
10
|
import { listRunLocks, lockHolderAlive } from "./project-lock.js";
|
|
11
11
|
import { addBatch, askersWithAnswers, askReplyPath, checkAnswers, describeCheck, isComplete, markDelivered, parseAskBody, readAskReply, renderAnswers, resolveOptionLetters, writeAskReply } from "./ask-reply.js";
|
|
12
12
|
import { deliver, deliverOnce, ensureAgentDirs, ensureProjectDirs, finishDone, listUnread, PENDING_DIR, readMessageNoFollow, rejectDone, routeOutboxes, unreadFiles } from "./mailbox.js";
|
|
@@ -15,7 +15,7 @@ import { DEFAULT_MAX_INSTANCES, assertInstancesResumable, heldStallKey, instance
|
|
|
15
15
|
import { abandonClaim, attemptLogDir, sourceIdOf, beginAttempt, claimMessages, commitClaim, fault, finishAttempt, loadClaim, markOutputReady, parkOutbox, recoverRunMail, RouteJournal } from "./message-store.js";
|
|
16
16
|
import { createRunLog } from "./run-log.js";
|
|
17
17
|
import { endOutcome, resolveDoneOutcome } from "./run-outcome.js";
|
|
18
|
-
import { inboxDir, outboxDir, sharedIndex } from "./policy.js";
|
|
18
|
+
import { inboxDir, outboxDir, proposalsDir, sharedIndex } from "./policy.js";
|
|
19
19
|
import { buildSystemPrompt, buildUserPrompt, pickMessages } from "./prompt.js";
|
|
20
20
|
import { collectDrafts, priorFailedAttempts, redoUserPrompt } from "./redo.js";
|
|
21
21
|
import { atomicWrite, readFileCapped } from "./fs-util.js";
|
|
@@ -215,6 +215,9 @@ export class RunSession {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
ensureProjectDirs(project);
|
|
218
|
+
// The agent of `run --agent` writes its proposals here; runtimes only get a directory that exists (spec 30, D-18).
|
|
219
|
+
if (project.solo === "run")
|
|
220
|
+
fs.mkdirSync(proposalsDir(project), { recursive: true });
|
|
218
221
|
fs.mkdirSync(runDir, { recursive: true });
|
|
219
222
|
const log = createRunLog(path.join(runDir, "log.jsonl"), cfg.log_max_bytes);
|
|
220
223
|
if (concurrent && !resume) {
|
|
@@ -283,8 +286,10 @@ export class RunSession {
|
|
|
283
286
|
}
|
|
284
287
|
const saveState = () => saveRunState(runDir, state);
|
|
285
288
|
// Concurrent runs: the repo's instruction files the run can touch are the lead worktree's copies; your own tree is never watched (or restored).
|
|
286
|
-
const otherLiveRuns = () => listRunLocks(project.paths.root).filter((l) => l.run_id !== runId && lockHolderAlive(l)).map((l) => l.run_id);
|
|
287
|
-
|
|
289
|
+
const otherLiveRuns = () => listRunLocks(project.paths.root).filter((l) => !l.call && l.run_id !== runId && lockHolderAlive(l)).map((l) => l.run_id);
|
|
290
|
+
// A solo agent is judged against every other run that began while it worked, live or not (spec 30, D-03): such a run's lead may write the shared files.
|
|
291
|
+
const guardOpts = project.solo ? { startedAfter: (stamp) => runsStartedAfter(project.paths.runs, stamp, runId), otherPrefixes: otherCallPrefixes(project.home, project.paths.root, runId) } : {};
|
|
292
|
+
const guard = new ProtectedGuard(leadSpace ? { ...project, workspaces: { ...project.workspaces, [project.lead]: leadSpace } } : project, otherLiveRuns, guardOpts);
|
|
288
293
|
if (resume) {
|
|
289
294
|
log("resume", { rounds: state.rounds, interrupted: Object.keys(resume.active ?? {}) });
|
|
290
295
|
if (opts.followup) {
|
package/dist/status.js
CHANGED
|
@@ -10,6 +10,7 @@ import { parseSlotName } from "./instances.js";
|
|
|
10
10
|
import { inboxDir } from "./policy.js";
|
|
11
11
|
import { tidyAdvice } from "./memory-tidy.js";
|
|
12
12
|
import { inspectRunLock, lockHolderAlive } from "./project-lock.js";
|
|
13
|
+
import { oldestPending, pendingProposals } from "./proposals.js";
|
|
13
14
|
/** The run to show: the newest one still running (a resumed run keeps its old id, so newer runs may sit above it), else the newest run. */
|
|
14
15
|
export function currentRun(project) {
|
|
15
16
|
const running = listRuns(project, Infinity).find((r) => !r.state.end_reason && runIsAlive(r.state, project));
|
|
@@ -349,6 +350,9 @@ export function buildStatusReport(base, runId, now = Date.now()) {
|
|
|
349
350
|
...(advice.length ? { memory_advice: advice } : {}),
|
|
350
351
|
};
|
|
351
352
|
belowCeiling.set(out, below);
|
|
353
|
+
const waiting = pendingProposals(project);
|
|
354
|
+
if (waiting.length)
|
|
355
|
+
pendingOf.set(out, { count: waiting.length, ...(oldestPending(waiting) ? { oldest: oldestPending(waiting) } : {}) });
|
|
352
356
|
return out;
|
|
353
357
|
}
|
|
354
358
|
/** Every run of the project, newest first. */
|
|
@@ -531,6 +535,8 @@ function fallbackLines(agents, c) {
|
|
|
531
535
|
}
|
|
532
536
|
return out;
|
|
533
537
|
}
|
|
538
|
+
/** Proposals waiting for the lead (spec 30), for the human page only: `status --json` stays as it was (it carries `schema_version: 1` for the web monitor). */
|
|
539
|
+
const pendingOf = new WeakMap();
|
|
534
540
|
/** Agents whose latest wake ran on a tiered model below the ceiling; kept off the report so `status --json` is unchanged. */
|
|
535
541
|
const belowCeiling = new WeakMap();
|
|
536
542
|
/** An agent whose latest wake ran on a model below its ceiling (spec 24.9): one line each, in agent order. */
|
|
@@ -581,5 +587,8 @@ export function formatStatusReport(report, now = Date.now(), color = false) {
|
|
|
581
587
|
lines.push("", `輸出 tokens:${tokens(run.output_tokens)}${cacheText(run.cache_read_tokens, run.cache_write_tokens) ? ` ${cacheText(run.cache_read_tokens, run.cache_write_tokens)}` : ""}`);
|
|
582
588
|
if (report.memory_advice?.length)
|
|
583
589
|
lines.push("", `記憶:${report.memory_advice.join(";")}(建議執行 agent-lyceum tidy -p ${report.project.name};status 只提示,不會自動整理)`);
|
|
590
|
+
const waiting = pendingOf.get(report);
|
|
591
|
+
if (waiting)
|
|
592
|
+
lines.push("", `提案:${waiting.count} 筆待審${waiting.oldest ? `(最舊 ${waiting.oldest})` : ""}(agent-lyceum proposals review -p ${report.project.name};status 只提示,不會自動審)`);
|
|
584
593
|
return lines.join("\n");
|
|
585
594
|
}
|