Public: anyone can read this; the crew can change it.
The terminal's Next up screen prints the chapter line the page prints #13279
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13254-the-terminal-s-next-up-screen-prints-the → main 4 commits fork 2 threads · 2 unresolved
4 files
changed +99
−10
docs/features/next-up.md +1 −1
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | |
| 16 | 16 | **Filter (#11867):** a plain GET form above the list narrows `/next` to one pillar (`?pillar=P7` or `Later`, typed in a box) and/or a word (`?q=cache`, matched without regard to case, shown as typed, at most 80 characters). A filter only hides rows: each keeps its real place in the whole ranking, the cut line stays where the whole list puts it (drawn only between shown rows), and a move made under a filter moves in the whole order and returns to the same filter. A line says "N of M shown", and that the week's capacity bar is left out while filtered. An unknown or malformed pillar shows an empty list that says so. **Terminal:** `/` asks for a pillar and/or a word (`P7 cache`); an empty answer clears it; ranks, `t` `u` `d` `l` and the header count behave as on the page. |
| 17 | 17 | |
| 18 | **The chapter line (#12681):** under the title, once the repository has chapters, `Ranked for <open chapter>: <progress sentence>` (linked), or "No chapter is open" with a link to draft one; a repository that never drafted a chapter shows no line. The terminal's Next up screen does not show it yet. | |
| 18 | **The chapter line (#12681):** under the title, once the repository has chapters, `Ranked for <open chapter>: <progress sentence>` (linked), or "No chapter is open" with a link to draft one; a repository that never drafted a chapter shows no line. **Terminal:** the screen prints the same line under the title, from the same function (`chapterWords` in `web/pages/next_chapters.ts`) (#13254). | |
| 19 | 19 | |
| 20 | 20 | **The growth line (#12290):** under the title, two `dl` rows: *Week* (issues opened in the last seven days, who opened them, how many closed, and what is open now: "2 issues opened (2 by owner), 0 closed. 2 open (2 issues, 0 pulls).", #12867: one row, so the numbers are said once) and *Planner* (on, paused until a time in UTC, or paused until the owner switches it on). The owner (a person who administers the repository) also gets the switch in the Planner row: a button in a post form to the same `planner_switch` action as the queue page, sent back to `/next`, so the pause is one tap and the owner stays on the list. A reader sees both rows and no button. Both rows come from one read (`weekLine`, which also counts open issues and pulls and what opened and closed today), sealed issues left out for a viewer who may not see them. **Terminal:** Next up shows the same sentence (`growthWords`, `pauseSentence`) above the list, and the owner presses `p` to pause the planner until they switch it on, and `p` again to switch it on; for a reader and for an agent the key does nothing. |
| 21 | 21 |
src/tui/screens/next.ts +15 −2
| @@ -17,6 +17,7 @@ import { setPlannerSwitch } from "../../actions/planner_switch.ts"; | ||
| 17 | 17 | import { pauseAt, weekLine, type WeekLine } from "../../core/growth.ts"; |
| 18 | 18 | import { pauseSentence } from "../../core/planner_pause.ts"; |
| 19 | 19 | import { canAdmin, canRead, canWrite, type Repo } from "../../core/repos.ts"; |
| 20 | import { listChapters } from "../../core/chapters.ts"; | |
| 20 | 21 | import { pillarsOf, servedBy } from "../../core/pillars.ts"; |
| 21 | 22 | import { sealedScope } from "../../core/sealed.ts"; |
| 22 | 23 | import { notStartable } from "../../crew/not_startable.ts"; |
| @@ -25,6 +26,7 @@ import { openPullStages } from "../../flow/read.ts"; | ||
| 25 | 26 | import type { Stage } from "../../flow/stage.ts"; |
| 26 | 27 | import { countWords, filtered, matches, readFilter, MAX_Q } from "../../web/pages/next_filter.ts"; |
| 27 | 28 | import { GROWTH_DAYS, growthWords } from "../../web/pages/next_growth.ts"; |
| 29 | import { chapterText, chapterWords } from "../../web/pages/next_chapters.ts"; | |
| 28 | 30 | import { stateWord } from "../../web/pages/next_state.ts"; |
| 29 | 31 | import type { Ctx, Screen } from "../app/app.ts"; |
| 30 | 32 | import { binding } from "../app/keys.ts"; |
| @@ -36,7 +38,10 @@ import { issueScreen } from "./issue.ts"; | ||
| 36 | 38 | import { local } from "./where.ts"; |
| 37 | 39 | import { ListState, drawList, hitList, live, promptScreen, type ListRow } from "./common.ts"; |
| 38 | 40 | |
| 39 | /** What reorders or reshapes the list: a rank, or an issue opening, closing or changing what it waits for. */ | |
| 41 | /** | |
| 42 | * What reorders or reshapes the list: a rank, or an issue opening, closing or changing what it | |
| 43 | * waits for. | |
| 44 | */ | |
| 40 | 45 | const LIVE_KINDS = ["issue.ranked", "issue.opened", "issue.closed", "issue.reopened", "issue.blocked", "issue.unblocked"]; |
| 41 | 46 | |
| 42 | 47 | export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { |
| @@ -48,6 +53,8 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 48 | 53 | let growing: { line: WeekLine; until: string | null } | undefined; |
| 49 | 54 | let stages = new Map<number, Stage>(); |
| 50 | 55 | let loaded = false; |
| 56 | // The page's chapter line (#13254), from the same function. | |
| 57 | let chapter: string | null = null; | |
| 51 | 58 | // The filter (#11867): a pillar (`P7`, `Later`) and/or words, as on the page. It hides rows |
| 52 | 59 | // only; ranks and moves stay the whole list's. |
| 53 | 60 | let asked = ""; |
| @@ -62,6 +69,7 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 62 | 69 | away = 0; |
| 63 | 70 | week = undefined; |
| 64 | 71 | growing = undefined; |
| 72 | chapter = null; | |
| 65 | 73 | } else { |
| 66 | 74 | const scope = sealedScope(f.db, repo, f.user); |
| 67 | 75 | const next = nextUp(f.db, repo, scope, (ready) => notStartable(f.app, repo, ready, scope)); |
| @@ -70,6 +78,8 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 70 | 78 | week = weekView(f.db, repo.id, rows, new Date()); |
| 71 | 79 | const line = weekLine(f.db, repo, GROWTH_DAYS, new Date(), scope); |
| 72 | 80 | growing = { line, until: pauseAt(line, new Date()) }; |
| 81 | const words = chapterWords(f.db, listChapters(f.db, repo.id)); | |
| 82 | chapter = words === null ? null : chapterText(words); | |
| 73 | 83 | stages = openPullStages(f.db, repo, scope, new Date(), new Set(rows.map((r) => r.issue.number))); |
| 74 | 84 | } |
| 75 | 85 | loaded = true; |
| @@ -193,7 +203,10 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 193 | 203 | }, |
| 194 | 204 | render(area, s) { |
| 195 | 205 | const c = ctx.theme.c; |
| 196 | const [grow, head, list] = split(area, "v", [len(1), len(1), fill(1)]); | |
| 206 | const rects = split(area, "v", [...(chapter === null ? [] : [len(1)]), len(1), len(1), fill(1)]); | |
| 207 | const line = chapter === null ? undefined : rects.shift(); | |
| 208 | const [grow, head, list] = rects; | |
| 209 | if (line !== undefined && chapter !== null) s.text(line.x, line.y, truncate(chapter, line.w), style(c.fg, c.bg), line.x + line.w); | |
| 197 | 210 | const note = !loaded |
| 198 | 211 | ? "Loading…" |
| 199 | 212 | : rows.length === 0 |
src/web/pages/next_chapters.ts +27 −7
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * are in its way; one closed in the last minute shows its receipt and an Undo. The acts are |
| 5 | 5 | * `actions/chapters.ts`. |
| 6 | 6 | */ |
| 7 | import type { Database } from "bun:sqlite"; | |
| 7 | 8 | import { CLOSE_UNDO_MS, stopsClose, undoableClose } from "../../actions/chapters.ts"; |
| 8 | 9 | import { itemsOf, progressOf, progressSentence, type Chapter } from "../../core/chapters.ts"; |
| 9 | 10 | import { canAdmin, type Repo } from "../../core/repos.ts"; |
| @@ -61,14 +62,33 @@ export function chaptersSection(ctx: Ctx, repo: Repo, back: string, all: readonl | ||
| 61 | 62 | } |
| 62 | 63 | |
| 63 | 64 | /** |
| 64 | * The line under the /next heading: the open chapter and where it stands, or that none is open | |
| 65 | * once chapters exist. | |
| 65 | * What the chapter line says, in words both the page and the terminal print: the open chapter's | |
| 66 | * name (null when none is open) and the rest of the sentence. | |
| 67 | */ | |
| 68 | export interface ChapterWords { | |
| 69 | name: string | null; | |
| 70 | tail: string; | |
| 71 | } | |
| 72 | ||
| 73 | /** The words of the line under the /next heading, or null for a repository with no chapters. */ | |
| 74 | export function chapterWords(db: Database, all: readonly Chapter[]): ChapterWords | null { | |
| 75 | if (all.length === 0) return null; // no chapter, no change: a repo that never drafted one flows on | |
| 76 | const open = all.find((c) => c.state === "open"); | |
| 77 | if (open === undefined) return { name: null, tail: "No chapter is open." }; | |
| 78 | return { name: open.name, tail: progressSentence(progressOf(open, itemsOf(db, open), new Date())) }; | |
| 79 | } | |
| 80 | ||
| 81 | /** The line as plain text: the terminal's. */ | |
| 82 | export const chapterText = (w: ChapterWords): string => (w.name === null ? w.tail : `Ranked for ${w.name}: ${w.tail}`); | |
| 83 | ||
| 84 | /** | |
| 85 | * The line under the /next heading: the open chapter and where it stands, or that none is open once | |
| 86 | * chapters exist. | |
| 66 | 87 | */ |
| 67 | 88 | export function chapterLine(ctx: Ctx, repo: Repo, all: readonly Chapter[]): Html | null { |
| 68 | if (all.length === 0) return null; // no chapter, no change: a repo that never drafted one flows on | |
| 89 | const w = chapterWords(ctx.app.db, all); | |
| 90 | if (w === null) return null; | |
| 69 | 91 | const base = repoBase(repo); |
| 70 | const open = all.find((c) => c.state === "open"); | |
| 71 | if (open === undefined) return html`<p class="muted" data-chapter-line>No chapter is open. <a href="${base}/chapters">Draft one</a>.</p>`; | |
| 72 | const p = progressOf(open, itemsOf(ctx.app.db, open), new Date()); | |
| 73 | return html`<p data-chapter-line>Ranked for <a href="${base}/chapters/${encodeURIComponent(open.name)}">${open.name}</a>: ${progressSentence(p)}</p>`; | |
| 92 | if (w.name === null) return html`<p class="muted" data-chapter-line>${w.tail} <a href="${base}/chapters">Draft one</a>.</p>`; | |
| 93 | return html`<p data-chapter-line>Ranked for <a href="${base}/chapters/${encodeURIComponent(w.name)}">${w.name}</a>: ${w.tail}</p>`; | |
| 74 | 94 | } |
test/chapter-next.test.ts +56
| @@ -68,3 +68,59 @@ test("/next names the open chapter and its progress sentence", async () => { | ||
| 68 | 68 | expect(page).toContain('Ranked for <a href="/alice/shop/chapters/v1.1.0">v1.1.0</a>: 0 of 0 done.'); |
| 69 | 69 | expect(page).not.toContain("No chapter is open."); |
| 70 | 70 | }); |
| 71 | ||
| 72 | const terminalNext = async () => { | |
| 73 | const { chapterText, chapterWords } = await import("../src/web/pages/next_chapters.ts"); | |
| 74 | const { listChapters } = await import("../src/core/chapters.ts"); | |
| 75 | const { createForgeApp } = await import("../src/tui/forge.ts"); | |
| 76 | const { headlessTerminal } = await import("../src/tui/term/terminal.ts"); | |
| 77 | const { settleApp } = await import("./helpers/tui.ts"); | |
| 78 | const screenOf = async (slug: string) => { | |
| 79 | const terminal = headlessTerminal(140, 30); | |
| 80 | const { app: tui } = createForgeApp(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: owner }, { terminal, exitHooks: false }); | |
| 81 | tui.start(); | |
| 82 | const send = async (key: string, ctrl = false) => { | |
| 83 | tui.dispatch({ type: "key", key, ctrl, alt: false, shift: false }); | |
| 84 | await settleApp(tui); | |
| 85 | }; | |
| 86 | await settleApp(tui); | |
| 87 | await send("k", true); | |
| 88 | for (const ch of "Next up in a repository") await send(ch); | |
| 89 | await send("enter"); | |
| 90 | for (const ch of slug) await send(ch); | |
| 91 | await send("enter"); | |
| 92 | const text = tui.screen.toText(); | |
| 93 | tui.stop(); | |
| 94 | return text; | |
| 95 | }; | |
| 96 | const line = (slug: string) => { | |
| 97 | const r = getRepo(app.db, "alice", slug)!; | |
| 98 | const w = chapterWords(app.db, listChapters(app.db, r.id)); | |
| 99 | return w === null ? null : chapterText(w); | |
| 100 | }; | |
| 101 | return { screenOf, line }; | |
| 102 | }; | |
| 103 | ||
| 104 | test("the terminal's Next up prints the page's chapter line for an open chapter", async () => { | |
| 105 | const { screenOf, line } = await terminalNext(); | |
| 106 | const open = line("shop")!; | |
| 107 | expect(open).toStartWith("Ranked for v1.1.0: "); | |
| 108 | expect(await screenOf("alice/shop")).toContain(open); | |
| 109 | }, 30_000); | |
| 110 | ||
| 111 | test("the terminal's Next up prints the page's chapter line when none is open", async () => { | |
| 112 | const { screenOf, line } = await terminalNext(); | |
The screen is compared against chapterText(chapterWords()), the same function it prints, so this cannot catch the page and terminal drifting apart. Also compare against the text of the page's chapterLine output. |
||
| 113 | app.db.query("UPDATE chapter SET state = 'closed', closed_at = ?2, notes = 'n' WHERE repo_id = ?1 AND state = 'open'").run(repo.id, "2026-11-02T00:00:00.000Z"); | |
| 114 | expect(line("shop")).toBe("No chapter is open."); | |
| 115 | expect(await screenOf("alice/shop")).toContain("No chapter is open."); | |
| 116 | }, 30_000); | |
| 117 | ||
| 118 | test("the terminal's Next up prints no chapter line for a repository with no chapters", async () => { | |
| 119 | const { screenOf, line } = await terminalNext(); | |
| 120 | const c = await newApp(app, owner, { name: "bare", description: "Words", visibility: "public" }); | |
| 121 | if (!c.ok) throw new Error(String(c.error)); | |
| 122 | expect(line("bare")).toBeNull(); | |
| 123 | const bare = await screenOf("alice/bare"); | |
| 124 | expect(bare).not.toContain("Ranked for"); | |
| 125 | expect(bare).not.toContain("No chapter is open"); | |
| 126 | }, 30_000); |
new above
offline
Building a rect list and then mutating it with shift() is hard to read. Split into two explicit layouts (with or without the chapter row), or pass len(chapter === null ? 0 : 1) so the row collapses. Behaviour is fine.