Public: anyone can read this; the crew can change it.
The terminal access-codes screen says when an admin's code acts as admin, and asks before minting one #12483
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12476-the-terminal-access-codes-screen-says-wh → main 3 commits fork
3 files
changed +43
−8
src/tui/screens/signins.ts +8 −6
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | * as Settings and the API do (your own only, and `token.deleted` is emitted). |
| 9 | 9 | * `m` makes a token through the action `createToken` (what Settings uses, so |
| 10 | 10 | * `token.created` is emitted and `ADMIN_TOKEN_WORDS` is the refusal): a name, |
| 11 | * a scope, and for admin a second explicit `y`. The secret is shown once on a | |
| 11 | * a scope, and for an admin's code of any scope a second explicit `y`. The secret is shown once on a | |
| 12 | 12 | * screen of its own and forgotten when that screen is left. Only a person |
| 13 | 13 | * minting from a terminal session may: an agent is not offered `m`. |
| 14 | 14 | * `p` changes your password through the action `changePassword` (what |
| @@ -84,7 +84,9 @@ export function signInsOf(f: Session): SignIn[] { | ||
| 84 | 84 | ...seen.value.tokens.map((t) => ({ |
| 85 | 85 | kind: "token" as const, |
| 86 | 86 | id: t.id, |
| 87 | where: t.oauthClient === null ? `${t.name} · ${t.scope}` : `${t.name} · ${t.scope} · ${t.oauthClient}, renews itself`, | |
| 87 | where: | |
| 88 | `${t.name} · ${t.scope}${user.isAdmin ? " · acts as admin" : ""}` + | |
| 89 | (t.oauthClient === null ? "" : ` · ${t.oauthClient}, renews itself`), | |
| 88 | 90 | seen: t.lastUsedAt, |
| 89 | 91 | since: t.createdAt, |
| 90 | 92 | here: false, |
| @@ -216,17 +218,17 @@ export function signInsScreen(f: Session, ctx: Ctx): Screen { | ||
| 216 | 218 | }; |
| 217 | 219 | |
| 218 | 220 | /** Asks admin to say it twice; a plain y mints. */ |
| 219 | const confirmAdmin = (name: string) => | |
| 221 | const confirmAdmin = (name: string, scope: TokenScope) => | |
| 220 | 222 | later(ctx, () => |
| 221 | 223 | confirmScreen(ctx, screen, { |
| 222 | 224 | title: "Make an admin access code", |
| 223 | body: [`${name} will act as admin: y to make it, n to cancel.`], | |
| 225 | body: [`${name} (${scope}) will act as admin, whatever its scope: y to make it, n to cancel.`], | |
| 224 | 226 | actions: [{ label: "Make it", variant: "danger" }, { label: "Cancel", variant: "ghost" }], |
| 225 | 227 | yesNo: true, |
| 226 | 228 | selected: 1, |
| 227 | 229 | width: 60, |
| 228 | 230 | onChoose: (i) => { |
| 229 | if (i === 0) mint(name, "admin"); | |
| 231 | if (i === 0) mint(name, scope); | |
| 230 | 232 | }, |
| 231 | 233 | }), |
| 232 | 234 | ); |
| @@ -241,7 +243,7 @@ export function signInsScreen(f: Session, ctx: Ctx): Screen { | ||
| 241 | 243 | const scope = word.toLowerCase(); |
| 242 | 244 | if (scope === "admin" && !isAdmin) return ADMIN_TOKEN_WORDS; |
| 243 | 245 | if (scope !== "ro" && scope !== "rw" && scope !== "admin") return isAdmin ? "Type ro, rw or admin." : "Type ro or rw."; |
| 244 | if (scope === "admin") return confirmAdmin(name); | |
| 246 | if (isAdmin || scope === "admin") return confirmAdmin(name, scope); | |
| 245 | 247 | return Promise.resolve().then(() => mint(name, scope)); |
| 246 | 248 | }, |
| 247 | 249 | }), |
test/tokens-oauth-client.test.ts +2 −2
| @@ -152,6 +152,6 @@ test("MCP `tokens` carries oauthClient on each token, null for a hand-made one", | ||
| 152 | 152 | test("the terminal's sign-ins screen names the harness on an OAuth token's row", () => { |
| 153 | 153 | const rows = signInsOf(new Session(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: alice })); |
| 154 | 154 | const where = (name: string) => rows.find((r) => r.kind === "token" && r.where.startsWith(`${name} · `))?.where; |
| 155 | expect(where("harness-token")).toBe("harness-token · rw · Claude Code, renews itself"); | |
| 156 | expect(where("laptop")).toBe("laptop · rw"); | |
| 155 | expect(where("harness-token")).toBe("harness-token · rw · acts as admin · Claude Code, renews itself"); | |
| 156 | expect(where("laptop")).toBe("laptop · rw · acts as admin"); | |
| 157 | 157 | }); |
test/tui-signins.test.ts +33
| @@ -141,6 +141,39 @@ describe("where you are signed in, in the terminal", () => { | ||
| 141 | 141 | h.stop(); |
| 142 | 142 | }); |
| 143 | 143 | |
| 144 | test("an admin's token rows say they act as admin and any scope asks first; an everyday account's do not", async () => { | |
| 145 | const made = await createUser(forge.db, { | |
| 146 | origin: "seed", | |
| 147 | trusted: true, | |
| 148 | username: "carol", | |
| 149 | email: "[email protected]", | |
| 150 | password: "a-good-passphrase", | |
| 151 | adminIfFirst: false, | |
| 152 | }); | |
| 153 | if (!made.ok) throw new Error(made.error); | |
| 154 | forge.db.run("UPDATE user SET is_admin = 1 WHERE username = 'carol'"); | |
| 155 | const carolId = getUserByName(forge.db, "carol")!.id; | |
| 156 | createToken(forge.db, carolId, "carol-ci", "ro"); | |
| 157 | const h = boot("carol"); | |
| 158 | await h.open(); | |
| 159 | expect(h.text()).toContain("carol-ci · ro · acts as admin"); | |
| 160 | await h.press("m", "enter"); | |
| 161 | await h.press("enter"); | |
| 162 | expect(h.text()).toContain("Make an admin access code"); | |
| 163 | expect(h.text()).toContain("(ro) will act as admin"); | |
| 164 | await h.press("enter"); | |
| 165 | expect(h.text()).not.toContain("New access code"); | |
| 166 | h.stop(); | |
| 167 | const g = boot("alice"); | |
| 168 | await g.open(); | |
| 169 | expect(g.text()).toContain("alice-ci · ro"); | |
| 170 | expect(g.text()).not.toContain("acts as admin"); | |
| 171 | await g.press("m", "enter"); | |
| 172 | await g.press("enter"); | |
| 173 | expect(g.text()).toContain("New access code"); | |
| 174 | g.stop(); | |
| 175 | }); | |
| 176 | ||
| 144 | 177 | test("bob sees only his own", async () => { |
| 145 | 178 | const h = boot("bob"); |
| 146 | 179 | await h.open(); |
new above
offline