Public: anyone can read this; the crew can change it.
In the studio, /apps is the shelf, not dev's table #102
scout/forge:scout/71-in-the-studio-apps-is-the-shelf-not-dev → main 2 commits fork
4 files
changed +186
−17
docs/STUDIO.md +15
| @@ -240,6 +240,21 @@ the toggle. A forge with no public apps yet — | ||
| 240 | 240 | most people's first visit — falls back to that same dev landing rather |
| 241 | 241 | than showing an empty shelf. |
| 242 | 242 | |
| 243 | ## Every app | |
| 244 | ||
| 245 | `/apps` in the studio, and the top bar's **Apps**, are the same shelf the | |
| 246 | home's *Your apps* wears — every app the viewer can land, one row each | |
| 247 | (`appShelf`, `src/web/studio/home.ts`), never a second copy of that | |
| 248 | markup. A count and a live/all filter sit above it, `?filter=live` a link | |
| 249 | rather than a form, so a filtered view has its own address; **New app** is | |
| 250 | on it, same as ever. A private app the viewer cannot read is left off, the | |
| 251 | same visibility check (`listReposVisibleTo`) as every other listing, and an | |
| 252 | app they can read but not write shows what a stranger sees, not the | |
| 253 | owner's numbers — `appShelf`'s own rule, asked once. `?mode=dev` is dev's | |
| 254 | table, unchanged, `New app` and all; a signed-out visitor in studio mode | |
| 255 | gets the public shelf and nothing more, `appsList`'s own authorization, | |
| 256 | unchanged from dev's. | |
| 257 | ||
| 243 | 258 | ## The board |
| 244 | 259 | |
| 245 | 260 | `/board` is the home's _Happening now_ as a wall for a second monitor |
src/web/pages/apps.ts +60 −1
| @@ -67,6 +67,7 @@ import { | ||
| 67 | 67 | icon, |
| 68 | 68 | listCard, |
| 69 | 69 | row, |
| 70 | seg, | |
| 70 | 71 | selectField, |
| 71 | 72 | sha, |
| 72 | 73 | terminalLine, |
| @@ -75,6 +76,7 @@ import { | ||
| 75 | 76 | field as formField, |
| 76 | 77 | } from "../ui.ts"; |
| 77 | 78 | import { actorsFor, issuesFor, runRow } from "./runs.ts"; |
| 79 | import { appShelf, appsOf } from "../studio/home.ts"; | |
| 78 | 80 | |
| 79 | 81 | // ---- what the viewer can see ---- |
| 80 | 82 | |
| @@ -186,8 +188,65 @@ export function appsCard(ctx: Ctx): Html { | ||
| 186 | 188 | }); |
| 187 | 189 | } |
| 188 | 190 | |
| 191 | /** | |
| 192 | * GET /apps in the studio: every app the viewer can land, as the same shelf | |
| 193 | * the home's *Your apps* wears (`appShelf`, `web/studio/home.ts`) — never a second | |
| 194 | * copy of that row. A count, and a live/all filter as a link (`?filter=`, | |
| 195 | * never a form, so a filtered view has its own address); **New app** stays | |
| 196 | * on it. A reader who cannot write an app still sees its row, in the | |
| 197 | * stranger's own words — `appShelf` already draws it that way. | |
| 198 | */ | |
| 199 | async function studioAppsList(ctx: Ctx): Promise<Response> { | |
| 200 | const { repos: appRepos, records } = appsOf(ctx, ctx.auth.user); | |
| 201 | const { entries } = await appShelf(ctx, appRepos, records); | |
| 202 | const liveOnly = ctx.url.searchParams.get("filter") === "live"; | |
| 203 | const liveCount = entries.filter((e) => e.live).length; | |
| 204 | const shown = liveOnly ? entries.filter((e) => e.live) : entries; | |
| 205 | const create = ctx.auth.user | |
| 206 | ? btn("New app", { | |
| 207 | href: "/apps/new", | |
| 208 | variant: "primary", | |
| 209 | size: "sm", | |
| 210 | icon: "plus", | |
| 211 | shortcut: "c", | |
| 212 | }) | |
| 213 | : btn("Sign in to make one", { href: "/signin", size: "sm" }); | |
| 214 | const filterBar = | |
| 215 | entries.length === 0 | |
| 216 | ? null | |
| 217 | : html`<div class="filters mb"> | |
| 218 | ${seg([ | |
| 219 | { label: `All ${entries.length}`, href: "/apps", current: !liveOnly }, | |
| 220 | { | |
| 221 | label: `Live ${liveCount}`, | |
| 222 | href: "/apps?filter=live", | |
| 223 | current: liveOnly, | |
| 224 | }, | |
| 225 | ])} | |
| 226 | </div>`; | |
| 227 | const body = html`${pageHead("Apps", { | |
| 228 | actions: create, | |
| 229 | sub: "Repositories that run. Production follows the default branch; every open pull request gets a preview.", | |
| 230 | })} | |
| 231 | ${filterBar} | |
| 232 | ${shown.length === 0 | |
| 233 | ? empty({ | |
| 234 | icon: "rocket", | |
| 235 | title: liveOnly ? "Nothing live right now" : "Nothing runs here yet", | |
| 236 | note: liveOnly | |
| 237 | ? "No app the crew is showing you is up. All shows the rest." | |
| 238 | : "A new app is a repository with a small working app in it, served at its own hostname a few seconds later.", | |
| 239 | action: liveOnly | |
| 240 | ? btn("All apps", { href: "/apps", size: "sm" }) | |
| 241 | : create, | |
| 242 | }) | |
| 243 | : listCard(shown.map((e) => e.row))}`; | |
| 244 | return page({ ctx, title: "Apps", body }); | |
| 245 | } | |
| 246 | ||
| 189 | 247 | // GET /apps |
| 190 | export function appsList(ctx: Ctx): Response { | |
| 248 | export async function appsList(ctx: Ctx): Promise<Response> { | |
| 249 | if (ctx.mode === "studio") return studioAppsList(ctx); | |
| 191 | 250 | const entries = appsForViewer(ctx); |
| 192 | 251 | const create = ctx.auth.user |
| 193 | 252 | ? btn("New app", { |
src/web/studio/home.ts +55 −16
| @@ -8,15 +8,15 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import { appsRuntime } from "../../apps/runtime.ts"; |
| 11 | import { appsForRepos } from "../../core/apps.ts"; | |
| 12 | import { canSeeOwnerFacts, listReposVisibleTo } from "../../core/repos.ts"; | |
| 11 | import { appsForRepos, type AppRecord } from "../../core/apps.ts"; | |
| 12 | import { canSeeOwnerFacts, listReposVisibleTo, type Repo } from "../../core/repos.ts"; | |
| 13 | 13 | import { latestAgentRunsForRepos, listActiveRuns } from "../../core/runs.ts"; |
| 14 | 14 | import { getUsersByIds, type User } from "../../core/users.ts"; |
| 15 | 15 | import { repoDir } from "../../git/repos.ts"; |
| 16 | 16 | import type { Ctx } from "../../http/context.ts"; |
| 17 | 17 | import { repoBase } from "../chrome.ts"; |
| 18 | 18 | import { asksJs, liveRegionsJs } from "../client.ts"; |
| 19 | import { html, when } from "../html.ts"; | |
| 19 | import { html, when, type Html } from "../html.ts"; | |
| 20 | 20 | import { page } from "../layout.ts"; |
| 21 | 21 | import { liveClientJs } from "../live.ts"; |
| 22 | 22 | import { |
| @@ -32,31 +32,50 @@ import { | ||
| 32 | 32 | type Tone, |
| 33 | 33 | } from "../ui.ts"; |
| 34 | 34 | import { onYouCard } from "../pages/site.ts"; |
| 35 | import { asksPanel, decisionsFor } from "./asks.ts"; | |
| 35 | import { asksPanel, decisionsFor, type Decision } from "./asks.ts"; | |
| 36 | 36 | import { withLikely } from "./leans.ts"; |
| 37 | 37 | import { stopForm } from "./run.ts"; |
| 38 | 38 | import { studioCss } from "./style.ts"; |
| 39 | 39 | import { runWord } from "./words.ts"; |
| 40 | 40 | |
| 41 | /** One app in the shelf: the row it draws, and whether production is live | |
| 42 | * — the fact a list filters on without re-parsing the row's own markup. */ | |
| 43 | export interface AppShelfEntry { | |
| 44 | readonly repo: Repo; | |
| 45 | readonly live: boolean; | |
| 46 | readonly row: Html; | |
| 47 | } | |
| 48 | ||
| 41 | 49 | /** |
| 42 | * The home in the studio: what asks you first, then every app as one row | |
| 43 | * that carries a real signal — live or not, what the crew last did there, | |
| 44 | * how many things wait on you — and beside it what is happening right now | |
| 45 | * across all of them, and what a person put on you. Built from the same | |
| 46 | * rows and cards as the rest of the forge, so it reads as the forge. | |
| 50 | * Every app the viewer may see, as one row each — live or not, what the | |
| 51 | * crew last did there, how many things ask them, and the way in — plus the | |
| 52 | * decisions behind those asks. This is the one place that row is drawn: the | |
| 53 | * home's *Your apps* and the studio's `/apps` shelf both call it, never a | |
| 54 | * second copy of the markup. Two grouped reads (the newest run of every | |
| 55 | * app, who ran them) carry the whole shelf, so it never gets slower as the | |
| 56 | * forge grows apps. | |
| 47 | 57 | */ |
| 48 | export async function studioHome(ctx: Ctx, user: User): Promise<Response> { | |
| 58 | export async function appShelf( | |
| 59 | ctx: Ctx, | |
| 60 | appRepos: readonly Repo[], | |
| 61 | records: ReadonlyMap<string, AppRecord>, | |
| 62 | ): Promise<{ | |
| 63 | entries: AppShelfEntry[]; | |
| 64 | decisions: Decision[]; | |
| 65 | ownerFacts: ReadonlySet<string>; | |
| 66 | }> { | |
| 49 | 67 | const db = ctx.app.db; |
| 50 | const { repos: appRepos, records } = appsOf(ctx, user); | |
| 51 | 68 | const runtime = appsRuntime(ctx.app); |
| 52 | 69 | // A public app you can only read appears here too, but who is on its |
| 53 | 70 | // crew is its owner's fact, not yours to see — same predicate as the |
| 54 | 71 | // app's own page. |
| 55 | 72 | const ownerFacts = new Set( |
| 56 | appRepos.filter((r) => canSeeOwnerFacts(db, r, user)).map((r) => r.id), | |
| 73 | appRepos | |
| 74 | .filter((r) => canSeeOwnerFacts(db, r, ctx.auth.user)) | |
| 75 | .map((r) => r.id), | |
| 57 | 76 | ); |
| 58 | 77 | // One read for the newest run of every app, one for who ran them: the |
| 59 | // home must not get slower as the apps grow. | |
| 78 | // shelf must not get slower as the apps grow. | |
| 60 | 79 | const latestRuns = latestAgentRunsForRepos( |
| 61 | 80 | db, |
| 62 | 81 | appRepos.map((r) => r.id), |
| @@ -72,7 +91,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> { | ||
| 72 | 91 | for (const d of decisions) |
| 73 | 92 | asksByRepo.set(d.repo.id, (asksByRepo.get(d.repo.id) ?? 0) + 1); |
| 74 | 93 | |
| 75 | const appRows = await Promise.all(appRepos.map(async (repo) => { | |
| 94 | const entries = await Promise.all(appRepos.map(async (repo) => { | |
| 76 | 95 | const record = records.get(repo.id)!; |
| 77 | 96 | const envs = runtime === undefined ? [] : runtime.status(record); |
| 78 | 97 | const production = envs.find((e) => e.env === "production"); |
| @@ -111,7 +130,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> { | ||
| 111 | 130 | ${word.word === "working" |
| 112 | 131 | ? html`· now` |
| 113 | 132 | : html`· ${time(latest.finishedAt ?? latest.createdAt)}`}`; |
| 114 | return row({ | |
| 133 | const row_ = row({ | |
| 115 | 134 | href: repoBase(repo), |
| 116 | 135 | nav: true, |
| 117 | 136 | lead: dot(tone), |
| @@ -129,7 +148,27 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> { | ||
| 129 | 148 | : state}</span |
| 130 | 149 | >`, |
| 131 | 150 | }); |
| 151 | return { repo, live: state === "running", row: row_ }; | |
| 132 | 152 | })); |
| 153 | return { entries, decisions, ownerFacts }; | |
| 154 | } | |
| 155 | ||
| 156 | /** | |
| 157 | * The home in the studio: what asks you first, then every app as one row | |
| 158 | * that carries a real signal — live or not, what the crew last did there, | |
| 159 | * how many things wait on you — and beside it what is happening right now | |
| 160 | * across all of them, and what a person put on you. Built from the same | |
| 161 | * rows and cards as the rest of the forge, so it reads as the forge. | |
| 162 | */ | |
| 163 | export async function studioHome(ctx: Ctx, user: User): Promise<Response> { | |
| 164 | const db = ctx.app.db; | |
| 165 | const { repos: appRepos, records } = appsOf(ctx, user); | |
| 166 | const { entries, decisions, ownerFacts } = await appShelf( | |
| 167 | ctx, | |
| 168 | appRepos, | |
| 169 | records, | |
| 170 | ); | |
| 171 | const appRows = entries.map((e) => e.row); | |
| 133 | 172 | |
| 134 | 173 | const apps = |
| 135 | 174 | appRows.length === 0 |
| @@ -237,7 +276,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> { | ||
| 237 | 276 | } |
| 238 | 277 | |
| 239 | 278 | /** The apps a person can see, as repositories, with their records. */ |
| 240 | export function appsOf(ctx: Ctx, user: User) { | |
| 279 | export function appsOf(ctx: Ctx, user: User | undefined) { | |
| 241 | 280 | const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200 }); |
| 242 | 281 | const records = appsForRepos( |
| 243 | 282 | ctx.app.db, |
test/studio.test.ts +56
| @@ -186,6 +186,62 @@ describe("the studio", () => { | ||
| 186 | 186 | expect(bad.headers.get("set-cookie")).toContain("forge_mode=;"); |
| 187 | 187 | }); |
| 188 | 188 | |
| 189 | test("/apps in studio mode is the same shelf the home's Your apps wears: a count, a live filter as a link, New app, and no dev table markup; ?mode=dev is today's table", async () => { | |
| 190 | const bob = await createUser(app.db, { | |
| 191 | username: "bob", | |
| 192 | email: "[email protected]", | |
| 193 | password: "a-good-passphrase", | |
| 194 | }); | |
| 195 | if (!bob.ok) throw new Error(String(bob.error)); | |
| 196 | const bobCookie = ( | |
| 197 | ( | |
| 198 | await fetch(`${base}/signin`, { | |
| 199 | method: "POST", | |
| 200 | body: new URLSearchParams({ | |
| 201 | username: "bob", | |
| 202 | password: "a-good-passphrase", | |
| 203 | }), | |
| 204 | redirect: "manual", | |
| 205 | }) | |
| 206 | ).headers.get("set-cookie") ?? "" | |
| 207 | ).split(";")[0]!; | |
| 208 | ||
| 209 | const studio = await (await get("/apps")).text(); | |
| 210 | expect(studio).toContain(">Apps<"); | |
| 211 | expect(studio).toContain("notes"); | |
| 212 | expect(studio).toContain('href="/alice/notes"'); | |
| 213 | expect(studio).toContain("New app"); | |
| 214 | expect(studio).toContain("All 1"); | |
| 215 | expect(studio).toContain("?filter=live"); | |
| 216 | // Not the dev table: no "/…/app" row link, no visibility badge. | |
| 217 | expect(studio).not.toContain('href="/alice/notes/app"'); | |
| 218 | expect(studio).not.toContain(">Private<"); | |
| 219 | ||
| 220 | // Bob cannot read alice's private "notes" app: it is off his shelf. | |
| 221 | const bobsView = await ( | |
| 222 | await get("/apps", { cookie: `${bobCookie}; forge_mode=studio` }) | |
| 223 | ).text(); | |
| 224 | expect(bobsView).not.toContain("notes"); | |
| 225 | expect(bobsView).toContain("Nothing runs here yet"); | |
| 226 | ||
| 227 | const dev = await ( | |
| 228 | await get("/apps", { cookie: `${cookie}; forge_mode=dev` }) | |
| 229 | ).text(); | |
| 230 | expect(dev).toContain('href="/alice/notes/app"'); | |
| 231 | expect(dev).toContain(">Private<"); | |
| 232 | expect(dev).not.toContain("?filter=live"); | |
| 233 | ||
| 234 | // Signed out in studio mode: the public shelf and nothing else. | |
| 235 | const anon = await ( | |
| 236 | await fetch(`${base}/apps`, { | |
| 237 | headers: { cookie: "forge_mode=studio" }, | |
| 238 | redirect: "manual", | |
| 239 | }) | |
| 240 | ).text(); | |
| 241 | expect(anon).not.toContain("notes"); | |
| 242 | expect(anon).toContain("Sign in to make one"); | |
| 243 | }); | |
| 244 | ||
| 189 | 245 | test("an app's home is the app in the studio, and the code in dev", async () => { |
| 190 | 246 | const studio = await (await get("/alice/notes")).text(); |
| 191 | 247 | expect(studio).toContain("Tell the crew"); |
new above
offline