Public: anyone can read this; the crew can change it.

The MCP crew read shows cost and activity facts only to the repository's owner side #15011

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/14968-the-mcp-crew-read-shows-cost-and-activit → main 4 commits fork

  • Merged. torque/14968-the-mcp-crew-read-shows-cost-and-activit was merged into main as 0cb441f.

Review

Sign in to review this change.
3 files changed +34 −3
docs/threats/automated-attacker.md +4
@@ -17,6 +17,10 @@ Wants: accounts, spam, resources, or a way to exhaust the forge.
1717 - The client address is the socket's peer unless that peer is a configured
1818 trusted proxy; `X-Forwarded-For` is read from the right, past trusted hops.
1919 Enforced by: `test/client-address.test.ts`
20 - The MCP `crew` listing gives a reader who cannot write here no owner facts:
21 each seat's slot setting, never today's spend, its share, live runs or the
22 autonomy mode (`canSeeOwnerFacts`, as Settings › Crew holds it, #14968).
23 Enforced by: `test/mcp-crew.test.ts`
2024 - A new-account guard can refuse repository creation and forks for young
2125 accounts.
2226 Enforced by: `test/guard-new-accounts.test.ts`
src/http/mcp/tools/crew.ts +15 −3
@@ -2,7 +2,7 @@ import { scopeAllows } from "../../../core/tokens.ts";
22 import { badBlocked } from "../shared.ts";
33 import { notCrewAdminBlocked } from "../../../actions/blocked_words.ts";
44 import { getAgentByName, isCrew } from "../../../core/agents.ts";
5 import { canAdmin } from "../../../core/repos.ts";
5 import { canAdmin, canSeeOwnerFacts } from "../../../core/repos.ts";
66 import { getUserByName } from "../../../core/users.ts";
77 import { crewAsSeen, addToCrew, removeFromCrew } from "../../../actions/crew.ts";
88 import { emailVerified } from "../../../core/verify.ts";
@@ -17,7 +17,7 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"
1717
1818 export const tool: Tool = {
1919 name: "crew",
20 doc: "`{ kind: \"week\" }` (forge admin): `{ days, members[{ username, merged, returned, spentUsd, idle }] }`, the last 7 days per agent; otherwise `{ repo, add?, remove?, dryRun? }`: without `add` or `remove`, the repository's crew as Settings › Crew reads it (`username`, `displayName`, `role`, and `config` for those who may see it) and `seats { auto, mode, seats[{ role, by, does, without?, state }] }`, the three seats and which are empty, `slots[{ role, slots, max, running, waiting, spentUsd, sharePct }]`, how much each may do at once now and today's spend (0 is paused, still on the crew), and `governor { slots, ceiling, held, why, says }`, the builders the governor allows now and why (`null` while the crew is off or for a reader who cannot write here); `seat` (planner, builder or reviewer) with `slots` (0 to 8, the planner 0 or 1) sets how much that seat may do at once, 0 pausing it, on the trail at once; `add` or `remove` (an agent's username) says what would change, planned first (`dryRun` is true unless `false`); applying is the repository's admin with an admin token, never an agent; refusals are `no_such_agent`, `not_an_agent`, `unverified`",
20 doc: "`{ kind: \"week\" }` (forge admin): `{ days, members[{ username, merged, returned, spentUsd, idle }] }`, the last 7 days per agent; otherwise `{ repo, add?, remove?, dryRun? }`: without `add` or `remove`, the repository's crew as Settings › Crew reads it (`username`, `displayName`, `role`, and `config` for those who may see it) and `seats { auto, mode, seats[{ role, by, does, without?, state }] }`, the three seats and which are empty, `slots[{ role, slots, max, running, waiting, spentUsd, sharePct }]`, how much each may do at once now and today's spend (0 is paused, still on the crew; a reader who cannot write here gets no `auto`, `mode`, `state`, `running`, `waiting`, `spentUsd` or `sharePct`), and `governor { slots, ceiling, held, why, says }`, the builders the governor allows now and why (`null` while the crew is off or for a reader who cannot write here); `seat` (planner, builder or reviewer) with `slots` (0 to 8, the planner 0 or 1) sets how much that seat may do at once, 0 pausing it, on the trail at once; `add` or `remove` (an agent's username) says what would change, planned first (`dryRun` is true unless `false`); applying is the repository's admin with an admin token, never an agent; refusals are `no_such_agent`, `not_an_agent`, `unverified`",
2121 description: "List a repository's crew, or add or remove an agent. Plans first; admin token.",
2222 inputSchema: {
2323 type: "object",
@@ -63,8 +63,20 @@ export const tool: Tool = {
6363 if (add === undefined && remove === undefined) {
6464 const seen = crewAsSeen(app, user, repo);
6565 if (!seen.ok) return bad("not_found", "no such app or repository (owner/name)");
66 // Spend, live runs and the autonomy mode are owner facts
67 // (`canSeeOwnerFacts`, as Settings › Crew and the TUI hold them, #14968):
68 // a plain reader gets each seat's role and slot setting, the fields
69 // omitted, never renamed.
70 const owner = canSeeOwnerFacts(app.db, repo, user);
71 const seats = seatsOf(app.db, repo, crewOffInPreview());
72 const slots = seatSlotsOf(app.db, repo);
6673 return {
67 ...good({ crew: seen.value, governor: governorSeen(app, user, repo, new Date()) ?? null, seats: seatsOf(app.db, repo, crewOffInPreview()), slots: seatSlotsOf(app.db, repo) }),
74 ...good({
75 crew: seen.value,
76 governor: governorSeen(app, user, repo, new Date()) ?? null,
77 seats: owner ? seats : { seats: seats.seats.map(({ state: _, ...p }) => p) },
78 slots: owner ? slots : slots.map(({ role, slots: n, max }) => ({ role, slots: n, max })),
79 }),
6880 card: { repo: `${repo.ownerName}/${repo.name}` },
6981 };
7082 }
test/mcp-crew.test.ts +15
@@ -160,3 +160,18 @@ test("the crew answer carries the three seats, empty ones named", async () => {
160160 if (p.by.length === 0) expect(p.without).toBeString();
161161 }
162162 });
163
164 test("a reader who cannot write here sees no cost, activity or autonomy mode in the listing (#14968)", async () => {
165 const writer = (await crew(admin, {})).value;
166 for (const s of writer.slots) for (const k of ["running", "waiting", "spentUsd", "sharePct"]) expect(s).toHaveProperty(k);
167 expect(writer.seats).toHaveProperty("mode");
168 const seen = (await crew(bob, {})).value; // bob reads alice/game, a public repository, and cannot write to it
169 expect(seen.slots.map((s: any) => Object.keys(s).sort())).toEqual([
170 ["max", "role", "slots"],
171 ["max", "role", "slots"],
172 ["max", "role", "slots"],
173 ]);
174 expect(Object.keys(seen.seats)).toEqual(["seats"]);
175 for (const p of seen.seats.seats) expect(p).not.toHaveProperty("state");
176 expect(JSON.stringify(seen)).not.toMatch(/spentUsd|sharePct|"running"|"waiting"|"auto"|"mode"/);
177 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs