Public: anyone can read this; the crew can change it.
The space page opens with the wave in flight and what landed from it today #16146
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16131-the-space-page-opens-with-the-wave-in-fl → main 0 commits fork 2 threads · 2 unresolved
5 files
changed +171
−4
docs/features/space.md +2 −1
| @@ -6,7 +6,7 @@ row: The space | ||
| 6 | 6 | |
| 7 | 7 | `/:owner/:name/space` is the map as a plane you move through (#10444). It is |
| 8 | 8 | linked from the map page ("The same work as a space to move through"). Its data |
| 9 | is `/:owner/:name/space.json`, the same plane for an agent. In the terminal it is the `space` entry in the palette (`src/tui/screens/space.ts`): pillars with their counts, issues by state, who of the crew is on what, and the week's landings, from the same `spaceOf` and so the same gate as the page (a guest sees what is public, an admin everything). | |
| 9 | is `/:owner/:name/space.json`, the same plane for an agent. In the terminal it is the `space` entry in the palette (`src/tui/screens/space.ts`): pillars with their counts, issues by state, who of the crew is on what, and the week's landings, under the wave line (below), from the same `spaceOf` and so the same gate as the page (a guest sees what is public, an admin everything). | |
| 10 | 10 | |
| 11 | 11 | ## Use |
| 12 | 12 | |
| @@ -16,6 +16,7 @@ is `/:owner/:name/space.json`, the same plane for an agent. In the terminal it i | ||
| 16 | 16 | - **Time.** The scrubber replays the last 7 days: issues appear when opened, slide from "in review" to "landed" when they close, and crew members sit on what they were running then. **Play** runs the week in 20 seconds. At **Now** the view is live: any run, issue or pull event of the repository fetches the plane again. |
| 17 | 17 | - **Crew.** Their avatars sit on the issue they are working; tap one (or its name in the bar) to see what they are on. |
| 18 | 18 | - **Legend.** **Legend**, above the scrubber, says what size, ink and distance mean and gives each state one line. It starts closed; on a wide screen it opens once, on a first visit, and stays closed after. It is real HTML from `space_model.ts`, so it reads without the script. |
| 19 | - **The wave line.** Under the repository's name the page says which wave is in flight and how many of its issues landed (a pull merged) in the last 24 hours, or that the crew is resting when none is open (`src/story/wave_today.ts`). The terminal screen opens with the same line. Sealed work is counted only for a reader who may see it: its author, or one who sees sealed work; a guest's count leaves it out. | |
| 19 | 20 | - **One line and `?q=`.** Above the fold, one line says size, colour and distance. The Find box is a plain GET form: `/:owner/:name/space?q=login` lists the matching issues as links (or says "No issue matches") without script; with script the view also flies to the first. In the terminal the same one line opens the screen. |
| 20 | 21 | - **Share.** The view is in the address hash: `#x=…&y=…&z=…` (centre in world units, zoom relative to Fit) and `&t=` (minutes since the epoch) when scrubbed back. |
| 21 | 22 |
src/story/wave_today.ts added +50
| @@ -0,0 +1,50 @@ | ||
| 1 | /** | |
| 2 | * The wave in flight, in one line for the top of a page: the open chapter's name and how many | |
| 3 | * of its issues landed (a pull merged) in the last 24 hours. No open chapter is a crew at rest. | |
| 4 | * Sealed work is counted only for a reader `sealedScope` lets see it. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import { openChapterOf } from "../core/chapters.ts"; | |
| 9 | ||
| 10 | export const DAY_MS = 24 * 3_600_000; | |
| 11 | ||
| 12 | export interface WaveToday { | |
| 13 | readonly name: string; | |
| 14 | readonly landed: number; | |
| 15 | } | |
| 16 | ||
| 17 | /** The open wave and its landings since `now - 24h`; undefined when none is open. */ | |
| 18 | export function waveToday( | |
| 19 | db: Database, | |
| 20 | repoId: string, | |
| 21 | scope: { sealed?: true; sealedBy?: string }, | |
| 22 | now: Date = new Date(), | |
| 23 | ): WaveToday | undefined { | |
| 24 | const chapter = openChapterOf(db, repoId); | |
| 25 | if (chapter === undefined) return undefined; | |
| 26 | const params: string[] = [chapter.id, new Date(now.getTime() - DAY_MS).toISOString()]; | |
| 27 | let seen = ""; | |
| 28 | if (scope.sealed !== true) { | |
| 29 | if (scope.sealedBy === undefined) seen = " AND i.sealed = 0"; | |
| 30 | else { | |
| 31 | params.push(scope.sealedBy); | |
| 32 | seen = " AND (i.sealed = 0 OR i.author_id = ?3)"; | |
| 33 | } | |
| 34 | } | |
| 35 | const row = db | |
| 36 | .query<{ n: number }, string[]>( | |
| 37 | `SELECT COUNT(DISTINCT i.id) AS n FROM chapter_item c | |
| 38 | JOIN issue i ON i.id = c.issue_id | |
| 39 | JOIN pull p ON p.issue_id = i.id | |
| 40 | WHERE c.chapter_id = ?1 AND p.merged_at IS NOT NULL AND p.merged_at >= ?2${seen}`, | |
| 41 | ) | |
| 42 | .get(...params); | |
| 43 | return { name: chapter.name, landed: row?.n ?? 0 }; | |
| 44 | } | |
| 45 | ||
| 46 | /** The line itself. */ | |
| 47 | export function waveLine(w: WaveToday | undefined): string { | |
| 48 | if (w === undefined) return "The crew is resting: no wave is open."; | |
| 49 | return `Wave in flight: ${w.name} · ${w.landed} landed in the last 24 hours`; | |
| 50 | } |
src/tui/screens/space.ts +6 −3
| @@ -6,6 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import type { Repo } from "../../core/repos.ts"; |
| 9 | import { sealedScope } from "../../core/sealed.ts"; | |
| 10 | import { waveLine, waveToday } from "../../story/wave_today.ts"; | |
| 9 | 11 | import { spaceOf } from "../../web/space_read.ts"; |
| 10 | 12 | import { LEGEND_LINE } from "../../web/space_model.ts"; |
| 11 | 13 | import type { ClusterRow, IssueRow, Region, State } from "../../web/space_model.ts"; |
| @@ -20,7 +22,7 @@ import { agoText, firstFound } from "../../web/space_view.ts"; | ||
| 20 | 22 | const NAMES: Record<State, string> = { ready: "Ready", building: "Building", review: "In review", waiting: "Waiting", landed: "Landed" }; |
| 21 | 23 | |
| 22 | 24 | /** The space as text lines, wrapped to `width`. */ |
| 23 | export function spaceLines(space: Record<string, unknown>, width = 80): string[] { | |
| 25 | export function spaceLines(space: Record<string, unknown>, width = 80, wave?: string): string[] { | |
| 24 | 26 | const w = Math.max(20, width); |
| 25 | 27 | const regions = space.regions as Region[]; |
| 26 | 28 | const clusters = space.clusters as ClusterRow[]; |
| @@ -28,7 +30,7 @@ export function spaceLines(space: Record<string, unknown>, width = 80): string[] | ||
| 28 | 30 | const issues = space.issues as IssueRow[]; |
| 29 | 31 | const crew = space.crew as { name: string; runs: [number, number, number][] }[]; |
| 30 | 32 | const now = space.now as number; |
| 31 | const out: string[] = [...wrap(LEGEND_LINE, w), ""]; | |
| 33 | const out: string[] = [...(wave === undefined ? [] : [...wrap(wave, w), ""]), ...wrap(LEGEND_LINE, w), ""]; | |
| 32 | 34 | regions.forEach((r, ri) => { |
| 33 | 35 | out.push(`${r.name} ${r.open} open, ${r.ready} ready, ${r.landed} landed this week${r.moving ? "" : ", still"}`); |
| 34 | 36 | const by = new Map<State, IssueRow[]>(); |
| @@ -94,7 +96,8 @@ export function spaceScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 94 | 96 | render(area, s) { |
| 95 | 97 | const c = ctx.theme.c; |
| 96 | 98 | const space = spaceOf(f.app, repo, f.user); |
| 97 | lines = [...(filter.on ? [`Find: ${filter.query}${filter.active ? "_" : ""}`, ...found, ""] : []), ...spaceLines({ ...space }, area.w - 4)]; | |
| 99 | const wave = waveLine(waveToday(f.app.db, repo.id, sealedScope(f.app.db, repo, f.user))); | |
| 100 | lines = [...(filter.on ? [`Find: ${filter.query}${filter.active ? "_" : ""}`, ...found, ""] : []), ...spaceLines({ ...space }, area.w - 4, wave)]; | |
| 98 | 101 | const from = scroll.window(area.h, lines.length); |
| 99 | 102 | for (let i = 0; i < area.h; i++) { |
| 100 | 103 | const line = lines[from + i]; |
src/web/pages/space.ts +4
| @@ -19,6 +19,8 @@ import { spaceCss, spaceJs } from "../space_client.ts"; | ||
| 19 | 19 | import { findBodies } from "../space_view.ts"; |
| 20 | 20 | import { COLOUR_SAYS, DISTANCE_SAYS, SIZE_SAYS, STATES, STATE_LEGEND, type Region, type Space } from "../space_model.ts"; |
| 21 | 21 | import { spaceOf } from "../space_read.ts"; |
| 22 | import { sealedScope } from "../../core/sealed.ts"; | |
| 23 | import { waveLine, waveToday } from "../../story/wave_today.ts"; | |
| 22 | 24 | |
| 23 | 25 | /** The plane as JSON: for the canvas, and for an agent that wants the numbers. */ |
| 24 | 26 | export function spaceJson(ctx: Ctx): Response { |
| @@ -56,6 +58,7 @@ export function spacePage(ctx: Ctx): Response { | ||
| 56 | 58 | const base = repoBase(repo); |
| 57 | 59 | const space = timePhase(ctx.request, "space", () => spaceOf(ctx.app, repo, ctx.auth.user)); |
| 58 | 60 | const regions = space.regions as Region[]; |
| 61 | const wave = waveToday(ctx.app.db, repo.id, sealedScope(ctx.app.db, repo, ctx.auth.user)); | |
| 59 | 62 | // ?q= is the finder without script: the matches as links, or the words that none match. |
| 60 | 63 | const q = (ctx.url.searchParams.get("q") ?? "").trim().slice(0, 200); |
| 61 | 64 | const hits = q ? findBodies(space.issues, q) : []; |
| @@ -129,6 +132,7 @@ export function spacePage(ctx: Ctx): Response { | ||
| 129 | 132 | ${factsList(`Issues of ${repo.name}`, spaceFacts(space, base), true)} |
| 130 | 133 | <div class="space-list"> |
| 131 | 134 | <h1>${repo.name}</h1> |
| 135 | <p id="space-wave" class="muted">${waveLine(wave)}</p> | |
Both doors: the terminal space screen (src/tui/screens/space.ts) needs this same line. Also confirm waveLine(wave) is escaped here, since the chapter name is user text. |
||
| 132 | 136 | <p id="space-error" class="muted" hidden>The canvas could not load the space. The pillars are below.</p> |
| 133 | 137 | <ul> |
| 134 | 138 | ${regions.map( |
test/space-wave.test.ts added +109
| @@ -0,0 +1,109 @@ | ||
| 1 | /** The space page opens with the wave in flight and what landed from it in 24 hours. */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { newApp } from "../src/actions/apps.ts"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { draftChapter, putIssue, startChapter } from "../src/core/chapters.ts"; | |
| 9 | import { createIssue } from "../src/core/issues.ts"; | |
| 10 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
| 11 | import { createUser } from "../src/core/users.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { waveLine, waveToday } from "../src/story/wave_today.ts"; | |
| 14 | import { quietLogs } from "./helpers/globals.ts"; | |
| 15 | ||
| 16 | quietLogs(); | |
| 17 | ||
| 18 | let dir = ""; | |
| 19 | let app: App; | |
| 20 | let servers: Servers; | |
| 21 | let repo: Repo; | |
| 22 | let owner: { id: string }; | |
| 23 | ||
| 24 | const merge = (issueId: string, at: Date) => | |
| 25 | app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'b', '', '', ?2)").run(issueId, at.toISOString()); | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dir = await mkdtemp(join(tmpdir(), "forge-space-wave-")); | |
| 29 | app = createApp({ dataDir: dir, port: 0, host: "forge.test", url: "https://forge.test" }); | |
| 30 | const made = await createUser(app.db, { username: "alice", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true }); | |
| 31 | if (!made.ok) throw new Error(String(made.error)); | |
| 32 | owner = made.value; | |
| 33 | const created = await newApp(app, made.value, { name: "shop", description: "Words", visibility: "public" }); | |
| 34 | if (!created.ok) throw new Error(String(created.error)); | |
| 35 | repo = getRepo(app.db, "alice", "shop")!; | |
| 36 | servers = await serve(app); | |
| 37 | }, 30_000); | |
| 38 | afterAll(async () => { | |
| 39 | servers.stop(); | |
| 40 | app.close(); | |
| 41 | await rm(dir, { recursive: true, force: true }); | |
| 42 | }); | |
| 43 | ||
| 44 | const text = async () => (await fetch(`${servers.url}/alice/shop/space`)).text(); | |
| 45 | ||
| 46 | test("with no open wave the page says the crew is resting", async () => { | |
| 47 | expect(waveToday(app.db, repo.id, { sealed: true })).toBeUndefined(); | |
| 48 | expect(await text()).toContain("The crew is resting"); | |
| 49 | }); | |
| 50 | ||
| 51 | test("an open wave is named with what landed from it in the last 24 hours", async () => { | |
| 52 | const chapter = draftChapter(app.db, repo.id, { name: "v2" }, owner.id); | |
| 53 | if (!chapter.ok) throw new Error(chapter.error); | |
| 54 | const now = new Date(); | |
| 55 | const ids: string[] = []; | |
| 56 | for (const title of ["a", "b", "c", "outside"]) { | |
| 57 | const i = createIssue(app.db, { repoId: repo.id, authorId: owner.id, title }); | |
| 58 | if (!i.ok) throw new Error(i.error); | |
| 59 | ids.push(i.value.id); | |
| 60 | if (title !== "outside") putIssue(app.db, chapter.value, i.value.id, owner.id); | |
| 61 | } | |
| 62 | merge(ids[0]!, new Date(now.getTime() - 3_600_000)); // landed an hour ago: counts | |
| 63 | merge(ids[1]!, new Date(now.getTime() - 48 * 3_600_000)); // two days ago: does not | |
| 64 | merge(ids[3]!, now); // not in the wave: does not | |
| 65 | startChapter(app.db, chapter.value, now); | |
| 66 | expect(waveToday(app.db, repo.id, { sealed: true }, now)).toEqual({ name: "v2", landed: 1 }); | |
| 67 | expect(waveLine({ name: "v2", landed: 1 })).toBe("Wave in flight: v2 · 1 landed in the last 24 hours"); | |
| 68 | const body = await text(); | |
| 69 | expect(body).toContain("Wave in flight: v2 · 1 landed in the last 24 hours"); | |
| 70 | expect(body).not.toContain("The crew is resting"); | |
| 71 | }); | |
| 72 | ||
| 73 | test("a sealed issue landed in the wave is counted for its author and hidden from a guest", async () => { | |
| 74 | const wave = draftChapter(app.db, repo.id, { name: "v3" }, owner.id); | |
| 75 | if (!wave.ok) throw new Error(wave.error); | |
| 76 | const stranger = await createUser(app.db, { username: "bob", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true }); | |
| 77 | if (!stranger.ok) throw new Error(String(stranger.error)); | |
| 78 | const now = new Date(); | |
| 79 | const pub = createIssue(app.db, { repoId: repo.id, authorId: owner.id, title: "open one" }); | |
| 80 | const sealed = createIssue(app.db, { repoId: repo.id, authorId: stranger.value.id, title: "hole", sealed: true }); | |
| 81 | if (!pub.ok || !sealed.ok) throw new Error("issue"); | |
| 82 | for (const i of [pub.value, sealed.value]) { | |
| 83 | putIssue(app.db, wave.value, i.id, owner.id); | |
| 84 | merge(i.id, new Date(now.getTime() - 60_000)); | |
| 85 | } | |
| 86 | // close v2 so v3 is the open wave | |
| 87 | app.db.query("UPDATE chapter SET state = 'closed' WHERE repo_id = ?1 AND name = 'v2'").run(repo.id); | |
| 88 | startChapter(app.db, wave.value, now); | |
| 89 | expect(waveToday(app.db, repo.id, {}, now)?.landed).toBe(1); // a guest: the public one only | |
| 90 | expect(waveToday(app.db, repo.id, { sealedBy: stranger.value.id }, now)?.landed).toBe(2); // its author | |
| 91 | expect(waveToday(app.db, repo.id, { sealedBy: "someone-else" }, now)?.landed).toBe(1); | |
| 92 | expect(waveToday(app.db, repo.id, { sealed: true }, now)?.landed).toBe(2); | |
| 93 | expect(await text()).toContain("v3 · 1 landed"); | |
| 94 | }); | |
| 95 | ||
| 96 | test("a chapter name with markup is escaped on the page", async () => { | |
| 97 | app.db.query("UPDATE chapter SET name = '<b>x</b>' WHERE repo_id = ?1 AND name = 'v3'").run(repo.id); | |
| 98 | const body = await text(); | |
| 99 | expect(body).toContain("<b>x</b> · "); | |
| 100 | expect(body).not.toContain("<b>x</b>"); | |
| 101 | }); | |
| 102 | ||
| 103 | test("the terminal's space opens with the same wave line", async () => { | |
| 104 | const { spaceLines } = await import("../src/tui/screens/space.ts"); | |
| 105 | const empty = { regions: [], clusters: [], states: [], issues: [], crew: [], now: 0 }; | |
| 106 | const line = waveLine({ name: "v9", landed: 2 }); | |
| 107 | expect(spaceLines(empty, 200, line)[0]).toBe(line); | |
| 108 | expect(spaceLines(empty, 200)[0]).not.toContain("Wave in flight"); | |
| 109 | }); |
new above
offline
The sealed branches (sealedBy and guest) are not tested. A wrong scope here leaks sealed work counts across users. Add tests for both.