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

The owner approves the plan: the planner proposes a wave, the owner nods or redirects in one tap #1322

Closed opened this in answer to
Closed without merging

scout/forge:scout/1114-the-owner-approves-the-plan-the-planner → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
23 files changed +1241 −34
docs/MCP.md +2 −1
@@ -57,7 +57,8 @@ for a tunnel and a forge that sleeps.
5757 | `link` | `{ app, issue, blockedBy }`: the issue waits for another; loops and cross-repository are refused | yes |
5858 | `unlink` | `{ app, issue, blockedBy }`: the issue stops waiting for it | yes |
5959 | `hold` | `{ app, pull, why?, release?, dryRun? }`: hold a pull so no rule reviews or lands it, or let it go; a person who can write, never an agent; plans unless `dryRun: false` | yes |
60 | `plan` | `{ app, issues }`: open up to 12 linked issues, all or none (see below) | yes |
60 | `plan` | `{ app, issues, title?, why?, milestone? }`: open up to 12 linked issues, all or none (see below); on the crew, where the app's plans need a nod, it proposes a wave (3–6 issues) and opens nothing; without `issues`, the waves waiting | yes |
61 | `decide` | `{ app, wave, decision, words? }`: approve a proposed wave (its issues open, linked), redirect it (`words`; the planner re-plans from them) or set it aside (`later`); a person who can write, never an agent | yes |
6162
6263 Answers are JSON in a text block; most carry a `says` sentence short enough
6364 to relay as it is.
docs/PLANNING.md +14
@@ -548,3 +548,17 @@ not confirm its own plan. Split also moves the parent's blocked-by edges to
548548 the issues named in `into` (a child that would make a loop is skipped), and
549549 the parent waits for nothing. Reopening clears the reason. Closes that
550550 predate reasons count as done.
551
552 ## The owner's nod (#1114)
553
554 Beside autonomy, a repository setting — *Plans need a nod*, on by default —
555 changes what the crew's planner may do. With it on, the planner opens no issues:
556 `POST /api/v1/repos/:owner/:name/plan` (or the MCP `plan`) keeps a **wave** — a
557 title, a one-line why, the milestone it moves, three to six issues in order —
558 and the owner's inbox shows it as one card. **Approve** opens the issues, linked
559 as the proposal named, ready; **Redirect** (a text box) puts the words on the
560 direction issue and hands it back to the planner; **Later** sets it aside.
561 `decide` (MCP) and `POST …/waves/:id/decide` do the same. A person's own plan
562 opens at once; an agent never decides a wave. While a wave waits, the planner is
563 not asked for another. The map reads as waves under their milestones (what
564 landed, what is left); `?graph=1` is the whole graph.
scripts/gate.ts +1
@@ -124,6 +124,7 @@ export const GATE: readonly string[] = [
124124 "test/asks-expiry.test.ts",
125125 "test/asks-rank.test.ts",
126126 "test/plan-pillars.test.ts",
127 "test/plan-nod.test.ts",
127128 "test/planner-declined.test.ts",
128129 "test/feed.test.ts",
129130 "test/feed-page.test.ts",
src/actions/plan.ts +24 −2
@@ -186,12 +186,21 @@ function loopAt(items: readonly PlanItem[]): string | undefined {
186186 return undefined;
187187 }
188188
189 export function openPlan(
189 /** What a good plan was checked against: the issues it waits for and the pillars it serves. */
190 interface Vetted {
191 readonly existing: Map<number, Issue>;
192 readonly serves: Map<string, Pillar>;
193 readonly gate: Issue | undefined;
194 readonly later: Issue | undefined;
195 }
196
197 /** Every refusal a plan can earn, found before anything is written. */
198 export function vetPlan(
190199 app: App,
191200 actor: User | undefined,
192201 repo: Repo,
193202 items: readonly PlanItem[],
194 ): Result<Planned, PlanError> {
203 ): Result<Vetted, PlanError> {
195204 if (!actor || !canRead(app.db, repo, actor))
196205 return refuse("not_found", "no such app or repository (owner/name)");
197206 if (!canWrite(app.db, repo, actor) && !isCrew(app.db, repo.id, actor.id))
@@ -258,6 +267,19 @@ export function openPlan(
258267 `"${item.key}" names no pillar: give it ${namesOf(pillars)}, or later: true and why`,
259268 );
260269 }
270 return ok({ existing, serves, gate, later });
271 }
272
273 export function openPlan(
274 app: App,
275 actor: User | undefined,
276 repo: Repo,
277 items: readonly PlanItem[],
278 ): Result<Planned, PlanError> {
279 const vetted = vetPlan(app, actor, repo, items);
280 if (!vetted.ok) return vetted;
281 const { existing, serves, gate, later } = vetted.value;
282 if (!actor) return refuse("not_found", "no such app or repository (owner/name)");
261283
262284 const opened: { key: string; number: number }[] = [];
263285 /** The links an item's purpose adds: [the issue that waits, what it waits for]. */
src/actions/repos.ts +6 −1
@@ -246,7 +246,11 @@ export async function updateRepoSettings(
246246 if (!admin.ok) return admin;
247247 // Who the crew obeys is a person's call: an agent never widens it, even
248248 // one on a team that administers the repository (`crew/direct.ts`).
249 if (settings.crewOutsiders !== undefined && admin.value.kind === "agent")
249 if (
250 (settings.crewOutsiders !== undefined ||
251 settings.plansNeedNod !== undefined) &&
252 admin.value.kind === "agent"
253 )
250254 return err("not_found");
251255 // The work on a sealed report stays private until it merges into its
252256 // base, whoever owns it (`core/sealed.ts`).
@@ -270,6 +274,7 @@ export async function updateRepoSettings(
270274 "requireReview",
271275 "requireChecks",
272276 "crewOutsiders",
277 "plansNeedNod",
273278 ] as const
274279 ).filter((k) => settings[k] !== undefined && settings[k] !== repo[k]);
275280 app.bus.append({
src/actions/waves.ts added +270
@@ -0,0 +1,270 @@
1 /**
2 * The owner approves the plan (#1114). Where a repository's plans need a
3 * nod, the crew's planner does not open issues: it proposes a wave — a
4 * title, a one-line why, the milestone it moves, three to six issues in
5 * order — and a person approves it (the issues open, linked, ready),
6 * redirects it (the planner re-plans from their words), or sets it aside
7 * for later. A person who writes here is the owner of their own plan: what
8 * they open themselves opens at once.
9 */
10
11 import type { App } from "../app.ts";
12 import { isCrew, listCrewRoles } from "../core/agents.ts";
13 import { canRead, canWrite, type Repo } from "../core/repos.ts";
14 import { MAX_BODY, getIssueById, type Issue } from "../core/issues.ts";
15 import type { User } from "../core/users.ts";
16 import {
17 createWave,
18 decideWave as writeDecision,
19 getWave,
20 listWaves,
21 type Wave,
22 } from "../core/waves.ts";
23 import { ensureDirectionIssue } from "../crew/autonomy.ts";
24 import { err, ok, type Result } from "../kernel/result.ts";
25 import { addComment, assignIssue } from "./issues.ts";
26 import {
27 openPlan,
28 parsePlan,
29 vetPlan,
30 WHY_MAX,
31 type PlanError,
32 type Planned,
33 } from "./plan.ts";
34
35 export const WAVE_MIN = 3;
36 export const WAVE_MAX = 6;
37 export const WAVE_TITLE_MAX = 120;
38 export const MILESTONE_MAX = 80;
39 export const WORDS_MAX = 2000;
40
41 const refuse = (error: string, message: string) => err({ error, message });
42
43 /** Whether this actor's plan waits for a nod: the crew's, where the repository asks for one. */
44 export const needsNod = (app: App, repo: Repo, actor: User): boolean =>
45 repo.plansNeedNod && actor.kind === "agent" && isCrew(app.db, repo.id, actor.id);
46
47 /** One line of text, bounded: the boundary for a title, a why, a milestone. */
48 function line(raw: unknown, what: string, max: number): Result<string, PlanError> {
49 if (typeof raw !== "string" || raw.trim() === "")
50 return refuse("invalid", `a wave needs a ${what}`);
51 const flat = raw.trim().replace(/\s+/g, " ");
52 if (flat.length > max)
53 return refuse("invalid", `the ${what} is at most ${max} characters`);
54 return ok(flat);
55 }
56
57 /** A wave as the wire gave it, checked, vetted against the repository, and kept. */
58 export function proposeWave(
59 app: App,
60 actor: User | undefined,
61 repo: Repo,
62 raw: {
63 title: unknown;
64 why: unknown;
65 milestone: unknown;
66 issues: unknown;
67 },
68 ): Result<Wave, PlanError> {
69 const title = line(raw.title, "title", WAVE_TITLE_MAX);
70 if (!title.ok) return title;
71 const why = line(raw.why, "why (one line)", WHY_MAX);
72 if (!why.ok) return why;
73 const milestone = line(raw.milestone, "milestone", MILESTONE_MAX);
74 if (!milestone.ok) return milestone;
75 const items = parsePlan(raw.issues);
76 if (!items.ok) return items;
77 if (items.value.length < WAVE_MIN || items.value.length > WAVE_MAX)
78 return refuse(
79 "wave_size",
80 `a wave is ${WAVE_MIN} to ${WAVE_MAX} issues, in order; this has ${items.value.length}`,
81 );
82 // Refused now, with the item named, rather than when the owner nods.
83 const vetted = vetPlan(app, actor, repo, items.value);
84 if (!vetted.ok) return vetted;
85 const wave = createWave(app.db, {
86 repoId: repo.id,
87 authorId: actor!.id,
88 title: title.value,
89 why: why.value,
90 milestone: milestone.value,
91 items: items.value,
92 });
93 app.bus.append({
94 kind: "wave.proposed",
95 repoId: repo.id,
96 actorId: actor!.id,
97 payload: { wave: wave.id, title: wave.title },
98 });
99 return ok(wave);
100 }
101
102 export type Decision = "approve" | "redirect" | "later";
103
104 export interface Decided {
105 readonly wave: Wave;
106 readonly planned?: Planned;
107 }
108
109 /** A wave of a repository the actor writes, or the refusal that does not say which. */
110 function waveOf(
111 app: App,
112 actor: User | undefined,
113 repo: Repo,
114 waveId: string,
115 ): Result<Wave, PlanError> {
116 const wave = getWave(app.db, waveId);
117 if (!actor || !canRead(app.db, repo, actor) || wave?.repoId !== repo.id)
118 return refuse("not_found", "no such wave here");
119 // The nod is a person's: an agent proposes and never decides.
120 if (actor.kind === "agent" || !canWrite(app.db, repo, actor))
121 return refuse("forbidden", "only a person who writes here decides a wave");
122 return ok(wave);
123 }
124
125 /** Approve, redirect or set a wave aside. Each is one call; nothing half-happens. */
126 export function decideWave(
127 app: App,
128 actor: User | undefined,
129 repo: Repo,
130 waveId: string,
131 decision: unknown,
132 words: unknown = "",
133 ): Result<Decided, PlanError> {
134 const found = waveOf(app, actor, repo, waveId);
135 if (!found.ok) return found;
136 const wave = found.value;
137 const by = actor!;
138 if (wave.state === "approved" || wave.state === "redirected")
139 return refuse("decided", `this wave was already ${wave.state}`);
140 if (decision === "approve") {
141 const planned = openPlan(app, by, repo, wave.items);
142 if (!planned.ok) return planned;
143 const numbers = Object.fromEntries(
144 planned.value.opened.map((o) => [o.key, o.number]),
145 );
146 writeDecision(app.db, wave.id, "approved", by.id, { numbers });
147 app.bus.append({
148 kind: "wave.approved",
149 repoId: repo.id,
150 actorId: by.id,
151 payload: { wave: wave.id, numbers: planned.value.opened.map((o) => o.number) },
152 });
153 return ok({ wave: getWave(app.db, wave.id)!, planned: planned.value });
154 }
155 if (decision === "later") {
156 writeDecision(app.db, wave.id, "later", by.id);
157 return ok({ wave: getWave(app.db, wave.id)! });
158 }
159 if (decision !== "redirect")
160 return refuse("invalid", "decision is approve, redirect or later");
161 if (typeof words !== "string" || words.trim() === "")
162 return refuse("empty_words", "say where the plan should go instead (words)");
163 if (words.length > WORDS_MAX || words.length > MAX_BODY)
164 return refuse("invalid", `words are at most ${WORDS_MAX} characters`);
165 const sent = replanFrom(app, by, repo, wave, words.trim());
166 if (!sent.ok) return sent;
167 writeDecision(app.db, wave.id, "redirected", by.id, { words: words.trim() });
168 app.bus.append({
169 kind: "wave.redirected",
170 repoId: repo.id,
171 actorId: by.id,
172 payload: { wave: wave.id },
173 });
174 return ok({ wave: getWave(app.db, wave.id)! });
175 }
176
177 /**
178 * The planner, asked again with the owner's words: they go on the direction
179 * issue as a comment — which is where the planner's task is read from, so
180 * the words are in its prompt — and the planner is handed the issue, or
181 * woken on it when it already holds it (`crew/dispatch.ts`).
182 */
183 function replanFrom(
184 app: App,
185 by: User,
186 repo: Repo,
187 wave: Wave,
188 words: string,
189 ): Result<Issue, PlanError> {
190 const planner = listCrewRoles(app.db, repo.id).find((c) => c.role === "planner");
191 if (planner === undefined)
192 return refuse("no_planner", "there is no planner on this crew to re-plan");
193 const direction = ensureDirectionIssue(app, by, repo);
194 if (direction === undefined)
195 return refuse("no_direction", "this repository has no direction to plan from");
196 const said = addComment(
197 app,
198 by,
199 repo,
200 direction,
201 `Redirect — you proposed the wave “${wave.title}”. Do not open it. Plan again from these words:\n\n${words}`,
202 );
203 if (!said.ok) return refuse("invalid", `could not send the words: ${String(said.error)}`);
204 if (direction.assigneeId !== planner.agent.user.id) {
205 if (direction.assigneeId !== null) {
206 const cleared = assignIssue(app, by, repo, direction, null);
207 if (!cleared.ok)
208 return refuse("invalid", `could not hand it back: ${String(cleared.error)}`);
209 }
210 const current = getIssueById(app.db, direction.id) ?? direction;
211 const assigned = assignIssue(app, by, repo, current, planner.agent.user);
212 if (!assigned.ok)
213 return refuse("invalid", `could not hand it back: ${String(assigned.error)}`);
214 }
215 return ok(direction);
216 }
217
218 /** The waves still waiting for a nod (or set aside for later), oldest first. */
219 export const waitingWaves = (app: App, repo: Repo): Wave[] =>
220 listWaves(app.db, repo.id, ["pending", "later"]);
221
222 /** What a plan call came to: a wave waiting for a nod, or issues opened. */
223 export type Submitted =
224 | { readonly proposed: Wave }
225 | { readonly opened: Planned };
226
227 /**
228 * One door for a plan. The crew's plan, where plans need a nod, becomes a
229 * wave and opens nothing; anyone else who writes here opens it at once.
230 */
231 export function submitPlan(
232 app: App,
233 actor: User | undefined,
234 repo: Repo,
235 raw: { title?: unknown; why?: unknown; milestone?: unknown; issues: unknown },
236 ): Result<Submitted, PlanError> {
237 if (actor !== undefined && needsNod(app, repo, actor)) {
238 const wave = proposeWave(app, actor, repo, {
239 title: raw.title,
240 why: raw.why,
241 milestone: raw.milestone,
242 issues: raw.issues,
243 });
244 return wave.ok ? ok({ proposed: wave.value }) : wave;
245 }
246 const items = parsePlan(raw.issues);
247 if (!items.ok) return items;
248 const planned = openPlan(app, actor, repo, items.value);
249 return planned.ok ? ok({ opened: planned.value }) : planned;
250 }
251
252 /** A wave as data, for the API and the MCP: what a person (or Grok in the car) reads before saying yes. */
253 export function waveJson(wave: Wave) {
254 return {
255 id: wave.id,
256 title: wave.title,
257 why: wave.why,
258 milestone: wave.milestone,
259 state: wave.state,
260 issues: wave.items.map((item, i) => ({
261 order: i + 1,
262 key: item.key,
263 title: item.title,
264 blockedBy: item.blockedBy,
265 ...(wave.numbers[item.key] === undefined ? {} : { number: wave.numbers[item.key] }),
266 })),
267 ...(wave.words === "" ? {} : { words: wave.words }),
268 proposedAt: wave.createdAt,
269 };
270 }
src/core/repos.ts +12 −1
@@ -116,6 +116,11 @@ export interface Repo {
116116 * default; on a public repository it hands strangers the owner's budget.
117117 */
118118 readonly crewOutsiders: boolean;
119 /**
120 * "Plans need a nod": the planner's wave is a proposal the owner approves,
121 * redirects or sets aside, not issues opened on the map (`actions/waves.ts`).
122 */
123 readonly plansNeedNod: boolean;
119124 /** The issue the planner is given, when the map has run dry. */
120125 readonly directionIssueId: string | null;
121126 /** The repo this was forked from, or null. */
@@ -160,6 +165,7 @@ interface RepoRow {
160165 autonomy_slots: number;
161166 autonomy_by: string | null;
162167 crew_outsiders: number;
168 plans_need_nod: number;
163169 direction_issue_id: string | null;
164170 fork_parent_id: string | null;
165171 sealed_for: string | null;
@@ -197,6 +203,7 @@ function toRepo(row: RepoRow): Repo {
197203 autonomySlots: row.autonomy_slots,
198204 autonomyBy: row.autonomy_by,
199205 crewOutsiders: row.crew_outsiders === 1,
206 plansNeedNod: row.plans_need_nod !== 0,
200207 directionIssueId: row.direction_issue_id,
201208 forkParentId: row.fork_parent_id,
202209 sealedFor: row.sealed_for,
@@ -1014,6 +1021,8 @@ export interface RepoSettings {
10141021 autonomyBy?: string | null;
10151022 /** Whether someone who cannot write here may start or steer a run. */
10161023 crewOutsiders?: boolean;
1024 /** Whether the planner's waves wait for the owner's nod. */
1025 plansNeedNod?: boolean;
10171026 }
10181027
10191028 /** Update the mutable repo fields, leaving unspecified ones untouched. */
@@ -1026,7 +1035,8 @@ export function updateRepoSettings(
10261035 `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3,
10271036 default_branch = ?4, require_review = ?5, require_checks = ?7,
10281037 autonomy = ?8, autonomy_direction = ?9, autonomy_ceiling_usd = ?10,
1029 autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13
1038 autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13,
1039 plans_need_nod = ?14
10301040 WHERE id = ?6`,
10311041 ).run(
10321042 settings.visibility ?? repo.visibility,
@@ -1042,6 +1052,7 @@ export function updateRepoSettings(
10421052 settings.autonomySlots ?? repo.autonomySlots,
10431053 settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy,
10441054 (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0,
1055 (settings.plansNeedNod ?? repo.plansNeedNod) ? 1 : 0,
10451056 );
10461057 return getRepoById(db, repo.id)!;
10471058 }
src/core/schema.ts +23
@@ -1578,6 +1578,29 @@ export const migrations: readonly string[] = [
15781578 expires_at TEXT NOT NULL
15791579 );
15801580 `,
1581 // 74 — plans need a nod (#1114): beside autonomy, a repository setting
1582 // (default on). With it the planner's wave is a proposal the owner
1583 // approves, redirects or sets aside, not a hundred open issues. The wave
1584 // keeps the issues it opened, so the map can read it as a row.
1585 `
1586 ALTER TABLE repo ADD COLUMN plans_need_nod INTEGER NOT NULL DEFAULT 1;
1587 CREATE TABLE wave (
1588 id TEXT PRIMARY KEY,
1589 repo_id TEXT NOT NULL REFERENCES repo(id) ON DELETE CASCADE,
1590 author_id TEXT NOT NULL REFERENCES user(id),
1591 title TEXT NOT NULL,
1592 why TEXT NOT NULL,
1593 milestone TEXT NOT NULL,
1594 items TEXT NOT NULL,
1595 state TEXT NOT NULL CHECK (state IN ('pending','later','approved','redirected')),
1596 words TEXT NOT NULL DEFAULT '',
1597 numbers TEXT NOT NULL DEFAULT '{}',
1598 created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
1599 decided_at TEXT,
1600 decided_by TEXT REFERENCES user(id)
1601 );
1602 CREATE INDEX wave_repo ON wave(repo_id, created_at);
1603 `,
15811604 ];
15821605
15831606 /**
src/core/waves.ts added +138
@@ -0,0 +1,138 @@
1 /**
2 * A wave: the planner's next step as one proposal (#1114) — a title, a
3 * one-line why, the milestone it moves, and three to six issues in order.
4 * It is kept until a person decides: approved (the issues opened, and their
5 * numbers kept so the map can read the wave as a row), redirected (with the
6 * words that sent the planner back), or set aside for later.
7 *
8 * Pure data, no authz, no events (`actions/waves.ts`).
9 */
10
11 import type { Database } from "bun:sqlite";
12 import { id } from "../kernel/id.ts";
13 import type { PlanItem } from "../actions/plan.ts";
14
15 export type WaveState = "pending" | "later" | "approved" | "redirected";
16
17 export interface Wave {
18 readonly id: string;
19 readonly repoId: string;
20 readonly authorId: string;
21 readonly title: string;
22 readonly why: string;
23 /** The named milestone this wave moves. */
24 readonly milestone: string;
25 /** The issues to open, in order. */
26 readonly items: readonly PlanItem[];
27 readonly state: WaveState;
28 /** For a redirect: the words the planner re-plans from. */
29 readonly words: string;
30 /** Once approved: the number each item's key opened as. */
31 readonly numbers: Readonly<Record<string, number>>;
32 readonly createdAt: string;
33 readonly decidedAt: string | null;
34 }
35
36 interface Row {
37 id: string;
38 repo_id: string;
39 author_id: string;
40 title: string;
41 why: string;
42 milestone: string;
43 items: string;
44 state: WaveState;
45 words: string;
46 numbers: string;
47 created_at: string;
48 decided_at: string | null;
49 }
50
51 const fromRow = (r: Row): Wave => ({
52 id: r.id,
53 repoId: r.repo_id,
54 authorId: r.author_id,
55 title: r.title,
56 why: r.why,
57 milestone: r.milestone,
58 items: JSON.parse(r.items) as PlanItem[],
59 state: r.state,
60 words: r.words,
61 numbers: JSON.parse(r.numbers) as Record<string, number>,
62 createdAt: r.created_at,
63 decidedAt: r.decided_at,
64 });
65
66 export function createWave(
67 db: Database,
68 wave: {
69 repoId: string;
70 authorId: string;
71 title: string;
72 why: string;
73 milestone: string;
74 items: readonly PlanItem[];
75 },
76 ): Wave {
77 const key = id();
78 db.query(
79 `INSERT INTO wave (id, repo_id, author_id, title, why, milestone, items, state)
80 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, 'pending')`,
81 ).run(
82 key,
83 wave.repoId,
84 wave.authorId,
85 wave.title,
86 wave.why,
87 wave.milestone,
88 JSON.stringify(wave.items),
89 );
90 return getWave(db, key)!;
91 }
92
93 export function getWave(db: Database, waveId: string): Wave | undefined {
94 const row = db.query<Row, [string]>("SELECT * FROM wave WHERE id = ?1").get(waveId);
95 return row ? fromRow(row) : undefined;
96 }
97
98 /** A repository's waves, oldest first (the order they were proposed in). */
99 export function listWaves(
100 db: Database,
101 repoId: string,
102 states?: readonly WaveState[],
103 ): Wave[] {
104 return db
105 .query<Row, [string]>(
106 "SELECT * FROM wave WHERE repo_id = ?1 ORDER BY created_at, id",
107 )
108 .all(repoId)
109 .map(fromRow)
110 .filter((w) => states === undefined || states.includes(w.state));
111 }
112
113 /** Waves awaiting a nod in these repositories: the inbox's cards. */
114 export function pendingWaves(db: Database, repoIds: readonly string[]): Wave[] {
115 if (repoIds.length === 0) return [];
116 const marks = repoIds.map(() => "?").join(",");
117 return db
118 .query<Row, string[]>(
119 `SELECT * FROM wave WHERE state = 'pending' AND repo_id IN (${marks})
120 ORDER BY created_at, id`,
121 )
122 .all(...repoIds)
123 .map(fromRow);
124 }
125
126 export function decideWave(
127 db: Database,
128 waveId: string,
129 state: WaveState,
130 by: string,
131 extra: { words?: string; numbers?: Record<string, number> } = {},
132 ): void {
133 db.query(
134 `UPDATE wave SET state = ?2, words = ?3, numbers = ?4, decided_by = ?5,
135 decided_at = strftime('%Y-%m-%dT%H:%M:%fZ','now')
136 WHERE id = ?1`,
137 ).run(waveId, state, extra.words ?? "", JSON.stringify(extra.numbers ?? {}), by);
138 }
src/crew/autonomy.ts +5
@@ -12,6 +12,7 @@
1212 * repository's origin.
1313 */
1414
15 import { pendingWaves } from "../core/waves.ts";
1516 import type { Database } from "bun:sqlite";
1617 import type { App } from "../app.ts";
1718 import {
@@ -452,6 +453,10 @@ async function planIfThin(
452453 if (ready >= THIN_MAP && handed.length === 0) return false;
453454 const planner = crew.find((c) => c.role === "planner")?.agent;
454455 if (planner === undefined) return notPlanned(repo, "no planner on the crew");
456 // A wave waiting for the owner's nod is the plan: the planner is not asked
457 // for another until it is approved or redirected (#1114).
458 if (pendingWaves(app.db, [repo.id]).length > 0)
459 return notPlanned(repo, "a wave waits for the owner's nod");
455460 if (repo.autonomyDirection.trim() === "")
456461 return notPlanned(repo, "no direction written");
457462 const direction = ensureDirectionIssue(app, by, repo);
src/crew/brief.ts +7
@@ -101,6 +101,13 @@ export function systemPrompt(input: BriefInput): string {
101101 " It answers with what it opened (key and number), the numbers now ready, and those deferred.",
102102 "- The direction is never finished. When what it names is built, propose its next increment in the same spirit: what a demanding user would want next, what is fragile, slow, ugly, untested or undocumented, what the pictures and the previews show is off. Leave the map with at least three ready issues, every time.",
103103 '- An issue with a comment that starts "Parked by the crew" was tried and could not be finished as written. Split it into smaller issues, or rewrite what done looks like, or close it with a word if the direction no longer needs it — never leave it as it was. One the crew parked twice is yours: your task lists it, with what you may do with it.',
104 ...(repo.plansNeedNod
105 ? [
106 `- Plans need the owner's nod here. Do NOT open issues or link them yourself: propose one wave, and the owner approves it (the issues then open, linked, in your order) or redirects you with words on the direction issue. Propose it in one call:`,
107 ` curl -sH "authorization: Bearer $FORGE_TOKEN" -H "content-type: application/json" -X POST "$FORGE_URL/api/v1/repos/${repo.ownerName}/${repo.name}/plan" -d '{"title":"…","why":"one line","milestone":"the named milestone it moves","issues":[{"key":"a","title":"…","body":"…","blockedBy":[],"pillar":"P0"},{"key":"b","title":"…","body":"…","blockedBy":["a"],"later":true,"why":"…"}]}'`,
108 " A wave is three to six issues in order; blockedBy names the keys (or open issue numbers) each waits for. A comment on the direction issue that starts \"Redirect\" is the owner sending you back: plan the next wave from those words, not the one you proposed before. Your final message names the wave you proposed.",
109 ]
110 : []),
104111 "- Assign nobody and push nothing: the map is the result. The direction issue stays open.",
105112 "- The forge's API works; open no issue to try it. Every issue you open is work a builder is given.",
106113 "- Finish with a short message that lists what you opened, in order, and what is ready now.",
src/http/api.ts +50 −16
@@ -253,8 +253,13 @@ import {
253253 unlinkIssue,
254254 confirmIssue,
255255 } from "../actions/dependencies.ts";
256 import { openPlan, parsePlan } from "../actions/plan.ts";
257256 import { dependenciesOf, repoGraph } from "../core/dependencies.ts";
257 import {
258 decideWave,
259 submitPlan,
260 waitingWaves,
261 waveJson,
262 } from "../actions/waves.ts";
258263 import { pillarView } from "../core/pillars.ts";
259264 import { decisionStats, listDecisions } from "../core/decisions.ts";
260265 import { globalMapJson, mapJson, marksFor } from "../web/pages/map.ts";
@@ -2387,27 +2392,56 @@ export function apiRoutes(router: Router<Handler>): void {
23872392 );
23882393 },
23892394 );
2390 // A plan, all or nothing: the same action as the MCP `plan` tool, so the
2391 // same items and the same refusals (docs/PLANNING.md).
2395 // A plan: issues opened all at once, or, where plans need a nod and the
2396 // caller is the crew, a wave proposed (nothing opened). Then the waves
2397 // waiting, and the nod, the redirect or the later that settles one.
2398 const planFailed = (e: { error: string; message: string }) =>
2399 e.error === "not_found"
2400 ? notFound()
2401 : apiError(e.error, e.error === "forbidden" ? 403 : 422, e.message);
23922402 router.add("POST", "/api/v1/repos/:owner/:name/plan", async (ctx) => {
23932403 const denied = requireScope(ctx, "rw");
23942404 if (denied) return denied;
23952405 const repo = loadRepo(ctx);
23962406 if (!repo) return notFound();
23972407 const input = await body(ctx.request);
2398 const items = parsePlan(input.issues);
2399 if (!items.ok)
2400 return apiError(items.error.error, 422, items.error.message);
2401 const planned = openPlan(ctx.app, ctx.auth.user, repo, items.value);
2402 if (!planned.ok) {
2403 const { error, message } = planned.error;
2404 return apiError(
2405 error,
2406 error === "not_found" ? 404 : error === "forbidden" ? 403 : 422,
2407 message,
2408 );
2409 }
2410 return json(planned.value, 201);
2408 const made = submitPlan(ctx.app, ctx.auth.user, repo, {
2409 title: input.title,
2410 why: input.why,
2411 milestone: input.milestone,
2412 issues: input.issues,
2413 });
2414 if (!made.ok) return planFailed(made.error);
2415 return "proposed" in made.value
2416 ? json({ proposed: waveJson(made.value.proposed) }, 202)
2417 : json(made.value.opened, 201);
2418 });
2419 router.add("GET", "/api/v1/repos/:owner/:name/waves", (ctx) => {
2420 const denied = requireScope(ctx, "ro");
2421 if (denied) return denied;
2422 const repo = loadRepo(ctx);
2423 if (!repo) return notFound();
2424 return json({ waves: waitingWaves(ctx.app, repo).map(waveJson) });
2425 });
2426 router.add("POST", "/api/v1/repos/:owner/:name/waves/:wave/decide", async (ctx) => {
2427 const denied = requireScope(ctx, "rw");
2428 if (denied) return denied;
2429 const repo = loadRepo(ctx);
2430 if (!repo) return notFound();
2431 const input = await body(ctx.request);
2432 const done = decideWave(
2433 ctx.app,
2434 ctx.auth.user,
2435 repo,
2436 ctx.params.wave!,
2437 input.decision,
2438 input.words,
2439 );
2440 if (!done.ok) return planFailed(done.error);
2441 return json({
2442 wave: waveJson(done.value.wave),
2443 ...(done.value.planned ? { opened: done.value.planned.opened } : {}),
2444 });
24112445 });
24122446 router.add(
24132447 "DELETE",
src/http/mcp.ts +80 −8
@@ -33,7 +33,15 @@ import {
3333 unlinkIssue,
3434 } from "../actions/dependencies.ts";
3535 import { holdPull, releasePull } from "../actions/holds.ts";
36 import { openPlan, parsePlan, PLAN_MAX } from "../actions/plan.ts";
36 import { PLAN_MAX } from "../actions/plan.ts";
37 import {
38 decideWave,
39 submitPlan,
40 waitingWaves,
41 waveJson,
42 WAVE_MAX,
43 WAVE_MIN,
44 } from "../actions/waves.ts";
3745 import { cancelRepoRun } from "../actions/runs.ts";
3846 import { clientRows } from "../spawn/clients.ts";
3947 import { reissueDoor, spawnDoor } from "../spawn/door.ts";
@@ -1530,11 +1538,14 @@ const TOOLS: readonly Tool[] = [
15301538 },
15311539 {
15321540 name: "plan",
1533 description: `Open several small issues and link them in one call: all of them or none. Each item has a key, a title, a body and optionally blockedBy, a list of keys of this plan or numbers of issues already open. Where the app has pillars (umbrella issues titled like "P0 Trust: …"), each item also says what it is for: pillar, the one it serves, or later: true with why, one sentence, which puts it behind the Later gate instead of on the ready list; an item that says neither is refused. A bad link (loop, unknown key) refuses the whole plan and names the item. At most ${PLAN_MAX} issues. Answers with the numbers opened, by key, what is ready now, and what waits for later.`,
1541 description: `Open several small issues and link them in one call: all of them or none. Each item has a key, a title, a body and optionally blockedBy, a list of keys of this plan or numbers of issues already open. Where the app has pillars (umbrella issues titled like "P0 Trust: …"), each item also says what it is for: pillar, the one it serves, or later: true with why, one sentence, which puts it behind the Later gate instead of on the ready list; an item that says neither is refused. A bad link (loop, unknown key) refuses the whole plan and names the item. At most ${PLAN_MAX} issues. Answers with the numbers opened, by key, what is ready now, and what waits for later. Where the app's plans need a nod (Settings → On its own) and you are on its crew, nothing is opened: give a title, why (one line), milestone (the one it moves) and ${WAVE_MIN} to ${WAVE_MAX} issues in order, and the answer is the proposed wave, which the owner approves or redirects (decide). Without issues, answers with the waves waiting for a nod, to read aloud.`,
15341542 inputSchema: {
15351543 type: "object",
15361544 properties: {
15371545 app: APP_ARG,
1546 title: { type: "string", description: "A wave's title (when plans need a nod)." },
1547 why: { type: "string", description: "A wave's why, in one line." },
1548 milestone: { type: "string", description: "The named milestone the wave moves." },
15381549 issues: {
15391550 type: "array",
15401551 minItems: 1,
@@ -1573,17 +1584,37 @@ const TOOLS: readonly Tool[] = [
15731584 },
15741585 },
15751586 },
1576 required: ["app", "issues"],
1587 required: ["app"],
15771588 },
15781589 writes: true,
15791590 run(ctx, user, args) {
15801591 const repo = planRepo(ctx, user, args);
15811592 if (isAnswer(repo)) return repo;
1582 const items = parsePlan(args["issues"]);
1583 if (!items.ok) return bad(items.error.error, items.error.message);
1584 const planned = openPlan(ctx.app, user, repo, items.value);
1585 if (!planned.ok) return bad(planned.error.error, planned.error.message);
1586 const { opened, ready, later, gate } = planned.value;
1593 if (args["issues"] === undefined) {
1594 const waves = waitingWaves(ctx.app, repo).map(waveJson);
1595 return good({
1596 says:
1597 waves.length === 0
1598 ? "No wave waits for a nod."
1599 : `${waves.length} wave${waves.length === 1 ? "" : "s"} wait${waves.length === 1 ? "s" : ""} for a nod: ${waves.map((w) => `“${w.title}” (${w.milestone})`).join("; ")}. Approve or redirect with decide.`,
1600 waves,
1601 });
1602 }
1603 const made = submitPlan(ctx.app, user, repo, {
1604 title: args["title"],
1605 why: args["why"],
1606 milestone: args["milestone"],
1607 issues: args["issues"],
1608 });
1609 if (!made.ok) return bad(made.error.error, made.error.message);
1610 if ("proposed" in made.value) {
1611 const wave = waveJson(made.value.proposed);
1612 return good({
1613 says: `Proposed the wave “${wave.title}” toward ${wave.milestone}: ${wave.why} Nothing is opened until the owner approves it or redirects you.`,
1614 wave,
1615 });
1616 }
1617 const { opened, ready, later, gate } = made.value.opened;
15871618 const waits =
15881619 gate === undefined
15891620 ? ""
@@ -1596,6 +1627,47 @@ const TOOLS: readonly Tool[] = [
15961627 });
15971628 },
15981629 },
1630 {
1631 name: "decide",
1632 description:
1633 "Settle a proposed wave (see plan, without issues, for the waves waiting): approve opens its issues, linked in the order proposed and ready; redirect sends the planner back with your words (words) and opens nothing; later sets it aside. Only a person who writes the app decides. Answers with the wave and, on approve, the issue numbers opened.",
1634 inputSchema: {
1635 type: "object",
1636 properties: {
1637 app: APP_ARG,
1638 wave: { type: "string", description: "The wave's id." },
1639 decision: { type: "string", enum: ["approve", "redirect", "later"] },
1640 words: { type: "string", maxLength: 2000, description: "With redirect: where the plan should go instead." },
1641 },
1642 required: ["app", "wave", "decision"],
1643 },
1644 writes: true,
1645 run(ctx, user, args) {
1646 const repo = planRepo(ctx, user, args);
1647 if (isAnswer(repo)) return repo;
1648 const done = decideWave(
1649 ctx.app,
1650 user,
1651 repo,
1652 str(args["wave"]),
1653 args["decision"],
1654 args["words"],
1655 );
1656 if (!done.ok) return bad(done.error.error, done.error.message);
1657 const wave = waveJson(done.value.wave);
1658 const opened = done.value.planned?.opened;
1659 return good({
1660 says:
1661 opened !== undefined
1662 ? `Approved “${wave.title}”: opened ${opened.map((o) => `#${o.number}`).join(", ")}.`
1663 : wave.state === "redirected"
1664 ? `Redirected “${wave.title}”: the planner plans again from your words.`
1665 : `Set “${wave.title}” aside for later.`,
1666 wave,
1667 ...(opened === undefined ? {} : { opened }),
1668 });
1669 },
1670 },
15991671 {
16001672 name: "capacity",
16011673 description:
src/http/server.ts +2
@@ -5,6 +5,7 @@
55 * verdict. Auth is resolved once per request and handed to handlers as data.
66 */
77
8 import { waveDecide } from "../web/pages/waves.ts";
89 import { unsealReleased } from "../actions/sealed.ts";
910 import { capacityPage, capacitySet } from "../web/pages/capacity.ts";
1011 import {
@@ -1101,6 +1102,7 @@ export function buildRouter(): Router<Handler> {
11011102 );
11021103 router.add("GET", "/:owner/:name/settings/autonomy", autonomySettingsPage);
11031104 router.add("POST", "/:owner/:name/settings/autonomy", autonomySettingsUpdate);
1105 router.add("POST", "/:owner/:name/waves/:wave/decide", waveDecide);
11041106 router.add("GET", "/:owner/:name/settings/labels", labelsPage);
11051107 router.add("POST", "/:owner/:name/settings/labels", labelCreate);
11061108 router.add("POST", "/:owner/:name/settings/labels/:id", labelUpdate);
src/web/pages/map.ts +29
@@ -57,6 +57,8 @@ import {
5757 } from "../chrome.ts";
5858 import { liveRegionsJs } from "../client.ts";
5959 import { html, type Html } from "../html.ts";
60 import { listWaves } from "../../core/waves.ts";
61 import { wavesSection } from "./waves_view.ts";
6062 import { page } from "../layout.ts";
6163 import { avatar, hueOf, icon } from "../ui.ts";
6264 import { autonomyStatus, type AutonomyStatus } from "../../crew/autonomy.ts";
@@ -1394,6 +1396,30 @@ export function mapPage(ctx: Ctx): Response {
13941396 graph.issues.map((i) => wordFor(i, readySet, marks)),
13951397 );
13961398 const pillars = pillarView(db, repo);
1399 // With waves on record the map reads as waves toward milestones; the
1400 // whole graph is one click away (?graph=1).
1401 const waves = listWaves(db, repo.id).filter((w) => w.state !== "later");
1402 const showWaves = waves.length > 0 && ctx.url.searchParams.get("graph") !== "1";
1403 if (showWaves)
1404 return page({
1405 ctx,
1406 title: `Map · ${repo.name}`,
1407 crumbs: crumbsFor(repo),
1408 palette: repoPalette(ctx, repo),
1409 body: html`${repoHeader(ctx, repo, "map")}
1410 <div class="page-head mt">
1411 <h1>Map</h1>
1412 <p class="muted">
1413 The plan as waves toward milestones: what each wave is for, what
1414 landed in it, what is left.
1415 <a href="${repoBase(repo)}/map?graph=1">Show the whole graph</a> ·
1416 <a href="${repoBase(repo)}/milestones">How far each milestone is</a>.
1417 </p>
1418 ${autonomyLine(ctx, repo)}
1419 </div>
1420 ${wavesSection(db, repo, waves, issueHref, repoBase(repo))}`,
1421 styleCss: mapCss,
1422 });
13971423 const body = html`${repoHeader(ctx, repo, "map")}
13981424 <div class="page-head mt">
13991425 <h1>Map</h1>
@@ -1401,6 +1427,9 @@ export function mapPage(ctx: Ctx): Response {
14011427 What waits for what. The top edge is ready now; the chain in the accent
14021428 is the least work that still has to happen in order.
14031429 <a href="${repoBase(repo)}/milestones">How far each milestone is</a>.
1430 ${waves.length > 0
1431 ? html`<a href="${repoBase(repo)}/map">Back to the waves</a>.`
1432 : null}
14041433 </p>
14051434 ${autonomyLine(ctx, repo)}
14061435 </div>
src/web/pages/settings.ts +1
@@ -1764,6 +1764,7 @@ export async function autonomySettingsUpdate(ctx: Ctx): Promise<Response> {
17641764 autonomyDirection: field(form, "direction").trim().slice(0, 2000),
17651765 autonomyCeilingUsd: ceiling,
17661766 autonomySlots: slots,
1767 plansNeedNod: form.get("plansNeedNod") !== null,
17671768 autonomyBy: mode === "off" ? null : (ctx.auth.user?.id ?? null),
17681769 });
17691770 return flashTo(ctx, `${base}/settings#autonomy`, {
src/web/pages/waves.ts added +41
@@ -0,0 +1,41 @@
1 /**
2 * The nod, as a form post (#1114): the inbox card's Approve, Redirect and
3 * Later. One route; the decision itself is `actions/waves.ts`, the same
4 * one the API and the MCP's `decide` call.
5 */
6
7 import { decideWave } from "../../actions/waves.ts";
8 import type { Ctx } from "../../http/context.ts";
9 import { notFoundPage, repoBase, loadRepo, signInFirst } from "../chrome.ts";
10 import { field, readForm } from "../form.ts";
11 import { flashTo } from "../layout.ts";
12
13 // POST /:owner/:name/waves/:wave/decide
14 export async function waveDecide(ctx: Ctx): Promise<Response> {
15 if (!ctx.auth.user) return signInFirst(ctx);
16 const repo = loadRepo(ctx);
17 if (!repo) return notFoundPage(ctx);
18 const form = await readForm(ctx, "rw");
19 if (form instanceof Response) return form;
20 const done = decideWave(
21 ctx.app,
22 ctx.auth.user,
23 repo,
24 ctx.params.wave ?? "",
25 field(form, "decision"),
26 field(form, "words"),
27 );
28 if (!done.ok)
29 return done.error.error === "not_found"
30 ? notFoundPage(ctx)
31 : flashTo(ctx, "/", { tone: "danger", message: done.error.message });
32 const { wave, planned } = done.value;
33 return flashTo(ctx, wave.state === "approved" ? `${repoBase(repo)}/map` : "/", {
34 message:
35 wave.state === "approved"
36 ? `Approved: ${planned!.opened.length} issues opened, linked and ready.`
37 : wave.state === "redirected"
38 ? "Redirected: the planner plans again from your words."
39 : "Set aside for later.",
40 });
41 }
src/web/pages/waves_view.ts added +79
@@ -0,0 +1,79 @@
1 /**
2 * The map read as waves toward named milestones (#1114): each wave a row —
3 * its title and why — its issues beneath, what landed in it and what is
4 * left. A wave waiting for a nod shows its issues as proposed. The full
5 * graph stays one click away (`?graph=1`, `map.ts`).
6 */
7
8 import { getIssue } from "../../core/issues.ts";
9 import type { Repo } from "../../core/repos.ts";
10 import type { Wave } from "../../core/waves.ts";
11 import type { Database } from "bun:sqlite";
12 import { html, type Html } from "../html.ts";
13
14 const STATE_WORDS: Readonly<Record<Wave["state"], string>> = {
15 pending: "waiting for a nod",
16 later: "set aside for later",
17 approved: "approved",
18 redirected: "redirected",
19 };
20
21 /** One wave: its row, its issues in order, and the tally. */
22 function waveRow(
23 db: Database,
24 repo: Repo,
25 wave: Wave,
26 issueHref: (base: string, number: number) => string,
27 base: string,
28 ): Html {
29 const issues = wave.items.map((item) => {
30 const number = wave.numbers[item.key];
31 const found = number === undefined ? undefined : getIssue(db, repo.id, number);
32 return { item, number, state: found?.state };
33 });
34 const landed = issues.filter((i) => i.state !== undefined && i.state !== "open").length;
35 const left = wave.state === "approved" ? issues.length - landed : issues.length;
36 return html`<li class="wave" id="wave-${wave.id}" data-state="${wave.state}">
37 <h3>${wave.title} <span class="muted small">${STATE_WORDS[wave.state]}</span></h3>
38 <p class="muted small">${wave.why}</p>
39 <ol class="small">
40 ${issues.map((i) =>
41 i.number === undefined
42 ? html`<li>${i.item.title}</li>`
43 : html`<li data-landed="${i.state === "open" ? "no" : "yes"}">
44 <a href="${issueHref(base, i.number)}">${i.item.title}</a>
45 ${i.state === "open" ? null : html`<span class="muted">landed</span>`}
46 </li>`,
47 )}
48 </ol>
49 <p class="small muted">
50 ${wave.state === "approved"
51 ? `${landed} landed, ${left} left`
52 : wave.state === "redirected"
53 ? `not opened; redirected${wave.words === "" ? "" : `: ${wave.words}`}`
54 : `${issues.length} proposed, none opened`}
55 </p>
56 </li>`;
57 }
58
59 /** The waves, grouped under the milestone each moves, newest wave last. */
60 export function wavesSection(
61 db: Database,
62 repo: Repo,
63 waves: readonly Wave[],
64 issueHref: (base: string, number: number) => string,
65 base: string,
66 ): Html {
67 const byMilestone = new Map<string, Wave[]>();
68 for (const w of waves) byMilestone.set(w.milestone, [...(byMilestone.get(w.milestone) ?? []), w]);
69 return html`<section class="waves" id="waves">
70 ${[...byMilestone].map(
71 ([milestone, rows]) => html`<div class="wave-milestone">
72 <h2>${milestone}</h2>
73 <ul class="list">
74 ${rows.map((w) => waveRow(db, repo, w, issueHref, base))}
75 </ul>
76 </div>`,
77 )}
78 </section>`;
79 }
src/web/studio/asks.ts +76 −1
@@ -14,6 +14,7 @@ import { appsRuntime } from "../../apps/runtime.ts";
1414 import { appsForRepos, getAppByRepo, listApps } from "../../core/apps.ts";
1515 import { latestDecision, stopStands } from "../../core/decisions.ts";
1616 import { getHold, holdsFor } from "../../core/holds.ts";
17 import { pendingWaves, type Wave } from "../../core/waves.ts";
1718 import { askDismissals } from "../../core/interactions.ts";
1819 import { askMeasure, syncAskLedger, type AskEnd } from "../../core/ask_ledger.ts";
1920 import {
@@ -93,7 +94,7 @@ export function writableAppsOf(ctx: Ctx, user: User | undefined) {
9394 );
9495 }
9596
96 export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined";
97 export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "proposed";
9798
9899 /** Dollars as a person reads them: cents when small, whole when not. */
99100 const dollars = (n: number): string => (n < 10 ? n.toFixed(2) : n.toFixed(0));
@@ -108,6 +109,8 @@ export interface Decision {
108109 /** For "parked": the issue the breaker stopped; for "declined": the
109110 * direction issue the planner declined. */
110111 readonly issue?: Issue | undefined;
112 /** For "proposed": the wave waiting for a nod. */
113 readonly wave?: Wave | undefined;
111114 readonly who: string;
112115 /** Three sentences at most: what, why, what happens next. */
113116 readonly says: string;
@@ -154,6 +157,11 @@ export const ASK_WORDS: Readonly<Record<DecisionKind, AskWords>> = {
154157 options: ["Answer the planner"],
155158 ifNothing: "the planner plans nothing more for this app",
156159 },
160 proposed: {
161 decision: "The planner proposes a wave: open its issues?",
162 options: ["Approve", "Redirect", "Later"],
163 ifNothing: "it waits; no issue opens and the planner plans nothing more",
164 },
157165 paused: {
158166 decision: "Raise today's ceiling?",
159167 options: ["Raise it in settings"],
@@ -176,6 +184,7 @@ export interface Consequence {
176184 export const KIND_TIER: Readonly<Record<DecisionKind, Consequence>> = {
177185 paused: { score: 80, why: "money: the crew is stopped at its ceiling" },
178186 declined: { score: 70, why: "the planner has stopped for this app" },
187 proposed: { score: 60, why: "the plan waits for your nod" },
179188 stopped: { score: 50, why: "red, and the crew stopped" },
180189 review: { score: 45, why: "an agent's change waits for a review" },
181190 parked: { score: 40, why: "parked by the crew" },
@@ -208,6 +217,7 @@ interface AskCandidate {
208217 readonly repo: Repo;
209218 readonly pull?: Pull;
210219 readonly issue?: Issue;
220 readonly wave?: Wave;
211221 readonly who: string;
212222 /** Whether the author is a crew member — a "look" card words itself
213223 * differently for a person's own change than for the crew's (below).
@@ -389,6 +399,19 @@ function askCandidatesFor(
389399 who: "the planner",
390400 decline: { runId: d.runId, words: d.words },
391401 });
402 // A wave the planner proposed waits for the owner's nod: one card.
403 for (const wave of pendingWaves(db, repos.map((r) => r.id))) {
404 const repo = byId.get(wave.repoId);
405 if (repo)
406 out.push({
407 kind: "proposed",
408 id: `proposed:${wave.id}`,
409 since: wave.createdAt,
410 repo,
411 wave,
412 who: "the planner",
413 });
414 }
392415 return out;
393416 }
394417
@@ -637,6 +660,8 @@ function lineOf(c: AskCandidate): string {
637660 return `the crew parked #${c.issue!.number} after three failed runs`;
638661 if (c.kind === "declined")
639662 return "the planner declined the direction and waits for you";
663 if (c.kind === "proposed")
664 return `the planner proposes the wave \u201c${c.wave!.title}\u201d toward ${c.wave!.milestone}`;
640665 const title = c.pull?.title ?? "";
641666 if (c.kind === "review")
642667 return `"${title}" waits for your review: ${reviewWhy(c.reviewWait)}`;
@@ -662,6 +687,7 @@ export const ROW_PLURAL: Readonly<Record<DecisionKind, (n: number) => string>> =
662687 stopped: (n) => `the crew stopped on ${n} changes`,
663688 parked: (n) => `the crew parked ${n} issues after three failed runs`,
664689 declined: (n) => `the planner declined ${n} times and waits for you`,
690 proposed: (n) => `the planner proposes ${n} waves and waits for your nod`,
665691 paused: (n) => `${n} pauses at the ceiling`,
666692 };
667693
@@ -717,6 +743,7 @@ export function askLinesFor(
717743 const line = `${row.repo.name}${only.kind === "paused" ? " " : ": "}${lineOf(only)}`;
718744 if (only.kind === "paused")
719745 return { ...about, line, link: `${base}/settings/autonomy` };
746 if (only.kind === "proposed") return { ...about, line, link: `${base}/map` };
720747 if (only.kind === "parked" || only.kind === "declined")
721748 return {
722749 ...about,
@@ -789,6 +816,16 @@ export function decisionsFor(
789816 says: `The planner declined the direction: \u201c${c.decline.words}\u201d. It plans nothing more until you answer on #${c.issue.number}.`,
790817 short: `the planner declined the direction: \u201c${c.decline.words}\u201d`,
791818 };
819 if (c.kind === "proposed" && c.wave)
820 return {
821 kind: "proposed",
822 id: `proposed:${c.wave.id}`,
823 repo: c.repo,
824 wave: c.wave,
825 who: c.who,
826 says: `${c.who} proposes the wave \u201c${c.wave.title}\u201d toward ${c.wave.milestone}: ${c.wave.why}`,
827 short: `a wave toward ${c.wave.milestone}: \u201c${c.wave.title}\u201d`,
828 };
792829 if (c.kind === "stopped" && c.pull) {
793830 const tries = c.tries ?? 0;
794831 const stopped = c.stoppedByDecider ?? false;
@@ -856,6 +893,13 @@ const askFormId = (d: Decision): string => `ask-${d.id}`;
856893 * HTML; the button reaches it by id.
857894 */
858895 export function decisionForm(d: Decision): Html | null {
896 if (d.kind === "proposed" && d.wave)
897 return html`<form
898 id="${askFormId(d)}"
899 method="post"
900 hidden
901 action="${repoBase(d.repo)}/waves/${d.wave.id}/decide"
902 ></form>`;
859903 const pull = d.pull;
860904 if (pull === undefined) return null;
861905 const base = repoBase(d.repo);
@@ -918,6 +962,35 @@ export function decisionActions(ctx: Ctx, d: Decision): Html {
918962 href: `${changeHref(base, pull.number)}#comment-body`,
919963 size: "sm",
920964 })}`;
965 if (d.kind === "proposed" && d.wave)
966 return html`${btn("Approve", {
967 name: "decision",
968 value: "approve",
969 form: askFormId(d),
970 size: "sm",
971 variant: "primary",
972 })}
973 <input
974 class="input"
975 type="text"
976 name="words"
977 form="${askFormId(d)}"
978 maxlength="2000"
979 placeholder="Or say where the plan should go instead"
980 aria-label="Redirect the plan: say where it should go"
981 />
982 ${btn("Redirect", {
983 name: "decision",
984 value: "redirect",
985 form: askFormId(d),
986 size: "sm",
987 })}
988 ${btn("Later", {
989 name: "decision",
990 value: "later",
991 form: askFormId(d),
992 size: "sm",
993 })}`;
921994 if (d.kind === "declined" && d.issue)
922995 return html`${btn("Answer", {
923996 href: `${base}/issues/${d.issue.number}#comment-body`,
@@ -1054,6 +1127,8 @@ export function askTargetsFor(
10541127 if (ask === undefined) refused.push({ item, reason: "it no longer asks you" });
10551128 else if (ask.kind === "paused")
10561129 refused.push({ item, reason: "a ceiling is raised in the app's settings" });
1130 else if (ask.kind === "proposed")
1131 refused.push({ item, reason: "a planner's wave is approved or redirected on its card" });
10571132 else if (ask.kind === "declined")
10581133 refused.push({ item, reason: "a planner's decline is answered on its issue" });
10591134 else issueIds.push((ask.pull ?? ask.issue)!.id);
src/web/studio/asks_page.ts +16 −4
@@ -93,15 +93,25 @@ const clause = (
9393 >
9494 </p>`;
9595
96 /** A proposed wave's issues, in the order they would open, so the nod is an informed one. */
97 const waveIssues = (d: Decision): Html | null =>
98 d.wave === undefined
99 ? null
100 : html`<ol class="small wave-issues">
101 ${d.wave.items.map((item) => html`<li>${item.title}</li>`)}
102 </ol>`;
103
96104 function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html {
97105 const base = repoBase(d.repo);
98 const title = d.pull
106 const title = d.wave
107 ? html`<a href="${base}/map#wave-${d.wave.id}">${d.wave.title}</a>`
108 : d.pull
99109 ? html`<a href="${changeHref(base, d.pull.number)}">${d.pull.title}</a>`
100110 : d.issue
101111 ? html`<a href="${base}/issues/${d.issue.number}">${d.issue.title}</a>`
102112 : html`<a href="${base}/settings/autonomy">Paused</a>`;
103113 return card(
104 html`${clause(d, d.kind, d.consequence)}
114 html`${clause(d, d.kind, d.consequence)}${waveIssues(d)}
105115 <div class="bar mt">${decisionActions(ctx, d)}</div>`,
106116 {
107117 id: askAnchor(d.id),
@@ -125,13 +135,15 @@ function rowCard(ctx: Ctx, r: AskRow<Decision>, picked: ReadonlySet<string>): Ht
125135 const base = repoBase(r.repo);
126136 const lines = r.items.map((d) => {
127137 const number = d.pull?.number ?? d.issue?.number;
128 const href = d.pull
138 const href = d.wave
139 ? `${base}/map#wave-${d.wave.id}`
140 : d.pull
129141 ? changeHref(base, d.pull.number)
130142 : `${base}/issues/${String(number)}`;
131143 const box = pick(d, picked);
132144 return row({
133145 ...(box === null ? {} : { lead: box }),
134 title: html`<a href="${href}">${d.pull?.title ?? d.issue?.title ?? ""}</a>`,
146 title: html`<a href="${href}">${d.wave?.title ?? d.pull?.title ?? d.issue?.title ?? ""}</a>`,
135147 meta: html`<span class="bar">${decisionActions(ctx, d)}</span>`,
136148 });
137149 });
src/web/studio/crew.ts +15
@@ -340,6 +340,21 @@ ${repo.autonomyDirection}</textarea
340340 type: "number",
341341 hint: "Agent runs at once here. This is the WIP limit.",
342342 })}
343 <div class="field">
344 <label class="check">
345 <input
346 type="checkbox"
347 name="plansNeedNod"
348 ${repo.plansNeedNod ? html`checked` : null}
349 />
350 <span
351 >Plans need a nod — the planner proposes a wave (a title, why,
352 three to six issues in order) as one card in your inbox. Approve
353 opens the issues, linked and ready; Redirect re-plans from your
354 words. Off, the planner opens issues on the map itself.</span
355 >
356 </label>
357 </div>
343358 <div class="form-actions">${btn("Save", { variant: "primary" })}</div>
344359 </form>`;
345360 // An autonomous repository with no reviewer lands nothing an agent wrote
test/mcp.test.ts +1
@@ -193,6 +193,7 @@ describe("the forge over MCP", () => {
193193 "unlink",
194194 "hold",
195195 "plan",
196 "decide",
196197 "capacity",
197198 "report",
198199 ]);
test/plan-nod.test.ts added +349
@@ -0,0 +1,349 @@
1 /**
2 * The owner approves the plan (#1114). Where plans need a nod, the crew's
3 * planner opens no issues: it proposes a wave. Approving opens the issues
4 * with the links the proposal named; redirecting sends the planner back with
5 * the owner's words in its prompt; the inbox shows one card; the map reads
6 * as waves; and the MCP says the same.
7 */
8
9 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
10 import { mkdtemp, rm } from "node:fs/promises";
11 import { tmpdir } from "node:os";
12 import { join } from "node:path";
13 import { createApp, type App } from "../src/app.ts";
14 import { addToCrew, createAgent } from "../src/actions/crew.ts";
15 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
16 import { decideWave, submitPlan } from "../src/actions/waves.ts";
17 import { setCrewRole } from "../src/core/agents.ts";
18 import { dependenciesOf } from "../src/core/dependencies.ts";
19 import { getIssue, listIssues, setIssueState } from "../src/core/issues.ts";
20 import { listComments } from "../src/core/issues.ts";
21 import { getRepoById, type Repo } from "../src/core/repos.ts";
22 import { createToken } from "../src/core/tokens.ts";
23 import { createUser, getUserByName, type User } from "../src/core/users.ts";
24 import { listWaves } from "../src/core/waves.ts";
25 import { systemPrompt, taskPrompt } from "../src/crew/brief.ts";
26 import { getAgent } from "../src/core/agents.ts";
27 import { serve, type Servers } from "../src/http/server.ts";
28 import { askLinesFor } from "../src/web/studio/asks.ts";
29 import { quietLogs } from "./helpers/globals.ts";
30
31 quietLogs();
32
33 const ISSUES = [
34 { key: "a", title: "Cut the engine out", body: "move it" },
35 { key: "b", title: "Give it a test", blockedBy: ["a"] },
36 { key: "c", title: "Document it", blockedBy: ["a", "b"] },
37 ];
38 const WAVE = {
39 title: "Engine out",
40 why: "A second game needs the engine.",
41 milestone: "Two games",
42 issues: ISSUES,
43 };
44
45 describe("plans need a nod", () => {
46 let dataDir = "";
47 let app: App;
48 let servers: Servers;
49 let alice: User;
50 let chart: User;
51 let repo: Repo;
52 let rw = "";
53 let nextId = 1;
54
55 const fresh = (): Repo => getRepoById(app.db, repo.id)!;
56 const issueCount = (): number => listIssues(app.db, repo.id, {}).length;
57
58 const tool = async (name: string, args: unknown) => {
59 const res = await fetch(`${servers.url}/mcp`, {
60 method: "POST",
61 headers: {
62 "content-type": "application/json",
63 accept: "application/json, text/event-stream",
64 authorization: `Bearer ${rw}`,
65 },
66 body: JSON.stringify({
67 jsonrpc: "2.0",
68 id: nextId++,
69 method: "tools/call",
70 params: { name, arguments: args },
71 }),
72 });
73 const body = (await res.json()) as any;
74 const text: string = body.result.content[0].text;
75 return body.result.isError === true
76 ? { error: text, value: undefined }
77 : { error: undefined, value: JSON.parse(text) };
78 };
79
80 beforeAll(async () => {
81 dataDir = await mkdtemp(join(tmpdir(), "forge-nod-"));
82 app = createApp({ dataDir, port: 0 });
83 servers = await serve(app);
84 const a = await createUser(app.db, {
85 trusted: true,
86 username: "alice",
87 email: "[email protected]",
88 password: "a-good-passphrase",
89 adminIfFirst: true,
90 });
91 if (!a.ok) throw new Error(a.error);
92 alice = a.value;
93 rw = createToken(app.db, alice.id, "rw", "rw").token;
94 const made = await createRepo(app, alice, { name: "garden", visibility: "private" });
95 if (!made.ok) throw new Error(String(made.error));
96 repo = made.value;
97 const agent = await createAgent(app, alice, { username: "chart" });
98 if (!agent.ok) throw new Error(String(agent.error));
99 expect(addToCrew(app, alice, repo, "chart").ok).toBe(true);
100 chart = getUserByName(app.db, "chart")!;
101 setCrewRole(app.db, repo.id, chart.id, "planner");
102 const set = await updateRepoSettings(app, alice, repo, {
103 autonomy: "assisted",
104 autonomyDirection: "Pull the engine out so a second game can use it.",
105 } as never);
106 if (!set.ok) throw new Error(String(set.error));
107 repo = fresh();
108 }, 30_000);
109
110 afterAll(async () => {
111 servers.stop();
112 app.close();
113 await rm(dataDir, { recursive: true, force: true });
114 });
115
116 test("the setting is on by default", () => {
117 expect(repo.plansNeedNod).toBe(true);
118 });
119
120 test("with it on, the planner's plan opens no issues: it is a wave", () => {
121 const before = issueCount();
122 const made = submitPlan(app, chart, repo, WAVE);
123 expect(made.ok).toBe(true);
124 if (!made.ok || !("proposed" in made.value)) throw new Error("not proposed");
125 expect(issueCount()).toBe(before);
126 const wave = made.value.proposed;
127 expect(wave.state).toBe("pending");
128 expect(wave.milestone).toBe("Two games");
129 expect(wave.items.map((i) => i.key)).toEqual(["a", "b", "c"]);
130 });
131
132 test("a wave is three to six issues, with a title, a why and a milestone", () => {
133 const two = submitPlan(app, chart, repo, { ...WAVE, issues: ISSUES.slice(0, 2) });
134 expect(two.ok ? "" : two.error.error).toBe("wave_size");
135 const seven = submitPlan(app, chart, repo, {
136 ...WAVE,
137 issues: Array.from({ length: 7 }, (_, i) => ({ key: `k${i}`, title: `t${i}` })),
138 });
139 expect(seven.ok ? "" : seven.error.error).toBe("wave_size");
140 for (const missing of ["title", "why", "milestone"] as const) {
141 const bad = submitPlan(app, chart, repo, { ...WAVE, [missing]: " " });
142 expect(bad.ok).toBe(false);
143 }
144 const loop = submitPlan(app, chart, repo, {
145 ...WAVE,
146 issues: [
147 { key: "a", title: "A", blockedBy: ["c"] },
148 { key: "b", title: "B", blockedBy: ["a"] },
149 { key: "c", title: "C", blockedBy: ["b"] },
150 ],
151 });
152 expect(loop.ok ? "" : loop.error.error).toBe("cycle");
153 });
154
155 test("the proposal is one card in the owner's inbox, with its issues and three answers", () => {
156 const lines = askLinesFor(app.db, alice).filter((l) => l.kind === "proposed");
157 expect(lines.length).toBe(1);
158 expect(lines[0]!.line).toContain("Engine out");
159 expect(lines[0]!.words.options).toEqual(["Approve", "Redirect", "Later"]);
160 });
161
162 test("an agent never decides a wave", () => {
163 const wave = listWaves(app.db, repo.id)[0]!;
164 const refused = decideWave(app, chart, repo, wave.id, "approve");
165 expect(refused.ok ? "" : refused.error.error).toBe("forbidden");
166 expect(issueCount()).toBe(0);
167 });
168
169 test("approval opens the issues with the dependencies the proposal named", () => {
170 const wave = listWaves(app.db, repo.id)[0]!;
171 const done = decideWave(app, alice, repo, wave.id, "approve");
172 expect(done.ok).toBe(true);
173 if (!done.ok) return;
174 const n = done.value.wave.numbers;
175 expect(Object.keys(n).sort()).toEqual(["a", "b", "c"]);
176 const waits = (key: string): number[] =>
177 dependenciesOf(app.db, getIssue(app.db, repo.id, n[key]!)!.id)
178 .blockedBy.map((i: { number: number }) => i.number)
179 .sort();
180 expect(waits("a")).toEqual([]);
181 expect(waits("b")).toEqual([n.a!]);
182 expect(waits("c")).toEqual([n.a!, n.b!].sort());
183 expect(done.value.planned!.ready).toEqual([n.a!]);
184 // Decided once.
185 const again = decideWave(app, alice, repo, wave.id, "approve");
186 expect(again.ok ? "" : again.error.error).toBe("decided");
187 // No longer asks.
188 expect(askLinesFor(app.db, alice).some((l) => l.kind === "proposed")).toBe(false);
189 });
190
191 test("the map reads as waves, with what landed and what is left", async () => {
192 const wave = listWaves(app.db, repo.id)[0]!;
193 setIssueState(app.db, getIssue(app.db, repo.id, wave.numbers.a!)!.id, "closed");
194 const res = await fetch(`${servers.url}/alice/garden/map`, {
195 headers: { authorization: `Bearer ${rw}` },
196 });
197 const text = await res.text();
198 // The wave's row, under its milestone, with the tally.
199 expect(text).toContain("Two games");
200 expect(text).toContain("Engine out");
201 expect(text).toContain("1 landed, 2 left");
202 expect(text).toContain("?graph=1");
203 const graph = await fetch(`${servers.url}/alice/garden/map?graph=1`, {
204 headers: { authorization: `Bearer ${rw}` },
205 });
206 expect(await graph.text()).toContain("Back to the waves");
207 });
208
209 test("redirect re-runs the planner with the words, and opens nothing", () => {
210 const made = submitPlan(app, chart, repo, { ...WAVE, title: "Engine again" });
211 if (!made.ok || !("proposed" in made.value)) throw new Error("not proposed");
212 const before = issueCount();
213 const words = "Start with the save format, not the engine.";
214 const done = decideWave(app, alice, repo, made.value.proposed.id, "redirect", words);
215 expect(done.ok).toBe(true);
216 expect(issueCount()).toBe(before + 1); // the direction issue, nothing else
217 expect(done.ok && done.value.wave.state).toBe("redirected");
218 const dir = listIssues(app.db, repo.id, {}).find((i) => i.title.startsWith("Direction"))!;
219 expect(dir.assigneeId).toBe(chart.id);
220 const comments = listComments(app.db, dir.id);
221 expect(comments.some((c) => c.body.includes(words))).toBe(true);
222 // And it is in the planner's prompt.
223 const prompt = taskPrompt({
224 agent: getAgent(app.db, chart.id)!,
225 repo: fresh(),
226 issue: dir,
227 branch: "x",
228 forgeUrl: "http://forge.test",
229 isApp: false,
230 resuming: false,
231 role: "planner",
232 reason: "assigned",
233 comments,
234 reviews: [],
235 reviewComments: [],
236 since: "",
237 } as never);
238 expect(prompt).toContain(words);
239 // A redirect with no words is refused.
240 const other = submitPlan(app, chart, repo, { ...WAVE, title: "Third" });
241 if (!other.ok || !("proposed" in other.value)) throw new Error("not proposed");
242 const empty = decideWave(app, alice, repo, other.value.proposed.id, "redirect", " ");
243 expect(empty.ok ? "" : empty.error.error).toBe("empty_words");
244 });
245
246 test("later sets a wave aside without opening it; the planner is told how to propose", () => {
247 const wave = listWaves(app.db, repo.id).find((w) => w.title === "Third")!;
248 const before = issueCount();
249 const done = decideWave(app, alice, repo, wave.id, "later");
250 expect(done.ok && done.value.wave.state).toBe("later");
251 expect(issueCount()).toBe(before);
252 const prompt = systemPrompt({
253 agent: getAgent(app.db, chart.id)!,
254 repo: fresh(),
255 issue: listIssues(app.db, repo.id, {})[0]!,
256 branch: "x",
257 forgeUrl: "http://forge.test",
258 isApp: false,
259 resuming: false,
260 role: "planner",
261 });
262 expect(prompt).toContain("Plans need the owner's nod");
263 expect(prompt).toContain("/plan");
264 });
265
266 test("a person's own plan opens at once; with the setting off, so does the planner's", async () => {
267 const mine = submitPlan(app, alice, repo, { issues: ISSUES });
268 expect(mine.ok && "opened" in mine.value).toBe(true);
269 const off = await updateRepoSettings(app, alice, repo, { plansNeedNod: false } as never);
270 if (!off.ok) throw new Error(String(off.error));
271 const theirs = submitPlan(app, chart, fresh(), { issues: ISSUES });
272 expect(theirs.ok && "opened" in theirs.value).toBe(true);
273 const back = await updateRepoSettings(app, alice, fresh(), { plansNeedNod: true } as never);
274 if (!back.ok) throw new Error(String(back.error));
275 });
276
277 test("an agent cannot turn the nod off", async () => {
278 const off = await updateRepoSettings(app, chart, fresh(), { plansNeedNod: false } as never);
279 expect(off.ok).toBe(false);
280 });
281
282 test("MCP: plan returns the proposal, reads the waves; decide approves", async () => {
283 const proposed = submitPlan(app, chart, fresh(), { ...WAVE, title: "Via MCP" });
284 if (!proposed.ok || !("proposed" in proposed.value)) throw new Error("not proposed");
285 const read = await tool("plan", { app: "alice/garden" });
286 expect(read.value.waves.map((w: any) => w.title)).toContain("Via MCP");
287 expect(read.value.says).toContain("Via MCP");
288 const before = issueCount();
289 const bad = await tool("decide", { app: "alice/garden", wave: proposed.value.proposed.id, decision: "maybe" });
290 expect(bad.error).toContain("invalid");
291 const yes = await tool("decide", { app: "alice/garden", wave: proposed.value.proposed.id, decision: "approve" });
292 expect(yes.value.opened.length).toBe(3);
293 expect(issueCount()).toBe(before + 3);
294 });
295
296 test("API: the crew's POST /plan proposes; the decide route redirects", async () => {
297 const agentToken = createToken(app.db, chart.id, "run", "rw").token;
298 const before = issueCount();
299 const res = await fetch(`${servers.url}/api/v1/repos/alice/garden/plan`, {
300 method: "POST",
301 headers: { authorization: `Bearer ${agentToken}`, "content-type": "application/json" },
302 body: JSON.stringify(WAVE),
303 });
304 expect(res.status).toBe(202);
305 const { proposed } = (await res.json()) as any;
306 expect(issueCount()).toBe(before);
307 // The agent cannot decide its own wave.
308 const no = await fetch(`${servers.url}/api/v1/repos/alice/garden/waves/${proposed.id}/decide`, {
309 method: "POST",
310 headers: { authorization: `Bearer ${agentToken}`, "content-type": "application/json" },
311 body: JSON.stringify({ decision: "approve" }),
312 });
313 expect(no.status).toBe(403);
314 const yes = await fetch(`${servers.url}/api/v1/repos/alice/garden/waves/${proposed.id}/decide`, {
315 method: "POST",
316 headers: { authorization: `Bearer ${rw}`, "content-type": "application/json" },
317 body: JSON.stringify({ decision: "redirect", words: "smaller, please" }),
318 });
319 expect(yes.status).toBe(200);
320 expect(issueCount()).toBe(before);
321 });
322
323 test("the inbox card is one tap: Approve posts to the wave's own route", async () => {
324 const proposed = submitPlan(app, chart, fresh(), { ...WAVE, title: "From the card" });
325 if (!proposed.ok || !("proposed" in proposed.value)) throw new Error("not proposed");
326 const wave = proposed.value.proposed;
327 const signin = await fetch(`${servers.url}/signin`, {
328 method: "POST",
329 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
330 redirect: "manual",
331 });
332 const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!;
333 const home = await (await fetch(`${servers.url}/`, { headers: { cookie } })).text();
334 expect(home).toContain("From the card");
335 expect(home).toContain(`/alice/garden/waves/${wave.id}/decide`);
336 expect(home).toContain('value="approve"');
337 expect(home).toContain('value="redirect"');
338 expect(home).toContain('value="later"');
339 const before = issueCount();
340 const post = await fetch(`${servers.url}/alice/garden/waves/${wave.id}/decide`, {
341 method: "POST",
342 headers: { cookie, origin: servers.url },
343 body: new URLSearchParams({ decision: "approve" }),
344 redirect: "manual",
345 });
346 expect(post.status).toBe(303);
347 expect(issueCount()).toBe(before + 3);
348 });
349 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs