intentumdiff-python 0.0.1__py3-none-win_arm64.whl → 0.0.2b2__py3-none-win_arm64.whl
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.
- intentumdiff/__init__.py +2 -0
- intentumdiff/__main__.py +12 -0
- intentumdiff/_differ_presentation.py +35 -682
- intentumdiff/_differ_runtime.py +13 -47
- intentumdiff/analysis/compile_commands.py +26 -141
- intentumdiff/analysis/cross_file.py +2 -4
- intentumdiff/analysis/guardrail_reports.py +7 -5
- intentumdiff/analysis/guardrails.py +110 -122
- intentumdiff/analysis/invariances.py +4 -1003
- intentumdiff/analysis/schema_resolver.py +49 -273
- intentumdiff/analysis/text_review.py +4 -3
- intentumdiff/analysis/user_schemas.py +55 -237
- intentumdiff/api.py +21 -0
- intentumdiff/cache/sqlite_store.py +5 -23
- intentumdiff/cli/__init__.py +59 -0
- intentumdiff/cli/_commands.py +174 -67
- intentumdiff/cli/_parser.py +11 -1
- intentumdiff/cli/_shared.py +96 -112
- intentumdiff/content_type.py +13 -30
- intentumdiff/core/commit_differ.py +105 -220
- intentumdiff/core/diffignore.py +28 -34
- intentumdiff/core/index.py +16 -18
- intentumdiff/core/indexer.py +148 -168
- intentumdiff/core/models.py +53 -14
- intentumdiff/differ.py +278 -605
- intentumdiff/github_app.py +35 -19
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +180 -17
- intentumdiff/lsp/client.py +7 -1
- intentumdiff/lsp/enricher.py +19 -119
- intentumdiff/lsp/exceptions.py +6 -7
- intentumdiff/lsp_server/_codelens.py +24 -57
- intentumdiff/lsp_server/_diagnostics.py +23 -51
- intentumdiff/lsp_server/_handlers.py +66 -8
- intentumdiff/lsp_server/server.py +28 -7
- intentumdiff/plugins/adapter.py +5 -0
- intentumdiff/plugins/builtins.py +7 -14
- intentumdiff/plugins/exceptions.py +4 -0
- intentumdiff/plugins/hub.py +1 -2
- intentumdiff/plugins/loader.py +229 -215
- intentumdiff/plugins/registry.py +249 -197
- intentumdiff/rust_core.py +744 -784
- intentumdiff/serve/_app.py +3 -10
- intentumdiff/sources/base.py +24 -0
- intentumdiff/sources/file_source.py +15 -2
- intentumdiff/sources/git_source.py +120 -58
- intentumdiff/sources/live_buffer_source.py +45 -5
- intentumdiff/sources/patch_source.py +36 -109
- intentumdiff/vcs/_safe_path.py +7 -0
- intentumdiff/vcs/base.py +6 -0
- intentumdiff/vcs/git_backend.py +1 -1
- intentumdiff/vcs/git_cli.py +38 -18
- intentumdiff/vcs/hg_backend.py +1 -1
- intentumdiff/vcs/perforce_backend.py +7 -1
- intentumdiff/vcs/svn_backend.py +1 -1
- intentumdiff/wasm/abap_parser.wasm +0 -0
- intentumdiff/wasm/adf_parser.wasm +0 -0
- intentumdiff/wasm/asciidoc_parser.wasm +0 -0
- intentumdiff/wasm/asm_parser.wasm +0 -0
- intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
- intentumdiff/wasm/astro_parser.wasm +0 -0
- intentumdiff/wasm/bash_parser.wasm +0 -0
- intentumdiff/wasm/clojure_parser.wasm +0 -0
- intentumdiff/wasm/cmake_parser.wasm +0 -0
- intentumdiff/wasm/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/css_parser.wasm +0 -0
- intentumdiff/wasm/dart_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/delphi_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_parser.wasm +0 -0
- intentumdiff/wasm/elixir_parser.wasm +0 -0
- intentumdiff/wasm/freebasic_parser.wasm +0 -0
- intentumdiff/wasm/generic_parser.wasm +0 -0
- intentumdiff/wasm/gitignore_parser.wasm +0 -0
- intentumdiff/wasm/go_parser.wasm +0 -0
- intentumdiff/wasm/gomod_parser.wasm +0 -0
- intentumdiff/wasm/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_parser.wasm +0 -0
- intentumdiff/wasm/haskell_parser.wasm +0 -0
- intentumdiff/wasm/html_parser.wasm +0 -0
- intentumdiff/wasm/html_renderer.wasm +0 -0
- intentumdiff/wasm/ini_parser.wasm +0 -0
- intentumdiff/wasm/java_parser.wasm +0 -0
- intentumdiff/wasm/js_ts_parser.wasm +0 -0
- intentumdiff/wasm/json_parser.wasm +0 -0
- intentumdiff/wasm/kotlin_parser.wasm +0 -0
- intentumdiff/wasm/latex_parser.wasm +0 -0
- intentumdiff/wasm/llm_renderer.wasm +0 -0
- intentumdiff/wasm/lua_parser.wasm +0 -0
- intentumdiff/wasm/make_parser.wasm +0 -0
- intentumdiff/wasm/markdown_parser.wasm +0 -0
- intentumdiff/wasm/mdx_parser.wasm +0 -0
- intentumdiff/wasm/ocaml_parser.wasm +0 -0
- intentumdiff/wasm/odin_parser.wasm +0 -0
- intentumdiff/wasm/parser_manifest.json +81 -2
- intentumdiff/wasm/patch_renderer.wasm +0 -0
- intentumdiff/wasm/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/po_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/proto_parser.wasm +0 -0
- intentumdiff/wasm/puppet_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/r_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/ruby_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/scala_parser.wasm +0 -0
- intentumdiff/wasm/scss_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/squirrel_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_parser.wasm +0 -0
- intentumdiff/wasm/terminal_renderer.wasm +0 -0
- intentumdiff/wasm/terraform_parser.wasm +0 -0
- intentumdiff/wasm/toml_parser.wasm +0 -0
- intentumdiff/wasm/tsql_parser.wasm +0 -0
- intentumdiff/wasm/vbnet_parser.wasm +0 -0
- intentumdiff/wasm/vue_parser.wasm +0 -0
- intentumdiff/wasm/wasm_provenance.json +884 -0
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/xml_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/wasm/zig_parser.wasm +0 -0
- intentumdiff_python-0.0.2b2.dist-info/METADATA +156 -0
- intentumdiff_python-0.0.2b2.dist-info/RECORD +171 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/WHEEL +1 -1
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
- intentumdiff/core/cst_serializer.py +0 -101
- intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
- intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import bisect
|
|
6
5
|
import hashlib
|
|
7
6
|
import json
|
|
8
7
|
import logging
|
|
9
|
-
from collections.abc import Iterator
|
|
10
8
|
from typing import Any
|
|
11
9
|
|
|
12
10
|
from intentumdiff.analysis.text_review import (
|
|
@@ -16,8 +14,6 @@ from intentumdiff.core.models import (
|
|
|
16
14
|
Change,
|
|
17
15
|
ChangeGroup,
|
|
18
16
|
ChangeGroupKind,
|
|
19
|
-
ChangeStreamEvent,
|
|
20
|
-
ChangeStreamPhase,
|
|
21
17
|
ChangeType,
|
|
22
18
|
NodePosition,
|
|
23
19
|
SemanticDiff,
|
|
@@ -84,465 +80,51 @@ def _count_semantic_nodes(root: SemanticNode) -> int:
|
|
|
84
80
|
|
|
85
81
|
|
|
86
82
|
def _empty_semantic_tree(language: str) -> SemanticNode:
|
|
87
|
-
|
|
88
|
-
return SemanticNode(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def _markdown_sections(source: str, *, side: str) -> list[SemanticNode]:
|
|
103
|
-
lines = source.splitlines()
|
|
104
|
-
heading_indices = [
|
|
105
|
-
idx
|
|
106
|
-
for idx, line in enumerate(lines)
|
|
107
|
-
if line.startswith("#") and line.lstrip("#").startswith(" ")
|
|
108
|
-
]
|
|
109
|
-
sections: list[SemanticNode] = []
|
|
110
|
-
for order, start in enumerate(heading_indices):
|
|
111
|
-
end = heading_indices[order + 1] if order + 1 < len(heading_indices) else len(lines)
|
|
112
|
-
text = "\n".join(lines[start:end]).strip()
|
|
113
|
-
if not text:
|
|
114
|
-
continue
|
|
115
|
-
digest = hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
116
|
-
sections.append(
|
|
117
|
-
SemanticNode(
|
|
118
|
-
id=f"markdown-{side}-{order}",
|
|
119
|
-
node_type="markdown_section",
|
|
120
|
-
label=lines[start].strip(),
|
|
121
|
-
position=NodePosition(
|
|
122
|
-
start_line=start,
|
|
123
|
-
start_col=0,
|
|
124
|
-
end_line=max(start, end - 1),
|
|
125
|
-
end_col=len(lines[end - 1]) if end > start else len(lines[start]),
|
|
126
|
-
),
|
|
127
|
-
structural_hash=digest,
|
|
128
|
-
children=[],
|
|
129
|
-
)
|
|
130
|
-
)
|
|
131
|
-
return sections
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def _markdown_section_body_hashes(source: str, *, side: str) -> dict[str, str]:
|
|
135
|
-
lines = source.splitlines()
|
|
136
|
-
heading_indices = [
|
|
137
|
-
idx
|
|
138
|
-
for idx, line in enumerate(lines)
|
|
139
|
-
if line.startswith("#") and line.lstrip("#").startswith(" ")
|
|
140
|
-
]
|
|
141
|
-
hashes: dict[str, str] = {}
|
|
142
|
-
for order, start in enumerate(heading_indices):
|
|
143
|
-
end = heading_indices[order + 1] if order + 1 < len(heading_indices) else len(lines)
|
|
144
|
-
body = "\n".join(lines[start + 1 : end]).strip()
|
|
145
|
-
hashes[f"markdown-{side}-{order}"] = hashlib.sha256(body.encode("utf-8")).hexdigest()
|
|
146
|
-
return hashes
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def _markdown_section_move_presentation(
|
|
150
|
-
presented: PresentationResult,
|
|
151
|
-
*,
|
|
152
|
-
old_source: str,
|
|
153
|
-
new_source: str,
|
|
154
|
-
old_filename: str,
|
|
155
|
-
new_filename: str,
|
|
156
|
-
) -> PresentationResult:
|
|
157
|
-
if not (_is_markdown_filename(old_filename) or _is_markdown_filename(new_filename)):
|
|
158
|
-
return presented
|
|
159
|
-
|
|
160
|
-
from intentumdiff.rust_core import try_rust_markdown_section_review
|
|
161
|
-
|
|
162
|
-
rust_review = try_rust_markdown_section_review(old_source, new_source)
|
|
163
|
-
if rust_review is not None:
|
|
164
|
-
moves = list(rust_review["moves"])
|
|
165
|
-
if not moves:
|
|
166
|
-
return presented
|
|
167
|
-
moved_labels = set(rust_review["moved_labels"])
|
|
168
|
-
filtered_changes = [
|
|
169
|
-
change
|
|
170
|
-
for change in presented.changes
|
|
171
|
-
if not (
|
|
172
|
-
change.change_type in {ChangeType.ADDITION, ChangeType.DELETION}
|
|
173
|
-
and (
|
|
174
|
-
change.old_node is not None
|
|
175
|
-
and change.old_node.label in moved_labels
|
|
176
|
-
or change.new_node is not None
|
|
177
|
-
and change.new_node.label in moved_labels
|
|
178
|
-
)
|
|
179
|
-
)
|
|
180
|
-
]
|
|
181
|
-
groups = list(presented.change_groups)
|
|
182
|
-
if rust_review["move_group"] is not None:
|
|
183
|
-
groups.append(rust_review["move_group"])
|
|
184
|
-
return PresentationResult(
|
|
185
|
-
changes=[*filtered_changes, *moves],
|
|
186
|
-
change_groups=groups,
|
|
187
|
-
ignored_style_changes=presented.ignored_style_changes,
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
# Python fallback — mirror of the Rust stage.
|
|
191
|
-
old_sections = _markdown_sections(old_source, side="old")
|
|
192
|
-
new_sections = _markdown_sections(new_source, side="new")
|
|
193
|
-
old_by_hash: dict[str, list[tuple[int, SemanticNode]]] = {}
|
|
194
|
-
new_by_hash: dict[str, list[tuple[int, SemanticNode]]] = {}
|
|
195
|
-
for idx, node in enumerate(old_sections):
|
|
196
|
-
old_by_hash.setdefault(node.structural_hash, []).append((idx, node))
|
|
197
|
-
for idx, node in enumerate(new_sections):
|
|
198
|
-
new_by_hash.setdefault(node.structural_hash, []).append((idx, node))
|
|
199
|
-
|
|
200
|
-
unique_common = [
|
|
201
|
-
digest
|
|
202
|
-
for digest, old_matches in old_by_hash.items()
|
|
203
|
-
if len(old_matches) == 1 and len(new_by_hash.get(digest, [])) == 1
|
|
204
|
-
]
|
|
205
|
-
old_relative_order = {
|
|
206
|
-
digest: order
|
|
207
|
-
for order, digest in enumerate(
|
|
208
|
-
sorted(unique_common, key=lambda item: old_by_hash[item][0][0])
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
new_relative_order = {
|
|
212
|
-
digest: order
|
|
213
|
-
for order, digest in enumerate(
|
|
214
|
-
sorted(unique_common, key=lambda item: new_by_hash[item][0][0])
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
# Insertion-shift discrimination (issue #15, mirroring the Rust LIS rule from issues
|
|
219
|
-
# #12/#32): sections whose RELATIVE order is preserved (longest increasing subsequence of
|
|
220
|
-
# new order walked in old order) are stationary anchors; only order-breaking sections
|
|
221
|
-
# move. A swap of two sections is ONE move, not two.
|
|
222
|
-
ordered_digests = sorted(unique_common, key=lambda item: old_relative_order[item])
|
|
223
|
-
sequence = [new_relative_order[digest] for digest in ordered_digests]
|
|
224
|
-
tails: list[int] = []
|
|
225
|
-
predecessors: dict[int, int | None] = {}
|
|
226
|
-
tail_indices: list[int] = []
|
|
227
|
-
for idx, value in enumerate(sequence):
|
|
228
|
-
pos = bisect.bisect_left([sequence[i] for i in tail_indices], value)
|
|
229
|
-
predecessors[idx] = tail_indices[pos - 1] if pos > 0 else None
|
|
230
|
-
if pos == len(tail_indices):
|
|
231
|
-
tail_indices.append(idx)
|
|
232
|
-
else:
|
|
233
|
-
tail_indices[pos] = idx
|
|
234
|
-
stationary: set[int] = set()
|
|
235
|
-
cursor: int | None = tail_indices[-1] if tail_indices else None
|
|
236
|
-
while cursor is not None:
|
|
237
|
-
stationary.add(cursor)
|
|
238
|
-
cursor = predecessors[cursor]
|
|
239
|
-
stationary_digests = {ordered_digests[idx] for idx in stationary}
|
|
240
|
-
|
|
241
|
-
moves: list[Change] = []
|
|
242
|
-
moved_labels: set[str] = set()
|
|
243
|
-
moved_old_ids: list[str] = []
|
|
244
|
-
moved_new_ids: list[str] = []
|
|
245
|
-
for digest in unique_common:
|
|
246
|
-
old_matches = old_by_hash[digest]
|
|
247
|
-
new_matches = new_by_hash[digest]
|
|
248
|
-
_old_idx, old_node = old_matches[0]
|
|
249
|
-
_new_idx, new_node = new_matches[0]
|
|
250
|
-
if old_relative_order[digest] == new_relative_order[digest]:
|
|
251
|
-
continue
|
|
252
|
-
if digest in stationary_digests:
|
|
253
|
-
continue
|
|
254
|
-
moves.append(
|
|
255
|
-
Change(
|
|
256
|
-
change_type=ChangeType.MOVE,
|
|
257
|
-
old_node=old_node,
|
|
258
|
-
new_node=new_node,
|
|
259
|
-
confidence=0.9,
|
|
260
|
-
description=f"Move Markdown section {old_node.label!r}",
|
|
261
|
-
)
|
|
262
|
-
)
|
|
263
|
-
moved_labels.add(old_node.label)
|
|
264
|
-
moved_old_ids.append(old_node.id)
|
|
265
|
-
moved_new_ids.append(new_node.id)
|
|
266
|
-
|
|
267
|
-
if not moves:
|
|
268
|
-
return presented
|
|
269
|
-
|
|
270
|
-
filtered_changes = [
|
|
271
|
-
change
|
|
272
|
-
for change in presented.changes
|
|
273
|
-
if not (
|
|
274
|
-
change.change_type in {ChangeType.ADDITION, ChangeType.DELETION}
|
|
275
|
-
and (
|
|
276
|
-
change.old_node is not None
|
|
277
|
-
and change.old_node.label in moved_labels
|
|
278
|
-
or change.new_node is not None
|
|
279
|
-
and change.new_node.label in moved_labels
|
|
280
|
-
)
|
|
281
|
-
)
|
|
282
|
-
]
|
|
283
|
-
move_group = ChangeGroup(
|
|
284
|
-
kind=ChangeGroupKind.MOVED_CODE,
|
|
285
|
-
raw_change_indices=[],
|
|
286
|
-
old_labels=sorted(moved_labels),
|
|
287
|
-
new_labels=sorted(moved_labels),
|
|
288
|
-
old_node_ids=moved_old_ids,
|
|
289
|
-
new_node_ids=moved_new_ids,
|
|
290
|
-
confidence=0.9,
|
|
291
|
-
rule_id="presentation.markdown_section_move",
|
|
292
|
-
metadata={"moved_section_count": len(moves)},
|
|
293
|
-
)
|
|
83
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
84
|
+
return SemanticNode.model_validate(_c_abi_call("empty_semantic_tree", language))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _markdown_presentation(presented: PresentationResult, *, old_source: str, new_source: str,
|
|
88
|
+
old_filename: str, new_filename: str, phase: str) -> PresentationResult:
|
|
89
|
+
"""DTO adapter for complete Rust reconciliation; core errors propagate."""
|
|
90
|
+
from intentumdiff.rust_core import _c_abi_call, _require_source_anchored_changes
|
|
91
|
+
result = _c_abi_call("reconcile_markdown", {
|
|
92
|
+
"changes": [change.model_dump(mode="json") for change in presented.changes],
|
|
93
|
+
"change_groups": [group.model_dump(mode="json") for group in presented.change_groups],
|
|
94
|
+
"ignored_style_changes": presented.ignored_style_changes,
|
|
95
|
+
}, old_source, new_source, old_filename, new_filename, phase)
|
|
294
96
|
return PresentationResult(
|
|
295
|
-
changes=[
|
|
296
|
-
|
|
297
|
-
|
|
97
|
+
changes=[Change.model_validate(value) for value in
|
|
98
|
+
_require_source_anchored_changes(result["changes"], "Rust Markdown reconciliation")],
|
|
99
|
+
change_groups=[ChangeGroup.model_validate(value) for value in result["change_groups"]],
|
|
100
|
+
ignored_style_changes=result["ignored_style_changes"],
|
|
298
101
|
)
|
|
299
102
|
|
|
300
103
|
|
|
301
|
-
def
|
|
302
|
-
presented
|
|
303
|
-
*,
|
|
304
|
-
old_source: str,
|
|
305
|
-
new_source: str,
|
|
306
|
-
old_filename: str,
|
|
307
|
-
new_filename: str,
|
|
308
|
-
) -> PresentationResult:
|
|
309
|
-
if not (_is_markdown_filename(old_filename) or _is_markdown_filename(new_filename)):
|
|
310
|
-
return presented
|
|
311
|
-
|
|
312
|
-
from intentumdiff.rust_core import try_rust_markdown_section_review
|
|
313
|
-
|
|
314
|
-
rust_review = try_rust_markdown_section_review(old_source, new_source)
|
|
315
|
-
if rust_review is not None:
|
|
316
|
-
modifications = list(rust_review["renames"])
|
|
317
|
-
if not modifications:
|
|
318
|
-
return presented
|
|
319
|
-
old_heading_lines = set(rust_review["old_heading_lines"])
|
|
320
|
-
new_heading_lines = set(rust_review["new_heading_lines"])
|
|
321
|
-
filtered_changes = [
|
|
322
|
-
change
|
|
323
|
-
for change in presented.changes
|
|
324
|
-
if not (
|
|
325
|
-
change.change_type
|
|
326
|
-
in {ChangeType.ADDITION, ChangeType.DELETION, ChangeType.MODIFICATION}
|
|
327
|
-
and (
|
|
328
|
-
change.old_node is not None
|
|
329
|
-
and change.old_node.position.start_line in old_heading_lines
|
|
330
|
-
or change.new_node is not None
|
|
331
|
-
and change.new_node.position.start_line in new_heading_lines
|
|
332
|
-
)
|
|
333
|
-
)
|
|
334
|
-
]
|
|
335
|
-
groups = list(presented.change_groups)
|
|
336
|
-
if rust_review["rename_group"] is not None:
|
|
337
|
-
groups.append(rust_review["rename_group"])
|
|
338
|
-
return PresentationResult(
|
|
339
|
-
changes=[*filtered_changes, *modifications],
|
|
340
|
-
change_groups=groups,
|
|
341
|
-
ignored_style_changes=presented.ignored_style_changes,
|
|
342
|
-
)
|
|
104
|
+
def _markdown_section_move_presentation(presented: PresentationResult, **kwargs: Any) -> PresentationResult:
|
|
105
|
+
return _markdown_presentation(presented, phase="moves", **kwargs)
|
|
343
106
|
|
|
344
|
-
# Python fallback — mirror of the Rust stage.
|
|
345
|
-
old_sections = _markdown_sections(old_source, side="old")
|
|
346
|
-
new_sections = _markdown_sections(new_source, side="new")
|
|
347
|
-
old_body_hashes = _markdown_section_body_hashes(old_source, side="old")
|
|
348
|
-
new_body_hashes = _markdown_section_body_hashes(new_source, side="new")
|
|
349
|
-
old_by_body: dict[str, list[SemanticNode]] = {}
|
|
350
|
-
new_by_body: dict[str, list[SemanticNode]] = {}
|
|
351
|
-
for node in old_sections:
|
|
352
|
-
old_by_body.setdefault(old_body_hashes.get(node.id, ""), []).append(node)
|
|
353
|
-
for node in new_sections:
|
|
354
|
-
new_by_body.setdefault(new_body_hashes.get(node.id, ""), []).append(node)
|
|
355
|
-
|
|
356
|
-
modifications: list[Change] = []
|
|
357
|
-
old_heading_lines: set[int] = set()
|
|
358
|
-
new_heading_lines: set[int] = set()
|
|
359
|
-
old_labels: list[str] = []
|
|
360
|
-
new_labels: list[str] = []
|
|
361
|
-
old_ids: list[str] = []
|
|
362
|
-
new_ids: list[str] = []
|
|
363
|
-
for body_hash, old_matches in old_by_body.items():
|
|
364
|
-
new_matches = new_by_body.get(body_hash, [])
|
|
365
|
-
if not body_hash or len(old_matches) != 1 or len(new_matches) != 1:
|
|
366
|
-
continue
|
|
367
|
-
old_node = old_matches[0]
|
|
368
|
-
new_node = new_matches[0]
|
|
369
|
-
if old_node.label == new_node.label:
|
|
370
|
-
continue
|
|
371
|
-
modifications.append(
|
|
372
|
-
Change(
|
|
373
|
-
change_type=ChangeType.MODIFICATION,
|
|
374
|
-
old_node=old_node,
|
|
375
|
-
new_node=new_node,
|
|
376
|
-
confidence=0.9,
|
|
377
|
-
description=(f"Rename Markdown section {old_node.label!r} -> {new_node.label!r}"),
|
|
378
|
-
)
|
|
379
|
-
)
|
|
380
|
-
old_heading_lines.add(old_node.position.start_line)
|
|
381
|
-
new_heading_lines.add(new_node.position.start_line)
|
|
382
|
-
old_labels.append(old_node.label)
|
|
383
|
-
new_labels.append(new_node.label)
|
|
384
|
-
old_ids.append(old_node.id)
|
|
385
|
-
new_ids.append(new_node.id)
|
|
386
|
-
|
|
387
|
-
if not modifications:
|
|
388
|
-
return presented
|
|
389
|
-
|
|
390
|
-
filtered_changes = [
|
|
391
|
-
change
|
|
392
|
-
for change in presented.changes
|
|
393
|
-
if not (
|
|
394
|
-
# A heading rename is now surfaced as one markdown_section MODIFICATION; drop the
|
|
395
|
-
# overlapping line-level change on the same heading line (add/delete OR the
|
|
396
|
-
# line-level modification the generic text diff produces) so it isn't duplicated.
|
|
397
|
-
change.change_type
|
|
398
|
-
in {ChangeType.ADDITION, ChangeType.DELETION, ChangeType.MODIFICATION}
|
|
399
|
-
and (
|
|
400
|
-
change.old_node is not None
|
|
401
|
-
and change.old_node.position.start_line in old_heading_lines
|
|
402
|
-
or change.new_node is not None
|
|
403
|
-
and change.new_node.position.start_line in new_heading_lines
|
|
404
|
-
)
|
|
405
|
-
)
|
|
406
|
-
]
|
|
407
|
-
group = ChangeGroup(
|
|
408
|
-
kind=ChangeGroupKind.MEANINGFUL_CHANGE,
|
|
409
|
-
raw_change_indices=[],
|
|
410
|
-
old_labels=old_labels,
|
|
411
|
-
new_labels=new_labels,
|
|
412
|
-
old_node_ids=old_ids,
|
|
413
|
-
new_node_ids=new_ids,
|
|
414
|
-
confidence=0.9,
|
|
415
|
-
rule_id="presentation.markdown_section_heading_rename",
|
|
416
|
-
metadata={"renamed_section_count": len(modifications)},
|
|
417
|
-
)
|
|
418
|
-
return PresentationResult(
|
|
419
|
-
changes=[*filtered_changes, *modifications],
|
|
420
|
-
change_groups=[*presented.change_groups, group],
|
|
421
|
-
ignored_style_changes=presented.ignored_style_changes,
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
def _all_semantic_nodes(root: SemanticNode) -> list[SemanticNode]:
|
|
426
|
-
return [root, *root.descendants()]
|
|
427
107
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
parents: dict[str, SemanticNode] = {}
|
|
431
|
-
for node in _all_semantic_nodes(root):
|
|
432
|
-
for child in node.children:
|
|
433
|
-
if child.id != node.id:
|
|
434
|
-
parents[child.id] = node
|
|
435
|
-
return parents
|
|
108
|
+
def _markdown_section_heading_rename_presentation(presented: PresentationResult, **kwargs: Any) -> PresentationResult:
|
|
109
|
+
return _markdown_presentation(presented, phase="renames", **kwargs)
|
|
436
110
|
|
|
437
111
|
|
|
438
112
|
def _has_error_node(tree: SemanticNode) -> bool:
|
|
439
|
-
"""
|
|
440
|
-
|
|
113
|
+
"""Ask Rust whether a semantic tree contains a parse error."""
|
|
114
|
+
from intentumdiff.rust_core import parse_errors_present
|
|
115
|
+
return parse_errors_present("", tree.model_dump_json(), "")
|
|
441
116
|
|
|
442
117
|
|
|
443
118
|
def _token_fallback_diff(
|
|
444
|
-
old_content: str,
|
|
445
|
-
|
|
446
|
-
old_filename: str,
|
|
447
|
-
new_filename: str,
|
|
448
|
-
language: str,
|
|
449
|
-
*,
|
|
450
|
-
metadata: dict[str, Any] | None = None,
|
|
119
|
+
old_content: str, new_content: str, old_filename: str, new_filename: str,
|
|
120
|
+
language: str, *, metadata: dict[str, Any] | None = None,
|
|
451
121
|
) -> SemanticDiff:
|
|
452
|
-
"""
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
so callers can distinguish it from a full semantic diff.
|
|
459
|
-
"""
|
|
460
|
-
import difflib
|
|
461
|
-
|
|
462
|
-
old_tokens = old_content.split()
|
|
463
|
-
new_tokens = new_content.split()
|
|
464
|
-
changes: list[Change] = []
|
|
465
|
-
matcher = difflib.SequenceMatcher(None, old_tokens, new_tokens, autojunk=False)
|
|
466
|
-
for op, i1, i2, j1, j2 in matcher.get_opcodes():
|
|
467
|
-
if op == "equal":
|
|
468
|
-
continue
|
|
469
|
-
if op == "insert":
|
|
470
|
-
changes.append(
|
|
471
|
-
Change(
|
|
472
|
-
change_type=ChangeType.ADDITION,
|
|
473
|
-
description=f"token-level fallback: inserted {j2 - j1} token(s)",
|
|
474
|
-
confidence=0.5,
|
|
475
|
-
)
|
|
476
|
-
)
|
|
477
|
-
elif op == "delete":
|
|
478
|
-
changes.append(
|
|
479
|
-
Change(
|
|
480
|
-
change_type=ChangeType.DELETION,
|
|
481
|
-
description=f"token-level fallback: deleted {i2 - i1} token(s)",
|
|
482
|
-
confidence=0.5,
|
|
483
|
-
)
|
|
484
|
-
)
|
|
485
|
-
elif op == "replace":
|
|
486
|
-
changes.append(
|
|
487
|
-
Change(
|
|
488
|
-
change_type=ChangeType.MODIFICATION,
|
|
489
|
-
description=f"token-level fallback: {i2 - i1} token(s) → {j2 - j1} token(s)",
|
|
490
|
-
confidence=0.5,
|
|
491
|
-
)
|
|
492
|
-
)
|
|
493
|
-
return SemanticDiff(
|
|
494
|
-
changes=changes,
|
|
495
|
-
old_filename=old_filename,
|
|
496
|
-
new_filename=new_filename,
|
|
497
|
-
language=language,
|
|
498
|
-
has_semantic_changes=bool(changes),
|
|
499
|
-
is_fallback=True,
|
|
500
|
-
parse_errors=["tree-sitter reported parse errors; token-level fallback used"],
|
|
501
|
-
metadata=metadata or {},
|
|
502
|
-
)
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
def _annotate_text_diffs(changes: list[Change]) -> list[Change]:
|
|
506
|
-
"""
|
|
507
|
-
Annotate leaf-node MODIFICATION changes with an inline character-level diff.
|
|
508
|
-
|
|
509
|
-
For each ``MODIFICATION`` change where both nodes are leaves with different
|
|
510
|
-
labels, populates ``Change.text_diff`` with a compact ``[-old][+new]``
|
|
511
|
-
annotation using ``difflib.SequenceMatcher``. Truncated to 200 characters.
|
|
512
|
-
Already-annotated changes (``text_diff is not None``) are left unchanged.
|
|
513
|
-
"""
|
|
514
|
-
import difflib
|
|
515
|
-
|
|
516
|
-
result: list[Change] = []
|
|
517
|
-
for change in changes:
|
|
518
|
-
if (
|
|
519
|
-
change.change_type == ChangeType.MODIFICATION
|
|
520
|
-
and change.old_node is not None
|
|
521
|
-
and change.new_node is not None
|
|
522
|
-
and change.old_node.is_leaf()
|
|
523
|
-
and change.new_node.is_leaf()
|
|
524
|
-
and change.old_node.label != change.new_node.label
|
|
525
|
-
and change.text_diff is None
|
|
526
|
-
):
|
|
527
|
-
old_label = change.old_node.label
|
|
528
|
-
new_label = change.new_node.label
|
|
529
|
-
matcher = difflib.SequenceMatcher(None, old_label, new_label, autojunk=False)
|
|
530
|
-
parts: list[str] = []
|
|
531
|
-
for op, i1, i2, j1, j2 in matcher.get_opcodes():
|
|
532
|
-
if op == "equal":
|
|
533
|
-
parts.append(old_label[i1:i2])
|
|
534
|
-
elif op == "replace":
|
|
535
|
-
parts.append(f"[-{old_label[i1:i2]}][+{new_label[j1:j2]}]")
|
|
536
|
-
elif op == "delete":
|
|
537
|
-
parts.append(f"[-{old_label[i1:i2]}]")
|
|
538
|
-
elif op == "insert":
|
|
539
|
-
parts.append(f"[+{new_label[j1:j2]}]")
|
|
540
|
-
text_diff: str = "".join(parts)
|
|
541
|
-
if len(text_diff) > 200:
|
|
542
|
-
text_diff = text_diff[:197] + "…"
|
|
543
|
-
change = change.model_copy(update={"text_diff": text_diff})
|
|
544
|
-
result.append(change)
|
|
545
|
-
return result
|
|
122
|
+
"""Compatibility adapter for Rust's source-preserving fallback."""
|
|
123
|
+
from intentumdiff.rust_core import source_fallback_diff
|
|
124
|
+
details = metadata or {}
|
|
125
|
+
result = source_fallback_diff(old_content, new_content, old_filename,
|
|
126
|
+
new_filename, language, str(details.get("fallback_reason", "parse_errors")))
|
|
127
|
+
return result.model_copy(update={"metadata": {**details, **dict(result.metadata)}})
|
|
546
128
|
|
|
547
129
|
|
|
548
130
|
# ---------------------------------------------------------------------------
|
|
@@ -550,237 +132,8 @@ def _annotate_text_diffs(changes: list[Change]) -> list[Change]:
|
|
|
550
132
|
# ---------------------------------------------------------------------------
|
|
551
133
|
|
|
552
134
|
|
|
553
|
-
_GENERIC_STRING_LABELS = frozenset({"string", "string_literal"})
|
|
554
|
-
|
|
555
|
-
# Entity node types whose labels should surface in review output even when
|
|
556
|
-
# the matcher preserved the container (its body changed in place but the
|
|
557
|
-
# container itself was matched by label). Broad coverage across all
|
|
558
|
-
# supported parsers — tree-sitter grammars plus the lightweight hand-written
|
|
559
|
-
# parsers (graphql, po, asciidoc, latex, ocaml, reasonml). See
|
|
560
|
-
# ``the retired NOISE_SUPPRESSION_RETUNE doc (git history)`` Step A2.
|
|
561
|
-
_NAMED_ENTITY_NODE_TYPES: frozenset[str] = frozenset(
|
|
562
|
-
{
|
|
563
|
-
# Tree-sitter common
|
|
564
|
-
"function_definition", "async_function_def", "class_definition",
|
|
565
|
-
"method_declaration", "function_declaration", "async_function_declaration",
|
|
566
|
-
"constructor_declaration",
|
|
567
|
-
"destructor_declaration", "property_declaration", "field_declaration",
|
|
568
|
-
"variable_declaration", "lexical_declaration", "struct_definition",
|
|
569
|
-
"interface_declaration", "enum_declaration", "enum_member_declaration",
|
|
570
|
-
"operator_declaration", "event_declaration", "delegate_declaration",
|
|
571
|
-
"record_declaration", "record_struct_declaration",
|
|
572
|
-
# GraphQL
|
|
573
|
-
"type_definition", "operation_definition", "fragment_definition",
|
|
574
|
-
"field_definition", "directive_definition", "schema_definition",
|
|
575
|
-
"enum_definition", "input_object_definition",
|
|
576
|
-
# PO/gettext
|
|
577
|
-
"message", "obsolete_message",
|
|
578
|
-
# AsciiDoc
|
|
579
|
-
"section_level_1", "section_level_2", "section_level_3",
|
|
580
|
-
"section_level_4", "section_level_5", "section_level_6",
|
|
581
|
-
# LaTeX
|
|
582
|
-
"document_class", "package", "section", "environment",
|
|
583
|
-
# OCaml / ReasonML
|
|
584
|
-
"module_binding", "module", "value_definition",
|
|
585
|
-
"recursive_value", "component", "signature_value", "class_type",
|
|
586
|
-
"exception",
|
|
587
|
-
}
|
|
588
|
-
)
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
def _is_named_entity_node(node: SemanticNode) -> bool:
|
|
592
|
-
"""Check whether a node is a named entity whose label should surface in review."""
|
|
593
|
-
if not node.label or node.label == node.node_type:
|
|
594
|
-
return False
|
|
595
|
-
return (
|
|
596
|
-
node.node_type in _NAMED_ENTITY_NODE_TYPES
|
|
597
|
-
or node.node_type.endswith("_definition")
|
|
598
|
-
or node.node_type.endswith("_declaration")
|
|
599
|
-
)
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
def _surface_changed_in_place_entities(
|
|
603
|
-
*,
|
|
604
|
-
matching: Any,
|
|
605
|
-
changes: list[Change],
|
|
606
|
-
) -> list[ChangeGroup]:
|
|
607
|
-
"""Emit MEANINGFUL_CHANGE groups for named entities whose body changed in place.
|
|
608
|
-
|
|
609
|
-
When the matcher preserves a named entity (e.g. ``type User``) whose body
|
|
610
|
-
changed, the entity itself doesn't appear in the change list — only its
|
|
611
|
-
changed descendants do. This function scans the matching for such pairs
|
|
612
|
-
and emits change-groups carrying the entity's label, so review UIs and
|
|
613
|
-
entity-label assertions can surface the container name.
|
|
614
|
-
|
|
615
|
-
Guards:
|
|
616
|
-
- Both endpoints must be named entities (``_is_named_entity_node``).
|
|
617
|
-
- At least one descendant of the pair must appear in the change list
|
|
618
|
-
(the container genuinely changed — detected via observable changes
|
|
619
|
-
rather than structural_hash, which may be unreliable for some
|
|
620
|
-
parser-produced trees).
|
|
621
|
-
- The pair's old/new IDs must not already appear in any top-level
|
|
622
|
-
change event (avoid duplicating already-surfaced entities).
|
|
623
|
-
"""
|
|
624
|
-
if not matching:
|
|
625
|
-
return []
|
|
626
|
-
|
|
627
|
-
# Collect IDs that already surface in the change list.
|
|
628
|
-
surfaced_old_ids: set[str] = set()
|
|
629
|
-
surfaced_new_ids: set[str] = set()
|
|
630
|
-
for change in changes:
|
|
631
|
-
if change.old_node is not None:
|
|
632
|
-
surfaced_old_ids.add(change.old_node.id)
|
|
633
|
-
if change.new_node is not None:
|
|
634
|
-
surfaced_new_ids.add(change.new_node.id)
|
|
635
|
-
|
|
636
|
-
groups: list[ChangeGroup] = []
|
|
637
|
-
for pair in matching:
|
|
638
|
-
old_node = getattr(pair, "old_node", None)
|
|
639
|
-
new_node = getattr(pair, "new_node", None)
|
|
640
|
-
if old_node is None or new_node is None:
|
|
641
|
-
continue
|
|
642
|
-
if not _is_named_entity_node(old_node) or not _is_named_entity_node(new_node):
|
|
643
|
-
continue
|
|
644
|
-
# Skip if either endpoint already surfaces in a top-level change.
|
|
645
|
-
if old_node.id in surfaced_old_ids or new_node.id in surfaced_new_ids:
|
|
646
|
-
continue
|
|
647
|
-
# Check if any descendant of this entity pair appears in the change
|
|
648
|
-
# list. This is the reliable signal that the container changed in
|
|
649
|
-
# place — structural_hash comparison alone is insufficient for some
|
|
650
|
-
# parser-produced trees where the hash doesn't capture content changes.
|
|
651
|
-
old_desc_ids = {d.id for d in old_node.descendants()}
|
|
652
|
-
new_desc_ids = {d.id for d in new_node.descendants()}
|
|
653
|
-
has_changed_descendant = bool(
|
|
654
|
-
old_desc_ids & surfaced_old_ids or new_desc_ids & surfaced_new_ids
|
|
655
|
-
)
|
|
656
|
-
if not has_changed_descendant:
|
|
657
|
-
continue
|
|
658
|
-
groups.append(
|
|
659
|
-
ChangeGroup(
|
|
660
|
-
kind=ChangeGroupKind.MEANINGFUL_CHANGE,
|
|
661
|
-
raw_change_indices=[],
|
|
662
|
-
old_labels=[old_node.label],
|
|
663
|
-
new_labels=[new_node.label],
|
|
664
|
-
old_node_ids=[old_node.id],
|
|
665
|
-
new_node_ids=[new_node.id],
|
|
666
|
-
confidence=0.9,
|
|
667
|
-
rule_id="presentation.surface_changed_in_place_entity",
|
|
668
|
-
metadata={
|
|
669
|
-
"entity_type": old_node.node_type,
|
|
670
|
-
"old_label": old_node.label,
|
|
671
|
-
"new_label": new_node.label,
|
|
672
|
-
},
|
|
673
|
-
)
|
|
674
|
-
)
|
|
675
|
-
return groups
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
def _slice_source_text(source: str, position: NodePosition) -> str:
|
|
679
|
-
lines = source.splitlines()
|
|
680
|
-
if position.start_line < 0 or position.start_line >= len(lines):
|
|
681
|
-
return ""
|
|
682
|
-
if position.end_line < position.start_line:
|
|
683
|
-
return ""
|
|
684
|
-
if position.start_line == position.end_line:
|
|
685
|
-
return lines[position.start_line][position.start_col : position.end_col]
|
|
686
|
-
|
|
687
|
-
selected = [lines[position.start_line][position.start_col :]]
|
|
688
|
-
for line_no in range(position.start_line + 1, min(position.end_line, len(lines))):
|
|
689
|
-
selected.append(lines[line_no])
|
|
690
|
-
if position.end_line < len(lines):
|
|
691
|
-
selected.append(lines[position.end_line][: position.end_col])
|
|
692
|
-
return "\n".join(selected)
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
def _clean_string_literal_label(text: str) -> str:
|
|
696
|
-
value = text.strip()
|
|
697
|
-
while value and value[0] in "rRuUbBfF@$":
|
|
698
|
-
value = value[1:]
|
|
699
|
-
if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"', "`"}:
|
|
700
|
-
value = value[1:-1]
|
|
701
|
-
return value.strip()
|
|
702
|
-
|
|
703
|
-
|
|
704
135
|
def _enrich_literal_labels(root: SemanticNode, source: str) -> SemanticNode:
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
node_type = root.node_type.lower()
|
|
708
|
-
if "string" in node_type and root.label in _GENERIC_STRING_LABELS:
|
|
709
|
-
literal = _clean_string_literal_label(_slice_source_text(source, root.position))
|
|
710
|
-
if literal:
|
|
711
|
-
label = literal
|
|
712
|
-
if node_type == "order_by_clause" and root.label in {root.node_type, node_type}:
|
|
713
|
-
source_slice = _slice_source_text(source, root.position).lower()
|
|
714
|
-
if "descending" in source_slice:
|
|
715
|
-
label = f"{root.label} descending"
|
|
716
|
-
if children == root.children and label == root.label:
|
|
717
|
-
return root
|
|
718
|
-
return root.model_copy(update={"label": label, "children": children})
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
def _changes_to_stream_events(
|
|
722
|
-
before: list[Change],
|
|
723
|
-
after: list[Change],
|
|
724
|
-
phase: ChangeStreamPhase,
|
|
725
|
-
) -> Iterator[ChangeStreamEvent]:
|
|
726
|
-
"""Diff two successive change lists and emit ``ChangeStreamEvent`` objects.
|
|
727
|
-
|
|
728
|
-
Uses Python object identity to detect which changes were consumed
|
|
729
|
-
(present in *before* but not *after*) and which were added (present in
|
|
730
|
-
*after* but not *before*). ``Change`` is a frozen Pydantic model, so
|
|
731
|
-
every logical change is a distinct Python object even when its content is
|
|
732
|
-
the same as another change.
|
|
733
|
-
|
|
734
|
-
For each new change in *after*:
|
|
735
|
-
|
|
736
|
-
* If the new change's ``old_node.id`` or ``new_node.id`` matches a node ID
|
|
737
|
-
from a consumed *before* change, the event is emitted as ``action="revise"``
|
|
738
|
-
with ``replaced_ids`` listing the consumed node IDs.
|
|
739
|
-
* Otherwise, ``action="add"`` is emitted (a brand-new change with no
|
|
740
|
-
predecessor in *before*).
|
|
741
|
-
|
|
742
|
-
Any change that was consumed but not referenced by a new change is emitted
|
|
743
|
-
as ``action="remove"`` with ``replaced_ids=[node_id]``.
|
|
744
|
-
"""
|
|
745
|
-
before_by_pyid = {id(c): c for c in before}
|
|
746
|
-
after_by_pyid = {id(c): c for c in after}
|
|
747
|
-
|
|
748
|
-
consumed = [c for pyid, c in before_by_pyid.items() if pyid not in after_by_pyid]
|
|
749
|
-
added = [c for pyid, c in after_by_pyid.items() if pyid not in before_by_pyid]
|
|
750
|
-
|
|
751
|
-
# Build node-id → consumed-change lookup.
|
|
752
|
-
consumed_node_ids: dict[str, Change] = {}
|
|
753
|
-
for c in consumed:
|
|
754
|
-
if c.old_node:
|
|
755
|
-
consumed_node_ids[c.old_node.id] = c
|
|
756
|
-
if c.new_node:
|
|
757
|
-
consumed_node_ids[c.new_node.id] = c
|
|
758
|
-
|
|
759
|
-
mentioned: set[str] = set()
|
|
760
|
-
|
|
761
|
-
for new_change in added:
|
|
762
|
-
replaced_ids: list[str] = []
|
|
763
|
-
if new_change.old_node and new_change.old_node.id in consumed_node_ids:
|
|
764
|
-
replaced_ids.append(new_change.old_node.id)
|
|
765
|
-
mentioned.add(new_change.old_node.id)
|
|
766
|
-
if new_change.new_node and new_change.new_node.id in consumed_node_ids:
|
|
767
|
-
replaced_ids.append(new_change.new_node.id)
|
|
768
|
-
mentioned.add(new_change.new_node.id)
|
|
769
|
-
yield ChangeStreamEvent(
|
|
770
|
-
phase=phase,
|
|
771
|
-
action="revise" if replaced_ids else "add",
|
|
772
|
-
replaced_ids=replaced_ids,
|
|
773
|
-
change=new_change,
|
|
774
|
-
)
|
|
775
|
-
|
|
776
|
-
# Emit "remove" for consumed changes not referenced by any new change.
|
|
777
|
-
for c in consumed:
|
|
778
|
-
node_id = c.old_node.id if c.old_node else c.new_node.id if c.new_node else None
|
|
779
|
-
if node_id and node_id not in mentioned:
|
|
780
|
-
yield ChangeStreamEvent(
|
|
781
|
-
phase=phase,
|
|
782
|
-
action="remove",
|
|
783
|
-
replaced_ids=[node_id],
|
|
784
|
-
)
|
|
785
|
-
|
|
136
|
+
"""Delegate literal-label enrichment to Rust; never reconstruct semantics."""
|
|
137
|
+
from intentumdiff.rust_core import enrich_literal_labels
|
|
786
138
|
|
|
139
|
+
return enrich_literal_labels(root, source)
|