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

Parked opened this
Closed without merging

scout/forge:scout/1927-mcp-a-feed-chips-tool-reads-and-switches → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +79 −4
README.md +1 −1
@@ -291,7 +291,7 @@ and `forge sync` below is what acts on it.
291291
292292 **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.
293293
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).
295295
296296 **On you, in the terminal**, answers to the same mutes and one-move verbs as
297297 the web card. Repositories you muted are hidden and counted ("2 repositories
src/http/mcp.ts +45 −3
@@ -100,7 +100,8 @@ import {
100100 import { plannerDeclines } from "../crew/autonomy.ts";
101101 import { listActiveRuns } from "../core/runs.ts";
102102 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";
104105 import { openapi } from "../contract/openapi.ts";
105106 import { audit } from "../contract/audit.ts";
106107 import { probeApp } from "../contract/probes.ts";
@@ -189,6 +190,8 @@ interface Tool {
189190 readonly inputSchema: Record<string, unknown>;
190191 /** Whether it changes anything: `rw` scope, and said so to the client. */
191192 readonly writes: boolean;
193 /** With this argument absent the tool only reads, whatever the token. */
194 readonly readsWithout?: string;
192195 /** A write that only plans (`dryRun` not false) is a read: `ro` may ask. */
193196 readonly dryByDefault?: true;
194197 run(ctx: Ctx, user: User, args: Args): Promise<Answer> | Answer;
@@ -1301,7 +1304,7 @@ const TOOLS: readonly Tool[] = [
13011304 {
13021305 name: "feed",
13031306 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`).",
13051308 inputSchema: {
13061309 type: "object",
13071310 properties: {
@@ -1327,6 +1330,43 @@ const TOOLS: readonly Tool[] = [
13271330 );
13281331 },
13291332 },
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 },
13301370 {
13311371 name: "make_it_yours",
13321372 description:
@@ -2180,7 +2220,9 @@ function rpcOne(
21802220 typeof params["arguments"] === "object" && params["arguments"] !== null
21812221 ? (params["arguments"] as Args)
21822222 : {};
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);
21842226 if (tool.writes && !plansOnly && !scopeAllows(ctx.auth.scope ?? "ro", "rw"))
21852227 return reply({
21862228 content: [
test/mcp.test.ts +33
@@ -190,6 +190,7 @@ describe("the forge over MCP", () => {
190190 "app_members",
191191 "explore",
192192 "feed",
193 "feed_chips",
193194 "make_it_yours",
194195 "front_page",
195196 "map",
@@ -716,4 +717,36 @@ describe("the forge over MCP", () => {
716717 expect(doc.openapi).toBe("3.1.0");
717718 expect(doc.paths["/mcp"].post).toBeDefined();
718719 });
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 });
719752 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs