Frog Wizard

Rewrite from a generated specification

I rewrite old programs by having the model write a spec from the code, fixing the spec, and then generating new code from the spec. The spec is the thing I keep. The legacy code is discarded entirely to prevent polluting the context.

1. Ask for a spec.

Read this codebase. Do not change it. Write a spec:
- every input (args, env, files, network, stdin) and its shape
- every output (files, exit codes, stdout, side effects) and its shape
- the rules that map inputs to outputs, numbered
- edge cases the code handles on purpose
Flag anything that looks accidental.

2. Fix the spec. Remove rules that only exist because of bad design. Add the ones the program should have had. Save a few real input/output examples from the old program as fixtures.

3. Delete the code. Open a fresh session with the spec and the fixtures.

Write a test for every numbered rule in this spec, plus the fixtures.
Then implement the spec until the tests pass.

Keep the spec in the repo. Next time, skip step 1.

#agents #ai #refactoring