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

A tell can be taken back for 60 seconds from the page it was sent on, and the MCP tell tool takes the same `undo` #15675

Merged opened this

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

Merged

mason/forge:mason/15658-a-tell-can-be-taken-back-for-60-seconds → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/15658-a-tell-can-be-taken-back-for-60-seconds was merged into main as 0ba4512.

Review

Sign in to review this change.
8 files changed +118 −17
docs/MCP.md +1
@@ -485,6 +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 - **Taking a tell back.** `tell` takes `undo` (an issue number, with `repo`): within 60 s of sending, while no run has begun and nobody has commented, the author closes it as dropped. A tell a run has picked up answers that it is running; after the minute, that it is too late.
488489 - **Where a tell came from.** `tell` takes `context`: `page` (http/https), `app` (a slug, shown as an `app:` line),
489490 `run`, `commit` (hex) and `said` (the person's words). Malformed context is
490491 refused; the rest is appended to the issue body. `tell` also takes `from`: a
src/actions/tell_undo.ts +27 −8
@@ -23,7 +23,28 @@ export const TAKEN_BACK_WORDS = "Taken back. Nothing was started.";
2323 /** Why a tell cannot be taken back: the minute passed, or someone has read it. */
2424 export const TOO_LATE_WORDS = "Too late to take that back: it was sent over a minute ago or the crew has read it.";
2525
26 export type UndoError = "not_found" | "unauthorized" | "forbidden" | "too_late";
26 /** Why a tell cannot be taken back once a run has picked it up: it is running, and stays. */
27 export const RUNNING_WORDS = "Too late to take that back: the crew has picked it up and it is running.";
28
29 export type UndoError = "not_found" | "unauthorized" | "forbidden" | "too_late" | "running";
30
31 /** The plain reason for a refused undo. */
32 export function undoRefusalWords(error: UndoError): string {
33 if (error === "too_late") return TOO_LATE_WORDS;
34 if (error === "running") return RUNNING_WORDS;
35 return "That tell cannot be taken back.";
36 }
37
38 /** Whether an agent run has begun on the issue (started, or finished). */
39 function runBegun(app: App, issue: Issue): boolean {
40 return (
41 app.db
42 .query<{ n: number }, [string]>(
43 "SELECT 1 AS n FROM run WHERE issue_id = ?1 AND kind = 'agent' AND state NOT IN ('queued','cancelled') LIMIT 1",
44 )
45 .get(issue.id) !== null
46 );
47 }
2748
2849 /** Whether an issue is still inside its undo minute and unread (no run begun, no comment). */
2950 export function tellUndoable(app: App, repo: Repo, issue: Issue, now = Date.now()): boolean {
@@ -32,12 +53,7 @@ export function tellUndoable(app: App, repo: Repo, issue: Issue, now = Date.now(
3253 if (!(age >= 0 && age < TELL_UNDO_MS)) return false;
3354 if (countComments(app.db, issue.id) > 0) return false;
3455 // One existence query, not a page of runs: a tell with many runs is still judged on all of them.
35 const begun = app.db
36 .query<{ n: number }, [string]>(
37 "SELECT 1 AS n FROM run WHERE issue_id = ?1 AND kind = 'agent' AND state NOT IN ('queued','cancelled') LIMIT 1",
38 )
39 .get(issue.id);
40 return begun === null;
56 return !runBegun(app, issue);
4157 }
4258
4359 /**
@@ -71,7 +87,10 @@ export function undoTell(
7187 const issue = getIssue(app.db, repo.id, number);
7288 if (issue === undefined) return err("not_found");
7389 if (issue.authorId !== actor.id) return err("forbidden");
74 if (!tellUndoable(app, repo, issue, now)) return err("too_late");
90 if (!tellUndoable(app, repo, issue, now)) {
91 const young = now - Date.parse(issue.createdAt) < TELL_UNDO_MS;
92 return err(young && issue.state === "open" && runBegun(app, issue) ? "running" : "too_late");
93 }
7594 const queued = app.db
7695 .query<{ id: string }, [string]>("SELECT id FROM run WHERE issue_id = ?1 AND kind = 'agent' AND state = 'queued'")
7796 .all(issue.id);
src/http/mcp/tools/forges.ts +1 −1
@@ -18,7 +18,7 @@ export const tool: Tool = {
1818 name: "forges",
1919 doc: "an admin's list of the forges sent from here: name, address, whom for, apps, claimed, stage (sent/opened/signed in/last tell; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large) or, with `plan`, grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge out of this forge's own process into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven and put back on any failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused lists the last 20 refused first asks; `kind` clients lists each client in the page's words",
2020 description:
21 "Forges sent from here (admin), clients, a forge's plan or size.",
21 "Forges sent from here (admin), clients, a forge plan or size.",
2222 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["refused", "clients"] }, forge: { type: "string" }, plan: { type: "string" }, codes: { type: "boolean" }, code: { type: "object" }, revoke: { type: "string" }, archive: { type: ["string", "array"], items: { type: "string" } }, restore: { type: "string" }, sandbox: { type: "boolean" }, size: { type: "string" }, acknowledge: { type: "boolean" }, dryRun: { type: "boolean" } } },
2323 writes: true,
2424 dryByDefault: true,
src/http/mcp/tools/runs.ts +3 −3
@@ -9,7 +9,7 @@ export const tool: Tool = {
99 name: "runs",
1010 doc: "`{ repo, kind?, limit? }`: the repository's recent runs (kind agent, deploy or check), newest first (id, kind, state, issue or pull number and title, `untrusted: true` on a title from someone who cannot write, started, ended; draws the `ui://forge/runs` card, a failed run first in its status, each row linked to its run page), 1–50, default 20; read as the runs page reads them",
1111 description:
12 "A repository's runs, newest first: id, kind, state, number, start, end.",
12 "A repo's runs, newest first: id, kind, state, number, start, end.",
1313 inputSchema: {
1414 type: "object",
1515 properties: {
@@ -17,13 +17,13 @@ export const tool: Tool = {
1717 kind: {
1818 type: "string",
1919 enum: ["agent", "deploy", "check"],
20 description: "Only runs of this kind; all kinds when omitted.",
20 description: "Only this kind; default all.",
2121 },
2222 limit: {
2323 type: "integer",
2424 minimum: 1,
2525 maximum: 50,
26 description: "Default 20.",
26 description: "Default 20",
2727 },
2828 },
2929 required: ["repo"],
src/http/mcp/tools/say.ts +1 −1
@@ -18,7 +18,7 @@ export const tool: Tool = {
1818 name: "say",
1919 doc: "`{ repo?, number?, text?, conversation?, action?, title?, archived? }`: speak on an issue or a pull; a working builder hears it as its next step. With no `repo` or `number` it speaks to the forge's own agent (`forge talk`), which answers in `GET /api/v1/conversation/turns`. `conversation` names one of your conversations (default: the latest); `action` list | find (`text`: words; matching line) | new | rename | archive | restore | download (Markdown) manages them (`title` for rename and new; `archived` lists archived); `action` build (`text` prompt, `template`) | build_state | build_diff (`version`) | build_restore (`version`) | build_publish drives a talk build of `conversation`",
2020 description:
21 "Say something on an issue or pull; with no repo, to the forge agent; manage, find, download chats.",
21 "Say something on an issue or pull; no repo: to the forge agent; manage, find, download chats.",
2222 inputSchema: {
2323 type: "object",
2424 properties: {
src/http/mcp/tools/tell.ts +23 −2
@@ -5,6 +5,7 @@ import { keepThought } from "../../../actions/thought.ts";
55 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, tellTooLongWords } from "../../../actions/tell_from.ts";
66 import { FROM_WORDS, tell, toldWords } from "../../../actions/tell.ts";
77 import { refusalWords } from "../../../actions/tell_answer.ts";
8 import { TAKEN_BACK_WORDS, undoRefusalWords, undoTell } from "../../../actions/tell_undo.ts";
89 import { mayReadRuns } from "../../../actions/runs.ts";
910 import { getIssue } from "../../../core/issues.ts";
1011 import { tellStatusFields } from "../../../runs/tell_status.ts";
@@ -12,14 +13,15 @@ import { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../share
1213
1314 export const tool: Tool = {
1415 name: "tell",
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 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); `{ repo, undo }` retracts your tell within 60 s while unread (closes it as dropped)",
1617 description:
17 "Tell an app's crew a change (first line: title). `issue`: status. No `repo`: kept",
18 "Tell app crew a change (line 1 titles). `issue`: status; retract by id. No repo: kept",
1819 inputSchema: {
1920 type: "object",
2021 properties: {
2122 repo: REPO_ARG,
2223 issue: { type: "integer" },
24 undo: { type: "integer" },
2325 text: { type: "string", maxLength: 4000 },
outdated

Restore maxLength on text (and on from and said below). Server-side validation stays, but clients lose the advertised limit. Make the room elsewhere.

2426 from: {
2527 type: "string",
@@ -65,6 +67,25 @@ export const tool: Tool = {
6567 "text is a string of at most 20,000 characters",
6668 );
6769 }
70 if (args["undo"] !== undefined) {
71 const found = repoArg(ctx, user, args);
72 if (isAnswer(found)) return found;
73 const n = args["undo"];
outdated

Add a test that a read-only token calling undo is refused, and wrap these long lines.

74 if (typeof n !== "number" || !Number.isInteger(n) || n < 1) {
75 return bad("invalid", "undo is a tell's issue number");
76 }
77 const undone = undoTell(ctx.app, user, found, n);
78 if (!undone.ok) {
79 const code = undone.error === "unauthorized" ? "forbidden" : undone.error;
80 return bad(code, undoRefusalWords(undone.error));
81 }
82 const { number } = undone.value;
83 return good({
84 issue: number,
85 status: "closed",
86 says: `${TAKEN_BACK_WORDS} Issue #${number} is closed as dropped.`,
87 });
88 }
6889 const said = str(args["text"]).trim();
6990 if (overTellLimit(said)) return bad("invalid", `${tellTooLongWords(said)} ${TELL_LIMIT_HINT}`);
7091 const repo = repoArg(ctx, user, args);
src/web/studio/actions.ts +2 −2
@@ -17,7 +17,7 @@ import { holdPull, releasePull } from "../../actions/holds.ts";
1717 import { addComment } from "../../actions/issues.ts";
1818 import { overTellLimit, parseFrom, tellTooLongWords } from "../../actions/tell_from.ts";
1919 import { SENT_WORDS, tell, toldWords } from "../../actions/tell.ts";
20 import { TAKEN_BACK_WORDS, TOO_LATE_WORDS, tellUndoable, undoTell } from "../../actions/tell_undo.ts";
20 import { TAKEN_BACK_WORDS, tellUndoable, undoRefusalWords, undoTell } from "../../actions/tell_undo.ts";
2121 import { contextNote, whereTold } from "../../actions/tell_context.ts";
2222 import { refusalWords } from "../../actions/tell_answer.ts";
2323 import { SAY_SOMETHING_WORDS, WITHOUT_WHERE_WORDS } from "../../actions/tell_words.ts";
@@ -219,7 +219,7 @@ export async function tellUndoSubmit(ctx: Ctx): Promise<Response> {
219219 if (!undone.ok)
220220 return flashTo(ctx, back, {
221221 tone: "danger",
222 message: undone.error === "too_late" ? TOO_LATE_WORDS : "That tell cannot be taken back.",
222 message: undoRefusalWords(undone.error),
223223 });
224224 return page({
225225 ctx,
test/mcp-tell-undo.test.ts added +60
@@ -0,0 +1,60 @@
1 /**
2 * The MCP tell tool takes `undo`: inside the minute, refused after it, refused for another person,
3 * running said plainly.
4 */
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6 import { getIssue } from "../src/core/issues.ts";
7 import { claimRun, createRun } from "../src/core/runs.ts";
8 import { TAKEN_BACK_WORDS, TOO_LATE_WORDS, RUNNING_WORDS, TELL_UNDO_MS } from "../src/actions/tell_undo.ts";
9 import { mcpClient, startMcpForge, type McpForge } from "./support/mcp-forge.ts";
10
11 describe("tell undo over MCP", () => {
12 let forge: McpForge;
13 const { tool } = mcpClient(() => forge.base);
14 beforeAll(async () => {
15 forge = await startMcpForge();
16 }, 30_000);
17 afterAll(() => forge.stop());
18
19 const send = async (text: string) => (await tool(forge.rw, "tell", { repo: "alice/game", text })).value.issue as number;
20
21 test("inside the window it closes the issue and says so", async () => {
22 const n = await send("undo me");
23 const r = await tool(forge.rw, "tell", { repo: "alice/game", undo: n });
24 expect(r.value.says).toContain(TAKEN_BACK_WORDS);
25 expect(getIssue(forge.app.db, forge.game.id, n)!.state).toBe("closed");
26 expect((await tool(forge.rw, "tell", { repo: "alice/game", undo: n })).error).toContain(TOO_LATE_WORDS);
27 });
28
29 test("after the window it is refused with the reason", async () => {
30 const n = await send("too slow");
31 const old = new Date(Date.now() - TELL_UNDO_MS - 5_000).toISOString();
32 forge.app.db.query("UPDATE issue SET created_at = ?1 WHERE repo_id = ?2 AND number = ?3").run(old, forge.game.id, n);
33 expect((await tool(forge.rw, "tell", { repo: "alice/game", undo: n })).error).toContain(TOO_LATE_WORDS);
34 expect(getIssue(forge.app.db, forge.game.id, n)!.state).toBe("open");
35 });
36
37 test("another person is refused", async () => {
38 const n = await send("mine");
39 const r = await tool(forge.bobRw, "tell", { repo: "alice/game", undo: n });
40 expect(r.error).toBeDefined();
41 expect(getIssue(forge.app.db, forge.game.id, n)!.state).toBe("open");
42 });
43
44 test("a read-only token is refused and the issue stays open", async () => {
45 const n = await send("mine, but read-only");
46 const r = await tool(forge.ro, "tell", { repo: "alice/game", undo: n });
47 expect(r.error).toBeDefined();
48 expect(r.value?.says).toBeUndefined();
49 expect(getIssue(forge.app.db, forge.game.id, n)!.state).toBe("open");
50 });
51
52 test("a tell a run has picked up says it is running", async () => {
53 const n = await send("already going");
54 const issue = getIssue(forge.app.db, forge.game.id, n)!;
55 const run = createRun(forge.app.db, { repoId: forge.game.id, kind: "agent", issueId: issue.id, branch: "b", reason: "assigned" });
56 claimRun(forge.app.db, run.id);
57 expect((await tool(forge.rw, "tell", { repo: "alice/game", undo: n })).error).toContain(RUNNING_WORDS);
58 expect(getIssue(forge.app.db, forge.game.id, n)!.state).toBe("open");
59 });
60 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs