Public: anyone can read this; the crew can change it.
MCP: a feed_chips tool reads and switches the feed chips (#1877 filters the feed tool without saying so) #1952
scout/forge:scout/1927-mcp-a-feed-chips-tool-reads-and-switches → main 1 commit fork
3 files
changed +79
−4
README.md +1 −1
| @@ -291,7 +291,7 @@ and `forge sync` below is what acts on it. | ||
| 291 | 291 | |
| 292 | 292 | **Muting a repository from the home**: each ask row on the home carries a "Mute owner/name" chip. A muted repository's asks leave the home, `/api/v1/asks`, the header count and the phone's pushes (the same per-user mute the On you card uses, no new table); the home says "N muted repositories still ask" with a "Listen again" button, and an app's own page still counts them. |
| 293 | 293 | |
| 294 | **Chips on the feed**: kind chips switch a kind of post off: `reviews` (pulls), `decisions` (decisions and choose decks), `crew` (tells, replies, looks) and `releases`; a person chip switches one person or agent off. Saved per user, one filter (`chipHides`) behind the home feed, `/api/v1/feed`, the Asks list and the terminal's inbox. `/live/apps` (your apps) is not feed items, so chips do not apply there. `GET /api/v1/feed/chips` answers `{kinds, people}`; `POST /api/v1/feed/chips` takes `{"kind": "kind"|"person", "value": "reviews"|"<username>", "hidden": true|false}` (scope `rw`, same-origin). In the terminal dashboard `1`–`4` switch the kind chips `h` on an On you row switches its author off (not your own) and the author's rows leave the card, and `P` brings every person back. | |
| 294 | **Chips on the feed**: kind chips switch a kind of post off: `reviews` (pulls), `decisions` (decisions and choose decks), `crew` (tells, replies, looks) and `releases`; a person chip switches one person or agent off. Saved per user, one filter (`chipHides`) behind the home feed, `/api/v1/feed`, the Asks list and the terminal's inbox. `/live/apps` (your apps) is not feed items, so chips do not apply there. `GET /api/v1/feed/chips` answers `{kinds, people}`; `POST /api/v1/feed/chips` takes `{"kind": "kind"|"person", "value": "reviews"|"<username>", "hidden": true|false}` (scope `rw`, same-origin). In the terminal dashboard `1`–`4` switch the kind chips `h` on an On you row switches its author off (not your own) and the author's rows leave the card, and `P` brings every person back. The MCP `feed` and `asks` tools answer through the same chips; the `feed_chips` tool reads them (no arguments, any token) and switches one (`kind`, `value`, `hidden`; an `rw` token). | |
| 295 | 295 | |
| 296 | 296 | **On you, in the terminal**, answers to the same mutes and one-move verbs as |
| 297 | 297 | the web card. Repositories you muted are hidden and counted ("2 repositories |
src/http/mcp.ts +45 −3
| @@ -100,7 +100,8 @@ import { | ||
| 100 | 100 | import { plannerDeclines } from "../crew/autonomy.ts"; |
| 101 | 101 | import { listActiveRuns } from "../core/runs.ts"; |
| 102 | 102 | import { scopeAllows } from "../core/tokens.ts"; |
| 103 | import { getUsersByIds, type User } from "../core/users.ts"; | |
| 103 | import { getUserByName, getUsersByIds, type User } from "../core/users.ts"; | |
| 104 | import { chipsOf, isKindChip, setChip } from "../core/feed_chips.ts"; | |
| 104 | 105 | import { openapi } from "../contract/openapi.ts"; |
| 105 | 106 | import { audit } from "../contract/audit.ts"; |
| 106 | 107 | import { probeApp } from "../contract/probes.ts"; |
| @@ -189,6 +190,8 @@ interface Tool { | ||
| 189 | 190 | readonly inputSchema: Record<string, unknown>; |
| 190 | 191 | /** Whether it changes anything: `rw` scope, and said so to the client. */ |
| 191 | 192 | readonly writes: boolean; |
| 193 | /** With this argument absent the tool only reads, whatever the token. */ | |
| 194 | readonly readsWithout?: string; | |
| 192 | 195 | /** A write that only plans (`dryRun` not false) is a read: `ro` may ask. */ |
| 193 | 196 | readonly dryByDefault?: true; |
| 194 | 197 | run(ctx: Ctx, user: User, args: Args): Promise<Answer> | Answer; |
| @@ -1301,7 +1304,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1301 | 1304 | { |
| 1302 | 1305 | name: "feed", |
| 1303 | 1306 | description: |
| 1304 | "Your home timeline, as the forge's home shows it: tells, replies, runs, changes and looks across the apps you can see, ranked, each with who did it, what it says, why it is there and a link to its thing. Pass `cursor` (next_cursor from the last answer) for the next page. The same items as GET /api/v1/feed.", | |
| 1307 | "Your home timeline, as the forge's home shows it: tells, replies, runs, changes and looks across the apps you can see, ranked, each with who did it, what it says, why it is there and a link to its thing. Pass `cursor` (next_cursor from the last answer) for the next page. The same items as GET /api/v1/feed. Your feed chips apply: kinds and people you switched off are left out (see `feed_chips`).", | |
| 1305 | 1308 | inputSchema: { |
| 1306 | 1309 | type: "object", |
| 1307 | 1310 | properties: { |
| @@ -1327,6 +1330,43 @@ const TOOLS: readonly Tool[] = [ | ||
| 1327 | 1330 | ); |
| 1328 | 1331 | }, |
| 1329 | 1332 | }, |
| 1333 | { | |
| 1334 | name: "feed_chips", | |
| 1335 | description: | |
| 1336 | "The feed chips you switched off, which `feed` and `asks` leave out: `{kinds, people}` as GET /api/v1/feed/chips. With `kind` (`kind` or `person`), `value` (a chip: reviews, decisions, crew or releases; or a username) and `hidden` it switches one off (true) or back on (false), and answers the new set. Yours alone.", | |
| 1337 | inputSchema: { | |
| 1338 | type: "object", | |
| 1339 | properties: { | |
| 1340 | kind: { type: "string", enum: ["kind", "person"] }, | |
| 1341 | value: { type: "string", maxLength: 100 }, | |
| 1342 | hidden: { type: "boolean" }, | |
| 1343 | }, | |
| 1344 | }, | |
| 1345 | writes: true, | |
| 1346 | readsWithout: "kind", | |
| 1347 | run(ctx, user, args) { | |
| 1348 | if (args["kind"] !== undefined) { | |
| 1349 | const value = str(args["value"]); | |
| 1350 | const hidden = args["hidden"]; | |
| 1351 | if (typeof hidden !== "boolean") return bad("invalid", "hidden is true or false"); | |
| 1352 | if (args["kind"] === "kind") { | |
| 1353 | if (!isKindChip(value)) return bad("invalid", "that kind has no chip"); | |
| 1354 | setChip(ctx.app.db, user.id, { kind: "kind", value }, hidden); | |
| 1355 | } else if (args["kind"] === "person") { | |
| 1356 | const who = getUserByName(ctx.app.db, value); | |
| 1357 | if (!who || who.kind === "org") return bad("not_found", "no such person"); | |
| 1358 | setChip(ctx.app.db, user.id, { kind: "person", value: who.id }, hidden); | |
| 1359 | } else return bad("invalid", "kind is `kind` or `person`"); | |
| 1360 | } | |
| 1361 | const chips = chipsOf(ctx.app.db, user.id); | |
| 1362 | return good({ | |
| 1363 | kinds: [...chips.kinds].sort(), | |
| 1364 | people: [...getUsersByIds(ctx.app.db, [...chips.people]).values()] | |
| 1365 | .map((u) => u.username) | |
| 1366 | .sort(), | |
| 1367 | }); | |
| 1368 | }, | |
| 1369 | }, | |
| 1330 | 1370 | { |
| 1331 | 1371 | name: "make_it_yours", |
| 1332 | 1372 | description: |
| @@ -2180,7 +2220,9 @@ function rpcOne( | ||
| 2180 | 2220 | typeof params["arguments"] === "object" && params["arguments"] !== null |
| 2181 | 2221 | ? (params["arguments"] as Args) |
| 2182 | 2222 | : {}; |
| 2183 | const plansOnly = tool.dryByDefault === true && args["dryRun"] !== false; | |
| 2223 | const plansOnly = | |
| 2224 | (tool.dryByDefault === true && args["dryRun"] !== false) || | |
| 2225 | (tool.readsWithout !== undefined && args[tool.readsWithout] === undefined); | |
| 2184 | 2226 | if (tool.writes && !plansOnly && !scopeAllows(ctx.auth.scope ?? "ro", "rw")) |
| 2185 | 2227 | return reply({ |
| 2186 | 2228 | content: [ |
test/mcp.test.ts +33
| @@ -190,6 +190,7 @@ describe("the forge over MCP", () => { | ||
| 190 | 190 | "app_members", |
| 191 | 191 | "explore", |
| 192 | 192 | "feed", |
| 193 | "feed_chips", | |
| 193 | 194 | "make_it_yours", |
| 194 | 195 | "front_page", |
| 195 | 196 | "map", |
| @@ -716,4 +717,36 @@ describe("the forge over MCP", () => { | ||
| 716 | 717 | expect(doc.openapi).toBe("3.1.0"); |
| 717 | 718 | expect(doc.paths["/mcp"].post).toBeDefined(); |
| 718 | 719 | }); |
| 720 | test("feed_chips reads and switches the chips the feed answers through", async () => { | |
| 721 | app.bus.append({ kind: "app.serving", repoId: game.id, actorId: alice.id, payload: {} }); | |
| 722 | const kinds = async () => { | |
| 723 | const r = await tool(rw, "feed", { limit: 50 }); | |
| 724 | return (r.value.items as { kind: string }[]).map((i) => i.kind); | |
| 725 | }; | |
| 726 | const api = async () => { | |
| 727 | const res = await fetch(`${base}/api/v1/feed?limit=50`, { headers: { authorization: `Bearer ${rw}` } }); | |
| 728 | return ((await res.json()) as { items: { kind: string }[] }).items.map((i) => i.kind); | |
| 729 | }; | |
| 730 | expect(await kinds()).toContain("release"); | |
| 731 | expect((await tool(rw, "feed_chips")).value).toEqual({ kinds: [], people: [] }); | |
| 732 | ||
| 733 | const set = await tool(rw, "feed_chips", { kind: "kind", value: "releases", hidden: true }); | |
| 734 | expect(set.value).toEqual({ kinds: ["releases"], people: [] }); | |
| 735 | expect(await kinds()).not.toContain("release"); | |
| 736 | expect(await api()).not.toContain("release"); | |
| 737 | // A read-only token may read the chips, not switch them. | |
| 738 | expect((await tool(ro, "feed_chips")).value).toEqual({ kinds: ["releases"], people: [] }); | |
| 739 | expect((await tool(ro, "feed_chips", { kind: "kind", value: "releases", hidden: false })).error).toContain("forbidden"); | |
| 740 | expect((await tool(rw, "feed_chips")).value.kinds).toEqual(["releases"]); | |
| 741 | ||
| 742 | expect((await tool(rw, "feed_chips", { kind: "kind", value: "nope", hidden: true })).error).toBeDefined(); | |
| 743 | expect((await tool(rw, "feed_chips", { kind: "person", value: "nobody", hidden: true })).error).toBeDefined(); | |
| 744 | expect((await tool(rw, "feed_chips", { kind: "kind", value: "crew" })).error).toBeDefined(); | |
| 745 | const person = await tool(rw, "feed_chips", { kind: "person", value: "bob", hidden: true }); | |
| 746 | expect(person.value).toEqual({ kinds: ["releases"], people: ["bob"] }); | |
| 747 | await tool(rw, "feed_chips", { kind: "person", value: "bob", hidden: false }); | |
| 748 | const back = await tool(rw, "feed_chips", { kind: "kind", value: "releases", hidden: false }); | |
| 749 | expect(back.value).toEqual({ kinds: [], people: [] }); | |
| 750 | expect(await kinds()).toContain("release"); | |
| 751 | }); | |
| 719 | 752 | }); |
new above
offline