agent-lyceum 0.44.0 → 0.45.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.
@@ -0,0 +1,29 @@
1
+ /** Who did the work and who reviewed it, written as git trailers at the end of agent-lyceum's commit messages. */
2
+ export declare const VERDICTS: readonly ["pass", "changes_requested", "fail"];
3
+ export type Verdict = (typeof VERDICTS)[number];
4
+ export declare function isVerdict(v: unknown): v is Verdict;
5
+ /** A review a teammate gave in a `reply` that carried `verdict:`. */
6
+ export interface ReviewRecord {
7
+ reviewer: string;
8
+ model?: string;
9
+ verdict: Verdict;
10
+ subject: string;
11
+ at: string;
12
+ }
13
+ export interface WorkerRef {
14
+ agent: string;
15
+ model?: string;
16
+ }
17
+ /** `name (model)`, or just `name` when the model is not known. Newlines are dropped so a value cannot start another trailer. */
18
+ export declare function agentLabel(w: WorkerRef): string;
19
+ /** The latest review per reviewer, in the order they first reviewed. */
20
+ export declare function latestReviews(reviews: readonly ReviewRecord[]): ReviewRecord[];
21
+ /** Trailer block (no leading blank line) for one commit. `Reviewed-by` appears only for reviews that really happened. */
22
+ export declare function trailers(i: {
23
+ implementers?: readonly WorkerRef[];
24
+ lead?: WorkerRef;
25
+ reviews?: readonly ReviewRecord[];
26
+ runId?: string;
27
+ }): string;
28
+ /** `<subject>\n\n<body?>\n\n<trailers>`. */
29
+ export declare function withTrailers(subject: string, body: string | undefined, t: string): string;
@@ -0,0 +1,35 @@
1
+ /** Who did the work and who reviewed it, written as git trailers at the end of agent-lyceum's commit messages. */
2
+ export const VERDICTS = ["pass", "changes_requested", "fail"];
3
+ export function isVerdict(v) {
4
+ return typeof v === "string" && VERDICTS.includes(v);
5
+ }
6
+ /** `name (model)`, or just `name` when the model is not known. Newlines are dropped so a value cannot start another trailer. */
7
+ export function agentLabel(w) {
8
+ const clean = (s) => s.replace(/\s+/g, " ").trim();
9
+ return w.model ? `${clean(w.agent)} (${clean(w.model)})` : clean(w.agent);
10
+ }
11
+ /** The latest review per reviewer, in the order they first reviewed. */
12
+ export function latestReviews(reviews) {
13
+ const byReviewer = new Map();
14
+ for (const r of reviews)
15
+ byReviewer.set(r.reviewer, r);
16
+ return [...byReviewer.values()];
17
+ }
18
+ /** Trailer block (no leading blank line) for one commit. `Reviewed-by` appears only for reviews that really happened. */
19
+ export function trailers(i) {
20
+ const lines = [];
21
+ for (const w of i.implementers ?? [])
22
+ lines.push(`Implemented-by: ${agentLabel(w)}`);
23
+ if (i.lead)
24
+ lines.push(`Led-by: ${agentLabel(i.lead)}`);
25
+ for (const r of latestReviews(i.reviews ?? []))
26
+ lines.push(`Reviewed-by: ${agentLabel({ agent: r.reviewer, model: r.model })} [${r.verdict}]`);
27
+ if (i.runId)
28
+ lines.push(`Run: ${i.runId.replace(/\s+/g, "")}`);
29
+ lines.push("Generated-by: agent-lyceum");
30
+ return lines.join("\n");
31
+ }
32
+ /** `<subject>\n\n<body?>\n\n<trailers>`. */
33
+ export function withTrailers(subject, body, t) {
34
+ return [subject, body?.trim(), t].filter(Boolean).join("\n\n");
35
+ }
package/dist/mailbox.d.ts CHANGED
@@ -3,6 +3,7 @@ import { type Step } from "./format.js";
3
3
  import { atomicWrite } from "./fs-util.js";
4
4
  import { type InstanceCap } from "./instances.js";
5
5
  import type { Tier } from "./schema.js";
6
+ import { type Verdict } from "./attribution.js";
6
7
  import { RouteJournal } from "./message-store.js";
7
8
  export { atomicWrite };
8
9
  export declare const MESSAGE_TYPES: readonly ["task", "reply", "failure", "done", "ask"];
@@ -85,7 +86,8 @@ export interface RouteResult {
85
86
  id: string;
86
87
  file: string;
87
88
  type: MessageType;
88
- subject: string;
89
+ subject: string; /** A reply's `verdict:` (a review result). */
90
+ verdict?: Verdict;
89
91
  }[];
90
92
  rejected: {
91
93
  from: string;
package/dist/mailbox.js CHANGED
@@ -8,6 +8,7 @@ import { atomicWrite, readRegularFileNoFollow } from "./fs-util.js";
8
8
  import { countFormatRejection, formatRejectionKey, formatRejections, MAX_FORMAT_REJECTIONS } from "./format-rejections.js";
9
9
  import { parallelFlag, roleOfName } from "./instances.js";
10
10
  import { effectiveTier, tierFlag } from "./tiers.js";
11
+ import { isVerdict } from "./attribution.js";
11
12
  import { deterministicId, fault, RouteJournal, sourceIdOf } from "./message-store.js";
12
13
  import { inboxDir, outboxDir, sharedDir } from "./policy.js";
13
14
  import { activeRecordsBytes, RECORD_KINDS, RECORDS_BUDGET } from "./records.js";
@@ -295,6 +296,15 @@ export function routeOutboxes(project, routing) {
295
296
  continue;
296
297
  }
297
298
  const subject = String(d.subject ?? "(no subject)");
299
+ // `verdict` is how a reviewer's result is recorded (it ends up as a `Reviewed-by` trailer); it is only meaningful on a reply.
300
+ let verdict;
301
+ if (d.verdict !== undefined && d.verdict !== null && d.verdict !== "") {
302
+ if (!isVerdict(d.verdict) || type !== "reply") {
303
+ reject(`verdict must be pass, changes_requested or fail, and only a \`reply\` carries one (got ${JSON.stringify(d.verdict)} on a ${type}). Leave the line out if you did not review anything.`);
304
+ continue;
305
+ }
306
+ verdict = d.verdict;
307
+ }
298
308
  if (type === "ask") {
299
309
  if (!sender.canAskUser) {
300
310
  reject(`you may not ask the user directly (can_ask_user is off for "${sender.name}"). Put the question in a reply to the lead ("${project.lead}"), who can ask.`);
@@ -310,7 +320,7 @@ export function routeOutboxes(project, routing) {
310
320
  }
311
321
  const over = RECORD_KINDS.map((k) => ({ k, n: activeRecordsBytes(project, k) })).filter((x) => x.n > RECORDS_BUDGET);
312
322
  if (over.length) {
313
- reject(`${over.map((x) => `records/${x.k} hold ${x.n} bytes of active entries`).join(" and ")}; the budget is ${RECORDS_BUDGET} bytes (6 KB) per kind. Merge entries, or mark obsolete ones "status: superseded" (or name them in a newer entry's "supersedes"), then send "done" again.`);
323
+ reject(`${over.map((x) => `records/${x.k} hold ${x.n} bytes of active entries`).join(" and ")}; the budget is ${RECORDS_BUDGET} bytes (${RECORDS_BUDGET / 1024} KB) per kind. Merge entries, or mark obsolete ones "status: superseded" (or name them in a newer entry's "supersedes"), then send "done" again.`);
314
324
  continue;
315
325
  }
316
326
  res.done = { from: sender.name, subject, body: parsed.body, file, meta: d };
@@ -438,7 +448,7 @@ export function routeOutboxes(project, routing) {
438
448
  });
439
449
  if (!fresh)
440
450
  continue;
441
- res.delivered.push({ from: sender.name, to, id: msg.meta.id, file: msg.file, type, subject });
451
+ res.delivered.push({ from: sender.name, to, id: msg.meta.id, file: msg.file, type, subject, ...(verdict ? { verdict } : {}) });
442
452
  if (missing.length)
443
453
  res.warnings.push({ from: sender.name, id: msg.meta.id, subject, missing });
444
454
  }
package/dist/prompt.js CHANGED
@@ -180,7 +180,7 @@ export function buildSystemPrompt(project, agent) {
180
180
  ? [
181
181
  `That directory is your own isolated git worktree (branch \`${project.workspaces?.[agent.name]?.branch}\`): teammates cannot see your changes while you work, and you cannot see theirs. Do not commit, push, switch branches or touch any other checkout; the dispatcher collects your changes from this directory after you finish.`,
182
182
  ]
183
- : []), `The team lead is **${project.lead}**${isLead ? " (that is you)" : ""}. Teammates: ${mates.join(", ") || "(none)"}.`, "", "## Sending mail", "You cannot talk to teammates directly. Mail you receive is shown in your prompt. To send mail, create a Markdown file", `(any name ending in \`.md\`) directly inside \`${outbox}\` with this exact shape:`, "", "```", "---", "to: <agent-name>", `type: reply # task | reply${agent.canAskUser ? " | ask" : ""}${isLead ? " | done" : ""}`, "subject: <short subject>", "reply_to: <message id> # optional", "---", "", "<body>", "```", "", `You may send to: ${recipients.join(", ") || "(nobody)"}.`, isLead
183
+ : []), `The team lead is **${project.lead}**${isLead ? " (that is you)" : ""}. Teammates: ${mates.join(", ") || "(none)"}.`, "", "## Sending mail", "You cannot talk to teammates directly. Mail you receive is shown in your prompt. To send mail, create a Markdown file", `(any name ending in \`.md\`) directly inside \`${outbox}\` with this exact shape:`, "", "```", "---", "to: <agent-name>", `type: reply # task | reply${agent.canAskUser ? " | ask" : ""}${isLead ? " | done" : ""}`, "subject: <short subject>", "reply_to: <message id> # optional", "verdict: pass | changes_requested | fail # optional; only in a reply that reviews someone's work, it is recorded as `Reviewed-by` in the commit", "---", "", "<body>", "```", "", `You may send to: ${recipients.join(", ") || "(nobody)"}.`, isLead
184
184
  ? `When the whole job is finished, send a message with \`type: done\` (no \`to\` needed). That ends the run. A summary in your reply text is never delivered and does not end the run: after the last teammate reply is verified you MUST send \`done\` (or a \`task\` for the remaining work), or the run stops as "idle" with no final report.`
185
185
  : `Report results to the lead by mail; the lead decides what happens next.`, isLead
186
186
  ? "Each wake-up handles one message, except that several `reply`/`failure` messages waiting together are handed to you in one wake-up: weigh them together, then decide the next step once."
package/dist/records.js CHANGED
@@ -5,7 +5,7 @@ import { readRegularFileNoFollow } from "./fs-util.js";
5
5
  import { recordsDir, recordsKindDir } from "./policy.js";
6
6
  export const RECORD_KINDS = ["decisions", "lessons"];
7
7
  /** Cap of one kind's effective-active entries in a prompt (and, for `done`, the most they may add up to). */
8
- export const RECORDS_BUDGET = 6 * 1024;
8
+ export const RECORDS_BUDGET = 12 * 1024;
9
9
  const ID_RE = /^[a-z0-9-]+$/;
10
10
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
11
11
  function parseEntry(kind, file) {
@@ -171,6 +171,8 @@ export declare class RunSession {
171
171
  * A finished member's files go from its worktree into the repo before anyone reads its mail, so the lead
172
172
  * sees them. When that cannot be done, nothing is applied, the member's work stays on its branch, and the lead is told.
173
173
  */
174
+ /** The agent and the model it last ran on (a tier or fallback shows in `last_wake`), else its configured model. */
175
+ private workerRef;
174
176
  private integrateMember;
175
177
  /** A member whose worktree was refused: it is not woken again in this run, and the lead is told so it can react. */
176
178
  private refuseMember;
@@ -19,6 +19,7 @@ import { inboxDir, outboxDir, 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";
22
+ import { trailers, withTrailers } from "./attribution.js";
22
23
  import { assertWorktreeRunnable, collectAgentChanges, dirtyPaths, existingAgentWorkspace, finishLeadBranch, integrateAgentChanges, prepareAgentWorkspace, recutLeadWorkspace, refusedIntegration, snapshotBase, snapshotHead, toplevel } from "./worktree.js";
23
24
  import { workingTreeHash } from "./worktree.js";
24
25
  import { bindRunProject, newRunId, newRunState, roundLimit, roundsLabel, saveRunState } from "./run-store.js";
@@ -865,12 +866,18 @@ export class RunSession {
865
866
  * A finished member's files go from its worktree into the repo before anyone reads its mail, so the lead
866
867
  * sees them. When that cannot be done, nothing is applied, the member's work stays on its branch, and the lead is told.
867
868
  */
869
+ /** The agent and the model it last ran on (a tier or fallback shows in `last_wake`), else its configured model. */
870
+ workerRef(agent) {
871
+ const model = this.state.last_wake[agent.name]?.model ?? agent.model;
872
+ return { agent: agent.name, ...(model ? { model } : {}) };
873
+ }
868
874
  integrateMember(agent, ws, key) {
869
875
  const { say, project, log, state } = this;
870
876
  let changes;
871
877
  let r;
872
878
  try {
873
- changes = collectAgentChanges(ws);
879
+ const who = this.workerRef(agent);
880
+ changes = collectAgentChanges(ws, withTrailers(`agent-lyceum: changes by ${agent.name}`, undefined, trailers({ implementers: [who], runId: this.runId })));
874
881
  r = integrateAgentChanges(project, changes, this.leadSpace);
875
882
  }
876
883
  catch (e) {
@@ -881,6 +888,10 @@ export class RunSession {
881
888
  const blocked = (state.blocked_integrations ?? []).filter((b) => b.agent !== agent.name);
882
889
  if (r.status === "integrated") {
883
890
  state.blocked_integrations = blocked;
891
+ if (r.files.length) {
892
+ const who = this.workerRef(agent);
893
+ state.implementers = [...(state.implementers ?? []).filter((w) => w.agent !== who.agent), who];
894
+ }
884
895
  if (r.files.length)
885
896
  say(` ${agent.name}: ${r.files.length} changed file(s) brought into the repo`);
886
897
  return;
@@ -945,6 +956,12 @@ export class RunSession {
945
956
  this.integrateMember(a, ws, claims.get(a.name)?.id ?? `${a.name}-${state.rounds}`);
946
957
  });
947
958
  const route = routeOutboxes(project, this.routing());
959
+ for (const m of route.delivered) {
960
+ const a = m.verdict ? (project.agents[m.from] ?? project.agents[roleOfName(project.agents, m.from)]) : undefined;
961
+ if (!m.verdict || !a)
962
+ continue;
963
+ state.reviews = [...(state.reviews ?? []), { reviewer: a.name, ...(this.workerRef(a).model ? { model: this.workerRef(a).model } : {}), verdict: m.verdict, subject: m.subject, at: new Date().toISOString() }];
964
+ }
948
965
  // A done that breaks the completion contract goes back to the lead (a limited number of times).
949
966
  let contract;
950
967
  if (route.done) {
@@ -1224,7 +1241,9 @@ export class RunSession {
1224
1241
  if (!this.leadSpace || endReason === "waiting")
1225
1242
  return undefined;
1226
1243
  try {
1227
- const rb = finishLeadBranch(this.leadSpace, `agent-lyceum: ${project.lead}'s work for run ${runId}\n\n${state.task_summary}`, path.join(runDir, "lead.patch"));
1244
+ const lead = project.agents[project.lead];
1245
+ const message = withTrailers(`agent-lyceum: ${project.lead}'s work for run ${runId}`, state.task_summary, trailers({ implementers: state.implementers, lead: lead ? this.workerRef(lead) : undefined, reviews: state.reviews, runId }));
1246
+ const rb = finishLeadBranch(this.leadSpace, message, path.join(runDir, "lead.patch"));
1228
1247
  state.result_branch = rb;
1229
1248
  log("lead-branch", { ...rb });
1230
1249
  say(rb.files ? ` work is on branch ${rb.branch} (${rb.files} file(s)); bring it into your repo with: git merge ${rb.branch}` : ` ${rb.branch}: no file changes`);
@@ -2,6 +2,7 @@ import type { ResolvedProject } from "./config.js";
2
2
  import type { DigestSection, Step } from "./format.js";
3
3
  import { type ErrorKind, type Runtime, type RunOutcome, type Tier } from "./schema.js";
4
4
  import type { ResultBranch } from "./worktree.js";
5
+ import type { ReviewRecord, WorkerRef } from "./attribution.js";
5
6
  export declare const STATE_FILE = "state.json";
6
7
  /** The newest state format this version reads. */
7
8
  export declare const STATE_SCHEMA_VERSION = 3;
@@ -140,6 +141,10 @@ export interface RunState {
140
141
  result_branch?: ResultBranch;
141
142
  /** Set when the run started with the lead in its own worktree (isolation mode); its resumes keep that, whatever the config says later. */
142
143
  lead_workspace?: true;
144
+ /** Reviews given in this run (a reply's `verdict:`), oldest first; written into the lead's commit as `Reviewed-by`. */
145
+ reviews?: ReviewRecord[];
146
+ /** Members whose files were brought into the repo, with the model they last ran on; written into the lead's commit as `Implemented-by`. */
147
+ implementers?: WorkerRef[];
143
148
  /** The pull request the dispatcher opened for this run (when the lead asked for one and it worked). */
144
149
  pr_url?: string;
145
150
  sessions: Record<string, string>;
package/dist/run-store.js CHANGED
@@ -68,6 +68,8 @@ const WireState = z
68
68
  active: z.record(z.string(), z.any()).optional(),
69
69
  wakes: z.array(z.any()).optional(),
70
70
  solo_agent: z.string().optional(),
71
+ reviews: z.array(z.any()).optional(),
72
+ implementers: z.array(z.any()).optional(),
71
73
  steps: z.array(z.object({ text: z.string(), done: z.boolean() })).optional(),
72
74
  failure: z
73
75
  .object({
package/dist/scaffold.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { assertName, homePaths, projectPaths } from "./paths.js";
4
+ import { RECORDS_BUDGET } from "./records.js";
4
5
  /** The lead's guidance on `parallel: true` (spec 23.12 point 5). Only `init` writes it, into a new lead AGENT.md. */
5
6
  export const LEAD_PARALLEL_HINT = "Mark a task `parallel: true` only when it is independent and touches different files from the other open tasks; list each task's files in `## Scope` first; shared components, types, routes and tokens go first, alone.";
6
7
  /** The lead's guidance on the `## Decisions` and `## Not done` sections of `done`. Only `init` writes it, into a new lead AGENT.md. */
@@ -11,7 +12,7 @@ const PERSONAS = {
11
12
  You coordinate the team. You receive the user's task, break it into concrete pieces, and delegate each piece to the right teammate by mail.
12
13
 
13
14
  - Keep \`COMMON.md\` (shared team context: goal, conventions) accurate and short.
14
- - Before you send \`done\`, record what was decided and why as decision entries, and what the project learned as lesson entries, in the records folders named in your rules (one file per entry, with frontmatter); mark outdated entries \`superseded\`. Later runs start from the effective-active ones (about 6 KB per kind).
15
+ - Before you send \`done\`, record what was decided and why as decision entries, and what the project learned as lesson entries, in the records folders named in your rules (one file per entry, with frontmatter); mark outdated entries \`superseded\`. Later runs start from the effective-active ones (about ${RECORDS_BUDGET / 1024} KB per kind).
15
16
  - Write every task with the standard task headings, and cite the mail it derives from under Upstream so teammates can trace it.
16
17
  - When a teammate reports back, decide the next step: assign follow-up work, ask another teammate to verify, or accept the result.
17
18
  - Teammates cannot message each other by default; route everything through yourself.
@@ -126,7 +126,7 @@ export declare function commitWorkspace(ws: AgentWorkspace, message: string): {
126
126
  * changed path (modified, added, deleted, or either end of a rename) against the project
127
127
  * folder, the protected instruction files, and symlink/submodule rules. Nothing is applied here.
128
128
  */
129
- export declare function collectAgentChanges(workspace: AgentWorkspace): ChangeSet;
129
+ export declare function collectAgentChanges(workspace: AgentWorkspace, message?: string): ChangeSet;
130
130
  export type IntegrationResult = {
131
131
  status: "integrated";
132
132
  files: ChangedFile[];
package/dist/worktree.js CHANGED
@@ -524,8 +524,8 @@ export function commitWorkspace(ws, message) {
524
524
  * changed path (modified, added, deleted, or either end of a rename) against the project
525
525
  * folder, the protected instruction files, and symlink/submodule rules. Nothing is applied here.
526
526
  */
527
- export function collectAgentChanges(workspace) {
528
- const { head } = commitWorkspace(workspace, `agent-lyceum: changes by ${workspace.agent}`);
527
+ export function collectAgentChanges(workspace, message) {
528
+ const { head } = commitWorkspace(workspace, (typeof message === "string" && message ? message : `agent-lyceum: changes by ${workspace.agent}`));
529
529
  const base = workspace.base;
530
530
  const raw = base === head ? "" : agentGit(workspace, ["diff", "--raw", "-z", "--no-renames", "--no-abbrev", base, head]);
531
531
  const parts = raw.split("\0").filter(Boolean);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-lyceum",
3
- "version": "0.44.0",
3
+ "version": "0.45.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",