agent-lyceum 0.56.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.
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;
package/dist/proposals.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { parse as parseYaml } from "yaml";
4
+ import { isVerdict } from "./attribution.js";
5
+ import { parseSlotName } from "./instances.js";
4
6
  import { readRegularFileNoFollow } from "./fs-util.js";
5
- import { proposalsKindDir, recordsDir, recordsKindDir } from "./policy.js";
7
+ import { proposalsKindDir, recordsDir, recordsKindDir, reviewerNames } from "./policy.js";
6
8
  import { RECORD_KINDS } from "./records.js";
7
9
  import { git, isGitRepo } from "./worktree.js";
8
10
  export const PROPOSAL_KINDS = RECORD_KINDS;
@@ -13,6 +15,8 @@ export const PENDING_SHOWN = 10;
13
15
  const ID_RE = /^[a-z0-9-]+$/;
14
16
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
15
17
  const SHA_RE = /^[0-9a-f]{7,40}$/;
18
+ /** A run id is a timestamp, a hyphen, then lowercase letters or digits (`newRunId`). Nothing else is joined onto `runs/`. */
19
+ const RUN_ID_RE = /^\d{8}T\d+Z-[a-z0-9]+$/;
16
20
  /** The part of a run or call id that is unique: its first 8 lowercase letters or digits after the timestamp (D-10). */
17
21
  export function shortIdOf(runId) {
18
22
  const rest = runId.includes("-") ? runId.slice(runId.indexOf("-") + 1) : runId;
@@ -34,6 +38,37 @@ export function proposalStatusOf(buf) {
34
38
  }
35
39
  /** The id's own prefix: what comes before the first `-`. */
36
40
  export const prefixOf = (id) => id.split("-")[0] ?? "";
41
+ export { isReviewer, reviewerNames } from "./policy.js";
42
+ /** A run id (`newRunId`): timestamp, hyphen, then lowercase letters or digits. Solo proposals are not held to this. */
43
+ export const isRunId = (value) => RUN_ID_RE.test(value);
44
+ /**
45
+ * The reviewer a team file name belongs to. `id` is the file name without `.md`: `<8 lowercase letters or digits>-<agent>-<slug>`.
46
+ * When one reviewer name is a prefix of another (`cli-reviewer` and `cli-reviewer--2`), the longer name wins. A `<role>--<k>-<slug>`
47
+ * 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.
48
+ */
49
+ export function proposalOwner(id, names) {
50
+ const rest = /^[a-z0-9]{8}-(.+)$/.exec(id)?.[1];
51
+ if (!rest)
52
+ return undefined;
53
+ // `<role>--<k>-<slug>` belongs to that slot when the role is a reviewer, even if the slot is not in `names` (a later run, or doctor, has no instance table).
54
+ const slot = /^(.+--(?:[2-9]|[1-9]\d+))-([a-z0-9][a-z0-9-]*)$/.exec(rest);
55
+ if (slot?.[1] && slot[2]) {
56
+ const parsed = parseSlotName(slot[1]);
57
+ if (parsed && (names.includes(parsed.role) || names.includes(slot[1])))
58
+ return slot[1];
59
+ }
60
+ let best;
61
+ for (const name of names) {
62
+ if ((rest === name || rest.startsWith(`${name}-`)) && (best === undefined || name.length > best.length))
63
+ best = name;
64
+ }
65
+ if (!best || !rest.startsWith(`${best}-`) || rest.length === best.length + 1)
66
+ return undefined;
67
+ const slug = rest.slice(best.length + 1);
68
+ if (slug.startsWith("-") || !/^[a-z0-9-]+$/.test(slug))
69
+ return undefined;
70
+ return best;
71
+ }
37
72
  const isoDate = (v) => {
38
73
  // YAML parses an unquoted 2026-01-02 as a Date.
39
74
  const d = v instanceof Date ? v.toISOString().slice(0, 10) : v;
@@ -68,9 +103,37 @@ function parseEvidenceItem(item) {
68
103
  }
69
104
  return `unknown evidence kind "${key}"`;
70
105
  }
106
+ /** The evidence value as written, for the verbatim copy a record must carry. */
107
+ function evidenceRaw(item) {
108
+ if (!item || typeof item !== "object" || Array.isArray(item))
109
+ return undefined;
110
+ const keys = Object.keys(item);
111
+ if (keys.length !== 1)
112
+ return undefined;
113
+ const val = item[keys[0]];
114
+ return typeof val === "string" && val.trim() ? val.trim() : undefined;
115
+ }
116
+ /** `finding` is optional. A bad severity is still stored, so doctor can name `minor` or `nit`. */
117
+ function parseFinding(v, problems) {
118
+ if (!v || typeof v !== "object" || Array.isArray(v)) {
119
+ problems.push("finding must be a mapping");
120
+ return undefined;
121
+ }
122
+ const f = v;
123
+ const mail = oneLine(f.mail);
124
+ const severity = oneLine(f.severity);
125
+ const className = oneLine(f.class);
126
+ if (!mail || /[\\/]/.test(mail) || mail.includes(".."))
127
+ problems.push("finding.mail must be a file name");
128
+ if (!severity || (severity !== "blocker" && severity !== "major"))
129
+ problems.push("finding.severity must be blocker or major");
130
+ if (!className)
131
+ problems.push("finding.class must be one non-empty line");
132
+ return { mail: mail ?? "", severity: severity ?? "", className: className ?? "" };
133
+ }
71
134
  export function parseProposal(kind, file) {
72
135
  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: [] };
136
+ const base = { kind, id, file, date: "", title: path.basename(file), proposedBy: "", run: "", evidence: [], evidenceText: [], supersedes: [], body: "", bytes: 0, problems: [] };
74
137
  // Never open a symlink or a FIFO/device (spec 30, acceptance 11).
75
138
  const buf = readRegularFileNoFollow(file);
76
139
  if (!buf)
@@ -112,6 +175,7 @@ export function parseProposal(kind, file) {
112
175
  if (!run)
113
176
  problems.push("run is required");
114
177
  const evidence = [];
178
+ const evidenceText = [];
115
179
  if (!Array.isArray(f.evidence) || f.evidence.length === 0)
116
180
  problems.push("evidence is required: at least one entry");
117
181
  else
@@ -119,9 +183,14 @@ export function parseProposal(kind, file) {
119
183
  const e = parseEvidenceItem(item);
120
184
  if (typeof e === "string")
121
185
  problems.push(e);
122
- else
186
+ else {
123
187
  evidence.push(e);
188
+ const raw = evidenceRaw(item);
189
+ if (raw)
190
+ evidenceText.push(raw);
191
+ }
124
192
  }
193
+ const finding = f.finding === undefined ? undefined : parseFinding(f.finding, problems);
125
194
  let supersedes = [];
126
195
  if (f.supersedes !== undefined) {
127
196
  if (Array.isArray(f.supersedes) && f.supersedes.every((x) => typeof x === "string"))
@@ -145,6 +214,8 @@ export function parseProposal(kind, file) {
145
214
  proposedBy: proposedBy ?? "",
146
215
  run: run ?? "",
147
216
  evidence,
217
+ evidenceText,
218
+ ...(finding ? { finding } : {}),
148
219
  ...(repo && path.isAbsolute(repo) ? { repo } : {}),
149
220
  ...(oneLine(f.scope) ? { scope: oneLine(f.scope) } : {}),
150
221
  supersedes,
@@ -201,22 +272,46 @@ export function describeProposals(project) {
201
272
  lines.push(` problem ${d.file}: ${d.problem}`);
202
273
  return lines;
203
274
  }
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) {
275
+ /** The live or archived file for `<kind>/<id>`, if one exists. */
276
+ function recordFile(project, ref) {
206
277
  const m = /^(decisions|lessons)\/([a-z0-9-]+)$/.exec(ref);
207
278
  if (!m)
208
- return false;
279
+ return undefined;
209
280
  const kind = m[1];
210
281
  const id = m[2];
211
- if (fs.existsSync(path.join(recordsKindDir(project, kind), `${id}.md`)))
212
- return true;
282
+ const live = path.join(recordsKindDir(project, kind), `${id}.md`);
283
+ if (fs.existsSync(live))
284
+ return live;
213
285
  const archive = path.join(recordsDir(project), ".archive");
214
286
  try {
215
- return fs.readdirSync(archive).some((stamp) => fs.existsSync(path.join(archive, stamp, kind, `${id}.md`)));
287
+ for (const stamp of fs.readdirSync(archive)) {
288
+ const file = path.join(archive, stamp, kind, `${id}.md`);
289
+ if (fs.existsSync(file))
290
+ return file;
291
+ }
216
292
  }
217
293
  catch {
218
- return false;
294
+ // no archive
219
295
  }
296
+ return undefined;
297
+ }
298
+ /** Whether `<kind>/<id>` is a record of the project, live or archived by a tidy (`.archive/<stamp>/<kind>/<id>.md`). */
299
+ const recordExists = (project, ref) => recordFile(project, ref) !== undefined;
300
+ /** Body after the frontmatter. A file that is not a regular file counts as empty, so a symlink is never treated as a copy. */
301
+ function recordBody(project, ref) {
302
+ const file = recordFile(project, ref);
303
+ const buf = file ? readRegularFileNoFollow(file) : undefined;
304
+ if (!buf)
305
+ return "";
306
+ const text = buf.toString("utf8");
307
+ const m = /^---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n([\s\S]*))?$/.exec(text);
308
+ return m ? (m[1] ?? "") : text;
309
+ }
310
+ const hasEvidenceHeading = (body) => body.split(/\r?\n/).some((line) => line.trim() === "## Evidence");
311
+ function copiesFinding(body, p) {
312
+ if (!p.finding)
313
+ return false;
314
+ return [...p.evidenceText, p.finding.mail, p.finding.severity, p.finding.className].every((bit) => bit !== "" && body.includes(bit));
220
315
  }
221
316
  /**
222
317
  * Layer 1 of D-09: the lead's decisions are complete. Only decided proposals are looked at. An `accepted` one must be a
@@ -245,10 +340,187 @@ export function checkDecisions(proposals, project) {
245
340
  add(p, `accepted_as ${p.acceptedAs} is not a record of the project`);
246
341
  if (!p.decided)
247
342
  add(p, "accepted without decided (YYYY-MM-DD)");
343
+ const owner = proposalOwner(p.id, reviewerNames(project));
344
+ if (owner)
345
+ addReviewerAcceptance(p, project, owner, add);
248
346
  }
249
347
  }
250
348
  return out;
251
349
  }
350
+ /** Extra acceptance rules for a file a reviewer owns (issue 177). A solo file has no owner, so spec 30 is unchanged. */
351
+ function addReviewerAcceptance(p, project, owner, add) {
352
+ if (!isRunId(p.run))
353
+ add(p, "accepted but run must be a run id");
354
+ if (!p.finding)
355
+ add(p, "accepted but finding is required");
356
+ else if (p.finding.mail && !/[\\/]/.test(p.finding.mail) && !p.finding.mail.includes("..")) {
357
+ const mail = checkFindingMail(project, p.run, p.finding.mail, owner);
358
+ if (mail === "missing")
359
+ add(p, "accepted but finding.mail was not found");
360
+ else if (mail === "not-a-verdict-reply")
361
+ add(p, "accepted but finding.mail is not a reply with verdict");
362
+ }
363
+ if (p.proposedBy !== owner)
364
+ add(p, "accepted but proposed_by does not match the file name");
365
+ if (checkEvidence(p, project.dir).strength !== "verified")
366
+ add(p, "accepted but evidence is not verified");
367
+ if (!p.acceptedAs || !recordExists(project, p.acceptedAs))
368
+ return;
369
+ const body = recordBody(project, p.acceptedAs);
370
+ if (!hasEvidenceHeading(body))
371
+ add(p, "accepted but the record has no ## Evidence section");
372
+ else if (!copiesFinding(body, p))
373
+ add(p, "accepted but the record does not copy the evidence and finding");
374
+ }
375
+ /** A real directory, never a symlink. */
376
+ function realRunDir(dir) {
377
+ try {
378
+ const st = fs.lstatSync(dir);
379
+ return st.isDirectory() && !st.isSymbolicLink();
380
+ }
381
+ catch {
382
+ return false;
383
+ }
384
+ }
385
+ /**
386
+ * The run directory whose mail can be checked. `claimedRun` is used only when it is a run id whose short id matches and whose
387
+ * directory is still there. Otherwise the directory is the one under `runs/` with that short id, so a short id or a missing
388
+ * claimed directory cannot skip the check while the run still exists. No such directory means the run was cleared: `skip`.
389
+ * Several directories with the same short id, and none of them the claimed id, is `ambiguous` (checked as missing, never skipped).
390
+ */
391
+ function resolveFindingRunDir(project, claimedRun, shortId) {
392
+ const root = project.paths.runs;
393
+ if (RUN_ID_RE.test(claimedRun) && shortIdOf(claimedRun) === shortId) {
394
+ const claimed = path.join(root, claimedRun);
395
+ if (realRunDir(claimed) && fs.existsSync(path.join(claimed, "state.json")))
396
+ return claimed;
397
+ }
398
+ let names;
399
+ try {
400
+ names = fs.readdirSync(root);
401
+ }
402
+ catch {
403
+ return "skip";
404
+ }
405
+ const matches = [];
406
+ for (const name of names) {
407
+ if (!RUN_ID_RE.test(name) || shortIdOf(name) !== shortId)
408
+ continue;
409
+ const dir = path.join(root, name);
410
+ if (realRunDir(dir) && fs.existsSync(path.join(dir, "state.json")))
411
+ matches.push(dir);
412
+ }
413
+ if (matches.length === 1)
414
+ return matches[0];
415
+ if (matches.length === 0)
416
+ return "skip";
417
+ return "ambiguous";
418
+ }
419
+ /**
420
+ * Whether `mailBase` is one reply carrying `verdict:` under the run's mail. The file name is the one the reviewer wrote in
421
+ * their outbox: after routing, `sent/<name>` wins over a rejected copy of the same name, and over every other agent's outbox.
422
+ * A delivered copy (a different file name) is looked up in inboxes, including `pending/`. No run directory left, or `mail_layout`
423
+ * other than `run`, means the mail cannot be checked any more: that is `skip`, not a failure. `runId` is never joined onto
424
+ * `runs/` unless it is a single run id.
425
+ */
426
+ export function checkFindingMail(project, runId, mailBase, owner) {
427
+ if (!mailBase || /[\\/]/.test(mailBase) || mailBase.includes(".."))
428
+ return "missing";
429
+ const resolved = resolveFindingRunDir(project, runId, shortIdOf(runId));
430
+ if (resolved === "skip")
431
+ return "skip";
432
+ if (resolved === "ambiguous")
433
+ return "missing";
434
+ const runDir = resolved;
435
+ const stateFile = path.join(runDir, "state.json");
436
+ if (!fs.existsSync(stateFile))
437
+ return "skip";
438
+ let layout;
439
+ try {
440
+ layout = JSON.parse(fs.readFileSync(stateFile, "utf8")).mail_layout;
441
+ }
442
+ catch {
443
+ return "skip";
444
+ }
445
+ if (layout !== "run")
446
+ return "skip";
447
+ const file = locateFindingMail(runDir, mailBase, owner);
448
+ if (!file)
449
+ return "missing";
450
+ const buf = readRegularFileNoFollow(file);
451
+ if (!buf)
452
+ return "missing";
453
+ return isVerdictReply(buf.toString("utf8")) ? "ok" : "not-a-verdict-reply";
454
+ }
455
+ function isRegularFile(file) {
456
+ try {
457
+ return fs.lstatSync(file).isFile();
458
+ }
459
+ catch {
460
+ return false;
461
+ }
462
+ }
463
+ /**
464
+ * The owner's `sent/` copy is the one that was routed. A same-named file in `rejected/`, or in another agent's outbox, does not count beside it.
465
+ * Without an outbox copy, one inbox file (including `read/` and `pending/`) is the delivered name.
466
+ */
467
+ function locateFindingMail(runDir, mailBase, owner) {
468
+ if (owner && !/[\\/]/.test(owner) && !owner.includes("..")) {
469
+ const base = path.join(runDir, "mail", "outbox", owner);
470
+ const sent = path.join(base, "sent", mailBase);
471
+ if (isRegularFile(sent))
472
+ return sent;
473
+ const live = [path.join(base, mailBase), path.join(base, "read", mailBase)].filter(isRegularFile);
474
+ if (live.length > 1)
475
+ return undefined;
476
+ if (live.length === 1)
477
+ return live[0];
478
+ const rejected = path.join(base, "rejected", mailBase);
479
+ if (isRegularFile(rejected))
480
+ return rejected;
481
+ }
482
+ const hits = [];
483
+ const root = path.join(runDir, "mail", "inbox");
484
+ let agents;
485
+ try {
486
+ agents = fs.readdirSync(root).filter((name) => {
487
+ try {
488
+ const st = fs.lstatSync(path.join(root, name));
489
+ return st.isDirectory() && !st.isSymbolicLink();
490
+ }
491
+ catch {
492
+ return false;
493
+ }
494
+ });
495
+ }
496
+ catch {
497
+ return undefined;
498
+ }
499
+ for (const agent of agents) {
500
+ for (const dir of [path.join(root, agent), path.join(root, agent, "read"), path.join(root, agent, "pending")]) {
501
+ const file = path.join(dir, mailBase);
502
+ if (isRegularFile(file))
503
+ hits.push(file);
504
+ }
505
+ }
506
+ return hits.length === 1 ? hits[0] : undefined;
507
+ }
508
+ /** A reply (type omitted counts as reply, the same as the mailbox) whose `verdict` is one of the three review results. */
509
+ function isVerdictReply(text) {
510
+ const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
511
+ if (!m)
512
+ return false;
513
+ try {
514
+ const fm = parseYaml(m[1]);
515
+ if (!fm || typeof fm !== "object" || Array.isArray(fm))
516
+ return false;
517
+ const type = fm.type ?? "reply";
518
+ return type === "reply" && isVerdict(fm.verdict);
519
+ }
520
+ catch {
521
+ return false;
522
+ }
523
+ }
252
524
  const tryGit = (cwd, args) => {
253
525
  try {
254
526
  return git(cwd, args);
@@ -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 { otherCallPrefixes, ProtectedGuard, runsStartedAfter } from "./guard.js";
9
+ import { otherCallPrefixes, proposalForeignPrefixes, 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";
@@ -19,7 +19,7 @@ import { crossRuntimeBlock } from "./review-gate.js";
19
19
  import { unboundCommands } from "./task-bind.js";
20
20
  import { capBatch, DEFAULT_MAX_AWAKE } from "./wake-cap.js";
21
21
  import { wakeIsReadOnly } from "./playbook.js";
22
- import { coordinatePolicy, inboxDir, osSandboxAvailable, outboxDir, proposalsDir, readOnlyPolicy, sharedIndex } from "./policy.js";
22
+ import { coordinatePolicy, ensureReviewerProposalDir, inboxDir, osSandboxAvailable, outboxDir, proposalsDir, readOnlyPolicy, sharedIndex } from "./policy.js";
23
23
  import { buildSystemPrompt, buildUserPrompt, pickMessages } from "./prompt.js";
24
24
  import { collectDrafts, priorFailedAttempts, redoUserPrompt } from "./redo.js";
25
25
  import { atomicWrite, readFileCapped } from "./fs-util.js";
@@ -238,6 +238,8 @@ export class RunSession {
238
238
  // The agent of `run --agent` writes its proposals here; runtimes only get a directory that exists (spec 30, D-18).
239
239
  if (project.solo === "run")
240
240
  fs.mkdirSync(proposalsDir(project), { recursive: true });
241
+ else
242
+ ensureReviewerProposalDir(project);
241
243
  fs.mkdirSync(runDir, { recursive: true });
242
244
  const log = createRunLog(path.join(runDir, "log.jsonl"), cfg.log_max_bytes);
243
245
  if (concurrent && !resume) {
@@ -324,7 +326,10 @@ export class RunSession {
324
326
  // 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).
325
327
  const otherLiveRuns = () => listRunLocks(project.paths.root).filter((l) => !l.call && l.run_id !== runId && lockHolderAlive(l)).map((l) => l.run_id);
326
328
  // 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.
327
- const guardOpts = project.solo ? { startedAfter: (stamp) => runsStartedAfter(project.paths.runs, stamp, runId), otherPrefixes: otherCallPrefixes(project.home, project.paths.root, runId) } : {};
329
+ // A normal run does not feed those runs into `other` (that would keep every proposal change). It only leaves their proposal prefixes alone.
330
+ const guardOpts = project.solo
331
+ ? { startedAfter: (stamp) => runsStartedAfter(project.paths.runs, stamp, runId), otherPrefixes: otherCallPrefixes(project.home, project.paths.root, runId) }
332
+ : { otherPrefixes: proposalForeignPrefixes(project.home, project.paths.root, project.paths.runs, runId) };
328
333
  const guard = new ProtectedGuard(leadSpace ? { ...project, workspaces: { ...project.workspaces, [project.lead]: leadSpace } } : project, otherLiveRuns, guardOpts);
329
334
  if (resume) {
330
335
  log("resume", { rounds: state.rounds, interrupted: Object.keys(resume.active ?? {}) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-lyceum",
3
- "version": "0.56.0",
3
+ "version": "0.57.0",
4
4
  "description": "Config + dispatcher for teams of Claude Code / Codex agents with scoped context and file-based mailboxes",
5
5
  "keywords": [
6
6
  "ai",