Public: anyone can read this; the crew can change it.
A tell sent from an app's forge toolbar carries the app, the page it was sent from and the pull number when in a preview #13497
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13487-a-tell-sent-from-an-app-s-forge-toolbar → main 2 commits fork
5 files
changed +61
−12
src/actions/tell_context.ts +6 −3
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | * the tell as a plain block the issue shows and the agent reads. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { previewLine } from "./tell_from.ts"; | |
| 9 | import { APP_SLUG, previewLine } from "./tell_from.ts"; | |
| 10 | 10 | |
| 11 | 11 | export interface TellContext { |
| 12 | 12 | readonly page?: string; |
| @@ -133,13 +133,16 @@ export function parseContext(v: unknown): TellContext | undefined | null { | ||
| 133 | 133 | * /x", takes the place of the page and pull lines. Any other door (MCP, API) |
| 134 | 134 | * keeps the plain page and pull, so no door claims a preview it did not see. |
| 135 | 135 | */ |
| 136 | export function contextNote(c: TellContext | undefined, opts: { preview?: boolean } = {}): string { | |
| 136 | export function contextNote(c: TellContext | undefined, opts: { preview?: boolean; app?: string } = {}): string { | |
| 137 | 137 | if (c === undefined) return ""; |
| 138 | const preview = opts.preview === true ? previewLine(c.pull, c.page) : ""; | |
| 138 | const preview = opts.preview === true ? previewLine(c.pull, c.page, opts.app) : ""; | |
| 139 | 139 | const lines = [ |
| 140 | 140 | preview !== "" ? `- ${preview}` : "", |
| 141 | 141 | preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`, |
| 142 | 142 | preview !== "" || c.pull === undefined ? "" : `- pull: #${c.pull}`, |
| 143 | preview !== "" || opts.app === undefined || !APP_SLUG.test(opts.app) | |
| 144 | ? "" | |
| 145 | : `- app: ${opts.app}`, | |
| 143 | 146 | c.run === undefined ? "" : `- run: ${c.run}`, |
| 144 | 147 | c.commit === undefined ? "" : `- commit: ${c.commit}`, |
| 145 | 148 | c.said === undefined || c.said === "" |
src/actions/tell_from.ts +10 −2
| @@ -30,6 +30,9 @@ export function parseFrom(raw: unknown): string | null | undefined { | ||
| 30 | 30 | return `${raw.slice(0, q)}${scrubQuery(raw.slice(q, end))}${raw.slice(end)}`; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | /** An app's slug as the forge names it; anything else is not said. */ | |
| 34 | export const APP_SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/; | |
| 35 | ||
| 33 | 36 | /** |
| 34 | 37 | * The plain line a tell from a preview's toolbar opens its issue with: |
| 35 | 38 | * "from preview of #N, page /x". The path is only the path of the page the |
| @@ -38,7 +41,11 @@ export function parseFrom(raw: unknown): string | null | undefined { | ||
| 38 | 41 | * context for a reader, never authority: nothing is granted by it. |
| 39 | 42 | * Empty when there is no pull or no usable page. |
| 40 | 43 | */ |
| 41 | export function previewLine(pull: number | undefined, page: string | undefined): string { | |
| 44 | export function previewLine( | |
| 45 | pull: number | undefined, | |
| 46 | page: string | undefined, | |
| 47 | app?: string, | |
| 48 | ): string { | |
| 42 | 49 | if (pull === undefined || page === undefined) return ""; |
| 43 | 50 | const url = URL.parse(page); |
| 44 | 51 | if (url === null) return ""; |
| @@ -47,5 +54,6 @@ export function previewLine(pull: number | undefined, page: string | undefined): | ||
| 47 | 54 | (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`, |
| 48 | 55 | ); |
| 49 | 56 | if (parseFrom(path) !== path) return ""; |
| 50 | return `from preview of #${pull}, page ${path}`; | |
| 57 | const named = app !== undefined && APP_SLUG.test(app) ? `, app ${app}` : ""; | |
| 58 | return `from preview of #${pull}, page ${path}${named}`; | |
| 51 | 59 | } |
src/web/studio/actions.ts +19 −6
| @@ -119,7 +119,10 @@ function toldAnswer( | ||
| 119 | 119 | return flashOrJson(ctx, back, { message: tellFlashWords(routed, from, subject) }, at); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | /** The words for a tell that went: who is on it, or that nobody is on the crew yet; named by the subject. */ | |
| 122 | /** | |
| 123 | * The words for a tell that went: who is on it, or that nobody is on the crew yet; named by the | |
| 124 | * subject. | |
| 125 | */ | |
| 123 | 126 | export function tellFlashWords(routed: Routed | undefined, from: string | null, subject: string): string { |
| 124 | 127 | if (routed === undefined) |
| 125 | 128 | return prefixed("Opened as an issue. Nobody is on the crew to take it yet — add someone under Settings → Crew.", subject); |
| @@ -128,7 +131,10 @@ export function tellFlashWords(routed: Routed | undefined, from: string | null, | ||
| 128 | 131 | return prefixed(`${routed.builder.user.username} is on it — ${routed.size} ${routed.kind}${decided}.${watch}`, subject); |
| 129 | 132 | } |
| 130 | 133 | |
| 131 | /** The first ask's flash names the app and the issue it made: "<subject>: <message>"; no subject, the message as is. */ | |
| 134 | /** | |
| 135 | * The first ask's flash names the app and the issue it made: "<subject>: <message>"; no subject, | |
| 136 | * the message as is. | |
| 137 | */ | |
| 132 | 138 | export function prefixed(message: string, subject: string): string { |
| 133 | 139 | return subject === "" ? message : `${subject}: ${message}`; |
| 134 | 140 | } |
| @@ -138,7 +144,10 @@ function withSubject<T extends { message: string }>(flash: T, subject: string): | ||
| 138 | 144 | return { ...flash, message: prefixed(flash.message, subject) }; |
| 139 | 145 | } |
| 140 | 146 | |
| 141 | /** The flash for words kept while the crew has no credit: saved, the crew cannot build yet, and the way forward. */ | |
| 147 | /** | |
| 148 | * The flash for words kept while the crew has no credit: saved, the crew cannot build yet, and the | |
| 149 | * way forward. | |
| 150 | */ | |
| 142 | 151 | function noCreditFlash(ctx: Ctx): { tone: "attn"; message: string; link: { href: string; label: string } } { |
| 143 | 152 | return { |
| 144 | 153 | tone: "attn", |
| @@ -179,7 +188,7 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response> | ||
| 179 | 188 | return flashTo(ctx, back, { tone: "danger", message: NOT_TOLD_FROM_WORDS }); |
| 180 | 189 | const text = field(form, "text").trim(); |
| 181 | 190 | if (text === "") return flashTo(ctx, back, { tone: "danger", message: SAY_SOMETHING_WORDS }); |
| 182 | const told = await tell(ctx.app, ctx.auth.user, repo, `${text}${contextNote(where, { preview: true })}`); | |
| 191 | const told = await tell(ctx.app, ctx.auth.user, repo, `${text}${contextNote(where, { preview: true, app: repo.name })}`); | |
| 183 | 192 | if (!told.ok) |
| 184 | 193 | return flashTo(ctx, back, { |
| 185 | 194 | tone: "danger", |
| @@ -239,7 +248,8 @@ export async function composerSubmit(ctx: Ctx): Promise<Response> { | ||
| 239 | 248 | |
| 240 | 249 | async function composerTell(ctx: Ctx, form: Form, target: string, home: string, onTold: () => void): Promise<Response> { |
| 241 | 250 | if (!ctx.auth.user) return signInFirst(ctx); |
| 242 | // The first ask of a new forge: one app made from the ask, the ask filed there (the terminal's first ask still keeps a thought). | |
| 251 | // The first ask of a new forge: one app made from the ask, the ask filed there (the terminal's | |
| 252 | // first ask still keeps a thought). | |
| 243 | 253 | if (target === NEW_APP_TARGET) { |
| 244 | 254 | const from = parseFrom(field(form, "from") || undefined) ?? null; |
| 245 | 255 | const first = await firstAsk(ctx.app, ctx.auth.user, field(form, COMPOSER_FIELDS.text), crewCanRun(ctx.app), from); |
| @@ -321,7 +331,10 @@ export async function shipSubmit(ctx: Ctx): Promise<Response> { | ||
| 321 | 331 | }); |
| 322 | 332 | } |
| 323 | 333 | |
| 324 | /** POST /:owner/:name/pulls/:number/update — ask the pull's agent to bring its branch up to date with main; nothing lands. A writer's. */ | |
| 334 | /** | |
| 335 | * POST /:owner/:name/pulls/:number/update — ask the pull's agent to bring its branch up to date | |
| 336 | * with main; nothing lands. A writer's. | |
| 337 | */ | |
| 325 | 338 | export async function updateSubmit(ctx: Ctx): Promise<Response> { |
| 326 | 339 | const repo = loadRepo(ctx); |
| 327 | 340 | if (!repo) return notFoundPage(ctx); |
test/apps-toolbar-context.test.ts added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { contextNote } from "../src/actions/tell_context.ts"; | |
| 3 | import { previewLine } from "../src/actions/tell_from.ts"; | |
| 4 | ||
| 5 | describe("a tell's context line names the app", () => { | |
| 6 | test("a preview line carries app, path and pull", () => { | |
| 7 | expect(previewLine(3, "https://n.apps.test/b?q=1", "notes")).toBe( | |
| 8 | "from preview of #3, page /b, app notes", | |
| 9 | ); | |
| 10 | }); | |
| 11 | test("production keeps its page and names the app on its own line", () => { | |
| 12 | const n = contextNote({ page: "https://n.apps.test/a" }, { preview: true, app: "notes" }); | |
| 13 | expect(n).toContain("- page: https://n.apps.test/a"); | |
| 14 | expect(n).toContain("- app: notes"); | |
| 15 | }); | |
| 16 | test("a hostile app or path is never said raw", () => { | |
| 17 | const n = contextNote( | |
| 18 | { page: "https://n.apps.test/x)[e](http://e.test)*<b>", pull: 3 }, | |
| 19 | { preview: true, app: "a](http://e.test)" }, | |
| 20 | ); | |
| 21 | expect(n).not.toContain("app a"); | |
| 22 | expect(n).not.toContain("app:"); | |
| 23 | expect(n.split("\n").find((l) => l.startsWith("- from"))!).not.toMatch(/[()\[\]*<>]/); | |
| 24 | }); | |
| 25 | }); |
test/apps-toolbar-tell.test.ts +1 −1
| @@ -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"); | |
| 173 | expect(issue.body).toContain("- from preview of #3, page /b, app notes"); | |
| 174 | 174 | expect(issue.body).not.toContain("- page:"); |
| 175 | 175 | expect(issue.body).not.toContain("- pull:"); |
| 176 | 176 | }); |
new above
offline