Public: anyone can read this; the crew can change it.
A forge started from a template names the template and its commit on its settings page #13959
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13946-a-forge-started-from-a-template-names-th → main 6 commits fork 2 threads · 2 unresolved
6 files
changed +52
−17
docs/features/made-from.md +3 −3
| @@ -1,9 +1,9 @@ | ||
| 1 | # Made from (#13038) | |
| 1 | # Started from (#13038) | |
| 2 | 2 | |
| 3 | 3 | A forge made from a template repository remembers which one and at what commit. The record is the `template` entry of its `parent.json` (`{ id, repo, tip }`, written when it is made); a forge made without a template repository, or before this was kept, has none and says nothing. |
| 4 | 4 | |
| 5 | - **Settings:** `/settings` has a `Made from` row, `<owner>/<name> at <short sha>`, in the same list as the Plan row. | |
| 6 | - **Terminal:** the palette entry *Made from* (`src/tui/screens/madefrom.ts`, offered only to a signed-in person and only when the record exists; a guest is told nothing) prints `Made from <template> at <short sha>`. | |
| 5 | - **Settings:** `/settings` has a `Started from` row, `<owner>/<name> at <short sha>`, in the same list as the Plan row. The name links to `/templates/<owner>/<name>` only while that repository is still marked as a template and the viewer can read it; otherwise it is plain text. | |
| 6 | - **Terminal:** the palette entry *Started from* (`src/tui/screens/madefrom.ts`, offered only to a signed-in person and only when the record exists; a guest is told nothing) prints `Started from <template> at <short sha>`. | |
| 7 | 7 | - **Parent's read:** `GET /api/v1/forge` returns `madeFrom: { template, at }` (the full commit) only when the caller shows the parent's secret; anyone else, or a wrong secret, gets no `madeFrom`. |
| 8 | 8 | - **MCP:** the `forges` tool's rows (admin) carry `madeFrom` (`{ template, at }` or null), read from the record the parent wrote; no new tool. |
| 9 | 9 | - **Try it:** make a forge from a template repository, open `/settings`. |
src/spawn/template_record.ts +7 −2
| @@ -41,9 +41,14 @@ export function madeFromOf(dataDir: string): MadeFrom | undefined { | ||
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | /** What a row says after its `Made from` label: `<template> at <short sha>`. */ | |
| 44 | /** The short form of the commit a forge was made at; the one place the length is chosen. */ | |
| 45 | export function shortCommit(at: string): string { | |
| 46 | return at.slice(0, 7); | |
| 47 | } | |
| 48 | ||
| 49 | /** What a row says after its `Started from` label: `<template> at <short sha>`. */ | |
| 45 | 50 | export function madeFromLine(m: MadeFrom): string { |
| 46 | return `${m.template} at ${m.at.slice(0, 7)}`; | |
| 51 | return `${m.template} at ${shortCommit(m.at)}`; | |
| 47 | 52 | } |
| 48 | 53 | |
| 49 | 54 | /** |
src/tui/screens/madefrom.ts +8 −6
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | * Where this forge came from, in the terminal (#13038): the settings page's `Made from` row, from | |
| 3 | * the same record (`madeFromOf`) and the same words (`madeFromLine`). | |
| 2 | * Where this forge came from, in the terminal (#13038): the settings page's `Started from` row, | |
| 3 | * from the same record (`madeFromOf`) and the same words (`madeFromLine`). | |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | import { madeFromLine, madeFromOf } from "../../spawn/template_record.ts"; |
| @@ -10,15 +10,17 @@ import { truncate } from "../term/width.ts"; | ||
| 10 | 10 | import type { Session } from "../session.ts"; |
| 11 | 11 | import type { PaletteEntry } from "./entries.ts"; |
| 12 | 12 | |
| 13 | /** `Made from <template> at <short sha>`; undefined when no template repository made this forge. */ | |
| 13 | /** | |
| 14 | * `Started from <template> at <short sha>`; undefined when no template repository made this forge. | |
| 15 | */ | |
| 14 | 16 | export function madeFromScreenLine(dataDir: string): string | undefined { |
| 15 | 17 | const made = madeFromOf(dataDir); |
| 16 | return made === undefined ? undefined : `Made from ${madeFromLine(made)}`; | |
| 18 | return made === undefined ? undefined : `Started from ${madeFromLine(made)}`; | |
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | export function madeFromScreen(f: Session, ctx: Ctx): Screen { |
| 20 | 22 | return { |
| 21 | title: "Made from", | |
| 23 | title: "Started from", | |
| 22 | 24 | keys: [], |
| 23 | 25 | render(area, s) { |
| 24 | 26 | // The settings page's identity: a guest is told nothing (a template may be private). |
| @@ -36,7 +38,7 @@ export function madeFromScreen(f: Session, ctx: Ctx): Screen { | ||
| 36 | 38 | */ |
| 37 | 39 | export const entry: PaletteEntry = { |
| 38 | 40 | id: "made-from", |
| 39 | title: "Made from", | |
| 41 | title: "Started from", | |
| 40 | 42 | hint: "the template and commit this forge was made from", |
| 41 | 43 | after: ["plan-row"], |
| 42 | 44 | offered: (session) => session.signedIn && madeFromOf(session.app.config.dataDir) !== undefined, |
src/web/pages/account.ts +3 −2
| @@ -86,7 +86,8 @@ import { STOPPED_ONE, myShells, stopIdleShells, stopShell, stoppedIdleSays } fro | ||
| 86 | 86 | import { DOTFILES_ERRORS, dotfilesRepoOf, setDotfilesRepo } from "../../machines/dotfiles.ts"; |
| 87 | 87 | import { billsBlock } from "./bills.ts"; |
| 88 | 88 | import { everydayLine } from "./everyday.ts"; |
| 89 | import { madeFromLine, madeFromOf } from "../../spawn/template_record.ts"; | |
| 89 | import { madeFromOf } from "../../spawn/template_record.ts"; | |
| 90 | import { madeFromHtml } from "../started_from.ts"; | |
| 90 | 91 | import { passkeyJs } from "../passkey-client.ts"; |
| 91 | 92 | import { THEME_NAMES, THEMES, type ThemeName } from "../../design/themes.ts"; |
| 92 | 93 | |
| @@ -591,7 +592,7 @@ export function accountPage(ctx: Ctx): Response { | ||
| 591 | 592 | const rendering = performance.now(); |
| 592 | 593 | const admin = user.isAdmin === true; |
| 593 | 594 | const made = madeFromOf(ctx.app.config.dataDir); |
| 594 | const madeRow = made === undefined ? null : html`<div class="status-row"><dt>Made from</dt><dd>${madeFromLine(made)}</dd></div>`; | |
| 595 | const madeRow = made === undefined ? null : html`<div class="status-row"><dt>Started from</dt><dd>${madeFromHtml(ctx.app.db, made, user)}</dd></div>`; | |
| 595 | 596 | const plan = |
| 596 | 597 | planRow(ctx.app.config.dataDir, parentIssuerOf(ctx.app.config), admin, html`${madeRow}${coresRow(admin, coresLine())}`) ?? |
| 597 | 598 | (madeRow === null ? null : html`<dl class="status-rows">${madeRow}</dl>`); |
src/web/started_from.ts +15 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | import type { Database } from "bun:sqlite"; |
| 9 | 9 | import { canRead, getRepo } from "../core/repos.ts"; |
| 10 | 10 | import type { User } from "../core/users.ts"; |
| 11 | import { startedFromOf, type StartedFrom } from "../spawn/template_record.ts"; | |
| 11 | import { shortCommit, startedFromOf, type MadeFrom, type StartedFrom } from "../spawn/template_record.ts"; | |
| 12 | 12 | import { html, type Html } from "./html.ts"; |
| 13 | 13 | |
| 14 | 14 | /** |
| @@ -37,3 +37,17 @@ export function startedFromText(dataDir: string): string | null { | ||
| 37 | 37 | const from = startedFromOf(dataDir); |
| 38 | 38 | return from === undefined ? null : `Started from ${from.name}`; |
| 39 | 39 | } |
| 40 | ||
| 41 | /** | |
| 42 | * The settings row's value: `<template> at <short id>`, the name linked to the template's page only | |
| 43 | * while that repository is still marked and the viewer can read it. | |
| 44 | */ | |
| 45 | export function madeFromHtml(db: Database, made: MadeFrom, viewer: User | undefined): Html { | |
| 46 | const [owner = "", name = ""] = made.template.split("/"); | |
| 47 | const repo = getRepo(db, owner, name); | |
| 48 | const shown = | |
| 49 | repo !== undefined && repo.template && canRead(db, repo, viewer) | |
| 50 | ? html`<a href="/templates/${repo.ownerName}/${repo.name}">${made.template}</a>` | |
| 51 | : html`${made.template}`; | |
| 52 | return html`${shown} at ${shortCommit(made.at)}`; | |
outdated
The |
||
| 53 | } |
test/spawn-template-record.test.ts +16 −3
| @@ -15,6 +15,7 @@ import { entry as madeFromEntry, madeFromScreenLine } from "../src/tui/screens/m | ||
| 15 | 15 | import { Session } from "../src/tui/forge.ts"; |
| 16 | 16 | import type { User } from "../src/core/users.ts"; |
| 17 | 17 | import { madeFromDoc, madeFromLine, madeFromOf } from "../src/spawn/template_record.ts"; |
| 18 | import { getRepo } from "../src/core/repos.ts"; | |
| 18 | 19 | import { createToken } from "../src/core/tokens.ts"; |
| 19 | 20 | import { createUser } from "../src/core/users.ts"; |
| 20 | 21 | import { createOrg } from "../src/core/orgs.ts"; |
| @@ -104,11 +105,23 @@ describe("a forge remembers its template", () => { | ||
| 104 | 105 | test("shown: a dl row on settings", async () => { |
| 105 | 106 | await record({ id: "alice/kit", repo: "alice/kit", tip: sha }); |
| 106 | 107 | const page = await (await fetch(`${base}/settings`, { headers: auth })).text(); |
| 107 | expect(page).toContain(`<dt>Made from</dt><dd>alice/kit at ${sha.slice(0, 7)}</dd>`); | |
| 108 | expect(page).toContain(`<dt>Started from</dt><dd><a href="/templates/alice/kit">alice/kit</a> at ${sha.slice(0, 7)}</dd>`); | |
| 108 | 109 | expect(page).not.toContain('<p class="muted small">alice/kit'); |
| 109 | 110 | expect(madeFromLine({ template: "alice/kit", at: sha })).toBe(`alice/kit at ${sha.slice(0, 7)}`); |
| 110 | 111 | }); |
| 111 | 112 | |
| 113 | test("not linked once the template is no longer marked, still named", async () => { | |
| 114 | await record({ id: "alice/kit", repo: "alice/kit", tip: sha }); | |
| 115 | const kit = getRepo(app.db, "alice", "kit")!; | |
| 116 | try { | |
| 117 | await updateRepoSettings(app, alice, kit, { template: false }); | |
| 118 | const page = await (await fetch(`${base}/settings`, { headers: auth })).text(); | |
| 119 | expect(page).toContain(`<dt>Started from</dt><dd>alice/kit at ${sha.slice(0, 7)}</dd>`); | |
| 120 | } finally { | |
| 121 | await updateRepoSettings(app, alice, getRepo(app.db, "alice", "kit")!, { template: true }); | |
| 122 | } | |
| 123 | }); | |
| 124 | ||
| 112 | 125 | test("the forge read gives madeFrom to the parent's secret only", async () => { |
| 113 | 126 | await record({ id: "alice/kit", repo: "alice/kit", tip: sha }); |
| 114 | 127 | expect((await forgeRead(secret)).madeFrom).toEqual({ template: "alice/kit", at: sha }); |
| @@ -118,7 +131,7 @@ describe("a forge remembers its template", () => { | ||
| 118 | 131 | |
| 119 | 132 | test("the terminal screen prints the same fact", async () => { |
| 120 | 133 | await record({ id: "alice/kit", repo: "alice/kit", tip: sha }); |
| 121 | expect(madeFromScreenLine(dataDir)).toBe(`Made from alice/kit at ${sha.slice(0, 7)}`); | |
| 134 | expect(madeFromScreenLine(dataDir)).toBe(`Started from alice/kit at ${sha.slice(0, 7)}`); | |
| 122 | 135 | }); |
| 123 | 136 | |
| 124 | 137 | test("the terminal entry is a signed-in person's, as the settings row is: a guest is not offered it", async () => { |
| @@ -135,7 +148,7 @@ describe("a forge remembers its template", () => { | ||
| 135 | 148 | expect(madeFromDoc({ template: { repo: "a/b", tip: "nothex" } })).toBeUndefined(); |
| 136 | 149 | await record({ id: "starter" }); |
| 137 | 150 | const page = await (await fetch(`${base}/settings`, { headers: auth })).text(); |
| 138 | expect(page).not.toContain("Made from"); | |
| 151 | expect(page).not.toContain("Started from"); | |
| 139 | 152 | expect((await forgeRead(secret)).madeFrom).toBeUndefined(); |
| 140 | 153 | expect(madeFromScreenLine(dataDir)).toBeUndefined(); |
| 141 | 154 | }); |
new above
offline
Principle 1/8: the doc is wrong. The terminal now prints
Started from <template> at <short sha>, notMade from. Fix the sentence, and say on the Settings line that the name links to /templates/<owner>/<name> only while the repository is still marked and readable.