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

Merged opened this

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

Merged

scout/forge:scout/12476-the-terminal-access-codes-screen-says-wh → main 3 commits fork

  • Merged. scout/12476-the-terminal-access-codes-screen-says-wh was merged into main as 8f5cf9c.

Review

Sign in to review this change.
3 files changed +43 −8
src/tui/screens/signins.ts +8 −6
@@ -8,7 +8,7 @@
88 * as Settings and the API do (your own only, and `token.deleted` is emitted).
99 * `m` makes a token through the action `createToken` (what Settings uses, so
1010 * `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
1212 * screen of its own and forgotten when that screen is left. Only a person
1313 * minting from a terminal session may: an agent is not offered `m`.
1414 * `p` changes your password through the action `changePassword` (what
@@ -84,7 +84,9 @@ export function signInsOf(f: Session): SignIn[] {
8484 ...seen.value.tokens.map((t) => ({
8585 kind: "token" as const,
8686 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`),
8890 seen: t.lastUsedAt,
8991 since: t.createdAt,
9092 here: false,
@@ -216,17 +218,17 @@ export function signInsScreen(f: Session, ctx: Ctx): Screen {
216218 };
217219
218220 /** Asks admin to say it twice; a plain y mints. */
219 const confirmAdmin = (name: string) =>
221 const confirmAdmin = (name: string, scope: TokenScope) =>
220222 later(ctx, () =>
221223 confirmScreen(ctx, screen, {
222224 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.`],
224226 actions: [{ label: "Make it", variant: "danger" }, { label: "Cancel", variant: "ghost" }],
225227 yesNo: true,
226228 selected: 1,
227229 width: 60,
228230 onChoose: (i) => {
229 if (i === 0) mint(name, "admin");
231 if (i === 0) mint(name, scope);
230232 },
231233 }),
232234 );
@@ -241,7 +243,7 @@ export function signInsScreen(f: Session, ctx: Ctx): Screen {
241243 const scope = word.toLowerCase();
242244 if (scope === "admin" && !isAdmin) return ADMIN_TOKEN_WORDS;
243245 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);
245247 return Promise.resolve().then(() => mint(name, scope));
246248 },
247249 }),
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",
152152 test("the terminal's sign-ins screen names the harness on an OAuth token's row", () => {
153153 const rows = signInsOf(new Session(app, { sshUsername: "t", remoteAddress: "127.0.0.1", user: alice }));
154154 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");
157157 });
test/tui-signins.test.ts +33
@@ -141,6 +141,39 @@ describe("where you are signed in, in the terminal", () => {
141141 h.stop();
142142 });
143143
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
144177 test("bob sees only his own", async () => {
145178 const h = boot("bob");
146179 await h.open();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs