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

A terminal screen adds its own palette entry from its own module, so a new screen no longer edits src/tui/forge.ts #7605

Parked opened this
Closed without merging

mason/forge:mason/7299-a-terminal-screen-adds-its-own-palette-e → main 7 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
56 files changed +1129 −645
AGENTS.md +2
@@ -5,3 +5,5 @@ Read `CLAUDE.md` first: it is the rulebook for agents editing this repo.
55 README.md is capped: a new feature's how-to goes in `docs/features/<name>.md`, not a new README section.
66
77 When you write an issue, end it with a `Files:` line naming the files the work touches (`Files: src/a.ts, docs/b.md`). The hot-file hold reads only that line when it is there; without it, every path the issue mentions counts.
8
9 A new terminal screen declares its own palette row: an exported `entry` (id, title, hint, `offered`, `run`) in `src/tui/screens/<name>.ts`, and one line in `src/tui/screens/entries.ts` that places it in the list. `src/tui/forge.ts` only reads that list and is not edited to add a row. That one line in `entries.ts` remains a shared edit: it removes the conflict on `forge.ts`, not on `entries.ts`. `test/tui-palette-entries.test.ts` holds the palette for an admin, a member, an agent and a signed-out session — add the new row to `test/fixtures/tui-palette.json` (`FORGE_WRITE_GOLDEN=1 bun test test/tui-palette-entries.test.ts`).
src/tui/forge.ts +15 −637
@@ -12,8 +12,7 @@ import type { App as Forge } from "../app.ts";
1212 import { search } from "../actions/search.ts";
1313 import { cleanQuery } from "../core/search.ts";
1414 import { guestCodeSearch } from "../http/strangers.ts";
15 import { sentinelSummary } from "../crew/sentinel.ts";
16 import { canRead, getRepo, type Repo } from "../core/repos.ts";
15 import { canRead, getRepo } from "../core/repos.ts";
1716 import { sourceFor } from "../view/source.ts";
1817 import { App, type Ctx, type Screen } from "./app/app.ts";
1918 import type { Command, PaletteItem, PaletteSearch } from "./app/palette.ts";
@@ -21,80 +20,13 @@ import { G } from "./term/screen.ts";
2120 import { fileIcon, icon, type IconName } from "./ui/icons.ts";
2221 import type { SessionOpts, Terminal } from "./term/terminal.ts";
2322 import { Session, type TuiIdentity } from "./session.ts";
24 import {
25 ISSUE_MARK,
26 ORIGIN_MARK,
27 PULL_MARK,
28 errorText,
29 pickerScreen,
30 promptScreen,
31 openOnWeb,
32 runAsync,
33 } from "./screens/common.ts";
34 import { chainScreen } from "./screens/chain.ts";
35 import { canSeeMemory } from "../boards/memory.ts";
36 import { boardsScreen } from "./screens/boards.ts";
37 import { askedScreen } from "./screens/asked.ts";
38 import { deciderScreen } from "./screens/decider.ts";
39 import { forgesScreen } from "./screens/forges.ts";
40 import { clientRows } from "../spawn/clients.ts";
41 import { familyScreen } from "./screens/family.ts";
42 import { familyLines, familyView } from "../spawn/family.ts";
23 import { ISSUE_MARK, ORIGIN_MARK, PULL_MARK, errorText } from "./screens/common.ts";
4324 import { issueScreen } from "./screens/issue.ts";
4425 import { pullScreen } from "./screens/pull.ts";
45 import { blobScreen } from "./screens/repo.ts";
26 import { blobScreen, repoScreen } from "./screens/repo.ts";
4627 import { dashboardScreen } from "./screens/dashboard.ts";
47 import { mayManageFlags } from "../core/flags.ts";
48 import { accessScreen } from "./screens/access.ts";
49 import { mayEditTrustedHosts } from "../origins/trusted-hosts.ts";
50 import { trustedHostsPrompt } from "./screens/trustedhosts.ts";
51 import { flagsScreen } from "./screens/flags.ts";
52 import { secretsScreen } from "./screens/secrets.ts";
53 import { scorecardScreen } from "./screens/scorecard.ts";
54 import { cloudScreen } from "./screens/cloud.ts";
55 import { crewSplitsScreen } from "./screens/crewsplits.ts";
56 import { crewHandoverScreen } from "./screens/crewhandover.ts";
57 import { usageScreen } from "./screens/usage.ts";
58 import { canScreen } from "./screens/can.ts";
59 import { peopleScreen } from "./screens/people.ts";
60 import { modelCeilingPrompt, modelGrantPrompt, modelScreen } from "./screens/model.ts";
61 import { notifyScreen } from "./screens/notify.ts";
62 import { sshKeysScreen } from "./screens/sshkeys.ts";
63 import { proposalTokensPrompt } from "./screens/proposal_tokens.ts";
64 import { invitesScreen } from "./screens/invites.ts";
65 import { subscriptionsScreen } from "./screens/subscriptions.ts";
66 import { signInsScreen } from "./screens/signins.ts";
67 import { limitsScreen } from "./screens/limits.ts";
68 import { quotasScreen } from "./screens/quotas.ts";
69 import { teamsScreen } from "./screens/teams.ts";
70 import { domainsScreen } from "./screens/domains.ts";
71 import { ownerScreen } from "./screens/owner.ts";
72 import { capacityScreen, mayCapacity } from "./screens/capacity.ts";
73 import { resilienceScreen } from "./screens/resilience.ts";
74 import { forgeCeiling } from "../flow/ceiling.ts";
75 import { flowLines, flowScreen } from "./screens/flow.ts";
76 import { readHeld } from "../flow/held.ts";
77 import { forgeLines, memoryScreen, systemLines, systemScreen } from "./screens/system.ts";
78 import { readHealth } from "../actions/health.ts";
79 import { grantable, READS_KEPT, recentReads } from "../core/telemetry.ts";
80 import { noteRead, setTelemetryGrant, telemetryReader } from "../actions/telemetry.ts";
81 import { queuesFor, systemFor } from "../system/telemetry.ts";
82 import { live as liveMachine } from "../system/live.ts";
83 import { apiScreen } from "./screens/api.ts";
84 import { changelogScreen } from "./screens/changelog.ts";
85 import { releasesScreen } from "./screens/releases.ts";
86 import { mayRead } from "../release/gate.ts";
87 import { fileHoldsPrompt } from "./screens/fileholds.ts";
88 import { stalledScreen } from "./screens/stalled.ts";
89 import { issuesScreen, newIssueScreen } from "./screens/issues.ts";
90 import { limbsScreen } from "./screens/limbs.ts";
91 import { newPullScreen } from "./screens/newpull.ts";
92 import { newForgeScreen } from "./screens/newforge.ts";
93 import { newOrgScreen } from "./screens/neworg.ts";
94 import { migrateScreen } from "./screens/migrate.ts";
95 import { newRepoScreen } from "./screens/newrepo.ts";
96 import { repoScreen } from "./screens/repo.ts";
97 import { signInScreen } from "./screens/signin.ts";
28 import { issuesScreen } from "./screens/issues.ts";
29 import { ENTRIES } from "./screens/entries.ts";
9830 import { local } from "./screens/where.ts";
9931
10032 export { Session, type TuiIdentity };
@@ -103,558 +35,19 @@ export function forgeRoot(session: Session): (ctx: Ctx) => Screen {
10335 return (ctx) => dashboardScreen(session, ctx);
10436 }
10537
106 /** The repo-scoped palette verbs: a name to ask for, and what to do with it. */
107 const REPO_VERBS: readonly {
108 id: string;
109 title: string;
110 /** The screen to push, or nothing when the verb hands over to the web. */
111 open: (f: Session, ctx: Ctx, repo: Repo) => Screen | undefined;
112 }[] = [
113 {
114 id: "repo",
115 title: "Open a repository",
116 open: (f, ctx, repo) => repoScreen(f, ctx, local(f, repo)),
117 },
118 {
119 id: "issues",
120 title: "Issues in a repository",
121 open: (f, ctx, repo) => issuesScreen(f, ctx, local(f, repo), "issue"),
122 },
123 {
124 id: "pulls",
125 title: "Pull requests in a repository",
126 open: (f, ctx, repo) => issuesScreen(f, ctx, local(f, repo), "pull"),
127 },
128 {
129 id: "milestones",
130 title: "Milestones in a repository",
131 open: (f, ctx, repo) => limbsScreen(f, ctx, repo),
132 },
133 {
134 // What the crew's tokens bought on one app, as MCP `returns` with `repo` (#7271).
135 id: "repo-usage",
136 title: "Usage of a repository",
137 open: (f, ctx, repo) => usageScreen(f, ctx, repo),
138 },
139 { id: "new-issue", title: "New issue", open: newIssueScreen },
140 { id: "new-pull", title: "New pull request", open: newPullScreen },
141 {
142 id: "settings",
143 title: "Repository settings",
144 // One settings page, the web's (#635): the terminal hands over its address.
145 open: (f, ctx, repo) => {
146 openOnWeb(f, ctx, `/${repo.ownerName}/${repo.name}/settings`, "Settings");
147 return undefined;
148 },
149 },
150 ];
151
15238 /**
153 * The palette. Repo-scoped verbs ask for `owner/name` in a prompt and resolve
154 * it through `getRepo` plus the screen's own access checks — a repo you
155 * cannot read is reported as not found, exactly as it is everywhere else.
39 * The palette: the rows `screens/entries.ts` names, those the session is
40 * offered, in that order. Each row's id, title, hint, audience and screen
41 * live next to the screen itself.
15642 */
15743 export function forgeCommands(session: Session): (ctx: Ctx) => Command[] {
158 return (ctx) => {
159 const commands: Command[] = [
160 {
161 id: "home",
162 title: "Home",
163 hint: "your repositories",
164 run: () => ctx.push(dashboardScreen(session, ctx)),
165 },
166 {
167 // Browsing other people and forges is the web explorer's (#607):
168 // the terminal hands over its address.
169 id: "explore",
170 title: "Explore",
171 hint: "on the web",
172 run: () => openOnWeb(session, ctx, "/explore", "The explorer"),
173 },
174 {
175 // A person's or an org's page is the web's (#636): the terminal
176 // hands over its address.
177 id: "profile",
178 title: "Open a profile",
179 hint: "username or org",
180 run: () =>
181 ctx.push(
182 askFor(ctx, "Profile", "username", (name) => {
183 openOnWeb(session, ctx, `/${encodeURIComponent(name)}`, "That profile");
184 return undefined;
185 }),
186 ),
187 },
188 ];
189
190 for (const verb of REPO_VERBS)
191 commands.push({
192 id: verb.id,
193 title: verb.title,
194 hint: "owner/name",
195 run: () =>
196 ctx.push(
197 askFor(ctx, verb.title, "owner/name", (spec) => {
198 const [owner, name] = spec.split("/");
199 const repo =
200 owner && name ? getRepo(session.db, owner, name) : undefined;
201 // The palette is a client like any other: a repo you cannot
202 // read is "not found", indistinguishable from a typo. Without
203 // this check the palette would be a way around `canRead`.
204 if (!repo || !canRead(session.db, repo, session.user))
205 return "not found";
206 // After the prompt has popped itself, or the pop takes the
207 // screen just pushed instead (`later` in screens/common.ts).
208 return Promise.resolve().then(() => {
209 const next = verb.open(session, ctx, repo);
210 if (next !== undefined) ctx.push(next);
211 });
212 }),
213 ),
214 });
215
216 commands.push(
217 session.signedIn
218 ? {
219 id: "new-repo",
220 title: "New repository",
221 run: () => ctx.push(newRepoScreen(session, ctx)),
222 }
223 : {
224 id: "signin",
225 title: "Sign in",
226 run: () =>
227 ctx.push(signInScreen(session, ctx, () => ctx.invalidate())),
228 },
229 );
230 // An organization you own, as /organizations/new and MCP `org_create` make it: a person's, never an agent's (#7260).
231 if (session.user !== undefined && session.user.kind !== "agent")
232 commands.push({
233 id: "new-org",
234 title: "New organization",
235 hint: "an organization you own, for a client's apps",
236 run: () => ctx.push(newOrgScreen(session, ctx)),
237 });
238 if (session.signedIn)
239 commands.push({
240 id: "migrate",
241 title: "Migrate a repository",
242 hint: "bring one in from an origin or a URL, pick its branch, put a crew on it",
243 run: () => ctx.push(migrateScreen(session, ctx)),
244 });
245 // A client's forge, as /forges/new makes it: any signed-in person's; the door decides the rest.
246 if (session.signedIn)
247 commands.push({
248 id: "new-forge",
249 title: "New forge",
250 hint: "spawn a client's forge and get its claim link",
251 run: () => ctx.push(newForgeScreen(session, ctx)),
252 });
253 // What you asked for and what became of it, as /asked says it: a signed-in person's.
254 if (session.signedIn)
255 commands.push({
256 id: "asked",
257 title: "Asked",
258 hint: "your thoughts and what became of them",
259 run: () => ctx.push(askedScreen(session, ctx)),
260 });
261 if (session.signedIn)
262 commands.push({
263 id: "decider",
264 title: "Decider",
265 hint: "what it closed, deferred and asked you about today",
266 run: () => ctx.push(deciderScreen(session, ctx)),
267 });
268 // Where a decision finds the owner; an agent is never offered it.
269 if (session.signedIn && session.user?.kind !== "agent")
270 commands.push({
271 id: "notify",
272 title: "Phone notifications",
273 hint: "where the crew reaches your phone; s sets, x turns off",
274 run: () => ctx.push(notifyScreen(session, ctx)),
275 });
276 if (session.signedIn)
277 commands.push({
278 id: "ssh-keys",
279 title: "SSH keys",
280 hint: "list, add and remove the keys that sign in as you",
281 run: () => ctx.push(sshKeysScreen(session, ctx)),
282 });
283 if (session.signedIn)
284 commands.push(
285 {
286 id: "account",
287 title: "Account settings",
288 run: () => openOnWeb(session, ctx, "/settings", "Account settings"),
289 },
290 // Settings → Sessions and MCP `sessions`, in the terminal (#7237).
291 {
292 id: "signins",
293 title: "Signed in",
294 hint: "your browsers and tokens; d signs a browser out",
295 run: () => ctx.push(signInsScreen(session, ctx)),
296 },
297 );
298 // The forge's own faults, as the board's strip shows them: a site admin's.
299 if (session.user?.isAdmin === true)
300 commands.push({
301 id: "sentinel",
302 title: "Sentinel",
303 hint: "the forge's open faults",
304 run: () =>
305 ctx.toast(
306 sentinelSummary(session.db) ?? "The sentinel has not hunted yet",
307 "default",
308 ),
309 });
310 // The boards, as the page gates them: a site admin who is a person, never an agent (#1817).
311 if (session.user?.isAdmin === true && session.user.kind !== "agent")
312 commands.push({
313 id: "boards",
314 title: "Boards",
315 hint: "the forge's boards and their panels",
316 run: () => ctx.push(boardsScreen(session, ctx)),
317 });
318 // The forge's RSS beside its JS heap, as /system gates it (#2151).
319 if (canSeeMemory(session.user))
320 commands.push({
321 id: "system-memory",
322 title: "System memory",
323 hint: "RSS beside the JS heap, hourly for 24 h",
324 run: () => ctx.push(memoryScreen(session, ctx)),
325 });
326 // The pipeline's bottleneck and throughput, as /flow says them: a site admin's (#1554, #1786).
327 const flowReader = telemetryReader(session.app, session.user);
328 if (flowReader)
329 commands.push({
330 id: "flow",
331 title: "Flow",
332 hint: "the pipeline's bottleneck and throughput",
333 run: () => {
334 if (session.user) noteRead(session.app, session.user, flowReader, "flow");
335 ctx.push(flowScreen(ctx, flowLines(
336 session.db,
337 new Date(),
338 systemFor(session.app, flowReader).duplicates,
339 flowReader.kind === "agent" ? { queues: queuesFor(session.app, flowReader, new Date(), { batches: true }) } : undefined,
340 readHeld(session.app, flowReader.kind === "owner"),
341 forgeCeiling(session.app.config),
342 )));
343 },
344 });
345 // The machine, as /system says it, and which agents may read it: the owner's, a person (#1789).
346 if (session.user?.isAdmin === true && session.user.kind !== "agent") {
347 commands.push({
348 id: "system",
349 title: "System",
350 hint: "the machine now: CPU, memory, disks, processes",
351 run: () => ctx.push(systemScreen(ctx, [
352 ...forgeLines(readHealth(session.app, session.user)),
353 "",
354 ...systemLines(liveMachine().read()),
355 ], session)),
356 });
357 commands.push({
358 id: "telemetry",
359 title: "Telemetry",
360 hint: "which agents may read flow and system; enter flips the grant",
361 run: () => {
362 const actor = session.user;
363 const agents = grantable(session.db);
364 if (agents.length === 0) return ctx.toast("No agent accounts yet");
365 const last = new Map<string, { n: number; what: string; at: string }>();
366 for (const r of recentReads(session.db, READS_KEPT).reverse()) {
367 last.set(r.username, { n: (last.get(r.username)?.n ?? 0) + 1, what: r.what, at: r.at });
368 }
369 const readsOf = (name: string): string => {
370 const l = last.get(name);
371 return l ? `${l.n} read${l.n === 1 ? "" : "s"}, last ${l.what} ${l.at}` : "no reads";
372 };
373 ctx.push(
374 pickerScreen(ctx, blank("Telemetry"), {
375 title: "Telemetry: telemetry:read",
376 items: agents.map((a) => ({ id: a.username, label: a.username, hint: `${a.granted ? "granted" : "not granted"} · ${readsOf(a.username)}` })),
377 onPick: ([name]) => {
378 const was = agents.find((a) => a.username === name);
379 if (!was) return;
380 const done = setTelemetryGrant(session.app, actor, was.username, !was.granted);
381 ctx.toast(
382 done.ok ? `${was.username}: telemetry:read ${done.value.on ? "granted" : "revoked"}` : "Could not change the grant",
383 done.ok ? "success" : "attn",
384 );
385 },
386 }),
387 );
388 },
389 });
390 }
391 // The forge's capacity and guards, as MCP `capacity` gates them: a forge admin who is a person.
392 if (mayCapacity(session))
393 commands.push({
394 id: "capacity",
395 title: "Capacity",
396 hint: "concurrency and guards, live; e changes a settable one",
397 run: () => ctx.push(capacityScreen(session, ctx)),
398 });
399 // Where snapshots go and each THREATS.md protection's standing, as /resilience says it: a site admin's; a person admin sets or forgets the destination and the mirror here.
400 if (session.user?.isAdmin === true)
401 commands.push({
402 id: "resilience",
403 title: "Resilience",
404 hint: "where snapshots go and the mirror; each protection green, red or untested",
405 run: () => ctx.push(resilienceScreen(session, ctx)),
406 });
407 // The forge's API operations, as /api lists them; Enter runs a GET: for anyone.
408 commands.push({
409 id: "api",
410 title: "API",
411 hint: "the forge's endpoints; run a GET",
412 run: () => ctx.push(apiScreen(session, ctx)),
413 });
414 // The last releases with their pulls, as /changelog shows them: for anyone.
415 commands.push({
416 id: "changelog",
417 title: "Changelog",
418 hint: "the last 30 releases and their pulls",
419 run: () => ctx.push(changelogScreen(session, ctx)),
420 });
421 // The live release and the kept ones, as /releases gates them: a site admin or a reader of FORGE_REPO.
422 if (mayRead(session.app, session.user))
423 commands.push({
424 id: "releases",
425 title: "Releases",
426 hint: "the live release and the kept ones",
427 run: () => ctx.push(releasesScreen(session, ctx)),
428 });
429 // Stalled flow steps the viewer can unblock, as the home's cards show them (#1807).
430 if (session.signedIn)
431 commands.push({
432 id: "stalled",
433 title: "Stalled steps",
434 hint: "pulls whose check is red or was never asked for; enter re-runs",
435 run: () => ctx.push(stalledScreen(session, ctx)),
436 });
437 // Hold new work on a file: the settings card's twin, admin-checked by the action itself.
438 if (session.signedIn)
439 commands.push({
440 id: "file-holds",
441 title: "Held files",
442 hint: "hold new work on a file, release it, or list the holds",
443 run: () => ctx.push(fileHoldsPrompt(session, ctx, blank("Held files"))),
444 });
445 // What outside agents tried, as Settings → Access says it: a site admin's (#1768).
446 if (session.user?.isAdmin === true && session.user.kind !== "agent")
447 commands.push({
448 id: "access",
449 title: "Access",
450 hint: "what outside agents tried",
451 run: () => ctx.push(accessScreen(session, ctx)),
452 });
453 // Settings → Flags, as the page has it: an admin who is not an agent (#1970).
454 if (mayManageFlags(session.user))
455 commands.push({
456 id: "flags",
457 title: "Flags",
458 hint: "declared flags and their live values",
459 run: () => ctx.push(flagsScreen(session, ctx)),
460 });
461 // Settings → Secrets, as the page has it: a forge admin; names only, never a value.
462 if (session.user?.isAdmin === true)
463 commands.push({
464 id: "secrets",
465 title: "Secrets",
466 hint: "sealed secrets by name; set or remove one",
467 run: () => ctx.push(secretsScreen(session, ctx)),
468 });
469 // Settings → Origins' trusted internal hosts: the same admin gate as the page.
470 if (mayEditTrustedHosts(session.user))
471 commands.push({
472 id: "trusted-hosts",
473 title: "Trusted hosts",
474 hint: "internal hosts an origin may reach",
475 run: () => ctx.push(trustedHostsPrompt(session, ctx, blank("Trusted hosts"))),
476 });
477 // Settings → Usage, as the page has it: the same gate as Flags (#1565).
478 if (mayManageFlags(session.user))
479 commands.push({
480 id: "usage",
481 title: "Usage",
482 hint: "every route, unused ones first",
483 run: () => ctx.push(usageScreen(session, ctx)),
484 });
485 // Settings → Crew's scorecard by model and prompt version: an admin (#2682).
486 if (session.user?.isAdmin === true)
487 commands.push({
488 id: "crew-scorecard",
489 title: "Crew scorecard",
490 hint: "agent runs per model and per prompt version",
491 run: () => ctx.push(crewSplitsScreen(session, ctx)),
492 });
493 // Settings → Crew's hand-overs: issues parked twice, the last restore drill.
494 if (session.user?.isAdmin === true)
495 commands.push({
496 id: "crew-handover",
497 title: "Crew hand-overs",
498 hint: "issues parked twice, and the last restore drill",
499 run: () => ctx.push(crewHandoverScreen(session, ctx)),
500 });
501 // Settings → Crew's scorecard per agent, as the page has it: a forge admin (#2677).
502 if (session.user?.isAdmin === true)
503 commands.push({
504 id: "scorecard",
505 title: "Crew scorecard per agent",
506 hint: "each agent's pulls landed, review rounds, red checks, reverts, time to land",
507 run: () => ctx.push(scorecardScreen(session, ctx)),
508 });
509 // Proposal tokens for a repository you write, as the API and MCP have them (#2148).
510 if (session.user !== undefined)
511 commands.push({
512 id: "proposal-tokens",
513 title: "Proposal tokens",
514 hint: "mint, list and revoke what a child proposes with",
515 run: () => ctx.push(proposalTokensPrompt(session, ctx, blank("Proposal tokens"))),
516 });
517 // Settings → Model: a person's own budget and subscription, as the page has them (#1145).
518 if (session.user?.kind === "user")
519 commands.push({
520 id: "model",
521 title: "Model budget",
522 hint: "what your crew may spend, and add your own subscription",
523 run: () => ctx.push(modelScreen(session, ctx)),
524 });
525 // A capped monthly grant to an account: a forge admin who is a person (#1145).
526 if (session.user?.isAdmin === true && session.user.kind === "user")
527 commands.push({
528 id: "model-grant",
529 title: "Model grant",
530 hint: "give an account dollars a month, or take it back",
531 run: () => ctx.push(modelGrantPrompt(session, ctx, blank("Model grant"))),
532 });
533 if (session.user?.isAdmin === true && session.user.kind === "user")
534 commands.push({
535 id: "model-ceiling",
536 title: "Model ceiling",
537 hint: "set an account's dollars a day and a run",
538 run: () => ctx.push(modelCeilingPrompt(session, ctx, blank("Model ceiling"))),
539 });
540 // The caller's own role and row of the roles table, as /settings and `whoami_can` have it (#2304).
541 if (session.user !== undefined)
542 commands.push({
543 id: "can",
544 title: "What I can do",
545 hint: "your role and what it allows here",
546 run: () => ctx.push(canScreen(session, ctx)),
547 });
548 // Guests, members and admins, as /settings/people has them (#2301).
549 if (session.user?.isAdmin === true && session.user.kind === "user")
550 commands.push({
551 id: "people",
552 title: "People",
553 hint: "who is a guest, a member or an admin; promote or demote",
554 run: () => ctx.push(peopleScreen(session, ctx)),
555 });
556 // Account quotas, as /admin/limits has them: an admin who is not an agent (#2191).
557 if (session.user?.isAdmin === true && session.user.kind !== "agent")
558 commands.push({
559 id: "quotas",
560 title: "Account quotas",
561 hint: "what one account may own, and who changed it",
562 run: () => ctx.push(quotasScreen(session, ctx)),
563 });
564 // The forge's limits, as MCP `limits` has them: an admin who is not an agent (#7268).
565 if (session.user?.isAdmin === true && session.user.kind !== "agent")
566 commands.push({
567 id: "limits",
568 title: "Limits",
569 hint: "what the forge caps, with default and bounds; change one",
570 run: () => ctx.push(limitsScreen(session, ctx)),
571 });
572 // Crew teams, as /settings/teams has them: an admin who is not an agent (#2679).
573 if (session.user?.isAdmin === true && session.user.kind !== "agent")
574 commands.push({
575 id: "teams",
576 title: "Crew teams",
577 hint: "each team's charter, dial and members",
578 run: () => ctx.push(teamsScreen(session, ctx)),
579 });
580 // Invite links, as /admin/limits has them: an admin who is a person (#2337).
581 if (session.user?.isAdmin === true && session.user.kind === "user")
582 commands.push({
583 id: "invites",
584 title: "Invite links",
585 hint: "make a single-use link, see which are open, revoke one",
586 run: () => ctx.push(invitesScreen(session, ctx)),
587 });
588 // The crew's Claude subscriptions, as MCP `subscriptions` has them: a forge admin (#7244).
589 if (session.user?.isAdmin === true && session.user.kind === "user")
590 commands.push({
591 id: "subscriptions",
592 title: "Crew subscriptions",
593 hint: "each account's budget and rest; wake one, set its budget, add or remove one",
594 run: () => ctx.push(subscriptionsScreen(session, ctx)),
595 });
596 // Cloud accounts, as Settings → Cloud accounts has them: a forge admin (#2199).
597 if (session.user?.isAdmin === true)
598 commands.push({
599 id: "cloud",
600 title: "Cloud accounts",
601 hint: "provider tokens, what they are used for, today's calls",
602 run: () => ctx.push(cloudScreen(session, ctx)),
603 });
604 // Each failure domain and its last drill, as Settings → Backups → Failure domains says it (#1945).
605 if (session.user?.isAdmin === true && session.user.kind !== "agent")
606 commands.push({
607 id: "domains",
608 title: "Failure domains",
609 hint: "failure domains and their last drill",
610 run: () => ctx.push(domainsScreen(session, ctx)),
611 });
612 // What needs the owner: needs, snapshot store, every failure domain (#1236).
613 if (session.user?.isAdmin === true && session.user.kind !== "agent")
614 commands.push({
615 id: "owner",
616 title: "Owner's needs",
617 hint: "what needs the owner, snapshots, failure domains",
618 run: () => ctx.push(ownerScreen(session, ctx)),
619 });
620 // The forges this one sent, as /forges lists them: an admin's only.
621 if (session.user?.isAdmin === true)
622 commands.push({
623 id: "forges",
624 title: "Forges you sent",
625 hint: "each forge sent, claimed or not, and its apps",
626 run: () =>
627 runAsync(ctx, async () => {
628 ctx.push(forgesScreen(ctx, await clientRows(session.app)));
629 }),
630 });
631 commands.push({
632 id: "family",
633 title: "Family",
634 hint: "the forge that sent this one, and the forges it sent",
635 run: () =>
636 runAsync(ctx, async () => {
637 const view = await familyView(session.app, session.user?.isAdmin === true);
638 ctx.push(familyScreen(ctx, familyLines(view)));
639 }),
640 });
641 commands.push({
642 id: "chain",
643 title: "Chain",
644 hint: "the forges this forge's code descends from, root first",
645 run: () =>
646 runAsync(ctx, async () => {
647 ctx.push(await chainScreen(session.app, session.user, ctx));
648 }),
649 });
650 commands.push({
651 id: "quit",
652 title: "Quit",
653 hint: "disconnect",
654 run: () => ctx.quit(),
655 });
656 return commands;
657 };
44 return (ctx) =>
45 ENTRIES.filter((entry) => entry.offered(session)).map((entry) => ({
46 id: entry.id,
47 title: entry.title,
48 ...(entry.hint !== undefined ? { hint: entry.hint } : {}),
49 run: () => entry.run(session, ctx),
50 }));
65851 }
65952
66053 /**
@@ -842,21 +235,6 @@ function countsHint(
842235 .join(" ");
843236 }
844237
845 /** A screen that draws nothing — the parent a palette-launched modal has. */
846 function blank(title: string): Screen {
847 return { title, keys: [], render: () => undefined, key: () => false };
848 }
849
850 /** A prompt with no parent to draw behind it — the palette closed already. */
851 function askFor(
852 ctx: Ctx,
853 title: string,
854 label: string,
855 onSubmit: (value: string) => string | undefined | Promise<void>,
856 ): Screen {
857 return promptScreen(ctx, blank(title), { title, label, onSubmit });
858 }
859
860238 export interface ForgeAppOptions extends SessionOpts {
861239 readonly terminal: Terminal;
862240 }
src/tui/screens/access.ts +11
@@ -16,6 +16,8 @@ import { style } from "../term/style.ts";
1616 import { truncate } from "../term/width.ts";
1717 import type { Session } from "../session.ts";
1818 import { ListState, drawList, promptScreen, type ListRow } from "./common.ts";
19 import type { Entry } from "./entry.ts";
20 import { isAdminNotAgent } from "./entry.ts";
1921
2022 type Filter = "since" | "ua" | "path";
2123
@@ -111,3 +113,12 @@ export function accessScreen(f: Session, ctx: Ctx): Screen {
111113 };
112114 return screen;
113115 }
116
117 /** What outside agents tried, as Settings → Access says it: a site admin's (#1768). */
118 export const entry: Entry = {
119 id: "access",
120 title: "Access",
121 hint: "what outside agents tried",
122 offered: isAdminNotAgent,
123 run: (s, ctx) => ctx.push(accessScreen(s, ctx)),
124 };
src/tui/screens/api.ts +10
@@ -17,6 +17,7 @@ import { fill, len, split } from "../ui/layout.ts";
1717 import { style } from "../term/style.ts";
1818 import { truncate } from "../term/width.ts";
1919 import { emptyState } from "../ui/widgets.ts";
20 import type { Entry } from "./entry.ts";
2021 import { Filter, ListState, Scroll, drawLines, drawList, metaOf, type ListRow } from "./common.ts";
2122
2223 const MAX_SHOWN = 400;
@@ -137,3 +138,12 @@ export function apiScreen(f: Session, ctx: Ctx): Screen {
137138 },
138139 };
139140 }
141
142 /** The forge's API operations, as /api lists them; Enter runs a GET: for anyone. */
143 export const entry: Entry = {
144 id: "api",
145 title: "API",
146 hint: "the forge's endpoints; run a GET",
147 offered: () => true,
148 run: (s, ctx) => ctx.push(apiScreen(s, ctx)),
149 };
src/tui/screens/asked.ts +10
@@ -32,6 +32,7 @@ import { emptyState, type Tone } from "../ui/widgets.ts";
3232 import { style } from "../term/style.ts";
3333 import { truncate } from "../term/width.ts";
3434 import { ListState, drawList, hitList, metaOf, openOnWeb, relTime, type ListRow } from "./common.ts";
35 import type { Entry } from "./entry.ts";
3536 import { issueScreen } from "./issue.ts";
3637 import { local } from "./where.ts";
3738
@@ -284,3 +285,12 @@ export function askedScreen(f: Session, ctx: Ctx): Screen {
284285 },
285286 };
286287 }
288
289 /** What you asked for and what became of it, as /asked says it: a signed-in person's. */
290 export const entry: Entry = {
291 id: "asked",
292 title: "Asked",
293 hint: "your thoughts and what became of them",
294 offered: (s) => s.signedIn,
295 run: (s, ctx) => ctx.push(askedScreen(s, ctx)),
296 };
src/tui/screens/boards.ts +11
@@ -23,6 +23,8 @@ import { emptyState } from "../ui/widgets.ts";
2323 import { style } from "../term/style.ts";
2424 import { truncate } from "../term/width.ts";
2525 import { ListState, Scroll, drawList, promptScreen, drawLines, hitList, hitScroll, metaOf, plural, runAsync, type ListRow } from "./common.ts";
26 import type { Entry } from "./entry.ts";
27 import { isAdminNotAgent } from "./entry.ts";
2628
2729 /** One line of plain text: a title or a query value may carry escapes the terminal must not obey. */
2830 export const plain = (text: string): string =>
@@ -247,3 +249,12 @@ export function boardsScreen(f: Session, ctx: Ctx): Screen {
247249 };
248250 return screen;
249251 }
252
253 /** The boards, as the page gates them: a site admin who is a person, never an agent (#1817). */
254 export const entry: Entry = {
255 id: "boards",
256 title: "Boards",
257 hint: "the forge's boards and their panels",
258 offered: isAdminNotAgent,
259 run: (s, ctx) => ctx.push(boardsScreen(s, ctx)),
260 };
src/tui/screens/can.ts +10
@@ -22,6 +22,7 @@ import { binding } from "../app/keys.ts";
2222 import type { Session } from "../session.ts";
2323 import { style } from "../term/style.ts";
2424 import { truncate } from "../term/width.ts";
25 import type { Entry } from "./entry.ts";
2526
2627 export function canScreen(f: Session, ctx: Ctx): Screen {
2728 const edgeLogin = (): string | undefined => {
@@ -93,3 +94,12 @@ export function canScreen(f: Session, ctx: Ctx): Screen {
9394 },
9495 };
9596 }
97
98 /** The caller's own role and row of the roles table, as /settings and `whoami_can` have it (#2304). */
99 export const entry: Entry = {
100 id: "can",
101 title: "What I can do",
102 hint: "your role and what it allows here",
103 offered: (s) => s.user !== undefined,
104 run: (s, ctx) => ctx.push(canScreen(s, ctx)),
105 };
src/tui/screens/capacity.ts +10
@@ -15,6 +15,7 @@ import { style } from "../term/style.ts";
1515 import { truncate } from "../term/width.ts";
1616 import { fill, len, split } from "../ui/layout.ts";
1717 import { ListState, confirmScreen, drawList, later, promptScreen, type ListRow } from "./common.ts";
18 import type { Entry } from "./entry.ts";
1819
1920 /** Whether the palette offers the screen: a forge admin who is a person. */
2021 export const mayCapacity = (session: Session): boolean =>
@@ -98,3 +99,12 @@ export function capacityScreen(f: Session, ctx: Ctx): Screen {
9899 };
99100 return screen;
100101 }
102
103 /** The forge's capacity and guards, as MCP `capacity` gates them: a forge admin who is a person. */
104 export const entry: Entry = {
105 id: "capacity",
106 title: "Capacity",
107 hint: "concurrency and guards, live; e changes a settable one",
108 offered: mayCapacity,
109 run: (s, ctx) => ctx.push(capacityScreen(s, ctx)),
110 };
src/tui/screens/chain.ts +14 −1
@@ -17,8 +17,9 @@ import { chainLines, chainOfRepo, forgeLinkOf, type ChainView, type FollowMode }
1717 import type { Ctx, Screen } from "../app/app.ts";
1818 import { binding } from "../app/keys.ts";
1919 import { card } from "../ui/widgets.ts";
20 import { drawFacts, promptScreen } from "./common.ts";
20 import { drawFacts, promptScreen, runAsync } from "./common.ts";
2121 import { familyScreen } from "./family.ts";
22 import type { Entry } from "./entry.ts";
2223
2324 /** The forge repository and its chain, when this viewer may read that repository. */
2425 export async function readableChain(
@@ -132,3 +133,15 @@ export async function chainScreen(app: Forge, user: User | undefined, ctx: Ctx):
132133 };
133134 return self;
134135 }
136
137 /** The forges this forge's code descends from, root first: offered to everyone; the screen shows only what the viewer may read. */
138 export const entry: Entry = {
139 id: "chain",
140 title: "Chain",
141 hint: "the forges this forge's code descends from, root first",
142 offered: () => true,
143 run: (s, ctx) =>
144 runAsync(ctx, async () => {
145 ctx.push(await chainScreen(s.app, s.user, ctx));
146 }),
147 };
src/tui/screens/changelog.ts +10
@@ -16,6 +16,7 @@ import { truncate } from "../term/width.ts";
1616 import { emptyState } from "../ui/widgets.ts";
1717 import { pullScreen } from "./pull.ts";
1818 import { Filter, ListState, ago, drawList, metaOf, type ListRow } from "./common.ts";
19 import type { Entry } from "./entry.ts";
1920
2021 /** Whether a release's version or any pull it carried names the word. */
2122 export function releaseMatches(filter: Filter, e: ReleaseEntry): boolean {
@@ -121,3 +122,12 @@ export function changelogScreen(f: Session, ctx: Ctx): Screen {
121122 },
122123 };
123124 }
125
126 /** The last releases with their pulls, as /changelog shows them: for anyone. */
127 export const entry: Entry = {
128 id: "changelog",
129 title: "Changelog",
130 hint: "the last 30 releases and their pulls",
131 offered: () => true,
132 run: (s, ctx) => ctx.push(changelogScreen(s, ctx)),
133 };
src/tui/screens/cloud.ts +11
@@ -18,6 +18,8 @@ import { truncate } from "../term/width.ts";
1818 import type { Session } from "../session.ts";
1919 import { fill, len, split } from "../ui/layout.ts";
2020 import { ListState, drawList, later, promptScreen, type ListRow } from "./common.ts";
21 import type { Entry } from "./entry.ts";
22 import { isAdmin } from "./entry.ts";
2123
2224 const day = (at: string | null): string => (at === null ? "never" : at.slice(0, 16).replace("T", " "));
2325
@@ -210,3 +212,12 @@ export function cloudScreen(f: Session, ctx: Ctx): Screen {
210212 };
211213 return screen;
212214 }
215
216 /** Cloud accounts, as Settings → Cloud accounts has them: a forge admin (#2199). */
217 export const entry: Entry = {
218 id: "cloud",
219 title: "Cloud accounts",
220 hint: "provider tokens, what they are used for, today's calls",
221 offered: isAdmin,
222 run: (s, ctx) => ctx.push(cloudScreen(s, ctx)),
223 };
src/tui/screens/common.ts +15
@@ -1072,3 +1072,18 @@ export function ago(iso: string): string {
10721072 }
10731073
10741074 export { plural } from "../../kernel/plural.ts";
1075
1076 /** A screen that draws nothing — the parent a palette-launched modal has. */
1077 export function blank(title: string): Screen {
1078 return { title, keys: [], render: () => undefined, key: () => false };
1079 }
1080
1081 /** A prompt with no parent to draw behind it — the palette closed already. */
1082 export function askFor(
1083 ctx: Ctx,
1084 title: string,
1085 label: string,
1086 onSubmit: (value: string) => string | undefined | Promise<void>,
1087 ): Screen {
1088 return promptScreen(ctx, blank(title), { title, label, onSubmit });
1089 }
src/tui/screens/crewhandover.ts +11
@@ -15,6 +15,8 @@ import { fill, len, split } from "../ui/layout.ts";
1515 import { issueScreen } from "./issue.ts";
1616 import { local } from "./where.ts";
1717 import { ListState, drawList, type ListRow } from "./common.ts";
18 import type { Entry } from "./entry.ts";
19 import { isAdmin } from "./entry.ts";
1820
1921 export function crewHandoverScreen(f: Session, ctx: Ctx): Screen {
2022 const state = new ListState();
@@ -80,3 +82,12 @@ export function crewHandoverScreen(f: Session, ctx: Ctx): Screen {
8082 },
8183 };
8284 }
85
86 /** Settings → Crew's hand-overs: issues parked twice, the last restore drill. */
87 export const entry: Entry = {
88 id: "crew-handover",
89 title: "Crew hand-overs",
90 hint: "issues parked twice, and the last restore drill",
91 offered: isAdmin,
92 run: (s, ctx) => ctx.push(crewHandoverScreen(s, ctx)),
93 };
src/tui/screens/crewsplits.ts +11
@@ -13,6 +13,8 @@ import { truncate } from "../term/width.ts";
1313 import type { Session } from "../session.ts";
1414 import { fill, len, split } from "../ui/layout.ts";
1515 import { ListState, drawList, type ListRow } from "./common.ts";
16 import type { Entry } from "./entry.ts";
17 import { isAdmin } from "./entry.ts";
1618
1719 export function splitRows(
1820 label: string,
@@ -62,3 +64,12 @@ export function crewSplitsScreen(f: Session, ctx: Ctx): Screen {
6264 key: (e) => state.key(e, rows.length),
6365 };
6466 }
67
68 /** Settings → Crew's scorecard by model and prompt version: an admin (#2682). */
69 export const entry: Entry = {
70 id: "crew-scorecard",
71 title: "Crew scorecard",
72 hint: "agent runs per model and per prompt version",
73 offered: isAdmin,
74 run: (s, ctx) => ctx.push(crewSplitsScreen(s, ctx)),
75 };
src/tui/screens/dashboard.ts +10
@@ -118,6 +118,7 @@ import { pullScreen } from "./pull.ts";
118118 import { repoScreen } from "./repo.ts";
119119 import { local } from "./where.ts";
120120 import { signInScreen } from "./signin.ts";
121 import type { Entry } from "./entry.ts";
121122
122123 /** Rows the list keeps under the figures strip; below it the strip shows fewer figures. */
123124 const FIGURES_ROOM = 6;
@@ -1459,3 +1460,12 @@ function note(s: Surface, r: Rect, c: Tokens, lines: readonly string[]): void {
14591460 ),
14601461 );
14611462 }
1463
1464 /** Home, offered to everyone: a signed-out session sees the dashboard's guest view. */
1465 export const entry: Entry = {
1466 id: "home",
1467 title: "Home",
1468 hint: "your repositories",
1469 offered: () => true,
1470 run: (s, ctx) => ctx.push(dashboardScreen(s, ctx)),
1471 };
src/tui/screens/decider.ts +10
@@ -28,6 +28,7 @@ import { emptyState } from "../ui/widgets.ts";
2828 import { style } from "../term/style.ts";
2929 import { truncate } from "../term/width.ts";
3030 import { ListState, drawList, hitList, metaOf, openOnWeb, relTime, type ListRow } from "./common.ts";
31 import type { Entry } from "./entry.ts";
3132
3233 const ROWS = 200;
3334
@@ -120,3 +121,12 @@ export function deciderScreen(f: Session, ctx: Ctx, first: DeciderPile = "closed
120121 },
121122 };
122123 }
124
125 /** What the decider closed, deferred or asked you about: a signed-in person's. */
126 export const entry: Entry = {
127 id: "decider",
128 title: "Decider",
129 hint: "what it closed, deferred and asked you about today",
130 offered: (s) => s.signedIn,
131 run: (s, ctx) => ctx.push(deciderScreen(s, ctx)),
132 };
src/tui/screens/domains.ts +11
@@ -14,6 +14,8 @@ import { style } from "../term/style.ts";
1414 import { truncate } from "../term/width.ts";
1515 import type { Session } from "../session.ts";
1616 import { ListState, confirmScreen, drawList, type ListRow } from "./common.ts";
17 import type { Entry } from "./entry.ts";
18 import { isAdminNotAgent } from "./entry.ts";
1719
1820 function drillLine(d: ResilienceRow): string {
1921 if (d.drill.name === null) return `Not drilled: ${d.drill.why}`;
@@ -127,3 +129,12 @@ export function domainsScreen(f: Session, ctx: Ctx): Screen {
127129 };
128130 return screen;
129131 }
132
133 /** Each failure domain and its last drill, as Settings → Backups → Failure domains says it (#1945). */
134 export const entry: Entry = {
135 id: "domains",
136 title: "Failure domains",
137 hint: "failure domains and their last drill",
138 offered: isAdminNotAgent,
139 run: (s, ctx) => ctx.push(domainsScreen(s, ctx)),
140 };
src/tui/screens/entries.ts added +113
@@ -0,0 +1,113 @@
1 /**
2 * The palette's rows, in the order it lists them. Each row is declared next to
3 * its screen (an exported `entry`); a new screen adds its own and one line
4 * here, so `tui/forge.ts` is not edited for it.
5 */
6
7 import { entry as access } from "./access.ts";
8 import { entry as api } from "./api.ts";
9 import { entry as asked } from "./asked.ts";
10 import { entry as boards } from "./boards.ts";
11 import { entry as can } from "./can.ts";
12 import { entry as capacity } from "./capacity.ts";
13 import { entry as chain } from "./chain.ts";
14 import { entry as changelog } from "./changelog.ts";
15 import { entry as cloud } from "./cloud.ts";
16 import { entry as crewHandover } from "./crewhandover.ts";
17 import { entry as crewSplits } from "./crewsplits.ts";
18 import { entry as dashboard } from "./dashboard.ts";
19 import { entry as decider } from "./decider.ts";
20 import { entry as domains } from "./domains.ts";
21 import type { Entry } from "./entry.ts";
22 import { entry as family } from "./family.ts";
23 import { entry as fileHolds } from "./fileholds.ts";
24 import { entry as flags } from "./flags.ts";
25 import { entry as flow } from "./flow.ts";
26 import { entry as forges } from "./forges.ts";
27 import { entry as invites } from "./invites.ts";
28 import { entry as migrate } from "./migrate.ts";
29 import { ceilingEntry as modelCeiling, entry as model, grantEntry as modelGrant } from "./model.ts";
30 import { entry as newForge } from "./newforge.ts";
31 import { entry as newOrg } from "./neworg.ts";
32 import { entry as newRepo } from "./newrepo.ts";
33 import { entry as owner } from "./owner.ts";
34 import { entry as limits } from "./limits.ts";
35 import { entry as notify } from "./notify.ts";
36 import { entry as people } from "./people.ts";
37 import { entry as proposalTokens } from "./proposal_tokens.ts";
38 import { entry as quit } from "./quit.ts";
39 import { entry as quotas } from "./quotas.ts";
40 import { entry as releases } from "./releases.ts";
41 import { entries as repoVerbs } from "./repoverbs.ts";
42 import { entry as resilience } from "./resilience.ts";
43 import { entry as scorecard } from "./scorecard.ts";
44 import { entry as secrets } from "./secrets.ts";
45 import { entry as sentinel } from "./sentinel.ts";
46 import { entry as signIn } from "./signin.ts";
47 import { entry as signIns } from "./signins.ts";
48 import { entry as sshKeys } from "./sshkeys.ts";
49 import { entry as stalled } from "./stalled.ts";
50 import { entry as subscriptions } from "./subscriptions.ts";
51 import { memoryEntry as systemMemory, systemEntry as system } from "./system.ts";
52 import { entry as teams } from "./teams.ts";
53 import { entry as telemetry } from "./telemetry.ts";
54 import { entry as trustedHosts } from "./trustedhosts.ts";
55 import { entry as usage } from "./usage.ts";
56 import { accountEntry as account, exploreEntry as explore, profileEntry as profile } from "./webpages.ts";
57
58 export const ENTRIES: readonly Entry[] = [
59 dashboard,
60 explore,
61 profile,
62 ...repoVerbs,
63 newRepo,
64 signIn,
65 newOrg,
66 migrate,
67 newForge,
68 asked,
69 decider,
70 notify,
71 sshKeys,
72 account,
73 signIns,
74 sentinel,
75 boards,
76 systemMemory,
77 flow,
78 system,
79 telemetry,
80 capacity,
81 resilience,
82 api,
83 changelog,
84 releases,
85 stalled,
86 fileHolds,
87 access,
88 flags,
89 secrets,
90 trustedHosts,
91 usage,
92 crewSplits,
93 crewHandover,
94 scorecard,
95 proposalTokens,
96 model,
97 modelGrant,
98 modelCeiling,
99 can,
100 people,
101 quotas,
102 limits,
103 teams,
104 invites,
105 subscriptions,
106 cloud,
107 domains,
108 owner,
109 forges,
110 family,
111 chain,
112 quit,
113 ];
src/tui/screens/entry.ts added +24
@@ -0,0 +1,24 @@
1 /**
2 * What a screen says about its own palette row: its id, title and hint, who is
3 * offered it, and what it opens. A screen module exports one (`entry`), and
4 * `entries.ts` names them in the order the palette lists them.
5 */
6
7 import type { Ctx } from "../app/app.ts";
8 import type { Session } from "../session.ts";
9
10 export interface Entry {
11 readonly id: string;
12 readonly title: string;
13 readonly hint?: string;
14 /** Who is offered the row; the screen still checks its own gate when it opens. */
15 readonly offered: (session: Session) => boolean;
16 readonly run: (session: Session, ctx: Ctx) => void;
17 }
18
19 /** A site admin, person or agent. */
20 export const isAdmin = (s: Session): boolean => s.user?.isAdmin === true;
21 /** A site admin who is not an agent. */
22 export const isAdminNotAgent = (s: Session): boolean => isAdmin(s) && s.user?.kind !== "agent";
23 /** A site admin whose account is a person's (kind "user"), not an agent's or an org's. */
24 export const isAdminUser = (s: Session): boolean => isAdmin(s) && s.user?.kind === "user";
src/tui/screens/family.ts +16 −1
@@ -7,7 +7,9 @@
77 import type { Ctx, Screen } from "../app/app.ts";
88 import { binding } from "../app/keys.ts";
99 import { card } from "../ui/widgets.ts";
10 import { drawFacts } from "./common.ts";
10 import { drawFacts, runAsync } from "./common.ts";
11 import type { Entry } from "./entry.ts";
12 import { familyLines, familyView } from "../../spawn/family.ts";
1113
1214 export function familyScreen(ctx: Ctx, rows: readonly (readonly [string, string])[], title = "Family"): Screen {
1315 return {
@@ -27,3 +29,16 @@ export function familyScreen(ctx: Ctx, rows: readonly (readonly [string, string]
2729 },
2830 };
2931 }
32
33 /** The forge that sent this one and the forges it sent: offered to everyone; an admin sees more of the forges sent, as /family does. */
34 export const entry: Entry = {
35 id: "family",
36 title: "Family",
37 hint: "the forge that sent this one, and the forges it sent",
38 offered: () => true,
39 run: (s, ctx) =>
40 runAsync(ctx, async () => {
41 const view = await familyView(s.app, s.user?.isAdmin === true);
42 ctx.push(familyScreen(ctx, familyLines(view)));
43 }),
44 };
src/tui/screens/fileholds.ts +11 −1
@@ -14,7 +14,8 @@ import { boardHolds } from "../../core/admin_holds.ts";
1414 import { getRepo } from "../../core/repos.ts";
1515 import type { Ctx, Screen } from "../app/app.ts";
1616 import type { Session } from "../session.ts";
17 import { promptScreen } from "./common.ts";
17 import { promptScreen, blank } from "./common.ts";
18 import type { Entry } from "./entry.ts";
1819
1920 const SAYS = {
2021 unauthorized: "Sign in first.",
@@ -68,3 +69,12 @@ export function fileHoldsPrompt(f: Session, ctx: Ctx, parent: Screen): Screen {
6869 },
6970 });
7071 }
72
73 /** Hold new work on a file: the settings card's twin, admin-checked by the action itself. */
74 export const entry: Entry = {
75 id: "file-holds",
76 title: "Held files",
77 hint: "hold new work on a file, release it, or list the holds",
78 offered: (s) => s.signedIn,
79 run: (s, ctx) => ctx.push(fileHoldsPrompt(s, ctx, blank("Held files"))),
80 };
src/tui/screens/flags.ts +10
@@ -28,6 +28,7 @@ import { truncate } from "../term/width.ts";
2828 import type { Session } from "../session.ts";
2929 import { fill, len, split } from "../ui/layout.ts";
3030 import { ListState, drawList, promptScreen, type ListRow } from "./common.ts";
31 import type { Entry } from "./entry.ts";
3132
3233 const KEYS = ["forge", "users", "roles", "percent"] as const;
3334
@@ -148,3 +149,12 @@ export function flagsScreen(f: Session, ctx: Ctx): Screen {
148149 };
149150 return screen;
150151 }
152
153 /** Settings → Flags, as the page has it: an admin who is not an agent (#1970). */
154 export const entry: Entry = {
155 id: "flags",
156 title: "Flags",
157 hint: "declared flags and their live values",
158 offered: (s) => mayManageFlags(s.user),
159 run: (s, ctx) => ctx.push(flagsScreen(s, ctx)),
160 };
src/tui/screens/flow.ts +31
@@ -46,6 +46,11 @@ import { pad, truncate, wrap } from "../term/width.ts";
4646 import { dialog } from "../ui/widgets.ts";
4747 import { live } from "../../system/live.ts";
4848 import { duplicateLines } from "./system.ts";
49 import { forgeCeiling } from "../../flow/ceiling.ts";
50 import { readHeld } from "../../flow/held.ts";
51 import { noteRead, telemetryReader } from "../../actions/telemetry.ts";
52 import { queuesFor, systemFor } from "../../system/telemetry.ts";
53 import type { Entry } from "./entry.ts";
4954
5055 const WIDTH = 64;
5156
@@ -235,3 +240,29 @@ export function flowScreen(ctx: Ctx, lines: readonly string[]): Screen {
235240 },
236241 };
237242 }
243
244 /** The pipeline's bottleneck and throughput, as /flow says them: a site admin's (#1554, #1786). */
245 export const entry: Entry = {
246 id: "flow",
247 title: "Flow",
248 hint: "the pipeline's bottleneck and throughput",
249 offered: (s) => telemetryReader(s.app, s.user) !== undefined,
250 run: (session, ctx) => {
251 const reader = telemetryReader(session.app, session.user);
252 if (!reader) return;
253 if (session.user) noteRead(session.app, session.user, reader, "flow");
254 ctx.push(
255 flowScreen(
256 ctx,
257 flowLines(
258 session.db,
259 new Date(),
260 systemFor(session.app, reader).duplicates,
261 reader.kind === "agent" ? { queues: queuesFor(session.app, reader, new Date(), { batches: true }) } : undefined,
262 readHeld(session.app, reader.kind === "owner"),
263 forgeCeiling(session.app.config),
264 ),
265 ),
266 );
267 },
268 };
src/tui/screens/forges.ts +16 −1
@@ -10,7 +10,10 @@ import { ATTENTION_WORDS, CLAIM_WORDS, claimState, runningWords, spendWords, typ
1010 import { useLine } from "../../spawn/usage.ts";
1111 import { timeAgo } from "../../web/ui.ts";
1212 import { card } from "../ui/widgets.ts";
13 import { drawFacts } from "./common.ts";
13 import { drawFacts, runAsync } from "./common.ts";
14 import type { Entry } from "./entry.ts";
15 import { isAdmin } from "./entry.ts";
16 import { clientRows } from "../../spawn/clients.ts";
1417
1518 /** [name, "Not reporting · for Maria · Claimed · 3 apps running"] per row; an empty line when none. */
1619 export function forgeLines(rows: readonly ClientRow[]): [string, string][] {
@@ -51,3 +54,15 @@ export function forgesScreen(ctx: Ctx, rows: readonly ClientRow[]): Screen {
5154 },
5255 };
5356 }
57
58 /** The forges this one sent, as /forges lists them: an admin's only. */
59 export const entry: Entry = {
60 id: "forges",
61 title: "Forges you sent",
62 hint: "each forge sent, claimed or not, and its apps",
63 offered: isAdmin,
64 run: (s, ctx) =>
65 runAsync(ctx, async () => {
66 ctx.push(forgesScreen(ctx, await clientRows(s.app)));
67 }),
68 };
src/tui/screens/invites.ts +11
@@ -21,6 +21,8 @@ import { truncate } from "../term/width.ts";
2121 import type { Session } from "../session.ts";
2222 import { fill, len, split } from "../ui/layout.ts";
2323 import { ListState, confirmScreen, drawList, pickerScreen, promptScreen, type ListRow } from "./common.ts";
24 import type { Entry } from "./entry.ts";
25 import { isAdminUser } from "./entry.ts";
2426
2527 export function invitesScreen(f: Session, ctx: Ctx): Screen {
2628 const state = new ListState();
@@ -141,3 +143,12 @@ export function invitesScreen(f: Session, ctx: Ctx): Screen {
141143 };
142144 return screen;
143145 }
146
147 /** Invite links, as /admin/limits has them: an admin who is a person (#2337). */
148 export const entry: Entry = {
149 id: "invites",
150 title: "Invite links",
151 hint: "make a single-use link, see which are open, revoke one",
152 offered: isAdminUser,
153 run: (s, ctx) => ctx.push(invitesScreen(s, ctx)),
154 };
src/tui/screens/limits.ts +11
@@ -14,6 +14,8 @@ import { binding } from "../app/keys.ts";
1414 import { style } from "../term/style.ts";
1515 import { truncate } from "../term/width.ts";
1616 import type { Session } from "../session.ts";
17 import type { Entry } from "./entry.ts";
18 import { isAdminNotAgent } from "./entry.ts";
1719 import { fill, len, split } from "../ui/layout.ts";
1820 import { ListState, confirmScreen, drawList, promptScreen, type ListRow } from "./common.ts";
1921
@@ -99,3 +101,12 @@ export function limitsScreen(f: Session, ctx: Ctx): Screen {
99101 };
100102 return screen;
101103 }
104
105 /** The forge's limits, as MCP `limits` has them: an admin who is not an agent (#7268). */
106 export const entry: Entry = {
107 id: "limits",
108 title: "Limits",
109 hint: "what the forge caps, with default and bounds; change one",
110 offered: isAdminNotAgent,
111 run: (s, ctx) => ctx.push(limitsScreen(s, ctx)),
112 };
src/tui/screens/migrate.ts +10
@@ -58,6 +58,7 @@ import {
5858 } from "./common.ts";
5959 import { repoScreen } from "./repo.ts";
6060 import { local } from "./where.ts";
61 import type { Entry } from "./entry.ts";
6162
6263 interface Row {
6364 readonly originId: string;
@@ -645,3 +646,12 @@ function jobScreen(
645646 },
646647 };
647648 }
649
650 /** Bringing a repository in from an origin or a URL: any signed-in person's; the action checks the rest. */
651 export const entry: Entry = {
652 id: "migrate",
653 title: "Migrate a repository",
654 hint: "bring one in from an origin or a URL, pick its branch, put a crew on it",
655 offered: (s) => s.signedIn,
656 run: (s, ctx) => ctx.push(migrateScreen(s, ctx)),
657 };
src/tui/screens/model.ts +29 −1
@@ -22,7 +22,9 @@ import { binding } from "../app/keys.ts";
2222 import { style } from "../term/style.ts";
2323 import { truncate } from "../term/width.ts";
2424 import type { Session } from "../session.ts";
25 import { later, promptScreen } from "./common.ts";
25 import { later, promptScreen, blank } from "./common.ts";
26 import type { Entry } from "./entry.ts";
27 import { isAdminUser } from "./entry.ts";
2628
2729 /** The signed-in person's budget line, and `a` to add their own subscription. */
2830 export function modelScreen(f: Session, ctx: Ctx): Screen {
@@ -131,3 +133,29 @@ export function modelCeilingPrompt(f: Session, ctx: Ctx, parent: Screen): Screen
131133 ),
132134 });
133135 }
136
137 /** Settings → Model: a person's own budget and subscription, as the page has them (#1145). */
138 export const entry: Entry = {
139 id: "model",
140 title: "Model budget",
141 hint: "what your crew may spend, and add your own subscription",
142 offered: (s) => s.user?.kind === "user",
143 run: (s, ctx) => ctx.push(modelScreen(s, ctx)),
144 };
145
146 /** A capped monthly grant to an account: a forge admin who is a person (#1145). */
147 export const grantEntry: Entry = {
148 id: "model-grant",
149 title: "Model grant",
150 hint: "give an account dollars a month, or take it back",
151 offered: isAdminUser,
152 run: (s, ctx) => ctx.push(modelGrantPrompt(s, ctx, blank("Model grant"))),
153 };
154
155 export const ceilingEntry: Entry = {
156 id: "model-ceiling",
157 title: "Model ceiling",
158 hint: "set an account's dollars a day and a run",
159 offered: isAdminUser,
160 run: (s, ctx) => ctx.push(modelCeilingPrompt(s, ctx, blank("Model ceiling"))),
161 };
src/tui/screens/newforge.ts +10
@@ -20,6 +20,7 @@ import { truncate } from "../term/width.ts";
2020 import { field } from "../ui/widgets.ts";
2121 import type { Session } from "../session.ts";
2222 import { linkScreen, runAsync } from "./common.ts";
23 import type { Entry } from "./entry.ts";
2324
2425 interface Spec {
2526 readonly key: string;
@@ -243,3 +244,12 @@ export function newForgeScreen(f: Session, ctx: Ctx): Screen {
243244 },
244245 };
245246 }
247
248 /** A client's forge, as /forges/new makes it: any signed-in person's; the door decides the rest. */
249 export const entry: Entry = {
250 id: "new-forge",
251 title: "New forge",
252 hint: "spawn a client's forge and get its claim link",
253 offered: (s) => s.signedIn,
254 run: (s, ctx) => ctx.push(newForgeScreen(s, ctx)),
255 };
src/tui/screens/neworg.ts +10
@@ -15,6 +15,7 @@ import { truncate } from "../term/width.ts";
1515 import { field } from "../ui/widgets.ts";
1616 import type { Session } from "../session.ts";
1717 import { newRepoScreen } from "./newrepo.ts";
18 import type { Entry } from "./entry.ts";
1819
1920 export function newOrgScreen(f: Session, ctx: Ctx): Screen {
2021 let name = "";
@@ -100,3 +101,12 @@ export function newOrgScreen(f: Session, ctx: Ctx): Screen {
100101 },
101102 };
102103 }
104
105 /** An organization you own, as /organizations/new and MCP `org_create` make it: a person's, never an agent's (#7260). */
106 export const entry: Entry = {
107 id: "new-org",
108 title: "New organization",
109 hint: "an organization you own, for a client's apps",
110 offered: (s) => s.user !== undefined && s.user.kind !== "agent",
111 run: (s, ctx) => ctx.push(newOrgScreen(s, ctx)),
112 };
src/tui/screens/newrepo.ts +9
@@ -17,6 +17,7 @@ import type { Session } from "../session.ts";
1717 import { errorText, runAsync } from "./common.ts";
1818 import { repoScreen } from "./repo.ts";
1919 import { local } from "./where.ts";
20 import type { Entry } from "./entry.ts";
2021
2122 type Focus = 0 | 1 | 2 | 3;
2223
@@ -226,3 +227,11 @@ export function forkScreen(f: Session, ctx: Ctx, parent: Repo): Screen {
226227 },
227228 };
228229 }
230
231 /** A new repository: a signed-in person's. A signed-out session is offered `signin` in its place. */
232 export const entry: Entry = {
233 id: "new-repo",
234 title: "New repository",
235 offered: (s) => s.signedIn,
236 run: (s, ctx) => ctx.push(newRepoScreen(s, ctx)),
237 };
src/tui/screens/notify.ts +10
@@ -12,6 +12,7 @@ import { binding } from "../app/keys.ts";
1212 import { style } from "../term/style.ts";
1313 import { truncate } from "../term/width.ts";
1414 import type { Session } from "../session.ts";
15 import type { Entry } from "./entry.ts";
1516 import { confirmScreen, promptScreen } from "./common.ts";
1617
1718 export function notifyScreen(f: Session, ctx: Ctx): Screen {
@@ -83,3 +84,12 @@ export function notifyScreen(f: Session, ctx: Ctx): Screen {
8384 };
8485 return screen;
8586 }
87
88 /** Where a decision finds the owner; an agent is never offered it. */
89 export const entry: Entry = {
90 id: "notify",
91 title: "Phone notifications",
92 hint: "where the crew reaches your phone; s sets, x turns off",
93 offered: (s) => s.signedIn && s.user?.kind !== "agent",
94 run: (s, ctx) => ctx.push(notifyScreen(s, ctx)),
95 };
src/tui/screens/owner.ts +11
@@ -13,6 +13,8 @@ import { style } from "../term/style.ts";
1313 import { truncate } from "../term/width.ts";
1414 import type { Session } from "../session.ts";
1515 import { ListState, drawList, type ListRow } from "./common.ts";
16 import type { Entry } from "./entry.ts";
17 import { isAdminNotAgent } from "./entry.ts";
1618
1719 export function ownerRows(v: OwnerView): ListRow[] {
1820 const needs: ListRow[] =
@@ -68,3 +70,12 @@ export function ownerScreen(f: Session, ctx: Ctx): Screen {
6870 };
6971 return screen;
7072 }
73
74 /** What needs the owner: needs, snapshot store, every failure domain (#1236). */
75 export const entry: Entry = {
76 id: "owner",
77 title: "Owner's needs",
78 hint: "what needs the owner, snapshots, failure domains",
79 offered: isAdminNotAgent,
80 run: (s, ctx) => ctx.push(ownerScreen(s, ctx)),
81 };
src/tui/screens/people.ts +11
@@ -22,6 +22,8 @@ import type { Session } from "../session.ts";
2222 import { style } from "../term/style.ts";
2323 import { truncate } from "../term/width.ts";
2424 import { confirmScreen, drawList, later, ListState, promptScreen, runAsync, type ListRow } from "./common.ts";
25 import type { Entry } from "./entry.ts";
26 import { isAdminUser } from "./entry.ts";
2527
2628 /**
2729 * The accounts page's no-mail card in one line that fits 80 columns: without
@@ -164,3 +166,12 @@ export function peopleScreen(f: Session, ctx: Ctx): Screen {
164166 };
165167 return screen;
166168 }
169
170 /** Guests, members and admins, as /settings/people has them (#2301). */
171 export const entry: Entry = {
172 id: "people",
173 title: "People",
174 hint: "who is a guest, a member or an admin; promote or demote",
175 offered: isAdminUser,
176 run: (s, ctx) => ctx.push(peopleScreen(s, ctx)),
177 };
src/tui/screens/proposal_tokens.ts +11 −1
@@ -20,7 +20,8 @@ import { style } from "../term/style.ts";
2020 import { truncate } from "../term/width.ts";
2121 import type { Session } from "../session.ts";
2222 import { fill, len, split } from "../ui/layout.ts";
23 import { ListState, drawList, later, promptScreen, type ListRow } from "./common.ts";
23 import { ListState, drawList, later, promptScreen, type ListRow, blank } from "./common.ts";
24 import type { Entry } from "./entry.ts";
2425
2526 /** Ask for `owner/name`, then show its proposal tokens. */
2627 export function proposalTokensPrompt(f: Session, ctx: Ctx, parent: Screen): Screen {
@@ -123,3 +124,12 @@ export function proposalTokensScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
123124 };
124125 return screen;
125126 }
127
128 /** Proposal tokens for a repository you write, as the API and MCP have them (#2148). */
129 export const entry: Entry = {
130 id: "proposal-tokens",
131 title: "Proposal tokens",
132 hint: "mint, list and revoke what a child proposes with",
133 offered: (s) => s.user !== undefined,
134 run: (s, ctx) => ctx.push(proposalTokensPrompt(s, ctx, blank("Proposal tokens"))),
135 };
src/tui/screens/quit.ts added +12
@@ -0,0 +1,12 @@
1 /** The palette's last row: leave the terminal. */
2
3 import type { Entry } from "./entry.ts";
4
5 /** Disconnect: offered to everyone. */
6 export const entry: Entry = {
7 id: "quit",
8 title: "Quit",
9 hint: "disconnect",
10 offered: () => true,
11 run: (_s, ctx) => ctx.quit(),
12 };
src/tui/screens/quotas.ts +11
@@ -17,6 +17,8 @@ import { truncate } from "../term/width.ts";
1717 import type { Session } from "../session.ts";
1818 import { fill, len, split } from "../ui/layout.ts";
1919 import { ListState, drawList, promptScreen, type ListRow } from "./common.ts";
20 import type { Entry } from "./entry.ts";
21 import { isAdminNotAgent } from "./entry.ts";
2022
2123 const limit = (v: number | string | null): string => (v === null || v === "" ? "no limit" : String(v));
2224
@@ -95,3 +97,12 @@ export function quotasScreen(f: Session, ctx: Ctx): Screen {
9597 };
9698 return screen;
9799 }
100
101 /** Account quotas, as /admin/limits has them: an admin who is not an agent (#2191). */
102 export const entry: Entry = {
103 id: "quotas",
104 title: "Account quotas",
105 hint: "what one account may own, and who changed it",
106 offered: isAdminNotAgent,
107 run: (s, ctx) => ctx.push(quotasScreen(s, ctx)),
108 };
src/tui/screens/releases.ts +10
@@ -19,6 +19,7 @@ import { truncate } from "../term/width.ts";
1919 import { fill, len, split } from "../ui/layout.ts";
2020 import { emptyState } from "../ui/widgets.ts";
2121 import { ListState, confirmScreen, drawList, hitList, ago, metaOf, runAsync, type ListRow } from "./common.ts";
22 import type { Entry } from "./entry.ts";
2223
2324 export interface ReleaseLine {
2425 readonly release: Release;
@@ -127,3 +128,12 @@ export function releasesScreen(f: Session, ctx: Ctx): Screen {
127128 };
128129 return self;
129130 }
131
132 /** The live release and the kept ones, as /releases gates them: a site admin or a reader of FORGE_REPO. */
133 export const entry: Entry = {
134 id: "releases",
135 title: "Releases",
136 hint: "the live release and the kept ones",
137 offered: (s) => mayRead(s.app, s.user),
138 run: (s, ctx) => ctx.push(releasesScreen(s, ctx)),
139 };
src/tui/screens/repoverbs.ts added +87
@@ -0,0 +1,87 @@
1 /**
2 * The repo-scoped palette verbs. Each asks for `owner/name` in a prompt and
3 * resolves it through `getRepo` plus the screen's own access checks — a repo
4 * you cannot read is reported as not found, exactly as it is everywhere else.
5 */
6
7 import { canRead, getRepo, type Repo } from "../../core/repos.ts";
8 import type { Ctx, Screen } from "../app/app.ts";
9 import type { Session } from "../session.ts";
10 import { askFor, openOnWeb } from "./common.ts";
11 import type { Entry } from "./entry.ts";
12 import { issuesScreen, newIssueScreen } from "./issues.ts";
13 import { limbsScreen } from "./limbs.ts";
14 import { newPullScreen } from "./newpull.ts";
15 import { repoScreen } from "./repo.ts";
16 import { usageScreen } from "./usage.ts";
17 import { local } from "./where.ts";
18
19 /** The repo-scoped palette verbs: a name to ask for, and what to do with it. */
20 const REPO_VERBS: readonly {
21 id: string;
22 title: string;
23 /** The screen to push, or nothing when the verb hands over to the web. */
24 open: (f: Session, ctx: Ctx, repo: Repo) => Screen | undefined;
25 }[] = [
26 {
27 id: "repo",
28 title: "Open a repository",
29 open: (f, ctx, repo) => repoScreen(f, ctx, local(f, repo)),
30 },
31 {
32 id: "issues",
33 title: "Issues in a repository",
34 open: (f, ctx, repo) => issuesScreen(f, ctx, local(f, repo), "issue"),
35 },
36 {
37 id: "pulls",
38 title: "Pull requests in a repository",
39 open: (f, ctx, repo) => issuesScreen(f, ctx, local(f, repo), "pull"),
40 },
41 {
42 id: "milestones",
43 title: "Milestones in a repository",
44 open: (f, ctx, repo) => limbsScreen(f, ctx, repo),
45 },
46 {
47 // What the crew's tokens bought on one app, as MCP `returns` with `repo` (#7271).
48 id: "repo-usage",
49 title: "Usage of a repository",
50 open: (f, ctx, repo) => usageScreen(f, ctx, repo),
51 },
52 { id: "new-issue", title: "New issue", open: newIssueScreen },
53 { id: "new-pull", title: "New pull request", open: newPullScreen },
54 {
55 id: "settings",
56 title: "Repository settings",
57 // One settings page, the web's (#635): the terminal hands over its address.
58 open: (f, ctx, repo) => {
59 openOnWeb(f, ctx, `/${repo.ownerName}/${repo.name}/settings`, "Settings");
60 return undefined;
61 },
62 },
63 ];
64
65 export const entries: readonly Entry[] = REPO_VERBS.map((verb) => ({
66 id: verb.id,
67 title: verb.title,
68 hint: "owner/name",
69 offered: () => true,
70 run: (session, ctx) =>
71 ctx.push(
72 askFor(ctx, verb.title, "owner/name", (spec) => {
73 const [owner, name] = spec.split("/");
74 const repo = owner && name ? getRepo(session.db, owner, name) : undefined;
75 // The palette is a client like any other: a repo you cannot
76 // read is "not found", indistinguishable from a typo. Without
77 // this check the palette would be a way around `canRead`.
78 if (!repo || !canRead(session.db, repo, session.user)) return "not found";
79 // After the prompt has popped itself, or the pop takes the
80 // screen just pushed instead (`later` in screens/common.ts).
81 return Promise.resolve().then(() => {
82 const next = verb.open(session, ctx, repo);
83 if (next !== undefined) ctx.push(next);
84 });
85 }),
86 ),
87 }));
src/tui/screens/resilience.ts +11
@@ -38,6 +38,8 @@ import type { Session } from "../session.ts";
3838 import { pad, wrap } from "../term/width.ts";
3939 import { dialog } from "../ui/widgets.ts";
4040 import { confirmScreen, later, promptScreen, runAsync } from "./common.ts";
41 import type { Entry } from "./entry.ts";
42 import { isAdmin } from "./entry.ts";
4143
4244 const WIDTH = 72;
4345 const INNER = WIDTH - 6;
@@ -283,3 +285,12 @@ export function resilienceScreen(f: Session, ctx: Ctx): Screen {
283285 };
284286 return screen;
285287 }
288
289 /** Each THREATS.md protection's standing, as /resilience says it: a site admin's. */
290 export const entry: Entry = {
291 id: "resilience",
292 title: "Resilience",
293 hint: "where snapshots go and the mirror; each protection green, red or untested",
294 offered: isAdmin,
295 run: (s, ctx) => ctx.push(resilienceScreen(s, ctx)),
296 };
src/tui/screens/scorecard.ts +11
@@ -29,6 +29,8 @@ import { truncate } from "../term/width.ts";
2929 import type { Session } from "../session.ts";
3030 import { fill, len, split } from "../ui/layout.ts";
3131 import { ListState, drawList, type ListRow } from "./common.ts";
32 import type { Entry } from "./entry.ts";
33 import { isAdmin } from "./entry.ts";
3234
3335 const landed = (s: Scorecard | undefined) =>
3436 s === undefined ? "—" : `${s.landed} of ${s.opened}`;
@@ -171,3 +173,12 @@ export function scorecardScreen(f: Session, ctx: Ctx): Screen {
171173 key: (e) => state.key(e, rows.length),
172174 };
173175 }
176
177 /** Settings → Crew's scorecard per agent, as the page has it: a forge admin (#2677). */
178 export const entry: Entry = {
179 id: "scorecard",
180 title: "Crew scorecard per agent",
181 hint: "each agent's pulls landed, review rounds, red checks, reverts, time to land",
182 offered: isAdmin,
183 run: (s, ctx) => ctx.push(scorecardScreen(s, ctx)),
184 };
src/tui/screens/secrets.ts +11
@@ -17,6 +17,8 @@ import { truncate } from "../term/width.ts";
1717 import type { Session } from "../session.ts";
1818 import { fill, len, split } from "../ui/layout.ts";
1919 import { confirmScreen, drawList, later, ListState, promptScreen } from "./common.ts";
20 import type { Entry } from "./entry.ts";
21 import { isAdmin } from "./entry.ts";
2022
2123 /** The action's refusals in this screen's words. */
2224 const ERRORS: Record<string, string> = {
@@ -170,3 +172,12 @@ export function secretsScreen(f: Session, ctx: Ctx): Screen {
170172 };
171173 return screen;
172174 }
175
176 /** Settings → Secrets, as the page has it: a forge admin; names only, never a value. */
177 export const entry: Entry = {
178 id: "secrets",
179 title: "Secrets",
180 hint: "sealed secrets by name; set or remove one",
181 offered: isAdmin,
182 run: (s, ctx) => ctx.push(secretsScreen(s, ctx)),
183 };
src/tui/screens/sentinel.ts added +14
@@ -0,0 +1,14 @@
1 /** The forge's own faults in the palette, as the board's strip shows them. */
2
3 import { sentinelSummary } from "../../crew/sentinel.ts";
4 import { isAdmin, type Entry } from "./entry.ts";
5
6 /** The forge's own faults, as the board's strip shows them: a site admin's. */
7 export const entry: Entry = {
8 id: "sentinel",
9 title: "Sentinel",
10 hint: "the forge's open faults",
11 offered: isAdmin,
12 run: (s, ctx) =>
13 ctx.toast(sentinelSummary(s.db) ?? "The sentinel has not hunted yet", "default"),
14 };
src/tui/screens/signin.ts +9
@@ -21,6 +21,7 @@ import { fill, len, split } from "../ui/layout.ts";
2121 import { field, segmented } from "../ui/widgets.ts";
2222 import type { Session } from "../session.ts";
2323 import { errorText, runAsync } from "./common.ts";
24 import type { Entry } from "./entry.ts";
2425
2526 interface Field {
2627 readonly label: string;
@@ -230,3 +231,11 @@ export function signInScreen(f: Session, ctx: Ctx, onDone: () => void): Screen {
230231 },
231232 };
232233 }
234
235 /** Sign in: offered only to a signed-out session, in the place `new-repo` takes for a signed-in one. */
236 export const entry: Entry = {
237 id: "signin",
238 title: "Sign in",
239 offered: (s) => !s.signedIn,
240 run: (s, ctx) => ctx.push(signInScreen(s, ctx, () => ctx.invalidate())),
241 };
src/tui/screens/signins.ts +10
@@ -20,6 +20,7 @@ import { truncate } from "../term/width.ts";
2020 import type { Session } from "../session.ts";
2121 import { fill, len, split } from "../ui/layout.ts";
2222 import { ListState, ago, confirmScreen, drawList, type ListRow } from "./common.ts";
23 import type { Entry } from "./entry.ts";
2324
2425 interface SignIn {
2526 readonly kind: "terminal" | "browser" | "token";
@@ -149,3 +150,12 @@ export function signInsScreen(f: Session, ctx: Ctx): Screen {
149150 };
150151 return screen;
151152 }
153
154 /** Settings → Sessions and MCP `sessions`, in the terminal (#7237). */
155 export const entry: Entry = {
156 id: "signins",
157 title: "Signed in",
158 hint: "your browsers and tokens; d signs a browser out",
159 offered: (s) => s.signedIn,
160 run: (s, ctx) => ctx.push(signInsScreen(s, ctx)),
161 };
src/tui/screens/sshkeys.ts +9
@@ -16,6 +16,7 @@ import { truncate } from "../term/width.ts";
1616 import type { Session } from "../session.ts";
1717 import { fill, len, split } from "../ui/layout.ts";
1818 import { ListState, confirmScreen, drawList, later, promptScreen, type ListRow } from "./common.ts";
19 import type { Entry } from "./entry.ts";
1920
2021 export function sshKeysScreen(f: Session, ctx: Ctx): Screen {
2122 const state = new ListState();
@@ -92,3 +93,11 @@ export function sshKeysScreen(f: Session, ctx: Ctx): Screen {
9293 };
9394 return screen;
9495 }
96
97 export const entry: Entry = {
98 id: "ssh-keys",
99 title: "SSH keys",
100 hint: "list, add and remove the keys that sign in as you",
101 offered: (s) => s.signedIn,
102 run: (s, ctx) => ctx.push(sshKeysScreen(s, ctx)),
103 };
src/tui/screens/stalled.ts +10
@@ -14,6 +14,7 @@ import { binding } from "../app/keys.ts";
1414 import type { Session } from "../session.ts";
1515 import { ListState, drawList, hitList, live, metaOf, relTime, runAsync, type ListRow } from "./common.ts";
1616 import { emptyState } from "../ui/widgets.ts";
17 import type { Entry } from "./entry.ts";
1718
1819 const VERB: Record<StalledStep["action"], string> = { run: "run check", rerun: "re-run" };
1920
@@ -66,3 +67,12 @@ export function stalledScreen(f: Session, ctx: Ctx): Screen {
6667 },
6768 };
6869 }
70
71 /** Stalled flow steps the viewer can unblock, as the home's cards show them (#1807). */
72 export const entry: Entry = {
73 id: "stalled",
74 title: "Stalled steps",
75 hint: "pulls whose check is red or was never asked for; enter re-runs",
76 offered: (s) => s.signedIn,
77 run: (s, ctx) => ctx.push(stalledScreen(s, ctx)),
78 };
src/tui/screens/subscriptions.ts +11
@@ -29,6 +29,8 @@ import { truncate } from "../term/width.ts";
2929 import type { Session } from "../session.ts";
3030 import { fill, len, split } from "../ui/layout.ts";
3131 import { ListState, confirmScreen, drawList, later, promptScreen, type ListRow } from "./common.ts";
32 import type { Entry } from "./entry.ts";
33 import { isAdminUser } from "./entry.ts";
3234
3335 const money = (n: number): string => `$${n.toFixed(2)}`;
3436
@@ -171,3 +173,12 @@ export function subscriptionsScreen(f: Session, ctx: Ctx): Screen {
171173 };
172174 return screen;
173175 }
176
177 /** The crew's Claude subscriptions, as MCP `subscriptions` has them: a forge admin (#7244). */
178 export const entry: Entry = {
179 id: "subscriptions",
180 title: "Crew subscriptions",
181 hint: "each account's budget and rest; wake one, set its budget, add or remove one",
182 offered: isAdminUser,
183 run: (s, ctx) => ctx.push(subscriptionsScreen(s, ctx)),
184 };
src/tui/screens/system.ts +28 −1
@@ -19,7 +19,6 @@
1919
2020 import type { Ctx, Screen } from "../app/app.ts";
2121 import type { SystemView } from "../../system/view.ts";
22 import type { readHealth } from "../../actions/health.ts";
2322 import { rolloutLine, type ForgeHealth } from "../../kernel/guard.ts";
2423 import { canSeeMemory, memoryHours } from "../../boards/memory.ts";
2524 import { telemetryReader } from "../../actions/telemetry.ts";
@@ -33,6 +32,9 @@ import { style } from "../term/style.ts";
3332 import { pad, truncate, wrap } from "../term/width.ts";
3433 import { dialog } from "../ui/widgets.ts";
3534 import { Scroll, confirmScreen, drawLines, hitScroll, later, pickerScreen } from "./common.ts";
35 import { readHealth } from "../../actions/health.ts";
36 import { live as liveMachine } from "../../system/live.ts";
37 import { isAdminNotAgent, type Entry } from "./entry.ts";
3638
3739 const WIDTH = 72;
3840 const GROUPS = 6;
@@ -260,3 +262,28 @@ export function memoryScreen(session: Session, ctx: Ctx): Screen {
260262 },
261263 };
262264 }
265
266 /** The forge's RSS beside its JS heap, as /system gates it (#2151). */
267 export const memoryEntry: Entry = {
268 id: "system-memory",
269 title: "System memory",
270 hint: "RSS beside the JS heap, hourly for 24 h",
271 offered: (s) => canSeeMemory(s.user),
272 run: (s, ctx) => ctx.push(memoryScreen(s, ctx)),
273 };
274
275 /** The machine, as /system says it, and which agents may read it: the owner's, a person (#1789). */
276 export const systemEntry: Entry = {
277 id: "system",
278 title: "System",
279 hint: "the machine now: CPU, memory, disks, processes",
280 offered: isAdminNotAgent,
281 run: (s, ctx) =>
282 ctx.push(
283 systemScreen(
284 ctx,
285 [...forgeLines(readHealth(s.app, s.user)), "", ...systemLines(liveMachine().read())],
286 s,
287 ),
288 ),
289 };
src/tui/screens/teams.ts +11
@@ -15,6 +15,8 @@ import { truncate } from "../term/width.ts";
1515 import type { Session } from "../session.ts";
1616 import { fill, len, split } from "../ui/layout.ts";
1717 import { ListState, drawList, promptScreen, type ListRow } from "./common.ts";
18 import type { Entry } from "./entry.ts";
19 import { isAdminNotAgent } from "./entry.ts";
1820
1921 export function teamsScreen(f: Session, ctx: Ctx): Screen {
2022 const state = new ListState();
@@ -95,3 +97,12 @@ export function teamsScreen(f: Session, ctx: Ctx): Screen {
9597 };
9698 return screen;
9799 }
100
101 /** Crew teams, as /settings/teams has them: an admin who is not an agent (#2679). */
102 export const entry: Entry = {
103 id: "teams",
104 title: "Crew teams",
105 hint: "each team's charter, dial and members",
106 offered: isAdminNotAgent,
107 run: (s, ctx) => ctx.push(teamsScreen(s, ctx)),
108 };
src/tui/screens/telemetry.ts added +42
@@ -0,0 +1,42 @@
1 /** Which agents may read flow and system, as a picker whose Enter flips the grant. */
2
3 import { setTelemetryGrant } from "../../actions/telemetry.ts";
4 import { grantable, READS_KEPT, recentReads } from "../../core/telemetry.ts";
5 import { blank, pickerScreen } from "./common.ts";
6 import { isAdminNotAgent, type Entry } from "./entry.ts";
7
8 /** The machine, as /system says it, and which agents may read it: the owner's, a person (#1789). */
9 export const entry: Entry = {
10 id: "telemetry",
11 title: "Telemetry",
12 hint: "which agents may read flow and system; enter flips the grant",
13 offered: isAdminNotAgent,
14 run: (session, ctx) => {
15 const actor = session.user;
16 const agents = grantable(session.db);
17 if (agents.length === 0) return ctx.toast("No agent accounts yet");
18 const last = new Map<string, { n: number; what: string; at: string }>();
19 for (const r of recentReads(session.db, READS_KEPT).reverse()) {
20 last.set(r.username, { n: (last.get(r.username)?.n ?? 0) + 1, what: r.what, at: r.at });
21 }
22 const readsOf = (name: string): string => {
23 const l = last.get(name);
24 return l ? `${l.n} read${l.n === 1 ? "" : "s"}, last ${l.what} ${l.at}` : "no reads";
25 };
26 ctx.push(
27 pickerScreen(ctx, blank("Telemetry"), {
28 title: "Telemetry: telemetry:read",
29 items: agents.map((a) => ({ id: a.username, label: a.username, hint: `${a.granted ? "granted" : "not granted"} · ${readsOf(a.username)}` })),
30 onPick: ([name]) => {
31 const was = agents.find((a) => a.username === name);
32 if (!was) return;
33 const done = setTelemetryGrant(session.app, actor, was.username, !was.granted);
34 ctx.toast(
35 done.ok ? `${was.username}: telemetry:read ${done.value.on ? "granted" : "revoked"}` : "Could not change the grant",
36 done.ok ? "success" : "attn",
37 );
38 },
39 }),
40 );
41 },
42 };
src/tui/screens/trustedhosts.ts +11 −1
@@ -7,7 +7,8 @@
77 import { editableHosts, envHosts, mayEditTrustedHosts, rejectedSentence, updateTrustedHosts } from "../../origins/trusted-hosts.ts";
88 import type { Ctx, Screen } from "../app/app.ts";
99 import type { Session } from "../session.ts";
10 import { promptScreen } from "./common.ts";
10 import { promptScreen, blank } from "./common.ts";
11 import type { Entry } from "./entry.ts";
1112
1213 export function trustedHostsPrompt(f: Session, ctx: Ctx, parent: Screen): Screen {
1314 const fixed = envHosts();
@@ -24,3 +25,12 @@ export function trustedHostsPrompt(f: Session, ctx: Ctx, parent: Screen): Screen
2425 },
2526 });
2627 }
28
29 /** Settings → Origins' trusted internal hosts: the same admin gate as the page. */
30 export const entry: Entry = {
31 id: "trusted-hosts",
32 title: "Trusted hosts",
33 hint: "internal hosts an origin may reach",
34 offered: (s) => mayEditTrustedHosts(s.user),
35 run: (s, ctx) => ctx.push(trustedHostsPrompt(s, ctx, blank("Trusted hosts"))),
36 };
src/tui/screens/usage.ts +10
@@ -27,6 +27,7 @@ import { truncate } from "../term/width.ts";
2727 import type { Session } from "../session.ts";
2828 import { fill, len, split } from "../ui/layout.ts";
2929 import { ListState, drawList, type ListRow } from "./common.ts";
30 import type { Entry } from "./entry.ts";
3031
3132 const part = (counts: Readonly<Record<string, number>>, keys: readonly string[]) =>
3233 keys.map((k) => `${k} ${counts[k] ?? 0}`).join(" ");
@@ -102,3 +103,12 @@ export function usageScreen(f: Session, ctx: Ctx, repo?: Repo): Screen {
102103 },
103104 };
104105 }
106
107 /** Settings → Usage, as the page has it: the same gate as Flags (#1565). */
108 export const entry: Entry = {
109 id: "usage",
110 title: "Usage",
111 hint: "every route, unused ones first",
112 offered: (s) => mayManageFlags(s.user),
113 run: (s, ctx) => ctx.push(usageScreen(s, ctx)),
114 };
src/tui/screens/webpages.ts added +38
@@ -0,0 +1,38 @@
1 /**
2 * The palette rows that hand over to a page of the web: browsing, a profile,
3 * the account's settings. The terminal has no screen of its own for them.
4 */
5
6 import { askFor, openOnWeb } from "./common.ts";
7 import type { Entry } from "./entry.ts";
8
9 /** Browsing other people and forges is the web explorer's (#607): the terminal hands over its address. */
10 export const exploreEntry: Entry = {
11 id: "explore",
12 title: "Explore",
13 hint: "on the web",
14 offered: () => true,
15 run: (s, ctx) => openOnWeb(s, ctx, "/explore", "The explorer"),
16 };
17
18 /** A person's or an org's page is the web's (#636): the terminal hands over its address. */
19 export const profileEntry: Entry = {
20 id: "profile",
21 title: "Open a profile",
22 hint: "username or org",
23 offered: () => true,
24 run: (s, ctx) =>
25 ctx.push(
26 askFor(ctx, "Profile", "username", (name) => {
27 openOnWeb(s, ctx, `/${encodeURIComponent(name)}`, "That profile");
28 return undefined;
29 }),
30 ),
31 };
32
33 export const accountEntry: Entry = {
34 id: "account",
35 title: "Account settings",
36 offered: (s) => s.signedIn,
37 run: (s, ctx) => openOnWeb(s, ctx, "/settings", "Account settings"),
38 };
test/fixtures/tui-palette.json added +146
@@ -0,0 +1,146 @@
1 {
2 "admin": [
3 "home | Home | your repositories",
4 "explore | Explore | on the web",
5 "profile | Open a profile | username or org",
6 "repo | Open a repository | owner/name",
7 "issues | Issues in a repository | owner/name",
8 "pulls | Pull requests in a repository | owner/name",
9 "milestones | Milestones in a repository | owner/name",
10 "repo-usage | Usage of a repository | owner/name",
11 "new-issue | New issue | owner/name",
12 "new-pull | New pull request | owner/name",
13 "settings | Repository settings | owner/name",
14 "new-repo | New repository | ",
15 "new-org | New organization | an organization you own, for a client's apps",
16 "migrate | Migrate a repository | bring one in from an origin or a URL, pick its branch, put a crew on it",
17 "new-forge | New forge | spawn a client's forge and get its claim link",
18 "asked | Asked | your thoughts and what became of them",
19 "decider | Decider | what it closed, deferred and asked you about today",
20 "notify | Phone notifications | where the crew reaches your phone; s sets, x turns off",
21 "ssh-keys | SSH keys | list, add and remove the keys that sign in as you",
22 "account | Account settings | ",
23 "signins | Signed in | your browsers and tokens; d signs a browser out",
24 "sentinel | Sentinel | the forge's open faults",
25 "boards | Boards | the forge's boards and their panels",
26 "system-memory | System memory | RSS beside the JS heap, hourly for 24 h",
27 "flow | Flow | the pipeline's bottleneck and throughput",
28 "system | System | the machine now: CPU, memory, disks, processes",
29 "telemetry | Telemetry | which agents may read flow and system; enter flips the grant",
30 "capacity | Capacity | concurrency and guards, live; e changes a settable one",
31 "resilience | Resilience | where snapshots go and the mirror; each protection green, red or untested",
32 "api | API | the forge's endpoints; run a GET",
33 "changelog | Changelog | the last 30 releases and their pulls",
34 "releases | Releases | the live release and the kept ones",
35 "stalled | Stalled steps | pulls whose check is red or was never asked for; enter re-runs",
36 "file-holds | Held files | hold new work on a file, release it, or list the holds",
37 "access | Access | what outside agents tried",
38 "flags | Flags | declared flags and their live values",
39 "secrets | Secrets | sealed secrets by name; set or remove one",
40 "trusted-hosts | Trusted hosts | internal hosts an origin may reach",
41 "usage | Usage | every route, unused ones first",
42 "crew-scorecard | Crew scorecard | agent runs per model and per prompt version",
43 "crew-handover | Crew hand-overs | issues parked twice, and the last restore drill",
44 "scorecard | Crew scorecard per agent | each agent's pulls landed, review rounds, red checks, reverts, time to land",
45 "proposal-tokens | Proposal tokens | mint, list and revoke what a child proposes with",
46 "model | Model budget | what your crew may spend, and add your own subscription",
47 "model-grant | Model grant | give an account dollars a month, or take it back",
48 "model-ceiling | Model ceiling | set an account's dollars a day and a run",
49 "can | What I can do | your role and what it allows here",
50 "people | People | who is a guest, a member or an admin; promote or demote",
51 "quotas | Account quotas | what one account may own, and who changed it",
52 "limits | Limits | what the forge caps, with default and bounds; change one",
53 "teams | Crew teams | each team's charter, dial and members",
54 "invites | Invite links | make a single-use link, see which are open, revoke one",
55 "subscriptions | Crew subscriptions | each account's budget and rest; wake one, set its budget, add or remove one",
56 "cloud | Cloud accounts | provider tokens, what they are used for, today's calls",
57 "domains | Failure domains | failure domains and their last drill",
58 "owner | Owner's needs | what needs the owner, snapshots, failure domains",
59 "forges | Forges you sent | each forge sent, claimed or not, and its apps",
60 "family | Family | the forge that sent this one, and the forges it sent",
61 "chain | Chain | the forges this forge's code descends from, root first",
62 "quit | Quit | disconnect"
63 ],
64 "member": [
65 "home | Home | your repositories",
66 "explore | Explore | on the web",
67 "profile | Open a profile | username or org",
68 "repo | Open a repository | owner/name",
69 "issues | Issues in a repository | owner/name",
70 "pulls | Pull requests in a repository | owner/name",
71 "milestones | Milestones in a repository | owner/name",
72 "repo-usage | Usage of a repository | owner/name",
73 "new-issue | New issue | owner/name",
74 "new-pull | New pull request | owner/name",
75 "settings | Repository settings | owner/name",
76 "new-repo | New repository | ",
77 "new-org | New organization | an organization you own, for a client's apps",
78 "migrate | Migrate a repository | bring one in from an origin or a URL, pick its branch, put a crew on it",
79 "new-forge | New forge | spawn a client's forge and get its claim link",
80 "asked | Asked | your thoughts and what became of them",
81 "decider | Decider | what it closed, deferred and asked you about today",
82 "notify | Phone notifications | where the crew reaches your phone; s sets, x turns off",
83 "ssh-keys | SSH keys | list, add and remove the keys that sign in as you",
84 "account | Account settings | ",
85 "signins | Signed in | your browsers and tokens; d signs a browser out",
86 "api | API | the forge's endpoints; run a GET",
87 "changelog | Changelog | the last 30 releases and their pulls",
88 "stalled | Stalled steps | pulls whose check is red or was never asked for; enter re-runs",
89 "file-holds | Held files | hold new work on a file, release it, or list the holds",
90 "proposal-tokens | Proposal tokens | mint, list and revoke what a child proposes with",
91 "model | Model budget | what your crew may spend, and add your own subscription",
92 "can | What I can do | your role and what it allows here",
93 "family | Family | the forge that sent this one, and the forges it sent",
94 "chain | Chain | the forges this forge's code descends from, root first",
95 "quit | Quit | disconnect"
96 ],
97 "agent": [
98 "home | Home | your repositories",
99 "explore | Explore | on the web",
100 "profile | Open a profile | username or org",
101 "repo | Open a repository | owner/name",
102 "issues | Issues in a repository | owner/name",
103 "pulls | Pull requests in a repository | owner/name",
104 "milestones | Milestones in a repository | owner/name",
105 "repo-usage | Usage of a repository | owner/name",
106 "new-issue | New issue | owner/name",
107 "new-pull | New pull request | owner/name",
108 "settings | Repository settings | owner/name",
109 "new-repo | New repository | ",
110 "migrate | Migrate a repository | bring one in from an origin or a URL, pick its branch, put a crew on it",
111 "new-forge | New forge | spawn a client's forge and get its claim link",
112 "asked | Asked | your thoughts and what became of them",
113 "decider | Decider | what it closed, deferred and asked you about today",
114 "ssh-keys | SSH keys | list, add and remove the keys that sign in as you",
115 "account | Account settings | ",
116 "signins | Signed in | your browsers and tokens; d signs a browser out",
117 "api | API | the forge's endpoints; run a GET",
118 "changelog | Changelog | the last 30 releases and their pulls",
119 "stalled | Stalled steps | pulls whose check is red or was never asked for; enter re-runs",
120 "file-holds | Held files | hold new work on a file, release it, or list the holds",
121 "proposal-tokens | Proposal tokens | mint, list and revoke what a child proposes with",
122 "can | What I can do | your role and what it allows here",
123 "family | Family | the forge that sent this one, and the forges it sent",
124 "chain | Chain | the forges this forge's code descends from, root first",
125 "quit | Quit | disconnect"
126 ],
127 "signedOut": [
128 "home | Home | your repositories",
129 "explore | Explore | on the web",
130 "profile | Open a profile | username or org",
131 "repo | Open a repository | owner/name",
132 "issues | Issues in a repository | owner/name",
133 "pulls | Pull requests in a repository | owner/name",
134 "milestones | Milestones in a repository | owner/name",
135 "repo-usage | Usage of a repository | owner/name",
136 "new-issue | New issue | owner/name",
137 "new-pull | New pull request | owner/name",
138 "settings | Repository settings | owner/name",
139 "signin | Sign in | ",
140 "api | API | the forge's endpoints; run a GET",
141 "changelog | Changelog | the last 30 releases and their pulls",
142 "family | Family | the forge that sent this one, and the forges it sent",
143 "chain | Chain | the forges this forge's code descends from, root first",
144 "quit | Quit | disconnect"
145 ]
146 }
test/tui-palette-entries.test.ts added +91
@@ -0,0 +1,91 @@
1 /**
2 * The palette is the list of each screen's own entry (`screens/entries.ts`):
3 * what a site admin, a member, an agent and a signed-out session are offered,
4 * in which order, under which id, title and hint, is the golden below, taken
5 * before the entries moved out of `tui/forge.ts`.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createUser, type User } from "../src/core/users.ts";
13 import { forgeCommands, Session } from "../src/tui/forge.ts";
14 import type { Ctx } from "../src/tui/app/app.ts";
15
16 let dataDir: string;
17 let app: App;
18 const users: Record<string, User | undefined> = {};
19
20 const identity = (user?: User) => ({
21 sshUsername: user?.username ?? "git",
22 remoteAddress: "127.0.0.1",
23 fingerprint: "SHA256:test",
24 user,
25 });
26
27 const palette = (user?: User) =>
28 forgeCommands(new Session(app, identity(user)))({} as unknown as Ctx).map(
29 (c) => `${c.id} | ${c.title} | ${c.hint ?? ""}`,
30 );
31
32 beforeAll(async () => {
33 dataDir = await mkdtemp(join(tmpdir(), "forge-tui-entries-"));
34 app = createApp({ dataDir, port: 0 });
35 const mk = async (username: string, adminIfFirst: boolean, agent = false) => {
36 const r = await createUser(app.db, {
37 origin: agent ? "agent" : "seed",
38 trusted: true,
39 username,
40 email: `${username}@forge.local`,
41 password: "a-good-passphrase",
42 adminIfFirst,
43 agent,
44 });
45 if (!r.ok) throw new Error(r.error);
46 return r.value;
47 };
48 users["admin"] = await mk("alice", true);
49 users["member"] = await mk("bob", false);
50 users["agent"] = await mk("carl", false, true);
51 });
52 afterAll(async () => {
53 app.close();
54 await rm(dataDir, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 });
55 });
56
57 const goldenFile = Bun.file(join(import.meta.dir, "fixtures", "tui-palette.json"));
58
59 describe("the palette's entries", () => {
60 test("each kind of session is offered what it was before the entries moved", async () => {
61 const now = {
62 admin: palette(users["admin"]),
63 member: palette(users["member"]),
64 agent: palette(users["agent"]),
65 signedOut: palette(undefined),
66 };
67 if (process.env["FORGE_WRITE_GOLDEN"] === "1")
68 await Bun.write(goldenFile, JSON.stringify(now, null, 2) + "\n");
69 expect(now).toEqual(await goldenFile.json());
70 });
71
72 test("ids are unique within a palette", () => {
73 for (const user of [users["admin"], users["member"], users["agent"], undefined]) {
74 const ids = palette(user).map((l) => l.split(" | ")[0]);
75 expect(new Set(ids).size).toBe(ids.length);
76 }
77 });
78
79 test("Flow is a site admin's: a guest is not offered it and running it opens nothing", () => {
80 const run = (user: User | undefined) => {
81 const pushed: unknown[] = [];
82 const ctx = { push: (x: unknown) => pushed.push(x), toast: () => undefined } as unknown as Ctx;
83 const flow = forgeCommands(new Session(app, identity(user)))(ctx).find((c) => c.id === "flow");
84 flow?.run();
85 return { offered: flow !== undefined, pushed: pushed.length };
86 };
87 expect(run(undefined)).toEqual({ offered: false, pushed: 0 });
88 expect(run(users["member"])).toEqual({ offered: false, pushed: 0 });
89 expect(run(users["admin"])).toEqual({ offered: true, pushed: 1 });
90 });
91 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs