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

A note's status says which version shipped it, and the panel is checked at 390×844 and 1440×900 #5101

Parked opened this
Closed without merging

scout/forge:scout/4821-a-note-s-status-says-which-version-shipp → main 1 commit fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +123 −20
README.md +3 −2
@@ -998,9 +998,10 @@ Under the box, four starter sentences are plain links (no script):
998998 `@name`. Moderation: 3 notes a minute per sender, 6 per source address, 20 per
999999 app, a word filter, and the owner's hide or ban, which closes the issue and, for
10001000 `ban`, refuses that sender. `GET /__forge/notes` gives the sender's own notes with a live
1001 status (queued, being built by a member, shipped on a date), polled every 15 s
1001 status (queued, being built by a member, "Shipped on <date>" once a pull that closes it has merged, "Shipped in <version>" once a wave (`waves/<version>.md` on the default branch) lists that pull), polled every 15 s
10021002 while the panel is open; a public app's note links to its issue. Left out: the
1003 optional screenshot and a version name in "shipped".
1003 optional screenshot. The pill and its panel stay out of the top 48 px of the
1004 screen (the camera) and are fixed beside the pill, so opening moves nothing.
10041005 From the terminal, a repository screen that is an app has two palette rows
10051006 (`:`): *Tell the builders* sends a note as you, and *Notes from the app*
10061007 lists yours with their status; the repository's admin sees every sender's and
src/actions/app_notes.ts +42 −7
@@ -12,10 +12,13 @@ import { createLabel, getIssue, getLabel } from "../core/issues.ts";
1212 import { RateLimiter } from "../core/ratelimit.ts";
1313 import { canAdmin, type Repo } from "../core/repos.ts";
1414 import { plainText } from "../core/reports.ts";
15 import { closesFromBody, mergedPullsClosing } from "../core/pulls.ts";
1516 import { workingAgentRuns } from "../core/runs.ts";
1617 import { getUserById, isActive, type User } from "../core/users.ts";
1718 import { unadoptedAmong } from "../crew/direct.ts";
19 import { repoDir } from "../git/repos.ts";
1820 import { err, ok, type Result } from "../kernel/result.ts";
21 import { readWaves } from "../story/waves.ts";
1922 import { openIssueThrough, setIssueLabelsThrough, setIssueStateThrough } from "./issues.ts";
2023
2124 export const FROM_APP_LABEL = "from-app";
@@ -94,15 +97,44 @@ export interface NoteView {
9497 readonly url?: string;
9598 }
9699
100 /** Pull number → the name of the oldest release that lists it. */
101 export type Shipped = ReadonlyMap<number, string>;
102
103 /** The releases (waves on the default branch) and the pulls each lists. */
104 export async function shippedPulls(app: App, repo: Repo): Promise<Shipped> {
105 const out = new Map<number, string>();
106 const entries = await readWaves(repoDir(app.reposRoot, repo.ownerName, repo.name), repo.defaultBranch);
107 // Newest first: a later (older) release overwrites, so the oldest names it.
108 for (const e of entries) {
109 if (!e.ok) continue;
110 for (const p of e.wave.pulls) {
111 const n = /\/pulls\/(\d+)\/?$/.exec(p.url)?.[1];
112 if (n !== undefined) out.set(Number(n), e.wave.version);
113 }
114 }
115 return out;
116 }
117
118 /** The merged pull that closed this issue, if one did. */
119 function closedBy(app: App, repo: Repo, number: number) {
120 return mergedPullsClosing(app.db, repo.id, number).find((p) => closesFromBody(p.body).includes(number));
121 }
122
97123 /** Where a note stands, read from the issue as it moves. */
98 export function statusOf(app: App, repo: Repo, number: number): { status: NoteStatus; title: string } | undefined {
124 export function statusOf(app: App, repo: Repo, number: number, shipped: Shipped = new Map()): { status: NoteStatus; title: string } | undefined {
99125 const issue = getIssue(app.db, repo.id, number);
100126 if (issue === undefined) return undefined;
101127 if (issue.state === "closed") {
102128 const when = (issue.closedAt ?? issue.updatedAt).slice(0, 10);
103129 // Only "done" is a promise kept; the other reasons say what they are.
104 if (issue.closeReason === "done" || issue.closeReason === null)
105 return { title: issue.title, status: { state: "shipped", label: `Shipped on ${when}` } };
130 if (issue.closeReason === "done" || issue.closeReason === null) {
131 const pull = closedBy(app, repo, number);
132 const release = pull === undefined ? undefined : shipped.get(pull.number);
133 if (pull !== undefined && release !== undefined)
134 return { title: issue.title, status: { state: "shipped", label: `Shipped in ${release}` } };
135 const day = pull?.mergedAt?.slice(0, 10) ?? when;
136 return { title: issue.title, status: { state: "shipped", label: `Shipped on ${day}` } };
137 }
106138 const label = issue.closeReason === "parked" ? "Set aside for now" : issue.closeReason === "split" ? "Split into smaller pieces" : "Closed without a change";
107139 return { title: issue.title, status: { state: "closed", label: `${label} (${when})` } };
108140 }
@@ -117,8 +149,8 @@ export function statusOf(app: App, repo: Repo, number: number): { status: NoteSt
117149 return { title: issue.title, status: { state: "queued", label: "In the queue for a builder" } };
118150 }
119151
120 function view(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, note: AppNote): NoteView | undefined {
121 const found = statusOf(app, repo, note.issueNumber);
152 function view(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, note: AppNote, shipped: Shipped = new Map()): NoteView | undefined {
153 const found = statusOf(app, repo, note.issueNumber, shipped);
122154 if (found === undefined) return undefined;
123155 const open = forgeUrl !== undefined && record.access === "public" && repo.visibility === "public";
124156 return {
@@ -132,9 +164,12 @@ function view(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefi
132164 }
133165
134166 /** A sender's own notes; an admin of the repository may ask for every sender's. */
135 export function notesFor(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, sender: Sender, everyone = false): NoteView[] {
167 export async function notesFor(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, sender: Sender, everyone = false): Promise<NoteView[]> {
136168 const rows = everyone ? notesOfApp(app.db, record.id) : notesOf(app.db, record.id, sender.key);
137 return rows.map((n) => view(app, record, repo, forgeUrl, n)).filter((n): n is NoteView => n !== undefined);
169 // Git is read only when some note is already closed: an open one cannot have shipped.
170 const closed = rows.some((n) => getIssue(app.db, repo.id, n.issueNumber)?.state === "closed");

Every poll of an open panel re-reads waves from git once one note is closed. Cache by the default branch head oid.

171 const shipped = closed ? await shippedPulls(app, repo) : new Map<number, string>();
172 return rows.map((n) => view(app, record, repo, forgeUrl, n, shipped)).filter((n): n is NoteView => n !== undefined);
138173 }
139174
140175 /** The longest run of backticks in `text`, so the fence can be longer. */
src/apps/feedback.ts +2 −2
@@ -154,9 +154,9 @@ async function send(ask: FeedbackAsk, door: Door): Promise<Response> {
154154 return json(201, { note: sent.value, name: sender.name }, cookies);
155155 }
156156
157 function list(ask: FeedbackAsk, door: Door): Response {
157 async function list(ask: FeedbackAsk, door: Door): Promise<Response> {
158158 const { sender, fresh } = senderOf(ask, door);
159 const notes = notesFor(ask.app, ask.record, door.repo, ask.forgeUrl, sender);
159 const notes = await notesFor(ask.app, ask.record, door.repo, ask.forgeUrl, sender);
160160 return json(
161161 200,
162162 { name: sender.name, notes, admin: door.viewer !== undefined && canAdmin(ask.app.db, door.repo, door.viewer) },
src/apps/toolbar.ts +3 −3
@@ -40,7 +40,7 @@ export const toolbarJs = `(function () {
4040 panel.setAttribute("role", "region");
4141 panel.setAttribute("aria-label", "Where you are");
4242 panel.tabIndex = -1;
43 panel.style.cssText = "outline:none;background:#1f2328;color:#fff;padding:8px 12px;border-radius:14px;box-shadow:0 1px 4px rgba(0,0,0,.4);max-width:min(320px,calc(100vw - 64px));max-height:min(70vh,calc(100vh - 88px));overflow:auto;flex-direction:column;gap:2px;display:none";
43 panel.style.cssText = "outline:none;background:#1f2328;color:#fff;padding:8px 12px;border-radius:14px;box-shadow:0 1px 4px rgba(0,0,0,.4);max-width:min(320px,calc(100vw - 64px));max-height:min(70vh,calc(100vh - 72px));max-height:min(70vh,calc(100dvh - 72px));overflow:auto;flex-direction:column;gap:2px;display:none";
4444 function line(text, bold) {
4545 var el = document.createElement("div");
4646 el.textContent = text;
@@ -255,7 +255,7 @@ export const toolbarJs = `(function () {
255255 function place(c) {
256256 corner = c;
257257 var top = c.charAt(0) === "t", left = c.charAt(1) === "l";
258 host.style.top = top ? "12px" : "auto";
258 host.style.top = top ? "max(48px,env(safe-area-inset-top))" : "auto";
259259 host.style.bottom = top ? "auto" : "12px";
260260 host.style.left = left ? "12px" : "auto";
261261 host.style.right = left ? "auto" : "12px";
@@ -279,7 +279,7 @@ export const toolbarJs = `(function () {
279279 host.style.right = "auto";
280280 host.style.bottom = "auto";
281281 host.style.left = Math.max(0, Math.min(window.innerWidth - 44, e.clientX - 22)) + "px";
282 host.style.top = Math.max(0, Math.min(window.innerHeight - 44, e.clientY - 22)) + "px";
282 host.style.top = Math.max(48, Math.min(window.innerHeight - 44, e.clientY - 22)) + "px";
283283 });
284284 function drop(e) {
285285 if (!drag) return;
src/core/pulls.ts +18
@@ -1025,6 +1025,24 @@ export function closesFromBody(body: string): number[] {
10251025 return [...out];
10261026 }
10271027
1028 /**
1029 * Merged pulls whose description mentions `#number`, oldest merge first;
1030 * callers confirm with `closesFromBody` that it is a closing word.
1031 */
1032 export function mergedPullsClosing(db: Database, repoId: string, number: number): Pull[] {
1033 const ids = db
1034 .query<{ issue_id: string }, [string, string]>(
1035 `SELECT pull.issue_id FROM pull JOIN issue ON issue.id = pull.issue_id
1036 WHERE issue.repo_id = ?1 AND pull.merged_at IS NOT NULL
1037 AND instr(issue.body, ?2) > 0
1038 ORDER BY pull.merged_at ASC`,
1039 )

instr on the bare #N also matches #12 for #1 and scans every merged pull of the repo. The closesFromBody filter keeps it correct, but narrow it here.

1040 .all(repoId, `#${number}`)
1041 .map((r) => r.issue_id);
1042 const issues = getIssuesByIds(db, ids);
1043 return joinMany(db, ids.map((id) => issues.get(id)).filter((i): i is Issue => i !== undefined));
1044 }
1045
10281046 /**
10291047 * Open pulls of a repository by the issue number each would close: the
10301048 * work that is proposed and not yet landed, which is neither ready nor
src/tui/screens/notes.ts +2 −2
@@ -48,8 +48,8 @@ export function noteCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R
4848 id: "notes",
4949 title: `${name} — Notes from the app`,
5050 hint: admin ? "every sender's; hide or ban" : "yours, with their status",
51 run: () => {
52 const notes = notesFor(f.app, record, repo, undefined, sender, admin);
51 run: async () => {
52 const notes = await notesFor(f.app, record, repo, undefined, sender, admin);
5353 if (notes.length === 0) return ctx.toast("No notes yet.");
5454 ctx.push(
5555 pickerScreen(ctx, parent(), {
test/apps-feedback.test.ts +50 −1
@@ -19,6 +19,8 @@ import { getNote } from "../src/core/app_notes.ts";
1919 import { grantedCookie } from "./helpers/identity.ts";
2020 import { getIssue, labelsFor, setIssueState } from "../src/core/issues.ts";
2121 import { getRepo } from "../src/core/repos.ts";
22 import { editFiles } from "../src/actions/contents.ts";

createIssue is imported from ../src/core/issues.ts on a second line; merge it into the existing import on line 20.

23 import { createIssue } from "../src/core/issues.ts";
2224 import { createUser, type User } from "../src/core/users.ts";
2325 import { serve, type Servers } from "../src/http/server.ts";
2426 import { quietLogs } from "./helpers/globals.ts";
@@ -297,6 +299,47 @@ describe("the forge button takes notes from anyone", () => {
297299 expect(await Bun.file(join(import.meta.dir, "../src/actions/app_notes.ts")).text()).not.toContain("x-forwarded-for");
298300 });
299301
302 test("a note that a merged pull closed says its release, or the merge date until one includes it", async () => {
303 const repo = getRepo(app.db, "alice", "notes")!;
304 const mergeFixing = (n: number) => {
305 const pull = createIssue(app.db, { repoId: repo.id, authorId: alice.id, title: `Fix ${n}`, body: `Closes #${n}`, kind: "pull" });
306 if (!pull.ok) throw new Error(pull.error);
307 app.db
308 .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'f', 'a', 'b', '2026-10-20T10:00:00.000Z')")
309 .run(pull.value.id);
310 return pull.value.number;
311 };
312 const notes = async (cookie: string) =>
313 ((await (await at("notes", "/__forge/notes", {}, cookie)).json()) as { notes: { text: string; status: { state: string; label: string } }[] }).notes;
314 const ship = async (source: string, text: string) => {
315 const first = await post(text, "", source);
316 const number = Number(((await first.json()) as { note: { url: string } }).note.url.split("/").pop());
317 app.db.query("UPDATE issue SET author_id = ?1 WHERE repo_id = ?2 AND number = ?3").run(alice.id, repo.id, number);
318 const pull = mergeFixing(number);
319 setIssueState(app.db, getIssue(app.db, repo.id, number)!.id, "closed", "done");
320 return { cookie: cookieOf(first), pull };
321 };
322 // Past the earlier tests' day of limits.
323 noteClock.now = () => Date.now() + 3 * 86_400_000;
324 let released, waiting;
325 try {
326 released = await ship("10.5.0.1", "Released fix");
327 waiting = await ship("10.5.0.2", "Merged, not released");
328 } finally {
329 noteClock.now = () => Date.now();
330 }
331 expect((await notes(released.cookie))[0]!.status.label).toBe("Shipped on 2026-10-20");
332 const wave = [
333 "---", "version: 9.9.9", "date: 2026-10-21", "headline: A release", "---", "", "## Highlights", "",
334 "- **One** — why", "- **Two** — why", "- **Three** — why", "", "## Pulls", "",
335 `- [#${released.pull} Fix](http://forge.test/alice/notes/pulls/${released.pull})`, "",
336 ].join("\n");
337 const edited = await editFiles(app, alice, repo, { branch: "main", message: "wave", files: [{ path: "waves/9.9.9.md", content: wave }] });
338 if (!edited.ok) throw new Error(JSON.stringify(edited.error));
339 expect((await notes(released.cookie))[0]!.status).toEqual({ state: "shipped", label: "Shipped in 9.9.9" });
340 expect((await notes(waiting.cookie))[0]!.status.label).toBe("Shipped on 2026-10-20");
341 });
342
300343 test("a private app takes notes from a signed-in reader, as themselves, and from no one else", async () => {
301344 const reader = await grantedCookie(app, servers.url, alice, getAppBySlug(app.db, "diary")!);
302345 const res = await post("A note on the diary", reader, "10.5.0.1", "diary");
@@ -315,9 +358,15 @@ describe("the forge button takes notes from anyone", () => {
315358 test("the panel fits a phone and a desktop, and says no forge words first", () => {
316359 // 390x844: at most 320px wide within the viewport, and 70% high leaves the top (camera) clear.
317360 expect(toolbarJs).toContain("max-width:min(320px,calc(100vw - 64px))");
318 expect(toolbarJs).toContain("max-height:min(70vh,calc(100vh - 88px))");
361 expect(toolbarJs).toContain("max-height:min(70vh,calc(100vh - 72px))");
319362 expect(toolbarJs).toContain("Tell the builders");
320363 expect(toolbarJs).toContain("What is this?");
321364 expect(toolbarJs).toContain("font:16px");
365 // The camera: nothing of the pill or its panel sits in the top 48 px, and
366 // the panel is fixed beside the pill, so opening it moves nothing.
367 expect(toolbarJs).toContain('"max(48px,env(safe-area-inset-top))"');
368 expect(toolbarJs).toContain("Math.max(48, Math.min(window.innerHeight - 44");
369 expect(toolbarJs).toContain("calc(100dvh - 72px)");
370 expect(toolbarJs).toContain("position:fixed");
322371 });
323372 });
test/toolbar-move.test.ts +3 −3
@@ -80,7 +80,7 @@ describe("moving the pill", () => {
8080 fire(pill, "pointermove", { clientX: 100, clientY: 60 });
8181 expect(host.style.left).toBe("78px"); // follows the pointer while dragging
8282 fire(pill, "pointerup", { clientX: 100, clientY: 60 });
83 expect(host.style.top).toBe("12px");
83 expect(host.style.top).toBe("max(48px,env(safe-area-inset-top))");
8484 expect(host.style.left).toBe("12px");
8585 expect(host.style.right).toBe("auto");
8686 expect(box.style.flexDirection).toBe("row");
@@ -88,7 +88,7 @@ describe("moving the pill", () => {
8888 expect(store["forge-pill-corner"]).toBe("tl");
8989 // The next page load puts it there again.
9090 expect(boot(store).host.style.left).toBe("12px");
91 expect(boot(store).host.style.top).toBe("12px");
91 expect(boot(store).host.style.top).toBe("max(48px,env(safe-area-inset-top))");
9292 });
9393
9494 test("a press that barely moves is a tap, not a drag", () => {
@@ -158,6 +158,6 @@ describe("moving the pill", () => {
158158
159159 test("the panel is bounded to the screen", () => {
160160 expect(toolbarJs).toContain("max-width:min(320px,calc(100vw - 64px))");
161 expect(toolbarJs).toContain("max-height:min(70vh,calc(100vh - 88px))");
161 expect(toolbarJs).toContain("max-height:min(70vh,calc(100vh - 72px))");
162162 });
163163 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs