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

Crew feed: show issues the crew parked twice and the drill result, off the owner's board #3822

Closed opened this
Closed without merging

scout/forge:scout/3819-crew-feed-show-issues-the-crew-parked-tw → main 3 commits fork 4 threads · 4 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +294 −0
README.md +3
@@ -27,6 +27,9 @@ claim state and the same apps-running note, never a claim link.
2727 Each agent's scorecard — pulls landed of opened, review rounds, red checks,
2828 reverts, time to land — is on Settings → Crew (`/settings/crew`) and in the
2929 terminal's palette as "Crew scorecard per agent"; both are a forge admin's only.
30 The same page lists, one line each, every issue the crew parked twice and handed
31 to the planner and the last restore drill's pass or fail; the terminal has them as
32 "Crew notes".
3033 Under the agents, each team that has a pull has one pooled row (its members'
3134 counts added, the ratios taken from the sums; an agent on two teams counts in
3235 both): `data-team` rows on the page, "team <name>" rows in that terminal screen.
src/crew/notes.ts added +46
@@ -0,0 +1,46 @@
1 /**
2 * What the crew keeps to itself, read once for both doors: each issue it
3 * parked twice and handed to the planner (`parkedTwice`), and the last
4 * restore drill. The owner's board is not where these are read (#3819); the
5 * crew page and the terminal's "Crew notes" are. Plain data, no storage.
6 */
7
8 import type { Database } from "bun:sqlite";
9 import { listEveryRepo, type Repo } from "../core/repos.ts";
10 import type { DrillResult } from "../snapshot/drill.ts";
11 import { lastDrill } from "../snapshot/drills.ts";
12 import { parkedTwice } from "./parks.ts";
13
14 /** One hand-over, with where to find the issue. */
15 export interface HandedNote {
16 readonly repo: Repo;
17 readonly number: number;
18 readonly title: string;
19 readonly reasons: readonly string[];
20 readonly at: string;
21 }
22
23 export interface CrewNotes {
24 /** Newest first. */
25 readonly handed: readonly HandedNote[];
26 readonly drill: DrillResult | undefined;
27 }
28
29 export function crewNotes(db: Database): CrewNotes {
30 const repos = listEveryRepo(db);
31 const byId = new Map(repos.map((r) => [r.id, r]));
32 const handed: HandedNote[] = [];
33 for (const issue of parkedTwice(db, repos)) {
34 const repo = byId.get(issue.repoId);
35 if (repo === undefined) continue;
36 handed.push({
37 repo,
38 number: issue.number,
39 title: issue.title,
40 reasons: issue.reasons,
41 at: issue.at,
42 });
43 }
44 handed.sort((a, b) => (a.at < b.at ? 1 : a.at > b.at ? -1 : 0));
45 return { handed, drill: lastDrill(db) };
46 }
src/tui/forge.ts +9
@@ -49,6 +49,7 @@ import { accessScreen } from "./screens/access.ts";
4949 import { mayEditTrustedHosts } from "../origins/trusted-hosts.ts";
5050 import { trustedHostsPrompt } from "./screens/trustedhosts.ts";
5151 import { flagsScreen } from "./screens/flags.ts";
52 import { crewNotesScreen } from "./screens/crewnotes.ts";
5253 import { scorecardScreen } from "./screens/scorecard.ts";
5354 import { cloudScreen } from "./screens/cloud.ts";
5455 import { crewSplitsScreen } from "./screens/crewsplits.ts";
@@ -405,6 +406,14 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] {
405406 hint: "each agent's pulls landed, review rounds, red checks, reverts, time to land",
406407 run: () => ctx.push(scorecardScreen(session, ctx)),
407408 });
409 // Settings → Crew's hand-overs and last drill, as the page has them: a forge admin (#3819).
410 if (session.user?.isAdmin === true)
411 commands.push({
412 id: "crew-notes",
413 title: "Crew notes",
414 hint: "issues the crew parked twice, and the last restore drill",
415 run: () => ctx.push(crewNotesScreen(session, ctx)),
416 });
408417 // Proposal tokens for a repository you write, as the API and MCP have them (#2148).
409418 if (session.user !== undefined)
410419 commands.push({
src/tui/screens/crewnotes.ts added +54
@@ -0,0 +1,54 @@
1 /**

Fine as a door, but the board's terminal/web copies of these notes remain; the issue asked to take them off the board.

2 * What the crew keeps to itself, in the terminal (#3819): each issue it
3 * parked twice and handed to the planner, then the last restore drill, as
4 * Settings → Crew shows them (`crew/notes.ts`). The gate is the page's: a
5 * forge admin; anyone else sees nothing.
6 */
7
8 import { crewNotes } from "../../crew/notes.ts";
9 import type { Ctx, Screen } from "../app/app.ts";
10 import { binding } from "../app/keys.ts";
11 import { style } from "../term/style.ts";
12 import { truncate } from "../term/width.ts";
13 import type { Session } from "../session.ts";
14 import { fill, len, split } from "../ui/layout.ts";
15 import { ListState, drawList, type ListRow } from "./common.ts";
16
17 export function crewNotesScreen(f: Session, ctx: Ctx): Screen {
18 const state = new ListState();
19 const allowed = f.user?.isAdmin === true;
20 const notes = allowed ? crewNotes(f.db) : undefined;
21 const rows: ListRow[] = [];
22 for (const n of notes?.handed ?? [])
23 rows.push({
24 title: `${n.repo.name} #${n.number} ${n.title}`,
25 secondary: `with the planner: ${n.reasons.join(" · ")}`,
26 });
27 const d = notes?.drill;
28 if (d !== undefined) {
29 rows.push(
30 d.verdict === "green"
31 ? { title: "Restore drill", tone: "success", secondary: `passed ${d.at}` }
32 : {
33 title: "Restore drill",
34 tone: "danger",
35 secondary: `failed at ${d.failedStep ?? "an unknown step"} ${d.at}`,
36 meta: d.reason ?? "",
37 },
38 );
39 }
40 return {
41 title: "Crew notes",
42 keys: [binding(["j", "k"], "move cursor")],
43 render(area, s) {
44 const c = ctx.theme.c;
45 const [head, list] = split(area, "v", [len(1), fill(1)]);
46 const text = !allowed
47 ? "The crew's notes are read by a forge admin."
48 : "Issues the crew parked twice and the last restore drill, as Settings → Crew shows them.";
49 s.text(head!.x, head!.y, truncate(text, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w);
50 drawList(s, list!, c, state, rows);
51 },
52 key: (e) => state.key(e, rows.length),
53 };
54 }
src/web/pages/crew-notes.ts added +52
@@ -0,0 +1,52 @@
1 /**
2 * The crew's own business, on the crew page: each issue the crew parked
3 * twice and handed to the planner, and the last restore drill — one line
4 * each. The owner's board carries neither (#3819); `crew/notes.ts` reads
5 * them for this page and for the terminal.
6 */
7
8 import { truncateAtWord } from "../../crew/autonomy.ts";
9 import { crewNotes as readNotes } from "../../crew/notes.ts";
10 import type { Ctx } from "../../http/context.ts";
11 import { repoBase } from "../chrome.ts";
12 import { html, type Html } from "../html.ts";
13 import { dot, listCard, row, time } from "../ui.ts";
14
15 const TITLE_MAX = 64;
16 const REASON_MAX = 96;
17
18 /** Each card for the crew page; a card with nothing to say is not drawn. */
19 export function crewNotes(ctx: Ctx): Html {
20 const { handed, drill } = readNotes(ctx.app.db);
21 const handedCard =
22 handed.length === 0
23 ? html``

Hand-rolled <h2 class="mb"> heading instead of a design-system card head; match the other crew cards (same for the Restore drill heading below).

24 : html`<h2 class="mb">Handed to the planner</h2>
25 <div id="crew-handed">${listCard(handed.map((n) =>
outdated

Return nothing from this section when handed is empty. An empty-state card is a zero drawn (docs/DESIGN.md).

26 row({
27 href: `${repoBase(n.repo)}/issues/${n.number}`,
28 title: `${n.repo.name} #${n.number} ${truncateAtWord(n.title, TITLE_MAX)}`,
29 meta: html`${n.reasons.map((r) => truncateAtWord(r, REASON_MAX)).join(" · ")}`,
30 trail: time(n.at),
31 data: { parked: "" },
32 }),
33 ))}</div>`;
34 const drillCard =
35 drill === undefined
outdated

Same for the drill: with no drill, draw no card. This row, and the data-drill="none" copy, should go.

36 ? html``
37 : html`<h2 class="mb">Restore drill</h2>
38 <div id="crew-drill">${listCard([
39 row({
40 href: "/settings/backups",
41 lead: dot(drill.verdict === "green" ? "success" : "danger"),
42 title:
43 drill.verdict === "green"
44 ? `Restore drill passed: snapshot ${drill.snapshotId ?? ""}, ${drill.ms} ms`
45 : `Restore drill failed at ${drill.failedStep ?? "an unknown step"}`,
46 ...(drill.verdict === "red" && drill.reason ? { meta: html`${drill.reason}` } : {}),
47 trail: time(drill.at),
48 data: { drill: drill.verdict },
49 }),
50 ])}</div>`;
51 return html`${handedCard}${drillCard}`;
52 }
src/web/pages/crew.ts +2
@@ -57,6 +57,7 @@ import {
5757 selectField,
5858 userLink,
5959 } from "../ui.ts";
60 import { crewNotes } from "./crew-notes.ts";
6061 import { accountSections } from "./origins.ts";
6162 import { markOf } from "../../core/marks.ts";
6263 import { limitValue } from "../../settings/limits.ts";
@@ -465,6 +466,7 @@ function crewView(
465466 const usernameError =
466467 error !== undefined && /username/i.test(error) ? error : undefined;
467468 return html`${crewReadiness(ctx)}
469 ${crewNotes(ctx)}
468470 ${when(spending.length > 0, () =>
469471 spendingCard(spending, ctx.app.config.crewCeilingUsd),
470472 )}
test/crew-notes.test.ts added +128
@@ -0,0 +1,128 @@
1 /**
2 * The crew page and the terminal carry what the owner's board does not:
3 * each issue the crew parked twice and handed to the planner, and the last
4 * drill (#3819). A forge admin's only, in both doors.
5 */
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { createForgeApp } from "../src/tui/forge.ts";
8 import { headlessTerminal } from "../src/tui/term/terminal.ts";
9 import { createSession } from "../src/core/sessions.ts";
10 import { createUser, getUserByName } from "../src/core/users.ts";
11 import { recordDrill } from "../src/snapshot/drills.ts";
12 import { quietLogs } from "./helpers/globals.ts";
13 import { settleApp } from "./helpers/tui.ts";
14 import { engine, tick, type Engine } from "./helpers/parks-engine.ts";
15
16 quietLogs();
17
18 const drill = (verdict: "green" | "red", reason: string | null) => ({
19 at: new Date().toISOString(),
20 snapshotId: "snap1",
21 ms: 12,
22 counts: { repositories: 1, issues: 1, users: 1, pulls: 0, apps: 0 },
23 health: verdict === "green" ? ("ok" as const) : ("unreached" as const),
24 verdict,
25 failedStep: verdict === "red" ? ("open" as const) : null,
26 reason,
27 phases: [],
28 budgetMs: 0,
29 });
30
31 describe("the crew's notes", () => {
32 let e: Engine;
33 let cookie = "";
34 let bobCookie = "";
35 const get = (c: string) => fetch(`${e.servers.url}/settings/crew`, { headers: { cookie: c } });
36
37 function terminal(username: string) {
38 const user = getUserByName(e.app.db, username)!;
39 const { app } = createForgeApp(
40 e.app,
41 { sshUsername: "t", remoteAddress: "127.0.0.1", user },
42 { terminal: headlessTerminal(140, 32), exitHooks: false },
43 );
44 app.start();
45 const key = (k: string, ctrl = false) =>
46 app.dispatch({ type: "key", key: k, ctrl, alt: false, shift: false });
47 return {
48 async open() {
49 key("k", true);
50 for (const ch of "Crew notes") key(ch);
51 await settleApp(app);
52 key("enter");
53 await settleApp(app);
54 return app.screen.toText();
55 },
56 stop: () => app.stop(),
57 };
58 }
59
60 beforeAll(async () => {
61 e = await engine("forge-crew-notes-");
62 e.app.db.query("UPDATE user SET is_admin = 1 WHERE id = ?1").run(e.alice.id);
63 cookie = `forge_session=${createSession(e.app.db, e.alice.id).token}`;
64 const bob = await createUser(e.app.db, {
65 origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase",
66 });
67 if (!bob.ok) throw new Error(bob.error);
68 bobCookie = `forge_session=${createSession(e.app.db, bob.value.id).token}`;
69 });
70 afterAll(() => e.close());
71
72 test("nothing parked and no drill draws no card, on the page or in the terminal", async () => {
73 const body = await (await get(cookie)).text();
74 for (const absent of ["Handed to the planner", "Restore drill", 'id="crew-handed"', 'id="crew-drill"', "data-drill", "nothing waits"])
75 expect(body).not.toContain(absent);
76 const t = terminal("alice");
77 const text = await t.open();
78 expect(text).not.toContain("none has run yet");
79 expect(text).not.toContain("Restore drill");
80 t.stop();
81 });
82
83 test("a hand-over is one line with its reasons and a link, in both doors; a green drill passes", async () => {
84 const work = e.issue("Scene graph");
85 e.ended(work, "no changes pushed: DECLINED: out of <scope>");
86 await tick();
87 e.ended(work, "nothing to propose");
88 await tick();
89 recordDrill(e.app.db, drill("green", null));
90 const body = await (await get(cookie)).text();
91 expect(body).toContain(`/alice/engine/issues/${work.number}`);
92 expect(body).toContain("out of &lt;scope&gt;");
93 expect(body).not.toContain("out of <scope>");
94 expect(body).toContain('data-drill="green"');
95 expect(body).toContain("Restore drill passed");
96 const t = terminal("alice");
97 const text = await t.open();
98 expect(text).toContain(`engine #${work.number} Scene graph`);
99 expect(text).toContain("out of <scope>");
100 expect(text).toContain("Restore drill");
101 expect(text).toContain("passed");
102 t.stop();
103 });
104
105 test("a failed drill shows its step and why", async () => {
106 recordDrill(e.app.db, drill("red", "key would not open"));
107 const body = await (await get(cookie)).text();
108 expect(body).toContain('data-drill="red"');
109 expect(body).toContain("failed at open");
110 expect(body).toContain("key would not open");
111 const t = terminal("alice");
112 const text = await t.open();
113 expect(text).toContain("failed at open");
114 t.stop();
115 });
116
117 test("a person who is not an admin sees nothing, on the page or in the terminal", async () => {
118 expect((await get(bobCookie)).status).toBe(404);
119 const guest = await fetch(`${e.servers.url}/settings/crew`, { redirect: "manual" });
120 expect(guest.status).not.toBe(200);
121 expect(await guest.text()).not.toContain("Scene graph");
122 const t = terminal("bob");
123 const text = await t.open();
124 expect(text).not.toContain("Scene graph");
125 expect(text).not.toContain("Restore drill");
126 t.stop();
127 });
128 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs