Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions docs/AGENT_ASSEMBLY_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

## Status

**Stage:** Planning. No catalog schema, hosted skill, MCP surface, or recipe
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 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).

**Phase 0 artifacts:**

| Artifact | Path |
| --- | --- |
| TypeScript schema | `src/data/catalog-schema.ts` |
| 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` |

**Goal:** An agent given a short product description chooses the right
`@pegma/*` packages, respects their refusals, and wires them at an explicit
Expand Down Expand Up @@ -215,7 +226,7 @@ recipe fixture, not a branded product clone.

## Phased delivery

### Phase 0 — Catalog schema and gap inventory ✓-ready to start
### Phase 0 — Catalog schema and gap inventory ✓ complete

Define the catalog schema (TypeScript types + example JSON) in this repo or
a small public agent-facing package. Inventory current registry fields vs.
Expand All @@ -226,6 +237,11 @@ rate-limit, authorization-identity, health, logger adapters, audit).
**Exit:** schema documented; recipe backlog prioritized; no production
architecture disclosure in any recipe intent.

**Done:** schema 0.1.0 in `src/data/catalog-schema.ts` with docs under
`docs/catalog/`; gap inventory maps `PegmaComponent` → catalog fields; recipe
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

Emit `catalog.json` (and optionally generated markdown) at site build or
Expand Down Expand Up @@ -343,17 +359,23 @@ Pegma’s scope:

## Open questions

- **Catalog compile home:** site build only vs. small shared package used
by site and MCP.
- **Version authority:** registry snapshot vs. release-projection Store vs.
npm at compile time (or a combination with clear precedence).
- **Recipe repo layout:** monorepo fixtures vs. one examples repository.
- **`plan_composition` input shape:** free text tags vs. structured
capability flags (structured is easier to keep deterministic).
Phase 0 recommendations (not irreversible) are recorded in
`docs/catalog/GAP_INVENTORY.md` under “Decisions locked for Phase 1 compile.”

- **Catalog compile home:** ~~site build only vs. small shared package~~ →
**prefer site build first**; extract a package only if MCP cannot fetch the
static catalog cleanly.
- **Version authority:** ~~registry prose vs Store vs npm~~ → **precedence:**
release-projection Store when present → npm at compile time → else
`version: null` / unpublished (never parse versions from `now` prose).
- **Recipe repo layout:** monorepo fixtures vs. one examples repository
(still open for Phase 2; backlog citations are layout-agnostic).
- **`plan_composition` input shape:** ~~free text vs structured~~ →
**structured `capabilityTags`** (see schema).
- **Skill packaging:** single canonical markdown vs. thin per-tool wrappers
that only differ in install paths.
that only differ in install paths. (Phase 3)
- **MCP hosting:** extend `pegma-dev-api` vs. separate Worker to keep the
account API’s privilege surface small.
account API’s privilege surface small. (Phase 4)

## Implementation note

Expand Down
92 changes: 92 additions & 0 deletions docs/catalog/GAP_INVENTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Catalog gap inventory

Compares the human-facing component registry
([`src/data/components.ts`](../../src/data/components.ts)) and related site
surfaces against the composition catalog schema
([`SCHEMA.md`](./SCHEMA.md), [`catalog-schema.ts`](../../src/data/catalog-schema.ts)).

**Date:** 2026-07-28 · **Schema:** 0.1.0 · **Registry snapshot:** 2026-07-28 (`SNAPSHOT_DATE` in `components.ts`)

## Registry fields today (`PegmaComponent`)

| Field | Present | Catalog destination | Gap |
| --- | --- | --- | --- |
| `repo` | yes | `id` + `repo` | No separate stable `id` field (today `repo` is the id) |
| `title` | yes | `title` | — |
| `packages` | yes (`string[]`) | `packages[]` with version/published | No per-package version or publish flag |
| `status` | yes | `status` | Hand-maintained only — **do not trust as sole authority** (see below); also no `publishUsability` aggregate |
| `summary` | yes | `summary` | — |
| `owns` | yes | `owns` | — |
| `refuses` | yes | `refuses` | — |
| `now` | yes | `now` | Not structured; versions embedded in prose |
| `plan` | optional path | `links.plan` | No absolute URL; no README/npm link objects |

## Fields the schema requires that the registry lacks

| Schema field | Why agents need it | Suggested Phase 1 source |
| --- | --- | --- |
| `status` | Lifecycle without registry drift | Prefer mapping from each repo’s `PROJECT_PLAN.md` stage (same discipline as the compiled roadmap); hand registry is fallback only when the plan is unreachable |
| `packages[].version` | Exact 0.x pins | npm / release projection / registry snapshot with precedence |
| `packages[].published` | Skip unpublished packages | npm existence + hand status |
| `publishUsability` | Fast list filter | Derived from package flags |
| `dependencies` | Correct composition order | Hand edges + package peer/optional deps where honest |
| `adapters` | Cloudflare vs Azure vs memory | Hand table per component (storage already known) |
| `hostMustProvide` | Stop agents from assuming the package owns cookies/DNS/UI | Hand list from READMEs / refuses |
| `capabilityTags` | Deterministic `plan_composition` | Hand tags on compile inputs |
| `recipeIds` | Recipe → component index | Recipe backlog + fixtures |
| `links.githubRepo` / `readme` / `npm` | Progressive disclosure | Convention + npm |
| `stage` | Drift-resistant status | Existing plan aggregation (`live-status` path) |
| `recipes[]` | Named intents with fixture citations | Recipe backlog → fixtures (Phase 2) |

## Adjacent surfaces (not the catalog)

| Asset | Role | Gap vs catalog |
| --- | --- | --- |
| `public/llms.txt` | Short agent index | No deps, pins, recipes, or refuses detail; Phase 1 should link to catalog URL only |
| `/stack` | Human component pages | Renders registry + stage; not machine-oriented |
| `/roadmap` | Compiled stage view | Stage only; not composition |
| `/examples` | Skeleton snippets from READMEs | Not recipe-index shaped; no fixture status |
| `worker/src/release-catalog.ts` | Release webhook allowlist / display order | Repo id map only — reuse order, not package facts |
| Component READMEs + conformance | Canonical package truth | Scattered; catalog must summarize and link, not fork |

## Publish / assembly-usable gate (compiled, not hand-copied)

Do **not** maintain a per-component “usable today?” table in this document.
That would duplicate lifecycle facts that AGENTS.md requires to be **compiled**
from component plans (and package-version authority), the same discipline as
the roadmap.

Phase 1 must set each catalog component’s `status`, `publishUsability`, and
`packages[].published` / `packages[].version` from:

1. Each repo’s `PROJECT_PLAN.md` stage (status / stage prose)
2. Version authority precedence (release-projection Store → npm at compile time)
3. Never from parsing `now` prose in `components.ts`

Until that compile exists, agents should treat only **npm-published** packages
with exact pins as production-assembly candidates, and treat anything still
unpublished on npm (including local vendor tarballs) as unusable.

## Decisions locked for Phase 1 compile (from open questions)

These are Phase 0 recommendations so Phase 1 does not re-litigate shape:

1. **Compile home:** site build in this repo for the first `catalog.json`
(static publish). Extract a shared package only if the MCP Worker cannot
consume the same static URL cleanly.
2. **Version authority (precedence):** release-projection Store facts when
present → else npm at compile time → else registry `now` parse is
**forbidden**; leave `version: null` and `published: false` rather than
guess from prose.
3. **Recipe layout:** backlog lives in `docs/catalog/`; fixtures decide their
home in Phase 2 (dedicated examples repo vs in-package). Catalog only
stores citations.
4. **`plan_composition` inputs:** structured `capabilityTags` + host
constraints — not free-text LLM classification inside Pegma.

## What Phase 0 deliberately does not do

- Emit `catalog.json` or change the site build (Phase 1)
- Add recipe fixture code (Phase 2)
- Publish a skill or MCP tools (Phases 3–4)
- Document commercial host route maps or data models
120 changes: 120 additions & 0 deletions docs/catalog/RECIPE_BACKLOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Synthetic recipe backlog

Prioritized composition intents for the agent catalog. Every intent is
**synthetic**: a purpose-built product shape for teaching assembly. None
describe a commercial host’s routes, tenancy, or operations.

**Fixture rule:** catalog and `/examples` may only quote wiring that exists in
a public, CI-tested source (`fixture.status === 'green'`). Until then, recipes
appear as intent metadata only.

**Publish rule:** recipes whose `requiresPublished` set is not fully usable
must not be offered for production assembly (they may stay in the backlog as
deferred).

## Priority order (ship fixtures in this order)

### P1 — `cf-passkey-accounts` (first end-to-end accounts recipe)

| | |
| --- | --- |
| **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 (published)** | `@pegma/identity`, `@pegma/sessions`, `@pegma/mail`, `@pegma/rate-limit`, `@pegma/authorization-identity`, `@pegma/storage-core`, `@pegma/storage-cloudflare-d1`, `@pegma/spine` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Compile publication claims instead of hard-coding them

The Packages (published) row embeds current lifecycle facts in a hand-maintained document. If any listed package is unpublished or renamed upstream, this backlog will continue advertising it as available until this repository is manually updated, bypassing the required build-time compilation from component plans. Generate this availability label from the catalog’s version authority or remove the publication claim.

AGENTS.md reference: AGENTS.md:L28-L30

Useful? React with 👍 / 👎.

| **Adapters** | `storage-core/cloudflare-d1`; mail provider chosen by host (e.g. Resend port on consumer pull) |
| **Host must provide** | HTTP routes, cookie/session boundary, WebAuthn origin config, email provider + DNS, secrets, any UI |
| **Non-goals** | Social login, OIDC server for third parties, passwords, multi-tenant orgs |
| **Anti-patterns** | Password table “just for admin”; durable events on Spine’s in-process bus; mail package owning its own outbox store; inventing sessions without `@pegma/sessions` |
| **requiresPublished** | identity, sessions, mail, rate-limit, authorization-core, storage-core, spine |
| **Fixture** | pending — Phase 2 synthetic fixture (not pegma.dev production account routes) |
| **Phase plan exit** | One of two required Phase 2 recipes (“accounts on Cloudflare-shaped host”) |

### P2 — `storage-audit-mail-outbox` (storage + audit/mail pattern)

| | |
| --- | --- |
| **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. After commit, a worker drains the outbox. |
| **Packages (published)** | `@pegma/storage-core`, `@pegma/audit`, `@pegma/mail`, `@pegma/spine` |
| **Adapters** | memory or cloudflare-d1 / azure-tables for demos; pattern is adapter-agnostic |
| **Host must provide** | Collection declarations, transaction boundary, outbox collection in host storage, mail provider adapter, delivery scheduler |
| **Non-goals** | Mail package owning storage; audit owning a store; cross-partition transactions |
| **Anti-patterns** | Separate “send email” after commit without an outbox job; audit write outside the caller’s `transact`; fake global ordering |
| **requiresPublished** | storage-core, audit, mail, spine |
| **Fixture** | pending — Phase 2; may cite package README/conformance excerpts until a dedicated fixture app exists |
| **Phase plan exit** | Second required Phase 2 recipe (“storage + audit/mail outbox pattern”) |

### P3 — `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 — never pretending the memory tier is a global quota. |
| **Packages** | `@pegma/rate-limit`, `@pegma/storage-core` (durable tier), `@pegma/spine` |
| **Anti-patterns** | Using only in-memory limits for email-code or passkey verify; calling memory tier a “cluster quota”; expecting rate-limit to stop volumetric DDoS |
| **requiresPublished** | rate-limit, storage-core, spine |
| **Fixture** | pending |

### P4 — `health-public-liveness`

| | |
| --- | --- |
| **Intent** | A fictional brochure site’s Worker exposes a public liveness endpoint composed from `@pegma/health` probes (process + optional store ping), with checks registered at an explicit composition root. |
| **Packages** | `@pegma/health`, `@pegma/spine`; optional `@pegma/storage-core` for store ping |
| **Anti-patterns** | Autodiscovery of checks; health package inventing domain collections; treating health as APM |
| **requiresPublished** | health, spine |
| **Fixture** | pending (package README may supply early green citations) |

### P5 — `logger-tee-composition`

| | |
| --- | --- |
| **Intent** | A fictional batch importer (“Ledger Drop”) wires Spine’s Logger once at the composition root through `@pegma/logger-tee` into Cloudflare Workers Logs (and optionally a second sink), without growing Spine or inventing a Pegma observability vocabulary. |
| **Packages** | `@pegma/spine`, `@pegma/logger-tee`, `@pegma/logger-cloudflare` (optional other logger adapters) |
| **Anti-patterns** | Putting sink SDKs into Spine; replacing Logger with a custom core; claiming traces/metrics are Pegma’s job |
| **requiresPublished** | spine, logger-adapters |
| **Fixture** | pending |

### P6 — `static-brochure-minimal`

| | |
| --- | --- |
| **Intent** | A fictional static museum site (“Glass Wing”) needs no accounts, no durable storage, and no mail — only honest stack awareness (and optional health if a Worker exists). Teaches agents to **select nothing extra**. |
| **Packages** | none required; optional `@pegma/health` if a Worker liveness route exists |
| **Anti-patterns** | Pulling identity/sessions “for later”; inventing a database for a static site |
| **requiresPublished** | (none) |
| **Fixture** | pending — may be skill/eval only with empty composition root |

## Deferred (unpublished packages)

Do not offer for production assembly until packages are on npm.

### D1 — `inbound-webhook-receipts` (when `@pegma/webhooks` is published)

| | |
| --- | --- |
| **Intent** | A fictional donation platform (“Copper Plate”) records inbound provider webhook receipts with idempotent dedup, poison quarantine, and retention — receipts hold ids and counters, never payloads. |
| **Blocks** | webhooks unpublished |
| **Anti-patterns** | Exactly-once claims; storing full payloads in the receipt ledger; ordering guarantees |

### D2 — `support-queue-slice` (when Support Desk packages are published)

| | |
| --- | --- |
| **Intent** | A fictional maker-space helpdesk (“Bench Ticket”) runs a composable support queue for web and email with permission-checked agents and outbox-backed mail. |
| **Blocks** | support-desk packages unpublished |
| **Anti-patterns** | Treating Support Desk as hosted SaaS; AI on ticket bodies before the host documents egress |

## Explicitly out of backlog (non-goals)

- Recipes that copy pegma.dev or retiregolden.org route maps, schemas, or ops topology
- Password-based auth “compatibility” recipes (Identity refuses passwords)
- Spine durable-event recipes (Spine refuses durable events on the in-process bus)
- Multi-package monorepo scaffolds that dictate a UI framework

## Mapping to plan Phase 2 exit

| Plan requirement | Backlog id |
| --- | --- |
| End-to-end accounts on Cloudflare-shaped host | P1 `cf-passkey-accounts` |
| Storage + audit/mail outbox pattern | P2 `storage-audit-mail-outbox` |

Ship P1 and P2 fixtures before declaring Phase 2 done. P3–P6 improve coverage;
D1–D2 wait on publication.
Loading