Public: anyone can read this; the crew can change it.
A post in the feed opens one step deeper to its run, diff or file with one visible link #13689
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/13657-a-post-in-the-feed-opens-one-step-deeper → main 5 commits fork 2 threads · 2 unresolved
8 files
changed +149
−2
docs/features/README.md +1
| @@ -20,6 +20,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 20 | 20 | - [](first-week.md) |
| 21 | 21 | - [](template-timing.md) |
| 22 | 22 | - [](feed-look.md) |
| 23 | - [](feed-depth.md) | |
| 23 | 24 | - [](red-pulls.md) |
| 24 | 25 | - [](empty-words.md) |
| 25 | 26 | - [](readme-description.md) |
docs/features/feed-depth.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | # One step deeper from a post | |
| 2 | ||
| 3 | A post in the feed has one plain link under it that goes one step deeper than the post's headline. | |
| 4 | ||
| 5 | - A run post: **Run log**, the run's log page. | |
| 6 | - A pull, or a look at a pull: **Diff**, the pull's files page. | |
| 7 | - An issue post (a `tell`), or a reply: **Thread**, the issue's page. A reply on a pull shows **Diff**. | |
| 8 | ||
| 9 | A post whose link is none of these, or belongs to another app, shows no link. Run links drop their line anchor, so the log opens at the top. | |
| 10 | ||
| 11 | **On the web:** a real link under the card, no script, with a touch-sized hit area. **In the terminal:** open the feed; the second line under a post reads `Run log: /owner/name/runs/ID`, `Diff: /owner/name/pulls/N/files` or `Thread: /owner/name/issues/N`. | |
| 12 | ||
| 13 | Code: `src/feed/depth.ts` (`depthOf`, `depthLine`), `src/web/studio/feed.ts`, `src/tui/screens/feed.ts` (`feedNote`). Tests: `test/feed-depth.test.ts`. |
src/feed/depth.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * The one step deeper from a post: its run log, pull diff or issue thread, as plain | |
| 3 | * data (a label and an address). A post names a depth only when its link is one; | |
| 4 | * the web card renders it as a real anchor, no script, and the terminal feed | |
| 5 | * prints it as a line (`depthLine`). There is no issue post kind: an issue shows as a | |
| 6 | * `tell` (and a comment on it as a `reply`). | |
| 7 | */ | |
| 8 | ||
| 9 | export type Depth = { label: string; href: string }; | |
| 10 | ||
| 11 | const RUN = /^(\/[^/]+\/[^/]+\/runs\/[A-Za-z0-9_-]+)(?:\?all=1#L\d+)?$/; | |
| 12 | const PULL = /^(\/[^/]+\/[^/]+\/pulls\/\d{1,9})(?:#[\w-]+)?$/; | |
| 13 | const ISSUE = /^(\/[^/]+\/[^/]+\/issues\/\d{1,9})(?:\?all=1)?(?:#[\w-]+)?$/; | |
| 14 | ||
| 15 | export function depthOf(item: { kind: string; app: string; link: string }): Depth | undefined { | |
| 16 | const inApp = (path: string): boolean => path.startsWith(`/${item.app}/`); | |
| 17 | const run = RUN.exec(item.link); | |
| 18 | if (item.kind === "run" && run !== null && inApp(run[1]!)) return { label: "Run log", href: run[1]! }; | |
| 19 | const pull = PULL.exec(item.link); | |
| 20 | if ((item.kind === "pull" || item.kind === "look" || item.kind === "reply") && pull !== null && inApp(pull[1]!)) | |
| 21 | return { label: "Diff", href: `${pull[1]!}/files` }; | |
| 22 | const issue = ISSUE.exec(item.link); | |
| 23 | if ((item.kind === "tell" || item.kind === "reply") && issue !== null && inApp(issue[1]!)) | |
| 24 | return { label: "Thread", href: issue[1]! }; | |
| 25 | return undefined; | |
| 26 | } | |
| 27 | ||
| 28 | /** The terminal's words for the same link: `Diff: /a/b/pulls/4/files`, or undefined. */ | |
| 29 | export function depthLine(item: { kind: string; app: string; link: string }): string | undefined { | |
| 30 | const d = depthOf(item); | |
| 31 | return d === undefined ? undefined : `${d.label}: ${d.href}`; | |
| 32 | } |
src/tui/screens/feed.ts +3 −2
| @@ -27,6 +27,7 @@ import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.t | ||
| 27 | 27 | import type { FeedItem } from "../../feed/rank.ts"; |
| 28 | 28 | import { readInteraction } from "../../feed/interact.ts"; |
| 29 | 29 | import { likeLedger, likersOf, toggleLike } from "../../feed/likes.ts"; |
| 30 | import { depthLine } from "../../feed/depth.ts"; | |
| 30 | 31 | import { permalinkOf, replyTarget } from "../../feed/reply.ts"; |
| 31 | 32 | import { runTarget } from "../../feed/run_link.ts"; |
| 32 | 33 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -53,11 +54,11 @@ const likeMark = (item: FeedItem): string => | ||
| 53 | 54 | |
| 54 | 55 | /** |
| 55 | 56 | * The quiet second line under a post: a look's alt text (what the page's picture says), |
| 56 | * else its step. | |
| 57 | * else its step, then the one step deeper (`depthLine`, the page's Run log, Diff or Thread link). | |
| 57 | 58 | */ |
| 58 | 59 | export function feedNote(item: FeedItem): { note?: string } { |
| 59 | 60 | const quiet = item.look !== undefined ? item.look.alt : item.step === undefined ? undefined : stepLine(item.step); |
| 60 | const note = [quiet, likedByLine(item)].filter((n): n is string => n !== undefined).join(" · "); | |
| 61 | const note = [quiet, depthLine(item), likedByLine(item)].filter((n): n is string => n !== undefined).join(" · "); | |
| 61 | 62 | return note === "" ? {} : { note }; |
| 62 | 63 | } |
| 63 | 64 |
src/web/studio/feed.ts +3
| @@ -23,6 +23,7 @@ import { parseShow, type Show } from "../../feed/mine.ts"; | ||
| 23 | 23 | import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts"; |
| 24 | 24 | import type { FeedItem } from "../../feed/rank.ts"; |
| 25 | 25 | import { permalinkOf, replyPath, replyRepo, threadOf } from "../../feed/reply.ts"; |
| 26 | import { depthOf } from "../../feed/depth.ts"; | |
| 26 | 27 | import { runLinkOf } from "../../feed/run_link.ts"; |
| 27 | 28 | import { getAppByRepo } from "../../core/apps.ts"; |
| 28 | 29 | import { getRepo, getRepoById } from "../../core/repos.ts"; |
| @@ -163,6 +164,7 @@ export function feedCard( | ||
| 163 | 164 | const reply = thread !== undefined; |
| 164 | 165 | const steer = item.kind === "run" || item.kind === "cost"; |
| 165 | 166 | const run = runLinkOf(item); |
| 167 | const depth = depthOf(item); | |
| 166 | 168 | const target = steer && run !== undefined ? `${run.page}/steer` : null; |
| 167 | 169 | // A run post links its headline only to a run page; one without (a sync failure) is plain text. |
| 168 | 170 | const headline = item.kind === "run" && run === undefined |
| @@ -190,6 +192,7 @@ export function feedCard( | ||
| 190 | 192 | ><img src="${picture.src}" width="${picture.width}" height="${picture.height}" alt="${item.look.alt}" loading="lazy" decoding="async" |
| 191 | 193 | /></a>`} |
| 192 | 194 | ${item.look === undefined ? null : html`<p class="small muted break"><a href="${item.link}">${lookTarget(item)}</a></p>`} |
| 195 | ${depth === undefined ? null : html`<p class="small break"><a href="${depth.href}" data-depth>${depth.label}</a></p>`} | |
outdated
Principle 8 and phone tap target: the link is a bare small-text line with an arrow glyph. Give it a touch-sized hit area using the existing tokens. The terminal feed also needs the same link through depthOf (both doors). |
||
| 193 | 196 | ${item.step === undefined ? null : html`<p class="break">${stepLink(item.step)}</p>`} |
| 194 | 197 | ${saysMore(item) ? html`<p class="small muted break">${item.reason}</p>` : null} |
| 195 | 198 | ${likeBar(item)}${likedBy(item)}`; |
src/web/style/components.ts +2
| @@ -460,6 +460,8 @@ a.sha:hover { color: var(--accent); } | ||
| 460 | 460 | .look[data-slot="thumb"] { flex: none; width: 30px; height: 40px; border-radius: 4px; } |
| 461 | 461 | .look[data-slot="thumb"] img { height: 100%; object-fit: cover; object-position: top; } |
| 462 | 462 | .permalink, [data-filter-app] { display: inline-block; padding: 12px 6px; margin: -12px -6px; } |
| 463 | /* The depth link under a post: a touch-sized hit area, the line itself no taller. */ | |
| 464 | [data-depth] { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; margin: -12px -6px; } | |
| 463 | 465 | .look[data-slot="feed"] { width: 160px; height: 100px; margin-top: 6px; } |
| 464 | 466 | .look[data-slot="feed"] img { height: 100%; object-fit: cover; object-position: top; } |
| 465 | 467 | .look[data-slot="now"] { flex: none; width: 168px; } |
test/feed-depth-route.test.ts added +41
| @@ -0,0 +1,41 @@ | ||
| 1 | /** The real /feed route: a run post carries its Run log link, once. */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { createSession } from "../src/core/sessions.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { freshHome } from "./helpers/home-fresh.ts"; | |
| 12 | import { promote } from "./helpers/members.ts"; | |
| 13 | ||
| 14 | let dataDir: string; | |
| 15 | let app: App; | |
| 16 | let servers: Servers; | |
| 17 | let cookie: string; | |
| 18 | ||
| 19 | beforeAll(async () => { | |
| 20 | dataDir = await mkdtemp(join(tmpdir(), "forge-depth-")); | |
| 21 | app = createApp({ dataDir, port: 0 }); | |
| 22 | servers = await serve(app); | |
| 23 | const r = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", allowReserved: true, email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 24 | if (!r.ok) throw new Error(r.error); | |
| 25 | promote(app.db, r.value); | |
| 26 | cookie = `forge_session=${createSession(app.db, r.value.id).token}`; | |
| 27 | const made = await createRepo(app, r.value, { name: "open", visibility: "public" }); | |
| 28 | if (!made.ok) throw new Error("repo"); | |
| 29 | app.bus.append({ kind: "run.finished", repoId: made.value.id, actorId: r.value.id, payload: { kind: "agent", state: "ok", summary: "work", runId: "r0" } }); | |
| 30 | }); | |
| 31 | afterAll(async () => { | |
| 32 | servers.stop(); | |
| 33 | app.close(); | |
| 34 | await rm(dataDir, { recursive: true, force: true }); | |
| 35 | }); | |
| 36 | ||
| 37 | test("the feed page shows a run post's Run log link", async () => { | |
| 38 | const text = await freshHome(servers.url, cookie, "/feed"); | |
| 39 | expect(text.split("data-depth").length).toBe(2); | |
| 40 | expect(text).toMatch(/<a href="\/alice\/open\/runs\/r0" data-depth>Run log<\/a>/); | |
| 41 | }); |
test/feed-depth.test.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** Each post kind shows one plain link one step deeper: run log, pull diff or issue thread. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { depthLine, depthOf } from "../src/feed/depth.ts"; | |
| 4 | import type { FeedItem } from "../src/feed/rank.ts"; | |
| 5 | import { feedNote } from "../src/tui/screens/feed.ts"; | |
| 6 | import { feedCard } from "../src/web/studio/feed.ts"; | |
| 7 | ||
| 8 | const card = (kind: FeedItem["kind"], link: string): string => | |
| 9 | String(feedCard({ id: "i1", kind, app: "a/b", actor: "a", at: new Date().toISOString(), link, what: "W", reason: "", score: 1 })); | |
| 10 | ||
| 11 | test("a run post links its run log", () => { | |
| 12 | expect(card("run", "/a/b/runs/r1")).toContain('<a href="/a/b/runs/r1" data-depth>Run log</a>'); | |
| 13 | }); | |
| 14 | test("a failed run links the log without the line anchor", () => { | |
| 15 | expect(card("run", "/a/b/runs/r1?all=1#L3")).toContain('<a href="/a/b/runs/r1" data-depth>'); | |
| 16 | }); | |
| 17 | test("a pull post links its diff", () => { | |
| 18 | expect(card("pull", "/a/b/pulls/4")).toContain('<a href="/a/b/pulls/4/files" data-depth>Diff</a>'); | |
| 19 | }); | |
| 20 | test("a tell (issue) post links its thread", () => { | |
| 21 | expect(card("tell", "/a/b/issues/7")).toContain('<a href="/a/b/issues/7" data-depth>Thread</a>'); | |
| 22 | }); | |
| 23 | test("a look of a pull links its diff", () => { | |
| 24 | expect(card("look", "/a/b/pulls/4")).toContain('<a href="/a/b/pulls/4/files" data-depth>'); | |
| 25 | }); | |
| 26 | test("a reply links the thread it answers", () => { | |
| 27 | expect(card("reply", "/a/b/issues/7#c1")).toContain('<a href="/a/b/issues/7" data-depth>'); | |
| 28 | }); | |
| 29 | test("no depth where the link is not one, or is another app's", () => { | |
| 30 | expect(card("run", "/a/b/app")).not.toContain("data-depth"); | |
| 31 | expect(card("look", "/a/b")).not.toContain("data-depth"); | |
| 32 | expect(depthOf({ kind: "pull", app: "a/b", link: "/x/y/pulls/4" })).toBeUndefined(); | |
| 33 | }); | |
| 34 | ||
| 35 | test("the link is the only data-depth anchor on a card, and has no arrow glyph", () => { | |
| 36 | const out = card("pull", "/a/b/pulls/4"); | |
| 37 | expect(out.split("data-depth").length).toBe(2); | |
| 38 | expect(out).not.toContain("→"); | |
| 39 | }); | |
| 40 | test("each kind has its label and address as plain data", () => { | |
| 41 | const at = (kind: string, link: string) => depthOf({ kind, app: "a/b", link }); | |
| 42 | expect(at("run", "/a/b/runs/r1")).toEqual({ label: "Run log", href: "/a/b/runs/r1" }); | |
| 43 | expect(at("pull", "/a/b/pulls/4")).toEqual({ label: "Diff", href: "/a/b/pulls/4/files" }); | |
| 44 | expect(at("tell", "/a/b/issues/7")).toEqual({ label: "Thread", href: "/a/b/issues/7" }); | |
| 45 | expect(at("look", "/a/b/pulls/4")?.label).toBe("Diff"); | |
| 46 | expect(at("reply", "/a/b/issues/7#c1")?.label).toBe("Thread"); | |
| 47 | expect(at("issue", "/a/b/issues/7")).toBeUndefined(); // there is no issue kind: an issue post is a tell | |
| 48 | }); | |
| 49 | test("the terminal feed prints the same label and address", () => { | |
| 50 | const item = { id: "i", kind: "pull", app: "a/b", link: "/a/b/pulls/4" } as unknown as FeedItem; | |
| 51 | expect(depthLine(item)).toBe("Diff: /a/b/pulls/4/files"); | |
| 52 | expect(feedNote(item)).toEqual({ note: "Diff: /a/b/pulls/4/files" }); | |
| 53 | expect(feedNote({ ...item, kind: "run", link: "/a/b/app" } as FeedItem)).toEqual({}); | |
| 54 | }); |
new above
offline
Both doors: nothing in src/tui/ consumes this, and there is no docs/features page. Add both.