Objective
Wire commit_changes and generate_commit_message into the full pipeline, then run code_agent.py end to end on a real task in your own repository.
Build
The capstone project
Every piece exists: file selection, planning, safe execution, multi-file rollback. Today's lesson wires the last two steps — a real git commit and a summary you can actually verify — and then you run the whole thing on a real task in your own repository.
Committing with GitPython
from git import Repo
def commit_changes(repo_path: str, files: list[str], commit_message: str):
repo = Repo(repo_path)
repo.index.add(files)
repo.index.commit(commit_message)
This only runs after execute_plan (Lesson 5) returns success -- committing a plan that partially failed and rolled back would put a misleading commit in the repo's history. The files list is exactly the completed_files list Lesson 5 already tracks; no new bookkeeping needed here, just using what the executor already knows.
Generating a commit message worth reading
"Automated changes by code-agent" is a commit message that actively makes git blame worse
A useful commit message says what changed and why, specifically -- generate it from the plan's task and each step's description, not a generic template. Ask the model for a conventional-commits-style subject line plus a short body listing what was actually done, using the SAME information the executor already has (the plan and its steps), not a fresh guess about what changed.
def generate_commit_message(client, plan) -> str:
steps_summary = "\n".join(f"- {s.file_path}: {s.description}" for s in plan.steps)
prompt = f"""Write a git commit message for this change:
Task: {plan.task}
Changes made:
{steps_summary}
Format: a short subject line (under 72 chars), blank line, then a bullet list
of what changed. No marketing language, no "this commit" preamble."""
response = client.messages.create(model="claude-sonnet-5", max_tokens=300,
messages=[{"role": "user", "content": prompt}])
return response.content[0].text
Notice this reuses the plan's own description fields rather than re-deriving "what changed" from scratch by re-reading diffs -- the plan already IS the record of intent; the commit message just needs to present it well.
The structured summary: show your work
The agent completes a 3-file task successfully and commits. Its summary says "Successfully implemented the requested changes." Is this summary good enough?
"Successfully implemented the requested changes" is exactly the kind of unverifiable claim this whole course has been building alternatives to since Lesson 1's checkpoint about test-driven loops beating trust in the model's own claims. A real summary: which files changed (from completed_files), what the test suite showed before/after, and the plan's own risk_notes -- concrete enough that a human reviewing it doesn't have to just take the agent's word for it.
Ship it
Run the complete agent — code_agent.py "<a real task>" — against a real task in a repo you actually care about. Watch it plan, execute, test, and commit end to end. Record the terminal session from start to finish.
Ship Prompt: Share the terminal recording and the resulting commit link. What task did you give it? Did it get it right the first time, or did the fix loop have to kick in?