Public: anyone can read this; the crew can change it.
The `map` tool's answer draws a ui://forge/map card: ready now, being worked on, waiting, by pillar #3351
scout/forge:scout/3343-the-map-tool-s-answer-draws-a-ui-forge-m → main 8 commits fork 5 threads · 5 unresolved
5 files
changed +98
−9
docs/MCP.md +5 −3
| @@ -61,7 +61,7 @@ for a tunnel and a forge that sleeps. | ||
| 61 | 61 | | `feed` | `{ limit?, cursor? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed` | | |
| 62 | 62 | | `make_it_yours` | `{ repo, name?, visibility?, dryRun? }`: a fork of an app you can see, as your own app, following the original; code and history copied, data and secrets not; private unless `visibility` is public (a public original only); at most 5 copies an account a day; plans unless `dryRun` is false | yes | |
| 63 | 63 | | `front_page` | `{ pinned?, hidden?, weights?, dryRun? }`: the front page as a stranger sees it, ranked, with numbers; a site admin sets what is pinned (first public one featured), hidden, and what counts (weights of forks, ships, use, fresh, 0 to 10) | yes | |
| 64 | | `map` | an app's plan: ready now, waiting on what, the critical path, where the crew is, parked twice and why (`app`) | | | |
| 64 | | `map` | an app's plan: ready now, waiting on what, the critical path, where the crew is, parked twice and why (`app`); draws the `ui://forge/map` card | | | |
| 65 | 65 | | `milestones` | `{ app, issue? }`: how far each thing asked for is (and, with `issue`, whether you watch it: `watching`), from the dependency tree: the plan's limbs with their weights, or one milestone opened (who is building, what is blocked and on what, what merged in 7 days, an estimate, and for an owner `spend`: dollars, changes landed ever, the costliest three issues) | | |
| 66 | 66 | | `limb` | `{ app, issue, action, reason?, pillar?, operation?, dryRun? }`: defer, resume or close a whole limb as not doing, or undo an operation; plans unless `dryRun` is false, and applying takes an admin token | yes | |
| 67 | 67 | | `watch` | `{ app, issue, watch? }`: watch a milestone, or stop with `watch: false`: one item in your feed that follows it, and one push to your phone when it lands | yes | |
| @@ -178,9 +178,11 @@ answers | ||
| 178 | 178 | |
| 179 | 179 | ## Cards, the contract and the plugins (#1116) |
| 180 | 180 | |
| 181 | - **Cards.** `apps`, `new_app`, `now`, `asks`, `milestones` and `feed` name a `ui://` resource in | |
| 181 | - **Cards.** `apps`, `new_app`, `now`, `asks`, `milestones`, `map` and `feed` name a `ui://` resource in | |
| 182 | 182 | `_meta.ui.resourceUri` (MCP Apps, SEP-1865): `ui://forge/app`, `run`, |
| 183 | `decision`, `wave`, `feed`. `resources/list` and `resources/read` serve one small | |
| 183 | `decision`, `wave`, `map`, `feed`. The Plan card (`map`) shows one row per pillar with | |
| 184 | its ready, working and waiting counts, and the first five ready issues linked | |
| 185 | to their pages; it has no actions. `resources/list` and `resources/read` serve one small | |
| 184 | 186 | sandboxed page, which draws the `structuredContent.card` model that the |
| 185 | 187 | tool result carries, with `textContent` only. The model is built in |
| 186 | 188 | `src/web/studio/cards.ts`. A card's |
src/http/mcp.ts +2 −2
| @@ -710,7 +710,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 710 | 710 | { |
| 711 | 711 | name: "issue", |
| 712 | 712 | description: |
| 713 | "Read one issue: title, state, closeReason, body, labels, assignee, comments (author, agent or not, body, time), `blockedBy`, `blocks`. A crew agent sees `untrusted: true` on text by non-writers, as in the REST API. Sealed or private issues you cannot see are not found.", | |
| 713 | "Read one issue: title, state, closeReason, body, labels, assignee, comments (author, agent?, body, time), `blockedBy`, `blocks`. A crew agent sees `untrusted: true` on text by non-writers, as in REST. Sealed or private issues you cannot see are not found.", | |
| 714 | 714 | inputSchema: { |
| 715 | 715 | type: "object", |
| 716 | 716 | properties: { |
| @@ -2494,7 +2494,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 2494 | 2494 | { |
| 2495 | 2495 | name: "map", |
| 2496 | 2496 | description: |
| 2497 | "An app's plan: open issues as ready or waiting, the critical path, every edge, where the crew is, and `parkedTwice` issues.", | |
| 2497 | "An app's plan: open issues ready or waiting, critical path, every edge, where the crew is, `parkedTwice` issues.", | |
| 2498 | 2498 | inputSchema: { |
| 2499 | 2499 | type: "object", |
| 2500 | 2500 | properties: { app: APP_ARG }, |
src/web/studio/cards.ts +32 −3
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | import { html, raw } from "../html.ts"; |
| 11 | 11 | import { timeAgo } from "../ui.ts"; |
| 12 | 12 | |
| 13 | export type CardKind = "app" | "run" | "decision" | "wave" | "feed"; | |
| 13 | export type CardKind = "app" | "run" | "decision" | "wave" | "map" | "feed"; | |
| 14 | 14 | |
| 15 | 15 | export interface CardRow { |
| 16 | 16 | readonly label: string; |
| @@ -36,7 +36,7 @@ export interface Card { | ||
| 36 | 36 | |
| 37 | 37 | export const CARD_MIME = "text/html;profile=mcp-app"; |
| 38 | 38 | export const CARD_URI = (kind: CardKind): string => `ui://forge/${kind}`; |
| 39 | export const CARD_KINDS: readonly CardKind[] = ["app", "run", "decision", "wave", "feed"]; | |
| 39 | export const CARD_KINDS: readonly CardKind[] = ["app", "run", "decision", "wave", "map", "feed"]; | |
| 40 | 40 | |
| 41 | 41 | /** The tool whose answer each card draws. */ |
| 42 | 42 | export const CARD_OF_TOOL: Readonly<Record<string, CardKind>> = { |
| @@ -44,6 +44,7 @@ export const CARD_OF_TOOL: Readonly<Record<string, CardKind>> = { | ||
| 44 | 44 | now: "run", |
| 45 | 45 | asks: "decision", |
| 46 | 46 | milestones: "wave", |
| 47 | map: "map", | |
| 47 | 48 | feed: "feed", |
| 48 | 49 | new_app: "app", |
| 49 | 50 | }; |
| @@ -53,6 +54,7 @@ const CARD_TITLE: Readonly<Record<CardKind, string>> = { | ||
| 53 | 54 | run: "Working now", |
| 54 | 55 | decision: "Waiting on you", |
| 55 | 56 | wave: "Wave", |
| 57 | map: "Plan", | |
| 56 | 58 | feed: "Feed", |
| 57 | 59 | }; |
| 58 | 60 | |
| @@ -136,6 +138,33 @@ export function cardFor(tool: string, value: unknown, origin = ""): Card | undef | ||
| 136 | 138 | if (repo !== "" && Number.isInteger(number) && number > 0) |
| 137 | 139 | actions.push({ label: "Redirect", tool: "say", args: { repo, number }, words: true }); |
| 138 | 140 | } |
| 141 | } else if (kind === "map") { | |
| 142 | const v = obj(value); | |
| 143 | const ready = list(v["ready"]).map(obj); | |
| 144 | const waiting = list(v["blockedOn"]).length; | |
| 145 | const workingNumbers = new Set(list(v["working"]).map(text)); | |
| 146 | const issues = list(v["issues"]).map(obj); | |
| 147 | const workingNow = issues.filter((i) => i["state"] === "open" && workingNumbers.has(text(i["number"]))).length; | |
Non-blocking: an issue can be both ready and worked on (#3 in the test). The status line then counts it twice, so "6 ready · 2 working" adds up to more than the open issues. Later, either count "working" as its own bucket (ready minus working) or say in docs/MCP.md that the counts overlap. |
||
| 148 | status = `${ready.length} ready · ${workingNow} working · ${waiting} waiting`; | |
| 149 | for (const p of list(v["pillars"]).map(obj).slice(0, LIMIT)) { | |
| 150 | const name = p["pillar"] === null ? "" : text(p["pillar"]); | |
| 151 | const mine = issues.filter((i) => i["state"] === "open" && (i["pillar"] ?? null) === (p["pillar"] ?? null)); | |
| 152 | const working = mine.filter((i) => workingNumbers.has(text(i["number"]))).length; | |
| 153 | rows.push({ | |
| 154 | label: name === "" ? "No pillar" : name, | |
| 155 | value: `${text(p["ready"])} ready · ${working} working · ${text(p["blocked"])} waiting`, | |
| 156 | }); | |
| 157 | } | |
| 158 | const repo = obj(v["repo"]); | |
| 159 | const base = `${origin}/${text(repo["owner"])}/${text(repo["name"])}/issues/`; | |
| 160 | for (const r of ready.slice(0, 5)) { | |
| 161 | const number = text(r["number"]); | |
| 162 | rows.push({ | |
| 163 | label: `#${number}`, | |
| 164 | value: text(r["title"]), | |
| 165 | ...(/^https?:\/\//.test(origin) && number !== "" ? { link: base + number } : {}), | |
| 166 | }); | |
| 167 | } | |
| 139 | 168 | } else if (kind === "feed") { |
| 140 | 169 | const fresh = Number(obj(value)["new"]); |
| 141 | 170 | status = Number.isInteger(fresh) && fresh > 0 ? `${fresh} new since you last looked` : "Latest"; |
| @@ -177,7 +206,7 @@ function draw(card) { | ||
| 177 | 206 | const dl = document.createElement("dl"); |
| 178 | 207 | for (const r of card.rows) { |
| 179 | 208 | const dt = el("dt", r.label); |
| 180 | if (r.link && (r.link.startsWith("https://") || r.link.startsWith("http://"))) { const a = el("a", r.label); a.href = r.link; a.onclick = (ev) => { ev.preventDefault(); parent.postMessage({ jsonrpc: "2.0", id: ++n, method: "ui/open-link", params: { url: r.link } }, "*"); }; dt.replaceChildren(a); } | |
| 209 | if (r.link && (r.link.startsWith("https://") || r.link.startsWith("http://"))) { const a = el("a", r.label); a.href = r.link; a.target = "_blank"; a.rel = "noopener noreferrer"; a.onclick = (ev) => { ev.preventDefault(); parent.postMessage({ jsonrpc: "2.0", id: ++n, method: "ui/open-link", params: { url: r.link } }, "*"); }; dt.replaceChildren(a); } | |
| 181 | 210 | dl.append(dt, el("dd", r.value)); |
| 182 | 211 | } |
| 183 | 212 | root.append(dl); |
test/card-shell.test.ts +57 −1
| @@ -6,12 +6,14 @@ class Node { | ||
| 6 | 6 | textContent = ""; |
| 7 | 7 | className = ""; |
| 8 | 8 | value = ""; |
| 9 | href = ""; | |
| 10 | 9 | onclick: ((ev?: any) => void) | undefined; |
| 11 | 10 | focused = false; |
| 12 | 11 | constructor(readonly tag: string) {} |
| 13 | 12 | append(...n: Node[]) { this.children.push(...n); } |
| 14 | 13 | replaceChildren(...n: Node[]) { this.children = n; } |
| 14 | href = ""; | |
| 15 | target = ""; | |
| 16 | rel = ""; | |
| 15 | 17 | setAttribute() {} |
| 16 | 18 | focus() { this.focused = true; } |
| 17 | 19 | all(): Node[] { return [this, ...this.children.flatMap((c) => c.all())]; } |
| @@ -87,6 +89,60 @@ describe("the card shell", () => { | ||
| 87 | 89 | expect(card.actions.some((a) => a.tool === "say")).toBe(false); |
| 88 | 90 | }); |
| 89 | 91 | |
| 92 | test("the map draws a Plan card: pillars, the first five ready issues, the status line", () => { | |
| 93 | const issue = (number: number, pillar: string | null) => ({ number, title: `T<${number}>`, pillar, state: "open" }); | |
| 94 | const card = cardFor( | |
| 95 | "map", | |
| 96 | { | |
| 97 | repo: { owner: "a", name: "b" }, | |
| 98 | ready: [1, 2, 3, 4, 5, 6].map((n) => issue(n, "P0")), | |
| 99 | blockedOn: [issue(7, "P1"), issue(8, "P1")], | |
| 100 | working: [3, 7, 9], | |
| 101 | issues: [...[1, 2, 3, 4, 5, 6].map((n) => issue(n, "P0")), issue(7, "P1"), issue(8, "P1"), { ...issue(9, "P0"), state: "closed" }], | |
| 102 | pillars: [ | |
| 103 | { pillar: "P0", open: 6, ready: 6, blocked: 0 }, | |
| 104 | { pillar: "P1", open: 2, ready: 0, blocked: 2 }, | |
| 105 | ], | |
| 106 | }, | |
| 107 | "https://f.example", | |
| 108 | )!; | |
| 109 | expect(card.title).toBe("Plan"); | |
| 110 | expect(card.status).toBe("6 ready · 2 working · 2 waiting"); | |
| 111 | expect(card.rows.slice(0, 2)).toEqual([ | |
| 112 | { label: "P0", value: "6 ready · 1 working · 0 waiting" }, | |
| 113 | { label: "P1", value: "0 ready · 1 working · 2 waiting" }, | |
| 114 | ]); | |
| 115 | const ready = card.rows.slice(2); | |
| 116 | expect(ready.length).toBe(5); | |
| 117 | expect(ready[0]).toEqual({ label: "#1", value: "T<1>", link: "https://f.example/a/b/issues/1" }); | |
| 118 | expect(cardFor("map", { ready: [issue(1, null)] }, "javascript:x")!.rows[0]!.link).toBeUndefined(); | |
| 119 | }); | |
| 120 | ||
| 121 | test("a row's https link draws an anchor that asks the host to open it; any other scheme stays text", () => { | |
| 122 | const s = shell(); | |
| 123 | s.send(s.result({ | |
| 124 | kind: "map", title: "Plan", status: "", actions: [], | |
| 125 | rows: [ | |
| 126 | { label: "#1", value: "ok", link: "https://f.example/a/b/issues/1" }, | |
| 127 | { label: "#2", value: "bad", link: "javascript:alert(1)" }, | |
| 128 | ], | |
| 129 | })); | |
| 130 | const dts = s.root.all().filter((n) => n.tag === "dt"); | |
| 131 | expect(dts.length).toBe(2); | |
| 132 | const a = dts[0]!.children[0]!; | |
| 133 | expect(a.tag).toBe("a"); | |
| 134 | expect(a.textContent).toBe("#1"); | |
| 135 | expect(a.href).toBe("https://f.example/a/b/issues/1"); | |
| 136 | expect(a.rel).toBe("noopener noreferrer"); | |
| 137 | let prevented = false; | |
| 138 | a.onclick!({ preventDefault: () => (prevented = true) }); | |
| 139 | expect(prevented).toBe(true); | |
| 140 | expect(s.posted[1]).toMatchObject({ method: "ui/open-link", params: { url: "https://f.example/a/b/issues/1" } }); | |
| 141 | expect(dts[1]!.children.length).toBe(0); | |
| 142 | expect(dts[1]!.textContent).toBe("#2"); | |
| 143 | expect(s.root.all().filter((n) => n.tag === "a").length).toBe(1); | |
| 144 | }); | |
| 145 | ||
| 90 | 146 | test("a feed row with a forge link is an anchor that asks the host to open it; no link, or a javascript: one, stays text", () => { |
| 91 | 147 | const s = shell(); |
| 92 | 148 | const feed = cardFor("feed", { items: [{ what: "x", link: "/a/b/pulls/1" }, { what: "y" }] }, "https://forge.test")!; |
test/mcp.test.ts +2
| @@ -1024,6 +1024,7 @@ describe("the forge over MCP", () => { | ||
| 1024 | 1024 | "ui://forge/app", |
| 1025 | 1025 | "ui://forge/decision", |
| 1026 | 1026 | "ui://forge/feed", |
| 1027 | "ui://forge/map", | |
| 1027 | 1028 | "ui://forge/run", |
| 1028 | 1029 | "ui://forge/wave", |
| 1029 | 1030 | ]); |
| @@ -1041,6 +1042,7 @@ describe("the forge over MCP", () => { | ||
| 1041 | 1042 | expect(meta("now")).toBe("ui://forge/run"); |
| 1042 | 1043 | expect(meta("asks")).toBe("ui://forge/decision"); |
| 1043 | 1044 | expect(meta("milestones")).toBe("ui://forge/wave"); |
| 1045 | expect(meta("map")).toBe("ui://forge/map"); | |
| 1044 | 1046 | expect(meta("feed")).toBe("ui://forge/feed"); |
| 1045 | 1047 | }); |
| 1046 | 1048 |
new above
offline
The status line's working count includes closed issues (
workingNumbers.size), but the pillar rows below count open issues only. Count it from the open issues so the status line and the rows agree.