Skip to content

feat: Implement DiffContextManager for precise diff analysis#194

Merged
finxo merged 7 commits intomasterfrom
feat/diff_manager
Apr 6, 2026
Merged

feat: Implement DiffContextManager for precise diff analysis#194
finxo merged 7 commits intomasterfrom
feat/diff_manager

Conversation

@finxo
Copy link
Copy Markdown
Collaborator

@finxo finxo commented Apr 6, 2026

Pull Request

📝 Summary

This PR introduces DiffContextManager, a new centralized class for parsing and querying git diff output. This manager provides a structured, line-number-aware representation of changes, which is used to improve the accuracy of AI analysis and comment placement. Additionally, this work includes centralizing the application's logging system and enhancing the developer experience by automatically enabling debug logs for the titan-dev executable.

🔧 Changes Made

  • DiffContextManager Implementation: Introduced a new class to parse the unified diff format. It indexes files, hunks, and line mappings between the old and new file versions.
  • Centralized Diff Logic: Refactored existing code to use DiffContextManager as the single source of truth for diff information, simplifying comment rendering logic and other dependent components.
  • Improved AI Context: The manager now provides AI prompts with diff context that includes line numbers, enabling more precise code analysis and suggestions.
  • Centralized Logging & DX: Consolidated logging configuration and modified the Makefile to set TITAN_ENV=development for the titan-dev script, which automatically enables more verbose logging during development.

🧪 Testing

  • Unit tests added/updated (poetry run pytest)
  • All tests passing (make test)
  • Manual testing with titan-dev

An extensive new test suite (test_diff_context_manager.py) was added to validate the DiffContextManager. It covers various scenarios including simple diffs, multi-hunk files, multi-file diffs, handling of deleted lines, and the logic for finding specific lines by code snippets.

📊 Logs

  • No new log events
  • diff_parse_start (DEBUG) — Fired when the DiffContextManager begins parsing a raw diff string.
  • diff_parse_complete (DEBUG) — Fired when parsing is complete, includes file_count, hunk_count, and duration.
  • find_line_by_snippet_miss (DEBUG) — Fired when a code snippet cannot be located in the diff for a given file, includes file_path.

✅ Checklist

  • Self-review done
  • Follows the project's logging rules (no secrets, no content in logs)
  • New and existing tests pass
  • Documentation updated if needed

@finxo finxo self-assigned this Apr 6, 2026
@finxo finxo merged commit 2629f7d into master Apr 6, 2026
5 checks passed
@finxo finxo deleted the feat/diff_manager branch April 6, 2026 08:47
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