Public: anyone can read this; the crew can change it.

Revert "Crew roles are config: an agent says what it does, migrate never picks a planner as builder, and a repo's team is three lists to choose from" #8977

Closed opened this
Closed without merging

revert-8922 → main 1 commit

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
90 files changed +332 −800
docs/PLANNING.md +2 −10
@@ -470,16 +470,8 @@ Everything it does, it does as that person, through the same actions they
470470 would take by hand — an assignment, a merge — so every run and every
471471 landing is credited and bounded exactly as theirs would be.
472472
473 **The crew's roles.** An agent declares its roles in its own config, beside
474 its model and brief (Settings → Crew → the agent; `roles` on `/api/v1/agents`
475 and the `agent` MCP tool): any of planner, builder, reviewer, one or more.
476 A repository's team is three lists, Planners, Builders and Reviewers, each
477 picking only from agents that declare the role, with how many may work at
478 once beside it; a repository narrows what an agent declares and never widens
479 it, and there is no default to builder. `/migrate` and a new app offer
480 builders only, and a dispatch never hands an agent a job outside its seat:
481 an issue assigned to a planner gets one comment saying so. Each crew member
482 then holds one of its roles on the repository: a _builder_ takes what is ready; a _planner_
473 **The crew's roles.** Each crew member has a role on the repository, set
474 under **Settings → Crew**: a _builder_ takes what is ready; a _planner_
483475 turns the direction into a map; a _reviewer_ is for the look-back. Which
484476 builder takes an issue is one fixed-choice function: the issue's own
485477 assignee when it is a builder here, else the builder with the least in
docs/features/crew-roles.md deleted −9
@@ -1,9 +0,0 @@
1 # An agent says what it does; a repo's team is three lists
2
3 An agent declares its **roles** in its own config: any of planner, builder, reviewer (at least one; none given reads as builder).
4
5 - **Where to set them.** Settings → Crew → the agent has a *Jobs* row of checkboxes. The same is `roles` (a list of strings) on `POST`/`PATCH /api/v1/agents`, on the `agent` MCP tool, and `r` on the terminal's *Crew agents* screen (comma separated, plan and confirm first). Anything but a list of the three names is `invalid_roles` (422).
6 - **A repository narrows, never widens.** A repo's *Settings → Crew* shows three lists, Planners, Builders and Reviewers, each with how many may work at once. An *Add…* list offers only agents that declare that role; the API refuses a role the agent does not declare (`role_not_declared`). There is no default to builder: an agent added with no seat takes the first it declares.
7 - **No silent moves.** Taking a role off an agent that still holds that seat on a repository is refused (`role_held`); move it off that repository's team first.
8 - **A dispatch keeps to the seat.** An assigned issue, feedback, a red check, a conflict, a converge and a resolve run only for a builder (the direction issue only for a planner); a review only for a reviewer. An issue assigned to a planner or reviewer gets one comment saying so.
9 - **`/migrate`** offers builders only; `crew=<name>` naming anyone else is refused in a sentence and the first builder stays the default.
src/actions/apps.ts +2 −5
@@ -284,7 +284,6 @@ export type NewAppError =
284284 | CreateAppError
285285 | "scaffold_failed"
286286 | "no_such_agent"
287 | "not_a_builder"
288287 | "app_limit";
289288
290289 /**
@@ -308,7 +307,6 @@ export async function newApp(
308307 ? undefined
309308 : getAgentByName(app.db, input.agent);
310309 if (input.agent && !agent) return err("no_such_agent");
311 if (agent && !agent.roles.includes("builder")) return err("not_a_builder");
312310
313311 // Refuse at the limit before a repository exists to take back.
314312 // The owner is resolved with the actor's rights, as createRepo does, so
@@ -373,7 +371,7 @@ export async function newApp(
373371 const binary = process.env["FORGE_CLAUDE"] ?? "claude";
374372 if (planningAvailable(binary)) {
375373 const roster = listAllAgents(app, user.value);
376 const agents = roster.ok ? roster.value.filter((a) => a.roles.includes("builder")) : [];
374 const agents = roster.ok ? roster.value : [];
377375 if (agents.length > 0) {
378376 const result = await plan(
379377 {
@@ -403,7 +401,7 @@ export async function newApp(
403401
404402 let issue: Issue | undefined;
405403 if (chosen) {
406 addCrew(app.db, repo.value.id, chosen.user.id, user.value.id, "builder");
404 addCrew(app.db, repo.value.id, chosen.user.id, user.value.id);
407405 app.bus.append({
408406 kind: "crew.added",
409407 repoId: repo.value.id,
@@ -461,7 +459,6 @@ export const NEW_APP_ERRORS: Record<string, string> = {
461459 already_app: "That repository is already an app.",
462460 scaffold_failed: "The starter app could not be committed.",
463461 no_such_agent: NO_SUCH_AGENT,
464 not_a_builder: "That agent is not a builder, so it cannot be handed a new app. Pick a builder.",
465462 };
466463
467464 export interface NewAppFromSentenceInput extends Omit<NewAppInput, "name"> {
src/actions/crew.ts +10 −49
@@ -17,10 +17,9 @@ import {
1717 isCrew,
1818 listAgents,
1919 listCrew as queryCrew,
20 isCrewRole,
2120 listCrewRoles,
2221 removeCrew as deleteCrew,
23 seatsOutside,
22 setCrewRole,
2423 updateAgent as patchAgent,
2524 type Agent,
2625 type AgentPatch,
@@ -46,25 +45,6 @@ export interface CreateAgentInput {
4645 model?: string;
4746 brief?: string;
4847 budgetUsd?: number;
49 /** The seats it can hold: any of planner, builder, reviewer. */
50 roles?: readonly string[];
51 }
52
53 /** An agent change as asked: roles still unchecked strings. */
54 export type AgentChange = Omit<AgentPatch, "roles"> & { roles?: readonly string[] };
55
56 /**
57 * The `roles` a request named, as a patch field: nothing when it named none;
58 * anything but a list of strings is carried as a value checkPatch refuses.
59 */
60 export function askedRoles(value: unknown): { roles?: readonly string[] } {
61 if (value === undefined) return {};
62 return {
63 roles:
64 Array.isArray(value) && value.every((r) => typeof r === "string")
65 ? value
66 : [""],
67 };
6848 }
6949
7050 export type CreateAgentError =
@@ -73,9 +53,7 @@ export type CreateAgentError =
7353 | CreateUserError
7454 | "invalid_model"
7555 | "brief_too_long"
76 | "invalid_budget"
77 | "invalid_roles"
78 | "role_held";
56 | "invalid_budget";
7957
8058 function requireForgeAdmin(
8159 actor: User | undefined,
@@ -88,13 +66,8 @@ function requireForgeAdmin(
8866 /** The bounds an agent change must meet; the screens check them before they ask. */
8967 export function checkPatch(
9068 app: App,
91 patch: AgentChange,
92 ): Result<AgentPatch, "invalid_model" | "brief_too_long" | "invalid_budget" | "invalid_roles"> {
93 let roles: CrewRole[] | undefined;
94 if (patch.roles !== undefined) {
95 if (patch.roles.length === 0 || !patch.roles.every(isCrewRole)) return err("invalid_roles");
96 roles = patch.roles as CrewRole[];
97 }
69 patch: AgentPatch,
70 ): Result<AgentPatch, "invalid_model" | "brief_too_long" | "invalid_budget"> {
9871 if (patch.model !== undefined) {
9972 if (patch.model.length > MODEL_MAX || /[\s\0]/.test(patch.model))
10073 return err("invalid_model");
@@ -108,8 +81,7 @@ export function checkPatch(
10881 patch.budgetUsd > limitValue(app.db, "agent.budget_max_usd"))
10982 )
11083 return err("invalid_budget");
111 const { roles: _asked, ...rest } = patch;
112 return ok({ ...rest, ...(roles === undefined ? {} : { roles }) });
84 return ok(patch);
11385 }
11486
11587 /** A new crew member. Admin only: this is an account that will act. */
@@ -124,7 +96,6 @@ export async function createAgent(
12496 ...(input.model === undefined ? {} : { model: input.model }),
12597 ...(input.brief === undefined ? {} : { brief: input.brief }),
12698 ...(input.budgetUsd === undefined ? {} : { budgetUsd: input.budgetUsd }),
127 ...(input.roles === undefined ? {} : { roles: input.roles }),
12899 });
129100 if (!patch.ok) return patch;
130101 const user = await createUser(app.db, {
@@ -141,7 +112,6 @@ export async function createAgent(
141112 model: patch.value.model,
142113 brief: patch.value.brief,
143114 budgetUsd: patch.value.budgetUsd,
144 roles: patch.value.roles,
145115 createdBy: admin.value.id,
146116 });
147117 app.bus.append({
@@ -156,7 +126,7 @@ export function updateAgent(
156126 app: App,
157127 actor: User | undefined,
158128 username: string,
159 patch: AgentChange,
129 patch: AgentPatch,
160130 ): Result<Agent, CreateAgentError | "not_found"> {
161131 const admin = requireForgeAdmin(actor);
162132 if (!admin.ok) return admin;
@@ -164,11 +134,6 @@ export function updateAgent(
164134 if (!agent) return err("not_found");
165135 const checked = checkPatch(app, patch);
166136 if (!checked.ok) return checked;
167 // No silent move: a seat the agent still holds on a repository is moved there first.
168 if (checked.value.roles) {
169 const held = seatsOutside(app.db, agent.user.id, checked.value.roles);
170 if (held.length > 0) return err("role_held");
171 }
172137 const updated = patchAgent(app.db, agent.user.id, checked.value);
173138 if (!updated) return err("not_found");
174139 app.bus.append({
@@ -241,8 +206,6 @@ export interface CrewMember {
241206 * or a stranger sees the crew's names and roles.
242207 */
243208 readonly config?: { model: string; brief: string; budgetUsd: number };
244 /** The seats the agent declares; the repository's `role` is one of them. */
245 readonly roles: readonly CrewRole[];
246209 }
247210
248211 /** The crew of a repository, shown as `actor` may see it. */
@@ -262,7 +225,6 @@ export function crewAsSeen(
262225 username: agent.user.username,
263226 displayName: agent.user.displayName,
264227 role,
265 roles: agent.roles,
266228 ...(configured
267229 ? {
268230 config: {
@@ -283,7 +245,7 @@ export function addToCrew(
283245 repo: Repo,
284246 username: string,
285247 role?: CrewRole,
286 ): Result<Agent, "not_found" | "no_such_agent" | "not_an_agent" | "unverified" | "role_not_declared"> {
248 ): Result<Agent, "not_found" | "no_such_agent" | "not_an_agent" | "unverified"> {
287249 const admin = requireRepoAdmin(app, actor, repo);
288250 if (!admin.ok) return admin;
289251 const proven = requireVerified(app, admin.value);
@@ -292,10 +254,9 @@ export function addToCrew(
292254 // A person is never on a crew: said plainly, before the database would.
293255 if (!agent)
294256 return err(getUserByName(app.db, username) ? "not_an_agent" : "no_such_agent");
295 // A repository narrows what an agent declares, never widens it.
296 if (role !== undefined && !agent.roles.includes(role)) return err("role_not_declared");
297 // A seat is named only for an agent who joins now; one already on the crew keeps its role.
298 if (insertCrew(app.db, repo.id, agent.user.id, admin.value.id, role)) {
257 if (insertCrew(app.db, repo.id, agent.user.id, admin.value.id)) {
258 // A seat is named only for an agent who joins now; one already on the crew keeps its role.
259 if (role !== undefined) setCrewRole(app.db, repo.id, agent.user.id, role);
299260 app.bus.append({
300261 kind: "crew.added",
301262 repoId: repo.id,
src/actions/migrate.ts +4 −10
@@ -133,8 +133,7 @@ export type MigrateError =
133133 | "no_such_origin"
134134 | "unreachable"
135135 | "invalid_branch"
136 | "no_such_agent"
137 | "not_a_builder";
136 | "no_such_agent";
138137
139138 /** What the clone reads from, resolved: where, and how to authenticate. */
140139 interface Resolved {
@@ -192,11 +191,8 @@ export async function migrateRepo(
192191
193192 const source = await resolveSource(app, user.value, input.source, input.resolve);
194193 if (!source.ok) return source;
195 if (input.crew !== undefined) {
196 const asked = getAgentByName(app.db, input.crew.agent);
197 if (!asked) return err("no_such_agent");
198 if (!asked.roles.includes("builder")) return err("not_a_builder");
199 }
194 if (input.crew !== undefined && !getAgentByName(app.db, input.crew.agent))
195 return err("no_such_agent");
200196 const branch = (input.branch ?? "").trim();
201197 if (branch !== "" && !isSafeRef(branch)) return err("invalid_branch");
202198
@@ -272,8 +268,6 @@ export function migrateMessage(error: MigrateError, limit = AT_REPOSITORY_LIMIT)
272268 return "The origin could not be reached. Try again, or reconnect it under Settings → Origins.";
273269 case "no_such_agent":
274270 return NO_SUCH_AGENT;
275 case "not_a_builder":
276 return "That agent is not a builder, so it cannot take a migration. Pick a builder, or change its roles under Settings → Crew.";
277271 case "invalid_branch":
278272 return "That is not a branch name git would take.";
279273 case "name_taken":
@@ -842,7 +836,7 @@ async function putCrewOn(
842836 work: WorkBranch | undefined,
843837 ): Promise<string> {
844838 const said: string[] = [];
845 const added = addToCrew(app, user, repo, crew.agent, "builder");
839 const added = addToCrew(app, user, repo, crew.agent);
846840 if (!added.ok) return `${crew.agent} could not join the crew.`;
847841 const made = enableApp(app, user, repo, {});
848842 if (!made.ok)
src/actions/spawn.ts +2 −4
@@ -415,11 +415,9 @@ async function copyInto(
415415 if (!forgeCode.ok) return err(forgeCode.error);
416416
417417 for (const b of plan.briefs) {
418 // The jobs it declares travel with it (#8907).
419 const roles = getAgentByName(app.db, b.agent)?.roles;
420418 const existing = getAgentByName(child.db, b.agent);
421419 if (existing) {
422 updateAgent(child.db, existing.user.id, { brief: b.text, ...(roles ? { roles } : {}) });
420 updateAgent(child.db, existing.user.id, { brief: b.text });
423421 continue;
424422 }
425423 const made = await createUser(child.db, {
@@ -429,7 +427,7 @@ async function copyInto(
429427 origin: "spawn",
430428 });
431429 if (!made.ok) return err(`could not make crew member ${b.agent}: ${made.error}`);
432 createAgentRow(child.db, { userId: made.value.id, brief: b.text, roles, createdBy: founder.id });
430 createAgentRow(child.db, { userId: made.value.id, brief: b.text, createdBy: founder.id });
433431 }
434432
435433 // A carried crew member keeps its place on each app: the role it had on
src/core/agents.ts +14 −68
@@ -19,8 +19,6 @@ export interface Agent {
1919 readonly brief: string;
2020 /** Spend per run in USD; 0 means the forge's default. */
2121 readonly budgetUsd: number;
22 /** The seats it can hold, in planner, builder, reviewer order; never empty. */
23 readonly roles: readonly CrewRole[];
2422 readonly createdBy: string | null;
2523 readonly createdAt: string;
2624 }
@@ -30,7 +28,6 @@ interface AgentRow {
3028 model: string;
3129 brief: string;
3230 budget_usd: number;
33 roles: string;
3431 created_by: string | null;
3532 created_at: string;
3633 }
@@ -49,7 +46,6 @@ function agentOf(user: User, row: AgentRow): Agent {
4946 model: row.model,
5047 brief: row.brief,
5148 budgetUsd: row.budget_usd,
52 roles: parseRoles(row.roles),
5349 createdBy: row.created_by,
5450 createdAt: row.created_at,
5551 };
@@ -62,19 +58,17 @@ export function createAgentRow(
6258 model?: string | undefined;
6359 brief?: string | undefined;
6460 budgetUsd?: number | undefined;
65 roles?: readonly CrewRole[] | undefined;
6661 createdBy?: string | undefined;
6762 },
6863 ): Agent {
6964 db.query(
70 "INSERT INTO agent (user_id, model, brief, budget_usd, created_by, roles) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
65 "INSERT INTO agent (user_id, model, brief, budget_usd, created_by) VALUES (?1, ?2, ?3, ?4, ?5)",
7166 ).run(
7267 input.userId,
7368 input.model ?? "",
7469 input.brief ?? "",
7570 input.budgetUsd ?? 0,
7671 input.createdBy ?? null,
77 joinRoles(input.roles),
7872 );
7973 return getAgent(db, input.userId)!;
8074 }
@@ -119,8 +113,6 @@ export interface AgentPatch {
119113 model?: string;
120114 brief?: string;
121115 budgetUsd?: number;
122 /** Replaces the agent's roles; empty or unknown ones are ignored. */
123 roles?: readonly CrewRole[];
124116 }
125117
126118 export function updateAgent(
@@ -142,23 +134,13 @@ export function updateAgent(
142134 params.push(Math.min(Math.max(patch.budgetUsd, 0), limitValue(db, "agent.budget_max_usd")));
143135 sets.push(`budget_usd = ?${params.length}`);
144136 }
145 if (patch.roles !== undefined && patch.roles.length > 0) {
146 params.push(joinRoles(patch.roles));
147 sets.push(`roles = ?${params.length}`);
148 }
149137 if (sets.length > 0) {
150138 params.push(userId);
151139 db.query(
152140 `UPDATE agent SET ${sets.join(", ")} WHERE user_id = ?${params.length}`,
153141 ).run(...params);
154142 }
155 const agent = getAgent(db, userId);
156 // A seat the agent no longer declares moves to one it does: a repo narrows, never widens.
157 if (agent && patch.roles !== undefined)
158 db.query(
159 "UPDATE repo_crew SET role = ?2 WHERE user_id = ?1 AND instr(',' || ?3 || ',', ',' || role || ',') = 0",
160 ).run(userId, agent.roles[0]!, agent.roles.join(","));
161 return agent;
143 return getAgent(db, userId);
162144 }
163145
164146 // ---- the crew of a repository ----
@@ -173,22 +155,13 @@ export function addCrew(
173155 repoId: string,
174156 userId: string,
175157 addedBy?: string,
176 role?: CrewRole,
177158 ): boolean {
178 const agent = getAgent(db, userId);
179 const declared = agent?.roles ?? [];
180 // No default to builder: the seat is the one asked for, else the first the agent declares.
181 // A user with no agent row goes on to the insert, where the database refuses a person.
182 const seat = agent
183 ? role !== undefined && declared.includes(role) ? role : declared[0]
184 : (role ?? "builder");
185 if (seat === undefined) return false;
186159 return (
187160 db
188161 .query(
189 "INSERT OR IGNORE INTO repo_crew (repo_id, user_id, added_by, role) VALUES (?1, ?2, ?3, ?4)",
162 "INSERT OR IGNORE INTO repo_crew (repo_id, user_id, added_by) VALUES (?1, ?2, ?3)",
190163 )
191 .run(repoId, userId, addedBy ?? null, seat).changes > 0
164 .run(repoId, userId, addedBy ?? null).changes > 0
192165 );
193166 }
194167
@@ -308,8 +281,8 @@ export function deleteAgent(db: Database, userId: string): boolean {
308281 */
309282 export type CrewRole = "builder" | "planner" | "reviewer";
310283 export const CREW_ROLES: readonly CrewRole[] = [
311 "planner",
312284 "builder",
285 "planner",
313286 "reviewer",
314287 ];
315288 export const isCrewRole = (value: unknown): value is CrewRole =>
@@ -322,37 +295,11 @@ export function crewRole(
322295 ): CrewRole | undefined {
323296 const row = db
324297 .query<
325 { role: string; roles: string },
298 { role: string },
326299 [string, string]
327 >("SELECT repo_crew.role, agent.roles FROM repo_crew JOIN agent ON agent.user_id = repo_crew.user_id WHERE repo_id = ?1 AND repo_crew.user_id = ?2")
300 >("SELECT role FROM repo_crew WHERE repo_id = ?1 AND user_id = ?2")
328301 .get(repoId, userId);
329 return row ? seatOf(row.role, parseRoles(row.roles)) : undefined;
330 }
331
332 /** The roles an agent declares, in seat order; a bad or empty value reads as builder. */
333 export function parseRoles(value: string): CrewRole[] {
334 const out = CREW_ROLES.filter((r) => value.split(",").includes(r));
335 return out.length > 0 ? out : ["builder"];
336 }
337
338 function joinRoles(roles: readonly CrewRole[] | undefined): string {
339 return parseRoles((roles ?? []).join(",")).join(",");
340 }
341
342 /** The seat a repo row holds: its own when the agent declares it, else the agent's first. */
343 function seatOf(role: string, declared: readonly CrewRole[]): CrewRole {
344 return isCrewRole(role) && declared.includes(role) ? role : declared[0]!;
345 }
346
347 /** The repositories where an agent holds a seat that `roles` would not declare. */
348 export function seatsOutside(db: Database, userId: string, roles: readonly CrewRole[]): string[] {
349 return db
350 .query<{ name: string }, [string, string]>(
351 `SELECT repo.name FROM repo_crew JOIN repo ON repo.id = repo_crew.repo_id
352 WHERE repo_crew.user_id = ?1 AND instr(',' || ?2 || ',', ',' || repo_crew.role || ',') = 0`,
353 )
354 .all(userId, roles.join(","))
355 .map((r) => r.name);
302 return row && isCrewRole(row.role) ? row.role : row ? "builder" : undefined;
356303 }
357304
358305 export function setCrewRole(
@@ -361,8 +308,6 @@ export function setCrewRole(
361308 userId: string,
362309 role: CrewRole,
363310 ): boolean {
364 // A repository narrows what an agent declares and never widens it.
365 if (!getAgent(db, userId)?.roles.includes(role)) return false;
366311 return (
367312 db
368313 .query(
@@ -383,11 +328,13 @@ export function listCrewRoles(
383328 "SELECT user_id, role FROM repo_crew WHERE repo_id = ?1",
384329 )
385330 .all(repoId)
386 .map((r) => [r.user_id, r.role] as const),
331 .map(
332 (r) => [r.user_id, isCrewRole(r.role) ? r.role : "builder"] as const,
333 ),
387334 );
388335 return listCrew(db, repoId).map((agent) => ({
389336 agent,
390 role: seatOf(roles.get(agent.user.id) ?? "", agent.roles),
337 role: roles.get(agent.user.id) ?? "builder",
391338 }));
392339 }
393340
@@ -413,7 +360,6 @@ export function crewWithRole(
413360 JOIN agent ON agent.user_id = repo_crew.user_id
414361 JOIN user ON user.id = agent.user_id
415362 WHERE repo_crew.role = ?1
416 AND instr(',' || agent.roles || ',', ',' || ?1 || ',') > 0
417363 AND repo_crew.repo_id IN (${batch.map((_, n) => `?${n + 2}`).join(",")})
418364 ORDER BY user.username COLLATE NOCASE`,
419365 )
@@ -450,8 +396,8 @@ export function reposWithBuilder(
450396 const batch = unique.slice(i, i + CHUNK);
451397 const rows = db
452398 .query<{ repo_id: string }, string[]>(
453 `SELECT DISTINCT repo_id FROM repo_crew JOIN agent ON agent.user_id = repo_crew.user_id
454 WHERE role = 'builder' AND instr(',' || agent.roles || ',', ',builder,') > 0 AND repo_id IN (${batch.map((_, n) => `?${n + 1}`).join(",")})`,
399 `SELECT DISTINCT repo_id FROM repo_crew
400 WHERE role = 'builder' AND repo_id IN (${batch.map((_, n) => `?${n + 1}`).join(",")})`,
455401 )
456402 .all(...batch);
457403 for (const row of rows) out.add(row.repo_id);
src/core/migration-pins/20261103140000-agent-roles.pin deleted −1
@@ -1,1 +0,0 @@
1 c7b646072706c89877014e53aa0c50485cd617b72d77c1c02ab62843e8118689
src/core/migrations/20261103140000-agent-roles.ts deleted −12
@@ -1,12 +0,0 @@
1 // An agent's roles are its own config (#8907): the seats it can hold, planner,
2 // builder, reviewer, one or more, comma-joined in that order. Existing agents
3 // take the roles they hold today on any repository, so nothing changes under
4 // them; an agent on no crew keeps `builder`, which is what it read as. Additive.
5 export default `
6 ALTER TABLE agent ADD COLUMN roles TEXT NOT NULL DEFAULT 'builder';
7 UPDATE agent SET roles = rtrim(
8 (CASE WHEN EXISTS (SELECT 1 FROM repo_crew WHERE user_id = agent.user_id AND role = 'planner') THEN 'planner,' ELSE '' END) ||
9 (CASE WHEN EXISTS (SELECT 1 FROM repo_crew WHERE user_id = agent.user_id AND role = 'builder') THEN 'builder,' ELSE '' END) ||
10 (CASE WHEN EXISTS (SELECT 1 FROM repo_crew WHERE user_id = agent.user_id AND role = 'reviewer') THEN 'reviewer,' ELSE '' END), ',')
11 WHERE EXISTS (SELECT 1 FROM repo_crew WHERE user_id = agent.user_id);
12 `;
src/crew/dispatch.ts −38
@@ -374,36 +374,6 @@ export function atCeiling(
374374 return spentUsd >= repo.autonomyCeilingUsd;
375375 }
376376
377 /**
378 * Whether this run is a job outside the agent's seat here: a build for one
379 * that is not a builder (the direction issue is the planner's), a review for
380 * one that is not a reviewer. On the crew the seat is the repository's; off
381 * it, what the agent declares.
382 */
383 export function outsideSeat(
384 app: App,
385 repo: Repo,
386 issue: Issue,
387 agent: Agent,
388 reason: RunReason,
389 ): boolean {
390 // Every reason but a review is building work: a first go, feedback, a red check, a conflict, a converge.
391 const seat =
392 reason === "review"
393 ? "reviewer"
394 : issue.id === repo.directionIssueId
395 ? "planner"
396 : "builder";
397 const held = crewRole(app.db, repo.id, agent.user.id);
398 // A pull assigned to its reviewer is asked for a look, a builder's for a fix: only a planner is outside.
399 if (reason !== "review" && issue.kind === "pull")
400 return (held ?? agent.roles[0]) === "planner";
401 return held === undefined ? !agent.roles.includes(seat) : held !== seat;
402 }
403
404 export const NOT_A_BUILDER_NOTE =
405 "I am not a builder here, so I have not started on this. Assign it to a builder on the crew, or change my roles in Settings.";
406
407377 /** Queue a run about an issue for an agent, unless one is already waiting. */
408378 export function queueAgentRun(
409379 app: App,
@@ -420,8 +390,6 @@ export function queueAgentRun(
420390 ): Run | undefined {
421391 // A suspended or removed owner's repositories run nothing, whoever asks.
422392 if (!accountActive(app.db, repo.ownerId)) return undefined;
423 // Never a job outside the agent's seat: building is a builder's, reviewing a reviewer's.
424 if (outsideSeat(app, repo, issue, agent, reason)) return undefined;
425393 // An archived repository starts nothing new; a run carrying on (`again`)
426394 // is one already going, and finishes. A first run
427395 // (`attempt` 0, as a conflict or converge run is queued) is new.
@@ -614,12 +582,6 @@ export function route(app: App, event: ForgeEvent): void {
614582 ? getAgent(app.db, issue.assigneeId)
615583 : undefined;
616584 if (!agent || issue.state !== "open") return;
617 // Assigned to a planner or a reviewer: said once, never silently run.
618 if (outsideSeat(app, repo, issue, agent, "assigned")) {
619 if (!listComments(app.db, issue.id).some((c) => c.body === NOT_A_BUILDER_NOTE))
620 addComment(app, agent.user, repo, issue, NOT_A_BUILDER_NOTE);
621 return;
622 }
623585 queueAgentRun(
624586 app,
625587 repo,
src/crew/planner.ts +3 −2
@@ -7,7 +7,7 @@
77
88 import type { App } from "../app.ts";
99 import { addToCrew } from "../actions/crew.ts";
10 import { getAgent, listCrewRoles, type Agent } from "../core/agents.ts";
10 import { getAgent, listCrewRoles, setCrewRole, type Agent } from "../core/agents.ts";
1111 import type { Repo } from "../core/repos.ts";
1212 import type { User } from "../core/users.ts";
1313
@@ -42,7 +42,8 @@ export function ensurePlanner(app: App, repo: Repo, by: User): Agent | undefined
4242 if (have !== undefined) return have.agent;
4343 const chosen = ownersPlanner(app, repo);
4444 if (chosen === undefined) return undefined;
45 if (!addToCrew(app, by, repo, chosen.user.username, "planner").ok) return undefined;
45 if (!addToCrew(app, by, repo, chosen.user.username).ok) return undefined;
46 setCrewRole(app.db, repo.id, chosen.user.id, "planner");
4647 return chosen;
4748 }
4849
src/http/api.ts −1
@@ -993,7 +993,6 @@ export function agentJson(agent: Agent) {
993993 model: agent.model,
994994 brief: agent.brief,
995995 budgetUsd: agent.budgetUsd,
996 roles: agent.roles,
997996 createdAt: agent.createdAt,
998997 };
999998 }
src/http/api/agents.ts −3
@@ -5,7 +5,6 @@
55 */
66
77 import {
8 askedRoles,
98 createAgent,
109 deleteAgent,
1110 getAgentView,
@@ -46,7 +45,6 @@ export function agentRoutes(router: Router<Handler>): void {
4645 ...(typeof input.budgetUsd === "number"
4746 ? { budgetUsd: input.budgetUsd }
4847 : {}),
49 ...askedRoles(input.roles),
5048 });
5149 if (!made.ok) return respondAccess(made.error, 422);
5250 return json(agentJson(made.value), 201);
@@ -78,7 +76,6 @@ export function agentRoutes(router: Router<Handler>): void {
7876 ...(typeof input.budgetUsd === "number"
7977 ? { budgetUsd: input.budgetUsd }
8078 : {}),
81 ...askedRoles(input.roles),
8279 },
8380 );
8481 if (!updated.ok) return respondAccess(updated.error, 422);
src/http/mcp/tools/agent.ts +2 −5
@@ -1,10 +1,10 @@
1 import { askedRoles, createAgent, deleteAgent, updateAgent } from "../../../actions/crew.ts";
1 import { createAgent, deleteAgent, updateAgent } from "../../../actions/crew.ts";
22 import type { Agent } from "../../../core/agents.ts";
33 import { good, bad, type Tool, str } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "agent",
7 doc: "`{ action, username, … }`: `create` a crew agent, `update` its `model`, `brief`, `budgetUsd` or `roles` (planner, builder, reviewer), or `remove` it; an admin's, with an `admin` token, as `/api/v1/agents`",
7 doc: "`{ action, username, … }`: `create` a crew agent, `update` its `model`, `brief` or `budgetUsd`, or `remove` it; an admin's, with an `admin` token, as `/api/v1/agents`",
88 description: "Admin: create|update|remove an agent.",
99 inputSchema: {
1010 type: "object",
@@ -15,7 +15,6 @@ export const tool: Tool = {
1515 model: { type: "string" },
1616 brief: { type: "string" },
1717 budgetUsd: { type: "number" },
18 roles: { type: "array", items: { type: "string" } },
1918 },
2019 required: ["action", "username"],
2120 },
@@ -31,7 +30,6 @@ export const tool: Tool = {
3130 ...(typeof model === "string" ? { model } : {}),
3231 ...(typeof brief === "string" ? { brief } : {}),
3332 ...(typeof budgetUsd === "number" ? { budgetUsd } : {}),
34 ...askedRoles(args["roles"]),
3533 };
3634 const shown = (a: Agent) => ({
3735 username: a.user.username,
@@ -39,7 +37,6 @@ export const tool: Tool = {
3937 model: a.model,
4038 brief: a.brief,
4139 budgetUsd: a.budgetUsd,
42 roles: a.roles,
4340 createdAt: a.createdAt,
4441 });
4542 const action = args["action"];
src/tui/screens/agents.ts +3 −12
@@ -1,15 +1,14 @@
11 /**
22 * Crew agents in the terminal, a forge admin's: each agent's model, budget and
33 * the first line of its brief, as MCP `agent` and /api/v1/agents have them.
4 * `m`, `b` and `B` change model, budget and brief, `r` its roles (planner,
5 * builder, reviewer: what a repository's team lists offer it for), `n` creates one and `d`
4 * `m`, `b` and `B` change model, budget and brief, `n` creates one and `d`
65 * removes one. Every change shows its plan and applies only after a confirm,
76 * through `updateAgent`, `createAgent` and `deleteAgent`, so the same bounds
87 * apply and a refusal is said in MCP's words (the error code).
98 */
109
1110 import { checkPatch, createAgent, deleteAgent, listAllAgents, updateAgent } from "../../actions/crew.ts";
12 import { CREW_ROLES, type AgentPatch } from "../../core/agents.ts";
11 import type { AgentPatch } from "../../core/agents.ts";
1312 import type { Ctx, Screen } from "../app/app.ts";
1413 import { binding } from "../app/keys.ts";
1514 import { style } from "../term/style.ts";
@@ -34,7 +33,7 @@ export function agentsScreen(f: Session, ctx: Ctx): Screen {
3433 const rows = (): ListRow[] =>
3534 list().map((a) => ({
3635 title: a.user.username,
37 secondary: `${a.roles.join("+")} · ${a.model === "" ? "default model" : a.model} · ${a.budgetUsd === 0 ? "default budget" : `$${a.budgetUsd}`}`,
36 secondary: `${a.model === "" ? "default model" : a.model} · ${a.budgetUsd === 0 ? "default budget" : `$${a.budgetUsd}`}`,
3837 meta: firstLine(a.brief),
3938 }));
4039
@@ -45,7 +44,6 @@ export function agentsScreen(f: Session, ctx: Ctx): Screen {
4544 binding(["m"], "model"),
4645 binding(["b"], "budget"),
4746 binding(["B"], "brief"),
48 binding(["r"], "roles"),
4947 binding(["n"], "new"),
5048 binding(["d"], "remove"),
5149 ],
@@ -103,13 +101,6 @@ export function agentsScreen(f: Session, ctx: Ctx): Screen {
103101 if (!bad.ok) return `refused: ${bad.error}`;
104102 return later(ctx, () => confirm(name, { brief: v }, `${name}: brief → "${truncate(v, 60)}". y/n`));
105103 });
106 else if (e.key === "r")
107 ask(name, `roles: ${CREW_ROLES.join(", ")} (comma separated)`, agent.roles.join(", "), (v) => {
108 const roles = v.split(",").map((r) => r.trim()).filter((r) => r !== "");
109 const bad = checkPatch(f.app, { roles });
110 if (!bad.ok) return `refused: ${bad.error}`;
111 return later(ctx, () => confirm(name, bad.value, `${name}: roles ${agent.roles.join("+")} → ${roles.join("+")}. y/n`));
112 });
113104 else if (e.key === "d")
114105 ctx.push(
115106 confirmScreen(ctx, screen, {
src/web/pages/crew-settings.ts +2 −7
@@ -43,10 +43,7 @@ export async function crewAdd(ctx: Ctx): Promise<Response> {
4343 const { repo, form } = gate;
4444 // The team card's one button names the seat it fills.
4545 const role = field(form, "role");
46 const asked = isCrewRole(role) ? role : undefined;
47 const added = addToCrew(ctx.app, ctx.auth.user, repo, field(form, "agent"), asked);
48 // An agent already on the crew picked for another list moves to it.
49 if (added.ok && asked !== undefined) setCrewRole(ctx.app.db, repo.id, added.value.user.id, asked);
46 const added = addToCrew(ctx.app, ctx.auth.user, repo, field(form, "agent"), isCrewRole(role) ? role : undefined);
5047 return flashTo(
5148 ctx,
5249 `${repoBase(repo)}/settings#crew`,
@@ -57,9 +54,7 @@ export async function crewAdd(ctx: Ctx): Promise<Response> {
5754 : {
5855 tone: "danger",
5956 message:
60 added.error === "role_not_declared"
61 ? "That agent does not do that job. Change its roles first, under Settings → Crew."
62 : added.error === "not_an_agent"
57 added.error === "not_an_agent"
6358 ? "Only an agent can be on a crew; a person is given access through an organization's team."
6459 : "No such agent on this forge.",
6560 },
src/web/pages/crew.ts +1 −21
@@ -15,7 +15,6 @@ import {
1515 } from "../../actions/crew.ts";
1616 import {
1717 BRIEF_MAX,
18 CREW_ROLES,
1918 MODEL_MAX,
2019 type Agent,
2120 } from "../../core/agents.ts";
@@ -51,7 +50,7 @@ import { autonomyStatus, type AutonomyStatus } from "../../crew/autonomy.ts";
5150 import { listAutonomousRepos, type Repo } from "../../core/repos.ts";
5251 import { notFoundPage, settingsLayout, signInFirst } from "../chrome.ts";
5352 import { field, readForm, type Form } from "../form.ts";
54 import { html, raw, when, type Html } from "../html.ts";
53 import { html, when, type Html } from "../html.ts";
5554 import { flashTo, page } from "../layout.ts";
5655 import {
5756 btn,
@@ -159,7 +158,6 @@ interface AgentValues {
159158 model: string;
160159 brief: string;
161160 budgetUsd: string;
162 roles: readonly string[];
163161 }
164162
165163 const agentErrors = (ctx: Ctx): Record<string, string> => ({
@@ -168,8 +166,6 @@ const agentErrors = (ctx: Ctx): Record<string, string> => ({
168166 email_taken: USERNAME_TAKEN,
169167 invalid_model: `A model is up to ${MODEL_MAX} characters with no spaces.`,
170168 brief_too_long: `A brief is at most ${BRIEF_MAX} characters.`,
171 invalid_roles: "Pick at least one job: planner, builder or reviewer.",
172 role_held: "That agent still holds a seat it would lose on a repository. Move it there first, under Settings → Crew.",
173169 invalid_budget: `A budget is a number of dollars between 0 and ${limitValue(ctx.app.db, "agent.budget_max_usd")}.`,
174170 });
175171
@@ -194,14 +190,6 @@ function agentFields(values: AgentValues, error?: string): Html {
194190 hint: "Who this agent is, in its own voice — appended to the prompt of every run. The repository's AGENTS.md says what the work is; this says who does it.",
195191 ...(error !== undefined && error.startsWith("A brief") ? { error } : {}),
196192 })}
197 <fieldset class="field" id="agent-roles">
198 <legend>Jobs</legend>
199 ${CREW_ROLES.map(
200 (r) => html`<label class="check"><input type="checkbox" name="roles" value="${r}" ${values.roles.includes(r) ? raw("checked") : null} />
201 <span>${r}</span></label>`,
202 )}
203 <p class="hint">What this agent does. A repository's team lists offer it only for these, and a dispatch never hands it another kind of job.${error !== undefined && error.startsWith("Pick at least") ? html` <strong>${error}</strong>` : null}</p>
204 </fieldset>
205193 ${uiField({
206194 label: "Budget per run (USD)",
207195 name: "budgetUsd",
@@ -218,11 +206,8 @@ const valuesOf = (agent: Agent): AgentValues => ({
218206 model: agent.model,
219207 brief: agent.brief,
220208 budgetUsd: agent.budgetUsd === 0 ? "" : String(agent.budgetUsd),
221 roles: agent.roles,
222209 });
223210
224 const rolesOf = (form: Form): string[] => form.getAll("roles").map(String);
225
226211 const budgetOf = (form: Form): number | undefined => {
227212 const raw = field(form, "budgetUsd").trim();
228213 return raw === "" ? undefined : Number(raw);
@@ -945,7 +930,6 @@ const EMPTY: AgentValues = {
945930 model: "",
946931 brief: "",
947932 budgetUsd: "",
948 roles: ["builder"],
949933 };
950934
951935 // GET /settings/crew
@@ -979,7 +963,6 @@ export async function agentCreate(ctx: Ctx): Promise<Response> {
979963 model: field(form, "model").trim(),
980964 brief: field(form, "brief"),
981965 budgetUsd: field(form, "budgetUsd").trim(),
982 roles: rolesOf(form),
983966 };
984967 const budgetUsd = budgetOf(form);
985968 const made = await createAgent(ctx.app, ctx.auth.user, {
@@ -987,7 +970,6 @@ export async function agentCreate(ctx: Ctx): Promise<Response> {
987970 ...(values.displayName === "" ? {} : { displayName: values.displayName }),
988971 model: values.model,
989972 brief: values.brief,
990 roles: values.roles,
991973 ...(budgetUsd === undefined ? {} : { budgetUsd }),
992974 });
993975 if (!made.ok) {
@@ -1077,13 +1059,11 @@ export async function agentUpdate(ctx: Ctx): Promise<Response> {
10771059 model: field(form, "model").trim(),
10781060 brief: field(form, "brief"),
10791061 budgetUsd: field(form, "budgetUsd").trim(),
1080 roles: rolesOf(form),
10811062 };
10821063 const updated = updateAgent(ctx.app, ctx.auth.user, agent.user.username, {
10831064 model: values.model,
10841065 brief: values.brief,
10851066 budgetUsd: budgetOf(form) ?? 0,
1086 roles: values.roles,
10871067 });
10881068 if (!updated.ok) {
10891069 if (updated.error === "not_found") return notFoundPage(ctx);
src/web/pages/migrate-prefill.ts −20
@@ -18,8 +18,6 @@ export interface Prefill {
1818 readonly agent?: string;
1919 /** Values that matched nothing, as given (capped) — the page escapes them. */
2020 readonly unmatched: string[];
21 /** Sentences for a name that is on the forge but is not a builder. */
22 readonly refused: string[];
2321 }
2422
2523 const FROM_MAX = 200;
@@ -38,10 +36,8 @@ export function prefill(
3836 query: { from?: string | null; crew?: string | null },
3937 origins: readonly PrefillOrigin[],
4038 agents: readonly string[],
41 notBuilders: readonly string[] = [],
4239 ): Prefill {
4340 const unmatched: string[] = [];
44 const refused: string[] = [];
4541 let repo: Prefill["repo"];
4642 let agent: string | undefined;
4743
@@ -67,8 +63,6 @@ export function prefill(
6763 if (crew !== "") {
6864 if (crew.length <= CREW_MAX && CREW_SAFE.test(crew) && agents.includes(crew))
6965 agent = crew;
70 else if (crew.length <= CREW_MAX && notBuilders.includes(crew))
71 refused.push(`${crew} is not a builder, so it cannot take a migration. Pick one of the builders below.`);
7266 else unmatched.push(`crew=${shown(crew)}`);
7367 }
7468
@@ -76,19 +70,5 @@ export function prefill(
7670 ...(repo ? { repo } : {}),
7771 ...(agent ? { agent } : {}),
7872 unmatched,
79 refused,
8073 };
8174 }
82
83 /**
84 * The agents a migration may be handed to: builders only, the ones that do
85 * nothing else first (a specialist is the surest fit), then by name. The
86 * first is the page's default, so a planner that sorts first is never picked.
87 */
88 export function migrationBuilders<A extends { roles: readonly string[]; user: { username: string } }>(
89 agents: readonly A[],
90 ): A[] {
91 return agents
92 .filter((a) => a.roles.includes("builder"))
93 .sort((a, b) => a.roles.length - b.roles.length || a.user.username.localeCompare(b.user.username));
94 }
src/web/pages/migrate.ts +4 −15
@@ -69,7 +69,7 @@ import {
6969 } from "../../origins/token-reach.ts";
7070 import type { TokenReach } from "../../origins/types.ts";
7171 import { STAGE_BADGE_JS, stageRow, stageStateFor } from "../stage-row.ts";
72 import { prefill, originHost, migrationBuilders } from "./migrate-prefill.ts";
72 import { prefill, originHost } from "./migrate-prefill.ts";
7373 import { githubConnectable, hostLabel } from "./origins.ts";
7474
7575 interface MigrateValues {
@@ -424,7 +424,6 @@ function migrateForm(
424424 branches: BranchChoices | undefined,
425425 error?: string,
426426 unmatched: readonly string[] = [],
427 refused: readonly string[] = [],
428427 ): Html {
429428 const user = ctx.auth.user!;
430429 const writeOrgs = listOrgsForUser(ctx.app.db, user.id).filter((org) =>
@@ -432,7 +431,7 @@ function migrateForm(
432431 );
433432 const owners = [user.username, ...writeOrgs.map((o) => o.username)];
434433 const agents = listAllAgents(ctx.app, user);
435 const crew = agents.ok ? migrationBuilders(agents.value) : [];
434 const crew = agents.ok ? agents.value : [];
436435
437436 return html`<div class="narrow-wide">
438437 ${pageHead("Migrate a repository", {
@@ -450,11 +449,6 @@ function migrateForm(
450449 ${icon("globe")} Ignored, nothing here matches:
451450 ${unmatched.join(", ")}
452451 </p>`}
453 ${refused.length === 0
454 ? null
455 : html`<p class="muted small mb" id="prefill-refused">
456 ${icon("globe")} ${refused.join(" ")}
457 </p>`}
458452 ${accounts(ctx, origins)}
459453 <form method="get" action="/migrate" id="migrate-search"></form>
460454 ${card(
@@ -619,7 +613,6 @@ async function show(
619613 error?: string,
620614 status = 200,
621615 unmatched: readonly string[] = [],
622 refused: readonly string[] = [],
623616 ): Promise<Response> {
624617 // Asked for only: each draw is a listing and a commit per branch at the
625618 // origin (remembered a minute), so a plain visit costs none of it.
@@ -633,7 +626,7 @@ async function show(
633626 {
634627 ctx,
635628 title: "Migrate",
636 body: migrateForm(ctx, values, origins, branches, error, unmatched, refused),
629 body: migrateForm(ctx, values, origins, branches, error, unmatched),
637630 scriptJs: migrateJs,
638631 },
639632 status,
@@ -654,14 +647,11 @@ export async function migratePage(ctx: Ctx): Promise<Response> {
654647 const agents = timePhase(ctx.request, "agents", () =>
655648 listAllAgents(ctx.app, user),
656649 );
657 const all = agents.ok ? agents.value : [];
658 const builders = migrationBuilders(all);
659 const names = builders.map((a) => a.user.username);
650 const names = agents.ok ? agents.value.map((a) => a.user.username) : [];
660651 const linked = prefill(
661652 { from: q.get("from"), crew: q.get("crew") },
662653 origins,
663654 names,
664 all.filter((a) => !builders.includes(a)).map((a) => a.user.username),
665655 );
666656 return show(
667657 ctx,
@@ -686,7 +676,6 @@ export async function migratePage(ctx: Ctx): Promise<Response> {
686676 undefined,
687677 200,
688678 linked.unmatched,
689 linked.refused,
690679 );
691680 }
692681
src/web/pages/settings.ts +1 −3
@@ -83,7 +83,7 @@ import {
8383 settingsLayout,
8484 } from "../chrome.ts";
8585 import { daySpark } from "../studio/kpi_row.ts";
86 import { settingsLead, teamJs } from "../studio/crew.ts";
86 import { settingsLead } from "../studio/crew.ts";
8787 import { pageTitle } from "../studio/nouns.ts";
8888 import { appHref } from "./apps.ts";
8989 import { field, readForm, type Form } from "../form.ts";
@@ -191,7 +191,6 @@ export function settingsPageResponse(
191191 crumbs: crumbsFor(repo),
192192 palette: repoPalette(ctx, repo),
193193 ...(styleCss !== undefined ? { styleCss } : {}),
194 scriptJs: teamJs,
195194 body: html`${repoHeader(ctx, repo, "settings", { compact: true })}
196195 ${settingsLayout(sections(repoBase(repo), active), body)}`,
197196 },
@@ -237,7 +236,6 @@ export async function settingsPage(ctx: Ctx): Promise<Response> {
237236 title: pageTitle("settings", readable, true),
238237 crumbs: crumbsFor(readable),
239238 palette: repoPalette(ctx, readable),
240 scriptJs: teamJs,
241239 body: html`${repoHeader(ctx, readable, "settings", { compact: true })}
242240 ${lead}${proposals ? html`<div class="mt">${proposals}</div>` : null}`,
243241 });
src/web/studio/crew.ts +98 −78
@@ -26,7 +26,7 @@
2626 */
2727
2828 import { listAllAgents, listCrew } from "../../actions/crew.ts";
29 import { listCrewRoles, type Agent, type CrewRole } from "../../core/agents.ts";
29 import { CREW_ROLES, listCrewRoles, type CrewRole } from "../../core/agents.ts";
3030 import { getAppByRepo } from "../../core/apps.ts";
3131 import { canAdmin, canSeeOwnerFacts, type Repo } from "../../core/repos.ts";
3232 import { seatsOf, type Seat } from "../../crew/seats.ts";
@@ -36,7 +36,7 @@ import { governorSeen } from "../../crew/governed.ts";
3636 import { crewOffInPreview } from "../../crew/preview.ts";
3737 import type { Ctx } from "../../http/context.ts";
3838 import { repoBase } from "../chrome.ts";
39 import { html, type Html } from "../html.ts";
39 import { html, raw, type Html } from "../html.ts";
4040 import { icon } from "../icons.ts";
4141 import { crewReadiness } from "../pages/crew.ts";
4242 import { grantsSection } from "../pages/subscriptions.ts";
@@ -125,93 +125,59 @@ const SEAT_BADGE: Record<Seat["state"], { text: string; tone: Tone }> = {
125125 invite: { text: "open seat", tone: "default" },
126126 };
127127
128 /** The script: choosing in a team list, or setting its number, saves at once. */
129 export const teamJs = /* js */ `
130 (function () {
131 document.querySelectorAll("form[data-team] select, form[data-team] input[type=number]").forEach(function (el) {
132 el.addEventListener("change", function () { el.form.requestSubmit(); });
133 });
134 document.querySelectorAll("form[data-team] button[type=submit]").forEach(function (b) { b.hidden = true; });
135 })();
136 `;
137
138 const SEAT_TITLE: Record<CrewRole, string> = {
139 planner: "Planners",
140 builder: "Builders",
141 reviewer: "Reviewers",
142 };
143
144128 /**
145 * Your team, as three lists: Planners, Builders, Reviewers (`seatsOf`, the
146 * same facts the MCP `crew` tool returns). Each list holds who fills it, a
147 * picker of only the agents that declare that role, and how many may work at
148 * once; each choice posts at once (`teamJs`; without script, the button is
149 * there). A seat with nobody warns when the team is on its own.
129 * Your team, as three seats (`seatsOf`, the same facts the MCP `crew` tool
130 * returns): whether it works on its own, who fills each seat, what it does,
131 * and — for an empty one — a warning when the team is on its own, a calm
132 * invitation when it is not, each with one button that puts an agent in it.
150133 */
151134 function teamCard(
152135 ctx: Ctx,
153136 repo: Repo,
154137 base: string,
155138 admin: boolean,
156 everyone: readonly Agent[],
139 candidate: string | undefined,
157140 ): Html {
158141 const team = seatsOf(ctx.app.db, repo, crewOffInPreview());
159 const held = new Map(listCrewRoles(ctx.app.db, repo.id).map((c) => [c.agent.user.username, c.role]));
142 const fill = (p: Seat): Html | undefined => {
143 if (!admin || p.state === "filled") return undefined;
144 if (candidate === undefined)
145 return ctx.auth.user?.isAdmin
146 ? btn("Add an agent", { href: "/settings/crew", size: "sm" })
147 : undefined;
148 return html`<form class="row-actions" method="post" action="${base}/settings/crew">
149 <input type="hidden" name="agent" value="${candidate}" />
150 <input type="hidden" name="role" value="${p.role}" />
151 ${btn(`Put ${candidate} on ${p.role}`, {
152 size: "sm",
153 variant: p.state === "warn" ? "primary" : "secondary",
154 })}
155 </form>`;
156 };
160157 const seatSlots = new Map(seatSlotsOf(ctx.app.db, repo).map((p) => [p.role, p]));
161158 const rows = team.seats.map((p) => {
159 const fillBy = fill(p);
160 const b = SEAT_BADGE[p.state];
162161 const slots = seatSlots.get(p.role)!;
163162 const paused = slots.slots === 0;
164 const b = SEAT_BADGE[p.state];
165 const picks = everyone.filter(
166 (a) => a.roles.includes(p.role) && held.get(a.user.username) !== p.role,
167 );
168 const add =
169 !admin || picks.length === 0
170 ? null
171 : html`<form class="row-fields" method="post" action="${base}/settings/crew" data-team>
172 <input type="hidden" name="role" value="${p.role}" />
173 <label class="sr-only" for="f-add-${p.role}">Add to ${SEAT_TITLE[p.role]}</label>
174 <select class="input input-sm" id="f-add-${p.role}" name="agent">
175 <option value="" disabled selected>Add…</option>
176 ${picks.map((a) => html`<option value="${a.user.username}">${a.user.username}</option>`)}
177 </select>
178 ${btn("Add", { size: "sm" })}
179 </form>`;
180 const setter = !admin
181 ? null
182 : html`<form class="row-fields" method="post" action="${base}/settings/pillars" data-team>
183 <input type="hidden" name="seat" value="${p.role}" />
184 <label class="sr-only" for="f-seat-${p.role}">${p.role}: ${SEAT_UNIT[p.role]}</label>
185 <input class="input input-sm" id="f-seat-${p.role}" name="slots" type="number" inputmode="numeric"
186 min="0" max="${String(slots.max)}" value="${String(slots.slots)}" />
187 ${btn("Set", { size: "sm" })}
188 </form>`;
189 const members = p.by.map((u) =>
190 row({
191 lead: icon("bot"),
192 title: userLink(u),
193 ...(admin
194 ? {
195 trail: html`<form class="row-actions" method="post" action="${base}/settings/crew/${encodeURIComponent(u)}/remove">
196 ${btn("Remove", { size: "sm", icon: "x" })}
197 </form>`,
198 }
199 : {}),
200 data: { member: u, seat: p.role },
201 }),
202 );
163 const setter = html`<form class="row-fields" method="post" action="${base}/settings/pillars">
164 <input type="hidden" name="seat" value="${p.role}" />
165 <label class="sr-only" for="f-seat-${p.role}">${p.role}: ${SEAT_UNIT[p.role]}</label>
166 <input class="input input-sm" id="f-seat-${p.role}" name="slots" type="number" inputmode="numeric"
167 min="0" max="${String(slots.max)}" value="${String(slots.slots)}" />
168 ${btn("Set", { size: "sm" })}
169 </form>`;
203170 return row({
204171 lead: icon(SEAT_LEAD[p.state]),
205 title: SEAT_TITLE[p.role],
206 meta: html`${p.does}${p.state === "warn" ? ` No ${p.role}: ${p.without}.` : null}`,
207 trail: html`${paused ? badge("paused", { tone: "attn" }) : badge(b.text, { tone: b.tone })}${add}`,
172 title: p.role[0]!.toUpperCase() + p.role.slice(1),
173 meta: html`${p.by.length > 0 ? html`${p.by.map((u, i) => html`${i > 0 ? ", " : ""}${userLink(u)}`)}: ` : null}${p.does}${p.state === "warn" ? ` No ${p.role}: ${p.without}.` : null}`,
174 trail: html`${paused ? badge("paused", { tone: "attn" }) : badge(b.text, { tone: b.tone })}${fillBy ?? null}`,
208175 data: { seat: p.role, state: p.state },
209176 children: [
210 ...members,
211177 row({
212178 title: paused ? "Paused" : `${String(slots.slots)} ${SEAT_UNIT[p.role]}`,
213179 meta: html`${seatSlotsWords(slots)}`,
214 ...(setter ? { trail: setter } : {}),
180 ...(admin ? { trail: setter } : {}),
215181 data: { slots: p.role, at: String(slots.slots) },
216182 }),
217183 ],
@@ -221,7 +187,7 @@ function teamCard(
221187 ? "The crew is off in a preview, so nobody here is working."
222188 : team.auto
223189 ? `Auto mode is on (${team.mode}): your team works on its own — a planner decides what is next, a builder builds it, a reviewer checks it.`
224 : "Auto mode is off: your team works only when you ask. Pick who fills each list, then turn auto mode on under On its own. The number beside a list is how many may work at once; 0 pauses it.";
190 : "Auto mode is off: your team works only when you ask. Fill the seats you want, then turn auto mode on under On its own. Each seat says how much it may do at once; 0 pauses it without taking it off the team.";
225191 return card(
226192 html`<p class="small" id="auto-mode" data-auto="${team.auto ? "on" : "off"}">
227193 ${intro}
@@ -290,18 +256,72 @@ function crewCard(ctx: Ctx, repo: Repo, base: string, admin: boolean): Html {
290256 ...(admin
291257 ? {
292258 trail: html`<form
293 class="row-actions"
294 method="post"
295 action="${base}/settings/crew/${encodeURIComponent(c.agent.user.username)}/remove"
296 >
297 ${btn("Remove", { size: "sm", icon: "x" })}
298 </form>`,
259 class="row-fields"
260 method="post"
261 action="${base}/settings/crew/${encodeURIComponent(
262 c.agent.user.username,
263 )}/role"
264 >
265 <label
266 class="sr-only"
267 for="f-role-${c.agent.user.username}"
268 >Role of ${c.agent.user.username}</label
269 >
270 <select
271 class="input input-sm"
272 id="f-role-${c.agent.user.username}"
273 name="role"
274 >
275 ${CREW_ROLES.map(
276 (r) =>
277 html`<option
278 value="${r}"
279 ${c.role === r ? raw("selected") : null}
280 >
281 ${ROLE_WORD[r]}
282 </option>`,
283 )}
284 </select>
285 ${btn("Set", { size: "sm" })}
286 </form>
287 <form
288 class="row-actions"
289 method="post"
290 action="${base}/settings/crew/${encodeURIComponent(
291 c.agent.user.username,
292 )}/remove"
293 >
294 ${btn("Remove", { size: "sm", icon: "x" })}
295 </form>`,
299296 }
300297 : {}),
301298 }),
302299 ),
303300 );
304301
302 const add =
303 !admin || available.length === 0
304 ? null
305 : card(
306 html`<form class="edit-row" method="post" action="${base}/settings/crew">
307 <label class="sr-only" for="f-agent">Agent</label>
308 <select class="input" id="f-agent" name="agent">
309 ${available.map(
310 (agent) =>
311 html`<option value="${agent.user.username}">
312 ${agent.user.username}
313 </option>`,
314 )}
315 </select>
316 ${btn("Add to crew", {
317 variant: "primary",
318 size: "sm",
319 icon: "plus",
320 })}
321 </form>`,
322 { head: html`<h2>Add an agent</h2>`, pad: false },
323 );
324
305325 // Whose money the crew spends here is the forge admin's to say.
306326 const grants =
307327 admin && forgeAdmin
@@ -316,14 +336,14 @@ function crewCard(ctx: Ctx, repo: Repo, base: string, admin: boolean): Html {
316336 })()
317337 : null;
318338 return html`<div id="crew">
319 ${teamCard(ctx, repo, base, admin, allListed.ok ? allListed.value : [])}
339 ${teamCard(ctx, repo, base, admin, available[0]?.user.username)}
320340 ${admin ? crewReadiness(ctx) : null}
321341 ${card(html`${rows}`, {
322342 head: html`${icon("bot")}
323343 <h2>Crew</h2>`,
324344 pad: false,
325345 })}
326 ${grants}
346 ${add} ${grants}
327347 </div>`;
328348 }
329349
test/api-give-back.test.ts +2 −3
@@ -5,13 +5,12 @@
55 * reader, or someone who cannot see the repository, gets `not_found`.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
1211 import { join } from "node:path";
1312 import { createApp, type App } from "../src/app.ts";
14 import { addCrew, createAgentRow } from "../src/core/agents.ts";
13 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1514 import { getIssueById, listComments } from "../src/core/issues.ts";
1615 import { createRepo, type Repo } from "../src/core/repos.ts";
1716 import { submitReview } from "../src/core/reviews.ts";
@@ -122,7 +121,7 @@ describe("POST /api/v1/asks/give-back", () => {
122121 privateRepo = closed.value;
123122 for (const target of [repo, privateRepo]) {
124123 for (const agent of [builder, reviewer]) addCrew(app.db, target.id, agent.id, owner.id);
125 seatAs(app.db, target.id, reviewer.id, "reviewer");
124 setCrewRole(app.db, target.id, reviewer.id, "reviewer");
126125 }
127126 rw = createToken(app.db, owner.id, "rw", "rw").token;
128127 ro = createToken(app.db, owner.id, "ro", "ro").token;
test/api-user-next-steps.test.ts +2 −3
@@ -3,7 +3,6 @@
33 * same three steps as MCP `next_steps`; anyone else, or an agent, gets [].
44 */
55
6 import { seatAs } from "./helpers/seat.ts";
76 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
87 import { mkdtemp, rm } from "node:fs/promises";
98 import { tmpdir } from "node:os";
@@ -11,7 +10,7 @@ import { join } from "node:path";
1110 import { createRepo } from "../src/actions/repos.ts";
1211 import { childDirOf, spawnForge } from "../src/actions/spawn.ts";
1312 import { createApp, type App } from "../src/app.ts";
14 import { addCrew, createAgentRow } from "../src/core/agents.ts";
13 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1514 import { createToken } from "../src/core/tokens.ts";
1615 import { createUser, getUserByName } from "../src/core/users.ts";
1716 import { commitFiles } from "../src/git/write.ts";
@@ -80,7 +79,7 @@ describe("GET /api/v1/user/next-steps", () => {
8079 createdBy: alice.id,
8180 });
8281 addCrew(parent.db, repo.value.id, atlas.value.id, alice.id);
83 seatAs(parent.db, repo.value.id, atlas.value.id, "planner");
82 setCrewRole(parent.db, repo.value.id, atlas.value.id, "planner");
8483 parentServers = await serve(parent);
8584 const spawned = await spawnForge(
8685 parent,
test/ask-settles.test.ts +2 −3
@@ -5,13 +5,12 @@
55 * changes requested goes back to its builder after a day of their silence.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
1211 import { join } from "node:path";
1312 import { createApp, type App } from "../src/app.ts";
14 import { addCrew, createAgentRow } from "../src/core/agents.ts";
13 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1514 import { getIssueById, type Issue } from "../src/core/issues.ts";
1615 import { submitReview } from "../src/core/reviews.ts";
1716 import { createRepo, type Repo } from "../src/core/repos.ts";
@@ -64,7 +63,7 @@ describe("an ask settles", () => {
6463 if (!made.ok) throw new Error(made.error);
6564 createAgentRow(app.db, { userId: made.value.id, brief: "b" });
6665 addCrew(app.db, repo.id, made.value.id, owner.id);
67 seatAs(app.db, repo.id, made.value.id, role);
66 setCrewRole(app.db, repo.id, made.value.id, role);
6867 return made.value;
6968 };
7069 const work = (kind: "pull" | "issue", assignee: User | null, createdAt = new Date().toISOString()): Issue => {
test/asks-bulk.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * first: an outsider and a plain reader act on nothing.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -18,7 +17,7 @@ import { addComment, openIssue } from "../src/actions/issues.ts";
1817 import { addTeamMember, createOrg, createTeam } from "../src/actions/orgs.ts";
1918 import { openPull } from "../src/actions/pulls.ts";
2019 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
21 import { getAgentByName } from "../src/core/agents.ts";
20 import { getAgentByName, setCrewRole } from "../src/core/agents.ts";
2221 import { getIssueById, listComments, type Issue } from "../src/core/issues.ts";
2322 import { assignIssue } from "../src/actions/issues.ts";
2423 import { mutedRepos, recordInteraction, removeMutes } from "../src/core/interactions.ts";
@@ -170,7 +169,7 @@ describe("acting on many asks at once", () => {
170169 });
171170 addToCrew(app, alice, made.value, "bot");
172171 addToCrew(app, alice, made.value, "planner");
173 seatAs(
172 setCrewRole(
174173 app.db,
175174 made.value.id,
176175 getAgentByName(app.db, "planner")!.user.id,
test/asks-counts.test.ts +2 −3
@@ -9,14 +9,13 @@
99 * branch of `askCandidatesFor` is on the measured path.
1010 */
1111
12 import { seatAs } from "./helpers/seat.ts";
1312 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1413 import type { Database } from "bun:sqlite";
1514 import { mkdtemp, rm } from "node:fs/promises";
1615 import { tmpdir } from "node:os";
1716 import { join } from "node:path";
1817 import { createApp, type App } from "../src/app.ts";
19 import { addCrew, createAgentRow } from "../src/core/agents.ts";
18 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
2019 import { createApp as createAppRecord } from "../src/core/apps.ts";
2120 import { createRepo, type Repo } from "../src/core/repos.ts";
2221 import { submitReview } from "../src/core/reviews.ts";
@@ -95,7 +94,7 @@ describe("home's asks are read grouped, and once", () => {
9594 });
9695 if (!made.ok) throw new Error(`seed repo ${name}: ${made.error}`);
9796 for (const agent of [builder, reviewer]) addCrew(app.db, made.value.id, agent.id, owner.id);
98 seatAs(app.db, made.value.id, reviewer.id, "reviewer");
97 setCrewRole(app.db, made.value.id, reviewer.id, "reviewer");
9998 app.db.query("UPDATE repo SET autonomy = ?2 WHERE id = ?1").run(made.value.id, autonomy);
10099 return made.value;
101100 };
test/asks-waiting.test.ts +2 −3
@@ -4,13 +4,12 @@
44 * pull still young stays the crew's.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
1110 import { join } from "node:path";
1211 import { createApp, type App } from "../src/app.ts";
13 import { addCrew, createAgentRow } from "../src/core/agents.ts";
12 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1413 import { addComment } from "../src/core/issues.ts";
1514 import { setHold } from "../src/core/holds.ts";
1615 import { createRepo, type Repo } from "../src/core/repos.ts";
@@ -110,7 +109,7 @@ describe("asks that wait on a person", () => {
110109 if (!made.ok) throw new Error(`seed repo: ${made.error}`);
111110 repo = made.value;
112111 for (const agent of [builder, reviewer]) addCrew(app.db, repo.id, agent.id, owner.id);
113 seatAs(app.db, repo.id, reviewer.id, "reviewer");
112 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
114113 token = createToken(app.db, owner.id, "ro", "ro").token;
115114
116115 handed = pull(builder, "Handed over", 3);
test/authors-pull.test.ts +2 −3
@@ -7,7 +7,6 @@
77 * following its branch.
88 */
99
10 import { seatAs } from "./helpers/seat.ts";
1110 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1211 import { mkdtemp, rm } from "node:fs/promises";
1312 import { tmpdir } from "node:os";
@@ -17,7 +16,7 @@ import { openPull } from "../src/actions/pulls.ts";
1716 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1817 import { createApp, type App } from "../src/app.ts";
1918 import { startChecks, type ChecksHandle } from "../src/checks/service.ts";
20 import {} from "../src/core/agents.ts";
19 import { setCrewRole } from "../src/core/agents.ts";
2120 import { getIssueById } from "../src/core/issues.ts";
2221 import { getPull, type Pull } from "../src/core/pulls.ts";
2322 import { getRepoById, type Repo } from "../src/core/repos.ts";
@@ -106,7 +105,7 @@ describe("a person's in-repo pull is a normal pull the crew leaves to its author
106105 }
107106 builder = getUserByName(app.db, "mason")!;
108107 reviewer = getUserByName(app.db, "quill")!;
109 seatAs(app.db, repo.id, reviewer.id, "reviewer");
108 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
110109 app.db
111110 .query("UPDATE repo SET autonomy = 'autonomous', autonomy_by = ?2, autonomy_slots = 3 WHERE id = ?1")
112111 .run(repo.id, alice.id);
test/autonomy.test.ts +13 −16
@@ -5,7 +5,6 @@
55 * here starts a real agent; the crew is not running, so an assignment is
66 * the observable effect.
77 */
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -19,7 +18,7 @@ import {
1918 createRepo,
2019 updateRepoSettings,
2120 } from "../src/actions/repos.ts";
22 import {} from "../src/core/agents.ts";
21 import { setCrewRole } from "../src/core/agents.ts";
2322 import {
2423 latestDecision,
2524 recordDecision,
@@ -111,9 +110,9 @@ describe("a repository on its own", () => {
111110 });
112111 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
113112 for (const name of ["scout", "mason", "atlas"]) {
114 const agent = await createAgent(app, alice, { username: name, roles: ["planner", "builder", "reviewer"] });
113 const agent = await createAgent(app, alice, { username: name });
115114 if (!agent.ok) throw new Error(String(agent.error));
116 expect(addToCrew(app, alice, repo, name, "builder").ok).toBe(true);
115 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
117116 }
118117 scout = getUserByName(
119118 app.db,
@@ -127,7 +126,7 @@ describe("a repository on its own", () => {
127126 app.db,
128127 "atlas",
129128 )!;
130 seatAs(app.db, repo.id, atlas.id, "planner");
129 setCrewRole(app.db, repo.id, atlas.id, "planner");
131130 for (const title of ["Renderer", "Input", "Scene graph"]) {
132131 const opened = openIssue(app, alice, repo, { title });
133132 if (!opened.ok) throw new Error(String(opened.error));
@@ -299,7 +298,7 @@ describe("a repository on its own", () => {
299298 ],
300299 });
301300 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
302 const opened = await openPull(app, mason, repo, {
301 const opened = await openPull(app, atlas, repo, {
303302 title: "Shared",
304303 baseBranch: "main",
305304 headBranch: "feature/shared",
@@ -336,7 +335,7 @@ describe("a repository on its own", () => {
336335 );
337336 expect(conflicts().length).toBe(1);
338337 expect(conflicts()[0]!.summary).toBe("main moved: shared.ts");
339 expect(conflicts()[0]!.actorId).toBe(mason.id);
338 expect(conflicts()[0]!.actorId).toBe(atlas.id);
340339 // Still not landed, still one run waiting: a second look queues nothing.
341340 expect(await landIfGreen(app, fresh(), pull)).toBe(false);
342341 expect(conflicts().length).toBe(1);
@@ -506,7 +505,6 @@ describe("a repository on its own", () => {
506505 model: "",
507506 brief: "",
508507 budgetUsd: 0,
509 roles: ["builder"] as const,
510508 createdBy: null,
511509 createdAt: "",
512510 };
@@ -515,7 +513,6 @@ describe("a repository on its own", () => {
515513 model: "",
516514 brief: "",
517515 budgetUsd: 0,
518 roles: ["builder"] as const,
519516 createdBy: null,
520517 createdAt: "",
521518 };
@@ -673,16 +670,16 @@ describe("the slot count is the rule the loop enforces", () => {
673670 });
674671 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
675672 for (const name of ["brick", "quill", "chart"]) {
676 const agent = await createAgent(app, alice, { username: name, roles: ["planner", "builder", "reviewer"] });
673 const agent = await createAgent(app, alice, { username: name });
677674 if (!agent.ok) throw new Error(String(agent.error));
678 expect(addToCrew(app, alice, repo, name, "builder").ok).toBe(true);
675 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
679676 }
680677 const byName = getUserByName;
681678 builder = byName(app.db, "brick")!;
682679 reviewer = byName(app.db, "quill")!;
683680 planner = byName(app.db, "chart")!;
684 seatAs(app.db, repo.id, reviewer.id, "reviewer");
685 seatAs(app.db, repo.id, planner.id, "planner");
681 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
682 setCrewRole(app.db, repo.id, planner.id, "planner");
686683 for (const title of ["Warp", "Weft", "Shuttle", "Heddle"]) {
687684 const opened = openIssue(app, alice, repo, { title });
688685 if (!opened.ok) throw new Error(String(opened.error));
@@ -818,13 +815,13 @@ describe("the planner is held while nothing lands or the plate is full", () => {
818815 });
819816 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
820817 for (const name of ["brick", "chart"]) {
821 const agent = await createAgent(app, alice, { username: name, roles: ["planner", "builder", "reviewer"] });
818 const agent = await createAgent(app, alice, { username: name });
822819 if (!agent.ok) throw new Error(String(agent.error));
823 expect(addToCrew(app, alice, repo, name, "builder").ok).toBe(true);
820 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
824821 }
825822 const byName = getUserByName;
826823 planner = byName(app.db, "chart")!;
827 seatAs(app.db, repo.id, planner.id, "planner");
824 setCrewRole(app.db, repo.id, planner.id, "planner");
828825 const on = await updateRepoSettings(app, alice, repo, {
829826 autonomy: "autonomous",
830827 autonomyDirection: "Weave the loom",
test/box-pass.test.ts +4 −5
@@ -4,7 +4,6 @@
44 * whose boxes are all ticked, and an issue held for boxes gets the same pass
55 * once. A builder is still never sent to redo shipped work.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { passOf } from "../src/actions/box_pass.ts";
1514 import { openIssue } from "../src/actions/issues.ts";
1615 import { mergePull, openPull, submitReview } from "../src/actions/pulls.ts";
1716 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { PASS_LEAD, tickBoxes, unticked } from "../src/core/done_on_main.ts";
2019 import { addComment, getIssueById, listComments, updateIssueText, type Issue } from "../src/core/issues.ts";
2120 import { getPull, type Pull } from "../src/core/pulls.ts";
@@ -115,8 +114,8 @@ describe("the reviewer's pass over the boxes", () => {
115114 if (!created.ok) throw new Error(String(created.error));
116115 expect(addToCrew(app, alice, made.value, agent).ok).toBe(true);
117116 }
118 seatAs(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
119 seatAs(app.db, made.value.id, getUserByName(app.db, "vesper")!.id, "reviewer");
117 setCrewRole(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
118 setCrewRole(app.db, made.value.id, getUserByName(app.db, "vesper")!.id, "reviewer");
120119 vesper = getUserByName(app.db, "vesper")!;
121120 mason = getUserByName(app.db, "mason")!;
122121 const set = await updateRepoSettings(app, alice, made.value, {
@@ -383,7 +382,7 @@ describe("the review-states door", () => {
383382 const created = await createAgent(app, alice, { username: "vesper" });
384383 if (!created.ok) throw new Error(String(created.error));
385384 addToCrew(app, alice, repo, "vesper");
386 seatAs(app.db, repo.id, getUserByName(app.db, "vesper")!.id, "reviewer");
385 setCrewRole(app.db, repo.id, getUserByName(app.db, "vesper")!.id, "reviewer");
387386 token = tokenFor(app, "vesper", "rw");
388387 const seeded = await commitToBranch(app, alice, repo, {
389388 message: "Start",
test/client-home.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * developer's words.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -18,7 +17,7 @@ import { getAppByRepo } from "../src/core/apps.ts";
1817 import { clientApps } from "../src/web/studio/client_home.ts";
1918 import type { Ctx } from "../src/http/context.ts";
2019 import { clientAppRows, cutTitle, doingLine } from "../src/core/client-apps.ts";
21 import { addCrew, createAgentRow } from "../src/core/agents.ts";
20 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
2221 import { moveArchived } from "../src/core/repos.ts";
2322 import { createSession } from "../src/core/sessions.ts";
2423 import { linkEveryday } from "../src/core/everyday.ts";
@@ -104,7 +103,7 @@ describe("a client's first screen", () => {
104103 createdBy: alice.id,
105104 });
106105 addCrew(parent.db, repo.value.id, atlas.value.id, alice.id);
107 seatAs(parent.db, repo.value.id, atlas.value.id, "planner");
106 setCrewRole(parent.db, repo.value.id, atlas.value.id, "planner");
108107 parentServers = await serve(parent);
109108 const spawned = await spawnForge(
110109 parent,
test/crew-direction-autonomy.test.ts +3 −4
@@ -6,7 +6,6 @@
66 * here starts a real agent: an assignment, a queued run or a merge is the
77 * observable effect, and each must not happen.
88 */
9 import { seatAs } from "./helpers/seat.ts";
109 import {
1110 afterAll,
1211 beforeAll,
@@ -36,7 +35,7 @@ import {
3635 updateRepoSettings,
3736 } from "../src/actions/repos.ts";
3837 import { tell } from "../src/actions/tell.ts";
39 import {} from "../src/core/agents.ts";
38 import { setCrewRole } from "../src/core/agents.ts";
4039 import { readyNow, repoGraph } from "../src/core/dependencies.ts";
4140 import {
4241 getIssue,
@@ -122,8 +121,8 @@ async function autonomous(): Promise<Repo> {
122121 );
123122 for (const name of ["mason", "atlas", "judge"])
124123 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
125 seatAs(app.db, repo.id, atlas.id, "planner");
126 seatAs(app.db, repo.id, judge.id, "reviewer");
124 setCrewRole(app.db, repo.id, atlas.id, "planner");
125 setCrewRole(app.db, repo.id, judge.id, "reviewer");
127126 ok(
128127 await updateRepoSettings(app, alice, repo, {
129128 autonomy: "autonomous",
test/crew-direction-cap.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * bounds planning is the breaker, the replan floor, the hold, the dollar
55 * ceiling — and the direction's own, generous day's share.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { assignIssue, openIssue, setIssueState } from "../src/actions/issues.ts";
1514 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { getIssueById, type Issue } from "../src/core/issues.ts";
1817 import { getRepoById, type Repo } from "../src/core/repos.ts";
1918 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
@@ -93,7 +92,7 @@ describe("the direction is paced, not capped", () => {
9392 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
9493 }
9594 atlas = getUserByName(app.db, "atlas")!;
96 seatAs(app.db, repo.id, atlas.id, "planner");
95 setCrewRole(app.db, repo.id, atlas.id, "planner");
9796 const set = await updateRepoSettings(app, alice, repo, {
9897 autonomy: "autonomous",
9998 autonomyDirection: "Keep the engine small.",
test/crew-direction.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * steers a run. A reader's words stay on the thread and do nothing more,
66 * and a run's brief quotes them as a reader's, never as an instruction.
77 */
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
1110 import { mkdtemp, rm } from "node:fs/promises";
@@ -26,7 +25,7 @@ import {
2625 updateRepoSettings,
2726 } from "../src/actions/repos.ts";
2827 import { steerRepoRun } from "../src/actions/runs.ts";
29 import { type Agent } from "../src/core/agents.ts";
28 import { setCrewRole, type Agent } from "../src/core/agents.ts";
3029 import { listEvents } from "../src/core/events.ts";
3130 import { getIssue, listComments, type Issue } from "../src/core/issues.ts";
3231 import { getPull } from "../src/core/pulls.ts";
@@ -137,7 +136,7 @@ fi
137136 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
138137 expect(addToCrew(app, alice, repo, "bot").ok).toBe(true);
139138 expect(addToCrew(app, alice, repo, "judge").ok).toBe(true);
140 seatAs(app.db, repo.id, judge.user.id, "reviewer");
139 setCrewRole(app.db, repo.id, judge.user.id, "reviewer");
141140 }, 30_000);
142141
143142 afterAll(async () => {
test/crew-guard.test.ts +2 −3
@@ -9,7 +9,6 @@
99 * since its last pass (#1097). Each skip and cap is counted for the
1010 * token-return view.
1111 */
12 import { seatAs } from "./helpers/seat.ts";
1312 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1413 import { mkdtemp, rm } from "node:fs/promises";
1514 import { tmpdir } from "node:os";
@@ -27,7 +26,7 @@ import {
2726 updateRepoSettings,
2827 } from "../src/actions/repos.ts";
2928 import { readUsage } from "../src/actions/usage.ts";
30 import { getAgent, type Agent } from "../src/core/agents.ts";
29 import { getAgent, setCrewRole, type Agent } from "../src/core/agents.ts";
3130 import { listDecisions } from "../src/core/decisions.ts";
3231 import {
3332 getIssueById,
@@ -418,7 +417,7 @@ describe("the planner is not given the direction again with nothing new (#1097)"
418417 );
419418 for (const name of ["bot", "atlas"])
420419 expect(addToCrew(app, alice, round, name).ok).toBe(true);
421 seatAs(app.db, round.id, atlas.user.id, "planner");
420 setCrewRole(app.db, round.id, atlas.user.id, "planner");
422421 ok(
423422 await updateRepoSettings(app, alice, round, {
424423 autonomy: "autonomous",
test/crew-held.test.ts +3 −4
@@ -6,7 +6,6 @@
66 * terminal's Flow dialog show the same counts, private repositories to the
77 * owner only. Each test makes its own repository and crew.
88 */
9 import { seatAs } from "./helpers/seat.ts";
109 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1110 import { mkdtemp, rm } from "node:fs/promises";
1211 import { tmpdir } from "node:os";
@@ -16,7 +15,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1615 import { addComment, assignIssue, openIssue } from "../src/actions/issues.ts";
1716 import { openPull } from "../src/actions/pulls.ts";
1817 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
19 import { getAgentByName } from "../src/core/agents.ts";
18 import { getAgentByName, setCrewRole } from "../src/core/agents.ts";
2019 import { getIssueById, listIssues, type Issue } from "../src/core/issues.ts";
2120 import { getRepoById, type Repo } from "../src/core/repos.ts";
2221 import { DONE_NOTE } from "../src/core/done_on_main.ts";
@@ -50,7 +49,7 @@ async function crewed(
5049 }
5150 expect(addToCrew(app, alice, made.value, agent).ok).toBe(true);
5251 }
53 seatAs(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
52 setCrewRole(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
5453 const set = await updateRepoSettings(app, alice, made.value, {
5554 autonomy: "autonomous",
5655 autonomyDirection: "Keep the engine small.",
@@ -273,7 +272,7 @@ describe("the tick says why each ready issue cannot start", () => {
273272 if (!made.ok) throw new Error(String(made.error));
274273 expect(addToCrew(app, alice, fresh(), "sentinel").ok).toBe(true);
275274 const sentinel = getUserByName(app.db, "sentinel")!;
276 seatAs(app.db, repo.id, sentinel.id, "reviewer");
275 setCrewRole(app.db, repo.id, sentinel.id, "reviewer");
277276
278277 // A lane past its budget: the sentinel files it at once, unassigned.
279278 const now = Date.now();
test/crew-hot-files.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * the feed, and the feed through the MCP. The hold lifts when the pile
66 * drains under five.
77 */
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1514 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1615 import { openPull } from "../src/actions/pulls.ts";
1716 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { getIssueById, type Issue } from "../src/core/issues.ts";
2019 import type { Pull } from "../src/core/pulls.ts";
2120 import { getRepoById, type Repo } from "../src/core/repos.ts";
@@ -123,7 +122,7 @@ describe("the picker holds a build on a hot file", () => {
123122 if (!created.ok) throw new Error(String(created.error));
124123 expect(addToCrew(app, alice, made.value, agent).ok).toBe(true);
125124 }
126 seatAs(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
125 setCrewRole(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
127126 const set = await updateRepoSettings(app, alice, made.value, {
128127 autonomy: "autonomous",
129128 autonomyDirection: "Keep the engine small.",
test/crew-loop.test.ts +7 −10
@@ -4,7 +4,6 @@
44 * leaves no comment; a finished planning run lets go of the direction; three
55 * failed runs in an hour park the issue until a person speaks.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -19,7 +18,7 @@ import { HANDOVER_NOTE, handedOverPulls, handoverOf } from "../src/crew/guard.ts
1918 import { addReviewComment } from "../src/core/reviews.ts";
2019 import { sendToReview, waitsForPerson } from "../src/crew/review.ts";
2120 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
22 import {} from "../src/core/agents.ts";
21 import { setCrewRole } from "../src/core/agents.ts";
2322 import { getIssueById, listComments, type Issue } from "../src/core/issues.ts";
2423 import { getRepoById, type Repo } from "../src/core/repos.ts";
2524 import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
@@ -75,7 +74,7 @@ describe("an agent's own comment never starts its next run", () => {
7574 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
7675 }
7776 atlas = getUserByName(app.db, "atlas")!;
78 seatAs(app.db, repo.id, atlas.id, "planner");
77 setCrewRole(app.db, repo.id, atlas.id, "planner");
7978 const set = await updateRepoSettings(app, alice, repo, {
8079 autonomy: "autonomous",
8180 autonomyDirection: "Keep the engine small.",
@@ -139,15 +138,13 @@ describe("an agent's own comment never starts its next run", () => {
139138 if (!issued.ok) throw new Error(String(issued.error));
140139 const issue = issued.value;
141140 const { assignIssue } = await import("../src/actions/issues.ts");
142 // A builder: an issue assigned to the planner is explained, not run (#8907).
143 const builder = getUserByName(app.db, "mason")!;
144 assignIssue(app, alice, fresh(), issue, builder);
141 assignIssue(app, alice, fresh(), issue, atlas);
145142 await new Promise((r) => setTimeout(r, 50));
146143 // The person's assignment started one run; the agent's words add none.
147144 expect(agentRuns(issue).length).toBe(1);
148145 const before = agentRuns(issue).length;
149146 for (let i = 0; i < 5; i++) {
150 addComment(app, builder, fresh(), issue, `Declined: not feedback ${i}`);
147 addComment(app, atlas, fresh(), issue, `Declined: not feedback ${i}`);
151148 await new Promise((r) => setTimeout(r, 20));
152149 }
153150 expect(agentRuns(issue).length).toBe(before);
@@ -158,13 +155,13 @@ describe("an agent's own comment never starts its next run", () => {
158155 const issued = openIssue(app, alice, fresh(), { title: "Stuck", body: "" });
159156 if (!issued.ok) throw new Error(String(issued.error));
160157 const issue = issued.value;
161 const agent = getAgent(app.db, getUserByName(app.db, "mason")!.id)!;
158 const agent = getAgent(app.db, atlas.id)!;
162159 for (let i = 0; i < 3; i++) {
163160 const r = createRun(app.db, {
164161 repoId: repo.id,
165162 kind: "agent",
166163 issueId: issue.id,
167 actorId: getUserByName(app.db, "mason")!.id,
164 actorId: atlas.id,
168165 reason: "feedback",
169166 });
170167 claimRun(app.db, r.id);
@@ -248,7 +245,7 @@ describe("a crew reviewer's changes-requested wakes the builder", () => {
248245 }
249246 mason = getUserByName(app.db, "mason")!;
250247 sentinel = getUserByName(app.db, "sentinel")!;
251 seatAs(app.db, repo.id, sentinel.id, "reviewer");
248 setCrewRole(app.db, repo.id, sentinel.id, "reviewer");
252249 crew = await startCrew(app, {
253250 forgeUrl: "http://127.0.0.1:1",
254251 localUrl: "http://127.0.0.1:1",
test/crew-parks-planner.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * migration 43 rewords old outage parks so they no longer count. Split from
55 * `test/crew-parks.test.ts`, whose `engine` it shares.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { Database } from "bun:sqlite";
109 import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
@@ -12,7 +11,7 @@ import { join } from "node:path";
1211 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1312 import { openPull } from "../src/actions/pulls.ts";
1413 import { commitToBranch } from "../src/actions/repos.ts";
15 import {} from "../src/core/agents.ts";
14 import { setCrewRole } from "../src/core/agents.ts";
1615 import { listRuns } from "../src/core/runs.ts";
1716 import { migrations } from "../src/core/schema.ts";
1817 import { submitReview } from "../src/core/reviews.ts";
@@ -133,7 +132,7 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"Nothing to
133132 if (!agent.ok) throw new Error(String(agent.error));
134133 expect(addToCrew(e.app, e.alice, e.fresh(), "sentinel").ok).toBe(true);
135134 const sentinel = getUserByName(e.app.db, "sentinel")!;
136 seatAs(e.app.db, e.repo.id, sentinel.id, "reviewer");
135 setCrewRole(e.app.db, e.repo.id, sentinel.id, "reviewer");
137136 const branch = await commitToBranch(e.app, e.alice, e.fresh(), {
138137 branch: "feature/spent",
139138 base: "main",
test/crew-reserve.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * brief names the target; the tick line says `reserve=startable/target`;
55 * and only a pass that did not end well waits out the 20-minute floor.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { addComment, openIssue, setIssueState } from "../src/actions/issues.ts";
1514 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
16 import { getAgentByName } from "../src/core/agents.ts";
15 import { getAgentByName, setCrewRole } from "../src/core/agents.ts";
1716 import { getIssueById, type Issue } from "../src/core/issues.ts";
1817 import { getRepoById, type Repo } from "../src/core/repos.ts";
1918 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
@@ -106,7 +105,7 @@ describe("a planner that keeps a standing reserve", () => {
106105 }
107106 mason = getUserByName(app.db, "mason")!;
108107 atlas = getUserByName(app.db, "atlas")!;
109 seatAs(app.db, repo.id, atlas.id, "planner");
108 setCrewRole(app.db, repo.id, atlas.id, "planner");
110109 // Seven slots, every one of them busy: seven issues with a run in flight.
111110 for (let n = 0; n < 7; n++) {
112111 const opened = openIssue(app, alice, repo, { title: `Busy ${n}` });
test/crew-review-budget.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * `crew.test.ts` so each part runs apart (#1798).
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import type { App } from "../src/app.ts";
109 import type { Repo } from "../src/core/repos.ts";
@@ -13,7 +12,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1312 import { openPull } from "../src/actions/pulls.ts";
1413 import { commitToBranch } from "../src/actions/repos.ts";
1514 import { queueAgentRun } from "../src/crew/dispatch.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { getIssue } from "../src/core/issues.ts";
1817 import { listRuns, type Run } from "../src/core/runs.ts";
1918 import {
@@ -46,7 +45,7 @@ describe("the crew, with a stand-in Claude Code: review budget", () => {
4645 const made = await createAgent(app, alice, { username: "slowrev" });
4746 if (!made.ok) throw new Error(String(made.error));
4847 expect(addToCrew(app, alice, repo, "slowrev").ok).toBe(true);
49 seatAs(app.db, repo.id, made.value.user.id, "reviewer");
48 setCrewRole(app.db, repo.id, made.value.user.id, "reviewer");
5049 const branch = await commitToBranch(app, alice, repo, {
5150 branch: "slow-fence",
5251 base: "main",
test/crew-review.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * `crew.test.ts` so each part runs apart (#1798).
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { readFileSync } from "node:fs";
109 import type { App } from "../src/app.ts";
@@ -14,7 +13,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch } from "../src/actions/repos.ts";
1615 import { queueAgentRun } from "../src/crew/dispatch.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import { getIssue, listComments } from "../src/core/issues.ts";
1918 import { listReviews } from "../src/core/reviews.ts";
2019 import type { Run } from "../src/core/runs.ts";
@@ -48,7 +47,7 @@ describe("the crew, with a stand-in Claude Code: review", () => {
4847 const made = await createAgent(app, alice, { username: "rev" });
4948 if (!made.ok) throw new Error(String(made.error));
5049 expect(addToCrew(app, alice, repo, "rev").ok).toBe(true);
51 seatAs(app.db, repo.id, made.value.user.id, "reviewer");
50 setCrewRole(app.db, repo.id, made.value.user.id, "reviewer");
5251 const branch = await commitToBranch(app, alice, repo, {
5352 branch: "fence",
5453 base: "main",
test/crew-roles.test.ts deleted −141
@@ -1,141 +0,0 @@
1 /**
2 * An agent's roles are its own config (#8907): a repository narrows them and
3 * never widens them, a dispatch never hands over a job outside them, and
4 * /migrate offers builders only.
5 */
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { mkdtemp } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { addToCrew, askedRoles, createAgent, updateAgent } from "../src/actions/crew.ts";
12 import { openIssue } from "../src/actions/issues.ts";
13 import { crewRole, getAgentByName, type Agent } from "../src/core/agents.ts";
14 import { createRepo, type Repo } from "../src/core/repos.ts";
15 import { createUser, type User } from "../src/core/users.ts";
16 import { outsideSeat } from "../src/crew/dispatch.ts";
17 import { migrationBuilders, prefill } from "../src/web/pages/migrate-prefill.ts";
18 import { quietLogs } from "./helpers/globals.ts";
19
20 quietLogs();
21
22 let app: App;
23 let admin: User;
24 let repo: Repo;
25
26 const agent = (name: string): Agent => getAgentByName(app.db, name)!;
27
28 beforeAll(async () => {
29 app = createApp({ dataDir: await mkdtemp(join(tmpdir(), "forge-roles-")), port: 0 });
30 const made = await createUser(app.db, { origin: "seed", username: "alice", email: "[email protected]", password: "a-long-crew-passphrase", adminIfFirst: true, trusted: true });
31 if (!made.ok) throw new Error("user");
32 admin = made.value;
33 const r = await createRepo(app.db, app.reposRoot, { ownerId: admin.id, name: "yard", visibility: "public" });
34 if (!r.ok) throw new Error(String(r.error));
35 repo = r.value;
36 const make = async (username: string, roles?: string[]) => {
37 const a = await createAgent(app, admin, { username, ...(roles ? { roles } : {}) });
38 if (!a.ok) throw new Error(`${username}: ${a.error}`);
39 };
40 await make("atlas", ["planner"]);
41 await make("both", ["planner", "builder"]);
42 await make("mason", ["builder"]);
43 await make("rev", ["reviewer"]);
44 await make("plain");
45 });
46 afterAll(() => app.db.close());
47
48 describe("roles are the agent's config", () => {
49 test("an agent says its roles; none given reads as builder, bad ones are refused", () => {
50 expect(agent("atlas").roles).toEqual(["planner"]);
51 expect(agent("both").roles).toEqual(["planner", "builder"]);
52 expect(agent("plain").roles).toEqual(["builder"]);
53 const bad = updateAgent(app, admin, "mason", { roles: ["boss"] });
54 expect(bad.ok ? "" : bad.error).toBe("invalid_roles");
55 const empty = updateAgent(app, admin, "mason", { roles: [] });
56 expect(empty.ok ? "" : empty.error).toBe("invalid_roles");
57 expect(agent("mason").roles).toEqual(["builder"]);
58 });
59
60 test("a repository can narrow a role, never widen it", () => {
61 const widened = addToCrew(app, admin, repo, "atlas", "builder");
62 expect(widened.ok ? "" : widened.error).toBe("role_not_declared");
63 expect(crewRole(app.db, repo.id, agent("atlas").user.id)).toBeUndefined();
64 expect(addToCrew(app, admin, repo, "both", "builder").ok).toBe(true);
65 expect(crewRole(app.db, repo.id, agent("both").user.id)).toBe("builder");
66 });
67
68 test("no role named: the first the agent declares, never builder by default", () => {
69 expect(addToCrew(app, admin, repo, "rev").ok).toBe(true);
70 expect(crewRole(app.db, repo.id, agent("rev").user.id)).toBe("reviewer");
71 });
72
73 test("taking a role an agent still holds on a repository is refused, not moved silently", () => {
74 const held = updateAgent(app, admin, "both", { roles: ["planner"] });
75 expect(held.ok ? "" : held.error).toBe("role_held");
76 expect(agent("both").roles).toEqual(["planner", "builder"]);
77 expect(crewRole(app.db, repo.id, agent("both").user.id)).toBe("builder");
78 expect(updateAgent(app, admin, "both", { roles: ["builder", "reviewer"] }).ok).toBe(true);
79 updateAgent(app, admin, "both", { roles: ["planner", "builder"] });
80 });
81
82 test("roles that are not a list of strings are invalid_roles, not ignored", () => {
83 for (const bad of ["planner", 3, null, { a: 1 }, [1], [["planner"]]]) {
84 const r = updateAgent(app, admin, "mason", { ...askedRoles(bad) });
85 expect(r.ok ? "" : r.error).toBe("invalid_roles");
86 }
87 expect(askedRoles(undefined)).toEqual({});
88 expect(agent("mason").roles).toEqual(["builder"]);
89 });
90 });
91
92 describe("a dispatch never hands over a job outside the seat", () => {
93 let issue: Awaited<ReturnType<typeof openIssue>> & { ok: true };
94 beforeAll(async () => {
95 const i = await openIssue(app, admin, repo, { title: "work" });
96 if (!i.ok) throw new Error(i.error);
97 issue = i as typeof issue;
98 addToCrew(app, admin, repo, "mason", "builder");
99 });
100
101 test("planner seat: a build is refused", () => {
102 app.db.query("UPDATE repo_crew SET role = 'planner' WHERE user_id = ?1").run(agent("both").user.id);
103 expect(outsideSeat(app, repo, issue.value, agent("both"), "assigned")).toBe(true);
104 });
105 test("builder seat: a build is allowed, a review is not", () => {
106 expect(outsideSeat(app, repo, issue.value, agent("mason"), "assigned")).toBe(false);
107 expect(outsideSeat(app, repo, issue.value, agent("mason"), "review")).toBe(true);
108 });
109 test("reviewer seat: a review is allowed, a build is not", () => {
110 expect(outsideSeat(app, repo, issue.value, agent("rev"), "review")).toBe(false);
111 expect(outsideSeat(app, repo, issue.value, agent("rev"), "assigned")).toBe(true);
112 });
113 });
114
115 describe("every kind of run keeps to the seat", () => {
116 const reasons = ["assigned", "feedback", "check_failed", "conflict", "resolve", "converge"] as const;
117 test("a non-builder is outside every building reason; a builder is outside a review", async () => {
118 const i = await openIssue(app, admin, repo, { title: "more work" });
119 if (!i.ok) throw new Error(i.error);
120 app.db.query("UPDATE repo_crew SET role = 'planner' WHERE user_id = ?1").run(agent("both").user.id);
121 for (const reason of reasons) {
122 expect(outsideSeat(app, repo, i.value, agent("both"), reason)).toBe(true);
123 expect(outsideSeat(app, repo, i.value, agent("rev"), reason)).toBe(true);
124 expect(outsideSeat(app, repo, i.value, agent("mason"), reason)).toBe(false);
125 }
126 expect(outsideSeat(app, repo, i.value, agent("mason"), "review")).toBe(true);
127 });
128 });
129
130 describe("/migrate offers builders only", () => {
131 test("a planner that sorts first is never the default; crew= naming it is refused in a sentence", () => {
132 const all = ["atlas", "both", "mason", "rev", "plain"].map(agent);
133 const builders = migrationBuilders(all).map((a) => a.user.username);
134 expect(builders).not.toContain("atlas");
135 expect(builders).not.toContain("rev");
136 expect(builders[0]).toBe("mason");
137 const linked = prefill({ crew: "atlas" }, [], builders, ["atlas", "rev"]);
138 expect(linked.agent).toBeUndefined();
139 expect(linked.refused[0]).toContain("atlas is not a builder");
140 });
141 });
test/crew-seats.test.ts +11 −13
@@ -4,14 +4,13 @@
44 * `addToCrew` names the seat only for an agent who joins now; the terminal's
55 * About card lists the seats and `p` fills one.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
1110 import { join } from "node:path";
1211 import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
14 import { crewRole, listCrewRoles, removeCrew } from "../src/core/agents.ts";
13 import { crewRole, listCrewRoles, removeCrew, setCrewRole } from "../src/core/agents.ts";
1514 import { createRepo, getRepoById, type Repo } from "../src/core/repos.ts";
1615 import { createUser, getUserByName, type User } from "../src/core/users.ts";
1716 import { seatsOf } from "../src/crew/seats.ts";
@@ -59,7 +58,7 @@ describe("the team's seats", () => {
5958 const made = await createRepo(app.db, app.reposRoot, { ownerId: alice.id, name: "yard", visibility: "public" });
6059 if (!made.ok) throw new Error(String(made.error));
6160 repo = made.value;
62 for (const name of ["aplan", "bbuild"]) if (!(await createAgent(app, alice, { username: name, roles: ["planner", "builder", "reviewer"] })).ok) throw new Error("agent");
61 for (const name of ["aplan", "bbuild"]) if (!(await createAgent(app, alice, { username: name })).ok) throw new Error("agent");
6362 cookies = { alice: await signIn("alice"), bob: await signIn("bob") };
6463 }, 30_000);
6564
@@ -84,31 +83,30 @@ describe("the team's seats", () => {
8483 expect(seatsOf(app.db, fresh(), true).auto).toBe(false);
8584 });
8685
87 test("each list picks from the agents that declare its role, for an admin only", async () => {
86 test("the card puts the first free agent on the seat it names, for an admin only", async () => {
8887 mode("autonomous");
8988 const html = await page("alice");
90 for (const role of ["planner", "builder", "reviewer"]) {
89 for (const role of ["planner", "builder", "reviewer"])
9190 expect(html).toContain(`name="role" value="${role}"`);
92 expect(html).toContain(`id="f-add-${role}"`);
93 }
94 expect(html).toContain('<option value="aplan">');
95 expect(html).toContain("Planners");
91 expect(html).toContain('name="agent" value="aplan"');
92 expect(html).toContain("Put aplan on reviewer");
9693 expect(await page("bob")).not.toContain('name="role"');
9794 });
9895
99 test("a filled seat names who fills it; the others still have a picker", async () => {
96 test("a filled seat names who fills it and has no button; the others still do", async () => {
10097 expect(addToCrew(app, alice, fresh(), "aplan", "planner").ok).toBe(true);
10198 expect(states()).toEqual({ planner: "filled", builder: "warn", reviewer: "warn" });
10299 expect(seatsOf(app.db, fresh()).seats[0]!.by).toEqual(["aplan"]);
103100 const html = await page("alice");
104 expect(html).toContain('data-member="aplan"');
105 expect(html).toContain('id="f-add-builder"');
101 expect(html).not.toContain('name="role" value="planner"');
102 expect(html).toContain('name="role" value="builder"');
103 expect(html).toContain('name="agent" value="bbuild"');
106104 expect(html).not.toContain("No planner:");
107105 expect(html).toContain("No builder: nothing gets built.");
108106 });
109107
110108 test("an agent already on the crew keeps its role", () => {
111 seatAs(app.db, repo.id, idOf("aplan"), "reviewer");
109 setCrewRole(app.db, repo.id, idOf("aplan"), "reviewer");
112110 const again = addToCrew(app, alice, fresh(), "aplan", "builder");
113111 expect(again.ok).toBe(true);
114112 expect(crewRole(app.db, repo.id, idOf("aplan"))).toBe("reviewer");
test/crew-settings-doors.test.ts +2 −2
@@ -97,7 +97,7 @@ describe("settings › crew doors", () => {
9797 });
9898 if (!made.ok) throw new Error(String(made.error));
9999 repo = made.value;
100 const bot = await createAgent(app, a.value, { username: "yardbot", roles: ["planner", "builder", "reviewer"] });
100 const bot = await createAgent(app, a.value, { username: "yardbot" });
101101 if (!bot.ok) throw new Error("agent");
102102 botId = bot.value.user.id;
103103 const sub = addSubscription(app.db, dataDir, {
@@ -106,7 +106,7 @@ describe("settings › crew doors", () => {
106106 });
107107 if (!sub.ok) throw new Error("subscription");
108108 subId = sub.value.id;
109 const other = await createAgent(app, a.value, { username: "otherbot", roles: ["planner", "builder", "reviewer"] });
109 const other = await createAgent(app, a.value, { username: "otherbot" });
110110 if (!other.ok) throw new Error("agent");
111111 otherId = other.value.user.id;
112112 const c = await createUser(app.db, {
test/crew-stalls.test.ts +2 −3
@@ -7,7 +7,6 @@
77 * The repositories are assisted, where nothing parks a stall when its run
88 * ends, so the tick is what frees it.
99 */
10 import { seatAs } from "./helpers/seat.ts";
1110 import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test";
1211 import { mkdtemp, rm } from "node:fs/promises";
1312 import { tmpdir } from "node:os";
@@ -17,7 +16,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1716 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1817 import { mergePull, openPull } from "../src/actions/pulls.ts";
1918 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
20 import { getAgentByName } from "../src/core/agents.ts";
19 import { getAgentByName, setCrewRole } from "../src/core/agents.ts";
2120 import { getIssueById, listComments, type Issue } from "../src/core/issues.ts";
2221 import { getRepoById, listAutonomousRepos, type Repo } from "../src/core/repos.ts";
2322 import {
@@ -56,7 +55,7 @@ async function crewed(builders: readonly string[]): Promise<Repo> {
5655 }
5756 expect(addToCrew(app, alice, created.value, name).ok).toBe(true);
5857 }
59 seatAs(app.db, created.value.id, getUserByName(app.db, "atlas")!.id, "planner");
58 setCrewRole(app.db, created.value.id, getUserByName(app.db, "atlas")!.id, "planner");
6059 const set = await updateRepoSettings(app, alice, created.value, {
6160 autonomy: "assisted",
6261 autonomyDirection: "Keep the engine small.",
test/decide.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * which case the rule's answer stands and the caller never knows the
55 * difference except by `by`.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openIssue } from "../src/actions/issues.ts";
1514 import { createRepo } from "../src/actions/repos.ts";
16 import { listCrewRoles } from "../src/core/agents.ts";
15 import { listCrewRoles, setCrewRole } from "../src/core/agents.ts";
1716 import { getIssueById } from "../src/core/issues.ts";
1817 import type { Repo } from "../src/core/repos.ts";
1918 import { createUser, getUserByName, type User } from "../src/core/users.ts";
@@ -253,7 +252,7 @@ describe("routing an issue", () => {
253252 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
254253 }
255254 scout = getUserByName(app.db, "scout")!;
256 seatAs(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner");
255 setCrewRole(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner");
257256 });
258257 afterAll(async () => {
259258 app.close();
test/finishing-attempts.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * and ended without a push. A run the forge cut short — a network error, a
55 * checkout that failed — is no attempt, and a new base is a new chance.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import type { Pull } from "../src/core/pulls.ts";
1817 import { getRepoById, type Repo } from "../src/core/repos.ts";
1918 import { submitReview } from "../src/core/reviews.ts";
@@ -74,7 +73,7 @@ beforeAll(async () => {
7473 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
7574 }
7675 const quill = getUserByName(app.db, "quill")!;
77 seatAs(app.db, repo.id, quill.id, "reviewer");
76 setCrewRole(app.db, repo.id, quill.id, "reviewer");
7877 const branch = await commitToBranch(app, alice, repo, {
7978 branch: "feature/1",
8079 base: "main",
test/finishing-pages.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * up to date. Its entry and every pull it drops are logged once per reason,
55 * and with no candidate the tick line says `0 candidates of N open`.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { createRun } from "../src/core/runs.ts";
1817 import type { Pull } from "../src/core/pulls.ts";
1918 import { getRepoById, type Repo } from "../src/core/repos.ts";
@@ -87,7 +86,7 @@ beforeAll(async () => {
8786 if (!agent.ok) throw new Error(String(agent.error));
8887 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
8988 }
90 seatAs(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
89 setCrewRole(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
9190 // The oldest pull edits the file main is about to change; fifty newer
9291 // ones each add their own file and merge clean.
9392 oldest = await pullOn(0, "export const zero = 'branch';\n");
test/finishing-room.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * queues no more bring-up-to-date runs — each a push, each a check — than
55 * the lane has slots for, however many builder slots are free.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { setCapacity } from "../src/core/capacity.ts";
1817 import type { Pull } from "../src/core/pulls.ts";
1918 import type { Repo } from "../src/core/repos.ts";
@@ -70,7 +69,7 @@ beforeAll(async () => {
7069 }
7170 const mason = getUserByName(app.db, "mason")!;
7271 const quill = getUserByName(app.db, "quill")!;
73 seatAs(app.db, repo.id, quill.id, "reviewer");
72 setCrewRole(app.db, repo.id, quill.id, "reviewer");
7473
7574 // Three approved pulls that all touch the file main is about to change.
7675 for (const n of [1, 2, 3]) {
test/finishing-skips.test.ts +3 −4
@@ -4,7 +4,6 @@
44 * only when the reason changes, and the tick line's
55 * `finishing="queued Q, in flight F, skipped S: <why>×k"`.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { setCapacity } from "../src/core/capacity.ts";
1817 import { setHold } from "../src/core/holds.ts";
1918 import type { Pull } from "../src/core/pulls.ts";
@@ -75,7 +74,7 @@ beforeAll(async () => {
7574 }
7675 const mason = getUserByName(app.db, "mason")!;
7776 const quill = getUserByName(app.db, "quill")!;
78 seatAs(app.db, repo.id, quill.id, "reviewer");
77 setCrewRole(app.db, repo.id, quill.id, "reviewer");
7978 for (const n of [1, 2, 3]) {
8079 const branch = await commitToBranch(app, alice, repo, {
8180 branch: `feature/${n}`,
@@ -148,7 +147,7 @@ test("a changed reason is said again, for that pull only", async () => {
148147 expect(full.skips[0]).toContain('finishing: skip pull=3 why="waits for room in the check lane"');
149148 expect(listRuns(app.db, repo.id, { kind: "agent" }).filter((r) => r.issueId === pulls[2]!.id)).toHaveLength(0);
150149
151 seatAs(app.db, repo.id, getUserByName(app.db, "mason")!.id, "reviewer");
150 setCrewRole(app.db, repo.id, getUserByName(app.db, "mason")!.id, "reviewer");
152151 const none = await pass(1);
153152 expect(none.skips).toHaveLength(1);
154153 expect(none.skips[0]).toContain(`finishing: skip pull=3 why=${JSON.stringify(NO_BUILDER_ON_CREW)}`);
test/finishing.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * updates that end without a push hand it to a person, on their review
55 * list, instead of closing it or trying again.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -14,7 +13,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openIssue } from "../src/actions/issues.ts";
1514 import { openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import { getIssueById, listComments, type Issue } from "../src/core/issues.ts";
1918 import type { Pull } from "../src/core/pulls.ts";
2019 import type { Repo } from "../src/core/repos.ts";
@@ -86,7 +85,7 @@ beforeAll(async () => {
8685 }
8786 mason = getUserByName(app.db, "mason")!;
8887 const quill = getUserByName(app.db, "quill")!;
89 seatAs(app.db, repo.id, quill.id, "reviewer");
88 setCrewRole(app.db, repo.id, quill.id, "reviewer");
9089
9190 const branch = await commitToBranch(app, alice, repo, {
9291 branch: "feature/shared",
test/first-login.test.ts +2 −3
@@ -7,7 +7,6 @@
77 * same three steps over the MCP.
88 */
99
10 import { seatAs } from "./helpers/seat.ts";
1110 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1211 import { orgAccessByOrg } from "../src/core/orgs.ts";
1312 import { getUserSetting } from "../src/core/settings.ts";
@@ -17,7 +16,7 @@ import { join } from "node:path";
1716 import { createRepo } from "../src/actions/repos.ts";
1817 import { childDirOf, spawnForge } from "../src/actions/spawn.ts";
1918 import { createApp, type App } from "../src/app.ts";
20 import { addCrew, createAgentRow } from "../src/core/agents.ts";
19 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
2120 import { createSession } from "../src/core/sessions.ts";
2221 import { createToken } from "../src/core/tokens.ts";
2322 import { createUser, getUserByName } from "../src/core/users.ts";
@@ -109,7 +108,7 @@ describe("the first login to a spawned forge", () => {
109108 createdBy: alice.id,
110109 });
111110 addCrew(parent.db, repo.value.id, atlas.value.id, alice.id);
112 seatAs(parent.db, repo.value.id, atlas.value.id, "planner");
111 setCrewRole(parent.db, repo.value.id, atlas.value.id, "planner");
113112 parentServers = await serve(parent);
114113 const spawned = await spawnForge(
115114 parent,
test/guests.test.ts +2 −5
@@ -4,7 +4,6 @@
44 * can; and every older refusal keeps its own reason.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { setArchivedIn } from "./helpers/archive.ts";
109 import { mkdtemp, rm } from "node:fs/promises";
@@ -15,7 +14,7 @@ import { changeCapacity } from "../src/actions/capacity.ts";
1514 import { proposePlan } from "../src/actions/plan.ts";
1615 import { redirectProposal } from "../src/actions/proposals.ts";
1716 import { ARCHIVED_WHY } from "../src/core/repos.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { getProposal } from "../src/core/proposals.ts";
2019 import { listComments } from "../src/core/issues.ts";
2120 import { ensureDirectionIssue } from "../src/crew/autonomy.ts";
@@ -267,7 +266,7 @@ describe("a guest cannot own, copy or run", () => {
267266 expect(assigned).toBe(0);
268267 });
269268 test("redirecting a wave: a guest's own pending proposal is refused before anything is written", async () => {
270 seatAs(app.db, lab.id, helper.id, "planner");
269 setCrewRole(app.db, lab.id, helper.id, "planner");
271270 const direction = ensureDirectionIssue(app, alice, lab)!;
272271 const proposed = proposePlan(app, alice, lab, [{ key: "a", title: "Weed", body: "", blockedBy: [] }], {
273272 title: "Spring",
@@ -314,8 +313,6 @@ describe("a guest cannot own, copy or run", () => {
314313 });
315314
316315 test("the wake-up sweep starts no run on an issue a guest assigned, and a hundred of them do not hold back a member's", async () => {
317 // Back to building: a dispatch gives a planner no build (#8907).
318 seatAs(app.db, lab.id, helper.id, "builder");
319316 // As an assignment made before the guard (or by a member since demoted):
320317 // the agent set, the event kept.
321318 const assignedBy = (who: User, title: string) => {
test/handover-give-back.test.ts +3 −4
@@ -4,7 +4,6 @@
44 * and the card leaves; a foreign Origin is refused; a reader gets a 404.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { chmodSync, writeFileSync } from "node:fs";
109 import { addComment } from "../src/actions/issues.ts";
@@ -13,7 +12,7 @@ import { mkdtemp, rm } from "node:fs/promises";
1312 import { tmpdir } from "node:os";
1413 import { join } from "node:path";
1514 import { createApp, type App } from "../src/app.ts";
16 import { addCrew, createAgentRow } from "../src/core/agents.ts";
15 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1716 import { getIssueById, listComments, setAssignee } from "../src/core/issues.ts";
1817 import { handoverOf } from "../src/crew/guard.ts";
1918 import { createRepo, type Repo } from "../src/core/repos.ts";
@@ -147,7 +146,7 @@ describe("give a handed-over pull back to the crew", () => {
147146 if (!made.ok) throw new Error(`seed repo: ${made.error}`);
148147 repo = made.value;
149148 for (const agent of [builder, reviewer]) addCrew(app.db, repo.id, agent.id, owner.id);
150 seatAs(app.db, repo.id, reviewer.id, "reviewer");
149 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
151150 cookie = await signIn("alice", "a-good-passphrase");
152151 readerCookie = await signIn("reader", "a-good-passphrase");
153152 }, 30_000);
@@ -227,7 +226,7 @@ describe("give a handed-over pull back to the crew", () => {
227226 if (!planner.ok) throw new Error(planner.error);
228227 createAgentRow(app.db, { userId: planner.value.id, brief: "plans." });
229228 addCrew(app.db, repo.id, planner.value.id, owner.id);
230 seatAs(app.db, repo.id, planner.value.id, "planner");
229 setCrewRole(app.db, repo.id, planner.value.id, "planner");
231230 const fake = join(dataDir, "fake-claude.sh");
232231 writeFileSync(
233232 fake,
test/helpers/parks-engine.ts +2 −3
@@ -1,4 +1,3 @@
1 import { seatAs } from "./seat.ts";
21 import { expect } from "bun:test";
32 import { mkdtemp, rm } from "node:fs/promises";
43 import { tmpdir } from "node:os";
@@ -7,7 +6,7 @@ import { createApp } from "../../src/app.ts";
76 import { addToCrew, createAgent } from "../../src/actions/crew.ts";
87 import { openIssue } from "../../src/actions/issues.ts";
98 import { createRepo, updateRepoSettings } from "../../src/actions/repos.ts";
10 import {} from "../../src/core/agents.ts";
9 import { setCrewRole } from "../../src/core/agents.ts";
1110 import type { Issue } from "../../src/core/issues.ts";
1211 import { getRepoById } from "../../src/core/repos.ts";
1312 import { claimRun, createRun, finishRun } from "../../src/core/runs.ts";
@@ -49,7 +48,7 @@ export async function engine(
4948 }
5049 const atlas = getUserByName(app.db, "atlas")!;
5150 const mason = getUserByName(app.db, "mason")!;
52 seatAs(app.db, repo.id, atlas.id, "planner");
51 setCrewRole(app.db, repo.id, atlas.id, "planner");
5352 const set = await updateRepoSettings(app, alice, repo, {
5453 autonomy: "autonomous",
5554 autonomyDirection: "Keep the engine small.",
test/helpers/seat.ts deleted −14
@@ -1,14 +0,0 @@
1 /**
2 * Seat an agent for a test: widens what it declares to include the seat, then
3 * sets it on the repository. The product only ever narrows (#8907); a test
4 * that wants a planner out of a plain agent says so here.
5 */
6 import type { Database } from "bun:sqlite";
7 import { getAgent, parseRoles, setCrewRole, type CrewRole } from "../../src/core/agents.ts";
8
9 export function seatAs(db: Database, repoId: string, userId: string, role: CrewRole): boolean {
10 const agent = getAgent(db, userId);
11 if (agent && !agent.roles.includes(role))
12 db.query("UPDATE agent SET roles = ?2 WHERE user_id = ?1").run(userId, parseRoles([...agent.roles, role].join(",")).join(","));
13 return setCrewRole(db, repoId, userId, role);
14 }
test/holds.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * or lands it. The refusals come first.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { openIssue } from "../src/actions/issues.ts";
1514 import { mergePull, openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1716 import { createApp, type App } from "../src/app.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { createApp as insertApp } from "../src/core/apps.ts";
2019 import {
2120 cleanWhy,
@@ -454,7 +453,7 @@ describe("a held pull and the rules", () => {
454453 });
455454
456455 test("a held green pull with an approving review does not land", async () => {
457 seatAs(f.app.db, f.repo.id, quill.id, "reviewer");
456 setCrewRole(f.app.db, f.repo.id, quill.id, "reviewer");
458457 const pull = await greenPull("approved", mason);
459458 approve(pull, f.alice);
460459 hold(pull);
test/issue-teams-doors.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * on the crew can ask never stops the pull being reviewed.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { openIssue } from "../src/actions/issues.ts";
1514 import { openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1716 import { createApp, type App } from "../src/app.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { listEvents } from "../src/core/events.ts";
2019 import { teamsOfIssue, teamVerdicts } from "../src/core/issue_teams.ts";
2120 import type { Issue } from "../src/core/issues.ts";
@@ -143,7 +142,7 @@ describe("naming teams, at every door", () => {
143142 const agent = await createAgent(app, alice, { username: "quill" });
144143 if (!agent.ok) throw new Error(String(agent.error));
145144 addToCrew(app, alice, repo, "quill");
146 seatAs(app.db, repo.id, id("quill"), "reviewer");
145 setCrewRole(app.db, repo.id, id("quill"), "reviewer");
147146 }, 30_000);
148147
149148 afterAll(async () => {
test/issue-teams.test.ts +3 −4
@@ -4,7 +4,6 @@
44 * and the naming is a writer's, validated at the boundary.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { openIssue } from "../src/actions/issues.ts";
1514 import { openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1716 import { createApp, type App } from "../src/app.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { teamsOfIssue, teamVerdicts } from "../src/core/issue_teams.ts";
2019 import type { Issue } from "../src/core/issues.ts";
2120 import type { Pull } from "../src/core/pulls.ts";
@@ -115,7 +114,7 @@ describe("cross-team work", () => {
115114 const agent = await createAgent(app, alice, { username: name });
116115 if (!agent.ok) throw new Error(String(agent.error));
117116 addToCrew(app, alice, repo, name);
118 seatAs(app.db, repo.id, id(name), "reviewer");
117 setCrewRole(app.db, repo.id, id(name), "reviewer");
119118 }
120119 });
121120 await step("teams", () => {
@@ -192,7 +191,7 @@ describe("cross-team work", () => {
192191 const agent = await createAgent(app, alice, { username: "ember" });
193192 if (!agent.ok) throw new Error(String(agent.error));
194193 addToCrew(app, alice, repo, "ember");
195 seatAs(app.db, repo.id, id("ember"), "reviewer");
194 setCrewRole(app.db, repo.id, id("ember"), "reviewer");
196195 saveTeam(app.db, "security", { charter: "", dial: 0, members: [id("ember")] });
197196 saveTeam(app.db, "platform", { charter: "", dial: 0, members: [id("ember")] });
198197 const pull = await pullClosing(issueNaming(["security", "platform"]));
test/landed-held.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * holds it under `landed`, and a person's comment or edit since the merge
55 * makes it pickable again; an agent's word does not.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -14,7 +13,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { addComment, editIssue, openIssue } from "../src/actions/issues.ts";
1514 import { mergePull, openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import { landedNote } from "../src/core/done_on_main.ts";
1918 import type { ForgeEvent } from "../src/core/events.ts";
2019 import { getIssueById, listComments, setAssignee, type Issue } from "../src/core/issues.ts";
@@ -80,7 +79,7 @@ describe("a landing with boxes unticked waits for a person", () => {
8079 if (!created.ok) throw new Error(String(created.error));
8180 expect(addToCrew(app, alice, made.value, agent).ok).toBe(true);
8281 }
83 seatAs(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
82 setCrewRole(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
8483 mason = getUserByName(app.db, "mason")!;
8584 const set = await updateRepoSettings(app, alice, made.value, {
8685 autonomy: "autonomous",
test/ledger.test.ts +2 −3
@@ -3,7 +3,6 @@
33 * ship or show, try again or stop — each with a rule underneath and a fake
44 * decider on top, and each written down with what came of it.
55 */
6 import { seatAs } from "./helpers/seat.ts";
76 import { beforeAll, afterAll, describe, expect, test } from "bun:test";
87 import { mkdtemp, rm } from "node:fs/promises";
98 import { tmpdir } from "node:os";
@@ -31,7 +30,7 @@ import { submitReview } from "../src/core/reviews.ts";
3130 import { provideChecksForTest, type ChecksHandle } from "../src/checks/service.ts";
3231 import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
3332 import { createUser, getUserByName, type User } from "../src/core/users.ts";
34 import {} from "../src/core/agents.ts";
33 import { setCrewRole } from "../src/core/agents.ts";
3534 import type { Answer, Decider, Questions } from "../src/crew/decide.ts";
3635 import { driveRepo, landIfGreen } from "../src/crew/autonomy.ts";
3736 import { summariseCheckFailure } from "../src/checks/summary.ts";
@@ -104,7 +103,7 @@ describe("the decision ledger", () => {
104103 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
105104 }
106105 scout = getUserByName(app.db, "scout")!;
107 seatAs(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner");
106 setCrewRole(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner");
108107 updateRepoSettings(app.db, repo, {
109108 autonomy: "autonomous",
110109 autonomyDirection: "Sell one real thing end to end.",
test/limb-replan.test.ts +2 −3
@@ -7,7 +7,6 @@
77 * closes only as split into what is new; a person takes it back before it
88 * runs; the milestone shows the change.
99 */
10 import { seatAs } from "./helpers/seat.ts";
1110 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1211 import { mkdtemp, rm } from "node:fs/promises";
1312 import { tmpdir } from "node:os";
@@ -18,7 +17,7 @@ import { linkIssue } from "../src/actions/dependencies.ts";
1817 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1918 import { previewReplan, replanLimb, takeBackLimb } from "../src/actions/limb_replan.ts";
2019 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
21 import {} from "../src/core/agents.ts";
20 import { setCrewRole } from "../src/core/agents.ts";
2221 import { readyNow, repoGraph } from "../src/core/dependencies.ts";
2322 import { getIssueById, type Issue } from "../src/core/issues.ts";
2423 import { pendingReplans, replanSince } from "../src/core/limb_replan.ts";
@@ -142,7 +141,7 @@ describe("a limb handed to the planner", () => {
142141 }
143142 atlas = getUserByName(app.db, "atlas")!;
144143 mason = getUserByName(app.db, "mason")!;
145 seatAs(app.db, repo.id, atlas.id, "planner");
144 setCrewRole(app.db, repo.id, atlas.id, "planner");
146145 const set = await updateRepoSettings(app, alice, repo, {
147146 autonomy: "autonomous",
148147 autonomyDirection: "Keep the engine small.",
test/limbs.test.ts +2 −3
@@ -9,7 +9,6 @@
99 * writes, what something outside the limb still needs is never taken, and
1010 * undo puts it back.
1111 */
12 import { seatAs } from "./helpers/seat.ts";
1312 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1413 import { mkdtemp, rm } from "node:fs/promises";
1514 import { tmpdir } from "node:os";
@@ -21,7 +20,7 @@ import { undoFleetOp } from "../src/actions/fleet.ts";
2120 import { openIssue, setIssueState } from "../src/actions/issues.ts";
2221 import { applyLimb, previewLimb } from "../src/actions/limbs.ts";
2322 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
24 import {} from "../src/core/agents.ts";
23 import { setCrewRole } from "../src/core/agents.ts";
2524 import {
2625 dependenciesOf,
2726 readyNow,
@@ -203,7 +202,7 @@ describe("limb actions", () => {
203202 }
204203 mason = getUserByName(app.db, "mason")!;
205204 atlas = getUserByName(app.db, "atlas")!;
206 seatAs(app.db, engine.id, atlas.id, "planner");
205 setCrewRole(app.db, engine.id, atlas.id, "planner");
207206
208207 trust = issue(engine, "P0 Trust: agents contained");
209208 feed = issue(engine, "P1 Feed: one front door");
test/map-first.test.ts +2 −3
@@ -2,7 +2,6 @@
22 * "This first" (#7806): a writer's rank puts a ready issue ahead of the rest
33 * for the dispatcher; it never lifts a blocker, and it ends when the issue closes.
44 */
5 import { seatAs } from "./helpers/seat.ts";
65 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
76 import { mkdtemp, rm } from "node:fs/promises";
87 import { tmpdir } from "node:os";
@@ -11,7 +10,7 @@ import { createApp, type App } from "../src/app.ts";
1110 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1211 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1312 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
14 import {} from "../src/core/agents.ts";
13 import { setCrewRole } from "../src/core/agents.ts";
1514 import { addDependency, readyNow, repoGraph } from "../src/core/dependencies.ts";
1615 import { firstAt, putFirst } from "../src/core/first.ts";
1716 import { getIssueById, type Issue } from "../src/core/issues.ts";
@@ -46,7 +45,7 @@ describe("this first", () => {
4645 if (!created.ok) throw new Error(String(created.error));
4746 expect(addToCrew(app, alice, made.value, agent).ok).toBe(true);
4847 }
49 seatAs(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
48 setCrewRole(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner");
5049 const set = await updateRepoSettings(app, alice, made.value, {
5150 autonomy: "autonomous",
5251 autonomyDirection: "Keep the engine small.",
test/mcp.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * action the pages call — so what a person may not do on a page they may
55 * not do here.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { chmodSync, writeFileSync } from "node:fs";
109 import { mkdtemp, rm } from "node:fs/promises";
@@ -15,7 +14,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1514 import { pullDir } from "../src/core/pulls.ts";
1615 import { resolveOid } from "../src/git/merge.ts";
1716 import { openIssue } from "../src/actions/issues.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { openPull } from "../src/actions/pulls.ts";
2019 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
2120 import { createApp as insertApp } from "../src/core/apps.ts";
@@ -572,7 +571,7 @@ describe("the forge over MCP", () => {
572571 const made = await createAgent(app, alice, { username: "closer", brief: "x" });
573572 if (!made.ok) throw new Error(String(made.error));
574573 expect(addToCrew(app, alice, game, "closer").ok).toBe(true);
575 seatAs(app.db, game.id, made.value.user.id, "planner");
574 setCrewRole(app.db, game.id, made.value.user.id, "planner");
576575 const botToken = createToken(app.db, made.value.user.id, "bot", "rw").token;
577576 const mine = (title: string) => {
578577 const o = openIssue(app, made.value.user, game, { title });
test/member-crew.test.ts +1 −1
@@ -47,7 +47,7 @@ describe("a member and the crew's standing instructions", () => {
4747 fetch(`${servers.url}/settings/crew/robin`, {
4848 method: "POST",
4949 headers: { cookie, origin: FORGE_URL },
50 body: new URLSearchParams({ model: "", brief: text, budgetUsd: "1", roles: "builder" }),
50 body: new URLSearchParams({ model: "", brief: text, budgetUsd: "1" }),
5151 redirect: "manual",
5252 });
5353
test/next-steps-card.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * second account.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { join } from "node:path";
1312 import { createRepo } from "../src/actions/repos.ts";
1413 import { childDirOf, spawnForge } from "../src/actions/spawn.ts";
1514 import { createApp, type App } from "../src/app.ts";
16 import { addCrew, createAgentRow } from "../src/core/agents.ts";
15 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1716 import { createSession } from "../src/core/sessions.ts";
1817 import { createUser } from "../src/core/users.ts";
1918 import { commitFiles } from "../src/git/write.ts";
@@ -103,7 +102,7 @@ describe("the next-steps card of a spawned forge", () => {
103102 createdBy: alice.id,
104103 });
105104 addCrew(parent.db, repo.value.id, atlas.value.id, alice.id);
106 seatAs(parent.db, repo.value.id, atlas.value.id, "planner");
105 setCrewRole(parent.db, repo.value.id, atlas.value.id, "planner");
107106 parentServers = await serve(parent);
108107 const spawned = await spawnForge(
109108 parent,
test/planner-closes-pull.test.ts +2 −3
@@ -2,7 +2,6 @@
22 * The planner's one close on a pull (#3301): an agent's pull whose issue is
33 * closed. An open issue, a person's pull, a merge and a reopen stay refused.
44 */
5 import { seatAs } from "./helpers/seat.ts";
65 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
76 import { mkdtemp, rm } from "node:fs/promises";
87 import { tmpdir } from "node:os";
@@ -12,7 +11,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1211 import { listComments } from "../src/core/issues.ts";
1312 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1413 import { createRepo } from "../src/actions/repos.ts";
15 import {} from "../src/core/agents.ts";
14 import { setCrewRole } from "../src/core/agents.ts";
1615 import { getIssueById, type Issue } from "../src/core/issues.ts";
1716 import type { Repo } from "../src/core/repos.ts";
1817 import { createToken } from "../src/core/tokens.ts";
@@ -72,7 +71,7 @@ describe("the planner closes a pull", () => {
7271 }
7372 atlas = getUserByName(app.db, "atlas")!;
7473 mason = getUserByName(app.db, "mason")!;
75 seatAs(app.db, repo.id, atlas.id, "planner");
74 setCrewRole(app.db, repo.id, atlas.id, "planner");
7675 token = createToken(app.db, atlas.id, "rw", "rw").token;
7776 });
7877
test/planner-lent.test.ts +3 −4
@@ -2,7 +2,6 @@
22 * A repository in auto mode with a direction and no planner gets one, and
33 * its first planned issues start without a further step (#7637).
44 */
5 import { seatAs } from "./helpers/seat.ts";
65 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
76 import { mkdtemp, rm } from "node:fs/promises";
87 import { tmpdir } from "node:os";
@@ -10,7 +9,7 @@ import { join } from "node:path";
109 import { createApp, type App } from "../src/app.ts";
1110 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1211 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
13 import { crewRole } from "../src/core/agents.ts";
12 import { crewRole, setCrewRole } from "../src/core/agents.ts";
1413 import { getIssueById } from "../src/core/issues.ts";
1514 import { createRepo as coreCreateRepo, getRepoById, type Repo } from "../src/core/repos.ts";
1615 import { createUser, getUserByName, type User } from "../src/core/users.ts";
@@ -61,7 +60,7 @@ describe("a migrated repository with only a builder", () => {
6160 // Elsewhere on the forge atlas plans.
6261 const home = await repo("home");
6362 expect(addToCrew(app, alice, home, "atlas").ok).toBe(true);
64 seatAs(app.db, home.id, getUserByName(app.db, "atlas")!.id, "planner");
63 setCrewRole(app.db, home.id, getUserByName(app.db, "atlas")!.id, "planner");
6564 // The migrated one: a builder, nothing else.
6665 pixel = await repo("pixel-plays");
6766 expect(addToCrew(app, alice, pixel, "torque").ok).toBe(true);
@@ -122,7 +121,7 @@ describe("a migrated repository with only a builder", () => {
122121 test("a planner with a crew but no direction issue yet reads the second message", async () => {
123122 const third = await repo("third");
124123 expect(addToCrew(app, alice, third, "atlas").ok).toBe(true);
125 seatAs(app.db, third.id, getUserByName(app.db, "atlas")!.id, "planner");
124 setCrewRole(app.db, third.id, getUserByName(app.db, "atlas")!.id, "planner");
126125 await updateRepoSettings(app, alice, third, {
127126 autonomy: "assisted",
128127 autonomyDirection: "more",
test/proposal-card.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * Refusals come first: a non-owner and a cross-origin post change nothing.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { proposePlan } from "../src/actions/plan.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import { getAgentByName } from "../src/core/agents.ts";
15 import { getAgentByName, setCrewRole } from "../src/core/agents.ts";
1716 import { listIssues, listComments } from "../src/core/issues.ts";
1817 import { getProposal } from "../src/core/proposals.ts";
1918 import type { Repo } from "../src/core/repos.ts";
@@ -91,7 +90,7 @@ describe("a wave proposal is one inbox card", () => {
9190 repo = made.value;
9291 await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# wave\n" }] });
9392 addToCrew(app, alice, repo, "planner");
94 seatAs(app.db, repo.id, getAgentByName(app.db, "planner")!.user.id, "planner");
93 setCrewRole(app.db, repo.id, getAgentByName(app.db, "planner")!.user.id, "planner");
9594 }, 30_000);
9695
9796 afterAll(async () => {
test/pull-tui-teams.test.ts +2 −3
@@ -2,7 +2,6 @@
22 * The terminal's pull screen names the team that still owes a review (#2897),
33 * as the web pull page's team card does.
44 */
5 import { seatAs } from "./helpers/seat.ts";
65 import { afterAll, beforeAll, expect, test } from "bun:test";
76 import { mkdtemp, rm } from "node:fs/promises";
87 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { openIssue } from "../src/actions/issues.ts";
1312 import { openPull } from "../src/actions/pulls.ts";
1413 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1514 import { createApp, type App } from "../src/app.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { getPull } from "../src/core/pulls.ts";
1817 import { submitReview } from "../src/core/reviews.ts";
1918 import { saveTeam } from "../src/core/teams.ts";
@@ -59,7 +58,7 @@ test("a two-team issue shows one team approved and one awaited; no team shows no
5958 const agent = await createAgent(app, alice, { username: name });
6059 if (!agent.ok) throw new Error(String(agent.error));
6160 addToCrew(app, alice, repo, name);
62 seatAs(app.db, repo.id, id(name), "reviewer");
61 setCrewRole(app.db, repo.id, id(name), "reviewer");
6362 }
6463 saveTeam(app.db, "design", { charter: "", dial: 0, members: [id("quill")] });
6564 saveTeam(app.db, "data-science", { charter: "", dial: 0, members: [id("pike")] });
test/red-approved.test.ts +2 −3
@@ -2,7 +2,6 @@
22 * An approved pull red for 24 h gets one re-check per head, then goes back
33 * to its builder naming the failing test (#6349). `now` is passed in.
44 */
5 import { seatAs } from "./helpers/seat.ts";
65 import { afterAll, beforeAll, expect, test } from "bun:test";
76 import { mkdtemp, rm } from "node:fs/promises";
87 import { tmpdir } from "node:os";
@@ -12,7 +11,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1211 import { openPull } from "../src/actions/pulls.ts";
1312 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1413 import { provideChecksForTest, type ChecksHandle } from "../src/checks/service.ts";
15 import {} from "../src/core/agents.ts";
14 import { setCrewRole } from "../src/core/agents.ts";
1615 import { listComments } from "../src/core/issues.ts";
1716 import type { Pull } from "../src/core/pulls.ts";
1817 import type { Repo } from "../src/core/repos.ts";
@@ -55,7 +54,7 @@ beforeAll(async () => {
5554 }
5655 const mason = getUserByName(app.db, "mason")!;
5756 quill = getUserByName(app.db, "quill")!;
58 seatAs(app.db, repo.id, quill.id, "reviewer");
57 setCrewRole(app.db, repo.id, quill.id, "reviewer");
5958 await commitToBranch(app, alice, repo, {
6059 branch: "feature/x",
6160 base: "main",
test/requested-pulls.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * share, so these pin it.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -14,7 +13,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1615 import { createApp, type App } from "../src/app.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import type { Pull } from "../src/core/pulls.ts";
1918 import { getPull } from "../src/core/pulls.ts";
2019 import { requestedPulls, verdictIsStale } from "../src/core/requested.ts";
@@ -101,7 +100,7 @@ describe("requestedPulls", () => {
101100 if (!r.ok) throw new Error(String(r.error));
102101 await push(r.value, "main");
103102 for (const who of ["mason", "quill"]) expect(addToCrew(app, alice, r.value, who).ok).toBe(true);
104 seatAs(app.db, r.value.id, reviewer.id, "reviewer");
103 setCrewRole(app.db, r.value.id, reviewer.id, "reviewer");
105104 repos.push(r.value);
106105 }
107106 [garden, orchard] = repos as [Repo, Repo];
test/requested.test.ts +2 −3
@@ -6,7 +6,6 @@
66 * which pulls wait on a builder and which on a reviewer.
77 */
88
9 import { seatAs } from "./helpers/seat.ts";
109 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1110 import { mkdtemp, rm } from "node:fs/promises";
1211 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1514 import { openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1716 import { createApp, type App } from "../src/app.ts";
18 import {} from "../src/core/agents.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
1918 import { getIssueById, listComments } from "../src/core/issues.ts";
2019 import { getPull, type Pull } from "../src/core/pulls.ts";
2120 import { getRepoById, type Repo } from "../src/core/repos.ts";
@@ -149,7 +148,7 @@ describe("a pull with changes requested always moves", () => {
149148 }
150149 builder = getUserByName(app.db, "mason")!;
151150 reviewer = getUserByName(app.db, "quill")!;
152 seatAs(app.db, repo.id, reviewer.id, "reviewer");
151 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
153152 // Assisted: a lapsed head is not sent for being autonomous, only for answering a verdict.
154153 app.db
155154 .query("UPDATE repo SET autonomy = 'assisted', autonomy_by = ?2, autonomy_slots = 3 WHERE id = ?1")
test/review-from-check.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * reviewer's task (#1237). A review that ends with no verdict is sent again,
55 * to the other reviewer when the crew has one.
66 */
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { mkdtemp, rm } from "node:fs/promises";
109 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1312 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1413 import { openPull } from "../src/actions/pulls.ts";
1514 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import type { Repo } from "../src/core/repos.ts";
1817 import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
1918 import { createUser, getUserByName, type User } from "../src/core/users.ts";
@@ -100,7 +99,7 @@ describe("a review that comes back with no verdict", () => {
10099 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
101100 }
102101 for (const name of ["juniper", "sentinel"])
103 seatAs(app.db, repo.id, getUserByName(app.db, name)!.id, "reviewer");
102 setCrewRole(app.db, repo.id, getUserByName(app.db, name)!.id, "reviewer");
104103 });
105104
106105 afterAll(async () => {
test/review-from-green.test.ts +2 −3
@@ -3,7 +3,6 @@
33 * a slow check queue must not lapse a pull before review was ever sent.
44 */
55
6 import { seatAs } from "./helpers/seat.ts";
76 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
87 import { mkdtemp, rm } from "node:fs/promises";
98 import { tmpdir } from "node:os";
@@ -12,7 +11,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts";
1211 import { openPull } from "../src/actions/pulls.ts";
1312 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1413 import { createApp, type App } from "../src/app.ts";
15 import {} from "../src/core/agents.ts";
14 import { setCrewRole } from "../src/core/agents.ts";
1615 import type { Pull } from "../src/core/pulls.ts";
1716 import { getRepoById, type Repo } from "../src/core/repos.ts";
1817 import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
@@ -99,7 +98,7 @@ describe("review is owed from the check's green", () => {
9998 const agent = await createAgent(app, alice, { username: "quill" });
10099 if (!agent.ok) throw new Error(String(agent.error));
101100 addToCrew(app, alice, repo, "quill");
102 seatAs(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
101 setCrewRole(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
103102 }, 30_000);
104103
105104 afterAll(async () => {
test/review-gate.test.ts +12 −13
@@ -5,7 +5,6 @@
55 * reviewer: it waits for a person (#597). A person's own pull lands as
66 * before.
77 */
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -14,7 +13,7 @@ import { createApp, type App } from "../src/app.ts";
1413 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1514 import { openPull } from "../src/actions/pulls.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import { getPull, type Pull } from "../src/core/pulls.ts";
1918 import { listComments } from "../src/core/issues.ts";
2019 import {
@@ -138,7 +137,7 @@ describe("the review gate", () => {
138137 ["an agent's", () => mason],
139138 ] as const) {
140139 test(`${who} green pull is reviewed, and lands only on an approval of its head`, async () => {
141 seatAs(app.db, repo.id, quill.id, "reviewer");
140 setCrewRole(app.db, repo.id, quill.id, "reviewer");
142141 const name = who.includes("person") ? "by-person" : "by-agent";
143142 const pull = await greenPull(author(), name);
144143 expect(await landIfGreen(app, fresh(), pull)).toBe(false);
@@ -181,7 +180,7 @@ describe("the review gate", () => {
181180 };
182181
183182 test("an agent's pull whose review lapses never ships: it waits for a person, and a person's approval lands it", async () => {
184 seatAs(app.db, repo.id, quill.id, "reviewer");
183 setCrewRole(app.db, repo.id, quill.id, "reviewer");
185184 const pull = await greenPull(mason, "unanswered");
186185 expect(await landIfGreen(app, fresh(), pull)).toBe(false);
187186 unanswered(pull);
@@ -201,7 +200,7 @@ describe("the review gate", () => {
201200 });
202201
203202 test("with no reviewer on the crew an agent's pull waits for a person and says why", async () => {
204 seatAs(app.db, repo.id, quill.id, "builder");
203 setCrewRole(app.db, repo.id, quill.id, "builder");
205204 const pull = await greenPull(mason, "no-reviewer");
206205 expect(await landIfGreen(app, fresh(), pull)).toBe(false);
207206 expect(reviewRuns(pull)).toHaveLength(0);
@@ -211,7 +210,7 @@ describe("the review gate", () => {
211210 });
212211
213212 test("a person's own pull is unchanged: a review that lapses does not hold it; it lands, and says so", async () => {
214 seatAs(app.db, repo.id, quill.id, "reviewer");
213 setCrewRole(app.db, repo.id, quill.id, "reviewer");
215214 const pull = await greenPull(alice, "person-unanswered");
216215 expect(await landIfGreen(app, fresh(), pull)).toBe(false);
217216 unanswered(pull);
@@ -223,7 +222,7 @@ describe("the review gate", () => {
223222 });
224223
225224 test("a change requested on the head holds the pull", async () => {
226 seatAs(app.db, repo.id, quill.id, "reviewer");
225 setCrewRole(app.db, repo.id, quill.id, "reviewer");
227226 const pull = await greenPull(alice, "contested");
228227 submitReview(app.db, {
229228 issueId: pull.id,
@@ -256,11 +255,11 @@ describe("the review gate", () => {
256255 }
257256
258257 test("a reviewer taken off the crew no longer holds the pulls it judged", async () => {
259 seatAs(app.db, repo.id, quill.id, "reviewer");
258 setCrewRole(app.db, repo.id, quill.id, "reviewer");
260259 const pull = await greenPull(mason, "judged");
261260 askChanges(pull, quill);
262261 expect(reviewSummary(app.db, pull.id, pull.headOid).changesRequested).toBe(1);
263 seatAs(app.db, repo.id, quill.id, "builder");
262 setCrewRole(app.db, repo.id, quill.id, "builder");
264263 expect(reviewSummary(app.db, pull.id, pull.headOid).changesRequested).toBe(0);
265264 // A person's request is the person's, whatever their crew.
266265 askChanges(pull, alice);
@@ -268,7 +267,7 @@ describe("the review gate", () => {
268267 });
269268
270269 test(`the reviewer gets ${REVIEW_ROUNDS} rounds of changes; a third is advice and the pull lands`, async () => {
271 seatAs(app.db, repo.id, quill.id, "reviewer");
270 setCrewRole(app.db, repo.id, quill.id, "reviewer");
272271 let pull = await greenPull(mason, "rounds");
273272 askChanges(pull, quill);
274273 // Asked twice on one head is still one round.
@@ -284,8 +283,8 @@ describe("the review gate", () => {
284283 });
285284
286285 test("a builder's run that answers a change request without pushing parks the pull", async () => {
287 seatAs(app.db, repo.id, quill.id, "reviewer");
288 seatAs(app.db, repo.id, mason.id, "builder");
286 setCrewRole(app.db, repo.id, quill.id, "reviewer");
287 setCrewRole(app.db, repo.id, mason.id, "builder");
289288 const pull = await greenPull(mason, "unmoved");
290289 askChanges(pull, quill);
291290 expect(
@@ -349,7 +348,7 @@ describe("a pull nobody reviewed, however old (#1655)", () => {
349348 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
350349 }
351350 mason = getUserByName(app.db, "mason")!;
352 seatAs(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
351 setCrewRole(app.db, repo.id, getUserByName(app.db, "quill")!.id, "reviewer");
353352 });
354353
355354 afterAll(async () => {
test/review-page.test.ts +2 −3
@@ -1,5 +1,4 @@
11 /** `/review` lists each ask waiting on a person as one row with its why. */
2 import { seatAs } from "./helpers/seat.ts";
32 import { afterAll, beforeAll, expect, test } from "bun:test";
43 import { mkdtempSync, rmSync } from "node:fs";
54 import { tmpdir } from "node:os";
@@ -7,7 +6,7 @@ import { join } from "node:path";
76 import { createApp, type App } from "../src/app.ts";
87 import { addComment, openIssue } from "../src/actions/issues.ts";
98 import { addComment as addRawComment } from "../src/core/issues.ts";
10 import { addCrew, createAgentRow } from "../src/core/agents.ts";
9 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1110 import { recordLook } from "../src/core/looks.ts";
1211 import { previewEnv } from "../src/apps/data.ts";
1312 import { createApp as createAppRow } from "../src/core/apps.ts";
@@ -59,7 +58,7 @@ beforeAll(async () => {
5958 if (!made.ok) throw new Error(made.error);
6059 const repo = made.value;
6160 for (const a of [builder, reviewer]) addCrew(app.db, repo.id, a.id, alice.id);
62 seatAs(app.db, repo.id, reviewer.id, "reviewer");
61 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
6362 let seq = 0;
6463 const pull = (author: string, title: string, age: number) => {
6564 const issueId = id();
test/review-route.test.ts +2 −3
@@ -6,7 +6,6 @@
66 * not only one that ships on its own. A review run is judged by its verdict:
77 * it pushes nothing by design.
88 */
9 import { seatAs } from "./helpers/seat.ts";
109 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1110 import { mkdtemp, rm } from "node:fs/promises";
1211 import { tmpdir } from "node:os";
@@ -15,7 +14,7 @@ import { createApp, type App } from "../src/app.ts";
1514 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1615 import { openPull } from "../src/actions/pulls.ts";
1716 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
18 import { type Agent } from "../src/core/agents.ts";
17 import { setCrewRole, type Agent } from "../src/core/agents.ts";
1918 import type { Pull } from "../src/core/pulls.ts";
2019 import { getRepoById, type Repo } from "../src/core/repos.ts";
2120 import type { Review } from "../src/core/reviews.ts";
@@ -186,7 +185,7 @@ describe("every green pull an agent wrote is sent to review", () => {
186185 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
187186 }
188187 for (const name of ["juniper", "sentinel"])
189 seatAs(app.db, repo.id, getUserByName(app.db, name)!.id, "reviewer");
188 setCrewRole(app.db, repo.id, getUserByName(app.db, name)!.id, "reviewer");
190189 // Not autonomous: review is not the shipping loop's alone.
191190 expect(repo.autonomy).not.toBe("autonomous");
192191 });
test/review-wait.test.ts +2 −3
@@ -3,7 +3,6 @@
33 * word), not in the owner's asks, and moves to the owner on a verdict (#1602).
44 */
55
6 import { seatAs } from "./helpers/seat.ts";
76 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
87 import { mkdtemp, rm } from "node:fs/promises";
98 import { tmpdir } from "node:os";
@@ -12,7 +11,7 @@ import { createApp, type App } from "../src/app.ts";
1211 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1312 import { openPull } from "../src/actions/pulls.ts";
1413 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
15 import {} from "../src/core/agents.ts";
14 import { setCrewRole } from "../src/core/agents.ts";
1615 import type { Pull } from "../src/core/pulls.ts";
1716 import type { Repo } from "../src/core/repos.ts";
1817 import { submitReview } from "../src/core/reviews.ts";
@@ -85,7 +84,7 @@ describe("a green agent pull and its reviewer", () => {
8584 await createAgent(app, alice, { username: name });
8685 addToCrew(app, alice, repo, name);
8786 }
88 seatAs(app.db, repo.id, getUserByName(app.db, "rev")!.id, "reviewer");
87 setCrewRole(app.db, repo.id, getUserByName(app.db, "rev")!.id, "reviewer");
8988 pull = await greenPull(1);
9089 await home(); // warm the first render so no test pays for it under load
9190 }, 60_000);
test/seat-slots.test.ts +9 −10
@@ -5,7 +5,6 @@
55 * a change is audited and takes effect on the next tick, and the MCP `crew`
66 * tool sets the same numbers.
77 */
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, setDefaultTimeout, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { join } from "node:path";
1312 import { createApp, type App } from "../src/app.ts";
1413 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1514 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
16 import {} from "../src/core/agents.ts";
15 import { setCrewRole } from "../src/core/agents.ts";
1716 import { crewNow } from "../src/actions/crew_now.ts";
1817 import { reviewSays } from "../src/crew/review_says.ts";
1918 import { askLinesFor } from "../src/web/studio/asks.ts";
@@ -73,13 +72,13 @@ beforeAll(async () => {
7372 servers = await serve(app);
7473 alice = ok(await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: PASSWORD, adminIfFirst: true }));
7574 proveAll(app);
76 for (const name of ["mason", "atlas", "judge"]) ok(await createAgent(app, alice, { username: name, roles: ["planner", "builder", "reviewer"] }));
75 for (const name of ["mason", "atlas", "judge"]) ok(await createAgent(app, alice, { username: name }));
7776 repo = ok(await createRepo(app, alice, { name: "yard", visibility: "public" }));
7877 ok(await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "README.md", content: "# yard\n" }] }));
79 for (const name of ["mason", "atlas", "judge"]) expect(addToCrew(app, alice, repo, name, "builder").ok).toBe(true);
78 for (const name of ["mason", "atlas", "judge"]) expect(addToCrew(app, alice, repo, name).ok).toBe(true);
8079 const id = (n: string) => getUserByName(app.db, n)!.id;
81 seatAs(app.db, repo.id, id("atlas"), "planner");
82 seatAs(app.db, repo.id, id("judge"), "reviewer");
80 setCrewRole(app.db, repo.id, id("atlas"), "planner");
81 setCrewRole(app.db, repo.id, id("judge"), "reviewer");
8382 ok(await updateRepoSettings(app, alice, repo, { autonomy: "autonomous", autonomyDirection: "Make the yard rounder.", autonomyCeilingUsd: 10, autonomySlots: 2, autonomyBy: alice.id }));
8483 const res = await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "alice", password: PASSWORD }), redirect: "manual" });
8584 cookie = (res.headers.get("set-cookie") ?? "").split(";")[0]!;
@@ -231,11 +230,11 @@ test("a lapsed review says why on the now list, the MCP and the asks: paused, un
231230 expect(paused.ask).toContain("the reviewer is paused");
232231 app.db.query("UPDATE repo SET reviewer_slots = 8 WHERE id = ?1").run(repo.id);
233232
234 seatAs(app.db, repo.id, judge.id, "builder");
233 setCrewRole(app.db, repo.id, judge.id, "builder");
235234 const none = await says();
236235 expect(none.now).toBe("no reviewer on the crew");
237236 expect(none.ask).toContain("no reviewer on the crew");
238 seatAs(app.db, repo.id, judge.id, "reviewer");
237 setCrewRole(app.db, repo.id, judge.id, "reviewer");
239238 });
240239
241240 test("three change requests are worded as such, never as an empty crew", () => {
@@ -292,8 +291,8 @@ describe("the reviewer's cap, end to end (#8734)", () => {
292291 beforeAll(async () => {
293292 porch = ok(await createRepo(app, alice, { name: "porch", visibility: "private" }));
294293 ok(await commitToBranch(app, alice, porch, { message: "Start", files: [{ path: "README.md", content: "# porch\n" }] }));
295 expect(addToCrew(app, alice, porch, "judge", "builder").ok).toBe(true);
296 seatAs(app.db, porch.id, getUserByName(app.db, "judge")!.id, "reviewer");
294 expect(addToCrew(app, alice, porch, "judge").ok).toBe(true);
295 setCrewRole(app.db, porch.id, getUserByName(app.db, "judge")!.id, "reviewer");
297296 });
298297
299298 test("at 1, the second agent pull is queued only after the first review ends", async () => {
test/spawn-child-apps.test.ts +2 −3
@@ -5,7 +5,6 @@
55 * credential, the home and the app page say so and where to add one.
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
109 import { mkdtemp, rm } from "node:fs/promises";
1110 import { tmpdir } from "node:os";
@@ -13,7 +12,7 @@ import { join } from "node:path";
1312 import { createRepo } from "../src/actions/repos.ts";
1413 import { childDirOf, spawnForge } from "../src/actions/spawn.ts";
1514 import { createApp, type App } from "../src/app.ts";
16 import { addCrew, createAgentRow } from "../src/core/agents.ts";
15 import { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts";
1716 import { getAppByRepo, listApps } from "../src/core/apps.ts";
1817 import { getRepo } from "../src/core/repos.ts";
1918 import {
@@ -92,7 +91,7 @@ describe("a spawned child's apps", () => {
9291 createdBy: alice.id,
9392 });
9493 addCrew(parent.db, repo.value.id, atlas.value.id, alice.id);
95 seatAs(parent.db, repo.value.id, atlas.value.id, "planner");
94 setCrewRole(parent.db, repo.value.id, atlas.value.id, "planner");
9695 }
9796 }
9897 const spawned = await spawnForge(
test/spawn-first-boot.test.ts +3 −3
@@ -6,7 +6,6 @@
66 * child's own pages — and a link that is used, expired or made up says so.
77 */
88
9 import { seatAs } from "./helpers/seat.ts";
109 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1110 import { readdir, mkdtemp, rm } from "node:fs/promises";
1211 import { tmpdir } from "node:os";
@@ -22,7 +21,8 @@ import {
2221 addCrew,
2322 createAgentRow,
2423 listCrewRoles,
25 } from "../src/core/agents.ts";
24 setCrewRole,
25 } from "../src/core/agents.ts";
2626 import { listIssues } from "../src/core/issues.ts";
2727 import { getOrg, listTeams, listTeamMembers } from "../src/core/orgs.ts";
2828 import { getRepo } from "../src/core/repos.ts";
@@ -113,7 +113,7 @@ describe("a spawned child's first boot", () => {
113113 createdBy: alice.id,
114114 });
115115 addCrew(parent.db, repo.value.id, agent.value.id, alice.id);
116 seatAs(parent.db, repo.value.id, agent.value.id, role);
116 setCrewRole(parent.db, repo.value.id, agent.value.id, role);
117117 }
118118 const source: SpawnSource = {
119119 catalog: [
test/studio-runs.test.ts +3 −4
@@ -5,7 +5,6 @@
55 * test/studio*.test.ts. It runs in about 2.5 s with no waits (#3578).
66 */
77
8 import { seatAs } from "./helpers/seat.ts";
98 import {
109 afterAll,
1110 afterEach,
@@ -35,7 +34,7 @@ import {
3534 createRepo,
3635 updateRepoSettings,
3736 } from "../src/actions/repos.ts";
38 import {} from "../src/core/agents.ts";
37 import { setCrewRole } from "../src/core/agents.ts";
3938 import type { Issue } from "../src/core/issues.ts";
4039 import { getPull, type Pull } from "../src/core/pulls.ts";
4140 import type { Repo } from "../src/core/repos.ts";
@@ -113,8 +112,8 @@ describe("the studio's slot count", () => {
113112 }
114113 const reviewer = getUserByName(app.db, "quill")!;
115114 const planner = getUserByName(app.db, "chart")!;
116 seatAs(app.db, repo.id, reviewer.id, "reviewer");
117 seatAs(app.db, repo.id, planner.id, "planner");
115 setCrewRole(app.db, repo.id, reviewer.id, "reviewer");
116 setCrewRole(app.db, repo.id, planner.id, "planner");
118117 const on = await updateRepoSettings(app, alice, repo, {
119118 autonomy: "autonomous",
120119 autonomyDirection: "",
test/team-dispatch.test.ts +2 −3
@@ -4,7 +4,6 @@
44 * a planning run receives the teams section in its task.
55 */
66
7 import { seatAs } from "./helpers/seat.ts";
87 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
98 import { chmodSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
109 import { mkdtemp, rm } from "node:fs/promises";
@@ -14,7 +13,7 @@ import { createApp, type App } from "../src/app.ts";
1413 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1514 import { assignIssue, openIssue } from "../src/actions/issues.ts";
1615 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import { createLabel, getIssueById, setIssueLabels, type Issue } from "../src/core/issues.ts";
1918 import { getRepoById, type Repo } from "../src/core/repos.ts";
2019 import { listRuns } from "../src/core/runs.ts";
@@ -65,7 +64,7 @@ beforeAll(async () => {
6564 if (!agent.ok) throw new Error(String(agent.error));
6665 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
6766 }
68 seatAs(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner");
67 setCrewRole(app.db, repo.id, getUserByName(app.db, "atlas")!.id, "planner");
6968 // The stand-in agent keeps the first line it is told and ends at once.
7069 const fake = join(dataDir, "fake-claude");
7170 writeFileSync(
test/tui-agents.test.ts −18
@@ -191,24 +191,6 @@ describe("agents in the terminal", () => {
191191 h.stop();
192192 });
193193
194 test("roles change after a confirm and a bad one is refused before it", async () => {
195 const h = boot("alice");
196 await open(h);
197 await h.press("r");
198 await clear(h, 20);
199 await h.type("planner, boss");
200 await h.press("enter");
201 expect(getAgentByName(forge.db, "bot1")!.roles).toEqual(["builder"]);
202 await h.press("escape");
203 await h.press("r");
204 await clear(h, 20);
205 await h.type("planner, reviewer");
206 await h.press("enter");
207 await h.press("y");
208 expect(getAgentByName(forge.db, "bot1")!.roles).toEqual(["planner", "reviewer"]);
209 h.stop();
210 });
211
212194 test("a non-admin and an admin agent are never offered the screen", async () => {
213195 for (const who of ["bob", "carol"]) {
214196 const h = boot(who);
test/tui-limbs-replanned.test.ts +2 −3
@@ -3,7 +3,6 @@
33 * `Re-planned <time ago>` and one line per split, as the milestones page does,
44 * and Enter on a split line opens the new issue. Owner facts only.
55 */
6 import { seatAs } from "./helpers/seat.ts";
76 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
87 import { mkdtemp, rm } from "node:fs/promises";
98 import { tmpdir } from "node:os";
@@ -14,7 +13,7 @@ import { linkIssue } from "../src/actions/dependencies.ts";
1413 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1514 import { replanLimb } from "../src/actions/limb_replan.ts";
1615 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
17 import {} from "../src/core/agents.ts";
16 import { setCrewRole } from "../src/core/agents.ts";
1817 import { getIssueById, type Issue } from "../src/core/issues.ts";
1918 import { getRepoById, type Repo } from "../src/core/repos.ts";
2019 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
@@ -91,7 +90,7 @@ describe("the limbs screen after a re-plan", () => {
9190 if (!agent.ok) throw new Error(String(agent.error));
9291 expect(addToCrew(app, alice, repo, "atlas").ok).toBe(true);
9392 atlas = getUserByName(app.db, "atlas")!;
94 seatAs(app.db, repo.id, atlas.id, "planner");
93 setCrewRole(app.db, repo.id, atlas.id, "planner");
9594 const set = await updateRepoSettings(app, alice, repo, {
9695 autonomy: "autonomous",
9796 autonomyDirection: "Keep the engine small.",
test/tui-limbs.test.ts +2 −3
@@ -8,7 +8,6 @@
88 * keys to change it, a guest sees nothing private, and a move reaches the
99 * outbox (and so a milestones page open on the web) as `limb.moved`.
1010 */
11 import { seatAs } from "./helpers/seat.ts";
1211 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1312 import { mkdtemp, rm } from "node:fs/promises";
1413 import { tmpdir } from "node:os";
@@ -17,7 +16,7 @@ import { linkIssue } from "../src/actions/dependencies.ts";
1716 import { openIssue } from "../src/actions/issues.ts";
1817 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1918 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
20 import {} from "../src/core/agents.ts";
19 import { setCrewRole } from "../src/core/agents.ts";
2120 import { pendingReplans } from "../src/core/limb_replan.ts";
2221 import { createApp, type App as Forge } from "../src/app.ts";
2322 import { listEvents } from "../src/core/events.ts";
@@ -275,7 +274,7 @@ describe("raise and lower a limb in the terminal", () => {
275274 const agent = await createAgent(forge, alice, { username: "atlas" });
276275 if (!agent.ok) throw new Error(String(agent.error));
277276 addToCrew(forge, alice, r, "atlas");
278 seatAs(forge.db, r.id, getUserByName(forge.db, "atlas")!.id, "planner");
277 setCrewRole(forge.db, r.id, getUserByName(forge.db, "atlas")!.id, "planner");
279278 await updateRepoSettings(forge, alice, r, {
280279 autonomy: "autonomous",
281280 autonomyDirection: "Keep it small.",
test/web-apps.test.ts +3 −4
@@ -732,7 +732,7 @@ describe("apps, runs and the crew on the web", () => {
732732 expect(await bodyOf(alice, "/settings")).toContain('href="/settings/crew"');
733733
734734 const bad = await web(alice, "/settings/crew", {
735 form: { username: "bot", budgetUsd: "-4", roles: "builder" },
735 form: { username: "bot", budgetUsd: "-4" },
736736 });
737737 expect(bad.status).toBe(422);
738738 const badPage = words(await bad.text());
@@ -751,7 +751,6 @@ describe("apps, runs and the crew on the web", () => {
751751 model: "",
752752 brief: "Be brief.",
753753 budgetUsd: "2",
754 roles: "builder",
755754 },
756755 });
757756 expect(made.status).toBe(303);
@@ -766,14 +765,14 @@ describe("apps, runs and the crew on the web", () => {
766765 expect(edit).toContain('value="bot"');
767766 expect(edit).toContain("Retire this agent");
768767 const updated = await web(alice, "/settings/crew/bot", {
769 form: { model: "sonnet", brief: "Be brief.", budgetUsd: "3", roles: "builder" },
768 form: { model: "sonnet", brief: "Be brief.", budgetUsd: "3" },
770769 });
771770 expect(updated.status).toBe(303);
772771 expect(getAgentByName(app.db, "bot")?.model).toBe("sonnet");
773772 expect(getAgentByName(app.db, "bot")?.budgetUsd).toBe(3);
774773 // A refused edit shows the error beside its field.
775774 const refused = await web(alice, "/settings/crew/bot", {
776 form: { model: "sonnet", brief: "Be brief.", budgetUsd: "-4", roles: "builder" },
775 form: { model: "sonnet", brief: "Be brief.", budgetUsd: "-4" },
777776 });
778777 expect(refused.status).toBe(422);
779778 const refusedPage = words(await refused.text());

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs