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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/14052-a-tell-sent-from-an-app-s-toolbar-carrie → main 3 commits fork 1 thread · 1 unresolved

  • Merged. torque/14052-a-tell-sent-from-an-app-s-toolbar-carrie was merged into main as 919f7e2.

Review

Sign in to review this change.
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.
2828 (`src/tui/screens/yours.ts`). Who the reader is comes from the app's own grant,
2929 read by `/__forge/crew`, never from the page.
3030 - **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
3333 environment, never the client's word) and up to five recent console errors
3434 (`console.error`, uncaught errors and unhandled rejections, message text
3535 only). Each error is cut to 200 characters, control characters, URL queries
3636 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
3938 fold is closed until opened.
4039 - **No layout shift:** it is `position: fixed` inside a closed shadow root and
4140 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
2929
3030 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.
3131
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.
3333
3434 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.
3535
src/actions/app_notes.ts +2 −5
@@ -254,12 +254,9 @@ export async function sendNote(
254254 "",
255255 fence(text),
256256 "",
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})`}`,
261258 `- 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 });
263260 // The label exists before the issue does, so a mirror's origin can apply it too.
264261 if (getLabel(app.db, repo.id, FROM_APP_LABEL) === undefined) createLabel(app.db, repo.id, FROM_APP_LABEL, LABEL_COLOR);
265262 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 @@
11 /**
22 * What a note from the forge pill says about where it came from (#10827):
33 * 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
65 * is checked at the boundary and bounded; what passes is a fold at the foot
76 * of the issue, never its headline. Console text can hold secrets, so only
87 * 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
4948 return { build: build !== undefined && BUILD.test(build) ? build : "", errors: list };
5049 }
5150
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 {
5558 const lines = [
59 where.page === undefined ? "" : `- Page: ${where.page === "" ? "unknown" : `\`${where.page.replace(/`/g, "%60")}\``}`,
60 where.viewport === undefined ? "" : `- Viewport: ${where.viewport}`,
5661 c.build === "" ? "" : `- Build: \`${c.build}\``,
5762 // The sender's browser's words, unchecked: data, not instructions.
5863 ...c.errors.map((e) => `- Console error: \`${e.replace(/`/g, "'")}\``),
5964 ].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");
6167 }
test/apps-feedback.test.ts +2 −2
@@ -146,7 +146,7 @@ describe("the forge button takes notes from anyone", () => {
146146 };
147147 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 }];
148148 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>");
150150 expect(body).toContain("- Build: `c0ffee1234567890abcdef`"); // the forge's, never the client's `build`
151151 expect(body).not.toContain("deadbeef");
152152 expect(body).not.toContain("- Path:");
@@ -251,7 +251,7 @@ describe("the forge button takes notes from anyone", () => {
251251 expect(issues()).toBe(before + 1);
252252 // The note says which pull the preview shows, as a link the owner can open.
253253 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)";
255255 expect(filed.body).toContain(context);
256256 // The brief an agent reads carries that line inside the fence, not outside it.
257257 const out = taskPrompt({
test/note-context.test.ts +16 −3
@@ -89,21 +89,34 @@ describe("a note's issue", () => {
8989 if (!sent.ok) throw new Error(sent.error.message);
9090 const issue = getIssue(app.db, repo.id, sent.value.number)!;
9191 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>");
9393 expect(issue.body).toContain(`- Build: \`${BUILD}\``);
9494 expect(issue.body).not.toContain("- Path:");

This comment is stale: the Page line now lives inside the Context fold.

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
9696 const errors = issue.body.split("\n").filter((l) => l.startsWith("- Console error:"));
9797 expect(errors.length).toBe(2);
9898 expect(errors[1]!.length).toBeLessThanOrEqual(200 + 20);
9999 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>");
101101 expect(html).not.toContain("<img");
102102 expect(html).toContain("&lt;img");
103103 expect(html.match(/<\/details>/g)!.length).toBe(1);
104104 });
105105 });
106106
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
107120 test("the pill sends the last console errors with a note", () => {
108121 expect(toolbarJs).toContain("errors: errs.slice(-5)");
109122 expect(toolbarJs).toContain('"unhandledrejection"');

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs