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

A forge made from a template says so on its home in one line: Started from <template> #13345

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13322-a-forge-made-from-a-template-says-so-on → main 6 commits fork 2 threads · 2 unresolved

  • Merged. scout/13322-a-forge-made-from-a-template-says-so-on was merged into main as 80c52af.

Review

Sign in to review this change.
8 files changed +304 −36
docs/features/README.md +1
@@ -16,6 +16,7 @@ A new note gets a row here (`test/feature-orphans.test.ts`).
1616
1717 Read with the guide page [What a forge is](../guide-what-a-forge-is.md).
1818
19 - [A forge made from a template says so on its home](started-from.md)
1920 - [A look in the feed](feed-look.md)
2021 - [An app with no description says its README](readme-description.md)
2122 - [Arcade carts](arcade-carts.md)
docs/features/started-from.md added +7
@@ -0,0 +1,7 @@
1 # Started from
2
3 A forge made from a template says so on its home, in one muted line under the rest: `Started from <template>`. The template is a built-in's title (for example "Starter app") or a repository's `owner/name`. The name is linked to the repository only while it is still marked as a template here and the reader can read it; otherwise it is plain words. A forge with no template, or one started Blank or from its own code, shows nothing.
4
5 The web home (both the lanes and the lean home) and the terminal home (`Home` in the palette) show the same line, read from the forge's record by `startedFromOf`. Guests see no line on the terminal.
6
7 Code: `src/web/started_from.ts` (the line, as Html and as text), `src/spawn/template_record.ts` (`startedFromDoc` validates the stored record). Test: `test/started-from-line.test.ts`.
src/spawn/template_record.ts +33
@@ -6,6 +6,7 @@
66
77 import { readFileSync } from "node:fs";
88 import { join } from "node:path";
9 import { DEFAULT_TEMPLATE, TEMPLATES } from "./templates.ts";
910
1011 export interface MadeFrom {
1112 /** The template, as `owner/name`. */
@@ -44,3 +45,35 @@ export function madeFromOf(dataDir: string): MadeFrom | undefined {
4445 export function madeFromLine(m: MadeFrom): string {
4546 return `${m.template} at ${m.at.slice(0, 7)}`;
4647 }
48
49 /**
50 * The template a forge was started from, as its record stores it: a name and, for a repository,
51 * where.
52 */
53 export interface StartedFrom {
54 /** What to print: a built-in template's title, or the repository's `owner/name`. */
55 readonly name: string;
56 /** The template repository, as `owner/name`; absent for a built-in template. */
57 readonly repo?: string;
58 }
59
60 /** The record's `template` entry, validated; undefined for none, `blank` or anything malformed. */
61 export function startedFromDoc(doc: unknown): StartedFrom | undefined {
62 if (typeof doc !== "object" || doc === null) return undefined;
63 const t = (doc as Record<string, unknown>)["template"];
64 if (typeof t !== "object" || t === null) return undefined;
65 const { id, repo } = t as Record<string, unknown>;
66 if (typeof repo === "string" && REPO.test(repo)) return { name: repo, repo };
67 const built = typeof id === "string" ? TEMPLATES.find((b) => b.id === id && b.id !== DEFAULT_TEMPLATE) : undefined;
68 if (built !== undefined) return { name: built.title };
69 return typeof id === "string" && REPO.test(id) ? { name: id, repo: id } : undefined;
70 }
71
72 /** This forge's record of what it was started from; undefined when it has none. */
73 export function startedFromOf(dataDir: string): StartedFrom | undefined {
74 try {
75 return startedFromDoc(JSON.parse(readFileSync(join(dataDir, "parent.json"), "utf8")));
76 } catch {
77 return undefined;
78 }
79 }
src/tui/screens/dashboard.ts +68 −16
@@ -33,6 +33,7 @@ import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts";
3333 import { agentsLine } from "../../web/studio/client_home.ts";
3434 import { lastVisit } from "../../core/home_visit.ts";
3535 import { quietFor, quietText } from "../../web/studio/home_empty.ts";
36 import { startedFromText } from "../../web/started_from.ts";
3637 import { sinceDigest } from "../../web/studio/since.ts";
3738 import { askForSomething } from "./tell.ts";
3839 import { movingLines } from "./moving.ts";
@@ -145,7 +146,10 @@ const FIRST_TELL_LINE = "What do you want built? t says it to the crew.";
145146
146147 const FIGURES_ROOM = 6;
147148
148 /** The forge-wide daily ceiling, from config, for the spend figure; the data directory, for the backup's age. */
149 /**
150 * The forge-wide daily ceiling, from config, for the spend figure; the data directory, for the
151 * backup's age.
152 */
149153 export const kpiForge = (app: { config: { crewCeilingUsd?: number; dataDir: string } }) => ({
150154 ceilingUsd: forgeCeiling(app.config),
151155 dataDir: app.config.dataDir,
@@ -203,14 +207,19 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
203207 let asideWaves: Proposal[] = [];
204208 /** Repositories the viewer muted that hold work assigned to them: said, never silent. */
205209 let silenced = new Map<string, Repo>();
206 /** How many asks the viewer's filters hide; undefined when none is set. `H` hides an app for a day, `F` shows all. */
210 /**
211 * How many asks the viewer's filters hide; undefined when none is set. `H` hides an app for a
212 * day, `F` shows all.
213 */
207214 let hidden: number | undefined;
208215 /** The rows marked for one verb, by issue id. */
209216 const marked = new Set<string>();
210217 let lastSet: Operation | undefined;
211218 /** The decision's Done line, as the page keeps it for a minute (`doneLine`). */
212219 let doneSet: ReturnType<typeof doneLine>;
213 /** What Home and /review count: live asks waiting on the viewer, and the stale ones folded apart. */
220 /**
221 * What Home and /review count: live asks waiting on the viewer, and the stale ones folded apart.
222 */
214223 let waitingSet: ReviewSet | undefined;
215224 /** The repositories marked for archiving, by id; only ones the viewer administers. */
216225 const markedRepos = new Set<string>();
@@ -226,14 +235,20 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
226235 let waits: string[] = [];
227236 /** A client's apps, one sentence each on whether its agents work or wait (#1812). */
228237 let clientLines: string[] = [];
229 /** "Since you were here" and its lines: read from the web home's last-visit row, never written here. */
238 /**
239 * "Since you were here" and its lines: read from the web home's last-visit row, never written
240 * here.
241 */
230242 let sinceLines: string[] = [];
231243 /**
232244 * The feed's quiet line (#12328), by the feed's own rule: nothing stalled, no milestone,
233245 * nothing landed.
234246 */
235247 let quiet = false;
236 /** The web home's living pipeline (#8015): Now for a site admin, then being built and just shipped. */
248 /**
249 * The web home's living pipeline (#8015): Now for a site admin, then being built and just
250 * shipped.
251 */
237252 let moving: string[] = [];
238253 /** The ids of those apps, so the key that asks for something stays on them. */
239254 let clientRepoIds = new Set<string>();
@@ -245,7 +260,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
245260 let flaky: string | null = null;
246261 /** What the decider did today, the board's Today line; null on a quiet day or for a reader. */
247262 let decider: string | null = null;
248 /** Home's three figures, as the web's row says them; empty unless an admin looks (they count every repository). */
263 /**
264 * Home's three figures, as the web's row says them; empty unless an admin looks (they count every
265 * repository).
266 */
249267 let figures: string[] = [];
250268 /**
251269 * The web home's everyday ask, as one muted line at the head (#8046): why,
@@ -253,9 +271,19 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
253271 * name of the account used day to day. Nobody else gets the row.
254272 */
255273 let everyday: { line: string; asking: boolean } | undefined;
256 /** A new forge's owner before their first tell: the home is one line, "what do you want built", and the everyday offer waits. */
274 /**
275 * A new forge's owner before their first tell: the home is one line, "what do you want built",
276 * and the everyday offer waits.
277 */
257278 let firstTell = false;
258 /** One line per fired flow alarm; an admin reads every repository, anyone else public ones alone. */
279 /**
280 * "Started from <template>", the web home's muted line (#13322); null for a forge with no
281 * template or a guest.
282 */
283 let startedFrom: string | null = null;
284 /**
285 * One line per fired flow alarm; an admin reads every repository, anyone else public ones alone.
286 */
259287 let alarms: string[] = [];
260288 /** The panels this admin pinned to the web home, by title and board, in their order. */
261289 let panelLines: string[] = [];
@@ -430,6 +458,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
430458 // this is a list of decisions — never a status that would be stale.
431459 pins = f.user ? listPins(f.db, f.user.id) : [];
432460 everyday = everydayHead();
461 startedFrom = f.user === undefined ? null : startedFromText(f.app.config.dataDir);
433462 pinned = f.user ? pinnedRepoIds(f.db, f.user.id) : new Set<string>();
434463 all = listReposVisibleTo(f.db, f.user, { limit: 200 });
435464 found = undefined;
@@ -746,7 +775,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
746775 const mayArchive = (repo: Repo): boolean =>
747776 f.user !== undefined && f.user.kind === "user" && canAdmin(f.db, repo, f.user);
748777
749 /** Archive the marked repositories: a one-line preview naming them, then the fleet `archive` verb. */
778 /**
779 * Archive the marked repositories: a one-line preview naming them, then the fleet `archive` verb.
780 */
750781 const archiveMarked = (): void => {
751782 const picked = repos.filter((repo) => markedRepos.has(repo.id) && mayArchive(repo));
752783 if (picked.length === 0 || f.user === undefined) return;
@@ -790,7 +821,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
790821 );
791822 };
792823
793 /** The asks older than 30 days, dismissed in one step: the bulk preview first, nothing before the choice. */
824 /**
825 * The asks older than 30 days, dismissed in one step: the bulk preview first, nothing before the
826 * choice.
827 */
794828 const archiveStale = (): void => {
795829 const stale = (waitingSet?.stale ?? []).slice(0, BULK_MAX);
796830 if (stale.length === 0 || f.user === undefined) return;
@@ -882,7 +916,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
882916 });
883917 };
884918
885 /** Give the handed-over or assigned work under the cursor to the crew, through the action the web uses. */
919 /**
920 * Give the handed-over or assigned work under the cursor to the crew, through the action the web
921 * uses.
922 */
886923 const giveBackHere = (): void => {
887924 const here = onYou[at("onyou").index];
888925 if (here === undefined) return;
@@ -921,7 +958,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
921958 ctx.toast("listening again", "success");
922959 };
923960
924 /** `H`: hide the app of the row under the cursor for a day: the web's "Hide for a day", the same table. */
961 /**
962 * `H`: hide the app of the row under the cursor for a day: the web's "Hide for a day", the same
963 * table.
964 */
925965 const hideAppForADay = (): void => {
926966 const item = onYou[at("onyou").index];
927967 if (f.user === undefined || item === undefined) return;
@@ -936,7 +976,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
936976 reload();
937977 };
938978
939 /** `1`–`4` switch a kind chip off or on, `P` brings back every person; the web's chips, the same table. */
979 /**
980 * `1`–`4` switch a kind chip off or on, `P` brings back every person; the web's chips, the same
981 * table.
982 */
940983 const toggleChip = (n: number): void => {
941984 if (f.user === undefined) return;
942985 const value = KIND_CHIPS[n];
@@ -946,7 +989,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
946989 reload();
947990 ctx.toast(`${value} ${hidden ? "off" : "on"}`, "success");
948991 };
949 /** `h` on an On you row switches its author off, as the web's person chip does; never yourself. */
992 /**
993 * `h` on an On you row switches its author off, as the web's person chip does; never yourself.
994 */
950995 const hideAuthor = (): void => {
951996 const here = onYou[at("onyou").index];
952997 if (f.user === undefined || here === undefined) return;
@@ -1170,6 +1215,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
11701215 s.text(strip!.x, strip!.y, truncate(everyday.line, strip!.w), style(c.mutedFg, c.bg), strip!.x + strip!.w);
11711216 body = rest!;
11721217 }
1218 if (startedFrom !== null) {
1219 const [strip, rest] = split(body, "v", [len(1), fill(1)]);
1220 s.text(strip!.x, strip!.y, truncate(startedFrom, strip!.w), style(c.mutedFg, c.bg), strip!.x + strip!.w);
1221 body = rest!;
1222 }
11731223 if (alarms.length > 0) {
11741224 const [strip, rest] = split(body, "v", [len(alarms.length), fill(1)]);
11751225 alarms.forEach((line, i) =>
@@ -1475,7 +1525,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
14751525 focused: on,
14761526 ...(footer === undefined ? {} : { footer }),
14771527 });
1478 // The week's asks lead the pane, muted; absent when all four are 0, so the list sits where it did.
1528 // The week's asks lead the pane, muted; absent when all four are 0, so the list sits where it
1529 // did.
14791530 let inner = frame;
14801531 if (asksLine !== undefined && frame.h > 1) {
14811532 s.text(frame.x, frame.y, truncate(asksLine, frame.w), style(c.mutedFg, c.bg), frame.x + frame.w);
@@ -1557,7 +1608,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
15571608 parts.push(
15581609 `${silenced.size} ${silenced.size === 1 ? "repository" : "repositories"} muted · L listen again`,
15591610 );
1560 // The minute's Done line leads the undo, the page's words and gate; after the minute the day's undo stays.
1611 // The minute's Done line leads the undo, the page's words and gate; after the minute the day's
1612 // undo stays.
15611613 const doneNow = doneSet !== undefined && inDoneMinute(doneSet.operation.createdAt) ? doneSet : undefined;
15621614 if (doneNow !== undefined && !doneNow.undo) parts.push(doneNow.line);
15631615 else if (lastSet !== undefined) parts.push(`${doneNow === undefined ? "" : `${doneNow.line} · `}u undo ${lastSet.verb}`);
src/web/pages/home_flow.ts +60 −19
@@ -78,9 +78,12 @@ import { untoldAnswer, markTold } from "../../core/requests.ts";
7878 import { YOURE_IN_MESSAGE } from "../../actions/users.ts";
7979 import { spawnedForge } from "../../spawn/claim.ts";
8080 import { forgeHasNoKey, NO_KEY_AT, NO_KEY_LINE } from "../../crew/no_key.ts";
81 import { startedFromLine } from "../started_from.ts";
8182
8283
83 /** The events that can move work between lanes, per lane. A burst of them is one fetch of the lane. */
84 /**
85 * The events that can move work between lanes, per lane. A burst of them is one fetch of the lane.
86 */
8487 const LANE_LIVE: Record<LaneKey, string> = {
8588 asked: "issue.opened,issue.closed,issue.reopened,issue.blocked,issue.unblocked,run.queued,run.started,run.finished",
8689 building: "run.queued,run.started,run.finished,pull.opened,pull.closed",
@@ -102,7 +105,10 @@ const filterOf = (url: URL): string | null => {
102105
103106 const query = (only: string | null): string => (only === null ? "" : `&app=${encodeURIComponent(only)}`);
104107
105 /** A stretch of time as a clock the page keeps: the words the server uses, redrawn by the page's script on any event. */
108 /**
109 * A stretch of time as a clock the page keeps: the words the server uses, redrawn by the page's
110 * script on any event.
111 */
106112 function age(iso: string, now: number): Html {
107113 const at = Date.parse(iso);
108114 return html`<time class="hf-age" datetime="${new Date(at).toISOString()}">${span(now - at)}</time>`;
@@ -146,12 +152,17 @@ function tile(i: LaneView["items"][number], now: number): Html {
146152 </li>`;
147153 }
148154
149 /** Where a lane's whole list is: the table, filtered to the lane (and the app, when one is chosen). */
155 /**
156 * Where a lane's whole list is: the table, filtered to the lane (and the app, when one is chosen).
157 */
150158 function laneHref(key: LaneKey, only: string | null): string {
151159 return `/?view=table&lane=${key}${query(only)}`;
152160 }
153161
154 /** One lane: a live region that answers for itself (`/live/lane`), so an event redraws this lane and no other. */
162 /**
163 * One lane: a live region that answers for itself (`/live/lane`), so an event redraws this lane and
164 * no other.
165 */
155166 export function laneRegion(
156167 view: LaneView,
157168 health: Health,
@@ -285,7 +296,10 @@ function weekFigure(strip: StripPart): { value: string; note: string; attn: bool
285296 return { value: `about ${money(strip.weekSpendUsd)}`, note: "spent by the crew in seven days, at list price; the provider has not reported its week", attn: false };
286297 }
287298
288 /** One thing that needs this person: an alarm (red: something is not working) or a notice (it can wait, and is not on fire). */
299 /**
300 * One thing that needs this person: an alarm (red: something is not working) or a notice (it can
301 * wait, and is not on fire).
302 */
289303 interface Need {
290304 readonly says: string;
291305 readonly href: string;
@@ -301,12 +315,18 @@ interface Need {
301315 * line says the first two; the proof's own record is
302316 * on /releases.
303317 */
304 /** Who the strip is drawn for; `everyday` is an admin with no everyday account and no recorded choice to keep working as admin. */
318 /**
319 * Who the strip is drawn for; `everyday` is an admin with no everyday account and no recorded
320 * choice to keep working as admin.
321 */
305322 interface StripViewer {
306323 readonly id: string;
307324 readonly isAdmin: boolean;
308325 readonly everyday?: boolean;
309 /** What hosted forges asked to reach and no admin has answered (`spawn/child_reach.ts`); an admin's only. */
326 /**
327 * What hosted forges asked to reach and no admin has answered (`spawn/child_reach.ts`); an
328 * admin's only.
329 */
310330 readonly reach?: readonly ReachAsk[];
311331 /**
312332 * What people here asked this viewer, as one who can change it, to change
@@ -321,7 +341,10 @@ interface StripViewer {
321341 readonly noKey?: true;
322342 }
323343
324 /** The everyday account's one quiet line: the step is on its own page, where "Keep using admin" is remembered. */
344 /**
345 * The everyday account's one quiet line: the step is on its own page, where "Keep using admin" is
346 * remembered.
347 */
325348 const EVERYDAY_NEED: Need = { says: "You are signed in as the admin. Make an everyday account", href: "/settings/everyday", tone: "notice" };
326349
327350 /**
@@ -365,7 +388,10 @@ function needsOf(picture: LanePicture, viewer: StripViewer, dataDir: string, now
365388 ];
366389 }
367390
368 /** The one line: what needs this person, at most two things, never a list; or that nothing does. Red only when something is not working. */
391 /**
392 * The one line: what needs this person, at most two things, never a list; or that nothing does. Red
393 * only when something is not working.
394 */
369395 function needLine(needs: readonly Need[]): Html {
370396 if (needs.length === 0) return html`<p class="hf-calm"><span class="dot" data-tone="success"></span>Nothing needs you right now.</p>`;
371397 const [first, second] = needs;
@@ -404,7 +430,10 @@ export function stripRegion(picture: LanePicture, viewer: StripViewer, dataDir:
404430
405431 // ---- before the first reading: the same regions, saying so ----
406432
407 /** A lane before the picture exists: its name, "reading…", and the address that fills it. The page's script fetches that address at once. */
433 /**
434 * A lane before the picture exists: its name, "reading…", and the address that fills it. The page's
435 * script fetches that address at once.
436 */
408437 function readingLane(key: LaneKey, only: string | null): Html {
409438 const scope = only === null ? null : html` data-live-repo="${only}"`;
410439 return html`<section class="lane" id="lane-${key}" data-lane="${key}" data-tone="quiet" data-count="" data-reading aria-busy="true"
@@ -474,7 +503,8 @@ function readForges(app: App, now: number): Promise<Forges | undefined> {
474503 /** Start reading the hosted forges now: the forge calls this once it is listening. */
475504 export function warmHome(app: App): void {
476505 if (process.env["NODE_ENV"] === "test") return;
477 // The people who run the forge are counted first: the line that says what waits on them is ready for their first page.
506 // The people who run the forge are counted first: the line that says what waits on them is ready
507 // for their first page.
478508 const owners = app.db.query<{ id: string }, []>("SELECT id FROM user WHERE is_admin = 1 AND is_agent = 0 LIMIT 4").all().map((u) => u.id);
479509 warmLanes(app.db, pictureOptions(app), Date.now(), owners);
480510 void readForges(app, Date.now());
@@ -545,7 +575,10 @@ function filterForm(repos: readonly string[], only: string | null): Html {
545575 </form>`;
546576 }
547577
548 /** Which view: the one the address asks for (and then remembers), else the one remembered, else the lanes. */
578 /**
579 * Which view: the one the address asks for (and then remembers), else the one remembered, else the
580 * lanes.
581 */
549582 function viewOf(ctx: Ctx): { view: "lanes" | "table"; asked: boolean } {
550583 const asked = ctx.url.searchParams.get("view");
551584 if (asked === "lanes" || asked === "table") return { view: asked, asked: true };
@@ -553,7 +586,9 @@ function viewOf(ctx: Ctx): { view: "lanes" | "table"; asked: boolean } {
553586 }
554587 const VIEW_COOKIE = "forge_home_view";
555588
556 /** The Lanes | Table switch: two links, each an address of its own, the app filter carried across. */
589 /**
590 * The Lanes | Table switch: two links, each an address of its own, the app filter carried across.
591 */
557592 function viewSwitch(view: "lanes" | "table", only: string | null): Html {
558593 const keep = only === null ? "" : `&app=${encodeURIComponent(only)}`;
559594 return html`<nav class="hf-views" aria-label="View">
@@ -562,7 +597,8 @@ function viewSwitch(view: "lanes" | "table", only: string | null): Html {
562597 </nav>`;
563598 }
564599
565 // GET / (signed in) — the home: the lanes, or the table of the same items. Called by the root route, and `/home` redirects here.
600 // GET / (signed in) — the home: the lanes, or the table of the same items. Called by the root
601 // route, and `/home` redirects here.
566602 export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited<ReturnType<typeof spawnedForge>> }): Promise<Response> {
567603 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
568604 const user = ctx.auth.user;
@@ -573,7 +609,8 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited
573609 const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx), "page", now));
574610 const rendering = performance.now();
575611 const viewing = picture === undefined ? undefined : timePhase(ctx.request, "viewing", () => viewFor(ctx.app.db, user, picture, view === "table" ? null : only));
576 // A spawned forge's owner is a client: the forge-wide figures are not theirs to see, whole home or lean.
612 // A spawned forge's owner is a client: the forge-wide figures are not theirs to see, whole home
613 // or lean.
577614 const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app));
578615 const wide = user.isAdmin && spawned === undefined;
579616 const strip = picture === undefined ? readingStrip() : stripRegion(picture, { id: user.id, isAdmin: wide, ...(wide && forgeHasNoKey(ctx.app) ? { noKey: true as const } : {}), everyday: askForEveryday(ctx.app.db, user), asked: asksToAnswer(ctx.app, user), ...(wide ? { reach: reachNeeds(ctx.app), archive: archiveNeeds(ctx.app), inProcess: await inProcessForges(ctx.app, now) } : {}) }, ctx.app.config.dataDir, now);
@@ -587,8 +624,10 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited
587624 <div class="hf-tell">${tellBox(ctx, user)}</div>`;
588625 // A client who asked for the whole home (`?all=1`) has a way back to their apps.
589626 const after = html`${ctx.url.searchParams.has("all") ? html`<p class="small muted" id="lean-home"><a href="/">Just my apps</a></p>` : null}${requestsCard(ctx, "home")}${timePhase(ctx.request, "held", () => heldLine(ctx, user))}
590 ${spawned?.url === undefined ? null : html`<p class="small muted" id="forge-address">Your forge: <a href="${spawned.url}">${new URL(spawned.url).host}</a></p>`}`;
591 // A run the host stopped is named, with its way to try again, while it is within the day: the one place the web offers that.
627 ${spawned?.url === undefined ? null : html`<p class="small muted" id="forge-address">Your forge: <a href="${spawned.url}">${new URL(spawned.url).host}</a></p>`}
628 ${startedFromLine(ctx.app.db, ctx.app.config.dataDir, user)}`;
629 // A run the host stopped is named, with its way to try again, while it is within the day: the one
630 // place the web offers that.
592631 const stopped = user.kind === "agent" ? null : timePhase(ctx.request, "stopped", () => interruptedOutLine(ctx, listReposWritableTo(ctx.app.db, user, { withoutArchived: true, limit: 200 })));
593632 const forges = wide ? await timePhaseAsync(ctx.request, "forges", () => forgesRegion(ctx.app, false)) : null;
594633 let main: Html;
@@ -635,7 +674,8 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited
635674 /** What the rows' states read besides the rows. */
636675 const tableInput = (picture: LanePicture, now: number) => ({ now, builders: picture.builders, moved: picture.moved });
637676
638 // GET /live/table?<view> — the table's rows alone, for the region that shows them; an unchanged table answers 304 without being drawn.
677 // GET /live/table?<view> — the table's rows alone, for the region that shows them; an unchanged
678 // table answers 304 without being drawn.
639679 export async function liveTableFragment(ctx: Ctx): Promise<Response> {
640680 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
641681 const user = ctx.auth.user;
@@ -726,7 +766,8 @@ export async function liveForgesFragment(ctx: Ctx): Promise<Response> {
726766 return res;
727767 }
728768
729 // GET /live/figures — the figures' grid alone, for the region that shows it. An admin's: the numbers are the forge's.
769 // GET /live/figures — the figures' grid alone, for the region that shows it. An admin's: the
770 // numbers are the forge's.
730771 export async function liveFiguresFragment(ctx: Ctx): Promise<Response> {
731772 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
732773 const user = ctx.auth.user;
src/web/started_from.ts added +38
@@ -0,0 +1,38 @@
1 /**

Both doors: the web home shows this line but the terminal home does not, and there is no docs/features/started-from.md. Add the how-to there (not in README) and show the same line on the TUI home, reading startedFromOf and gated like the page.

2 * "Started from <template>": the one muted line a forge made from a template shows on its home.
3 * The stored name is printed; it links to the template's page only while that repository is
4 * still marked as a template here and the viewer can read it. Nothing for a forge with no template.
5 */
6
7 import type { Database } from "bun:sqlite";
8 import { canRead, getRepo } from "../core/repos.ts";
9 import type { User } from "../core/users.ts";
10 import { startedFromOf, type StartedFrom } from "../spawn/template_record.ts";
11 import { html, type Html } from "./html.ts";
12
13 /**
14 * The note for a template record, as a muted line; the name is escaped, and linked only while it
15 * may be read.
16 */
17 export function startedFromHtml(db: Database, from: StartedFrom, viewer: User | undefined): Html {
18 let shown: Html = html`${from.name}`;
19 if (from.repo !== undefined) {
20 const [owner = "", name = ""] = from.repo.split("/");
21 const repo = getRepo(db, owner, name);
22 if (repo !== undefined && repo.template && canRead(db, repo, viewer)) {
23 shown = html`<a href="/${repo.ownerName}/${repo.name}">${from.name}</a>`;
24 }
25 }
26 return html`<p class="small muted" id="started-from">Started from ${shown}</p>`;
27 }
28
29 export function startedFromLine(db: Database, dataDir: string, viewer: User | undefined): Html | null {
30 const from = startedFromOf(dataDir);
31 return from === undefined ? null : startedFromHtml(db, from, viewer);
32 }
33
34 /** The same line as plain words, for the terminal home; null for a forge with no template. */
35 export function startedFromText(dataDir: string): string | null {
36 const from = startedFromOf(dataDir);
37 return from === undefined ? null : `Started from ${from.name}`;
38 }
src/web/studio/home.ts +2 −1
@@ -83,6 +83,7 @@ import { firstAskJs, nextStepsCard, nextStepsOf } from "../pages/next-steps.ts";
8383 import { spawnedForge } from "../../spawn/claim.ts";
8484 import { readableNotes } from "../../actions/desk.ts";
8585 import { deskStrip } from "../desk_strip.ts";
86 import { startedFromLine } from "../started_from.ts";
8687 import { clientApps } from "./client_home.ts";
8788
8889 /** The events that can change what is on you. */
@@ -314,7 +315,7 @@ export async function studioHome(
314315 // Before the first tell the card is the one box and carries the key line and the composer.
315316 const firstTell = steps.some((s) => s.key === "tell" && !s.done);
316317 const lean = html`<h1 class="sr-only">Home</h1>
317 ${firstSteps} ${address} ${firstTell ? null : crewKeyCard(ctx)} ${heldLine(ctx, user, !firstTell)} ${apps}
318 ${firstSteps} ${address} ${startedFromLine(ctx.app.db, ctx.app.config.dataDir, user)} ${firstTell ? null : crewKeyCard(ctx)} ${heldLine(ctx, user, !firstTell)} ${apps}
318319 <div class="stack">
319320 ${firstTell ? null : composer(ctx, user)}
320321 <p class="small muted">
test/started-from-line.test.ts added +95
@@ -0,0 +1,95 @@
1 /** A forge made from a template says so on its home in one muted line (#13322). */
2 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts";
8 import { createToken } from "../src/core/tokens.ts";
9 import { createUser, type User } from "../src/core/users.ts";
10 import { startedFromDoc } from "../src/spawn/template_record.ts";
11 import { startedFromHtml, startedFromLine, startedFromText } from "../src/web/started_from.ts";
12 import { serve, type Servers } from "../src/http/server.ts";
13 import { quietLogs } from "./helpers/globals.ts";
14
15 quietLogs();
16
17 describe("started from", () => {
18 let dataDir: string;
19 let app: App;
20 let servers: Servers;
21 let alice: User;
22 let auth = "";
23 const record = (template: unknown) => Bun.write(join(dataDir, "parent.json"), JSON.stringify({ org: "x", template }));
24 const line = async () => startedFromLine(app.db, dataDir, alice)?.toString() ?? null;
25
26 beforeAll(async () => {
27 dataDir = await mkdtemp(join(tmpdir(), "forge-started-from-"));
28 app = createApp({ dataDir, port: 0 });
29 servers = await serve(app);
30 const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
31 if (!a.ok) throw new Error("user");
32 alice = a.value;
33 auth = `Bearer ${createToken(app.db, alice.id, "rw", "rw").token}`;
34 const kit = await createRepo(app, alice, { name: "kit", visibility: "public", description: "" });
35 if (!kit.ok) throw new Error("repo");
36 await commitToBranch(app, alice, kit.value, { message: "seed", files: [{ path: "a.txt", content: "a" }] });
37 const marked = await updateRepoSettings(app, alice, kit.value, { template: true });
38 if (!marked.ok) throw new Error("mark");
39 }, 30_000);
40
41 afterAll(async () => {
42 servers.stop();
43 app.close();
44 await rm(dataDir, { recursive: true, force: true });
45 });
46
47 test("a template repository still offered is named and linked", async () => {
48 await record({ id: "alice/kit", repo: "alice/kit", tip: "a".repeat(40) });
49 const l = await line();
50 expect(l).toContain("Started from");
51 expect(l).toContain('<a href="/alice/kit">alice/kit</a>');
52 const home = await (await fetch(`${servers.url}/`, { headers: { authorization: auth } })).text();
53 expect(home).toContain('id="started-from"');
54 });
55
56 test("a template since unmarked is named, not linked", async () => {
57 const repo = (await import("../src/core/repos.ts")).getRepo(app.db, "alice", "kit")!;
58 await updateRepoSettings(app, alice, repo, { template: false });
59 const l = await line();
60 expect(l).toContain("Started from alice/kit");
61 expect(l).not.toContain("<a ");
62 });
63
64 test("a built-in template is named by its title", async () => {
65 await record({ id: "starter" });
66 expect(await line()).toContain("Started from Starter app");
67 });
68
69 test("no template, blank, or a malformed record shows no line; a stored name is escaped", async () => {

Box 3: this test only shows malformed names are rejected by startedFromDoc. Add a case with a valid-looking but hostile stored name, e.g. a built-in title or repo like alice/<b> that passes the regex if one can, or unit-test startedFromLine through a StartedFrom value, and assert the output contains &lt; and never the raw tag. Today nothing would fail if escaping were removed.

70 await Bun.write(join(dataDir, "parent.json"), JSON.stringify({ org: "x" }));
71 expect(await line()).toBeNull();
72 await record({ id: "blank" });
73 expect(await line()).toBeNull();
74 expect(startedFromDoc({ template: { repo: "<b>/x" } })).toBeUndefined();
75 expect(startedFromDoc({ template: { id: "<script>" } })).toBeUndefined();
76 const home = await (await fetch(`${servers.url}/`, { headers: { authorization: auth } })).text();
77 expect(home).not.toContain('id="started-from"');
78 });
79
80 test("a hostile stored name is escaped, never raw", () => {
81 const out = startedFromHtml(app.db, { name: "alice/<b>x</b>", repo: "alice/kit" }, alice).toString();
82 expect(out).toContain("&lt;b&gt;");
83 expect(out).not.toContain("<b>");
84 const plain = startedFromHtml(app.db, { name: "<img src=x onerror=1>" }, alice).toString();
85 expect(plain).toContain("&lt;img");
86 expect(plain).not.toContain("<img");
87 });
88
89 test("the terminal home reads the same record", async () => {
90 await record({ id: "starter" });
91 expect(startedFromText(dataDir)).toBe("Started from Starter app");
92 await record({ id: "blank" });
93 expect(startedFromText(dataDir)).toBeNull();
94 });
95 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs