When to Use
When validating any prompt unit — from CLI (stratt validate), CI pipeline, or programmatic checks. This is the single entry point for all unit validation.
The Pipeline (6 Steps)
| Step | Check | Fails on |
|---|---|---|
| 1 | Zod structural parse | Missing/invalid fields, wrong types, regex mismatches |
| 2 | URI consistency | id field doesn’t decompose to match domain/type/slug/version |
| 3 | Import format | Any import is not a valid strat:// URI |
| 4 | CON-010 draft isolation | Stable unit (1.0.0+) imports draft unit (0.x.x) |
| 5 | Lifecycle validity | Warns (not fails) on author-set tampered status |
| 6 | Forbidden block check | composition block present on role/rule/fragment |
Return Type
Key Design Decisions
Zod discriminated union:z.discriminatedUnion("type", [...]) dispatches to the correct branch based on the type field. If type is invalid, the error message explains which values are valid.
Forbidden blocks checked against raw input: Zod’s .extend() strips unknown keys, so a composition block on a fragment would be silently removed. The pipeline checks "composition" in parsed on the raw input before Zod parsing discards it.
Error accumulation: Steps 2-6 accumulate all errors rather than short-circuiting. The caller sees every problem at once.
CON-010 heuristic: Draft versions are identified by version.startsWith("0."). This correctly identifies all 0.x.x versions per semver convention.