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.
- package/README.md +2 -0
- package/README.zh-TW.md +2 -0
- package/dist/adapters/cursor.js +5 -1
- package/dist/attribution.d.ts +2 -0
- package/dist/cli.js +33 -7
- package/dist/config.d.ts +3 -0
- package/dist/config.js +5 -1
- package/dist/dispatcher.js +7 -2
- package/dist/doctor.js +12 -3
- package/dist/format.d.ts +4 -1
- package/dist/format.js +40 -2
- package/dist/mailbox.d.ts +29 -1
- package/dist/mailbox.js +56 -15
- package/dist/memory-tidy.js +18 -2
- package/dist/message-store.d.ts +10 -0
- package/dist/message-store.js +26 -0
- package/dist/open-pr.d.ts +13 -1
- package/dist/open-pr.js +12 -4
- package/dist/playbook.d.ts +28 -0
- package/dist/playbook.js +40 -0
- package/dist/policy.d.ts +12 -0
- package/dist/policy.js +55 -0
- package/dist/project-lock.d.ts +16 -0
- package/dist/project-lock.js +34 -2
- package/dist/prompt.d.ts +2 -0
- package/dist/prompt.js +25 -7
- package/dist/quota.js +62 -10
- package/dist/records.d.ts +10 -0
- package/dist/records.js +46 -0
- package/dist/review-gate.d.ts +33 -0
- package/dist/review-gate.js +78 -0
- package/dist/run-cleanup.d.ts +9 -2
- package/dist/run-cleanup.js +67 -4
- package/dist/run-outcome.d.ts +4 -0
- package/dist/run-outcome.js +8 -1
- package/dist/run-session.d.ts +27 -0
- package/dist/run-session.js +347 -39
- package/dist/run-store.d.ts +17 -3
- package/dist/run-store.js +10 -2
- package/dist/scaffold.d.ts +1 -1
- package/dist/scaffold.js +5 -2
- package/dist/schema.d.ts +12 -0
- package/dist/schema.js +6 -0
- package/dist/status-watch.d.ts +4 -2
- package/dist/status-watch.js +27 -5
- package/dist/status.d.ts +4 -2
- package/dist/status.js +11 -8
- package/dist/task-bind.d.ts +4 -0
- package/dist/task-bind.js +42 -0
- package/dist/wake-cap.d.ts +5 -0
- package/dist/wake-cap.js +11 -0
- package/dist/worktree.d.ts +153 -6
- package/dist/worktree.js +378 -15
- package/package.json +1 -1
- package/web/dist/public/assets/index-CVkc3V2B.js +92 -0
- package/web/dist/public/assets/index-zT-RkrlC.css +2 -0
- package/web/dist/public/index.html +2 -2
- package/web/dist/server/hub.js +40 -5
- package/web/dist/start.js +45 -5
- package/web/dist/public/assets/index-BPY1-W3F.css +0 -2
- package/web/dist/public/assets/index-CbQs5aMP.js +0 -92
package/dist/open-pr.d.ts
CHANGED
|
@@ -47,6 +47,18 @@ export interface OpenPrInput {
|
|
|
47
47
|
run: CommandRunner;
|
|
48
48
|
/** The run already has a pull request for this branch: while it is still open only the branch is pushed; otherwise (merged, closed) a new one is opened. */
|
|
49
49
|
existingUrl?: string;
|
|
50
|
+
/** The branch the pull request targets. Without it the repo's default branch is looked up. */
|
|
51
|
+
base?: string;
|
|
52
|
+
/** Git arguments that go in front of `push` (the pins that keep git from running anything an agent planted). */
|
|
53
|
+
pinnedGit?: string[];
|
|
50
54
|
}
|
|
51
|
-
/**
|
|
55
|
+
/** The commands that finish the job by hand. `base` is left out when it is not known, so gh picks the repo's default branch. */
|
|
56
|
+
export declare function manualPrCommands(i: {
|
|
57
|
+
cwd: string;
|
|
58
|
+
branch: string;
|
|
59
|
+
base?: string;
|
|
60
|
+
title: string;
|
|
61
|
+
bodyFile: string;
|
|
62
|
+
}): string[];
|
|
63
|
+
/** Push the branch and open a pull request against `base` (the default branch when none is given). Never throws; says how to finish by hand when a step fails. */
|
|
52
64
|
export declare function openPullRequest(i: OpenPrInput): OpenPrResult;
|
package/dist/open-pr.js
CHANGED
|
@@ -46,19 +46,27 @@ export function defaultBase(cwd, run) {
|
|
|
46
46
|
const firstLine = (s) => s.split(/\r?\n/).find((l) => l.trim())?.trim() ?? "no output";
|
|
47
47
|
/** POSIX single-quote: safe to paste into a shell whatever the string holds. */
|
|
48
48
|
const sh = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
49
|
-
/**
|
|
49
|
+
/** The commands that finish the job by hand. `base` is left out when it is not known, so gh picks the repo's default branch. */
|
|
50
|
+
export function manualPrCommands(i) {
|
|
51
|
+
return [
|
|
52
|
+
`git -C ${sh(i.cwd)} push -u origin ${sh(i.branch)}`,
|
|
53
|
+
`gh pr create --head ${sh(i.branch)}${i.base ? ` --base ${sh(i.base)}` : ""} --title ${sh(i.title)} --body-file ${sh(path.resolve(i.bodyFile))}`,
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
/** Push the branch and open a pull request against `base` (the default branch when none is given). Never throws; says how to finish by hand when a step fails. */
|
|
50
57
|
export function openPullRequest(i) {
|
|
58
|
+
const pushArgs = [...(i.pinnedGit ?? []), "push", "-u", "origin", i.branch];
|
|
51
59
|
if (i.existingUrl) {
|
|
52
60
|
// A squash merge leaves the branch looking unmerged, so ask GitHub. When the lookup itself fails, assume the PR is still open.
|
|
53
61
|
const view = i.run("gh", ["pr", "view", i.existingUrl, "--json", "state", "-q", ".state"], i.cwd);
|
|
54
62
|
if (!view.ok || view.out.trim() === "OPEN") {
|
|
55
|
-
const push = i.run("git",
|
|
63
|
+
const push = i.run("git", pushArgs, i.cwd);
|
|
56
64
|
if (push.ok)
|
|
57
65
|
return { status: "opened", url: i.existingUrl, updated: true };
|
|
58
66
|
return { status: "failed", step: "push", reason: firstLine(push.out), manual: [`git -C ${sh(i.cwd)} push -u origin ${sh(i.branch)}`] };
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
|
-
const base = defaultBase(i.cwd, i.run);
|
|
69
|
+
const base = i.base ?? defaultBase(i.cwd, i.run);
|
|
62
70
|
try {
|
|
63
71
|
atomicWrite(i.bodyFile, i.body);
|
|
64
72
|
}
|
|
@@ -68,7 +76,7 @@ export function openPullRequest(i) {
|
|
|
68
76
|
const createArgs = ["pr", "create", "--head", i.branch, "--base", base, "--title", i.title, "--body-file", i.bodyFile];
|
|
69
77
|
const manualPush = `git -C ${sh(i.cwd)} push -u origin ${sh(i.branch)}`;
|
|
70
78
|
const manualCreate = `gh pr create --head ${sh(i.branch)} --base ${sh(base)} --title ${sh(i.title)} --body-file ${sh(path.resolve(i.bodyFile))}`;
|
|
71
|
-
const push = i.run("git",
|
|
79
|
+
const push = i.run("git", pushArgs, i.cwd);
|
|
72
80
|
if (!push.ok)
|
|
73
81
|
return { status: "failed", step: "push", reason: firstLine(push.out), manual: [manualPush, manualCreate] };
|
|
74
82
|
const created = i.run("gh", createArgs, i.cwd);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const PLAYBOOKS: readonly ["investigate", "fix", "feature", "refactor"];
|
|
2
|
+
export type Playbook = (typeof PLAYBOOKS)[number];
|
|
3
|
+
export declare function isPlaybook(v: unknown): v is Playbook;
|
|
4
|
+
export type PlaybookFlag = "absent" | "invalid" | Playbook | {
|
|
5
|
+
ignored: "not-lead" | "not-a-task";
|
|
6
|
+
};
|
|
7
|
+
export declare function playbookFlag(i: {
|
|
8
|
+
value: unknown;
|
|
9
|
+
senderIsLead: boolean;
|
|
10
|
+
type: string;
|
|
11
|
+
}): PlaybookFlag;
|
|
12
|
+
export type ReadOnlyFlag = "absent" | "invalid" | boolean | {
|
|
13
|
+
ignored: "not-lead" | "not-a-task";
|
|
14
|
+
};
|
|
15
|
+
export declare function readOnlyFlag(i: {
|
|
16
|
+
value: unknown;
|
|
17
|
+
senderIsLead: boolean;
|
|
18
|
+
type: string;
|
|
19
|
+
}): ReadOnlyFlag;
|
|
20
|
+
/** investigate 為真;明確的 true 為真;false、absent、ignored 為假。 */
|
|
21
|
+
export declare function effectiveReadOnly(playbook: Playbook | undefined, flag: ReadOnlyFlag): boolean;
|
|
22
|
+
/** feature 要多一個 Shape;其他 playbook 沒有額外標題。 */
|
|
23
|
+
export declare function extraSections(playbook: Playbook | undefined): string[];
|
|
24
|
+
export declare function wakeIsReadOnly(messages: readonly {
|
|
25
|
+
type: string;
|
|
26
|
+
playbook?: string;
|
|
27
|
+
read_only?: unknown;
|
|
28
|
+
}[]): boolean;
|
package/dist/playbook.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const PLAYBOOKS = ["investigate", "fix", "feature", "refactor"];
|
|
2
|
+
export function isPlaybook(v) {
|
|
3
|
+
return typeof v === "string" && PLAYBOOKS.includes(v);
|
|
4
|
+
}
|
|
5
|
+
const isEmpty = (v) => v === undefined || v === null || v === "";
|
|
6
|
+
export function playbookFlag(i) {
|
|
7
|
+
if (isEmpty(i.value))
|
|
8
|
+
return "absent";
|
|
9
|
+
if (!i.senderIsLead)
|
|
10
|
+
return { ignored: "not-lead" };
|
|
11
|
+
if (!isPlaybook(i.value))
|
|
12
|
+
return "invalid";
|
|
13
|
+
if (i.type !== "task")
|
|
14
|
+
return { ignored: "not-a-task" };
|
|
15
|
+
return i.value;
|
|
16
|
+
}
|
|
17
|
+
export function readOnlyFlag(i) {
|
|
18
|
+
if (isEmpty(i.value))
|
|
19
|
+
return "absent";
|
|
20
|
+
if (!i.senderIsLead)
|
|
21
|
+
return { ignored: "not-lead" };
|
|
22
|
+
if (typeof i.value !== "boolean")
|
|
23
|
+
return "invalid";
|
|
24
|
+
if (i.type !== "task")
|
|
25
|
+
return { ignored: "not-a-task" };
|
|
26
|
+
return i.value;
|
|
27
|
+
}
|
|
28
|
+
/** investigate 為真;明確的 true 為真;false、absent、ignored 為假。 */
|
|
29
|
+
export function effectiveReadOnly(playbook, flag) {
|
|
30
|
+
return playbook === "investigate" || flag === true;
|
|
31
|
+
}
|
|
32
|
+
/** feature 要多一個 Shape;其他 playbook 沒有額外標題。 */
|
|
33
|
+
export function extraSections(playbook) {
|
|
34
|
+
return playbook === "feature" ? ["Shape"] : [];
|
|
35
|
+
}
|
|
36
|
+
export function wakeIsReadOnly(messages) {
|
|
37
|
+
return (messages.length > 0 &&
|
|
38
|
+
messages.every((m) => m.type === "task" &&
|
|
39
|
+
effectiveReadOnly(isPlaybook(m.playbook) ? m.playbook : undefined, m.read_only === true ? true : m.read_only === false ? false : "absent")));
|
|
40
|
+
}
|
package/dist/policy.d.ts
CHANGED
|
@@ -60,6 +60,18 @@ export declare function ownAgentDirAllowed(project: ResolvedProject, agent: Reso
|
|
|
60
60
|
/** True when `shared/common/` does not overlap another agent's persona, memory, inbox or outbox. */
|
|
61
61
|
export declare function projectCommonDirAllowed(project: ResolvedProject, agent: ResolvedAgent): boolean;
|
|
62
62
|
export declare function writePolicy(project: ResolvedProject, agent: ResolvedAgent): WritePolicy;
|
|
63
|
+
/**
|
|
64
|
+
* A team lead's wake. The lead coordinates: mail, records, handoff notes, and `AGENT.md` files outside the repo stay writable.
|
|
65
|
+
* The repo stays in `readDirs`. `sandbox.write`, the git dir, and in-repo instruction files are not writable: Codex widens an
|
|
66
|
+
* allow-file to its parent directory, so a repo `CLAUDE.md` would open the whole tree. `run --agent` does not use this policy.
|
|
67
|
+
*/
|
|
68
|
+
export declare function coordinatePolicy(project: ResolvedProject, agent: ResolvedAgent): WritePolicy;
|
|
69
|
+
/**
|
|
70
|
+
* 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`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function readOnlyPolicy(project: ResolvedProject, agent: ResolvedAgent): WritePolicy;
|
|
63
75
|
export declare function osSandboxAvailable(): boolean;
|
|
64
76
|
/** Test seam: pretend the OS sandbox is (un)available; `undefined` re-probes the host. */
|
|
65
77
|
export declare function setOsSandboxForTest(available: boolean | undefined): void;
|
package/dist/policy.js
CHANGED
|
@@ -217,6 +217,61 @@ export function writePolicy(project, agent) {
|
|
|
217
217
|
deny: [...new Set(deny)],
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
|
+
/** A path is the repo root or a file inside it. Missing files still resolve. */
|
|
221
|
+
function insideRepo(repo, target) {
|
|
222
|
+
const root = canonicalPath(repo);
|
|
223
|
+
const file = canonicalPath(target);
|
|
224
|
+
return file === root || file.startsWith(root + path.sep);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A team lead's wake. The lead coordinates: mail, records, handoff notes, and `AGENT.md` files outside the repo stay writable.
|
|
228
|
+
* The repo stays in `readDirs`. `sandbox.write`, the git dir, and in-repo instruction files are not writable: Codex widens an
|
|
229
|
+
* allow-file to its parent directory, so a repo `CLAUDE.md` would open the whole tree. `run --agent` does not use this policy.
|
|
230
|
+
*/
|
|
231
|
+
export function coordinatePolicy(project, agent) {
|
|
232
|
+
const normal = writePolicy(project, agent);
|
|
233
|
+
const repo = repoDirFor(project, agent.name);
|
|
234
|
+
const outside = (p) => !insideRepo(repo, p);
|
|
235
|
+
const ownDir = projectAgentDir(project, agent.name);
|
|
236
|
+
const grantOwnDir = ownAgentDirAllowed(project, agent);
|
|
237
|
+
const isLead = agent.name === project.lead && !project.solo;
|
|
238
|
+
const shared = sharedDir(project);
|
|
239
|
+
const allowDirs = [
|
|
240
|
+
...memoryDirs(agent),
|
|
241
|
+
...(project.solo === "call" ? [] : [outboxDir(project, agent.name)]),
|
|
242
|
+
...(grantOwnDir ? [ownDir] : []),
|
|
243
|
+
...(isLead ? [recordsDir(project)] : []),
|
|
244
|
+
...(isLead || mayPropose(project) ? [proposalsDir(project)] : []),
|
|
245
|
+
...(shared && agent.name === project.lead ? [shared] : []),
|
|
246
|
+
].filter(outside);
|
|
247
|
+
return {
|
|
248
|
+
allowDirs,
|
|
249
|
+
allowFiles: normal.allowFiles.filter(outside),
|
|
250
|
+
readDirs: [...new Set([repo, ...normal.readDirs, ...normal.allowDirs.filter((d) => !allowDirs.includes(d))])],
|
|
251
|
+
deny: normal.deny,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 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`.
|
|
258
|
+
*/
|
|
259
|
+
export function readOnlyPolicy(project, agent) {
|
|
260
|
+
const normal = writePolicy(project, agent);
|
|
261
|
+
const ownDir = projectAgentDir(project, agent.name);
|
|
262
|
+
const grantOwnDir = ownAgentDirAllowed(project, agent);
|
|
263
|
+
const allowDirs = [
|
|
264
|
+
...memoryDirs(agent),
|
|
265
|
+
...(project.solo === "call" ? [] : [outboxDir(project, agent.name)]),
|
|
266
|
+
...(grantOwnDir ? [ownDir] : []),
|
|
267
|
+
];
|
|
268
|
+
return {
|
|
269
|
+
allowDirs,
|
|
270
|
+
allowFiles: [],
|
|
271
|
+
readDirs: [...new Set([repoDirFor(project, agent.name), ...normal.readDirs, ...normal.allowDirs.filter((d) => !allowDirs.includes(d))])],
|
|
272
|
+
deny: normal.deny,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
220
275
|
let sandboxProbe;
|
|
221
276
|
export function osSandboxAvailable() {
|
|
222
277
|
if (sandboxProbe !== undefined)
|
package/dist/project-lock.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type WorkspacePlan } from "./worktree.js";
|
|
1
2
|
/** The project-wide lock of older versions. Still read (it counts as one active run) and cleared; never written. */
|
|
2
3
|
export declare const LOCK_FILE = "lock.json";
|
|
3
4
|
/** One lock file per active run: `<project home>/locks/<run-id>.json`. */
|
|
@@ -75,7 +76,22 @@ export declare function listRunLocks(root: string): LockInfo[];
|
|
|
75
76
|
export declare function listUnreadableRunLocks(root: string): string[];
|
|
76
77
|
/** The lock a run holds (per-run file, or an older version's `lock.json` written for that run), if readable. */
|
|
77
78
|
export declare function inspectRunLock(root: string, runId: string): LockInfo | undefined;
|
|
79
|
+
/** Another run holds the project checkout. A caller that can work in a worktree instead catches this (and nothing else) to do so. */
|
|
80
|
+
export declare class CheckoutBusyError extends Error {
|
|
81
|
+
readonly holder: LockInfo;
|
|
82
|
+
constructor(holder: LockInfo, dir: string, reason: string);
|
|
83
|
+
}
|
|
78
84
|
export declare function acquireProjectLock(root: string, runId: string, opts?: LockOptions): ProjectLease;
|
|
85
|
+
/**
|
|
86
|
+
* Take the lock for a new run that intends to borrow the project checkout. If the checkout is held by another run, or (once we hold
|
|
87
|
+
* it) `recheck` says it is no longer fit to borrow, take a worktree lock instead and return the plan with the lead in its own worktree.
|
|
88
|
+
* Any other error from `acquire` is the caller's. `why`, when given, is asked after the fallback was decided; its answer is
|
|
89
|
+
* `lockFallback` on the returned plan, so the run can log it. Nothing is written here.
|
|
90
|
+
*/
|
|
91
|
+
export declare function lockForPlan(intended: WorkspacePlan, acquire: (checkout: boolean) => ProjectLease, recheck: () => boolean, why?: () => string): {
|
|
92
|
+
lease: ProjectLease;
|
|
93
|
+
plan: WorkspacePlan;
|
|
94
|
+
};
|
|
79
95
|
/**
|
|
80
96
|
* Remove a lock regardless of owner (the `clear --lock --force` escape hatch). With a run id: that run's lock (and an
|
|
81
97
|
* older version's `lock.json` when it was written for that run). Without: only the older project-wide `lock.json`.
|
package/dist/project-lock.js
CHANGED
|
@@ -4,6 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { atomicWrite } from "./fs-util.js";
|
|
7
|
+
import { toLeadWorktree } from "./worktree.js";
|
|
7
8
|
/** The project-wide lock of older versions. Still read (it counts as one active run) and cleared; never written. */
|
|
8
9
|
export const LOCK_FILE = "lock.json";
|
|
9
10
|
/** One lock file per active run: `<project home>/locks/<run-id>.json`. */
|
|
@@ -209,9 +210,18 @@ function heldError(info) {
|
|
|
209
210
|
return new Error(`Run ${info.run_id} is still running (pid ${info.pid}, heartbeat ${Number.isFinite(late) ? late : "?"}s ago). ` +
|
|
210
211
|
`A run cannot be started or resumed twice; wait for it to end, or stop it first.`);
|
|
211
212
|
}
|
|
213
|
+
/** Another run holds the project checkout. A caller that can work in a worktree instead catches this (and nothing else) to do so. */
|
|
214
|
+
export class CheckoutBusyError extends Error {
|
|
215
|
+
holder;
|
|
216
|
+
constructor(holder, dir, reason) {
|
|
217
|
+
super(`Run ${holder.run_id} (pid ${holder.pid}) is working directly in ${dir}, and this run would too (${reason}), so only one can be active. ` +
|
|
218
|
+
`Wait for it to end or stop it; in a git repo with a commit, runs work in their own worktrees and can run side by side.`);
|
|
219
|
+
this.name = "CheckoutBusyError";
|
|
220
|
+
this.holder = holder;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
212
223
|
function checkoutBusyError(holder, dir, reason) {
|
|
213
|
-
return new
|
|
214
|
-
`Wait for it to end or stop it; in a git repo with a commit, runs work in their own worktrees and can run side by side.`);
|
|
224
|
+
return new CheckoutBusyError(holder, dir, reason);
|
|
215
225
|
}
|
|
216
226
|
function exclusiveError(holder) {
|
|
217
227
|
return new Error(`${holder.run_id} (pid ${holder.pid}) needs the project to itself (a memory tidy or restore); wait for it to finish, then try again.`);
|
|
@@ -371,6 +381,28 @@ export function acquireProjectLock(root, runId, opts = {}) {
|
|
|
371
381
|
release,
|
|
372
382
|
};
|
|
373
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Take the lock for a new run that intends to borrow the project checkout. If the checkout is held by another run, or (once we hold
|
|
386
|
+
* it) `recheck` says it is no longer fit to borrow, take a worktree lock instead and return the plan with the lead in its own worktree.
|
|
387
|
+
* Any other error from `acquire` is the caller's. `why`, when given, is asked after the fallback was decided; its answer is
|
|
388
|
+
* `lockFallback` on the returned plan, so the run can log it. Nothing is written here.
|
|
389
|
+
*/
|
|
390
|
+
export function lockForPlan(intended, acquire, recheck, why) {
|
|
391
|
+
const fallback = () => ({ ...toLeadWorktree(intended), ...(why ? { lockFallback: why() } : {}) });
|
|
392
|
+
let lease;
|
|
393
|
+
try {
|
|
394
|
+
lease = acquire(true);
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
if (!(e instanceof CheckoutBusyError))
|
|
398
|
+
throw e;
|
|
399
|
+
return { lease: acquire(false), plan: fallback() };
|
|
400
|
+
}
|
|
401
|
+
if (recheck())
|
|
402
|
+
return { lease, plan: intended };
|
|
403
|
+
lease.release();
|
|
404
|
+
return { lease: acquire(false), plan: fallback() };
|
|
405
|
+
}
|
|
374
406
|
/**
|
|
375
407
|
* Remove a lock regardless of owner (the `clear --lock --force` escape hatch). With a run id: that run's lock (and an
|
|
376
408
|
* older version's `lock.json` when it was written for that run). Without: only the older project-wide `lock.json`.
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ResolvedAgent, ResolvedProject } from "./config.js";
|
|
2
2
|
import type { Message } from "./mailbox.js";
|
|
3
3
|
import type { Layer, MemoryFile, MissingPath, ProjectChanges } from "./memory-tidy.js";
|
|
4
|
+
/** How the lead labels a task, and how a member reads that label. Placed before the message-format rules, and therefore before the lead's wake-economy rules. */
|
|
5
|
+
export declare const PLAYBOOK_SECTION: readonly ["## Playbooks", "On a new task you send, set `playbook` to one of: investigate, fix, feature, refactor. Leave it out only when none of these fits.", "- `investigate`: read only. Do not change product code. The dispatcher runs that wake without a writable repo. The reply puts the answer under Open items and `None` under Changes.", "- `fix`: the acceptance criteria names the check that fails before the fix and passes after.", "- `feature`: add a `## Shape` heading that names the data type or module boundary before any edit.", "- `refactor`: behavior stays the same. The acceptance criteria names the check that already passes and must still pass.", "`playbook: investigate` is read-only even without `read_only: true`. You may also set `read_only: true` on a task that must not edit the repo. A teammate cannot set either field.", "A review task, including asking QA to check someone else's work, is `read_only: true`. In a shared-folder run that is what keeps the reviewer from being treated as an author."];
|
|
4
6
|
/** Lead-only rules that keep the number of wake-ups down; placed after the progress-tracking block. */
|
|
5
7
|
export declare const WAKE_ECONOMY_SECTION: string[];
|
|
6
8
|
/** The lead's system prompt gets this at its very end when same-role instances are possible in the run (spec 23.12). No trailing newline. */
|
package/dist/prompt.js
CHANGED
|
@@ -33,13 +33,24 @@ function memoryBlock(agent, dir) {
|
|
|
33
33
|
out.push("</memory>");
|
|
34
34
|
return out;
|
|
35
35
|
}
|
|
36
|
+
/** How the lead labels a task, and how a member reads that label. Placed before the message-format rules, and therefore before the lead's wake-economy rules. */
|
|
37
|
+
export const PLAYBOOK_SECTION = [
|
|
38
|
+
"## Playbooks",
|
|
39
|
+
"On a new task you send, set `playbook` to one of: investigate, fix, feature, refactor. Leave it out only when none of these fits.",
|
|
40
|
+
"- `investigate`: read only. Do not change product code. The dispatcher runs that wake without a writable repo. The reply puts the answer under Open items and `None` under Changes.",
|
|
41
|
+
"- `fix`: the acceptance criteria names the check that fails before the fix and passes after.",
|
|
42
|
+
"- `feature`: add a `## Shape` heading that names the data type or module boundary before any edit.",
|
|
43
|
+
"- `refactor`: behavior stays the same. The acceptance criteria names the check that already passes and must still pass.",
|
|
44
|
+
"`playbook: investigate` is read-only even without `read_only: true`. You may also set `read_only: true` on a task that must not edit the repo. A teammate cannot set either field.",
|
|
45
|
+
"A review task, including asking QA to check someone else's work, is `read_only: true`. In a shared-folder run that is what keeps the reviewer from being treated as an author.",
|
|
46
|
+
];
|
|
36
47
|
/** Lead-only rules that keep the number of wake-ups down; placed after the progress-tracking block. */
|
|
37
48
|
export const WAKE_ECONOMY_SECTION = [
|
|
38
49
|
"## Keeping wake-ups few",
|
|
39
50
|
"Every wake-up re-reads your whole context (prompt, memory, mail), so the number of wake-ups, yours and your teammates', is the main cost of a run.",
|
|
40
51
|
"- Send all work that is independent of each other in the same wake-up (for example the implementation and the matching docs), each task naming its reviewer, instead of one task per wake-up.",
|
|
41
52
|
"- When a reply arrives while other work you sent is still out and the reply needs nothing from you yet, send no mail: note it in your task memory and end the wake-up. Decide the next step once, when the rest is back; replies waiting together are handed to you in one wake-up.",
|
|
42
|
-
"-
|
|
53
|
+
"- When a teammate uses a different runtime from the people who wrote the change, a `completed` done is sent back until one of those teammates has replied with `verdict: pass` in this segment. Your own pass does not count. A review task is `read_only: true`. A small fix still needs that reply when such a teammate exists. When every teammate shares your runtime, no such reply is required. When nobody else can give that pass, the done is accepted without it. `verify.cross_runtime: false` turns the gate off.",
|
|
43
54
|
"- Use the most capable (most expensive) model only at three moments: before the plan is final, when the same error shows up a second time, and before you send `done`. In other rounds prefer teammates on cheaper models; read-only search work suits the cheapest one.",
|
|
44
55
|
];
|
|
45
56
|
/** The lead's system prompt gets this at its very end when same-role instances are possible in the run (spec 23.12). No trailing newline. */
|
|
@@ -121,8 +132,11 @@ function writeScopeRules(project, agent) {
|
|
|
121
132
|
: `- The shared team context is in \`${commonPath}\` (read-only). Project records are ${records} Both are read-only.`,
|
|
122
133
|
...(mayWriteOwn ? [`- You may write your project agent directory \`${ownDir}/\`. Creating \`AGENT.md\` there makes it this project's persona on the next run; the global persona file stays read-only.`] : []),
|
|
123
134
|
...(ownPersona ? [`- You may edit your project persona \`${agent.agentMd}\`.`] : []),
|
|
135
|
+
...(isLead ? ["- You do not edit product code. Send that work to a teammate. A one-line fix is `run --agent <name>` of the agent who writes it. You still write mail, records, and handoff notes."] : []),
|
|
124
136
|
...(agent.canEditAgentMd
|
|
125
|
-
?
|
|
137
|
+
? isLead
|
|
138
|
+
? ["- You may edit `AGENT.md` files that live outside the repository. You do not edit the repository's `CLAUDE.md`/`AGENTS.md`."]
|
|
139
|
+
: ["- You may edit every `AGENT.md` and the repository's `CLAUDE.md`/`AGENTS.md`; those changes are logged."]
|
|
126
140
|
: ["- Never edit another agent's AGENT.md, a global `AGENT.md`, or the repository's own `CLAUDE.md`/`AGENTS.md`."]),
|
|
127
141
|
"- Never touch another agent's memory, inbox or outbox, or the configuration files of agent-lyceum (`project.yaml`, `team.yaml`, `runs/`).",
|
|
128
142
|
];
|
|
@@ -258,9 +272,11 @@ export function buildSystemPrompt(project, agent) {
|
|
|
258
272
|
const isLead = agent.name === project.lead;
|
|
259
273
|
const lines = [];
|
|
260
274
|
lines.push(readPersona(agent), "", "---", "", "# Team protocol (injected by agent-lyceum)", "");
|
|
261
|
-
lines.push(
|
|
262
|
-
? `You are **${agent.name}**,
|
|
263
|
-
:
|
|
275
|
+
lines.push(isLead
|
|
276
|
+
? `You are **${agent.name}**, the lead of the team "${project.name}". You do not edit product code. You read the repository \`${repoDirFor(project, agent.name)}\` and send the change to a teammate. A one-line fix is \`run --agent <name>\` of the agent who writes it.`
|
|
277
|
+
: agent.instance && agent.instance.k >= 2
|
|
278
|
+
? `You are **${agent.name}**, instance ${agent.instance.k} of **${agent.instance.role}** in the team "${project.name}". Other instances of ${agent.instance.role} may be working on other tasks at the same time, each in its own worktree. You work in the repository \`${repoDirFor(project, agent.name)}\`.`
|
|
279
|
+
: `You are **${agent.name}**, a member of the team "${project.name}". You work in the repository \`${repoDirFor(project, agent.name)}\`.`, ...(agent.instance?.k === 1
|
|
264
280
|
? [
|
|
265
281
|
`Other instances of you${(() => {
|
|
266
282
|
const names = Object.values(project.agents).filter((a) => a.instance?.role === agent.name && a.instance.k >= 2).map((a) => a.name);
|
|
@@ -269,13 +285,15 @@ export function buildSystemPrompt(project, agent) {
|
|
|
269
285
|
]
|
|
270
286
|
: []), ...(project.workspaces?.[agent.name]
|
|
271
287
|
? [
|
|
272
|
-
|
|
288
|
+
isLead
|
|
289
|
+
? `That directory is the run's checkout (branch \`${project.workspaces[agent.name]?.branch}\`). Edits you make there are removed when this wake ends. Do not commit, push, switch branches or touch any other checkout. A one-line fix is \`run --agent <name>\` of the agent who writes it.`
|
|
290
|
+
: `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.`,
|
|
273
291
|
]
|
|
274
292
|
: []), `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
|
|
275
293
|
? `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.`
|
|
276
294
|
: `Report results to the lead by mail; the lead decides what happens next.`, isLead
|
|
277
295
|
? "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."
|
|
278
|
-
: "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
|
|
296
|
+
: "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.", "", ...PLAYBOOK_SECTION, "", "## 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, except `## Acceptance criteria`: that section needs a `command` in backticks, a file name or a test name, and writing `None` is sent back).", "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
|
|
279
297
|
? "- `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`; one entry per choice: what you chose, then what you rejected and why; leave follow-ups to `## Not done`) 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
|
|
280
298
|
: "- `done` has no required headings.", ...(agent.canAskUser
|
|
281
299
|
? [
|
package/dist/quota.js
CHANGED
|
@@ -50,9 +50,16 @@ function windowOf(label, used, resets) {
|
|
|
50
50
|
function roundPercent(n) {
|
|
51
51
|
return Math.round(n * 10) / 10;
|
|
52
52
|
}
|
|
53
|
+
const CLAUDE_USAGE = ["-p", "--no-session-persistence", "--output-format", "text", "/usage"];
|
|
54
|
+
const CODEX_LIMITS = ["app-server", "--stdio"];
|
|
55
|
+
const CODEX_LIMITS_NO_PLUGINS = ["app-server", "--disable", "plugins", "--stdio"];
|
|
56
|
+
const CLAUDE_ADDED_OPTIONS = ["--safe-mode"];
|
|
57
|
+
const CODEX_ADDED_OPTIONS = ["--disable", "plugins"];
|
|
53
58
|
export async function claudeQuota(signal) {
|
|
54
59
|
try {
|
|
55
|
-
|
|
60
|
+
let text = await capture("claude", ["--safe-mode", ...CLAUDE_USAGE], 20_000, signal);
|
|
61
|
+
if (optionRejected(text, CLAUDE_ADDED_OPTIONS))
|
|
62
|
+
text = await capture("claude", CLAUDE_USAGE, 20_000, signal);
|
|
56
63
|
const windows = parseClaudeUsage(text.stdout);
|
|
57
64
|
if (windows.length === 0)
|
|
58
65
|
return { runtime: "claude", windows: [], error: firstLine(text.stderr) || firstLine(text.stdout) || "claude /usage 沒有回傳額度。" };
|
|
@@ -66,7 +73,15 @@ export async function claudeQuota(signal) {
|
|
|
66
73
|
}
|
|
67
74
|
export async function codexQuota(signal) {
|
|
68
75
|
try {
|
|
69
|
-
|
|
76
|
+
let limits;
|
|
77
|
+
try {
|
|
78
|
+
limits = await readCodexLimits(signal, CODEX_LIMITS_NO_PLUGINS);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (isAbort(error) || !(error instanceof OptionRejected))
|
|
82
|
+
throw error;
|
|
83
|
+
limits = await readCodexLimits(signal, CODEX_LIMITS);
|
|
84
|
+
}
|
|
70
85
|
return { runtime: "codex", windows: codexWindows(limits) };
|
|
71
86
|
}
|
|
72
87
|
catch (error) {
|
|
@@ -347,35 +362,61 @@ function missing(cmd, error) {
|
|
|
347
362
|
function firstLine(text) {
|
|
348
363
|
return text.split("\n").map((line) => line.trim()).find(Boolean) ?? "";
|
|
349
364
|
}
|
|
365
|
+
/** An old CLI that does not know the new flag. Timeouts and aborts are not this. */
|
|
366
|
+
class OptionRejected extends Error {
|
|
367
|
+
constructor(message) {
|
|
368
|
+
super(message);
|
|
369
|
+
this.name = "OptionRejected";
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/** The rejection names one of the flags this version added. Any other unknown option stays a real failure. */
|
|
373
|
+
function addedOptionRejected(text, added) {
|
|
374
|
+
for (const match of text.matchAll(/(?:unknown option|unexpected argument)\s+(['"]?)([^\s'"]+)\1/gi)) {
|
|
375
|
+
const name = match[2];
|
|
376
|
+
if (name && added.includes(name))
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
function optionRejected(out, added) {
|
|
382
|
+
return out.code !== 0 && out.code !== null && addedOptionRejected(`${out.stderr}\n${out.stdout}`, added);
|
|
383
|
+
}
|
|
350
384
|
function capture(cmd, args, timeoutMs, signal) {
|
|
351
385
|
return new Promise((resolve, reject) => {
|
|
352
386
|
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"], ...(signal ? { signal } : {}) });
|
|
353
387
|
let stdout = "";
|
|
354
388
|
let stderr = "";
|
|
389
|
+
let settled = false;
|
|
355
390
|
const timer = setTimeout(() => {
|
|
391
|
+
if (settled)
|
|
392
|
+
return;
|
|
393
|
+
settled = true;
|
|
356
394
|
child.kill();
|
|
357
395
|
reject(new Error(`${cmd} 超過 ${Math.round(timeoutMs / 1000)} 秒沒有回應。`));
|
|
358
396
|
}, timeoutMs);
|
|
359
397
|
child.stdout.on("data", (chunk) => (stdout += String(chunk)));
|
|
360
398
|
child.stderr.on("data", (chunk) => (stderr += String(chunk)));
|
|
361
399
|
child.on("error", (error) => {
|
|
400
|
+
if (settled)
|
|
401
|
+
return;
|
|
402
|
+
settled = true;
|
|
362
403
|
clearTimeout(timer);
|
|
363
404
|
reject(error);
|
|
364
405
|
});
|
|
365
|
-
child.on("close", () => {
|
|
406
|
+
child.on("close", (code) => {
|
|
407
|
+
if (settled)
|
|
408
|
+
return;
|
|
409
|
+
settled = true;
|
|
366
410
|
clearTimeout(timer);
|
|
367
|
-
resolve({ stdout, stderr });
|
|
411
|
+
resolve({ stdout, stderr, code });
|
|
368
412
|
});
|
|
369
413
|
});
|
|
370
414
|
}
|
|
371
|
-
function readCodexLimits(signal) {
|
|
415
|
+
function readCodexLimits(signal, args) {
|
|
372
416
|
return new Promise((resolve, reject) => {
|
|
373
|
-
const child = spawn("codex",
|
|
417
|
+
const child = spawn("codex", args, { stdio: ["pipe", "pipe", "pipe"], ...(signal ? { signal } : {}) });
|
|
374
418
|
let buf = "";
|
|
375
|
-
|
|
376
|
-
child.kill();
|
|
377
|
-
reject(new Error("codex 超過 20 秒沒有回應。"));
|
|
378
|
-
}, 20_000);
|
|
419
|
+
let stderr = "";
|
|
379
420
|
let done = false;
|
|
380
421
|
const finish = (error, limits) => {
|
|
381
422
|
if (done)
|
|
@@ -388,7 +429,18 @@ function readCodexLimits(signal) {
|
|
|
388
429
|
else
|
|
389
430
|
resolve(limits ?? {});
|
|
390
431
|
};
|
|
432
|
+
const timer = setTimeout(() => {
|
|
433
|
+
finish(new Error("codex 超過 20 秒沒有回應。"));
|
|
434
|
+
}, 20_000);
|
|
391
435
|
child.on("error", (error) => finish(error));
|
|
436
|
+
child.stderr.on("data", (chunk) => (stderr += String(chunk)));
|
|
437
|
+
child.on("close", (code) => {
|
|
438
|
+
const text = `${stderr}\n${buf}`;
|
|
439
|
+
if (code !== 0 && code !== null && addedOptionRejected(text, CODEX_ADDED_OPTIONS))
|
|
440
|
+
finish(new OptionRejected(firstLine(text)));
|
|
441
|
+
else
|
|
442
|
+
finish(new Error(firstLine(stderr) || firstLine(buf) || "codex 沒有回傳額度。"));
|
|
443
|
+
});
|
|
392
444
|
child.stdout.on("data", (chunk) => {
|
|
393
445
|
buf += String(chunk);
|
|
394
446
|
let cut = buf.indexOf("\n");
|
package/dist/records.d.ts
CHANGED
|
@@ -14,9 +14,19 @@ export interface ProjectRecord {
|
|
|
14
14
|
supersedes: string[];
|
|
15
15
|
title: string;
|
|
16
16
|
body: string;
|
|
17
|
+
/** How many times this lesson has come up. Absent when the file does not say. */
|
|
18
|
+
seen?: number;
|
|
19
|
+
/** The only guard a lesson may ask the doctor to check. */
|
|
20
|
+
guard?: "verify-configured";
|
|
17
21
|
/** Why the entry could not be read as a record; set entries still count as active so nothing silently disappears. */
|
|
18
22
|
invalid?: string;
|
|
19
23
|
}
|
|
24
|
+
/** Doctor findings for lessons that keep coming back. Superseded lessons are skipped. Nothing here runs a shell. */
|
|
25
|
+
export declare function lessonGuardFindings(lessons: readonly ProjectRecord[], verifyCommandCount: number): {
|
|
26
|
+
level: "warn" | "error";
|
|
27
|
+
file: string;
|
|
28
|
+
message: string;
|
|
29
|
+
}[];
|
|
20
30
|
/** Every `*.md` entry of one kind, sorted by id. Entries that cannot be parsed are listed with `invalid` set; a missing folder is an empty list. */
|
|
21
31
|
export declare function listRecords(project: ResolvedProject, kind: RecordKind): ProjectRecord[];
|
|
22
32
|
/** Decisions kept from cleared runs, same file format as a record. A missing or symlinked folder is an empty list. */
|
package/dist/records.js
CHANGED
|
@@ -50,6 +50,20 @@ function parseEntry(kind, file) {
|
|
|
50
50
|
}
|
|
51
51
|
if (f.run !== undefined && typeof f.run !== "string")
|
|
52
52
|
problems.push("run must be a string");
|
|
53
|
+
let seen;
|
|
54
|
+
if (f.seen !== undefined) {
|
|
55
|
+
if (typeof f.seen === "number" && Number.isInteger(f.seen) && f.seen >= 1)
|
|
56
|
+
seen = f.seen;
|
|
57
|
+
else
|
|
58
|
+
problems.push("seen must be a positive integer");
|
|
59
|
+
}
|
|
60
|
+
let guard;
|
|
61
|
+
if (f.guard !== undefined) {
|
|
62
|
+
if (f.guard === "verify-configured")
|
|
63
|
+
guard = "verify-configured";
|
|
64
|
+
else
|
|
65
|
+
problems.push("guard must be verify-configured");
|
|
66
|
+
}
|
|
53
67
|
if (problems.length)
|
|
54
68
|
return { ...fallback, body, invalid: problems.join("; ") };
|
|
55
69
|
return {
|
|
@@ -62,8 +76,40 @@ function parseEntry(kind, file) {
|
|
|
62
76
|
supersedes,
|
|
63
77
|
title: f.title.trim(),
|
|
64
78
|
body,
|
|
79
|
+
...(seen !== undefined ? { seen } : {}),
|
|
80
|
+
...(guard ? { guard } : {}),
|
|
65
81
|
};
|
|
66
82
|
}
|
|
83
|
+
function lessonTitle(title) {
|
|
84
|
+
return title.trim().toLowerCase().replace(/\s+/g, " ");
|
|
85
|
+
}
|
|
86
|
+
/** Doctor findings for lessons that keep coming back. Superseded lessons are skipped. Nothing here runs a shell. */
|
|
87
|
+
export function lessonGuardFindings(lessons, verifyCommandCount) {
|
|
88
|
+
const active = effectiveActive([...lessons]).filter((r) => r.kind === "lessons" && !r.invalid);
|
|
89
|
+
const found = [];
|
|
90
|
+
for (const r of active) {
|
|
91
|
+
if (r.seen !== undefined && r.seen >= 2 && r.guard === undefined) {
|
|
92
|
+
found.push({ level: "warn", file: r.file, message: `${r.title}: seen ${r.seen} times with no guard. Set guard: verify-configured or mark it superseded.` });
|
|
93
|
+
}
|
|
94
|
+
if (r.seen !== undefined && r.seen >= 2 && r.guard === "verify-configured" && verifyCommandCount === 0) {
|
|
95
|
+
found.push({ level: "error", file: r.file, message: `${r.title}: seen ${r.seen} times and asks for verify.commands, but verify.commands is empty.` });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const byTitle = new Map();
|
|
99
|
+
for (const r of active) {
|
|
100
|
+
const key = lessonTitle(r.title);
|
|
101
|
+
const list = byTitle.get(key) ?? [];
|
|
102
|
+
list.push(r);
|
|
103
|
+
byTitle.set(key, list);
|
|
104
|
+
}
|
|
105
|
+
for (const group of byTitle.values()) {
|
|
106
|
+
if (group.length < 2)
|
|
107
|
+
continue;
|
|
108
|
+
for (const r of group)
|
|
109
|
+
found.push({ level: "warn", file: r.file, message: `duplicate lesson title "${r.title}".` });
|
|
110
|
+
}
|
|
111
|
+
return found;
|
|
112
|
+
}
|
|
67
113
|
/** Every `*.md` entry of one kind, sorted by id. Entries that cannot be parsed are listed with `invalid` set; a missing folder is an empty list. */
|
|
68
114
|
export function listRecords(project, kind) {
|
|
69
115
|
const dir = recordsKindDir(project, kind);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ResolvedProject } from "./config.js";
|
|
2
|
+
export declare function crossRuntimeBlock(project: ResolvedProject, state: {
|
|
3
|
+
reviews?: readonly {
|
|
4
|
+
reviewer: string;
|
|
5
|
+
verdict: string;
|
|
6
|
+
at: string;
|
|
7
|
+
}[];
|
|
8
|
+
/** `at` is when the files were integrated. A record with no `at` counts only when this segment has no reopen. */
|
|
9
|
+
implementers?: readonly {
|
|
10
|
+
agent: string;
|
|
11
|
+
at?: string;
|
|
12
|
+
}[];
|
|
13
|
+
reopened?: readonly {
|
|
14
|
+
at: string;
|
|
15
|
+
}[];
|
|
16
|
+
wakes?: readonly {
|
|
17
|
+
agent: string;
|
|
18
|
+
at: string;
|
|
19
|
+
runtime?: string;
|
|
20
|
+
read_only?: boolean;
|
|
21
|
+
handling: readonly {
|
|
22
|
+
type: string;
|
|
23
|
+
}[];
|
|
24
|
+
}[];
|
|
25
|
+
}, _mode: "worktree" | "shared"): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* What `doctor` can see before a run. A team lead does not edit the repository; a one-line fix is `run --agent`.
|
|
28
|
+
* When nobody but the lead is on another runtime, a completed done does not wait for a pass. Solo runs are out of this.
|
|
29
|
+
*/
|
|
30
|
+
export declare function teamRunFindings(project: ResolvedProject): {
|
|
31
|
+
level: "info" | "warn";
|
|
32
|
+
message: string;
|
|
33
|
+
}[];
|