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

Home is the feed: signed in, `/` is a composer above one timeline, and your apps move one step away #676

Closed opened this in answer to
Closed without merging

scout/forge:scout/599-home-is-the-feed-signed-in-is-a-composer → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
13 files changed +297 −146
docs/FEED.md +16 −12
@@ -5,7 +5,7 @@ one sentence saying why it is there.
55
66 `GET /api/v1/feed?limit=&cursor=` → `{ items, next_cursor }`, for the signed-in
77 viewer only. An item is `{ id, kind, app, actor, at, link, reason, score }`;
8 `kind` is `run | ask | pull | decision | map | cost`. Strings are plain text,
8 `kind` is `run | ask | pull | decision | map | cost | tell | reply | look`; `what` is the post's own words and `reason` is why it is there. Strings are plain text,
99 not HTML: whatever renders them escapes them.
1010
1111 `POST /api/v1/feed/interactions` `{ item, kind, app? }` records what the viewer
@@ -16,10 +16,10 @@ Anything the viewer cannot read is a 404.
1616
1717 ## Where items come from (`src/feed/items.ts`)
1818
19 - Events through `listEventsVisibleTo` then `audienceFilter`: `run.finished`
19 - Events through `listEventsVisibleTo` then `audienceFilter`: `issue.opened` (a `tell`, titled), `issue.commented|pull.commented` (a `reply`, under its thing), `run.finished`
2020 (a deploy, check or agent run; a costly agent run is a `cost` item, shown
2121 only to those who may see owner facts), `pull.opened|merged|reviewed`,
22 `look.taken` (new: a full set of preview pictures), `app.serving`,
22 `look.taken` (a `look`: a full set of preview pictures), `app.serving`,
2323 `issue.blocked|unblocked` (map changes).
2424 - Pending asks (`askLinesFor`), only for what the viewer may decide.
2525 - Decision-ledger outcomes, only for repositories the viewer may write.
@@ -42,16 +42,20 @@ muted away. Dismissing hides one item. The cursor is `score|id` of the last
4242 item; the feed is recomputed per request and resumes by id (or by score if
4343 that item has gone).
4444
45 ## The page (`src/web/studio/feed.ts`)
45 ## The page (`src/web/studio/feed.ts`, `home.ts`)
4646
47 `/` for a signed-in viewer renders the first 20 items as cards above the shelf,
48 server-side, and `/live/feed` answers the same region for the live-regions
49 client (etag, 304). A card: the reason as a link into the thing, Steer (run
50 cards, posts to the run's `steer`) or Tell the crew (everything else, posts to
51 the app's `tell`), Dismiss and Mute app (the interactions API, same-origin).
52 Keys: `j`/`k`/Enter are the shell's, `x` dismisses the focused card.
53 Not yet: the `choose` deck card (nothing in the feed produces one), stop from
54 a card, and paging past the first 20.
47 `/` for a signed-in viewer is one timeline: a composer (an app's tell, sent
48 through the outbox to `POST /api/v1/feed/tells`), then the first 20 items as
49 posts, server-side, with the actor's name and face. A post's words link in one
50 tap to its thing (issue, change, run, look). `/live/feed` answers the same
51 region for the live-regions client (etag, 304). A post also has Steer (runs) or
52 Tell the crew, Dismiss and Mute app. Keys: `j`/`k`/Enter are the shell's, `x`
53 dismisses the focused post. "Your apps" is a narrow column on a desk and a tab
54 on a phone, linking to `/apps`, where the shelf rows and the day's cost line
55 now live. The MCP tool `feed { limit, cursor }` returns the same
56 `{ items, next_cursor }`.
57 Not yet: the `choose` deck card, stop from a card, and paging past the first 20
58 on the page.
5559
5660 ## Offline (`src/web/sw.ts`, `outbox.ts`)
5761
src/feed/items.ts +32 −4
@@ -10,6 +10,7 @@ import type { Database } from "bun:sqlite";
1010 import { listDecidedIn } from "../core/decisions.ts";
1111 import { audienceFilter } from "../core/event_audience.ts";
1212 import { listEventsVisibleTo, type ForgeEvent } from "../core/events.ts";
13 import { getIssue } from "../core/issues.ts";
1314 import { getPull, toldBy } from "../core/pulls.ts";
1415 import {
1516 canSeeOwnerFacts,
@@ -20,7 +21,16 @@ import {
2021 import { getUserById, type User } from "../core/users.ts";
2122 import { askLinesFor } from "../web/studio/asks.ts";
2223
23 export type FeedKind = "run" | "ask" | "pull" | "decision" | "map" | "cost";
24 export type FeedKind =
25 | "run"
26 | "ask"
27 | "pull"
28 | "decision"
29 | "map"
30 | "cost"
31 | "tell"
32 | "reply"
33 | "look";
2434
2535 /** What a candidate is, before it is ranked and worded. */
2636 export interface Candidate {
@@ -186,13 +196,31 @@ function fromEvent(
186196 case "pull.reviewed":
187197 return { ...common, kind: "pull", link: change, what: `a change was reviewed${title ? `: ${clip(title)}` : ""}` };
188198 case "look.taken":
199 return { ...common, kind: "look", link: base(repo), what: "a new preview picture is ready" };
189200 case "app.serving":
201 return { ...common, kind: "pull", link: base(repo), what: "a new version is serving" };
202 case "issue.opened": {
203 if (number === undefined) return undefined;
204 const title = getIssue(db, repo.id, number)?.title ?? "";
190205 return {
191206 ...common,
192 kind: "pull",
193 link: base(repo),
194 what: e.kind === "look.taken" ? "a new preview picture is ready" : "a new version is serving",
207 kind: "tell",
208 link: `${base(repo)}/issues/${number}`,
209 what: title === "" ? `#${number} was told` : clip(title),
195210 };
211 }
212 case "issue.commented":
213 case "pull.commented": {
214 if (number === undefined) return undefined;
215 const noun = e.kind === "issue.commented" ? "issues" : "changes";
216 const said = typeof p["body"] === "string" ? p["body"].trim() : "";
217 return {
218 ...common,
219 kind: "reply",
220 link: `${base(repo)}/${noun}/${number}`,
221 what: said === "" ? `a reply on #${number}` : `replied on #${number}: ${clip(said)}`,
222 };
223 }
196224 case "issue.blocked":
197225 case "issue.unblocked":
198226 return {
src/feed/rank.ts +3
@@ -17,6 +17,8 @@ export interface FeedItem {
1717 readonly actor: string | null;
1818 readonly at: string;
1919 readonly link: string;
20 /** What happened, in the post's own words. */
21 readonly what: string;
2022 /** One sentence: why this, and why here. */
2123 readonly reason: string;
2224 readonly score: number;
@@ -135,6 +137,7 @@ export function rank(
135137 actor: s!.c.actor,
136138 at: s!.c.at,
137139 link: s!.c.link,
140 what: s!.c.what,
138141 reason: s!.reason,
139142 score: Math.round(bestScore * 1e6) / 1e6,
140143 });
src/http/mcp.ts +26
@@ -35,6 +35,7 @@ import {
3535 USAGE_DAYS_MAX,
3636 } from "../actions/usage.ts";
3737 import { ITEM_ID } from "../core/interactions.ts";
38 import { FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX, parseCursor, readFeed } from "../feed/feed.ts";
3839 import { share } from "../feed/share.ts";
3940 import { parseTargets } from "./feed.ts";
4041 import { appsRuntime } from "../apps/runtime.ts";
@@ -187,6 +188,31 @@ const TOOLS: readonly Tool[] = [
187188 });
188189 },
189190 },
191 {
192 name: "feed",
193 description:
194 "The home timeline, as the signed-in person sees it: tells, replies, runs, changes and looks, ranked, each with the sentence for why it is there and a link to its thing. Pass the cursor from one answer to get the next page.",
195 inputSchema: {
196 type: "object",
197 properties: {
198 limit: { type: "integer", minimum: 1, maximum: FEED_LIMIT_MAX },
199 cursor: { type: "string", description: "next_cursor from the last answer" },
200 },
201 },
202 writes: false,
203 run(ctx, user, args) {
204 const limit = args["limit"] === undefined ? FEED_LIMIT_DEFAULT : Number(args["limit"]);
205 if (!Number.isInteger(limit) || limit < 1 || limit > FEED_LIMIT_MAX)
206 return bad("invalid", `limit is 1 to ${FEED_LIMIT_MAX}`);
207 const raw = args["cursor"];
208 const cursor = raw === undefined ? undefined : parseCursor(str(raw));
209 if (raw !== undefined && cursor === undefined)
210 return bad("invalid", "that cursor was not issued here");
211 return good(
212 readFeed(ctx.app.db, user, { limit, ...(cursor === undefined ? {} : { cursor }) }),
213 );
214 },
215 },
190216 {
191217 name: "share",
192218 description:
src/web/pages/apps.ts +2 −1
@@ -48,6 +48,7 @@ import {
4848 import { field, readForm } from "../form.ts";
4949 import { html, when, type Html } from "../html.ts";
5050 import { flashTo, page, redirect } from "../layout.ts";
51 import { costLine } from "../studio/cost_line.ts";
5152 import { shelfRows } from "../studio/shelf.ts";
5253 import {
5354 badge,
@@ -261,7 +262,7 @@ async function studioAppsList(ctx: Ctx): Promise<Response> {
261262 shown.map((e) => e.repo),
262263 );
263264 const body = html`${pageHead("Apps", { actions: create })}
264 ${filters}
265 ${ctx.auth.user ? costLine(ctx, ctx.auth.user) : null} ${filters}
265266 ${shown.length === 0
266267 ? empty({
267268 icon: "rocket",
src/web/pages/site.ts +1 −1
@@ -582,7 +582,7 @@ export async function home(ctx: Ctx): Promise<Response> {
582582 // the default: apps, the crew, what asks you; `?mode=dev` on the home is
583583 // the escape hatch to the repositories, resolved once for `ctx.mode`.
584584 if (user === undefined) return studioDoor(ctx);
585 if (ctx.mode === "studio") return await studioHome(ctx, user);
585 if (ctx.mode === "studio") return studioHome(ctx, user);
586586 return page({
587587 ctx,
588588 title: "forge",
src/web/studio/cost_line.ts added +29
@@ -0,0 +1,29 @@
1 /**
2 * The owner's first question, on the page of apps: what the crew cost today
3 * across the apps they can write, and how many are paused at their ceiling.
4 * One bounded read each (`spentTodayForRepos`, `crewForRepos`), never a query
5 * per app. Every app counted is one the viewer can write, so the money is
6 * only ever the owner's own.
7 */
8
9 import { crewForRepos } from "../../core/agents.ts";
10 import type { User } from "../../core/users.ts";
11 import { isPausedAtCeiling, spentTodayForRepos } from "../../crew/autonomy.ts";
12 import type { Ctx } from "../../http/context.ts";
13 import { html, type Html } from "../html.ts";
14 import { writableAppsOf } from "./asks.ts";
15
16 export function costLine(ctx: Ctx, user: User): Html | null {
17 const { repos } = writableAppsOf(ctx, user);
18 if (repos.length === 0) return null;
19 const ids = repos.map((r) => r.id);
20 const spentToday = spentTodayForRepos(ctx.app.db, ids);
21 const crew = crewForRepos(ctx.app.db, ids);
22 const spentUsd = repos.reduce((sum, r) => sum + (spentToday.get(r.id) ?? 0), 0);
23 const paused = repos.filter((r) => isPausedAtCeiling(r, crew, spentToday)).length;
24 const noun = `app${repos.length === 1 ? "" : "s"}`;
25 const sentence = `$${spentUsd.toFixed(2)} spent today across ${repos.length} ${noun} you can write`;
26 return html`<p class="small muted studio-cost">
27 ${sentence} · ${paused} paused at <a href="/map">their ceiling</a>
28 </p>`;
29 }
src/web/studio/feed.ts +43 −3
@@ -14,11 +14,12 @@ import type { FeedItem } from "../../feed/rank.ts";
1414 import { html, type Html } from "../html.ts";
1515 import { fragment } from "../layout.ts";
1616 import { outboxJs } from "../outbox.ts";
17 import { btn, empty } from "../ui.ts";
17 import { avatar, btn, empty } from "../ui.ts";
18 import { writableAppsOf } from "./asks.ts";
1819
1920 /** Events that can change what the feed says. */
2021 export const FEED_LIVE =
21 "run.finished,pull.opened,pull.merged,pull.reviewed,pull.closed,look.taken,app.serving,issue.blocked,issue.unblocked,decision.*";
22 "run.finished,issue.opened,issue.commented,pull.commented,pull.opened,pull.merged,pull.reviewed,pull.closed,look.taken,app.serving,issue.blocked,issue.unblocked,decision.*";
2223
2324 export const FEED_FIRST_PAGE = 20;
2425
@@ -31,6 +32,9 @@ const KIND_LABEL: Record<FeedItem["kind"], string> = {
3132 decision: "Decision",
3233 map: "Map",
3334 cost: "Cost",
35 tell: "Told",
36 reply: "Reply",
37 look: "Look",
3438 };
3539
3640 /** One card. A run's card steers the run; every card can tell its app. */
@@ -46,13 +50,16 @@ export function feedCard(item: FeedItem): Html {
4650 data-kind="${item.kind}"
4751 >
4852 <div class="fcard-head">
53 ${avatar(item.actor ?? item.app)}
54 <strong class="fcard-who">${item.actor ?? item.app}</strong>
4955 <span class="badge">${KIND_LABEL[item.kind]}</span>
5056 <span class="fcard-app muted small">${item.app}</span>
5157 <span class="spacer"></span>
5258 <button type="button" class="btn btn-sm btn-ghost" data-feed="dismissed" title="Dismiss (x)">Dismiss</button>
5359 <button type="button" class="btn btn-sm btn-ghost" data-feed="muted" title="Mute ${item.app}">Mute app</button>
5460 </div>
55 <p class="fcard-reason"><a href="${item.link}" data-feed-open>${item.reason}</a></p>
61 <p class="fcard-reason"><a href="${item.link}" data-feed-open>${item.what}</a></p>
62 <p class="fcard-why small muted">${item.reason}</p>
5663 <details class="fcard-say">
5764 <summary class="small">${target ? "Steer" : "Tell the crew"}</summary>
5865 <form method="post" action="${target ?? `/${item.app}/tell`}" class="fcard-form">
@@ -63,6 +70,27 @@ export function feedCard(item: FeedItem): Html {
6370 </article>`;
6471 }
6572
73 /**
74 * The composer: say it to an app's crew, which opens a tell. The one primary
75 * action on the home. With no app to say it to, the way to make one instead.
76 * The script sends it through the outbox to `POST /api/v1/feed/tells`.
77 */
78 export function composer(ctx: Ctx, user: User): Html {
79 const { repos } = writableAppsOf(ctx, user);
80 if (repos.length === 0) return html``;
81 const slug = (r: { ownerName: string; name: string }) => `${r.ownerName}/${r.name}`;
82 return html`<form id="composer" class="composer" method="post" action="/${slug(repos[0]!)}/tell">
83 <textarea name="text" rows="2" maxlength="2000" required placeholder="Tell the crew what should change" aria-label="Tell the crew"></textarea>
84 <div class="composer-bar">
85 ${repos.length === 1
86 ? html`<input type="hidden" name="app" value="${slug(repos[0]!)}" /><span class="muted small">${slug(repos[0]!)}</span>`
87 : html`<select name="app" aria-label="App">${repos.map((r) => html`<option value="${slug(r)}">${slug(r)}</option>`)}</select>`}
88 <span class="spacer"></span>
89 ${btn("Post", { variant: "primary" })}
90 </div>
91 </form>`;
92 }
93
6694 /**
6795 * One line above the feed, empty unless there is something to say: the feed
6896 * on screen is old (the service worker served it with no network), or acts
@@ -180,6 +208,18 @@ ${outboxJs}
180208 var d = form.closest('details');
181209 if (d) d.open = false;
182210 });
211 // The composer is a tell: kept and sent like the card's, the box clears at once.
212 var composer = document.getElementById('composer');
213 if (composer) composer.addEventListener('submit', function (e) {
214 var box = composer.elements.text;
215 var app = composer.elements.app;
216 var text = box.value.trim();
217 if (!text || !app) return;
218 if (!queue('/api/v1/feed/tells', { app: app.value, text: text })) return;
219 e.preventDefault();
220 box.value = '';
221 box.focus();
222 });
183223 document.addEventListener('keydown', function (e) {
184224 if (e.key !== 'x' || e.metaKey || e.ctrlKey || e.altKey) return;
185225 var a = document.activeElement;
src/web/studio/feed_style.ts +15
@@ -6,10 +6,25 @@ export const feedCss = /* css */ `
66 .fcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
77 .fcard[hidden] { display: none; }
88 .fcard-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
9 .fcard-who { font-weight: 600; }
10 .composer { display: grid; gap: 8px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
11 .composer textarea { width: 100%; min-height: 64px; resize: vertical; }
12 .composer-bar { display: flex; align-items: center; gap: 8px; }
13 .home-tabs { display: none; }
14 .home-apps { display: grid; gap: 6px; }
15 .home-app { padding: 4px 0; }
16 .fcard[data-kind="reply"] { margin-left: 16px; }
17 .fcard-why { margin: 0 0 4px; }
918 .fcard-reason { margin: 8px 0 4px; font-size: 1.05em; overflow-wrap: anywhere; }
1019 .fcard-say summary { cursor: pointer; color: var(--muted-fg, inherit); padding: 4px 0; }
1120 .fcard-form { display: grid; gap: 8px; margin-top: 6px; }
1221 .fcard-form textarea { width: 100%; min-height: 56px; resize: vertical; }
22 @media (max-width: 700px) {
23 .home-tabs { display: flex; gap: 16px; margin-bottom: 12px; }
24 .home-tabs a { padding: 10px 0; border-bottom: 2px solid transparent; }
25 .home-tabs a[aria-current] { border-color: var(--accent); font-weight: 600; }
26 #live-apps { display: none; }
27 }
1328 @media (max-width: 600px) {
1429 .fcard { padding: 12px; }
1530 .fcard-head .btn { padding: 8px 10px; }
src/web/studio/home.ts +53 −108
@@ -1,19 +1,15 @@
11 /**
2 * The home in the studio: every app as a shelf
3 * row (`shelf.ts` draws those — the row is not this page's to decide), and
4 * beside it what is happening right now across all of them, and what a
5 * person put on you. Built from the same rows and cards as the rest of the
6 * forge, from grouped reads only, so the page does not get slower as the
7 * apps grow. A stranger gets the door instead: the public apps, live first.
2 * The home in the studio: one timeline (`feed.ts`) with a composer on top,
3 * a narrow column of your apps beside it, and what a person put on you.
4 * Grouped reads only, so the page does not get slower as the apps grow. A
5 * stranger gets the door instead: the public apps, live first.
86 */
97
108 import { appsRuntime, type EnvState } from "../../apps/runtime.ts";
11 import { crewForRepos } from "../../core/agents.ts";
129 import { listPublicApps } from "../../core/apps.ts";
1310 import { DEFAULT_PAGE, LOOK_SIZES, looksForApps } from "../../core/looks.ts";
14 import { getReposByIds, type Repo } from "../../core/repos.ts";
11 import { getReposByIds } from "../../core/repos.ts";
1512 import { type User } from "../../core/users.ts";
16 import { isPausedAtCeiling, spentTodayForRepos } from "../../crew/autonomy.ts";
1713 import type { Ctx } from "../../http/context.ts";
1814 import { edgeLoginUrl } from "../../http/edge.ts";
1915 import { sshCommand } from "../../ssh/command.ts";
@@ -22,74 +18,51 @@ import { liveRegionsJs } from "../client.ts";
2218 import { html, when, type Html } from "../html.ts";
2319 import { fragment, page } from "../layout.ts";
2420 import { liveClientJs } from "../live.ts";
25 import { btn, empty, envStateBadge, icon, listCard } from "../ui.ts";
21 import { btn, empty, envStateBadge, icon } from "../ui.ts";
2622 import { onYouCard } from "../pages/site.ts";
2723 import { lookUrl, pictured } from "../pages/looks.ts";
2824 import { writableAppsOf } from "./asks.ts";
29 import { productionFactsForRepos, shelfRows } from "./shelf.ts";
30 import { servingHistory } from "./words.ts";
31 import { feedJs, feedNote, feedRegion } from "./feed.ts";
25 import { composer, feedJs, feedNote, feedRegion } from "./feed.ts";
3226
33 /** The events that can change a row on the shelf. */
34 const APPS_LIVE =
35 "app.serving,app.stopped,run.queued,run.started,run.finished,pull.opened,pull.closed,pull.merged";
27 const APPS_SHOWN = 12;
28
29 /** The events that can change the column of your apps. */
30 const APPS_LIVE = "app.serving,app.stopped,pull.merged";
3631 /** The events that can change what is on you. */
3732 const ON_YOU_LIVE =
3833 "issue.assigned,pull.assigned,issue.closed,pull.closed,issue.reopened,pull.reopened,pull.merged";
3934
4035 /**
41 * The shelf: every app the viewer can write, one row each. The front door
42 * leads with what the viewer can write — their own apps and their
43 * organisations' — never widened by a stranger's public app
44 * (`writableAppsOf`, not the visibility every reader gets from `appsOf`).
36 * "Your apps": one link each, a step away from the timeline — the apps the
37 * viewer can write, never widened by a stranger's public app
38 * (`writableAppsOf`). The page of apps itself is `/apps`.
4539 */
46 async function shelf(
47 ctx: Ctx,
48 user: User,
49 ): Promise<{ appRepos: readonly Repo[]; apps: Html }> {
50 const { repos: appRepos } = writableAppsOf(ctx, user);
51 // Read once, shown twice again: a shipped or failed deploy is a row's own
52 // word, and — when nothing is running and no change waits — the rail's.
53 const productionFacts = productionFactsForRepos(ctx, appRepos);
54 // One memo of production's history for every word on this page: the
55 // shelf's rows ask it once per repository.
56 const history = servingHistory();
57 const appRows = await shelfRows(ctx, appRepos, {
58 productionFacts,
59 history,
60 });
61 const apps =
62 appRows.length === 0
63 ? empty({
64 icon: "rocket",
65 title: "No apps yet",
66 note: "Make one, tell the crew what it is, and watch it come up.",
67 action: html`${btn("New app", {
68 href: "/apps/new",
69 variant: "primary",
70 })}
71 ${btn("Repositories", { href: "/?mode=dev" })}`,
72 })
73 : listCard(appRows, {
74 head: html`${icon("rocket")}
75 <h2>Your apps</h2>
76 <span class="spacer"></span>
77 ${btn("Map", { href: "/map", size: "sm", icon: "map" })}
78 ${btn("Audit", { href: "/audit", size: "sm", icon: "shield" })}
79 ${btn("Board", { href: "/board", size: "sm", icon: "activity" })}
80 ${btn("New app", { href: "/apps/new", size: "sm", icon: "plus" })}`,
81 });
82 return { appRepos, apps };
40 function appsColumn(ctx: Ctx, user: User): Html {
41 const { repos } = writableAppsOf(ctx, user);
42 return repos.length === 0
43 ? empty({
44 icon: "rocket",
45 title: "No apps yet",
46 note: "Make one, tell the crew what it is, and watch it come up.",
47 action: html`${btn("New app", { href: "/apps/new", variant: "primary" })}
48 ${btn("Repositories", { href: "/?mode=dev" })}`,
49 })
50 : html`<nav class="home-apps" aria-label="Your apps">
51 <h2 class="small muted">Your apps</h2>
52 ${repos.slice(0, APPS_SHOWN).map(
53 (r) =>
54 html`<a class="home-app truncate" href="${repoBase(r)}"
55 >${r.name}</a
56 >`,
57 )}
58 <a class="small" href="/apps">All apps</a>
59 </nav>`;
8360 }
8461
85 /**
86 * Each live region on the home has an address of its own (`data-live-src`),
87 * so an event fetches that region — the shelf, or what is on you — and not
88 * the page; the fragment answers with the same element, id and all.
89 */
90 const appsRegion = (apps: Html): Html =>
62 /** Each live region has an address of its own (`data-live-src`). */
63 const appsRegion = (ctx: Ctx, user: User): Html =>
9164 html`<div id="live-apps" data-live="${APPS_LIVE}" data-live-src="/live/apps">
92 ${apps}
65 ${appsColumn(ctx, user)}
9366 </div>`;
9467
9568 const onYouRegion = (ctx: Ctx, user: User): Html =>
@@ -101,12 +74,11 @@ const onYouRegion = (ctx: Ctx, user: User): Html =>
10174 ${onYouCard(ctx, user) ?? null}
10275 </div>`;
10376
104 // GET /live/apps — the shelf alone, for the region that shows it.
105 export async function liveAppsFragment(ctx: Ctx): Promise<Response> {
77 // GET /live/apps — the column alone, for the region that shows it.
78 export function liveAppsFragment(ctx: Ctx): Response {
10679 const user = ctx.auth.user;
10780 if (!user) return fragment(html``, { status: 404 });
108 const { apps } = await shelf(ctx, user);
109 return fragment(appsRegion(apps), { request: ctx.request });
81 return fragment(appsRegion(ctx, user), { request: ctx.request });
11082 }
11183
11284 // GET /live/on-you — what is on the viewer, alone.
@@ -116,54 +88,27 @@ export function liveOnYouFragment(ctx: Ctx): Response {
11688 return fragment(onYouRegion(ctx, user), { request: ctx.request });
11789 }
11890
119 export async function studioHome(ctx: Ctx, user: User): Promise<Response> {
120 const db = ctx.app.db;
121 const { appRepos, apps } = await shelf(ctx, user);
122
123 // What the crew cost today across every app on the shelf, and how many
124 // are paused at their ceiling right now — the owner's first question at
125 // the front door, in one bounded read each (`spentTodayForRepos`,
126 // `crewForRepos`), never a query or an `autonomyStatus` call per app.
127 // Every app here is already one the viewer can write, so no further
128 // filter is needed to keep the money to the owner's own.
129 const costLine = when(appRepos.length > 0, () => {
130 const spentToday = spentTodayForRepos(
131 db,
132 appRepos.map((r) => r.id),
133 );
134 const crew = crewForRepos(
135 db,
136 appRepos.map((r) => r.id),
137 );
138 const spentUsd = appRepos.reduce(
139 (sum, r) => sum + (spentToday.get(r.id) ?? 0),
140 0,
141 );
142 const paused = appRepos.filter((r) =>
143 isPausedAtCeiling(r, crew, spentToday),
144 ).length;
145 const noun = `app${appRepos.length === 1 ? "" : "s"}`;
146 const sentence = `$${spentUsd.toFixed(2)} spent today across ${appRepos.length} ${noun} you can write`;
147 return html`<p class="small muted studio-cost">
148 ${sentence} · ${paused} paused at <a href="/map">their ceiling</a>
149 </p>`;
150 });
151
152 const body = html`<h1 class="sr-only">Studio</h1>
153 ${costLine}
91 /**
92 * Signed in, home is the timeline: the composer, then the feed. Your apps
93 * are a narrow column on a desk and a tab on a phone, one step away.
94 */
95 export function studioHome(ctx: Ctx, user: User): Response {
96 const body = html`<h1 class="sr-only">Home</h1>
97 <nav class="home-tabs" aria-label="Home">
98 <a href="/" aria-current="page">Feed</a>
99 <a href="/apps">Your apps</a>
100 </nav>
154101 <div class="dash">
155102 <div class="dash-main stack">
156 ${feedNote()}
157 ${feedRegion(user, ctx)}
158 ${appsRegion(apps)}
103 ${composer(ctx, user)} ${feedNote()} ${feedRegion(user, ctx)}
159104 </div>
160105 <aside class="dash-rail stack">
161 ${onYouRegion(ctx, user)}
106 ${appsRegion(ctx, user)} ${onYouRegion(ctx, user)}
162107 </aside>
163108 </div>`;
164109 return page({
165110 ctx,
166 title: "Studio",
111 title: "Home",
167112 body,
168113 scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${feedJs}`,
169114 });
test/feed-page.test.ts +36
@@ -13,6 +13,8 @@ import { createSession } from "../src/core/sessions.ts";
1313 import type { Repo } from "../src/core/repos.ts";
1414 import { createUser, type User } from "../src/core/users.ts";
1515 import { serve, type Servers } from "../src/http/server.ts";
16 import { openIssue, addCommentThrough } from "../src/actions/issues.ts";
17 import { createApp as insertApp } from "../src/core/apps.ts";
1618 import { readFeed } from "../src/feed/feed.ts";
1719 import { feedCard } from "../src/web/studio/feed.ts";
1820
@@ -105,11 +107,13 @@ describe("the feed on the home page", () => {
105107 actor: null,
106108 at: new Date().toISOString(),
107109 link: "/a/b/runs/r",
110 what: "<i>y</i>",
108111 reason: "<b>x</b>",
109112 score: 1,
110113 }).text;
111114 expect(card).not.toContain("<img");
112115 expect(card).not.toContain("<b>x</b>");
116 expect(card).not.toContain("<i>y</i>");
113117 });
114118
115119 test("a viewer sees only their own feed: no leak from a private app", async () => {
@@ -149,4 +153,36 @@ describe("the feed on the home page", () => {
149153 expect(text).toContain("data-nav");
150154 expect(text).toContain("/api/v1/feed/interactions");
151155 });
156
157 test("home is a composer above the timeline of tells and replies, apps one step away", async () => {
158 const rec = insertApp(app.db, { repoId: open.id, slug: "open", access: "public" });
159 if (!rec.ok) throw new Error(rec.error);
160 const made = openIssue(app, alice, open, { title: "Add dark mode" });
161 if (!made.ok) throw new Error(made.error);
162 const said = await addCommentThrough(app, alice, open, made.value, "I think blue");
163 if (!said.ok) throw new Error(JSON.stringify(said.error));
164
165 const text = await (await get("/", aliceCookie)).text();
166 expect(text).toContain('id="composer"');
167 expect(text.indexOf('id="composer"')).toBeLessThan(text.indexOf('id="live-feed"'));
168 expect(text).toContain('href="/alice/open/issues/1"');
169 expect(text).toContain("Add dark mode");
170 expect(text).toContain("replied on #1: I think blue");
171 expect(text).toContain('data-kind="tell"');
172 expect(text).toContain('data-kind="reply"');
173 expect(text).toContain('href="/apps"');
174 expect(text).toContain("Your apps");
175
176 // Someone with no app has no composer to say anything with.
177 expect(await (await get("/", bobCookie)).text()).not.toContain('id="composer"');
178 });
179
180 test("the composer's tell goes through the feed API and opens an issue", async () => {
181 const res = await fetch(`${servers.url}/api/v1/feed/tells`, {
182 method: "POST",
183 headers: { cookie: aliceCookie, origin: servers.url, "content-type": "application/json" },
184 body: JSON.stringify({ app: "alice/open", text: "Make the logo bigger" }),
185 });
186 expect(res.status).toBe(201);
187 });
152188 });
test/mcp.test.ts +18
@@ -8,6 +8,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
88 import { mkdtemp, rm } from "node:fs/promises";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
11 import { readFeed } from "../src/feed/feed.ts";
1112 import { createApp, type App } from "../src/app.ts";
1213 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1314 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
@@ -156,6 +157,7 @@ describe("the forge over MCP", () => {
156157 expect(names).toEqual([
157158 "apps",
158159 "tell",
160 "feed",
159161 "share",
160162 "say",
161163 "now",
@@ -184,6 +186,22 @@ describe("the forge over MCP", () => {
184186 ).toBe(-32602);
185187 });
186188
189 test("feed returns the posts the home shows, a page at a time", async () => {
190 app.bus.append({ kind: "run.finished", repoId: game.id, actorId: alice.id, payload: { kind: "check", state: "ok", runId: "r1" } });
191 app.bus.append({ kind: "run.finished", repoId: game.id, actorId: alice.id, payload: { kind: "check", state: "ok", runId: "r2" } });
192 const all = await tool(ro, "feed");
193 expect(all.value.items.map((i: { id: string }) => i.id)).toEqual(readFeed(app.db, alice).items.map((i) => i.id));
194 expect(all.value.items.length).toBeGreaterThan(1);
195 const first = await tool(ro, "feed", { limit: 1 });
196 expect(first.value.items).toHaveLength(1);
197 expect(first.value.next_cursor).not.toBeNull();
198 const second = await tool(ro, "feed", { limit: 1, cursor: first.value.next_cursor });
199 expect(second.value.items[0].id).toBe(all.value.items[1].id);
200 expect((await tool(ro, "feed", { limit: 0 })).error).toBeDefined();
201 expect((await tool(ro, "feed", { cursor: "nope" })).error).toBeDefined();
202 expect((await tool(bobRw, "feed")).value.items).toEqual([]);
203 });
204
187205 test("apps and now read what the studio reads", async () => {
188206 const apps = await tool(ro, "apps");
189207 expect(apps.value).toHaveLength(1);
test/studio.test.ts +23 −17
@@ -211,7 +211,7 @@ describe("the studio", () => {
211211 * move the page.
212212 */
213213 test("an app is one row on the shelf: a dot, its name and line, what the crew last did, the way in", async () => {
214 const home = await (await get("/")).text();
214 const home = await (await get("/apps")).text();
215215 const at = home.indexOf('href="/alice/notes"');
216216 expect(at).toBeGreaterThan(-1);
217217 const start = home.lastIndexOf("<li>", at);
@@ -228,7 +228,7 @@ describe("the studio", () => {
228228 expect(long.length).toBeGreaterThanOrEqual(399);
229229 app.db.run("UPDATE repo SET description = ?1 WHERE id = ?2", [long, repo.id]);
230230 try {
231 const home = await (await get("/")).text();
231 const home = await (await get("/apps")).text();
232232 const at = home.indexOf('href="/alice/notes"');
233233 const shelfRow = home.slice(home.lastIndexOf("<li>", at), home.indexOf("</li>", at));
234234 expect(shelfRow).toContain(`title="${long}"`);
@@ -2272,15 +2272,21 @@ describe("the studio home keeps itself current", () => {
22722272 expect(home).not.toContain("Write the README");
22732273 });
22742274
2275 // On you alone: the timeline names the issue too, as the tell it was.
2276 const onYou = () =>
2277 fetch(`${base}/live/on-you`, {
2278 headers: { cookie: `${cookie}; forge_mode=studio` },
2279 });
2280
22752281 test("a card leaves On you once its issue closes", async () => {
2276 const before = await (await get()).text();
2282 const before = await (await onYou()).text();
22772283 expect(before).toContain("Write the README");
22782284
22792285 const merged = await mergePull(app, alice, repo, pull, "squash");
22802286 expect(merged.ok).toBe(true);
22812287 expect(setIssueState(app, alice, repo, readme, "closed").ok).toBe(true);
22822288
2283 const after = await (await get()).text();
2289 const after = await (await onYou()).text();
22842290 expect(after).not.toContain("Write the README");
22852291 });
22862292 });
@@ -2310,7 +2316,7 @@ describe("the studio head says why the app is not up", () => {
23102316 /** The home's own shelf row for this app — the badge issue #201 is about. */
23112317 const shelfBadge = async (cookie: string): Promise<string> => {
23122318 const home = await (
2313 await fetch(`${base}/`, {
2319 await fetch(`${base}/apps`, {
23142320 headers: { cookie: `${cookie}; forge_mode=studio` },
23152321 redirect: "manual",
23162322 })
@@ -4693,7 +4699,7 @@ describe('a tell nobody on the crew can take is not "quiet"', () => {
46934699 });
46944700
46954701 test('the shelf row for that app is not "quiet"', async () => {
4696 const home = await (await get("/")).text();
4702 const home = await (await get("/apps")).text();
46974703 const at = home.indexOf('href="/alice/pad"');
46984704 expect(at).toBeGreaterThan(-1);
46994705 const start = home.lastIndexOf("<li>", at);
@@ -4957,7 +4963,7 @@ describe("an open change is never quiet on the front door", () => {
49574963 });
49584964
49594965 test("the shelf row carries the change's own word, its badge and dot kept", async () => {
4960 const home = await (await get("/")).text();
4966 const home = await (await get("/apps")).text();
49614967 const at = home.indexOf('href="/alice/pad"');
49624968 expect(at).toBeGreaterThan(-1);
49634969 const start = home.lastIndexOf("<li>", at);
@@ -4969,7 +4975,7 @@ describe("an open change is never quiet on the front door", () => {
49694975 });
49704976
49714977 test("an app with nothing open still reads quiet", async () => {
4972 const home = await (await get("/")).text();
4978 const home = await (await get("/apps")).text();
49734979 const at = home.indexOf('href="/alice/quiet"');
49744980 expect(at).toBeGreaterThan(-1);
49754981 const start = home.lastIndexOf("<li>", at);
@@ -5137,7 +5143,7 @@ describe("a deploy that just landed is news on the front door", () => {
51375143 });
51385144
51395145 test("the shelf row reads shipped, with who and when, not quiet", async () => {
5140 const home = await (await get("/")).text();
5146 const home = await (await get("/apps")).text();
51415147 const shelfRow = shelfRowFor(home, "/alice/sap");
51425148 expect(shelfRow).not.toContain("quiet — tell the crew something");
51435149 expect(shelfRow).toContain('data-word="shipped"');
@@ -5145,7 +5151,7 @@ describe("a deploy that just landed is news on the front door", () => {
51455151 });
51465152
51475153 test("an app with no recent deploy still reads quiet", async () => {
5148 const home = await (await get("/")).text();
5154 const home = await (await get("/apps")).text();
51495155 const shelfRow = shelfRowFor(home, `/alice/${quietRepo.name}`);
51505156 expect(shelfRow).toContain("quiet — tell the crew something");
51515157 });
@@ -5164,7 +5170,7 @@ describe("a deploy that just landed is news on the front door", () => {
51645170 manifest: { tty: null },
51655171 },
51665172 });
5167 const home = await (await get("/")).text();
5173 const home = await (await get("/apps")).text();
51685174 const shelfRow = shelfRowFor(home, "/alice/sap");
51695175 expect(shelfRow).not.toContain('data-word="shipped"');
51705176 expect(shelfRow).toContain("quiet — tell the crew something");
@@ -5183,7 +5189,7 @@ describe("a deploy that just landed is news on the front door", () => {
51835189 manifest: { tty: null },
51845190 },
51855191 });
5186 const home = await (await get("/")).text();
5192 const home = await (await get("/apps")).text();
51875193 const shelfRow = shelfRowFor(home, "/alice/sap");
51885194 expect(shelfRow).not.toContain('data-word="shipped"');
51895195 expect(shelfRow).toContain("quiet — tell the crew something");
@@ -5452,10 +5458,10 @@ describe("a stranger sees the app, not the owner's books", () => {
54525458 });
54535459
54545460 test("the studio home names the crew for the owner, but only 'the crew' for a signed-in reader of the same public app", async () => {
5455 const asStranger = await (await get("/", strangerCookie)).text();
5461 const asStranger = await (await get("/apps", strangerCookie)).text();
54565462 expect(asStranger).not.toContain("keeper");
54575463 expect(asStranger).toContain("beacon");
5458 const asOwner = await (await get("/", ownerCookie)).text();
5464 const asOwner = await (await get("/apps", ownerCookie)).text();
54595465 expect(asOwner).toContain("keeper");
54605466 expect(asOwner).toContain("beacon");
54615467 });
@@ -7427,7 +7433,7 @@ describe("the studio home says what the crew cost you today", () => {
74277433 ).split(";")[0]!;
74287434
74297435 const home = (cookie: string) =>
7430 fetch(`${base}/`, {
7436 fetch(`${base}/apps`, {
74317437 headers: { cookie: `${cookie}; forge_mode=studio` },
74327438 redirect: "manual",
74337439 }).then((r) => r.text());
@@ -7673,7 +7679,7 @@ describe("every studio page's headings form one outline", () => {
76737679 const outline = headingOutline(html);
76747680 expect(outline.levels.filter((l) => l === 1).length).toBe(1);
76757681 expect(outline.ok).toBe(true);
7676 expect(html).toMatch(/<h1 class="sr-only">Studio<\/h1>/);
7682 expect(html).toMatch(/<h1 class="sr-only">Home<\/h1>/);
76777683 });
76787684
76797685 test("the app page, the three lists, a tell, a change and a run each have one outline with no skipped level", async () => {
@@ -8462,7 +8468,7 @@ describe("the studio can change what an app says it is (#230)", () => {
84628468 const appHead = await (await get("/alice/lamp/app", ownerCookie)).text();
84638469 expect(appHead).toContain("Private");
84648470
8465 const shelf = await (await get("/", ownerCookie)).text();
8471 const shelf = await (await get("/apps", ownerCookie)).text();
84668472 expect(shelf).toContain("a lamp that stays lit all night");
84678473
84688474 const list = await (await get("/apps", ownerCookie)).text();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs