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

Access 3, terminal and games: SSH screens and game grants ask may() in shadow #18412

opened this

Merged 1h 57m ago, live in production

mason/forge:mason/18396-access-3-terminal-and-games-ssh-screens → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/18396-access-3-terminal-and-games-ssh-screens was merged into main as fea5438.

Review

Sign in to review this change.
155 files changed +662 −69
docs/features/may.md +28 −3
@@ -13,7 +13,9 @@ A client asks the forge what it may do instead of reading a role. One function,
1313
1414 Actions are named in one registry (`ACTIONS`), each with one sentence: `repo.read`, `repo.write`, `repo.admin` (over a
1515 repository), `forge.read`, `forge.write` (any change at all, as your account: a session, or a token of scope `rw`), `forge.comment`, `forge.contribute`, `forge.make_it_yours`, `forge.run_crew`,
16 `forge.administer`, and `account.manage` (the account itself, never a token).
16 `forge.administer`, and `account.manage` (the account itself, never a token). Over a game box or one server of it:
17 `game.view`, `game.operate` and `game.own`, the viewer, operator and owner of `game_grant` (forge admins own every box;
18 nobody holds a role on the forge's own helper beside the servers).
1719
1820 **API.** `GET /api/v1/user` carries `can`: the forge-wide actions you may take.
1921
@@ -23,8 +25,8 @@ curl -H "authorization: Bearer $TOKEN" "$FORGE/api/v1/may?action=repo.write&reso
2325 "may": false, "why": "forbidden", "reason": "Your account may not do this." }
2426 ```
2527
26 A forge-wide action takes no `resource`. The call needs no account: anonymous gets anonymous's answers. A repository
27 that is not there and one you may not read answer alike.
28 A forge-wide action takes no `resource`; a game action takes `resource=box` or `box/service`. The call needs no account:
29 anonymous gets anonymous's answers. A repository (or game box) that is not there and one you may not read answer alike.
2830
2931 **MCP.** `whoami_can` lists `actions`, the same names; `repo` adds read, write and admin there.
3032
@@ -52,3 +54,26 @@ An anonymous visit to a signed-in page parts on `forge.read`, which is open to a
5254 than reading. The page's old check (`isAdmin`, an account
5355 behind the request) still decides; `may` is worked out beside it, and where the two part the count's door is
5456 `web <page>`, the page's module. Nothing you can open on the web changes while the count is read.
57
58 **The terminal's screens ask it.** A palette entry whose gate is the forge's admin names `forge.administer` beside it,
59 and one whose gate is an account names `forge.read` (opening a screen is a read); the palette asks `may` that action as
60 the terminal's account, once a session for each entry and answer, not on every build (`src/tui/screens/entries.ts`, the
61 entry's `asks`). The entry's own gate still decides what the palette offers; where the two part the count's door is
62 `terminal <entry>`. Whether there is anything to show (a file, the forge's own key, runs) is the entry's `shows`, asked
63 first: a screen with nothing to show is not offered and counts nothing. Two partings are expected: signed out, every
64 screen for accounts (as on the web), and an admin agent, on the screens that are a person's. A screen gated on
65 something `may` has no action for (a telemetry role, a subscription, an organization, a game grant) or on nothing names
66 no action and says why beside its gate.
67
68 **The game grants ask it.** A game box's grant checks (the box and server pages, the games MCP tool, the game door's
69 API, the map, and the terminal's Games screens and keys) go through `mayOnGame` (`src/games/game_may.ts`): the grant still
70 decides, `may` is asked `game.view`, `game.operate` or `game.own` beside it with the caller's credential, and where the
71 two part the count's door is `game <door>` (`game page`, `game tool console`, `game shell`, …). An `ro` token that
72 operates a server by its grant is the parting you will see: `may` says its scope only reads. Seeing a box at all (its
73 page, the tool's `metrics` without a `service`) goes through `seesGameBox`, which asks `game.view` over the box: a person
74 whose grants are on one server only sees the box but holds no `game.view` over all of it, an expected parting.
75
76 Not asked yet: the checks that only filter what a list shows (which servers, snapshots and status lines a box's page,
77 the tool's `list`, the terminal's Games list, the cloud's containers and the in-game chat show to whom), and the checks
78 made again on a background job's behalf (`games/chat.ts`, `games/when_quiet.ts`, `games/shell.ts`). They still read
79 the grant alone.
src/contract/openapi/routes/getApiV1May.ts +2 −2
@@ -6,7 +6,7 @@ export const route: Route = {
66 path: "/api/v1/may",
77 summary: "Ask whether you may take an action, with the reason in words",
88 detail:
9 "Ask whether the caller may take `action` (a name from the `can` list of GET /api/v1/user, or one over a repository: repo.read, repo.write, repo.admin), over `resource` (owner/name, for an action over a repository; none for one over the whole forge). Answers { action, says, resource?, may, why?, reason? }: `may` is yes or no, and a no carries `why` (not_found: it does not exist for you; unauthorized: sign in; forbidden) and `reason` in words. A repository that is not there and one you may not read answer alike. Never cached.",
9 "Ask whether the caller may take `action` (a name from the `can` list of GET /api/v1/user, or one over a repository: repo.read, repo.write, repo.admin, or over a game box: game.view, game.operate, game.own), over `resource` (owner/name, for an action over a repository; box or box/service, for one over a game box; none for one over the whole forge). Answers { action, says, resource?, may, why?, reason? }: `may` is yes or no, and a no carries `why` (not_found: it does not exist for you; unauthorized: sign in; forbidden) and `reason` in words. A repository (or game box) that is not there and one you may not read answer alike. Never cached.",
1010 auth: false,
1111 role: "anonymous",
1212 query: { action: "string", resource: "string" },
@@ -18,6 +18,6 @@ export const route: Route = {
1818 refusals: {
1919 invalid_token: "401, a bearer or basic credential was sent and matches no account or token: sign in again; send none to be anonymous",
2020 unknown_action: "422: action is not one of the registry's names",
21 invalid: "422: resource is missing or malformed for an action over a repository, or sent for one over the whole forge",
21 invalid: "422: resource is missing or malformed for an action over a repository or a game box, or sent for one over the whole forge",
2222 },
2323 };
src/core/access_disagreement.ts +13 −2
@@ -12,8 +12,8 @@
1212 */
1313
1414 import type { Database } from "bun:sqlite";
15 import type { Action } from "./may.ts";
16 import type { PrincipalKind } from "./principal.ts";
15 import { type Action, holds, type Resource } from "./may.ts";
16 import type { Principal, PrincipalKind } from "./principal.ts";
1717 import { quietly } from "./write_clock.ts";
1818
1919 /** Count one disagreement: `may` said `said`, the old check said the opposite. */
@@ -32,3 +32,14 @@ export function noteDisagreement(
3232 ).run(door, action, principal, said ? 1 : 0, new Date().toISOString()),
3333 );
3434 }
35
36 /**
37 * Ask `may` beside `old`, the answer of the check it is replacing, and count a parting under
38 * `door`: what every door in shadow does (`http/may_beside.ts`, the terminal's palette, the game
39 * grants). Returns what `may` said; a door still in shadow keeps its old answer itself.
40 */
41 export function askBeside(db: Database, asking: Principal, door: string, action: Action, old: boolean, resource?: Resource): boolean {
42 const said = holds(db, asking, action, resource);
43 if (said !== old) noteDisagreement(db, door, action, asking.kind, said);
44 return said;
45 }
src/core/may.ts +50 −8
@@ -3,7 +3,8 @@
33 * (`core/principal.ts`: `principalOf(auth)` for a request, `principalOfUser(user)` for a check made
44 * on someone's behalf), the action is a name in
55 * `ACTIONS`, each with one sentence a person can read, and the resource is the repository the
6 * action is over, when it is over one. The answer is yes, or no with which of the forge's
6 * action is over, when it is over one, or the game box (or one server of it) a `game.*` action is
7 * over. The answer is yes, or no with which of the forge's
78 * existing answers applies: `not_found` (what you may not read does not exist for you),
89 * `unauthorized` (sign in) or `forbidden`.
910 *
@@ -20,16 +21,31 @@ import { userOf, type Principal } from "./principal.ts";
2021 import { scopeAllows, type TokenScope } from "./tokens.ts";
2122 import type { User } from "./users.ts";
2223
23 /** What an action is over: a repository, or (nothing) the forge as a whole. */
24 export interface Resource {
25 readonly repo: Repo;
24 /** A role on a game box or one server of it (`game_grant`), lowest first. */
25 export const GAME_ROLES = ["viewer", "operator", "owner"] as const;
26 export type GameRole = (typeof GAME_ROLES)[number];
27
28 /** How far a game role reaches: 0 for none, or for a stored word that is no role. */
29 export const gameRank = (role: string | undefined): number => GAME_ROLES.indexOf(role as GameRole) + 1;
30
31 /**
32 * A game box, or one server of it: the role `game_grant` gives this account there (a forge admin's
33 * is the forge's to add: admins own every box), and whether it is the forge's own helper beside the
34 * servers, which nobody holds a role on (`games/store.ts`, `roleOn`).
35 */
36 export interface GameResource {
37 readonly granted: GameRole | undefined;
38 readonly helper: boolean;
2639 }
2740
41 /** What an action is over: a repository, a game box, or (nothing) the forge as a whole. */
42 export type Resource = { readonly repo: Repo; readonly game?: never } | { readonly game: GameResource; readonly repo?: never };
43
2844 interface ActionRow {
2945 /** One sentence a person can read. */
3046 readonly says: string;
3147 /** What it is over: a repository, or the forge as a whole. */
32 readonly over: "repo" | "forge";
48 readonly over: "repo" | "forge" | "game";
3349 /** The scope a token must hold: reading needs `ro`, anything that changes something `rw`. */
3450 readonly scope: TokenScope;
3551 }
@@ -56,6 +72,9 @@ export const ACTIONS = {
5672 scope: "rw",
5773 },
5874 "account.manage": { says: "Change your own account: password, profile and tokens, as yourself and not by a token", over: "forge", scope: "ro" },
75 "game.view": { says: "See a game box or one server of it: its state, people, logs and settings", over: "game", scope: "ro" },
76 "game.operate": { says: "Operate a game server: its console, players, worlds, restarts and settings", over: "game", scope: "rw" },
77 "game.own": { says: "Own a game box: its shell, machine, lending and who holds a role on it", over: "game", scope: "rw" },
5978 } as const satisfies Record<string, ActionRow>;
6079 export type Action = keyof typeof ACTIONS;
6180
@@ -95,6 +114,27 @@ function repoRuleHolds(db: Database, action: Action, repo: Repo, user: User | un
95114 return adminsRepo(db, repo, user);
96115 }
97116
117 /** The game role each game action needs: viewer, operator or owner, as `game_grant` names them. */
118 const GAME_NEED: Readonly<Partial<Record<Action, GameRole>>> = { "game.view": "viewer", "game.operate": "operator", "game.own": "owner" };
119
120 /**
121 * Whether the rule of a game action holds: the forge's admin owns every box (`forge.administer`),
122 * anyone else holds what their grant there says, and nobody holds a role on the forge's helper.
123 */
124 function gameRuleHolds(db: Database, action: Action, game: GameResource, p: Principal): boolean {
125 if (game.helper || userOf(p) === undefined) return false;
126 const role = forgeRuleHolds(db, "forge.administer", p) ? "owner" : game.granted;
127 return gameRank(role) >= gameRank(GAME_NEED[action]);
128 }
129
130 /** The rule of `action` over `resource`, ignoring any token's scope. */
131 function ruleHolds(db: Database, action: Action, p: Principal, resource: Resource | undefined): boolean {
132 const over = ACTIONS[action].over;
133 if (over === "repo") return repoRuleHolds(db, action, resource!.repo!, userOf(p));
134 if (over === "game") return gameRuleHolds(db, action, resource!.game!, p);
135 return forgeRuleHolds(db, action, p);
136 }
137
98138 function forgeRuleHolds(db: Database, action: Action, p: Principal): boolean {
99139 const ability = ABILITY_OF[action];
100140 if (ability === "read") return true;
@@ -117,7 +157,7 @@ function forgeRuleHolds(db: Database, action: Action, p: Principal): boolean {
117157 */
118158 export function holds(db: Database, p: Principal, action: Action, resource?: Resource): boolean {
119159 const row: ActionRow = ACTIONS[action];
120 const held = row.over === "repo" ? repoRuleHolds(db, action, resource!.repo, userOf(p)) : forgeRuleHolds(db, action, p);
160 const held = ruleHolds(db, action, p, resource);
121161 // Only a token carries a scope; the account itself acts with all of its own authority.
122162 return held && (!("scope" in p) || scopeAllows(p.scope, row.scope));
123163 }
@@ -128,10 +168,12 @@ export function may(db: Database, p: Principal, action: Action, resource?: Resou
128168 if (holds(db, p, action, resource)) return yes;
129169 if (action === "account.manage") return no(user === undefined ? "unauthorized" : "forbidden", BROWSER_WORDS);
130170 // What you may not read does not exist for you, signed in or not.
131 if (row.over === "repo" && (action === "repo.read" || !readsRepo(db, resource!.repo, user))) return no("not_found");
171 if (row.over === "repo" && (action === "repo.read" || !readsRepo(db, resource!.repo!, user))) return no("not_found");
172 // A game box you hold no role on is not there for you either.
173 if (row.over === "game" && !gameRuleHolds(db, "game.view", resource!.game!, p)) return no("not_found");
132174 if (user === undefined) return no("unauthorized");
133175 // Only here is it asked whether the rule held and the token's scope alone said no.
134 const held = row.over === "repo" ? repoRuleHolds(db, action, resource!.repo, user) : forgeRuleHolds(db, action, p);
176 const held = ruleHolds(db, action, p, resource);
135177 return no("forbidden", held ? SCOPE_WORDS : undefined);
136178 }
137179
src/games/game_may.ts added +50
@@ -0,0 +1,50 @@
1 /**
2 * A game box's grant checks ask `may` in shadow (#18396), as the repository routes, the MCP tools,
3 * the web pages and the terminal's palette did before them. `game_grant`'s viewer, operator and
4 * owner are `may`'s `game.view`, `game.operate` and `game.own` over the box or one server of it
5 * (`core/may.ts`); the grant is the one there is, and no table is added.
6 *
7 * The old check (`mayDo(roleOn(…), need)`) still decides; `may` is asked beside it with the
8 * principal the door has (a request's credential, or the terminal's account), and where the two
9 * part one row is counted under `game <door>` (`core/access_disagreement.ts`). Nobody's access
10 * changes here.
11 */
12
13 import type { Database } from "bun:sqlite";
14 import { askBeside } from "../core/access_disagreement.ts";
15 import type { Action, Resource } from "../core/may.ts";
16 import { userOf, type Principal } from "../core/principal.ts";
17 import type { User } from "../core/users.ts";
18 import { grantOn, isWaker, mayDo, roleOn, seesBox, type Role } from "./store.ts";
19
20 const ACTION_OF: Readonly<Record<Role, Action>> = { viewer: "game.view", operator: "game.operate", owner: "game.own" };
21
22 /** A box (`service` empty) or one server of it, as `may` reads it: `user`'s grant there. */
23 export const gameResource = (db: Database, user: User | undefined, boxId: string, service = ""): Resource => ({
24 game: { granted: grantOn(db, user, boxId, service), helper: isWaker(service) },
25 });
26
27 /**
28 * Ask `may` `action` over the box (or its `service`) beside `old`, counting a parting; returns
29 * `old`.
30 */
31 function beside(db: Database, asking: Principal, door: string, action: Action, old: boolean, boxId: string, service = ""): boolean {
32 askBeside(db, asking, `game ${door}`, action, old, gameResource(db, userOf(asking), boxId, service));
33 return old;
34 }
35
36 /**
37 * Whether `asking` holds `need` on the box `boxId` (or its `service`), by the grant check, which
38 * still decides; `may` is asked beside it and a parting counted under `game <door>`.
39 */
40 export const mayOnGame = (db: Database, asking: Principal, door: string, boxId: string, service: string, need: Role): boolean =>
41 beside(db, asking, door, ACTION_OF[need], mayDo(roleOn(db, userOf(asking), boxId, service), need), boxId, service);
42
43 /**
44 * Whether `asking` sees the box `boxId` at all (any grant on it, a server's too), by `seesBox`,
45 * which still decides; `may` is asked `game.view` over the box beside it. A person whose grants
46 * are on one server only sees the box yet holds no `game.view` over all of it: that parting is
47 * expected, and counted under `game <door>`.
48 */
49 export const seesGameBox = (db: Database, asking: Principal, door: string, boxId: string): boolean =>
50 beside(db, asking, door, "game.view", seesBox(db, userOf(asking), boxId), boxId);
src/games/store.ts +11 −4
@@ -19,6 +19,7 @@ import type { App } from "../app.ts";
1919 import { existsAtProvider } from "../cloud/billing.ts";
2020 import { getPinned } from "../core/pinned.ts";
2121 import { resolveSecrets, setSecret } from "../core/secret_store.ts";
22 import { gameRank, type GameRole } from "../core/may.ts";
2223 import type { User } from "../core/users.ts";
2324 import { sha256 } from "../kernel/hash.ts";
2425 import { id as newId } from "../kernel/id.ts";
@@ -39,8 +40,8 @@ const OUTPUT_MAX = 16_384;
3940 const MAP_OUTPUT_MAX = 820_000;
4041 export const COMMAND_KINDS = ["rcon", "restart", "stop", "start", "recreate", "pull", "shell", "people", "world", "hashes", "tell", "map"] as const;
4142 export type CommandKind = (typeof COMMAND_KINDS)[number];
42 export type Role = "owner" | "operator" | "viewer";
43 const RANK: Record<Role, number> = { viewer: 1, operator: 2, owner: 3 };
43 /** A role on a box or a server of it: `may`'s game roles (`core/may.ts`). */
44 export type Role = GameRole;
4445
4546 export interface GameBox {
4647 readonly id: string;
@@ -279,6 +280,12 @@ export const isWaker = (service: string): boolean => service === WAKER;
279280 export function roleOn(db: Database, user: User | undefined, boxId: string, service = ""): Role | undefined {
280281 if (user === undefined || isWaker(service)) return undefined;
281282 if (user.isAdmin) return "owner";
283 return grantOn(db, user, boxId, service);
284 }
285
286 /** The best role `user`'s own grants give on a box or one service of it, admin or not. */
287 export function grantOn(db: Database, user: User | undefined, boxId: string, service = ""): Role | undefined {
288 if (user === undefined || isWaker(service)) return undefined;
282289 const rows = db
283290 .query<
284291 { role: Role },
@@ -286,10 +293,10 @@ export function roleOn(db: Database, user: User | undefined, boxId: string, serv
286293 >("SELECT role FROM game_grant WHERE box_id = ?1 AND user_id = ?2 AND (service = '' OR service = ?3)")
287294 .all(boxId, user.id, service);
288295 let best: Role | undefined;
289 for (const r of rows) if (RANK[r.role] !== undefined && (best === undefined || RANK[r.role] > RANK[best])) best = r.role;
296 for (const r of rows) if (gameRank(r.role) > gameRank(best)) best = r.role;
290297 return best;
291298 }
292 export const mayDo = (role: Role | undefined, need: Role): boolean => role !== undefined && RANK[role] >= RANK[need];
299 export const mayDo = (role: Role | undefined, need: Role): boolean => role !== undefined && gameRank(role) >= gameRank(need);
293300
294301 /** The box-wide owners, not forge admins, of each game box on the machine `pinnedId` names. */
295302 export const boxOwnersOfMachine = (db: Database, pinnedId: string): { userId: string; box: string }[] =>
src/http/api/game_door.ts +4 −2
@@ -9,17 +9,19 @@
99
1010 import { passkeyProves, proofChallenge, PROOF_FIELDS } from "../../actions/passkey_proof.ts";
1111 import { getUserById } from "../../core/users.ts";
12 import { boxNamed, mayDo, roleOn } from "../../games/store.ts";
12 import { boxNamed } from "../../games/store.ts";
1313 import { doorOf, doorWords, lockDoor, openWindow } from "../../games/write_window.ts";
1414 import type { Ctx, Handler } from "../context.ts";
1515 import { apiError, body, json, notFound, requireScope } from "../respond.ts";
1616 import type { Router } from "../router.ts";
17 import { principalOf } from "../../core/principal.ts";
18 import { mayOnGame } from "../../games/game_may.ts";
1719
1820 /** The box when the caller owns it. */
1921 function ownedBox(ctx: Ctx) {
2022 const user = ctx.auth.user;
2123 const box = user === null || user === undefined ? undefined : boxNamed(ctx.app.db, ctx.params.box ?? "");
22 return user && box && mayDo(roleOn(ctx.app.db, user, box.id), "owner") ? box : undefined;
24 return user && box && mayOnGame(ctx.app.db, principalOf(ctx.auth), "door", box.id, "", "owner") ? box : undefined;
2325 }
2426
2527 /** The door as the app reads it: the state and the words the page says of it. */
src/http/api/may.ts +21 −7
@@ -2,12 +2,15 @@
22 * `GET /api/v1/may?action=…&resource=owner/name`: one cheap read of what this caller may do, so a
33 * client asks instead of reading a role. The answer is `may` (`core/may.ts`): yes, or no with the
44 * forge's own reason (`not_found`, `unauthorized`, `forbidden`) and the reason in words. A
5 * repository that is not there and one the caller may not read answer alike.
5 * repository that is not there and one the caller may not read answer alike. A `game.*` action is
6 * over a game box, `resource=box` or `box/service`; a box you hold no role on is not there for you.
67 */
78
8 import { ACTIONS, isAction, may, WHY_WORDS, type Action } from "../../core/may.ts";
9 import { principalOf } from "../../core/principal.ts";
9 import { ACTIONS, isAction, may, WHY_WORDS, type Action, type Resource } from "../../core/may.ts";
10 import { principalOf, userOf } from "../../core/principal.ts";
1011 import { getRepo } from "../../core/repos.ts";
12 import { gameResource } from "../../games/game_may.ts";
13 import { BOX_NAME, boxNamed, SERVICE_NAME } from "../../games/store.ts";
1114 import { INVALID_TOKEN_HINT, INVALID_TOKEN_WORDS } from "../../actions/here.ts";
1215 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
1316 import type { Handler } from "../context.ts";
@@ -17,6 +20,9 @@ import type { Router } from "../router.ts";
1720 /** `owner/name`, each part a repository name's characters and no longer than one may be. */
1821 const REPO_RESOURCE = /^([A-Za-z0-9._-]{1,100})\/([A-Za-z0-9._-]{1,100})$/;
1922
23 /** `box` or `box/service`; each part is checked against its own pattern after. */
24 const GAME_RESOURCE = /^([^/]{1,64})(?:\/([^/]{1,64}))?$/;
25
2026 const names = (): string => (Object.keys(ACTIONS) as Action[]).join(", ");
2127
2228 export function mayRoutes(router: Router<Handler>): void {
@@ -28,17 +34,25 @@ export function mayRoutes(router: Router<Handler>): void {
2834 if (!isAction(action)) return apiError("unknown_action", 422, `action is one of: ${names()}`);
2935 const resource = ctx.url.searchParams.get("resource") ?? undefined;
3036 const row = ACTIONS[action];
31 let repo;
37 const asking = principalOf(ctx.auth);
38 let over: Resource | undefined;
3239 if (row.over === "forge") {
3340 if (resource !== undefined) return apiError("invalid", 422, `${action} is over the whole forge: send no resource`);
41 } else if (row.over === "game") {
42 const named = resource === undefined ? null : GAME_RESOURCE.exec(resource);
43 if (named === null || !BOX_NAME.test(named[1]!) || (named[2] !== undefined && !SERVICE_NAME.test(named[2])))
44 return apiError("invalid", 422, `${action} is over a game box: resource is box or box/service`);
45 const box = boxNamed(ctx.app.db, named[1]!);
46 if (box !== undefined) over = gameResource(ctx.app.db, userOf(asking), box.id, named[2] ?? "");
3447 } else {
3548 const named = resource === undefined ? null : REPO_RESOURCE.exec(resource);
3649 if (named === null) return apiError("invalid", 422, `${action} is over a repository: resource is owner/name`);
37 repo = getRepo(ctx.app.db, named[1]!, named[2]!);
50 const repo = getRepo(ctx.app.db, named[1]!, named[2]!);
51 if (repo !== undefined) over = { repo };
3852 }
39 const answer = row.over === "repo" && repo === undefined
53 const answer = row.over !== "forge" && over === undefined
4054 ? ({ ok: false, why: "not_found", says: WHY_WORDS.not_found } as const)
41 : may(ctx.app.db, principalOf(ctx.auth), action, repo === undefined ? undefined : { repo });
55 : may(ctx.app.db, asking, action, over);
4256 return json(
4357 {
4458 action,
src/http/games_map.ts +4 −2
@@ -12,11 +12,13 @@
1212
1313 import { askMap, mapPath } from "../games/map.ts";
1414 import { mapPass, passUser } from "../games/map_token.ts";
15 import { boxNamed, mayDo, roleOn, servicesOf } from "../games/store.ts";
15 import { boxNamed, servicesOf } from "../games/store.ts";
1616 import { getUserById } from "../core/users.ts";
1717 import { boxOf } from "../web/pages/games.ts";
1818 import type { Ctx } from "./context.ts";
1919 import { securityFloor } from "./respond.ts";
20 import { principalOfUser } from "../core/principal.ts";
21 import { mayOnGame } from "../games/game_may.ts";
2022
2123 /**
2224 * No origin, so no cookie and no same-origin reach into the forge; `connect-src 'self'` is the
@@ -53,7 +55,7 @@ export async function gameMap(ctx: Ctx): Promise<Response> {
5355 const userId = box === undefined ? undefined : passUser(ctx.app.config.dataDir, box.id, service, ctx.params.pass ?? "");
5456 const user = userId === undefined ? undefined : getUserById(ctx.app.db, userId);
5557 // A grant taken back ends the pass at the next file.
56 if (box === undefined || user === undefined || !mayDo(roleOn(ctx.app.db, user, box.id, service), "viewer")) return refuse(404, "no such map");
58 if (box === undefined || user === undefined || !mayOnGame(ctx.app.db, principalOfUser(user), "map", box.id, service, "viewer")) return refuse(404, "no such map");
5759 if (!servicesOf(ctx.app.db, box.id).some((s) => s.name === service)) return refuse(404, "no such server");
5860 const ask = mapPath(ctx.params.path ?? "");
5961 if (!ask.ok) return refuse(404, ask.error);
src/http/may_beside.ts +3 −6
@@ -5,14 +5,11 @@
55 * door still in shadow returns its old answer itself.
66 */
77
8 import { noteDisagreement } from "../core/access_disagreement.ts";
9 import { type Action, holds } from "../core/may.ts";
8 import { askBeside } from "../core/access_disagreement.ts";
9 import type { Action } from "../core/may.ts";
1010 import { principalOf } from "../core/principal.ts";
1111 import type { Ctx } from "./context.ts";
1212
1313 export function mayBeside(ctx: Ctx, door: string, action: Action, old: boolean): boolean {
14 const asking = principalOf(ctx.auth);
15 const said = holds(ctx.app.db, asking, action);
16 if (said !== old) noteDisagreement(ctx.app.db, door, action, asking.kind, said);
17 return said;
14 return askBeside(ctx.app.db, principalOf(ctx.auth), door, action, old);
1815 }
src/http/mcp/tools/games.ts +10 −6
@@ -25,6 +25,8 @@ import { verdictsOf } from "../../../games/set_verdict.ts";
2525 import { takeBack } from "../../../games/take_back.ts";
2626 import { newestProof, proofWords } from "../../../games/lent_proof.ts";
2727 import { queueWorld } from "../../../games/worlds.ts";
28 import { principalOf } from "../../../core/principal.ts";
29 import { mayOnGame, seesGameBox } from "../../../games/game_may.ts";
2830
2931 export const tool: Tool = {
3032 name: "games",
@@ -120,7 +122,7 @@ export const tool: Tool = {
120122 // A server added or taken out is the box's: its operators', planned first.
121123 if (action === "create_server" || action === "remove_server") {
122124 if (box === undefined || !seesBox(db, user, box.id)) return bad("not_found", "no such box here");
123 if (!mayDo(roleOn(db, user, box.id), "operator")) return bad("forbidden", `you are not an operator of ${box.name}`);
125 if (!mayOnGame(db, principalOf(ctx.auth), `tool ${action}`, box.id, "", "operator")) return bad("forbidden", `you are not an operator of ${box.name}`);
124126 let planned;
125127 if (action === "create_server") {
126128 const parsed = await wishOn(ctx.app, box, str(args["words"]));
@@ -146,16 +148,18 @@ export const tool: Tool = {
146148 }
147149 const service = str(args["service"]);
148150 if (action === "metrics") {
149 if (box === undefined || !seesBox(db, user, box.id)) return bad("not_found", "no such box here");
150 if (service === "") return good(compactMetrics(db, box, (s) => mayDo(roleOn(db, user, box.id, s), "viewer")));
151 if (!SERVICE_NAME.test(service) || !mayDo(roleOn(db, user, box.id, service), "viewer")) return bad("not_found", "no such service here");
151 const asking = principalOf(ctx.auth);
152 // The whole box's numbers ask may over the box; one server's, over that server alone.
153 if (box === undefined || !(service === "" ? seesGameBox(db, asking, "tool metrics", box.id) : seesBox(db, user, box.id))) return bad("not_found", "no such box here");
154 if (service === "") return good(compactMetrics(db, box, (s) => mayOnGame(db, asking, "tool metrics", box.id, s, "viewer")));
155 if (!SERVICE_NAME.test(service) || !mayOnGame(db, asking, "tool metrics", box.id, service, "viewer")) return bad("not_found", "no such service here");
152156 const window = (str(args["window"]) || "1h") as Window;
153157 if (!(window in WINDOWS)) return bad("invalid", `window is one of ${Object.keys(WINDOWS).join(", ")}`);
154158 return good(compactSeries(db, box, service, window));
155159 }
156160 if (box === undefined || !seesBox(db, user, box.id) || !SERVICE_NAME.test(service)) return bad("not_found", "no such box or service here");
157161 if (action === "config") {
158 if (!mayDo(roleOn(db, user, box.id, service), "viewer")) return bad("forbidden", `you may not see ${service} on ${box.name}`);
162 if (!mayOnGame(db, principalOf(ctx.auth), "tool config", box.id, service, "viewer")) return bad("forbidden", `you may not see ${service} on ${box.name}`);
159163 const got = await serviceSettings(ctx.app, box, service);
160164 if (!got.ok) return bad("refused", got.error);
161165 return good({
@@ -172,7 +176,7 @@ export const tool: Tool = {
172176 })),
173177 });
174178 }
175 if (!mayDo(roleOn(db, user, box.id, service), "operator")) return bad("forbidden", `you are not an operator of ${service} on ${box.name}`);
179 if (!mayOnGame(db, principalOf(ctx.auth), `tool ${action}`, box.id, service, "operator")) return bad("forbidden", `you are not an operator of ${service} on ${box.name}`);
176180 if (action === "console") {
177181 const text = str(args["text"]).trim();
178182 if (text === "") return bad("invalid", "say the command as text");
src/tui/screens/abstractions.ts +1
@@ -59,6 +59,7 @@ export const entry: PaletteEntry = {
5959 id: "abstractions",
6060 title: "Tables",
6161 hint: "the forge's tables: how much each is used, and what builds on what",
62 asks: "forge.administer",
6263 offered: (session) => mayReadAtlas(session.user),
6364 run: (session, ctx) => ctx.push(abstractionsScreen(session, ctx)),
6465 };
src/tui/screens/access.ts +1
@@ -120,6 +120,7 @@ export const entry: PaletteEntry = {
120120 title: "Access",
121121 hint: "what outside agents tried",
122122 after: ["file-holds"],
123 asks: "forge.administer",
123124 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
124125 run: (session, ctx) => ctx.push(accessScreen(session, ctx)),
125126 };
src/tui/screens/account_access.ts +1
@@ -173,6 +173,7 @@ export const entry: PaletteEntry = {
173173 title: "Account access",
174174 hint: "search people, reset access, end sessions",
175175 after: ["people"],
176 asks: "forge.administer",
176177 offered: (session) => session.user?.isAdmin === true && session.user.kind === "user",
177178 run: (session, ctx) => ctx.push(accountAccessScreen(session, ctx)),
178179 };
src/tui/screens/advisories.ts +1
@@ -73,6 +73,7 @@ export const entry: PaletteEntry = {
7373 title: "Advisories",
7474 hint: "known vulnerabilities in your lockfiles",
7575 after: ["resilience"],
76 asks: "forge.administer",
7677 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
7778 run: openAdvisories,
7879 };
src/tui/screens/agents.ts +1
@@ -156,6 +156,7 @@ export const entry: PaletteEntry = {
156156 title: "Crew agents",
157157 hint: "each agent's model, budget and brief",
158158 after: ["teams", "limits", "quotas", "people"],
159 asks: "forge.administer",
159160 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
160161 run: (session, ctx) => ctx.push(agentsScreen(session, ctx)),
161162 };
src/tui/screens/app_templates.ts +1
@@ -169,6 +169,7 @@ export const entry: PaletteEntry = {
169169 title: "App templates",
170170 hint: "the repositories New app offers; mark or unmark one",
171171 after: ["economics"],
172 asks: "forge.administer",
172173 offered: (session) => mayMark(session),
173174 run: (session, ctx) => ctx.push(appTemplatesScreen(session, ctx)),
174175 };
src/tui/screens/appleusage.ts +1
@@ -97,6 +97,7 @@ export const entry: PaletteEntry = {
9797 title: "App usage",
9898 hint: "the Apple app's anonymous usage: counts and timings per version",
9999 after: ["limits"],
100 asks: "forge.administer",
100101 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
101102 run: (session, ctx) => ctx.push(appleUsageScreen(session, ctx)),
102103 };
src/tui/screens/apps_crew.ts +1
@@ -93,6 +93,7 @@ export const entry: PaletteEntry = {
9393 id: "apps-crew",
9494 title: "What the crew is doing",
9595 hint: "one plain sentence per app: who is on what",
96 // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside.
9697 offered: () => true,
9798 run: (session, ctx) => ctx.push(appsCrewScreen(session, ctx)),
9899 };
src/tui/screens/archived.ts +1
@@ -108,6 +108,7 @@ export const entry: PaletteEntry = {
108108 id: "archived",
109109 title: "Archive",
110110 hint: "what is put away, who put it there: open one or unarchive it",
111 asks: "forge.read",
111112 offered: (session) => session.user !== undefined,
112113 run: (session, ctx) => ctx.push(archivedScreen(session, ctx)),
113114 };
src/tui/screens/ask_data.ts +1
@@ -155,6 +155,7 @@ export const entry: PaletteEntry = {
155155 title: "Data explorer",
156156 hint: "start from a question about the forge's data",
157157 after: ["boards"],
158 asks: "forge.administer",
158159 offered: mayExplore,
159160 run: (session, ctx) => ctx.push(askDataScreen(session, ctx)),
160161 };
src/tui/screens/audit.ts +1
@@ -110,6 +110,7 @@ export const entry: PaletteEntry = {
110110 id: "audit",
111111 title: "Who can do what",
112112 hint: "each app's doors from its contract.json: yes, own or no",
113 // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside.
113114 offered: () => true,
114115 run: (session, ctx) =>
115116 runAsync(ctx, async () => {
src/tui/screens/bets.ts +1
@@ -197,6 +197,7 @@ export const entry: PaletteEntry = {
197197 id: "bets",
198198 title: "Bets",
199199 hint: "back, stop and finish a repository's bets",
200 asks: "forge.read",
200201 offered: (session) => session.user !== undefined && session.user.kind !== "agent",
201202 run: (session, ctx) => ctx.push(betsScreen(session, ctx)),
202203 };
src/tui/screens/billing.ts +1
@@ -134,6 +134,7 @@ export const entry: PaletteEntry = {
134134 id: "billing",
135135 title: "Billing",
136136 hint: "each forge's plan, and grant one by hand",
137 asks: "forge.administer",
137138 offered: isAdmin,
138139 run: (session, ctx) => ctx.push(billingScreen(session, ctx)),
139140 };
src/tui/screens/bills.ts +2
@@ -66,6 +66,8 @@ export const entry: PaletteEntry = {
6666 id: "bills",
6767 title: "Your forges' bills",
6868 hint: "this month's cost of each forge you claimed",
69 asks: "forge.read",
70 shows: (session) => session.user === undefined || billNames(session.app, session.user).length > 0,
6971 offered: (session) => session.user !== undefined && session.user.kind === "user" && billNames(session.app, session.user).length > 0,
7072 run: (session, ctx) => ctx.push(billsScreen(session, ctx)),
7173 };
src/tui/screens/boards.ts +1
@@ -423,6 +423,7 @@ export const entry: PaletteEntry = {
423423 title: "Boards",
424424 hint: "the forge's boards and their panels",
425425 after: ["sentinel"],
426 asks: "forge.administer",
426427 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
427428 run: (session, ctx) => ctx.push(boardsScreen(session, ctx)),
428429 };
src/tui/screens/bottleneck.ts +2
@@ -70,6 +70,8 @@ export const entry: PaletteEntry = {
7070 title: "Where the bottleneck is",
7171 hint: "what limits the forge, what the host is tuned to, what changed",
7272 after: ["system"],
73 // Names no `asks`: the gate is a telemetry role (`telemetryReader`), which `may` has no action
74 // for.
7375 offered: mayRead,
7476 run: (session, ctx) => ctx.push(bottleneckScreen(session, ctx)),
7577 };
src/tui/screens/buckets.ts +1
@@ -110,6 +110,7 @@ export const entry: PaletteEntry = {
110110 id: "buckets",
111111 title: "Buckets",
112112 hint: "an object bucket's price a month, and binding it to an app",
113 asks: "forge.read",
113114 offered: (session) => session.user !== undefined,
114115 run: (session, ctx) => ctx.push(bucketsScreen(session, ctx)),
115116 };
src/tui/screens/budgets.ts +1
@@ -90,6 +90,7 @@ export const entry: PaletteEntry = {
9090 id: "budgets",
9191 title: "Cloud budgets",
9292 hint: "each cloud account's monthly budget against its projected spend",
93 asks: "forge.administer",
9394 offered: (session) => session.user?.isAdmin === true,
9495 run: (session, ctx) => ctx.push(budgetsScreen(session, ctx)),
9596 };
src/tui/screens/bugs.ts +1
@@ -52,6 +52,7 @@ export const entry: PaletteEntry = {
5252 title: "Bugs",
5353 hint: "open bugs and the bug clock",
5454 after: ["boards"],
55 // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside.
5556 offered: () => true,
5657 run: (session, ctx) => ctx.push(bugsScreen(session, ctx)),
5758 };
src/tui/screens/bulk.ts +1
@@ -169,6 +169,7 @@ export const entry: PaletteEntry = {
169169 title: "Bulk actions",
170170 hint: "your last bulk actions; u undoes one inside its day",
171171 after: ["invites", "teams", "limits"],
172 asks: "forge.read",
172173 offered: isPerson,
173174 run: (session, ctx) => ctx.push(bulkScreen(session, ctx)),
174175 };
src/tui/screens/childcredit.ts +1
@@ -52,6 +52,7 @@ export const entry: PaletteEntry = {
5252 title: "Lend a child credit",
5353 hint: "set the dollars a forge you sent may spend on this one's model credential",
5454 after: ["forges"],
55 asks: "forge.administer",
5556 offered: (session) => session.user?.isAdmin === true,
5657 run: (session, ctx) =>
5758 runAsync(ctx, async () => {
src/tui/screens/claim_start.ts +1
@@ -71,6 +71,7 @@ export const entry: PaletteEntry = {
7171 title: "Take an agent's work",
7272 hint: "claim the repositories an agent started, from its one-time link",
7373 after: ["invites", "repos"],
74 asks: "forge.read",
7475 offered: (session) => session.user?.kind === "user",
7576 run: (session, ctx) => ctx.push(claimStartScreen(session, ctx)),
7677 };
src/tui/screens/client_clouds.ts +1
@@ -160,6 +160,7 @@ export const entry: PaletteEntry = {
160160 id: "client-clouds",
161161 title: "Clients' clouds",
162162 hint: "sealed, expiring, read-only views of a client's cloud",
163 // Names no `asks`: the gate is being named on a client's cloud (or the admin), not one action.
163164 offered: (session) => session.user?.kind === "user" && (session.user.isAdmin || myClientClouds(session.app, session.user).length > 0),
164165 run: (session, ctx) => ctx.push(clientCloudsScreen(session, ctx)),
165166 };
src/tui/screens/cloud.ts +1
@@ -276,6 +276,7 @@ export const entry: PaletteEntry = {
276276 id: "cloud",
277277 title: "Cloud accounts",
278278 hint: "provider tokens, what they are used for, today's calls",
279 asks: "forge.administer",
279280 offered: (session) => session.user?.isAdmin === true,
280281 run: (session, ctx) => ctx.push(cloudScreen(session, ctx)),
281282 };
src/tui/screens/cloudcost.ts +1
@@ -55,6 +55,7 @@ export const entry: PaletteEntry = {
5555 title: "What the clouds cost",
5656 hint: "each account against its budget, and what costs most",
5757 after: ["footing", "system"],
58 asks: "forge.administer",
5859 offered: mayRead,
5960 run: (session, ctx) => ctx.push(cloudCostScreen(session, ctx)),
6061 };
src/tui/screens/cloudtree.ts +1
@@ -323,6 +323,7 @@ export const entry: PaletteEntry = {
323323 title: "Cloud resources",
324324 hint: "every resource on every cloud, what it costs, filtered",
325325 after: ["cloud"],
326 asks: "forge.administer",
326327 offered: (session) => session.user?.isAdmin === true,
327328 run: (session, ctx) => ctx.push(cloudTreeScreen(session, ctx)),
328329 };
src/tui/screens/codes.ts +1
@@ -99,6 +99,7 @@ export const entry: PaletteEntry = {
9999 id: "codes",
100100 title: "Gift codes",
101101 hint: "make a code that gives a plan for free, and revoke one",
102 asks: "forge.administer",
102103 offered: isAdmin,
103104 run: (session, ctx) => ctx.push(codesScreen(session, ctx)),
104105 };
src/tui/screens/connections.ts +1
@@ -166,6 +166,7 @@ export const entry: PaletteEntry = {
166166 id: "origins",
167167 title: "Connected accounts",
168168 hint: "the hosts your mirrors come from",
169 asks: "forge.read",
169170 offered: (session) => session.user !== undefined && session.user.kind !== "agent",
170171 run: (session, ctx) => ctx.push(connectionsScreen(session, ctx)),
171172 };
src/tui/screens/controls.ts +1
@@ -72,6 +72,7 @@ export const entry: PaletteEntry = {
7272 id: "security-controls",
7373 title: "Security controls",
7474 hint: "each safeguard, its state, and when it was last checked",
75 asks: "forge.administer",
7576 offered: isAdmin,
7677 run: (session, ctx) => ctx.push(controlsScreen(session, ctx)),
7778 };
src/tui/screens/cores.ts +2
@@ -29,6 +29,8 @@ export const entry: PaletteEntry = {
2929 title: "Cores",
3030 hint: "what this forge's cores mean for builds",
3131 after: ["plan-row", "limits"],
32 asks: "forge.administer",
33 shows: () => coresLine() !== undefined,
3234 offered: (session) => session.user?.isAdmin === true && coresLine() !== undefined,
3335 run: (session, ctx) => {
3436 if (session.user?.isAdmin === true) ctx.push(coresScreen(session, ctx));
src/tui/screens/crewbudgets.ts +3
@@ -91,6 +91,9 @@ export const entry: PaletteEntry = {
9191 title: "Crew budgets",
9292 hint: "what the crew may spend per run, day and month on your key",
9393 after: ["crewkey", "subscriptions"],
94 asks: "forge.administer",
95 // The budgets are the forge's own key's: a forge sent to someone has none to set.
96 shows: (session) => isOwnForge(session.app),
9497 offered: mayAct,
9598 run: (session, ctx) => ctx.push(crewBudgetsScreen(session, ctx)),
9699 };
src/tui/screens/crewfallback.ts +1
@@ -92,6 +92,7 @@ export const entry: PaletteEntry = {
9292 title: "Metered fallback",
9393 hint: "the capped key the crew falls back to when every plan's window is full",
9494 after: ["crewbudgets"],
95 asks: "forge.administer",
9596 offered: mayAct,
9697 run: (session, ctx) => ctx.push(crewFallbackScreen(session, ctx)),
9798 };
src/tui/screens/crewhandover.ts +1
@@ -112,6 +112,7 @@ export const entry: PaletteEntry = {
112112 title: "Crew hand-overs",
113113 hint: "issues parked twice, and the last restore drill",
114114 after: ["crew-scorecard"],
115 asks: "forge.administer",
115116 offered: (session) => session.user?.isAdmin === true,
116117 run: (session, ctx) => ctx.push(crewHandoverScreen(session, ctx)),
117118 };
src/tui/screens/crewkey.ts +1
@@ -66,6 +66,7 @@ export const entry: PaletteEntry = {
6666 title: "Crew key",
6767 hint: "what the crew runs on; add your own model key",
6868 after: ["subscriptions"],
69 asks: "forge.administer",
6970 offered: isAdmin,
7071 run: (session, ctx) => ctx.push(crewKeyScreen(session, ctx)),
7172 };
src/tui/screens/crewsplits.ts +1
@@ -81,6 +81,7 @@ export const entry: PaletteEntry = {
8181 title: "Crew scorecard",
8282 hint: "agent runs per model and per prompt version",
8383 after: ["usage", "trusted-hosts", "secrets"],
84 asks: "forge.administer",
8485 offered: (session) => session.user?.isAdmin === true,
8586 run: (session, ctx) => ctx.push(crewSplitsScreen(session, ctx)),
8687 };
src/tui/screens/crewtop.ts +1
@@ -159,6 +159,7 @@ export const entry: PaletteEntry = {
159159 title: "Crew now",
160160 hint: "who is on what, what waits, accounts, the week and runs that failed early",
161161 after: ["scorecard"],
162 asks: "forge.administer",
162163 offered: mayReadCrewTop,
163164 run: (session, ctx) => ctx.push(crewTopScreen(session, ctx)),
164165 };
src/tui/screens/dataset.ts +1
@@ -67,6 +67,7 @@ export const entry: PaletteEntry = {
6767 title: "Dataset",
6868 hint: "what the forge's dataset holds, and what it already answers",
6969 after: ["bottleneck", "system"],
70 asks: "forge.administer",
7071 offered: mayRead,
7172 run: (session, ctx) => ctx.push(datasetScreen(session, ctx)),
7273 };
src/tui/screens/design.ts +1
@@ -142,6 +142,7 @@ export const entry: PaletteEntry = {
142142 title: "Design: the forge's theme",
143143 hint: "colours and scales, the AA verdict; publish or revert",
144144 after: ["footing"],
145 asks: "forge.read",
145146 offered: (session) => session.user !== undefined,
146147 run: (session, ctx) => ctx.push(designScreen(session, ctx)),
147148 };
src/tui/screens/devices.ts +1
@@ -182,6 +182,7 @@ export const entry: PaletteEntry = {
182182 title: "Devices",
183183 hint: "LAN printers: model, state, supplies; declare or remove one",
184184 after: ["app-templates"],
185 asks: "forge.administer",
185186 offered: (session) => mayUse(session),
186187 run: (session, ctx) => ctx.push(devicesScreen(session, ctx)),
187188 };
src/tui/screens/disks.ts +1
@@ -69,6 +69,7 @@ export const entry: PaletteEntry = {
6969 title: "Disks",
7070 hint: "machines' disk readings: 30-day write rate and projected rated-TBW date",
7171 after: ["system"],
72 asks: "forge.administer",
7273 offered: (session) => mayHandleDisks(session.user),
7374 run: (session, ctx) => {
7475 const names = readMachines(session.app, session.user);
src/tui/screens/displays.ts +1
@@ -81,6 +81,7 @@ export const entry: PaletteEntry = {
8181 title: "Displays",
8282 hint: "the displays you may read",
8383 after: ["repos"],
84 asks: "forge.read",
8485 offered: (session) => session.user !== undefined,
8586 run: (session, ctx) => ctx.push(displaysScreen(session, ctx)),
8687 };
src/tui/screens/domains.ts +1
@@ -136,6 +136,7 @@ export const entry: PaletteEntry = {
136136 id: "domains",
137137 title: "Failure domains",
138138 hint: "failure domains and their last drill",
139 asks: "forge.administer",
139140 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
140141 run: (session, ctx) => ctx.push(domainsScreen(session, ctx)),
141142 };
src/tui/screens/dotfiles.ts +1
@@ -66,6 +66,7 @@ export const entry: PaletteEntry = {
6666 id: "dotfiles",
6767 title: "Your dotfiles",
6868 hint: "the repository every shell you open copies from",
69 asks: "forge.read",
6970 offered: (session) => session.user !== undefined && session.user.kind !== "agent",
7071 run: (session, ctx) => ctx.push(dotfilesScreen(session, ctx)),
7172 };
src/tui/screens/drift.ts +1
@@ -82,6 +82,7 @@ export const entry: PaletteEntry = {
8282 title: "Drifting pulls",
8383 hint: "open pulls far behind main, and the one action that brings each up to date",
8484 after: ["boards"],
85 asks: "forge.administer",
8586 offered: mayDrift,
8687 run: (session, ctx) => ctx.push(driftScreen(session, ctx)),
8788 };
src/tui/screens/dutybudgets.ts +1
@@ -78,6 +78,7 @@ export const entry: PaletteEntry = {
7878 title: "Set a maintenance duty's budget",
7979 hint: "runs per day and dollars per day a duty may use",
8080 after: ["maintenance-duties", "maintenance-runs"],
81 asks: "forge.administer",
8182 offered: mayAct,
8283 run: (session, ctx) => ctx.push(dutyBudgetScreen(session, ctx)),
8384 };
src/tui/screens/dutyswitch.ts +1
@@ -97,6 +97,7 @@ export const entry: PaletteEntry = {
9797 title: "Pause, resume or dismiss a maintenance duty",
9898 hint: "switch a duty off, or on again after it paused itself",
9999 after: ["maintenance-runs", "maintenance"],
100 asks: "forge.administer",
100101 offered: mayAct,
101102 run: (session, ctx) => ctx.push(dutySwitchScreen(session, ctx)),
102103 };
src/tui/screens/economics.ts +1
@@ -202,6 +202,7 @@ export const entry: PaletteEntry = {
202202 title: "Economics",
203203 hint: "the profit slider's position, the margin, the owned-node label and the prices; change one",
204204 after: ["limits"],
205 asks: "forge.administer",
205206 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
206207 run: (session, ctx) => ctx.push(economicsScreen(session, ctx)),
207208 };
src/tui/screens/edgeonly.ts +1
@@ -57,6 +57,7 @@ export const entry: PaletteEntry = {
5757 id: "edge-only-accounts",
5858 title: "Edge-only accounts",
5959 hint: "who would be locked out if the platform edge sign-in went off",
60 asks: "forge.administer",
6061 offered: isAdmin,
6162 run: (session, ctx) => ctx.push(edgeOnlyScreen(session, ctx)),
6263 };
src/tui/screens/entries.ts +44 −2
@@ -9,6 +9,9 @@
99 * `forge.ts`, never the reverse.
1010 */
1111
12 import { askBeside } from "../../core/access_disagreement.ts";
13 import type { Action } from "../../core/may.ts";
14 import { principalOfUser } from "../../core/principal.ts";
1215 import type { Ctx } from "../app/app.ts";
1316 import type { Command } from "../app/palette.ts";
1417 import type { Session } from "../session.ts";
@@ -29,8 +32,21 @@ export interface PaletteEntry {
2932 * `addEntries` is called.
3033 */
3134 readonly after?: readonly string[];
32 /** Whether this session is offered the entry. */
35 /** Whether this session is offered the entry: the whole answer, callers may ask it alone. */
3336 offered(session: Session): boolean;
37 /**
38 * The part of `offered` that is not who is asking (a file the forge has, a repository with
39 * runs): asked first, and when it says no the entry is not offered and `may` is not asked, so a
40 * screen with nothing to show counts no parting.
41 */
42 shows?(session: Session): boolean;
43 /**
44 * The action `offered` stands for, when its gate is the forge's admin (`forge.administer`) or an
45 * account (`forge.read`, opening a screen): `may` is asked it beside `offered`, which still
46 * decides, and a parting is counted under `terminal <id>` (#18396). An entry gated on anything
47 * else (a grant, a subscription, a telemetry role, or nothing) names none, and says why.
48 */
49 readonly asks?: Action;
3450 run(session: Session, ctx: Ctx): void;
3551 }
3652
@@ -42,13 +58,39 @@ export const ENTRIES: readonly PaletteEntry[] = SCREEN_MODULES.flatMap(([mod, na
4258 (a, b) => a.rank - b.rank,
4359 );
4460
61 /**
outdated

This does a database write per disagreeing entry on every palette build. For a signed-out or agent session that is dozens of upserts each time the palette opens. Ask once per session and entry, or batch the notes.

62 * What each session's palette has asked `may` already: an entry, the account and the gate's answer.
63 * The palette is built on every open, and an answer asked once is not asked again, so a session
64 * writes at most one parting per entry and not one per build.
65 */
66 const asked = new WeakMap<Session, Set<string>>();
67
68 /**
69 * Whether the session is offered `e`: its own gate decides; when the entry names the action that
70 * gate stands for, `may` is asked it beside, once a session, as the screen's account (`none`: the
71 * terminal acts for the person signed in to it), and a parting is counted.
72 */
73 function offers(e: PaletteEntry, session: Session): boolean {
74 if (e.shows?.(session) === false) return false;
75 const old = e.offered(session);
76 if (e.asks === undefined) return old;
77 const key = `${e.id} ${session.user?.id ?? ""} ${session.user?.isAdmin === true} ${old}`;
78 let seen = asked.get(session);
79 if (seen === undefined) asked.set(session, (seen = new Set()));
80 if (!seen.has(key)) {
81 seen.add(key);
82 askBeside(session.app.db, principalOfUser(session.user), `terminal ${e.id}`, e.asks, old);
83 }
84 return old;
85 }
86
4587 /**
4688 * Put each entry the session is offered into `commands`, after the command it names or at the end.
4789 */
4890 export function addEntries(commands: Command[], session: Session, ctx: Ctx): void {
4991 const placed = new Map<string, number>();
5092 for (const e of ENTRIES) {
51 if (!e.offered(session)) continue;
93 if (!offers(e, session)) continue;
5294 const command: Command = { id: e.id, title: e.title, hint: e.hint, run: () => e.run(session, ctx) };
5395 const anchor = e.after?.find((id) => commands.some((c) => c.id === id));
5496 if (anchor === undefined) {
src/tui/screens/experiments.ts +1
@@ -151,6 +151,7 @@ export const entry: PaletteEntry = {
151151 title: "Experiments",
152152 hint: "what each cloud machine costs and answers",
153153 after: ["pinned"],
154 asks: "forge.administer",
154155 offered: (session) => session.user?.isAdmin === true,
155156 run: (session, ctx) => ctx.push(experimentsScreen(session, ctx)),
156157 };
src/tui/screens/featurefeed.ts +1
@@ -121,6 +121,7 @@ export const entry: PaletteEntry = {
121121 title: "Feature feeds",
122122 hint: "the feed items about an absorbed app, as Settings › Features shows them",
123123 after: ["feature-review"],
124 asks: "forge.read",
124125 offered: (session) => session.user !== undefined,
125126 run: (session, ctx) => ctx.push(featureFeedPicker(session, ctx)),
126127 };
src/tui/screens/features.ts +1
@@ -78,6 +78,7 @@ export const entry: PaletteEntry = {
7878 id: "feature-review",
7979 title: "Menu entries to review",
8080 hint: "absorbed apps whose declared name or page changed: accept them",
81 asks: "forge.administer",
8182 offered: mayReview,
8283 run: (session, ctx) => ctx.push(featuresScreen(session, ctx)),
8384 };
src/tui/screens/featureswitch.ts +1
@@ -162,6 +162,7 @@ export const entry: PaletteEntry = {
162162 id: "features",
163163 title: "Features",
164164 hint: "apps that declare a feature: absorb one, change its settings",
165 asks: "forge.administer",
165166 offered: mayFeatures,
166167 run: (session, ctx) => ctx.push(featureSwitchScreen(session, ctx)),
167168 };
src/tui/screens/feed.ts +1
@@ -337,6 +337,7 @@ export const entry: PaletteEntry = {
337337 id: "feed",
338338 title: "Feed",
339339 hint: "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log",
340 asks: "forge.read",
340341 offered: (session) => session.user !== undefined,
341342 run: (session, ctx) => ctx.push(feedScreen(session, ctx)),
342343 };
src/tui/screens/flowsall.ts +1
@@ -72,6 +72,7 @@ export const entry: PaletteEntry = {
7272 title: "Flows across the forge",
7373 hint: "every repository's flow lines, by kind and stale",
7474 after: ["limits"],
75 asks: "forge.administer",
7576 offered: mayRead,
7677 run: (session, ctx) => ctx.push(flowsAllScreen(session, ctx)),
7778 };
src/tui/screens/footing.ts +1
@@ -76,6 +76,7 @@ export const entry: PaletteEntry = {
7676 title: "What the forge stands on",
7777 hint: "each piece on another machine, in the order it would break the forge",
7878 after: ["stalls", "system"],
79 asks: "forge.administer",
7980 offered: mayRead,
8081 run: (session, ctx) => ctx.push(footingScreen(session, ctx)),
8182 };
src/tui/screens/forgeready.ts +1
@@ -17,6 +17,7 @@ export const entry: PaletteEntry = {
1717 hint: "ask whether a forge you sent answers yet",
1818 after: ["forges"],
1919 // Admin only, as `forges` is: the list names every forge this one sent.
20 asks: "forge.administer",
2021 offered: (session) => session.user?.isAdmin === true,
2122 run: (session, ctx: Ctx) =>
2223 runAsync(ctx, async () => {
src/tui/screens/forges.ts +1
@@ -504,6 +504,7 @@ export const entry: PaletteEntry = {
504504 id: "forges",
505505 title: "Forges you sent",
506506 hint: "each forge sent, claimed or not, and its apps",
507 asks: "forge.administer",
507508 offered: (session) => session.user?.isAdmin === true,
508509 run: (session, ctx) => runAsync(ctx, async () => {
509510 ctx.push(forgesScreen(ctx, await clientRows(session.app), session));
src/tui/screens/forgeview.ts +1
@@ -77,6 +77,7 @@ export const entry: PaletteEntry = {
7777 title: "Forge view",
7878 hint: "the forge's counts, and Foundry when it is installed",
7979 after: ["now"],
80 asks: "forge.read",
8081 offered: (session) => session.user !== undefined,
8182 run: (session, ctx) => ctx.push(forgeViewScreen(session, ctx)),
8283 };
src/tui/screens/front.ts +1
@@ -156,6 +156,7 @@ export const entry: PaletteEntry = {
156156 id: "front",
157157 title: "Front page",
158158 hint: "the apps a first visitor sees, ranked; an admin pins or hides",
159 // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside.
159160 offered: () => true,
160161 run: (session, ctx) => ctx.push(frontScreen(session, ctx)),
161162 };
src/tui/screens/frontms.ts +1
@@ -58,6 +58,7 @@ export const entry: PaletteEntry = {
5858 title: "Milestones",
5959 hint: "the biggest open milestones: how far, what landed this week",
6060 after: ["now"],
61 asks: "forge.read",
6162 offered: (f) => f.user !== undefined,
6263 run: (session, ctx) => ctx.push(frontMilestonesScreen(session, ctx)),
6364 };
src/tui/screens/funnel.ts +1
@@ -50,6 +50,7 @@ export const entry: PaletteEntry = {
5050 id: "from-visit-to-paid",
5151 title: "From visit to paid",
5252 hint: "the last 7 days: home visits, plans seen, plan clicks, forges made, paid",
53 asks: "forge.administer",
5354 offered: mayRead,
5455 run: (f, ctx) => ctx.push(funnelScreen(f, ctx)),
5556 };
src/tui/screens/game_config.ts +4 −2
@@ -11,7 +11,9 @@
1111 import { emptyText } from "../../core/empty_words.ts";
1212 import { commitConfig, configsOf, planConfig, planRevertConfig, type ConfigFile, type ConfigPlan } from "../../games/plugin_config.ts";
1313 import type { Result } from "../../games/modrinth.ts";
14 import { mayDo, roleOn, type GameBox } from "../../games/store.ts";
14 import type { GameBox } from "../../games/store.ts";
15 import { mayOnGame } from "../../games/game_may.ts";
16 import { principalOfUser } from "../../core/principal.ts";
1517 import type { Ctx, Screen } from "../app/app.ts";
1618 import { binding } from "../app/keys.ts";
1719 import { style } from "../term/style.ts";
@@ -30,7 +32,7 @@ export function gameConfigScreen(f: Session, ctx: Ctx, box: GameBox, service: st
3032 let pending: ConfigPlan | undefined;
3133 // The text box open on a file, and the path it is for.
3234 let editing: { path: string; text: Textarea } | undefined;
33 const operator = () => mayDo(roleOn(f.app.db, f.user, box.id, service), "operator");
35 const operator = () => mayOnGame(f.app.db, principalOfUser(f.user), "plugin config", box.id, service, "operator");
3436 const say = (words: string): void => {
3537 note = words;
3638 ctx.invalidate();
src/tui/screens/game_map.ts +4 −2
@@ -8,13 +8,15 @@
88 import { askMap, mapPath } from "../../games/map.ts";
99 import { mapLine, refreshMap } from "../../games/map_check.ts";
1010 import { mapPathOf, mapWords } from "../../games/map_words.ts";
11 import { roleOn, mayDo, type GameBox } from "../../games/store.ts";
11 import type { GameBox } from "../../games/store.ts";
1212 import type { Ctx, Screen } from "../app/app.ts";
1313 import { binding } from "../app/keys.ts";
1414 import { style } from "../term/style.ts";
1515 import { truncate, wrap } from "../term/width.ts";
1616 import type { Session } from "../session.ts";
1717 import { fill, len, split } from "../ui/layout.ts";
18 import { principalOfUser } from "../../core/principal.ts";
19 import { mayOnGame } from "../../games/game_may.ts";
1820
1921 export function gameMapScreen(f: Session, ctx: Ctx, box: GameBox, service: string): Screen {
2022 let note = "";
@@ -31,7 +33,7 @@ export function gameMapScreen(f: Session, ctx: Ctx, box: GameBox, service: strin
3133 },
3234 key(e) {
3335 if (e.ctrl || e.alt || e.key !== "p") return false;
34 if (f.user === undefined || !mayDo(roleOn(f.app.db, f.user, box.id, service), "viewer")) note = `You may not see ${service}.`;
36 if (f.user === undefined || !mayOnGame(f.app.db, principalOfUser(f.user), "map", box.id, service, "viewer")) note = `You may not see ${service}.`;
3537 else {
3638 note = "Asking the box…";
3739 const front = mapPath("");
src/tui/screens/game_mods.ts +4 −2
@@ -11,7 +11,9 @@ import { offered, SETS, SET_PREFIX } from "../../games/mod_sets.ts";
1111 import { search, type Hit, type Result } from "../../games/modrinth.ts";
1212 import { commitPlan, modsOf, packUpdateOf, planInstall, planPack, planPackUpdate, planRemove, planUpdate, updatesOf, type Mods, type Plan } from "../../games/mods.ts";
1313 import { makePackLink, packRow, revokeLinks, type PackRow } from "../../games/client_pack.ts";
14 import { mayDo, roleOn, type GameBox } from "../../games/store.ts";
14 import type { GameBox } from "../../games/store.ts";
15 import { mayOnGame } from "../../games/game_may.ts";
16 import { principalOfUser } from "../../core/principal.ts";
1517 import type { Ctx, Screen } from "../app/app.ts";
1618 import { binding } from "../app/keys.ts";
1719 import { style } from "../term/style.ts";
@@ -30,7 +32,7 @@ export function gameModsScreen(f: Session, ctx: Ctx, box: GameBox, service: stri
3032 // The pack row, and a link just made (shown here once, then gone with the next key).
3133 let players: PackRow | undefined;
3234 let link = "";
33 const operator = () => mayDo(roleOn(f.app.db, f.user, box.id, service), "operator");
35 const operator = () => mayOnGame(f.app.db, principalOfUser(f.user), "mods", box.id, service, "operator");
3436 const say = (words: string): void => {
3537 note = words;
3638 ctx.invalidate();
src/tui/screens/game_spark.ts +5 −3
@@ -9,13 +9,15 @@
99 import { publicOrigin } from "../../core/public_origin.ts";
1010 import { sparkFindingsOf } from "../../games/spark_finding.ts";
1111 import { SPARK_WORDS, newSparkSecret, profilesOf, sparkBase } from "../../games/spark.ts";
12 import { mayDo, roleOn, type GameBox } from "../../games/store.ts";
12 import type { GameBox } from "../../games/store.ts";
1313 import type { Ctx, Screen } from "../app/app.ts";
1414 import { binding } from "../app/keys.ts";
1515 import { style } from "../term/style.ts";
1616 import { truncate, wrap } from "../term/width.ts";
1717 import type { Session } from "../session.ts";
1818 import { gameSparkViewScreen } from "./game_spark_view.ts";
19 import { principalOfUser } from "../../core/principal.ts";
20 import { mayOnGame } from "../../games/game_may.ts";
1921
2022 export function gameSparkScreen(f: Session, ctx: Ctx, box: GameBox): Screen {
2123 let address = "";
@@ -45,11 +47,11 @@ export function gameSparkScreen(f: Session, ctx: Ctx, box: GameBox): Screen {
4547 } else if (e.key === "k" || e.key === "up") {
4648 at = Math.max(0, at - 1);
4749 } else if (e.key === "enter") {
48 if (stored[at] === undefined || !mayDo(roleOn(f.app.db, f.user, box.id), "viewer")) return false;
50 if (stored[at] === undefined || !mayOnGame(f.app.db, principalOfUser(f.user), "spark", box.id, "", "viewer")) return false;
4951 ctx.push(gameSparkViewScreen(f, ctx, box, stored[at]!.key));
5052 return true;
5153 } else if (e.key === "u") {
52 if (!mayDo(roleOn(f.app.db, f.user, box.id), "owner")) return false;
54 if (!mayOnGame(f.app.db, principalOfUser(f.user), "spark_link", box.id, "", "owner")) return false;
5355 address = sparkBase(publicOrigin(f.app.config.url, `http://localhost:${String(f.app.config.port)}`), newSparkSecret(f.app.db, box.id));
5456 } else {
5557 return false;
src/tui/screens/games.ts +16 −12
@@ -79,6 +79,8 @@ import { gameMapScreen } from "./game_map.ts";
7979 import { gameConfigScreen } from "./game_config.ts";
8080 import { gameModsScreen } from "./game_mods.ts";
8181 import { gameSparkScreen } from "./game_spark.ts";
82 import { principalOfUser } from "../../core/principal.ts";
83 import { mayOnGame } from "../../games/game_may.ts";
8284
8385 /** "4 online · 19.8 TPS · 3.1 ms tick" from the last hour's numbers, or nothing before any. */
8486 function playersTps(f: Session, box: { id: string }, service: string): string[] {
@@ -218,7 +220,7 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen {
218220 return true;
219221 }
220222 if (at !== undefined && !e.ctrl && !e.alt && e.key === "!") {
221 if (!mayDo(roleOn(f.app.db, f.user, at.box.id), "owner")) note = `Only the owner of ${at.box.name} runs a shell on it.`;
223 if (!mayOnGame(f.app.db, principalOfUser(f.user), "shell", at.box.id, "", "owner")) note = `Only the owner of ${at.box.name} runs a shell on it.`;
222224 else ctx.push(gameShellScreen(f, ctx, at.box));
223225 ctx.invalidate();
224226 return true;
@@ -244,8 +246,8 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen {
244246 return true;
245247 }
246248 if (!e.ctrl && !e.alt && e.key === "n") {
247 const box = at?.box ?? listBoxes(f.app.db).find((b) => mayDo(roleOn(f.app.db, f.user, b.id), "operator"));
248 if (box === undefined || !mayDo(roleOn(f.app.db, f.user, box.id), "operator")) note = "You run no game box to add a server to.";
249 const box = at?.box ?? listBoxes(f.app.db).find((b) => mayOnGame(f.app.db, principalOfUser(f.user), "create_server", b.id, "", "operator"));
250 if (box === undefined || !mayOnGame(f.app.db, principalOfUser(f.user), "create_server", box.id, "", "operator")) note = "You run no game box to add a server to.";
249251 else
250252 ctx.push(
251253 promptScreen(ctx, screen, {
@@ -262,13 +264,13 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen {
262264 // The selected server out of the network: the plan shown, yes commits; its world is kept.
263265 if (at !== undefined && !e.ctrl && !e.alt && e.key === "d") {
264266 const { box, service } = at;
265 if (!mayDo(roleOn(f.app.db, f.user, box.id), "operator")) note = `You are not an operator of ${box.name}.`;
267 if (!mayOnGame(f.app.db, principalOfUser(f.user), "remove_server", box.id, "", "operator")) note = `You are not an operator of ${box.name}.`;
266268 else void ctx.track(planRemoveServer(f.app, box, service.name).then((planned) => showPlan(box, `Remove ${service.name} from ${box.name}`, "Remove it", planned)));
267269 ctx.invalidate();
268270 return true;
269271 }
270272 if (at !== undefined && !e.ctrl && !e.alt && e.key === "z") {
271 if (!mayDo(roleOn(f.app.db, f.user, at.box.id, at.service.name), "operator")) note = `You are not an operator of ${at.service.name}.`;
273 if (!mayOnGame(f.app.db, principalOfUser(f.user), "sleep", at.box.id, at.service.name, "operator")) note = `You are not an operator of ${at.service.name}.`;
272274 else {
273275 const { box, service } = at;
274276 note = `${box.name}/${service.name}: saving…`;
@@ -285,7 +287,7 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen {
285287 }
286288 const kind: Power | undefined = e.key === "s" ? "start" : e.key === "x" ? "stop" : e.key === "r" ? "restart" : undefined;
287289 if (kind === undefined || at === undefined || e.ctrl || e.alt) return false;
288 if (!mayDo(roleOn(f.app.db, f.user, at.box.id, at.service.name), "operator")) note = `You are not an operator of ${at.service.name}.`;
290 if (!mayOnGame(f.app.db, principalOfUser(f.user), kind, at.box.id, at.service.name, "operator")) note = `You are not an operator of ${at.service.name}.`;
289291 else {
290292 const { box, service } = at;
291293 void askPower(f.app, f.user, box, service.name, kind)
@@ -343,7 +345,7 @@ export function gameServiceScreen(f: Session, ctx: Ctx, box: GameBox, service: s
343345 let note = "";
344346 let compose: string | undefined;
345347 let loaded = false;
346 const operator = () => mayDo(roleOn(f.app.db, f.user, box.id, service), "operator");
348 const operator = () => mayOnGame(f.app.db, principalOfUser(f.user), "server", box.id, service, "operator");
347349 const load = async (): Promise<void> => {
348350 compose = (await readCompose(f.app, box))?.text;
349351 loaded = true;
@@ -525,7 +527,7 @@ export function gameSettingsScreen(f: Session, ctx: Ctx, box: GameBox, service:
525527 let values: SettingValue[] = [];
526528 let wanted: Record<string, string> = {};
527529 let plan: (SettingsPlan & { sha: string }) | undefined;
528 const operator = () => mayDo(roleOn(f.app.db, f.user, box.id, service), "operator");
530 const operator = () => mayOnGame(f.app.db, principalOfUser(f.user), "settings", box.id, service, "operator");
529531 const load = async (): Promise<void> => {
530532 compose = await readCompose(f.app, box);
531533 values = compose === undefined ? [] : settingsOf(compose.text, service, serviceEnv(compose.text, service));
@@ -675,12 +677,12 @@ export function gameBoxScreen(f: Session, ctx: Ctx, box: GameBox): Screen {
675677 else if (e.key === "p") {
676678 ctx.push(gameSparkScreen(f, ctx, box));
677679 return true;
678 } else if (e.key === "l" && mayDo(roleOn(f.app.db, f.user, box.id), "owner") && f.user !== undefined) {
680 } else if (e.key === "l" && mayOnGame(f.app.db, principalOfUser(f.user), "lend", box.id, "", "owner") && f.user !== undefined) {
679681 const b = listBoxes(f.app.db).find((x) => x.id === box.id) ?? box;
680682 setLend(f.app.db, b, lentRunnerOf(f.app.db, b.id) === undefined, f.user.id);
681 } else if (e.key === "w" && mayDo(roleOn(f.app.db, f.user, box.id), "owner") && f.user !== undefined) {
683 } else if (e.key === "w" && mayOnGame(f.app.db, principalOfUser(f.user), "door", box.id, "", "owner") && f.user !== undefined) {
682684 lockDoor(f.app.db, box.id, f.user.id);
683 } else if (e.key === "a" && mayDo(roleOn(f.app.db, f.user, box.id), "owner")) {
685 } else if (e.key === "a" && mayOnGame(f.app.db, principalOfUser(f.user), "lock on leave", box.id, "", "owner")) {
684686 setLocksOnLeave(f.app.db, box.id, !locksOnLeave(f.app.db, box.id));
685687 } else return false;
686688 ctx.invalidate();
@@ -693,7 +695,7 @@ export function gameBoxScreen(f: Session, ctx: Ctx, box: GameBox): Screen {
693695 export function gameGrantsScreen(f: Session, ctx: Ctx, box: GameBox): Screen {
694696 const state = new ListState();
695697 let note = "";
696 const owner = () => mayDo(roleOn(f.app.db, f.user, box.id), "owner");
698 const owner = () => mayOnGame(f.app.db, principalOfUser(f.user), "grants", box.id, "", "owner");
697699 const screen: Screen = {
698700 title: `${box.name} grants`,
699701 keys: [binding(["j", "k"], "move cursor"), binding(["a"], "grant")],
@@ -793,6 +795,8 @@ export const entry: PaletteEntry = {
793795 title: "Games",
794796 hint: "game servers on your cloud: state, start, stop, restart",
795797 after: ["pinned"],
798 // Names no `asks`: the gate is a game grant; each box's grant is asked `game.*` in
799 // `games/game_may.ts`.
796800 offered: (session) => seesAnyBox(session.app.db, session.user),
797801 run: (session, ctx) => ctx.push(gamesScreen(session, ctx)),
798802 };
src/tui/screens/gifts.ts +1
@@ -60,6 +60,7 @@ export const entry: PaletteEntry = {
6060 id: "gifts",
6161 title: "Gifts",
6262 hint: "give a friend a forge with one link, and see who came",
63 // Names no `asks`: the gate is a subscription, which `may` has no action for.
6364 offered: (f) => f.user !== undefined && isSubscriber(f.app, f.user),
6465 run: (session, ctx) => ctx.push(giftsScreen(session, ctx)),
6566 };
src/tui/screens/health_voice.ts +1
@@ -36,6 +36,7 @@ export const entry: PaletteEntry = {
3636 title: "Health — spoken",
3737 hint: "how the forge is, in two plain sentences",
3838 after: ["system", "flow", "boards"],
39 // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside.
3940 offered: () => true,
4041 run: (session, ctx) => ctx.push(healthVoiceScreen(session, ctx)),
4142 };
src/tui/screens/home_pins.ts +1
@@ -90,6 +90,7 @@ export const entry: PaletteEntry = {
9090 title: "Pinned panels",
9191 hint: "the panels pinned to home: reorder and unpin",
9292 after: ["boards"],
93 asks: "forge.administer",
9394 offered: mayPin,
9495 run: (session, ctx) => ctx.push(homePinsScreen(session, ctx)),
9596 };
src/tui/screens/hostreach.ts +1
@@ -183,6 +183,7 @@ export const entry: PaletteEntry = {
183183 title: "What hosted forges may reach",
184184 hint: "answer what a hosted forge asked to reach, and take a grant back",
185185 after: ["forges"],
186 asks: "forge.administer",
186187 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
187188 run: (session, ctx) => ctx.push(hostReachScreen(session, ctx)),
188189 };
src/tui/screens/infra.ts +1
@@ -693,6 +693,7 @@ export const entry: PaletteEntry = {
693693 title: "Infrastructure",
694694 hint: "what runs on your own cloud, what it costs, when it ends",
695695 after: ["cloud"],
696 asks: "forge.administer",
696697 offered: (session) => session.user?.isAdmin === true,
697698 run: (session, ctx) => ctx.push(infraScreen(session, ctx)),
698699 };
src/tui/screens/inventory.ts +1
@@ -118,6 +118,7 @@ export const entry: PaletteEntry = {
118118 title: "What is left to bring over",
119119 hint: "every repository on your connected accounts, what it holds, where its move stands",
120120 after: ["migrate"],
121 asks: "forge.read",
121122 offered: (session) => session.user !== undefined,
122123 run: (session, ctx) => ctx.push(inventoryScreen(session, ctx)),
123124 };
src/tui/screens/invites.ts +1
@@ -220,6 +220,7 @@ export const entry: PaletteEntry = {
220220 title: "Invite links",
221221 hint: "make a single-use link, see which are open, revoke one",
222222 after: ["teams", "limits", "quotas", "people", "can"],
223 asks: "forge.administer",
223224 offered: (session) => session.user?.isAdmin === true && session.user.kind === "user",
224225 run: (session, ctx) => ctx.push(invitesScreen(session, ctx)),
225226 };
src/tui/screens/knobs.ts +1
@@ -70,6 +70,7 @@ export const entry: PaletteEntry = {
7070 title: "Knobs",
7171 hint: "speed, weekly budget, polish, autonomy, feedback first",
7272 after: ["crew-scorecard", "usage"],
73 asks: "forge.administer",
7374 offered: (session) => session.user?.isAdmin === true,
7475 run: (session, ctx) => ctx.push(knobsScreen(session, ctx)),
7576 };
src/tui/screens/lapsed.ts +1
@@ -94,6 +94,7 @@ export const entry: PaletteEntry = {
9494 title: "Lapsed forges",
9595 hint: "forges asleep until paid, when their data goes, pay again",
9696 after: ["billing"],
97 asks: "forge.administer",
9798 offered: isAdmin,
9899 run: (session, ctx) => ctx.push(lapsedScreen(session, ctx)),
99100 };
src/tui/screens/limits.ts +1
@@ -110,6 +110,7 @@ export const entry: PaletteEntry = {
110110 title: "Limits",
111111 hint: "what the forge caps, with default and bounds; change one",
112112 after: ["quotas", "people", "can"],
113 asks: "forge.administer",
113114 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
114115 run: (session, ctx) => ctx.push(limitsScreen(session, ctx)),
115116 };
src/tui/screens/loopstalls.ts +1
@@ -149,6 +149,7 @@ export const entry: PaletteEntry = {
149149 title: "Main-thread stalls",
150150 hint: "the last hour's stall ms by route",
151151 after: ["system"],
152 asks: "forge.administer",
152153 offered: mayRead,
153154 run: (session, ctx) => ctx.push(stallsScreen(session, ctx)),
154155 };
src/tui/screens/madefrom.ts +2
@@ -42,6 +42,8 @@ export const entry: PaletteEntry = {
4242 title: "Started from",
4343 hint: "the template and commit this forge was made from",
4444 after: ["plan-row"],
45 asks: "forge.read",
46 shows: (session) => madeFromOf(session.app.config.dataDir) !== undefined,
4547 offered: (session) => session.signedIn && madeFromOf(session.app.config.dataDir) !== undefined,
4648 run: (session, ctx) => ctx.push(madeFromScreen(session, ctx)),
4749 };
src/tui/screens/maintainruns.ts +1
@@ -33,6 +33,7 @@ export const entry: PaletteEntry = {
3333 title: "Maintenance duty runs",
3434 hint: "what each duty found, did and probed",
3535 after: ["maintenance"],
36 asks: "forge.administer",
3637 offered: mayRead,
3738 run: (session, ctx) => ctx.push(maintainRunsScreen(session, ctx)),
3839 };
src/tui/screens/maintenance.ts +1
@@ -280,6 +280,7 @@ export const entry: PaletteEntry = {
280280 title: "Maintenance",
281281 hint: "prepare the forge for a power-off, check the drain, or end maintenance",
282282 after: ["resilience", "capacity", "flow", "sentinel"],
283 asks: "forge.administer",
283284 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
284285 run: (session, ctx) => ctx.push(maintenanceScreen(session, ctx)),
285286 };
src/tui/screens/maintenanceweek.ts +2
@@ -39,6 +39,8 @@ export const entry: PaletteEntry = {
3939 title: "Maintenance, last 7 days",
4040 hint: "what each maintenance worker found and did this week",
4141 after: ["footing", "stalls", "system"],
42 // Names no `asks`: the gate is a telemetry role (`telemetryReader`), which `may` has no action
43 // for.
4244 offered: mayRead,
4345 run: (session, ctx) => ctx.push(weekScreen(session, ctx)),
4446 };
src/tui/screens/mergedbranches.ts +1
@@ -78,6 +78,7 @@ export const entry: PaletteEntry = {
7878 title: "Branches of pulls merged over 7 days ago",
7979 hint: "delete the merged pulls' branches in one receipted step",
8080 after: ["maintenance", "maintenance-runs", "stale-pulls"],
81 asks: "forge.administer",
8182 offered: mayAct,
8283 run: (session, ctx) => ctx.push(mergedBranchesScreen(session, ctx)),
8384 };
src/tui/screens/mirrorpacks.ts +1
@@ -67,6 +67,7 @@ export const entry: PaletteEntry = {
6767 title: "Mirror the packs' upstreams",
6868 hint: "bring each pack's upstream projects in as read-only repositories",
6969 after: ["packs"],
70 asks: "forge.administer",
7071 offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent",
7172 run: (session, ctx) => ctx.push(mirrorPacksScreen(session, ctx)),
7273 };
src/tui/screens/model.ts +2
@@ -365,6 +365,7 @@ export const modelGrantEntry: PaletteEntry = {
365365 title: "Model grant",
366366 hint: "give an account dollars a month, or take it back",
367367 after: ["model"],
368 asks: "forge.administer",
368369 offered: (session) => session.user?.isAdmin === true && session.user.kind === "user",
369370 run: (session, ctx) => ctx.push(modelGrantPrompt(session, ctx, blank("Model grant"))),
370371 };
@@ -376,6 +377,7 @@ export const modelCeilingEntry: PaletteEntry = {
376377 title: "Model ceiling",
377378 hint: "set an account's dollars a day and a run",
378379 after: ["model-grant"],
380 asks: "forge.administer",
379381 offered: (session) => session.user?.isAdmin === true && session.user.kind === "user",
380382 run: (session, ctx) => ctx.push(modelCeilingPrompt(session, ctx, blank("Model ceiling"))),
381383 };
src/tui/screens/money.ts +1
@@ -99,6 +99,7 @@ export const entry: PaletteEntry = {
9999 title: "Money",
100100 hint: "this month's cost, revenue and gap, and the last 30 days",
101101 after: ["economics"],
102 asks: "forge.administer",
102103 offered: (f) => f.user?.isAdmin === true && f.user.kind !== "agent",
103104 run: (f, ctx) => ctx.push(moneyScreen(f, ctx)),
104105 };

55 more files not shown.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs