Schema first development

From beep-effect/beep-effect · View interactive version

Schema first development is an AI agent skill from the GitHub repository beep-effect/beep-effect. Focused schema-first guidance for this repo's effect/Schema and @beep/schema patterns. Use when adding or refactoring schemas, replacing exported interface/type data models, fixing schema-first lint violations, modeling literal domains or tagged unions, applying schema defaults or transformations, d

How to use this skill

Skill file

Schema-First Development

Use this skill for schema-heavy work in this repository.

Treat schema-first rules as enforced repository law, not style preference.

The primary sources are:

Keep Schema as the source of truth for pure data models.

Workflow

  1. Classify the task.
  1. Load only the reference file you need.
  1. Check local Effect v4 source for nontrivial Schema API choices.

.repos/effect points to $HOME/YeeBois/references/effect/effect, the Effect

child of the reference workspace; Effect main is v4.

specialized module (SchemaAST, SchemaGetter, SchemaIssue,

SchemaRepresentation, SchemaTransformation) when using advanced APIs.

  1. Apply the laws in this order.

S.Struct (S.TaggedStruct for _tag data). Keep S.Class /

S.TaggedClass / S.Error / S.TaggedError for errors, persisted

entities, schemas with instance members, and .extend chains. Every schema

class and Opaque declaration carries { readonly brand: unique symbol }.

local schemas before inventing new checks. Where upstream covers a

foundation/modeling concept's intent, its covered facets retire in the

same PR that migrates their consumers, with no alias; the whole concept

retires unless the lines reading its uncovered members outnumber the lines

using its covered facets (ADAPT, per the facet census in

standards/architecture/DECISIONS.md "Upstream-First Foundation/Modeling").

schema.

(LiteralKit included); classes take $I.annote(...) as their trailing

argument.

literal helpers from the schema instead of writing parallel helpers.

when the error leaves the local helper/module boundary.

  1. Verify before finishing.

payload bags.

Fast Rules

package whose modules a deployed Lambda bundle loads (@beep/schema,

@beep/alchemy-github-runners, @beep/infra-ci-runners) takes its composer

from its src/internal/<Composer>.ts leaf instead, so the registry stays out

of the bundle (goals/infra-alchemy-rebuild decision of 2026-11-19).

beep lint identity-registry enforces it: $BeepId only in such a leaf,

over the package's own slug, and no registry import in a leaf package.

Construct with X.make(...); there is no new X(...) and no .extend.

Annotate the Struct inside the pipe, because X.annotate(...) drops the

statics. See references/repo-laws.md section 2.

.is, match, .toTaggedUnion(...)) plus the S.Literals members it

inherits (.literals, .pick(...), .mapMembers(...)). Use S.Literals

for anonymous inline unions never referenced by name.

decoded literal helper surfaces.

LiteralKit(...); its const type parameters preserve the literal tuple.

case-specific payloads as discriminated unions, not one optional/nullish

payload bag.

compatibility requires the wire shape.

status, type, subtype, profile, or family.

other required single-literal field with S.tag(v), never S.Literal(v);

bun run beep laws schema-tag-idioms --check enforces it.

.match) when constructing, guarding, or branching on a schema tagged union.

X.makeOption(...), never O.some(X.make(...)). Every schema, class, brand

and tagged-union case (X.cases.Y.makeOption(...)) has it. It returns

O.none() on input the schema refuses, where make throws, so use it only

where an absent value is a legal outcome of that branch (EF-35b).

S.OptionFromOptionalKey for absence at the boundary. Optional fields use

exact keys (EF-40): S.optionalKey, S.withDecodingDefaultKey,

S.OptionFromOptionalKey, never their undefined-admitting siblings.

runtime Option values are already being shaped into an object, prefer

O.getSomesStruct({...}) (@beep/utils) for heterogeneous struct spreads

with known keys — runtime-identical to R.getSomes but type-preserving per

key; reserve R.getSomes({...}) for homogeneous dynamic-key dictionaries.

Use O.all({...}) for all-or-nothing fixed-shape composition. (Amended

2026-07-05 — see standards/architecture/DECISIONS.md.)

S.decodeTo(...) with SchemaTransformation for normalization and fallback

behavior.

out. When one value answers both (an empty collection, a zero counter, an

absent link), put it on the field as a constructor default plus a decoding

default (S.withDecodingDefaultTypeKey), and write the owner's initial as

State.make({}). Describe the key with S.annotateKey({ description })

first in the pipe: placed after a decoding default or after

S.OptionFromOptionalKey it is dropped from generated JSON Schema. An

optional field that starts absent is

X.pipe(S.annotateKey({ description }), S.OptionFromOptionalKey, S.withConstructorDefault(Effect.succeedNone)).

Give no default to identity, authority, provenance or money, or to a field

whose empty value is the widest one (EF-34).

S.Number, and unbounded arrays as prompts to ask whether the schema should

be more precise.

description.

Arbitrary.schema(schema) (effect/Arbitrary) for schema-modeled property tests.

boundaries.

S.encodeEffect by default. Reach for S.decodeUnknownResult,

S.decodeResult, or S.decodeUnknownOption only for deliberate

non-throwing synchronous helpers; do not teach or add S.decodeSync,

S.decodeUnknownSync, S.encodeSync, or S.encodeUnknownSync. If a

legacy synchronous wrapper must still throw, convert Result failures with

Result.getOrThrowWith(...) so raw schema issues do not escape the boundary.

Escalation

including service/layer wiring and typed error flow outside schema modeling.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.