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

A tell's receipt names the run that picked it up, linking to it, within the same page #14169

Merged opened this

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

Merged

scout/forge:scout/14161-a-tell-s-receipt-names-the-run-that-pick → main 9 commits fork 3 threads · 3 unresolved

  • Merged. scout/14161-a-tell-s-receipt-names-the-run-that-pick was merged into main as 70a9be8.

Review

Sign in to review this change.
9 files changed +236 −38
docs/MCP.md +1 −1
@@ -232,7 +232,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`;
232232 | `teams` | — | Crew teams for person admins: charter, dial (0–100) and member agents | 338 |
233233 | `telemetry_grant` | — | Grant an agent telemetry:read, or `on: false` takes it back | 226 |
234234 | `telemetry_history` | — | Machine CPU, memory, load over `hours` (1–72, default 6) | 239 |
235 | `tell` | — | Tell an app's crew what to change (first line: title) | 480 |
235 | `tell` | — | Tell an app's crew what to change (first line: title) | 484 |
236236 | `templates` | — | The templates a child forge may start from | 164 |
237237 | `thought` | — | Where a thought went, by its id (from `tell` without a repo) | 220 |
238238 | `threads` | — | A pull's review threads; with `anchor`, resolve one or reopen it (`resolved` false) | 317 |
docs/features/tell-status.md +5 −1
@@ -2,13 +2,17 @@
22
33 The head of a tell's page (and the terminal's issue screen, in its summary row) carries one line:
44
5 - `Waiting: nobody has picked it up yet`, or `Waiting: queued for the crew`
5 - `Sent: nobody has picked it up yet`, or `Sent: queued for the crew`; after 10 minutes `Stalled: nothing picked it up in 10 minutes` with, for writers, `Pick an assignee below` (a link to the assignee box; it assigns nothing itself) and, in the terminal, `a to assign it` (the existing assign key)
66 - `Picked up by <crew member>` while a run is going, or `…; no pull came of it (<state>)`
77 - `…pull #N is open` and `Landed in pull #N`, with the pull linked on the page
88
9 The picking run is linked (`run`). The page keeps the line live (the existing stream, plus one look when the ten minutes pass). The MCP `tell` tool reads the same with `{ repo, issue }`: `status` is `sent`, `picked_up`, `stalled`, `landed` or `closed`, with `run` and `pull`.
10
911 A tell with several agent runs shows the latest and `· N runs`.
1012
1113 - **Where it comes from.** `tellStatus` (`src/runs/tell_status.ts`) reads the `run` rows of the issue and
1214 the pull that closes it or that the latest run's branch opened. No table of its own.
1315 - **Who sees it.** Those who may read the app's runs (`mayReadRuns`); a private app's tells show it to nobody else.
1416 - Tests: `test/tell-status.test.ts`.
17
18 - **Left out.** The stall clock counts from the tell's creation and ignores a queued run that was dropped. The MCP status read (`{ repo, issue }`) is a read: a read-only token may make it.
src/http/mcp/tools/tell.ts +17 −5
@@ -5,23 +5,26 @@ import { keepThought } from "../../../actions/thought.ts";
55 import { overTellLimit, parseFrom, TELL_LIMIT_HINT, TELL_LIMIT_WORDS } 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 { mayReadRuns } from "../../../actions/runs.ts";
9 import { getIssue } from "../../../core/issues.ts";
10 import { tellStatusFields } from "../../../runs/tell_status.ts";
811 import { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
912
1013 export const tool: Tool = {
1114 name: "tell",
12 doc: "`{ repo?, text, from?, context? }`: a sentence becomes an issue, a builder is picked, a run starts on the crew's next tick",
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)",
1316 description:
14 "Tell an app's crew what to change (first line: title). No `repo`: kept.",
17 "Tell an app's crew what to change (first line: title). `issue`: status. No `repo`: kept",
1518 inputSchema: {
1619 type: "object",
1720 properties: {
1821 repo: REPO_ARG,
22 issue: { type: "integer" },
1923 text: { type: "string", maxLength: 4000 },
2024 from: {
2125 type: "string",
2226 maxLength: 512,
23 description:
24 "Forge path to link, as /a/b/pulls/3.",
27 description: "Path /a/b/pulls/3",
2528 },
2629 context: {
2730 type: "object",
@@ -34,9 +37,11 @@ export const tool: Tool = {
3437 },
3538 },
3639 },
37 required: ["text"],
3840 },
3941 writes: true,
42 // `{ repo, issue }` only reads a status: a read-only token may make it, and no write gate holds
43 // it.
44 readsWhen: (args) => args["issue"] !== undefined && args["repo"] != null && args["text"] === undefined,
4045 async run(ctx, user, args) {
4146 if (args["repo"] === undefined || args["repo"] === null) {
4247 // No repository named: a person with no app but the forge's own copy makes a new app.
@@ -63,6 +68,12 @@ export const tool: Tool = {
6368 return bad("invalid", `${TELL_LIMIT_WORDS} ${TELL_LIMIT_HINT}`);
6469 const repo = repoArg(ctx, user, args);
6570 if (isAnswer(repo)) return repo;
71 if (args["issue"] !== undefined) {
72 const n = args["issue"];
73 const found = typeof n === "number" && Number.isInteger(n) && n > 0 ? getIssue(ctx.app.db, repo.id, n) : undefined;
74 if (found === undefined || !mayReadRuns(ctx.app, user, repo)) return bad("not_found", "no such tell");
75 return good({ issue: found.number, ...tellStatusFields(ctx.app.db, repo.id, found) });
76 }
6677 const where = parseContext(args["context"]);
6778 if (where === null)
6879 return bad(
@@ -85,6 +96,7 @@ export const tool: Tool = {
8596 return good({
8697 says: toldWords(told.value),
8798 issue: told.value.issue.number,
99 status: "sent",
88100 page: `${ctx.url.origin}/${repo.ownerName}/${repo.name}/issues/${told.value.issue.number}`,
89101 });
90102 },
src/runs/tell_status.ts +61 −8
@@ -7,14 +7,27 @@
77
88 import type { Database } from "bun:sqlite";
99 import type { Issue } from "../core/issues.ts";
10 import { getPull, pullForBranch, type Pull } from "../core/pulls.ts";
10 import { getPull, openPullsClosing, pullForBranch, type Pull } from "../core/pulls.ts";
1111 import { listRuns, type Run } from "../core/runs.ts";
1212 import { getUsersByIds, type User } from "../core/users.ts";
1313
1414 /** How many runs a reader loads for a tell; more is shown as `N+ runs`. */
1515 export const TELL_RUNS_SHOWN = 10;
1616
17 /** How long a tell may wait for a pickup before it is called stalled. */
18 export const TELL_STALL_MS = 10 * 60_000;
19
20 /** Where a tell stands: said and waiting, taken up, stalled, or over. */
21 export type TellState = "sent" | "picked_up" | "stalled" | "landed" | "closed";
22
1723 export interface TellStatus {
24 readonly state: TellState;
25 /** The run that picked it up (newest), when one did. */
26 readonly run: string | null;
27 /** Milliseconds until a waiting tell counts as stalled; null when it is not waiting. */
28 readonly stallInMs: number | null;
29 /** When that is, as an ISO time that does not move between reads; null when it is not waiting. */
30 readonly stallAt: string | null;
1831 /** The line before the pull number (all of it when there is no pull). */
1932 readonly before: string;
2033 /** The pull it produced, when there is one. */
@@ -39,6 +52,7 @@ export function tellStatus(
3952 runs: readonly Run[],
4053 actors: ReadonlyMap<string, Pick<User, "username">>,
4154 closingPull?: Pull,
55 now: number = Date.now(),
4256 ): TellStatus {
4357 const latest = runs[0];
4458 const pull =
@@ -46,24 +60,44 @@ export function tellStatus(
4660 const who = (latest?.actorId != null && actors.get(latest.actorId)?.username) || "the crew";
4761 let before: string;
4862 let after = "";
63 let state: TellState = "picked_up";
64 let stallInMs: number | null = null;
65 let stallAt: string | null = null;
4966 if (pull !== undefined) {
50 if (pull.mergedAt !== null) before = "Landed in pull ";
51 else if (pull.state === "closed") {
67 if (pull.mergedAt !== null) {
68 before = "Landed in pull ";
69 state = "landed";
70 } else if (pull.state === "closed") {
71 state = "closed";
5272 before = "Pull ";
5373 after = " was closed";
5474 } else {
5575 before = `${latest ? `Picked up by ${who}; ` : ""}pull `;
5676 after = " is open";
5777 }
58 } else if (latest === undefined) {
59 before = issue.state === "closed" ? "Closed without the crew" : "Waiting: nobody has picked it up yet";
60 } else if (latest.state === "queued") before = "Waiting: queued for the crew";
61 else if (latest.state === "running") before = `Picked up by ${who}`;
78 } else if (latest === undefined || latest.state === "queued") {
79 if (issue.state === "closed") {
80 state = "closed";
81 before = "Closed without the crew";
82 } else {
83 const left = Date.parse(issue.createdAt) + TELL_STALL_MS - now;
84 if (left <= 0) {
85 state = "stalled";
86 before = "Stalled: nothing picked it up in 10 minutes";
87 } else {
88 state = "sent";
89 stallInMs = left;
90 stallAt = new Date(Date.parse(issue.createdAt) + TELL_STALL_MS).toISOString();
91 before = latest === undefined ? "Sent: nobody has picked it up yet" : "Sent: queued for the crew";
92 }
93 }
94 } else if (latest.state === "running") before = `Picked up by ${who}`;
6295 else before = `Picked up by ${who}; no pull came of it (${latest.state})`;
6396 const n = runs.length >= TELL_RUNS_SHOWN ? `${TELL_RUNS_SHOWN}+` : String(runs.length);
6497 const count = runs.length > 1 ? ` · ${n} runs` : "";
6598 const num = pull === undefined ? "" : `#${pull.number}`;
66 return { before, pull: pull?.number ?? null, after, count, plain: `${before}${num}${after}${count}` };
99 const run = state === "picked_up" || state === "landed" ? (latest?.id ?? null) : null;
100 return { state, run, stallInMs, stallAt, before, pull: pull?.number ?? null, after, count, plain: `${before}${num}${after}${count}` };
67101 }
68102
69103 /** `tellStatus` with its own reads, for the terminal. */
@@ -73,6 +107,15 @@ export function readTellStatus(db: Database, repoId: string, issue: Issue, closi
73107 return tellStatus(db, repoId, issue, runs, getUsersByIds(db, ids), closingPull);
74108 }
75109
110 /**
111 * `readTellStatus` with the pull that closes (or closed) the tell found too: the one way to read a
112 * tell alone.
113 */
114 export function readTellStatusOf(db: Database, repoId: string, issue: Issue): TellStatus {
115 const closing = issue.state === "closed" ? landedPull(db, repoId, issue) : openPullsClosing(db, repoId).get(issue.number);
116 return readTellStatus(db, repoId, issue, closing);
117 }
118
76119 /**
77120 * The pull whose merge closed a closed tell, from the `issue.closed` event the merge left (the web
78121 * page reads the same record).
@@ -92,3 +135,13 @@ export function landedPull(db: Database, repoId: string, issue: Issue): Pull | u
92135 const n = Number(row?.pull);
93136 return Number.isInteger(n) ? getPull(db, repoId, n) : undefined;
94137 }
138
139 /** What a tell's status says to a program: the same states the page's line shows. */
140 export function tellStatusFields(
141 db: Database,
142 repoId: string,
143 issue: Issue,
144 ): { status: TellState; run: string | null; pull: number | null; says: string } {
145 const s = readTellStatusOf(db, repoId, issue);
146 return { status: s.state, run: s.run, pull: s.pull, says: s.plain };
147 }
src/tui/screens/issue.ts +8 −8
@@ -35,8 +35,7 @@ import { THREAD_SAYS } from "../../actions/thread_words.ts";
3535 import { ISSUE_TEAMS_SAY, nameTeams } from "../../actions/issue_teams.ts";
3636 import { teamsOfIssue, TEAMS_MAX } from "../../core/issue_teams.ts";
3737 import { listTeams } from "../../core/teams.ts";
38 import { landedPull, readTellStatus } from "../../runs/tell_status.ts";
39 import { openPullsClosing } from "../../core/pulls.ts";
38 import { readTellStatusOf, type TellStatus } from "../../runs/tell_status.ts";
4039 import { costLine, issueCostFor, type IssueCost } from "../../core/issue_cost.ts";
4140 import { listRepoRuns, mayReadRuns } from "../../actions/runs.ts";
4241 import { readPlan } from "../../actions/run_plan.ts";
@@ -158,6 +157,12 @@ export function doneText(commits: readonly string[], canClose: boolean): string
158157 return ` · done on main in ${shas}${canClose ? ", x to close" : ""}`;
159158 }
160159
160 /**
161 * The status line; a writer is told the key that assigns a stalled tell (`a`, the existing assign).
162 */
outdated

No test covers this line or the a hint; and the closing-pull lookup below is now duplicated with tellStatusFields. Share one helper.

163 const tellLine = (s: TellStatus, writer: boolean): string =>
164 s.state === "stalled" && writer ? `${s.plain} · a to assign it` : s.plain;
165
161166 export function issueScreen(
162167 f: Session,
163168 ctx: Ctx,
@@ -248,12 +253,7 @@ export function issueScreen(
248253 statusText =
249254 repo === undefined || issueRow === undefined || !mayReadRuns(f.app, f.user, repo)
250255 ? ""
251 : readTellStatus(
252 f.db,
253 repo.id,
254 issueRow,
255 issueRow.state === "closed" ? landedPull(f.db, repo.id, issueRow) : openPullsClosing(f.db, repo.id).get(issueRow.number),
256 ).plain;
256 : tellLine(readTellStatusOf(f.db, repo.id, issueRow), mayWrite());
257257 crew.set(runs !== undefined && runs.ok ? runs.value : []);
258258 plan =
259259 repo === undefined || issueRow === undefined ? undefined : readPlan(f.app, repo, f.user, issueRow);
src/web/client.ts +8
@@ -2500,6 +2500,14 @@ export const liveRegionsJs = /* js */ `
25002500 timer = setTimeout(refresh, Math.max(600, last + MIN_GAP - Date.now()));
25012501 }
25022502 connect();
2503 // A region that changes with the clock, not an event (data-live-at, an
2504 // ISO time, so the page stays the same bytes between visits): looked at
2505 // once when the time comes.
2506 Array.prototype.forEach.call(document.querySelectorAll('[data-live-at]'), function (r) {
2507 var ms = Date.parse(r.getAttribute('data-live-at')) - Date.now() + 1000;
2508 if (!r.id || !(ms > 0) || ms > 2147483647) return;
2509 setTimeout(function () { due[r.id] = true; if (timer === null) timer = setTimeout(refresh, 100); }, ms);
2510 });
25032511 // Back online: reconnect from the last id and look at every region once,
25042512 // in case the replay window no longer reaches back that far.
25052513 window.addEventListener('online', function () {
src/web/studio/tell.ts +17 −3
@@ -516,9 +516,23 @@ async function studioTell(
516516 const statusLine =
517517 status === undefined
518518 ? null
519 : html`<p class="small" data-tell-status>${status.before}${
520 status.pull === null ? null : html`<a href="${changeHref(base, status.pull)}">#${status.pull}</a>`
521 }${status.after}${status.count}</p>`;
519 : html`<p
520 class="small"
521 id="tell-status"
522 data-tell-status
523 data-tell-state="${status.state}"
524 data-live="run.*,pull.*,issue.*"
525 data-live-repo="${repo.ownerName}/${repo.name}"
526 data-live-at="${status.stallAt ?? ""}"
527 >${status.before}${
528 status.pull === null ? null : html`<a href="${changeHref(base, status.pull)}">#${status.pull}</a>`
529 }${status.after}${status.count}${
outdated

Box 2 wants an action that assigns. This only scrolls to the select. Offer a real assign (button in a post form with a same-origin check), or say honestly that it is a jump.

530 status.run === null ? null : html` · <a href="${base}/runs/${status.run}">run</a>`
531 }${
532 status.state === "stalled" && issue.state === "open" && canWrite(db, repo, user)
533 ? html` · <a href="#f-assignee">Pick an assignee below</a>`
534 : null
535 }</p>`;
522536
523537 const marks = marksByName(db, [issue.authorName, issue.assigneeName ?? ""]);
524538 const head = html`<div class="page-head">
test/mcp.test.ts +1 −1
@@ -413,7 +413,7 @@ describe("the forge over MCP", () => {
413413 expect(signup).not.toContain("not redeemed");
414414 expect(signup).toContain("invite lets in only a person with an open invite link");
415415 expect(signup).toContain("closed refuses every new account");
416 expect(byName.get("tell").inputSchema.required).toEqual(["text"]);
416 expect(byName.get("tell").inputSchema.required).toBeUndefined();
417417
418418 expect((await call(rw, "nothing/here")).body.error.code).toBe(-32601);
419419 expect(
test/tell-status.test.ts +118 −11
@@ -15,15 +15,16 @@ import { createApp as createAppRecord } from "../src/core/apps.ts";
1515 import { createApp, type App } from "../src/app.ts";
1616 import type { Issue } from "../src/core/issues.ts";
1717 import { getRepoById, type Repo } from "../src/core/repos.ts";
18 import { createRun } from "../src/core/runs.ts";
18 import { createRun, listRuns } from "../src/core/runs.ts";
1919 import { createSession } from "../src/core/sessions.ts";
2020 import { createUser, type User } from "../src/core/users.ts";
2121 import { serve, type Servers } from "../src/http/server.ts";
22 import { readTellStatus } from "../src/runs/tell_status.ts";
22 import { readTellStatus, tellStatus, TELL_STALL_MS } from "../src/runs/tell_status.ts";
2323 import { createForgeApp } from "../src/tui/forge.ts";
2424 import { issueScreen } from "../src/tui/screens/issue.ts";
2525 import { local } from "../src/tui/screens/where.ts";
2626 import { headlessTerminal } from "../src/tui/term/terminal.ts";
27 import { tokenFor } from "./helpers/tokens.ts";
2728 import { quietLogs } from "./helpers/globals.ts";
2829 import { settleApp } from "./helpers/tui.ts";
2930
@@ -51,7 +52,7 @@ describe("what became of a tell", () => {
5152 headers: { cookie: `forge_session=${createSession(app.db, as.id).token}` },
5253 })
5354 ).text();
54 return /<p class="small" data-tell-status>([\s\S]*?)<\/p>/.exec(html)?.[1]?.replace(/<[^>]+>/g, "") ?? "";
55 return /<p[^>]*data-tell-status[^>]*>([\s\S]*?)<\/p>/.exec(html)?.[1]?.replace(/<[^>]+>/g, "") ?? "";
5556 };
5657
5758 beforeAll(async () => {
@@ -86,15 +87,15 @@ describe("what became of a tell", () => {
8687
8788 test("a tell nobody has picked up is waiting", async () => {
8889 const issue = tell("Water the beds");
89 expect(readTellStatus(app.db, repo.id, issue).plain).toBe("Waiting: nobody has picked it up yet");
90 expect(await line(issue)).toBe("Waiting: nobody has picked it up yet");
90 expect(readTellStatus(app.db, repo.id, issue).plain).toBe("Sent: nobody has picked it up yet");
91 expect(await line(issue)).toBe("Sent: nobody has picked it up yet");
9192 });
9293
9394 test("a running run names who picked it up, and several runs are counted", async () => {
9495 const issue = tell("Prune the roses");
9596 run(issue, "failed");
9697 run(issue, "running");
97 expect(await line(issue)).toBe("Picked up by alice · 2 runs");
98 expect(await line(issue)).toBe("Picked up by alice · 2 runs · run");
9899 });
99100
100101 test("a pull the run produced is linked, and merged reads landed", async () => {
@@ -114,7 +115,7 @@ describe("what became of a tell", () => {
114115 });
115116 if (!p.ok) throw new Error(String(p.error));
116117 run(issue, "ok", "fence");
117 expect(await line(issue)).toBe(`Picked up by alice; pull #${p.value.number} is open`);
118 expect(await line(issue)).toBe(`Picked up by alice; pull #${p.value.number} is open · run`);
118119 const html = await (
119120 await fetch(`${servers.url}/alice/garden/issues/${issue.number}`, { headers: { cookie: cookie() } })
120121 ).text();
@@ -218,8 +219,8 @@ describe("what became of a tell", () => {
218219 if (!o.ok) throw new Error(o.error);
219220 const issue = o.value;
220221 // The owner sees it; the reader who may only read the repository does not.
221 expect(await line(issue, alice, "vault")).toBe("Waiting: nobody has picked it up yet");
222 expect(await screen(alice, vault, issue)).toContain("Waiting: nobody has picked it up yet");
222 expect(await line(issue, alice, "vault")).toBe("Sent: nobody has picked it up yet");
223 expect(await screen(alice, vault, issue)).toContain("Sent: nobody has picked it up yet");
223224 const page = await (
224225 await fetch(`${servers.url}/alice/vault/issues/${issue.number}`, {
225226 headers: { cookie: `forge_session=${createSession(app.db, bob.id).token}` },
@@ -227,7 +228,7 @@ describe("what became of a tell", () => {
227228 ).text();
228229 expect(page).toContain("Seal it");
229230 expect(page).not.toContain("data-tell-status");
230 expect(await screen(bob, vault, issue)).not.toContain("Waiting: nobody");
231 expect(await screen(bob, vault, issue)).not.toContain("Sent: nobody");
231232 // A guest with no session sees none either.
232233 const guest = await (await fetch(`${servers.url}/alice/vault/issues/${issue.number}`)).text();
233234 expect(guest).not.toContain("data-tell-status");
@@ -238,7 +239,113 @@ describe("what became of a tell", () => {
238239 const html = await (
239240 await fetch(`${servers.url}/alice/garden/issues/${issue.number}`, { headers: { cookie: cookie() } })
240241 ).text();
241 const head = /<div class="page-head">[\s\S]*?data-tell-status>/.exec(html)![0];
242 const head = /<div class="page-head">[\s\S]*?data-tell-status\b[^>]*>/.exec(html)![0];
242243 expect((head.match(/<div\b/g) ?? []).length).toBe((head.match(/<\/div>/g) ?? []).length);
243244 });
245
246 test("sent, then picked up with the run linked, then stalled with one action to assign", async () => {
247 const issue = tell("Stake the beans");
248 const t0 = Date.parse(issue.createdAt);
249 const sent = tellStatus(app.db, repo.id, issue, [], new Map(), undefined, t0 + 1000);
250 expect(sent.state).toBe("sent");
251 expect(sent.stallInMs).toBe(TELL_STALL_MS - 1000);
252 const late = tellStatus(app.db, repo.id, issue, [], new Map(), undefined, t0 + TELL_STALL_MS);
253 expect(late.state).toBe("stalled");
254 expect(late.plain).toBe("Stalled: nothing picked it up in 10 minutes");
255 // Nothing picked it up in ten minutes: the page says so and offers to assign.
256 app.db.query("UPDATE issue SET created_at = ?2 WHERE id = ?1").run(issue.id, new Date(t0 - TELL_STALL_MS - 1000).toISOString());
257 let html = await (await fetch(`${servers.url}/alice/garden/issues/${issue.number}`, { headers: { cookie: cookie() } })).text();
258 expect(html).toContain('data-tell-state="stalled"');
259 expect(html).toContain('<a href="#f-assignee">Pick an assignee below</a>');
260 // A run picks it up: the line names who and links the run.
261 run(issue, "running");
262 const id = listRuns(app.db, repo.id, { kind: "agent", issueId: issue.id, limit: 1 })[0]!.id;
263 html = await (await fetch(`${servers.url}/alice/garden/issues/${issue.number}`, { headers: { cookie: cookie() } })).text();
264 expect(html).toContain('data-tell-state="picked_up"');
265 expect(html).toContain(`href="/alice/garden/runs/${id}"`);
266 expect(html).not.toContain("Pick an assignee");
267 });
268
269 test("the MCP tell tool reads the same states by issue", async () => {
270 const issue = tell("Hoe the rows");
271 const call = async (args: unknown) => {
272 const res = await fetch(`${servers.url}/mcp`, {
273 method: "POST",
274 headers: {
275 "content-type": "application/json",
276 accept: "application/json, text/event-stream",
277 authorization: `Bearer ${tokenFor(app, "alice", "rw")}`,
278 },
279 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "tell", arguments: args } }),
280 });
281 const body = (await res.json()) as { result: { isError?: boolean; content: { text: string }[] } };
282 return { error: body.result.isError === true, data: (body.result.isError === true ? {} : JSON.parse(body.result.content[0]!.text)) as Record<string, unknown> };
283 };
284 expect((await call({ repo: "alice/garden", issue: issue.number })).data["status"]).toBe("sent");
285 app.db.query("UPDATE issue SET created_at = ?2 WHERE id = ?1").run(issue.id, new Date(Date.now() - TELL_STALL_MS - 1000).toISOString());
286 expect((await call({ repo: "alice/garden", issue: issue.number })).data["status"]).toBe("stalled");
287 run(issue, "running");
288 const picked = (await call({ repo: "alice/garden", issue: issue.number })).data;
289 expect(picked["status"]).toBe("picked_up");
290 expect(typeof picked["run"]).toBe("string");
291 expect((await call({ repo: "alice/garden", issue: 9999 })).error).toBe(true);
292 });
293 test("a stalled tell: the terminal says Stalled and `a to assign it` to a writer, nothing of the key to a reader", async () => {
294 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "carol", email: "[email protected]", password: "a-good-passphrase" });
295 if (!made.ok) throw new Error(made.error);
296 const carol = made.value;
297 const r = await createRepo(app, alice, { name: "meadow", visibility: "public" });
298 if (!r.ok) throw new Error(String(r.error));
299 const seeded = await commitToBranch(app, alice, r.value, { message: "seed", files: [{ path: "README.md", content: "# meadow\n" }] });
300 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
301 const meadow = getRepoById(app.db, r.value.id)!;
302 const o = openIssue(app, alice, meadow, { title: "Mow it" });
303 if (!o.ok) throw new Error(o.error);
304 const issue = o.value;
305 const page = async (cookieValue?: string) =>
306 (await fetch(`${servers.url}/alice/meadow/issues/${issue.number}`, { headers: cookieValue === undefined ? {} : { cookie: cookieValue } })).text();
307 const asUser = (u: User) => `forge_session=${createSession(app.db, u.id).token}`;
308 // Sent: the clock is in the page as one fixed time, the same bytes on two reads.
309 const at = new Date(Date.parse(issue.createdAt) + TELL_STALL_MS).toISOString();
310 const first = await page(asUser(alice));
311 expect(first).toContain(`data-live-at="${at}"`);
312 expect(await page(asUser(alice))).toBe(first);
313 expect(await screen(alice, meadow, issue)).not.toContain("a to assign it");
314 // Stalled: no clock left, and the action goes to a writer only.
315 app.db.query("UPDATE issue SET created_at = ?2 WHERE id = ?1").run(issue.id, new Date(Date.now() - TELL_STALL_MS - 1000).toISOString());
316 const stalled = await page(asUser(alice));
317 expect(stalled).toContain('data-live-at=""');
318 expect(stalled).toContain("Pick an assignee below");
319 expect(await page(asUser(alice))).toBe(stalled);
320 const seen = await page(asUser(carol));
321 expect(seen).toContain('data-tell-state="stalled"');
322 expect(seen).not.toContain("Pick an assignee");
323 expect(await page()).not.toContain("Pick an assignee");
324 const mine = await screen(alice, meadow, issue);
325 expect(mine).toContain("Stalled");
326 expect(mine).toContain("a to assign it");
327 const theirs = await screen(carol, meadow, issue);
328 expect(theirs).toContain("Stalled");
329 expect(theirs).not.toContain("a to assign it");
330 });
331
332 test("a read-only token may read a tell's status, and still may not tell", async () => {
333 const issue = tell("Prune the vines");
334 const call = async (args: unknown) => {
335 const res = await fetch(`${servers.url}/mcp`, {
336 method: "POST",
337 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${tokenFor(app, "alice", "ro")}` },
338 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "tell", arguments: args } }),
339 });
340 const body = (await res.json()) as { result?: { isError?: boolean; content: { text: string }[] }; error?: unknown };
341 return body.result;
342 };
343 const read = await call({ repo: "alice/garden", issue: issue.number });
344 expect(read?.isError).not.toBe(true);
345 expect(JSON.parse(read!.content[0]!.text).status).toBe("sent");
346 const before = app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM issue").get()!.n;
347 const wrote = await call({ repo: "alice/garden", text: "Water the beans" });
348 expect(wrote?.isError).toBe(true);
349 expect(app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM issue").get()!.n).toBe(before);
350 });
244351 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs