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

Merged opened this

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

Merged

scout/forge:scout/13946-a-forge-started-from-a-template-names-th → main 6 commits fork 2 threads · 2 unresolved

  • Merged. scout/13946-a-forge-started-from-a-template-names-th was merged into main as 4f0767d.

Review

Sign in to review this change.
6 files changed +52 −17
docs/features/made-from.md +3 −3
@@ -1,9 +1,9 @@
1 # Made from (#13038)
1 # Started from (#13038)
22
33 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.
44
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>`.
outdated

Principle 1/8: the doc is wrong. The terminal now prints Started from <template> at <short sha>, not Made 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.

77 - **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`.
88 - **MCP:** the `forges` tool's rows (admin) carry `madeFrom` (`{ template, at }` or null), read from the record the parent wrote; no new tool.
99 - **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 {
4141 }
4242 }
4343
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>`. */
4550 export function madeFromLine(m: MadeFrom): string {
46 return `${m.template} at ${m.at.slice(0, 7)}`;
51 return `${m.template} at ${shortCommit(m.at)}`;
4752 }
4853
4954 /**
src/tui/screens/madefrom.ts +8 −6
@@ -1,6 +1,6 @@
11 /**
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`).
44 */
55
66 import { madeFromLine, madeFromOf } from "../../spawn/template_record.ts";
@@ -10,15 +10,17 @@ import { truncate } from "../term/width.ts";
1010 import type { Session } from "../session.ts";
1111 import type { PaletteEntry } from "./entries.ts";
1212
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 */
1416 export function madeFromScreenLine(dataDir: string): string | undefined {
1517 const made = madeFromOf(dataDir);
16 return made === undefined ? undefined : `Made from ${madeFromLine(made)}`;
18 return made === undefined ? undefined : `Started from ${madeFromLine(made)}`;
1719 }
1820
1921 export function madeFromScreen(f: Session, ctx: Ctx): Screen {
2022 return {
21 title: "Made from",
23 title: "Started from",
2224 keys: [],
2325 render(area, s) {
2426 // 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 {
3638 */
3739 export const entry: PaletteEntry = {
3840 id: "made-from",
39 title: "Made from",
41 title: "Started from",
4042 hint: "the template and commit this forge was made from",
4143 after: ["plan-row"],
4244 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
8686 import { DOTFILES_ERRORS, dotfilesRepoOf, setDotfilesRepo } from "../../machines/dotfiles.ts";
8787 import { billsBlock } from "./bills.ts";
8888 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";
9091 import { passkeyJs } from "../passkey-client.ts";
9192 import { THEME_NAMES, THEMES, type ThemeName } from "../../design/themes.ts";
9293
@@ -591,7 +592,7 @@ export function accountPage(ctx: Ctx): Response {
591592 const rendering = performance.now();
592593 const admin = user.isAdmin === true;
593594 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>`;
595596 const plan =
596597 planRow(ctx.app.config.dataDir, parentIssuerOf(ctx.app.config), admin, html`${madeRow}${coresRow(admin, coresLine())}`) ??
597598 (madeRow === null ? null : html`<dl class="status-rows">${madeRow}</dl>`);
src/web/started_from.ts +15 −1
@@ -8,7 +8,7 @@
88 import type { Database } from "bun:sqlite";
99 import { canRead, getRepo } from "../core/repos.ts";
1010 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";
1212 import { html, type Html } from "./html.ts";
1313
1414 /**
@@ -37,3 +37,17 @@ export function startedFromText(dataDir: string): string | null {
3737 const from = startedFromOf(dataDir);
3838 return from === undefined ? null : `Started from ${from.name}`;
3939 }
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 <template> at <short id> phrasing and the 7-char slice duplicate madeFromLine in template_record.ts. Share one source so the page and the terminal cannot disagree.

53 }
test/spawn-template-record.test.ts +16 −3
@@ -15,6 +15,7 @@ import { entry as madeFromEntry, madeFromScreenLine } from "../src/tui/screens/m
1515 import { Session } from "../src/tui/forge.ts";
1616 import type { User } from "../src/core/users.ts";
1717 import { madeFromDoc, madeFromLine, madeFromOf } from "../src/spawn/template_record.ts";
18 import { getRepo } from "../src/core/repos.ts";
1819 import { createToken } from "../src/core/tokens.ts";
1920 import { createUser } from "../src/core/users.ts";
2021 import { createOrg } from "../src/core/orgs.ts";
@@ -104,11 +105,23 @@ describe("a forge remembers its template", () => {
104105 test("shown: a dl row on settings", async () => {
105106 await record({ id: "alice/kit", repo: "alice/kit", tip: sha });
106107 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>`);
108109 expect(page).not.toContain('<p class="muted small">alice/kit');
109110 expect(madeFromLine({ template: "alice/kit", at: sha })).toBe(`alice/kit at ${sha.slice(0, 7)}`);
110111 });
111112
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
112125 test("the forge read gives madeFrom to the parent's secret only", async () => {
113126 await record({ id: "alice/kit", repo: "alice/kit", tip: sha });
114127 expect((await forgeRead(secret)).madeFrom).toEqual({ template: "alice/kit", at: sha });
@@ -118,7 +131,7 @@ describe("a forge remembers its template", () => {
118131
119132 test("the terminal screen prints the same fact", async () => {
120133 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)}`);
122135 });
123136
124137 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", () => {
135148 expect(madeFromDoc({ template: { repo: "a/b", tip: "nothex" } })).toBeUndefined();
136149 await record({ id: "starter" });
137150 const page = await (await fetch(`${base}/settings`, { headers: auth })).text();
138 expect(page).not.toContain("Made from");
151 expect(page).not.toContain("Started from");
139152 expect((await forgeRead(secret)).madeFrom).toBeUndefined();
140153 expect(madeFromScreenLine(dataDir)).toBeUndefined();
141154 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs