from pydantic import BaseModel, Field from typing import Optional class ContentReference(BaseModel): """ Reference to content location in the original trace using line numbers and character positions. """ line_start: Optional[int] = Field(None, description="""Starting line number where the content begins (1-based indexing from , ... markers).""" ) line_end: Optional[int] = Field(None, description="""Ending line number where content ends (1-based indexing from , ... markers).""" ) def validate_line_range(self) -> bool: """Validate that line_end >= line_start""" return self.line_end >= self.line_start def get_line_count(self) -> int: """Get the number of lines this reference spans""" return self.line_end - self.line_start + 1 def is_single_line(self) -> bool: """Check if this reference is within a single line""" return self.line_start == self.line_end def __str__(self) -> str: """String representation for debugging""" if self.is_single_line(): return f"Line {self.line_start}" else: return f"Lines {self.line_start}-{self.line_end}"