agent-lyceum 0.37.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/format.d.ts CHANGED
@@ -24,14 +24,17 @@ export interface DoneContract {
24
24
  outcome?: RunOutcome;
25
25
  /** What the report lacks; empty when the contract is met. */
26
26
  missing: string[];
27
+ /** Advisory only: sections a `completed` report should carry but that never reject it. */
28
+ warnings: string[];
27
29
  /** First lines of `## Verification`, for display. */
28
30
  verification?: string;
29
31
  }
30
32
  /**
31
33
  * The completion contract of a `done` report: frontmatter `outcome`, and `## Result` and `## Not done`;
32
- * a `completed` report must also carry `## Files` and `## Verification` and leave no checklist step unticked
34
+ * a `completed` report must also carry `## Files`, `## Verification` and `## Decisions` and leave no checklist step unticked
33
35
  * (the report's own `## Steps`, else the run's latest `stateSteps`).
34
36
  */
37
+ export declare const ADVISORY_DONE_SECTIONS: readonly ["Spot-check", "Quiz"];
35
38
  export declare function doneContract(meta: Record<string, unknown>, body: string, stateSteps?: Step[]): DoneContract;
36
39
  export interface DigestSection {
37
40
  label: string;
package/dist/format.js CHANGED
@@ -77,21 +77,26 @@ export function sectionText(body, name) {
77
77
  export const DECLARABLE_OUTCOMES = ["completed", "partial", "blocked", "failed"];
78
78
  /**
79
79
  * The completion contract of a `done` report: frontmatter `outcome`, and `## Result` and `## Not done`;
80
- * a `completed` report must also carry `## Files` and `## Verification` and leave no checklist step unticked
80
+ * a `completed` report must also carry `## Files`, `## Verification` and `## Decisions` and leave no checklist step unticked
81
81
  * (the report's own `## Steps`, else the run's latest `stateSteps`).
82
82
  */
83
+ export const ADVISORY_DONE_SECTIONS = ["Spot-check", "Quiz"];
83
84
  export function doneContract(meta, body, stateSteps) {
84
85
  const missing = [];
86
+ const warnings = [];
85
87
  const declared = String(meta.outcome ?? "").trim().toLowerCase();
86
88
  const outcome = DECLARABLE_OUTCOMES.includes(declared) ? declared : undefined;
87
89
  if (!outcome)
88
90
  missing.push(`\`outcome: ${DECLARABLE_OUTCOMES.join("|")}\` in the frontmatter${declared ? ` (got "${declared}")` : ""}`);
89
- const need = outcome === "completed" || !outcome ? ["Result", "Files", "Verification", "Not done"] : ["Result", "Not done"];
91
+ const need = outcome === "completed" || !outcome ? ["Result", "Files", "Verification", "Decisions", "Not done"] : ["Result", "Not done"];
90
92
  const have = new Set([...body.matchAll(HEADING)].map((m) => (m[1] ?? "").trim().toLowerCase()));
91
93
  for (const h of need)
92
94
  if (!have.has(h.toLowerCase()))
93
95
  missing.push(`\`## ${h}\``);
94
96
  if (outcome === "completed") {
97
+ for (const h of ADVISORY_DONE_SECTIONS)
98
+ if (!have.has(h.toLowerCase()))
99
+ warnings.push(`\`## ${h}\``);
95
100
  const own = parseSteps(body);
96
101
  const open = (own.length ? own : (stateSteps ?? [])).filter((x) => !x.done);
97
102
  if (open.length)
@@ -106,7 +111,7 @@ export function doneContract(meta, body, stateSteps) {
106
111
  .join(" ")
107
112
  .slice(0, 400) || undefined
108
113
  : undefined;
109
- return { outcome, missing, verification };
114
+ return { outcome, missing, warnings, verification };
110
115
  }
111
116
  const DIGEST_MAX_LINES = 3;
112
117
  const DIGEST_MAX_CHARS = 80;
package/dist/prompt.d.ts CHANGED
@@ -40,7 +40,17 @@ export declare function buildSystemPrompt(project: ResolvedProject, agent: Resol
40
40
  * at most `LEAD_BATCH_LIMIT` on the same thread.
41
41
  */
42
42
  export declare function pickMessages(project: ResolvedProject, agent: ResolvedAgent, queue: Message[]): Message[];
43
- export declare function buildUserPrompt(project: ResolvedProject, agent: ResolvedAgent, unread: Message[], handleCount?: number, handoff?: boolean): string;
43
+ /** Most bytes of the user's original task put into a teammate's wake-up prompt. */
44
+ export declare const USER_TASK_LIMIT: number;
45
+ /**
46
+ * The user's original task for a teammate's wake-up (`<user_task>`), so a reviewer or QA can judge the work against what the user asked,
47
+ * not only against the lead's reading of it. Not for the lead (it has the task as its first mail), and not when a mail already carries the tag.
48
+ */
49
+ export declare function userTaskBlock(project: ResolvedProject, agent: ResolvedAgent, unread: Message[], task: string | undefined, file?: string): string[];
50
+ export declare function buildUserPrompt(project: ResolvedProject, agent: ResolvedAgent, unread: Message[], handleCount?: number, handoff?: boolean, userTask?: {
51
+ text: string;
52
+ file?: string;
53
+ }): string;
44
54
  export interface TidyRecordsContext {
45
55
  /** The project records folder (`<shared>/common/records`). */
46
56
  dir: string;
package/dist/prompt.js CHANGED
@@ -130,7 +130,7 @@ export function buildSoloSystemPrompt(project, agent) {
130
130
  ? "Do the task you are given. Your final reply text is printed to the user as your answer, so end with the answer or a short report of what you did; nothing else is delivered."
131
131
  : "");
132
132
  if (!isCall) {
133
- lines.push("## Finishing", `When the job is finished, create a Markdown file (any name ending in \`.md\`) directly inside \`${outboxDir(project, agent.name)}\` with this exact shape:`, "", "```", "---", "type: done", "subject: <short subject>", "outcome: completed|partial|blocked|failed", "---", "", "## Result", "## Files", "## Verification", "## Not done", "```", "", "That ends the run. `## Result` is the actual deliverable or conclusion (not just \"done\"), `## Files` the paths you created or changed, `## Verification` what you ran or checked and what it showed, `## Not done` anything skipped or unverified (or `None`). Only `completed` means success and it needs all four headings; if work remains or is blocked say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A summary in your reply text is never delivered: without a `done` mail the run ends as idle with no report. " + OPEN_PR_RULE);
133
+ lines.push("## Finishing", `When the job is finished, create a Markdown file (any name ending in \`.md\`) directly inside \`${outboxDir(project, agent.name)}\` with this exact shape:`, "", "```", "---", "type: done", "subject: <short subject>", "outcome: completed|partial|blocked|failed", "---", "", "## Result", "## Files", "## Verification", "## Not done", "```", "", "That ends the run. `## Result` is the actual deliverable or conclusion (not just \"done\"), `## Files` the paths you created or changed, `## Verification` what you ran or checked and what it showed, `## Decisions` the choices you made that the task did not specify and the assumptions you relied on (or `None`), `## Not done` anything skipped or unverified (or `None`). Only `completed` means success and it needs all five headings; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A summary in your reply text is never delivered: without a `done` mail the run ends as idle with no report. " + OPEN_PR_RULE);
134
134
  }
135
135
  const shared = sharedDir(project);
136
136
  if (!isCall && shared)
@@ -185,7 +185,7 @@ export function buildSystemPrompt(project, agent) {
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."
187
187
  : "Each wake-up handles one message, except that consecutive `reply`/`failure` messages on the same thread may be handed to you together: handle them together. Do the work it asks, then send the replies that are needed, then stop.", "Mail that repeats an earlier mail of yours to the same agent (same type, same text) is not sent again; you are told, and should wait for the answer or ask for something different instead of resending.", "", "## Message format", "The body of every `task` and `reply` must contain these `##` headings, exactly as written (write `None` under a heading if there is nothing to say).", "A `task` or `reply` missing a heading is sent back to you (at most twice per sender + type + subject); after that it is delivered with a warning flagged to the recipient.", "", `- \`task\`: ${REQUIRED_SECTIONS.task.map((h) => `\`## ${h}\``).join(", ")} (Upstream = id of the mail this task derives from, or \`None\`).`, `- \`reply\`: ${REQUIRED_SECTIONS.reply.map((h) => `\`## ${h}\``).join(", ")}.`, isLead
188
- ? "- `done`: your final report to the user (shown when the run ends, saved as `result.md`). Its frontmatter must contain `outcome: completed|partial|blocked|failed`, and the body the headings `## Result` (the actual deliverable or conclusion, not just \"done\"), `## Files` (paths created or changed), `## Verification` (what you ran or checked, and what it showed) and `## Not done` (anything skipped or unverified, or `None`). Only `completed` means success, and it needs all four headings and every checklist step ticked; if work remains or is blocked, say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A `done` that breaks this is sent back to you and does not end the run. " + OPEN_PR_RULE
188
+ ? "- `done`: your final report to the user (shown when the run ends, saved as `result.md`). Its frontmatter must contain `outcome: completed|partial|blocked|failed`, and the body the headings `## Result` (the actual deliverable or conclusion, not just \"done\"), `## Files` (paths created or changed), `## Verification` (what you ran or checked, and what it showed), `## Decisions` (choices you made that the task did not specify and assumptions you relied on, or `None`) and `## Not done` (anything skipped or unverified, or `None`). Only `completed` means success, and it needs all five headings and every checklist step ticked; it should also carry `## Spot-check` (which sources you re-opened and what they showed) and `## Quiz` (questions the user should be able to answer if they read your work), which are not enforced but flagged when missing; if work remains or is blocked, say `partial`/`blocked`/`failed` (those need only `## Result` and `## Not done`). A `done` that breaks this is sent back to you and does not end the run. " + OPEN_PR_RULE
189
189
  : "- `done` has no required headings.", ...(agent.canAskUser
190
190
  ? [
191
191
  "",
@@ -279,7 +279,23 @@ export function pickMessages(project, agent, queue) {
279
279
  }
280
280
  return run;
281
281
  }
282
- export function buildUserPrompt(project, agent, unread, handleCount = 1, handoff = false) {
282
+ /** Most bytes of the user's original task put into a teammate's wake-up prompt. */
283
+ export const USER_TASK_LIMIT = 4 * 1024;
284
+ /**
285
+ * The user's original task for a teammate's wake-up (`<user_task>`), so a reviewer or QA can judge the work against what the user asked,
286
+ * not only against the lead's reading of it. Not for the lead (it has the task as its first mail), and not when a mail already carries the tag.
287
+ */
288
+ export function userTaskBlock(project, agent, unread, task, file) {
289
+ if (!task?.trim() || agent.name === project.lead)
290
+ return [];
291
+ if (unread.some((m) => m.body.includes("<user_task>")))
292
+ return [];
293
+ const raw = Buffer.from(task.trim(), "utf8");
294
+ const shown = cutUtf8(raw, USER_TASK_LIMIT);
295
+ const text = shown.length === raw.length ? task.trim() : `${shown.toString("utf8")}\n[agent-lyceum: cut at ${shown.length} of ${raw.length} bytes${file ? `; the whole task is in \`${file}\`` : ""}]`;
296
+ return ["", '<user_task note="the user\'s original request, verbatim; judge the work against it, not only against the lead\'s acceptance criteria">', text, "</user_task>"];
297
+ }
298
+ export function buildUserPrompt(project, agent, unread, handleCount = 1, handoff = false, userTask) {
283
299
  const parts = [];
284
300
  const common = readCapped(commonFile(project), COMMON_LIMIT);
285
301
  parts.push('<shared_context source="COMMON.md">');
@@ -300,6 +316,7 @@ export function buildUserPrompt(project, agent, unread, handleCount = 1, handoff
300
316
  if (view)
301
317
  parts.push("", `<${tag}>`, view, `</${tag}>`); // nothing recorded yet: no tag, no tokens
302
318
  }
319
+ parts.push(...userTaskBlock(project, agent, unread, userTask?.text, userTask?.file));
303
320
  const handoffFile = handoff ? sharedIndex(project) : undefined;
304
321
  const notes = handoffFile ? readCapped(handoffFile, HANDOFF_LIMIT) : undefined;
305
322
  if (handoffFile && notes?.text.trim()) {
@@ -157,6 +157,8 @@ export declare class RunSession {
157
157
  private stallHeld;
158
158
  private pendingAgents;
159
159
  private pickBatch;
160
+ /** The run's original task as the user wrote it (`task.md` in the run folder), for the teammates' prompts; undefined when there is none. */
161
+ private userTask;
160
162
  private wake;
161
163
  /**
162
164
  * The earlier failed attempts at these messages and the drafts they left, for the invoke that `attemptId` is about to make.
@@ -561,6 +561,12 @@ export class RunSession {
561
561
  return [must(pending[0], "an agent to wake")];
562
562
  return pending;
563
563
  }
564
+ /** The run's original task as the user wrote it (`task.md` in the run folder), for the teammates' prompts; undefined when there is none. */
565
+ userTask() {
566
+ const file = path.join(this.runDir, "task.md");
567
+ const got = readFileCapped(file, 64 * 1024);
568
+ return got?.text.trim() ? { text: got.text, file } : undefined;
569
+ }
564
570
  async wake(agent) {
565
571
  const { invoke, say, cfg, runDir, project, log, state, claims, attempts, noSessionNoted, opts, cooldowns } = this;
566
572
  const queue = listUnread(project, agent.name);
@@ -579,7 +585,7 @@ export class RunSession {
579
585
  workDir,
580
586
  workspace: spaces[agent.name],
581
587
  systemPrompt: buildSystemPrompt(aproject, agent),
582
- userPrompt: buildUserPrompt(project, agent, queue, unread.length, (state.reopened?.length ?? 0) > 0),
588
+ userPrompt: buildUserPrompt(project, agent, queue, unread.length, (state.reopened?.length ?? 0) > 0, this.userTask()),
583
589
  timeoutSec: cfg.wake_timeout_sec,
584
590
  };
585
591
  // Without a fallback chain (one candidate) the loop, its output and its records are exactly those of plain retries (spec 20.2 decision 11).
@@ -911,7 +917,7 @@ export class RunSession {
911
917
  to: project.lead,
912
918
  type: "failure",
913
919
  subject: "Your done report was not accepted",
914
- body: `The run was not ended: your \`done\` report does not meet the completion contract. Missing:\n${list}\n\nSend \`type: done\` again with the frontmatter line \`outcome: completed|partial|blocked|failed\` and the headings \`## Result\`, \`## Files\`, \`## Verification\`, \`## Not done\`. \`completed\` needs all four and every step ticked; if work remains, report \`partial\` or \`blocked\` (those need only \`## Result\` and \`## Not done\`) or \`failed\`, or send the task that continues the work. (Reminder ${state.done_rejections} of ${MAX_DONE_REJECTIONS}.)`,
920
+ body: `The run was not ended: your \`done\` report does not meet the completion contract. Missing:\n${list}\n\nSend \`type: done\` again with the frontmatter line \`outcome: completed|partial|blocked|failed\` and the headings \`## Result\`, \`## Files\`, \`## Verification\`, \`## Decisions\`, \`## Not done\`. \`completed\` needs all five and every step ticked; if work remains, report \`partial\` or \`blocked\` (those need only \`## Result\` and \`## Not done\`) or \`failed\`, or send the task that continues the work. (Reminder ${state.done_rejections} of ${MAX_DONE_REJECTIONS}.)`,
915
921
  });
916
922
  rejectDone(route.done.file);
917
923
  say(` done report sent back to ${project.lead}: missing ${contract.missing.join("; ")}`);
@@ -994,7 +1000,12 @@ export class RunSession {
994
1000
  const spec = bad ? project.verify?.commands.find((c) => c.name === bad.name) : undefined;
995
1001
  this.dispatcherVerification = bad ? { passed: false, text: `FAILED: ${bad.name} (${spec?.run ?? "?"}) ${describeFailure(bad, spec?.timeout_sec)}` } : { passed: true, text: `passed (${verified.record.commands.map((c) => c.name).join(", ")})` };
996
1002
  }
997
- const report = `# ${route.done.subject}\n\n**Outcome:** ${this.doneOutcome}${this.doneNote ? ` (${this.doneNote})` : ""}\n\n${route.done.body.trimEnd()}\n${verified ? `\n${verificationSection(verified.record, must(project.verify, "verify settings"), verified.cwd)}` : ""}`;
1003
+ const advisory = contract?.warnings.length ? `> [agent-lyceum] Format warning: this report has no ${contract.warnings.join(", ")} section (advisory; the report was accepted).\n\n` : "";
1004
+ if (advisory) {
1005
+ say(` done report accepted without ${contract?.warnings.join(", ")} (advisory)`);
1006
+ log("done-advisory", { missing: contract?.warnings });
1007
+ }
1008
+ const report = `# ${route.done.subject}\n\n**Outcome:** ${this.doneOutcome}${this.doneNote ? ` (${this.doneNote})` : ""}\n\n${advisory}${route.done.body.trimEnd()}\n${verified ? `\n${verificationSection(verified.record, must(project.verify, "verify settings"), verified.cwd)}` : ""}`;
998
1009
  atomicWrite(path.join(runDir, RESULT_FILE), report);
999
1010
  atomicWrite(path.join(runDir, `done-${(state.reopened?.length ?? 0) + 1}.md`), report);
1000
1011
  this.pendingDoneFile = route.done.file;
@@ -1279,7 +1290,7 @@ export class RunSession {
1279
1290
  to: project.lead,
1280
1291
  type: "failure",
1281
1292
  subject: "No done message sent",
1282
- body: `All mailboxes are empty and you have not sent a \`done\` message, so the run would end without a final report. If the job is finished and verified, send \`type: done\` now (with \`outcome: completed|partial|blocked|failed\` in the frontmatter and \`## Result\`, \`## Files\`, \`## Verification\`, \`## Not done\`${state.steps ? " and the full `## Steps` checklist" : ""}). If work remains, send the \`task\` that continues it. Writing a summary in your reply text does not count: only mail is delivered.`,
1293
+ body: `All mailboxes are empty and you have not sent a \`done\` message, so the run would end without a final report. If the job is finished and verified, send \`type: done\` now (with \`outcome: completed|partial|blocked|failed\` in the frontmatter and \`## Result\`, \`## Files\`, \`## Verification\`, \`## Decisions\`, \`## Not done\`${state.steps ? " and the full `## Steps` checklist" : ""}). If work remains, send the \`task\` that continues it. Writing a summary in your reply text does not count: only mail is delivered.`,
1283
1294
  });
1284
1295
  pending = this.pendingAgents();
1285
1296
  }
@@ -1,5 +1,7 @@
1
1
  /** The lead's guidance on `parallel: true` (spec 23.12 point 5). Only `init` writes it, into a new lead AGENT.md. */
2
2
  export declare 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.";
3
+ /** The lead's guidance on the `## Decisions` and `## Not done` sections of `done`. Only `init` writes it, into a new lead AGENT.md. */
4
+ export declare const LEAD_DONE_HINT = " Under `## Decisions` list every decision or assumption made without an answer from the user, each with the alternative you rejected; under `## Not done` say what the checks did not cover.";
3
5
  export declare const GLOBAL_TEAM_YAML = "# Global agent library. Projects pick agents from here by name and may override any field.\n# Relative paths here are resolved against this folder. \"~\" is allowed.\nagents:\n lead:\n runtime: claude-code # claude-code | codex\n agent_md: agents/lead/AGENT.md\n memory: { global: agents/lead/memory }\n # model: opus # most capable model: keep it for the lead\n fe-member:\n runtime: claude-code\n agent_md: agents/fe-member/AGENT.md\n memory: { global: agents/fe-member/memory }\n # model: sonnet # cheaper model for routine work\n qa-member:\n runtime: claude-code\n agent_md: agents/qa-member/AGENT.md\n memory: { global: agents/qa-member/memory }\n # model: sonnet # cheaper model for routine work\n # Model hints (comments only):\n # - a read-only search/explorer role suits \"model: haiku\", the cheapest tier (the alias resolves per provider; on the Anthropic API it is claude-haiku-5-5).\n # - a reviewer can run on the other runtime (\"runtime: codex\"); leave the codex model unset to use the CLI default.\n";
4
6
  export interface InitResult {
5
7
  home: string;
package/dist/scaffold.js CHANGED
@@ -3,6 +3,8 @@ import path from "node:path";
3
3
  import { assertName, homePaths, projectPaths } from "./paths.js";
4
4
  /** The lead's guidance on `parallel: true` (spec 23.12 point 5). Only `init` writes it, into a new lead AGENT.md. */
5
5
  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
+ /** The lead's guidance on the `## Decisions` and `## Not done` sections of `done`. Only `init` writes it, into a new lead AGENT.md. */
7
+ export const LEAD_DONE_HINT = " Under `## Decisions` list every decision or assumption made without an answer from the user, each with the alternative you rejected; under `## Not done` say what the checks did not cover.";
6
8
  const PERSONAS = {
7
9
  lead: `# Lead
8
10
 
@@ -14,7 +16,7 @@ You coordinate the team. You receive the user's task, break it into concrete pie
14
16
  - When a teammate reports back, decide the next step: assign follow-up work, ask another teammate to verify, or accept the result.
15
17
  - Teammates cannot message each other by default; route everything through yourself.
16
18
  - ${LEAD_PARALLEL_HINT}
17
- - When the whole job is verified and finished, send a \`done\` message summarising what was delivered.
19
+ - When the whole job is verified and finished, send a \`done\` message summarising what was delivered.${LEAD_DONE_HINT}
18
20
  `,
19
21
  "fe-member": `# Frontend member
20
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-lyceum",
3
- "version": "0.37.0",
3
+ "version": "0.39.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",