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
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
155 files
changed +662
−69
- docs/features/may.md
- src/contract/openapi/routes/getApiV1May.ts
- src/core/access_disagreement.ts
- src/core/may.ts
- src/games/game_may.ts
- src/games/store.ts
- src/http/api/game_door.ts
- src/http/api/may.ts
- src/http/games_map.ts
- src/http/may_beside.ts
- src/http/mcp/tools/games.ts
- src/tui/screens/abstractions.ts
- src/tui/screens/access.ts
- src/tui/screens/account_access.ts
- src/tui/screens/advisories.ts
- src/tui/screens/agents.ts
- src/tui/screens/app_templates.ts
- src/tui/screens/appleusage.ts
- src/tui/screens/apps_crew.ts
- src/tui/screens/archived.ts
- src/tui/screens/ask_data.ts
- src/tui/screens/audit.ts
- src/tui/screens/bets.ts
- src/tui/screens/billing.ts
- src/tui/screens/billinglinks.ts
- src/tui/screens/bills.ts
- src/tui/screens/boards.ts
- src/tui/screens/bottleneck.ts
- src/tui/screens/buckets.ts
- src/tui/screens/budgets.ts
- src/tui/screens/bugs.ts
- src/tui/screens/bulk.ts
- src/tui/screens/childcredit.ts
- src/tui/screens/claim_link.ts
- src/tui/screens/claim_start.ts
- src/tui/screens/client_clouds.ts
- src/tui/screens/cloud.ts
- src/tui/screens/cloudcost.ts
- src/tui/screens/cloudtree.ts
- src/tui/screens/codes.ts
- src/tui/screens/connections.ts
- src/tui/screens/controls.ts
- src/tui/screens/cores.ts
- src/tui/screens/crewbudgets.ts
- src/tui/screens/crewfallback.ts
- src/tui/screens/crewhandover.ts
- src/tui/screens/crewkey.ts
- src/tui/screens/crewsplits.ts
- src/tui/screens/crewtop.ts
- src/tui/screens/dataset.ts
- src/tui/screens/design.ts
- src/tui/screens/design_gallery.ts
- src/tui/screens/devices.ts
- src/tui/screens/disks.ts
- src/tui/screens/displays.ts
- src/tui/screens/domains.ts
- src/tui/screens/dotfiles.ts
- src/tui/screens/drift.ts
- src/tui/screens/dutybudgets.ts
- src/tui/screens/dutyswitch.ts
- src/tui/screens/economics.ts
- src/tui/screens/edgeonly.ts
- src/tui/screens/entries.ts
- src/tui/screens/experiments.ts
- src/tui/screens/featurefeed.ts
- src/tui/screens/features.ts
- src/tui/screens/featureswitch.ts
- src/tui/screens/feed.ts
- src/tui/screens/flowsall.ts
- src/tui/screens/footing.ts
- src/tui/screens/forgeready.ts
- src/tui/screens/forges.ts
- src/tui/screens/forgeview.ts
- src/tui/screens/front.ts
- src/tui/screens/frontms.ts
- src/tui/screens/funnel.ts
- src/tui/screens/game_config.ts
- src/tui/screens/game_map.ts
- src/tui/screens/game_mods.ts
- src/tui/screens/game_spark.ts
- src/tui/screens/games.ts
- src/tui/screens/gifts.ts
- src/tui/screens/health_voice.ts
- src/tui/screens/home_pins.ts
- src/tui/screens/hostreach.ts
- src/tui/screens/infra.ts
- src/tui/screens/inventory.ts
- src/tui/screens/invites.ts
- src/tui/screens/knobs.ts
- src/tui/screens/lapsed.ts
- src/tui/screens/limits.ts
- src/tui/screens/loopstalls.ts
- src/tui/screens/madefrom.ts
- src/tui/screens/maintainruns.ts
- src/tui/screens/maintenance.ts
- src/tui/screens/maintenanceweek.ts
- src/tui/screens/mergedbranches.ts
- src/tui/screens/mirrorpacks.ts
- src/tui/screens/model.ts
- src/tui/screens/money.ts
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, | ||
| 13 | 13 | |
| 14 | 14 | Actions are named in one registry (`ACTIONS`), each with one sentence: `repo.read`, `repo.write`, `repo.admin` (over a |
| 15 | 15 | 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). | |
| 17 | 19 | |
| 18 | 20 | **API.** `GET /api/v1/user` carries `can`: the forge-wide actions you may take. |
| 19 | 21 | |
| @@ -23,8 +25,8 @@ curl -H "authorization: Bearer $TOKEN" "$FORGE/api/v1/may?action=repo.write&reso | ||
| 23 | 25 | "may": false, "why": "forbidden", "reason": "Your account may not do this." } |
| 24 | 26 | |
| 25 | 27 | |
| 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. | |
| 28 | 30 | |
| 29 | 31 | **MCP.** `whoami_can` lists `actions`, the same names; `repo` adds read, write and admin there. |
| 30 | 32 | |
| @@ -52,3 +54,26 @@ An anonymous visit to a signed-in page parts on `forge.read`, which is open to a | ||
| 52 | 54 | than reading. The page's old check (`isAdmin`, an account |
| 53 | 55 | behind the request) still decides; `may` is worked out beside it, and where the two part the count's door is |
| 54 | 56 | `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 = { | ||
| 6 | 6 | path: "/api/v1/may", |
| 7 | 7 | summary: "Ask whether you may take an action, with the reason in words", |
| 8 | 8 | 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.", | |
| 10 | 10 | auth: false, |
| 11 | 11 | role: "anonymous", |
| 12 | 12 | query: { action: "string", resource: "string" }, |
| @@ -18,6 +18,6 @@ export const route: Route = { | ||
| 18 | 18 | refusals: { |
| 19 | 19 | invalid_token: "401, a bearer or basic credential was sent and matches no account or token: sign in again; send none to be anonymous", |
| 20 | 20 | 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", | |
| 22 | 22 | }, |
| 23 | 23 | }; |
src/core/access_disagreement.ts +13 −2
| @@ -12,8 +12,8 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | 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"; | |
| 17 | 17 | import { quietly } from "./write_clock.ts"; |
| 18 | 18 | |
| 19 | 19 | /** Count one disagreement: `may` said `said`, the old check said the opposite. */ |
| @@ -32,3 +32,14 @@ export function noteDisagreement( | ||
| 32 | 32 | ).run(door, action, principal, said ? 1 : 0, new Date().toISOString()), |
| 33 | 33 | ); |
| 34 | 34 | } |
| 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 @@ | ||
| 3 | 3 | * (`core/principal.ts`: `principalOf(auth)` for a request, `principalOfUser(user)` for a check made |
| 4 | 4 | * on someone's behalf), the action is a name in |
| 5 | 5 | * `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 | |
| 7 | 8 | * existing answers applies: `not_found` (what you may not read does not exist for you), |
| 8 | 9 | * `unauthorized` (sign in) or `forbidden`. |
| 9 | 10 | * |
| @@ -20,16 +21,31 @@ import { userOf, type Principal } from "./principal.ts"; | ||
| 20 | 21 | import { scopeAllows, type TokenScope } from "./tokens.ts"; |
| 21 | 22 | import type { User } from "./users.ts"; |
| 22 | 23 | |
| 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; | |
| 26 | 39 | } |
| 27 | 40 | |
| 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 | ||
| 28 | 44 | interface ActionRow { |
| 29 | 45 | /** One sentence a person can read. */ |
| 30 | 46 | readonly says: string; |
| 31 | 47 | /** What it is over: a repository, or the forge as a whole. */ |
| 32 | readonly over: "repo" | "forge"; | |
| 48 | readonly over: "repo" | "forge" | "game"; | |
| 33 | 49 | /** The scope a token must hold: reading needs `ro`, anything that changes something `rw`. */ |
| 34 | 50 | readonly scope: TokenScope; |
| 35 | 51 | } |
| @@ -56,6 +72,9 @@ export const ACTIONS = { | ||
| 56 | 72 | scope: "rw", |
| 57 | 73 | }, |
| 58 | 74 | "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" }, | |
| 59 | 78 | } as const satisfies Record<string, ActionRow>; |
| 60 | 79 | export type Action = keyof typeof ACTIONS; |
| 61 | 80 | |
| @@ -95,6 +114,27 @@ function repoRuleHolds(db: Database, action: Action, repo: Repo, user: User | un | ||
| 95 | 114 | return adminsRepo(db, repo, user); |
| 96 | 115 | } |
| 97 | 116 | |
| 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 | ||
| 98 | 138 | function forgeRuleHolds(db: Database, action: Action, p: Principal): boolean { |
| 99 | 139 | const ability = ABILITY_OF[action]; |
| 100 | 140 | if (ability === "read") return true; |
| @@ -117,7 +157,7 @@ function forgeRuleHolds(db: Database, action: Action, p: Principal): boolean { | ||
| 117 | 157 | */ |
| 118 | 158 | export function holds(db: Database, p: Principal, action: Action, resource?: Resource): boolean { |
| 119 | 159 | 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); | |
| 121 | 161 | // Only a token carries a scope; the account itself acts with all of its own authority. |
| 122 | 162 | return held && (!("scope" in p) || scopeAllows(p.scope, row.scope)); |
| 123 | 163 | } |
| @@ -128,10 +168,12 @@ export function may(db: Database, p: Principal, action: Action, resource?: Resou | ||
| 128 | 168 | if (holds(db, p, action, resource)) return yes; |
| 129 | 169 | if (action === "account.manage") return no(user === undefined ? "unauthorized" : "forbidden", BROWSER_WORDS); |
| 130 | 170 | // 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"); | |
| 132 | 174 | if (user === undefined) return no("unauthorized"); |
| 133 | 175 | // 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); | |
| 135 | 177 | return no("forbidden", held ? SCOPE_WORDS : undefined); |
| 136 | 178 | } |
| 137 | 179 |
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"; | ||
| 19 | 19 | import { existsAtProvider } from "../cloud/billing.ts"; |
| 20 | 20 | import { getPinned } from "../core/pinned.ts"; |
| 21 | 21 | import { resolveSecrets, setSecret } from "../core/secret_store.ts"; |
| 22 | import { gameRank, type GameRole } from "../core/may.ts"; | |
| 22 | 23 | import type { User } from "../core/users.ts"; |
| 23 | 24 | import { sha256 } from "../kernel/hash.ts"; |
| 24 | 25 | import { id as newId } from "../kernel/id.ts"; |
| @@ -39,8 +40,8 @@ const OUTPUT_MAX = 16_384; | ||
| 39 | 40 | const MAP_OUTPUT_MAX = 820_000; |
| 40 | 41 | export const COMMAND_KINDS = ["rcon", "restart", "stop", "start", "recreate", "pull", "shell", "people", "world", "hashes", "tell", "map"] as const; |
| 41 | 42 | 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; | |
| 44 | 45 | |
| 45 | 46 | export interface GameBox { |
| 46 | 47 | readonly id: string; |
| @@ -279,6 +280,12 @@ export const isWaker = (service: string): boolean => service === WAKER; | ||
| 279 | 280 | export function roleOn(db: Database, user: User | undefined, boxId: string, service = ""): Role | undefined { |
| 280 | 281 | if (user === undefined || isWaker(service)) return undefined; |
| 281 | 282 | 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; | |
| 282 | 289 | const rows = db |
| 283 | 290 | .query< |
| 284 | 291 | { role: Role }, |
| @@ -286,10 +293,10 @@ export function roleOn(db: Database, user: User | undefined, boxId: string, serv | ||
| 286 | 293 | >("SELECT role FROM game_grant WHERE box_id = ?1 AND user_id = ?2 AND (service = '' OR service = ?3)") |
| 287 | 294 | .all(boxId, user.id, service); |
| 288 | 295 | 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; | |
| 290 | 297 | return best; |
| 291 | 298 | } |
| 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); | |
| 293 | 300 | |
| 294 | 301 | /** The box-wide owners, not forge admins, of each game box on the machine `pinnedId` names. */ |
| 295 | 302 | export const boxOwnersOfMachine = (db: Database, pinnedId: string): { userId: string; box: string }[] => |
src/http/api/game_door.ts +4 −2
| @@ -9,17 +9,19 @@ | ||
| 9 | 9 | |
| 10 | 10 | import { passkeyProves, proofChallenge, PROOF_FIELDS } from "../../actions/passkey_proof.ts"; |
| 11 | 11 | import { getUserById } from "../../core/users.ts"; |
| 12 | import { boxNamed, mayDo, roleOn } from "../../games/store.ts"; | |
| 12 | import { boxNamed } from "../../games/store.ts"; | |
| 13 | 13 | import { doorOf, doorWords, lockDoor, openWindow } from "../../games/write_window.ts"; |
| 14 | 14 | import type { Ctx, Handler } from "../context.ts"; |
| 15 | 15 | import { apiError, body, json, notFound, requireScope } from "../respond.ts"; |
| 16 | 16 | import type { Router } from "../router.ts"; |
| 17 | import { principalOf } from "../../core/principal.ts"; | |
| 18 | import { mayOnGame } from "../../games/game_may.ts"; | |
| 17 | 19 | |
| 18 | 20 | /** The box when the caller owns it. */ |
| 19 | 21 | function ownedBox(ctx: Ctx) { |
| 20 | 22 | const user = ctx.auth.user; |
| 21 | 23 | 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; | |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | /** 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 @@ | ||
| 2 | 2 | * `GET /api/v1/may?action=…&resource=owner/name`: one cheap read of what this caller may do, so a |
| 3 | 3 | * client asks instead of reading a role. The answer is `may` (`core/may.ts`): yes, or no with the |
| 4 | 4 | * 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. | |
| 6 | 7 | */ |
| 7 | 8 | |
| 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"; | |
| 10 | 11 | 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"; | |
| 11 | 14 | import { INVALID_TOKEN_HINT, INVALID_TOKEN_WORDS } from "../../actions/here.ts"; |
| 12 | 15 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 13 | 16 | import type { Handler } from "../context.ts"; |
| @@ -17,6 +20,9 @@ import type { Router } from "../router.ts"; | ||
| 17 | 20 | /** `owner/name`, each part a repository name's characters and no longer than one may be. */ |
| 18 | 21 | const REPO_RESOURCE = /^([A-Za-z0-9._-]{1,100})\/([A-Za-z0-9._-]{1,100})$/; |
| 19 | 22 | |
| 23 | /** `box` or `box/service`; each part is checked against its own pattern after. */ | |
| 24 | const GAME_RESOURCE = /^([^/]{1,64})(?:\/([^/]{1,64}))?$/; | |
| 25 | ||
| 20 | 26 | const names = (): string => (Object.keys(ACTIONS) as Action[]).join(", "); |
| 21 | 27 | |
| 22 | 28 | export function mayRoutes(router: Router<Handler>): void { |
| @@ -28,17 +34,25 @@ export function mayRoutes(router: Router<Handler>): void { | ||
| 28 | 34 | if (!isAction(action)) return apiError("unknown_action", 422, `action is one of: ${names()}`); |
| 29 | 35 | const resource = ctx.url.searchParams.get("resource") ?? undefined; |
| 30 | 36 | const row = ACTIONS[action]; |
| 31 | let repo; | |
| 37 | const asking = principalOf(ctx.auth); | |
| 38 | let over: Resource | undefined; | |
| 32 | 39 | if (row.over === "forge") { |
| 33 | 40 | 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] ?? ""); | |
| 34 | 47 | } else { |
| 35 | 48 | const named = resource === undefined ? null : REPO_RESOURCE.exec(resource); |
| 36 | 49 | 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 }; | |
| 38 | 52 | } |
| 39 | const answer = row.over === "repo" && repo === undefined | |
| 53 | const answer = row.over !== "forge" && over === undefined | |
| 40 | 54 | ? ({ 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); | |
| 42 | 56 | return json( |
| 43 | 57 | { |
| 44 | 58 | action, |
src/http/games_map.ts +4 −2
| @@ -12,11 +12,13 @@ | ||
| 12 | 12 | |
| 13 | 13 | import { askMap, mapPath } from "../games/map.ts"; |
| 14 | 14 | 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"; | |
| 16 | 16 | import { getUserById } from "../core/users.ts"; |
| 17 | 17 | import { boxOf } from "../web/pages/games.ts"; |
| 18 | 18 | import type { Ctx } from "./context.ts"; |
| 19 | 19 | import { securityFloor } from "./respond.ts"; |
| 20 | import { principalOfUser } from "../core/principal.ts"; | |
| 21 | import { mayOnGame } from "../games/game_may.ts"; | |
| 20 | 22 | |
| 21 | 23 | /** |
| 22 | 24 | * 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> { | ||
| 53 | 55 | const userId = box === undefined ? undefined : passUser(ctx.app.config.dataDir, box.id, service, ctx.params.pass ?? ""); |
| 54 | 56 | const user = userId === undefined ? undefined : getUserById(ctx.app.db, userId); |
| 55 | 57 | // 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"); | |
| 57 | 59 | if (!servicesOf(ctx.app.db, box.id).some((s) => s.name === service)) return refuse(404, "no such server"); |
| 58 | 60 | const ask = mapPath(ctx.params.path ?? ""); |
| 59 | 61 | if (!ask.ok) return refuse(404, ask.error); |
src/http/may_beside.ts +3 −6
| @@ -5,14 +5,11 @@ | ||
| 5 | 5 | * door still in shadow returns its old answer itself. |
| 6 | 6 | */ |
| 7 | 7 | |
| 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"; | |
| 10 | 10 | import { principalOf } from "../core/principal.ts"; |
| 11 | 11 | import type { Ctx } from "./context.ts"; |
| 12 | 12 | |
| 13 | 13 | 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); | |
| 18 | 15 | } |
src/http/mcp/tools/games.ts +10 −6
| @@ -25,6 +25,8 @@ import { verdictsOf } from "../../../games/set_verdict.ts"; | ||
| 25 | 25 | import { takeBack } from "../../../games/take_back.ts"; |
| 26 | 26 | import { newestProof, proofWords } from "../../../games/lent_proof.ts"; |
| 27 | 27 | import { queueWorld } from "../../../games/worlds.ts"; |
| 28 | import { principalOf } from "../../../core/principal.ts"; | |
| 29 | import { mayOnGame, seesGameBox } from "../../../games/game_may.ts"; | |
| 28 | 30 | |
| 29 | 31 | export const tool: Tool = { |
| 30 | 32 | name: "games", |
| @@ -120,7 +122,7 @@ export const tool: Tool = { | ||
| 120 | 122 | // A server added or taken out is the box's: its operators', planned first. |
| 121 | 123 | if (action === "create_server" || action === "remove_server") { |
| 122 | 124 | 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}`); | |
| 124 | 126 | let planned; |
| 125 | 127 | if (action === "create_server") { |
| 126 | 128 | const parsed = await wishOn(ctx.app, box, str(args["words"])); |
| @@ -146,16 +148,18 @@ export const tool: Tool = { | ||
| 146 | 148 | } |
| 147 | 149 | const service = str(args["service"]); |
| 148 | 150 | 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"); | |
| 152 | 156 | const window = (str(args["window"]) || "1h") as Window; |
| 153 | 157 | if (!(window in WINDOWS)) return bad("invalid", `window is one of ${Object.keys(WINDOWS).join(", ")}`); |
| 154 | 158 | return good(compactSeries(db, box, service, window)); |
| 155 | 159 | } |
| 156 | 160 | if (box === undefined || !seesBox(db, user, box.id) || !SERVICE_NAME.test(service)) return bad("not_found", "no such box or service here"); |
| 157 | 161 | 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}`); | |
| 159 | 163 | const got = await serviceSettings(ctx.app, box, service); |
| 160 | 164 | if (!got.ok) return bad("refused", got.error); |
| 161 | 165 | return good({ |
| @@ -172,7 +176,7 @@ export const tool: Tool = { | ||
| 172 | 176 | })), |
| 173 | 177 | }); |
| 174 | 178 | } |
| 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}`); | |
| 176 | 180 | if (action === "console") { |
| 177 | 181 | const text = str(args["text"]).trim(); |
| 178 | 182 | if (text === "") return bad("invalid", "say the command as text"); |
src/tui/screens/abstractions.ts +1
| @@ -59,6 +59,7 @@ export const entry: PaletteEntry = { | ||
| 59 | 59 | id: "abstractions", |
| 60 | 60 | title: "Tables", |
| 61 | 61 | hint: "the forge's tables: how much each is used, and what builds on what", |
| 62 | asks: "forge.administer", | |
| 62 | 63 | offered: (session) => mayReadAtlas(session.user), |
| 63 | 64 | run: (session, ctx) => ctx.push(abstractionsScreen(session, ctx)), |
| 64 | 65 | }; |
src/tui/screens/access.ts +1
| @@ -120,6 +120,7 @@ export const entry: PaletteEntry = { | ||
| 120 | 120 | title: "Access", |
| 121 | 121 | hint: "what outside agents tried", |
| 122 | 122 | after: ["file-holds"], |
| 123 | asks: "forge.administer", | |
| 123 | 124 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 124 | 125 | run: (session, ctx) => ctx.push(accessScreen(session, ctx)), |
| 125 | 126 | }; |
src/tui/screens/account_access.ts +1
| @@ -173,6 +173,7 @@ export const entry: PaletteEntry = { | ||
| 173 | 173 | title: "Account access", |
| 174 | 174 | hint: "search people, reset access, end sessions", |
| 175 | 175 | after: ["people"], |
| 176 | asks: "forge.administer", | |
| 176 | 177 | offered: (session) => session.user?.isAdmin === true && session.user.kind === "user", |
| 177 | 178 | run: (session, ctx) => ctx.push(accountAccessScreen(session, ctx)), |
| 178 | 179 | }; |
src/tui/screens/advisories.ts +1
| @@ -73,6 +73,7 @@ export const entry: PaletteEntry = { | ||
| 73 | 73 | title: "Advisories", |
| 74 | 74 | hint: "known vulnerabilities in your lockfiles", |
| 75 | 75 | after: ["resilience"], |
| 76 | asks: "forge.administer", | |
| 76 | 77 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 77 | 78 | run: openAdvisories, |
| 78 | 79 | }; |
src/tui/screens/agents.ts +1
| @@ -156,6 +156,7 @@ export const entry: PaletteEntry = { | ||
| 156 | 156 | title: "Crew agents", |
| 157 | 157 | hint: "each agent's model, budget and brief", |
| 158 | 158 | after: ["teams", "limits", "quotas", "people"], |
| 159 | asks: "forge.administer", | |
| 159 | 160 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 160 | 161 | run: (session, ctx) => ctx.push(agentsScreen(session, ctx)), |
| 161 | 162 | }; |
src/tui/screens/app_templates.ts +1
| @@ -169,6 +169,7 @@ export const entry: PaletteEntry = { | ||
| 169 | 169 | title: "App templates", |
| 170 | 170 | hint: "the repositories New app offers; mark or unmark one", |
| 171 | 171 | after: ["economics"], |
| 172 | asks: "forge.administer", | |
| 172 | 173 | offered: (session) => mayMark(session), |
| 173 | 174 | run: (session, ctx) => ctx.push(appTemplatesScreen(session, ctx)), |
| 174 | 175 | }; |
src/tui/screens/appleusage.ts +1
| @@ -97,6 +97,7 @@ export const entry: PaletteEntry = { | ||
| 97 | 97 | title: "App usage", |
| 98 | 98 | hint: "the Apple app's anonymous usage: counts and timings per version", |
| 99 | 99 | after: ["limits"], |
| 100 | asks: "forge.administer", | |
| 100 | 101 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 101 | 102 | run: (session, ctx) => ctx.push(appleUsageScreen(session, ctx)), |
| 102 | 103 | }; |
src/tui/screens/apps_crew.ts +1
| @@ -93,6 +93,7 @@ export const entry: PaletteEntry = { | ||
| 93 | 93 | id: "apps-crew", |
| 94 | 94 | title: "What the crew is doing", |
| 95 | 95 | 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. | |
| 96 | 97 | offered: () => true, |
| 97 | 98 | run: (session, ctx) => ctx.push(appsCrewScreen(session, ctx)), |
| 98 | 99 | }; |
src/tui/screens/archived.ts +1
| @@ -108,6 +108,7 @@ export const entry: PaletteEntry = { | ||
| 108 | 108 | id: "archived", |
| 109 | 109 | title: "Archive", |
| 110 | 110 | hint: "what is put away, who put it there: open one or unarchive it", |
| 111 | asks: "forge.read", | |
| 111 | 112 | offered: (session) => session.user !== undefined, |
| 112 | 113 | run: (session, ctx) => ctx.push(archivedScreen(session, ctx)), |
| 113 | 114 | }; |
src/tui/screens/ask_data.ts +1
| @@ -155,6 +155,7 @@ export const entry: PaletteEntry = { | ||
| 155 | 155 | title: "Data explorer", |
| 156 | 156 | hint: "start from a question about the forge's data", |
| 157 | 157 | after: ["boards"], |
| 158 | asks: "forge.administer", | |
| 158 | 159 | offered: mayExplore, |
| 159 | 160 | run: (session, ctx) => ctx.push(askDataScreen(session, ctx)), |
| 160 | 161 | }; |
src/tui/screens/audit.ts +1
| @@ -110,6 +110,7 @@ export const entry: PaletteEntry = { | ||
| 110 | 110 | id: "audit", |
| 111 | 111 | title: "Who can do what", |
| 112 | 112 | 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. | |
| 113 | 114 | offered: () => true, |
| 114 | 115 | run: (session, ctx) => |
| 115 | 116 | runAsync(ctx, async () => { |
src/tui/screens/bets.ts +1
| @@ -197,6 +197,7 @@ export const entry: PaletteEntry = { | ||
| 197 | 197 | id: "bets", |
| 198 | 198 | title: "Bets", |
| 199 | 199 | hint: "back, stop and finish a repository's bets", |
| 200 | asks: "forge.read", | |
| 200 | 201 | offered: (session) => session.user !== undefined && session.user.kind !== "agent", |
| 201 | 202 | run: (session, ctx) => ctx.push(betsScreen(session, ctx)), |
| 202 | 203 | }; |
src/tui/screens/billing.ts +1
src/tui/screens/billinglinks.ts +1
| @@ -76,6 +76,7 @@ export const entry: PaletteEntry = { | ||
| 76 | 76 | title: "Buy links", |
| 77 | 77 | hint: "where each hosted plan is paid for, shown on the home page", |
| 78 | 78 | after: ["limits", "invites"], |
| 79 | asks: "forge.administer", | |
| 79 | 80 | offered: (session) => session.user?.isAdmin === true && session.user.kind === "user", |
| 80 | 81 | run: (session, ctx) => ctx.push(billingLinksScreen(session, ctx)), |
| 81 | 82 | }; |
src/tui/screens/bills.ts +2
| @@ -66,6 +66,8 @@ export const entry: PaletteEntry = { | ||
| 66 | 66 | id: "bills", |
| 67 | 67 | title: "Your forges' bills", |
| 68 | 68 | 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, | |
| 69 | 71 | offered: (session) => session.user !== undefined && session.user.kind === "user" && billNames(session.app, session.user).length > 0, |
| 70 | 72 | run: (session, ctx) => ctx.push(billsScreen(session, ctx)), |
| 71 | 73 | }; |
src/tui/screens/boards.ts +1
| @@ -423,6 +423,7 @@ export const entry: PaletteEntry = { | ||
| 423 | 423 | title: "Boards", |
| 424 | 424 | hint: "the forge's boards and their panels", |
| 425 | 425 | after: ["sentinel"], |
| 426 | asks: "forge.administer", | |
| 426 | 427 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 427 | 428 | run: (session, ctx) => ctx.push(boardsScreen(session, ctx)), |
| 428 | 429 | }; |
src/tui/screens/bottleneck.ts +2
| @@ -70,6 +70,8 @@ export const entry: PaletteEntry = { | ||
| 70 | 70 | title: "Where the bottleneck is", |
| 71 | 71 | hint: "what limits the forge, what the host is tuned to, what changed", |
| 72 | 72 | after: ["system"], |
| 73 | // Names no `asks`: the gate is a telemetry role (`telemetryReader`), which `may` has no action | |
| 74 | // for. | |
| 73 | 75 | offered: mayRead, |
| 74 | 76 | run: (session, ctx) => ctx.push(bottleneckScreen(session, ctx)), |
| 75 | 77 | }; |
src/tui/screens/buckets.ts +1
| @@ -110,6 +110,7 @@ export const entry: PaletteEntry = { | ||
| 110 | 110 | id: "buckets", |
| 111 | 111 | title: "Buckets", |
| 112 | 112 | hint: "an object bucket's price a month, and binding it to an app", |
| 113 | asks: "forge.read", | |
| 113 | 114 | offered: (session) => session.user !== undefined, |
| 114 | 115 | run: (session, ctx) => ctx.push(bucketsScreen(session, ctx)), |
| 115 | 116 | }; |
src/tui/screens/budgets.ts +1
| @@ -90,6 +90,7 @@ export const entry: PaletteEntry = { | ||
| 90 | 90 | id: "budgets", |
| 91 | 91 | title: "Cloud budgets", |
| 92 | 92 | hint: "each cloud account's monthly budget against its projected spend", |
| 93 | asks: "forge.administer", | |
| 93 | 94 | offered: (session) => session.user?.isAdmin === true, |
| 94 | 95 | run: (session, ctx) => ctx.push(budgetsScreen(session, ctx)), |
| 95 | 96 | }; |
src/tui/screens/bugs.ts +1
| @@ -52,6 +52,7 @@ export const entry: PaletteEntry = { | ||
| 52 | 52 | title: "Bugs", |
| 53 | 53 | hint: "open bugs and the bug clock", |
| 54 | 54 | after: ["boards"], |
| 55 | // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside. | |
| 55 | 56 | offered: () => true, |
| 56 | 57 | run: (session, ctx) => ctx.push(bugsScreen(session, ctx)), |
| 57 | 58 | }; |
src/tui/screens/bulk.ts +1
| @@ -169,6 +169,7 @@ export const entry: PaletteEntry = { | ||
| 169 | 169 | title: "Bulk actions", |
| 170 | 170 | hint: "your last bulk actions; u undoes one inside its day", |
| 171 | 171 | after: ["invites", "teams", "limits"], |
| 172 | asks: "forge.read", | |
| 172 | 173 | offered: isPerson, |
| 173 | 174 | run: (session, ctx) => ctx.push(bulkScreen(session, ctx)), |
| 174 | 175 | }; |
src/tui/screens/childcredit.ts +1
| @@ -52,6 +52,7 @@ export const entry: PaletteEntry = { | ||
| 52 | 52 | title: "Lend a child credit", |
| 53 | 53 | hint: "set the dollars a forge you sent may spend on this one's model credential", |
| 54 | 54 | after: ["forges"], |
| 55 | asks: "forge.administer", | |
| 55 | 56 | offered: (session) => session.user?.isAdmin === true, |
| 56 | 57 | run: (session, ctx) => |
| 57 | 58 | runAsync(ctx, async () => { |
src/tui/screens/claim_link.ts +2
| @@ -69,6 +69,7 @@ export const entry: PaletteEntry = { | ||
| 69 | 69 | title: "A fresh claim link for a forge I sent", |
| 70 | 70 | hint: "the old link stops; shown once", |
| 71 | 71 | after: ["claim-start"], |
| 72 | asks: "forge.read", | |
| 72 | 73 | offered: (session) => session.user?.kind === "user", |
| 73 | 74 | run: (session, ctx) => ctx.push(claimLinkScreen(session, ctx)), |
| 74 | 75 | }; |
| @@ -121,6 +122,7 @@ export const recoveryEntry: PaletteEntry = { | ||
| 121 | 122 | title: "A recovery link for a forge's owner who lost their passkey", |
| 122 | 123 | hint: "shown once; works once", |
| 123 | 124 | after: ["claim-link"], |
| 125 | asks: "forge.read", | |
| 124 | 126 | offered: (session) => session.user?.kind === "user", |
| 125 | 127 | run: (session, ctx) => ctx.push(recoveryLinkScreen(session, ctx)), |
| 126 | 128 | }; |
src/tui/screens/claim_start.ts +1
| @@ -71,6 +71,7 @@ export const entry: PaletteEntry = { | ||
| 71 | 71 | title: "Take an agent's work", |
| 72 | 72 | hint: "claim the repositories an agent started, from its one-time link", |
| 73 | 73 | after: ["invites", "repos"], |
| 74 | asks: "forge.read", | |
| 74 | 75 | offered: (session) => session.user?.kind === "user", |
| 75 | 76 | run: (session, ctx) => ctx.push(claimStartScreen(session, ctx)), |
| 76 | 77 | }; |
src/tui/screens/client_clouds.ts +1
| @@ -160,6 +160,7 @@ export const entry: PaletteEntry = { | ||
| 160 | 160 | id: "client-clouds", |
| 161 | 161 | title: "Clients' clouds", |
| 162 | 162 | 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. | |
| 163 | 164 | offered: (session) => session.user?.kind === "user" && (session.user.isAdmin || myClientClouds(session.app, session.user).length > 0), |
| 164 | 165 | run: (session, ctx) => ctx.push(clientCloudsScreen(session, ctx)), |
| 165 | 166 | }; |
src/tui/screens/cloud.ts +1
| @@ -276,6 +276,7 @@ export const entry: PaletteEntry = { | ||
| 276 | 276 | id: "cloud", |
| 277 | 277 | title: "Cloud accounts", |
| 278 | 278 | hint: "provider tokens, what they are used for, today's calls", |
| 279 | asks: "forge.administer", | |
| 279 | 280 | offered: (session) => session.user?.isAdmin === true, |
| 280 | 281 | run: (session, ctx) => ctx.push(cloudScreen(session, ctx)), |
| 281 | 282 | }; |
src/tui/screens/cloudcost.ts +1
| @@ -55,6 +55,7 @@ export const entry: PaletteEntry = { | ||
| 55 | 55 | title: "What the clouds cost", |
| 56 | 56 | hint: "each account against its budget, and what costs most", |
| 57 | 57 | after: ["footing", "system"], |
| 58 | asks: "forge.administer", | |
| 58 | 59 | offered: mayRead, |
| 59 | 60 | run: (session, ctx) => ctx.push(cloudCostScreen(session, ctx)), |
| 60 | 61 | }; |
src/tui/screens/cloudtree.ts +1
| @@ -323,6 +323,7 @@ export const entry: PaletteEntry = { | ||
| 323 | 323 | title: "Cloud resources", |
| 324 | 324 | hint: "every resource on every cloud, what it costs, filtered", |
| 325 | 325 | after: ["cloud"], |
| 326 | asks: "forge.administer", | |
| 326 | 327 | offered: (session) => session.user?.isAdmin === true, |
| 327 | 328 | run: (session, ctx) => ctx.push(cloudTreeScreen(session, ctx)), |
| 328 | 329 | }; |
src/tui/screens/codes.ts +1
| @@ -99,6 +99,7 @@ export const entry: PaletteEntry = { | ||
| 99 | 99 | id: "codes", |
| 100 | 100 | title: "Gift codes", |
| 101 | 101 | hint: "make a code that gives a plan for free, and revoke one", |
| 102 | asks: "forge.administer", | |
| 102 | 103 | offered: isAdmin, |
| 103 | 104 | run: (session, ctx) => ctx.push(codesScreen(session, ctx)), |
| 104 | 105 | }; |
src/tui/screens/connections.ts +1
| @@ -166,6 +166,7 @@ export const entry: PaletteEntry = { | ||
| 166 | 166 | id: "origins", |
| 167 | 167 | title: "Connected accounts", |
| 168 | 168 | hint: "the hosts your mirrors come from", |
| 169 | asks: "forge.read", | |
| 169 | 170 | offered: (session) => session.user !== undefined && session.user.kind !== "agent", |
| 170 | 171 | run: (session, ctx) => ctx.push(connectionsScreen(session, ctx)), |
| 171 | 172 | }; |
src/tui/screens/controls.ts +1
| @@ -72,6 +72,7 @@ export const entry: PaletteEntry = { | ||
| 72 | 72 | id: "security-controls", |
| 73 | 73 | title: "Security controls", |
| 74 | 74 | hint: "each safeguard, its state, and when it was last checked", |
| 75 | asks: "forge.administer", | |
| 75 | 76 | offered: isAdmin, |
| 76 | 77 | run: (session, ctx) => ctx.push(controlsScreen(session, ctx)), |
| 77 | 78 | }; |
src/tui/screens/cores.ts +2
| @@ -29,6 +29,8 @@ export const entry: PaletteEntry = { | ||
| 29 | 29 | title: "Cores", |
| 30 | 30 | hint: "what this forge's cores mean for builds", |
| 31 | 31 | after: ["plan-row", "limits"], |
| 32 | asks: "forge.administer", | |
| 33 | shows: () => coresLine() !== undefined, | |
| 32 | 34 | offered: (session) => session.user?.isAdmin === true && coresLine() !== undefined, |
| 33 | 35 | run: (session, ctx) => { |
| 34 | 36 | if (session.user?.isAdmin === true) ctx.push(coresScreen(session, ctx)); |
src/tui/screens/crewbudgets.ts +3
| @@ -91,6 +91,9 @@ export const entry: PaletteEntry = { | ||
| 91 | 91 | title: "Crew budgets", |
| 92 | 92 | hint: "what the crew may spend per run, day and month on your key", |
| 93 | 93 | 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), | |
| 94 | 97 | offered: mayAct, |
| 95 | 98 | run: (session, ctx) => ctx.push(crewBudgetsScreen(session, ctx)), |
| 96 | 99 | }; |
src/tui/screens/crewfallback.ts +1
| @@ -92,6 +92,7 @@ export const entry: PaletteEntry = { | ||
| 92 | 92 | title: "Metered fallback", |
| 93 | 93 | hint: "the capped key the crew falls back to when every plan's window is full", |
| 94 | 94 | after: ["crewbudgets"], |
| 95 | asks: "forge.administer", | |
| 95 | 96 | offered: mayAct, |
| 96 | 97 | run: (session, ctx) => ctx.push(crewFallbackScreen(session, ctx)), |
| 97 | 98 | }; |
src/tui/screens/crewhandover.ts +1
| @@ -112,6 +112,7 @@ export const entry: PaletteEntry = { | ||
| 112 | 112 | title: "Crew hand-overs", |
| 113 | 113 | hint: "issues parked twice, and the last restore drill", |
| 114 | 114 | after: ["crew-scorecard"], |
| 115 | asks: "forge.administer", | |
| 115 | 116 | offered: (session) => session.user?.isAdmin === true, |
| 116 | 117 | run: (session, ctx) => ctx.push(crewHandoverScreen(session, ctx)), |
| 117 | 118 | }; |
src/tui/screens/crewkey.ts +1
src/tui/screens/crewsplits.ts +1
| @@ -81,6 +81,7 @@ export const entry: PaletteEntry = { | ||
| 81 | 81 | title: "Crew scorecard", |
| 82 | 82 | hint: "agent runs per model and per prompt version", |
| 83 | 83 | after: ["usage", "trusted-hosts", "secrets"], |
| 84 | asks: "forge.administer", | |
| 84 | 85 | offered: (session) => session.user?.isAdmin === true, |
| 85 | 86 | run: (session, ctx) => ctx.push(crewSplitsScreen(session, ctx)), |
| 86 | 87 | }; |
src/tui/screens/crewtop.ts +1
| @@ -159,6 +159,7 @@ export const entry: PaletteEntry = { | ||
| 159 | 159 | title: "Crew now", |
| 160 | 160 | hint: "who is on what, what waits, accounts, the week and runs that failed early", |
| 161 | 161 | after: ["scorecard"], |
| 162 | asks: "forge.administer", | |
| 162 | 163 | offered: mayReadCrewTop, |
| 163 | 164 | run: (session, ctx) => ctx.push(crewTopScreen(session, ctx)), |
| 164 | 165 | }; |
src/tui/screens/dataset.ts +1
| @@ -67,6 +67,7 @@ export const entry: PaletteEntry = { | ||
| 67 | 67 | title: "Dataset", |
| 68 | 68 | hint: "what the forge's dataset holds, and what it already answers", |
| 69 | 69 | after: ["bottleneck", "system"], |
| 70 | asks: "forge.administer", | |
| 70 | 71 | offered: mayRead, |
| 71 | 72 | run: (session, ctx) => ctx.push(datasetScreen(session, ctx)), |
| 72 | 73 | }; |
src/tui/screens/design.ts +1
| @@ -142,6 +142,7 @@ export const entry: PaletteEntry = { | ||
| 142 | 142 | title: "Design: the forge's theme", |
| 143 | 143 | hint: "colours and scales, the AA verdict; publish or revert", |
| 144 | 144 | after: ["footing"], |
| 145 | asks: "forge.read", | |
| 145 | 146 | offered: (session) => session.user !== undefined, |
| 146 | 147 | run: (session, ctx) => ctx.push(designScreen(session, ctx)), |
| 147 | 148 | }; |
src/tui/screens/design_gallery.ts +1
| @@ -11,6 +11,7 @@ export const entry: PaletteEntry = { | ||
| 11 | 11 | id: "design-gallery", |
| 12 | 12 | title: "Component gallery", |
| 13 | 13 | hint: "every component the design names", |
| 14 | // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside. | |
| 14 | 15 | offered: () => true, |
| 15 | 16 | run: (_session, ctx) => ctx.toast(galleryLine(), "default"), |
| 16 | 17 | }; |
src/tui/screens/devices.ts +1
| @@ -182,6 +182,7 @@ export const entry: PaletteEntry = { | ||
| 182 | 182 | title: "Devices", |
| 183 | 183 | hint: "LAN printers: model, state, supplies; declare or remove one", |
| 184 | 184 | after: ["app-templates"], |
| 185 | asks: "forge.administer", | |
| 185 | 186 | offered: (session) => mayUse(session), |
| 186 | 187 | run: (session, ctx) => ctx.push(devicesScreen(session, ctx)), |
| 187 | 188 | }; |
src/tui/screens/disks.ts +1
| @@ -69,6 +69,7 @@ export const entry: PaletteEntry = { | ||
| 69 | 69 | title: "Disks", |
| 70 | 70 | hint: "machines' disk readings: 30-day write rate and projected rated-TBW date", |
| 71 | 71 | after: ["system"], |
| 72 | asks: "forge.administer", | |
| 72 | 73 | offered: (session) => mayHandleDisks(session.user), |
| 73 | 74 | run: (session, ctx) => { |
| 74 | 75 | const names = readMachines(session.app, session.user); |
src/tui/screens/displays.ts +1
src/tui/screens/domains.ts +1
| @@ -136,6 +136,7 @@ export const entry: PaletteEntry = { | ||
| 136 | 136 | id: "domains", |
| 137 | 137 | title: "Failure domains", |
| 138 | 138 | hint: "failure domains and their last drill", |
| 139 | asks: "forge.administer", | |
| 139 | 140 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 140 | 141 | run: (session, ctx) => ctx.push(domainsScreen(session, ctx)), |
| 141 | 142 | }; |
src/tui/screens/dotfiles.ts +1
| @@ -66,6 +66,7 @@ export const entry: PaletteEntry = { | ||
| 66 | 66 | id: "dotfiles", |
| 67 | 67 | title: "Your dotfiles", |
| 68 | 68 | hint: "the repository every shell you open copies from", |
| 69 | asks: "forge.read", | |
| 69 | 70 | offered: (session) => session.user !== undefined && session.user.kind !== "agent", |
| 70 | 71 | run: (session, ctx) => ctx.push(dotfilesScreen(session, ctx)), |
| 71 | 72 | }; |
src/tui/screens/drift.ts +1
| @@ -82,6 +82,7 @@ export const entry: PaletteEntry = { | ||
| 82 | 82 | title: "Drifting pulls", |
| 83 | 83 | hint: "open pulls far behind main, and the one action that brings each up to date", |
| 84 | 84 | after: ["boards"], |
| 85 | asks: "forge.administer", | |
| 85 | 86 | offered: mayDrift, |
| 86 | 87 | run: (session, ctx) => ctx.push(driftScreen(session, ctx)), |
| 87 | 88 | }; |
src/tui/screens/dutybudgets.ts +1
| @@ -78,6 +78,7 @@ export const entry: PaletteEntry = { | ||
| 78 | 78 | title: "Set a maintenance duty's budget", |
| 79 | 79 | hint: "runs per day and dollars per day a duty may use", |
| 80 | 80 | after: ["maintenance-duties", "maintenance-runs"], |
| 81 | asks: "forge.administer", | |
| 81 | 82 | offered: mayAct, |
| 82 | 83 | run: (session, ctx) => ctx.push(dutyBudgetScreen(session, ctx)), |
| 83 | 84 | }; |
src/tui/screens/dutyswitch.ts +1
| @@ -97,6 +97,7 @@ export const entry: PaletteEntry = { | ||
| 97 | 97 | title: "Pause, resume or dismiss a maintenance duty", |
| 98 | 98 | hint: "switch a duty off, or on again after it paused itself", |
| 99 | 99 | after: ["maintenance-runs", "maintenance"], |
| 100 | asks: "forge.administer", | |
| 100 | 101 | offered: mayAct, |
| 101 | 102 | run: (session, ctx) => ctx.push(dutySwitchScreen(session, ctx)), |
| 102 | 103 | }; |
src/tui/screens/economics.ts +1
| @@ -202,6 +202,7 @@ export const entry: PaletteEntry = { | ||
| 202 | 202 | title: "Economics", |
| 203 | 203 | hint: "the profit slider's position, the margin, the owned-node label and the prices; change one", |
| 204 | 204 | after: ["limits"], |
| 205 | asks: "forge.administer", | |
| 205 | 206 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 206 | 207 | run: (session, ctx) => ctx.push(economicsScreen(session, ctx)), |
| 207 | 208 | }; |
src/tui/screens/edgeonly.ts +1
| @@ -57,6 +57,7 @@ export const entry: PaletteEntry = { | ||
| 57 | 57 | id: "edge-only-accounts", |
| 58 | 58 | title: "Edge-only accounts", |
| 59 | 59 | hint: "who would be locked out if the platform edge sign-in went off", |
| 60 | asks: "forge.administer", | |
| 60 | 61 | offered: isAdmin, |
| 61 | 62 | run: (session, ctx) => ctx.push(edgeOnlyScreen(session, ctx)), |
| 62 | 63 | }; |
src/tui/screens/entries.ts +44 −2
| @@ -9,6 +9,9 @@ | ||
| 9 | 9 | * `forge.ts`, never the reverse. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { askBeside } from "../../core/access_disagreement.ts"; | |
| 13 | import type { Action } from "../../core/may.ts"; | |
| 14 | import { principalOfUser } from "../../core/principal.ts"; | |
| 12 | 15 | import type { Ctx } from "../app/app.ts"; |
| 13 | 16 | import type { Command } from "../app/palette.ts"; |
| 14 | 17 | import type { Session } from "../session.ts"; |
| @@ -29,8 +32,21 @@ export interface PaletteEntry { | ||
| 29 | 32 | * `addEntries` is called. |
| 30 | 33 | */ |
| 31 | 34 | 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. */ | |
| 33 | 36 | 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; | |
| 34 | 50 | run(session: Session, ctx: Ctx): void; |
| 35 | 51 | } |
| 36 | 52 | |
| @@ -42,13 +58,39 @@ export const ENTRIES: readonly PaletteEntry[] = SCREEN_MODULES.flatMap(([mod, na | ||
| 42 | 58 | (a, b) => a.rank - b.rank, |
| 43 | 59 | ); |
| 44 | 60 | |
| 61 | /** | |
| 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 | ||
| 45 | 87 | /** |
| 46 | 88 | * Put each entry the session is offered into `commands`, after the command it names or at the end. |
| 47 | 89 | */ |
| 48 | 90 | export function addEntries(commands: Command[], session: Session, ctx: Ctx): void { |
| 49 | 91 | const placed = new Map<string, number>(); |
| 50 | 92 | for (const e of ENTRIES) { |
| 51 | if (!e.offered(session)) continue; | |
| 93 | if (!offers(e, session)) continue; | |
| 52 | 94 | const command: Command = { id: e.id, title: e.title, hint: e.hint, run: () => e.run(session, ctx) }; |
| 53 | 95 | const anchor = e.after?.find((id) => commands.some((c) => c.id === id)); |
| 54 | 96 | if (anchor === undefined) { |
src/tui/screens/experiments.ts +1
| @@ -151,6 +151,7 @@ export const entry: PaletteEntry = { | ||
| 151 | 151 | title: "Experiments", |
| 152 | 152 | hint: "what each cloud machine costs and answers", |
| 153 | 153 | after: ["pinned"], |
| 154 | asks: "forge.administer", | |
| 154 | 155 | offered: (session) => session.user?.isAdmin === true, |
| 155 | 156 | run: (session, ctx) => ctx.push(experimentsScreen(session, ctx)), |
| 156 | 157 | }; |
src/tui/screens/featurefeed.ts +1
| @@ -121,6 +121,7 @@ export const entry: PaletteEntry = { | ||
| 121 | 121 | title: "Feature feeds", |
| 122 | 122 | hint: "the feed items about an absorbed app, as Settings › Features shows them", |
| 123 | 123 | after: ["feature-review"], |
| 124 | asks: "forge.read", | |
| 124 | 125 | offered: (session) => session.user !== undefined, |
| 125 | 126 | run: (session, ctx) => ctx.push(featureFeedPicker(session, ctx)), |
| 126 | 127 | }; |
src/tui/screens/features.ts +1
| @@ -78,6 +78,7 @@ export const entry: PaletteEntry = { | ||
| 78 | 78 | id: "feature-review", |
| 79 | 79 | title: "Menu entries to review", |
| 80 | 80 | hint: "absorbed apps whose declared name or page changed: accept them", |
| 81 | asks: "forge.administer", | |
| 81 | 82 | offered: mayReview, |
| 82 | 83 | run: (session, ctx) => ctx.push(featuresScreen(session, ctx)), |
| 83 | 84 | }; |
src/tui/screens/featureswitch.ts +1
| @@ -162,6 +162,7 @@ export const entry: PaletteEntry = { | ||
| 162 | 162 | id: "features", |
| 163 | 163 | title: "Features", |
| 164 | 164 | hint: "apps that declare a feature: absorb one, change its settings", |
| 165 | asks: "forge.administer", | |
| 165 | 166 | offered: mayFeatures, |
| 166 | 167 | run: (session, ctx) => ctx.push(featureSwitchScreen(session, ctx)), |
| 167 | 168 | }; |
src/tui/screens/feed.ts +1
| @@ -337,6 +337,7 @@ export const entry: PaletteEntry = { | ||
| 337 | 337 | id: "feed", |
| 338 | 338 | title: "Feed", |
| 339 | 339 | 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", | |
| 340 | 341 | offered: (session) => session.user !== undefined, |
| 341 | 342 | run: (session, ctx) => ctx.push(feedScreen(session, ctx)), |
| 342 | 343 | }; |
src/tui/screens/flowsall.ts +1
| @@ -72,6 +72,7 @@ export const entry: PaletteEntry = { | ||
| 72 | 72 | title: "Flows across the forge", |
| 73 | 73 | hint: "every repository's flow lines, by kind and stale", |
| 74 | 74 | after: ["limits"], |
| 75 | asks: "forge.administer", | |
| 75 | 76 | offered: mayRead, |
| 76 | 77 | run: (session, ctx) => ctx.push(flowsAllScreen(session, ctx)), |
| 77 | 78 | }; |
src/tui/screens/footing.ts +1
| @@ -76,6 +76,7 @@ export const entry: PaletteEntry = { | ||
| 76 | 76 | title: "What the forge stands on", |
| 77 | 77 | hint: "each piece on another machine, in the order it would break the forge", |
| 78 | 78 | after: ["stalls", "system"], |
| 79 | asks: "forge.administer", | |
| 79 | 80 | offered: mayRead, |
| 80 | 81 | run: (session, ctx) => ctx.push(footingScreen(session, ctx)), |
| 81 | 82 | }; |
src/tui/screens/forgeready.ts +1
| @@ -17,6 +17,7 @@ export const entry: PaletteEntry = { | ||
| 17 | 17 | hint: "ask whether a forge you sent answers yet", |
| 18 | 18 | after: ["forges"], |
| 19 | 19 | // Admin only, as `forges` is: the list names every forge this one sent. |
| 20 | asks: "forge.administer", | |
| 20 | 21 | offered: (session) => session.user?.isAdmin === true, |
| 21 | 22 | run: (session, ctx: Ctx) => |
| 22 | 23 | runAsync(ctx, async () => { |
src/tui/screens/forges.ts +1
| @@ -504,6 +504,7 @@ export const entry: PaletteEntry = { | ||
| 504 | 504 | id: "forges", |
| 505 | 505 | title: "Forges you sent", |
| 506 | 506 | hint: "each forge sent, claimed or not, and its apps", |
| 507 | asks: "forge.administer", | |
| 507 | 508 | offered: (session) => session.user?.isAdmin === true, |
| 508 | 509 | run: (session, ctx) => runAsync(ctx, async () => { |
| 509 | 510 | ctx.push(forgesScreen(ctx, await clientRows(session.app), session)); |
src/tui/screens/forgeview.ts +1
| @@ -77,6 +77,7 @@ export const entry: PaletteEntry = { | ||
| 77 | 77 | title: "Forge view", |
| 78 | 78 | hint: "the forge's counts, and Foundry when it is installed", |
| 79 | 79 | after: ["now"], |
| 80 | asks: "forge.read", | |
| 80 | 81 | offered: (session) => session.user !== undefined, |
| 81 | 82 | run: (session, ctx) => ctx.push(forgeViewScreen(session, ctx)), |
| 82 | 83 | }; |
src/tui/screens/front.ts +1
| @@ -156,6 +156,7 @@ export const entry: PaletteEntry = { | ||
| 156 | 156 | id: "front", |
| 157 | 157 | title: "Front page", |
| 158 | 158 | 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. | |
| 159 | 160 | offered: () => true, |
| 160 | 161 | run: (session, ctx) => ctx.push(frontScreen(session, ctx)), |
| 161 | 162 | }; |
src/tui/screens/frontms.ts +1
| @@ -58,6 +58,7 @@ export const entry: PaletteEntry = { | ||
| 58 | 58 | title: "Milestones", |
| 59 | 59 | hint: "the biggest open milestones: how far, what landed this week", |
| 60 | 60 | after: ["now"], |
| 61 | asks: "forge.read", | |
| 61 | 62 | offered: (f) => f.user !== undefined, |
| 62 | 63 | run: (session, ctx) => ctx.push(frontMilestonesScreen(session, ctx)), |
| 63 | 64 | }; |
src/tui/screens/funnel.ts +1
| @@ -50,6 +50,7 @@ export const entry: PaletteEntry = { | ||
| 50 | 50 | id: "from-visit-to-paid", |
| 51 | 51 | title: "From visit to paid", |
| 52 | 52 | hint: "the last 7 days: home visits, plans seen, plan clicks, forges made, paid", |
| 53 | asks: "forge.administer", | |
| 53 | 54 | offered: mayRead, |
| 54 | 55 | run: (f, ctx) => ctx.push(funnelScreen(f, ctx)), |
| 55 | 56 | }; |
src/tui/screens/game_config.ts +4 −2
| @@ -11,7 +11,9 @@ | ||
| 11 | 11 | import { emptyText } from "../../core/empty_words.ts"; |
| 12 | 12 | import { commitConfig, configsOf, planConfig, planRevertConfig, type ConfigFile, type ConfigPlan } from "../../games/plugin_config.ts"; |
| 13 | 13 | 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"; | |
| 15 | 17 | import type { Ctx, Screen } from "../app/app.ts"; |
| 16 | 18 | import { binding } from "../app/keys.ts"; |
| 17 | 19 | import { style } from "../term/style.ts"; |
| @@ -30,7 +32,7 @@ export function gameConfigScreen(f: Session, ctx: Ctx, box: GameBox, service: st | ||
| 30 | 32 | let pending: ConfigPlan | undefined; |
| 31 | 33 | // The text box open on a file, and the path it is for. |
| 32 | 34 | 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"); | |
| 34 | 36 | const say = (words: string): void => { |
| 35 | 37 | note = words; |
| 36 | 38 | ctx.invalidate(); |
src/tui/screens/game_map.ts +4 −2
| @@ -8,13 +8,15 @@ | ||
| 8 | 8 | import { askMap, mapPath } from "../../games/map.ts"; |
| 9 | 9 | import { mapLine, refreshMap } from "../../games/map_check.ts"; |
| 10 | 10 | 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"; | |
| 12 | 12 | import type { Ctx, Screen } from "../app/app.ts"; |
| 13 | 13 | import { binding } from "../app/keys.ts"; |
| 14 | 14 | import { style } from "../term/style.ts"; |
| 15 | 15 | import { truncate, wrap } from "../term/width.ts"; |
| 16 | 16 | import type { Session } from "../session.ts"; |
| 17 | 17 | import { fill, len, split } from "../ui/layout.ts"; |
| 18 | import { principalOfUser } from "../../core/principal.ts"; | |
| 19 | import { mayOnGame } from "../../games/game_may.ts"; | |
| 18 | 20 | |
| 19 | 21 | export function gameMapScreen(f: Session, ctx: Ctx, box: GameBox, service: string): Screen { |
| 20 | 22 | let note = ""; |
| @@ -31,7 +33,7 @@ export function gameMapScreen(f: Session, ctx: Ctx, box: GameBox, service: strin | ||
| 31 | 33 | }, |
| 32 | 34 | key(e) { |
| 33 | 35 | 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}.`; | |
| 35 | 37 | else { |
| 36 | 38 | note = "Asking the box…"; |
| 37 | 39 | 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"; | ||
| 11 | 11 | import { search, type Hit, type Result } from "../../games/modrinth.ts"; |
| 12 | 12 | import { commitPlan, modsOf, packUpdateOf, planInstall, planPack, planPackUpdate, planRemove, planUpdate, updatesOf, type Mods, type Plan } from "../../games/mods.ts"; |
| 13 | 13 | 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"; | |
| 15 | 17 | import type { Ctx, Screen } from "../app/app.ts"; |
| 16 | 18 | import { binding } from "../app/keys.ts"; |
| 17 | 19 | import { style } from "../term/style.ts"; |
| @@ -30,7 +32,7 @@ export function gameModsScreen(f: Session, ctx: Ctx, box: GameBox, service: stri | ||
| 30 | 32 | // The pack row, and a link just made (shown here once, then gone with the next key). |
| 31 | 33 | let players: PackRow | undefined; |
| 32 | 34 | 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"); | |
| 34 | 36 | const say = (words: string): void => { |
| 35 | 37 | note = words; |
| 36 | 38 | ctx.invalidate(); |
src/tui/screens/game_spark.ts +5 −3
| @@ -9,13 +9,15 @@ | ||
| 9 | 9 | import { publicOrigin } from "../../core/public_origin.ts"; |
| 10 | 10 | import { sparkFindingsOf } from "../../games/spark_finding.ts"; |
| 11 | 11 | 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"; | |
| 13 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| 14 | 14 | import { binding } from "../app/keys.ts"; |
| 15 | 15 | import { style } from "../term/style.ts"; |
| 16 | 16 | import { truncate, wrap } from "../term/width.ts"; |
| 17 | 17 | import type { Session } from "../session.ts"; |
| 18 | 18 | import { gameSparkViewScreen } from "./game_spark_view.ts"; |
| 19 | import { principalOfUser } from "../../core/principal.ts"; | |
| 20 | import { mayOnGame } from "../../games/game_may.ts"; | |
| 19 | 21 | |
| 20 | 22 | export function gameSparkScreen(f: Session, ctx: Ctx, box: GameBox): Screen { |
| 21 | 23 | let address = ""; |
| @@ -45,11 +47,11 @@ export function gameSparkScreen(f: Session, ctx: Ctx, box: GameBox): Screen { | ||
| 45 | 47 | } else if (e.key === "k" || e.key === "up") { |
| 46 | 48 | at = Math.max(0, at - 1); |
| 47 | 49 | } 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; | |
| 49 | 51 | ctx.push(gameSparkViewScreen(f, ctx, box, stored[at]!.key)); |
| 50 | 52 | return true; |
| 51 | 53 | } 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; | |
| 53 | 55 | address = sparkBase(publicOrigin(f.app.config.url, `http://localhost:${String(f.app.config.port)}`), newSparkSecret(f.app.db, box.id)); |
| 54 | 56 | } else { |
| 55 | 57 | return false; |
src/tui/screens/games.ts +16 −12
| @@ -79,6 +79,8 @@ import { gameMapScreen } from "./game_map.ts"; | ||
| 79 | 79 | import { gameConfigScreen } from "./game_config.ts"; |
| 80 | 80 | import { gameModsScreen } from "./game_mods.ts"; |
| 81 | 81 | import { gameSparkScreen } from "./game_spark.ts"; |
| 82 | import { principalOfUser } from "../../core/principal.ts"; | |
| 83 | import { mayOnGame } from "../../games/game_may.ts"; | |
| 82 | 84 | |
| 83 | 85 | /** "4 online · 19.8 TPS · 3.1 ms tick" from the last hour's numbers, or nothing before any. */ |
| 84 | 86 | function playersTps(f: Session, box: { id: string }, service: string): string[] { |
| @@ -218,7 +220,7 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen { | ||
| 218 | 220 | return true; |
| 219 | 221 | } |
| 220 | 222 | 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.`; | |
| 222 | 224 | else ctx.push(gameShellScreen(f, ctx, at.box)); |
| 223 | 225 | ctx.invalidate(); |
| 224 | 226 | return true; |
| @@ -244,8 +246,8 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen { | ||
| 244 | 246 | return true; |
| 245 | 247 | } |
| 246 | 248 | 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."; | |
| 249 | 251 | else |
| 250 | 252 | ctx.push( |
| 251 | 253 | promptScreen(ctx, screen, { |
| @@ -262,13 +264,13 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen { | ||
| 262 | 264 | // The selected server out of the network: the plan shown, yes commits; its world is kept. |
| 263 | 265 | if (at !== undefined && !e.ctrl && !e.alt && e.key === "d") { |
| 264 | 266 | 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}.`; | |
| 266 | 268 | else void ctx.track(planRemoveServer(f.app, box, service.name).then((planned) => showPlan(box, `Remove ${service.name} from ${box.name}`, "Remove it", planned))); |
| 267 | 269 | ctx.invalidate(); |
| 268 | 270 | return true; |
| 269 | 271 | } |
| 270 | 272 | 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}.`; | |
| 272 | 274 | else { |
| 273 | 275 | const { box, service } = at; |
| 274 | 276 | note = `${box.name}/${service.name}: saving…`; |
| @@ -285,7 +287,7 @@ export function gamesScreen(f: Session, ctx: Ctx): Screen { | ||
| 285 | 287 | } |
| 286 | 288 | const kind: Power | undefined = e.key === "s" ? "start" : e.key === "x" ? "stop" : e.key === "r" ? "restart" : undefined; |
| 287 | 289 | 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}.`; | |
| 289 | 291 | else { |
| 290 | 292 | const { box, service } = at; |
| 291 | 293 | 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 | ||
| 343 | 345 | let note = ""; |
| 344 | 346 | let compose: string | undefined; |
| 345 | 347 | 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"); | |
| 347 | 349 | const load = async (): Promise<void> => { |
| 348 | 350 | compose = (await readCompose(f.app, box))?.text; |
| 349 | 351 | loaded = true; |
| @@ -525,7 +527,7 @@ export function gameSettingsScreen(f: Session, ctx: Ctx, box: GameBox, service: | ||
| 525 | 527 | let values: SettingValue[] = []; |
| 526 | 528 | let wanted: Record<string, string> = {}; |
| 527 | 529 | 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"); | |
| 529 | 531 | const load = async (): Promise<void> => { |
| 530 | 532 | compose = await readCompose(f.app, box); |
| 531 | 533 | 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 { | ||
| 675 | 677 | else if (e.key === "p") { |
| 676 | 678 | ctx.push(gameSparkScreen(f, ctx, box)); |
| 677 | 679 | 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) { | |
| 679 | 681 | const b = listBoxes(f.app.db).find((x) => x.id === box.id) ?? box; |
| 680 | 682 | 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) { | |
| 682 | 684 | 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")) { | |
| 684 | 686 | setLocksOnLeave(f.app.db, box.id, !locksOnLeave(f.app.db, box.id)); |
| 685 | 687 | } else return false; |
| 686 | 688 | ctx.invalidate(); |
| @@ -693,7 +695,7 @@ export function gameBoxScreen(f: Session, ctx: Ctx, box: GameBox): Screen { | ||
| 693 | 695 | export function gameGrantsScreen(f: Session, ctx: Ctx, box: GameBox): Screen { |
| 694 | 696 | const state = new ListState(); |
| 695 | 697 | 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"); | |
| 697 | 699 | const screen: Screen = { |
| 698 | 700 | title: `${box.name} grants`, |
| 699 | 701 | keys: [binding(["j", "k"], "move cursor"), binding(["a"], "grant")], |
| @@ -793,6 +795,8 @@ export const entry: PaletteEntry = { | ||
| 793 | 795 | title: "Games", |
| 794 | 796 | hint: "game servers on your cloud: state, start, stop, restart", |
| 795 | 797 | 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`. | |
| 796 | 800 | offered: (session) => seesAnyBox(session.app.db, session.user), |
| 797 | 801 | run: (session, ctx) => ctx.push(gamesScreen(session, ctx)), |
| 798 | 802 | }; |
src/tui/screens/gifts.ts +1
| @@ -60,6 +60,7 @@ export const entry: PaletteEntry = { | ||
| 60 | 60 | id: "gifts", |
| 61 | 61 | title: "Gifts", |
| 62 | 62 | 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. | |
| 63 | 64 | offered: (f) => f.user !== undefined && isSubscriber(f.app, f.user), |
| 64 | 65 | run: (session, ctx) => ctx.push(giftsScreen(session, ctx)), |
| 65 | 66 | }; |
src/tui/screens/health_voice.ts +1
| @@ -36,6 +36,7 @@ export const entry: PaletteEntry = { | ||
| 36 | 36 | title: "Health — spoken", |
| 37 | 37 | hint: "how the forge is, in two plain sentences", |
| 38 | 38 | after: ["system", "flow", "boards"], |
| 39 | // Names no `asks`: offered to everyone, so there is no gate for `may` to be asked beside. | |
| 39 | 40 | offered: () => true, |
| 40 | 41 | run: (session, ctx) => ctx.push(healthVoiceScreen(session, ctx)), |
| 41 | 42 | }; |
src/tui/screens/home_pins.ts +1
src/tui/screens/hostreach.ts +1
| @@ -183,6 +183,7 @@ export const entry: PaletteEntry = { | ||
| 183 | 183 | title: "What hosted forges may reach", |
| 184 | 184 | hint: "answer what a hosted forge asked to reach, and take a grant back", |
| 185 | 185 | after: ["forges"], |
| 186 | asks: "forge.administer", | |
| 186 | 187 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 187 | 188 | run: (session, ctx) => ctx.push(hostReachScreen(session, ctx)), |
| 188 | 189 | }; |
src/tui/screens/infra.ts +1
| @@ -693,6 +693,7 @@ export const entry: PaletteEntry = { | ||
| 693 | 693 | title: "Infrastructure", |
| 694 | 694 | hint: "what runs on your own cloud, what it costs, when it ends", |
| 695 | 695 | after: ["cloud"], |
| 696 | asks: "forge.administer", | |
| 696 | 697 | offered: (session) => session.user?.isAdmin === true, |
| 697 | 698 | run: (session, ctx) => ctx.push(infraScreen(session, ctx)), |
| 698 | 699 | }; |
src/tui/screens/inventory.ts +1
| @@ -118,6 +118,7 @@ export const entry: PaletteEntry = { | ||
| 118 | 118 | title: "What is left to bring over", |
| 119 | 119 | hint: "every repository on your connected accounts, what it holds, where its move stands", |
| 120 | 120 | after: ["migrate"], |
| 121 | asks: "forge.read", | |
| 121 | 122 | offered: (session) => session.user !== undefined, |
| 122 | 123 | run: (session, ctx) => ctx.push(inventoryScreen(session, ctx)), |
| 123 | 124 | }; |
src/tui/screens/invites.ts +1
| @@ -220,6 +220,7 @@ export const entry: PaletteEntry = { | ||
| 220 | 220 | title: "Invite links", |
| 221 | 221 | hint: "make a single-use link, see which are open, revoke one", |
| 222 | 222 | after: ["teams", "limits", "quotas", "people", "can"], |
| 223 | asks: "forge.administer", | |
| 223 | 224 | offered: (session) => session.user?.isAdmin === true && session.user.kind === "user", |
| 224 | 225 | run: (session, ctx) => ctx.push(invitesScreen(session, ctx)), |
| 225 | 226 | }; |
src/tui/screens/knobs.ts +1
| @@ -70,6 +70,7 @@ export const entry: PaletteEntry = { | ||
| 70 | 70 | title: "Knobs", |
| 71 | 71 | hint: "speed, weekly budget, polish, autonomy, feedback first", |
| 72 | 72 | after: ["crew-scorecard", "usage"], |
| 73 | asks: "forge.administer", | |
| 73 | 74 | offered: (session) => session.user?.isAdmin === true, |
| 74 | 75 | run: (session, ctx) => ctx.push(knobsScreen(session, ctx)), |
| 75 | 76 | }; |
src/tui/screens/lapsed.ts +1
| @@ -94,6 +94,7 @@ export const entry: PaletteEntry = { | ||
| 94 | 94 | title: "Lapsed forges", |
| 95 | 95 | hint: "forges asleep until paid, when their data goes, pay again", |
| 96 | 96 | after: ["billing"], |
| 97 | asks: "forge.administer", | |
| 97 | 98 | offered: isAdmin, |
| 98 | 99 | run: (session, ctx) => ctx.push(lapsedScreen(session, ctx)), |
| 99 | 100 | }; |
src/tui/screens/limits.ts +1
| @@ -110,6 +110,7 @@ export const entry: PaletteEntry = { | ||
| 110 | 110 | title: "Limits", |
| 111 | 111 | hint: "what the forge caps, with default and bounds; change one", |
| 112 | 112 | after: ["quotas", "people", "can"], |
| 113 | asks: "forge.administer", | |
| 113 | 114 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 114 | 115 | run: (session, ctx) => ctx.push(limitsScreen(session, ctx)), |
| 115 | 116 | }; |
src/tui/screens/loopstalls.ts +1
| @@ -149,6 +149,7 @@ export const entry: PaletteEntry = { | ||
| 149 | 149 | title: "Main-thread stalls", |
| 150 | 150 | hint: "the last hour's stall ms by route", |
| 151 | 151 | after: ["system"], |
| 152 | asks: "forge.administer", | |
| 152 | 153 | offered: mayRead, |
| 153 | 154 | run: (session, ctx) => ctx.push(stallsScreen(session, ctx)), |
| 154 | 155 | }; |
src/tui/screens/madefrom.ts +2
| @@ -42,6 +42,8 @@ export const entry: PaletteEntry = { | ||
| 42 | 42 | title: "Started from", |
| 43 | 43 | hint: "the template and commit this forge was made from", |
| 44 | 44 | after: ["plan-row"], |
| 45 | asks: "forge.read", | |
| 46 | shows: (session) => madeFromOf(session.app.config.dataDir) !== undefined, | |
| 45 | 47 | offered: (session) => session.signedIn && madeFromOf(session.app.config.dataDir) !== undefined, |
| 46 | 48 | run: (session, ctx) => ctx.push(madeFromScreen(session, ctx)), |
| 47 | 49 | }; |
src/tui/screens/maintainruns.ts +1
| @@ -33,6 +33,7 @@ export const entry: PaletteEntry = { | ||
| 33 | 33 | title: "Maintenance duty runs", |
| 34 | 34 | hint: "what each duty found, did and probed", |
| 35 | 35 | after: ["maintenance"], |
| 36 | asks: "forge.administer", | |
| 36 | 37 | offered: mayRead, |
| 37 | 38 | run: (session, ctx) => ctx.push(maintainRunsScreen(session, ctx)), |
| 38 | 39 | }; |
src/tui/screens/maintenance.ts +1
| @@ -280,6 +280,7 @@ export const entry: PaletteEntry = { | ||
| 280 | 280 | title: "Maintenance", |
| 281 | 281 | hint: "prepare the forge for a power-off, check the drain, or end maintenance", |
| 282 | 282 | after: ["resilience", "capacity", "flow", "sentinel"], |
| 283 | asks: "forge.administer", | |
| 283 | 284 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 284 | 285 | run: (session, ctx) => ctx.push(maintenanceScreen(session, ctx)), |
| 285 | 286 | }; |
src/tui/screens/maintenanceweek.ts +2
| @@ -39,6 +39,8 @@ export const entry: PaletteEntry = { | ||
| 39 | 39 | title: "Maintenance, last 7 days", |
| 40 | 40 | hint: "what each maintenance worker found and did this week", |
| 41 | 41 | after: ["footing", "stalls", "system"], |
| 42 | // Names no `asks`: the gate is a telemetry role (`telemetryReader`), which `may` has no action | |
| 43 | // for. | |
| 42 | 44 | offered: mayRead, |
| 43 | 45 | run: (session, ctx) => ctx.push(weekScreen(session, ctx)), |
| 44 | 46 | }; |
src/tui/screens/mergedbranches.ts +1
| @@ -78,6 +78,7 @@ export const entry: PaletteEntry = { | ||
| 78 | 78 | title: "Branches of pulls merged over 7 days ago", |
| 79 | 79 | hint: "delete the merged pulls' branches in one receipted step", |
| 80 | 80 | after: ["maintenance", "maintenance-runs", "stale-pulls"], |
| 81 | asks: "forge.administer", | |
| 81 | 82 | offered: mayAct, |
| 82 | 83 | run: (session, ctx) => ctx.push(mergedBranchesScreen(session, ctx)), |
| 83 | 84 | }; |
src/tui/screens/mirrorpacks.ts +1
| @@ -67,6 +67,7 @@ export const entry: PaletteEntry = { | ||
| 67 | 67 | title: "Mirror the packs' upstreams", |
| 68 | 68 | hint: "bring each pack's upstream projects in as read-only repositories", |
| 69 | 69 | after: ["packs"], |
| 70 | asks: "forge.administer", | |
| 70 | 71 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", |
| 71 | 72 | run: (session, ctx) => ctx.push(mirrorPacksScreen(session, ctx)), |
| 72 | 73 | }; |
src/tui/screens/model.ts +2
| @@ -365,6 +365,7 @@ export const modelGrantEntry: PaletteEntry = { | ||
| 365 | 365 | title: "Model grant", |
| 366 | 366 | hint: "give an account dollars a month, or take it back", |
| 367 | 367 | after: ["model"], |
| 368 | asks: "forge.administer", | |
| 368 | 369 | offered: (session) => session.user?.isAdmin === true && session.user.kind === "user", |
| 369 | 370 | run: (session, ctx) => ctx.push(modelGrantPrompt(session, ctx, blank("Model grant"))), |
| 370 | 371 | }; |
| @@ -376,6 +377,7 @@ export const modelCeilingEntry: PaletteEntry = { | ||
| 376 | 377 | title: "Model ceiling", |
| 377 | 378 | hint: "set an account's dollars a day and a run", |
| 378 | 379 | after: ["model-grant"], |
| 380 | asks: "forge.administer", | |
| 379 | 381 | offered: (session) => session.user?.isAdmin === true && session.user.kind === "user", |
| 380 | 382 | run: (session, ctx) => ctx.push(modelCeilingPrompt(session, ctx, blank("Model ceiling"))), |
| 381 | 383 | }; |
src/tui/screens/money.ts +1
| @@ -99,6 +99,7 @@ export const entry: PaletteEntry = { | ||
| 99 | 99 | title: "Money", |
| 100 | 100 | hint: "this month's cost, revenue and gap, and the last 30 days", |
| 101 | 101 | after: ["economics"], |
| 102 | asks: "forge.administer", | |
| 102 | 103 | offered: (f) => f.user?.isAdmin === true && f.user.kind !== "agent", |
| 103 | 104 | run: (f, ctx) => ctx.push(moneyScreen(f, ctx)), |
| 104 | 105 | }; |
55 more files not shown.
new above
offline
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.