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

Merged opened this

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

Merged

scout/forge:scout/13487-a-tell-sent-from-an-app-s-forge-toolbar → main 2 commits fork

  • Merged. scout/13487-a-tell-sent-from-an-app-s-forge-toolbar was merged into main as d336734.

Review

Sign in to review this change.
5 files changed +61 −12
src/actions/tell_context.ts +6 −3
@@ -6,7 +6,7 @@
66 * the tell as a plain block the issue shows and the agent reads.
77 */
88
9 import { previewLine } from "./tell_from.ts";
9 import { APP_SLUG, previewLine } from "./tell_from.ts";
1010
1111 export interface TellContext {
1212 readonly page?: string;
@@ -133,13 +133,16 @@ export function parseContext(v: unknown): TellContext | undefined | null {
133133 * /x", takes the place of the page and pull lines. Any other door (MCP, API)
134134 * keeps the plain page and pull, so no door claims a preview it did not see.
135135 */
136 export function contextNote(c: TellContext | undefined, opts: { preview?: boolean } = {}): string {
136 export function contextNote(c: TellContext | undefined, opts: { preview?: boolean; app?: string } = {}): string {
137137 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) : "";
139139 const lines = [
140140 preview !== "" ? `- ${preview}` : "",
141141 preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`,
142142 preview !== "" || c.pull === undefined ? "" : `- pull: #${c.pull}`,
143 preview !== "" || opts.app === undefined || !APP_SLUG.test(opts.app)
144 ? ""
145 : `- app: ${opts.app}`,
143146 c.run === undefined ? "" : `- run: ${c.run}`,
144147 c.commit === undefined ? "" : `- commit: ${c.commit}`,
145148 c.said === undefined || c.said === ""
src/actions/tell_from.ts +10 −2
@@ -30,6 +30,9 @@ export function parseFrom(raw: unknown): string | null | undefined {
3030 return `${raw.slice(0, q)}${scrubQuery(raw.slice(q, end))}${raw.slice(end)}`;
3131 }
3232
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
3336 /**
3437 * The plain line a tell from a preview's toolbar opens its issue with:
3538 * "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 {
3841 * context for a reader, never authority: nothing is granted by it.
3942 * Empty when there is no pull or no usable page.
4043 */
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 {
4249 if (pull === undefined || page === undefined) return "";
4350 const url = URL.parse(page);
4451 if (url === null) return "";
@@ -47,5 +54,6 @@ export function previewLine(pull: number | undefined, page: string | undefined):
4754 (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`,
4855 );
4956 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}`;
5159 }
src/web/studio/actions.ts +19 −6
@@ -119,7 +119,10 @@ function toldAnswer(
119119 return flashOrJson(ctx, back, { message: tellFlashWords(routed, from, subject) }, at);
120120 }
121121
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 */
123126 export function tellFlashWords(routed: Routed | undefined, from: string | null, subject: string): string {
124127 if (routed === undefined)
125128 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,
128131 return prefixed(`${routed.builder.user.username} is on it — ${routed.size} ${routed.kind}${decided}.${watch}`, subject);
129132 }
130133
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 */
132138 export function prefixed(message: string, subject: string): string {
133139 return subject === "" ? message : `${subject}: ${message}`;
134140 }
@@ -138,7 +144,10 @@ function withSubject<T extends { message: string }>(flash: T, subject: string):
138144 return { ...flash, message: prefixed(flash.message, subject) };
139145 }
140146
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 */
142151 function noCreditFlash(ctx: Ctx): { tone: "attn"; message: string; link: { href: string; label: string } } {
143152 return {
144153 tone: "attn",
@@ -179,7 +188,7 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response>
179188 return flashTo(ctx, back, { tone: "danger", message: NOT_TOLD_FROM_WORDS });
180189 const text = field(form, "text").trim();
181190 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 })}`);
183192 if (!told.ok)
184193 return flashTo(ctx, back, {
185194 tone: "danger",
@@ -239,7 +248,8 @@ export async function composerSubmit(ctx: Ctx): Promise<Response> {
239248
240249 async function composerTell(ctx: Ctx, form: Form, target: string, home: string, onTold: () => void): Promise<Response> {
241250 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).
243253 if (target === NEW_APP_TARGET) {
244254 const from = parseFrom(field(form, "from") || undefined) ?? null;
245255 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> {
321331 });
322332 }
323333
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 */
325338 export async function updateSubmit(ctx: Ctx): Promise<Response> {
326339 const repo = loadRepo(ctx);
327340 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", () => {
170170 });
171171 expect(res.status).toBe(200);
172172 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");
174174 expect(issue.body).not.toContain("- page:");
175175 expect(issue.body).not.toContain("- pull:");
176176 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs