{"name":"review-type-invariants-prompt","description":"A prompt that reviews the types or classes in a change for how well they protect their rules - lists each invariant, rates encapsulation, expression, usefulness and enforcement 1-10, and suggests changes that make illegal states unrepresentable without over-engineering. Use when the user adds a new type or domain model, wants type design reviewed, or keeps hitting bugs from invalid state.","category":"coding-prompts","tags":["typescript","architecture","code-review","quality"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/review-type-invariants-prompt","api_url":"https://theskillvault.ai/api/skills/review-type-invariants-prompt","raw_url":"https://theskillvault.ai/api/skills/review-type-invariants-prompt/raw","body":"# Review type invariants (prompt)\n\nGood types make bugs hard to write. If an order can be both \"paid\" and \"refunded\", or an email field can hold any string, the code has to guard against it everywhere. This prompt reviews each new type and asks how well it protects its own rules.\n\n## When to use\n- You added a new type, class or domain model and want its design checked.\n- A change adds several data types and you want them reviewed together.\n- Bugs keep coming from objects in states that should not exist.\n\n## When not to use\n- You want the words and names in your domain sorted out first. Use model-domain-and-glossary-prompt.\n- You want database tables designed. Use design-postgres-tables.\n- You want a broad review of a whole branch's structure. Use review-maintainability-strictly-prompt.\n\n## Steps\n1. Commit your work, then open the branch in your AI coding tool.\n2. Paste the prompt below. Change the base branch, or name the types to review.\n3. Read the invariants list for each type first. Correct any rule the AI got wrong before reading the ratings.\n4. Pick the improvements worth their cost. Prefer small ones such as a validating constructor or a union of states.\n5. Add a test that tries to build an invalid value, then make the change and run the tests.\n\n## Prompt\n```text\nReview the design of each type, class, interface or schema added or changed in this branch (git diff main...HEAD). Do not edit code yet.\n\nFor each type:\n1. Invariants: list the rules it must always keep, such as field relationships, allowed values, valid state changes and pre and post conditions. Say which are enforced and which are only assumed.\n2. Rate 1-10, with one line of reasons each:\n   - Encapsulation: can outside code break the rules? Are internals hidden and the interface small?\n   - Expression: are the rules visible in the type itself, ideally checked at compile time?\n   - Usefulness: do the rules prevent real bugs and match the business need, without being too strict?\n   - Enforcement: are rules checked on creation and on every change? Can an invalid value be built?\n3. Flag: exposed mutable internals; rules kept only in comments; no validation at construction; some mutators checking rules and others not; types doing too many jobs; plain data bags where behaviour belongs with the data; booleans or optional fields that allow impossible combinations.\n\nPrefer compile-time guarantees, immutability and making invalid states impossible to represent. Weigh each suggestion against the complexity and breaking changes it adds; a simpler type can be the better answer.\nOutput per type: invariants; four ratings with reasons; strengths; concerns; up to three recommended changes, smallest first, with a short code sketch.\n```\n\n## How to adapt\n- Not TypeScript? Name your language. In Python ask for dataclasses or Pydantic, in Rust for enums and newtypes.\n- Types come from an API or database schema? Ask it to check where the data is parsed and validated at the boundary.\n- Reviewing existing code? Replace the diff with \"the types in src/orders/\".\n- Team prefers plain data and functions over classes? Say so, and it will suggest constructors and unions instead.\n\n## Gotchas\n- Ratings are opinions, not measurements. Use them to compare types, not as a target score.\n- Stricter types can break callers. Check who uses a type before you change it.\n- Types for secrets, such as API keys or tokens, should not print their value in logs or toString output.\n\n## Portability\nWorks with any typed language and any AI coding tool or chat AI. In a chat without repo access, paste the type definitions and the code that creates them.\n\n## Done when\n- Each new type has its invariants written down and checked by someone who knows the domain.\n- Accepted changes have a test showing an invalid value is now rejected or cannot be built.\n- No accepted change added more complexity than the bugs it prevents.\n\n## Example prompt\n\"Review the new types in my branch. List the rules each must keep, rate encapsulation, expression, usefulness and enforcement 1 to 10, and suggest the smallest changes that make invalid states impossible.\"\n\n---\nModified from the \"type-design-analyzer\" agent in anthropics/claude-plugins-official (pr-review-toolkit, by Anthropic; README credits Daisy). Licensed Apache-2.0 per the LICENSE file at commit a7ba5b9. Original: https://github.com/anthropics/claude-plugins-official/blob/a7ba5b93db0c7c8d17f3f1d25853adca79598a1a/plugins/pr-review-toolkit/agents/type-design-analyzer.md. Changes by TheSkillVault are listed in the metadata above and in NOTICE.txt. See LICENSE.txt.","files":["LICENSE.txt","NOTICE.txt"],"license":"Apache-2.0","license_name":"Apache License 2.0","license_url":"https://www.apache.org/licenses/LICENSE-2.0","attribution":"Based on work by Anthropic (anthropics/claude-plugins-official, pr-review-toolkit, type-design-analyzer; the plugin README credits Daisy, daisy@anthropic.com) (Anthropic (the upstream LICENSE keeps the blank Apache template line 'Copyright [yyyy] [name of copyright owner]'; no other copyright notice at this commit). Apache License 2.0 text in LICENSE.txt, attributions in NOTICE.txt, Apache License 2.0), https://github.com/anthropics/claude-plugins-official/blob/a7ba5b93db0c7c8d17f3f1d25853adca79598a1a/plugins/pr-review-toolkit/agents/type-design-analyzer.md; adapted by TheSkillVault, https://theskillvault.ai","install":{"claude_code":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/raw' -o ~/'.claude/skills/review-type-invariants-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/files/LICENSE.txt' -o ~/'.claude/skills/review-type-invariants-prompt/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/files/NOTICE.txt' -o ~/'.claude/skills/review-type-invariants-prompt/NOTICE.txt'","cursor":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/raw' -o '.cursor/skills/review-type-invariants-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/files/LICENSE.txt' -o '.cursor/skills/review-type-invariants-prompt/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/files/NOTICE.txt' -o '.cursor/skills/review-type-invariants-prompt/NOTICE.txt'","agents":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/raw' -o '.agents/skills/review-type-invariants-prompt/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/files/LICENSE.txt' -o '.agents/skills/review-type-invariants-prompt/LICENSE.txt' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/review-type-invariants-prompt/files/NOTICE.txt' -o '.agents/skills/review-type-invariants-prompt/NOTICE.txt'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-03T21:40:06.669Z"}}