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

The "Since you were here" digest ends with a link to the feed that keeps the active filter #16084

Merged opened this

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

Merged

torque/forge:torque/16071-the-since-you-were-here-digest-ends-with → main 0 commits fork 2 threads · 2 unresolved

  • Merged. torque/16071-the-since-you-were-here-digest-ends-with was merged into main as 9168e2e.

Review

Sign in to review this change.
6 files changed +106 −8
docs/features/since-you-were-here.md +5 −1
@@ -10,9 +10,13 @@ Home shows a digest headed `Since you were here · 2 days`: the pulls that lande
1010 - The window starts at that time, at least 1 hour and at most 7 days. A first visit looks back 24 hours.
1111 - Nothing landed in the window: no section. Private repositories are never read.
1212
13 ## The way on
14
15 The digest ends with one link, **All of it in the feed**, to `/feed`. It keeps the filter the page was opened with: `?show=` (`mine`, as `feed/mine` parses it) and `?app=` (a valid app name) are carried over, anything else is dropped, so `/feed?show=mine&app=garden` links to itself. No digest, no link.
16
1317 ## The terminal
1418
15 The terminal's home (`ssh`, the dashboard) shows the same lines under the same heading, read from the same `home_visit` row. The terminal only reads it: opening home on the web is what moves "since you were here".
19 The terminal's home (`ssh`, the dashboard) shows the same lines under the same heading, read from the same `home_visit` row. It ends with the same words, `All of it in the feed (v)`; `v` shows the address of `/feed` to open or copy. The terminal's filter is its chips (`1`-`4`, `h`), kept per person and read by the feed, so that link carries no query. The terminal only reads it: opening home on the web is what moves "since you were here".
1620
1721 ## MCP
1822
src/tui/screens/dashboard.ts +11 −3
@@ -42,7 +42,8 @@ import { firstWeekText } from "../../web/first_week.ts";
4242 import { firstWrong, firstWrongText, readFacts } from "../../web/first_wrong.ts";
4343 import { lanePicture } from "../../flow/lanes.ts";
4444 import { startedFromText } from "../../web/started_from.ts";
45 import { sinceDigest } from "../../web/studio/since.ts";
45 import { publicOrigin } from "../../core/public_origin.ts";
46 import { FEED_MORE, sinceDigest } from "../../web/studio/since.ts";
4647 import { askForSomething } from "./tell.ts";
4748 import { movingLines } from "./moving.ts";
4849 import { pipelineNow } from "../../web/studio/living.ts";
@@ -458,7 +459,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
458459
459460 const loadSinceLines = (): void => {
460461 const d = f.user ? sinceDigest(f.app.db, f.user, lastVisit(f.app.db, f.user.id), Date.now()) : undefined;
461 sinceLines = d === undefined ? [] : [d.heading, ...d.lines.map((l) => ` ${l.says}`)];
462 sinceLines = d === undefined ? [] : [d.heading, ...d.lines.map((l) => ` ${l.says}`), ` ${FEED_MORE} (v)`];
462463 quiet = f.user !== undefined && quietFor({ app: f.app }, f.user, d !== undefined);
463464 ctx.invalidate();
464465 };
@@ -1262,6 +1263,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
12621263 ...(clientNextSteps(f.user).some((s) => s.key === "i") ? [binding(["i"], "invite someone")] : []),
12631264 ]
12641265 : []),
1266 ...(sinceLines.length > 0 ? [binding(["v"], "feed link")] : []),
12651267 ...(clientLive.size > 0 ? [binding(["o"], "open the app")] : []),
12661268 ...(exploring() && explored?.next != null
12671269 ? [binding(["n"], "more results")]
@@ -1327,7 +1329,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
13271329 body = rest!;
13281330 }
13291331 if (sinceLines.length > 0) {
1330 const lines = sinceLines.slice(0, 4);
1332 const lines = sinceLines.slice(0, 5);
13311333 const [strip, rest] = split(body, "v", [len(lines.length), fill(1)]);
13321334 lines.forEach((line, i) =>
13331335 s.text(strip!.x, strip!.y + i, truncate(line, strip!.w), style(i === 0 ? c.mutedFg : c.fg, c.bg), strip!.x + strip!.w),
@@ -1560,6 +1562,12 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
15601562 if (repo && clientRepoIds.has(repo.id)) askForSomething(f, ctx, () => screen, repo);
15611563 return true;
15621564 }
1565 if (e.key === "v" && sinceLines.length > 0) {
1566 // The terminal's filter is the chips, kept per person and read by the feed itself; the link
1567 // carries none.
1568 ctx.push(linkScreen(ctx, `${publicOrigin(f.app.config.url, `http://localhost:${f.app.config.port}`)}/feed`, screen));
1569 return true;
1570 }
15631571 if (e.key === "w" && f.user && clientLines.length > 0 && !firstTell) {
15641572 ctx.push(changelogScreen(f, ctx));
15651573 return true;
src/web/studio/home.ts +1 −1
@@ -394,7 +394,7 @@ export async function feedPage(ctx: Ctx): Promise<Response> {
394394 const newer = timePhase(ctx.request, "new", () => newSince(ctx.app.db, user, before, visitedAt));
395395 const fresh = newLine(newer);
396396 // One sentence, once: the count rides in the digest's head; with no digest it stands alone.
397 const since = timePhase(ctx.request, "since", () => sinceYouWere(ctx.app.db, user, before, visitedAt, fresh));
397 const since = timePhase(ctx.request, "since", () => sinceYouWere(ctx.app.db, user, before, visitedAt, fresh, ctx.url.searchParams));

Fine on the web. Mirror it in the TUI dashboard digest (src/tui/screens/dashboard.ts:460) so both doors end the same way.

398398 // Milestones are only an input here: the feed does not draw them (#12328).
399399 const quiet = isQuiet({ stalled: stalled !== null, milestones: biggestMilestones(ctx, appRepos).length > 0, landed: since !== null });
400400 const body = html`<h1 class="sr-only">Feed</h1>
src/web/studio/since.ts +21 −1
@@ -10,6 +10,8 @@ import { lastVisit as visitOf } from "../../core/home_visit.ts";
1010 import { canRead, getRepoById, type Repo } from "../../core/repos.ts";
1111 import type { User } from "../../core/users.ts";
1212 import { digest, headingOf, windowOf, type DigestEvent, type DigestLine } from "../../feed/digest.ts";
outdated

Import order: put feed/app_filter and feed/mine after feed/digest. Also drop the unused data-digest-more attribute on the link.

13 import { isAppName } from "../../feed/app_filter.ts";
14 import { parseShow } from "../../feed/mine.ts";
1315 import { html, type Html } from "../html.ts";
1416 import { listCard, row } from "../ui.ts";
1517
@@ -121,6 +123,23 @@ export function feedDigest(db: Database, viewer: User, now: number): { heading:
121123 return sinceDigest(db, viewer, visitOf(db, viewer.id), now) ?? null;
122124 }
123125
126 /** The words the digest ends with, on the web and in the terminal. */
127 export const FEED_MORE = "All of it in the feed";
128
129 /**
130 * The feed, keeping the filter the page was opened with (`?show=`, `?app=`); both are validated
131 * here.
132 */
133 export function feedLink(params: URLSearchParams): string {
134 const q = new URLSearchParams();
135 const show = parseShow(params.get("show"));
136 if (show !== undefined) q.set("show", show);
137 const app = params.get("app") ?? "";
138 if (isAppName(app)) q.set("app", app);
139 const text = q.toString();
140 return text === "" ? "/feed" : `/feed?${text}`;
141 }
142
124143 /**
125144 * The digest card; `fresh`, the new-post count's sentence, rides in its head so the page says it
126145 * once.
@@ -131,11 +150,12 @@ export function sinceYouWere(
131150 lastVisit: number | undefined,
132151 now: number,
133152 fresh: string | null = null,
153 params: URLSearchParams = new URLSearchParams(),
134154 ): Html | null {
135155 const d = sinceDigest(db, viewer, lastVisit, now);
136156 if (d === undefined) return null;
137157 return listCard(
138158 d.lines.map((l) => row({ title: html`${l.says}`, href: l.href, nav: true })),
139 { id: "since-you-were-here", head: html`<h2>${d.heading}</h2>${fresh === null ? null : html`<p id="feed-new" class="small muted" role="status">${fresh}</p>`}` },
159 { id: "since-you-were-here", foot: html`<a href="${feedLink(params)}">${FEED_MORE}</a>`, head: html`<h2>${d.heading}</h2>${fresh === null ? null : html`<p id="feed-new" class="small muted" role="status">${fresh}</p>`}` },
140160 );
141161 }
test/digest-doors.test.ts +10 −2
@@ -9,7 +9,8 @@ import { createSession } from "../src/core/sessions.ts";
99 import { createToken } from "../src/core/tokens.ts";
1010 import { createUser, type User } from "../src/core/users.ts";
1111 import { lastVisit } from "../src/core/home_visit.ts";
12 import { sinceDigest } from "../src/web/studio/since.ts";
12 import { publicOrigin } from "../src/core/public_origin.ts";
13 import { FEED_MORE, sinceDigest } from "../src/web/studio/since.ts";
1314 import { serve, type Servers } from "../src/http/server.ts";
1415 import { createForgeApp } from "../src/tui/forge.ts";
1516 import { headlessTerminal } from "../src/tui/term/terminal.ts";
@@ -80,7 +81,14 @@ test("web, terminal and MCP give identical digest lines for one seeded forge", a
8081 tui.start();
8182 await settleApp(tui);
8283 const text = tui.screen.toText();
83 tui.stop();
8484 expect(text).toContain("Since you were here");
8585 for (const l of lines) expect(text).toContain(l.says);
86 // Both doors end the same way: the web's link, the terminal's line and the key that shows its
87 // address.
88 expect(page).toContain(`${FEED_MORE}</a>`);
89 expect(text).toContain(`${FEED_MORE} (v)`);
90 terminal.feed("v");
91 await settleApp(tui);
92 expect(tui.screen.toText()).toContain(`${publicOrigin(app.config.url, `http://localhost:${app.config.port}`)}/feed`);
93 tui.stop();
8694 });
test/feed-digest-more.test.ts added +58
@@ -0,0 +1,58 @@
1 /**
2 * The digest ends with one link to the feed that keeps the page's filter; no digest, no link; three
3 * lines at most.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { createRepo } from "../src/actions/repos.ts";
7 import { DIGEST_LINES } from "../src/feed/digest.ts";
8 import { feedLink, sinceYouWere } from "../src/web/studio/since.ts";
9 import { snappyFixture, type SnappyFixture } from "../bench/snappy.ts";
10
11 const H = 3600 * 1000;
12 let f: SnappyFixture;
13 beforeAll(async () => {
14 f = await snappyFixture();
15 }, 120_000);
16 afterAll(async () => {
17 await f.close();
18 });
19
20 test("feedLink keeps a valid filter, escapes nothing it did not validate", () => {
21 expect(feedLink(new URLSearchParams())).toBe("/feed");
22 expect(feedLink(new URLSearchParams("show=mine&app=a/b"))).toBe("/feed?show=mine&app=a%2Fb");
23 expect(feedLink(new URLSearchParams("show=x&app=%22%3E%3Cscript%3E"))).toBe("/feed");
24 });
25
26 test("the digest links to the feed with the filter, once; with no digest there is no link; the cap holds", async () => {
27 const db = f.app.db;
28 const pub = f.repos.find((r) => r.visibility === "public")!;
29 const get = async (q: string) =>
30 (await (await fetch(`${f.base}/feed?all=1${q}`, { headers: { cookie: f.ownerCookie } })).text());
31 db.query("DELETE FROM pull WHERE issue_id LIKE 'more-%'").run();
32 db.query("DELETE FROM issue WHERE id LIKE 'more-%'").run();
33 const setVisit = () =>
34 db.query("INSERT INTO home_visit (user_id, at) VALUES (?1, ?2) ON CONFLICT(user_id) DO UPDATE SET at = excluded.at").run(f.owner.id, Date.now() - 3 * H);
35 setVisit();
36 const later = Date.parse("2100-01-01T00:00:00Z");
37 expect(sinceYouWere(db, f.owner, later - 3 * H, later)).toBeNull();
38 db.query("INSERT INTO issue (id, repo_id, number, kind, title, author_id) VALUES ('more-1', ?1, 9501, 'pull', 't', ?2)").run(pub.id, f.owner.id);
39 db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES ('more-1', 'main', 'h', 'a', 'b', ?1)").run(new Date(Date.now() - H).toISOString());
40 // The digest groups by repository: four repositories, four groups, three shown.
41 for (let n = 2; n <= 4; n++) {
42 const made = await createRepo(f.app, f.owner, { name: `more-${n}`, visibility: "public" });
43 if (!made.ok) throw new Error("repo");
44 db.query("INSERT INTO issue (id, repo_id, number, kind, title, author_id) VALUES (?1, ?2, ?3, 'pull', 't', ?4)").run(`more-${n}`, made.value.id, 1, f.owner.id);
45 db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'h', 'a', 'b', ?2)").run(`more-${n}`, new Date(Date.now() - n * 60_000).toISOString());
46 }
47 setVisit();
48 const text = await get("&show=mine");
49 expect(text).toContain("All of it in the feed");
50 expect(text.match(/All of it in the feed/g)).toHaveLength(1);
51 expect(text).toContain('href="/feed?show=mine"');
52 const card = text.slice(text.indexOf('id="since-you-were-here"'));
53 const lines = card.slice(0, card.indexOf("card-foot")).match(/<li\b/g) ?? [];
54 // Four events seeded: exactly the cap, then the one link.
55 expect(DIGEST_LINES).toBe(3);
56 expect(lines).toHaveLength(3);
57 expect(text).not.toContain("data-digest-more");
58 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs