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

Closed opened this
Closed without merging

scout/forge:scout/3343-the-map-tool-s-answer-draws-a-ui-forge-m → main 8 commits fork 5 threads · 5 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +98 −9
docs/MCP.md +5 −3
@@ -61,7 +61,7 @@ for a tunnel and a forge that sleeps.
6161 | `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` | |
6262 | `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 |
6363 | `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 | |
6565 | `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) | |
6666 | `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 |
6767 | `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
178178
179179 ## Cards, the contract and the plugins (#1116)
180180
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
182182 `_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
184186 sandboxed page, which draws the `structuredContent.card` model that the
185187 tool result carries, with `textContent` only. The model is built in
186188 `src/web/studio/cards.ts`. A card's
src/http/mcp.ts +2 −2
@@ -710,7 +710,7 @@ const TOOLS: readonly Tool[] = [
710710 {
711711 name: "issue",
712712 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.",
714714 inputSchema: {
715715 type: "object",
716716 properties: {
@@ -2494,7 +2494,7 @@ const TOOLS: readonly Tool[] = [
24942494 {
24952495 name: "map",
24962496 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.",
24982498 inputSchema: {
24992499 type: "object",
25002500 properties: { app: APP_ARG },
src/web/studio/cards.ts +32 −3
@@ -10,7 +10,7 @@
1010 import { html, raw } from "../html.ts";
1111 import { timeAgo } from "../ui.ts";
1212
13 export type CardKind = "app" | "run" | "decision" | "wave" | "feed";
13 export type CardKind = "app" | "run" | "decision" | "wave" | "map" | "feed";
1414
1515 export interface CardRow {
1616 readonly label: string;
@@ -36,7 +36,7 @@ export interface Card {
3636
3737 export const CARD_MIME = "text/html;profile=mcp-app";
3838 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"];
4040
4141 /** The tool whose answer each card draws. */
4242 export const CARD_OF_TOOL: Readonly<Record<string, CardKind>> = {
@@ -44,6 +44,7 @@ export const CARD_OF_TOOL: Readonly<Record<string, CardKind>> = {
4444 now: "run",
4545 asks: "decision",
4646 milestones: "wave",
47 map: "map",
4748 feed: "feed",
4849 new_app: "app",
4950 };
@@ -53,6 +54,7 @@ const CARD_TITLE: Readonly<Record<CardKind, string>> = {
5354 run: "Working now",
5455 decision: "Waiting on you",
5556 wave: "Wave",
57 map: "Plan",
5658 feed: "Feed",
5759 };
5860
@@ -136,6 +138,33 @@ export function cardFor(tool: string, value: unknown, origin = ""): Card | undef
136138 if (repo !== "" && Number.isInteger(number) && number > 0)
137139 actions.push({ label: "Redirect", tool: "say", args: { repo, number }, words: true });
138140 }
141 } else if (kind === "map") {
142 const v = obj(value);
143 const ready = list(v["ready"]).map(obj);
outdated

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.

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 }
139168 } else if (kind === "feed") {
140169 const fresh = Number(obj(value)["new"]);
141170 status = Number.isInteger(fresh) && fresh > 0 ? `${fresh} new since you last looked` : "Latest";
@@ -177,7 +206,7 @@ function draw(card) {
177206 const dl = document.createElement("dl");
178207 for (const r of card.rows) {
179208 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); }
181210 dl.append(dt, el("dd", r.value));
182211 }
183212 root.append(dl);
test/card-shell.test.ts +57 −1
@@ -6,12 +6,14 @@ class Node {
66 textContent = "";
77 className = "";
88 value = "";
9 href = "";
109 onclick: ((ev?: any) => void) | undefined;
1110 focused = false;
1211 constructor(readonly tag: string) {}
1312 append(...n: Node[]) { this.children.push(...n); }
1413 replaceChildren(...n: Node[]) { this.children = n; }
14 href = "";
15 target = "";
16 rel = "";
1517 setAttribute() {}
1618 focus() { this.focused = true; }
1719 all(): Node[] { return [this, ...this.children.flatMap((c) => c.all())]; }
@@ -87,6 +89,60 @@ describe("the card shell", () => {
8789 expect(card.actions.some((a) => a.tool === "say")).toBe(false);
8890 });
8991
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
90146 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", () => {
91147 const s = shell();
92148 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", () => {
10241024 "ui://forge/app",
10251025 "ui://forge/decision",
10261026 "ui://forge/feed",
1027 "ui://forge/map",
10271028 "ui://forge/run",
10281029 "ui://forge/wave",
10291030 ]);
@@ -1041,6 +1042,7 @@ describe("the forge over MCP", () => {
10411042 expect(meta("now")).toBe("ui://forge/run");
10421043 expect(meta("asks")).toBe("ui://forge/decision");
10431044 expect(meta("milestones")).toBe("ui://forge/wave");
1045 expect(meta("map")).toBe("ui://forge/map");
10441046 expect(meta("feed")).toBe("ui://forge/feed");
10451047 });
10461048

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs