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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15658-a-tell-can-be-taken-back-for-60-seconds → main 0 commits fork 2 threads · 2 unresolved
8 files
changed +118
−17
docs/MCP.md +1
| @@ -485,6 +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 | - **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. | |
| 488 | 489 | - **Where a tell came from.** `tell` takes `context`: `page` (http/https), `app` (a slug, shown as an `app:` line), |
| 489 | 490 | `run`, `commit` (hex) and `said` (the person's words). Malformed context is |
| 490 | 491 | 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."; | ||
| 23 | 23 | /** Why a tell cannot be taken back: the minute passed, or someone has read it. */ |
| 24 | 24 | export const TOO_LATE_WORDS = "Too late to take that back: it was sent over a minute ago or the crew has read it."; |
| 25 | 25 | |
| 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 | } | |
| 27 | 48 | |
| 28 | 49 | /** Whether an issue is still inside its undo minute and unread (no run begun, no comment). */ |
| 29 | 50 | 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( | ||
| 32 | 53 | if (!(age >= 0 && age < TELL_UNDO_MS)) return false; |
| 33 | 54 | if (countComments(app.db, issue.id) > 0) return false; |
| 34 | 55 | // 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); | |
| 41 | 57 | } |
| 42 | 58 | |
| 43 | 59 | /** |
| @@ -71,7 +87,10 @@ export function undoTell( | ||
| 71 | 87 | const issue = getIssue(app.db, repo.id, number); |
| 72 | 88 | if (issue === undefined) return err("not_found"); |
| 73 | 89 | 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 | } | |
| 75 | 94 | const queued = app.db |
| 76 | 95 | .query<{ id: string }, [string]>("SELECT id FROM run WHERE issue_id = ?1 AND kind = 'agent' AND state = 'queued'") |
| 77 | 96 | .all(issue.id); |
src/http/mcp/tools/forges.ts +1 −1
| @@ -18,7 +18,7 @@ export const tool: Tool = { | ||
| 18 | 18 | name: "forges", |
| 19 | 19 | 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", |
| 20 | 20 | 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.", | |
| 22 | 22 | 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" } } }, |
| 23 | 23 | writes: true, |
| 24 | 24 | dryByDefault: true, |
src/http/mcp/tools/runs.ts +3 −3
| @@ -9,7 +9,7 @@ export const tool: Tool = { | ||
| 9 | 9 | name: "runs", |
| 10 | 10 | 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", |
| 11 | 11 | 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.", | |
| 13 | 13 | inputSchema: { |
| 14 | 14 | type: "object", |
| 15 | 15 | properties: { |
| @@ -17,13 +17,13 @@ export const tool: Tool = { | ||
| 17 | 17 | kind: { |
| 18 | 18 | type: "string", |
| 19 | 19 | enum: ["agent", "deploy", "check"], |
| 20 | description: "Only runs of this kind; all kinds when omitted.", | |
| 20 | description: "Only this kind; default all.", | |
| 21 | 21 | }, |
| 22 | 22 | limit: { |
| 23 | 23 | type: "integer", |
| 24 | 24 | minimum: 1, |
| 25 | 25 | maximum: 50, |
| 26 | description: "Default 20.", | |
| 26 | description: "Default 20", | |
| 27 | 27 | }, |
| 28 | 28 | }, |
| 29 | 29 | required: ["repo"], |
src/http/mcp/tools/say.ts +1 −1
| @@ -18,7 +18,7 @@ export const tool: Tool = { | ||
| 18 | 18 | name: "say", |
| 19 | 19 | 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`", |
| 20 | 20 | 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.", | |
| 22 | 22 | inputSchema: { |
| 23 | 23 | type: "object", |
| 24 | 24 | properties: { |
src/http/mcp/tools/tell.ts +23 −2
| @@ -5,6 +5,7 @@ import { keepThought } from "../../../actions/thought.ts"; | ||
| 5 | 5 | import { overTellLimit, parseFrom, TELL_LIMIT_HINT, tellTooLongWords } from "../../../actions/tell_from.ts"; |
| 6 | 6 | import { FROM_WORDS, tell, toldWords } from "../../../actions/tell.ts"; |
| 7 | 7 | import { refusalWords } from "../../../actions/tell_answer.ts"; |
| 8 | import { TAKEN_BACK_WORDS, undoRefusalWords, undoTell } from "../../../actions/tell_undo.ts"; | |
| 8 | 9 | import { mayReadRuns } from "../../../actions/runs.ts"; |
| 9 | 10 | import { getIssue } from "../../../core/issues.ts"; |
| 10 | 11 | import { tellStatusFields } from "../../../runs/tell_status.ts"; |
| @@ -12,14 +13,15 @@ import { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../share | ||
| 12 | 13 | |
| 13 | 14 | export const tool: Tool = { |
| 14 | 15 | 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)", | |
| 16 | 17 | 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", | |
| 18 | 19 | inputSchema: { |
| 19 | 20 | type: "object", |
| 20 | 21 | properties: { |
| 21 | 22 | repo: REPO_ARG, |
| 22 | 23 | issue: { type: "integer" }, |
| 24 | undo: { type: "integer" }, | |
| 23 | 25 | text: { type: "string", maxLength: 4000 }, |
| 24 | 26 | from: { |
| 25 | 27 | type: "string", |
| @@ -65,6 +67,25 @@ export const tool: Tool = { | ||
| 65 | 67 | "text is a string of at most 20,000 characters", |
| 66 | 68 | ); |
| 67 | 69 | } |
| 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 | } | |
| 68 | 89 | const said = str(args["text"]).trim(); |
| 69 | 90 | if (overTellLimit(said)) return bad("invalid", `${tellTooLongWords(said)} ${TELL_LIMIT_HINT}`); |
| 70 | 91 | const repo = repoArg(ctx, user, args); |
src/web/studio/actions.ts +2 −2
| @@ -17,7 +17,7 @@ import { holdPull, releasePull } from "../../actions/holds.ts"; | ||
| 17 | 17 | import { addComment } from "../../actions/issues.ts"; |
| 18 | 18 | import { overTellLimit, parseFrom, tellTooLongWords } from "../../actions/tell_from.ts"; |
| 19 | 19 | 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"; | |
| 21 | 21 | import { contextNote, whereTold } from "../../actions/tell_context.ts"; |
| 22 | 22 | import { refusalWords } from "../../actions/tell_answer.ts"; |
| 23 | 23 | import { SAY_SOMETHING_WORDS, WITHOUT_WHERE_WORDS } from "../../actions/tell_words.ts"; |
| @@ -219,7 +219,7 @@ export async function tellUndoSubmit(ctx: Ctx): Promise<Response> { | ||
| 219 | 219 | if (!undone.ok) |
| 220 | 220 | return flashTo(ctx, back, { |
| 221 | 221 | tone: "danger", |
| 222 | message: undone.error === "too_late" ? TOO_LATE_WORDS : "That tell cannot be taken back.", | |
| 222 | message: undoRefusalWords(undone.error), | |
| 223 | 223 | }); |
| 224 | 224 | return page({ |
| 225 | 225 | 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 | }); |
new above
offline
Restore maxLength on text (and on from and said below). Server-side validation stays, but clients lose the advertised limit. Make the room elsewhere.