agent-lyceum 0.55.0 → 0.57.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 CHANGED
@@ -56,7 +56,7 @@ Its own data (config, mailboxes, logs, memory, worktrees) lives in `~/agent-lyce
56
56
  | `call <agent>` | Ask one global agent on its own, outside any project. [details](docs/commands.md#call) |
57
57
  | `demo` | Try a 3-agent team on a throwaway sample repo. [details](docs/commands.md#demo) |
58
58
  | `tidy` | Have agents tidy their own memory (archives, never deletes). [details](docs/commands.md#tidy) |
59
- | `proposals` | List, or have the lead decide, lesson proposals of agents that ran alone. [details](docs/commands.md#proposals) |
59
+ | `proposals` | List proposals, or have the lead decide them. An agent that ran alone proposes a lesson or a decision; in a normal run, a role whose name ends with `-reviewer` can propose a lesson from a blocker or major finding. [details](docs/commands.md#proposals) |
60
60
 
61
61
  `agent-lyceum <command> --help` prints the full options. Ctrl-C cancels cleanly; [exit codes](docs/commands.md#exit-codes) tell scripts how a run ended.
62
62
 
package/README.zh-TW.md CHANGED
@@ -56,7 +56,7 @@ npx agent-lyceum status
56
56
  | `call <agent>` | 在任何專案之外單獨呼叫一個全域 agent。 [詳細](docs/commands.zh-TW.md#call) |
57
57
  | `demo` | 在拋棄式範例 repo 上試跑 3 個 agent 的團隊。 [詳細](docs/commands.zh-TW.md#demo) |
58
58
  | `tidy` | 讓 agent 整理自己的記憶(只封存,不刪除)。 [詳細](docs/commands.zh-TW.md#tidy) |
59
- | `proposals` | 列出單獨執行的 agent 提出的教訓提案,或讓 lead 決議。 [詳細](docs/commands.zh-TW.md#proposals) |
59
+ | `proposals` | 列出提案,或讓 lead 決議。單獨執行的 agent 可提案 lesson 或 decision;一般 run 裡,角色名以 `-reviewer` 結尾的成員可把 blocker 或 major finding 寫成 lesson 提案。 [詳細](docs/commands.zh-TW.md#proposals) |
60
60
 
61
61
  `agent-lyceum <指令> --help` 會印出完整選項。Ctrl-C 可乾淨取消;腳本可依[結束碼](docs/commands.zh-TW.md#退出碼)判斷 run 的結果。
62
62
 
package/dist/doctor.js CHANGED
@@ -7,7 +7,8 @@ import { tidyAdvice } from "./memory-tidy.js";
7
7
  import { teamRunFindings } from "./review-gate.js";
8
8
  import { lessonGuardFindings, listRecords, RECORD_KINDS } from "./records.js";
9
9
  import { listRunLocks, listUnreadableRunLocks, lockHolderAlive } from "./project-lock.js";
10
- import { checkDecisions, listProposals, oldestPending, pendingProposals } from "./proposals.js";
10
+ import { checkDecisions, checkFindingMail, isRunId, listProposals, oldestPending, pendingProposals, proposalOwner } from "./proposals.js";
11
+ import { reviewerNames } from "./policy.js";
11
12
  import { runInvocation } from "./process-runner.js";
12
13
  import { validateProject } from "./validate.js";
13
14
  import { diagnoseInstances } from "./doctor-instances.js";
@@ -235,9 +236,24 @@ export async function diagnoseProject(project, opts = {}) {
235
236
  const waiting = pendingProposals(project);
236
237
  if (waiting.length)
237
238
  checks.push({ level: "info", subject: "proposals", message: `${waiting.length} proposal(s) wait for the lead (oldest ${oldestPending(waiting) ?? "unknown"}): \`agent-lyceum proposals review -p ${project.name}\`.` });
239
+ const reviewers = reviewerNames(project);
238
240
  for (const pr of listProposals(project)) {
239
241
  if (pr.problems.length && (pr.status === undefined || pr.status === "proposed"))
240
242
  checks.push({ level: "warn", subject: "proposals", message: `${pr.file}: ${pr.problems.join("; ")}.` });
243
+ const owner = proposalOwner(pr.id, reviewers);
244
+ if ((pr.status !== undefined && pr.status !== "proposed") || !owner)
245
+ continue;
246
+ if (!isRunId(pr.run))
247
+ checks.push({ level: "warn", subject: "proposals", message: `${pr.file}: run must be a run id.` });
248
+ if (!pr.finding)
249
+ checks.push({ level: "warn", subject: "proposals", message: `${pr.file}: finding is required.` });
250
+ else if (pr.finding.mail && !/[\\/]/.test(pr.finding.mail) && !pr.finding.mail.includes("..")) {
251
+ const mail = checkFindingMail(project, pr.run, pr.finding.mail, owner);
252
+ if (mail === "missing")
253
+ checks.push({ level: "warn", subject: "proposals", message: `${pr.file}: finding.mail was not found.` });
254
+ else if (mail === "not-a-verdict-reply")
255
+ checks.push({ level: "warn", subject: "proposals", message: `${pr.file}: finding.mail is not a reply with verdict.` });
256
+ }
241
257
  }
242
258
  for (const d of checkDecisions(listProposals(project), project))
243
259
  checks.push({ level: "warn", subject: "proposals", message: `${d.file}: ${d.problem}.` });
package/dist/guard.d.ts CHANGED
@@ -37,6 +37,11 @@ export interface GuardOptions {
37
37
  */
38
38
  otherPrefixes?: (stamp: string) => string[];
39
39
  }
40
+ /**
41
+ * Short ids of other calls, and of runs that started after `stamp`, excluding `selfId`. A normal run's proposal guard
42
+ * leaves files with these prefixes in place. It is not passed as `startedAfter`: that would keep every proposal change.
43
+ */
44
+ export declare function proposalForeignPrefixes(home: string, projectRoot: string, runsDir: string, selfId: string): (stamp: string) => string[];
40
45
  /** The short ids of the calls other than `selfId` that hold a live project lock, or that started after `stamp` (their ids sort by start time). */
41
46
  export declare function otherCallPrefixes(home: string, projectRoot: string, selfId: string): (stamp: string) => string[];
42
47
  /** The timestamp part of a run id, for `Date` (the same text `newRunId` starts with). */
@@ -85,13 +90,18 @@ export declare class ProtectedGuard {
85
90
  check(running: ResolvedAgent[]): Violation[];
86
91
  private checkRecords;
87
92
  /**
88
- * A solo agent may create and change only its own `proposals/<kind>/<short id>-<slug>.md`, and only while the file is
89
- * `proposed` (spec 30, D-03). Everything else under the proposals tree is put back: other prefixes, other folders,
90
- * `.archive/`, deletions, a file that was already decided (even one with its own prefix, e.g. after a resume), and a
91
- * write of `accepted` or `rejected`. A file that is merely badly formed is let through; D-09 flags it for the lead.
92
- * Not watched for an ordinary run: its members are held back by the write policy only (30.8).
93
+ * Solo: only its own `proposals/<kind>/<short id>-<slug>.md` while `proposed` (spec 30). A normal run: a reviewer may
94
+ * create and change only `proposals/lessons/<short id>-<agent>-<slug>.md` while it stays `proposed`; the lead may change
95
+ * proposals but not delete them. When the batch contains more than one of those writers, the change is `unattributed`
96
+ * and kept (issue 177).
93
97
  */
94
98
  private checkProposals;
99
+ private checkSoloProposals;
100
+ /** A normal run. `other` (another live run) keeps every change, the same as records. */
101
+ private checkTeamProposals;
102
+ /** A reviewer may keep `lessons/<short id>-<own name>-<slug>.md` only while it is still `proposed`. */
103
+ private reviewerMayKeep;
104
+ private revertProposal;
95
105
  /**
96
106
  * Make every directory from the records root down to `dir` a real directory. A symlink or file standing in for one is an
97
107
  * unauthorized change: unlink it (never follow it), recreate the directory and report it. False when `dir` is not safe to write into.
package/dist/guard.js CHANGED
@@ -2,11 +2,20 @@ import crypto from "node:crypto";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { readRegularFileNoFollow } from "./fs-util.js";
5
+ import { roleOfName } from "./instances.js";
5
6
  import { escapesParent } from "./paths.js";
6
- import { mayEditProtected, proposalsDir, recordsDir, repoInstructionFiles, sharedContextFiles, sharedIndex } from "./policy.js";
7
+ import { mayEditProtected, proposalsDir, recordsDir, repoInstructionFiles, reviewerNames, sharedContextFiles, sharedIndex } from "./policy.js";
7
8
  import { listRunLocks, lockHolderAlive } from "./project-lock.js";
8
- import { prefixOf, proposalStatusOf, shortIdOf } from "./proposals.js";
9
+ import { prefixOf, proposalOwner, proposalStatusOf, shortIdOf } from "./proposals.js";
9
10
  export const MAX_KEEP_BYTES = 1024 * 1024;
11
+ /**
12
+ * Short ids of other calls, and of runs that started after `stamp`, excluding `selfId`. A normal run's proposal guard
13
+ * leaves files with these prefixes in place. It is not passed as `startedAfter`: that would keep every proposal change.
14
+ */
15
+ export function proposalForeignPrefixes(home, projectRoot, runsDir, selfId) {
16
+ const calls = otherCallPrefixes(home, projectRoot, selfId);
17
+ return (stamp) => [...new Set([...calls(stamp), ...runsStartedAfter(runsDir, stamp, selfId).map(shortIdOf)])];
18
+ }
10
19
  /** The short ids of the calls other than `selfId` that hold a live project lock, or that started after `stamp` (their ids sort by start time). */
11
20
  export function otherCallPrefixes(home, projectRoot, selfId) {
12
21
  return (stamp) => {
@@ -215,15 +224,19 @@ export class ProtectedGuard {
215
224
  this.records = now;
216
225
  }
217
226
  /**
218
- * A solo agent may create and change only its own `proposals/<kind>/<short id>-<slug>.md`, and only while the file is
219
- * `proposed` (spec 30, D-03). Everything else under the proposals tree is put back: other prefixes, other folders,
220
- * `.archive/`, deletions, a file that was already decided (even one with its own prefix, e.g. after a resume), and a
221
- * write of `accepted` or `rejected`. A file that is merely badly formed is let through; D-09 flags it for the lead.
222
- * Not watched for an ordinary run: its members are held back by the write policy only (30.8).
227
+ * Solo: only its own `proposals/<kind>/<short id>-<slug>.md` while `proposed` (spec 30). A normal run: a reviewer may
228
+ * create and change only `proposals/lessons/<short id>-<agent>-<slug>.md` while it stays `proposed`; the lead may change
229
+ * proposals but not delete them. When the batch contains more than one of those writers, the change is `unattributed`
230
+ * and kept (issue 177).
223
231
  */
224
232
  checkProposals(running, violations, other) {
225
- if (!this.project.solo)
233
+ if (this.project.solo) {
234
+ this.checkSoloProposals(running, violations, other);
226
235
  return;
236
+ }
237
+ this.checkTeamProposals(running, violations, other);
238
+ }
239
+ checkSoloProposals(running, violations, other) {
227
240
  const prefix = this.ownPrefix();
228
241
  if (!prefix)
229
242
  return;
@@ -274,6 +287,85 @@ export class ProtectedGuard {
274
287
  }
275
288
  this.proposals = readTree(root);
276
289
  }
290
+ /** A normal run. `other` (another live run) keeps every change, the same as records. */
291
+ checkTeamProposals(running, violations, other) {
292
+ const prefix = this.ownPrefix();
293
+ if (!prefix)
294
+ return;
295
+ const root = this.proposalsRoot();
296
+ if (isLink(path.dirname(root)) || isLink(path.dirname(path.dirname(root))))
297
+ return;
298
+ const now = readTree(root);
299
+ const suspects = running.map((a) => a.name);
300
+ const names = reviewerNames(this.project);
301
+ // A slot opened after the guard was built is not in `this.project.agents`. Its own `instance.role` still says it reviews.
302
+ const reviews = (a) => {
303
+ if (this.project.solo || a.name === this.project.lead)
304
+ return false;
305
+ return (a.instance?.role ?? roleOfName(this.project.agents, a.name)).endsWith("-reviewer");
306
+ };
307
+ const reviewers = running.filter(reviews);
308
+ const leadIn = running.some((a) => a.name === this.project.lead);
309
+ const memberIn = running.some((a) => a.name !== this.project.lead && !reviews(a));
310
+ const fixedDirs = new Set();
311
+ const theirs = new Set(this.opts.otherPrefixes?.(this.baseStamp) ?? []);
312
+ const ambiguous = (leadIn && reviewers.length > 0) || reviewers.length > 1 || (memberIn && (leadIn || reviewers.length > 0));
313
+ for (const file of new Set([...this.proposals.keys(), ...now.keys()])) {
314
+ const before = this.proposals.get(file) ?? null;
315
+ const cur = now.get(file) ?? null;
316
+ if (same(before, cur))
317
+ continue;
318
+ if (other.length || ambiguous) {
319
+ this.unattributed.push({ file, agents: suspects, otherRuns: other });
320
+ continue;
321
+ }
322
+ // A proposal of another call, or of a run that started during this window, is that run's own.
323
+ if (theirs.has(prefixOf(path.basename(file))))
324
+ continue;
325
+ if (leadIn) {
326
+ if (cur === null && before !== null)
327
+ this.revertProposal(root, file, before, cur, suspects, violations, fixedDirs);
328
+ continue;
329
+ }
330
+ const reviewer = reviewers[0];
331
+ if (reviewer && this.reviewerMayKeep(file, root, before, cur, reviewer.name, prefix, names))
332
+ continue;
333
+ this.revertProposal(root, file, before, cur, suspects, violations, fixedDirs);
334
+ }
335
+ this.proposals = readTree(root);
336
+ }
337
+ /** A reviewer may keep `lessons/<short id>-<own name>-<slug>.md` only while it is still `proposed`. */
338
+ reviewerMayKeep(file, root, before, cur, agentName, shortId, names) {
339
+ const rel = path.relative(root, file);
340
+ if (path.dirname(rel) !== "lessons" || !rel.endsWith(".md") || cur === null)
341
+ return false;
342
+ const id = path.basename(file, ".md");
343
+ if (proposalOwner(id, names) !== agentName || !id.startsWith(`${shortId}-`))
344
+ return false;
345
+ if (before) {
346
+ const was = proposalStatusOf(before);
347
+ if (was === "accepted" || was === "rejected")
348
+ return false;
349
+ }
350
+ const next = proposalStatusOf(cur);
351
+ return next !== "accepted" && next !== "rejected";
352
+ }
353
+ revertProposal(root, file, before, cur, suspects, violations, fixedDirs) {
354
+ const kept = this.keep(file, cur);
355
+ if (before === null) {
356
+ if (!insideRoot(root, path.dirname(file)))
357
+ return;
358
+ fs.rmSync(file, { force: true });
359
+ violations.push({ file, action: "removed", suspects, ...kept });
360
+ }
361
+ else {
362
+ if (!this.realDirs(root, path.dirname(file), fixedDirs, suspects, violations))
363
+ return;
364
+ fs.rmSync(file, { recursive: true, force: true });
365
+ fs.writeFileSync(file, before);
366
+ violations.push({ file, action: "restored", suspects, ...kept });
367
+ }
368
+ }
277
369
  /**
278
370
  * Make every directory from the records root down to `dir` a real directory. A symlink or file standing in for one is an
279
371
  * unauthorized change: unlink it (never follow it), recreate the directory and report it. False when `dir` is not safe to write into.
@@ -588,6 +588,22 @@ export const ADVICE_COMMITS = 50;
588
588
  /** Hints only: project memory whose index is larger than what an agent is shown, or whose baseline is far behind. Never acts. */
589
589
  export function tidyAdvice(project) {
590
590
  const out = [];
591
+ // One report walks every target. The repo check and each baseline count are shared; the text stays the same.
592
+ let repo;
593
+ const counts = new Map();
594
+ const inRepo = () => {
595
+ if (repo === undefined)
596
+ repo = fs.existsSync(project.dir) && isGitRepo(project.dir);
597
+ return repo;
598
+ };
599
+ const commitsSince = (since) => {
600
+ const cached = counts.get(since);
601
+ if (cached !== undefined)
602
+ return cached;
603
+ const n = Number(tryGit(project.dir, ["rev-list", "--count", `${since}..HEAD`]));
604
+ counts.set(since, n);
605
+ return n;
606
+ };
591
607
  for (const t of targetsFor(project, { layer: "project" })) {
592
608
  if (!fs.existsSync(t.dir))
593
609
  continue;
@@ -597,9 +613,9 @@ export function tidyAdvice(project) {
597
613
  continue;
598
614
  }
599
615
  const since = readTidyState(t.dir)?.head;
600
- if (!since || !fs.existsSync(project.dir) || !isGitRepo(project.dir))
616
+ if (!since || !inRepo())
601
617
  continue;
602
- const n = Number(tryGit(project.dir, ["rev-list", "--count", `${since}..HEAD`]));
618
+ const n = commitsSince(since);
603
619
  if (Number.isFinite(n) && n >= ADVICE_COMMITS)
604
620
  out.push({ agent: t.agent, reason: `${n} commits since the last tidy` });
605
621
  }
package/dist/policy.d.ts CHANGED
@@ -35,6 +35,15 @@ export declare function recordsKindDir(project: ResolvedProject, kind: "decision
35
35
  export declare function proposalsDir(project: ResolvedProject): string;
36
36
  /** Whether the agent of this solo project may write proposals: `run --agent`, and `call -p` (a plain `call` has no project). */
37
37
  export declare const mayPropose: (project: ResolvedProject) => boolean;
38
+ /**
39
+ * Slot names that may write a lesson proposal in a normal run. The role name ends with `-reviewer`; the lead never counts.
40
+ * A solo project has none, so spec 30 is unchanged.
41
+ */
42
+ export declare function reviewerNames(project: ResolvedProject): string[];
43
+ /** Whether this agent may write lesson proposals during a normal run, including a read-only review. */
44
+ export declare const isReviewer: (project: ResolvedProject, agent: ResolvedAgent) => boolean;
45
+ /** Create the proposals directory for a normal run that has a reviewer. A solo run keeps its own `mkdir`. */
46
+ export declare function ensureReviewerProposalDir(project: ResolvedProject): void;
38
47
  export declare function proposalsKindDir(project: ResolvedProject, kind: "decisions" | "lessons"): string;
39
48
  /** The lead-maintained files shared by every run of the project. */
40
49
  export declare function sharedContextFiles(project: ResolvedProject): string[];
@@ -68,8 +77,9 @@ export declare function writePolicy(project: ResolvedProject, agent: ResolvedAge
68
77
  export declare function coordinatePolicy(project: ResolvedProject, agent: ResolvedAgent): WritePolicy;
69
78
  /**
70
79
  * A read-only wake. `invokeWithSandboxChecks` skips `sandboxRefusal` when `input.policy` is set, so this must not
71
- * copy `sandbox.write` (nor the git dir, records, proposals, or `can_edit_agent_md` files) into the writable set.
72
- * The repo stays readable via `readDirs`.
80
+ * copy `sandbox.write` (nor the git dir, records, or `can_edit_agent_md` files) into the writable set.
81
+ * The repo stays readable via `readDirs`. A reviewer may still write `proposals/`: a review task is read-only, and that
82
+ * is when a blocker or major finding is filed. Records stay out.
73
83
  */
74
84
  export declare function readOnlyPolicy(project: ResolvedProject, agent: ResolvedAgent): WritePolicy;
75
85
  export declare function osSandboxAvailable(): boolean;
package/dist/policy.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { findOnPath } from "./fs-util.js";
4
+ import { roleOfName } from "./instances.js";
4
5
  import { canonicalPath } from "./paths.js";
5
6
  export function commonFile(project) {
6
7
  return path.join(project.paths.shared, "common", "COMMON.md");
@@ -25,6 +26,23 @@ export function proposalsDir(project) {
25
26
  }
26
27
  /** Whether the agent of this solo project may write proposals: `run --agent`, and `call -p` (a plain `call` has no project). */
27
28
  export const mayPropose = (project) => project.solo === "run" || (project.solo === "call" && !!project.proposalsRef);
29
+ /**
30
+ * Slot names that may write a lesson proposal in a normal run. The role name ends with `-reviewer`; the lead never counts.
31
+ * A solo project has none, so spec 30 is unchanged.
32
+ */
33
+ export function reviewerNames(project) {
34
+ if (project.solo)
35
+ return [];
36
+ return Object.keys(project.agents).filter((name) => name !== project.lead && roleOfName(project.agents, name).endsWith("-reviewer"));
37
+ }
38
+ /** Whether this agent may write lesson proposals during a normal run, including a read-only review. */
39
+ export const isReviewer = (project, agent) => reviewerNames(project).includes(agent.name);
40
+ /** Create the proposals directory for a normal run that has a reviewer. A solo run keeps its own `mkdir`. */
41
+ export function ensureReviewerProposalDir(project) {
42
+ if (project.solo || reviewerNames(project).length === 0)
43
+ return;
44
+ fs.mkdirSync(proposalsDir(project), { recursive: true });
45
+ }
28
46
  export function proposalsKindDir(project, kind) {
29
47
  return path.join(proposalsDir(project), kind);
30
48
  }
@@ -159,7 +177,7 @@ export function writePolicy(project, agent) {
159
177
  ...(shared && mayWriteShared ? [shared] : []),
160
178
  ...(isLead ? [recordsDir(project)] : []),
161
179
  // Proposals: the lead (it decides them) and a solo agent (it writes them); the guard holds the solo agent to its own `proposed` files.
162
- ...(isLead || mayPropose(project) ? [proposalsDir(project)] : []),
180
+ ...(isLead || mayPropose(project) || isReviewer(project, agent) ? [proposalsDir(project)] : []),
163
181
  ...(grantOwnDir ? [ownDir] : []),
164
182
  // Spec 25: canonical, because the OS sandbox compares real paths (`/tmp` is `/private/tmp` on macOS).
165
183
  ...(agent.sandbox?.write ?? []).map(canonicalPath),
@@ -241,7 +259,7 @@ export function coordinatePolicy(project, agent) {
241
259
  ...(project.solo === "call" ? [] : [outboxDir(project, agent.name)]),
242
260
  ...(grantOwnDir ? [ownDir] : []),
243
261
  ...(isLead ? [recordsDir(project)] : []),
244
- ...(isLead || mayPropose(project) ? [proposalsDir(project)] : []),
262
+ ...(isLead || mayPropose(project) || isReviewer(project, agent) ? [proposalsDir(project)] : []),
245
263
  ...(shared && agent.name === project.lead ? [shared] : []),
246
264
  ].filter(outside);
247
265
  return {
@@ -253,8 +271,9 @@ export function coordinatePolicy(project, agent) {
253
271
  }
254
272
  /**
255
273
  * A read-only wake. `invokeWithSandboxChecks` skips `sandboxRefusal` when `input.policy` is set, so this must not
256
- * copy `sandbox.write` (nor the git dir, records, proposals, or `can_edit_agent_md` files) into the writable set.
257
- * The repo stays readable via `readDirs`.
274
+ * copy `sandbox.write` (nor the git dir, records, or `can_edit_agent_md` files) into the writable set.
275
+ * The repo stays readable via `readDirs`. A reviewer may still write `proposals/`: a review task is read-only, and that
276
+ * is when a blocker or major finding is filed. Records stay out.
258
277
  */
259
278
  export function readOnlyPolicy(project, agent) {
260
279
  const normal = writePolicy(project, agent);
@@ -264,6 +283,7 @@ export function readOnlyPolicy(project, agent) {
264
283
  ...memoryDirs(agent),
265
284
  ...(project.solo === "call" ? [] : [outboxDir(project, agent.name)]),
266
285
  ...(grantOwnDir ? [ownDir] : []),
286
+ ...(isReviewer(project, agent) ? [proposalsDir(project)] : []),
267
287
  ];
268
288
  return {
269
289
  allowDirs,
package/dist/prompt.js CHANGED
@@ -3,9 +3,9 @@ import path from "node:path";
3
3
  import { REQUIRED_SECTIONS } from "./format.js";
4
4
  import { senderLabel, slotName } from "./instances.js";
5
5
  import { modelForTier } from "./tiers.js";
6
- import { checkEvidence, oldestPending, pendingProposals, PENDING_SHOWN, shortIdOf } from "./proposals.js";
6
+ import { checkEvidence, oldestPending, pendingProposals, PENDING_SHOWN, proposalOwner, reviewerNames, shortIdOf } from "./proposals.js";
7
7
  import { activeRecordsBytes, buildRecordsView, effectiveActive, listRecords, RECORD_KINDS, RECORDS_BUDGET } from "./records.js";
8
- import { commonFile, mayPropose, memoryDirs, outboxDir, ownAgentDirAllowed, projectAgentDir, proposalsDir, recordsKindDir, repoDirFor, sharedDir, sharedIndex } from "./policy.js";
8
+ import { commonFile, isReviewer, mayPropose, memoryDirs, outboxDir, ownAgentDirAllowed, projectAgentDir, proposalsDir, recordsKindDir, repoDirFor, sharedDir, sharedIndex } from "./policy.js";
9
9
  function memoryLabel(agent, dir) {
10
10
  if (dir === agent.memory.task)
11
11
  return "task (this task only, isolated)";
@@ -208,6 +208,24 @@ export function pendingProposalLines(project) {
208
208
  `${pending.length} proposals await a decision (oldest: ${oldestPending(pending) ?? "unknown"}). Showing ${shown.length}:`,
209
209
  ...shown.map((p) => `- \`${p.file}\` — ${p.title} — ${strength(p)}`),
210
210
  `For each one, check the evidence yourself, then either create the record (a new file, not a copy) and set the proposal to \`status: accepted\` with \`accepted_as: <kind>/<id>\`, or set \`status: rejected\` with \`reject_reason\`. In both cases also write \`decided: <today's date>\`. Put a short summary of the evidence in the record's body. Active entries use ${used}; merge or supersede before you exceed it.`,
211
+ ...(shown.some((p) => proposalOwner(p.id, reviewerNames(project)))
212
+ ? ["A proposal whose file name is a reviewer's must be copied into the record under a heading that is exactly `## Evidence`: the evidence entries and the finding's mail, severity and class, verbatim. Accept it only when one evidence entry is a path at a commit or a commit. The program rejects the done otherwise."]
213
+ : []),
214
+ ];
215
+ }
216
+ /** What a reviewer in a normal run is told about filing a blocker or major finding (issue 177). Nothing for anyone else, and nothing without a bound run. */
217
+ function reviewerProposalRules(project, agent) {
218
+ if (!isReviewer(project, agent) || !project.run)
219
+ return [];
220
+ const prefix = shortIdOf(project.run.id);
221
+ const dir = proposalsDir(project);
222
+ return [
223
+ "",
224
+ "## Proposals",
225
+ "When a finding in your review has severity blocker or major, and it would change how a later run should work, write one proposal. Minor and nit findings are not proposals.",
226
+ `Write one Markdown file \`${prefix}-${agent.name}-<slug>.md\` in \`${dir}/lessons/\` only, not in decisions/. The prefix \`${prefix}-${agent.name}-\` is fixed for this run. The slug uses only lowercase letters, digits and \`-\`.`,
227
+ `Start the file with \`status: proposed\`, \`date\`, \`title\`, \`proposed_by\` (your name), \`run: ${project.run.id}\` and \`finding\` with \`mail\` (the file name you wrote in your outbox for the reply that carries \`verdict:\`; that same name is what is checked after the reply is sent), \`severity\` (\`blocker\` or \`major\`) and \`class\` (one line). \`evidence\` needs at least one verified entry: \`- path: file:line @ <commit sha>\` or \`- commit: <sha>\`. \`mail:\` and \`output:\` may be added but do not count as verified.`,
228
+ "Write the facts you observed first, then your guess about the cause, and mark it as a guess. Never set `status` to `accepted` or `rejected`. Never edit another agent's proposal, never delete a proposal, and never write the records.",
211
229
  ];
212
230
  }
213
231
  /** The prompts of a `proposals review` wake-up (spec 30, D-14): the lead decides the pending proposals and writes the records, nothing else. */
@@ -342,6 +360,7 @@ export function buildSystemPrompt(project, agent) {
342
360
  let text = lines.join("\n");
343
361
  if (isLead && project.run?.instances)
344
362
  text = `${text}\n\n${PARALLEL_SECTION(project.run.instances.max)}`;
363
+ text += reviewerProposalRules(project, agent).join("\n");
345
364
  if (isLead) {
346
365
  const members = Object.values(project.agents)
347
366
  .filter((a) => a.name !== project.lead && (!a.instance || a.instance.k === 1) && (a.tiers?.length ?? 0) >= 2)
@@ -7,6 +7,14 @@ import { type RecordKind } from "./records.js";
7
7
  export type ProposalKind = RecordKind;
8
8
  export declare const PROPOSAL_KINDS: readonly ProposalKind[];
9
9
  export type ProposalStatus = "proposed" | "accepted" | "rejected";
10
+ /** A reviewer's blocker or major finding. `severity` is kept even when it is not blocker or major, so a warning can name it. */
11
+ export interface Finding {
12
+ mail: string;
13
+ severity: string;
14
+ className: string;
15
+ }
16
+ /** Where a `finding.mail` file stands while its run directory still exists. `skip` means the run is gone or its mail is not in the run folder. */
17
+ export type FindingMail = "skip" | "ok" | "missing" | "not-a-verdict-reply";
10
18
  /** One proposal file is at most this big; a larger one is "not in the right format" (D-11). */
11
19
  export declare const PROPOSAL_MAX_BYTES: number;
12
20
  /** The lead's prompt lists at most this many pending proposals (D-11). */
@@ -38,6 +46,10 @@ export interface Proposal {
38
46
  proposedBy: string;
39
47
  run: string;
40
48
  evidence: Evidence[];
49
+ /** The evidence values as written, so a record can be checked for a verbatim copy. */
50
+ evidenceText: string[];
51
+ /** Set when the file has a `finding` mapping. Absent when the key is omitted (a solo proposal). */
52
+ finding?: Finding;
41
53
  repo?: string;
42
54
  scope?: string;
43
55
  supersedes: string[];
@@ -55,6 +67,15 @@ export declare function shortIdOf(runId: string): string;
55
67
  export declare function proposalStatusOf(buf: Buffer): ProposalStatus | undefined;
56
68
  /** The id's own prefix: what comes before the first `-`. */
57
69
  export declare const prefixOf: (id: string) => string;
70
+ export { isReviewer, reviewerNames } from "./policy.js";
71
+ /** A run id (`newRunId`): timestamp, hyphen, then lowercase letters or digits. Solo proposals are not held to this. */
72
+ export declare const isRunId: (value: string) => boolean;
73
+ /**
74
+ * The reviewer a team file name belongs to. `id` is the file name without `.md`: `<8 lowercase letters or digits>-<agent>-<slug>`.
75
+ * When one reviewer name is a prefix of another (`cli-reviewer` and `cli-reviewer--2`), the longer name wins. A `<role>--<k>-<slug>`
76
+ * file belongs to that slot when the role is one of `names`, even if the slot itself is not. A solo `<short id>-<slug>` has no owner.
77
+ */
78
+ export declare function proposalOwner(id: string, names: readonly string[]): string | undefined;
58
79
  export declare function parseProposal(kind: ProposalKind, file: string): Proposal;
59
80
  /** Every `*.md` proposal of one kind, sorted by id. A missing or symlinked folder lists nothing; `.archive/` is never read. */
60
81
  export declare function listKindProposals(project: ResolvedProject, kind: ProposalKind): Proposal[];
@@ -75,6 +96,14 @@ export interface DecisionProblem {
75
96
  * sent back for it. Evidence that does not exist on disk is not checked here (layer 2, `checkEvidence`).
76
97
  */
77
98
  export declare function checkDecisions(proposals: Proposal[], project: ResolvedProject): DecisionProblem[];
99
+ /**
100
+ * Whether `mailBase` is one reply carrying `verdict:` under the run's mail. The file name is the one the reviewer wrote in
101
+ * their outbox: after routing, `sent/<name>` wins over a rejected copy of the same name, and over every other agent's outbox.
102
+ * A delivered copy (a different file name) is looked up in inboxes, including `pending/`. No run directory left, or `mail_layout`
103
+ * other than `run`, means the mail cannot be checked any more: that is `skip`, not a failure. `runId` is never joined onto
104
+ * `runs/` unless it is a single run id.
105
+ */
106
+ export declare function checkFindingMail(project: ResolvedProject, runId: string, mailBase: string, owner?: string): FindingMail;
78
107
  export type EvidenceStrength = "verified" | "weak" | "none";
79
108
  export interface EvidenceCheck {
80
109
  strength: EvidenceStrength;