Public: anyone can read this; the crew can change it.

The terminal's Next up screen prints the chapter line the page prints #13279

Merged opened this

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

Merged

mason/forge:mason/13254-the-terminal-s-next-up-screen-prints-the → main 4 commits fork 2 threads · 2 unresolved

  • Merged. mason/13254-the-terminal-s-next-up-screen-prints-the was merged into main as 0fd342c.

Review

Sign in to review this change.
4 files changed +99 −10
docs/features/next-up.md +1 −1
@@ -15,7 +15,7 @@
1515
1616 **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.
1717
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).
1919
2020 **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.
2121
src/tui/screens/next.ts +15 −2
@@ -17,6 +17,7 @@ import { setPlannerSwitch } from "../../actions/planner_switch.ts";
1717 import { pauseAt, weekLine, type WeekLine } from "../../core/growth.ts";
1818 import { pauseSentence } from "../../core/planner_pause.ts";
1919 import { canAdmin, canRead, canWrite, type Repo } from "../../core/repos.ts";
20 import { listChapters } from "../../core/chapters.ts";
2021 import { pillarsOf, servedBy } from "../../core/pillars.ts";
2122 import { sealedScope } from "../../core/sealed.ts";
2223 import { notStartable } from "../../crew/not_startable.ts";
@@ -25,6 +26,7 @@ import { openPullStages } from "../../flow/read.ts";
2526 import type { Stage } from "../../flow/stage.ts";
2627 import { countWords, filtered, matches, readFilter, MAX_Q } from "../../web/pages/next_filter.ts";
2728 import { GROWTH_DAYS, growthWords } from "../../web/pages/next_growth.ts";
29 import { chapterText, chapterWords } from "../../web/pages/next_chapters.ts";
2830 import { stateWord } from "../../web/pages/next_state.ts";
2931 import type { Ctx, Screen } from "../app/app.ts";
3032 import { binding } from "../app/keys.ts";
@@ -36,7 +38,10 @@ import { issueScreen } from "./issue.ts";
3638 import { local } from "./where.ts";
3739 import { ListState, drawList, hitList, live, promptScreen, type ListRow } from "./common.ts";
3840
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 */
4045 const LIVE_KINDS = ["issue.ranked", "issue.opened", "issue.closed", "issue.reopened", "issue.blocked", "issue.unblocked"];
4146
4247 export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
@@ -48,6 +53,8 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
4853 let growing: { line: WeekLine; until: string | null } | undefined;
4954 let stages = new Map<number, Stage>();
5055 let loaded = false;
56 // The page's chapter line (#13254), from the same function.
57 let chapter: string | null = null;
5158 // The filter (#11867): a pillar (`P7`, `Later`) and/or words, as on the page. It hides rows
5259 // only; ranks and moves stay the whole list's.
5360 let asked = "";
@@ -62,6 +69,7 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
6269 away = 0;
6370 week = undefined;
6471 growing = undefined;
72 chapter = null;
6573 } else {
6674 const scope = sealedScope(f.db, repo, f.user);
6775 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 {
7078 week = weekView(f.db, repo.id, rows, new Date());
7179 const line = weekLine(f.db, repo, GROWTH_DAYS, new Date(), scope);
7280 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);
7383 stages = openPullStages(f.db, repo, scope, new Date(), new Set(rows.map((r) => r.issue.number)));
7484 }
7585 loaded = true;
@@ -193,7 +203,10 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
193203 },
194204 render(area, s) {
195205 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();

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.

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);
197210 const note = !loaded
198211 ? "Loading…"
199212 : rows.length === 0
src/web/pages/next_chapters.ts +27 −7
@@ -4,6 +4,7 @@
44 * are in its way; one closed in the last minute shows its receipt and an Undo. The acts are
55 * `actions/chapters.ts`.
66 */
7 import type { Database } from "bun:sqlite";
78 import { CLOSE_UNDO_MS, stopsClose, undoableClose } from "../../actions/chapters.ts";
89 import { itemsOf, progressOf, progressSentence, type Chapter } from "../../core/chapters.ts";
910 import { canAdmin, type Repo } from "../../core/repos.ts";
@@ -61,14 +62,33 @@ export function chaptersSection(ctx: Ctx, repo: Repo, back: string, all: readonl
6162 }
6263
6364 /**
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.
6687 */
6788 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;
6991 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>`;
7494 }
test/chapter-next.test.ts +56
@@ -68,3 +68,59 @@ test("/next names the open chapter and its progress sentence", async () => {
6868 expect(page).toContain('Ranked for <a href="/alice/shop/chapters/v1.1.0">v1.1.0</a>: 0 of 0 done.');
6969 expect(page).not.toContain("No chapter is open.");
7070 });
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);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs