agent-lyceum 0.54.0 → 0.55.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/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/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.d.ts +1 -1
- 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/public/assets/index-BPY1-W3F.css +0 -2
- package/web/dist/public/assets/index-DzxHf7RE.js +0 -92
package/dist/run-store.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ import type { ResultBranch } from "./worktree.js";
|
|
|
5
5
|
import type { ReviewRecord, WorkerRef } from "./attribution.js";
|
|
6
6
|
export declare const STATE_FILE = "state.json";
|
|
7
7
|
/** The newest state format this version reads. */
|
|
8
|
-
export declare const STATE_SCHEMA_VERSION =
|
|
9
|
-
/** What a new run is written as: v3 only appears when the first parallel task opens instances (spec 23.6). */
|
|
8
|
+
export declare const STATE_SCHEMA_VERSION = 4;
|
|
9
|
+
/** What a new run is written as: v3 only appears when the first parallel task opens instances (spec 23.6); v4 only on a run that works in the project checkout on its own branch. */
|
|
10
10
|
export declare const NEW_RUN_SCHEMA_VERSION = 2;
|
|
11
|
+
/** What a run that works in the project checkout on its own branch is written as; opening instances never lowers it. */
|
|
12
|
+
export declare const CHECKOUT_SCHEMA_VERSION = 4;
|
|
11
13
|
/** Refuse a state newer than `supported`, before anything is written (the failure an older binary gives a v3 run). */
|
|
12
14
|
export declare function assertSupportedVersion(version: number | undefined, supported: number, file: string): void;
|
|
13
15
|
export type EndReason = "done" | "idle" | "max_rounds" | "lead_failed" | "agent_failed" | "cancelled" | "waiting";
|
|
@@ -54,6 +56,8 @@ export interface WakeRecord {
|
|
|
54
56
|
kind?: ErrorKind;
|
|
55
57
|
/** The tier this wake ran at (spec 24): set only when every mail it handled carried a valid one. */
|
|
56
58
|
tier?: Tier;
|
|
59
|
+
/** The wake was not allowed to edit the repo. */
|
|
60
|
+
read_only?: true;
|
|
57
61
|
}
|
|
58
62
|
/** A model given up on during a wake with a fallback chain, for `failure.tried`. */
|
|
59
63
|
export interface TriedModel {
|
|
@@ -125,7 +129,17 @@ export interface RunState {
|
|
|
125
129
|
/** Recovery remarks (interrupted attempts whose side effects may have happened). */
|
|
126
130
|
notes?: string[];
|
|
127
131
|
/** "worktree": non-lead agents work in their own git worktrees. */
|
|
128
|
-
workspace_mode?: "shared" | "worktree";
|
|
132
|
+
workspace_mode?: "shared" | "worktree" | "checkout";
|
|
133
|
+
/** Checkout runs (schema 4): the branch the lead works on, fixed when the run started; never recomputed from the lead's current name. */
|
|
134
|
+
task_branch?: string;
|
|
135
|
+
/** Checkout runs: the remote ref (`origin/main`) the run was cut from, the commit it pointed at, and the `origin` URL then. */
|
|
136
|
+
base_ref?: string;
|
|
137
|
+
base_sha?: string;
|
|
138
|
+
origin_url?: string;
|
|
139
|
+
/** Checkout runs (schema 4): written by whoever starts the run; this session only keeps it. */
|
|
140
|
+
checkout_from?: string;
|
|
141
|
+
/** Checkout runs: the task mail reached the lead's inbox. A checkout run without it is never resumed (nothing says what was sent). */
|
|
142
|
+
task_sent?: true;
|
|
129
143
|
/** Set when the run was started with `run --agent <name>`: that member works alone (a resumed run keeps it). */
|
|
130
144
|
solo_agent?: string;
|
|
131
145
|
/** Agents whose finished work could not be brought into the repo yet; their work is kept on their branch. */
|
package/dist/run-store.js
CHANGED
|
@@ -7,9 +7,11 @@ import { atomicWrite } from "./fs-util.js";
|
|
|
7
7
|
import { ERROR_KINDS, RUNTIMES } from "./schema.js";
|
|
8
8
|
export const STATE_FILE = "state.json";
|
|
9
9
|
/** The newest state format this version reads. */
|
|
10
|
-
export const STATE_SCHEMA_VERSION =
|
|
11
|
-
/** What a new run is written as: v3 only appears when the first parallel task opens instances (spec 23.6). */
|
|
10
|
+
export const STATE_SCHEMA_VERSION = 4;
|
|
11
|
+
/** What a new run is written as: v3 only appears when the first parallel task opens instances (spec 23.6); v4 only on a run that works in the project checkout on its own branch. */
|
|
12
12
|
export const NEW_RUN_SCHEMA_VERSION = 2;
|
|
13
|
+
/** What a run that works in the project checkout on its own branch is written as; opening instances never lowers it. */
|
|
14
|
+
export const CHECKOUT_SCHEMA_VERSION = STATE_SCHEMA_VERSION;
|
|
13
15
|
/** Refuse a state newer than `supported`, before anything is written (the failure an older binary gives a v3 run). */
|
|
14
16
|
export function assertSupportedVersion(version, supported, file) {
|
|
15
17
|
if ((version ?? 1) > supported) {
|
|
@@ -85,6 +87,12 @@ const WireState = z
|
|
|
85
87
|
tidy: z.boolean().optional(),
|
|
86
88
|
reopened: z.array(z.object({ at: z.string() })).optional(),
|
|
87
89
|
round_floor: nonNeg.optional(),
|
|
90
|
+
task_branch: z.string().optional(),
|
|
91
|
+
base_ref: z.string().optional(),
|
|
92
|
+
base_sha: z.string().optional(),
|
|
93
|
+
origin_url: z.string().optional(),
|
|
94
|
+
checkout_from: z.string().optional(),
|
|
95
|
+
task_sent: z.literal(true).optional(),
|
|
88
96
|
instances: z.object({ roles: z.record(z.string(), z.array(z.string()).min(1)) }).optional(),
|
|
89
97
|
})
|
|
90
98
|
.passthrough();
|
package/dist/scaffold.d.ts
CHANGED
|
@@ -1,7 +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
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.";
|
|
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. When a new lesson repeats an active lesson's title, do not add a second file. Set `seen` to the next integer on the existing one. Set `guard: verify-configured` only when the fix is that project.yaml should list verify commands. Do not put a shell command in the lesson.";
|
|
5
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";
|
|
6
6
|
export interface InitResult {
|
|
7
7
|
home: string;
|
package/dist/scaffold.js
CHANGED
|
@@ -5,7 +5,7 @@ import { RECORDS_BUDGET } from "./records.js";
|
|
|
5
5
|
/** The lead's guidance on `parallel: true` (spec 23.12 point 5). Only `init` writes it, into a new lead AGENT.md. */
|
|
6
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.";
|
|
7
7
|
/** The lead's guidance on the `## Decisions` and `## Not done` sections of `done`. Only `init` writes it, into a new lead AGENT.md. */
|
|
8
|
-
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.";
|
|
8
|
+
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. When a new lesson repeats an active lesson's title, do not add a second file. Set `seen` to the next integer on the existing one. Set `guard: verify-configured` only when the fix is that project.yaml should list verify commands. Do not put a shell command in the lesson.";
|
|
9
9
|
const PERSONAS = {
|
|
10
10
|
lead: `# Lead
|
|
11
11
|
|
|
@@ -17,6 +17,8 @@ You coordinate the team. You receive the user's task, break it into concrete pie
|
|
|
17
17
|
- When a teammate reports back, decide the next step: assign follow-up work, ask another teammate to verify, or accept the result.
|
|
18
18
|
- Teammates cannot message each other by default; route everything through yourself.
|
|
19
19
|
- ${LEAD_PARALLEL_HINT}
|
|
20
|
+
- Set \`playbook\` on every task you send (investigate, fix, feature, or refactor) and make every acceptance item a command, a file or a test name.
|
|
21
|
+
- 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.
|
|
20
22
|
- When the whole job is verified and finished, send a \`done\` message summarising what was delivered.${LEAD_DONE_HINT}
|
|
21
23
|
`,
|
|
22
24
|
"fe-member": `# Frontend member
|
|
@@ -25,6 +27,7 @@ You implement frontend work assigned by the lead: components, pages, styling, cl
|
|
|
25
27
|
|
|
26
28
|
- Read the lead's message carefully and restate the acceptance criteria to yourself before editing.
|
|
27
29
|
- Keep changes small and focused; run the project's own checks (lint, type-check, tests) when they exist.
|
|
30
|
+
- When the task says \`playbook: investigate\` or \`read_only: true\`, do not edit the repo.
|
|
28
31
|
- Fill the standard reply headings: list changed files under Changes, how you checked them under Verification, and note anything unfinished or risky.
|
|
29
32
|
`,
|
|
30
33
|
"qa-member": `# QA member
|
|
@@ -33,7 +36,7 @@ You verify work: run and write tests, reproduce bugs, and review changes against
|
|
|
33
36
|
|
|
34
37
|
- Do not fix product code yourself unless the lead asks; report findings to the lead with clear reproduction steps.
|
|
35
38
|
- Prefer concrete evidence (commands run, output, failing test names) over opinions.
|
|
36
|
-
-
|
|
39
|
+
- When you review, set \`verdict: pass\`, \`changes_requested\` or \`fail\` in the reply frontmatter. The dispatcher reads that line, not a \`## Verdict\` heading. A pass means you ran the check. On a read-only wake the repo is not writable, so a check that must write caches or build output cannot be the proof; say so under Open items.
|
|
37
40
|
`,
|
|
38
41
|
};
|
|
39
42
|
export const GLOBAL_TEAM_YAML = `# Global agent library. Projects pick agents from here by name and may override any field.
|
package/dist/schema.d.ts
CHANGED
|
@@ -139,6 +139,7 @@ export declare const DispatcherPartial: z.ZodObject<{
|
|
|
139
139
|
}, z.core.$strict>>>;
|
|
140
140
|
fallback_cooldown_sec: z.ZodOptional<z.ZodNumber>;
|
|
141
141
|
max_instances: z.ZodOptional<z.ZodNumber>;
|
|
142
|
+
max_awake: z.ZodOptional<z.ZodNumber>;
|
|
142
143
|
}, z.core.$strict>;
|
|
143
144
|
/** Settings that no longer exist; files that still carry them load, and `validate` warns. */
|
|
144
145
|
export declare const REMOVED_DISPATCHER_KEYS: readonly ["max_parallel", "max_concurrent_runs", "workspace_mode"];
|
|
@@ -224,6 +225,8 @@ export declare const VerifyCommandPartial: z.ZodObject<{
|
|
|
224
225
|
}, z.core.$strict>;
|
|
225
226
|
export declare const VerifyPartial: z.ZodObject<{
|
|
226
227
|
max_rejections: z.ZodOptional<z.ZodNumber>;
|
|
228
|
+
bind_task: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
+
cross_runtime: z.ZodOptional<z.ZodBoolean>;
|
|
227
230
|
commands: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
228
231
|
name: z.ZodString;
|
|
229
232
|
run: z.ZodString;
|
|
@@ -232,6 +235,10 @@ export declare const VerifyPartial: z.ZodObject<{
|
|
|
232
235
|
}, z.core.$strict>;
|
|
233
236
|
export interface VerifySettings {
|
|
234
237
|
max_rejections: number;
|
|
238
|
+
/** Compare the task's Verification section to `commands`. Default false. A mismatch is a note; it does not change the outcome. */
|
|
239
|
+
bind_task: boolean;
|
|
240
|
+
/** A completed done needs a cross-runtime pass when this is true. Default true. */
|
|
241
|
+
cross_runtime: boolean;
|
|
235
242
|
commands: {
|
|
236
243
|
name: string;
|
|
237
244
|
run: string;
|
|
@@ -254,6 +261,8 @@ export declare const ProjectConfig: z.ZodObject<{
|
|
|
254
261
|
}, z.core.$strict>>;
|
|
255
262
|
verify: z.ZodOptional<z.ZodObject<{
|
|
256
263
|
max_rejections: z.ZodOptional<z.ZodNumber>;
|
|
264
|
+
bind_task: z.ZodOptional<z.ZodBoolean>;
|
|
265
|
+
cross_runtime: z.ZodOptional<z.ZodBoolean>;
|
|
257
266
|
commands: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
258
267
|
name: z.ZodString;
|
|
259
268
|
run: z.ZodString;
|
|
@@ -287,6 +296,7 @@ export declare const ProjectConfig: z.ZodObject<{
|
|
|
287
296
|
}, z.core.$strict>>>;
|
|
288
297
|
fallback_cooldown_sec: z.ZodOptional<z.ZodNumber>;
|
|
289
298
|
max_instances: z.ZodOptional<z.ZodNumber>;
|
|
299
|
+
max_awake: z.ZodOptional<z.ZodNumber>;
|
|
290
300
|
}, z.core.$strict>>;
|
|
291
301
|
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
292
302
|
runtime: z.ZodOptional<z.ZodEnum<{
|
|
@@ -358,6 +368,8 @@ export interface DispatcherSettings {
|
|
|
358
368
|
fallback_cooldown_sec: number;
|
|
359
369
|
/** Most instances of one role at a time. Not in `DISPATCHER_DEFAULTS`, so `doctor --resolved` lists it only when written; the default lives in `instances.ts`. */
|
|
360
370
|
max_instances?: number;
|
|
371
|
+
/** Most non-lead agents woken in one worktree round. Not in `DISPATCHER_DEFAULTS`; the default lives in `wake-cap.ts`. */
|
|
372
|
+
max_awake?: number;
|
|
361
373
|
}
|
|
362
374
|
export declare const DISPATCHER_DEFAULTS: DispatcherSettings;
|
|
363
375
|
/** How a run turned out, independent of why it stopped (`EndReason`). Only "completed" means success. */
|
package/dist/schema.js
CHANGED
|
@@ -100,6 +100,8 @@ export const DispatcherPartial = z
|
|
|
100
100
|
fallback_cooldown_sec: z.number().int().min(0).optional(),
|
|
101
101
|
/** Most instances of one role at a time (spec 23); 1 turns parallel tasks off. Unset = `DEFAULT_MAX_INSTANCES`. */
|
|
102
102
|
max_instances: z.number().int().min(1).max(8).optional(),
|
|
103
|
+
/** Most non-lead agents woken in one worktree round. Unset = `DEFAULT_MAX_AWAKE`. */
|
|
104
|
+
max_awake: z.number().int().min(1).max(16).optional(),
|
|
103
105
|
})
|
|
104
106
|
.strict();
|
|
105
107
|
/** Settings that no longer exist; files that still carry them load, and `validate` warns. */
|
|
@@ -131,6 +133,10 @@ export const VerifyCommandPartial = z
|
|
|
131
133
|
export const VerifyPartial = z
|
|
132
134
|
.object({
|
|
133
135
|
max_rejections: z.number().int().min(0).max(5).optional(),
|
|
136
|
+
/** When true, a completed done notes checks named in the task that are not already a verify command. It does not change the outcome. */
|
|
137
|
+
bind_task: z.boolean().optional(),
|
|
138
|
+
/** When false, a completed done does not need a cross-runtime `verdict: pass`. Default true. */
|
|
139
|
+
cross_runtime: z.boolean().optional(),
|
|
134
140
|
commands: z.array(VerifyCommandPartial).default([]),
|
|
135
141
|
})
|
|
136
142
|
.strict()
|
package/dist/status.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export interface RunReport {
|
|
|
103
103
|
/** First lines of the result, for the summary page. */
|
|
104
104
|
result_head: string[];
|
|
105
105
|
mail_layout: "run" | "legacy";
|
|
106
|
-
workspace_mode?: "shared" | "worktree";
|
|
106
|
+
workspace_mode?: "shared" | "worktree" | "checkout";
|
|
107
107
|
last_wake: Record<string, {
|
|
108
108
|
at: string;
|
|
109
109
|
ok: boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Commands named in `## Verification`: a bullet that is only one backtick span, or a non-empty line inside a fence. */
|
|
2
|
+
export declare function boundCommands(taskMarkdown: string): string[];
|
|
3
|
+
/** Commands the task names that are not an exact `verify.commands[].run`. */
|
|
4
|
+
export declare function unboundCommands(taskMarkdown: string, runs: readonly string[]): string[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { sectionText } from "./format.js";
|
|
2
|
+
/** Commands named in `## Verification`: a bullet that is only one backtick span, or a non-empty line inside a fence. */
|
|
3
|
+
export function boundCommands(taskMarkdown) {
|
|
4
|
+
const text = sectionText(taskMarkdown, "Verification");
|
|
5
|
+
if (!text)
|
|
6
|
+
return [];
|
|
7
|
+
const out = [];
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
const add = (raw) => {
|
|
10
|
+
const t = raw.trim();
|
|
11
|
+
if (!t || seen.has(t))
|
|
12
|
+
return;
|
|
13
|
+
seen.add(t);
|
|
14
|
+
out.push(t);
|
|
15
|
+
};
|
|
16
|
+
let fence = false;
|
|
17
|
+
for (const line of text.split(/\r?\n/)) {
|
|
18
|
+
const trimmed = line.trim();
|
|
19
|
+
if (!fence && (trimmed === "```" || /^```[^\s`]*$/.test(trimmed))) {
|
|
20
|
+
fence = true;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (fence && trimmed === "```") {
|
|
24
|
+
fence = false;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (fence) {
|
|
28
|
+
if (trimmed)
|
|
29
|
+
add(line);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const bullet = /^[ \t]*[-*][ \t]+`([^`\n]+)`[ \t]*$/.exec(line);
|
|
33
|
+
if (bullet?.[1])
|
|
34
|
+
add(bullet[1]);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/** Commands the task names that are not an exact `verify.commands[].run`. */
|
|
39
|
+
export function unboundCommands(taskMarkdown, runs) {
|
|
40
|
+
const known = new Set(runs);
|
|
41
|
+
return boundCommands(taskMarkdown).filter((c) => !known.has(c));
|
|
42
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_AWAKE = 8;
|
|
2
|
+
/** How many of `pending` may wake together. The lead wakes alone. Shared mode wakes one. */
|
|
3
|
+
export declare function capBatch<T extends {
|
|
4
|
+
name: string;
|
|
5
|
+
}>(pending: readonly T[], leadName: string, mode: "worktree" | "shared", maxAwake: number): T[];
|
package/dist/wake-cap.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const DEFAULT_MAX_AWAKE = 8;
|
|
2
|
+
/** How many of `pending` may wake together. The lead wakes alone. Shared mode wakes one. */
|
|
3
|
+
export function capBatch(pending, leadName, mode, maxAwake) {
|
|
4
|
+
const lead = pending.find((a) => a.name === leadName);
|
|
5
|
+
if (lead)
|
|
6
|
+
return [lead];
|
|
7
|
+
if (mode !== "worktree")
|
|
8
|
+
return pending[0] ? [pending[0]] : [];
|
|
9
|
+
const n = Math.max(maxAwake, 1);
|
|
10
|
+
return pending.slice(0, n);
|
|
11
|
+
}
|
package/dist/worktree.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export interface AgentWorkspace {
|
|
|
18
18
|
base: string;
|
|
19
19
|
}
|
|
20
20
|
export declare function git(cwd: string, args: string[], env?: NodeJS.ProcessEnv): string;
|
|
21
|
+
/**
|
|
22
|
+
* What the dispatcher never lets git take from a place an agent can write. Each one was seen running a planted program:
|
|
23
|
+
* fsmonitor and hooks (post-commit runs despite --no-verify); a nested repository in the worktree, which `status` and `add`
|
|
24
|
+
* otherwise visit with git reading that repository's own config (its fsmonitor and filters); `submodule.recurse` / `diff.submodule`
|
|
25
|
+
* would do the same for reset and diff; signing runs gpg.program.
|
|
26
|
+
*/
|
|
27
|
+
export declare const PINNED_CONFIG: string[];
|
|
21
28
|
type PinnedWorkspace = Pick<AgentWorkspace, "root" | "gitDir" | "commonDir" | "worktreeConfig" | "branch">;
|
|
22
29
|
/**
|
|
23
30
|
* Refuse a worktree whose git files were rewritten in a way pinning cannot neutralise:
|
|
@@ -42,6 +49,37 @@ export declare function assertWorkspaceIntact(ws: PinnedWorkspace): void;
|
|
|
42
49
|
export declare function agentGit(ws: PinnedWorkspace, args: string[], env?: NodeJS.ProcessEnv, input?: string | Buffer): string;
|
|
43
50
|
/** `agentGit`, with a failing git command giving `undefined`. A worktree that fails `assertWorkspaceIntact` still throws. */
|
|
44
51
|
export declare function tryAgentGit(ws: PinnedWorkspace, args: string[], env?: NodeJS.ProcessEnv): string | undefined;
|
|
52
|
+
/** True when the worktree has any uncommitted or untracked path. Uses pinned git, never `dirtyPaths`. */
|
|
53
|
+
export declare function workspaceDirty(ws: AgentWorkspace): boolean;
|
|
54
|
+
/** Put the worktree back at `head` (the sha recorded on the claim) and drop untracked files. Never call this on `project.dir`. */
|
|
55
|
+
export declare function discardWorkspaceEdits(ws: AgentWorkspace, head: string): void;
|
|
56
|
+
/** HEAD and dirty paths of the user's checkout, before a read-only wake that has no worktree. Undefined when `dir` is not a git repo. */
|
|
57
|
+
export declare function snapshotCheckout(dir: string): {
|
|
58
|
+
head: string;
|
|
59
|
+
dirty: string[];
|
|
60
|
+
} | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* What changed in a checkout that has no worktree of its own since `snap`. Does not change the checkout:
|
|
63
|
+
* a borrowed folder is shared with the user, so a new path or a moved HEAD is only reported.
|
|
64
|
+
* A path that was already dirty is not listed again.
|
|
65
|
+
*/
|
|
66
|
+
export declare function borrowedEdits(dir: string, snap: {
|
|
67
|
+
head: string;
|
|
68
|
+
dirty: string[];
|
|
69
|
+
}): {
|
|
70
|
+
headMoved: boolean;
|
|
71
|
+
paths: string[];
|
|
72
|
+
};
|
|
73
|
+
/** Dirty paths in an agent worktree, using pinned git. */
|
|
74
|
+
export declare function workspaceStatusPaths(ws: AgentWorkspace): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Undo a read-only wake in an agent worktree. Earlier dirty paths stay, and the tree is not `reset --hard`
|
|
77
|
+
* or cleaned wholesale. Returns the paths that were put back. Never call this on `project.dir`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function restoreWorkspaceEdits(ws: AgentWorkspace, snap: {
|
|
80
|
+
head: string;
|
|
81
|
+
dirty: string[];
|
|
82
|
+
}): string[];
|
|
45
83
|
/**
|
|
46
84
|
* Refuse a worktree that holds a git repository of its own. `status`, `add -A` and `commit` can visit a nested repository and run
|
|
47
85
|
* git there with that repository's config — which the agent wrote. Run before any command that walks the working tree.
|
|
@@ -58,22 +96,101 @@ export declare const toplevel: (dir: string) => string;
|
|
|
58
96
|
export declare function dirtyPaths(dir: string): string[];
|
|
59
97
|
/** Why `dir` cannot give every run and agent its own git worktree, or undefined when it can. */
|
|
60
98
|
export declare function isolationBlocker(dir: string): string | undefined;
|
|
99
|
+
/** The result of one git call made through a `GitRunner`: never thrown, a failure or a timeout is `ok: false`. */
|
|
100
|
+
export interface GitRunResult {
|
|
101
|
+
ok: boolean;
|
|
102
|
+
stdout?: string;
|
|
103
|
+
stderr?: string;
|
|
104
|
+
}
|
|
105
|
+
/** Runs `git <args>` in `cwd` with `env` added to the process environment. Used for `fetch`, the only call that can wait on the network. */
|
|
106
|
+
export type GitRunner = (cwd: string, args: string[], env: NodeJS.ProcessEnv) => GitRunResult;
|
|
107
|
+
export interface RemoteBase {
|
|
108
|
+
/** `origin/main` and the like. */
|
|
109
|
+
ref: string;
|
|
110
|
+
sha: string;
|
|
111
|
+
originUrl?: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The commit new runs should start from: `origin/HEAD`, else `origin/main`, else `origin/master`.
|
|
115
|
+
* Fetches `origin` first when there is one; a fetch that fails or times out is not an error, the remote refs already in the repo are used.
|
|
116
|
+
* `onFetchFailed` is called when that fetch failed, so the caller can say so.
|
|
117
|
+
*/
|
|
118
|
+
export declare function resolveRemoteBase(dir: string, run?: GitRunner, onFetchFailed?: () => void): RemoteBase | undefined;
|
|
61
119
|
export interface WorkspacePlan {
|
|
62
120
|
mode: WorkspaceMode;
|
|
63
121
|
/** The lead works in its own worktree (isolation mode); otherwise it works in the checkout. */
|
|
64
122
|
leadWorktree: boolean;
|
|
65
|
-
/**
|
|
123
|
+
/** Set on resume of a run that works in the project checkout on its own branch: the branch its state recorded. */
|
|
124
|
+
taskBranch?: string;
|
|
125
|
+
/** The remote ref (`origin/main`) and the commit it pointed at when the plan was made. */
|
|
126
|
+
baseRef?: string;
|
|
127
|
+
baseSha?: string;
|
|
128
|
+
originUrl?: string;
|
|
129
|
+
/** Set with `taskBranch` on a new run: the branch (or commit, when detached) the checkout was on before the task branch was cut. */
|
|
130
|
+
checkoutFrom?: string;
|
|
131
|
+
/** Why the run works in the checkout, or why the lead is not in the project checkout, when it was probed. */
|
|
66
132
|
reason?: string;
|
|
133
|
+
/** `git fetch origin` failed or timed out while planning; the remote refs already in the repo were used. */
|
|
134
|
+
fetchFailed?: boolean;
|
|
135
|
+
/** Why a run that meant to borrow the project checkout was moved to its own worktree when the lock was taken (busy, or no longer fit). */
|
|
136
|
+
lockFallback?: string;
|
|
67
137
|
}
|
|
138
|
+
export interface PlanOptions {
|
|
139
|
+
/** Test seam: replaces the runner that fetches `origin`. */
|
|
140
|
+
fetch?: GitRunner;
|
|
141
|
+
/** The caller found the project checkout taken by another run; the plan then keeps the lead out of it. */
|
|
142
|
+
checkoutHeldByOther?: boolean;
|
|
143
|
+
}
|
|
144
|
+
/** The plan a run falls back to when it cannot borrow the project checkout: the lead in its own worktree, no task branch; the remote base stays. */
|
|
145
|
+
export declare function toLeadWorktree(plan: WorkspacePlan): WorkspacePlan;
|
|
146
|
+
/** Does this (new run's) plan intend to borrow the project checkout? */
|
|
147
|
+
export declare const borrowsCheckout: (plan: WorkspacePlan) => boolean;
|
|
148
|
+
/** Why the checkout cannot be borrowed now (dirty, moved off `plan.baseSha`, on an `agent-lyceum/*` branch), or undefined when it still can. Takes no lock. */
|
|
149
|
+
export declare function checkoutBlockedNow(dir: string, plan: WorkspacePlan): string | undefined;
|
|
150
|
+
/** The checkout's current branch name, or its commit when HEAD is detached: what a failed start returns to. */
|
|
151
|
+
export declare function currentCheckoutRef(dir: string): string | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Cut `branch` at `sha` and switch the checkout to it (`git checkout -b`, never `-B`: an existing branch is an error and is not reset).
|
|
154
|
+
* The repository's hooks run. Whether it worked is judged by where HEAD is before and after, not by git's exit code: a failing
|
|
155
|
+
* `post-checkout` hook still leaves HEAD on the new branch (`moved: true`), a hook that stops the switch leaves it where it was (`moved: false`).
|
|
156
|
+
*/
|
|
157
|
+
export declare function checkoutLeadBranch(dir: string, branch: string, sha: string): {
|
|
158
|
+
moved: boolean;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* A new checkout run whose state is written but whose task is not yet in the lead's inbox, taken back: the checkout returns to
|
|
162
|
+
* `checkout_from`, the task branch (when it is still at `base_sha`) and the whole run dir are removed. Call it with the run's lock held.
|
|
163
|
+
* It only ever changes what this start changed: a branch with commits of its own, a tree with uncommitted changes, or a `checkout_from`
|
|
164
|
+
* that is gone make it throw and leave the state, the branch and HEAD alone (it never tries a second switch).
|
|
165
|
+
*/
|
|
166
|
+
export declare function rollbackCheckoutStart(dir: string, runDir: string, state: RunState): void;
|
|
167
|
+
/** The first thing a new checkout run does once its state is saved (without `task_sent`): cut the task branch. On any failure the run dir is gone. */
|
|
168
|
+
export declare function beginCheckoutRun(dir: string, runDir: string, state: RunState): void;
|
|
169
|
+
/**
|
|
170
|
+
* Under the run's lock, before a checkout run goes on. Its task never reached the lead (`task_sent` missing): the start is taken back
|
|
171
|
+
* (see `rollbackCheckoutStart`) and this throws that the run is gone. Its task was sent: the checkout must still be on the task branch;
|
|
172
|
+
* it is never switched for you, and the run is not turned into a worktree run.
|
|
173
|
+
*/
|
|
174
|
+
export declare function assertCheckoutResumable(dir: string, runDir: string, state: RunState): void;
|
|
68
175
|
/**
|
|
69
176
|
* Where a run's agents work. A new run is isolated when the project dir can be (see `isolationBlocker`), otherwise it shares the
|
|
70
|
-
* checkout.
|
|
177
|
+
* checkout. When the repo has a remote base and the project checkout is clean, sits exactly on it and nobody else holds it, the lead
|
|
178
|
+
* borrows the checkout (`leadWorktree: false`, with `baseSha`); otherwise the lead gets its own worktree. A resumed run keeps what its
|
|
179
|
+
* state recorded, whatever the repo looks like now. Decided once, before the run's lock is taken; it takes no lock itself.
|
|
71
180
|
*/
|
|
72
|
-
export declare function planWorkspace(project: ResolvedProject, resume?: RunState): WorkspacePlan;
|
|
181
|
+
export declare function planWorkspace(project: ResolvedProject, resume?: RunState, opts?: PlanOptions): WorkspacePlan;
|
|
73
182
|
/** Refuse to resume a worktree run when its repo can no longer be isolated; returns nothing when it is fine. */
|
|
74
183
|
export declare function assertWorktreeRunnable(project: ResolvedProject): void;
|
|
75
184
|
/** `refs/agent-lyceum/<run>/base-0` pointing at the repo's HEAD: where a concurrent run starts. Nothing in the repo changes. */
|
|
76
185
|
export declare function snapshotHead(project: ResolvedProject, runId: string): string;
|
|
186
|
+
/** `refs/agent-lyceum/<run>/base-0` pointing at `sha` (a remote base the run records): where a concurrent run with a remote base starts, whatever the local HEAD is. */
|
|
187
|
+
export declare function snapshotCommit(project: ResolvedProject, runId: string, sha: string): string;
|
|
188
|
+
/**
|
|
189
|
+
* What to tell the user when a new run starts from the remote base `sha` while the local HEAD is somewhere else: on another task's
|
|
190
|
+
* `agent-lyceum/*` branch the run is moved into a worktree; otherwise your local checkout has not reached that commit.
|
|
191
|
+
* Undefined when HEAD is at `sha` (or the repo has no HEAD).
|
|
192
|
+
*/
|
|
193
|
+
export declare function remoteBaseNote(project: ResolvedProject, sha: string, baseRef?: string): string | undefined;
|
|
77
194
|
/**
|
|
78
195
|
* Commit the repo's current working tree (tracked changes and new, non-ignored files) as an unreferenced-by-branch
|
|
79
196
|
* snapshot `refs/agent-lyceum/<run>/base-<n>`. Uses a throwaway index, so HEAD, branches, the real index and the
|
|
@@ -170,8 +287,14 @@ export interface WorkspaceWork {
|
|
|
170
287
|
/** Set when the state could not be determined; treat as work that must not be deleted. */
|
|
171
288
|
unknown?: string;
|
|
172
289
|
}
|
|
173
|
-
/**
|
|
174
|
-
|
|
290
|
+
/**
|
|
291
|
+
* What is in an agent's worktree that exists nowhere else: uncommitted changes, and commits whose files are not in the main repo.
|
|
292
|
+
* `target`: where the commits are looked for. A worktree (the lead's, in a concurrent run), a commit of your repo (`{ commit }`: a checkout
|
|
293
|
+
* run's recorded result, compared as it was committed, whatever your HEAD is now), or by default your repo's working tree.
|
|
294
|
+
*/
|
|
295
|
+
export declare function inspectWorkspace(project: ResolvedProject, runId: string, agent: string, target?: AgentWorkspace | {
|
|
296
|
+
commit: string;
|
|
297
|
+
}): WorkspaceWork | undefined;
|
|
175
298
|
export interface ResultBranch {
|
|
176
299
|
branch: string;
|
|
177
300
|
head: string;
|
|
@@ -184,11 +307,35 @@ export interface ResultBranch {
|
|
|
184
307
|
}
|
|
185
308
|
/** Commit the lead's checkout on its branch (once, at the end of a run) and write what changed as a patch. Never touches your repo's working tree. */
|
|
186
309
|
export declare function finishLeadBranch(ws: AgentWorkspace, message: string, patchFile: string): ResultBranch;
|
|
310
|
+
/** What a checkout run's task branch is now, for `clear`: its tip (undefined when the branch is gone), whether HEAD names it, and whether the tip is in HEAD. */
|
|
311
|
+
export declare function taskBranchState(dir: string, branch: string): {
|
|
312
|
+
tip?: string;
|
|
313
|
+
headIsBranch: boolean;
|
|
314
|
+
tipInHead: boolean;
|
|
315
|
+
};
|
|
316
|
+
/** A commit of your repo by name (a sha), or undefined when it is not there. */
|
|
317
|
+
export declare function resolveCommit(dir: string, sha: string): string | undefined;
|
|
318
|
+
/**
|
|
319
|
+
* `git branch -D` of a checkout run's task branch, only while it is still what `clear` planned to delete: HEAD does not name it, its tip
|
|
320
|
+
* is `expectedTip` (nothing was committed on it since the plan) and that tip is in HEAD. Throws, deleting nothing, otherwise.
|
|
321
|
+
*/
|
|
322
|
+
export declare function deleteTaskBranch(dir: string, branch: string, expectedTip: string): void;
|
|
323
|
+
/** Why the project checkout is not on its task branch `branch` (HEAD names another branch, or is detached), or undefined when it is. */
|
|
324
|
+
export declare function checkoutHeadProblem(dir: string, branch: string): string | undefined;
|
|
325
|
+
/**
|
|
326
|
+
* A checkout run, at its end: commit what is in the project checkout on the task branch `branch`, once, and write what changed since
|
|
327
|
+
* `baseSha` as a patch. Returns undefined, and touches nothing, when HEAD is not `refs/heads/<branch>` (the checkout was moved: a commit
|
|
328
|
+
* would land on the branch HEAD names now). `add -A` and `commit` run with the pinned config (no hooks, no fsmonitor, no signing, `--no-verify`),
|
|
329
|
+
* and a nested git repository in the checkout is refused first, as in an agent's worktree. `run` is a test seam, as for `resolveRemoteBase`.
|
|
330
|
+
*/
|
|
331
|
+
export declare function finishCheckoutBranch(dir: string, branch: string, baseSha: string, message: string, patchFile: string, run?: GitRunner): ResultBranch | undefined;
|
|
187
332
|
/**
|
|
188
333
|
* A reopened run whose lead branch was already merged into your HEAD starts its next segment on a fresh branch cut from HEAD,
|
|
189
334
|
* so the merged work is not offered again. Only when nothing would be lost: the branch's last committed head (`resultHead`) is
|
|
190
335
|
* in HEAD, the worktree is still at that head, and it holds no uncommitted work and nothing whose state is unknown.
|
|
191
|
-
* Otherwise the worktree and branch are returned unchanged.
|
|
336
|
+
* Otherwise the worktree and branch are returned unchanged. Also unchanged while HEAD is on an `agent-lyceum/*` branch (another task's).
|
|
337
|
+
* The new branch is always cut from the local HEAD, never from the run's `base_sha`, which would drop what you merged since.
|
|
338
|
+
* Your working tree, index and HEAD are never touched.
|
|
192
339
|
*/
|
|
193
340
|
export declare function recutLeadWorkspace(project: ResolvedProject, runId: string, agent: string, ws: AgentWorkspace, resultHead: string | undefined): {
|
|
194
341
|
ws: AgentWorkspace;
|