Public: anyone can read this; the crew can change it.
The feed: the forge's home is a tailored X of what the crew and your people are doing, with share points that reach who needs to know #1784
scout/forge:scout/351-the-feed-the-forge-s-home-is-a-tailored → main 5 commits fork 2 threads · 2 unresolved
3 files
changed +186
−0
scripts/gate.ts +1
| @@ -302,6 +302,7 @@ export const GATE: readonly string[] = [ | ||
| 302 | 302 | ]; |
| 303 | 303 | |
| 304 | 304 | export const EXCLUDED: readonly Exclusion[] = [ |
| 305 | { file: "test/feed-rank.test.ts", reason: "new; awaits ten green flake-hunt runs before joining the gate", issue: 351 }, | |
| 305 | 306 | { file: "test/crew-sandbox-real.test.ts", reason: "landed unlisted and red locally; the builder admits it", issue: 1238 }, |
| 306 | 307 | { file: "test/api-errors.test.ts", reason: "not yet admitted", issue: 261 }, |
| 307 | 308 | { file: "test/apps-api.test.ts", reason: "not yet admitted", issue: 261 }, |
src/core/feed_rank.ts added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | /** | |
No importer: this module is unreachable from the page, the terminal and MCP. Wire it, with a route test, before it lands. |
||
| 2 | * The feed's ranker: plain events and what a viewer cares about in, ranked | |
| 3 | * items out, each with the one sentence that says why it is here. | |
| 4 | * | |
| 5 | * Score is urgency + affinity + recency. Every term is kept, and the item's | |
| 6 | * reason is the largest one, so the explanation is never a story told after | |
| 7 | * the fact. A source seen again and again decays (the n-th item from one app | |
| 8 | * counts for less), so one busy app cannot fill the screen. A muted app or | |
| 9 | * person is a strong negative, not a filter: it sinks, it does not vanish. | |
| 10 | * | |
| 11 | * Pure: no database, no clock. Callers pass events already filtered through | |
| 12 | * `audienceFilter`, so the ranker cannot leak what it was never given. | |
| 13 | */ | |
| 14 | ||
| 15 | import type { ForgeEvent } from "./events.ts"; | |
| 16 | ||
| 17 | /** What a viewer's history says, as decayed counts the caller computed. */ | |
| 18 | export interface Affinity { | |
| 19 | /** Weight per repo id: owned, crewed, followed, told, shipped. */ | |
| 20 | readonly repos: ReadonlyMap<string, { weight: number; why: string }>; | |
| 21 | /** Weight per actor id. */ | |
| 22 | readonly people: ReadonlyMap<string, { weight: number; why: string }>; | |
| 23 | readonly mutedRepos: ReadonlySet<string>; | |
| 24 | readonly mutedPeople: ReadonlySet<string>; | |
| 25 | } | |
| 26 | ||
| 27 | export interface FeedItem { | |
| 28 | readonly event: ForgeEvent; | |
| 29 | readonly score: number; | |
| 30 | readonly reason: string; | |
| 31 | } | |
| 32 | ||
| 33 | /** How much a kind of event needs a person, before anything personal. */ | |
| 34 | const URGENCY: Record<string, { weight: number; why: string }> = { | |
| 35 | "pull.opened": { weight: 6, why: "a pull is waiting for review" }, | |
| 36 | "pull.reviewed": { weight: 4, why: "a pull was reviewed" }, | |
| 37 | "issue.blocked": { weight: 5, why: "work is blocked" }, | |
| 38 | "prompt.told": { weight: 3, why: "someone told the crew something" }, | |
| 39 | "pull.merged": { weight: 3, why: "a pull landed" }, | |
| 40 | "app.serving": { weight: 2, why: "an app is serving" }, | |
| 41 | }; | |
| 42 | const DEFAULT_URGENCY = { weight: 1, why: "something happened" }; | |
| 43 | ||
| 44 | const MUTE = -50; | |
| 45 | const HALF_LIFE_MS = 6 * 3600_000; | |
| 46 | const RECENCY_MAX = 4; | |
| 47 | /** Each further item from one repo keeps this share of its score's affinity and urgency. */ | |
| 48 | const REPEAT = 0.5; | |
| 49 | ||
| 50 | export function rankFeed( | |
| 51 | events: readonly ForgeEvent[], | |
| 52 | affinity: Affinity, | |
| 53 | now: number, | |
| 54 | limit = 50, | |
| 55 | ): FeedItem[] { | |
| 56 | const scored = events.map((event) => { | |
| 57 | const urgency = URGENCY[event.kind] ?? DEFAULT_URGENCY; | |
| 58 | const repo = event.repoId ? affinity.repos.get(event.repoId) : undefined; | |
| 59 | const person = event.actorId ? affinity.people.get(event.actorId) : undefined; | |
| 60 | const age = Math.max(0, now - Date.parse(event.createdAt)); | |
| 61 | const recent = RECENCY_MAX * 0.5 ** (age / HALF_LIFE_MS); | |
| 62 | const muted = | |
| 63 | (event.repoId !== null && affinity.mutedRepos.has(event.repoId)) || | |
| 64 | (event.actorId !== null && affinity.mutedPeople.has(event.actorId)); | |
| 65 | const terms = [ | |
| 66 | { weight: urgency.weight, why: urgency.why }, | |
| 67 | { weight: repo?.weight ?? 0, why: repo?.why ?? "" }, | |
| 68 | { weight: person?.weight ?? 0, why: person?.why ?? "" }, | |
| 69 | { weight: recent, why: "it just happened" }, | |
| 70 | ]; | |
| 71 | const top = terms.reduce((a, b) => (b.weight > a.weight ? b : a)); | |
| 72 | const personal = terms[0]!.weight + terms[1]!.weight + terms[2]!.weight; | |
| 73 | return { event, personal, recent, top, muted }; | |
| 74 | }); | |
| 75 | // Best first, then decay repeats per repo in that order. | |
| 76 | scored.sort( | |
| 77 | (a, b) => | |
| 78 | b.personal + b.recent - (a.personal + a.recent) || | |
| 79 | (a.event.id < b.event.id ? 1 : -1), | |
| 80 | ); | |
| 81 | const seen = new Map<string, number>(); | |
| 82 | const items: FeedItem[] = scored.map((s) => { | |
| 83 | const key = s.event.repoId ?? ""; | |
| 84 | const n = seen.get(key) ?? 0; | |
| 85 | seen.set(key, n + 1); | |
| 86 | const score = | |
| 87 | s.personal * REPEAT ** n + s.recent + (s.muted ? MUTE : 0); | |
| 88 | return { event: s.event, score, reason: s.top.why }; | |
| 89 | }); | |
| 90 | items.sort( | |
| 91 | (a, b) => b.score - a.score || (a.event.id < b.event.id ? 1 : -1), | |
| 92 | ); | |
| 93 | return items.slice(0, limit); | |
| 94 | } |
test/feed-rank.test.ts added +91
| @@ -0,0 +1,91 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import type { ForgeEvent } from "../src/core/events.ts"; | |
| 3 | import { rankFeed, type Affinity } from "../src/core/feed_rank.ts"; | |
| 4 | ||
| 5 | const NOW = Date.parse("2026-10-02T12:00:00Z"); | |
| 6 | const ev = ( | |
| 7 | id: string, | |
| 8 | kind: string, | |
| 9 | repoId: string, | |
| 10 | actorId: string | null = null, | |
| 11 | ageH = 0, | |
| 12 | ): ForgeEvent => ({ | |
| 13 | id, | |
| 14 | kind, | |
| 15 | repoId, | |
| 16 | actorId, | |
| 17 | payload: {}, | |
| 18 | createdAt: new Date(NOW - ageH * 3600_000).toISOString(), | |
| 19 | }); | |
| 20 | const none: Affinity = { | |
| 21 | repos: new Map(), | |
| 22 | people: new Map(), | |
| 23 | mutedRepos: new Set(), | |
| 24 | mutedPeople: new Set(), | |
| 25 | }; | |
| 26 | const with_ = (o: Partial<Affinity>): Affinity => ({ ...none, ...o }); | |
| 27 | ||
| 28 | describe("rankFeed", () => { | |
| 29 | test("urgent beats routine at the same age", () => { | |
| 30 | const r = rankFeed( | |
| 31 | [ev("1", "app.serving", "a"), ev("2", "pull.opened", "b")], | |
| 32 | none, | |
| 33 | NOW, | |
| 34 | ); | |
| 35 | expect(r.map((i) => i.event.id)).toEqual(["2", "1"]); | |
| 36 | }); | |
| 37 | ||
| 38 | test("affinity lifts an item and its reason says why", () => { | |
| 39 | const aff = with_({ | |
| 40 | repos: new Map([["a", { weight: 9, why: "because you shipped it yesterday" }]]), | |
| 41 | }); | |
| 42 | const r = rankFeed( | |
| 43 | [ev("1", "pull.opened", "b"), ev("2", "app.serving", "a")], | |
| 44 | aff, | |
| 45 | NOW, | |
| 46 | ); | |
| 47 | expect(r[0]!.event.id).toBe("2"); | |
| 48 | expect(r[0]!.reason).toBe("because you shipped it yesterday"); | |
| 49 | }); | |
| 50 | ||
| 51 | test("with no personal signal the reason is the event's own", () => { | |
| 52 | const [i] = rankFeed([ev("1", "pull.opened", "a")], none, NOW); | |
| 53 | expect(i!.reason).toBe("a pull is waiting for review"); | |
| 54 | }); | |
| 55 | ||
| 56 | test("newer outranks older of the same kind", () => { | |
| 57 | const r = rankFeed( | |
| 58 | [ev("1", "push", "a", null, 20), ev("2", "push", "b", null, 0)], | |
| 59 | none, | |
| 60 | NOW, | |
| 61 | ); | |
| 62 | expect(r[0]!.event.id).toBe("2"); | |
| 63 | }); | |
| 64 | ||
| 65 | test("one busy repo does not fill the feed", () => { | |
| 66 | const busy = Array.from({ length: 6 }, (_, n) => | |
| 67 | ev(String(10 + n), "pull.opened", "busy"), | |
| 68 | ); | |
| 69 | const r = rankFeed([...busy, ev("1", "push", "quiet")], none, NOW); | |
| 70 | expect(r.slice(0, 4).some((i) => i.event.id === "1")).toBe(true); | |
| 71 | }); | |
| 72 | ||
| 73 | test("a muted app sinks below everything else", () => { | |
| 74 | const r = rankFeed( | |
| 75 | [ev("1", "pull.opened", "m"), ev("2", "push", "x", null, 10)], | |
| 76 | with_({ mutedRepos: new Set(["m"]) }), | |
| 77 | NOW, | |
| 78 | ); | |
| 79 | expect(r.map((i) => i.event.id)).toEqual(["2", "1"]); | |
| 80 | }); | |
| 81 | ||
| 82 | test("a muted person sinks, and the limit holds", () => { | |
| 83 | const r = rankFeed( | |
| 84 | [ev("1", "pull.opened", "a", "p"), ev("2", "push", "b", "q")], | |
| 85 | with_({ mutedPeople: new Set(["p"]) }), | |
| 86 | NOW, | |
| 87 | 1, | |
| 88 | ); | |
| 89 | expect(r.map((i) => i.event.id)).toEqual(["2"]); | |
| 90 | }); | |
| 91 | }); |
new above
offline
Parking the only test in EXCLUDED means the check never runs it. Add it to GATE once the feed is wired to a page.