Public: anyone can read this; the crew can change it.
/space has a legend for size, colour and distance, and a search that flies to a body by name #15646
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15591-space-has-a-legend-for-size-colour-and-d → main 0 commits fork 3 threads · 3 unresolved
7 files
changed +76
−14
docs/features/space.md +1
| @@ -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 | - **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. | |
| 19 | 20 | - **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. |
| 20 | 21 | |
| 21 | 22 | The MCP `map` tool answers `view: "space"` with the same `spaceOf` result, scoped to the caller like the page. |
src/tui/screens/space.ts +2 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | |
| 8 | 8 | import type { Repo } from "../../core/repos.ts"; |
| 9 | 9 | import { spaceOf } from "../../web/space_read.ts"; |
| 10 | import { LEGEND_LINE } from "../../web/space_model.ts"; | |
| 10 | 11 | import type { ClusterRow, IssueRow, Region, State } from "../../web/space_model.ts"; |
| 11 | 12 | import type { Ctx, Screen } from "../app/app.ts"; |
| 12 | 13 | import { binding } from "../app/keys.ts"; |
| @@ -27,7 +28,7 @@ export function spaceLines(space: Record<string, unknown>, width = 80): string[] | ||
| 27 | 28 | const issues = space.issues as IssueRow[]; |
| 28 | 29 | const crew = space.crew as { name: string; runs: [number, number, number][] }[]; |
| 29 | 30 | const now = space.now as number; |
| 30 | const out: string[] = []; | |
| 31 | const out: string[] = [...wrap(LEGEND_LINE, w), ""]; | |
| 31 | 32 | regions.forEach((r, ri) => { |
| 32 | 33 | out.push(`${r.name} ${r.open} open, ${r.ready} ready, ${r.landed} landed this week${r.moving ? "" : ", still"}`); |
| 33 | 34 | const by = new Map<State, IssueRow[]>(); |
src/web/pages/space.ts +25 −11
| @@ -13,9 +13,10 @@ import { holds, weakEtag } from "../../http/etag.ts"; | ||
| 13 | 13 | import { loadRepo, notFoundPage, repoBase } from "../chrome.ts"; |
| 14 | 14 | import { html } from "../html.ts"; |
| 15 | 15 | import { page } from "../layout.ts"; |
| 16 | import { btn } from "../ui.ts"; | |
| 16 | import { btn, row } from "../ui.ts"; | |
| 17 | 17 | import { factsCss, factsList, type Fact } from "../node_facts.ts"; |
| 18 | 18 | import { spaceCss, spaceJs } from "../space_client.ts"; |
| 19 | import { findBodies } from "../space_view.ts"; | |
| 19 | 20 | import { COLOUR_SAYS, DISTANCE_SAYS, SIZE_SAYS, STATES, STATE_LEGEND, type Region, type Space } from "../space_model.ts"; |
| 20 | 21 | import { spaceOf } from "../space_read.ts"; |
| 21 | 22 | |
| @@ -55,6 +56,9 @@ export function spacePage(ctx: Ctx): Response { | ||
| 55 | 56 | const base = repoBase(repo); |
| 56 | 57 | const space = timePhase(ctx.request, "space", () => spaceOf(ctx.app, repo, ctx.auth.user)); |
| 57 | 58 | const regions = space.regions as Region[]; |
| 59 | // ?q= is the finder without script: the matches as links, or the words that none match. | |
| 60 | const q = (ctx.url.searchParams.get("q") ?? "").trim().slice(0, 200); | |
| 61 | const hits = q ? findBodies(space.issues, q) : []; | |
| 58 | 62 | const rendering = performance.now(); |
| 59 | 63 | const response = page({ |
| 60 | 64 | ctx, |
| @@ -78,16 +82,20 @@ export function spacePage(ctx: Ctx): Response { | ||
| 78 | 82 | ${btn("Fit", { type: "button", id: "space-fit", variant: "outline", size: "sm" })} |
| 79 | 83 | ${btn("+", { type: "button", id: "space-in", label: "Zoom in", variant: "outline", size: "sm" })} |
| 80 | 84 | ${btn("−", { type: "button", id: "space-out", label: "Zoom out", variant: "outline", size: "sm" })} |
| 81 | <label class="sr-only" for="space-find">Find an issue by number or title</label> | |
| 82 | <input | |
| 83 | class="input" | |
| 84 | type="search" | |
| 85 | id="space-find" | |
| 86 | placeholder="Find an issue" | |
| 87 | autocomplete="off" | |
| 88 | maxlength="200" | |
| 89 | /> | |
| 90 | <span id="space-find-status" class="muted" role="status" aria-live="polite"></span> | |
| 85 | <form method="get" action="${base}/space" role="search" class="space-find-form"> | |
| 86 | <label class="sr-only" for="space-find">Find an issue by number or title</label> | |
| 87 | <input | |
| 88 | class="input" | |
| 89 | type="search" | |
| 90 | id="space-find" | |
| 91 | name="q" | |
| 92 | value="${q}" | |
| 93 | placeholder="Find an issue" | |
| 94 | autocomplete="off" | |
| 95 | maxlength="200" | |
| 96 | /> | |
| 97 | </form> | |
| 98 | <span id="space-find-status" class="muted" role="status" aria-live="polite">${q && !hits.length ? "No issue matches" : ""}</span> | |
| 91 | 99 | <span id="space-crew"></span> |
| 92 | 100 | </div> |
| 93 | 101 | <aside class="space-panel" id="space-panel" hidden></aside> |
| @@ -112,6 +120,12 @@ export function spacePage(ctx: Ctx): Response { | ||
| 112 | 120 | ${btn("Now", { type: "button", id: "space-now", variant: "outline", size: "sm" })} |
| 113 | 121 | </div> |
| 114 | 122 | </div> |
| 123 | ${q | |
| 124 | ? html`<section class="space-found" aria-label="Matches for ${q}"> | |
| 125 | <h2>${hits.length ? `${hits.length} ${hits.length === 1 ? "issue matches" : "issues match"} “${q}”` : `No issue matches “${q}”`}</h2> | |
| 126 | ${hits.slice(0, 50).map((r) => row({ href: `${base}/issues/${r[0]}`, title: `#${r[0]} ${r[6]}` }))} | |
| 127 | </section>` | |
| 128 | : ""} | |
| 115 | 129 | ${factsList(`Issues of ${repo.name}`, spaceFacts(space, base), true)} |
| 116 | 130 | <div class="space-list"> |
| 117 | 131 | <h1>${repo.name}</h1> |
src/web/space_client.ts +3 −2
| @@ -45,12 +45,13 @@ 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-find-form { display: contents; } | |
| 48 | 49 | .space-bar input[type=search] { width: 11rem; max-width: 40vw; } |
| 49 | 50 | .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; } |
| 50 | 51 | .space-panel[hidden] { display: none; } |
| 51 | 52 | .space-panel h2 { font-size: 1rem; margin: 0 0 .35rem; } |
| 52 | 53 | .space-panel .status-rows { margin-top: 0; border-top: 0; } |
| 53 | html.space-on .space-list { display: none; } | |
| 54 | html.space-on .space-list, html.space-on .space-found { display: none; } | |
| 54 | 55 | .space-legend { padding: 0 1rem; font-size: .85rem; } |
| 55 | 56 | .space-legend summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; } |
| 56 | 57 | .space-legend summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } |
| @@ -114,7 +115,7 @@ ${viewJs} | ||
| 114 | 115 | if (live) T = S.now; |
| 115 | 116 | slider.value = String(Math.round((T - S.weekStart) / 60000)); |
| 116 | 117 | crewChips(); |
| 117 | if (first) { resize(); fit(true); fromHash(); } | |
| 118 | if (first) { resize(); fit(true); fromHash(); if (finder && finder.value && !location.hash) find(); } | |
| 118 | 119 | if (picked) refreshPanel(); |
| 119 | 120 | dirty = true; |
| 120 | 121 | }) |
src/web/space_model.ts +3
| @@ -56,6 +56,9 @@ export const SIZE_SAYS = "Size: one square is one issue. A pillar's area follows | ||
| 56 | 56 | export const COLOUR_SAYS = "Colour: one ink. The stronger it is, the nearer the work is to moving."; |
| 57 | 57 | export const DISTANCE_SAYS = `Distance: a pillar's issues sit together, in this order: ${STATES.map((s) => STATE_LEGEND[s].label).join(", ")}.`; |
| 58 | 58 | |
| 59 | /** The legend in one line, for the terminal: the three sentences above, joined, not retyped. */ | |
| 60 | export const LEGEND_LINE = [SIZE_SAYS, COLOUR_SAYS, DISTANCE_SAYS].join(" "); | |
| 61 | ||
Principle 1: LEGEND_LINE restates SIZE_SAYS, COLOUR_SAYS and DISTANCE_SAYS in new words. Derive one from the other, or remove it. |
||
| 59 | 62 | export const DAY_MS = 86_400_000; |
| 60 | 63 | /** How far back the scrubber goes. */ |
| 61 | 64 | export const WEEK_MS = 7 * DAY_MS; |
test/space-page.test.ts +28
| @@ -136,3 +136,31 @@ test("the space says its issues in text: one tabbable link per issue drawn, capp | ||
| 136 | 136 | expect(body.match(/<details class="facts"[^>]*>/)![0]).not.toContain("open"); |
| 137 | 137 | expect(body.indexOf('<details class="facts"')).toBeLessThan(body.indexOf('class="space-list"')); |
| 138 | 138 | }); |
| 139 | ||
| 140 | test("?q= returns the matching bodies as links, and says when none match", async () => { | |
| 141 | const data = (await (await get("/keeper/forge/space.json")).json()) as { issues: any[][] }; | |
| 142 | const one = data.issues[0]!; | |
| 143 | const res = await get(`/keeper/forge/space?q=${encodeURIComponent("#" + one[0])}`); | |
| 144 | const body = await res.text(); | |
| 145 | expect(res.status).toBe(200); | |
| 146 | expect(body).toContain(`href="/keeper/forge/issues/${one[0]}"`); | |
| 147 | expect(body).toContain("space-found"); | |
| 148 | expect(body).toContain('name="q"'); | |
| 149 | const none = await (await get("/keeper/forge/space?q=zzqxnomatch")).text(); | |
| 150 | expect(none).toContain("No issue matches"); | |
| 151 | const xss = await (await get(`/keeper/forge/space?q=${encodeURIComponent('"><script>x</script>')}`)).text(); | |
| 152 | expect(xss).not.toContain("<script>x</script>"); | |
| 153 | }); | |
| 154 | ||
| 155 | test("the legend is said once, and the finder's list is hidden when the canvas runs", async () => { | |
| 156 | const body = await (await get("/keeper/forge/space")).text(); | |
| 157 | expect(body).not.toContain("space-legend-line"); | |
| 158 | expect(body.split("one square is one issue").length - 1).toBe(1); | |
| 159 | const { spaceCss } = await import("../src/web/space_client.ts"); | |
| 160 | expect(spaceCss).toContain("html.space-on .space-found { display: none; }"); | |
| 161 | }); | |
| 162 | ||
| 163 | test("with a query and no hash the script flies to the first match on load", async () => { | |
| 164 | const { spaceJs } = await import("../src/web/space_client.ts"); | |
| 165 | expect(spaceJs).toContain("finder && finder.value && !location.hash"); | |
| 166 | }); |
test/space-screen.test.ts +14
| @@ -42,3 +42,17 @@ test("foundLines: the first match's facts and link; no match says so", () => { | ||
| 42 | 42 | expect(foundLines(space, "#3", (n) => `/x/${n}`)[0]).toBe("#3 Shipped"); |
| 43 | 43 | expect(foundLines(space, "zzz", (n) => `/x/${n}`)).toEqual(["No issue matches"]); |
| 44 | 44 | }); |
| 45 | ||
| 46 | test("the terminal's space opens with the one-line legend the page shows", async () => { | |
| 47 | const { LEGEND_LINE } = await import("../src/web/space_model.ts"); | |
| 48 | const lines = spaceLines({ regions: [], clusters: [], states: [], issues: [], crew: [], now: 0 }, 200); | |
| 49 | expect(lines.slice(0, -1).join(" ").replace(/\s+/g, " ")).toContain(LEGEND_LINE); | |
| 50 | }); | |
| 51 | ||
| 52 | test("the legend line comes before the first region", async () => { | |
| 53 | const { LEGEND_LINE } = await import("../src/web/space_model.ts"); | |
| 54 | const space = { regions: [{ name: "Alpha", open: 1, ready: 0, landed: 0 }], clusters: [], states: [], issues: [], crew: [], now: 0 } as any; | |
| 55 | const text = spaceLines(space, 400).join("\n"); | |
| 56 | expect(text.indexOf(LEGEND_LINE)).toBeGreaterThanOrEqual(0); | |
| 57 | expect(text.indexOf(LEGEND_LINE)).toBeLessThan(text.indexOf("Alpha")); | |
| 58 | }); |
new above
offline
Principle 2: not hidden when html.space-on is set, unlike .space-list, so it can fight the full-screen canvas. Hide it with script on, or move the matches into the panel.