Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change is minimal and correctly scoped—dirty-marking only runs for executed mutating tools while preserving prompt ordering and the stable prefix—and it is comprehensively covered by the new regression tests.
No open issues 🎉
What changed in this PR
This PR fixes stale workspace context (git status, branch, recent commits, project docs) being presented to the model after a tool mutates the workspace within a session. Previously, WorkspaceContext.text() was embedded in the once-built prompt prefix, so it never reflected changes made by write_file, patch_file, or run_shell. The fix keeps the rules/tools/examples prefix stable and renders the workspace context as a separate, refreshable section, rebuilding it only when a mutating tool has actually executed (tracked via a workspace_dirty flag set in a finally block, so partial mutations before a failure are still captured). This addresses issue #15 and preserves the existing prompt ordering and prefix-cache behavior.
Changes:
- Added a
workspace_dirtyflag thatrun_toolsets after executingwrite_file,patch_file, orrun_shell(including on partial-failure), andprompt()rebuildsWorkspaceContextand clears the flag before composing the next prompt. - Removed
workspace.text()frombuild_prefixand moved it intoprompt()as a distinct section, keeping the overall section order unchanged. - Added regression tests covering refresh after each mutating tool, git branch/commit changes, partial failure, the stable prefix, and no-refresh after reads, denied writes, or invalid arguments.
| File | Description |
|---|---|
| mini_coding_agent.py | Introduces workspace_dirty, removes workspace text from the stable prefix, refreshes WorkspaceContext in prompt(), and marks dirty in run_tool's finally for mutating tools. |
| tests/test_mini_coding_agent.py | Adds a git fixture and parametrized regression tests validating workspace refresh behavior and stable-prefix invariants. |
Review effort: Balanced
After
write_file,patch_file, orrun_shell, the next model turn currently receives the original workspace snapshot. This can leave git status, branch, recent commits, and project documentation stale.Keep the rules/tools/examples prefix stable and render workspace context separately. Mark that context dirty only after a mutating tool actually executes, and rebuild it once before the next prompt. Invalidation also happens if execution raises after a partial mutation. Argument validation, approval checks, and path restrictions are unchanged.
Fixes #15.
Validation:
717cae4: 5 failed, 3 passed.ruff check .with Ruff 0.17.1 reports 13 existing diagnostics on both base and this branch, with identical rule/message counts and no new diagnostics. The full lint check therefore remains failing; no rules or workflow checks are suppressed. These unrelated baseline diagnostics are outside this fix.git diff --check: passed.The tests cover all three mutating tools, branch/commit changes, partial failure, stable prompt prefix, and no refresh after reads, denied writes, or invalid arguments. No runtime dependencies, credentials, or workflow changes are introduced.
AI assistance: repository research, implementation, and validation were performed with AI assistance. The regression results and the pre-existing lint limitation are provided for maintainer review.