Instruction file imported from AIHeart-Professional/MCP_Server (
.github/instructions/code-reuse.instructions.md). Copyright stays with the author.
Code Reuse — Pre-Implementation Check (Mandatory)
BLOCKING REQUIREMENT: Before writing any new function, class, method, route, service, use case, database query, or utility, you MUST perform all steps below. This applies to every implementation request without exception.
Step 1 — Read KEYWORDS from Existing Docstrings
Search for any function whose KEYWORDS overlap with what you are about to write:
grep_search("KEYWORDS:.*<domain_term>|KEYWORDS:.*<action_term>", isRegexp=True)
- Extract 3–6 domain/action keywords from the request.
- Any function with 2+ keyword matches is a reuse candidate — read it before proceeding.
Step 2 — Run a Semantic Search
semantic_search("<natural language description of the feature>")
Review the top 5–10 results. Look for exact matches, partial matches, or composable helpers.
Step 3 — Declare Your Finding Before Writing Code
Before any implementation, explicitly state one of:
- ♻️ Reuse: "Function
Xinpath/to/file.pyalready does this — I will call/extend it." - 🔀 Compose: "Functions
XandYcan be composed to cover this — I will use them." - 🆕 New: "No existing implementation found after checking KEYWORDS and semantic search. New code is required."
Only proceed to write new code after reaching a 🆕 New conclusion.
Rule Summary
- NEVER write a new function without completing Steps 1–3 first.
- NEVER duplicate logic that already exists in the codebase.
- ALWAYS prefer calling/importing an existing function over reimplementing it.
- ALWAYS prefer composing two existing functions over writing a new one.