Design skill tooling
Petal's design skill tooling packages design guidance with a versioned view of the component API. It helps an engineer or coding agent choose Petal components, use their current contracts, and compare the quality of generated Phoenix UI through repeatable evaluations.
Tooling model
The tooling joins three related concerns: guidance for design work, a local API snapshot for component lookup, and a fixed evaluation script for generated experiences. The guidance shapes decisions, the snapshot reduces API guesses, and the evaluation measures whether those decisions improve the result.
This diagram shows how package changes become developer guidance and how that guidance is measured in a clean application.
flowchart LR
Source[Compiled component API] --> Generator[Skill snapshot generator]
Generator --> Schema[data/schemas.json]
Generator --> Inventory[Component inventory]
Generator --> Version[Skill version marker]
Guidance[Design guidance] --> Skill[petal-design skill]
Schema --> Skill
Inventory --> Skill
Skill --> Generated[Generated Phoenix UI]
Generated --> Eval[Fixed evaluation]
MCP[Petal MCP lookup] --> Eval
Eval --> Measures[Violation and quality measures]
Design skill package
The petal-design skill is the developer-facing entry point. It tells an agent when to build, review, or theme UI and routes each request to the small set of guidance files needed for that task. Its purpose is to make Petal's visual rules and component choices consistent without requiring a separate design specification in each application.
The skill uses a lookup order for component contracts: the Petal MCP server when available, the bundled snapshot next, and the installed package source as a final check. This makes the skill useful in both connected and offline work while keeping the current component API as the source of truth.
References: skills/…/SKILL.md• L7-49
Snapshot outputs
The snapshot is a versioned, machine-readable copy of each public component's contract. It records the component name, module, attributes, slots, defaults, required flags, allowed values, and curated examples. A generated Markdown inventory provides the shorter choice list that helps a developer find a component before reading its full schema.
The generator also records the package version in the skill front matter. The output is stable for meaningful changes because object keys and components are sorted; only the generation time is expected to vary. Showcase examples are attached to the component they actually render, so the snapshot teaches usage in a realistic context without treating the showcase helpers as application components.
References: lib/…/petal.gen.skill_snapshot.ex• L1-25 lib/…/petal.gen.skill_snapshot.ex• L142-169 lib/…/petal.gen.skill_snapshot.ex• L214-228 lib/…/petal.gen.skill_snapshot.ex• L267-291
Release synchronization
Snapshot generation is a release-time task. It compiles and starts the Petal component package, reads the live component metadata, then refreshes the schema data, the component inventory, and the version marker in one run. The same refresh is expected to stay aligned with the Petal MCP schema sync.
The task belongs in the Petal Components repository rather than a consuming application. Its output is useful only when it describes the package version that the skill claims to support.
References: lib/…/petal.gen.skill_snapshot.ex• L44-62 lib/…/petal.gen.skill_snapshot.ex• L69-84 lib/…/petal.gen.skill_snapshot.ex• L297-368
Snapshot verification
The snapshot tests protect the link between the live component API and the material that agents read. They check both the version labels and the shape of the public API, so a file with a correct version cannot hide an obsolete or incomplete schema.
API drift checks
The verification suite checks the snapshot in both directions. It compares each documented component's attributes and slots with the live module metadata, including types, defaults, required status, and enum values. It also checks that every live public component appears in the snapshot.
This matters because component changes can keep the same function name while changing what callers may pass. The checks turn that silent drift into a release failure before the skill distributes invalid guidance.
References: test/…/skill_snapshot_test.exs• L28-115
Example and reference checks
The tests protect the usage paths that are easy to break while regenerating the package. Chat examples must use the namespace required by normal applications, and every reference path named by SKILL.md must still exist. These checks keep copied examples compilable and prevent the skill from pointing at missing guidance.
References: test/…/skill_snapshot_test.exs• L117-180 lib/…/petal.gen.skill_snapshot.ex• L171-184
Generated experience evaluation
The evaluation tooling measures the effect of the design skill instead of relying on a selected screenshot or a subjective claim. It uses the same application context, prompts, model, seed data, and attempt limits across clean sessions, then records both visible design violations and component API errors.
Evaluation arms
An evaluation arm is one controlled source of developer guidance. The main comparison uses three arms:
- Bare has no MCP lookup and no design skill.
- MCP has the Petal MCP lookup service but no design skill.
- Skill has the same MCP access and also has the copied
petal-designskill.
The skill arm must not be named in its prompt. This isolates the effect of the installed skill from coaching in the task text. A separate cold-start comparison measures a fresh Phoenix application without Petal against an application with Petal, its schema data, and the skill.
References: skills/…/demo-script.md• L1-13 skills/…/demo-script.md• L19-27
Fixed evaluation tasks
The task set covers the main ways a generated component experience can succeed or fail. It asks the arms to build a settings page, convert raw markup to Petal usage, add dark mode to a light-only view, and review a seeded design-system diff. The cold-start task adds a defined application shell and plan view so the comparison tests the same product request on both sides.
Each task uses one prompt and one attempt. The review task contains a fixed list of seeded violations, which gives the review arm a known recall target rather than an open-ended score.
References: skills/…/demo-script.md• L15-25 skills/…/demo-script.md• L29-74
Evaluation measures
The evaluation records four deltas for each arm and task. Together they measure rule violations, invalid component calls, theme completeness, and the balance between Petal components and raw HTML.
| Measure | What it shows |
|---|---|
| Grep-table violation count | How many known design drift patterns appear in changed UI files. |
| Schema-invalid attributes | Whether component calls use unknown attributes or values outside the current contract. |
| Dark-pair coverage | Whether color-bearing classes provide matching dark-mode treatment. |
| Component-to-raw ratio | Whether the output uses available Petal components instead of recreating common controls. |
The counts are evidence, not the whole judgment. A clean grep is only a baseline, so the published result must include every measured number, including a metric on which the skill arm performs worse.
References: skills/…/demo-script.md• L76-83
Screenshot evidence
The marketing capture renders the settings route with identical seed data in light and dark mode. It saves named screenshots for each arm and pairs the bare-versus-skill images with the four-number measure table. This keeps the visual story tied to a reproducible run rather than to edited or cherry-picked output.
References: skills/…/demo-script.md• L85-87
Developer workflow
The normal workflow moves from guidance to contract lookup and then to measured output. A developer can use the skill package during UI work, while package maintainers use the generator and verification suite when the component API changes.
- Install or copy the
petal-designskill into the application workspace. - Use its mode rules to select build, review, or theme guidance.
- Resolve non-default component attributes through MCP, the bundled snapshot, or package source.
- For a release, run
mix petal.gen.skill_snapshotfrom the Petal Components repository. - Run the snapshot checks before publishing the refreshed skill.
- Run the fixed evaluation when comparing generated experiences or preparing before-and-after evidence.
Guidance relationships
The Petal design skill child page explains the guidance package itself. Read it for the design modes, token rules, composition patterns, component inventory, and review playbook that the tooling packages and exposes to developers.
References: skills/…/SKILL.md• L15-32 skills/…/SKILL.md• L51-112 skills/…/components.md• L1-9 skills/…/review.md• L1-17 skills/…/patterns.md• L1-3 skills/…/tokens.md• L1-3
Change checklist
When these files or sections are changed, remember to consider these:
- When the package version changes, refresh the schema snapshot, component inventory, skill front matter, and the matching MCP schema before release.
- When a component attribute, slot, default, or allowed value changes, check both the machine-readable snapshot and the copied examples that teach that contract.
- When a showcase example changes its target or component call, check example attachment, Chat namespacing, and the component selected by the inventory.
- When the skill lookup ladder changes, update the offline fallback and the guidance link so agents do not use stale component contracts.
- When an evaluation prompt, arm, seed, or metric changes, keep all comparison arms symmetric and update the screenshot naming and published measure set.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The snapshot task runs from a consuming Phoenix application. | The task stops without refreshing the skill because the live package metadata is not the package's own release context. | Run mix petal.gen.skill_snapshot from the Petal Components repository. |
| A package API changes but the snapshot is not regenerated. | Agents receive stale attributes or miss new components, even if the skill version text looks correct. | Run the generator and rely on the version, shape, and completeness checks before release. |
| A Chat example is copied with a bare component call. | The copied example does not compile in a normal application because Chat is namespaced. | Preserve the generator's Chat rewrite and the namespacing test. |
| The skill arm receives different MCP access or prompt coaching from the MCP arm. | The before-and-after result cannot show whether the skill caused the measured change. | Use the same MCP availability and verbatim prompts, and do not name the skill in the task. |
| A screenshot is selected without its recorded metrics or run conditions. | The visual claim cannot be reproduced or checked against known design and API measures. | Publish both light and dark captures with the four-number table from the same run. |
Key files
| File | Why to read it |
|---|---|
| skills/…/SKILL.md | Defines the developer-facing modes, component lookup order, version marker, and design rules. |
lib/mix/tasks/petal.gen.skill_snapshot.ex | Defines how live component metadata becomes the schema snapshot, inventory, examples, and version stamp. |
| skills/…/schemas.json | Provides the versioned component contracts used when live MCP lookup is not available. |
| skills/…/components.md | Provides the compact component choice list generated from the schema data. |
test/petal/skill_snapshot_test.exs | Defines the release guards for version alignment, API shape, component completeness, namespaced examples, and reference paths. |
| skills/…/demo-script.md | Defines the controlled comparison arms, fixed prompts, measures, and screenshot evidence. |
| skills/…/tokens.md | Contains the visual token guidance used for custom markup and theme evaluation. |
| skills/…/patterns.md | Contains the composition guidance used for component-heavy page generation. |
| skills/…/review.md | Contains the review order and violation checks used by the seeded evaluation. |