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

In the studio, /apps is the shelf, not dev's table #102

Closed opened this
Closed without merging

scout/forge:scout/71-in-the-studio-apps-is-the-shelf-not-dev → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +186 −17
docs/STUDIO.md +15
@@ -240,6 +240,21 @@ the toggle. A forge with no public apps yet —
240240 most people's first visit — falls back to that same dev landing rather
241241 than showing an empty shelf.
242242
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
243258 ## The board
244259
245260 `/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 {
6767 icon,
6868 listCard,
6969 row,
70 seg,
7071 selectField,
7172 sha,
7273 terminalLine,
@@ -75,6 +76,7 @@ import {
7576 field as formField,
7677 } from "../ui.ts";
7778 import { actorsFor, issuesFor, runRow } from "./runs.ts";
79 import { appShelf, appsOf } from "../studio/home.ts";
7880
7981 // ---- what the viewer can see ----
8082
@@ -186,8 +188,65 @@ export function appsCard(ctx: Ctx): Html {
186188 });
187189 }
188190
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
189247 // 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);
191250 const entries = appsForViewer(ctx);
192251 const create = ctx.auth.user
193252 ? btn("New app", {
src/web/studio/home.ts +55 −16
@@ -8,15 +8,15 @@
88 */
99
1010 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";
1313 import { latestAgentRunsForRepos, listActiveRuns } from "../../core/runs.ts";
1414 import { getUsersByIds, type User } from "../../core/users.ts";
1515 import { repoDir } from "../../git/repos.ts";
1616 import type { Ctx } from "../../http/context.ts";
1717 import { repoBase } from "../chrome.ts";
1818 import { asksJs, liveRegionsJs } from "../client.ts";
19 import { html, when } from "../html.ts";
19 import { html, when, type Html } from "../html.ts";
2020 import { page } from "../layout.ts";
2121 import { liveClientJs } from "../live.ts";
2222 import {
@@ -32,31 +32,50 @@ import {
3232 type Tone,
3333 } from "../ui.ts";
3434 import { onYouCard } from "../pages/site.ts";
35 import { asksPanel, decisionsFor } from "./asks.ts";
35 import { asksPanel, decisionsFor, type Decision } from "./asks.ts";
3636 import { withLikely } from "./leans.ts";
3737 import { stopForm } from "./run.ts";
3838 import { studioCss } from "./style.ts";
3939 import { runWord } from "./words.ts";
4040
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
4149 /**
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.
4757 */
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 }> {
4967 const db = ctx.app.db;
50 const { repos: appRepos, records } = appsOf(ctx, user);
5168 const runtime = appsRuntime(ctx.app);
5269 // A public app you can only read appears here too, but who is on its
5370 // crew is its owner's fact, not yours to see — same predicate as the
5471 // app's own page.
5572 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),
5776 );
5877 // 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.
6079 const latestRuns = latestAgentRunsForRepos(
6180 db,
6281 appRepos.map((r) => r.id),
@@ -72,7 +91,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> {
7291 for (const d of decisions)
7392 asksByRepo.set(d.repo.id, (asksByRepo.get(d.repo.id) ?? 0) + 1);
7493
75 const appRows = await Promise.all(appRepos.map(async (repo) => {
94 const entries = await Promise.all(appRepos.map(async (repo) => {
7695 const record = records.get(repo.id)!;
7796 const envs = runtime === undefined ? [] : runtime.status(record);
7897 const production = envs.find((e) => e.env === "production");
@@ -111,7 +130,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> {
111130 ${word.word === "working"
112131 ? html`· now`
113132 : html`· ${time(latest.finishedAt ?? latest.createdAt)}`}`;
114 return row({
133 const row_ = row({
115134 href: repoBase(repo),
116135 nav: true,
117136 lead: dot(tone),
@@ -129,7 +148,27 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> {
129148 : state}</span
130149 >`,
131150 });
151 return { repo, live: state === "running", row: row_ };
132152 }));
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);
133172
134173 const apps =
135174 appRows.length === 0
@@ -237,7 +276,7 @@ export async function studioHome(ctx: Ctx, user: User): Promise<Response> {
237276 }
238277
239278 /** 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) {
241280 const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200 });
242281 const records = appsForRepos(
243282 ctx.app.db,
test/studio.test.ts +56
@@ -186,6 +186,62 @@ describe("the studio", () => {
186186 expect(bad.headers.get("set-cookie")).toContain("forge_mode=;");
187187 });
188188
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
189245 test("an app's home is the app in the studio, and the code in dev", async () => {
190246 const studio = await (await get("/alice/notes")).text();
191247 expect(studio).toContain("Tell the crew");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs