Public: anyone can read this; the crew can change it.
The feed can be narrowed to one app from a link on any post's app name #14531
Check · Review · Land · Live — No review yet.
scout/forge:scout/14516-the-feed-can-be-narrowed-to-one-app-from → main 7 commits fork
This pull asks to reach lab--forge-trevato-apps.open-platform.sh. Its preview and check reach what main reaches; the new host opens when the pull lands.
5 files
changed +97
−5
src/feed/app_filter.ts +6
| @@ -29,3 +29,9 @@ export function appFilterOf(db: Database, viewer: User, raw: string | null): App | ||
| 29 | 29 | |
| 30 | 30 | /** Whether `raw` is shaped like an app name: what a variant key may carry. */ |
| 31 | 31 | export const isAppName = (raw: string): boolean => raw.length <= 140 && APP.test(raw); |
| 32 | ||
| 33 | /** | |
| 34 | * The plain line a narrowed feed leads with: the web page's and the MCP feed tool's, in the same | |
| 35 | * words. | |
| 36 | */ | |
| 37 | export const onlyLine = (app: string): string => `Only ${app}`; |
src/http/mcp/tools/feed.ts +9 −2
| @@ -1,12 +1,13 @@ | ||
| 1 | 1 | import { FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX, parseCursor, readFeed } from "../../../feed/feed.ts"; |
| 2 | 2 | import { parseBefore, readTimeline } from "../../../feed/timeline.ts"; |
| 3 | 3 | import { CURSOR_NOT_ISSUED } from "../../../actions/feed_words.ts"; |
| 4 | import { appFilterOf, APP_UNKNOWN_LINE, onlyLine } from "../../../feed/app_filter.ts"; | |
| 4 | 5 | import { feedDigest } from "../../../web/studio/since.ts"; |
| 5 | 6 | import { good, bad, type Tool, CHIP_ARGS, chipArgs, str } from "../shared.ts"; |
| 6 | 7 | |
| 7 | 8 | export const tool: Tool = { |
| 8 | 9 | name: "feed", |
| 9 | doc: "`{ limit?, cursor?, before?, hide_kinds?, hide_people? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed`; `before` (a `next_cursor`, or `now`) reads the log newest first instead of ranked, as constant-cost pages with no repeat or skip; `digest` (first page only) is home's \"Since you were here\" card, `{ heading, lines: [{ repo, says, href }] }` or null; `quietRuns` counts agent runs of the last 24 h that pushed, opened or said nothing, which the timeline leaves out; an item with `lines: [{ text, link }]` and `more` is a folded burst (3+ issues one author opened in one repository within 2 minutes: `planned N issues in owner/name`, linking to its map) — `lines` are the first three, `more` the rest", | |
| 10 | doc: "`{ limit?, cursor?, before?, app?, hide_kinds?, hide_people? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed`; `before` (a `next_cursor`, or `now`) reads the log newest first instead of ranked, as constant-cost pages with no repeat or skip; `app` (`owner/name`) narrows the ranked page to it, with `filter`; unknown leaves it whole; not with `before`; `digest` (first page only) is home's \"Since you were here\" card, `{ heading, lines: [{ repo, says, href }] }` or null; `quietRuns` counts agent runs of the last 24 h that pushed, opened or said nothing, which the timeline leaves out; an item with `lines: [{ text, link }]` and `more` is a folded burst (3+ issues one author opened in one repository within 2 minutes: `planned N issues in owner/name`, linking to its map) — `lines` are the first three, `more` the rest", | |
| 10 | 11 | description: |
| 11 | 12 | "Your ranked home timeline; `cursor` pages; saved filter applies.", |
| 12 | 13 | inputSchema: { |
| @@ -15,6 +16,7 @@ export const tool: Tool = { | ||
| 15 | 16 | limit: { type: "integer", minimum: 1, maximum: FEED_LIMIT_MAX }, |
| 16 | 17 | cursor: { type: "string" }, |
| 17 | 18 | before: { type: "string" }, |
| 19 | app: { type: "string", maxLength: 140 }, | |
| 18 | 20 | ...CHIP_ARGS, |
| 19 | 21 | }, |
| 20 | 22 | }, |
| @@ -30,7 +32,11 @@ export const tool: Tool = { | ||
| 30 | 32 | const cursor = given === undefined ? undefined : parseCursor(str(given)); |
| 31 | 33 | if (given !== undefined && cursor === undefined) |
| 32 | 34 | return bad("invalid", CURSOR_NOT_ISSUED); |
| 35 | const rawApp = args["app"]; | |
| 36 | const only = rawApp === undefined ? ({ kind: "none" } as const) : appFilterOf(ctx.app.db, user, str(rawApp)); | |
| 37 | const filter = only.kind === "app" ? onlyLine(only.app) : only.kind === "unknown" ? APP_UNKNOWN_LINE : undefined; | |
| 33 | 38 | const rawBefore = args["before"]; |
| 39 | if (rawBefore !== undefined && only.kind === "app") return bad("invalid", "app narrows the ranked page; leave before out"); | |
| 34 | 40 | if (rawBefore !== undefined) { |
| 35 | 41 | const before = parseBefore(str(rawBefore)); |
| 36 | 42 | if (before === undefined || given !== undefined) return bad("invalid", CURSOR_NOT_ISSUED); |
| @@ -45,8 +51,9 @@ export const tool: Tool = { | ||
| 45 | 51 | const page = readFeed(ctx.app.db, user, { |
| 46 | 52 | limit, |
| 47 | 53 | ...(chips === undefined ? {} : { chips }), |
| 54 | ...(only.kind === "app" ? { repoId: only.repo.id } : {}), | |
| 48 | 55 | ...(cursor === undefined ? {} : { cursor }), |
| 49 | 56 | }); |
| 50 | return good({ ...page, ...(cursor === undefined ? { digest: feedDigest(ctx.app.db, user, Date.now()) } : {}) }); | |
| 57 | return good({ ...page, ...(filter === undefined ? {} : { filter }), ...(cursor === undefined ? { digest: feedDigest(ctx.app.db, user, Date.now()) } : {}) }); | |
| 51 | 58 | }, |
| 52 | 59 | }; |
src/web/studio/feed.ts +1 −1
| @@ -421,7 +421,7 @@ function filterLine(filter: AppFilter): Html | null { | ||
| 421 | 421 | if (filter.kind === "none") return null; |
| 422 | 422 | if (filter.kind === "unknown") return html`<p class="small muted" data-app-filter="unknown">${APP_UNKNOWN_LINE}</p>`; |
| 423 | 423 | return html`<p class="bar small" data-app-filter="${filter.app}"> |
| 424 | <span>Showing <a href="/${filter.app}">${filter.app}</a></span> | |
| 424 | <span>Only <a href="/${filter.app}">${filter.app}</a></span> | |
| 425 | 425 | <a href="/feed">Clear</a> |
| 426 | 426 | </p>`; |
| 427 | 427 | } |
test/feed-app-link.test.ts added +79
| @@ -0,0 +1,79 @@ | ||
| 1 | /** | |
| 2 | * The one-app feed is reachable: a link on each post's app name, and an `app` argument on the MCP | |
| 3 | * feed tool. | |
| 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 { createSession } from "../src/core/sessions.ts"; | |
| 12 | import { createToken } from "../src/core/tokens.ts"; | |
| 13 | import { createUser, type User } from "../src/core/users.ts"; | |
| 14 | import { APP_UNKNOWN_LINE } from "../src/feed/app_filter.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { promote } from "./helpers/members.ts"; | |
| 17 | import { mcpTool } from "./helpers/mcp.ts"; | |
| 18 | ||
| 19 | describe("feed app link and argument", () => { | |
| 20 | let dir: string; | |
| 21 | let app: App; | |
| 22 | let servers: Servers; | |
| 23 | let bob: User; | |
| 24 | let tok: string; | |
| 25 | let cookie: string; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dir = await mkdtemp(join(tmpdir(), "feed-app-link-")); | |
| 29 | app = createApp({ dataDir: dir, port: 0 }); | |
| 30 | servers = await serve(app); | |
| 31 | const mk = async (username: string, first = false) => { | |
| 32 | const r = await createUser(app.db, { origin: "seed", trusted: true, username, allowReserved: true, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first }); | |
| 33 | if (!r.ok) throw new Error(r.error); | |
| 34 | promote(app.db, r.value); | |
| 35 | return r.value; | |
| 36 | }; | |
| 37 | await mk("root", true); | |
| 38 | const alice = await mk("alice"); | |
| 39 | bob = await mk("bob"); | |
| 40 | for (const name of ["open", "other"]) { | |
| 41 | const r = await createRepo(app, alice, { name, visibility: "public" }); | |
| 42 | if (!r.ok) throw new Error("repo"); | |
| 43 | app.bus.append({ kind: "run.finished", repoId: r.value.id, actorId: alice.id, payload: { kind: "deploy", state: "ok", summary: `hello from ${name}`, runId: `r-${name}` } }); | |
| 44 | } | |
| 45 | tok = createToken(app.db, bob.id, "rw", "rw").token; | |
| 46 | cookie = `forge_session=${createSession(app.db, bob.id).token}`; | |
| 47 | }); | |
| 48 | afterAll(async () => { | |
| 49 | servers.stop(); | |
| 50 | app.close(); | |
| 51 | await rm(dir, { recursive: true, force: true }); | |
| 52 | }); | |
| 53 | ||
| 54 | test("each post's app name links to its one-app feed, which says Only <app>", async () => { | |
| 55 | const page = await (await fetch(`${servers.url}/feed`, { headers: { cookie } })).text(); | |
| 56 | expect(page).toContain('href="/feed?app=alice/open" class="muted" data-filter-app'); | |
| 57 | const one = await (await fetch(`${servers.url}/feed?app=alice/open`, { headers: { cookie } })).text(); | |
| 58 | expect(one).toContain("<span>Only <a"); | |
| 59 | expect(one).toContain('href="/feed">Clear'); | |
| 60 | }); | |
| 61 | ||
| 62 | test("the MCP feed tool takes app and says the same words", async () => { | |
| 63 | const all = await mcpTool(servers.url, tok, "feed", {}); | |
| 64 | expect(all.value.filter).toBeUndefined(); | |
| 65 | const one = await mcpTool(servers.url, tok, "feed", { app: "alice/open" }); | |
| 66 | expect(one.value.filter).toBe("Only alice/open"); | |
| 67 | const apps = new Set((one.value.items as { app: string }[]).map((i) => i.app)); | |
| 68 | expect([...apps]).toEqual(["alice/open"]); | |
| 69 | }); | |
| 70 | ||
| 71 | test("an unknown or malformed app answers the whole feed with the line, not an error", async () => { | |
| 72 | for (const app of ["alice/nothing", "<script>", "../x"]) { | |
| 73 | const r = await mcpTool(servers.url, tok, "feed", { app }); | |
| 74 | expect(r.error).toBeUndefined(); | |
| 75 | expect(r.value.filter).toBe(APP_UNKNOWN_LINE); | |
| 76 | expect(r.value.items.length).toBeGreaterThan(1); | |
| 77 | } | |
| 78 | }); | |
| 79 | }); |
test/feed-filter.test.ts +2 −2
| @@ -58,7 +58,7 @@ describe("the one-app feed filter", () => { | ||
| 58 | 58 | test("a readable app shows only its items, with the line and a clear link", async () => { |
| 59 | 59 | const body = await (await get("/feed?app=alice/open")).text(); |
| 60 | 60 | expect(body).toContain('data-app-filter="alice/open"'); |
| 61 | expect(body).toContain("Showing"); | |
| 61 | expect(body).toContain("Only <a"); | |
| 62 | 62 | expect(body).toContain('href="/feed">Clear'); |
| 63 | 63 | expect(body).toContain("hello from open"); |
| 64 | 64 | expect(body).not.toContain("hello from other"); |
| @@ -69,7 +69,7 @@ describe("the one-app feed filter", () => { | ||
| 69 | 69 | const priv = await (await get("/feed?app=alice/secret")).text(); |
| 70 | 70 | for (const body of [unknown, priv]) { |
| 71 | 71 | expect(body).toContain(APP_UNKNOWN_LINE); |
| 72 | expect(body).not.toContain("Showing"); | |
| 72 | expect(body).not.toContain("Only <a"); | |
| 73 | 73 | expect(body).not.toContain("hello from secret"); |
| 74 | 74 | expect(body).toContain("hello from other"); |
| 75 | 75 | } |
new above
offline