From 2a49e51dc9a7ea2133cc46950e9239beb2e47928 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Wed, 29 Jul 2026 00:25:24 -0400 Subject: [PATCH 1/3] Compile agent composition catalog.json at site build. Add a build-time compiler over the component registry, plan stages, npm pins, enrichment edges, and recipe backlog; prerender /catalog.json and point llms.txt at it so agents can fetch dated package facts without inventing versions. --- docs/AGENT_ASSEMBLY_PLAN.md | 25 +-- public/llms.txt | 10 ++ src/data/catalog-enrichment.ts | 235 ++++++++++++++++++++++++++++ src/data/compile-catalog.test.ts | 109 +++++++++++++ src/data/compile-catalog.ts | 195 +++++++++++++++++++++++ src/data/recipe-backlog.ts | 255 +++++++++++++++++++++++++++++++ src/pages/catalog.json.ts | 17 +++ 7 files changed, 837 insertions(+), 9 deletions(-) create mode 100644 src/data/catalog-enrichment.ts create mode 100644 src/data/compile-catalog.test.ts create mode 100644 src/data/compile-catalog.ts create mode 100644 src/data/recipe-backlog.ts create mode 100644 src/pages/catalog.json.ts diff --git a/docs/AGENT_ASSEMBLY_PLAN.md b/docs/AGENT_ASSEMBLY_PLAN.md index 7a6fc6a..a243ae8 100644 --- a/docs/AGENT_ASSEMBLY_PLAN.md +++ b/docs/AGENT_ASSEMBLY_PLAN.md @@ -2,14 +2,13 @@ ## Status -**Stage:** Phase 0 complete (schema + gap inventory + recipe backlog). No -compiled `catalog.json`, hosted skill, MCP surface, or recipe fixture package -exists yet. This document is the working plan for closing the gap between what -AI coding agents tend to do (regenerate common backend functions as bespoke -code) and what the Pegma stack already packages (typed, tested, pin-able -components). +**Stage:** Phase 1 complete (compiled `catalog.json` at site build). No hosted +skill, MCP surface, or recipe fixture package exists yet. This document is the +working plan for closing the gap between what AI coding agents tend to do +(regenerate common backend functions as bespoke code) and what the Pegma stack +already packages (typed, tested, pin-able components). -**Phase 0 artifacts:** +**Phase 0–1 artifacts:** | Artifact | Path | | --- | --- | @@ -17,7 +16,9 @@ components). | Schema documentation | `docs/catalog/SCHEMA.md` | | Registry gap inventory | `docs/catalog/GAP_INVENTORY.md` | | Prioritized recipe backlog | `docs/catalog/RECIPE_BACKLOG.md` | -| Example catalog (illustrative) | `docs/catalog/example-catalog.json` | +| Example catalog (fictional shape sample) | `docs/catalog/example-catalog.json` | +| Catalog compiler | `src/data/compile-catalog.ts` | +| Published catalog | `https://pegma.dev/catalog.json` (build emit) | **Goal:** An agent given a short product description chooses the right `@pegma/*` packages, respects their refusals, and wires them at an explicit @@ -242,7 +243,7 @@ architecture disclosure in any recipe intent. backlog prioritizes P1 `cf-passkey-accounts` and P2 `storage-audit-mail-outbox` (synthetic intents only); deferred recipes gated on unpublished packages. -### Phase 1 — Compiled catalog artifact +### Phase 1 — Compiled catalog artifact ✓ complete Emit `catalog.json` (and optionally generated markdown) at site build or from a small compile step fed by the component registry, plan aggregation, @@ -255,6 +256,12 @@ entire catalog into the index file. **Exit:** an agent can HTTP-fetch a complete, dated composition catalog; unpublished packages are explicitly flagged. +**Done:** `src/pages/catalog.json.ts` prerenders `/catalog.json` via +`compileCompositionCatalog` (registry + plan stage + npm latest pins + +enrichment + recipe backlog). `public/llms.txt` links the catalog without +inlining it. Unpublished packages get `published: false` / `publishUsability: +unpublished|partial`. + ### Phase 2 — Synthetic recipe fixtures Create public, CI-tested fixtures for the highest-value published diff --git a/public/llms.txt b/public/llms.txt index 3507703..77169e5 100644 --- a/public/llms.txt +++ b/public/llms.txt @@ -64,6 +64,16 @@ reference environment. Each repository's docs/PROJECT_PLAN.md is the source of truth for its status, design decisions, and non-goals. +## Composition catalog (agents) + +- [catalog.json](https://pegma.dev/catalog.json): machine-readable composition + catalog — components, exact npm pins when known, owns/refuses, dependencies, + adapters, and synthetic recipe intents. Compiled at site build. Unpublished + packages are flagged (`published: false`, `publishUsability: unpublished`). + Do not invent package versions; fetch this document. +- Schema and recipe backlog (source docs): + https://github.com/pegma-dev/pegma.dev/tree/main/docs/catalog + ## Site - [The stack](https://pegma.dev/stack): every component — owns, refuses, diff --git a/src/data/catalog-enrichment.ts b/src/data/catalog-enrichment.ts new file mode 100644 index 0000000..f242c4c --- /dev/null +++ b/src/data/catalog-enrichment.ts @@ -0,0 +1,235 @@ +/** + * Hand enrichment for composition-catalog fields the registry does not yet + * carry (deps, adapters, hostMustProvide, capability tags). + * + * Status and package versions are compiled (plan stage + npm). These edges are + * curated agent-facing facts; keep them short and refuse-aligned. + */ + +import type { + CapabilityTag, + CatalogAdapter, + CatalogDependency, +} from './catalog-schema'; + +export interface ComponentEnrichment { + readonly dependencies: readonly CatalogDependency[]; + readonly adapters: readonly CatalogAdapter[]; + readonly hostMustProvide: readonly string[]; + readonly capabilityTags: readonly CapabilityTag[]; +} + +/** Keyed by component id (= registry `repo`). */ +export const COMPONENT_ENRICHMENT: Readonly> = { + spine: { + dependencies: [], + adapters: [], + hostMustProvide: [ + 'Composition-root wiring for Clock, Logger, and any in-process bus subscribers', + ], + capabilityTags: ['logging', 'events_in_process'], + }, + 'storage-core': { + dependencies: [ + { componentId: 'spine', kind: 'requires', note: 'Shared contracts and Logger' }, + ], + adapters: [ + { + id: 'memory', + packageName: '@pegma/storage-core', + host: 'memory', + when: 'Tests and local sketches; not a production durability claim', + }, + { + id: 'azure-tables', + packageName: '@pegma/storage-azure-tables', + host: 'azure', + when: 'Azure-hosted apps using the Tables adapter', + }, + { + id: 'cloudflare-d1', + packageName: '@pegma/storage-cloudflare-d1', + host: 'cloudflare', + when: 'Cloudflare Workers/Pages with D1', + }, + ], + hostMustProvide: [ + 'Chosen adapter binding (D1 database, Azure connection, or memory for tests)', + 'Collection declarations and codecs', + ], + capabilityTags: ['storage', 'cloudflare', 'azure'], + }, + 'authorization-core': { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { + componentId: 'storage-core', + kind: 'optional', + note: 'When using storage-backed authorization adapters', + }, + ], + adapters: [], + hostMustProvide: [ + 'Trusted identity/billing facts at the composition root', + 'Policy versioning and permission checks at the HTTP boundary', + ], + capabilityTags: ['authorization'], + }, + audit: { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { + componentId: 'storage-core', + kind: 'requires', + note: 'Audit rows commit inside the caller’s storage transaction', + }, + ], + adapters: [], + hostMustProvide: [ + 'Caller-owned storage transaction that includes the audit TransactionAction', + ], + capabilityTags: ['audit', 'storage'], + }, + 'support-desk': { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { componentId: 'storage-core', kind: 'requires' }, + { componentId: 'mail', kind: 'requires' }, + { componentId: 'authorization-core', kind: 'requires' }, + ], + adapters: [], + hostMustProvide: [ + 'Host runtime and data ownership (not a hosted SaaS)', + 'Mail provider and permission model', + ], + capabilityTags: ['support_queue', 'mail_transactional'], + }, + webhooks: { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { componentId: 'storage-core', kind: 'requires' }, + ], + adapters: [], + hostMustProvide: [ + 'HTTP endpoint and provider signature verification', + 'Storage binding for the receipt ledger', + ], + capabilityTags: ['webhooks_inbound'], + }, + sessions: { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { componentId: 'storage-core', kind: 'requires' }, + ], + adapters: [], + hostMustProvide: [ + 'Authentication (login) at the host', + 'Cookie/session HTTP boundary and CSRF strategy', + ], + capabilityTags: ['sessions'], + }, + mail: { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { + componentId: 'storage-core', + kind: 'requires', + note: 'Outbox jobs live in the caller’s store', + }, + ], + adapters: [], + hostMustProvide: [ + 'Outbox collection in host storage', + 'Provider adapter and delivery worker schedule', + 'DNS for SPF/DKIM/DMARC', + ], + capabilityTags: ['mail_transactional'], + }, + identity: { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { componentId: 'storage-core', kind: 'requires' }, + { componentId: 'sessions', kind: 'requires' }, + { componentId: 'mail', kind: 'composes_with', note: 'Email codes' }, + { + componentId: 'rate-limit', + kind: 'composes_with', + note: 'Durable limits on expensive auth paths', + }, + { + componentId: 'authorization-core', + kind: 'composes_with', + note: 'Identity claims adapter', + }, + ], + adapters: [], + hostMustProvide: [ + 'HTTP routes and cookie boundary', + 'WebAuthn relying-party configuration', + 'Email provider and secrets', + 'Any account UI', + ], + capabilityTags: [ + 'accounts', + 'passkeys', + 'email_codes', + 'sessions', + 'authorization', + 'mail_transactional', + ], + }, + 'rate-limit': { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { + componentId: 'storage-core', + kind: 'optional', + note: 'Required for the durable fixed-window tier', + }, + ], + adapters: [], + hostMustProvide: [ + 'Explicit tier choice (memory vs durable) per path', + 'Storage binding when using the durable tier', + ], + capabilityTags: ['rate_limit_durable', 'rate_limit_memory'], + }, + 'logger-adapters': { + dependencies: [ + { componentId: 'spine', kind: 'requires', note: 'Implements Spine Logger' }, + ], + adapters: [], + hostMustProvide: [ + 'Composition-root Logger wiring (e.g. tee + sink factories)', + 'Vendor credentials/config for chosen sinks', + ], + capabilityTags: ['logging'], + }, + health: { + dependencies: [ + { componentId: 'spine', kind: 'requires' }, + { + componentId: 'storage-core', + kind: 'optional', + note: 'When registering a store ping check', + }, + ], + adapters: [], + hostMustProvide: [ + 'Explicit check registration at the composition root', + 'HTTP route that returns health responses', + ], + capabilityTags: ['health'], + }, +}; + +export function enrichmentFor(componentId: string): ComponentEnrichment { + return ( + COMPONENT_ENRICHMENT[componentId] ?? { + dependencies: [], + adapters: [], + hostMustProvide: [], + capabilityTags: [], + } + ); +} diff --git a/src/data/compile-catalog.test.ts b/src/data/compile-catalog.test.ts new file mode 100644 index 0000000..b95c490 --- /dev/null +++ b/src/data/compile-catalog.test.ts @@ -0,0 +1,109 @@ +import { describe, expect, it } from 'vitest'; +import { + clearNpmVersionCache, + compileCompositionCatalog, +} from './compile-catalog'; +import { CATALOG_SCHEMA_VERSION } from './catalog-schema'; +import { components } from './components'; +import { RECIPE_BACKLOG } from './recipe-backlog'; + +const FIXED_AT = '2026-07-29T00:00:00.000Z'; +/** Empty stage map → no GitHub plan fetches in unit tests. */ +const NO_STAGES: Record = Object.fromEntries( + components.map((c) => [c.repo, null]), +); + +/** Deterministic npm map for tests — never hits the network. */ +function fakeNpm(versions: Record) { + return async (name: string): Promise => + Object.prototype.hasOwnProperty.call(versions, name) ? versions[name]! : null; +} + +function compile(npm: Record) { + return compileCompositionCatalog({ + generatedAt: FIXED_AT, + stageByRepo: NO_STAGES, + npmLookup: fakeNpm(npm), + }); +} + +describe('compileCompositionCatalog', () => { + it('emits schema 0.1.0 with one entry per registry component', async () => { + clearNpmVersionCache(); + const catalog = await compile({ + '@pegma/spine': '0.1.1', + '@pegma/storage-core': '0.4.0', + '@pegma/storage-azure-tables': '0.4.0', + '@pegma/storage-cloudflare-d1': '0.4.0', + '@pegma/health': '0.1.1', + }); + + expect(catalog.schemaVersion).toBe(CATALOG_SCHEMA_VERSION); + expect(catalog.generatedAt).toBe(FIXED_AT); + expect(catalog.components).toHaveLength(components.length); + expect(catalog.recipes).toHaveLength(RECIPE_BACKLOG.length); + }); + + it('flags unpublished packages when npm has no version', async () => { + clearNpmVersionCache(); + const catalog = await compile({ + '@pegma/spine': '0.1.1', + // webhooks and support-desk packages absent → unpublished + }); + + const webhooks = catalog.components.find((c) => c.id === 'webhooks')!; + expect(webhooks.publishUsability).toBe('unpublished'); + expect(webhooks.packages.every((p) => p.published === false)).toBe(true); + expect(webhooks.packages.every((p) => p.version === null)).toBe(true); + + const spine = catalog.components.find((c) => c.id === 'spine')!; + expect(spine.publishUsability).toBe('usable'); + expect(spine.packages[0]).toMatchObject({ + name: '@pegma/spine', + version: '0.1.1', + published: true, + }); + }); + + it('marks partial when only some packages resolve on npm', async () => { + clearNpmVersionCache(); + const catalog = await compile({ + '@pegma/storage-core': '0.4.0', + // azure / d1 missing + }); + const storage = catalog.components.find((c) => c.id === 'storage-core')!; + expect(storage.publishUsability).toBe('partial'); + expect(storage.packages.filter((p) => p.published)).toHaveLength(1); + }); + + it('includes recipe intents without inventing green fixtures', async () => { + clearNpmVersionCache(); + const catalog = await compile({}); + const accounts = catalog.recipes.find((r) => r.id === 'cf-passkey-accounts')!; + expect(accounts.backlogPriority).toBe(1); + expect(accounts.fixture.status).toBe('pending'); + expect(accounts.adapters[0]).toEqual({ + componentId: 'storage-core', + adapterId: 'cloudflare-d1', + }); + for (const recipe of catalog.recipes) { + expect(recipe.intent).not.toMatch(/retiregolden/i); + expect(recipe.fixture.status).not.toBe('green'); + } + }); + + it('attaches enrichment deps and adapters for storage-core', async () => { + clearNpmVersionCache(); + const catalog = await compile({ + '@pegma/storage-core': '0.4.0', + '@pegma/storage-azure-tables': '0.4.0', + '@pegma/storage-cloudflare-d1': '0.4.0', + }); + const storage = catalog.components.find((c) => c.id === 'storage-core')!; + expect(storage.dependencies.some((d) => d.componentId === 'spine')).toBe(true); + expect(storage.adapters.map((a) => a.id)).toEqual( + expect.arrayContaining(['memory', 'azure-tables', 'cloudflare-d1']), + ); + expect(storage.capabilityTags).toContain('storage'); + }); +}); diff --git a/src/data/compile-catalog.ts b/src/data/compile-catalog.ts new file mode 100644 index 0000000..5ab2cc6 --- /dev/null +++ b/src/data/compile-catalog.ts @@ -0,0 +1,195 @@ +/** + * Build-time composition catalog compiler. + * + * Inputs: component registry, plan stage aggregation, npm latest versions, + * hand enrichment, recipe backlog. + * + * Version authority (Phase 0 decision): npm at compile time for package pins. + * Never parse versions from registry `now` prose. Fail soft: missing npm → + * version null + published false. + */ + +import { components, SNAPSHOT_DATE, type ComponentStatus } from './components'; +import { enrichmentFor } from './catalog-enrichment'; +import { RECIPE_BACKLOG } from './recipe-backlog'; +import { compileComponentStatus } from './live-status'; +import { + CATALOG_SCHEMA_VERSION, + type CatalogComponent, + type CatalogComponentStatus, + type CatalogPackage, + type CompositionCatalog, + type PublishUsability, +} from './catalog-schema'; + +export interface NpmVersionLookup { + (packageName: string): Promise; +} + +const npmCache = new Map>(); + +/** Default: fetch latest from the public npm registry (build-time only). */ +export async function fetchNpmLatestVersion( + packageName: string, +): Promise { + let hit = npmCache.get(packageName); + if (!hit) { + hit = (async () => { + try { + const url = `https://registry.npmjs.org/${packageName}/latest`; + const res = await fetch(url, { + cache: 'no-store', + headers: { + Accept: 'application/json', + 'User-Agent': 'pegma-dev-catalog-build', + }, + signal: AbortSignal.timeout(10_000), + }); + if (!res.ok) return null; + const body: unknown = await res.json(); + if ( + body && + typeof body === 'object' && + typeof (body as { version?: unknown }).version === 'string' + ) { + return (body as { version: string }).version; + } + return null; + } catch { + return null; + } + })(); + npmCache.set(packageName, hit); + } + return hit; +} + +/** Test helper — clear npm cache between tests. */ +export function clearNpmVersionCache(): void { + npmCache.clear(); +} + +function mapStatus(status: ComponentStatus): CatalogComponentStatus { + switch (status) { + case 'published': + return 'published'; + case 'in development': + return 'in_development'; + case 'planned': + return 'planned'; + } +} + +function publishUsability(packages: readonly CatalogPackage[]): PublishUsability { + if (packages.length === 0) return 'unpublished'; + const publishedCount = packages.filter((p) => p.published && p.version).length; + if (publishedCount === 0) return 'unpublished'; + if (publishedCount === packages.length) return 'usable'; + return 'partial'; +} + +async function resolvePackages( + names: readonly string[], + lookup: NpmVersionLookup, +): Promise { + const out: CatalogPackage[] = []; + for (const name of names) { + const version = await lookup(name); + const published = version !== null; + out.push({ + name, + version, + published, + ...(published + ? { npmUrl: `https://www.npmjs.com/package/${name}` } + : {}), + }); + } + return out; +} + +export interface CompileCatalogOptions { + readonly npmLookup?: NpmVersionLookup; + readonly generatedAt?: string; + /** + * When set, used instead of live plan fetches (unit tests). + * Values are stage paragraphs or null when the plan is unavailable. + */ + readonly stageByRepo?: Readonly>; +} + +/** + * Compile the full composition catalog for static publish. + */ +export async function compileCompositionCatalog( + options: CompileCatalogOptions = {}, +): Promise { + const npmLookup = options.npmLookup ?? fetchNpmLatestVersion; + const generatedAt = options.generatedAt ?? new Date().toISOString(); + + const compiled = + options.stageByRepo !== undefined + ? components.map((component) => ({ + ...component, + stage: options.stageByRepo![component.repo] ?? null, + // Keep registry status when stages are injected (tests). + status: component.status, + })) + : await Promise.all(components.map(compileComponentStatus)); + const catalogComponents: CatalogComponent[] = []; + + for (const component of compiled) { + const id = component.repo; + const packages = await resolvePackages(component.packages, npmLookup); + const enrichment = enrichmentFor(id); + const usability = publishUsability(packages); + const recipeIds = RECIPE_BACKLOG.filter( + (r) => + r.requiresPublished.includes(id) || + r.packages.some((spec) => + packages.some((p) => spec === p.name || spec.startsWith(`${p.name}@`)), + ), + ).map((r) => r.id); + + const firstPublished = packages.find((p) => p.published)?.name; + + catalogComponents.push({ + id, + title: component.title, + repo: component.repo, + packages, + status: mapStatus(component.status), + publishUsability: usability, + summary: component.summary, + owns: component.owns, + refuses: component.refuses, + dependencies: enrichment.dependencies, + adapters: enrichment.adapters, + hostMustProvide: enrichment.hostMustProvide, + capabilityTags: enrichment.capabilityTags, + recipeIds, + links: { + githubRepo: `https://github.com/pegma-dev/${component.repo}`, + ...(component.plan + ? { + plan: `https://github.com/pegma-dev/${component.repo}/blob/main/${component.plan}`, + } + : {}), + readme: `https://github.com/pegma-dev/${component.repo}#readme`, + ...(firstPublished + ? { npm: `https://www.npmjs.com/package/${firstPublished}` } + : {}), + }, + now: component.now, + ...(component.stage ? { stage: component.stage } : {}), + }); + } + + return { + schemaVersion: CATALOG_SCHEMA_VERSION, + generatedAt, + snapshotDate: SNAPSHOT_DATE, + components: catalogComponents, + recipes: RECIPE_BACKLOG, + }; +} diff --git a/src/data/recipe-backlog.ts b/src/data/recipe-backlog.ts new file mode 100644 index 0000000..032b8e4 --- /dev/null +++ b/src/data/recipe-backlog.ts @@ -0,0 +1,255 @@ +/** + * Prioritized synthetic recipe intents for the compiled catalog. + * Source narrative: docs/catalog/RECIPE_BACKLOG.md + * + * Fixtures are pending until Phase 2; wiring code must not be invented here. + */ + +import type { CatalogRecipe } from './catalog-schema'; + +/** Recipes included in catalog.json (intent metadata; fixtures still pending). */ +export const RECIPE_BACKLOG: readonly CatalogRecipe[] = [ + { + id: 'cf-passkey-accounts', + intent: + 'A small Cloudflare Worker host for a fictional community library (Northshelf Branch) offers first-party accounts: passkey sign-in, email one-time codes for enrollment and recovery, server-side sessions, and durable rate limits on expensive auth paths. No passwords.', + packages: [ + '@pegma/identity', + '@pegma/sessions', + '@pegma/mail', + '@pegma/rate-limit', + '@pegma/authorization-identity', + '@pegma/storage-core', + '@pegma/storage-cloudflare-d1', + '@pegma/spine', + ], + adapters: [{ componentId: 'storage-core', adapterId: 'cloudflare-d1' }], + hostResponsibilities: [ + 'HTTP routes and cookie/session boundary', + 'WebAuthn relying-party configuration', + 'Email provider adapter and DNS', + 'Secrets and any account UI', + ], + nonGoals: [ + 'Social login', + 'OIDC server for third parties', + 'Passwords', + 'Multi-tenant organizations', + ], + antiPatterns: [ + 'Password table or reset flow', + 'Durable events on Spine in-process bus', + 'Mail package owning its own outbox store', + ], + fixture: { + kind: 'pending', + citation: + 'docs/catalog/RECIPE_BACKLOG.md#p1--cf-passkey-accounts-first-end-to-end-accounts-recipe', + status: 'pending', + }, + capabilityTags: [ + 'accounts', + 'passkeys', + 'email_codes', + 'sessions', + 'authorization', + 'mail_transactional', + 'rate_limit_durable', + 'storage', + 'cloudflare', + ], + requiresPublished: [ + 'identity', + 'sessions', + 'mail', + 'rate-limit', + 'authorization-core', + 'storage-core', + 'spine', + ], + backlogPriority: 1, + }, + { + id: 'storage-audit-mail-outbox', + intent: + 'A fictional equipment checkout service (Yard Loan) records inventory mutations in Storage Core and, in the same single-partition transaction, appends an audit row and enqueues a transactional mail delivery job.', + packages: ['@pegma/storage-core', '@pegma/audit', '@pegma/mail', '@pegma/spine'], + adapters: [{ componentId: 'storage-core', adapterId: 'memory' }], + hostResponsibilities: [ + 'Collection declarations', + 'Transaction boundary', + 'Outbox collection in host storage', + 'Mail provider and delivery worker schedule', + ], + nonGoals: [ + 'Mail-owned outbox store', + 'Audit-owned store', + 'Cross-partition transactions', + ], + antiPatterns: [ + 'Send email after commit without an outbox job in the same transaction', + 'Audit write outside the caller transact', + ], + fixture: { + kind: 'pending', + citation: + 'docs/catalog/RECIPE_BACKLOG.md#p2--storage-audit-mail-outbox-storage--auditmail-pattern', + status: 'pending', + }, + capabilityTags: ['storage', 'audit', 'mail_transactional'], + requiresPublished: ['storage-core', 'audit', 'mail', 'spine'], + backlogPriority: 2, + }, + { + id: 'durable-auth-rate-limits', + intent: + 'A fictional API for appointment holds (Chair Queue) applies durable fixed-window rate limits to expensive verification endpoints and an honest in-memory tier only for cheap abuse dampening.', + packages: ['@pegma/rate-limit', '@pegma/storage-core', '@pegma/spine'], + adapters: [], + hostResponsibilities: [ + 'Explicit tier choice per path', + 'Storage binding for durable counters', + ], + nonGoals: ['Volumetric DDoS protection at the app tier'], + antiPatterns: [ + 'Using only in-memory limits for email-code or passkey verify', + 'Calling the memory tier a cluster quota', + ], + fixture: { + kind: 'pending', + citation: 'docs/catalog/RECIPE_BACKLOG.md#p3--durable-auth-rate-limits', + status: 'pending', + }, + capabilityTags: ['rate_limit_durable', 'rate_limit_memory', 'storage'], + requiresPublished: ['rate-limit', 'storage-core', 'spine'], + backlogPriority: 3, + }, + { + id: 'health-public-liveness', + intent: + 'A fictional brochure site Worker exposes a public liveness endpoint composed from @pegma/health probes with checks registered at an explicit composition root.', + packages: ['@pegma/health', '@pegma/spine'], + adapters: [], + hostResponsibilities: [ + 'HTTP health route', + 'Explicit check registration at the composition root', + ], + nonGoals: ['APM, metrics, or alert fan-out'], + antiPatterns: [ + 'Autodiscovery of checks', + 'Health package inventing domain collections', + ], + fixture: { + kind: 'pending', + citation: 'docs/catalog/RECIPE_BACKLOG.md#p4--health-public-liveness', + status: 'pending', + }, + capabilityTags: ['health'], + requiresPublished: ['health', 'spine'], + backlogPriority: 4, + }, + { + id: 'logger-tee-composition', + intent: + 'A fictional batch importer (Ledger Drop) wires Spine Logger once at the composition root through @pegma/logger-tee into Cloudflare Workers Logs.', + packages: [ + '@pegma/spine', + '@pegma/logger-tee', + '@pegma/logger-cloudflare', + ], + adapters: [], + hostResponsibilities: ['Composition-root Logger wiring', 'Sink configuration'], + nonGoals: ['Pegma-owned traces, metrics, or APM'], + antiPatterns: [ + 'Putting sink SDKs into Spine', + 'Replacing Logger with a custom observability core', + ], + fixture: { + kind: 'pending', + citation: 'docs/catalog/RECIPE_BACKLOG.md#p5--logger-tee-composition', + status: 'pending', + }, + capabilityTags: ['logging'], + requiresPublished: ['spine', 'logger-adapters'], + backlogPriority: 5, + }, + { + id: 'static-brochure-minimal', + intent: + 'A fictional static museum site (Glass Wing) needs no accounts, no durable storage, and no mail — teaching agents to select nothing extra.', + packages: [], + adapters: [], + hostResponsibilities: ['Static hosting only'], + nonGoals: ['Accounts, sessions, databases'], + antiPatterns: [ + 'Pulling identity/sessions for later', + 'Inventing a database for a static site', + ], + fixture: { + kind: 'pending', + citation: 'docs/catalog/RECIPE_BACKLOG.md#p6--static-brochure-minimal', + status: 'pending', + }, + capabilityTags: ['static_host'], + requiresPublished: [], + backlogPriority: 6, + }, + { + id: 'inbound-webhook-receipts', + intent: + 'A fictional donation platform (Copper Plate) records inbound provider webhook receipts with idempotent dedup and poison quarantine. Deferred until @pegma/webhooks is published.', + packages: ['@pegma/webhooks', '@pegma/storage-core', '@pegma/spine'], + adapters: [], + hostResponsibilities: [ + 'HTTP endpoint', + 'Provider signature verification', + 'Storage for the receipt ledger', + ], + nonGoals: ['Exactly-once delivery', 'Payload archival in the receipt ledger'], + antiPatterns: [ + 'Claiming exactly-once processing', + 'Storing full webhook bodies in receipts', + ], + fixture: { + kind: 'pending', + citation: + 'docs/catalog/RECIPE_BACKLOG.md#d1--inbound-webhook-receipts-when-pegmawebhooks-is-published', + status: 'none', + }, + capabilityTags: ['webhooks_inbound'], + requiresPublished: ['webhooks', 'storage-core', 'spine'], + backlogPriority: 90, + }, + { + id: 'support-queue-slice', + intent: + 'A fictional maker-space helpdesk (Bench Ticket) runs a composable support queue for web and email. Deferred until Support Desk packages are published.', + packages: [ + '@pegma/support-desk-contracts', + '@pegma/support-desk-core', + '@pegma/support-desk-application', + '@pegma/mail', + '@pegma/storage-core', + '@pegma/spine', + ], + adapters: [], + hostResponsibilities: [ + 'Host runtime and data ownership', + 'Permission model and mail provider', + ], + nonGoals: ['Hosted SaaS Support Desk', 'AI on ticket bodies without documented egress'], + antiPatterns: [ + 'Treating Support Desk as multi-tenant SaaS', + 'AI processing before the host documents what may leave its boundary', + ], + fixture: { + kind: 'pending', + citation: + 'docs/catalog/RECIPE_BACKLOG.md#d2--support-queue-slice-when-support-desk-packages-are-published', + status: 'none', + }, + capabilityTags: ['support_queue', 'mail_transactional'], + requiresPublished: ['support-desk', 'mail', 'storage-core', 'spine'], + backlogPriority: 91, + }, +]; diff --git a/src/pages/catalog.json.ts b/src/pages/catalog.json.ts new file mode 100644 index 0000000..603f283 --- /dev/null +++ b/src/pages/catalog.json.ts @@ -0,0 +1,17 @@ +/** + * Static composition catalog at /catalog.json (built at site build time). + * Agents should HTTP-fetch this URL rather than inventing package sets. + */ +import { compileCompositionCatalog } from '../data/compile-catalog'; + +export const prerender = true; + +export async function GET(): Promise { + const catalog = await compileCompositionCatalog(); + return new Response(JSON.stringify(catalog, null, 2), { + headers: { + 'Content-Type': 'application/json; charset=utf-8', + 'Cache-Control': 'public, max-age=300', + }, + }); +} From 1ab3d3510fedb71811c2369b5bbef7943edcaf1c Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Wed, 29 Jul 2026 00:29:10 -0400 Subject: [PATCH 2/3] Parallelize catalog npm version lookups at build time. Resolve package pins concurrently across components so a slow or flaky registry cannot serialize the static catalog prerender. --- src/data/compile-catalog.test.ts | 7 ++++-- src/data/compile-catalog.ts | 40 +++++++++++++++++++------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/data/compile-catalog.test.ts b/src/data/compile-catalog.test.ts index b95c490..1054239 100644 --- a/src/data/compile-catalog.test.ts +++ b/src/data/compile-catalog.test.ts @@ -15,8 +15,11 @@ const NO_STAGES: Record = Object.fromEntries( /** Deterministic npm map for tests — never hits the network. */ function fakeNpm(versions: Record) { - return async (name: string): Promise => - Object.prototype.hasOwnProperty.call(versions, name) ? versions[name]! : null; + return async (name: string): Promise => { + if (!Object.prototype.hasOwnProperty.call(versions, name)) return null; + const version = versions[name]; + return version === undefined ? null : version; + }; } function compile(npm: Record) { diff --git a/src/data/compile-catalog.ts b/src/data/compile-catalog.ts index 5ab2cc6..af4ea04 100644 --- a/src/data/compile-catalog.ts +++ b/src/data/compile-catalog.ts @@ -92,20 +92,21 @@ async function resolvePackages( names: readonly string[], lookup: NpmVersionLookup, ): Promise { - const out: CatalogPackage[] = []; - for (const name of names) { - const version = await lookup(name); - const published = version !== null; - out.push({ - name, - version, - published, - ...(published - ? { npmUrl: `https://www.npmjs.com/package/${name}` } - : {}), - }); - } - return out; + // Parallel lookups: independent packages must not serialize 10s timeouts. + return Promise.all( + names.map(async (name) => { + const version = await lookup(name); + const published = version !== null; + return { + name, + version, + published, + ...(published + ? { npmUrl: `https://www.npmjs.com/package/${name}` } + : {}), + }; + }), + ); } export interface CompileCatalogOptions { @@ -138,9 +139,16 @@ export async function compileCompositionCatalog( : await Promise.all(components.map(compileComponentStatus)); const catalogComponents: CatalogComponent[] = []; - for (const component of compiled) { + // Resolve every component’s packages concurrently (npm lookups are independent). + const resolved = await Promise.all( + compiled.map(async (component) => { + const packages = await resolvePackages(component.packages, npmLookup); + return { component, packages }; + }), + ); + + for (const { component, packages } of resolved) { const id = component.repo; - const packages = await resolvePackages(component.packages, npmLookup); const enrichment = enrichmentFor(id); const usability = publishUsability(packages); const recipeIds = RECIPE_BACKLOG.filter( From 49c5d814b3b0a0263e0577364f2e5a728a00657b Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Wed, 29 Jul 2026 00:33:27 -0400 Subject: [PATCH 3/3] Do not pin the memory adapter on the durable outbox recipe. storage-audit-mail-outbox needs durable inventory, audit, and outbox rows; leave adapter selection to the host rather than recommending memory. --- src/data/compile-catalog.test.ts | 3 +++ src/data/recipe-backlog.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/data/compile-catalog.test.ts b/src/data/compile-catalog.test.ts index 1054239..3b3adf2 100644 --- a/src/data/compile-catalog.test.ts +++ b/src/data/compile-catalog.test.ts @@ -89,6 +89,9 @@ describe('compileCompositionCatalog', () => { componentId: 'storage-core', adapterId: 'cloudflare-d1', }); + const outbox = catalog.recipes.find((r) => r.id === 'storage-audit-mail-outbox')!; + // Durable pattern: host picks adapter; memory must not be the recipe default. + expect(outbox.adapters).toEqual([]); for (const recipe of catalog.recipes) { expect(recipe.intent).not.toMatch(/retiregolden/i); expect(recipe.fixture.status).not.toBe('green'); diff --git a/src/data/recipe-backlog.ts b/src/data/recipe-backlog.ts index 032b8e4..ca39e29 100644 --- a/src/data/recipe-backlog.ts +++ b/src/data/recipe-backlog.ts @@ -74,10 +74,13 @@ export const RECIPE_BACKLOG: readonly CatalogRecipe[] = [ intent: 'A fictional equipment checkout service (Yard Loan) records inventory mutations in Storage Core and, in the same single-partition transaction, appends an audit row and enqueues a transactional mail delivery job.', packages: ['@pegma/storage-core', '@pegma/audit', '@pegma/mail', '@pegma/spine'], - adapters: [{ componentId: 'storage-core', adapterId: 'memory' }], + // Host chooses a durable storage-core adapter (cloudflare-d1 or azure-tables). + // Do not pin memory here — the recipe needs durable inventory/audit/outbox rows. + adapters: [], hostResponsibilities: [ 'Collection declarations', 'Transaction boundary', + 'Durable storage-core adapter for production (not memory)', 'Outbox collection in host storage', 'Mail provider and delivery worker schedule', ],