Public: anyone can read this; the crew can change it.
A tell from an app's page carries the app and the page it was sent from #15124
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15092-a-tell-from-an-app-s-page-carries-the-ap → main 5 commits fork 1 thread · 1 unresolved
8 files
changed +107
−51
src/actions/tell_context.ts +30 −1
| @@ -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 { APP_SLUG, previewLine } from "./tell_from.ts"; | |
| 9 | import { APP_SLUG, parseFrom, previewLine } from "./tell_from.ts"; | |
| 10 | 10 | |
| 11 | 11 | export interface TellContext { |
| 12 | 12 | readonly page?: string; |
| @@ -85,6 +85,19 @@ export function scrubQuery(query: string): string { | ||
| 85 | 85 | return kept.length === 0 ? "" : `${lead}${kept.join("&")}`; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | /** | |
| 89 | * The context of a tell said on a page, from the raw page and pull a door was given. What does not | |
| 90 | * check is dropped, never refused: the tell still goes, and `dropped` says something was left off | |
| 91 | * so the door can say so once. The web and the terminal both call this. | |
| 92 | */ | |
| 93 | export function whereTold(page: string, pull: string): { where: TellContext | undefined; dropped: boolean } { | |
| 94 | const n = pull === "" ? undefined : /^\d{1,9}$/.test(pull) ? Number(pull) : -1; | |
| 95 | const where = | |
| 96 | parseContext({ page, ...(n === undefined ? {} : { pull: n }) }) ?? parseContext({ page }) ?? undefined; | |
| 97 | const dropped = (page !== "" && where?.page === undefined) || (pull !== "" && where?.pull === undefined); | |
| 98 | return { where, dropped }; | |
| 99 | } | |
| 100 | ||
| 88 | 101 | /** The checked context, nothing for none, or null when a field is malformed. */ |
| 89 | 102 | export function parseContext(v: unknown): TellContext | undefined | null { |
| 90 | 103 | if (v === undefined) return undefined; |
| @@ -144,6 +157,7 @@ export function contextNote(c: TellContext | undefined, opts: { preview?: boolea | ||
| 144 | 157 | const preview = opts.preview === true ? previewLine(c.pull, c.page, app) : ""; |
| 145 | 158 | const lines = [ |
| 146 | 159 | preview !== "" ? `- ${preview}` : "", |
| 160 | preview === "" ? fromLine(c.page, opts.app) : "", | |
| 147 | 161 | preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`, |
| 148 | 162 | preview !== "" || c.pull === undefined ? "" : `- pull: #${c.pull}`, |
| 149 | 163 | preview !== "" || app === undefined || !APP_SLUG.test(app) |
| @@ -157,3 +171,18 @@ export function contextNote(c: TellContext | undefined, opts: { preview?: boolea | ||
| 157 | 171 | ].filter((l) => l !== ""); |
| 158 | 172 | return lines.length === 0 ? "" : `\n\n---\nWhere this was told from:\n${lines.join("\n")}`; |
| 159 | 173 | } |
| 174 | ||
| 175 | /** | |
| 176 | * "- from <app> <path>": the app and the path of the page a tell was said on; empty unless both | |
| 177 | * check. | |
| 178 | */ | |
| 179 | function fromLine(page: string | undefined, app: string | undefined): string { | |
| 180 | if (page === undefined || app === undefined || !APP_SLUG.test(app)) return ""; | |
| 181 | const url = URL.parse(page); | |
| 182 | if (url === null) return ""; | |
| 183 | const path = url.pathname.replace( | |
| 184 | /[\\\s\x00-\x1f\x7f<>()\[\]`"'*_~|!#&]/g, | |
| 185 | (ch) => `%${ch.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`, | |
| 186 | ); | |
| 187 | return parseFrom(path) === path ? `- from ${app} ${path}` : ""; | |
| 188 | } |
src/actions/tell_words.ts +2 −2
| @@ -7,8 +7,8 @@ | ||
| 7 | 7 | /** A tell that failed for a reason nobody can be told about. */ |
| 8 | 8 | export const NOT_TOLD_WORDS = "That could not be told."; |
| 9 | 9 | |
| 10 | /** A tell from a page whose context could not be read. */ | |
| 11 | export const NOT_TOLD_FROM_WORDS = "That page could not be told from."; | |
| 10 | /** Said after a sent tell whose page or pull did not check, and so was left off. */ | |
| 11 | export const WITHOUT_WHERE_WORDS = "It was sent without where it was told from."; | |
| 12 | 12 | |
| 13 | 13 | /** A tell, reply or report sent with nothing in it. */ |
| 14 | 14 | export const SAY_SOMETHING_WORDS = "Say something first."; |
src/tui/screens/tell.ts +18 −19
| @@ -4,14 +4,15 @@ | ||
| 4 | 4 | * The row is the screen's own and only for who `mayDirectCrew` there — the |
| 5 | 5 | * gate `tellRow` in `src/web/scope.ts` asks. `from` is null: a terminal |
| 6 | 6 | * screen has no page path of its own. A second row tells from a page: it asks |
| 7 | * for the page's address and the pull, checked and written into the tell by | |
| 8 | * the same `parseContext` and `contextNote` the pill's tell and the MCP use. | |
| 7 | * for the page's address and the pull, checked by `whereTold` (what does not | |
| 8 | * check is dropped, as on the page) and written into the tell by `contextNote` the pill's tell and | |
| 9 | * the MCP use. | |
| 9 | 10 | */ |
| 10 | 11 | |
| 11 | 12 | import { SENT_WORDS, tell } from "../../actions/tell.ts"; |
| 12 | 13 | import { tellAnswer } from "../../actions/tell_answer.ts"; |
| 13 | import { contextNote, parseContext } from "../../actions/tell_context.ts"; | |
| 14 | import { NOT_TOLD_FROM_WORDS, SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts"; | |
| 14 | import { contextNote, parseContext, whereTold } from "../../actions/tell_context.ts"; | |
| 15 | import { SAY_SOMETHING_WORDS, WITHOUT_WHERE_WORDS } from "../../actions/tell_words.ts"; | |
| 15 | 16 | import type { Repo } from "../../core/repos.ts"; |
| 16 | 17 | import { mayDirectCrew } from "../../crew/direct.ts"; |
| 17 | 18 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -55,7 +56,6 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 55 | 56 | label: name, |
| 56 | 57 | hint: "http(s) address of the page; enter continues", |
| 57 | 58 | onSubmit: (page) => { |
| 58 | if (parseContext({ page }) === null) return "That is not an http(s) address."; | |
| 59 | 59 | return later(ctx, () => |
| 60 | 60 | promptScreen(ctx, parent(), { |
| 61 | 61 | title: "Pull", |
| @@ -63,8 +63,6 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 63 | 63 | hint: "the pull number on a preview, or leave empty", |
| 64 | 64 | onSubmit: (pull) => { |
| 65 | 65 | const number = pull === "" ? undefined : /^\d{1,9}$/.test(pull) ? Number(pull) : -1; |
| 66 | if (parseContext({ page, ...(number === undefined ? {} : { pull: number }) }) === null) | |
| 67 | return "A pull is a number, like 7."; | |
| 68 | 66 | return later(ctx, () => |
| 69 | 67 | promptScreen(ctx, parent(), { |
| 70 | 68 | title: "App", |
| @@ -72,7 +70,6 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 72 | 70 | hint: "the app's name, or leave empty; enter continues", |
| 73 | 71 | onSubmit: (appName) => { |
| 74 | 72 | const app = appName === "" ? undefined : appName; |
| 75 | if (parseContext({ page, app }) === null) return "An app is a name like notes."; | |
| 76 | 73 | return later(ctx, () => |
| 77 | 74 | promptScreen(ctx, parent(), { |
| 78 | 75 | title: "Tell the crew", |
| @@ -107,17 +104,19 @@ export async function tellFromPage( | ||
| 107 | 104 | pull: number | undefined, |
| 108 | 105 | app?: string, |
| 109 | 106 | ): Promise<void> { |
| 110 | const where = parseContext({ | |
| 111 | page, | |
| 112 | ...(pull === undefined ? {} : { pull }), | |
| 113 | ...(app === undefined ? {} : { app }), | |
| 114 | }); | |
| 115 | if (where === null || where === undefined) { | |
| 116 | ctx.toast(NOT_TOLD_FROM_WORDS, "danger"); | |
| 117 | return; | |
| 118 | } | |
| 119 | const answer = tellAnswer(await tell(f.app, f.user, repo, `${said}${contextNote(where, { preview: true })}`)); | |
| 120 | ctx.toast(answer.text, answer.tone); | |
| 107 | // A name that does not check is dropped like a bad page: the tell goes under the repository's | |
| 108 | // name. | |
| 109 | const named = app !== undefined && parseContext({ app }) !== null; | |
| 110 | const { where, dropped } = whereTold(page, pull === undefined ? "" : String(pull)); | |
| 111 | const told = await tell( | |
| 112 | f.app, | |
| 113 | f.user, | |
| 114 | repo, | |
| 115 | `${said}${contextNote(where, { preview: true, app: named ? app : repo.name })}`, | |
| 116 | ); | |
| 117 | const answer = tellAnswer(told); | |
| 118 | const left = dropped || (app !== undefined && !named); | |
| 119 | ctx.toast(left && told.ok ? `${answer.text} ${WITHOUT_WHERE_WORDS}` : answer.text, answer.tone); | |
| 121 | 120 | } |
| 122 | 121 | |
| 123 | 122 | /** A client's "Ask for something" on the first screen: one line to the app's crew, answered in the web's words. */ |
src/web/studio/actions.ts +6 −10
| @@ -17,9 +17,9 @@ import { addComment } from "../../actions/issues.ts"; | ||
| 17 | 17 | import { overTellLimit, parseFrom } from "../../actions/tell_from.ts"; |
| 18 | 18 | import { SENT_WORDS, tell, toldWords, TOO_LONG_WORDS } from "../../actions/tell.ts"; |
| 19 | 19 | import { TAKEN_BACK_WORDS, TOO_LATE_WORDS, tellUndoable, undoTell } from "../../actions/tell_undo.ts"; |
| 20 | import { contextNote, parseContext } from "../../actions/tell_context.ts"; | |
| 20 | import { contextNote, whereTold } from "../../actions/tell_context.ts"; | |
| 21 | 21 | import { refusalWords } from "../../actions/tell_answer.ts"; |
| 22 | import { NOT_TOLD_FROM_WORDS, SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts"; | |
| 22 | import { SAY_SOMETHING_WORDS, WITHOUT_WHERE_WORDS } from "../../actions/tell_words.ts"; | |
| 23 | 23 | import { keepThought } from "../../actions/thought.ts"; |
| 24 | 24 | import { mergePull } from "../../actions/pulls.ts"; |
| 25 | 25 | import { revertPull } from "../../actions/revert.ts"; |
| @@ -172,19 +172,15 @@ export async function tellSubmit(ctx: Ctx): Promise<Response> { | ||
| 172 | 172 | * tell, answered with a receipt that links to the issue it opened. |
| 173 | 173 | */ |
| 174 | 174 | async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response> { |
| 175 | const pull = field(form, "pull"); | |
| 176 | const where = parseContext({ | |
| 177 | page: field(form, "page"), | |
| 178 | ...(pull === "" ? {} : { pull: /^\d{1,9}$/.test(pull) ? Number(pull) : -1 }), | |
| 179 | }); | |
| 175 | // A page that does not check, or a pull that does not, is dropped: the | |
| 176 | // tell is still sent, only without where it was said. | |
| 177 | const { where, dropped } = whereTold(field(form, "page"), field(form, "pull")); | |
| 180 | 178 | // A refusal sends the person back to the box with their words, the page |
| 181 | 179 | // and the pull kept, so they can retry. |
| 182 | 180 | const keep = new URLSearchParams({ text: field(form, "text").slice(0, 1000) }); |
| 183 | 181 | if (where?.page !== undefined) keep.set("page", where.page); |
| 184 | 182 | if (where?.pull !== undefined) keep.set("pull", String(where.pull)); |
| 185 | 183 | const back = `${repoBase(repo)}/tell?${keep}`; |
| 186 | if (where === null || where === undefined) | |
| 187 | return flashTo(ctx, back, { tone: "danger", message: NOT_TOLD_FROM_WORDS }); | |
| 188 | 184 | const text = field(form, "text").trim(); |
| 189 | 185 | if (text === "") return flashTo(ctx, back, { tone: "danger", message: SAY_SOMETHING_WORDS }); |
| 190 | 186 | if (overTellLimit(text)) return flashTo(ctx, back, { tone: "danger", message: TOO_LONG_WORDS }); |
| @@ -200,7 +196,7 @@ async function tellFromPage(ctx: Ctx, repo: Repo, form: Form): Promise<Response> | ||
| 200 | 196 | title: `Issue opened · ${repo.name}`, |
| 201 | 197 | crumbs: crumbsFor(repo), |
| 202 | 198 | body: html`${pageHead("Issue opened")} |
| 203 | <p>${toldWords(told.value)}</p> | |
| 199 | <p>${toldWords(told.value)}${dropped ? ` ${WITHOUT_WHERE_WORDS}` : ""}</p> | |
| 204 | 200 | <p><a href="${issue}" data-receipt>See issue #${String(told.value.issue.number)}</a></p> |
| 205 | 201 | ${ |
| 206 | 202 | tellUndoable(ctx.app, repo, told.value.issue) |
test/apps-toolbar-context.test.ts +9
| @@ -22,4 +22,13 @@ describe("a tell's context line names the app", () => { | ||
| 22 | 22 | expect(n).not.toContain("app:"); |
| 23 | 23 | expect(n.split("\n").find((l) => l.startsWith("- from"))!).not.toMatch(/[()\[\]*<>]/); |
| 24 | 24 | }); |
| 25 | test("production's page says 'from <app> <path>', without query or host", () => { | |
| 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"); | |
| 28 | }); | |
| 29 | test("a hostile path or app is encoded or dropped from the from line", () => { | |
| 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 "); | |
| 33 | }); | |
| 25 | 34 | }); |
test/apps-toolbar-tell.test.ts +18 −8
| @@ -185,16 +185,26 @@ describe("tell the crew from the pill", () => { | ||
| 185 | 185 | const issue = listIssues(app.db, repoId, {}).find((i) => i.title === "Hostile path")!; |
| 186 | 186 | const line = issue.body.split("\n").find((l) => l.startsWith("- from preview"))!; |
| 187 | 187 | expect(line).not.toMatch(/[()\[\]*<>]/); |
| 188 | const before = told().length; | |
| 189 | expect((await post({ text: "x", page: "https://a.test/", pull: "3; drop" })).status).toBe(303); | |
| 190 | expect(told().length).toBe(before); | |
| 191 | 188 | }); |
| 192 | 189 | |
| 193 | test("a bad page or pull opens nothing", async () => { | |
| 194 | const before = told().length; | |
| 195 | expect((await post({ text: "x", page: "javascript:alert(1)" })).status).toBe(303); | |
| 196 | expect((await post({ text: "x", page: "https://a.test/", pull: "-1" })).status).toBe(303); | |
| 197 | expect(told().length).toBe(before); | |
| 190 | test("a bad page or pull is dropped, not an error: the tell is sent without it", async () => { | |
| 191 | expect((await post({ text: "Dropped page", page: "javascript:alert(1)" })).status).toBe(200); | |
| 192 | const a = listIssues(app.db, repoId, {}).find((i) => i.title === "Dropped page")!; | |
| 193 | expect(a.body).not.toContain("Where this was told from"); | |
| 194 | const flash = await (await post({ text: "Dropped again", page: "javascript:alert(1)" })).text(); | |
| 195 | expect(flash).toContain("It was sent without where it was told from."); | |
| 196 | expect((await post({ text: "Dropped pull", page: "https://notes.apps.test/k", pull: "3; drop" })).status).toBe(200); | |
| 197 | const b = listIssues(app.db, repoId, {}).find((i) => i.title === "Dropped pull")!; | |
| 198 | expect(b.body).toContain("- from notes /k"); | |
| 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", | |
| 201 | ); | |
| 202 | }); | |
| 203 | ||
| 204 | test("a tell from production stores 'from <app> <path>'", async () => { | |
| 205 | await post({ text: "Carried", page: "https://notes.apps.test/deep/page?q=1" }); | |
| 206 | const i = listIssues(app.db, repoId, {}).find((x) => x.title === "Carried")!; | |
| 207 | expect(i.body).toContain("- from notes /deep/page\n"); | |
| 198 | 208 | }); |
| 199 | 209 | |
| 200 | 210 | test("a refused tell sends the person back with their words, the page and the pull kept", async () => { |
test/tell-words.test.ts +3 −3
| @@ -8,14 +8,14 @@ import { readFileSync } from "node:fs"; | ||
| 8 | 8 | import { join } from "node:path"; |
| 9 | 9 | import { |
| 10 | 10 | NOT_SENT_WORDS, |
| 11 | NOT_TOLD_FROM_WORDS, | |
| 12 | 11 | NOT_TOLD_WORDS, |
| 13 | 12 | SAY_SOMETHING_WORDS, |
| 13 | WITHOUT_WHERE_WORDS, | |
| 14 | 14 | } from "../src/actions/tell_words.ts"; |
| 15 | 15 | |
| 16 | 16 | const SENTENCES = { |
| 17 | 17 | NOT_TOLD_WORDS: "That could not be told.", |
| 18 | NOT_TOLD_FROM_WORDS: "That page could not be told from.", | |
| 18 | WITHOUT_WHERE_WORDS: "It was sent without where it was told from.", | |
| 19 | 19 | SAY_SOMETHING_WORDS: "Say something first.", |
| 20 | 20 | NOT_SENT_WORDS: "That could not be sent.", |
| 21 | 21 | }; |
| @@ -33,7 +33,7 @@ const read = (path: string): string => readFileSync(join(import.meta.dir, "..", | ||
| 33 | 33 | |
| 34 | 34 | describe("tell words", () => { |
| 35 | 35 | test("the module says each sentence word for word", () => { |
| 36 | expect({ NOT_TOLD_WORDS, NOT_TOLD_FROM_WORDS, SAY_SOMETHING_WORDS, NOT_SENT_WORDS }).toEqual(SENTENCES); | |
| 36 | expect({ NOT_TOLD_WORDS, WITHOUT_WHERE_WORDS, SAY_SOMETHING_WORDS, NOT_SENT_WORDS }).toEqual(SENTENCES); | |
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | 39 | for (const door of DOORS) { |
test/tui-tell.test.ts +21 −8
| @@ -97,20 +97,33 @@ describe("tell the crew in the terminal", () => { | ||
| 97 | 97 | expect(await palette(bob, [":", "from a page"])).not.toContain("Tell the crew from a page"); |
| 98 | 98 | }); |
| 99 | 99 | |
| 100 | test("a tell from a page can name the app, and a bad name is refused", async () => { | |
| 100 | test("a tell from a page can name the app, and a bad name is dropped", async () => { | |
| 101 | 101 | const page = [":", "from a page", "\r", ..."https://notes.apps.test/a".split(""), "\r", "\r"]; |
| 102 | 102 | await palette(alice, [...page, ..."notes".split(""), "\r", ..."name the app".split(""), "\r"]); |
| 103 | 103 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "name the app")!; |
| 104 | 104 | expect(issue.body).toContain("- app: notes"); |
| 105 | const text = await palette(alice, [...page, ..."<b>".split(""), "\r"]); | |
| 106 | expect(text).toContain("An app is a name like notes."); | |
| 105 | const text = await palette(alice, [...page, ..."<b>".split(""), "\r", ..."bad app name".split(""), "\r"]); | |
| 106 | expect(text).toContain("It was sent without"); | |
| 107 | const bad = listIssues(app.db, repo.id, {}).find((i) => i.title === "bad app name")!; | |
| 108 | expect(bad.body).not.toContain("<b>"); | |
| 107 | 109 | }); |
| 108 | 110 | |
| 109 | test("a page that is not http(s) keeps the prompt open and tells nothing", async () => { | |
| 110 | const before = listIssues(app.db, repo.id, {}).length; | |
| 111 | const text = await palette(alice, [":", "from a page", "\r", ..."javascript:alert(1)".split(""), "\r"]); | |
| 112 | expect(text).toContain("That is not an http(s) address."); | |
| 113 | expect(listIssues(app.db, repo.id, {}).length).toBe(before); | |
| 111 | test("a page that is not http(s) is dropped: the tell is sent, and says it went without it", async () => { | |
| 112 | const text = await palette(alice, [":", "from a page", "\r", ..."javascript:alert(1)".split(""), "\r", "\r", "\r", ..."bad page tell".split(""), "\r"]); | |
| 113 | // the toast is cut at the screen's width, so the start of the sentence is what shows | |
| 114 | expect(text).toContain("It was sent without"); | |
| 115 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "bad page tell")!; | |
| 116 | expect(issue.body).not.toContain("Where this was told from"); | |
| 117 | }); | |
| 118 | ||
| 119 | test("a bad pull is dropped, the good page kept", async () => { | |
| 120 | const text = await palette(alice, [":", "from a page", "\r", ..."https://notes.apps.test/k".split(""), "\r", ..."x7".split(""), "\r", "\r", ..."bad pull tell".split(""), "\r"]); | |
| 121 | // the toast is cut at the screen's width, so the start of the sentence is what shows | |
| 122 | expect(text).toContain("It was sent without"); | |
| 123 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "bad pull tell")!; | |
| 124 | expect(issue.body).toBe( | |
| 125 | "---\nWhere this was told from:\n- from lobby /k\n- page: https://notes.apps.test/k\n- app: lobby", | |
| 126 | ); | |
| 114 | 127 | }); |
| 115 | 128 | |
| 116 | 129 | test("an empty line says so and tells nothing", async () => { |
new above
offline
The web door now drops a bad page.
src/tui/screens/tell.tsstill refuses with NOT_TOLD_FROM_WORDS, so the two doors disagree. Share this fallback (for example in tell_context.ts) and use it in both.