5.4 Add one feature without regressions

Overview and links for this section of the guide.

Goal: add one feature safely

This is the moment where vibe coding either becomes engineering—or becomes spaghetti. You’re going to add one feature without breaking anything else.

The rule

One feature per loop. If you try to add three things at once, you won’t know what caused the break.

Pick a feature with tight scope

Choose something that:

  • does not require rewriting the parser from scratch,
  • can be validated with 3–6 tests,
  • does not expand the CLI surface too much.

Feature we’ll use: add an interactive REPL mode (--repl) while preserving the existing “one expression as an argument” mode.

Write the mini spec (1 screen)

Write the spec before you prompt. Keep it small and testable.

  • New behavior: python -m calc --repl starts an interactive session.
  • Prompt: show calc> before each input line.
  • Exit: exit or quit ends the session with exit code 0.
  • Blank lines: ignored.
  • Errors: invalid expressions print an error and continue (do not crash the REPL).
  • Existing behavior unchanged: python -m calc "2+2" still works exactly as before.
Notice what’s not in the spec

No history, no variables, no fancy commands. You’re buying reliability, not features.

Lock it with tests first

Before implementation, add tests that fail until the feature exists. For REPL, the easiest way is to make the CLI entrypoint testable with injected stdin/stdout (if you didn’t do this in refactor, do it now).

Example test ideas

  • REPL reads 2+2 then exit and prints 4.
  • REPL handles 2+*3 by printing an error and continuing.
  • Non-REPL path still returns the same exit code behavior.
“Tests first” can be light

You don’t need a perfect test suite. You need enough truth to catch regressions and prove the feature works.

A feature prompt that avoids regressions

We have a working Python CLI calculator with tests.

Feature: add an interactive REPL mode enabled by `--repl`.

Requirements:
- Existing behavior for `python -m calc "expr"` must remain unchanged
- In REPL mode:
  - show `calc> ` prompt
  - read one line at a time from stdin
  - ignore blank lines
  - `exit` or `quit` ends with exit code 0
  - invalid expressions print an error to stderr and continue (do not crash)
- No new third-party dependencies

Process:
1) Propose a minimal plan.
2) Identify what public API changes (if any) are needed to test this.
3) Provide a diff-only patch.
4) Ensure tests cover the new behavior (add tests if missing).

Context:
- File tree: (paste)
- Current relevant files: (paste calc/cli.py and tests)

Start with the plan only.
Don’t accept “I updated the whole parser”

A REPL should not require a full parsing rewrite. If the model proposes sweeping changes, ask it to reduce scope and keep the evaluator untouched.

Verification loop

After applying the diff:

  • run tests,
  • run python -m calc "2*(3+4)",
  • run python -m calc --repl and try:
    • 2+2
    • 2+*3
    • exit
If something breaks, shrink the diff

Ask for the smallest fix that passes one failing test. “Smallest fix” is the fastest path back to green.

Ship point: commit the feature

Once tests pass and the REPL works manually, commit:

git add .
git commit -m "Feature: add --repl interactive mode"

Where to go next