Public: anyone can read this; the crew can change it.
The board speaks the studio's five words, from the same place the pages do #478
mason/forge:mason/67-the-board-speaks-the-studio-s-five-words → main 2 commits fork
5 files
changed +357
−78
docs/STUDIO.md +13 −3
| @@ -387,12 +387,22 @@ person's dev home. | ||
| 387 | 387 | (**Focus** on that card opens it): no top bar, dark unless you chose a |
| 388 | 388 | theme, four regions that fill the window. **Working now** is one card per |
| 389 | 389 | run in flight — who, which app, what it is on, why, how long, what it has |
| 390 | cost — ordered by when it started. **Landed** is the last dozen shipped | |
| 390 | cost — ordered by when it started. **Landed** is the last dozen merged | |
| 391 | 391 | changes across your apps, each with the app's production look on a phone. |
| 392 | 392 | **Decided** is the last dozen entries in the decision ledger: which issue |
| 393 | 393 | next, ship or show, try again — the answer, how sure the decider was, and |
| 394 | what came of it. **Today** is one row per app that runs on its own: spend | |
| 395 | against the ceiling, runs, shipped, and whether it is paused — plus any | |
| 394 | what came of it. The board speaks the same five words as every studio page | |
| 395 | and nothing of its own: a run card's word is `runWord`'s, a landed change's | |
| 396 | `pullWord`'s, and what came of a decision is where its pull or tell stands | |
| 397 | now (`pullWord`/`tellWord`, `studio/words.ts`) — never the ledger's own | |
| 398 | outcome — so a merge production has not served yet reads _waiting_ on the | |
| 399 | wall exactly as it does on the app's page, and _shipped_ only once | |
| 400 | production is serving it. Every word is coloured by `wordVariant`, the | |
| 401 | same map the badge draws from, so a word added later is never uncoloured. | |
| 402 | **Today** is one row per app that runs on its own: spend against the | |
| 403 | ceiling, runs, shipped, and whether it is paused — the app page's own | |
| 404 | reads (`autonomyStatus`, `agentRunTotals`, `mergedPullCount`) over today, | |
| 405 | and its paused words (`pausedWords`) — plus any | |
| 396 | 406 | other app the crew spent on this week — and beneath it the efficiency |
| 397 | 407 | signal: spend per shipped change over the last 7 days (the usage ledger's |
| 398 | 408 | `cost_usd` ÷ pulls merged, `core/efficiency.ts`, every app in one grouped |
src/web/pages/board.ts +130 −55
| @@ -6,7 +6,9 @@ | ||
| 6 | 6 | * matching event lands. A site admin also gets two strips above them: the |
| 7 | 7 | * forge's health, and each subscription's windows. Nothing on it |
| 8 | 8 | * needs a click, and everything on it links somewhere. It reads the same |
| 9 | * tables as the studio and adds no state of its own. | |
| 9 | * tables as the studio and adds no state of its own — nor words: every | |
| 10 | * run, change and decision on it is worded by `runWord`/`pullWord`/ | |
| 11 | * `tellWord`, the studio's own, and coloured by `wordVariant`. | |
| 10 | 12 | * |
| 11 | 13 | * `?wall` is its one wall mode, for a screen across the room that nobody |
| 12 | 14 | * touches: the same regions in larger type, without the key hints or a |
| @@ -27,26 +29,41 @@ import { listApps } from "../../core/apps.ts"; | ||
| 27 | 29 | import { vitals, type Vitals } from "../../kernel/vitals.ts"; |
| 28 | 30 | import { getIssue, getIssuesByIds, type Issue } from "../../core/issues.ts"; |
| 29 | 31 | import { looksForApps } from "../../core/looks.ts"; |
| 30 | import { listPulls, mergedPullsForRepos, type Pull } from "../../core/pulls.ts"; | |
| 32 | import { | |
| 33 | getPull, | |
| 34 | mergedPullCount, | |
| 35 | mergedPullsForRepos, | |
| 36 | openPullsClosing, | |
| 37 | type Pull, | |
| 38 | } from "../../core/pulls.ts"; | |
| 31 | 39 | import { |
| 32 | 40 | canSeeOwnerFacts, |
| 33 | 41 | listReposVisibleTo, |
| 34 | 42 | type Repo, |
| 35 | 43 | } from "../../core/repos.ts"; |
| 36 | import { listActiveRuns, listRuns, type Run } from "../../core/runs.ts"; | |
| 44 | import { agentRunTotals, listActiveRuns, type Run } from "../../core/runs.ts"; | |
| 37 | 45 | import { getUsersByIds } from "../../core/users.ts"; |
| 38 | 46 | import { autonomyStatus, startOfTodayUtc } from "../../crew/autonomy.ts"; |
| 47 | import { repoDir } from "../../git/repos.ts"; | |
| 39 | 48 | import type { Ctx } from "../../http/context.ts"; |
| 40 | 49 | import { repoBase, signInFirst } from "../chrome.ts"; |
| 41 | 50 | import { boardJs, liveRegionsJs } from "../client.ts"; |
| 42 | 51 | import { html, when, type Html } from "../html.ts"; |
| 43 | 52 | import { page, redirect } from "../layout.ts"; |
| 44 | 53 | import { avatar, icon, time } from "../ui.ts"; |
| 54 | import { tellWord } from "../studio/tell.ts"; | |
| 45 | 55 | import { voiceFor } from "../studio/voice.ts"; |
| 46 | 56 | import { |
| 57 | pausedWords, | |
| 47 | 58 | perShippedWords, |
| 59 | pullWord, | |
| 60 | runWord, | |
| 61 | servingHistory, | |
| 48 | 62 | windowWords, |
| 63 | wordVariant, | |
| 49 | 64 | type FigureWords, |
| 65 | type Word, | |
| 66 | type WordCtx, | |
| 50 | 67 | } from "../studio/words.ts"; |
| 51 | 68 | import { lookUrl, thumbLook } from "./looks.ts"; |
| 52 | 69 | |
| @@ -72,13 +89,6 @@ function reasonWords(reason: string): string { | ||
| 72 | 89 | } |
| 73 | 90 | } |
| 74 | 91 | |
| 75 | type StateWord = "queued" | "working" | "paused"; | |
| 76 | ||
| 77 | function stateWord(run: Run): StateWord { | |
| 78 | if (run.state === "running") return "working"; | |
| 79 | return run.notBefore === null ? "queued" : "paused"; | |
| 80 | } | |
| 81 | ||
| 82 | 92 | const KIND_WORDS: Record<DecisionKind, string> = { |
| 83 | 93 | next: "next issue", |
| 84 | 94 | land: "ship or show", |
| @@ -102,6 +112,9 @@ interface BoardScope { | ||
| 102 | 112 | * access, same as the studio. A repo the viewer can only read is on the |
| 103 | 113 | * board (it is still theirs to watch land) but carries none of that. */ |
| 104 | 114 | readonly ownerFacts: ReadonlySet<string>; |
| 115 | /** What the studio's word functions need to see each app's production, | |
| 116 | * every app sharing one render's memo of production's history. */ | |
| 117 | readonly words: (repo: Repo) => WordCtx; | |
| 105 | 118 | } |
| 106 | 119 | |
| 107 | 120 | /** The scope for some repositories: the ones among them that are apps. */ |
| @@ -111,6 +124,9 @@ function boardScope( | ||
| 111 | 124 | records: ReadonlyMap<string, AppRecord>, |
| 112 | 125 | ): BoardScope { |
| 113 | 126 | const kept = repos.filter((r) => records.has(r.id)); |
| 127 | const runtime = appsRuntime(ctx.app); | |
| 128 | const history = servingHistory(); | |
| 129 | const contexts = new Map<string, WordCtx>(); | |
| 114 | 130 | return { |
| 115 | 131 | repos: kept, |
| 116 | 132 | ids: kept.map((r) => r.id), |
| @@ -121,13 +137,37 @@ function boardScope( | ||
| 121 | 137 | .filter((r) => canSeeOwnerFacts(ctx.app.db, r, ctx.auth.user)) |
| 122 | 138 | .map((r) => r.id), |
| 123 | 139 | ), |
| 140 | words: (repo) => { | |
| 141 | let made = contexts.get(repo.id); | |
| 142 | if (made === undefined) { | |
| 143 | made = { | |
| 144 | db: ctx.app.db, | |
| 145 | dir: repoDir(ctx.app.reposRoot, repo.ownerName, repo.name), | |
| 146 | runtime, | |
| 147 | record: records.get(repo.id), | |
| 148 | history, | |
| 149 | }; | |
| 150 | contexts.set(repo.id, made); | |
| 151 | } | |
| 152 | return made; | |
| 153 | }, | |
| 124 | 154 | }; |
| 125 | 155 | } |
| 126 | 156 | |
| 157 | /** A studio word on a card, coloured from the word itself. */ | |
| 158 | function wordSpan(cls: string, word: Word): Html { | |
| 159 | return html`<span | |
| 160 | class="${cls}" | |
| 161 | data-word="${word}" | |
| 162 | data-variant="${wordVariant(word)}" | |
| 163 | >${word}</span | |
| 164 | >`; | |
| 165 | } | |
| 166 | ||
| 127 | 167 | // ---- the page ---- |
| 128 | 168 | |
| 129 | 169 | /** GET /board — signed in; every app the viewer can see, or `?apps=` some; `?wall` for the wall mode. */ |
| 130 | export function boardPage(ctx: Ctx): Response { | |
| 170 | export async function boardPage(ctx: Ctx): Promise<Response> { | |
| 131 | 171 | const user = ctx.auth.user; |
| 132 | 172 | if (!user) return signInFirst(ctx); |
| 133 | 173 | const db = ctx.app.db; |
| @@ -181,7 +221,8 @@ export function boardPage(ctx: Ctx): Response { | ||
| 181 | 221 | </header> |
| 182 | 222 | ${forgeStrip(ctx)} ${windowsStrip(ctx)} |
| 183 | 223 | <div class="board-grid"> |
| 184 | ${working(ctx, scope)} ${landed(ctx, scope)} ${decided(ctx, scope)} | |
| 224 | ${await working(ctx, scope)} ${await landed(ctx, scope)} | |
| 225 | ${await decided(ctx, scope)} | |
| 185 | 226 | ${today(ctx, scope)} |
| 186 | 227 | </div> |
| 187 | 228 | </div>`; |
| @@ -358,7 +399,7 @@ function windowsStrip(ctx: Ctx): Html | null { | ||
| 358 | 399 | |
| 359 | 400 | // ---- working now ---- |
| 360 | 401 | |
| 361 | function working(ctx: Ctx, scope: BoardScope): Html { | |
| 402 | async function working(ctx: Ctx, scope: BoardScope): Promise<Html> { | |
| 362 | 403 | const db = ctx.app.db; |
| 363 | 404 | const runs = listActiveRuns(db, scope.ids); |
| 364 | 405 | // Working first, by when it started; then what waits, by when it was queued. |
| @@ -376,7 +417,10 @@ function working(ctx: Ctx, scope: BoardScope): Html { | ||
| 376 | 417 | db, |
| 377 | 418 | runs.map((r) => r.issueId).filter((id): id is string => id !== null), |
| 378 | 419 | ); |
| 379 | const rows = runs.map((run) => { | |
| 420 | const words = await Promise.all( | |
| 421 | runs.map((run) => runWord(scope.words(scope.byId.get(run.repoId)!), run)), | |
| 422 | ); | |
| 423 | const rows = runs.map((run, n) => { | |
| 380 | 424 | const repo = scope.byId.get(run.repoId)!; |
| 381 | 425 | // The same rule the app's page signs its rows by, `voiceFor` |
| 382 | 426 | // (`studio/voice.ts`): the crew's own work reads as the app's own story |
| @@ -390,11 +434,12 @@ function working(ctx: Ctx, scope: BoardScope): Html { | ||
| 390 | 434 | scope.ownerFacts.has(repo.id), |
| 391 | 435 | ); |
| 392 | 436 | const issue = run.issueId === null ? undefined : about.get(run.issueId); |
| 393 | const word = stateWord(run); | |
| 437 | const { word, note } = words[n]!; | |
| 394 | 438 | return html`<li> |
| 395 | 439 | <a |
| 396 | 440 | class="board-card board-run" |
| 397 | 441 | data-state="${word}" |
| 442 | data-variant="${wordVariant(word)}" | |
| 398 | 443 | data-key="run:${run.id}" |
| 399 | 444 | href="${repoBase(repo)}/runs/${run.id}" |
| 400 | 445 | > |
| @@ -408,7 +453,7 @@ function working(ctx: Ctx, scope: BoardScope): Html { | ||
| 408 | 453 | <span class="board-state">${word}</span> |
| 409 | 454 | <span |
| 410 | 455 | >${ |
| 411 | word === "paused" ? "resumes soon" : reasonWords(run.reason) | |
| 456 | run.notBefore === null ? reasonWords(run.reason) : note | |
| 412 | 457 | }</span |
| 413 | 458 | > |
| 414 | 459 | ${when( |
| @@ -433,7 +478,7 @@ function working(ctx: Ctx, scope: BoardScope): Html { | ||
| 433 | 478 | |
| 434 | 479 | // ---- landed ---- |
| 435 | 480 | |
| 436 | function landed(ctx: Ctx, scope: BoardScope): Html { | |
| 481 | async function landed(ctx: Ctx, scope: BoardScope): Promise<Html> { | |
| 437 | 482 | const db = ctx.app.db; |
| 438 | 483 | const pulls = mergedPullsForRepos(db, scope.ids, 12); |
| 439 | 484 | // The newest production picture of each app, on a phone, in one read. |
| @@ -460,7 +505,10 @@ function landed(ctx: Ctx, scope: BoardScope): Html { | ||
| 460 | 505 | ) |
| 461 | 506 | ); |
| 462 | 507 | }; |
| 463 | const rows = pulls.map((pull: Pull) => { | |
| 508 | const words = await Promise.all( | |
| 509 | pulls.map((pull) => pullWord(scope.words(scope.byId.get(pull.repoId)!), pull)), | |
| 510 | ); | |
| 511 | const rows = pulls.map((pull: Pull, n) => { | |
| 464 | 512 | const repo = scope.byId.get(pull.repoId)!; |
| 465 | 513 | const picture = pictureOf(repo); |
| 466 | 514 | const author = voiceFor( |
| @@ -488,7 +536,10 @@ function landed(ctx: Ctx, scope: BoardScope): Html { | ||
| 488 | 536 | > |
| 489 | 537 | <span class="board-landed-title">${pull.title}</span> |
| 490 | 538 | <span class="board-when">${time(pull.mergedAt ?? pull.createdAt)}</span> |
| 491 | <span class="board-landed-meta">${repo.name} · ${author}</span> | |
| 539 | <span class="board-landed-meta" | |
| 540 | >${repo.name} · ${author} | |
| 541 | ${wordSpan("board-word", words[n]!.word)}</span | |
| 542 | > | |
| 492 | 543 | </a> |
| 493 | 544 | </li>`; |
| 494 | 545 | }); |
| @@ -504,7 +555,7 @@ function landed(ctx: Ctx, scope: BoardScope): Html { | ||
| 504 | 555 | |
| 505 | 556 | // ---- decided ---- |
| 506 | 557 | |
| 507 | function decided(ctx: Ctx, scope: BoardScope): Html { | |
| 558 | async function decided(ctx: Ctx, scope: BoardScope): Promise<Html> { | |
| 508 | 559 | const db = ctx.app.db; |
| 509 | 560 | // The decision ledger is the owner's own record of what the crew chose — |
| 510 | 561 | // never shown for a repository this viewer can only read. |
| @@ -516,15 +567,41 @@ function decided(ctx: Ctx, scope: BoardScope): Html { | ||
| 516 | 567 | db, |
| 517 | 568 | decisions.map((d) => d.issueId).filter((id): id is string => id !== null), |
| 518 | 569 | ); |
| 519 | const rows = decisions.map((d: Decision) => { | |
| 570 | // What each decision was about: the issue picked for `next`, the pull | |
| 571 | // for the rest. A pick names its issue by number. | |
| 572 | const subjects = decisions.map((d): Issue | undefined => { | |
| 573 | const issue = d.issueId === null ? undefined : about.get(d.issueId); | |
| 574 | if (d.kind === "next" && /^\d+$/.test(d.answer)) | |
| 575 | return getIssue(db, d.repoId, Number(d.answer)) ?? issue; | |
| 576 | return issue; | |
| 577 | }); | |
| 578 | // What came of it is where that pull or tell stands now, in the studio's | |
| 579 | // own words — never the ledger's private outcome, so a merge production | |
| 580 | // has not served yet reads *waiting* here as it does on the app's page. | |
| 581 | const closing = new Map<string, Map<number, Pull>>(); | |
| 582 | const words = await Promise.all( | |
| 583 | decisions.map(async (d, n) => { | |
| 584 | const issue = subjects[n]; | |
| 585 | if (issue === undefined) return undefined; | |
| 586 | const repo = scope.byId.get(d.repoId)!; | |
| 587 | const wordCtx = scope.words(repo); | |
| 588 | if (issue.kind === "pull") { | |
| 589 | const pull = getPull(db, repo.id, issue.number); | |
| 590 | return pull && (await pullWord(wordCtx, pull)); | |
| 591 | } | |
| 592 | let pulls = closing.get(repo.id); | |
| 593 | if (pulls === undefined) { | |
| 594 | pulls = openPullsClosing(db, repo.id); | |
| 595 | closing.set(repo.id, pulls); | |
| 596 | } | |
| 597 | return await tellWord(wordCtx, repo, issue, pulls.get(issue.number)); | |
| 598 | }), | |
| 599 | ); | |
| 600 | const rows = decisions.map((d: Decision, n) => { | |
| 520 | 601 | const repo = scope.byId.get(d.repoId)!; |
| 521 | 602 | const base = repoBase(repo); |
| 522 | // What the decision was about: the issue picked for `next`, the pull | |
| 523 | // for the rest. A pick names its issue by number. | |
| 524 | let issue: Issue | undefined = | |
| 525 | d.issueId === null ? undefined : about.get(d.issueId); | |
| 526 | if (d.kind === "next" && /^\d+$/.test(d.answer)) | |
| 527 | issue = getIssue(db, repo.id, Number(d.answer)) ?? issue; | |
| 603 | const issue = subjects[n]; | |
| 604 | const word = words[n]?.word; | |
| 528 | 605 | const href = |
| 529 | 606 | issue === undefined |
| 530 | 607 | ? base |
| @@ -552,9 +629,11 @@ function decided(ctx: Ctx, scope: BoardScope): Html { | ||
| 552 | 629 | ></span> |
| 553 | 630 | <span class="num">${Math.round(d.p * 100)}%</span> |
| 554 | 631 | </span> |
| 555 | <span class="board-outcome" data-outcome="${d.outcome ?? ""}" | |
| 556 | >${d.outcome ?? "—"}</span | |
| 557 | > | |
| 632 | ${ | |
| 633 | word === undefined | |
| 634 | ? html`<span class="board-outcome">—</span>` | |
| 635 | : wordSpan("board-outcome", word) | |
| 636 | } | |
| 558 | 637 | <span class="board-when">${time(d.createdAt)}</span> |
| 559 | 638 | </a> |
| 560 | 639 | </li>`; |
| @@ -590,22 +669,12 @@ function today(ctx: Ctx, scope: BoardScope): Html { | ||
| 590 | 669 | ) |
| 591 | 670 | .map((repo) => { |
| 592 | 671 | const s = autonomyStatus(ctx.app, repo); |
| 593 | const runs = listRuns(db, repo.id, { kind: "agent", limit: 200 }).filter( | |
| 594 | (r) => r.createdAt >= since, | |
| 595 | ).length; | |
| 596 | const shipped = listPulls(db, repo.id, { | |
| 597 | state: "closed", | |
| 598 | limit: 100, | |
| 599 | }).filter((p) => p.mergedAt !== null && p.mergedAt >= since).length; | |
| 672 | // The app page's own reads (`studio/app.ts`), over today rather | |
| 673 | // than the week: counted by the database, not off a page of rows. | |
| 674 | const runs = agentRunTotals(db, repo.id, since).runs; | |
| 675 | const shipped = mergedPullCount(db, repo.id, since); | |
| 600 | 676 | const share = s.ceilingUsd > 0 ? s.spentTodayUsd / s.ceilingUsd : 0; |
| 601 | const note = | |
| 602 | s.paused === "ceiling" | |
| 603 | ? "at its ceiling until 00:00 UTC" | |
| 604 | : s.paused === "nobody" | |
| 605 | ? "nobody turned it on" | |
| 606 | : s.paused === "no crew" | |
| 607 | ? "no crew" | |
| 608 | : repo.autonomy; | |
| 677 | const note = s.paused === null ? repo.autonomy : pausedWords(s.paused); | |
| 609 | 678 | return html`<li> |
| 610 | 679 | <a |
| 611 | 680 | class="board-card board-app" |
| @@ -709,13 +778,17 @@ ${widths} | ||
| 709 | 778 | .board-run-meta { grid-column: 2 / span 2; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; font-size: .9em; color: var(--muted-fg); } |
| 710 | 779 | .board-state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--fg); } |
| 711 | 780 | .board-state::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--faint); } |
| 712 | .board-run[data-state="working"] { border-color: color-mix(in srgb, var(--accent) 38%, var(--border)); } | |
| 713 | .board-run[data-state="working"] .board-state { color: var(--accent); } | |
| 714 | .board-run[data-state="working"] .board-state::before { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); } | |
| 715 | .board-run[data-state="working"] .board-elapsed { color: var(--accent); } | |
| 716 | .board-run[data-state="queued"] .board-elapsed { color: var(--muted-fg); } | |
| 717 | .board-run[data-state="paused"] .board-state { color: var(--attn); } | |
| 718 | .board-run[data-state="paused"] .board-state::before { background: var(--attn); } | |
| 781 | /* Coloured by the word's variant (wordVariant), never by the word, so a | |
| 782 | word added later is coloured the moment it exists. */ | |
| 783 | .board-run[data-variant="accent"] { border-color: color-mix(in srgb, var(--accent) 38%, var(--border)); } | |
| 784 | .board-run[data-variant="accent"] .board-state { color: var(--accent); } | |
| 785 | .board-run[data-variant="accent"] .board-state::before { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); } | |
| 786 | .board-run[data-variant="accent"] .board-elapsed { color: var(--accent); } | |
| 787 | .board-run[data-variant="secondary"] .board-elapsed { color: var(--muted-fg); } | |
| 788 | .board-run[data-variant="success"] .board-state { color: var(--success); } | |
| 789 | .board-run[data-variant="success"] .board-state::before { background: var(--success); } | |
| 790 | .board-run[data-variant="danger"] .board-state { color: var(--danger); } | |
| 791 | .board-run[data-variant="danger"] .board-state::before { background: var(--danger); } | |
| 719 | 792 | /* Nothing on the wall animates on its own. A perpetual animation keeps the |
| 720 | 793 | browser painting every frame all day — three pulsing dots measured at over |
| 721 | 794 | 100% CPU under software rendering. The ticking clocks are the sign of life. */ |
| @@ -737,9 +810,11 @@ ${widths} | ||
| 737 | 810 | .board-p { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: .75em; color: var(--muted-fg); } |
| 738 | 811 | .board-p .board-bar { flex: 1; } |
| 739 | 812 | .board-outcome { font-size: .875em; color: var(--faint); } |
| 740 | .board-outcome[data-outcome="shipped"], .board-outcome[data-outcome="green"] { color: var(--success); } | |
| 741 | .board-outcome[data-outcome="red"] { color: var(--danger); } | |
| 742 | .board-outcome[data-outcome="shown"], .board-outcome[data-outcome="closed"] { color: var(--attn); } | |
| 813 | .board-word { font-size: .875em; color: var(--faint); margin-left: 4px; } | |
| 814 | .board-outcome[data-variant="success"], .board-word[data-variant="success"] { color: var(--success); } | |
| 815 | .board-outcome[data-variant="danger"], .board-word[data-variant="danger"] { color: var(--danger); } | |
| 816 | .board-outcome[data-variant="accent"], .board-word[data-variant="accent"] { color: var(--accent); } | |
| 817 | .board-outcome[data-variant="secondary"], .board-word[data-variant="secondary"] { color: var(--muted-fg); } | |
| 743 | 818 | |
| 744 | 819 | /* Today: each app that runs on its own, its spend against the ceiling. */ |
| 745 | 820 | .board-app { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: baseline; padding: 12px 16px; } |
src/web/studio/app.ts +2 −6
| @@ -43,7 +43,7 @@ import { | ||
| 43 | 43 | import { changesHref, tellsHref } from "./nouns.ts"; |
| 44 | 44 | import { nowCard, nowRegion } from "./now.ts"; |
| 45 | 45 | import { appPanels } from "./previews.ts"; |
| 46 | import { servingHistory, type WordCtx } from "./words.ts"; | |
| 46 | import { pausedWords, servingHistory, type WordCtx } from "./words.ts"; | |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * The week's decisions in one line: how many, how many the decider took |
| @@ -394,11 +394,7 @@ export async function studioApp( | ||
| 394 | 394 | <dd>${autonomy.active} of ${autonomy.slots} in use</dd> |
| 395 | 395 | ${autonomy.paused |
| 396 | 396 | ? html`<dt>Paused</dt> |
| 397 | <dd> | |
| 398 | ${autonomy.paused === "ceiling" | |
| 399 | ? "at the ceiling, until 00:00 UTC" | |
| 400 | : autonomy.paused} | |
| 401 | </dd>` | |
| 397 | <dd>${pausedWords(autonomy.paused)}</dd>` | |
| 402 | 398 | : null} |
| 403 | 399 | </dl>`, |
| 404 | 400 | { |
src/web/studio/words.ts +42 −12
| @@ -14,6 +14,7 @@ import type { AppsRuntime, EnvStatus } from "../../apps/runtime.ts"; | ||
| 14 | 14 | import type { AppRecord } from "../../core/apps.ts"; |
| 15 | 15 | import type { Efficiency } from "../../core/efficiency.ts"; |
| 16 | 16 | import type { WindowStanding } from "../../core/standing.ts"; |
| 17 | import type { Paused } from "../../crew/autonomy.ts"; | |
| 17 | 18 | import { whenText } from "../../crew/limits.ts"; |
| 18 | 19 | import { getIssueById } from "../../core/issues.ts"; |
| 19 | 20 | import { getPull, pullForBranch, type Pull } from "../../core/pulls.ts"; |
| @@ -328,28 +329,57 @@ const WORD_ICON: Record<Word, Parameters<typeof icon>[0]> = { | ||
| 328 | 329 | cancelled: "ban", |
| 329 | 330 | }; |
| 330 | 331 | |
| 332 | /** The colour a word is drawn in. */ | |
| 333 | export type WordVariant = "success" | "danger" | "accent" | "secondary"; | |
| 334 | ||
| 335 | /** | |
| 336 | * Each word's colour, decided once: the badge draws it and the board | |
| 337 | * colours its cards by it, so a word added to `Word` cannot render | |
| 338 | * uncoloured anywhere — the `Record` will not compile without it. | |
| 339 | * `cancelled` draws the same quiet, secondary look as `waiting` and | |
| 340 | * `planned` — a restart is never the danger red a real failure earns. | |
| 341 | */ | |
| 342 | const WORD_VARIANT: Record<Word, WordVariant> = { | |
| 343 | working: "accent", | |
| 344 | look: "success", | |
| 345 | shipped: "success", | |
| 346 | stopped: "danger", | |
| 347 | waiting: "secondary", | |
| 348 | planned: "secondary", | |
| 349 | told: "secondary", | |
| 350 | done: "success", | |
| 351 | cancelled: "secondary", | |
| 352 | }; | |
| 353 | ||
| 354 | export const wordVariant = (word: Word): WordVariant => WORD_VARIANT[word]; | |
| 355 | ||
| 331 | 356 | /** One of the five (or six) studio words, as a badge. An id names the one a |
| 332 | * live script repaints as a run finishes (`studioRunJs`). `cancelled` draws | |
| 333 | * the same quiet, secondary look as `waiting` and `planned` — a restart is | |
| 334 | * never the danger red a real failure earns. */ | |
| 357 | * live script repaints as a run finishes (`studioRunJs`). */ | |
| 335 | 358 | export function wordBadge(word: Word, id?: string): Html { |
| 336 | const variant = | |
| 337 | word === "look" || word === "shipped" || word === "done" | |
| 338 | ? "success" | |
| 339 | : word === "stopped" | |
| 340 | ? "danger" | |
| 341 | : word === "working" | |
| 342 | ? "accent" | |
| 343 | : "secondary"; | |
| 344 | 359 | return html`<span |
| 345 | 360 | class="badge" |
| 346 | data-variant="${variant}" | |
| 361 | data-variant="${wordVariant(word)}" | |
| 347 | 362 | data-word="${word}" |
| 348 | 363 | ${id === undefined ? null : html`id="${id}"`} |
| 349 | 364 | >${word === "working" ? icon("loader") : null}${word}</span |
| 350 | 365 | >`; |
| 351 | 366 | } |
| 352 | 367 | |
| 368 | /** Why an app that runs on its own is not running right now, in words — | |
| 369 | * the app page's *On its own* card and the board's *Today* row both. */ | |
| 370 | export function pausedWords(paused: Paused): string { | |
| 371 | switch (paused) { | |
| 372 | case "ceiling": | |
| 373 | return "at the ceiling, until 00:00 UTC"; | |
| 374 | case "forge ceiling": | |
| 375 | return "at the forge's ceiling, until 00:00 UTC"; | |
| 376 | case "nobody": | |
| 377 | return "nobody turned it on"; | |
| 378 | case "no crew": | |
| 379 | return "no crew"; | |
| 380 | } | |
| 381 | } | |
| 382 | ||
| 353 | 383 | // ---- what a subscription has left, and what a change costs ---- |
| 354 | 384 | |
| 355 | 385 | /** One figure as a person reads it, and whether the forge worked it out |
test/board.test.ts +170 −2
| @@ -2,13 +2,14 @@ | ||
| 2 | 2 | * The board: a live wall of the crews at work. Signed in, four live |
| 3 | 3 | * regions; a run in flight and a merged pull on it; `?apps=` narrows it; |
| 4 | 4 | * `?wall` is its wall mode, where every old `/big` address lands; |
| 5 | * anonymous is sent to sign in. | |
| 5 | * anonymous is sent to sign in. Its words are the studio's own. | |
| 6 | 6 | */ |
| 7 | 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 8 | 8 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import { AppsRuntime } from "../src/apps/runtime.ts"; | |
| 12 | 13 | import { enableApp } from "../src/actions/apps.ts"; |
| 13 | 14 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 14 | 15 | import { openIssue } from "../src/actions/issues.ts"; |
| @@ -226,8 +227,11 @@ describe("the board", () => { | ||
| 226 | 227 | html.indexOf('id="working"'), |
| 227 | 228 | html.indexOf('id="landed"'), |
| 228 | 229 | ); |
| 230 | // In the studio's words (`runWord`): in flight is *working*, queued | |
| 231 | // is *waiting* — the board has no words of its own. | |
| 229 | 232 | expect(working).toContain('data-state="working"'); |
| 230 | expect(working).toContain('data-state="queued"'); | |
| 233 | expect(working).toContain('data-state="waiting"'); | |
| 234 | expect(working).not.toContain('data-state="queued"'); | |
| 231 | 235 | expect(working.indexOf("on the cart")).toBeLessThan( |
| 232 | 236 | working.indexOf("Make the notes page load"), |
| 233 | 237 | ); |
| @@ -328,6 +332,170 @@ describe("the board", () => { | ||
| 328 | 332 | }); |
| 329 | 333 | }); |
| 330 | 334 | |
| 335 | describe("the board speaks the studio's words", () => { | |
| 336 | let dataDir: string; | |
| 337 | let app: App; | |
| 338 | let servers: Servers; | |
| 339 | let runtime: AppsRuntime; | |
| 340 | let cookie: string; | |
| 341 | ||
| 342 | const board = async () => | |
| 343 | ( | |
| 344 | await fetch(`${servers.url}/board`, { | |
| 345 | headers: { cookie }, | |
| 346 | redirect: "manual", | |
| 347 | }) | |
| 348 | ).text(); | |
| 349 | const between = (html: string, from: string, to: string) => | |
| 350 | html.slice(html.indexOf(`id="${from}"`), html.indexOf(`id="${to}"`)); | |
| 351 | ||
| 352 | /** Production at this commit, as the runtime would report it — the same | |
| 353 | * stand-in `test/studio.test.ts` uses for its words. */ | |
| 354 | const serving = (appId: string, commitOid: string): void => { | |
| 355 | const envs = (runtime as unknown as { envs: Map<string, unknown> }).envs; | |
| 356 | const record = { id: appId }; | |
| 357 | envs.set(`${appId}/production`, { | |
| 358 | app: record, | |
| 359 | env: "production", | |
| 360 | chain: Promise.resolve(), | |
| 361 | restarts: [], | |
| 362 | live: { | |
| 363 | commitOid, | |
| 364 | handle: { port: 4321 }, | |
| 365 | runId: "fake", | |
| 366 | since: new Date().toISOString(), | |
| 367 | manifest: { tty: null }, | |
| 368 | }, | |
| 369 | }); | |
| 370 | }; | |
| 371 | ||
| 372 | beforeAll(async () => { | |
| 373 | dataDir = await mkdtemp(join(tmpdir(), "forge-board-words-")); | |
| 374 | app = createApp({ dataDir, port: 0 }); | |
| 375 | servers = await serve(app); | |
| 376 | // Never started: nothing deploys on its own, so production stands | |
| 377 | // exactly where `serving` puts it. | |
| 378 | runtime = new AppsRuntime(app, { | |
| 379 | domain: "board-words.test", | |
| 380 | scheme: "http", | |
| 381 | publicPort: servers.port, | |
| 382 | forgeUrl: servers.url, | |
| 383 | concurrency: 1, | |
| 384 | }); | |
| 385 | const a = await createUser(app.db, { | |
| 386 | username: "alice", | |
| 387 | email: "[email protected]", | |
| 388 | password: "a-good-passphrase", | |
| 389 | adminIfFirst: true, | |
| 390 | }); | |
| 391 | if (!a.ok) throw new Error(a.error); | |
| 392 | cookie = ( | |
| 393 | ( | |
| 394 | await fetch(`${servers.url}/signin`, { | |
| 395 | method: "POST", | |
| 396 | body: new URLSearchParams({ | |
| 397 | username: "alice", | |
| 398 | password: "a-good-passphrase", | |
| 399 | }), | |
| 400 | redirect: "manual", | |
| 401 | }) | |
| 402 | ).headers.get("set-cookie") ?? "" | |
| 403 | ).split(";")[0]!; | |
| 404 | }, 30_000); | |
| 405 | ||
| 406 | afterAll(async () => { | |
| 407 | servers.stop(); | |
| 408 | app.close(); | |
| 409 | await rm(dataDir, { recursive: true, force: true }); | |
| 410 | }); | |
| 411 | ||
| 412 | test("a merge production has not served is not shipped; a run in flight is working; the regions are as they were", async () => { | |
| 413 | const alice = getUserByName(app.db, "alice")!; | |
| 414 | const made = await createRepo(app, alice, { name: "notes" }); | |
| 415 | if (!made.ok) throw new Error(String(made.error)); | |
| 416 | const repo = made.value; | |
| 417 | const seeded = await commitToBranch(app, alice, repo, { | |
| 418 | message: "Start", | |
| 419 | files: [{ path: "README.md", content: "start\n" }], | |
| 420 | }); | |
| 421 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 422 | const enabled = await enableApp(app, alice, repo, { slug: "notes" }); | |
| 423 | if (!enabled.ok) throw new Error(String(enabled.error)); | |
| 424 | const record = getAppByRepo(app.db, repo.id)!; | |
| 425 | ||
| 426 | const branch = await commitToBranch(app, alice, repo, { | |
| 427 | branch: "feature/fast", | |
| 428 | base: "main", | |
| 429 | message: "Faster", | |
| 430 | files: [{ path: "FAST.md", content: "fast\n" }], | |
| 431 | }); | |
| 432 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 433 | const opened = await openPull(app, alice, repo, { | |
| 434 | title: "Faster notes", | |
| 435 | body: "", | |
| 436 | baseBranch: "main", | |
| 437 | headBranch: "feature/fast", | |
| 438 | }); | |
| 439 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 440 | recordDecision(app.db, { | |
| 441 | kind: "land", | |
| 442 | repoId: repo.id, | |
| 443 | issueId: opened.value.id, | |
| 444 | state: {}, | |
| 445 | answer: "ship", | |
| 446 | p: 0.9, | |
| 447 | by: "typesafe", | |
| 448 | ms: 1, | |
| 449 | }); | |
| 450 | const merged = await mergePull(app, alice, repo, opened.value, "squash"); | |
| 451 | if (!merged.ok) throw new Error(JSON.stringify(merged.error)); | |
| 452 | const pull = getPull(app.db, repo.id, opened.value.number)!; | |
| 453 | const run = createRun(app.db, { | |
| 454 | repoId: repo.id, | |
| 455 | kind: "agent", | |
| 456 | reason: "feedback", | |
| 457 | summary: "on the list", | |
| 458 | }); | |
| 459 | claimRun(app.db, run.id); | |
| 460 | ||
| 461 | // Production is still on the commit before the merge. | |
| 462 | serving(record.id, seeded.value.commitOid); | |
| 463 | const before = await board(); | |
| 464 | const landed = between(before, "landed", "decided"); | |
| 465 | expect(landed).toContain("Faster notes"); | |
| 466 | expect(landed).toMatch(/data-word="waiting"\s+data-variant="secondary"/); | |
| 467 | expect(landed).not.toContain('data-word="shipped"'); | |
| 468 | // The ledger wrote *shipped* at the merge; the board does not repeat it. | |
| 469 | const decided = between(before, "decided", "today"); | |
| 470 | expect(decided).toContain("ship or show"); | |
| 471 | expect(decided).toContain('data-word="waiting"'); | |
| 472 | expect(decided).not.toContain(">shipped<"); | |
| 473 | expect(decided).not.toContain("data-outcome"); | |
| 474 | const working = between(before, "working", "landed"); | |
| 475 | expect(working).toMatch( | |
| 476 | /data-state="working"\s+data-variant="accent"/, | |
| 477 | ); | |
| 478 | expect(working).toContain("on what you said"); | |
| 479 | // The regions themselves are as they were. | |
| 480 | expect(before).toMatch(/id="working"\s+data-live="run\.\*"/); | |
| 481 | expect(before).toMatch( | |
| 482 | /id="landed"\s+data-live="pull\.merged,run\.finished"/, | |
| 483 | ); | |
| 484 | expect(before).toMatch(/id="decided"\s+data-live="run\.\*,pull\.\*"/); | |
| 485 | expect(before).toMatch(/id="today"\s+data-live="run\.\*,pull\.merged"/); | |
| 486 | ||
| 487 | // Production caught up with the merge: shipped, in both lists. | |
| 488 | serving(record.id, pull.mergedOid!); | |
| 489 | const after = await board(); | |
| 490 | expect(between(after, "landed", "decided")).toMatch( | |
| 491 | /data-word="shipped"\s+data-variant="success"/, | |
| 492 | ); | |
| 493 | expect(between(after, "decided", "today")).toContain( | |
| 494 | 'data-word="shipped"', | |
| 495 | ); | |
| 496 | }); | |
| 497 | }); | |
| 498 | ||
| 331 | 499 | describe("the board's forge strip", () => { |
| 332 | 500 | let dataDir: string; |
| 333 | 501 | let app: App; |
new above
offline