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
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16071-the-since-you-were-here-digest-ends-with → main 0 commits fork 2 threads · 2 unresolved
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 | ||
| 10 | 10 | - The window starts at that time, at least 1 hour and at most 7 days. A first visit looks back 24 hours. |
| 11 | 11 | - Nothing landed in the window: no section. Private repositories are never read. |
| 12 | 12 | |
| 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 | ||
| 13 | 17 | ## The terminal |
| 14 | 18 | |
| 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". | |
| 16 | 20 | |
| 17 | 21 | ## MCP |
| 18 | 22 |
src/tui/screens/dashboard.ts +11 −3
| @@ -42,7 +42,8 @@ import { firstWeekText } from "../../web/first_week.ts"; | ||
| 42 | 42 | import { firstWrong, firstWrongText, readFacts } from "../../web/first_wrong.ts"; |
| 43 | 43 | import { lanePicture } from "../../flow/lanes.ts"; |
| 44 | 44 | 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"; | |
| 46 | 47 | import { askForSomething } from "./tell.ts"; |
| 47 | 48 | import { movingLines } from "./moving.ts"; |
| 48 | 49 | import { pipelineNow } from "../../web/studio/living.ts"; |
| @@ -458,7 +459,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 458 | 459 | |
| 459 | 460 | const loadSinceLines = (): void => { |
| 460 | 461 | 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)`]; | |
| 462 | 463 | quiet = f.user !== undefined && quietFor({ app: f.app }, f.user, d !== undefined); |
| 463 | 464 | ctx.invalidate(); |
| 464 | 465 | }; |
| @@ -1262,6 +1263,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1262 | 1263 | ...(clientNextSteps(f.user).some((s) => s.key === "i") ? [binding(["i"], "invite someone")] : []), |
| 1263 | 1264 | ] |
| 1264 | 1265 | : []), |
| 1266 | ...(sinceLines.length > 0 ? [binding(["v"], "feed link")] : []), | |
| 1265 | 1267 | ...(clientLive.size > 0 ? [binding(["o"], "open the app")] : []), |
| 1266 | 1268 | ...(exploring() && explored?.next != null |
| 1267 | 1269 | ? [binding(["n"], "more results")] |
| @@ -1327,7 +1329,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1327 | 1329 | body = rest!; |
| 1328 | 1330 | } |
| 1329 | 1331 | if (sinceLines.length > 0) { |
| 1330 | const lines = sinceLines.slice(0, 4); | |
| 1332 | const lines = sinceLines.slice(0, 5); | |
| 1331 | 1333 | const [strip, rest] = split(body, "v", [len(lines.length), fill(1)]); |
| 1332 | 1334 | lines.forEach((line, i) => |
| 1333 | 1335 | 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 { | ||
| 1560 | 1562 | if (repo && clientRepoIds.has(repo.id)) askForSomething(f, ctx, () => screen, repo); |
| 1561 | 1563 | return true; |
| 1562 | 1564 | } |
| 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 | } | |
| 1563 | 1571 | if (e.key === "w" && f.user && clientLines.length > 0 && !firstTell) { |
| 1564 | 1572 | ctx.push(changelogScreen(f, ctx)); |
| 1565 | 1573 | return true; |
src/web/studio/home.ts +1 −1
| @@ -394,7 +394,7 @@ export async function feedPage(ctx: Ctx): Promise<Response> { | ||
| 394 | 394 | const newer = timePhase(ctx.request, "new", () => newSince(ctx.app.db, user, before, visitedAt)); |
| 395 | 395 | const fresh = newLine(newer); |
| 396 | 396 | // 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)); | |
| 398 | 398 | // Milestones are only an input here: the feed does not draw them (#12328). |
| 399 | 399 | const quiet = isQuiet({ stalled: stalled !== null, milestones: biggestMilestones(ctx, appRepos).length > 0, landed: since !== null }); |
| 400 | 400 | 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"; | ||
| 10 | 10 | import { canRead, getRepoById, type Repo } from "../../core/repos.ts"; |
| 11 | 11 | import type { User } from "../../core/users.ts"; |
| 12 | 12 | 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"; | |
| 13 | 15 | import { html, type Html } from "../html.ts"; |
| 14 | 16 | import { listCard, row } from "../ui.ts"; |
| 15 | 17 | |
| @@ -121,6 +123,23 @@ export function feedDigest(db: Database, viewer: User, now: number): { heading: | ||
| 121 | 123 | return sinceDigest(db, viewer, visitOf(db, viewer.id), now) ?? null; |
| 122 | 124 | } |
| 123 | 125 | |
| 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 | ||
| 124 | 143 | /** |
| 125 | 144 | * The digest card; `fresh`, the new-post count's sentence, rides in its head so the page says it |
| 126 | 145 | * once. |
| @@ -131,11 +150,12 @@ export function sinceYouWere( | ||
| 131 | 150 | lastVisit: number | undefined, |
| 132 | 151 | now: number, |
| 133 | 152 | fresh: string | null = null, |
| 153 | params: URLSearchParams = new URLSearchParams(), | |
| 134 | 154 | ): Html | null { |
| 135 | 155 | const d = sinceDigest(db, viewer, lastVisit, now); |
| 136 | 156 | if (d === undefined) return null; |
| 137 | 157 | return listCard( |
| 138 | 158 | 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>`}` }, | |
| 140 | 160 | ); |
| 141 | 161 | } |
test/digest-doors.test.ts +10 −2
| @@ -9,7 +9,8 @@ import { createSession } from "../src/core/sessions.ts"; | ||
| 9 | 9 | import { createToken } from "../src/core/tokens.ts"; |
| 10 | 10 | import { createUser, type User } from "../src/core/users.ts"; |
| 11 | 11 | 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"; | |
| 13 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 14 | 15 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 15 | 16 | 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 | ||
| 80 | 81 | tui.start(); |
| 81 | 82 | await settleApp(tui); |
| 82 | 83 | const text = tui.screen.toText(); |
| 83 | tui.stop(); | |
| 84 | 84 | expect(text).toContain("Since you were here"); |
| 85 | 85 | 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(); | |
| 86 | 94 | }); |
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 | }); |
new above
offline
Fine on the web. Mirror it in the TUI dashboard digest (src/tui/screens/dashboard.ts:460) so both doors end the same way.