Schema 优先开发指南
schema-first-development
针对本仓库 effect/Schema 和 @beep/schema 模式的专项 Schema 优先开发指导。适用于新增或重构 schema、替换导出的 interface/type 数据模型、修复 schema-first lint 违规、建模字面量域或带标签联合类型(tagged union)、应用 schema 默认值或转换、解码外部输入,或审查 schema 代码是否符合仓库规范(repo-law)。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 80
- Forks
- 14
01 前言 Front Matter
- name
- schema-first-development
- description
- 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, decoding external input, or reviewing schema code for repo-law compliance.
02 资源文件 4
- 参考文档references/examples.md5.6 KB
- 参考文档references/local-primitives.md6.2 KB
- 参考文档references/pattern-catalog.md8.0 KB
- 参考文档references/repo-laws.md11.5 KB
03 SKILL.md 正文
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:
standards/effect-first-development.mdpackages/tooling/tool/cli/src/commands/Lint/SchemaFirst.tsstandards/schema-first.inventory.jsonc
Keep Schema as the source of truth for pure data models.
Workflow
- Classify the task.
- New schema or domain model
- Refactor from exported
interface/ type literal - Boundary decode, transform, or defaulting work
- Literal domain or tagged union modeling
- Review or lint-fix
- Load only the reference file you need.
- Repository laws:
references/repo-laws.md - Local shared schema primitives:
references/local-primitives.md - Pattern selection and anti-patterns:
references/pattern-catalog.md - Real repository examples:
references/examples.md
- Check local Effect v4 source for nontrivial Schema API choices.
.repos/effectpoints to$HOME/YeeBois/references/effect/effect, the Effect child of the reference workspace; Effectmainis v4.
- Start with
.repos/effect/packages/effect/SCHEMA.md. - Confirm behavior in
.repos/effect/packages/effect/src/Schema.tsor the specialized module (SchemaAST,SchemaGetter,SchemaIssue,SchemaRepresentation,SchemaTransformation) when using advanced APIs. - Prefer exact upstream or repo-local helpers over memory and ad-hoc plumbing.
- Apply the laws in this order.
- Model pure data with
Schemafirst. - Model plain object data as a branded
S.Opaqueover an annotatedS.Struct(S.TaggedStructfor_tagdata). KeepS.Class/S.TaggedClass/S.Error/S.TaggedErrorfor errors, persisted entities, schemas with instance members, and.extendchains. Every schema class and Opaque declaration carries{ readonly brand: unique symbol }. - Check upstream
effect/Schemafirst, then reuse@beep/schemaand existing local schemas before inventing new checks. Where upstream covers afoundation/modelingconcept'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 instandards/architecture/DECISIONS.md"Upstream-First Foundation/Modeling"). - Move normalization, defaults, nullable handling, and JSON parsing into the schema.
- Annotate reusable non-class schemas with
.pipe($I.annoteSchema(...))(LiteralKitincluded); classes take$I.annote(...)as their trailing argument. - Derive guards, equivalence, arbitraries, codecs, tagged-union helpers, and literal helpers from the schema instead of writing parallel helpers.
- Prefer Effect schema codecs; map schema errors with
Effect.mapError(...)when the error leaves the local helper/module boundary.
- Verify before finishing.
- No exported pure-data
interfaceor type literal remains. - No schema value ends with
Schema. - Non-class schemas export same-name runtime type aliases.
- Tagged unions use the repo-preferred construction.
- Finite variants are modeled as discriminated unions instead of optional payload bags.
- JSON boundaries use schema codecs, not native JSON helpers.
Fast Rules
- Prefer
import * as S from "effect/Schema"and canonical Effect aliases. - Create file-local identity composers with
@beep/identity/packages. - Plain data is
class X extends S.Opaque<X, { readonly brand: unique symbol }>()(S.Struct({...}).pipe($I.annoteSchema("X", {...}))) {}. Construct withX.make(...); there is nonew X(...)and no.extend. Annotate the Struct inside the pipe, becauseX.annotate(...)drops the statics. Seereferences/repo-laws.mdsection 2. - Use named intermediate schemas for reused concepts.
- Prefer
LiteralKitfor named literal domains: its keyed API (.Enum,.is,match,.toTaggedUnion(...)) plus theS.Literalsmembers it inherits (.literals,.pick(...),.mapMembers(...)). UseS.Literalsfor anonymous inline unions never referenced by name. - Prefer
MappedLiteralKitwhen a protocol/code mapping needs both encoded and decoded literal helper surfaces. - Do not add
as constto inline array literals passed directly toLiteralKit(...); its const type parameters preserve the literal tuple. - Model finite variants, lifecycle states, status/result cases, and case-specific payloads as discriminated unions, not one optional/nullish payload bag.
- Decode external optional/nullish case bags into internal tagged models when compatibility requires the wire shape.
- Use
S.toTaggedUnion("<field>")for discriminators such askind,status,type,subtype,profile, orfamily. - Use
S.TaggedUnion(...)only for canonical_tagobject unions. - Fix a tag with
S.TaggedStruct/S.TaggedClass/S.TaggedError, and any other required single-literal field withS.tag(v), neverS.Literal(v);bun run beep laws schema-tag-idioms --checkenforces it. - Prefer schema-derived tagged-union helpers (
.cases,.guards,.isAnyOf,.match) when constructing, guarding, or branching on a schema tagged union. - Use
S.OptionFromNullOr,S.OptionFromNullishOrandS.OptionFromOptionalKeyfor absence at the boundary. Optional fields use exact keys (EF-40):S.optionalKey,S.withDecodingDefaultKey,S.OptionFromOptionalKey, never theirundefined-admitting siblings. - Use
S.OptionFrom*when the wire/schema field is optional or nullish. If runtimeOptionvalues are already being shaped into an object, preferO.getSomesStruct({...})(@beep/utils) for heterogeneous struct spreads with known keys — runtime-identical toR.getSomesbut type-preserving per key; reserveR.getSomes({...})for homogeneous dynamic-key dictionaries. UseO.all({...})for all-or-nothing fixed-shape composition. (Amended 2026-07-05 — seestandards/architecture/DECISIONS.md.) - Use
S.withConstructorDefault(...),S.withDecodingDefaultKey(...), andS.decodeTo(...)withSchemaTransformationfor normalization and fallback behavior. - Prefer built-in schema constructors and checks before
S.makeFilter(...). - Treat broad exported/domain/boundary primitives such as
S.String,S.Number, and unbounded arrays as prompts to ask whether the schema should be more precise. - If you need a custom reusable check, include
identifier,title, anddescription. - Use
S.is(schema)for guards,S.toEquivalence(schema)for comparisons, andArbitrary.schema(schema)(effect/Arbitrary) for schema-modeled property tests. - Use
S.fromJsonString(S.Unknown)orS.fromJsonString(schema)for JSON string boundaries. - Use
S.decodeUnknownEffect/S.decodeEffectandS.encodeUnknownEffect/S.encodeEffectby default. Reach forS.decodeUnknownResult,S.decodeResult, orS.decodeUnknownOptiononly for deliberate non-throwing synchronous helpers; do not teach or addS.decodeSync,S.decodeUnknownSync,S.encodeSync, orS.encodeUnknownSync. If a legacy synchronous wrapper must still throw, convert Result failures withResult.getOrThrowWith(...)so raw schema issues do not escape the boundary.
Escalation
- Use
effect-first-developmentwhen the task is broader than schema work, including service/layer wiring and typed error flow outside schema modeling.
04 同仓库更多 Skills
alchemy-provider
Bring up a new Alchemy cloud provider (its own `@alchemy.run/<provider>` package under packages/<provider>) end to end — credentials, a distilled SDK, resources, bindings, live tests, and the patch loop that feeds live-test failures back into distilled — or extend an existing provider with a new service, or bring an existing provider up to the bar (gap audit, then waves). Use for "add a <X> provider", "create an alchemy provider for <X>", "port <X> to alchemy", "add <service> to the <X> provider", "bring the <X> provider up to par", or any work that needs a distilled SDK plus Alchemy resources tested against a live API.
alchemy-domain
Build backends with @alchemy.run/domain (domain-driven design on Effect) - turn requirements into aggregates, commands, events, rejections, views, policies, sagas, projections, streams, queries, external systems and Apis; lay them out in a monorepo (domain / server / web packages, kind-suffixed files); test them with stories; host them on Durable Objects (Cloudflare, Rivet or Effect Cluster) with alchemy; and drive them from a foldkit frontend. Use when designing or changing an @alchemy.run/domain model, adding a building block, wiring hosting or a frontend, or reviewing such code.
update-harnesses
Update every agent harness on every fleet host: T3 Code, Codex, Claude Code, Grok Build, Kimi Code, Junie, Cursor Agent and Muse on DankStation, beep-worker, dankserver, tbk-worker, tom-pc-1-wsl and the grok-bot VM, plus the desktop apps (ChatGPT and Claude Desktop on DankStation and grok-bot; Cursor and Kimi Desktop on DankStation). Use on `/update-harnesses`, when a harness is out of date somewhere, or to audit which versions and install methods each host runs.
auth-environments
Sign Claude Code in to a chosen Claude subscription on every linked T3 fleet host (grok-bot, beep-worker, dankserver, tbk-worker, tom-pc-1-wsl). Use when a Claude account hits its weekly limit, when `bun run beep accounts` shows the fleet's account used up, or on `/auth-environments`. Opens each host's OAuth page and a masked KDE code dialog together and verifies the admitted account.
shadcn 技能来源校验
shadcn
用于 shadcn 技能不可变来源(provenance)的固定装置(fixture)。
QA 库存判定
qa-inventory-judge
暂无简介