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
37 changes: 32 additions & 5 deletions docs/AGENT_ASSEMBLY_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Status

**Stage:** Phase 4 complete (public catalog MCP). Phase 5 (scaffold + eval)
remains open.
**Stage:** Phase 5 complete (scaffold + offline assembly eval). Implementable
agent-assembly plan work is done.

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
Expand All @@ -26,6 +26,8 @@ what the Pegma stack already packages (typed, tested, pin-able components).
| Skill install notes | `https://pegma.dev/skill` (`src/pages/skill.astro`) |
| Catalog tool logic | `src/data/mcp-tools.ts` |
| MCP Worker surface | `worker/src/mcp-server.ts` → `https://pegma.dev/api/mcp` |
| Minimal CF scaffold | `recipes/scaffold-cf-minimal/` |
| Offline assembly eval | `evals/assembly-eval.ts` (`npm run eval:assembly`) |

**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 @@ -343,16 +345,41 @@ no private data plane.
and `llms.txt`; `plan_composition` is rule-based over structured
`capabilityTags`.

### Phase 5 — Scaffold and eval harness
### Phase 5 — Scaffold and eval harness ✓

Public synthetic starter template with pinned known-good versions and an
empty-ish composition root. Small offline or CI eval set of prompts
(“static brochure site”, “passkey accounts on Workers”, “health endpoint
only”, “do not use passwords”) scored on package selection and refusal
compliance — not on UI polish.

**Exit:** measured improvement when skill + catalog (+ MCP if present) are
enabled vs. baseline agent with only web search.
Shipped:

| Surface | Path |
| --- | --- |
| Scaffold fixture | `recipes/scaffold-cf-minimal/` (Glass Wing) |
| Catalog recipe | `static-brochure-minimal` (green scaffold citation) |
| Eval cases | `evals/assembly-cases.ts` |
| Eval runner | `evals/assembly-eval.ts` |
| CI coverage | `evals/assembly-eval.test.ts` via `npm test` / `npm run eval:assembly` |

The offline harness scores `plan_composition` over the **compiled** catalog
against the prompt set. Offline baseline is a **no-catalog** empty plan
(agent never fetches catalog facts): same package/refusal assertions, scored
honestly. Catalog mode must beat that pass rate. That is the automated gate;
full multi-agent LLM A/B (web search vs skill+catalog+MCP) remains optional
outside CI and is not claimed by the unit harness alone.

**Exit (automated):** offline compiled-catalog planner pass rate strictly
greater than the offline **no-catalog** baseline on the four Phase 5 prompts;
scaffold fixture green and catalog-cited.

**Exit (optional, out of band):** full multi-agent LLM A/B (web search only vs
skill + catalog + MCP) remains available for human/operator measurement and is
not required for the CI gate.

**Done:** automated exit met — compiled-catalog pass rate > no-catalog baseline
on the four prompts; scaffold fixture is green and cited from the catalog.

## Non-goals

Expand Down
12 changes: 7 additions & 5 deletions docs/catalog/RECIPE_BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ deferred).
| **requiresPublished** | spine, logger-adapters |
| **Fixture** | pending |

### P6 — `static-brochure-minimal`
### P6 — `static-brochure-minimal` (scaffold)

| | |
| --- | --- |
| **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 |
| **Intent** | A fictional static museum site (“Glass Wing”) needs no accounts, no durable storage, and no mail — only honest stack awareness. Teaches agents to **select nothing extra**. Optional Worker health is host-owned (`withHealth`), not a required catalog capability. |
| **Packages (pinned)** | `@pegma/spine@0.1.1` only (fixture does not import `@pegma/health`; host may add health from the catalog) |
| **Host must provide** | Static hosting / optional Worker fetch; explicit empty-ish composition root |
| **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 |
| **requiresPublished** | spine |
| **capabilityTags** | `static_host` only (not bare `cloudflare` — host-tag alone must not select this scaffold) |
| **Fixture** | green — [`recipes/scaffold-cf-minimal/`](../../recipes/scaffold-cf-minimal/) |

## Deferred (unpublished packages)

Expand Down
84 changes: 84 additions & 0 deletions evals/assembly-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Offline assembly eval cases for Phase 5.
*
* Prompts are scored by mapping them to structured capabilityTags and
* running plan_composition over the **compiled** catalog (same path as
* catalog.json). This measures package selection and refusal compliance
* without hosting an LLM in Pegma.
*
* Offline “no-catalog” baseline: empty package set and no refuse notes
* (agent never fetched catalog facts). Same assertions as catalog mode.
* This is not a full web-search LLM A/B — it measures the planner gate
* against a no-catalog agent. Live multi-agent eval remains out of band.
*/

import type { CapabilityTag } from '../src/data/catalog-schema';

export interface AssemblyEvalCase {
readonly id: string;
/** Short product prompt (synthetic). */
readonly prompt: string;
/** Structured tags an agent should pass to plan_composition. */
readonly capabilityTags: readonly CapabilityTag[];
readonly host?: 'cloudflare' | 'azure' | 'memory' | 'other';
/** Package name substrings that must appear in the plan. */
readonly mustIncludePackageNames?: readonly string[];
/** Package name substrings that must not appear. */
readonly mustNotIncludePackageNames?: readonly string[];
/** Substrings that must appear in combined refuses notes / component refuses. */
readonly mustSurfaceRefusalSubstrings?: readonly string[];
/** Substrings that must not appear in recommended package names. */
readonly mustNotRecommendSubstrings?: readonly string[];
/** Primary recipe id that must be selected (catalog mode). */
readonly mustPrimaryRecipeId?: string;
/** Primary recipe id that must not be selected (catalog mode). */
readonly mustNotPrimaryRecipeId?: string;
}

/**
* Plan Phase 5 prompt set: static brochure, passkeys on Workers, health only,
* and password refusal compliance.
*/
export const ASSEMBLY_EVAL_CASES: readonly AssemblyEvalCase[] = [
{
id: 'static-brochure',
prompt:
'Static brochure museum site (Glass Wing). No accounts, no durable storage, no mail.',
capabilityTags: ['static_host'],
mustPrimaryRecipeId: 'static-brochure-minimal',
mustNotIncludePackageNames: [
'@pegma/identity',
'@pegma/sessions',
'@pegma/mail',
'@pegma/storage-core',
],
},
{
id: 'passkey-accounts-workers',
prompt:
'Passkey accounts on Cloudflare Workers with email-code fallback. No passwords.',
capabilityTags: ['accounts', 'passkeys', 'email_codes', 'cloudflare'],
host: 'cloudflare',
mustIncludePackageNames: ['@pegma/identity'],
mustNotRecommendSubstrings: ['password'],
mustSurfaceRefusalSubstrings: ['password'],
},
{
id: 'health-endpoint-only',
prompt: 'Public liveness health endpoint only on a small Worker.',
capabilityTags: ['health'],
mustIncludePackageNames: ['@pegma/health'],
mustNotIncludePackageNames: ['@pegma/identity', '@pegma/mail'],
// Do not send agents to the static museum scaffold for a health-only plan.
mustNotPrimaryRecipeId: 'static-brochure-minimal',
},
{
id: 'no-passwords',
prompt:
'First-party accounts for a club site. Passkeys preferred. Do not use passwords.',
capabilityTags: ['accounts', 'passkeys'],
mustIncludePackageNames: ['@pegma/identity'],
mustNotRecommendSubstrings: ['password'],
mustSurfaceRefusalSubstrings: ['password'],
},
];
126 changes: 126 additions & 0 deletions evals/assembly-eval.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { describe, expect, it, beforeAll } from 'vitest';
import {
clearNpmVersionCache,
compileCompositionCatalog,
} from '../src/data/compile-catalog';
import { components } from '../src/data/components';
import type { CompositionCatalog } from '../src/data/catalog-schema';
import { runAssemblyEval } from './assembly-eval';
import { ASSEMBLY_EVAL_CASES } from './assembly-cases';

const FIXED_AT = '2026-07-29T12:00:00.000Z';
const NO_STAGES: Record<string, string | null> = Object.fromEntries(
components.map((c) => [c.repo, null]),
);

/**
* Deterministic npm pins matching known-good published versions used by
* recipe backlog pins and the site worker. Never hits the network.
*/
const EVAL_NPM: Record<string, string | null> = {
'@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/storage-blobs': '0.1.0',
'@pegma/storage-azure-blob': '0.1.0',
'@pegma/storage-cloudflare-r2': '0.1.0',
'@pegma/storage-s3': '0.1.0',
'@pegma/authorization-contracts': '0.1.2',
'@pegma/authorization-core': '0.1.2',
'@pegma/authorization-policy': '0.1.2',
'@pegma/authorization-auth0': '0.1.2',
'@pegma/authorization-stripe': '0.1.2',
'@pegma/authorization-storage': '0.1.2',
'@pegma/authorization-tokens': '0.1.2',
'@pegma/authorization-identity': '0.1.2',
'@pegma/audit': '0.1.0',
'@pegma/support-desk-contracts': '0.1.0',
'@pegma/support-desk-core': '0.1.0',
'@pegma/support-desk-application': '0.1.0',
'@pegma/support-desk-templates': '0.1.0',
'@pegma/webhooks': null, // unpublished for production assembly
'@pegma/sessions': '0.1.0',
'@pegma/mail': '0.1.0',
'@pegma/billing-core': null,
'@pegma/identity': '0.1.0',
'@pegma/rate-limit': '0.1.0',
'@pegma/logger-tee': '0.1.1',
'@pegma/logger-applicationinsights': '0.1.1',
'@pegma/logger-cloudflare': '0.1.1',
'@pegma/logger-datadog': '0.1.1',
'@pegma/health': '0.1.1',
};

async function compileEvalCatalog(): Promise<CompositionCatalog> {
clearNpmVersionCache();
return compileCompositionCatalog({
generatedAt: FIXED_AT,
stageByRepo: NO_STAGES,
npmLookup: async (name) =>
Object.prototype.hasOwnProperty.call(EVAL_NPM, name)
? EVAL_NPM[name]!
: null,
});
}

describe('assembly eval harness (Phase 5)', () => {
let catalog: CompositionCatalog;

beforeAll(async () => {
catalog = await compileEvalCatalog();
});

it('defines the plan prompt set', () => {
expect(ASSEMBLY_EVAL_CASES.map((c) => c.id).sort()).toEqual(
[
'health-endpoint-only',
'no-passwords',
'passkey-accounts-workers',
'static-brochure',
].sort(),
);
});

it('compiles the real catalog artifact (not a hand-built twin)', () => {
expect(catalog.schemaVersion).toBe('0.1.0');
expect(catalog.components.length).toBe(components.length);
const scaffold = catalog.recipes.find((r) => r.id === 'static-brochure-minimal');
expect(scaffold?.fixture.status).toBe('green');
expect(scaffold?.fixture.citation).toContain('scaffold-cf-minimal');
expect(scaffold?.capabilityTags).toEqual(['static_host']);
expect(scaffold?.capabilityTags).not.toContain('health');
expect(scaffold?.capabilityTags).not.toContain('cloudflare');
});

it('baseline scores assertions against an empty plan (not forced all-fail)', () => {
const report = runAssemblyEval(null, 'baseline');
// Static brochure may pass (must-not-include only); include cases fail.
const byId = Object.fromEntries(report.cases.map((c) => [c.id, c]));
expect(byId['static-brochure']?.pass).toBe(true);
expect(byId['passkey-accounts-workers']?.pass).toBe(false);
expect(byId['health-endpoint-only']?.pass).toBe(false);
expect(byId['no-passwords']?.pass).toBe(false);
expect(report.passRate).toBeGreaterThan(0);
expect(report.passRate).toBeLessThan(1);
});

it('catalog planner improves pass rate over baseline on compiled catalog', () => {
const baseline = runAssemblyEval(null, 'baseline');
const withCatalog = runAssemblyEval(catalog, 'catalog');
expect(withCatalog.passRate).toBeGreaterThan(baseline.passRate);
for (const c of withCatalog.cases) {
expect(c.pass, `${c.id}: ${JSON.stringify(c.checks)}`).toBe(true);
}
expect(withCatalog.passRate).toBe(1);

const staticCase = withCatalog.cases.find((c) => c.id === 'static-brochure')!;
expect(staticCase.primaryRecipeId).toBe('static-brochure-minimal');

const healthCase = withCatalog.cases.find((c) => c.id === 'health-endpoint-only')!;
expect(healthCase.primaryRecipeId).not.toBe('static-brochure-minimal');
expect(healthCase.packageNames.some((p) => p.includes('@pegma/health'))).toBe(
true,
);
});
});
Loading
Loading