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

A forge link's page shows its crew working right now: the last three runs of the new forge, with no sign-in #13694

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13666-a-forge-link-s-page-shows-its-crew-worki → main 9 commits fork 8 threads · 8 unresolved

  • Merged. scout/13666-a-forge-link-s-page-shows-its-crew-worki was merged into main as 8933aa5.

Review

Sign in to review this change.
23 files changed +471 −61
docs/features/README.md +1
@@ -18,6 +18,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md).
1818
1919 - [A forge made from a template says so on its home](started-from.md)
2020 - [First week: three steps on a new forge's home](first-week.md)
21 - [The crew on a forge link's page](crew-now.md)
2122 - [A hosted forge proposes to its parent once the parent has handed it a credential](propose-to-parent.md)
2223 - [How long the last forge from a template took, at /templates/<name>](template-timing.md)
2324 - [A look in the feed](feed-look.md)
docs/features/crew-now.md added +9
@@ -0,0 +1,9 @@
1 # The crew on a forge link's page
2
3 The page a forge link opens (`/claim`, and `/welcome` on a forge's first account) ends with the crew at work: up to three agent runs, the ones waiting or working first, then the latest finished. Each row says what the run is for (its issue's title, else its summary), who ran it and on which repository, and its state in plain words: waiting to start, working now, finished, stopped with a problem, or cancelled. Before any run exists it says the crew is starting. No sign-in is needed.
4
5 Only public repositories are read: the page is open to anyone holding the link, so a private repository's name and work never reach it. The read is one statement of five bounded, indexed lookups, so it costs the same however many runs are stored. Nothing is stored.
6
7 In the terminal, the palette's **Your crew's latest work** shows the same three runs in the same words.
8
9 Code: `src/core/crew_now.ts` (the read and the words), `src/web/crew_now.ts` (the section), `src/tui/screens/crew_now.ts` (the screen). Test: `test/link-crew-now.test.ts`.
src/actions/proposals.ts +3 −1
@@ -40,7 +40,9 @@ function errorWords(e: unknown): string {
4040 return typeof m === "string" ? m : "it was refused";
4141 }
4242
43 /** The proposal and its repository, when this person is who it asks and it is in one of `states`. */
43 /**
44 * The proposal and its repository, when this person is who it asks and it is in one of `states`.
45 */
4446 function mine(
4547 app: App,
4648 actor: User | undefined,
src/core/crew_now.ts added +79
@@ -0,0 +1,79 @@
1 /**
2 * What the crew of this forge is doing right now, for the page a forge link opens: up to three
3 * agent runs, live ones first, then the latest finished, each with who ran it and what it was
4 * for. Read from the forge's own stored runs; nothing is stored and nothing of any other forge
5 * is read.
6 */
7
8 import type { Database } from "bun:sqlite";
9
10 export const CREW_NOW_MAX = 3;
11
12 export interface CrewRun {
13 readonly who: string;
14 readonly what: string;
15 readonly repo: string;
16 readonly state: "queued" | "running" | "ok" | "failed" | "cancelled";
17 }
18
19 /** The state in plain words, the same on the page and in the terminal. */
20 export const STATE_WORDS: Record<CrewRun["state"], string> = {
21 queued: "waiting to start",
22 running: "working now",
23 ok: "finished",
24 failed: "stopped with a problem",
25 cancelled: "cancelled",
26 };
27
28 /** What shows when no public run exists yet. */
29 export const CREW_STARTING = "Your crew is starting, and its first public work shows here.";
30
31 interface Row {
32 id: string;
33 username: string | null;
34 title: string | null;
35 summary: string;
36 reason: string;
37 repo: string;
38 state: CrewRun["state"];
39 }
40
41 const clip = (s: string, n: number): string => {
42 const one = s.replace(/\s+/g, " ").trim();
43 return one.length > n ? `${one.slice(0, n - 1)}…` : one;
outdated

Clean: this comment sits above STATES but describes the whole query. Move it onto ALL.

44 };
45
outdated

HIGH (private data leaks across users): no filter on repo visibility. This runs for anonymous visitors and returns private repo names, issue titles and summaries. Join on repo visibility and show only public ones.

46 const STATES = ["running", "queued", "ok", "failed", "cancelled"] as const;
outdated

MEDIUM (DoS): ORDER BY on a computed expression scans and sorts every agent run on each unauthenticated request. Use two indexed, LIMITed queries (live, then latest finished) and merge them.

47
48 const BY_STATE = (n: number): string => `SELECT r.id AS id, u.username AS username, i.title AS title, r.summary AS summary,
49 r.reason AS reason, p.name AS repo, r.state AS state
50 FROM run r
51 JOIN repo p ON p.id = r.repo_id AND p.visibility = 'public'
52 LEFT JOIN user u ON u.id = r.actor_id
53 LEFT JOIN issue i ON i.id = r.issue_id
54 WHERE r.kind = 'agent' AND r.state = ?${n}
55 ORDER BY r.id DESC
56 LIMIT ?6`;
57
58 /**
59 * Only public repositories are shown: this runs for anyone who holds the link, so a private
outdated

live is defined above and recomputed here; use live(r).

60 * repository's name, issue title and summary never reach it. Each state is read through the
61 * (kind, state) index, newest first, three rows at most, so the cost does not grow with the
62 * number of runs: one statement, five LIMITed reads, merged here.
63 */
64 const ALL = STATES.map((_, i) => `SELECT * FROM (${BY_STATE(i + 1)})`).join(" UNION ALL ");
65
66 const live = (r: Row): boolean => r.state === "running" || r.state === "queued";
67
68 export function crewNow(db: Database): readonly CrewRun[] {
69 const found = db.query<Row, (string | number)[]>(ALL).all(...STATES, CREW_NOW_MAX);
70 const rows = found
71 .sort((a, b) => Number(live(b)) - Number(live(a)) || (a.id < b.id ? 1 : a.id > b.id ? -1 : 0))
72 .slice(0, CREW_NOW_MAX);
73 return rows.map((r) => ({
74 who: r.username ?? "the crew",
75 what: clip(r.title || r.summary || r.reason || "working", 100),
76 repo: r.repo,
77 state: r.state,
78 }));
79 }
src/core/dep_standing.ts +4 −1
@@ -286,7 +286,10 @@ export function blockerByTitle(
286286 return { says: `${found.length > 5 ? "More than five" : found.length} issues match "${wanted}": ${found.slice(0, 5).map((i) => `#${i.number}`).join(", ")}. Type the number.` };
287287 }
288288
289 /** The chain as plain lines for the terminal: what it waits for (furthest back first), then what waits for it. */
289 /**
290 * The chain as plain lines for the terminal: what it waits for (furthest back first), then what
291 * waits for it.
292 */
290293 export function chainLines(s: Standing): string[] {
291294 const row = (lead: string, n: StandingNode): string =>
292295 `${lead} #${n.number} ${n.title} - ${n.word}${n.holding ? " · holding this" : ""}${n.next === "" ? "" : ` · next: ${n.next}`}`;
src/crew/autonomy.ts +21 −12
@@ -394,7 +394,9 @@ function meanRunUsd(db: App["db"], repoId: string): number {
394394 );
395395 }
396396
397 /** The issues each repository picked in this tick, by repository id: their runs may not show yet. */
397 /**
398 * The issues each repository picked in this tick, by repository id: their runs may not show yet.
399 */
398400 export type TickPicks = ReadonlyMap<string, ReadonlySet<string>>;
399401
400402 /**
@@ -649,10 +651,10 @@ export function startable(
649651
650652 /**
651653 * Give the planner the direction when the reserve is due a pass — down to
652 * half of two startable issues per builder slot (`reserve.ts`) — or when the crew has handed it an issue it parked twice,
653 * and no planning run is in flight, and the last one is old enough.
654 * Returns whether a planning run was set up. Planning runs alongside
655 * building: the builders are never waited for.
654 * half of two startable issues per builder slot (`reserve.ts`) — or when the crew has handed it an
655 * issue it parked twice, and no planning run is in flight, and the last one is old enough. Returns
656 * whether a planning run was set up. Planning runs alongside building: the builders are never
657 * waited for.
656658 *
657659 * A hand-over is owed one pass, not one a minute: it asks only while it is
658660 * newer than the last planning run. That one pass is owed even by a planner
@@ -1008,7 +1010,10 @@ export function parkForBreaker(
10081010 return true;
10091011 }
10101012
1011 /** How many times the crew has parked this issue since a person who directs it last spoke (`parks.ts`). */
1013 /**
1014 * How many times the crew has parked this issue since a person who directs it last spoke
1015 * (`parks.ts`).
1016 */
10121017 export function parkedCount(app: App, repo: Repo, issueId: string): number {
10131018 return countParks(app.db, repo, issueId);
10141019 }
@@ -1305,7 +1310,8 @@ export async function autonomyTick(
13051310 sweep: (app: App, repo: Repo) => Promise<number> = sweepGreen,
13061311 ): Promise<void> {
13071312 if (crewOffInPreview()) return;
1308 // A pull a person holds with changes requested goes back to its builder after a day of silence, in any repository.
1313 // A pull a person holds with changes requested goes back to its builder after a day of silence,
1314 // in any repository.
13091315 try {
13101316 sweepStranded(app, now);
13111317 } catch (error) {
@@ -1336,7 +1342,8 @@ export async function autonomyTick(
13361342 // the next batch is formed, not at its gate (#6611).
13371343 pruneLine(app, repo);
13381344 void startSweep(app, repo, sweep);
1339 // Each pass below is one slice of the thread: a request waiting is served between them (#8848).
1345 // Each pass below is one slice of the thread: a request waiting is served between them
1346 // (#8848).
13401347 await breathe();
13411348 // First of all: a slot freed goes to an approved pull that no longer
13421349 // merges, before a changes-requested one or a new issue (#3682).
@@ -1432,7 +1439,8 @@ export async function autonomyTick(
14321439 // The standing reserve the planner keeps: startable/target (#3237).
14331440 reserve: reserveWords(reserveOf(held.startable.length, status.slots)),
14341441 held: heldWords(held),
1435 // What the picker passes over among the startable, so no ready issue goes unexplained (#8924).
1442 // What the picker passes over among the startable, so no ready issue goes unexplained
1443 // (#8924).
14361444 passed: passedWords(pickFilter(app, current, held.startable, now).passed),
14371445 // The files 5 or more open pulls touch, which no new build starts on (#5934).
14381446 ...(held.by.hot_file.length === 0 ? {} : { hot: hotWords(hotFiles(current.id)) }),
@@ -1448,8 +1456,8 @@ export async function autonomyTick(
14481456 idle: idleBuilders(activeNow, crewNow),
14491457 ...(governor === undefined ? {} : { governor }),
14501458 // Approved conflicted pulls: queued, in flight, and why each other is
1451 // skipped (#3682, #6237), or "0 candidates of N open" (#6263); and the lane for rebases: conflicted N,
1452 // rebasing M, room R (#6140).
1459 // skipped (#3682, #6237), or "0 candidates of N open" (#6263); and the lane for rebases:
1460 // conflicted N, rebasing M, room R (#6140).
14531461 ...finishFields(finishing.moves, readConflictLane(app.db), finishing.open),
14541462 ...(requested.length === 0
14551463 ? {}
@@ -2256,7 +2264,8 @@ async function admit(
22562264 if (!again) addComment(app, by, repo, getIssueById(app.db, pull.id) ?? pull, clashSaid(red.comment, together));
22572265 // A red that reproduces on the re-gate is the code's: only then is it the doctor's to hold.
22582266 if (again) treatRed(app, repo, by, pull, red, baseOid);
2259 // Red only on top of pulls that landed first: no single culprit yet, so the class is recorded and the re-gate alone decides.
2267 // Red only on top of pulls that landed first: no single culprit yet, so the class is recorded
2268 // and the re-gate alone decides.
22602269 else noteRed(app, repo, pull, red, baseOid, together);
22612270 },
22622271 });
src/crew/held.ts +16 −4
@@ -98,7 +98,10 @@ export interface Held {
9898 readonly by: Readonly<Record<HoldName, readonly Issue[]>>;
9999 /** Of the `hot_file` ones, those an admin's hold keeps: issue number to the hold that does. */
100100 readonly pinned: ReadonlyMap<number, FileHold>;
101 /** Of the `hot_file` ones, those that wait because another issue already relieves the same path: issue number to that path and issue. */
101 /**
102 * Of the `hot_file` ones, those that wait because another issue already relieves the same path:
103 * issue number to that path and issue.
104 */
102105 readonly relieving: ReadonlyMap<number, { path: string; by: number }>;
103106 /** Of the `twin` ones: issue number to the twin that holds the same work. */
104107 readonly twins: ReadonlyMap<number, Twin>;
@@ -110,7 +113,10 @@ export interface LastRun {
110113 readonly created_at: string;
111114 }
112115
113 /** The newest agent run of each of `ids` in a few reads, not one per issue; an issue never run is absent. */
116 /**
117 * The newest agent run of each of `ids` in a few reads, not one per issue; an issue never run is
118 * absent.
119 */
114120 export function lastAgentRuns(app: App, ids: readonly string[]): Map<string, LastRun> {
115121 const out = new Map<string, LastRun>();
116122 const CHUNK = 400;
@@ -415,7 +421,10 @@ export function mapHolds(
415421 return { holds, startable: held.startable.map((r) => r.issue.number) };
416422 }
417423
418 /** The pulls a viewer of `scope` may see: all with the sealed scope, else the unsealed and their own. */
424 /**
425 * The pulls a viewer of `scope` may see: all with the sealed scope, else the unsealed and their
426 * own.
427 */
419428 export function admits(app: App, repo: Repo, scope: { sealed?: true; sealedBy?: string }) {
420429 if (scope.sealed === true) return () => true;
421430 return (n: number): boolean => {
@@ -424,7 +433,10 @@ export function admits(app: App, repo: Repo, scope: { sealed?: true; sealedBy?:
424433 };
425434 }
426435
427 /** How long a viewer's map holds are reused by the next reader of the same repository. Off under `bun test`. */
436 /**
437 * How long a viewer's map holds are reused by the next reader of the same repository. Off under
438 * `bun test`.
439 */
428440 export const mapHeldReuse = { ms: process.env["NODE_ENV"] === "test" ? 0 : 5_000 };
429441 const mapHeldKept = new WeakMap<App, Map<string, { at: number; holds: ReturnType<typeof mapHolds> }>>();
430442
src/flow/alarms.ts +4 −1
@@ -51,7 +51,10 @@ export const FORGE_BROKEN: ReadonlySet<FiredAlarm["key"]> = new Set(["red_main",
5151 export function firedAlarms(
5252 db: Database,
5353 now: Date,
54 /** `dataDir` is required so a caller cannot forget it and lose the backup alarm; `null` says there is none to read (a unit over a bare db). */
54 /**
55 * `dataDir` is required so a caller cannot forget it and lose the backup alarm; `null` says there
56 * is none to read (a unit over a bare db).
57 */
5558 opts: { readonly dataDir: string | null; readonly publicOnly?: boolean; readonly ceilingUsd?: number | null },
5659 ): FiredAlarm[] {
5760 const out: FiredAlarm[] = [];
src/flow/lanes_read.ts +51 −16
@@ -52,14 +52,19 @@ export const MOVED_MS = 30 * 60_000;
5252 export const SLOW_MS = 30_000;
5353
5454 export interface LaneItem {
55 /** Stable across lanes: the same change keeps its key as it moves, so the page can move its tile. */
55 /**
56 * Stable across lanes: the same change keeps its key as it moves, so the page can move its tile.
57 */
5658 readonly key: string;
5759 readonly repoId: string;
5860 readonly kind: "issue" | "pull" | "main" | "deploy";
5961 readonly number: number | null;
6062 readonly title: string;
6163 readonly sealed: boolean;
62 /** Who has it: the crew member, the reviewer, the person who asked or merged. Empty when no one does. */
64 /**
65 * Who has it: the crew member, the reviewer, the person who asked or merged. Empty when no one
66 * does.
67 */
6368 readonly who: string;
6469 /** When it entered this lane. */
6570 readonly since: string;
@@ -71,7 +76,10 @@ export interface LaneItem {
7176 readonly position: number | null;
7277 /** When its worker last said it was alive; null when it does not say. */
7378 readonly beat: string | null;
74 /** The issue or pull this is, for an action over it (`fleet/verbs.ts`); null for a check of main and a deploy. */
79 /**
80 * The issue or pull this is, for an action over it (`fleet/verbs.ts`); null for a check of main
81 * and a deploy.
82 */
7583 readonly issueId: string | null;
7684 /** When the issue or pull was opened; null where there is none. */
7785 readonly born: string | null;
@@ -95,7 +103,10 @@ export interface StripPart {
95103 readonly usedPct: number;
96104 readonly mayUsePct: number;
97105 } | null;
98 /** The crew's spend over seven days at list price, for the forge's own estimate when the provider has not reported. */
106 /**
107 * The crew's spend over seven days at list price, for the forge's own estimate when the provider
108 * has not reported.
109 */
99110 readonly weekSpendUsd: number;
100111 readonly ceilingUsd: number | null;
101112 readonly needs: readonly { readonly says: string; readonly href: string }[];
@@ -117,7 +128,10 @@ export interface LanePicture {
117128 readonly asks: Readonly<Record<string, AsksWaiting>>;
118129 /** The home's figures; null until the slow part has been read. */
119130 readonly figures: Figures | null;
120 /** Why no builder is starting anything, when something names it (the day's ceiling, no subscription with room, nothing ready); null otherwise. */
131 /**
132 * Why no builder is starting anything, when something names it (the day's ceiling, no
133 * subscription with room, nothing ready); null otherwise.
134 */
121135 readonly idle: IdleReason | null;
122136 }
123137
@@ -223,7 +237,10 @@ function item(
223237 };
224238 }
225239
226 /** Runs of one kind in flight, running first and then by age; a queued run paused on a limit is not waiting for a worker. */
240 /**
241 * Runs of one kind in flight, running first and then by age; a queued run paused on a limit is not
242 * waiting for a worker.
243 */
227244 function runRows(
228245 db: Database,
229246 kind: "agent" | "check",
@@ -342,9 +359,10 @@ interface Deploy {
342359 /**
343360 * Production deploys going live now and those that went live in the last 24
344361 * hours, newest first. Only the ids and times come from the run table, and
345 * only through its own two small indexes (`run_live`, `run_queue`), named (`INDEXED BY`) because the planner picks `run_kind_state` and walks every deploy: the
346 * deploy ledger (`deploy_pull`) is never counted or sorted, because a deploy
347 * lists every change it carries and production's holds ten million rows.
362 * only through its own two small indexes (`run_live`, `run_queue`), named (`INDEXED BY`) because
363 * the planner picks `run_kind_state` and walks every deploy: the deploy ledger (`deploy_pull`) is
364 * never counted or sorted, because a deploy lists every change it carries and production's holds
365 * ten million rows.
348366 */
349367 function deploys(
350368 db: Database,
@@ -473,12 +491,14 @@ function live(db: Database, dayAgo: string): LaneRead {
473491 const { rows, total } = deploys(db, dayAgo);
474492 const seen = new Set<string>();
475493 const items: LaneItem[] = [];
476 // Enough to list; the carried-change lookup is a few rows each, so it is bounded to what a lane draws.
494 // Enough to list; the carried-change lookup is a few rows each, so it is bounded to what a lane
495 // draws.
477496 for (const d of rows) {
478497 if (items.length >= LANE_ITEMS + 3) break;
479498 const going = d.state === "queued" || d.state === "running";
480499 const change = carried(db, d.repo_id, d.at);
481 // A tile is the change it put live, keyed as the change (so Landing's tile arrives here); a deploy that names none is keyed by itself.
500 // A tile is the change it put live, keyed as the change (so Landing's tile arrives here); a
501 // deploy that names none is keyed by itself.
482502 const key = `i-${change?.id ?? d.id}`;
483503 if (seen.has(key)) continue;
484504 seen.add(key);
@@ -515,7 +535,10 @@ export interface Fast {
515535 readonly working: ReadonlySet<string>;
516536 }
517537
518 /** The fast part: running and queued work, approved and merged pulls, deploys. A few indexed reads, each bounded. */
538 /**
539 * The fast part: running and queued work, approved and merged pulls, deploys. A few indexed reads,
540 * each bounded.
541 */
519542 export function readFast(db: Database, now: Date): Fast {
520543 const iso = now.toISOString();
521544 const week = new Date(now.getTime() - 7 * 86_400_000).toISOString();
@@ -596,7 +619,10 @@ export function withWaits(
596619 }
597620
598621 export interface Slow {
599 /** The crew's next asks in its own order, a few more than a lane draws so a build starting leaves the lane full. */
622 /**
623 * The crew's next asks in its own order, a few more than a lane draws so a build starting leaves
624 * the lane full.
625 */
600626 readonly asked: readonly LaneItem[];
601627 readonly askedTotal: number;
602628 readonly strip: StripPart;
@@ -706,7 +732,10 @@ export function readSlow(
706732 };
707733 }
708734
709 /** Why the builders sit idle, from the same module the dispatcher is asked in; `app` is the database and the data directory, the two things it reads. */
735 /**
736 * Why the builders sit idle, from the same module the dispatcher is asked in; `app` is the database
737 * and the data directory, the two things it reads.
738 */
710739 function idleOf(db: Database, dataDir: string, now: Date): IdleReason | null {
711740 try {
712741 return idleReason({ db, config: { dataDir } } as unknown as App, now);
@@ -715,7 +744,10 @@ function idleOf(db: Database, dataDir: string, now: Date): IdleReason | null {
715744 }
716745 }
717746
718 /** What waits on each viewer: the same set `/review` draws (`reviewSetOf`), counted per person the worker was told of. */
747 /**
748 * What waits on each viewer: the same set `/review` draws (`reviewSetOf`), counted per person the
749 * worker was told of.
750 */
719751 function asksOf(db: Database, viewers: readonly string[], now: Date): Record<string, AsksWaiting> {
720752 const out: Record<string, AsksWaiting> = {};
721753 for (const id of viewers) {
@@ -730,7 +762,10 @@ function asksOf(db: Database, viewers: readonly string[], now: Date): Record<str
730762 return out;
731763 }
732764
733 /** A short hash of what a lane shows: its items without the heartbeat, which moves every few seconds and is no change. */
765 /**
766 * A short hash of what a lane shows: its items without the heartbeat, which moves every few seconds
767 * and is no change.
768 */
734769 function versionOf(read: LaneRead): string {
735770 return Bun.hash(
736771 JSON.stringify([
src/snapshot/sealed_store.ts +30 −8
@@ -34,7 +34,10 @@ export const SEALED_PREFIX = "sealed/";
3434 const MAGIC = Buffer.from("FSO1");
3535 const IV_BYTES = 12;
3636 const TAG_BYTES = 16;
37 /** The lane's header, beside the sealed objects and unsealed: the salt and a check value, never the key. */
37 /**
38 * The lane's header, beside the sealed objects and unsealed: the salt and a check value, never the
39 * key.
40 */
3841 export const LANE_HEADER = `${SEALED_PREFIX}lane.json`;
3942 const SALT_BYTES = 16;
4043 const SALT_HEX = /^[0-9a-f]{32}$/;
@@ -49,7 +52,10 @@ export interface SealKeys {
4952 readonly mac: Buffer;
5053 }
5154
52 /** The two keys a passphrase gives under a lane's salt: one seals bodies, one hides names. One scrypt, about 100 ms, off the main thread. */
55 /**
56 * The two keys a passphrase gives under a lane's salt: one seals bodies, one hides names. One
57 * scrypt, about 100 ms, off the main thread.
58 */
5359 export function sealKeys(passphrase: string, salt: Uint8Array): Promise<SealKeys> {
5460 return new Promise((resolve, reject) => {
5561 scrypt(passphrase, salt, 64, SCRYPT, (error, k) => {
@@ -59,7 +65,10 @@ export function sealKeys(passphrase: string, salt: Uint8Array): Promise<SealKeys
5965 });
6066 }
6167
62 /** What the header keeps to tell the right passphrase from a wrong one; an HMAC, so it gives no shortcut past scrypt. */
68 /**
69 * What the header keeps to tell the right passphrase from a wrong one; an HMAC, so it gives no
70 * shortcut past scrypt.
71 */
6372 const checkOf = (keys: SealKeys): string => createHmac("sha256", keys.mac).update("forge off-site lane header").digest("hex");
6473
6574 /** A header's salt and check, or a sentence when the object is not one the lane wrote. */
@@ -103,7 +112,10 @@ export function sealBody(keys: SealKeys, body: Uint8Array | string): Uint8Array
103112 return Buffer.concat([MAGIC, iv, cipher.update(plain), cipher.final(), cipher.getAuthTag()]);
104113 }
105114
106 /** The plain body; throws, naming the key, when the passphrase is wrong or the object is not one the lane sealed. */
115 /**
116 * The plain body; throws, naming the key, when the passphrase is wrong or the object is not one the
117 * lane sealed.
118 */
107119 export function openBody(keys: SealKeys, sealed: Uint8Array, key: string): Uint8Array {
108120 const b = Buffer.from(sealed.buffer, sealed.byteOffset, sealed.byteLength);
109121 if (b.length < MAGIC.length + IV_BYTES + TAG_BYTES || !b.subarray(0, MAGIC.length).equals(MAGIC))
@@ -130,14 +142,21 @@ export function hiddenKey(keys: SealKeys, key: string): string {
130142 }
131143
132144 export interface SealedOptions {
133 /** Whether a lane with no header yet starts one (the mirror pass); a restore reads, so it does not. */
145 /**
146 * Whether a lane with no header yet starts one (the mirror pass); a restore reads, so it does
147 * not.
148 */
134149 readonly create?: boolean;
135150 }
136151
137 /** `inner`, every object sealed under `passphrase` and named so a path never shows. The keys are derived on first use. */
152 /**
153 * `inner`, every object sealed under `passphrase` and named so a path never shows. The keys are
154 * derived on first use.
155 */
138156 export function sealedStore(inner: Store, passphrase: string, options: SealedOptions = {}): Store {
139157 let pending: Promise<SealKeys> | undefined;
140 // One derivation for the store and every bounded view of it; a failed read of the header is tried again next time.
158 // One derivation for the store and every bounded view of it; a failed read of the header is tried
159 // again next time.
141160 const keys = (): Promise<SealKeys> =>
142161 (pending ??= laneKeys(inner, passphrase, options.create ?? true).catch((error: unknown) => {
143162 pending = undefined;
@@ -183,7 +202,10 @@ function over(inner: Store, keys: () => Promise<SealKeys>): Store {
183202 return bounded === undefined ? store : { ...store, bounded: (leftMs) => over(bounded.call(inner, leftMs), keys) };
184203 }
185204
186 /** A lane that may not write: every call fails with `reason`, so the board says why and nothing leaves unsealed. */
205 /**
206 * A lane that may not write: every call fails with `reason`, so the board says why and nothing
207 * leaves unsealed.
208 */
187209 export function refusingStore(where: string, reason: string): Store {
188210 const no = async (): Promise<never> => {
189211 throw new Error(reason);
src/snapshot/snapshot.ts +7 −2
@@ -184,7 +184,10 @@ export interface Progress {
184184 readonly etaMs?: number;
185185 }
186186
187 /** What a page shows beside "N objects, X so far": one label and value each; parts not known are left out. */
187 /**
188 * What a page shows beside "N objects, X so far": one label and value each; parts not known are
189 * left out.
190 */
188191 export function progressFacts(p: Progress): { label: string; value: string }[] {
189192 const rows: { label: string; value: string }[] = [];
190193 if (p.already !== undefined && p.seen !== undefined && p.seen > 0) rows.push({ label: "Already there", value: `${p.already} of ${p.seen} chunks` });
@@ -194,7 +197,9 @@ export function progressFacts(p: Progress): { label: string; value: string }[] {
194197 return rows;
195198 }
196199
197 /** Progress as a short sentence for the log and the terminal: what is sent, what is left, how long. */
200 /**
201 * Progress as a short sentence for the log and the terminal: what is sent, what is left, how long.
202 */
198203 export function progressWords(p: Progress): string {
199204 const parts = [`${fmtBytes(p.bytes)} sent`];
200205 if (p.toGoBytes !== undefined) parts.push(`${fmtBytes(p.toGoBytes)} left`);
src/snapshot/store.ts +11 −3
@@ -34,7 +34,9 @@ export interface Store {
3434 * this out.
3535 */
3636 storedKey?(key: string): Promise<string>;
37 /** True when every object is encrypted before it reaches the store (the off-site lane, #11805). */
37 /**
38 * True when every object is encrypted before it reaches the store (the off-site lane, #11805).
39 */
3840 readonly sealed?: boolean;
3941 /**
4042 * What the line is giving this store's puts (`line.ts`); a store that does not measure leaves it
@@ -102,12 +104,18 @@ export function s3FromEnv(
102104
103105 /** The slowest uplink a put may assume: 5 Mbit/s, a third of the home line it runs behind. */
104106 export const FLOOR_BYTES_PER_S = 5_000_000 / 8;
105 /** What every attempt gets on top of its bytes' time: the handshake, the server's thought, a queue ahead of it. */
107 /**
108 * What every attempt gets on top of its bytes' time: the handshake, the server's thought, a queue
109 * ahead of it.
110 */
106111 export const SLACK_MS = 60_000;
107112 /** How long a read, a listing or a delete may go unanswered. */
108113 export const CALL_DEADLINE_MS = 180_000;
109114
110 /** How long a put of `bytes` may take before it counts as failed: its bytes at the floor rate, plus slack. */
115 /**
116 * How long a put of `bytes` may take before it counts as failed: its bytes at the floor rate, plus
117 * slack.
118 */
111119 export const deadlineFor = (
112120 bytes: number,
113121 floorBytesPerS = FLOOR_BYTES_PER_S,
src/spawn/upstream.ts +2 −1
@@ -184,7 +184,8 @@ async function run(app: App, options: { remote?: string; now?: number }): Promis
184184 }
185185 }
186186 const repo = getRepo(app.db, o, n);
187 // Remember the tip before the card, so a crash between them can lose a card but never repeat one.
187 // Remember the tip before the card, so a crash between them can lose a card but never repeat
188 // one.
188189 const tell = repo !== undefined && link.mode === "tell-me" && state.error === "" && state.parentTip !== "" &&
189190 (state.behind ?? 0) > 0 && state.parentTip !== state.toldTip;
190191 if (tell) state = { ...state, toldTip: state.parentTip };
src/tui/forge.ts +2
@@ -19,6 +19,7 @@ import { sourceFor } from "../view/source.ts";
1919 import { fleetCommand } from "./screens/fleet.ts";
2020 import { dataCommand } from "./screens/data.ts";
2121 import { packsCommand } from "./screens/packs.ts";
22 import { crewNowCommand } from "./screens/crew_now.ts";
2223 import { statusCommand } from "./screens/status.ts";
2324 import { templatesCommand } from "./screens/templates.ts";
2425 import { needsCommands } from "./screens/needs.ts";
@@ -271,6 +272,7 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] {
271272 ...needsCommands(session, ctx),
272273 ...asksAdminCommands(session, ctx),
273274 packsCommand(session, ctx),
275 crewNowCommand(session, ctx),
274276 statusCommand(session, ctx),
275277 templatesCommand(session, ctx),
276278 shareTellCommand(session, ctx),
src/tui/screens/crew_now.ts added +38
@@ -0,0 +1,38 @@
1 /**
2 * The crew at work, in the terminal: the same up to three public runs a forge link's page shows
3 * (`core/crew_now.ts`), each as what, who on which repository, and its state in the page's words.
4 */
5
6 import { CREW_STARTING, crewNow, STATE_WORDS, type CrewRun } from "../../core/crew_now.ts";
7 import type { Ctx, Screen } from "../app/app.ts";
8 import { style } from "../term/style.ts";
9 import { wrap } from "../term/width.ts";
10 import type { Session } from "../session.ts";
11
12 /** The screen's lines, plain data: one block per run, or the starting line. */
13 export function crewNowLines(runs: readonly CrewRun[]): string[] {
14 if (runs.length === 0) return [CREW_STARTING];
15 return runs.flatMap((r) => [r.what, ` ${r.who} on ${r.repo}: ${STATE_WORDS[r.state]}`, ""]);
16 }
17
18 export function crewNowScreen(f: Session, ctx: Ctx, runs: readonly CrewRun[] = crewNow(f.app.db)): Screen {
19 const lines = crewNowLines(runs);
20 return {
21 title: "Your crew's latest work",
22 keys: [],
23 render(area, s) {
24 const c = ctx.theme.c;
25 const shown = lines.flatMap((l) => (l === "" ? [""] : wrap(l, Math.max(20, area.w - 2))));
26 shown.slice(0, area.h).forEach((l, i) => s.text(area.x + 1, area.y + i, l, style(c.fg, c.bg), area.x + area.w));
27 },
28 key: () => false,
29 };
30 }
31
32 /** Offered to everyone in `forgeCommands`, as the page shows it to anyone with the link. */
33 export const crewNowCommand = (session: Session, ctx: Ctx) => ({
34 id: "crew-now",
35 title: "Your crew's latest work",
36 hint: "the three runs a forge link's page shows",
37 run: () => ctx.push(crewNowScreen(session, ctx)),
38 });
src/tui/screens/resilience.ts +17 −5
@@ -66,7 +66,10 @@ export function resilienceLines(dataDir: string): string[] {
6666 /** How many of a nightly job's last lines the output dialog shows. */
6767 export const OUTPUT_TAIL = 12;
6868
69 /** Each nightly job's line and the tail of its newest output, as /resilience/nightly/<job> shows it whole. */
69 /**
70 * Each nightly job's line and the tail of its newest output, as /resilience/nightly/<job> shows it
71 * whole.
72 */
7073 export function nightlyOutputLines(dataDir: string): string[] {
7174 const said = nightlyLines(dataDir);
7275 return JOBS.flatMap((job, i) => {
@@ -103,7 +106,10 @@ export function mirrorLine(f: Session): string {
103106 return where === undefined ? "Mirror: none." : `Mirror: ${where}`;
104107 }
105108
106 /** The bucket's verdict, as home and the MCP's `backups` say it: the line, each lane's newest, what is wrong. */
109 /**
110 * The bucket's verdict, as home and the MCP's `backups` say it: the line, each lane's newest, what
111 * is wrong.
112 */
107113 export function verdictLines(f: Session): string[] {
108114 const v = backupVerdict(f.app.config.dataDir, lastDrill(f.app.db));
109115 const mark = v.state === "red" ? "RED" : v.state === "unknown" ? "unknown" : "ok";
@@ -157,7 +163,9 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen {
157163 const refusedAll = "Where snapshots go is a forge admin's.";
158164 // The actions refuse anyone else too; the keys are not offered to them.
159165 const mayAct = (): boolean => f.user?.isAdmin === true;
160 /** The newest snapshots, `unreadable` when the store could not be listed; undefined until read. */
166 /**
167 * The newest snapshots, `unreadable` when the store could not be listed; undefined until read.
168 */
161169 let snapshots: string[] | "unreadable" | undefined;
162170 let asking: Asking | undefined;
163171 // While an action runs, `n`, `l` and `r` are ignored: a second would queue behind it.
@@ -291,7 +299,8 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen {
291299 const out: string[] = [];
292300 if (asking !== undefined) out.push(QUESTION[asking], "");
293301 else if (said !== "") out.push(...wrap(said, INNER), "");
294 // A refusal or a result of a change stays up here too, above where a prompt opens over the middle.
302 // A refusal or a result of a change stays up here too, above where a prompt opens over the
303 // middle.
295304 if (note !== "") out.push(...wrap(note, INNER), "");
296305 out.push(...wrap(backupsLine(f.app).says, INNER), ...verdictLines(f), "");
297306 for (const line of nightlyLines(f.app.config.dataDir)) out.push(...wrap(line, INNER));
@@ -380,7 +389,10 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen {
380389 return screen;
381390 }
382391
383 /** Where snapshots go and each THREATS.md protection's standing, as /resilience says it: a site admin's; a person admin sets or forgets the destination and the mirror here. */
392 /**
393 * Where snapshots go and each THREATS.md protection's standing, as /resilience says it: a site
394 * admin's; a person admin sets or forgets the destination and the mirror here.
395 */
384396 export const entry: PaletteEntry = {
385397 id: "resilience",
386398 title: "Resilience",
src/web/crew_now.ts added +16
@@ -0,0 +1,16 @@
1 /**
2 * The crew at work, as the forge link's page shows it with no sign-in: up to three runs, who and
3 * what, or one honest line that the crew is starting. See `core/crew_now.ts`; the terminal's
4 * screen is `tui/screens/crew_now.ts` and reads the same words.
5 */
6
7 import { CREW_STARTING, STATE_WORDS, type CrewRun } from "../core/crew_now.ts";
8 import { html, type Html } from "./html.ts";
9
10 export function crewNowHtml(runs: readonly CrewRun[]): Html {
11 if (runs.length === 0)
12 return html`<section id="crew-now" class="mt" aria-label="The crew"><p class="small muted">${CREW_STARTING}</p></section>`;
13 return html`<section id="crew-now" class="mt" aria-label="The crew"><h2 class="small">Your crew's latest work</h2>
14 <ul class="list">${runs.map((r) => html`<li class="row"><span class="row-main"><span class="row-title">${r.what}</span>
15 <span class="row-meta">${r.who} on ${r.repo}</span></span><span class="row-trail muted small">${STATE_WORDS[r.state]}</span></li>`)}</ul></section>`;
16 }
src/web/pages/claim.ts +4
@@ -22,6 +22,8 @@
2222 * so before anyone submits, and where to remove it.
2323 */
2424
25 import { crewNow } from "../../core/crew_now.ts";
26 import { crewNowHtml } from "../crew_now.ts";
2527 import { PASSWORD_TOO_LONG, withinPasswordCap } from "../../core/hash-gate.ts";
2628 import { givenEmail, MIN_SIGNUP_PASSWORD, noEmail } from "../../actions/users.ts";
2729 import type { Credential } from "../../auth/webauthn.ts";
@@ -236,6 +238,7 @@ function claimForm(
236238 <p class="mb">Pick a username, then create your passkey. You will be the admin of this forge.</p>
237239 ${accountForm(ctx, "/welcome", values, errors)}
238240 </section>
241 ${crewNowHtml(crewNow(ctx.app.db))}
239242 </div></div>`;
240243 return html`<div class="shell"><div class="narrow">
241244 ${pageHead("This forge is yours")}
@@ -251,6 +254,7 @@ function claimForm(
251254 ${takeover(ctx, spawned, spawner)}
252255 ${accountForm(ctx, "/claim", values, errors)}
253256 </section>
257 ${crewNowHtml(crewNow(ctx.app.db))}
254258 </div></div>`;
255259 }
256260
test/home-flow.test.ts +6 −3
@@ -97,7 +97,8 @@ describe("the new home draws every lane", () => {
9797 const landingBefore = await (await get("/live/lane?s=landing", owner)).text();
9898 expect(titles(before, "checks")).not.toContain("Pasted links keep their address");
9999 expect(titles(landingBefore, "landing")).toContain("Pasted links keep their address");
100 // the crew starts the checks on an approved pull: its approval is superseded by new work, a check begins
100 // the crew starts the checks on an approved pull: its approval is superseded by new work, a
101 // check begins
101102 const pull = seed.pulls["a2"]!;
102103 app.db.run("UPDATE review SET state = 'commented' WHERE issue_id = ?1", [pull]);
103104 startCheck(app, pull, seed.repos.glue.id);
@@ -258,7 +259,8 @@ describe("nothing on the new home polls", () => {
258259 const text = readFileSync(join(import.meta.dir, "..", file), "utf8");
259260 expect(text).not.toMatch(/setInterval\s*\(/);
260261 expect(text).not.toMatch(/requestAnimationFrame/);
261 // the picture's two one-shots (a pause, a deadline on one worker job) are the only timers, and they hold nothing
262 // the picture's two one-shots (a pause, a deadline on one worker job) are the only timers,
263 // and they hold nothing
262264 expect((text.match(/setTimeout\s*\(/g) ?? []).length).toBe(file === "src/flow/lanes.ts" ? 2 : 0);
263265 }
264266 });
@@ -289,7 +291,8 @@ describe("before the first reading, a page never reads on the thread", () => {
289291 expect(html).toContain("Reading the hosted forges");
290292 for (const lane of LANES) expect(html).toContain(`id="lane-${lane}"`);
291293 expect(html).not.toContain("A cost ledger per delivery");
292 // its script fills each region from the region's own address: the lane waits for the worker, off the thread
294 // its script fills each region from the region's own address: the lane waits for the worker,
295 // off the thread
293296 const lane = await (await fetch(`${srv.url}/live/lane?s=building`, { headers: { cookie } })).text();
294297 expect(lane).toContain("A cost ledger per delivery");
295298 expect(lane).not.toContain("data-reading");
test/home-kpi-row.test.ts +4 −1
@@ -1,4 +1,7 @@
1 /** Home's figures row (#2871): the tiles, their links, studio words only, a sparkline of 24 points and one of 30 days of visitors (#3186). */
1 /**
2 * Home's figures row (#2871): the tiles, their links, studio words only, a sparkline of 24 points
3 * and one of 30 days of visitors (#3186).
4 */
25 import { Database } from "bun:sqlite";
36 import { bugTables, reachTables } from "./helpers/reach-tables.ts";
47 import { NO_REACH, readReach } from "../src/flow/reach.ts";
test/no-alarm-banner.test.ts +7 −3
@@ -71,7 +71,9 @@ interface World {
7171 readonly cookie: string;
7272 }
7373
74 /** A forge in an alarm state; `spent` is the crew's spend today, in dollars, against a $1 ceiling. */
74 /**
75 * A forge in an alarm state; `spent` is the crew's spend today, in dollars, against a $1 ceiling.
76 */
7577 async function world(spent: number): Promise<World> {
7678 const root = mkdtempSync(join(tmpdir(), "forge-no-alarm-banner-"));
7779 const app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge", crewCeilingUsd: 1 });
@@ -89,7 +91,8 @@ async function world(spent: number): Promise<World> {
8991 mkdirSync(join(root, "snapshot"), { recursive: true });
9092 const long = new Date(Date.now() - 72 * 3_600_000).toISOString();
9193 writeFileSync(join(root, "snapshot", "state.json"), JSON.stringify({ at: long, failingSince: long, error: "the bucket refused" }));
92 // A bug past its 48 h clock, in a repository that runs itself and has started no run: the bug-clock and idle-crew alarms.
94 // A bug past its 48 h clock, in a repository that runs itself and has started no run: the
95 // bug-clock and idle-crew alarms.
9396 const bug = openIssue(app, made.value, repo.value, { title: "The page is blank" });
9497 if (!bug.ok) throw new Error(String(bug.error));
9598 const label = createLabel(app.db, repo.value.id, "bug", "d73a4a");
@@ -209,7 +212,8 @@ test("the detector names a banner and passes the lines the forge really draws",
209212 expect(offenders("/", `<main id="main">${banner}<h1>Home</h1></main>`)).toHaveLength(1);
210213 expect(offenders("/", '<p role="alert">Disk is low</p>')).toHaveLength(1);
211214 expect(offenders("/", '<div class="stack banner">x</div>')).toHaveLength(1);
212 // Markup copied from the rendered pages: the home alarm line, the board's need, the menu item that carries the disk.
215 // Markup copied from the rendered pages: the home alarm line, the board's need, the menu item
216 // that carries the disk.
213217 expect(offenders("/", '<p class="small"><a href="/flow">No off-box backup has landed. The snapshot failed: the bucket refused</a></p>')).toEqual([]);
214218 expect(offenders("/board", '<li><a data-need id="sentinel" href="/trevato/forge/issues"><span class="dot" data-tone="attn"></span> The sentinel has 1 open finding</a></li>')).toEqual([]);
215219 expect(offenders("/", '<span class="menu-item" aria-disabled="true" title="this host&#39;s disk has 0.0% free">New forge</span>')).toEqual([]);
test/palette-roster.test.ts +4
@@ -53,6 +53,7 @@ test("a site-admin person is offered the whole roster", () => {
5353 ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"],
5454 ["mirror-packs", "Mirror the packs' upstreams", "bring each pack's upstream projects in as read-only repositories"],
5555 ["pack-repos", "Pack repositories", "which repositories /packs lists"],
56 ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"],
5657 ["status", "Status", "is the forge working, in one sentence"],
5758 ["templates", "Templates", "what a new forge can start from"],
5859 ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"],
@@ -234,6 +235,7 @@ test("a site-admin agent is offered the roster without the person-only entries",
234235 ["needs", "How is my forge?", "what needs you, with a recommendation each; a takes a safe one"],
235236 ["asks-admin", "What stands in the way", "what waits on you and what stands in your way; a asks whoever can, o opens the control"],
236237 ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"],
238 ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"],
237239 ["status", "Status", "is the forge working, in one sentence"],
238240 ["templates", "Templates", "what a new forge can start from"],
239241 ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"],
@@ -335,6 +337,7 @@ test("a member person is offered the signed-in roster without the admin entries"
335337 ["needs", "How is my forge?", "what needs you, with a recommendation each; a takes a safe one"],
336338 ["asks-admin", "What stands in the way", "what waits on you and what stands in your way; a asks whoever can, o opens the control"],
337339 ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"],
340 ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"],
338341 ["status", "Status", "is the forge working, in one sentence"],
339342 ["templates", "Templates", "what a new forge can start from"],
340343 ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"],
@@ -432,6 +435,7 @@ test("signed out, the palette offers sign-in and the public entries", () => {
432435 ["explore", "Explore", "on the web"],
433436 ["explore-feed", "Explore feed", "Atom address"],
434437 ["packs", "Forge packs", "premade forges to deploy, and how to help build their apps"],
438 ["crew-now", "Your crew's latest work", "the three runs a forge link's page shows"],
435439 ["status", "Status", "is the forge working, in one sentence"],
436440 ["templates", "Templates", "what a new forge can start from"],
437441 ["share-tell", "Share a link or text with the crew", "a draft, then where; nothing is sent until you confirm"],

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs