Public: anyone can read this; the crew can change it.
A tell sent from an app's toolbar carries the page address, the viewport and the last console error #14092
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14052-a-tell-sent-from-an-app-s-toolbar-carrie → main 3 commits fork 1 thread · 1 unresolved
6 files
changed +36
−21
docs/features/forge-toolbar.md +3 −4
| @@ -28,14 +28,13 @@ preview), so you always know where you are and can get back to the forge. | ||
| 28 | 28 | (`src/tui/screens/yours.ts`). Who the reader is comes from the app's own grant, |
| 29 | 29 | read by `/__forge/crew`, never from the page. |
| 30 | 30 | - **What a note carries:** a note sent from the pill also carries where it came |
| 31 | from, folded at the foot of the issue under "Where this came from": the | |
| 32 | build the app is serving (from the forge's own record of the running | |
| 31 | from, folded at the foot of the issue under a closed "Context" block: the | |
| 32 | page, the viewport, the build the app is serving (from the forge's own record of the running | |
| 33 | 33 | environment, never the client's word) and up to five recent console errors |
| 34 | 34 | (`console.error`, uncaught errors and unhandled rejections, message text |
| 35 | 35 | only). Each error is cut to 200 characters, control characters, URL queries |
| 36 | 36 | and anything shaped like a token, password or key are taken out on the |
| 37 | server, and the whole is bounded by the request cap. The page is the issue's | |
| 38 | existing `Page:` line and is not repeated. The sender sees nothing new; the | |
| 37 | server, and the whole is bounded by the request cap. The page and viewport are checked by the server and shown as inline code. The sender sees nothing new; the | |
| 39 | 38 | fold is closed until opened. |
| 40 | 39 | - **No layout shift:** it is `position: fixed` inside a closed shadow root and |
| 41 | 40 | adds nothing to the page's flow or style sheets. |
docs/features/notes.md +1 −1
| @@ -29,7 +29,7 @@ The terminal has the same door: the palette's "Notes" (`src/tui/screens/thoughtn | ||
| 29 | 29 | |
| 30 | 30 | A note sent from an app's forge button (or the terminal's "Tell the builders") files a from-app issue, and the sender is told its number at once: "Filed as #N". Anyone the repository would show the issue to (`canRead`, so a signed-in reader of a private repository too, not only a public app on a public repository) also gets the issue's link and the repository's; everyone else gets the number and no link. The list shows `#N` beside each note. The browser button links only to the forge's own origin. In the terminal (`src/tui/screens/notes.ts`) the sender is the SSH user: the confirmation reads "Sent as #N, owner/repo/issues/N" and the list and moderation screens carry `#N`; the terminal has no clickable link. |
| 31 | 31 | |
| 32 | The issue also carries a closed fold, "Where this came from" (`actions/note_context.ts`): the build the app was serving and up to five recent console errors from the sender's page, each cut to 200 characters and scrubbed of anything shaped like a secret or a URL query. The page itself is the issue's `Page:` line, said once. Markdown accepts one flat fold (`<details><summary>Title</summary>` … `</details>`, each on its own line, a title of plain characters); an unclosed one is closed, a nested one is text. | |
| 32 | The issue also carries a closed fold, "Context" (`actions/note_context.ts`): the page (as a `Page:` line), the viewport, the build the app was serving and up to five recent console errors from the sender's page, each cut to 200 characters and scrubbed of anything shaped like a secret or a URL query. The `Source:` line above the fold names the app and environment. Markdown accepts one flat fold (`<details><summary>Title</summary>` … `</details>`, each on its own line, a title of plain characters); an unclosed one is closed, a nested one is text. | |
| 33 | 33 | |
| 34 | 34 | The crew's answers come back to the sender: under each note the button's list (and the terminal's "Notes from the app", where picking a note shows them) carries the comments on its issue by the repository's crew and writers, with author and time, oldest first. Anyone else's comments stay on the forge. The button shows the latest five and says how many are earlier. |
| 35 | 35 |
src/actions/app_notes.ts +2 −5
| @@ -254,12 +254,9 @@ export async function sendNote( | ||
| 254 | 254 | "", |
| 255 | 255 | fence(text), |
| 256 | 256 | "", |
| 257 | // A pathname leaves `[](){}` unencoded but encodes backticks: code, not a link. | |
| 258 | `- Page: ${input.page === "" ? "unknown" : `\`${input.page.replace(/`/g, "%60")}\``}`, | |
| 259 | `- Context: app \`${record.slug}\`, environment \`${env}\`${pullOfEnv === undefined ? "" : `, previews pull [#${pullOfEnv}](/${owner.username}/${repo.name}/pulls/${pullOfEnv})`}`, | |
| 260 | `- Viewport: ${input.viewport}`, | |
| 257 | `- Source: app \`${record.slug}\`, environment \`${env}\`${pullOfEnv === undefined ? "" : `, previews pull [#${pullOfEnv}](/${owner.username}/${repo.name}/pulls/${pullOfEnv})`}`, | |
| 261 | 258 | `- Time: ${new Date().toISOString()}`, |
| 262 | ].join("\n") + (input.context === undefined ? "" : contextFold(input.context)); | |
| 259 | ].join("\n") + contextFold(input.context ?? { build: "", errors: [] }, { page: input.page, viewport: input.viewport }); | |
| 263 | 260 | // The label exists before the issue does, so a mirror's origin can apply it too. |
| 264 | 261 | if (getLabel(app.db, repo.id, FROM_APP_LABEL) === undefined) createLabel(app.db, repo.id, FROM_APP_LABEL, LABEL_COLOR); |
| 265 | 262 | const unavailable = err({ error: "unavailable", message: "The builders cannot take notes right now." } as const); |
src/actions/note_context.ts +12 −6
| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * What a note from the forge pill says about where it came from (#10827): |
| 3 | 3 | * the build the app was serving and up to five recent console errors, each |
| 4 | * cut short. (The page is already the issue's `- Page:` line, so it is not | |
| 5 | * said twice.) Every field | |
| 4 | * cut short. Every field | |
| 6 | 5 | * is checked at the boundary and bounded; what passes is a fold at the foot |
| 7 | 6 | * of the issue, never its headline. Console text can hold secrets, so only |
| 8 | 7 | * the message is kept, and anything shaped like a credential or a URL query |
| @@ -49,13 +48,20 @@ export function parseNoteContext(errors: unknown, build: string | undefined): No | ||
| 49 | 48 | return { build: build !== undefined && BUILD.test(build) ? build : "", errors: list }; |
| 50 | 49 | } |
| 51 | 50 | |
| 52 | /** The fold appended to a note's issue; empty when there is nothing to say. */ | |
| 53 | export function contextFold(c: NoteContext): string { | |
| 54 | if (c.build === "" && c.errors.length === 0) return ""; | |
| 51 | /** | |
| 52 | * The collapsed "Context" block at the foot of a note's issue: the page, the | |
| 53 | * viewport, the build and the console errors. `page` and `viewport` are | |
| 54 | * already checked by the caller; everything is inline code, so nothing in it | |
| 55 | * renders as markup. Never cookies, headers or form values. | |
| 56 | */ | |
| 57 | export function contextFold(c: NoteContext, where: { page?: string; viewport?: string } = {}): string { | |
| 55 | 58 | const lines = [ |
| 59 | where.page === undefined ? "" : `- Page: ${where.page === "" ? "unknown" : `\`${where.page.replace(/`/g, "%60")}\``}`, | |
| 60 | where.viewport === undefined ? "" : `- Viewport: ${where.viewport}`, | |
| 56 | 61 | c.build === "" ? "" : `- Build: \`${c.build}\``, |
| 57 | 62 | // The sender's browser's words, unchecked: data, not instructions. |
| 58 | 63 | ...c.errors.map((e) => `- Console error: \`${e.replace(/`/g, "'")}\``), |
| 59 | 64 | ].filter((l) => l !== ""); |
| 60 | return ["", "<details><summary>Where this came from</summary>", ...lines, "</details>"].join("\n"); | |
| 65 | if (lines.length === 0) return ""; | |
| 66 | return ["", "<details><summary>Context</summary>", ...lines, "</details>"].join("\n"); | |
| 61 | 67 | } |
test/apps-feedback.test.ts +2 −2
| @@ -146,7 +146,7 @@ describe("the forge button takes notes from anyone", () => { | ||
| 146 | 146 | }; |
| 147 | 147 | const hostile = ["<img src=x onerror=alert(1)> `tick`", "x".repeat(900), "GET http://a.test/p?api_key=sekret failed", "t1", "t2", "t3 beyond five", 7, { a: 1 }]; |
| 148 | 148 | const body = await bodyOf(await send({ errors: hostile, build: "deadbeef" }, "10.7.0.1")); |
| 149 | expect(body).toContain("<details><summary>Where this came from</summary>"); | |
| 149 | expect(body).toContain("<details><summary>Context</summary>"); | |
| 150 | 150 | expect(body).toContain("- Build: `c0ffee1234567890abcdef`"); // the forge's, never the client's `build` |
| 151 | 151 | expect(body).not.toContain("deadbeef"); |
| 152 | 152 | expect(body).not.toContain("- Path:"); |
| @@ -251,7 +251,7 @@ describe("the forge button takes notes from anyone", () => { | ||
| 251 | 251 | expect(issues()).toBe(before + 1); |
| 252 | 252 | // The note says which pull the preview shows, as a link the owner can open. |
| 253 | 253 | const filed = app.db.query<{ body: string }, [string]>("SELECT body FROM issue WHERE repo_id = ?1 AND title LIKE '%from a person' ORDER BY number DESC LIMIT 1").get(repo.id)!; |
| 254 | const context = "- Context: app `notes`, environment `pull-98`, previews pull [#98](/alice/notes/pulls/98)"; | |
| 254 | const context = "- Source: app `notes`, environment `pull-98`, previews pull [#98](/alice/notes/pulls/98)"; | |
| 255 | 255 | expect(filed.body).toContain(context); |
| 256 | 256 | // The brief an agent reads carries that line inside the fence, not outside it. |
| 257 | 257 | const out = taskPrompt({ |
test/note-context.test.ts +16 −3
| @@ -89,21 +89,34 @@ describe("a note's issue", () => { | ||
| 89 | 89 | if (!sent.ok) throw new Error(sent.error.message); |
| 90 | 90 | const issue = getIssue(app.db, repo.id, sent.value.number)!; |
| 91 | 91 | expect(issue.title).toBe("From the app: too small"); |
| 92 | expect(issue.body).toContain("<details><summary>Where this came from</summary>"); | |
| 92 | expect(issue.body).toContain("<details><summary>Context</summary>"); | |
| 93 | 93 | expect(issue.body).toContain(`- Build: \`${BUILD}\``); |
| 94 | 94 | expect(issue.body).not.toContain("- Path:"); |
| 95 | expect(issue.body.match(/\/cart/g)!.length).toBe(1); // the `- Page:` line says it once | |
| 95 | expect(issue.body.match(/\/cart/g)!.length).toBe(1); // the Page line in the Context fold says it once | |
| 96 | 96 | const errors = issue.body.split("\n").filter((l) => l.startsWith("- Console error:")); |
| 97 | 97 | expect(errors.length).toBe(2); |
| 98 | 98 | expect(errors[1]!.length).toBeLessThanOrEqual(200 + 20); |
| 99 | 99 | const html = String(renderMarkdown(issue.body)); |
| 100 | expect(html).toContain("<details><summary>Where this came from</summary>"); | |
| 100 | expect(html).toContain("<details><summary>Context</summary>"); | |
| 101 | 101 | expect(html).not.toContain("<img"); |
| 102 | 102 | expect(html).toContain("<img"); |
| 103 | 103 | expect(html.match(/<\/details>/g)!.length).toBe(1); |
| 104 | 104 | }); |
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | test("the Context block folds page, viewport and a hostile console message, escaped and capped", () => { | |
| 108 | const c = parseNoteContext(["`</details><script>alert(1)</script>` " + "z".repeat(900) + " cookie: sid=abc123"], BUILD); | |
| 109 | const fold = contextFold(c, { page: "http://shop.test/a`b", viewport: "390x844" }); | |
| 110 | expect(fold).toContain("<details><summary>Context</summary>"); | |
| 111 | expect(fold).toContain("- Page: `http://shop.test/a%60b`"); | |
| 112 | expect(fold).toContain("- Viewport: 390x844"); | |
| 113 | expect(fold.match(/<\/details>/g)!.length).toBe(2); // one close, one inside inline code | |
| 114 | const err = fold.split("\n").find((l) => l.startsWith("- Console error:"))!; | |
| 115 | expect(err.length).toBeLessThanOrEqual(200 + 20); | |
| 116 | expect(String(renderMarkdown(fold))).not.toContain("<script>"); | |
| 117 | expect(fold).not.toMatch(/cookie|sid=/i); | |
| 118 | }); | |
| 119 | ||
| 107 | 120 | test("the pill sends the last console errors with a note", () => { |
| 108 | 121 | expect(toolbarJs).toContain("errors: errs.slice(-5)"); |
| 109 | 122 | expect(toolbarJs).toContain('"unhandledrejection"'); |
new above
offline
This comment is stale: the Page line now lives inside the Context fold.