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

A global component registry (shadcn registry format): every app installs owned copies, updates arrive as pulls, a gallery with usage, MCP install; the app template rebuilt on it #16959

Merged opened this in answer to

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

Merged

scout/forge:scout/6009-a-global-component-registry-shadcn-regis → main 0 commits fork

  • Merged. scout/6009-a-global-component-registry-shadcn-regis was merged into main as fe0dfb9.

Review

Sign in to review this change.
13 files changed +315 −31
docs/features/component-registry.md added +15
@@ -0,0 +1,15 @@
1 ---
2 topic: Your apps
3 row: The component registry: install the forge's parts into an app
4 ---
5 # The component registry
6
7 The forge serves its parts in shadcn's registry format (#6009). `/r/registry.json` lists them; `/r/<name>.json` is one item with its source whole. Public, no sign-in yet.
8
9 bunx shadcn add https://<this forge>/r/button.json
10
11 The source is copied into the app, which owns it. Items: `tokens` (colours and radius, light and dark), `button`, `empty-state`.
12
13 From a terminal: `curl <this forge>/r/registry.json`.
14
15 Not yet: private items, recording which app has which version, update pulls, the gallery, MCP install.
src/contract/openapi/routes/getRNameJson.ts added +12
@@ -0,0 +1,12 @@
1 import type { Route } from "../shared.ts";
2
3 export const route: Route = {
4 method: "get",
5 path: "/r/{name}.json",
6 summary: "A component of the forge's registry, in shadcn's registry-item format",
7 detail: "The registry item `name` (tokens, button or empty-state) as shadcn's registry-item JSON, for `bunx shadcn add <origin>/r/<name>.json`; public and cacheable. An unknown name is a 404",
8 auth: false,
9 role: "anonymous",
10 refusals: { not_found: "404: no registry item has that name" },
11 errorStatus: { 404: "`not_found`: no registry item has that name" },
12 };
src/contract/openapi/routes/index.ts +1
@@ -288,6 +288,7 @@ export { route as getHealth } from "./getHealth.ts";
288288 export { route as getMetrics } from "./getMetrics.ts";
289289 export { route as getOembed } from "./getOembed.ts";
290290 export { route as getOwnerNamePullsNumberCheckTxt } from "./getOwnerNamePullsNumberCheckTxt.ts";
291 export { route as getRNameJson } from "./getRNameJson.ts";
291292 export { route as getWellKnownMcpServerCardJson } from "./getWellKnownMcpServerCardJson.ts";
292293 export { route as patchApiV1AdminSettings } from "./patchApiV1AdminSettings.ts";
293294 export { route as patchApiV1AgentsUsername } from "./patchApiV1AgentsUsername.ts";
src/contract/tags.ts +1
@@ -141,6 +141,7 @@ export const TAG_WORDS: Readonly<Record<string, string>> = {
141141 milestones: "Milestones and watching them",
142142 plan: "A repository's vision, statement, roadmap, iterations and waves",
143143 prompts: "Saved prompts and running them",
144 r: "The component registry: the forge's parts as shadcn registry items",
144145 pulls: "Pull requests: reviews, threads, checks, looks, merging and holding",
145146 repos: "A repository: its record, branches, commits, contents, tags, origin and transfer",
146147 reports: "Reports filed on a repository and their triage",
src/core/reserved.ts +1
@@ -33,6 +33,7 @@ export const SYSTEM_NAMES: readonly string[] = [
3333 "platform",
3434 "forge",
3535 "crew",
36 "r",
3637 "agent",
3738 "agents",
3839 "privacy",
src/generated/marks.ts +33 −31
@@ -167,37 +167,38 @@ import k162 from "../http/marks/pipeline.json";
167167 import k163 from "../http/marks/plugins.json";
168168 import k164 from "../http/marks/pricing.json";
169169 import k165 from "../http/marks/privacy.json";
170 import k166 from "../http/marks/recover.json";
171 import k167 from "../http/marks/releases.json";
172 import k168 from "../http/marks/releases.json.json";
173 import k169 from "../http/marks/repos.json";
174 import k170 from "../http/marks/resilience.json";
175 import k171 from "../http/marks/review.json";
176 import k172 from "../http/marks/robots.txt.json";
177 import k173 from "../http/marks/root.json";
178 import k174 from "../http/marks/runs.json";
179 import k175 from "../http/marks/script-error.json";
180 import k176 from "../http/marks/search.json";
181 import k177 from "../http/marks/security.json";
182 import k178 from "../http/marks/settings.json";
183 import k179 from "../http/marks/sign-in.json";
184 import k180 from "../http/marks/signin.json";
185 import k181 from "../http/marks/signup.json";
186 import k182 from "../http/marks/sitemap.xml.json";
187 import k183 from "../http/marks/status.json";
188 import k184 from "../http/marks/sw.js.json";
189 import k185 from "../http/marks/system.json";
190 import k186 from "../http/marks/talk.json";
191 import k187 from "../http/marks/tell.json";
192 import k188 from "../http/marks/templates.json";
193 import k189 from "../http/marks/templates.json.json";
194 import k190 from "../http/marks/terms.json";
195 import k191 from "../http/marks/theme.json";
196 import k192 from "../http/marks/toolbar-lab.js.json";
197 import k193 from "../http/marks/toolbar-lab.json";
198 import k194 from "../http/marks/verify.json";
199 import k195 from "../http/marks/welcome.json";
200 import k196 from "../http/marks/well-known.json";
170 import k166 from "../http/marks/r.json";
171 import k167 from "../http/marks/recover.json";
172 import k168 from "../http/marks/releases.json";
173 import k169 from "../http/marks/releases.json.json";
174 import k170 from "../http/marks/repos.json";
175 import k171 from "../http/marks/resilience.json";
176 import k172 from "../http/marks/review.json";
177 import k173 from "../http/marks/robots.txt.json";
178 import k174 from "../http/marks/root.json";
179 import k175 from "../http/marks/runs.json";
180 import k176 from "../http/marks/script-error.json";
181 import k177 from "../http/marks/search.json";
182 import k178 from "../http/marks/security.json";
183 import k179 from "../http/marks/settings.json";
184 import k180 from "../http/marks/sign-in.json";
185 import k181 from "../http/marks/signin.json";
186 import k182 from "../http/marks/signup.json";
187 import k183 from "../http/marks/sitemap.xml.json";
188 import k184 from "../http/marks/status.json";
189 import k185 from "../http/marks/sw.js.json";
190 import k186 from "../http/marks/system.json";
191 import k187 from "../http/marks/talk.json";
192 import k188 from "../http/marks/tell.json";
193 import k189 from "../http/marks/templates.json";
194 import k190 from "../http/marks/templates.json.json";
195 import k191 from "../http/marks/terms.json";
196 import k192 from "../http/marks/theme.json";
197 import k193 from "../http/marks/toolbar-lab.js.json";
198 import k194 from "../http/marks/toolbar-lab.json";
199 import k195 from "../http/marks/verify.json";
200 import k196 from "../http/marks/welcome.json";
201 import k197 from "../http/marks/well-known.json";
201202
202203 /** Each file of `http/marks/`, parsed, in name order. */
203204 export const MARK_FILES: readonly unknown[] = [
@@ -398,4 +399,5 @@ export const MARK_FILES: readonly unknown[] = [
398399 k194,
399400 k195,
400401 k196,
402 k197,
401403 ];
src/http/marks/r.json added +4
@@ -0,0 +1,4 @@
1 {
2 "head": "/r",
3 "mark": "open"
4 }
src/http/server.ts +4
@@ -5,6 +5,7 @@
55 * verdict. Auth is resolved once per request and handed to handlers as data.
66 */
77
8 import { registryItem } from "../registry/serve.ts";
89 import { forgeTemplateUpdate } from "../web/pages/forge-template-setting.ts";
910 import { gamesRoutes } from "./games_routes.ts";
1011 import { allocationMove, allocationPage, allocationWeekly } from "../web/pages/allocation.ts";
@@ -917,6 +918,9 @@ export function buildRouter(): Router<Handler> {
917918 router.add("GET", "/agents", agentsPage);
918919 router.add("GET", "/.well-known/change-password", changePassword);
919920 router.add("GET", "/robots.txt", robotsTxt);
921 // The component registry in shadcn's format, for `bunx shadcn add <origin>/r/<name>.json`
922 // (#6009).
923 router.add("GET", "/r/:name.json", registryItem);
920924 // A stand-in app with fixed bars under the toolbar, photographed by the looks (#16310).
921925 router.add("GET", TOOLBAR_LAB_PATH, (ctx) => toolbarLabPage(new URL(ctx.request.url)));
922926 router.add("GET", TOOLBAR_LAB_SCRIPT_PATH, () => toolbarLabScript());
src/registry/items.ts added +154
@@ -0,0 +1,154 @@
1 /**
2 * The forge's component registry (#6009), in shadcn's registry format: `registry.json` lists items,
3 * each `registry-item.json` carries its files' source whole, so `bunx shadcn add <url>` copies the
4 * source into an app, which then owns it. Three items to begin with: the design tokens, a button
5 * and an empty state. Plain data in, plain data out; `serve.ts` answers with it.
6 */
7
8 export const SCHEMA_ITEM = "https://ui.shadcn.com/schema/registry-item.json";
9 export const SCHEMA_REGISTRY = "https://ui.shadcn.com/schema/registry.json";
10
11 export interface RegistryFile {
12 path: string;
13 type: "registry:file" | "registry:ui" | "registry:style";
14 target: string;
15 content: string;
16 }
17
18 export interface RegistryItem {
19 $schema: string;
20 name: string;
21 type: "registry:style" | "registry:ui" | "registry:block";
22 title: string;
23 description: string;
24 registryDependencies?: string[];
25 cssVars?: { light: Record<string, string>; dark: Record<string, string> };
26 files: RegistryFile[];
27 }
28
29 const TOKENS_CSS = `:root {
30 --forge-bg: #ffffff;
31 --forge-fg: #14171a;
32 --forge-muted: #5c6670;
33 --forge-line: #d9dee3;
34 --forge-brand: #e5531b;
35 --forge-brand-fg: #ffffff;
36 --forge-radius: 8px;
37 }
38 @media (prefers-color-scheme: dark) {
39 :root {
40 --forge-bg: #101316;
41 --forge-fg: #eef1f3;
42 --forge-muted: #9aa5af;
43 --forge-line: #2a3037;
44 --forge-brand: #ff7a45;
45 --forge-brand-fg: #101316;
46 }
47 }
48 `;
49
50 const BUTTON_TS = `/** A button or a link that looks like one. Every string is escaped; the caller passes text, never markup. */
51 export function esc(text: string): string {
52 return text.replace(/[&<>"']/g, (c) => \`&#\${c.charCodeAt(0)};\`);
53 }
54
55 export interface ButtonOptions {
56 href?: string;
57 primary?: boolean;
58 type?: "button" | "submit";
59 }
60
61 export function button(label: string, o: ButtonOptions = {}): string {
62 const cls = o.primary ? "btn btn-primary" : "btn";
63 if (o.href !== undefined) return \`<a class="\${cls}" href="\${esc(o.href)}">\${esc(label)}</a>\`;
64 return \`<button class="\${cls}" type="\${o.type ?? "button"}">\${esc(label)}</button>\`;
65 }
66 `;
67
68 const BUTTON_CSS = `.btn {
69 display: inline-flex; align-items: center; justify-content: center;
70 min-height: 40px; padding: 0 16px; border-radius: var(--forge-radius);
71 border: 1px solid var(--forge-line); background: var(--forge-bg); color: var(--forge-fg);
72 font: inherit; text-decoration: none; cursor: pointer;
73 }
74 .btn:focus-visible { outline: 2px solid var(--forge-brand); outline-offset: 2px; }
75 .btn-primary { background: var(--forge-brand); border-color: var(--forge-brand); color: var(--forge-brand-fg); }
76 `;
77
78 const EMPTY_TS = `import { button, esc } from "./button.ts";
79
80 /** What a page says when there is nothing yet: what this is, and the one thing to do first. */
81 export function emptyState(o: { title: string; hint: string; action?: { label: string; href: string } }): string {
82 const act = o.action ? button(o.action.label, { href: o.action.href, primary: true }) : "";
83 return \`<section class="empty"><h2>\${esc(o.title)}</h2><p>\${esc(o.hint)}</p>\${act}</section>\`;
84 }
85 `;
86
87 const EMPTY_CSS = `.empty { display: grid; justify-items: center; gap: 12px; padding: 48px 16px; text-align: center; }
88 .empty h2 { margin: 0; font-size: 1.25rem; }
89 .empty p { margin: 0; max-width: 32rem; color: var(--forge-muted); }
90 `;
91
92 const file = (path: string, content: string, type: RegistryFile["type"] = "registry:ui"): RegistryFile => ({
93 path,
94 type,
95 target: path,
96 content,
97 });
98
99 export const ITEMS: readonly RegistryItem[] = [
100 {
101 $schema: SCHEMA_ITEM,
102 name: "tokens",
103 type: "registry:style",
104 title: "Forge design tokens",
105 description: "The forge's colours and radius as CSS variables, light and dark.",
106 cssVars: {
107 light: { "forge-bg": "#ffffff", "forge-fg": "#14171a", "forge-brand": "#e5531b" },
108 dark: { "forge-bg": "#101316", "forge-fg": "#eef1f3", "forge-brand": "#ff7a45" },
109 },
110 files: [file("styles/forge-tokens.css", TOKENS_CSS, "registry:style")],
111 },
112 {
113 $schema: SCHEMA_ITEM,
114 name: "button",
115 type: "registry:ui",
116 title: "Button",
117 description: "A button or link-button, primary or plain, with escaped text.",
118 registryDependencies: ["tokens"],
119 files: [file("ui/button.ts", BUTTON_TS), file("ui/button.css", BUTTON_CSS, "registry:style")],
120 },
121 {
122 $schema: SCHEMA_ITEM,
123 name: "empty-state",
124 type: "registry:block",
125 title: "Empty state",
126 description: "Says what the page is and the one thing to do first.",
127 registryDependencies: ["tokens", "button"],
128 files: [file("ui/empty-state.ts", EMPTY_TS), file("ui/empty-state.css", EMPTY_CSS, "registry:style")],
129 },
130 ];
131
132 /** The item named, or undefined. Names are looked up, never built into a path. */
133 export function findItem(name: string): RegistryItem | undefined {
134 return ITEMS.find((i) => i.name === name);
135 }
136
137 /**
138 * The item as served: its bare dependency names made the absolute URLs shadcn resolves from a URL
139 * install.
140 */
141 export function servedItem(item: RegistryItem, origin: string): RegistryItem {
142 if (!item.registryDependencies) return item;
143 return { ...item, registryDependencies: item.registryDependencies.map((d) => `${origin}/r/${d}.json`) };
144 }
145
146 /** `registry.json`: the index, without file contents, as shadcn's schema has it. */
147 export function registryIndex(origin: string): Record<string, unknown> {
148 return {
149 $schema: SCHEMA_REGISTRY,
150 name: "forge",
151 homepage: origin,
152 items: ITEMS.map((i) => servedItem(i, origin)).map(({ $schema: _s, files, ...rest }) => ({ ...rest, files: files.map(({ content: _c, ...f }) => f) })),
153 };
154 }
src/registry/serve.ts added +27
@@ -0,0 +1,27 @@
1 /**
2 * GET /r/<name>.json: the registry's items (#6009), public, immutable per deploy, never a path from
3 * the name.
4 */
5 import type { Ctx } from "../http/context.ts";
6 import { ITEMS, findItem, registryIndex, servedItem } from "./items.ts";
7
8 const NAME = /^[a-z0-9][a-z0-9-]{0,40}$/;
9
10 function json(body: unknown, status = 200): Response {
11 return new Response(JSON.stringify(body, null, 2) + "\n", {
12 status,
13 headers: {
14 "content-type": "application/json; charset=utf-8",
15 "cache-control": status === 200 ? "public, max-age=300" : "no-store",
16 "access-control-allow-origin": "*",
17 },
18 });
19 }
20
21 export function registryItem(ctx: Pick<Ctx, "params" | "url">): Response {
22 const name = ctx.params["name"] ?? "";
23 if (name === "registry") return json(registryIndex(ctx.url.origin));
24 const item = NAME.test(name) ? findItem(name) : undefined;
25 if (!item) return json({ error: "not_found", hint: "Fetch /r/registry.json for the names of the items.", items: ITEMS.map((i) => i.name) }, 404);
26 return json(servedItem(item, ctx.url.origin));
27 }
test/egress-literals.test.ts +1
@@ -34,6 +34,7 @@ const NOT_CALLED: Record<string, string> = {
3434 "forge.open-platform.sh": "the upstream repository's link (core/upstream.ts) and a link-relation URI (apps/proxy.ts)",
3535 "git.open-platform.sh": "placeholder in the follow-upstream form",
3636 "jsonfeed.org": "the JSON Feed version URI, a name and not a request",
37 "ui.shadcn.com": "the registry schema URIs in registry/items.ts, names the shadcn CLI reads and the forge never requests",
3738 "ntfy.sh": "placeholder in the account notification field",
3839 "schema.org": "the JSON-LD @context, a name and not a request",
3940 "specification.website": "section links in release and preview reports",
test/openapi-drift.test.ts +1
@@ -19,6 +19,7 @@ const NOT_ROUTED: Readonly<Record<string, string>> = {
1919 "GET /oembed": "routed outside /api/v1 (src/http/server.ts, web/standards.ts): the oEmbed endpoint other tools discover from a page's head",
2020 "GET /explore.json": "routed outside /api/v1 (src/http/server.ts, explore_json.ts): the explore page's own JSON form (#15744)",
2121 "POST /api/{}/envelope": "routed outside /api/v1 (src/http/error_envelope.ts): the door a stock Sentry SDK posts to, keyed by the app id (#6003)",
22 "GET /r/{}.json": "routed outside /api/v1 (src/http/server.ts, registry/serve.ts): the component registry shadcn reads (#6009)",
2223 };
2324 const NOT_DESCRIBED: Readonly<Record<string, string>> = {};
2425
test/registry.test.ts added +61
@@ -0,0 +1,61 @@
1 import { Database } from "bun:sqlite";
2 import { reservedName } from "../src/core/reserved.ts";
3 import { expect, test } from "bun:test";
4 import { ITEMS, findItem, registryIndex, SCHEMA_ITEM } from "../src/registry/items.ts";
5 import { registryItem } from "../src/registry/serve.ts";
6
7 const ask = (name: string): Response =>
8 registryItem({ params: { name }, url: new URL(`https://forge.test/r/${name}.json`) });
9
10 test("three items in shadcn's item schema, each with source", () => {
11 expect(ITEMS.map((i) => i.name)).toEqual(["tokens", "button", "empty-state"]);
12 for (const i of ITEMS) {
13 expect(i.$schema).toBe(SCHEMA_ITEM);
14 expect(i.files.length).toBeGreaterThan(0);
15 for (const f of i.files) expect(f.content.length).toBeGreaterThan(20);
16 }
17 });
18
19 test("served dependencies are absolute URLs that resolve to items", async () => {
20 let seen = 0;
21 for (const i of ITEMS) {
22 const served = (await ask(i.name).json()) as { registryDependencies?: string[] };
23 for (const d of served.registryDependencies ?? []) {
24 seen++;
25 const u = new URL(d);
26 expect(u.origin).toBe("https://forge.test");
27 const m = /^\/r\/([a-z0-9-]+)\.json$/.exec(u.pathname);
28 expect(m).not.toBeNull();
29 expect(findItem(m![1]!)).toBeDefined();
30 }
31 }
32 expect(seen).toBe(3);
33 const idx = registryIndex("https://forge.test") as { items: { registryDependencies?: string[] }[] };
34 expect(idx.items[1]!.registryDependencies).toEqual(["https://forge.test/r/tokens.json"]);
35 });
36
37 test("r is a reserved name, so no account or repository can take /r", () => {
38 expect(reservedName(new Database(":memory:"), "r")).toBe("system");
39 });
40
41 test("the index lists items without file contents", () => {
42 const idx = registryIndex("https://forge.test") as { items: { files: object[] }[] };
43 expect(idx.items).toHaveLength(3);
44 expect(JSON.stringify(idx)).not.toContain("content");
45 });
46
47 test("served: an item, the index, a miss and a hostile name", async () => {
48 const ok = ask("button");
49 expect(ok.status).toBe(200);
50 expect(ok.headers.get("content-type")).toContain("application/json");
51 expect(((await ok.json()) as { name: string }).name).toBe("button");
52 expect(((await ask("registry").json()) as { items: unknown[] }).items).toHaveLength(3);
53 expect(ask("nope").status).toBe(404);
54 expect(ask("../../etc/passwd").status).toBe(404);
55 });
56
57 test("the button's source escapes its text", async () => {
58 const js = new Bun.Transpiler({ loader: "ts" }).transformSync(findItem("button")!.files[0]!.content);
59 const mod = (await import(`data:text/javascript;base64,${btoa(js)}`)) as { button: (l: string) => string };
60 expect(mod.button("<b>")).not.toContain("<b>");
61 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs