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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13322-a-forge-made-from-a-template-says-so-on → main 6 commits fork 2 threads · 2 unresolved
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`). | ||
| 16 | 16 | |
| 17 | 17 | Read with the guide page [](../guide-what-a-forge-is.md). |
| 18 | 18 | |
| 19 | - [](started-from.md) | |
| 19 | 20 | - [](feed-look.md) |
| 20 | 21 | - [](readme-description.md) |
| 21 | 22 | - [](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 @@ | ||
| 6 | 6 | |
| 7 | 7 | import { readFileSync } from "node:fs"; |
| 8 | 8 | import { join } from "node:path"; |
| 9 | import { DEFAULT_TEMPLATE, TEMPLATES } from "./templates.ts"; | |
| 9 | 10 | |
| 10 | 11 | export interface MadeFrom { |
| 11 | 12 | /** The template, as `owner/name`. */ |
| @@ -44,3 +45,35 @@ export function madeFromOf(dataDir: string): MadeFrom | undefined { | ||
| 44 | 45 | export function madeFromLine(m: MadeFrom): string { |
| 45 | 46 | return `${m.template} at ${m.at.slice(0, 7)}`; |
| 46 | 47 | } |
| 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"; | ||
| 33 | 33 | import { agentsLine } from "../../web/studio/client_home.ts"; |
| 34 | 34 | import { lastVisit } from "../../core/home_visit.ts"; |
| 35 | 35 | import { quietFor, quietText } from "../../web/studio/home_empty.ts"; |
| 36 | import { startedFromText } from "../../web/started_from.ts"; | |
| 36 | 37 | import { sinceDigest } from "../../web/studio/since.ts"; |
| 37 | 38 | import { askForSomething } from "./tell.ts"; |
| 38 | 39 | import { movingLines } from "./moving.ts"; |
| @@ -145,7 +146,10 @@ const FIRST_TELL_LINE = "What do you want built? t says it to the crew."; | ||
| 145 | 146 | |
| 146 | 147 | const FIGURES_ROOM = 6; |
| 147 | 148 | |
| 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 | */ | |
| 149 | 153 | export const kpiForge = (app: { config: { crewCeilingUsd?: number; dataDir: string } }) => ({ |
| 150 | 154 | ceilingUsd: forgeCeiling(app.config), |
| 151 | 155 | dataDir: app.config.dataDir, |
| @@ -203,14 +207,19 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 203 | 207 | let asideWaves: Proposal[] = []; |
| 204 | 208 | /** Repositories the viewer muted that hold work assigned to them: said, never silent. */ |
| 205 | 209 | 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 | */ | |
| 207 | 214 | let hidden: number | undefined; |
| 208 | 215 | /** The rows marked for one verb, by issue id. */ |
| 209 | 216 | const marked = new Set<string>(); |
| 210 | 217 | let lastSet: Operation | undefined; |
| 211 | 218 | /** The decision's Done line, as the page keeps it for a minute (`doneLine`). */ |
| 212 | 219 | 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 | */ | |
| 214 | 223 | let waitingSet: ReviewSet | undefined; |
| 215 | 224 | /** The repositories marked for archiving, by id; only ones the viewer administers. */ |
| 216 | 225 | const markedRepos = new Set<string>(); |
| @@ -226,14 +235,20 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 226 | 235 | let waits: string[] = []; |
| 227 | 236 | /** A client's apps, one sentence each on whether its agents work or wait (#1812). */ |
| 228 | 237 | 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 | */ | |
| 230 | 242 | let sinceLines: string[] = []; |
| 231 | 243 | /** |
| 232 | 244 | * The feed's quiet line (#12328), by the feed's own rule: nothing stalled, no milestone, |
| 233 | 245 | * nothing landed. |
| 234 | 246 | */ |
| 235 | 247 | 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 | */ | |
| 237 | 252 | let moving: string[] = []; |
| 238 | 253 | /** The ids of those apps, so the key that asks for something stays on them. */ |
| 239 | 254 | let clientRepoIds = new Set<string>(); |
| @@ -245,7 +260,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 245 | 260 | let flaky: string | null = null; |
| 246 | 261 | /** What the decider did today, the board's Today line; null on a quiet day or for a reader. */ |
| 247 | 262 | 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 | */ | |
| 249 | 267 | let figures: string[] = []; |
| 250 | 268 | /** |
| 251 | 269 | * 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 { | ||
| 253 | 271 | * name of the account used day to day. Nobody else gets the row. |
| 254 | 272 | */ |
| 255 | 273 | 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 | */ | |
| 257 | 278 | 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 | */ | |
| 259 | 287 | let alarms: string[] = []; |
| 260 | 288 | /** The panels this admin pinned to the web home, by title and board, in their order. */ |
| 261 | 289 | let panelLines: string[] = []; |
| @@ -430,6 +458,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 430 | 458 | // this is a list of decisions — never a status that would be stale. |
| 431 | 459 | pins = f.user ? listPins(f.db, f.user.id) : []; |
| 432 | 460 | everyday = everydayHead(); |
| 461 | startedFrom = f.user === undefined ? null : startedFromText(f.app.config.dataDir); | |
| 433 | 462 | pinned = f.user ? pinnedRepoIds(f.db, f.user.id) : new Set<string>(); |
| 434 | 463 | all = listReposVisibleTo(f.db, f.user, { limit: 200 }); |
| 435 | 464 | found = undefined; |
| @@ -746,7 +775,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 746 | 775 | const mayArchive = (repo: Repo): boolean => |
| 747 | 776 | f.user !== undefined && f.user.kind === "user" && canAdmin(f.db, repo, f.user); |
| 748 | 777 | |
| 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 | */ | |
| 750 | 781 | const archiveMarked = (): void => { |
| 751 | 782 | const picked = repos.filter((repo) => markedRepos.has(repo.id) && mayArchive(repo)); |
| 752 | 783 | if (picked.length === 0 || f.user === undefined) return; |
| @@ -790,7 +821,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 790 | 821 | ); |
| 791 | 822 | }; |
| 792 | 823 | |
| 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 | */ | |
| 794 | 828 | const archiveStale = (): void => { |
| 795 | 829 | const stale = (waitingSet?.stale ?? []).slice(0, BULK_MAX); |
| 796 | 830 | if (stale.length === 0 || f.user === undefined) return; |
| @@ -882,7 +916,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 882 | 916 | }); |
| 883 | 917 | }; |
| 884 | 918 | |
| 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 | */ | |
| 886 | 923 | const giveBackHere = (): void => { |
| 887 | 924 | const here = onYou[at("onyou").index]; |
| 888 | 925 | if (here === undefined) return; |
| @@ -921,7 +958,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 921 | 958 | ctx.toast("listening again", "success"); |
| 922 | 959 | }; |
| 923 | 960 | |
| 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 | */ | |
| 925 | 965 | const hideAppForADay = (): void => { |
| 926 | 966 | const item = onYou[at("onyou").index]; |
| 927 | 967 | if (f.user === undefined || item === undefined) return; |
| @@ -936,7 +976,10 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 936 | 976 | reload(); |
| 937 | 977 | }; |
| 938 | 978 | |
| 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 | */ | |
| 940 | 983 | const toggleChip = (n: number): void => { |
| 941 | 984 | if (f.user === undefined) return; |
| 942 | 985 | const value = KIND_CHIPS[n]; |
| @@ -946,7 +989,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 946 | 989 | reload(); |
| 947 | 990 | ctx.toast(`${value} ${hidden ? "off" : "on"}`, "success"); |
| 948 | 991 | }; |
| 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 | */ | |
| 950 | 995 | const hideAuthor = (): void => { |
| 951 | 996 | const here = onYou[at("onyou").index]; |
| 952 | 997 | if (f.user === undefined || here === undefined) return; |
| @@ -1170,6 +1215,11 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1170 | 1215 | s.text(strip!.x, strip!.y, truncate(everyday.line, strip!.w), style(c.mutedFg, c.bg), strip!.x + strip!.w); |
| 1171 | 1216 | body = rest!; |
| 1172 | 1217 | } |
| 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 | } | |
| 1173 | 1223 | if (alarms.length > 0) { |
| 1174 | 1224 | const [strip, rest] = split(body, "v", [len(alarms.length), fill(1)]); |
| 1175 | 1225 | alarms.forEach((line, i) => |
| @@ -1475,7 +1525,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 1475 | 1525 | focused: on, |
| 1476 | 1526 | ...(footer === undefined ? {} : { footer }), |
| 1477 | 1527 | }); |
| 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. | |
| 1479 | 1530 | let inner = frame; |
| 1480 | 1531 | if (asksLine !== undefined && frame.h > 1) { |
| 1481 | 1532 | 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 { | ||
| 1557 | 1608 | parts.push( |
| 1558 | 1609 | `${silenced.size} ${silenced.size === 1 ? "repository" : "repositories"} muted · L listen again`, |
| 1559 | 1610 | ); |
| 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. | |
| 1561 | 1613 | const doneNow = doneSet !== undefined && inDoneMinute(doneSet.operation.createdAt) ? doneSet : undefined; |
| 1562 | 1614 | if (doneNow !== undefined && !doneNow.undo) parts.push(doneNow.line); |
| 1563 | 1615 | 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"; | ||
| 78 | 78 | import { YOURE_IN_MESSAGE } from "../../actions/users.ts"; |
| 79 | 79 | import { spawnedForge } from "../../spawn/claim.ts"; |
| 80 | 80 | import { forgeHasNoKey, NO_KEY_AT, NO_KEY_LINE } from "../../crew/no_key.ts"; |
| 81 | import { startedFromLine } from "../started_from.ts"; | |
| 81 | 82 | |
| 82 | 83 | |
| 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 | */ | |
| 84 | 87 | const LANE_LIVE: Record<LaneKey, string> = { |
| 85 | 88 | asked: "issue.opened,issue.closed,issue.reopened,issue.blocked,issue.unblocked,run.queued,run.started,run.finished", |
| 86 | 89 | building: "run.queued,run.started,run.finished,pull.opened,pull.closed", |
| @@ -102,7 +105,10 @@ const filterOf = (url: URL): string | null => { | ||
| 102 | 105 | |
| 103 | 106 | const query = (only: string | null): string => (only === null ? "" : `&app=${encodeURIComponent(only)}`); |
| 104 | 107 | |
| 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 | */ | |
| 106 | 112 | function age(iso: string, now: number): Html { |
| 107 | 113 | const at = Date.parse(iso); |
| 108 | 114 | 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 { | ||
| 146 | 152 | </li>`; |
| 147 | 153 | } |
| 148 | 154 | |
| 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 | */ | |
| 150 | 158 | function laneHref(key: LaneKey, only: string | null): string { |
| 151 | 159 | return `/?view=table&lane=${key}${query(only)}`; |
| 152 | 160 | } |
| 153 | 161 | |
| 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 | */ | |
| 155 | 166 | export function laneRegion( |
| 156 | 167 | view: LaneView, |
| 157 | 168 | health: Health, |
| @@ -285,7 +296,10 @@ function weekFigure(strip: StripPart): { value: string; note: string; attn: bool | ||
| 285 | 296 | 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 }; |
| 286 | 297 | } |
| 287 | 298 | |
| 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 | */ | |
| 289 | 303 | interface Need { |
| 290 | 304 | readonly says: string; |
| 291 | 305 | readonly href: string; |
| @@ -301,12 +315,18 @@ interface Need { | ||
| 301 | 315 | * line says the first two; the proof's own record is |
| 302 | 316 | * on /releases. |
| 303 | 317 | */ |
| 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 | */ | |
| 305 | 322 | interface StripViewer { |
| 306 | 323 | readonly id: string; |
| 307 | 324 | readonly isAdmin: boolean; |
| 308 | 325 | 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 | */ | |
| 310 | 330 | readonly reach?: readonly ReachAsk[]; |
| 311 | 331 | /** |
| 312 | 332 | * What people here asked this viewer, as one who can change it, to change |
| @@ -321,7 +341,10 @@ interface StripViewer { | ||
| 321 | 341 | readonly noKey?: true; |
| 322 | 342 | } |
| 323 | 343 | |
| 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 | */ | |
| 325 | 348 | const EVERYDAY_NEED: Need = { says: "You are signed in as the admin. Make an everyday account", href: "/settings/everyday", tone: "notice" }; |
| 326 | 349 | |
| 327 | 350 | /** |
| @@ -365,7 +388,10 @@ function needsOf(picture: LanePicture, viewer: StripViewer, dataDir: string, now | ||
| 365 | 388 | ]; |
| 366 | 389 | } |
| 367 | 390 | |
| 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 | */ | |
| 369 | 395 | function needLine(needs: readonly Need[]): Html { |
| 370 | 396 | if (needs.length === 0) return html`<p class="hf-calm"><span class="dot" data-tone="success"></span>Nothing needs you right now.</p>`; |
| 371 | 397 | const [first, second] = needs; |
| @@ -404,7 +430,10 @@ export function stripRegion(picture: LanePicture, viewer: StripViewer, dataDir: | ||
| 404 | 430 | |
| 405 | 431 | // ---- before the first reading: the same regions, saying so ---- |
| 406 | 432 | |
| 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 | */ | |
| 408 | 437 | function readingLane(key: LaneKey, only: string | null): Html { |
| 409 | 438 | const scope = only === null ? null : html` data-live-repo="${only}"`; |
| 410 | 439 | 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> { | ||
| 474 | 503 | /** Start reading the hosted forges now: the forge calls this once it is listening. */ |
| 475 | 504 | export function warmHome(app: App): void { |
| 476 | 505 | 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. | |
| 478 | 508 | 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); |
| 479 | 509 | warmLanes(app.db, pictureOptions(app), Date.now(), owners); |
| 480 | 510 | void readForges(app, Date.now()); |
| @@ -545,7 +575,10 @@ function filterForm(repos: readonly string[], only: string | null): Html { | ||
| 545 | 575 | </form>`; |
| 546 | 576 | } |
| 547 | 577 | |
| 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 | */ | |
| 549 | 582 | function viewOf(ctx: Ctx): { view: "lanes" | "table"; asked: boolean } { |
| 550 | 583 | const asked = ctx.url.searchParams.get("view"); |
| 551 | 584 | if (asked === "lanes" || asked === "table") return { view: asked, asked: true }; |
| @@ -553,7 +586,9 @@ function viewOf(ctx: Ctx): { view: "lanes" | "table"; asked: boolean } { | ||
| 553 | 586 | } |
| 554 | 587 | const VIEW_COOKIE = "forge_home_view"; |
| 555 | 588 | |
| 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 | */ | |
| 557 | 592 | function viewSwitch(view: "lanes" | "table", only: string | null): Html { |
| 558 | 593 | const keep = only === null ? "" : `&app=${encodeURIComponent(only)}`; |
| 559 | 594 | return html`<nav class="hf-views" aria-label="View"> |
| @@ -562,7 +597,8 @@ function viewSwitch(view: "lanes" | "table", only: string | null): Html { | ||
| 562 | 597 | </nav>`; |
| 563 | 598 | } |
| 564 | 599 | |
| 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. | |
| 566 | 602 | export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited<ReturnType<typeof spawnedForge>> }): Promise<Response> { |
| 567 | 603 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 568 | 604 | const user = ctx.auth.user; |
| @@ -573,7 +609,8 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 573 | 609 | const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx), "page", now)); |
| 574 | 610 | const rendering = performance.now(); |
| 575 | 611 | 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. | |
| 577 | 614 | const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app)); |
| 578 | 615 | const wide = user.isAdmin && spawned === undefined; |
| 579 | 616 | 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 | ||
| 587 | 624 | <div class="hf-tell">${tellBox(ctx, user)}</div>`; |
| 588 | 625 | // A client who asked for the whole home (`?all=1`) has a way back to their apps. |
| 589 | 626 | 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. | |
| 592 | 631 | const stopped = user.kind === "agent" ? null : timePhase(ctx.request, "stopped", () => interruptedOutLine(ctx, listReposWritableTo(ctx.app.db, user, { withoutArchived: true, limit: 200 }))); |
| 593 | 632 | const forges = wide ? await timePhaseAsync(ctx.request, "forges", () => forgesRegion(ctx.app, false)) : null; |
| 594 | 633 | let main: Html; |
| @@ -635,7 +674,8 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 635 | 674 | /** What the rows' states read besides the rows. */ |
| 636 | 675 | const tableInput = (picture: LanePicture, now: number) => ({ now, builders: picture.builders, moved: picture.moved }); |
| 637 | 676 | |
| 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. | |
| 639 | 679 | export async function liveTableFragment(ctx: Ctx): Promise<Response> { |
| 640 | 680 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 641 | 681 | const user = ctx.auth.user; |
| @@ -726,7 +766,8 @@ export async function liveForgesFragment(ctx: Ctx): Promise<Response> { | ||
| 726 | 766 | return res; |
| 727 | 767 | } |
| 728 | 768 | |
| 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. | |
| 730 | 771 | export async function liveFiguresFragment(ctx: Ctx): Promise<Response> { |
| 731 | 772 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 732 | 773 | const user = ctx.auth.user; |
src/web/started_from.ts added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | /** | |
| 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"; | ||
| 83 | 83 | import { spawnedForge } from "../../spawn/claim.ts"; |
| 84 | 84 | import { readableNotes } from "../../actions/desk.ts"; |
| 85 | 85 | import { deskStrip } from "../desk_strip.ts"; |
| 86 | import { startedFromLine } from "../started_from.ts"; | |
| 86 | 87 | import { clientApps } from "./client_home.ts"; |
| 87 | 88 | |
| 88 | 89 | /** The events that can change what is on you. */ |
| @@ -314,7 +315,7 @@ export async function studioHome( | ||
| 314 | 315 | // Before the first tell the card is the one box and carries the key line and the composer. |
| 315 | 316 | const firstTell = steps.some((s) => s.key === "tell" && !s.done); |
| 316 | 317 | 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} | |
| 318 | 319 | <div class="stack"> |
| 319 | 320 | ${firstTell ? null : composer(ctx, user)} |
| 320 | 321 | <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 < 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("<b>"); | |
| 83 | expect(out).not.toContain("<b>"); | |
| 84 | const plain = startedFromHtml(app.db, { name: "<img src=x onerror=1>" }, alice).toString(); | |
| 85 | expect(plain).toContain("<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 | }); |
new above
offline
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.