agentleFS
wangxiaohuiboywangxiaohuiboy/lean-agent-skills/skills/lean-diff/SKILL.md

lean-diff

Skill0 starsChanged 2 months agoMITView on GitHub

Solve a coding request with the smallest correct change. Use for features, bug fixes, and refactors when scope discipline matters, when the user asks for minimal code, or when prior attempts over-built the solution. Not for greenfield design work where a real architecture is the point.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Stop at the first rung that holds:

    line 16
  2. Distinctive:

    Does an installed dependency do it?: Use what is already in the tree before adding anything.

    line 22
  3. Distinctive:

    Can it be one line or a config change?: Do that.

    line 23
  4. Distinctive:

    Only then: write the minimum code that works.

    line 24
  5. Distinctive:

    When two standard-library approaches are the same size, pick the one that is correct at the edges.

    line 56
  6. Distinctive:

    When you knowingly take the cheaper option with a real ceiling — an O(n²) scan, a global lock, a naive heuristic, a hard-coded region — …

    line 60
  7. Distinctive:

    Keep it to a few lines: what changed, what you deliberately did not do, and the one thing worth watching.

    line 74

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Lean Diff

The best code is the code that did not need to be written. Be efficient, not careless: a small diff you do not understand is not lean, it is a second bug.

Read before you climb

The ladder below runs after you understand the problem, never instead of it. Read the code the task touches and trace the real flow end to end. Every rung you skip in understanding comes back as a wrong edit.

The solution ladder

Stop at the first rung that holds:

  1. Does this need to exist at all? A local script, a manual step, or the feature the user already has may cover it. Say so in one line and propose the smaller option.
  2. Does this repo already do it? Reuse the existing helper, hook, or pattern. Grep before you write.
  3. Does the standard library do it? Intl, pathlib, URL, structuredClone, crypto.randomUUID over a package.
  4. Does the platform do it? Native <dialog>, CSS clamp()/:has(), fetch, file input, AbortController, database constraints over application code.
  5. Does an installed dependency do it? Use what is already in the tree before adding anything.
  6. Can it be one line or a config change? Do that.
  7. Only then write the minimum code that works.

Bug fix means root cause

A bug report names a symptom. Before patching:

  1. Find every caller of the function you are about to touch — rg -n 'functionName\('.
  2. Decide where the invariant actually belongs. One guard at the shared function is usually a smaller diff than one per caller.
  3. Fix once, at the narrowest shared point that covers all real callers.

Patching only the path the report names leaves sibling callers broken — that is not a small diff, it is an unfinished one.

Do not add

  • Abstractions that were not requested; an interface with one implementation; a factory with one product.
  • Configuration for a value that is used once.
  • A dependency for one function.
  • Boilerplate, scaffolding, or generated files nobody asked for.
  • Error handling for states that cannot occur.
  • Tests for trivial one-liners.
  • A rewrite of working adjacent code. Leave the neighborhood as you found it.

Do not skip

Laziness is about code volume, not rigor. These are never on the chopping block:

  • Input validation at trust boundaries.
  • Error handling that prevents data loss.
  • Security, and accessibility.
  • Behavior the user explicitly asked for.
  • Correct handling of the real platform: clock drift, sensor calibration, partial failures, the network being absent.

When two standard-library approaches are the same size, pick the one that is correct at the edges. Lean means less code, not a flimsier algorithm.

Mark deliberate shortcuts

When you knowingly take the cheaper option with a real ceiling — an O(n²) scan, a global lock, a naive heuristic, a hard-coded region — leave one line naming the ceiling and the upgrade path:

// lean: global lock; fine below ~1k req/s. Upgrade: per-key sharded locks.

This is what separates a deliberate trade-off from an accident.

Finish with one check

Non-trivial logic leaves one runnable check behind — the smallest thing that fails if the logic breaks. Prefer a single test in the repo's existing framework, or a tiny assert-based script when there is none. Do not introduce a test framework, fixtures, or a matrix of cases for a change this size. Trivial one-liners need no test.

Report the shape of the change

Keep it to a few lines: what changed, what you deliberately did not do, and the one thing worth watching. If you skipped a plausible approach, name it in one clause so the user knows it was a decision rather than an oversight.

See references/ladder-examples.md for worked examples of each rung.

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.