Skip to content
Courses/Codex for programmers/Repository hygiene: remove redundancy without breaking behavior

Repository hygiene: remove redundancy without breaking behavior

Turn a vague refactor into measurable work: baseline, scope, justified deletions, tests, and a final diff.

The problem is not that the agent writes a lot

The problem starts when every iteration adds a layer without removing the previous one: forwarding wrappers, unused legacy aliases, duplicate validation, and exports that enlarge the public contract. Tests may remain green while the repository becomes harder to understand and change.

A post detected by Aulafy's X radar was used only as a demand signal. The technical method comes from official documentation and a reproducible lab; a social report alone does not prove that a tool causes technical debt.

Five gates for a safe refactor

  • Baseline: run tests and record Git state before editing.
  • Contract: identify imports, exports, effects, and outputs that must remain.
  • Budget: limit files and forbid unnecessary dependencies or abstractions.
  • Evidence: require green behavior tests and a separate structural audit.
  • Diff: explain every deletion and confirm tests were not weakened to hide a regression.
Terminal
git status --short
git diff --stat
npm test

# After the change
npm test
npm run auditar
git diff --numstat -- src/tasks.mjs
git diff -- src/tasks.mjs

Green tests do not mean a clean repository

Behavior tests answer “does it still work?”. A structural audit can answer “were the agreed wrappers removed?” or “did the public API stay within its budget?”. You need both signals: line count alone can reward compressed code, while a suite alone may ignore dead code.

What to ask the agent

Official Codex guidance recommends stating the goal, context, constraints, and definition of done, then running checks and reviewing the diff. Claude Code documentation likewise recommends giving the agent a way to verify its work and keeping project instructions concise.

Terminal
Goal: remove redundant wrappers without changing the API covered by tests.
Context: read AGENTS.md, src/tasks.mjs, and test/tasks.test.mjs.
Boundaries: edit only src/tasks.mjs; do not change tests or package.json; add no dependency or abstraction.
Done when: npm test and npm run auditar pass; the diff deletes more than it adds; explain every deletion and remaining risk.

Review the result

  • Reject test edits that merely adapt expectations to a regression.
  • Look for new names hiding the same old abstraction.
  • Check consumers outside the file before removing a real export.
  • Do not use fewer lines as the only criterion: readability and contract matter.
  • Start in a training repository or reversible branch.

MIT lab

The aulafy/taller repository provides a working but redundant baseline, a dependency-free test suite, an audit that intentionally fails at first, and a reference solution. You can repeat the same exercise with Codex, Claude Code, or manually.

Lesson deliverable

What you will build

A small refactor that reduces an API from six functions to three without changing any tested output.

Why it matters

You will require justified deletions and evidence instead of accepting new code merely because the agent calls it clean.

Starter repository or files

Clone aulafy/taller and open cursos/codex-programadores/laboratorios/higiene-repositorio-agentes. It uses synthetic data and no dependencies.

Steps

  1. 1. Run npm test and confirm all three tests pass.
  2. 2. Run npm run auditar and preserve the expected initial failure.
  3. 3. Give Codex the bounded task from this lesson.
  4. 4. Run tests and the audit again without editing the suite.
  5. 5. Read git diff --numstat and the full diff; justify every deletion.

Copy-ready Codex request

Goal: reduce redundancy in src/tasks.mjs without changing behavior. Read AGENTS.md and the tests. Edit only src/tasks.mjs; do not change tests or package.json; add no dependencies or abstractions. Finish only when npm test and npm run auditar pass. Review the diff, explain each deletion, and state risks.

Expected result

Three public functions, identical outputs, three green tests, and a passing structural audit.

Verification command

npm test && npm run auditar && git diff --numstat -- src/tasks.mjs

Manual check

Confirm only src/tasks.mjs changed, no tests were weakened, and the result is clearer rather than merely shorter.

Common error. Asking to “clean the whole repo” produces changes that are hard to attribute. Bound the file, contract, and checks first.

Mini exercise

First add a test for an empty owner and repeat the refactor; decide whether the default belongs in createTask or normalizeText.

Show solution

Keep normalizeText, createTask, and formatTask. Call normalizeText directly from createTask and remove the three unconsumed wrappers.

Evidence to save

Save before-and-after output, the initial audit failure, numeric diff, full diff, and an explanation of the three deletions.

Complete Aulafy mapSee how this lesson fits without leaving your path.

Complete Aulafy map

How all courses connect

This is not a checklist. Start with the foundation, choose an outcome, and go deeper only when your project needs more control.

  1. 1Understand
  2. 2Apply or build
  3. 3Operate with confidence
01

Choose an application

Turn the foundation into a visible outcome: a website, a business improvement, media, or an interactive experience.

Continue into the technical branch when you need to maintain code, data, or infrastructure.

02

Build with code

Prepare your environment, work with coding agents, and run models while keeping control of your projects.

This branch prepares you to design and operate reliable AI systems.

03

Take systems to production

Combine retrieval, agents, evaluation, security, deployment, and model adaptation when the problem requires it.

You do not need every course: choose the component your system needs and return as it grows.

View full catalogue