Skip to content

Refactor message optimization: extract helpers, consolidate diff extraction, add lint hooks#2554

Merged
hiroshinishio merged 2 commits intomainfrom
wes
Apr 19, 2026
Merged

Refactor message optimization: extract helpers, consolidate diff extraction, add lint hooks#2554
hiroshinishio merged 2 commits intomainfrom
wes

Conversation

@hiroshinishio
Copy link
Copy Markdown
Collaborator

@hiroshinishio hiroshinishio commented Apr 19, 2026

Summary

  • Refactored monolithic remove_outdated_file_edit_attempts.py (338 lines) into focused single-responsibility modules: detect_outdated_tool_ids.py, track_tool_use.py, extract_diff_result_file_path.py, remove_tool_pairs.py, remove_outdated_user_messages.py, remove_outdated_messages.py
  • Consolidated duplicate extract_diff_file_path + extract_success_diff_file_path into one function with a DIFF_MARKERS table
  • Added shared file_tracking.py for FilePosition, FileReadEntry, FILE_EDIT_TOOLS types
  • Used proper Anthropic SDK types (ToolResultBlockParam, ToolUseBlockParam) with pyright discriminated union narrowing instead of cast or bare dict
  • Added 3 new pre-commit lint hooks: check_cast_usage.sh, check_private_functions.sh, check_partial_assertions.sh
  • 43 new tests across 7 test files covering every extracted module

Social Media Post (GitAuto)

Refactored message optimization into single-responsibility modules

  • Split 338-line monolith into 6 focused files with proper SDK types
  • Consolidated duplicate diff extraction functions into one with a marker table
  • Added pre-commit hooks blocking cast(), private functions, and partial assertions

Social Media Post (Wes)

Spent a day splitting one giant function into six small ones. The function worked fine. But every time I touched it, I had to re-read 300 lines to find the part I needed. Now each piece is obvious. Boring refactor, faster future changes.

@hiroshinishio hiroshinishio self-assigned this Apr 19, 2026
@hiroshinishio hiroshinishio merged commit 190caff into main Apr 19, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch April 19, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant