typedown-expert
Expert guidance on writing correct Typedown code, focusing on syntax, best practices, and common pitfalls.
What this skill does
# Typedown Expert
This skill provides expert knowledge for writing **Typedown** files (`.td`). Typedown is a Consensus Modeling Language that embeds Pydantic models and Pytest logic into Markdown.
## Core Syntax Rules
1. **File Structure**:
- Typedown files are valid Markdown files.
- They consist of natural language text interleaved with special Code Blocks.
- **Crucial**: Every `.td` file MUST start with a Level 1 Heading (`# Title`) and a brief textual description. Never start with a code block.
2. **Model Blocks (`model:<Name>`)**:
- Used to define Pydantic models.
- **One Model Per Block**: Do NOT define multiple classes in a single block. Each class gets its own `model:ClassName` block.
- **No Imports in Block**: Do NOT import `typing` or `pydantic` inside the block unless it's a specific, non-standard import. The environment pre-loads standard types.
- **Class Name Match**: The class defined MUST match the block argument (e.g., `class User` inside ` ```model:User `).
3. **Config Blocks (`config`)**:
- Used for global configuration and exports.
- **Location**: Strictly restricted to `config.td` files only. Do NOT use `config` blocks in regular `.td` files.
- **Exposure**: All symbols defined in `config` are automatically exposed to the directory scope and inherited by subdirectories.
4. **Entity Blocks & Identifiers**:
- Every Entity MUST have a unique identity.
- **Syntax**: `entity <Type>: <ID>`
- **The ID**:
- The string after the colon is the entity identifier.
- **Styles**: Can be a simple name (`alice`) or a slug (`user-alice-v1`).
- **Content**: Valid YAML matching the Pydantic model.
- **Reference Rule**: When referencing other entities within an entity block, you **MUST** use the `[[ID]]` (Wiki Link) syntax.
5. **References (`[[...]]`)**:
- Typedown supports two reference forms:
1. **ID Reference**: `[[id]]`
- Lookup by name in the current scope or global index.
- Examples: `[[alice]]`, `[[users/alice]]`
2. **Hash Reference**: `[[sha256:...]]`
- Match content hash exactly for immutable references.
- Used for version locking and history tracking.
6. **Evolution Semantics (`former`)**:
When tracking object changes over time:
- **Syntax**: `former: [[<Identifier>]]`
- **Rule**: You **MUST** use the reference syntax `[[]]` for the `former` field.
- **Rule**: Prefer using **Content Hash** for `former` pointers to ensure historical stability. Globally unique IDs are also acceptable.
7. **Spec Blocks (`spec`)**:
- Used for validation logic.
- Contains Python functions decorating with `@target`.
## The Typedown Mindset: Consensus Modeling
Typedown is not just a syntax; it is a rigorous method for converting loose natural language into strict systemic consensus. When using Typedown, follow this 5-step cognitive process:
### 1. Entity Discovery (Identification)
Scan the unstructured text or requirement to identify Key Entities. Immediately instantiate them using `entity` blocks to fix their existence.
- **Action**: Create `entity:<Type>` blocks with YAML content.
- **Goal**: Turn "User Alice" into data.
### 2. Schema Abstraction (Structure)
Analyze the `entity` blocks you just created. Abstract their common structure into Pydantic models (`model`).
- **Action**: Define `model:<Type>` blocks.
- **Context**: Place shared models in a parent `config.td` or `common.td` and `export` them if they are used across multiple files.
### 3. Constraint Engineering (Logic)
Analyze the business rules governing these entities. Enforce them using three layers of defense:
- **Layer 1 (Field Types)**: Use strict types (e.g., `EmailStr`, `PositiveInt`).
- **Layer 2 (Validators)**: Use Pydantic `@field_validator` or `@model_validator` for self-contained consistency.
- **Layer 3 (Specs)**: Use `spec` blocks with `@target` tags for cross-entity or graph-level validation (e.g., "A specific user must exist in the admin group").
### 4. Reference & Learning (Research)
If you are unsure about advanced syntax (e.g., how to use `former` for versioning or `tags` for filtering):
- **Action**: Create a `_reference` directory (it is git-ignored).
- **Action**: Clone the official repo: `git clone https://github.com/IndenScale/typedown.git _reference/typedown`.
- **Action**: Read `docs/` or `cookbook/01_getting_started/` in the reference to ground your knowledge.
### 5. Verification (Feedback)
Never assume your code is correct. Always verify with the compiler.
- **Action**: Run `uvx typedown check <path>` immediately after editing.
- **Action**: Treat warnings as errors.
## Example: The Modeling Loop
- Step 1: Raw Draft
"We need a server 'Alpha' compliant with ISO-27001."
- Step 2: Typedown Modeling
```model:ComplianceStandard
class ComplianceStandard(str, Enum):
ISO_27001 = "ISO-27001"
SOC2 = "SOC2"
```
```model:Server
class Server(BaseModel):
hostname: str
compliance: List[ComplianceStandard]
@model_validator(mode='after')
def check_security(self):
if ComplianceStandard.ISO_27001 in self.compliance:
# Enforce some logic...
pass
return self
```
```entity Server: alpha-01
hostname: "alpha-01"
compliance:
- "ISO-27001"
```
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.