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

Merged opened this

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

Merged

torque/forge:torque/15591-space-has-a-legend-for-size-colour-and-d → main 0 commits fork 3 threads · 3 unresolved

  • Merged. torque/15591-space-has-a-legend-for-size-colour-and-d was merged into main as fc2839a.

Review

Sign in to review this change.
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
1616 - **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.
1717 - **Crew.** Their avatars sit on the issue they are working; tap one (or its name in the bar) to see what they are on.
1818 - **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.
1920 - **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.
2021
2122 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 @@
77
88 import type { Repo } from "../../core/repos.ts";
99 import { spaceOf } from "../../web/space_read.ts";
10 import { LEGEND_LINE } from "../../web/space_model.ts";
1011 import type { ClusterRow, IssueRow, Region, State } from "../../web/space_model.ts";
1112 import type { Ctx, Screen } from "../app/app.ts";
1213 import { binding } from "../app/keys.ts";
@@ -27,7 +28,7 @@ export function spaceLines(space: Record<string, unknown>, width = 80): string[]
2728 const issues = space.issues as IssueRow[];
2829 const crew = space.crew as { name: string; runs: [number, number, number][] }[];
2930 const now = space.now as number;
30 const out: string[] = [];
31 const out: string[] = [...wrap(LEGEND_LINE, w), ""];
3132 regions.forEach((r, ri) => {
3233 out.push(`${r.name} ${r.open} open, ${r.ready} ready, ${r.landed} landed this week${r.moving ? "" : ", still"}`);
3334 const by = new Map<State, IssueRow[]>();
src/web/pages/space.ts +25 −11
@@ -13,9 +13,10 @@ import { holds, weakEtag } from "../../http/etag.ts";
1313 import { loadRepo, notFoundPage, repoBase } from "../chrome.ts";
1414 import { html } from "../html.ts";
1515 import { page } from "../layout.ts";
16 import { btn } from "../ui.ts";
16 import { btn, row } from "../ui.ts";
1717 import { factsCss, factsList, type Fact } from "../node_facts.ts";
1818 import { spaceCss, spaceJs } from "../space_client.ts";
19 import { findBodies } from "../space_view.ts";
1920 import { COLOUR_SAYS, DISTANCE_SAYS, SIZE_SAYS, STATES, STATE_LEGEND, type Region, type Space } from "../space_model.ts";
2021 import { spaceOf } from "../space_read.ts";
2122
@@ -55,6 +56,9 @@ export function spacePage(ctx: Ctx): Response {
5556 const base = repoBase(repo);
5657 const space = timePhase(ctx.request, "space", () => spaceOf(ctx.app, repo, ctx.auth.user));
5758 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) : [];
5862 const rendering = performance.now();
5963 const response = page({
6064 ctx,
@@ -78,16 +82,20 @@ export function spacePage(ctx: Ctx): Response {
7882 ${btn("Fit", { type: "button", id: "space-fit", variant: "outline", size: "sm" })}
7983 ${btn("+", { type: "button", id: "space-in", label: "Zoom in", variant: "outline", size: "sm" })}
8084 ${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>
9199 <span id="space-crew"></span>
92100 </div>
93101 <aside class="space-panel" id="space-panel" hidden></aside>
@@ -112,6 +120,12 @@ export function spacePage(ctx: Ctx): Response {
112120 ${btn("Now", { type: "button", id: "space-now", variant: "outline", size: "sm" })}
113121 </div>
114122 </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>
outdated

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.

126 ${hits.slice(0, 50).map((r) => row({ href: `${base}/issues/${r[0]}`, title: `#${r[0]} ${r[6]}` }))}
127 </section>`
128 : ""}
115129 ${factsList(`Issues of ${repo.name}`, spaceFacts(space, base), true)}
116130 <div class="space-list">
117131 <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;
4545 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%); }
4646 .space-time input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
4747 .space-time output { font-variant-numeric: tabular-nums; min-width: 9ch; text-align: right; }
48 .space-find-form { display: contents; }
4849 .space-bar input[type=search] { width: 11rem; max-width: 40vw; }
4950 .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; }
5051 .space-panel[hidden] { display: none; }
5152 .space-panel h2 { font-size: 1rem; margin: 0 0 .35rem; }
5253 .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; }
5455 .space-legend { padding: 0 1rem; font-size: .85rem; }
5556 .space-legend summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
5657 .space-legend summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@@ -114,7 +115,7 @@ ${viewJs}
114115 if (live) T = S.now;
115116 slider.value = String(Math.round((T - S.weekStart) / 60000));
116117 crewChips();
117 if (first) { resize(); fit(true); fromHash(); }
118 if (first) { resize(); fit(true); fromHash(); if (finder && finder.value && !location.hash) find(); }
118119 if (picked) refreshPanel();
119120 dirty = true;
120121 })
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
5656 export const COLOUR_SAYS = "Colour: one ink. The stronger it is, the nearer the work is to moving.";
5757 export const DISTANCE_SAYS = `Distance: a pillar's issues sit together, in this order: ${STATES.map((s) => STATE_LEGEND[s].label).join(", ")}.`;
5858
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.

5962 export const DAY_MS = 86_400_000;
6063 /** How far back the scrubber goes. */
6164 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
136136 expect(body.match(/<details class="facts"[^>]*>/)![0]).not.toContain("open");
137137 expect(body.indexOf('<details class="facts"')).toBeLessThan(body.indexOf('class="space-list"'));
138138 });
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", () => {
4242 expect(foundLines(space, "#3", (n) => `/x/${n}`)[0]).toBe("#3 Shipped");
4343 expect(foundLines(space, "zzz", (n) => `/x/${n}`)).toEqual(["No issue matches"]);
4444 });
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs