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
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14968-the-mcp-crew-read-shows-cost-and-activit → main 4 commits fork
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. | ||
| 17 | 17 | - The client address is the socket's peer unless that peer is a configured |
| 18 | 18 | trusted proxy; `X-Forwarded-For` is read from the right, past trusted hops. |
| 19 | 19 | 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` | |
| 20 | 24 | - A new-account guard can refuse repository creation and forks for young |
| 21 | 25 | accounts. |
| 22 | 26 | 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"; | ||
| 2 | 2 | import { badBlocked } from "../shared.ts"; |
| 3 | 3 | import { notCrewAdminBlocked } from "../../../actions/blocked_words.ts"; |
| 4 | 4 | import { getAgentByName, isCrew } from "../../../core/agents.ts"; |
| 5 | import { canAdmin } from "../../../core/repos.ts"; | |
| 5 | import { canAdmin, canSeeOwnerFacts } from "../../../core/repos.ts"; | |
| 6 | 6 | import { getUserByName } from "../../../core/users.ts"; |
| 7 | 7 | import { crewAsSeen, addToCrew, removeFromCrew } from "../../../actions/crew.ts"; |
| 8 | 8 | import { emailVerified } from "../../../core/verify.ts"; |
| @@ -17,7 +17,7 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts" | ||
| 17 | 17 | |
| 18 | 18 | export const tool: Tool = { |
| 19 | 19 | 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`", | |
| 21 | 21 | description: "List a repository's crew, or add or remove an agent. Plans first; admin token.", |
| 22 | 22 | inputSchema: { |
| 23 | 23 | type: "object", |
| @@ -63,8 +63,20 @@ export const tool: Tool = { | ||
| 63 | 63 | if (add === undefined && remove === undefined) { |
| 64 | 64 | const seen = crewAsSeen(app, user, repo); |
| 65 | 65 | 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); | |
| 66 | 73 | 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 | }), | |
| 68 | 80 | card: { repo: `${repo.ownerName}/${repo.name}` }, |
| 69 | 81 | }; |
| 70 | 82 | } |
test/mcp-crew.test.ts +15
| @@ -160,3 +160,18 @@ test("the crew answer carries the three seats, empty ones named", async () => { | ||
| 160 | 160 | if (p.by.length === 0) expect(p.without).toBeString(); |
| 161 | 161 | } |
| 162 | 162 | }); |
| 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 | }); |
new above
offline