Le secrétaire de Fernand

Step 3: A dead-code finder in the loop

Step 3: A dead-code finder in the loop

The third step of the harness I put around my coding agents: a dead-code finder in the agent's loop, as an error, so the agent deletes its own leftovers.

1 min read

Part of the series: Codebase Harness, Step by Step · View all parts

Previously in this series: Step 2: The strictest linter

An agent rewrites a function and leaves the old one behind: nobody calls it, nothing flags it, and the next session may build on it. Put a dead-code finder in the agent's loop, as an error, and it deletes its leftovers before you ever see them. In TypeScript, knip.

Böckeler's grid

Two dimensions. A guide acts before the agent, a sensor after. Each is inferential, judged by a model, or computational, decided by a program. Inferential guides are what the agent reads, AGENTS.md, a skill, a plan, sharper written in the literature's words; computational guides are deterministic tools, a codemod, a generator, a command that acts in the agent's place, code mode, where the agent writes a program instead of a string of actions, a language server. Inferential sensors are a review by a model or a person; computational sensors are the type checker, the linter, tests and fitness functions. Each practice moves a judgement toward computation, and the computational sensor is the optimum.

Inferentiala model judges, your attention follows
Computationala program decides, without your attention
Guidesbefore the agent acts
AGENTS.md · a skill · a plan, in the literature's words
toward computation
a codemod · a generator · a command (CLI) · code mode · a language server
Sensorsafter the agent acts
a review by a model or a person
toward computation
the optimum
  1. 1 · type checker
  2. 2 · linter
  3. 3 · dead codetoday

In Birgitta Böckeler's grid of guides and sensors, knip is a computational sensor: it looks at the whole project after the agent acts, and answers the same every time. The series' map: Guides and Sensors: Mapping Your Attention to Free It

Why a tool of its own

The linter sees an unused variable inside a file. knip sees what no single file can: an export nobody imports, a file nobody reaches, a dependency nobody uses.

Make it fail the check, not warn. A warning is one more thing for you to notice; an error is the agent's to fix before the commit.

If you want an example, here is my knip config: lbdremy/phax/knip.json

A thought after reading?

If you would like to discuss about this article, you can write to me here. I share because I care and I want to learn. Please teach me with care.

Send me an emailremy@lesecretairedefernand.co