largefile 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. {largefile-0.2.0 → largefile-0.3.0}/PKG-INFO +2 -2
  2. {largefile-0.2.0 → largefile-0.3.0}/README.md +1 -1
  3. {largefile-0.2.0 → largefile-0.3.0}/docs/API.md +25 -1
  4. {largefile-0.2.0 → largefile-0.3.0}/docs/design.md +2 -0
  5. {largefile-0.2.0 → largefile-0.3.0}/docs/examples.md +41 -0
  6. {largefile-0.2.0 → largefile-0.3.0}/pyproject.toml +1 -1
  7. largefile-0.3.0/src/change_marker.py +150 -0
  8. {largefile-0.2.0 → largefile-0.3.0}/src/data_models.py +2 -0
  9. {largefile-0.2.0 → largefile-0.3.0}/src/server.py +55 -1
  10. {largefile-0.2.0 → largefile-0.3.0}/src/tools.py +119 -8
  11. {largefile-0.2.0 → largefile-0.3.0}/src/tree_parser.py +150 -0
  12. largefile-0.3.0/tests/integration/test_get_overview_diff.py +196 -0
  13. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_mcp_server.py +3 -1
  14. largefile-0.3.0/tests/integration/test_read_enclosing.py +45 -0
  15. largefile-0.3.0/tests/test_data/javascript/nested_arrow.js +24 -0
  16. largefile-0.3.0/tests/test_data/python/nested_class.py +27 -0
  17. largefile-0.3.0/tests/unit/test_change_marker.py +261 -0
  18. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_tools.py +123 -0
  19. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_tree_parser.py +112 -0
  20. {largefile-0.2.0 → largefile-0.3.0}/uv.lock +2 -2
  21. {largefile-0.2.0 → largefile-0.3.0}/.gitattributes +0 -0
  22. {largefile-0.2.0 → largefile-0.3.0}/.github/workflows/ci.yml +0 -0
  23. {largefile-0.2.0 → largefile-0.3.0}/.github/workflows/release.yml +0 -0
  24. {largefile-0.2.0 → largefile-0.3.0}/.gitignore +0 -0
  25. {largefile-0.2.0 → largefile-0.3.0}/.python-version +0 -0
  26. {largefile-0.2.0 → largefile-0.3.0}/codecov.yml +0 -0
  27. {largefile-0.2.0 → largefile-0.3.0}/docs/3rd-party/python-mcp-sdk.md +0 -0
  28. {largefile-0.2.0 → largefile-0.3.0}/docs/3rd-party/research-llm-file-editing-apis.md +0 -0
  29. {largefile-0.2.0 → largefile-0.3.0}/docs/3rd-party/tree-sitter.md +0 -0
  30. {largefile-0.2.0 → largefile-0.3.0}/docs/CONTRIBUTING.md +0 -0
  31. {largefile-0.2.0 → largefile-0.3.0}/docs/configuration.md +0 -0
  32. {largefile-0.2.0 → largefile-0.3.0}/scripts/.gitignore +0 -0
  33. {largefile-0.2.0 → largefile-0.3.0}/scripts/pre-push +0 -0
  34. {largefile-0.2.0 → largefile-0.3.0}/src/__init__.py +0 -0
  35. {largefile-0.2.0 → largefile-0.3.0}/src/config.py +0 -0
  36. {largefile-0.2.0 → largefile-0.3.0}/src/editor.py +0 -0
  37. {largefile-0.2.0 → largefile-0.3.0}/src/exceptions.py +0 -0
  38. {largefile-0.2.0 → largefile-0.3.0}/src/file_access.py +0 -0
  39. {largefile-0.2.0 → largefile-0.3.0}/src/main.py +0 -0
  40. {largefile-0.2.0 → largefile-0.3.0}/src/search_engine.py +0 -0
  41. {largefile-0.2.0 → largefile-0.3.0}/src/utils.py +0 -0
  42. {largefile-0.2.0 → largefile-0.3.0}/tests/__init__.py +0 -0
  43. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_codebase_workflows.py +0 -0
  44. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_directory_workflows.py +0 -0
  45. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_documentation_workflows.py +0 -0
  46. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_editor_operations.py +0 -0
  47. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_file_strategies.py +0 -0
  48. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_performance_strategies.py +0 -0
  49. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_real_world_examples.py +0 -0
  50. {largefile-0.2.0 → largefile-0.3.0}/tests/integration/test_search_directory_workflows.py +0 -0
  51. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/LICENSES.md +0 -0
  52. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/README.md +0 -0
  53. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/csharp/aspnet-controller.cs +0 -0
  54. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/go/docker-daemon.go +0 -0
  55. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/java/spring-application.java +0 -0
  56. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/javascript/lodash-utility.js +0 -0
  57. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/markdown/anthropic-readme.md +0 -0
  58. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/markdown/fastapi-docs.md +0 -0
  59. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/markdown/nodejs-readme.md +0 -0
  60. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/markdown/openai-readme.md +0 -0
  61. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/markdown/pytorch-readme.md +0 -0
  62. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/php/laravel-model.php +0 -0
  63. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/python/django-models.py +0 -0
  64. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/rust/serde-derive.rs +0 -0
  65. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/text/rfc-specification.txt +0 -0
  66. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/text/shakespeare-complete.txt +0 -0
  67. {largefile-0.2.0 → largefile-0.3.0}/tests/test_data/typescript/vscode-extension.ts +0 -0
  68. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/__init__.py +0 -0
  69. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_backup_management.py +0 -0
  70. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_editor.py +0 -0
  71. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_file_access.py +0 -0
  72. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_revert_edit.py +0 -0
  73. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_search_engine.py +0 -0
  74. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_tools_list_directory.py +0 -0
  75. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_tools_search_directory.py +0 -0
  76. {largefile-0.2.0 → largefile-0.3.0}/tests/unit/test_tree_parser_verification.py +0 -0
  77. {largefile-0.2.0 → largefile-0.3.0}/tests/utils/__init__.py +0 -0
  78. {largefile-0.2.0 → largefile-0.3.0}/tests/utils/env_override.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: largefile
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: MCP server for AI assistants to navigate, search, and edit large codebases, logs, and data files with semantic code analysis
5
5
  Project-URL: Homepage, https://github.com/peteretelej/largefile
6
6
  Project-URL: Repository, https://github.com/peteretelej/largefile.git
@@ -38,7 +38,7 @@ Description-Content-Type: text/markdown
38
38
 
39
39
  Navigate, search, and edit large codebases, logs, and data files that exceed AI context limits.
40
40
 
41
- [![CI](https://img.shields.io/github/actions/workflow/status/peteretelej/largefile/ci.yml?branch=main&logo=github)](https://github.com/peteretelej/largefile/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/peteretelej/largefile/branch/main/graph/badge.svg)](https://codecov.io/gh/peteretelej/largefile) [![PyPI version](https://img.shields.io/pypi/v/largefile.svg)](https://pypi.org/project/largefile/) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
41
+ [![CI](https://img.shields.io/github/actions/workflow/status/peteretelej/largefile/ci.yml?branch=main&logo=github)](https://github.com/peteretelej/largefile/actions/workflows/ci.yml) [![PyPI version](https://img.shields.io/pypi/v/largefile.svg)](https://pypi.org/project/largefile/) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
42
42
 
43
43
  ## Why Largefile?
44
44
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Navigate, search, and edit large codebases, logs, and data files that exceed AI context limits.
4
4
 
5
- [![CI](https://img.shields.io/github/actions/workflow/status/peteretelej/largefile/ci.yml?branch=main&logo=github)](https://github.com/peteretelej/largefile/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/peteretelej/largefile/branch/main/graph/badge.svg)](https://codecov.io/gh/peteretelej/largefile) [![PyPI version](https://img.shields.io/pypi/v/largefile.svg)](https://pypi.org/project/largefile/) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![CI](https://img.shields.io/github/actions/workflow/status/peteretelej/largefile/ci.yml?branch=main&logo=github)](https://github.com/peteretelej/largefile/actions/workflows/ci.yml) [![PyPI version](https://img.shields.io/pypi/v/largefile.svg)](https://pypi.org/project/largefile/) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
7
  ## Why Largefile?
8
8
 
@@ -27,12 +27,14 @@ Analyze file structure with semantic outline and search hints.
27
27
  **Signature:**
28
28
  ```python
29
29
  def get_overview(
30
- absolute_file_path: str
30
+ absolute_file_path: str,
31
+ changed_lines: list[list[int | str]] | None = None,
31
32
  ) -> dict
32
33
  ```
33
34
 
34
35
  **Parameters:**
35
36
  - `absolute_file_path`: Absolute path to the file (required)
37
+ - `changed_lines` (optional): List of changed line ranges from a diff. Each entry is `[start, end]` or `[start, end, type]` where `type` is `"added"`, `"modified"`, or `"removed"`. Defaults to `"modified"` when type is omitted. Example: `[[10, 15, "added"], [45, 52]]`.
36
38
 
37
39
  **Returns:** Dictionary with:
38
40
  - `line_count`: Total lines in file
@@ -43,6 +45,9 @@ def get_overview(
43
45
  - `long_lines`: Object with detailed long line statistics
44
46
  - `outline`: Hierarchical structure via Tree-sitter (if supported)
45
47
  - `search_hints`: Suggested search patterns for exploration
48
+ - `changed_symbols` (int, when `changed_lines` provided): Number of outline symbols that overlap with changed lines
49
+
50
+ When `changed_lines` is provided, each outline item gains a `changes` field: `"added"`, `"modified"`, `"removed"`, or `null`.
46
51
 
47
52
  **Long Lines Object:**
48
53
  ```python
@@ -71,6 +76,25 @@ if overview["long_lines"]["has_long_lines"]:
71
76
  print(f"Warning: {overview['long_lines']['count']} lines exceed {overview['long_lines']['threshold']} chars")
72
77
  ```
73
78
 
79
+ **Diff-Aware Overview Example:**
80
+ ```python
81
+ # Pass changed line ranges from a diff to highlight affected symbols
82
+ overview = get_overview(
83
+ "/path/to/src/auth.py",
84
+ changed_lines=[[10, 15, "added"], [45, 52, "modified"]]
85
+ )
86
+ print(f"{overview['changed_symbols']} symbols affected by changes")
87
+
88
+ # Each outline item includes a "changes" field when changed_lines is provided
89
+ for item in overview["outline"]:
90
+ if item["changes"]:
91
+ print(f"{item['name']} ({item['type']}): {item['changes']}")
92
+ # Output:
93
+ # 2 symbols affected by changes
94
+ # create_session (function): added
95
+ # validate_token (function): modified
96
+ ```
97
+
74
98
  ### search_content
75
99
 
76
100
  Find patterns with fuzzy matching, regex, and semantic context.
@@ -206,6 +206,7 @@ class FileOverview:
206
206
  has_long_lines: bool # >1000 chars (triggers truncation)
207
207
  outline: List[OutlineItem] # Hierarchical via Tree-sitter
208
208
  search_hints: List[str] # Common patterns for exploration
209
+ changed_symbols: int = 0 # Count of symbols overlapping changed lines
209
210
 
210
211
  @dataclass
211
212
  class OutlineItem:
@@ -215,6 +216,7 @@ class OutlineItem:
215
216
  end_line: int
216
217
  children: List[OutlineItem] # Nested structure
217
218
  line_count: int
219
+ changes: str | None = None # "added", "modified", "removed", or None
218
220
 
219
221
  @dataclass
220
222
  class SearchResult:
@@ -516,6 +516,47 @@ if input("Apply changes? (y/n): ") == "y":
516
516
  # revert_edit("/path/to/app.py") # Instant recovery
517
517
  ```
518
518
 
519
+ ## Diff-Aware Code Review
520
+
521
+ ### Reviewing Changes with Targeted Symbol Navigation
522
+
523
+ **AI Question:** *"I have a diff patch file. Can you review just the functions that changed in src/auth.py?"*
524
+
525
+ **AI Assistant workflow:**
526
+ 1. Use `diffchunk list_chunks` to get file details with changed line ranges
527
+ 2. Pass those ranges as `changed_lines` to `get_overview`
528
+ 3. Focus review on symbols with non-null `changes`
529
+
530
+ ```python
531
+ # Step 1: Get diff overview to identify changed files and line ranges
532
+ chunks = list_chunks("/path/to/diff.patch")
533
+ # file_details shows: src/auth.py has changes at lines 10-15, 45-52
534
+
535
+ # Step 2: Get diff-aware overview
536
+ overview = get_overview(
537
+ "/path/to/src/auth.py",
538
+ changed_lines=[[10, 15, "added"], [45, 52, "modified"]]
539
+ )
540
+ # Response includes:
541
+ # {
542
+ # "changed_symbols": 2,
543
+ # "outline": [
544
+ # {"name": "validate_token", "type": "function", "line_number": 42,
545
+ # "end_line": 68, "changes": "modified"},
546
+ # {"name": "create_session", "type": "function", "line_number": 8,
547
+ # "end_line": 20, "changes": "added"},
548
+ # {"name": "logout", "type": "function", "line_number": 70,
549
+ # "end_line": 85, "changes": null}
550
+ # ]
551
+ # }
552
+
553
+ # Step 3: Focus review on changed functions
554
+ changed = [s for s in overview["outline"] if s["changes"]]
555
+ for symbol in changed:
556
+ code = read_content("/path/to/src/auth.py", offset=symbol["line_number"],
557
+ limit=symbol["line_count"])
558
+ ```
559
+
519
560
  ---
520
561
 
521
562
  These examples demonstrate how AI assistants use the Largefile MCP Server to handle real-world scenarios with large files, from code analysis to refactoring to data processing, with robust error recovery and batch operations.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "largefile"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "MCP server for AI assistants to navigate, search, and edit large codebases, logs, and data files with semantic code analysis"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -0,0 +1,150 @@
1
+ """Change-marking logic for diff-aware file overviews.
2
+
3
+ Classifies outline symbols as added, modified, or removed based on
4
+ changed line ranges from a diff.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from .data_models import OutlineItem
10
+
11
+ # (start_line, end_line, change_type)
12
+ # change_type: "added" | "modified" | "removed"
13
+ ChangedLineRange = tuple[int, int, str]
14
+
15
+ _VALID_CHANGE_TYPES = frozenset({"added", "modified", "removed"})
16
+
17
+
18
+ def parse_changed_lines(raw: list[list[int | str]]) -> list[ChangedLineRange]:
19
+ """Validate and convert JSON input to internal ``ChangedLineRange`` list.
20
+
21
+ Each element of *raw* is ``[start, end]`` or ``[start, end, type]``.
22
+ When *type* is omitted it defaults to ``"modified"``.
23
+
24
+ After validation the ranges are sorted by start line and adjacent /
25
+ overlapping ranges **of the same type** are merged.
26
+ """
27
+ validated: list[ChangedLineRange] = []
28
+
29
+ for entry in raw:
30
+ if not isinstance(entry, list | tuple) or len(entry) not in (2, 3):
31
+ raise ValueError(
32
+ f"Each entry must have 2 or 3 elements, got {len(entry) if isinstance(entry, list | tuple) else type(entry).__name__}"
33
+ )
34
+
35
+ start = entry[0]
36
+ end = entry[1]
37
+ change_type: str = str(entry[2]) if len(entry) == 3 else "modified"
38
+
39
+ if not isinstance(start, int) or not isinstance(end, int):
40
+ raise ValueError(
41
+ f"start and end must be integers, got {type(start).__name__} and {type(end).__name__}"
42
+ )
43
+ if start < 1:
44
+ raise ValueError(f"start must be >= 1, got {start}")
45
+ if start > end:
46
+ raise ValueError(f"start ({start}) must be <= end ({end})")
47
+ if change_type not in _VALID_CHANGE_TYPES:
48
+ raise ValueError(
49
+ f"type must be one of {sorted(_VALID_CHANGE_TYPES)}, got {change_type!r}"
50
+ )
51
+
52
+ validated.append((start, end, change_type))
53
+
54
+ # Sort by start line
55
+ validated.sort(key=lambda r: r[0])
56
+
57
+ # Merge overlapping / adjacent ranges of the same type
58
+ merged: list[ChangedLineRange] = []
59
+ for rng in validated:
60
+ if merged and merged[-1][2] == rng[2] and merged[-1][1] >= rng[0] - 1:
61
+ # Extend the previous range
62
+ prev = merged[-1]
63
+ merged[-1] = (prev[0], max(prev[1], rng[1]), prev[2])
64
+ else:
65
+ merged.append(rng)
66
+
67
+ return merged
68
+
69
+
70
+ def classify_change(
71
+ symbol_start: int,
72
+ symbol_end: int,
73
+ changed_ranges: list[ChangedLineRange],
74
+ ) -> str | None:
75
+ """Determine the change classification for a single symbol.
76
+
77
+ Returns ``"added"``, ``"modified"``, ``"removed"``, or ``None``.
78
+ """
79
+ overlapping: list[ChangedLineRange] = [
80
+ r for r in changed_ranges if r[0] <= symbol_end and r[1] >= symbol_start
81
+ ]
82
+
83
+ if not overlapping:
84
+ return None
85
+
86
+ types = {r[2] for r in overlapping}
87
+
88
+ if types == {"removed"}:
89
+ return "removed"
90
+
91
+ if types == {"added"}:
92
+ # Check full coverage: compute union of overlapping added ranges
93
+ # clipped to symbol bounds
94
+ symbol_len = symbol_end - symbol_start + 1
95
+ covered = _union_coverage(overlapping, symbol_start, symbol_end)
96
+ if covered == symbol_len:
97
+ return "added"
98
+ return "modified"
99
+
100
+ # Mixed types
101
+ return "modified"
102
+
103
+
104
+ def _union_coverage(
105
+ ranges: list[ChangedLineRange], clip_start: int, clip_end: int
106
+ ) -> int:
107
+ """Compute the total number of lines covered by *ranges* within [clip_start, clip_end]."""
108
+ clipped = []
109
+ for start, end, _ in ranges:
110
+ cs = max(start, clip_start)
111
+ ce = min(end, clip_end)
112
+ if cs <= ce:
113
+ clipped.append((cs, ce))
114
+
115
+ if not clipped:
116
+ return 0
117
+
118
+ clipped.sort()
119
+ total = 0
120
+ cur_start, cur_end = clipped[0]
121
+ for s, e in clipped[1:]:
122
+ if s <= cur_end + 1:
123
+ cur_end = max(cur_end, e)
124
+ else:
125
+ total += cur_end - cur_start + 1
126
+ cur_start, cur_end = s, e
127
+ total += cur_end - cur_start + 1
128
+ return total
129
+
130
+
131
+ def mark_outline(
132
+ items: list[OutlineItem],
133
+ changed_ranges: list[ChangedLineRange],
134
+ ) -> tuple[list[OutlineItem], int]:
135
+ """Classify each item in a flat outline list and set its ``changes`` field.
136
+
137
+ The list returned by ``generate_outline()`` is already flattened via
138
+ ``_flatten_outline_items()``, so children appear as top-level entries.
139
+ This function does **not** recurse into ``item.children`` to avoid
140
+ double-counting.
141
+
142
+ Returns ``(items, changed_count)`` - items are mutated in place.
143
+ """
144
+ changed_count = 0
145
+ for item in items:
146
+ result = classify_change(item.line_number, item.end_line, changed_ranges)
147
+ item.changes = result
148
+ if result is not None:
149
+ changed_count += 1
150
+ return items, changed_count
@@ -62,6 +62,7 @@ class FileOverview:
62
62
  binary_hint: str | None
63
63
  outline: list["OutlineItem"]
64
64
  search_hints: list[str]
65
+ changed_symbols: int = 0
65
66
 
66
67
 
67
68
  @dataclass
@@ -72,6 +73,7 @@ class OutlineItem:
72
73
  end_line: int
73
74
  children: list["OutlineItem"]
74
75
  line_count: int
76
+ changes: str | None = None # "added" | "modified" | "removed" | None
75
77
 
76
78
 
77
79
  @dataclass
@@ -32,6 +32,16 @@ def get_overview(
32
32
  description="Absolute path to target file (e.g., /path/to/large_module.py)"
33
33
  ),
34
34
  ],
35
+ changed_lines: Annotated[
36
+ list[list[int | str]] | None,
37
+ Field(
38
+ description="Optional list of changed line ranges from a diff. "
39
+ "Each entry is [start, end] or [start, end, type] where type is "
40
+ '"added", "modified", or "removed". '
41
+ 'Example: [[10, 15, "added"], [45, 52]]. '
42
+ "Available from diffchunk list_chunks file_details output."
43
+ ),
44
+ ] = None,
35
45
  ) -> dict:
36
46
  """Get file structure, size, and semantic outline for large files (code, logs, data).
37
47
 
@@ -41,7 +51,7 @@ def get_overview(
41
51
  files, uses Tree-sitter to extract functions, classes, and structure. Does
42
52
  NOT return file content - use read_content or search_content for that.
43
53
  """
44
- return tools.get_overview(absolute_file_path) # type: ignore[no-any-return]
54
+ return tools.get_overview(absolute_file_path, changed_lines=changed_lines) # type: ignore[no-any-return]
45
55
 
46
56
 
47
57
  @mcp.tool(
@@ -168,6 +178,50 @@ def read_content(
168
178
  )
169
179
 
170
180
 
181
+ @mcp.tool(
182
+ annotations=ToolAnnotations(readOnlyHint=True, destructiveHint=False),
183
+ structured_output=False,
184
+ )
185
+ def read_enclosing(
186
+ absolute_file_path: Annotated[
187
+ str,
188
+ Field(description="Absolute path to target file"),
189
+ ],
190
+ line: Annotated[
191
+ int,
192
+ Field(description="Line number to find the enclosing function/class for", ge=1),
193
+ ],
194
+ depth: Annotated[
195
+ int,
196
+ Field(
197
+ description="Nesting depth: 1 = innermost definition, 2 = parent (e.g., class containing a method)",
198
+ ge=1,
199
+ ),
200
+ ] = 1,
201
+ context_lines: Annotated[
202
+ int,
203
+ Field(
204
+ description="Lines of context for fallback window when no enclosing definition is found",
205
+ ge=1,
206
+ ),
207
+ ] = 40,
208
+ ) -> dict:
209
+ """Find the enclosing function or class for a specific line number.
210
+
211
+ Given a file and line number, returns the complete enclosing definition
212
+ (function, method, class, struct, etc.) containing that line. Use depth=2
213
+ to get the parent definition (e.g., the class containing a method).
214
+ Falls back to a centered context window for unsupported languages or
215
+ top-level code.
216
+ """
217
+ return tools.read_enclosing( # type: ignore[no-any-return]
218
+ absolute_file_path,
219
+ line=line,
220
+ depth=depth,
221
+ context_lines=context_lines,
222
+ )
223
+
224
+
171
225
  @mcp.tool(
172
226
  annotations=ToolAnnotations(readOnlyHint=False, destructiveHint=True),
173
227
  structured_output=False,
@@ -10,6 +10,7 @@ from typing import Any
10
10
 
11
11
  from mcp.server.fastmcp.exceptions import ToolError
12
12
 
13
+ from .change_marker import mark_outline, parse_changed_lines
13
14
  from .config import config
14
15
  from .data_models import (
15
16
  BackupInfo,
@@ -20,6 +21,7 @@ from .data_models import (
20
21
  DirectorySearchResult,
21
22
  FileOverview,
22
23
  LongLineStats,
24
+ OutlineItem,
23
25
  SearchResult,
24
26
  )
25
27
  from .editor import batch_edit_content
@@ -40,6 +42,7 @@ from .file_access import (
40
42
  from .search_engine import search_file
41
43
  from .tree_parser import (
42
44
  extract_semantic_context,
45
+ find_enclosing_definition,
43
46
  generate_outline,
44
47
  get_semantic_chunk,
45
48
  parse_file_content,
@@ -81,22 +84,36 @@ def handle_tool_errors(func: Callable) -> Callable:
81
84
 
82
85
 
83
86
  @handle_tool_errors
84
- def get_overview(absolute_file_path: str) -> dict:
87
+ def get_overview(
88
+ absolute_file_path: str,
89
+ changed_lines: list[list[int | str]] | None = None,
90
+ ) -> dict:
85
91
  """Get file structure with basic analysis using auto-detected encoding.
86
92
 
87
93
  Provides file metadata, line count, and basic structure analysis.
88
94
  Detects binary files and long lines, returns search hints for efficient
89
95
  exploration.
90
96
 
97
+ Optionally accepts changed_lines to mark which symbols in the outline
98
+ contain changes from a diff, enabling diff-aware code review.
99
+
91
100
  CRITICAL: You must use an absolute file path - relative paths will fail.
92
101
  DO NOT attempt to read large files directly as they exceed context limits.
93
102
 
94
103
  Parameters:
95
104
  - absolute_file_path: Absolute path to the file
105
+ - changed_lines: Optional list of changed line ranges from a diff.
106
+ Each entry is [start, end] or [start, end, type] where type is
107
+ "added", "modified", or "removed" (defaults to "modified").
108
+ Example: [[10, 15, "added"], [45, 52, "modified"]] or [[10, 15]].
109
+ Available from diffchunk list_chunks file_details output.
96
110
 
97
111
  Returns:
98
112
  - FileOverview with line count, file size, detected encoding, binary detection,
99
113
  long line statistics, and search hints
114
+ - When changed_lines is provided, each outline item includes a "changes" field
115
+ ("added", "modified", "removed", or null) and the response includes
116
+ "changed_symbols" count
100
117
  """
101
118
  canonical_path = normalize_path(absolute_file_path)
102
119
  file_info = get_file_info(canonical_path)
@@ -105,6 +122,8 @@ def get_overview(absolute_file_path: str) -> dict:
105
122
  is_binary, binary_hint = is_binary_file(canonical_path)
106
123
 
107
124
  if is_binary:
125
+ if changed_lines is not None:
126
+ raise ToolError("changed_lines not supported for binary files")
108
127
  # Return early for binary files
109
128
  long_lines_stats = LongLineStats(
110
129
  has_long_lines=False,
@@ -161,6 +180,16 @@ def get_overview(absolute_file_path: str) -> dict:
161
180
 
162
181
  # Generate search hints based on file type
163
182
  file_ext = Path(canonical_path).suffix.lower()
183
+
184
+ # Mark changed symbols if changed_lines provided
185
+ changed_count = 0
186
+ if changed_lines is not None:
187
+ try:
188
+ parsed_ranges = parse_changed_lines(changed_lines)
189
+ except ValueError as e:
190
+ raise ToolError(f"Invalid changed_lines: {e}") from e
191
+ outline, changed_count = mark_outline(outline, parsed_ranges)
192
+
164
193
  if file_ext == ".py":
165
194
  search_hints = ["def ", "class ", "import ", "from "]
166
195
  elif file_ext in [".js", ".ts", ".jsx", ".tsx"]:
@@ -198,19 +227,28 @@ def get_overview(absolute_file_path: str) -> dict:
198
227
  "threshold": overview.long_lines.threshold,
199
228
  },
200
229
  "outline": [
201
- {
202
- "name": item.name,
203
- "type": item.type,
204
- "line_number": item.line_number,
205
- "end_line": item.end_line,
206
- "line_count": item.line_count,
207
- }
230
+ _serialize_outline_item(item, include_changes=changed_lines is not None)
208
231
  for item in overview.outline
209
232
  ],
210
233
  "search_hints": overview.search_hints,
234
+ **({"changed_symbols": changed_count} if changed_lines is not None else {}),
211
235
  }
212
236
 
213
237
 
238
+ def _serialize_outline_item(item: OutlineItem, include_changes: bool) -> dict:
239
+ """Serialize an OutlineItem to a flat dict, optionally including changes."""
240
+ d: dict[str, Any] = {
241
+ "name": item.name,
242
+ "type": item.type,
243
+ "line_number": item.line_number,
244
+ "end_line": item.end_line,
245
+ "line_count": item.line_count,
246
+ }
247
+ if include_changes:
248
+ d["changes"] = item.changes
249
+ return d
250
+
251
+
214
252
  @handle_tool_errors
215
253
  def search_content(
216
254
  absolute_file_path: str,
@@ -471,6 +509,79 @@ def read_content(
471
509
  return result
472
510
 
473
511
 
512
+ @handle_tool_errors
513
+ def read_enclosing(
514
+ absolute_file_path: str,
515
+ line: int,
516
+ depth: int = 1,
517
+ context_lines: int = 40,
518
+ ) -> dict:
519
+ """Find the enclosing function or class for a specific line number.
520
+
521
+ Given a file and line number, returns the complete enclosing definition
522
+ (function, method, class, struct, etc.) containing that line. Use depth=2
523
+ to get the parent definition (e.g., the class containing a method).
524
+ Falls back to a centered context window for unsupported languages or
525
+ top-level code.
526
+
527
+ Parameters:
528
+ - absolute_file_path: Absolute path to the file
529
+ - line: Line number to find the enclosing definition for (1-indexed)
530
+ - depth: Nesting depth: 1 = innermost, 2 = parent definition
531
+ - context_lines: Lines of context for fallback window
532
+
533
+ Returns:
534
+ - Content of the enclosing definition with metadata
535
+ """
536
+ canonical_path = normalize_path(absolute_file_path)
537
+
538
+ # Validate parameters
539
+ if line < 1:
540
+ raise ToolError("line must be >= 1.")
541
+ if depth < 1:
542
+ raise ToolError("depth must be >= 1.")
543
+ if context_lines < 1:
544
+ raise ToolError("context_lines must be >= 1.")
545
+
546
+ lines = read_file_lines(canonical_path)
547
+ content = read_file_content(canonical_path)
548
+ total_lines = len(lines)
549
+
550
+ if line > total_lines:
551
+ raise ToolError(f"line {line} is beyond end of file ({total_lines} lines).")
552
+
553
+ result = find_enclosing_definition(canonical_path, content, line, depth)
554
+
555
+ if result is not None:
556
+ content_text, start_line, end_line, symbol_label = result
557
+ return {
558
+ "content": content_text,
559
+ "start_line": start_line,
560
+ "end_line": end_line,
561
+ "lines_returned": end_line - start_line + 1,
562
+ "total_lines": total_lines,
563
+ "mode": "enclosing",
564
+ "enclosing_symbol": symbol_label,
565
+ }
566
+
567
+ # Fallback: centered context window
568
+ start = max(1, line - context_lines // 2)
569
+ end = min(total_lines, start + context_lines - 1)
570
+ # Backfill: shift start backward when clipped at EOF
571
+ if end - start + 1 < context_lines:
572
+ start = max(1, end - context_lines + 1)
573
+ content_text = "".join(lines[start - 1 : end])
574
+ return {
575
+ "content": content_text,
576
+ "start_line": start,
577
+ "end_line": end,
578
+ "lines_returned": end - start + 1,
579
+ "total_lines": total_lines,
580
+ "mode": "context_window",
581
+ "enclosing_symbol": None,
582
+ }
583
+
584
+
474
585
  def _change_result_to_dict(r: ChangeResult) -> dict:
475
586
  """Convert ChangeResult to dictionary."""
476
587
  d: dict[str, Any] = {