Public: anyone can read this; the crew can change it.
The space view finds a body by name and flies to it #12783
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12758-the-space-view-finds-a-body-by-name-and → main 8 commits fork 3 threads · 3 unresolved
8 files
changed +181
−7
docs/design/size-budget.json +1 −1
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | "css": 44032 |
| 25 | 25 | }, |
| 26 | 26 | "/:owner/:name/space": { |
| 27 | "js": 28672, | |
| 27 | "js": 28928, | |
| 28 | 28 | "css": 44800 |
| 29 | 29 | }, |
| 30 | 30 | "/:owner/:name/space.json": { |
docs/features/space.md +1 −1
| @@ -6,7 +6,7 @@ is `/:owner/:name/space.json`, the same plane for an agent. In the terminal it i | ||
| 6 | 6 | |
| 7 | 7 | ## Use |
| 8 | 8 | |
| 9 | - **Move.** Drag (or two fingers) to pan; pinch, wheel or `+`/`-` (also with ⌘/Ctrl) to zoom; arrows pan; `0` or **Fit** shows the whole plane; `n` or **Now** returns to live. No page scroll fights it (`touch-action: none`). | |
| 9 | - **Move.** Drag (or two fingers) to pan; pinch, wheel or `+`/`-` (also with ⌘/Ctrl) to zoom; arrows pan; `0` or **Fit** shows the whole plane; `n` or **Now** returns to live. `/` focuses the finder (when you are not typing in a field); type a number or part of a title and **Enter** flies to the first match that exists at the time shown and selects it, or says "No issue matches"; **Esc** clears it. In the terminal, `/` opens the same find, Enter shows the first match's facts and link, Esc clears. No page scroll fights it (`touch-action: none`). | |
| 10 | 10 | - **Semantic zoom.** Out: pillars are regions whose area follows open work, with a progress bar (landed ÷ open + landed over the week) and whether they moved. In: each region's issues sit in clusters by state (ready, building, in review, waiting, landed). Further in: an issue is a card with its title, then its pull, checks and the crew member on it. Words are set at a fixed pixel size at every level; detail is added, nothing shrinks. |
| 11 | 11 | - **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. |
| 12 | 12 | - **Crew.** Their avatars sit on the issue they are working; tap one (or its name in the bar) to see what they are on. |
src/tui/screens/space.ts +50 −3
| @@ -13,7 +13,8 @@ import { binding } from "../app/keys.ts"; | ||
| 13 | 13 | import type { Session } from "../session.ts"; |
| 14 | 14 | import { style } from "../term/style.ts"; |
| 15 | 15 | import { wrap } from "../term/width.ts"; |
| 16 | import { Scroll } from "./common.ts"; | |
| 16 | import { Filter, Scroll } from "./common.ts"; | |
| 17 | import { firstFound } from "../../web/space_view.ts"; | |
| 17 | 18 | |
| 18 | 19 | const NAMES: Record<State, string> = { ready: "Ready", building: "Building", review: "In review", waiting: "Waiting", landed: "Landed" }; |
| 19 | 20 | |
| @@ -54,15 +55,41 @@ export function spaceLines(space: Record<string, unknown>, width = 80): string[] | ||
| 54 | 55 | return out; |
| 55 | 56 | } |
| 56 | 57 | |
| 58 | /** | |
| 59 | * What a found issue shows: its facts and where it is on the web. | |
| 60 | * `link` is the issue's URL or path. | |
| 61 | */ | |
| 62 | export function foundLines(space: Record<string, unknown>, query: string, link: (n: number) => string, width = 80): string[] { | |
| 63 | const clusters = space.clusters as ClusterRow[]; | |
| 64 | const states = space.states as State[]; | |
| 65 | const regions = space.regions as Region[]; | |
| 66 | const hit = firstFound(space.issues as IssueRow[], query, space.now as number); | |
| 67 | if (hit === null) return ["No issue matches"]; | |
| 68 | const row = hit.row as IssueRow; | |
| 69 | const c = clusters[row[1]]; | |
| 70 | const state = c === undefined ? "" : NAMES[states[c[1]!]!]; | |
| 71 | const pillar = c === undefined ? "" : (regions[c[0]]?.name ?? ""); | |
| 72 | return [ | |
| 73 | ...wrap(`#${row[0]} ${row[6]}`, width), | |
| 74 | ` ${[state, pillar].filter((x) => x !== "").join(" in ")}`, | |
| 75 | ...(row[7] ? [` Pull #${row[7]}${row[12] ? `, checks ${row[12]}` : ""}`] : []), | |
| 76 | ` ${link(row[0])}`, | |
| 77 | ]; | |
| 78 | } | |
| 79 | ||
| 57 | 80 | export function spaceScreen(f: Session, ctx: Ctx, repo: Repo): Screen { |
| 58 | 81 | const scroll = new Scroll(); |
| 59 | 82 | let lines: string[] = []; |
| 83 | const filter = new Filter(); | |
| 84 | let found: string[] = []; | |
| 85 | const link = (n: number): string => `${(f.app.config.url ?? "").replace(/\/+$/, "")}/${repo.ownerName}/${repo.name}/issues/${n}`; | |
| 60 | 86 | return { |
| 61 | 87 | title: `Space · ${repo.ownerName}/${repo.name}`, |
| 62 | keys: [binding(["j", "k"], "scroll"), binding(["esc"], "back")], | |
| 88 | keys: [binding(["j", "k"], "scroll"), binding(["/"], "find"), binding(["enter"], "select the first match"), binding(["esc"], "back")], | |
| 63 | 89 | render(area, s) { |
| 64 | 90 | const c = ctx.theme.c; |
| 65 | lines = spaceLines(spaceOf(f.app, repo, f.user), area.w - 4); | |
| 91 | const space = spaceOf(f.app, repo, f.user); | |
| 92 | lines = [...(filter.on ? [`Find: ${filter.query}${filter.active ? "_" : ""}`, ...found, ""] : []), ...spaceLines(space, area.w - 4)]; | |
| 66 | 93 | const from = scroll.window(area.h, lines.length); |
| 67 | 94 | for (let i = 0; i < area.h; i++) { |
| 68 | 95 | const line = lines[from + i]; |
| @@ -70,6 +97,26 @@ export function spaceScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 70 | 97 | } |
| 71 | 98 | }, |
| 72 | 99 | key(e) { |
| 100 | if (filter.active && e.key === "enter") { | |
| 101 | filter.active = false; | |
| 102 | found = filter.query === "" ? [] : foundLines(spaceOf(f.app, repo, f.user), filter.query, link, 76); | |
| 103 | return true; | |
| 104 | } | |
| 105 | if (filter.active && e.key === "esc") { | |
| 106 | filter.active = false; | |
| 107 | filter.query = ""; | |
| 108 | found = []; | |
| 109 | return true; | |
| 110 | } | |
| 111 | if (filter.key(e)) { | |
| 112 | found = []; | |
| 113 | return true; | |
| 114 | } | |
| 115 | if (e.key === "esc" && filter.query !== "") { | |
| 116 | filter.query = ""; | |
| 117 | found = []; | |
| 118 | return true; | |
| 119 | } | |
| 73 | 120 | if (e.key === "esc" || e.key === "q") { |
| 74 | 121 | ctx.pop(); |
| 75 | 122 | return true; |
src/web/pages/space.ts +10
| @@ -64,6 +64,16 @@ export function spacePage(ctx: Ctx): Response { | ||
| 64 | 64 | ${btn("Fit", { type: "button", id: "space-fit", variant: "outline", size: "sm" })} |
| 65 | 65 | ${btn("+", { type: "button", id: "space-in", label: "Zoom in", variant: "outline", size: "sm" })} |
| 66 | 66 | ${btn("−", { type: "button", id: "space-out", label: "Zoom out", variant: "outline", size: "sm" })} |
| 67 | <label class="sr-only" for="space-find">Find an issue by number or title</label> | |
| 68 | <input | |
| 69 | class="input" | |
| 70 | type="search" | |
| 71 | id="space-find" | |
| 72 | placeholder="Find an issue" | |
| 73 | autocomplete="off" | |
| 74 | maxlength="200" | |
| 75 | /> | |
| 76 | <span id="space-find-status" class="muted" role="status" aria-live="polite"></span> | |
| 67 | 77 | <span id="space-crew"></span> |
| 68 | 78 | </div> |
| 69 | 79 | <aside class="space-panel" id="space-panel" hidden></aside> |
src/web/space_client.ts +26
| @@ -45,6 +45,7 @@ html.space-on .space-bar { display: flex; position: absolute; left: 0; right: 0; | ||
| 45 | 45 | html.space-on .space-time { display: flex; gap: .6rem; align-items: center; padding: .6rem .75rem calc(.6rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 60%); } |
| 46 | 46 | .space-time input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); } |
| 47 | 47 | .space-time output { font-variant-numeric: tabular-nums; min-width: 9ch; text-align: right; } |
| 48 | .space-bar input[type=search] { width: 11rem; max-width: 40vw; } | |
| 48 | 49 | .space-panel { position: absolute; right: .75rem; top: 3.5rem; width: min(22rem, calc(100% - 1.5rem)); background: var(--bg); border-left: 1px solid var(--border); padding: .75rem 1rem; } |
| 49 | 50 | .space-panel[hidden] { display: none; } |
| 50 | 51 | .space-panel h2 { font-size: 1rem; margin: 0 0 .35rem; } |
| @@ -79,6 +80,8 @@ ${viewJs} | ||
| 79 | 80 | var panel = document.getElementById('space-panel'); |
| 80 | 81 | var slider = document.getElementById('space-t'); |
| 81 | 82 | var clock = document.getElementById('space-clock'); |
| 83 | var finder = document.getElementById('space-find'); | |
| 84 | var findStatus = document.getElementById('space-find-status'); | |
| 82 | 85 | var crewBox = document.getElementById('space-crew'); |
| 83 | 86 | var playBtn = document.getElementById('space-play'); |
| 84 | 87 | var S = null, rows = [], W = 0, H = 0, dpr = 1; |
| @@ -434,6 +437,29 @@ ${viewJs} | ||
| 434 | 437 | }); |
| 435 | 438 | } |
| 436 | 439 | |
| 440 | // ---- find ---- | |
| 441 | // Enter: fly to the first match that exists at the time shown, and select it as a tap would. | |
| 442 | function find() { | |
| 443 | if (!S) return; | |
| 444 | var hit = firstFound(rows, finder.value, T); | |
| 445 | if (!hit) { finder.setAttribute('aria-invalid', 'true'); findStatus.textContent = 'No issue matches'; return; } | |
| 446 | pick({ kind: 'issue', number: hit.row[0] }); | |
| 447 | fly({ x: hit.pos[0], y: hit.pos[1], k: Math.max(view.k, fitK * 24) }); | |
| 448 | } | |
| 449 | function clearFind() { finder.removeAttribute('aria-invalid'); findStatus.textContent = ''; } | |
| 450 | if (finder) { | |
| 451 | finder.addEventListener('input', clearFind); | |
| 452 | finder.addEventListener('keydown', function (e) { | |
| 453 | if (e.key === 'Enter') { e.preventDefault(); find(); } | |
| 454 | else if (e.key === 'Escape') { finder.value = ''; clearFind(); finder.blur(); } | |
| 455 | }); | |
| 456 | document.addEventListener('keydown', function (e) { | |
| 457 | var t = e.target, tag = t && t.tagName; | |
| 458 | if (e.key !== '/' || e.metaKey || e.ctrlKey || e.altKey || tag === 'INPUT' || tag === 'TEXTAREA') return; | |
| 459 | e.preventDefault(); finder.focus(); finder.select(); | |
| 460 | }); | |
| 461 | } | |
| 462 | ||
| 437 | 463 | // ---- time ---- |
| 438 | 464 | function showClock() { |
| 439 | 465 | clock.textContent = live ? 'Now' : new Date(T).toLocaleString([], { weekday: 'short', hour: '2-digit', minute: '2-digit' }); |
src/web/space_view.ts +29 −1
| @@ -115,5 +115,33 @@ export function pickIssue(rows: any[][], clusters: any[][], T: number, wx: numbe | ||
| 115 | 115 | return best; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | /** | |
| 119 | * The rows whose number or title holds `query` (case-insensitive substring; a | |
| 120 | * leading `#` is ignored), in row order. An empty query matches nothing. | |
| 121 | */ | |
| 122 | export function findBodies(rows: any[][], query: string): any[][] { | |
| 123 | const q = query.trim().replace(/^#/, "").toLowerCase(); | |
| 124 | const out: any[][] = []; | |
| 125 | if (!q) return out; | |
| 126 | for (let i = 0; i < rows.length; i++) { | |
| 127 | const r = rows[i]!; | |
| 128 | if (String(r[0]).indexOf(q) >= 0 || String(r[6]).toLowerCase().indexOf(q) >= 0) out.push(r); | |
| 129 | } | |
| 130 | return out; | |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * What Enter picks: the first match (row order) that exists at time `T`, with | |
| 135 | * its position then; or null when nothing matches or every match is not yet born. | |
| 136 | */ | |
| 137 | export function firstFound(rows: any[][], query: string, T: number): { row: any[]; pos: number[] } | null { | |
| 138 | const hits = findBodies(rows, query); | |
| 139 | for (let i = 0; i < hits.length; i++) { | |
| 140 | const pos = placeAt(hits[i]!, T); | |
| 141 | if (pos) return { row: hits[i]!, pos }; | |
| 142 | } | |
| 143 | return null; | |
| 144 | } | |
| 145 | ||
| 118 | 146 | /** The source the page ships for these functions. */ |
| 119 | export const viewJs = [clamp, ease, placeAt, crewAt, parseHash, hashOf, pickIssue].map((f) => f.toString()).join("\n"); | |
| 147 | export const viewJs = [clamp, ease, placeAt, crewAt, parseHash, hashOf, pickIssue, findBodies, firstFound].map((f) => f.toString()).join("\n"); |
test/space-find.test.ts added +53
| @@ -0,0 +1,53 @@ | ||
| 1 | /** The space's finder (#12758): the pure match, and the string the page ships. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { findBodies, firstFound } from "../src/web/space_view.ts"; | |
| 4 | import { spaceJs } from "../src/web/space_client.ts"; | |
| 5 | ||
| 6 | const row = (n: number, title: string) => [n, 0, 0, 0, 1, 0, title, 0, 0, 0, 0, "", ""]; | |
| 7 | const rows = [row(12, "Fix the Login"), row(120, "Space view"), row(7, "login again"), row(5, "Other")]; | |
| 8 | ||
| 9 | test("matches by number substring, with or without #", () => { | |
| 10 | expect(findBodies(rows, "12").map((r) => r[0])).toEqual([12, 120]); | |
| 11 | expect(findBodies(rows, "#7").map((r) => r[0])).toEqual([7]); | |
| 12 | }); | |
| 13 | ||
| 14 | test("matches title substrings case-insensitively, in row order", () => { | |
| 15 | expect(findBodies(rows, "LOGIN").map((r) => r[0])).toEqual([12, 7]); | |
| 16 | expect(findBodies(rows, " space ").map((r) => r[0])).toEqual([120]); | |
| 17 | }); | |
| 18 | ||
| 19 | test("no match, and an empty query, find nothing", () => { | |
| 20 | expect(findBodies(rows, "zzz")).toEqual([]); | |
| 21 | expect(findBodies(rows, "")).toEqual([]); | |
| 22 | expect(findBodies(rows, "#")).toEqual([]); | |
| 23 | }); | |
| 24 | ||
| 25 | test("5,000 rows: the hits are exact (correctness, not speed)", () => { | |
| 26 | const big = Array.from({ length: 5000 }, (_, i) => row(i + 1, `Issue number ${i} about thing ${i % 97}`)); | |
| 27 | const hits = findBodies(big, "thing 96"); | |
| 28 | expect(hits.length).toBe(big.filter((r) => String(r[6]).includes("thing 96")).length); | |
| 29 | expect(hits.length).toBeGreaterThan(0); | |
| 30 | }); | |
| 31 | ||
| 32 | // A row born at `born` (ms); placeAt shows it from then on. | |
| 33 | const born = (n: number, title: string, at: number) => [n, 0, 0, 0, at, 0, title, 0, 0, 0, 0, "", ""]; | |
| 34 | ||
| 35 | test("firstFound: the first match that exists at the time shown, skipping the unborn", () => { | |
| 36 | const rs = [born(1, "login early", 5000), born(2, "login mid", 1000), born(3, "login late", 500)]; | |
| 37 | expect(firstFound(rs, "login", 2000)!.row[0]).toBe(2); | |
| 38 | expect(firstFound(rs, "login", 800)!.row[0]).toBe(3); | |
outdated
This assertion rebuilds the id string with replace calls to check one getElementById; it tests nothing about behaviour. Replace with a test of the selection logic. |
||
| 39 | expect(firstFound(rs, "login", 100)).toBeNull(); | |
| 40 | expect(firstFound(rs, "nothing", 9000)).toBeNull(); | |
| 41 | expect(firstFound(rs, "", 9000)).toBeNull(); | |
| 42 | expect(firstFound(rs, "login", 9000)!.pos.length).toBeGreaterThanOrEqual(3); | |
| 43 | }); | |
| 44 | ||
| 45 | test("the shipped script flies and selects through firstFound, says no match in text, and clears it", () => { | |
| 46 | expect(spaceJs).toContain("function firstFound"); | |
| 47 | const start = spaceJs.indexOf("function find()"); | |
| 48 | const body = spaceJs.slice(start, spaceJs.indexOf("function clearFind", start)); | |
| 49 | expect(body).toContain("firstFound(rows, finder.value, T)"); | |
| 50 | expect(body).toContain("pick("); | |
| 51 | expect(body).toContain("fly("); | |
| 52 | expect(body).toContain("No issue matches"); | |
| 53 | }); |
test/space-screen.test.ts +11 −1
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** The space in the terminal (#10444): the same plane as text. */ |
| 2 | 2 | import { expect, test } from "bun:test"; |
| 3 | 3 | import { buildSpace, type SpaceInput } from "../src/web/space_model.ts"; |
| 4 | import { spaceLines } from "../src/tui/screens/space.ts"; | |
| 4 | import { foundLines, spaceLines } from "../src/tui/screens/space.ts"; | |
| 5 | 5 | |
| 6 | 6 | const NOW = Date.UTC(2026, 10, 10, 12); |
| 7 | 7 | const input: SpaceInput = { |
| @@ -30,3 +30,13 @@ test("spaceLines: a quiet repository says so", () => { | ||
| 30 | 30 | expect(text).toContain("Nobody is building right now."); |
| 31 | 31 | expect(text).toContain("Landed this week (0)"); |
| 32 | 32 | }); |
| 33 | ||
| 34 | test("foundLines: the first match's facts and link; no match says so", () => { | |
| 35 | const space = { ...buildSpace(input) }; | |
| 36 | const out = foundLines(space, "build", (n) => `/a/b/issues/${n}`); | |
| 37 | expect(out[0]).toBe("#2 Build it"); | |
| 38 | expect(out.join("\n")).toContain("Pull #7, checks running"); | |
| 39 | expect(out.at(-1)).toBe(" /a/b/issues/2"); | |
| 40 | expect(foundLines(space, "#3", (n) => `/x/${n}`)[0]).toBe("#3 Shipped"); | |
| 41 | expect(foundLines(space, "zzz", (n) => `/x/${n}`)).toEqual(["No issue matches"]); | |
| 42 | }); |
new above
offline
Principle 8: placeholder 'Find # or title /' is a key hint, not words. Use 'Find an issue'; put the
/hint in docs. Also a no-match state needs visible text, not only aria-invalid.