| name | cp-code-style |
| description | Code-writing style and validation workflow for the /home/kkkzbh/code/cp KCP compiler repo. Use before editing C++ modules, tests, CMake, or project documentation that replaces code_style.md. |
CP Code Style
Overview
Use this skill before changing code in this repo. Keep the source modern, direct, and invariant-driven: do not hide broken assumptions with fallback code; put mechanical checks into scripts and structural invariants into tests.
Workflow
- Read nearby modules first and follow their current module, naming, and layout boundaries.
- Make the smallest coherent change that improves the architecture; do not add compatibility aliases unless the user asks.
- After edits, run:
python3 .codex/skills/cp-code-style/scripts/check_cp_style.py
Then run the relevant build/test command for the touched surface.
C++ Style
Architecture Principles
- Make illegal states explicit at the type, API, or test boundary instead of letting them drift through production code.
- Do not use broad fallback branches to hide broken assumptions. If a state is architecturally impossible, expose the invariant violation and fix the upstream boundary.
- Prefer repairing the source of an invariant violation over patching downstream symptoms.
- Keep production code direct and focused on the valid execution path. Put internal invariant checks in tests; reserve production contracts for real external boundaries.
- For closed, unreachable production paths, use language-level unreachable markers where appropriate instead of exception-based internal control flow.
- Keep runtime and link dependencies scoped to the targets that actually need them.
Deterministic Checks
The script at scripts/check_cp_style.py intentionally checks only simple, low-false-positive rules: user-defined class, prefix const T&/const T*, non-trailing function return types, same-line function attributes, declaration specifier order around auto, explicit optional .has_value(), banned .at(), obvious pair/tuple/optional parenthesized construction, and obvious construct-then-insert container calls such as push_back(Type{...}) or emplace_back(Type{...}). Formatting and alignment rules live primarily in this skill text because they need judgment.