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

The home feed has three one-tap filters, Crew, Mine and Ships, kept in the URL #14091

Merged opened this

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

Merged

scout/forge:scout/14047-the-home-feed-has-three-one-tap-filters → main 6 commits fork 4 threads · 4 unresolved

  • Merged. scout/14047-the-home-feed-has-three-one-tap-filters was merged into main as 4b1842f.

Review

Sign in to review this change.
8 files changed +254 −31
docs/features/README.md +1
@@ -36,6 +36,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md).
3636 - [Engine shape](engine-shape.md)
3737 - [Feed fold](feed-fold.md)
3838 - [Filter the feed by one app](feed-app-filter.md)
39 - [Narrow the feed to crew, yours or ships](feed-filters.md)
3940 - [Questions on an issue](question.md)
4041 - [A feed post has a permalink](feed-permalink.md)
4142 - [A run post opens its log](feed-run-log.md)
docs/features/feed-filters.md added +23
@@ -0,0 +1,23 @@
1 # Feed filters: Crew, Mine and Ships
2
3 This page is for anyone who reads the home feed. Three one-tap filters narrow it to the part you want. They work on the page and in the terminal, with the same rules.
4
5 ## On the page
6
7 Open `/feed`. Under the heading there are three buttons: **Crew**, **Mine**, **Ships**.
8
9 - **Crew**: what agents did (a pull opened, a reply, a run).
10 - **Mine**: your own posts, replies to them, and what agents did on your repositories.
11 - **Ships**: what landed: a pull merged, an app serving a new version, a release step.
12
13 Tap one to narrow the feed. The button that is on is outlined. Tap it again to clear it. The choice is in the address (`/feed?show=ships`), so you can bookmark or share it. An unknown `show` value shows the whole feed.
14
15 The filter only narrows what you may already read. A repository you cannot read never shows, whatever the filter.
16
17 ## In the terminal
18
19 Open the feed from the palette. Press `c` for Crew, `m` for Mine, `s` for Ships. Press the same key again to clear it. `t` goes back to the ranked feed. The keys line at the bottom says which is on.
20
21 ## What it does not do
22
23 One filter at a time. It does not combine with `?app=`: choosing an app shows that app's posts unfiltered.
src/feed/mine.ts +23 −1
@@ -13,7 +13,7 @@ import { getIssuesByNumbers, numberKey } from "../core/issues.ts";
1313 import { getUsersByIds, type User } from "../core/users.ts";
1414
1515 /** The values `?show=` takes; anything else is no filter. */
16 export const SHOW_VALUES = ["mine"] as const;
16 export const SHOW_VALUES = ["crew", "mine", "ships"] as const;
1717 export type Show = (typeof SHOW_VALUES)[number];
1818
1919 export function parseShow(raw: string | null): Show | undefined {
@@ -61,3 +61,25 @@ export function mineFilter(
6161 return false;
6262 };
6363 }
64
65 /** What lands: a pull merged, an app serving a new version, a release step. */
66 export const SHIPS = /^(pull\.merged|app\.serving|release\..+)$/;
67
68 /** Crew: what an agent did, wherever the viewer may read it. */
69 function crewFilter(db: Database, events: readonly ForgeEvent[]): (e: ForgeEvent) => boolean {
70 const actors = getUsersByIds(db, events.flatMap((e) => (e.actorId === null ? [] : [e.actorId])));
71 return (e) => e.actorId !== null && actors.get(e.actorId)?.kind === "agent";
72 }
73
74 /** The predicate for one `?show=` value over a batch of events the viewer may already read. */
75 export function showFilter(
76 db: Database,
77 viewer: User,
78 show: Show,
79 events: readonly ForgeEvent[],
80 repos: ReadonlyMap<string, Repo>,
81 ): (e: ForgeEvent) => boolean {
82 if (show === "mine") return mineFilter(db, viewer, events, repos);
83 if (show === "crew") return crewFilter(db, events);
84 return (e) => SHIPS.test(e.kind);
85 }
src/feed/timeline.ts +4 −4
@@ -27,7 +27,7 @@ import type { User } from "../core/users.ts";
2727 import { chipHides } from "./chips.ts";
2828 import { decorate, FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX } from "./feed.ts";
2929 import { eventCandidates } from "./items.ts";
30 import { mineFilter } from "./mine.ts";
30 import { showFilter, type Show } from "./mine.ts";
3131 import { ago, type FeedItem } from "./rank.ts";
3232
3333 /** `before=now` starts at the newest post. */
@@ -53,8 +53,8 @@ export function readTimeline(
5353 limit?: number;
5454 now?: number;
5555 chips?: Chips;
56 /** Only the viewer's own (`mine.ts`). */
57 mine?: boolean;
56 /** One of the one-tap filters (`mine.ts`): crew, mine or ships. */
57 show?: Show;
5858 phase?: (name: string, ms: number) => void;
5959 } = {},
outdated

Two options for one idea. Remove mine and move its callers to show.

6060 ): { items: FeedItem[]; next_cursor: string | null } {
@@ -79,7 +79,7 @@ export function readTimeline(
7979 more = batch.length === BATCH;
8080 const heard = batch.filter(audienceFilter(db, viewer, batch));
8181 const repos = getReposByIds(db, heard.map((e) => e.repoId!));
82 const own = options.mine === true ? mineFilter(db, viewer, heard, repos) : undefined;
82 const own = options.show === undefined ? undefined : showFilter(db, viewer, options.show, heard, repos);
8383 const kept = own === undefined ? heard : heard.filter(own);
8484 for (const c of eventCandidates(db, viewer, now, kept, repos)) {
8585 if (chipHides(chips, c) || dismissed.has(c.id) || muted.has(c.repoId)) continue;
src/tui/screens/feed.ts +20 −15
@@ -11,10 +11,11 @@
1111 * (`likedByLine`, the page's line, gated by `feed/feed.ts`). `p` says the post's permalink
1212 * (`permalinkOf`, the page's time link) in a toast. `o` opens the log of the run a run post is
1313 * about, the page's headline link (`runTarget`). Twenty posts at a time; `t` switches to every
14 * post, newest first (`readTimeline`); `m` narrows that to only mine (its `mine` option, the page's
15 * `?show=mine`); `a` shows only the app of the post under the cursor, through the page's
16 * `appFilterOf` (`?app=`), and a second `a` shows every app again; `n` reads the next page from the
17 * cursor the last returned.
14 * post, newest first (`readTimeline`); `c`, `m` and `s` narrow that to the crew's posts, only mine,
15 * or only what shipped (its `show` option, the page's `?show=crew|mine|ships`; a second press
16 * clears it); `a` shows only the app of the post under the cursor, through the page's `appFilterOf`
17 * (`?app=`), and a second `a` shows every app again; `n` reads the next page from the cursor the
18 * last returned.
1819 */
1920
2021 import { addCommentThrough } from "../../actions/issues.ts";
@@ -23,6 +24,7 @@ import { lastVisit } from "../../core/home_visit.ts";
2324 import { newLine, newSince } from "../../feed/last_seen.ts";
2425 import { appFilterOf } from "../../feed/app_filter.ts";
2526 import { parseCursor, readFeed } from "../../feed/feed.ts";
27 import type { Show } from "../../feed/mine.ts";
2628 import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts";
2729 import type { FeedItem } from "../../feed/rank.ts";
2830 import { readInteraction } from "../../feed/interact.ts";
@@ -69,18 +71,18 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
6971 let next: string | null = null;
7072 // `t`: the log newest first, deeper than the ranked page reaches (the page's `?before=now`).
7173 let timeline = false;
72 // `m`: only mine (`feed/mine.ts`), the page's `?show=mine`; read as the timeline is.
73 let mine = false;
74 // `c`, `m`, `s`: one of the page's `?show=` filters (`feed/mine.ts`); read as the timeline is.
75 let show: Show | undefined;
7476 // `a`: one app's posts (`feed/app_filter.ts`), the page's `?app=`; the ranked page, as there.
7577 let only: { repoId: string; app: string } | undefined;
7678
7779 const read = (cursor?: string): void => {
7880 if (f.user === undefined) return;
79 if (only === undefined && (timeline || mine)) {
81 if (only === undefined && (timeline || show !== undefined)) {
8082 const from = parseBefore(cursor ?? TIMELINE_START);
8183 const page = readTimeline(f.db, f.user, {
8284 limit: PAGE,
83 ...(mine ? { mine: true } : {}),
85 ...(show === undefined ? {} : { show }),
8486 ...(from?.id === undefined ? {} : { before: from.id }),
8587 });
8688 items.push(...page.items);
@@ -200,8 +202,10 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
200202 ? [binding(["o"], "open the log")]
201203 : []),
202204 ...(next === null ? [] : [binding(["n"], "next page")]),
203 binding(["t"], timeline || mine ? "ranked" : "newest first"),
204 binding(["m"], mine ? "everyone's" : "only mine"),
205 binding(["t"], timeline || show !== undefined ? "ranked" : "newest first"),
206 binding(["c"], show === "crew" ? "everyone's" : "only crew"),
207 binding(["m"], show === "mine" ? "everyone's" : "only mine"),
208 binding(["s"], show === "ships" ? "everyone's" : "only ships"),
205209 ...(only !== undefined || items[state.index] !== undefined ? [binding(["a"], only === undefined ? "only this app" : "every app")] : []),
206210 binding(["esc", "q"], "back"),
207211 ];
@@ -267,12 +271,13 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
267271 else if (e.key === "h") showHistory();
268272 else if (e.key === "p") permalink();
269273 else if (e.key === "o") openLog();
270 else if (e.key === "t" || e.key === "m") {
274 else if (e.key === "t" || e.key === "c" || e.key === "m" || e.key === "s") {
271275 only = undefined;
272 if (e.key === "m") mine = !mine;
276 const pick = e.key === "c" ? "crew" : e.key === "m" ? "mine" : e.key === "s" ? "ships" : undefined;
277 if (pick !== undefined) show = show === pick ? undefined : pick;
273278 else {
274 timeline = mine ? false : !timeline;
275 mine = false;
279 timeline = show !== undefined ? false : !timeline;
280 show = undefined;
276281 }
277282 items.length = 0;
278283 state.index = 0;
@@ -284,7 +289,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen {
284289 if (only === undefined && found?.kind !== "app") return true;
285290 only = found?.kind === "app" ? { repoId: found.repo.id, app: found.app } : undefined;
286291 timeline = false;
287 mine = false;
292 show = undefined;
288293 items.length = 0;
289294 state.index = 0;
290295 state.offset = 0;
src/web/studio/feed.ts +16 −10
@@ -19,7 +19,7 @@ import { placementsOf, type Placement } from "../../core/placements.ts";
1919 import { recentThoughts, type Thought } from "../../core/thoughts.ts";
2020 import { appFilterOf, APP_UNKNOWN_LINE, type AppFilter } from "../../feed/app_filter.ts";
2121 import { parseCursor, readFeedPage } from "../../feed/feed.ts";
22 import { parseShow, type Show } from "../../feed/mine.ts";
22 import { parseShow, SHOW_VALUES, type Show } from "../../feed/mine.ts";
2323 import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts";
2424 import type { FeedItem } from "../../feed/rank.ts";
2525 import { permalinkOf, replyPath, replyRepo, threadOf } from "../../feed/reply.ts";
@@ -373,15 +373,21 @@ function chipsBar(user: User, ctx: Ctx, items: readonly FeedItem[]): Html {
373373 </div>`;
374374 }
375375
376 const SHOW_LABEL: Record<Show, string> = { crew: "Crew", mine: "Mine", ships: "Ships" };
377
376378 /**
377 * Mine: a plain link that toggles `?show=mine`; the page says which is on
378 * (`aria-current`, "Mine ✓"); the chip is the one signal. No script.
379 * Crew, Mine, Ships: three plain links, each `?show=<it>`; the one on says `aria-current` and
380 * takes the outlined button, and links to the bare feed, so a second tap clears it. The text is
381 * the same on or off and ghost and outline buttons share one border box, so no chip changes width
382 * and nothing moves. A `<nav>`, so a screen reader announces the group. No script.
379383 */
outdated

Both doors: add the same three filters to src/tui/. Also, aria-label on a bare <p> is poorly supported; use a <nav aria-label=...> so screen readers announce the group.

380 function mineChip(show: Show | undefined): Html {
381 const on = show === "mine";
382 return html`<p class="bar small" data-show="${on ? "mine" : "all"}">
383 <a class="btn" data-variant="ghost" data-size="sm" href="${on ? "/feed" : "/feed?show=mine"}" ${on ? html`aria-current="true"` : html``}>${on ? "Mine ✓" : "Mine"}</a>
384 </p>`;
384 function showChips(show: Show | undefined): Html {
385 return html`<nav class="bar small" data-show="${show ?? "all"}" aria-label="Narrow the feed">
386 ${SHOW_VALUES.map((v) => {
387 const on = show === v;
outdated

Principle 3/6 and layout: the tick text changes this chip's width and shifts the others. Keep the width fixed.

388 return html`<a class="btn" data-variant="${on ? "outline" : "ghost"}" data-size="sm" data-show-chip="${v}" href="${on ? "/feed" : `/feed?show=${v}`}" ${on ? html`aria-current="true"` : html``}>${SHOW_LABEL[v]}</a>`;
389 })}
390 </nav>`;
385391 }
386392
387393 /**
@@ -427,7 +433,7 @@ function readRegion(user: User, ctx: Ctx) {
427433 : {
428434 ...readTimeline(ctx.app.db, user, {
429435 limit: FEED_FIRST_PAGE,
430 mine: show === "mine",
436 ...(show === undefined ? {} : { show }),
431437 phase: (name, ms) => notePhase(ctx.request, name, ms),
432438 ...(before.id === undefined ? {} : { before: before.id }),
433439 }),
@@ -524,7 +530,7 @@ function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>):
524530 data-live-src="/live/feed${liveQuery === "" ? "" : `?${liveQuery}`}"
525531 >
526532 ${filterLine(filter)}
527 ${filter.kind === "app" ? null : mineChip(show)}
533 ${filter.kind === "app" ? null : showChips(show)}
528534 ${chipsBar(user, ctx, items)}
529535 ${thoughts.map((t) => thoughtCard(t, user.username, placed.get(t.id)))}
530536 ${items.length === 0 && thoughts.length === 0
test/feed-filters.test.ts added +166
@@ -0,0 +1,166 @@
1 /**

Missing: tests for app.serving and release.* under Ships, and a human-actor exclusion under Crew. Both would fail if the regex or the agent check were wrong.

2 * `?show=crew|mine|ships` narrows the timeline on the server, marks the one on, and a second tap
3 * (a link to the bare feed) clears it; an unknown value is the unfiltered feed.
4 */
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo } from "../src/actions/repos.ts";
11 import { createIssue } from "../src/core/issues.ts";
12 import { createSession } from "../src/core/sessions.ts";
13 import type { Repo } from "../src/core/repos.ts";
14 import { createUser, type User } from "../src/core/users.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import { parseShow, SHIPS as SHIPS_KINDS } from "../src/feed/mine.ts";
17 import { readTimeline } from "../src/feed/timeline.ts";
18 import { feedScreen } from "../src/tui/screens/feed.ts";
19 import { Screen as Surface } from "../src/tui/term/screen.ts";
20 import { theme } from "../src/tui/ui/theme.ts";
21 import type { Ctx } from "../src/tui/app/app.ts";
22 import type { Session } from "../src/tui/session.ts";
23 import { promote } from "./helpers/members.ts";
24 import type { KeyEvent } from "../src/tui/term/input.ts";
25 const pressed = (key: string): KeyEvent => ({ type: "key", key, ctrl: false, alt: false, shift: false });
26
27 describe("the feed's three one-tap filters", () => {
28 let dataDir: string;
29 let app: App;
30 let servers: Servers;
31 let alice: User;
32 let bob: User;
33 let repo: Repo;
34 let cookie: string;
35 const links = (show?: "crew" | "mine" | "ships") =>
36 readTimeline(app.db, alice, { limit: 50, ...(show === undefined ? {} : { show }) }).items.map((i) => i.link);
37 const get = async (q: string) => (await fetch(`${servers.url}/feed${q}`, { headers: { cookie } })).text();
38
39 beforeAll(async () => {
40 dataDir = await mkdtemp(join(tmpdir(), "forge-feed-filters-"));
41 app = createApp({ dataDir, port: 0 });
42 servers = await serve(app);
43 const mk = async (username: string, first = false) => {
44 const r = await createUser(app.db, {
45 origin: "seed", trusted: true, username, allowReserved: true,
46 email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first,
47 });
48 if (!r.ok) throw new Error(r.error);
49 promote(app.db, r.value);
50 return r.value;
51 };
52 await mk("root", true);
53 alice = await mk("alice");
54 bob = await mk("bob");
55 cookie = `forge_session=${createSession(app.db, alice.id).token}`;
56 app.db.run("INSERT INTO user (id, username, email, password_hash, is_agent) VALUES ('agent-scout', 'scout', '[email protected]', '', 1)");
57 const r = await createRepo(app, bob, { name: "theirs", visibility: "public" });
58 if (!r.ok) throw new Error("repo");
59 repo = r.value;
60 const mkIssue = (author: User, title: string) => {
61 const i = createIssue(app.db, { repoId: repo.id, authorId: author.id, title });
62 if (!i.ok) throw new Error(i.error);
63 app.bus.append({ kind: "issue.opened", repoId: repo.id, actorId: author.id, payload: { number: i.value.number } });
64 return i.value.number;
65 };
66 mkIssue(alice, "alice asks");
67 mkIssue(bob, "bob asks");
68 app.bus.append({ kind: "pull.opened", repoId: repo.id, actorId: "agent-scout", payload: { number: 21 } });
69 app.bus.append({ kind: "pull.merged", repoId: repo.id, actorId: bob.id, payload: { number: 22 } });
70 app.bus.append({ kind: "app.serving", repoId: repo.id, payload: { commitOid: "a".repeat(40) } });
71 app.bus.append({ kind: "release.verified_live", repoId: repo.id, payload: {} });
72 // An agent's comment is crew; a person's is not.
73 app.bus.append({ kind: "issue.commented", repoId: repo.id, actorId: "agent-scout", payload: { number: 1 } });
74 }, 30_000);
75
76 afterAll(async () => {
77 servers.stop();
78 app.close();
79 await rm(dataDir, { recursive: true, force: true });
80 });
81
82 test("crew: only what agents did, never a person's post", () => {
83 const only = links("crew");
84 expect(only).toContain("/bob/theirs/pulls/21");
85 expect(only).toContain("/bob/theirs/issues/1"); // the agent's comment
86 for (const human of ["/bob/theirs/pulls/22", "/bob/theirs/issues/2"]) expect(only).not.toContain(human);
87 expect(only.some((l) => l.includes("/commit/"))).toBe(false); // an app.serving has no actor
88 expect(only.length).toBeLessThan(links().length);
89 });
90
91 test("mine: my posts and replies to them; not another person's, not the crew's elsewhere", () => {
92 const only = links("mine");
93 expect(only).toContain("/bob/theirs/issues/1"); // alice's own post (and the agent's reply to it)
94 expect(only).not.toContain("/bob/theirs/issues/2"); // bob's
95 expect(only).not.toContain("/bob/theirs/pulls/22");
96 expect(only).not.toContain("/bob/theirs/pulls/21");
97 expect(links()).toContain("/bob/theirs/issues/2"); // the filter is what removed it
98 });
99
100 test("ships: a merged pull, an app serving and a release step; nothing else", () => {
101 const only = links("ships");
102 expect(only).toContain("/bob/theirs/pulls/22");
103 expect(only).toContain("/bob/theirs"); // the app serving: no release note, so the repository's page
104 expect(only).not.toContain("/bob/theirs/pulls/21");
105 expect(only.some((l) => l.includes("/issues/"))).toBe(false);
106 for (const k of ["app.serving", "release.verified_live"]) expect(SHIPS_KINDS.test(k)).toBe(true);
107 for (const k of ["app.gated", "pull.opened", "releases.x", "xrelease.held"]) expect(SHIPS_KINDS.test(k)).toBe(false);
108 });
109
110 test("the terminal's c, m and s keys read the same filters; a second press clears", () => {
111 const ctx = { theme: theme("dark"), invalidate() {}, toast() {}, push() {}, pop() {}, copy() {}, hit() {}, setCursor() {} } as unknown as Ctx;
112 const screen = feedScreen({ app, db: app.db, user: alice } as unknown as Session, ctx);
113 const text = () => {
114 const s = new Surface(140, 44);
115 screen.render({ x: 0, y: 0, w: 140, h: 44 }, s);
116 return s.toText();
117 };
118 const press = (key: string) => screen.key!(pressed(key));
119 const helps = () => screen.keys.map((k) => k.help);
120 expect(helps()).toEqual(expect.arrayContaining(["only crew", "only mine", "only ships"]));
121 press("s");
122 expect(text()).toContain("merged");
123 expect(text()).not.toContain("bob asks");
124 expect(helps()).toContain("everyone's");
125 press("s");
126 expect(text()).toContain("bob asks");
127 press("c");
128 expect(text()).not.toContain("bob asks");
129 expect(text()).toContain("scout replied");
130 expect(text()).not.toContain("alice opened");
131 press("c");
132 press("m");
133 expect(text()).toContain("alice asks");
134 expect(text()).not.toContain("bob asks");
135 });
136
137 test("a guest reads nothing through the terminal's filters", () => {
138 const ctx = { theme: theme("dark"), invalidate() {}, toast() {}, push() {}, pop() {}, copy() {}, hit() {}, setCursor() {} } as unknown as Ctx;
139 const screen = feedScreen({ app, db: app.db, user: undefined } as unknown as Session, ctx);
140 for (const k of ["c", "m", "s"]) expect(() => screen.key!(pressed(k))).not.toThrow();
141 });
142
143 test("the page narrows, marks the one on, and a second tap clears it", async () => {
144 for (const v of ["crew", "mine", "ships"] as const) {
145 const on = await get(`?show=${v}`);
146 expect(on).toContain(`data-show="${v}"`);
147 expect(on).toMatch(new RegExp(`data-show-chip="${v}" href="/feed" aria-current="true"`));
148 for (const other of ["crew", "mine", "ships"].filter((o) => o !== v))
149 expect(on).toContain(`data-show-chip="${other}" href="/feed?show=${other}"`);
150 }
151 const ships = await get("?show=ships");
152 expect(ships).toContain("/bob/theirs/pulls/22");
153 expect(ships).not.toContain("alice asks");
154 expect(ships).toContain("<nav ");
155 });
156
157 test("an unknown value is the unfiltered feed, not an error", async () => {
158 expect(parseShow("bogus")).toBeUndefined();
159 const res = await fetch(`${servers.url}/feed?show=bogus`, { headers: { cookie } });
160 expect(res.status).toBe(200);
161 const text = await res.text();
162 expect(text).toContain('data-show="all"');
163 expect(text).toContain("alice asks");
164 expect(text).toContain("bob asks");
165 });
166 });
test/feed-mine.test.ts +1 −1
@@ -30,7 +30,7 @@ describe("the Mine filter", () => {
3030 let secret: Repo;
3131 let aliceCookie: string;
3232 const links = (viewer: User, mine: boolean) =>
33 readTimeline(app.db, viewer, { mine, limit: 50 }).items.map((i) => i.link);
33 readTimeline(app.db, viewer, { limit: 50, ...(mine ? { show: "mine" as const } : {}) }).items.map((i) => i.link);
3434
3535 const issue = (repo: Repo, author: User, title: string) => {
3636 const r = createIssue(app.db, { repoId: repo.id, authorId: author.id, title });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs