ks-cookbook / rules
Cursor rule9 starsChanged 7 months agoMITView on GitHub
Python clean code for cookbook flagships and recipes
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,263 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/flagship_author.mdcCursor rule
- .cursor/rules/recipe_author.mdcCursor rule
The file
We split this python_clean_code.mdc into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
No copy-pasted agent wiring across flagships.
- Distinctive: line 29
No speculative abstractions.
- Very specific: line 34
No magic UUIDs or strings in code.
- Distinctive: line 40
Only write comments that explain why (a hidden constraint, a workaround, a non-obvious tradeoff).
- Distinctive: line 46
No function that orchestrates, does I/O, and transforms data.
- Distinctive: line 51
Never swallow an exception silently.
- Very specific: line 57
Prefer explicit types on public functions (-> Memo, -> list[Hit]).
- Very specific: line 58
Use pathlib.Path, never os.path.
- Very specific: line 59
Use pydantic for every structured output.
- Distinctive: line 68
If a fact isn't in the retrieved material, say so and lower confidence.
≈ “Common” is an estimate: at least 1 in 5 of the 7,111 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
--- description: Python clean code for cookbook flagships and recipes alwaysApply: false --- # Clean-code rules for ks-cookbook Applies to every Python file under `flagships/`, `recipes/`, and `mcp-python/`. ## Hard constraints ### SRP - Each function does one thing. If its name or its docstring needs "and", split it. - Each module has one concern. `agent.py` wires the agent; `schema.py` holds the output model; `__main__.py` is CLI-only. ### Small units - Functions ≤ 30 lines. - Modules ≤ 200 lines unless there is a clear reason. - Recipes ≤ 100 LOC total (docstrings + comments don't count). Larger → promote to `flagships/`. ### Naming - Intent-revealing. No `data`, `info`, `handler`, `manager` unless domain-meaningful. - Boolean predicates: `is_*`, `has_*`, `should_*`. ### DRY & composition - No copy-pasted agent wiring across flagships. Use the same `MCPServerStdio` boilerplate; if you find yourself duplicating more than a few lines across files, factor into `_shared/`. ### KISS - No speculative abstractions. Three similar lines beats a premature helper. ## Forbidden ### Magic values - No magic UUIDs or strings in code. Folder IDs belong in the Makefile as per-demo env defaults, not hardcoded in `agent.py`. ### Deep nesting - Guard clauses and early returns. Max nesting depth 3. ### "What" comments - Only write comments that explain **why** (a hidden constraint, a workaround, a non-obvious tradeoff). Never comments that describe what a line does. ### Error codes / sentinel returns - Raise an exception or return a typed result. No `return None` to signal "failure" alongside valid `None`. ### God functions - No function that orchestrates, does I/O, and transforms data. Split into pure helpers + a thin orchestrator. ## Error handling - Errors surface as exceptions, typed when possible. - Never swallow an exception silently. If retrieval fails, say so in the output — don't emit made-up content. - For MCP tool calls, let `MCPServerStdio` errors propagate. The CLI (`__main__.py`) catches and prints a useful message before exiting non-zero. ## Style - PEP 8 via `ruff`. Line-length 100. Import order enforced (`ruff check`). - Prefer explicit types on public functions (`-> Memo`, `-> list[Hit]`). Private helpers can infer. - Use `pathlib.Path`, never `os.path`. - Use `pydantic` for every structured output. Never return a raw `dict` from an agent. ## The four prompt invariants These are in every flagship system prompt and must stay there: 1. Enumerate with `list_contents(folder_id=__CORPUS_FOLDER_ID__)` first. 2. Pass UUID `path_part_id` values to `read` — not document names. 3. Citations (`Citation.chunk_id`, or inline `[chunk:<uuid>]` tags) must be copied verbatim from `read` output. Never synthesize. 4. If a fact isn't in the retrieved material, say so and lower confidence. Do not fabricate numbers.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

