agent-lyceum 0.54.1 → 0.56.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.
Files changed (61) hide show
  1. package/README.md +2 -0
  2. package/README.zh-TW.md +2 -0
  3. package/dist/adapters/cursor.js +5 -1
  4. package/dist/attribution.d.ts +2 -0
  5. package/dist/cli.js +33 -7
  6. package/dist/config.d.ts +3 -0
  7. package/dist/config.js +5 -1
  8. package/dist/dispatcher.js +7 -2
  9. package/dist/doctor.js +12 -3
  10. package/dist/format.d.ts +4 -1
  11. package/dist/format.js +40 -2
  12. package/dist/mailbox.d.ts +29 -1
  13. package/dist/mailbox.js +56 -15
  14. package/dist/memory-tidy.js +18 -2
  15. package/dist/message-store.d.ts +10 -0
  16. package/dist/message-store.js +26 -0
  17. package/dist/open-pr.d.ts +13 -1
  18. package/dist/open-pr.js +12 -4
  19. package/dist/playbook.d.ts +28 -0
  20. package/dist/playbook.js +40 -0
  21. package/dist/policy.d.ts +12 -0
  22. package/dist/policy.js +55 -0
  23. package/dist/project-lock.d.ts +16 -0
  24. package/dist/project-lock.js +34 -2
  25. package/dist/prompt.d.ts +2 -0
  26. package/dist/prompt.js +25 -7
  27. package/dist/quota.js +62 -10
  28. package/dist/records.d.ts +10 -0
  29. package/dist/records.js +46 -0
  30. package/dist/review-gate.d.ts +33 -0
  31. package/dist/review-gate.js +78 -0
  32. package/dist/run-cleanup.d.ts +9 -2
  33. package/dist/run-cleanup.js +67 -4
  34. package/dist/run-outcome.d.ts +4 -0
  35. package/dist/run-outcome.js +8 -1
  36. package/dist/run-session.d.ts +27 -0
  37. package/dist/run-session.js +347 -39
  38. package/dist/run-store.d.ts +17 -3
  39. package/dist/run-store.js +10 -2
  40. package/dist/scaffold.d.ts +1 -1
  41. package/dist/scaffold.js +5 -2
  42. package/dist/schema.d.ts +12 -0
  43. package/dist/schema.js +6 -0
  44. package/dist/status-watch.d.ts +4 -2
  45. package/dist/status-watch.js +27 -5
  46. package/dist/status.d.ts +4 -2
  47. package/dist/status.js +11 -8
  48. package/dist/task-bind.d.ts +4 -0
  49. package/dist/task-bind.js +42 -0
  50. package/dist/wake-cap.d.ts +5 -0
  51. package/dist/wake-cap.js +11 -0
  52. package/dist/worktree.d.ts +153 -6
  53. package/dist/worktree.js +378 -15
  54. package/package.json +1 -1
  55. package/web/dist/public/assets/index-CVkc3V2B.js +92 -0
  56. package/web/dist/public/assets/index-zT-RkrlC.css +2 -0
  57. package/web/dist/public/index.html +2 -2
  58. package/web/dist/server/hub.js +40 -5
  59. package/web/dist/start.js +45 -5
  60. package/web/dist/public/assets/index-BPY1-W3F.css +0 -2
  61. package/web/dist/public/assets/index-CbQs5aMP.js +0 -92
@@ -0,0 +1,78 @@
1
+ import { roleOfName } from "./instances.js";
2
+ export function crossRuntimeBlock(project, state, _mode) {
3
+ if (project.verify?.cross_runtime === false)
4
+ return undefined;
5
+ const configured = Object.values(project.agents).map((a) => a.runtime);
6
+ if (configured.length > 0 && configured.every((r) => r === configured[0]))
7
+ return undefined;
8
+ const since = state.reopened?.length ? state.reopened[state.reopened.length - 1].at : "";
9
+ const role = (name) => roleOfName(project.agents, name);
10
+ const runtimeOf = (name) => {
11
+ const key = role(name);
12
+ const last = [...(state.wakes ?? [])].reverse().find((w) => w.at >= since && w.runtime && role(w.agent) === key);
13
+ return last?.runtime ?? project.agents[key]?.runtime ?? project.agents[name]?.runtime;
14
+ };
15
+ // Authors are people whose files were integrated in this segment. Handling a task, even without `read_only: true`, is not authorship.
16
+ const authors = new Set();
17
+ for (const i of state.implementers ?? []) {
18
+ if (since && (i.at === undefined || i.at < since))
19
+ continue;
20
+ authors.add(role(i.agent));
21
+ }
22
+ const authorRuntimes = new Set();
23
+ for (const name of authors) {
24
+ const rt = runtimeOf(name);
25
+ if (rt)
26
+ authorRuntimes.add(rt);
27
+ }
28
+ if (authorRuntimes.size === 0) {
29
+ const leadRt = runtimeOf(project.lead);
30
+ if (leadRt)
31
+ authorRuntimes.add(leadRt);
32
+ }
33
+ const names = Object.keys(project.agents)
34
+ .filter((name) => name !== project.lead && !authorRuntimes.has(runtimeOf(name) ?? ""))
35
+ .sort();
36
+ // Nobody can give the pass (only the lead is on the other runtime, or every other-runtime teammate wrote code). Do not block.
37
+ if (names.length === 0)
38
+ return undefined;
39
+ const passed = (state.reviews ?? []).some((r) => r.verdict === "pass" && r.at >= since && names.includes(role(r.reviewer)));
40
+ if (passed)
41
+ return undefined;
42
+ return `A completed report needs \`verdict: pass\` from a teammate whose runtime is not the implementer's. Teammates who can give it: ${names.join(", ")}.`;
43
+ }
44
+ /**
45
+ * What `doctor` can see before a run. A team lead does not edit the repository; a one-line fix is `run --agent`.
46
+ * When nobody but the lead is on another runtime, a completed done does not wait for a pass. Solo runs are out of this.
47
+ */
48
+ export function teamRunFindings(project) {
49
+ if (project.solo)
50
+ return [];
51
+ const lead = project.agents[project.lead];
52
+ if (!lead)
53
+ return [];
54
+ const others = Object.values(project.agents).filter((a) => a.name !== project.lead);
55
+ const findings = [
56
+ {
57
+ level: "info",
58
+ message: `On a team run, ${project.lead} does not edit the repository, including CLAUDE.md and AGENTS.md. A one-line fix is \`run --agent <name>\` of the agent who writes it.`,
59
+ },
60
+ ];
61
+ const reachable = lead.canMessage === "all" ? others.map((a) => a.name) : others.filter((a) => lead.canMessage.includes(a.name)).map((a) => a.name);
62
+ if (reachable.length === 0) {
63
+ findings.push({
64
+ level: "warn",
65
+ message: `${project.lead} cannot send work to a teammate, so a team run cannot land a code change. Use \`run --agent <name>\` of the agent who writes it.`,
66
+ });
67
+ }
68
+ const memberRuntimes = others.map((a) => a.runtime).filter((r) => !!r);
69
+ const configured = Object.values(project.agents).map((a) => a.runtime).filter((r) => !!r);
70
+ const mixed = configured.length > 1 && configured.some((r) => r !== configured[0]);
71
+ if (mixed && memberRuntimes.length > 0 && memberRuntimes.every((r) => r === memberRuntimes[0]) && memberRuntimes[0] !== lead.runtime) {
72
+ findings.push({
73
+ level: "info",
74
+ message: `Every teammate except ${project.lead} uses ${memberRuntimes[0]}. A completed done does not wait for a cross-runtime pass then, because nobody else can give one. Set \`verify.cross_runtime: false\` to turn the gate off.`,
75
+ });
76
+ }
77
+ return findings;
78
+ }
@@ -1,10 +1,16 @@
1
1
  import type { ResolvedProject } from "./config.js";
2
2
  export interface CleanupItem {
3
- kind: "workspace" | "refs" | "task-memory" | "run";
3
+ kind: "workspace" | "task-branch" | "refs" | "task-memory" | "run";
4
4
  /** One line for people. */
5
5
  label: string;
6
6
  path?: string;
7
7
  agent?: string;
8
+ /** `task-branch`: a checkout run's branch, in the project repo. Only branches that are deleted are items (the ones kept are in `keep`). */
9
+ branch?: string;
10
+ delete?: boolean;
11
+ /** `task-branch`: the tip that was checked at plan time; the branch is deleted only while it is still there. */
12
+ tip?: string;
13
+ reason?: string;
8
14
  }
9
15
  export interface CleanupPlan {
10
16
  project: ResolvedProject;
@@ -20,7 +26,8 @@ export interface CleanupPlan {
20
26
  agent: string;
21
27
  branch: string;
22
28
  path: string;
23
- files: string[];
29
+ files: string[]; /** Set for a checkout run's task branch: why it stays. */
30
+ reason?: string;
24
31
  }[];
25
32
  /** Short description of the run, for messages. */
26
33
  summary: string;
@@ -5,7 +5,7 @@ import { assertName } from "./paths.js";
5
5
  import { inspectRunLock } from "./project-lock.js";
6
6
  import { loadRunState } from "./run-store.js";
7
7
  import { runIsAlive } from "./status.js";
8
- import { deleteSnapshotRefs, existingAgentWorkspace, inspectWorkspace, listSnapshotRefs, listWorkspaceAgents, removeAgentWorkspace } from "./worktree.js";
8
+ import { deleteSnapshotRefs, existingAgentWorkspace, inspectWorkspace, deleteTaskBranch, listSnapshotRefs, listWorkspaceAgents, removeAgentWorkspace, resolveCommit, taskBranchState } from "./worktree.js";
9
9
  import { must } from "./assert.js";
10
10
  const journalDir = (p) => path.join(p.paths.root, "cleanup");
11
11
  const journalFile = (p, runId) => path.join(journalDir(p), `${runId}.json`);
@@ -33,8 +33,9 @@ export function planRunCleanup(project, runId, opts = {}) {
33
33
  if (!hasRun && !hasJournal)
34
34
  throw new Error(`Run "${runId}" not found in ${project.paths.runs}. List ids with: agent-lyceum status --task-list`);
35
35
  const plan = { project, runId, runDir, keepWorktrees, items: [], refusals: [], keep: [], summary: runId };
36
+ let state;
36
37
  if (hasRun) {
37
- const state = loadRunState(runDir);
38
+ state = loadRunState(runDir);
38
39
  plan.summary = `${runId}: ${state.task_summary}`;
39
40
  if (!state.end_reason && !opts.lockHeld && runIsAlive(state, project)) {
40
41
  const holder = state.schema_version >= 2 ? inspectRunLock(project.paths.root, runId) : undefined;
@@ -43,8 +44,14 @@ export function planRunCleanup(project, runId, opts = {}) {
43
44
  }
44
45
  // A concurrent run has a worktree for the lead: members' work lands there, and the lead's branch is what you merge.
45
46
  const leadWs = existingAgentWorkspace(project, runId, project.lead);
47
+ // A checkout run's lead worked in the project checkout on `task_branch`: members' work is looked for in what the run recorded as its
48
+ // result (else the branch's tip), never in whatever the user has checked out now.
49
+ const taskBranch = state?.workspace_mode === "checkout" && state.task_branch ? state.task_branch : undefined;
50
+ const branchNow = taskBranch ? safeTaskBranchState(project, taskBranch) : undefined;
51
+ const recorded = taskBranch ? state?.result_branch : undefined;
52
+ const against = taskBranch ? ((recorded && safeResolve(project, recorded.head)) ?? branchNow?.state?.tip) : undefined;
46
53
  for (const agent of listWorkspaceAgents(project, runId)) {
47
- const w = inspectWorkspace(project, runId, agent, agent === project.lead ? undefined : leadWs);
54
+ const w = inspectWorkspace(project, runId, agent, agent === project.lead ? undefined : against ? { commit: against } : leadWs);
48
55
  if (!w)
49
56
  continue;
50
57
  const files = [...new Set([...w.dirty, ...w.unintegrated])];
@@ -60,6 +67,8 @@ export function planRunCleanup(project, runId, opts = {}) {
60
67
  }
61
68
  plan.items.push({ kind: "workspace", agent, path: w.root, label: `worktree and branch of ${agent} (${w.root}, ${w.branch}): its work is in the repo` });
62
69
  }
70
+ if (taskBranch && branchNow)
71
+ planTaskBranch(plan, taskBranch, branchNow, recorded);
63
72
  if (!keepWorktrees && listSnapshotRefs(project, runId).length) {
64
73
  plan.items.push({ kind: "refs", label: `snapshot refs refs/agent-lyceum/${runId}/*` });
65
74
  }
@@ -70,6 +79,58 @@ export function planRunCleanup(project, runId, opts = {}) {
70
79
  plan.items.push({ kind: "run", path: runDir, label: `run directory ${runDir} (state, log, result, snapshots, kept violations, mailboxes)` });
71
80
  return plan;
72
81
  }
82
+ function safeTaskBranchState(project, branch) {
83
+ try {
84
+ return { state: taskBranchState(project.dir, branch) };
85
+ }
86
+ catch (e) {
87
+ return { error: e.message.split("\n")[0] };
88
+ }
89
+ }
90
+ function safeResolve(project, sha) {
91
+ try {
92
+ return resolveCommit(project.dir, sha);
93
+ }
94
+ catch {
95
+ return undefined;
96
+ }
97
+ }
98
+ /**
99
+ * What happens to a checkout run's task branch. It is deleted only when all hold: a result is recorded, the worktrees are not kept, HEAD does
100
+ * not name the branch, and the branch's tip (not just the recorded `result_branch.head`) is in HEAD. Anything else keeps it and says why.
101
+ * HEAD on the branch refuses the plan: nothing is switched for the user.
102
+ */
103
+ function planTaskBranch(plan, branch, now, recorded) {
104
+ const { project, keepWorktrees } = plan;
105
+ const keep = (reason) => {
106
+ plan.keep.push({ agent: project.lead, branch, path: project.dir, files: [], reason });
107
+ };
108
+ if (!now.state) {
109
+ keep(`its state could not be read (${now.error ?? "unknown"}), so it was not deleted`);
110
+ return;
111
+ }
112
+ const { tip, headIsBranch, tipInHead } = now.state;
113
+ if (headIsBranch) {
114
+ plan.refusals.push(`The project checkout is on the run's task branch ${branch}. Switch to another branch first (it is not switched for you), then clear again.`);
115
+ return;
116
+ }
117
+ if (tip === undefined)
118
+ return; // gone already
119
+ if (keepWorktrees) {
120
+ keep(`kept by --keep-worktrees${recorded ? "" : "; there is also no recorded result commit"}`);
121
+ return;
122
+ }
123
+ if (!recorded) {
124
+ keep("沒有已記錄的結果 commit (the run recorded no result), so whether its work is in HEAD is not known; it was not deleted");
125
+ return;
126
+ }
127
+ if (!tipInHead) {
128
+ const later = tip !== recorded.head ? `; it has moved on from the recorded result ${recorded.head.slice(0, 8)}` : "";
129
+ keep(`its tip ${tip.slice(0, 8)} is not in HEAD (not merged, or squashed)${later}; it was not deleted`);
130
+ return;
131
+ }
132
+ plan.items.push({ kind: "task-branch", branch, delete: true, tip, label: `task branch ${branch} (its tip ${tip.slice(0, 8)} is in HEAD)` });
133
+ }
73
134
  /** Remove a path without ever following a symlink, and only inside the project home. */
74
135
  function safeRemove(project, target) {
75
136
  if (!lexists(target))
@@ -102,7 +163,9 @@ export function executeRunCleanup(plan, hooks = {}) {
102
163
  for (let n = 0; n < plan.items.length; n++) {
103
164
  const item = must(plan.items[n], "cleanup item");
104
165
  try {
105
- if (item.kind === "workspace") {
166
+ if (item.kind === "task-branch")
167
+ deleteTaskBranch(project.dir, must(item.branch, "task branch"), must(item.tip, "task branch tip"));
168
+ else if (item.kind === "workspace") {
106
169
  removeAgentWorkspace(project, runId, item.agent);
107
170
  const dir = path.dirname(item.path);
108
171
  if (fs.existsSync(dir) && fs.readdirSync(dir).length === 0)
@@ -11,6 +11,10 @@ export declare function resolveDoneOutcome(contract: DoneContract, rejections: n
11
11
  /** Spec 27/28: a verify command failed and no rejections were left, or the same failure repeated on an unchanged workspace; `note` says which and how. */
12
12
  verifyFailure?: {
13
13
  note: string;
14
+ },
15
+ /** A completed report that still fails a gate after the rejection budget is spent. */
16
+ gateFailure?: {
17
+ note: string;
14
18
  }): {
15
19
  outcome: RunOutcome;
16
20
  note?: string;
@@ -2,7 +2,9 @@ import path from "node:path";
2
2
  /** What a lead's `done` amounts to: its declared outcome, unless the contract is broken or member work never reached the repo. */
3
3
  export function resolveDoneOutcome(contract, rejections, unintegrated,
4
4
  /** Spec 27/28: a verify command failed and no rejections were left, or the same failure repeated on an unchanged workspace; `note` says which and how. */
5
- verifyFailure) {
5
+ verifyFailure,
6
+ /** A completed report that still fails a gate after the rejection budget is spent. */
7
+ gateFailure) {
6
8
  const ok = contract.missing.length === 0;
7
9
  let outcome = ok ? (contract.outcome ?? "partial") : "partial";
8
10
  let note = ok ? undefined : `Completion contract not met after ${rejections} reminder(s): missing ${contract.missing.join("; ")}. Reported as partial; the lead's report is kept as written.`;
@@ -16,6 +18,11 @@ verifyFailure) {
16
18
  outcome = "partial";
17
19
  note = note ? `${note} ${verifyFailure.note}` : verifyFailure.note;
18
20
  }
21
+ if (gateFailure) {
22
+ if (outcome === "completed")
23
+ outcome = "partial";
24
+ note = note ? `${note} ${gateFailure.note}` : gateFailure.note;
25
+ }
19
26
  return { outcome, note, verification: contract.verification };
20
27
  }
21
28
  /** How a run turned out, from why it stopped (`done` carries the lead's own verdict). */
@@ -9,6 +9,8 @@ export { newRunId };
9
9
  export type { ActiveWake, EndReason, RunState, SentTopic, WakeRecord, WakeTopic } from "./run-store.js";
10
10
  export declare const RESULT_FILE = "result.md";
11
11
  /** How many times a non-conforming `done` goes back to the lead before it is accepted as `partial`. */
12
+ /** The acceptance line of a follow-up task. It names the task file, so the mail's acceptance check can see a real path. */
13
+ export declare function followupAcceptance(taskFile: string): string;
12
14
  export declare const MAX_DONE_REJECTIONS = 2;
13
15
  /** How many times a malformed `ask` goes back to its sender before the lead is told instead. */
14
16
  export declare const MAX_ASK_REJECTIONS = 2;
@@ -57,6 +59,11 @@ export interface RunOptions {
57
59
  resume?: RunState;
58
60
  /** Where the run's agents work, decided by `planWorkspace` before the run's lock was taken; the session never recomputes it. */
59
61
  plan: WorkspacePlan;
62
+ /**
63
+ * A new checkout run (`plan.taskBranch`) that has not cut its branch yet. The state is saved first (without `task_sent`), then the
64
+ * project checkout is switched to the task branch, then the task is delivered; a failure in between is taken back. The caller holds the run lock.
65
+ */
66
+ startCheckout?: boolean;
60
67
  /** Reopen a done run: this text becomes a new task for the lead. Only with `resume` of a run that ended `done`. */
61
68
  followup?: {
62
69
  text: string;
@@ -86,6 +93,10 @@ export declare class RunSession {
86
93
  private readonly resume;
87
94
  /** The handoff index as this segment started; the lead is noted when it is the same at `done`. */
88
95
  private readonly sharedAtStart;
96
+ /** Set once at run start when `bind_task` names checks that are not in project.yaml. A note only; it does not change the outcome. */
97
+ private bindNote;
98
+ /** Checkout at the start of a read-only wake. The claim stores the same pair so a resume can put paths back. */
99
+ private roSnaps;
89
100
  private readonly invoke;
90
101
  private readonly say;
91
102
  private readonly cfg;
@@ -143,6 +154,16 @@ export declare class RunSession {
143
154
  private note;
144
155
  /** Spec 24.5.2: log every tier that was dropped; tell the sender once per reason (`no-tiers` is log-only). */
145
156
  private noteTierIgnored;
157
+ /** A `playbook` or `read_only` that did not apply: log every one, and tell the sender once per reason. */
158
+ private noteFlagIgnored;
159
+ /**
160
+ * A read-only wake in its own worktree puts back only the paths that changed. Paths that were already dirty stay.
161
+ * This is not `reset --hard` and not a clean of the whole tree.
162
+ * A wake with no worktree shares the project folder with the user, so it only notes a moved HEAD and new paths.
163
+ * Cursor denies `Write` on the repo. Claude and Codex rely on the OS sandbox. When that cannot block the write,
164
+ * a worktree is still put back; a borrowed folder is only noted.
165
+ */
166
+ private revertReadOnly;
146
167
  /** Bind the project to this run again, after its slot table changed. */
147
168
  private rebind;
148
169
  /** What the router needs to hold and place mail for roles with several instances (spec 23.7.1). */
@@ -175,6 +196,10 @@ export declare class RunSession {
175
196
  */
176
197
  /** The agent and the model it last ran on (a tier or fallback shows in `last_wake`), else its configured model. */
177
198
  private workerRef;
199
+ /** A checkout run's task branch (the lead works in the project checkout, not in a worktree of its own), else undefined. Always the recorded one. */
200
+ private checkoutBranch;
201
+ /** Why the project checkout is no longer on a checkout run's task branch, or undefined (also for runs that do not work in the checkout). */
202
+ private checkoutMoved;
178
203
  private integrateMember;
179
204
  /** A member whose worktree was refused: it is not woken again in this run, and the lead is told so it can react. */
180
205
  private refuseMember;
@@ -200,6 +225,8 @@ export declare class RunSession {
200
225
  * A request that cannot be honoured is reported and noted; it never changes how the run turned out.
201
226
  */
202
227
  private maybeOpenPr;
228
+ /** Checks named in the task that are not verify commands. Undefined when binding is off or everything matches. */
229
+ private bindMismatch;
203
230
  /** On resume: sort out what the interrupted process left behind before anything is woken. */
204
231
  private recover;
205
232
  run(): Promise<RunSummary>;