Foreman

Case study · Start from an empty folder

Add wc.py CLI that prints line, word and character counts of a file, with tests

make a small Python command-line tool, wc.py, that prints the line, word and character counts of a file, with tests

Start from an empty folder

fm code 'make a small Python command-line tool, wc.py, that prints the line, word and character counts of a file, with tests' --worker claude

fm code tui at the end of this run: Add wc.py CLI that prints line, word and character counts of a file, with tests

Plan FEATURE S · Add wc.py CLI that prints line, word and character counts of a file, with tests

Steps

  1. Write test_wc.py (unittest) with failing tests: counts() on empty text, text with and without a trailing newline, multi-word lines, and non-ASCII characters; plus a main() test for a real file and a missing file (returns 1)
  2. Create wc.py with counts(text) returning (lines, words, chars) using text.count('\n'), len(text.split()) and len(text), read as UTF-8
  3. Add main(argv) using argparse for one file path argument that prints the counts and the filename, and prints 'wc.py: <error>' to stderr and returns 1 on OSError; guard with sys.exit(main()) under if __name__ == '__main__'
  4. Run python3 -m unittest test_wc and the CLI checks, then fix any failures

Checks

  • PASS Unit tests for the counting function and the CLI exist and passpython3 -m unittest test_wc (failed before the work)
  • PASS Running wc.py on a file prints its line, word and character counts followed by the filenameprintf 'a b\nc\n' > /tmp/wc_check.txt && python3 wc.py /tmp/wc_check.txt | grep -q '^ *2 *3 *6 /tmp/wc_check.txt$' (failed before the work)
  • PASS Running wc.py on a missing file exits with status 1 and a 'wc.py: <error>' message on stderr, with no tracebackpython3 wc.py /nonexistent/file >/dev/null 2>/tmp/wc_err.txt; [ $? -eq 1 ] && grep -q '^wc\.py: ' /tmp/wc_err.txt && ! grep -q Traceback /tmp/wc_err.txt (failed before the work)

Changed

  • test_wc.py +45
  • wc.py +24

Closed T-0001 closed; committed 9c48f19 (2 files). Undo: git revert --no-edit 9c48f19 (tokens: 66506 in, 1919 out)

4 worker turns · 68k tokens · 1m31s · replay it: fm code tui --events demo/examples/new-project.jsonl · the case study

The run, event by event

  1. 24s before fails: python3 -m unittest test_wc
  2. 25s before fails: printf 'a b\nc\n' > /tmp/wc_check.txt && python3 wc.py /tmp/wc_check.txt | grep -q '^ *2 *3 *6 /tmp/wc_check.txt$'
  3. 25s before fails: python3 wc.py /nonexistent/file >/dev/null 2>/tmp/wc_err.txt; [ $? -eq 1 ] && grep -q '^wc\.py: ' /tmp/wc_err.txt && ! grep -q Traceback /tmp/wc_err.txt
  4. 25s step step 1/4: Write test_wc.py (unittest) with failing tests: counts() on empty text, text with and without a trailing newline, multi-word lines, and non-ASCII characters; plus a main() test for a real file and a missing file (returns 1)
  5. 39s changed test_wc.py
  6. 39s step step 2/4: Create wc.py with counts(text) returning (lines, words, chars) using text.count('\n'), len(text.split()) and len(text), read as UTF-8
  7. 49s changed test_wc.py, wc.py
  8. 49s step step 3/4: Add main(argv) using argparse for one file path argument that prints the counts and the filename, and prints 'wc.py: <error>' to stderr and returns 1 on OSError; guard with sys.exit(main()) under if __name__ == '__main__'
  9. 1m12s changed test_wc.py, wc.py
  10. 1m12s step step 4/4: Run python3 -m unittest test_wc and the CLI checks, then fix any failures
  11. 1m27s changed test_wc.py, wc.py
  12. 1m28s check passes: python3 -m unittest test_wc
  13. 1m28s check passes: printf 'a b\nc\n' > /tmp/wc_check.txt && python3 wc.py /tmp/wc_check.txt | grep -q '^ *2 *3 *6 /tmp/wc_check.txt$'
  14. 1m29s check passes: python3 wc.py /nonexistent/file >/dev/null 2>/tmp/wc_err.txt; [ $? -eq 1 ] && grep -q '^wc\.py: ' /tmp/wc_err.txt && ! grep -q Traceback /tmp/wc_err.txt
  15. 1m31s closed T-0001 closed; committed 9c48f19 (2 files). Undo: git revert --no-edit 9c48f19 (tokens: 66506 in, 1919 out)

Back to fm code