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 #5177

Parked opened this
Closed without merging

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

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
9 files changed +176 −22
README.md +4 −2
@@ -998,9 +998,11 @@ 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). Not checked: no 390×844 or 1440×900 look has been taken of
1005 the open panel, and nothing here claims that opening it shifts nothing.
10041006 From the terminal, a repository screen that is an app has two palette rows
10051007 (`:`): *Tell the builders* sends a note as you, and *Notes from the app*
10061008 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");
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 +20
@@ -1025,6 +1025,26 @@ 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 * One scan of the repository's merged pulls per call (instr on the body),
1032 * so a caller asks once per closed note: fine for a handful of notes.
1033 */
1034 export function mergedPullsClosing(db: Database, repoId: string, number: number): Pull[] {
1035 const ids = db
1036 .query<{ issue_id: string }, [string, string]>(
1037 `SELECT pull.issue_id FROM pull JOIN issue ON issue.id = pull.issue_id
1038 WHERE issue.repo_id = ?1 AND pull.merged_at IS NOT NULL
1039 AND instr(issue.body, ?2) > 0
1040 ORDER BY pull.merged_at ASC`,
1041 )
1042 .all(repoId, `#${number}`)
1043 .map((r) => r.issue_id);
1044 const issues = getIssuesByIds(db, ids);
1045 return joinMany(db, ids.map((id) => issues.get(id)).filter((i): i is Issue => i !== undefined));
1046 }
1047
10281048 /**
10291049 * Open pulls of a repository by the issue number each would close: the
10301050 * 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 +74 −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";
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,73 @@ 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
343 test("a release that lists a pull which does not close the note, or a note closed with no reason, says what it can", async () => {
344 const repo = getRepo(app.db, "alice", "notes")!;
345 const mk = (title: string, body: string, kind: "issue" | "pull") => {
346 const r = createIssue(app.db, { repoId: repo.id, authorId: alice.id, title, body, kind });
347 if (!r.ok) throw new Error(r.error);
348 return r.value;
349 };
350 const merge = (id: string) =>
351 app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'g', 'a', 'b', '2026-10-20T10:00:00.000Z')").run(id);
352 const { shippedPulls, statusOf } = await import("../src/actions/app_notes.ts");
353 // A pull that only mentions the note ("see #N") is in release 9.9.9, but did not close it.
354 const note = mk("Mentioned only", "x", "issue");
355 const mention = mk("Related", `Refs: see #${note.number}`, "pull");
356 merge(mention.id);
357 setIssueState(app.db, note.id, "closed", "done");
358 expect(statusOf(app, repo, note.number, new Map([[mention.number, "9.9.9"]]))!.status.label).toMatch(/^Shipped on \d{4}-\d\d-\d\d$/);
359 // closeReason null: closed by a merged pull that a release lists.
360 const bare = mk("No reason", "y", "issue");
361 const fix = mk("Fix", `Closes #${bare.number}`, "pull");
362 merge(fix.id);
363 app.db.query("UPDATE issue SET state = 'closed', close_reason = NULL WHERE id = ?1").run(bare.id);
364 expect(statusOf(app, repo, bare.number, new Map([[fix.number, "9.9.9"]]))!.status.label).toBe("Shipped in 9.9.9");
365 expect(statusOf(app, repo, bare.number)!.status.label).toBe("Shipped on 2026-10-20");
366 expect(typeof shippedPulls).toBe("function");
367 });
368
300369 test("a private app takes notes from a signed-in reader, as themselves, and from no one else", async () => {
301370 const reader = await grantedCookie(app, servers.url, alice, getAppBySlug(app.db, "diary")!);
outdated

This assertion passes on the base, because position:fixed already exists on the host. It would not fail without the change, so it proves nothing about "opening moves nothing". Remove it, or test real behaviour.

302371 const res = await post("A note on the diary", reader, "10.5.0.1", "diary");
@@ -315,9 +384,13 @@ describe("the forge button takes notes from anyone", () => {
315384 test("the panel fits a phone and a desktop, and says no forge words first", () => {
316385 // 390x844: at most 320px wide within the viewport, and 70% high leaves the top (camera) clear.
317386 expect(toolbarJs).toContain("max-width:min(320px,calc(100vw - 64px))");
318 expect(toolbarJs).toContain("max-height:min(70vh,calc(100vh - 88px))");
387 expect(toolbarJs).toContain("max-height:min(70vh,calc(100vh - 72px))");
319388 expect(toolbarJs).toContain("Tell the builders");
320389 expect(toolbarJs).toContain("What is this?");
321390 expect(toolbarJs).toContain("font:16px");
391 // The camera: nothing of the pill or its panel sits in the top 48 px.
392 expect(toolbarJs).toContain('"max(48px,env(safe-area-inset-top))"');
393 expect(toolbarJs).toContain("Math.max(48, Math.min(window.innerHeight - 44");
394 expect(toolbarJs).toContain("calc(100dvh - 72px)");
322395 });
323396 });
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 });
test/tui-notes.test.ts +26 −2
@@ -11,9 +11,10 @@ import { join } from "node:path";
1111 import { newApp } from "../src/actions/apps.ts";
1212 import { createRepo } from "../src/actions/repos.ts";
1313 import { createApp, type App } from "../src/app.ts";
14 import { isBanned } from "../src/core/app_notes.ts";
14 import { insertNote, isBanned } from "../src/core/app_notes.ts";
1515 import { getAppBySlug } from "../src/core/apps.ts";
16 import { getIssue, labelsFor } from "../src/core/issues.ts";
16 import { editFiles } from "../src/actions/contents.ts";
17 import { createIssue, getIssue, labelsFor, setIssueState } from "../src/core/issues.ts";
1718 import { getRepo, type Repo } from "../src/core/repos.ts";
1819 import { createUser, type User } from "../src/core/users.ts";
1920 import { createForgeApp } from "../src/tui/forge.ts";
@@ -106,4 +107,27 @@ describe("notes from the app, in the terminal", () => {
106107 const record = getAppBySlug(app.db, "notes")!;
107108 expect(isBanned(app.db, record.id, `u:${bob.id}`)).toBe(true);
108109 });
110
111 test("the terminal names the release that shipped a note, as the page does", async () => {
112 // bob's note was banned above; alice has one of her own, filed as the page would.
113 const own = createIssue(app.db, { repoId: notes.id, authorId: alice.id, title: "Add a dark mode", body: "from the app", kind: "issue" });
114 if (!own.ok) throw new Error(own.error);
115 const row = { issue_number: own.value.number };
116 insertNote(app.db, { appId: getAppBySlug(app.db, "notes")!.id, repoId: notes.id, issueNumber: row.issue_number, visitor: `u:${alice.id}`, name: "@alice" });
117 const fix = createIssue(app.db, { repoId: notes.id, authorId: alice.id, title: "Fix blur", body: `Closes #${row.issue_number}`, kind: "pull" });
118 if (!fix.ok) throw new Error(fix.error);
119 app.db
120 .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')")
121 .run(fix.value.id);
122 setIssueState(app.db, getIssue(app.db, notes.id, row.issue_number)!.id, "closed", "done");
123 expect(await palette(alice, notes, [":", "Notes from", "\r", "\r"])).toContain("Shipped on 2026-10-20");
124 const wave = [
125 "---", "version: 9.9.9", "date: 2026-10-21", "headline: A release", "---", "", "## Highlights", "",
126 "- **One** — why", "- **Two** — why", "- **Three** — why", "", "## Pulls", "",
127 `- [#${fix.value.number} Fix](http://forge.test/alice/notes/pulls/${fix.value.number})`, "",
128 ].join("\n");
129 const edited = await editFiles(app, alice, notes, { branch: "main", message: "wave", files: [{ path: "waves/9.9.9.md", content: wave }] });
130 if (!edited.ok) throw new Error(JSON.stringify(edited.error));
131 expect(await palette(alice, notes, [":", "Notes from", "\r", "\r"])).toContain("Shipped in 9.9.9");
132 });
109133 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs