Public: anyone can read this; the crew can change it.

A tell sent through the MCP carries the page it came from #14879

Merged opened this

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

Merged

mason/forge:mason/14859-a-tell-sent-through-the-mcp-carries-the → main 5 commits fork 2 threads · 2 unresolved

  • Merged. mason/14859-a-tell-sent-through-the-mcp-carries-the was merged into main as f4cdab5.

Review

Sign in to review this change.
8 files changed +92 −16
docs/MCP.md +1 −1
@@ -485,7 +485,7 @@ answers
485485 `POST …/issues/{number}/dependencies` and
486486 `DELETE …/issues/{number}/dependencies/{blocker}`. `test/openapi.test.ts` fails
487487 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),
489489 `run`, `commit` (hex) and `said` (the person's words). Malformed context is
490490 refused; the rest is appended to the issue body. `tell` also takes `from`: a
491491 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";
1111 export interface TellContext {
1212 readonly page?: string;
1313 readonly pull?: number;
14 readonly app?: string;
1415 readonly run?: string;
1516 readonly commit?: string;
1617 readonly said?: string;
@@ -89,7 +90,7 @@ export function parseContext(v: unknown): TellContext | undefined | null {
8990 if (v === undefined) return undefined;
9091 if (typeof v !== "object" || v === null || Array.isArray(v)) return null;
9192 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 } = {};
9394 if (o["page"] !== undefined) {
9495 const url =
9596 typeof o["page"] === "string" && o["page"].length <= 2000
@@ -111,6 +112,10 @@ export function parseContext(v: unknown): TellContext | undefined | null {
111112 if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) return null;
112113 out.pull = n;
113114 }
115 if (o["app"] !== undefined) {
116 if (typeof o["app"] !== "string" || !APP_SLUG.test(o["app"])) return null;
117 out.app = o["app"];
118 }
114119 if (o["run"] !== undefined) {
115120 if (typeof o["run"] !== "string" || !RUN.test(o["run"])) return null;
116121 out.run = o["run"];
@@ -135,14 +140,15 @@ export function parseContext(v: unknown): TellContext | undefined | null {
135140 */
136141 export function contextNote(c: TellContext | undefined, opts: { preview?: boolean; app?: string } = {}): string {
137142 if (c === undefined) return "";
138 const preview = opts.preview === true ? previewLine(c.pull, c.page, opts.app) : "";
143 const app = opts.app ?? c.app;

Precedence of opts.app over c.app is new behaviour with no test; add one.

144 const preview = opts.preview === true ? previewLine(c.pull, c.page, app) : "";
139145 const lines = [
140146 preview !== "" ? `- ${preview}` : "",
141147 preview !== "" || c.page === undefined ? "" : `- page: ${c.page}`,
142148 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)
144150 ? ""
145 : `- app: ${opts.app}`,
151 : `- app: ${app}`,
146152 c.run === undefined ? "" : `- run: ${c.run}`,
147153 c.commit === undefined ? "" : `- commit: ${c.commit}`,
148154 c.said === undefined || c.said === ""
src/http/mcp/tools/tell.ts +4 −3
@@ -14,7 +14,7 @@ export const tool: Tool = {
1414 name: "tell",
1515 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)",
1616 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",
1818 inputSchema: {
1919 type: "object",
2020 properties: {
@@ -30,7 +30,8 @@ export const tool: Tool = {
3030 type: "object",
3131 properties: {
3232 page: { type: "string" },
33 pull: { type: "integer", minimum: 1 },
33 pull: { type: "integer" },
34 app: { type: "string" },
3435 run: { type: "string" },
3536 commit: { type: "string" },
3637 said: { type: "string", maxLength: 2000 },
@@ -78,7 +79,7 @@ export const tool: Tool = {
7879 if (where === null)
7980 return bad(
8081 "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 }",
8283 );
8384 const from = parseFrom(args["from"]);
8485 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
4747 {
4848 id: "tell-page",
4949 title: `${name} — Tell the crew from a page`,
50 hint: "page, pull, then one line",
50 hint: "page, pull, app, then one line",
5151 run: () =>
5252 ctx.push(
5353 promptScreen(ctx, parent(), {
@@ -67,12 +67,23 @@ export function tellCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R
6767 return "A pull is a number, like 7.";
6868 return later(ctx, () =>
6969 promptScreen(ctx, parent(), {
70 title: "Tell the crew",
70 title: "App",
7171 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 );
7687 },
7788 }),
7889 );
@@ -94,8 +105,13 @@ export async function tellFromPage(
94105 said: string,
95106 page: string,
96107 pull: number | undefined,
108 app?: string,
97109 ): 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 });
99115 if (where === null || where === undefined) {
100116 ctx.toast(NOT_TOLD_FROM_WORDS, "danger");
101117 return;
test/mcp-tell.test.ts +17
@@ -10,6 +10,8 @@ import { createApp, type App } from "../src/app.ts";
1010 import { newApp } from "../src/actions/apps.ts";
1111 import { refusalWords, tellAnswer } from "../src/actions/tell_answer.ts";
1212 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";
1315 import { getUserByName } from "../src/core/users.ts";
1416 import { serve, type Servers } from "../src/http/server.ts";
1517 import { seedAdmin } from "./helpers/admin.ts";
@@ -61,6 +63,21 @@ describe("MCP tell refusals", () => {
6163 expect(r.text).toContain(SAY_SOMETHING_WORDS);
6264 });
6365
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
6481 test("an over-long tell is refused in the words the terminal and the page say", async () => {
6582 const r = await call({ repo: "alice/notes", text: "x".repeat(7999) + "\n".repeat(3) + "y".repeat(60_000) });
6683 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'", () => {
2626 // A preview with no pull is no preview.
2727 expect(contextNote(parseContext({ page: "https://n.apps.test/a" }) ?? undefined, { preview: true })).toContain("- page:");
2828 });
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", () => {
8989 });
9090
9191 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"];
9393 const text = await palette(alice, keys);
9494 expect(text).toContain("Nobody is on the crew to take it yet");
9595 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", () => {
9797 expect(await palette(bob, [":", "from a page"])).not.toContain("Tell the crew from a page");
9898 });
9999
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
100109 test("a page that is not http(s) keeps the prompt open and tells nothing", async () => {
101110 const before = listIssues(app.db, repo.id, {}).length;
102111 const text = await palette(alice, [":", "from a page", "\r", ..."javascript:alert(1)".split(""), "\r"]);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs