Public: anyone can read this; the crew can change it.
A tell sent from a preview or an app's toolbar carries the page address and the pull it previews into the issue it opens #15671
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15638-a-tell-sent-from-a-preview-or-an-app-s-t → main 0 commits fork 2 threads · 2 unresolved
10 files
changed +54
−32
docs/features/tell-context-app.md +1 −1
| @@ -9,5 +9,5 @@ A tell can say where it was told from. `context.page` is the address (the url) a | ||
| 9 | 9 | - MCP: `tell` takes `context: { page?, app?, pull?, run?, commit?, said? }`. A malformed `app` (not a slug) refuses the whole call. |
| 10 | 10 | - Terminal: `:` then "Tell the crew from a page" asks for the page, the pull, the app (empty to skip), then the line. The app is checked by the same `parseContext`. |
| 11 | 11 | - A door that knows the app itself (the web toolbar passes the repository's name) wins over `context.app`. |
| 12 | - With a pull and a page the body says one `from preview of #N` line in place of the page, pull and app lines. | |
| 12 | - With a pull and a page the body says one `From: <app> /x (preview of #N)` line, last in the block, in place of the page, pull and app lines. | |
| 13 | 13 | - Code: `src/actions/tell_context.ts`, `src/tui/screens/tell.ts`; tests in `test/tell-context.test.ts`, `test/mcp-tell.test.ts`, `test/tui-tell.test.ts`. |
docs/features/toolbar-tell.md +2 −2
| @@ -5,8 +5,8 @@ row: A tell from a preview's toolbar carries its pull | ||
| 5 | 5 | # A tell from a preview's toolbar carries its pull |
| 6 | 6 | |
| 7 | 7 | A tell sent from the forge toolbar of an app or a preview arrives with where it was said. |
| 8 | On a preview the issue's "Where this was told from" block opens with one line, | |
| 9 | `from preview of #N, page /x`, in place of the plain page and pull lines. | |
| 8 | On a preview the issue's "Where this was told from" block ends with one line, | |
| 9 | `From: <app> /x (preview of #N)`, in place of the plain page and pull lines. | |
| 10 | 10 | |
| 11 | 11 | - **Which doors say it.** The toolbar's tell form (`tellFromPage`, `src/web/studio/actions.ts`) |
| 12 | 12 | and the terminal's "Tell the crew from a page" (`src/tui/screens/tell.ts`), both of which ask for |
src/actions/tell_context.ts +7 −7
| @@ -147,17 +147,16 @@ export function parseContext(v: unknown): TellContext | undefined | null { | ||
| 147 | 147 | /** |
| 148 | 148 | * The block appended to a tell; empty when there is nothing to say. `preview` |
| 149 | 149 | * is said only by a door that asked for a preview's pull (the forge toolbar, |
| 150 | * the terminal's "from a page"); then one line, "from preview of #N, page | |
| 151 | * /x", takes the place of the page and pull lines. Any other door (MCP, API) | |
| 152 | * keeps the plain page and pull, so no door claims a preview it did not see. | |
| 150 | * the terminal's "from a page"); then one closing line, "From: <app> /x | |
| 151 | * (preview of #N)", takes the place of the page and pull lines. Any other | |
| 152 | * door (MCP, API) keeps the plain page and pull, so no door claims a | |
| 153 | * preview it did not see. | |
| 153 | 154 | */ |
| 154 | 155 | export function contextNote(c: TellContext | undefined, opts: { preview?: boolean; app?: string } = {}): string { |
| 155 | 156 | if (c === undefined) return ""; |
| 156 | 157 | const app = opts.app ?? c.app; |
| 157 | 158 | const preview = opts.preview === true ? previewLine(c.pull, c.page, app) : ""; |
| 158 | 159 | const lines = [ |
| 159 | preview !== "" ? `- ${preview}` : "", | |
| 160 | preview === "" ? fromLine(c.page, opts.app) : "", | |
| 161 | 160 | preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`, |
| 162 | 161 | preview !== "" || c.pull === undefined ? "" : `- pull: #${c.pull}`, |
| 163 | 162 | preview !== "" || app === undefined || !APP_SLUG.test(app) |
| @@ -168,12 +167,13 @@ export function contextNote(c: TellContext | undefined, opts: { preview?: boolea | ||
| 168 | 167 | c.said === undefined || c.said === "" |
| 169 | 168 | ? "" |
| 170 | 169 | : `- their words: ${c.said.replace(/\s*\n\s*/g, " ")}`, |
| 170 | preview === "" ? fromLine(c.page, opts.app) : preview, | |
| 171 | 171 | ].filter((l) => l !== ""); |
| 172 | 172 | return lines.length === 0 ? "" : `\n\n---\nWhere this was told from:\n${lines.join("\n")}`; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | * "- from <app> <path>": the app and the path of the page a tell was said on; empty unless both | |
| 176 | * "From: <app> <path>": the app and the path of the page a tell was said on; empty unless both | |
| 177 | 177 | * check. |
| 178 | 178 | */ |
| 179 | 179 | function fromLine(page: string | undefined, app: string | undefined): string { |
| @@ -184,5 +184,5 @@ function fromLine(page: string | undefined, app: string | undefined): string { | ||
| 184 | 184 | /[\\\s\x00-\x1f\x7f<>()\[\]`"'*_~|!#&]/g, |
| 185 | 185 | (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`, |
| 186 | 186 | ); |
| 187 | return parseFrom(path) === path ? `- from ${app} ${path}` : ""; | |
| 187 | return parseFrom(path) === path ? `From: ${app} ${path}` : ""; | |
| 188 | 188 | } |
src/actions/tell_from.ts +3 −3
| @@ -48,7 +48,7 @@ export const APP_SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/; | ||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * The plain line a tell from a preview's toolbar opens its issue with: |
| 51 | * "from preview of #N, page /x". The path is only the path of the page the | |
| 51 | * "From: <app> /x (preview of #N)". The path is only the path of the page the | |
| 52 | 52 | * person was on (never its host, query or fragment), with every character |
| 53 | 53 | * `parseFrom` refuses percent-encoded, so it cannot become markup. It is |
| 54 | 54 | * context for a reader, never authority: nothing is granted by it. |
| @@ -67,6 +67,6 @@ export function previewLine( | ||
| 67 | 67 | (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`, |
| 68 | 68 | ); |
| 69 | 69 | if (parseFrom(path) !== path) return ""; |
| 70 | const named = app !== undefined && APP_SLUG.test(app) ? `, app ${app}` : ""; | |
| 71 | return `from preview of #${pull}, page ${path}${named}`; | |
| 70 | const named = app !== undefined && APP_SLUG.test(app) ? `${app} ` : ""; | |
| 71 | return `From: ${named}${path} (preview of #${pull})`; | |
| 72 | 72 | } |
test/apps-toolbar-context.test.ts +28 −6
| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | import { describe, expect, test } from "bun:test"; |
| 2 | import { contextNote } from "../src/actions/tell_context.ts"; | |
| 2 | import { contextNote, parseContext } from "../src/actions/tell_context.ts"; | |
| 3 | 3 | import { previewLine } from "../src/actions/tell_from.ts"; |
| 4 | 4 | |
| 5 | 5 | describe("a tell's context line names the app", () => { |
| 6 | 6 | test("a preview line carries app, path and pull", () => { |
| 7 | 7 | expect(previewLine(3, "https://n.apps.test/b?q=1", "notes")).toBe( |
| 8 | "from preview of #3, page /b, app notes", | |
| 8 | "From: notes /b (preview of #3)", | |
| 9 | 9 | ); |
| 10 | 10 | }); |
| 11 | 11 | test("production keeps its page and names the app on its own line", () => { |
| @@ -20,15 +20,37 @@ describe("a tell's context line names the app", () => { | ||
| 20 | 20 | ); |
| 21 | 21 | expect(n).not.toContain("app a"); |
| 22 | 22 | expect(n).not.toContain("app:"); |
| 23 | expect(n.split("\n").find((l) => l.startsWith("- from"))!).not.toMatch(/[()\[\]*<>]/); | |
| 23 | expect(n.split("\n").find((l) => l.startsWith("From:"))!.replace(" (preview of #3)", "")).not.toMatch(/[()\[\]*<>]/); | |
| 24 | 24 | }); |
| 25 | 25 | test("production's page says 'from <app> <path>', without query or host", () => { |
| 26 | 26 | const n = contextNote({ page: "https://n.apps.test/a/b?x=1" }, { preview: true, app: "notes" }); |
| 27 | expect(n).toContain("- from notes /a/b\n"); | |
| 27 | expect(n).toContain("From: notes /a/b"); | |
| 28 | 28 | }); |
| 29 | 29 | test("a hostile path or app is encoded or dropped from the from line", () => { |
| 30 | 30 | const bad = contextNote({ page: "https://n.apps.test/x)[e](http://e.test)*<b>" }, { preview: true, app: "notes" }); |
| 31 | expect(bad.split("\n").find((l) => l.startsWith("- from "))!).not.toMatch(/[()\[\]*<>]/); | |
| 32 | expect(contextNote({ page: "https://n.apps.test/a" }, { preview: true, app: "a](x)" })).not.toContain("- from "); | |
| 31 | expect(bad.split("\n").find((l) => l.startsWith("From: "))!.replace(" (preview of #3)", "")).not.toMatch(/[()\[\]*<>]/); | |
| 32 | expect(contextNote({ page: "https://n.apps.test/a" }, { preview: true, app: "a](x)" })).not.toContain("From: "); | |
outdated
|
||
| 33 | }); | |
| 34 | test("a production tell with a hostile or off-origin page says no From line", () => { | |
| 35 | for (const page of ["javascript:alert(1)", "//evil.test/x", "/relative", "ftp://e.test/x"]) { | |
| 36 | expect(parseContext({ page })).toBeNull(); | |
| 37 | } | |
| 38 | const hostile = parseContext({ page: "https://n.apps.test/x\\y" }) ?? undefined; | |
| 39 | const n = contextNote(hostile, { preview: true, app: "notes" }); | |
| 40 | expect(n).not.toContain("From: notes /x\\"); | |
| 41 | expect(n).not.toMatch(/\\\\/); | |
| 42 | }); | |
| 43 | test("the From line is the last line when run, commit and their words exist", () => { | |
| 44 | const c = { page: "https://n.apps.test/a", pull: 3, run: "r1", commit: "abc1234", said: "make it bigger" }; | |
| 45 | for (const body of [ | |
| 46 | contextNote(c, { preview: true, app: "notes" }), | |
| 47 | contextNote({ page: c.page, run: c.run, commit: c.commit, said: c.said }, { preview: true, app: "notes" }), | |
| 48 | ]) { | |
| 49 | const lines = body.split("\n"); | |
| 50 | expect(lines.at(-1)!.startsWith("From: notes /a")).toBe(true); | |
| 51 | expect(body).toContain("- run: r1"); | |
| 52 | expect(body).toContain("- commit: abc1234"); | |
| 53 | expect(body).toContain("- their words: make it bigger"); | |
| 54 | } | |
| 33 | 55 | }); |
| 34 | 56 | }); |
test/apps-toolbar-tell.test.ts +5 −5
| @@ -170,7 +170,7 @@ describe("tell the crew from the pill", () => { | ||
| 170 | 170 | }); |
| 171 | 171 | expect(res.status).toBe(200); |
| 172 | 172 | const issue = listIssues(app.db, repoId, {}).find((i) => i.title === "Bigger button")!; |
| 173 | expect(issue.body).toContain("- from preview of #3, page /b, app notes"); | |
| 173 | expect(issue.body).toContain("From: notes /b (preview of #3)"); | |
| 174 | 174 | expect(issue.body).not.toContain("- page:"); |
| 175 | 175 | expect(issue.body).not.toContain("- pull:"); |
| 176 | 176 | }); |
| @@ -183,7 +183,7 @@ describe("tell the crew from the pill", () => { | ||
| 183 | 183 | }); |
| 184 | 184 | expect(res.status).toBe(200); |
| 185 | 185 | const issue = listIssues(app.db, repoId, {}).find((i) => i.title === "Hostile path")!; |
| 186 | const line = issue.body.split("\n").find((l) => l.startsWith("- from preview"))!; | |
| 186 | const line = issue.body.split("\n").find((l) => l.startsWith("From:"))!.replace(" (preview of #3)", ""); | |
| 187 | 187 | expect(line).not.toMatch(/[()\[\]*<>]/); |
| 188 | 188 | }); |
| 189 | 189 | |
| @@ -195,16 +195,16 @@ describe("tell the crew from the pill", () => { | ||
| 195 | 195 | expect(flash).toContain("It was sent without where it was told from."); |
| 196 | 196 | expect((await post({ text: "Dropped pull", page: "https://notes.apps.test/k", pull: "3; drop" })).status).toBe(200); |
| 197 | 197 | const b = listIssues(app.db, repoId, {}).find((i) => i.title === "Dropped pull")!; |
| 198 | expect(b.body).toContain("- from notes /k"); | |
| 198 | expect(b.body).toContain("From: notes /k"); | |
| 199 | 199 | expect(b.body).toBe( |
| 200 | "---\nWhere this was told from:\n- from notes /k\n- page: https://notes.apps.test/k\n- app: notes", | |
| 200 | "---\nWhere this was told from:\n- page: https://notes.apps.test/k\n- app: notes\nFrom: notes /k", | |
| 201 | 201 | ); |
| 202 | 202 | }); |
| 203 | 203 | |
| 204 | 204 | test("a tell from production stores 'from <app> <path>'", async () => { |
| 205 | 205 | await post({ text: "Carried", page: "https://notes.apps.test/deep/page?q=1" }); |
| 206 | 206 | const i = listIssues(app.db, repoId, {}).find((x) => x.title === "Carried")!; |
| 207 | expect(i.body).toContain("- from notes /deep/page\n"); | |
| 207 | expect(i.body).toContain("From: notes /deep/page"); | |
| 208 | 208 | }); |
| 209 | 209 | |
| 210 | 210 | test("a refused tell sends the person back with their words, the page and the pull kept", async () => { |
test/tell-context.test.ts +2 −2
| @@ -16,11 +16,11 @@ test("a page without a fragment is kept as it was", () => { | ||
| 16 | 16 | test("only a door that asked for a preview's pull says 'from preview'", () => { |
| 17 | 17 | const where = parseContext({ page: "https://n.apps.test/a?x=1", pull: 7 }) ?? undefined; |
| 18 | 18 | const plain = contextNote(where); |
| 19 | expect(plain).not.toContain("from preview"); | |
| 19 | expect(plain).not.toContain("(preview of"); | |
| 20 | 20 | expect(plain).toContain("- page: https://n.apps.test/a?x=1"); |
| 21 | 21 | expect(plain).toContain("- pull: #7"); |
| 22 | 22 | const said = contextNote(where, { preview: true }); |
| 23 | expect(said).toContain("- from preview of #7, page /a"); | |
| 23 | expect(said).toContain("From: /a (preview of #7)"); | |
| 24 | 24 | expect(said).not.toContain("- page:"); |
| 25 | 25 | expect(said).not.toContain("- pull:"); |
| 26 | 26 | // A preview with no pull is no preview. |
test/tell_from.test.ts +3 −3
| @@ -180,7 +180,7 @@ describe("tell from a page, through the box", () => { | ||
| 180 | 180 | |
| 181 | 181 | describe("previewLine", () => { |
| 182 | 182 | test("says the pull and the path, nothing else", () => { |
| 183 | expect(previewLine(7, "https://n-pull-7.apps.test/a/b?token=x#h")).toBe("from preview of #7, page /a/b"); | |
| 183 | expect(previewLine(7, "https://n-pull-7.apps.test/a/b?token=x#h")).toBe("From: /a/b (preview of #7)"); | |
| 184 | 184 | }); |
| 185 | 185 | test("no pull or no page is no line", () => { |
| 186 | 186 | expect(previewLine(undefined, "https://a.test/")).toBe(""); |
| @@ -189,8 +189,8 @@ describe("previewLine", () => { | ||
| 189 | 189 | }); |
| 190 | 190 | test("a hostile path cannot carry markup", () => { |
| 191 | 191 | const l = previewLine(3, "https://a.test/x)[y](http://e.test)*_`<i>"); |
| 192 | expect(l).not.toMatch(/[()\[\]*`<>]/); | |
| 193 | expect(l.startsWith("from preview of #3, page /x%29")).toBe(true); | |
| 192 | expect(l.replace(" (preview of #3)", "")).not.toMatch(/[()\[\]*`<>]/); | |
| 193 | expect(l.startsWith("From: /x%29")).toBe(true); | |
| 194 | 194 | }); |
| 195 | 195 | test("a hostile from value is refused", () => { |
| 196 | 196 | expect(parseFrom("//evil.test")).toBeUndefined(); |
test/toolbar-actions.test.ts +1 −1
| @@ -282,7 +282,7 @@ describe("toolbar actions", () => { | ||
| 282 | 282 | pull: String(pullNumber), |
| 283 | 283 | }); |
| 284 | 284 | const two = listIssues(app.db, repoId, {}).find((i) => i.title === "Page tell preview")!; |
| 285 | expect(two.body).toContain(`- from preview of #${pullNumber}, page /b`); | |
| 285 | expect(two.body).toContain(`From: notes /b (preview of #${pullNumber})`); | |
| 286 | 286 | expect(two.body).not.toContain("- pull:"); |
| 287 | 287 | }); |
| 288 | 288 |
test/tui-tell.test.ts +2 −2
| @@ -94,7 +94,7 @@ describe("tell the crew in the terminal", () => { | ||
| 94 | 94 | const text = await palette(alice, keys); |
| 95 | 95 | expect(text).toContain("Nobody is on the crew to take it yet"); |
| 96 | 96 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "move the button")!; |
| 97 | expect(issue.body).toContain("- from preview of #7, page /a"); | |
| 97 | expect(issue.body).toContain("From: lobby /a (preview of #7)"); | |
| 98 | 98 | expect(await palette(bob, [":", "from a page"])).not.toContain("Tell the crew from a page"); |
| 99 | 99 | }); |
| 100 | 100 | |
| @@ -123,7 +123,7 @@ describe("tell the crew in the terminal", () => { | ||
| 123 | 123 | expect(text).toContain("It was sent without"); |
| 124 | 124 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "bad pull tell")!; |
| 125 | 125 | expect(issue.body).toBe( |
| 126 | "---\nWhere this was told from:\n- from lobby /k\n- page: https://notes.apps.test/k\n- app: lobby", | |
| 126 | "---\nWhere this was told from:\n- page: https://notes.apps.test/k\n- app: lobby\nFrom: lobby /k", | |
| 127 | 127 | ); |
| 128 | 128 | }); |
| 129 | 129 |
new above
offline
This comment line runs past the wrap width; rewrap it with the gate.