agentleFS
Fergius-EngineeringFergius-Engineering/instincts/skills/no-duplicate-logic/SKILL.md

no-duplicate-logic

Skill2 starsChanged 4 months agoMITView on GitHub

Use when adding a case, check, or branch to a function that already exists, especially after jumping straight to the insertion point.

The file

Files
SKILL.md

The rule

Before you add logic to a function that already exists, read the whole function. The case you're about to write is often already handled a few lines down. A second block that produces the same result doesn't replace the first — both run, and the output silently doubles. The fix you needed was usually three lines added to the block that's already there, not a new block beside it.

This is not the same as fixing in the shared layer. That's about where a bug lives across callers. This is narrower: don't paste a parallel branch inside one function without reading what's already in it.

Fires when

Adding a case, branch, check, or emit to an existing function, handler, switch, or validation pass — especially when you jumped straight to the insertion point without reading the rest of the function.

How to apply

Before adding logic that emits a result keyed by some id or name, search the whole function for that id or that result. If a block already handles it, extend that block instead of adding a new one. Read the function top to bottom before you insert anything into it.

Worked example

A validation function already emits a "bad-name" issue for a record. You add a new block to emit "bad-name" without noticing the existing one a screen above. Now every bad-named record produces two identical issues, and a count somewhere is quietly off by a factor of two. The real change was three lines inside the block that was already there. Reading the function before inserting would have shown it.

Red flags

ThoughtReality
"I'll just add the block here"The block may already exist above; read first.
"It's a new case"Check it's actually new before you write it.
"The function's long, I'll jump to the spot"Jumping to the spot is how you duplicate the spot.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.