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.
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.
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. Run npm test and confirm all three tests pass.
- 2. Run npm run auditar and preserve the expected initial failure.
- 3. Give Codex the bounded task from this lesson.
- 4. Run tests and the audit again without editing the suite.
- 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.
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.