Public: anyone can read this; the crew can change it.
A tell sent through the MCP carries the page it came from #14879
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14859-a-tell-sent-through-the-mcp-carries-the → main 5 commits fork 2 threads · 2 unresolved
8 files
changed +92
−16
docs/MCP.md +1 −1
| @@ -485,7 +485,7 @@ answers | ||
| 485 | 485 | `POST …/issues/{number}/dependencies` and |
| 486 | 486 | `DELETE …/issues/{number}/dependencies/{blocker}`. `test/openapi.test.ts` fails |
| 487 | 487 | when the manifest names a route it lacks. |
| 488 | - **Where a tell came from.** `tell` takes `context`: `page` (http/https), | |
| 488 | - **Where a tell came from.** `tell` takes `context`: `page` (http/https), `app` (a slug, shown as an `app:` line), | |
| 489 | 489 | `run`, `commit` (hex) and `said` (the person's words). Malformed context is |
| 490 | 490 | refused; the rest is appended to the issue body. `tell` also takes `from`: a |
| 491 | 491 | same-forge path (at most 512 characters, like `/alice/notes/pulls/3`) that |
docs/features/tell-context-app.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: A tell says the page and the app it was told from, at the MCP and in the terminal | |
| 4 | --- | |
| 5 | # A tell names its page and app (#14859) | |
| 6 | ||
| 7 | A tell can say where it was told from. `context.page` is the address (the url) and `context.app` is the app's slug; both land in the issue body under `Where this was told from:` as `- page:` and `- app:`. | |
| 8 | ||
| 9 | - MCP: `tell` takes `context: { page?, app?, pull?, run?, commit?, said? }`. A malformed `app` (not a slug) refuses the whole call. | |
| 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 | - 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. | |
| 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`. |
src/actions/tell_context.ts +10 −4
| @@ -11,6 +11,7 @@ import { APP_SLUG, previewLine } from "./tell_from.ts"; | ||
| 11 | 11 | export interface TellContext { |
| 12 | 12 | readonly page?: string; |
| 13 | 13 | readonly pull?: number; |
| 14 | readonly app?: string; | |
| 14 | 15 | readonly run?: string; |
| 15 | 16 | readonly commit?: string; |
| 16 | 17 | readonly said?: string; |
| @@ -89,7 +90,7 @@ export function parseContext(v: unknown): TellContext | undefined | null { | ||
| 89 | 90 | if (v === undefined) return undefined; |
| 90 | 91 | if (typeof v !== "object" || v === null || Array.isArray(v)) return null; |
| 91 | 92 | const o = v as Record<string, unknown>; |
| 92 | const out: { page?: string; pull?: number; run?: string; commit?: string; said?: string } = {}; | |
| 93 | const out: { page?: string; pull?: number; app?: string; run?: string; commit?: string; said?: string } = {}; | |
| 93 | 94 | if (o["page"] !== undefined) { |
| 94 | 95 | const url = |
| 95 | 96 | typeof o["page"] === "string" && o["page"].length <= 2000 |
| @@ -111,6 +112,10 @@ export function parseContext(v: unknown): TellContext | undefined | null { | ||
| 111 | 112 | if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) return null; |
| 112 | 113 | out.pull = n; |
| 113 | 114 | } |
| 115 | if (o["app"] !== undefined) { | |
| 116 | if (typeof o["app"] !== "string" || !APP_SLUG.test(o["app"])) return null; | |
| 117 | out.app = o["app"]; | |
| 118 | } | |
| 114 | 119 | if (o["run"] !== undefined) { |
| 115 | 120 | if (typeof o["run"] !== "string" || !RUN.test(o["run"])) return null; |
| 116 | 121 | out.run = o["run"]; |
| @@ -135,14 +140,15 @@ export function parseContext(v: unknown): TellContext | undefined | null { | ||
| 135 | 140 | */ |
| 136 | 141 | export function contextNote(c: TellContext | undefined, opts: { preview?: boolean; app?: string } = {}): string { |
| 137 | 142 | if (c === undefined) return ""; |
| 138 | const preview = opts.preview === true ? previewLine(c.pull, c.page, opts.app) : ""; | |
| 143 | const app = opts.app ?? c.app; | |
| 144 | const preview = opts.preview === true ? previewLine(c.pull, c.page, app) : ""; | |
| 139 | 145 | const lines = [ |
| 140 | 146 | preview !== "" ? `- ${preview}` : "", |
| 141 | 147 | preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`, |
| 142 | 148 | preview !== "" || c.pull === undefined ? "" : `- pull: #${c.pull}`, |
| 143 | preview !== "" || opts.app === undefined || !APP_SLUG.test(opts.app) | |
| 149 | preview !== "" || app === undefined || !APP_SLUG.test(app) | |
| 144 | 150 | ? "" |
| 145 | : `- app: ${opts.app}`, | |
| 151 | : `- app: ${app}`, | |
| 146 | 152 | c.run === undefined ? "" : `- run: ${c.run}`, |
| 147 | 153 | c.commit === undefined ? "" : `- commit: ${c.commit}`, |
| 148 | 154 | c.said === undefined || c.said === "" |
src/http/mcp/tools/tell.ts +4 −3
| @@ -14,7 +14,7 @@ export const tool: Tool = { | ||
| 14 | 14 | name: "tell", |
| 15 | 15 | doc: "`{ repo?, text?, from? (a forge path like /a/b/pulls/3), context? }` or `{ repo, issue }`: a sentence becomes an issue, a builder is picked, a run starts on the crew's next tick; `issue` reads its status (sent, picked_up, stalled, landed, closed)", |
| 16 | 16 | description: |
| 17 | "Tell an app's crew what to change (first line: title). `issue`: status. No `repo`: kept", | |
| 17 | "Tell an app's crew a change (first line: title). `issue`: status. No `repo`: kept", | |
| 18 | 18 | inputSchema: { |
| 19 | 19 | type: "object", |
| 20 | 20 | properties: { |
| @@ -30,7 +30,8 @@ export const tool: Tool = { | ||
| 30 | 30 | type: "object", |
| 31 | 31 | properties: { |
| 32 | 32 | page: { type: "string" }, |
| 33 | pull: { type: "integer", minimum: 1 }, | |
| 33 | pull: { type: "integer" }, | |
| 34 | app: { type: "string" }, | |
| 34 | 35 | run: { type: "string" }, |
| 35 | 36 | commit: { type: "string" }, |
| 36 | 37 | said: { type: "string", maxLength: 2000 }, |
| @@ -78,7 +79,7 @@ export const tool: Tool = { | ||
| 78 | 79 | if (where === null) |
| 79 | 80 | return bad( |
| 80 | 81 | "invalid", |
| 81 | "context is { page?: http(s) address, pull?: number, run?: id, commit?: hex, said?: words }", | |
| 82 | "context is { page?: http(s) address, pull?: number, app?: slug, run?: id, commit?: hex, said?: words }", | |
| 82 | 83 | ); |
| 83 | 84 | const from = parseFrom(args["from"]); |
| 84 | 85 | if (from === undefined) return bad("invalid", FROM_WORDS); |
src/tui/screens/tell.ts +23 −7
| @@ -47,7 +47,7 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 47 | 47 | { |
| 48 | 48 | id: "tell-page", |
| 49 | 49 | title: `${name} — Tell the crew from a page`, |
| 50 | hint: "page, pull, then one line", | |
| 50 | hint: "page, pull, app, then one line", | |
| 51 | 51 | run: () => |
| 52 | 52 | ctx.push( |
| 53 | 53 | promptScreen(ctx, parent(), { |
| @@ -67,12 +67,23 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 67 | 67 | return "A pull is a number, like 7."; |
| 68 | 68 | return later(ctx, () => |
| 69 | 69 | promptScreen(ctx, parent(), { |
| 70 | title: "Tell the crew", | |
| 70 | title: "App", | |
| 71 | 71 | label: name, |
| 72 | hint: "enter sends", | |
| 73 | onSubmit: (said) => { | |
| 74 | if (said === "") return SAY_SOMETHING_WORDS; | |
| 75 | return tellFromPage(f, ctx, repo, said, page, number); | |
| 72 | hint: "the app's name, or leave empty; enter continues", | |
| 73 | onSubmit: (appName) => { | |
| 74 | const app = appName === "" ? undefined : appName; | |
| 75 | if (parseContext({ page, app }) === null) return "An app is a name like notes."; | |
| 76 | return later(ctx, () => | |
| 77 | promptScreen(ctx, parent(), { | |
| 78 | title: "Tell the crew", | |
| 79 | label: name, | |
| 80 | hint: "enter sends", | |
| 81 | onSubmit: (said) => { | |
| 82 | if (said === "") return SAY_SOMETHING_WORDS; | |
| 83 | return tellFromPage(f, ctx, repo, said, page, number, app); | |
| 84 | }, | |
| 85 | }), | |
| 86 | ); | |
| 76 | 87 | }, |
| 77 | 88 | }), |
| 78 | 89 | ); |
| @@ -94,8 +105,13 @@ export async function tellFromPage( | ||
| 94 | 105 | said: string, |
| 95 | 106 | page: string, |
| 96 | 107 | pull: number | undefined, |
| 108 | app?: string, | |
| 97 | 109 | ): Promise<void> { |
| 98 | const where = parseContext({ page, ...(pull === undefined ? {} : { pull }) }); | |
| 110 | const where = parseContext({ | |
| 111 | page, | |
| 112 | ...(pull === undefined ? {} : { pull }), | |
| 113 | ...(app === undefined ? {} : { app }), | |
| 114 | }); | |
| 99 | 115 | if (where === null || where === undefined) { |
| 100 | 116 | ctx.toast(NOT_TOLD_FROM_WORDS, "danger"); |
| 101 | 117 | return; |
test/mcp-tell.test.ts +17
| @@ -10,6 +10,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { newApp } from "../src/actions/apps.ts"; |
| 11 | 11 | import { refusalWords, tellAnswer } from "../src/actions/tell_answer.ts"; |
| 12 | 12 | import { SAY_SOMETHING_WORDS } from "../src/actions/tell_words.ts"; |
| 13 | import { listIssues } from "../src/core/issues.ts"; | |
| 14 | import { getRepo } from "../src/core/repos.ts"; | |
| 13 | 15 | import { getUserByName } from "../src/core/users.ts"; |
| 14 | 16 | import { serve, type Servers } from "../src/http/server.ts"; |
| 15 | 17 | import { seedAdmin } from "./helpers/admin.ts"; |
| @@ -61,6 +63,21 @@ describe("MCP tell refusals", () => { | ||
| 61 | 63 | expect(r.text).toContain(SAY_SOMETHING_WORDS); |
| 62 | 64 | }); |
| 63 | 65 | |
| 66 | test("context.app and context.page reach the issue body; a bad app is refused", async () => { | |
| 67 | const r = await call({ | |
| 68 | repo: "alice/notes", | |
| 69 | text: "Move the button", | |
| 70 | context: { page: "https://notes.apps.test/a", app: "notes" }, | |
| 71 | }); | |
| 72 | expect(r.error).toBe(false); | |
| 73 | const repo = getRepo(app.db, "alice", "notes")!; | |
| 74 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "Move the button")!; | |
| 75 | expect(issue.body).toContain("- page: https://notes.apps.test/a"); | |
| 76 | expect(issue.body).toContain("- app: notes"); | |
| 77 | const bad = await call({ repo: "alice/notes", text: "x", context: { app: "<b>" } }); | |
| 78 | expect(bad.error).toBe(true); | |
| 79 | }); | |
| 80 | ||
| 64 | 81 | test("an over-long tell is refused in the words the terminal and the page say", async () => { |
| 65 | 82 | const r = await call({ repo: "alice/notes", text: "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000) }); |
| 66 | 83 | expect(r.error).toBe(true); |
test/tell-context.test.ts +14
| @@ -26,3 +26,17 @@ test("only a door that asked for a preview's pull says 'from preview'", () => { | ||
| 26 | 26 | // A preview with no pull is no preview. |
| 27 | 27 | expect(contextNote(parseContext({ page: "https://n.apps.test/a" }) ?? undefined, { preview: true })).toContain("- page:"); |
| 28 | 28 | }); |
| 29 | ||
| 30 | test("context.app is told as a line, escaped by its slug shape, and a bad one is refused", () => { | |
| 31 | const c = parseContext({ page: "https://n.apps.test/a", app: "notes" }); | |
| 32 | expect(c).toEqual({ page: "https://n.apps.test/a", app: "notes" }); | |
| 33 | expect(contextNote(c ?? undefined)).toContain("- app: notes"); | |
| 34 | expect(parseContext({ app: "<b>x</b>" })).toBeNull(); | |
| 35 | expect(parseContext({ app: 5 })).toBeNull(); | |
| 36 | }); | |
| 37 | ||
| 38 | test("a door-supplied app wins over context.app", () => { | |
| 39 | const c = parseContext({ page: "https://n.apps.test/a", app: "notes" }); | |
| 40 | expect(contextNote(c ?? undefined, { app: "other" })).toContain("- app: other"); | |
| 41 | expect(contextNote(c ?? undefined, { app: "other" })).not.toContain("notes"); | |
| 42 | }); |
test/tui-tell.test.ts +10 −1
| @@ -89,7 +89,7 @@ describe("tell the crew in the terminal", () => { | ||
| 89 | 89 | }); |
| 90 | 90 | |
| 91 | 91 | test("a tell from a page carries its page and pull, and bob has no such row", async () => { |
| 92 | const keys = [":", "from a page", "\r", ..."https://notes.apps.test/a".split(""), "\r", "7", "\r", ..."move the button".split(""), "\r"]; | |
| 92 | const keys = [":", "from a page", "\r", ..."https://notes.apps.test/a".split(""), "\r", "7", "\r", "\r", ..."move the button".split(""), "\r"]; | |
| 93 | 93 | const text = await palette(alice, keys); |
| 94 | 94 | expect(text).toContain("Nobody is on the crew to take it yet"); |
| 95 | 95 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "move the button")!; |
| @@ -97,6 +97,15 @@ 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 () => { | |
| 101 | const page = [":", "from a page", "\r", ..."https://notes.apps.test/a".split(""), "\r", "\r"]; | |
| 102 | await palette(alice, [...page, ..."notes".split(""), "\r", ..."name the app".split(""), "\r"]); | |
| 103 | const issue = listIssues(app.db, repo.id, {}).find((i) => i.title === "name the app")!; | |
| 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."); | |
| 107 | }); | |
| 108 | ||
| 100 | 109 | test("a page that is not http(s) keeps the prompt open and tells nothing", async () => { |
| 101 | 110 | const before = listIssues(app.db, repo.id, {}).length; |
| 102 | 111 | const text = await palette(alice, [":", "from a page", "\r", ..."javascript:alert(1)".split(""), "\r"]); |
new above
offline
Precedence of opts.app over c.app is new behaviour with no test; add one.