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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14161-a-tell-s-receipt-names-the-run-that-pick → main 9 commits fork 3 threads · 3 unresolved
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`; | ||
| 232 | 232 | | `teams` | — | Crew teams for person admins: charter, dial (0–100) and member agents | 338 | |
| 233 | 233 | | `telemetry_grant` | — | Grant an agent telemetry:read, or `on: false` takes it back | 226 | |
| 234 | 234 | | `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 | | |
| 236 | 236 | | `templates` | — | The templates a child forge may start from | 164 | |
| 237 | 237 | | `thought` | — | Where a thought went, by its id (from `tell` without a repo) | 220 | |
| 238 | 238 | | `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 @@ | ||
| 2 | 2 | |
| 3 | 3 | The head of a tell's page (and the terminal's issue screen, in its summary row) carries one line: |
| 4 | 4 | |
| 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) | |
| 6 | 6 | - `Picked up by <crew member>` while a run is going, or `…; no pull came of it (<state>)` |
| 7 | 7 | - `…pull #N is open` and `Landed in pull #N`, with the pull linked on the page |
| 8 | 8 | |
| 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 | ||
| 9 | 11 | A tell with several agent runs shows the latest and `· N runs`. |
| 10 | 12 | |
| 11 | 13 | - **Where it comes from.** `tellStatus` (`src/runs/tell_status.ts`) reads the `run` rows of the issue and |
| 12 | 14 | the pull that closes it or that the latest run's branch opened. No table of its own. |
| 13 | 15 | - **Who sees it.** Those who may read the app's runs (`mayReadRuns`); a private app's tells show it to nobody else. |
| 14 | 16 | - 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"; | ||
| 5 | 5 | import { overTellLimit, parseFrom, TELL_LIMIT_HINT, TELL_LIMIT_WORDS } 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 { mayReadRuns } from "../../../actions/runs.ts"; | |
| 9 | import { getIssue } from "../../../core/issues.ts"; | |
| 10 | import { tellStatusFields } from "../../../runs/tell_status.ts"; | |
| 8 | 11 | import { good, bad, type Tool, str, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| 9 | 12 | |
| 10 | 13 | export const tool: Tool = { |
| 11 | 14 | 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)", | |
| 13 | 16 | 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", | |
| 15 | 18 | inputSchema: { |
| 16 | 19 | type: "object", |
| 17 | 20 | properties: { |
| 18 | 21 | repo: REPO_ARG, |
| 22 | issue: { type: "integer" }, | |
| 19 | 23 | text: { type: "string", maxLength: 4000 }, |
| 20 | 24 | from: { |
| 21 | 25 | type: "string", |
| 22 | 26 | maxLength: 512, |
| 23 | description: | |
| 24 | "Forge path to link, as /a/b/pulls/3.", | |
| 27 | description: "Path /a/b/pulls/3", | |
| 25 | 28 | }, |
| 26 | 29 | context: { |
| 27 | 30 | type: "object", |
| @@ -34,9 +37,11 @@ export const tool: Tool = { | ||
| 34 | 37 | }, |
| 35 | 38 | }, |
| 36 | 39 | }, |
| 37 | required: ["text"], | |
| 38 | 40 | }, |
| 39 | 41 | 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, | |
| 40 | 45 | async run(ctx, user, args) { |
| 41 | 46 | if (args["repo"] === undefined || args["repo"] === null) { |
| 42 | 47 | // 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 = { | ||
| 63 | 68 | return bad("invalid", `${TELL_LIMIT_WORDS} ${TELL_LIMIT_HINT}`); |
| 64 | 69 | const repo = repoArg(ctx, user, args); |
| 65 | 70 | 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 | } | |
| 66 | 77 | const where = parseContext(args["context"]); |
| 67 | 78 | if (where === null) |
| 68 | 79 | return bad( |
| @@ -85,6 +96,7 @@ export const tool: Tool = { | ||
| 85 | 96 | return good({ |
| 86 | 97 | says: toldWords(told.value), |
| 87 | 98 | issue: told.value.issue.number, |
| 99 | status: "sent", | |
| 88 | 100 | page: `${ctx.url.origin}/${repo.ownerName}/${repo.name}/issues/${told.value.issue.number}`, |
| 89 | 101 | }); |
| 90 | 102 | }, |
src/runs/tell_status.ts +61 −8
| @@ -7,14 +7,27 @@ | ||
| 7 | 7 | |
| 8 | 8 | import type { Database } from "bun:sqlite"; |
| 9 | 9 | 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"; | |
| 11 | 11 | import { listRuns, type Run } from "../core/runs.ts"; |
| 12 | 12 | import { getUsersByIds, type User } from "../core/users.ts"; |
| 13 | 13 | |
| 14 | 14 | /** How many runs a reader loads for a tell; more is shown as `N+ runs`. */ |
| 15 | 15 | export const TELL_RUNS_SHOWN = 10; |
| 16 | 16 | |
| 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 | ||
| 17 | 23 | 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; | |
| 18 | 31 | /** The line before the pull number (all of it when there is no pull). */ |
| 19 | 32 | readonly before: string; |
| 20 | 33 | /** The pull it produced, when there is one. */ |
| @@ -39,6 +52,7 @@ export function tellStatus( | ||
| 39 | 52 | runs: readonly Run[], |
| 40 | 53 | actors: ReadonlyMap<string, Pick<User, "username">>, |
| 41 | 54 | closingPull?: Pull, |
| 55 | now: number = Date.now(), | |
| 42 | 56 | ): TellStatus { |
| 43 | 57 | const latest = runs[0]; |
| 44 | 58 | const pull = |
| @@ -46,24 +60,44 @@ export function tellStatus( | ||
| 46 | 60 | const who = (latest?.actorId != null && actors.get(latest.actorId)?.username) || "the crew"; |
| 47 | 61 | let before: string; |
| 48 | 62 | let after = ""; |
| 63 | let state: TellState = "picked_up"; | |
| 64 | let stallInMs: number | null = null; | |
| 65 | let stallAt: string | null = null; | |
| 49 | 66 | 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"; | |
| 52 | 72 | before = "Pull "; |
| 53 | 73 | after = " was closed"; |
| 54 | 74 | } else { |
| 55 | 75 | before = `${latest ? `Picked up by ${who}; ` : ""}pull `; |
| 56 | 76 | after = " is open"; |
| 57 | 77 | } |
| 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}`; | |
| 62 | 95 | else before = `Picked up by ${who}; no pull came of it (${latest.state})`; |
| 63 | 96 | const n = runs.length >= TELL_RUNS_SHOWN ? `${TELL_RUNS_SHOWN}+` : String(runs.length); |
| 64 | 97 | const count = runs.length > 1 ? ` · ${n} runs` : ""; |
| 65 | 98 | 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}` }; | |
| 67 | 101 | } |
| 68 | 102 | |
| 69 | 103 | /** `tellStatus` with its own reads, for the terminal. */ |
| @@ -73,6 +107,15 @@ export function readTellStatus(db: Database, repoId: string, issue: Issue, closi | ||
| 73 | 107 | return tellStatus(db, repoId, issue, runs, getUsersByIds(db, ids), closingPull); |
| 74 | 108 | } |
| 75 | 109 | |
| 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 | ||
| 76 | 119 | /** |
| 77 | 120 | * The pull whose merge closed a closed tell, from the `issue.closed` event the merge left (the web |
| 78 | 121 | * page reads the same record). |
| @@ -92,3 +135,13 @@ export function landedPull(db: Database, repoId: string, issue: Issue): Pull | u | ||
| 92 | 135 | const n = Number(row?.pull); |
| 93 | 136 | return Number.isInteger(n) ? getPull(db, repoId, n) : undefined; |
| 94 | 137 | } |
| 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"; | ||
| 35 | 35 | import { ISSUE_TEAMS_SAY, nameTeams } from "../../actions/issue_teams.ts"; |
| 36 | 36 | import { teamsOfIssue, TEAMS_MAX } from "../../core/issue_teams.ts"; |
| 37 | 37 | 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"; | |
| 40 | 39 | import { costLine, issueCostFor, type IssueCost } from "../../core/issue_cost.ts"; |
| 41 | 40 | import { listRepoRuns, mayReadRuns } from "../../actions/runs.ts"; |
| 42 | 41 | import { readPlan } from "../../actions/run_plan.ts"; |
| @@ -158,6 +157,12 @@ export function doneText(commits: readonly string[], canClose: boolean): string | ||
| 158 | 157 | return ` · done on main in ${shas}${canClose ? ", x to close" : ""}`; |
| 159 | 158 | } |
| 160 | 159 | |
| 160 | /** | |
| 161 | * The status line; a writer is told the key that assigns a stalled tell (`a`, the existing assign). | |
| 162 | */ | |
| 163 | const tellLine = (s: TellStatus, writer: boolean): string => | |
| 164 | s.state === "stalled" && writer ? `${s.plain} · a to assign it` : s.plain; | |
| 165 | ||
| 161 | 166 | export function issueScreen( |
| 162 | 167 | f: Session, |
| 163 | 168 | ctx: Ctx, |
| @@ -248,12 +253,7 @@ export function issueScreen( | ||
| 248 | 253 | statusText = |
| 249 | 254 | repo === undefined || issueRow === undefined || !mayReadRuns(f.app, f.user, repo) |
| 250 | 255 | ? "" |
| 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()); | |
| 257 | 257 | crew.set(runs !== undefined && runs.ok ? runs.value : []); |
| 258 | 258 | plan = |
| 259 | 259 | 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 */ ` | ||
| 2500 | 2500 | timer = setTimeout(refresh, Math.max(600, last + MIN_GAP - Date.now())); |
| 2501 | 2501 | } |
| 2502 | 2502 | 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 | }); | |
| 2503 | 2511 | // Back online: reconnect from the last id and look at every region once, |
| 2504 | 2512 | // in case the replay window no longer reaches back that far. |
| 2505 | 2513 | window.addEventListener('online', function () { |
src/web/studio/tell.ts +17 −3
| @@ -516,9 +516,23 @@ async function studioTell( | ||
| 516 | 516 | const statusLine = |
| 517 | 517 | status === undefined |
| 518 | 518 | ? 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>`; | |
| 522 | 536 | |
| 523 | 537 | const marks = marksByName(db, [issue.authorName, issue.assigneeName ?? ""]); |
| 524 | 538 | const head = html`<div class="page-head"> |
test/mcp.test.ts +1 −1
| @@ -413,7 +413,7 @@ describe("the forge over MCP", () => { | ||
| 413 | 413 | expect(signup).not.toContain("not redeemed"); |
| 414 | 414 | expect(signup).toContain("invite lets in only a person with an open invite link"); |
| 415 | 415 | 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(); | |
| 417 | 417 | |
| 418 | 418 | expect((await call(rw, "nothing/here")).body.error.code).toBe(-32601); |
| 419 | 419 | expect( |
test/tell-status.test.ts +118 −11
| @@ -15,15 +15,16 @@ import { createApp as createAppRecord } from "../src/core/apps.ts"; | ||
| 15 | 15 | import { createApp, type App } from "../src/app.ts"; |
| 16 | 16 | import type { Issue } from "../src/core/issues.ts"; |
| 17 | 17 | 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"; | |
| 19 | 19 | import { createSession } from "../src/core/sessions.ts"; |
| 20 | 20 | import { createUser, type User } from "../src/core/users.ts"; |
| 21 | 21 | 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"; | |
| 23 | 23 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 24 | 24 | import { issueScreen } from "../src/tui/screens/issue.ts"; |
| 25 | 25 | import { local } from "../src/tui/screens/where.ts"; |
| 26 | 26 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 27 | import { tokenFor } from "./helpers/tokens.ts"; | |
| 27 | 28 | import { quietLogs } from "./helpers/globals.ts"; |
| 28 | 29 | import { settleApp } from "./helpers/tui.ts"; |
| 29 | 30 | |
| @@ -51,7 +52,7 @@ describe("what became of a tell", () => { | ||
| 51 | 52 | headers: { cookie: `forge_session=${createSession(app.db, as.id).token}` }, |
| 52 | 53 | }) |
| 53 | 54 | ).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, "") ?? ""; | |
| 55 | 56 | }; |
| 56 | 57 | |
| 57 | 58 | beforeAll(async () => { |
| @@ -86,15 +87,15 @@ describe("what became of a tell", () => { | ||
| 86 | 87 | |
| 87 | 88 | test("a tell nobody has picked up is waiting", async () => { |
| 88 | 89 | 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"); | |
| 91 | 92 | }); |
| 92 | 93 | |
| 93 | 94 | test("a running run names who picked it up, and several runs are counted", async () => { |
| 94 | 95 | const issue = tell("Prune the roses"); |
| 95 | 96 | run(issue, "failed"); |
| 96 | 97 | 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"); | |
| 98 | 99 | }); |
| 99 | 100 | |
| 100 | 101 | test("a pull the run produced is linked, and merged reads landed", async () => { |
| @@ -114,7 +115,7 @@ describe("what became of a tell", () => { | ||
| 114 | 115 | }); |
| 115 | 116 | if (!p.ok) throw new Error(String(p.error)); |
| 116 | 117 | 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`); | |
| 118 | 119 | const html = await ( |
| 119 | 120 | await fetch(`${servers.url}/alice/garden/issues/${issue.number}`, { headers: { cookie: cookie() } }) |
| 120 | 121 | ).text(); |
| @@ -218,8 +219,8 @@ describe("what became of a tell", () => { | ||
| 218 | 219 | if (!o.ok) throw new Error(o.error); |
| 219 | 220 | const issue = o.value; |
| 220 | 221 | // 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"); | |
| 223 | 224 | const page = await ( |
| 224 | 225 | await fetch(`${servers.url}/alice/vault/issues/${issue.number}`, { |
| 225 | 226 | headers: { cookie: `forge_session=${createSession(app.db, bob.id).token}` }, |
| @@ -227,7 +228,7 @@ describe("what became of a tell", () => { | ||
| 227 | 228 | ).text(); |
| 228 | 229 | expect(page).toContain("Seal it"); |
| 229 | 230 | 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"); | |
| 231 | 232 | // A guest with no session sees none either. |
| 232 | 233 | const guest = await (await fetch(`${servers.url}/alice/vault/issues/${issue.number}`)).text(); |
| 233 | 234 | expect(guest).not.toContain("data-tell-status"); |
| @@ -238,7 +239,113 @@ describe("what became of a tell", () => { | ||
| 238 | 239 | const html = await ( |
| 239 | 240 | await fetch(`${servers.url}/alice/garden/issues/${issue.number}`, { headers: { cookie: cookie() } }) |
| 240 | 241 | ).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]; | |
| 242 | 243 | expect((head.match(/<div\b/g) ?? []).length).toBe((head.match(/<\/div>/g) ?? []).length); |
| 243 | 244 | }); |
| 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 | }); | |
| 244 | 351 | }); |
new above
offline
No test covers this line or the
ahint; and the closing-pull lookup below is now duplicated withtellStatusFields. Share one helper.