intentumdiff-python 0.0.1__py3-none-win_amd64.whl → 0.0.3b1__py3-none-win_amd64.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 +9 -0
- intentumdiff/__main__.py +12 -0
- intentumdiff/_differ_gate.py +0 -136
- intentumdiff/_differ_presentation.py +17 -735
- intentumdiff/_differ_runtime.py +13 -64
- intentumdiff/analysis/compile_commands.py +26 -141
- intentumdiff/analysis/cross_file.py +23 -25
- intentumdiff/analysis/diagnostics.py +1 -164
- intentumdiff/analysis/guardrail_reports.py +31 -33
- intentumdiff/analysis/guardrails.py +111 -188
- intentumdiff/analysis/schema_resolver.py +72 -360
- intentumdiff/analysis/user_schemas.py +57 -254
- intentumdiff/api.py +21 -0
- intentumdiff/cache/sqlite_store.py +5 -23
- intentumdiff/cli/__init__.py +59 -0
- intentumdiff/cli/_commands.py +243 -137
- intentumdiff/cli/_parser.py +51 -56
- intentumdiff/cli/_shared.py +151 -116
- intentumdiff/content_type.py +13 -30
- intentumdiff/core/commit_differ.py +137 -286
- intentumdiff/core/diffignore.py +28 -34
- intentumdiff/core/index.py +16 -18
- intentumdiff/core/indexer.py +148 -169
- intentumdiff/core/models.py +279 -83
- intentumdiff/differ.py +366 -1000
- intentumdiff/github_app.py +40 -27
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +197 -34
- intentumdiff/lsp/client.py +49 -43
- intentumdiff/lsp/enricher.py +19 -119
- intentumdiff/lsp/exceptions.py +6 -7
- intentumdiff/lsp/servers.py +10 -11
- intentumdiff/lsp_server/_codelens.py +24 -57
- intentumdiff/lsp_server/_diagnostics.py +23 -51
- intentumdiff/lsp_server/_handlers.py +67 -9
- intentumdiff/lsp_server/server.py +28 -8
- intentumdiff/plugins/adapter.py +5 -0
- intentumdiff/plugins/builtins.py +7 -14
- intentumdiff/plugins/exceptions.py +28 -0
- intentumdiff/plugins/hub.py +39 -43
- intentumdiff/plugins/loader.py +229 -215
- intentumdiff/plugins/registry.py +259 -207
- intentumdiff/plugins/registry.schema.json +156 -15
- intentumdiff/plugins/registry_schema.py +47 -140
- intentumdiff/rust_core.py +623 -1326
- intentumdiff/serve/_app.py +26 -35
- intentumdiff/sources/base.py +24 -0
- intentumdiff/sources/file_source.py +15 -2
- intentumdiff/sources/git_source.py +64 -185
- 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 +0 -27
- 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/watcher.py +15 -17
- intentumdiff_python-0.0.3b1.dist-info/METADATA +188 -0
- intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +1 -1
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
- intentumdiff/analysis/invariances.py +0 -1207
- intentumdiff/analysis/keyed_profiles.py +0 -25
- intentumdiff/analysis/resource_profiles.py +0 -14
- intentumdiff/analysis/text_review.py +0 -46
- intentumdiff/core/cst_serializer.py +0 -101
- intentumdiff/invariances/__init__.py +0 -2
- intentumdiff/invariances/rules.schema.json +0 -283
- intentumdiff/invariances/rules.yaml +0 -349
- 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.3b1.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
|
@@ -10,11 +10,12 @@ level:
|
|
|
10
10
|
1. Runs ``SemanticDiffer.diff_commit()`` to get per-file ``SemanticDiff``
|
|
11
11
|
objects for every changed file.
|
|
12
12
|
2. Parses all changed files (old and new versions) into ``SemanticNode``
|
|
13
|
-
trees
|
|
14
|
-
3.
|
|
15
|
-
``MOVE_TO_MODULE`` / ``SPLIT_MODULE`` /
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
trees (or records the parse-failure text for a side).
|
|
14
|
+
3. Hands them to core's ``commit_cross_file_index`` (core #298), which builds
|
|
15
|
+
the symbol tables, detects ``MOVE_TO_MODULE`` / ``SPLIT_MODULE`` /
|
|
16
|
+
``CROSS_FILE_RENAME`` changes and reports unindexed files.
|
|
17
|
+
4. Returns a ``CommitDiff`` with the per-file diffs, the cross-file changes and
|
|
18
|
+
core's index completeness fields.
|
|
18
19
|
|
|
19
20
|
Usage::
|
|
20
21
|
|
|
@@ -32,19 +33,20 @@ Usage::
|
|
|
32
33
|
|
|
33
34
|
from __future__ import annotations
|
|
34
35
|
|
|
35
|
-
import json
|
|
36
36
|
import logging
|
|
37
37
|
import os
|
|
38
38
|
from dataclasses import dataclass
|
|
39
|
-
from typing import TYPE_CHECKING, Iterator
|
|
39
|
+
from typing import TYPE_CHECKING, Callable, Iterator
|
|
40
40
|
|
|
41
|
-
from intentumdiff.core.models import CommitDiff,
|
|
41
|
+
from intentumdiff.core.models import CommitDiff, DiffConfig, SemanticDiff
|
|
42
42
|
from intentumdiff.differ import SemanticDiffer
|
|
43
|
-
from intentumdiff.analysis.cross_file import
|
|
44
|
-
from intentumdiff.core.index import SemanticIndex
|
|
43
|
+
from intentumdiff.analysis.cross_file import cross_file_change_from_core
|
|
45
44
|
from intentumdiff.plugins.exceptions import PluginError, PluginNotFoundError
|
|
45
|
+
from intentumdiff.rust_core import commit_cross_file_index
|
|
46
46
|
from intentumdiff.sources.git_source import iter_changed_sources
|
|
47
47
|
from intentumdiff.vcs.base import VcsBackend
|
|
48
|
+
from intentumdiff.vcs.git_cli import resolve_repo_root
|
|
49
|
+
from intentumdiff.vcs._safe_path import safe_policy_path
|
|
48
50
|
|
|
49
51
|
if TYPE_CHECKING:
|
|
50
52
|
from intentumdiff.core.models import SemanticNode
|
|
@@ -135,15 +137,9 @@ class CommitDiffer:
|
|
|
135
137
|
if backend is not None:
|
|
136
138
|
return self._diff_with_backend(backend, old_ref, new_ref)
|
|
137
139
|
|
|
138
|
-
# Pre-pass: collect git-deletion paths and any new .gitignore content so
|
|
139
|
-
# we can tag SemanticDiff objects whose deletion was triggered by a .gitignore
|
|
140
|
-
# rule change rather than actual code removal.
|
|
141
|
-
deleted_paths, gitignore_spec = self._collect_gitignore_state(
|
|
142
|
-
repo_path, old_ref, new_ref
|
|
143
|
-
)
|
|
144
|
-
|
|
145
140
|
results, errors, changed_file_count = self._collect_file_diffs(
|
|
146
|
-
iter_changed_sources(repo_path, old_ref, new_ref)
|
|
141
|
+
iter_changed_sources(repo_path, old_ref, new_ref),
|
|
142
|
+
policy_root=resolve_repo_root(repo_path),
|
|
147
143
|
)
|
|
148
144
|
|
|
149
145
|
return self._finalize_commit_diff(
|
|
@@ -152,8 +148,6 @@ class CommitDiffer:
|
|
|
152
148
|
changed_file_count=changed_file_count,
|
|
153
149
|
old_ref=old_ref,
|
|
154
150
|
new_ref=new_ref,
|
|
155
|
-
deleted_paths=deleted_paths,
|
|
156
|
-
gitignore_spec=gitignore_spec,
|
|
157
151
|
)
|
|
158
152
|
|
|
159
153
|
def iter_file_diffs(
|
|
@@ -165,8 +159,7 @@ class CommitDiffer:
|
|
|
165
159
|
"""
|
|
166
160
|
Yield per-file diffs one at a time for progressive/streaming review.
|
|
167
161
|
|
|
168
|
-
|
|
169
|
-
then yields each changed source's :class:`FileDiffResult` (on success)
|
|
162
|
+
Yields each changed source's :class:`FileDiffResult` (on success)
|
|
170
163
|
or :class:`FileDiffError` (when no parser is available or the pipeline
|
|
171
164
|
failed). Cross-file analysis is NOT performed here — callers that need
|
|
172
165
|
a complete :class:`CommitDiff` should collect the results and pass them
|
|
@@ -175,31 +168,23 @@ class CommitDiffer:
|
|
|
175
168
|
Always uses the git backend (the ``backend`` parameter of
|
|
176
169
|
:meth:`diff_commit` is not supported by this streaming entry point).
|
|
177
170
|
"""
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
# a text parser (the generic catch-all) explodes the CST — e.g. a PNG
|
|
183
|
-
# producing >100 MB of output that the plugin host then rejects.
|
|
184
|
-
head = text[:8192]
|
|
185
|
-
if not head:
|
|
186
|
-
return False
|
|
187
|
-
if "\x00" in head:
|
|
188
|
-
return True
|
|
189
|
-
return head.count("�") / len(head) > 0.1
|
|
190
|
-
|
|
191
|
-
for source in iter_changed_sources(repo_path, old_ref, new_ref):
|
|
171
|
+
from intentumdiff.content_type import is_text_bytes
|
|
172
|
+
|
|
173
|
+
policy_root = resolve_repo_root(repo_path)
|
|
174
|
+
for source in iter_changed_sources(policy_root, old_ref, new_ref):
|
|
192
175
|
old_content, new_content, old_path, new_path, staging_status = source
|
|
193
176
|
# Backstop: primary content-based routing happens at the git read
|
|
194
|
-
# boundary (magic-byte detection);
|
|
177
|
+
# boundary (magic-byte detection); the same Rust detector catches any
|
|
195
178
|
# binary that reaches the streaming path through another route,
|
|
196
179
|
# before it explodes the text parser.
|
|
197
|
-
if
|
|
180
|
+
if not is_text_bytes(new_content.encode("utf-8")) or not is_text_bytes(old_content.encode("utf-8")):
|
|
198
181
|
logger.debug("Skipping %r — binary/non-text asset", old_path)
|
|
199
182
|
continue
|
|
200
183
|
try:
|
|
201
184
|
file_diff = self._differ._run_pipeline(
|
|
202
|
-
old_content, new_content, old_path, None, new_filename=new_path
|
|
185
|
+
old_content, new_content, old_path, None, new_filename=new_path,
|
|
186
|
+
_policy_old_filename=safe_policy_path(policy_root, old_path),
|
|
187
|
+
_policy_source_filename=safe_policy_path(policy_root, new_path or old_path),
|
|
203
188
|
)
|
|
204
189
|
if staging_status is not None:
|
|
205
190
|
file_diff = file_diff.model_copy(
|
|
@@ -231,8 +216,8 @@ class CommitDiffer:
|
|
|
231
216
|
|
|
232
217
|
def finalize_commit_diff(
|
|
233
218
|
self,
|
|
234
|
-
results: list[FileDiffResult],
|
|
235
|
-
errors: list[FileDiffError],
|
|
219
|
+
results: list[FileDiffResult | FileDiffError],
|
|
220
|
+
errors: list[FileDiffError] | None = None,
|
|
236
221
|
*,
|
|
237
222
|
old_ref: str,
|
|
238
223
|
new_ref: str,
|
|
@@ -241,41 +226,42 @@ class CommitDiffer:
|
|
|
241
226
|
"""
|
|
242
227
|
Build a complete :class:`CommitDiff` from streamed per-file results.
|
|
243
228
|
|
|
244
|
-
|
|
245
|
-
the pre-pass can run), runs cross-file analysis, and assembles the
|
|
229
|
+
Preserves engine-produced file evidence, runs cross-file analysis, and assembles the
|
|
246
230
|
terminal ``CommitDiff``. This is the counterpart to
|
|
247
231
|
:meth:`iter_file_diffs`.
|
|
248
232
|
"""
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
repo_path, old_ref, new_ref
|
|
254
|
-
)
|
|
255
|
-
changed_file_count = len(results) + len(errors)
|
|
233
|
+
successful = [item for item in results if isinstance(item, FileDiffResult)]
|
|
234
|
+
collected_errors = [item for item in results if isinstance(item, FileDiffError)]
|
|
235
|
+
collected_errors.extend(errors or [])
|
|
236
|
+
changed_file_count = len(successful) + len(collected_errors)
|
|
256
237
|
return self._finalize_commit_diff(
|
|
257
|
-
results=
|
|
258
|
-
errors=
|
|
238
|
+
results=successful,
|
|
239
|
+
errors=collected_errors,
|
|
259
240
|
changed_file_count=changed_file_count,
|
|
260
241
|
old_ref=old_ref,
|
|
261
242
|
new_ref=new_ref,
|
|
262
|
-
|
|
263
|
-
gitignore_spec=gitignore_spec,
|
|
243
|
+
allow_partial_errors=True,
|
|
264
244
|
)
|
|
265
245
|
|
|
266
246
|
def _collect_file_diffs(
|
|
267
247
|
self,
|
|
268
248
|
sources: Iterator[tuple[str, str, str, str, object]],
|
|
249
|
+
*,
|
|
250
|
+
policy_root: str | os.PathLike[str],
|
|
251
|
+
policy_path_resolver: Callable[[str], str] | None = None,
|
|
269
252
|
) -> tuple[list[FileDiffResult], list[FileDiffError], int]:
|
|
270
253
|
"""Run the per-file pipeline over an iterator of changed sources."""
|
|
271
254
|
results: list[FileDiffResult] = []
|
|
272
255
|
errors: list[FileDiffError] = []
|
|
273
256
|
changed_file_count = 0
|
|
257
|
+
policy_path = policy_path_resolver or (lambda path: safe_policy_path(policy_root, path))
|
|
274
258
|
for old_content, new_content, old_path, new_path, staging_status in sources:
|
|
275
259
|
changed_file_count += 1
|
|
276
260
|
try:
|
|
277
261
|
file_diff = self._differ._run_pipeline(
|
|
278
|
-
old_content, new_content, old_path, None, new_filename=new_path
|
|
262
|
+
old_content, new_content, old_path, None, new_filename=new_path,
|
|
263
|
+
_policy_old_filename=policy_path(old_path),
|
|
264
|
+
_policy_source_filename=policy_path(new_path or old_path),
|
|
279
265
|
)
|
|
280
266
|
if staging_status is not None:
|
|
281
267
|
file_diff = file_diff.model_copy(
|
|
@@ -320,45 +306,27 @@ class CommitDiffer:
|
|
|
320
306
|
changed_file_count: int,
|
|
321
307
|
old_ref: str,
|
|
322
308
|
new_ref: str,
|
|
323
|
-
|
|
324
|
-
gitignore_spec=None,
|
|
309
|
+
allow_partial_errors: bool = False,
|
|
325
310
|
) -> CommitDiff:
|
|
326
311
|
"""Assemble the terminal CommitDiff from per-file results + errors."""
|
|
327
312
|
file_diffs = [result.file_diff for result in results]
|
|
328
|
-
parse_errors = [
|
|
329
|
-
f"{error.old_path}: {error.reason}"
|
|
330
|
-
for error in errors
|
|
331
|
-
if error.kind == "pipeline_error"
|
|
332
|
-
]
|
|
333
|
-
|
|
334
|
-
self._raise_if_all_parsers_failed(changed_file_count, file_diffs, parse_errors)
|
|
335
|
-
|
|
336
|
-
# Tag diffs whose file deletion was caused by a .gitignore rule addition.
|
|
337
|
-
if gitignore_spec is not None and deleted_paths:
|
|
338
|
-
file_diffs = [
|
|
339
|
-
fd.model_copy(update={"gitignore_excluded": True})
|
|
340
|
-
if fd.old_filename in deleted_paths
|
|
341
|
-
and gitignore_spec.match_file(fd.old_filename)
|
|
342
|
-
else fd
|
|
343
|
-
for fd in file_diffs
|
|
344
|
-
]
|
|
345
|
-
|
|
346
|
-
# Build semantic indexes for changed files only.
|
|
347
|
-
old_file_contents = [
|
|
348
|
-
(result.old_path, result.file_diff.language, result.old_content)
|
|
349
|
-
for result in results
|
|
350
|
-
]
|
|
351
|
-
new_file_contents = [
|
|
352
|
-
(result.new_path, result.file_diff.language, result.new_content)
|
|
353
|
-
for result in results
|
|
354
|
-
]
|
|
355
|
-
cross_file_changes: list[CrossFileChange] = []
|
|
356
|
-
if old_file_contents:
|
|
357
|
-
old_index = self._build_index(old_file_contents)
|
|
358
|
-
new_index = self._build_index(new_file_contents)
|
|
359
|
-
if old_index is not None and new_index is not None:
|
|
360
|
-
cross_file_changes = self._detect_cross_file(old_index, new_index)
|
|
313
|
+
parse_errors = [f"{error.old_path}: {error.reason}" for error in errors]
|
|
361
314
|
|
|
315
|
+
self._raise_if_all_parsers_failed(
|
|
316
|
+
changed_file_count, file_diffs, parse_errors, file_errors=errors
|
|
317
|
+
)
|
|
318
|
+
if errors and not allow_partial_errors:
|
|
319
|
+
details = "; ".join(
|
|
320
|
+
f"{err.old_path}: {err.kind}: {err.reason}" for err in errors
|
|
321
|
+
)
|
|
322
|
+
raise RuntimeError(
|
|
323
|
+
f"Commit diff incomplete ({len(errors)} of {changed_file_count} text files failed): "
|
|
324
|
+
f"{details}"
|
|
325
|
+
)
|
|
326
|
+
# Core owns commit-wide cross-file indexing and its completeness policy (#298):
|
|
327
|
+
# the host only parses each changed file (plugin dispatch) and hands core the
|
|
328
|
+
# trees, or the parse-failure text for a side it could not parse.
|
|
329
|
+
index = commit_cross_file_index([self._index_input(result) for result in results])
|
|
362
330
|
return CommitDiff(
|
|
363
331
|
old_ref=old_ref,
|
|
364
332
|
new_ref=new_ref,
|
|
@@ -368,8 +336,14 @@ class CommitDiffer:
|
|
|
368
336
|
for violation in file_diff.guardrail_violations
|
|
369
337
|
],
|
|
370
338
|
file_diffs=file_diffs,
|
|
371
|
-
cross_file_changes=
|
|
339
|
+
cross_file_changes=[
|
|
340
|
+
cross_file_change_from_core(item) for item in index["cross_file_changes"]
|
|
341
|
+
],
|
|
372
342
|
parse_errors=parse_errors,
|
|
343
|
+
cross_file_index_status=index["cross_file_index_status"],
|
|
344
|
+
cross_file_index_complete=index["cross_file_index_complete"],
|
|
345
|
+
indexed_file_count=index["indexed_file_count"],
|
|
346
|
+
index_errors=index["index_errors"],
|
|
373
347
|
)
|
|
374
348
|
|
|
375
349
|
# ------------------------------------------------------------------
|
|
@@ -382,69 +356,30 @@ class CommitDiffer:
|
|
|
382
356
|
old_ref: str,
|
|
383
357
|
new_ref: str,
|
|
384
358
|
) -> CommitDiff:
|
|
385
|
-
"""
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
for cf in changed_files:
|
|
400
|
-
if cf.is_binary:
|
|
401
|
-
continue
|
|
402
|
-
changed_file_count += 1
|
|
403
|
-
|
|
404
|
-
old_path = cf.old_path or cf.new_path
|
|
405
|
-
new_path = cf.new_path or cf.old_path
|
|
406
|
-
|
|
407
|
-
if old_path is None:
|
|
408
|
-
continue
|
|
409
|
-
|
|
410
|
-
old_content = backend.get_blob(old_path, old_ref) if cf.old_path else ""
|
|
411
|
-
new_content = backend.get_blob(new_path, new_ref) if cf.new_path else "" # type: ignore[arg-type]
|
|
412
|
-
|
|
413
|
-
try:
|
|
414
|
-
file_diff = self._differ._run_pipeline(
|
|
415
|
-
old_content, new_content, old_path, None, new_filename=new_path
|
|
416
|
-
)
|
|
417
|
-
file_diffs.append(file_diff)
|
|
418
|
-
old_file_contents.append((old_path, file_diff.language, old_content))
|
|
419
|
-
new_file_contents.append(
|
|
420
|
-
(new_path or old_path, file_diff.language, new_content)
|
|
421
|
-
)
|
|
422
|
-
except PluginNotFoundError:
|
|
423
|
-
logger.debug("Skipping %r — no parser available", old_path)
|
|
424
|
-
except (PluginError, ValueError, RuntimeError) as exc:
|
|
425
|
-
logger.warning("Failed to diff %r: %s", old_path, exc)
|
|
426
|
-
parse_errors.append(f"{old_path}: {exc}")
|
|
359
|
+
"""Apply the same fail-closed Rust-backed per-file route to every VCS."""
|
|
360
|
+
|
|
361
|
+
def changed_sources() -> Iterator[tuple[str, str, str, str, object]]:
|
|
362
|
+
for changed in backend.list_changed_files(old_ref, new_ref):
|
|
363
|
+
if changed.is_binary:
|
|
364
|
+
continue
|
|
365
|
+
path = changed.old_path or changed.new_path
|
|
366
|
+
if path is None:
|
|
367
|
+
raise ValueError("VCS backend returned a changed text file without a path")
|
|
368
|
+
new_path = changed.new_path or path
|
|
369
|
+
old = backend.get_blob(changed.old_path, old_ref) if changed.old_path else ""
|
|
370
|
+
new = backend.get_blob(changed.new_path, new_ref) if changed.new_path else ""
|
|
371
|
+
yield old, new, path, new_path, None
|
|
427
372
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
return CommitDiff(
|
|
373
|
+
results, errors, changed_file_count = self._collect_file_diffs(
|
|
374
|
+
changed_sources(), policy_root=backend.resolve_root(),
|
|
375
|
+
policy_path_resolver=backend.guardrail_policy_path,
|
|
376
|
+
)
|
|
377
|
+
return self._finalize_commit_diff(
|
|
378
|
+
results=results,
|
|
379
|
+
errors=errors,
|
|
380
|
+
changed_file_count=changed_file_count,
|
|
438
381
|
old_ref=old_ref,
|
|
439
382
|
new_ref=new_ref,
|
|
440
|
-
guardrail_violations=[
|
|
441
|
-
violation
|
|
442
|
-
for file_diff in file_diffs
|
|
443
|
-
for violation in file_diff.guardrail_violations
|
|
444
|
-
],
|
|
445
|
-
file_diffs=file_diffs,
|
|
446
|
-
cross_file_changes=cross_file_changes,
|
|
447
|
-
parse_errors=parse_errors,
|
|
448
383
|
)
|
|
449
384
|
|
|
450
385
|
def _raise_if_all_parsers_failed(
|
|
@@ -452,9 +387,11 @@ class CommitDiffer:
|
|
|
452
387
|
changed_file_count: int,
|
|
453
388
|
file_diffs: list,
|
|
454
389
|
parse_errors: list[str],
|
|
390
|
+
*,
|
|
391
|
+
file_errors: list[FileDiffError] | None = None,
|
|
455
392
|
) -> None:
|
|
456
393
|
"""Fail loudly when changed files exist but no parser plugin loaded."""
|
|
457
|
-
if changed_file_count <= 0 or file_diffs
|
|
394
|
+
if changed_file_count <= 0 or file_diffs:
|
|
458
395
|
return
|
|
459
396
|
summary_fn = getattr(self._differ._registry, "parser_load_failure_summary", None)
|
|
460
397
|
if not callable(summary_fn):
|
|
@@ -462,138 +399,52 @@ class CommitDiffer:
|
|
|
462
399
|
summary = summary_fn()
|
|
463
400
|
if summary:
|
|
464
401
|
raise RuntimeError(summary)
|
|
402
|
+
# Preserve concrete failing paths when the registry cannot supply a richer
|
|
403
|
+
# parser-load diagnostic. A generic error hides the failed file and masks
|
|
404
|
+
# actionable evidence from the fail-closed commit boundary.
|
|
405
|
+
details = (
|
|
406
|
+
": " + "; ".join(f"{error.old_path}: {error.reason}" for error in file_errors)
|
|
407
|
+
if file_errors else ""
|
|
408
|
+
)
|
|
409
|
+
raise RuntimeError(
|
|
410
|
+
"Commit diff incomplete: no parser succeeded for changed text files" + details
|
|
411
|
+
)
|
|
465
412
|
|
|
466
|
-
def
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
# Capture the new .gitignore content for root or subdir gitignore files.
|
|
506
|
-
if code[:1] in ("A", "M") and (
|
|
507
|
-
b_path == ".gitignore" or b_path.endswith("/.gitignore")
|
|
508
|
-
):
|
|
509
|
-
raw: str | None = None
|
|
510
|
-
if new_ref: # commit-to-commit: read the new blob
|
|
511
|
-
try:
|
|
512
|
-
raw = run_git_bytes(
|
|
513
|
-
root, ["cat-file", "blob", f"{new_ref}:{b_path}"]
|
|
514
|
-
).decode("utf-8", errors="replace")
|
|
515
|
-
except subprocess.CalledProcessError:
|
|
516
|
-
raw = None
|
|
517
|
-
else: # working-tree mode: read from disk
|
|
518
|
-
from pathlib import Path as _Path
|
|
519
|
-
disk_gi = _Path(root) / b_path
|
|
520
|
-
if disk_gi.exists():
|
|
521
|
-
try:
|
|
522
|
-
raw = disk_gi.read_text(encoding="utf-8", errors="replace")
|
|
523
|
-
except OSError:
|
|
524
|
-
pass
|
|
525
|
-
if raw is not None:
|
|
526
|
-
try:
|
|
527
|
-
import pathspec as _pathspec # lazy import
|
|
528
|
-
# For subdirectory gitignore files (e.g. src/.gitignore),
|
|
529
|
-
# prepend the directory so patterns are matched against
|
|
530
|
-
# full repo-relative paths.
|
|
531
|
-
gitignore_dir = b_path[: -len(".gitignore")].rstrip("/")
|
|
532
|
-
if gitignore_dir:
|
|
533
|
-
lines = [
|
|
534
|
-
f"{gitignore_dir}/{ln}" if ln and not ln.startswith("#")
|
|
535
|
-
else ln
|
|
536
|
-
for ln in raw.splitlines()
|
|
537
|
-
]
|
|
538
|
-
else:
|
|
539
|
-
lines = raw.splitlines()
|
|
540
|
-
gitignore_spec = _pathspec.PathSpec.from_lines("gitignore", lines)
|
|
541
|
-
except Exception as exc: # pragma: no cover
|
|
542
|
-
logger.debug("Failed to parse .gitignore blob: %s", exc)
|
|
543
|
-
except Exception as exc:
|
|
544
|
-
logger.debug("gitignore pre-pass failed: %s", exc)
|
|
545
|
-
return deleted_paths, gitignore_spec
|
|
546
|
-
|
|
547
|
-
def _build_index(
|
|
548
|
-
self, file_contents: list[tuple[str, str, str]]
|
|
549
|
-
) -> SemanticIndex | None:
|
|
550
|
-
"""
|
|
551
|
-
Build a ``SemanticIndex`` from a list of (filename, language, content)
|
|
552
|
-
triples.
|
|
553
|
-
|
|
554
|
-
The symbol/reference tables are built by the Rust core
|
|
555
|
-
(index-engine-lib) inside ``SemanticIndex.build()``. Returns ``None`` if
|
|
556
|
-
no files could be parsed.
|
|
557
|
-
"""
|
|
558
|
-
index = SemanticIndex()
|
|
559
|
-
for filename, language, content in file_contents:
|
|
560
|
-
try:
|
|
561
|
-
tree = self._parse_to_tree(filename, language, content)
|
|
562
|
-
if tree is not None:
|
|
563
|
-
index.add_tree(filename, language, tree)
|
|
564
|
-
except Exception as exc:
|
|
565
|
-
logger.debug("Could not parse %r for index: %s", filename, exc)
|
|
566
|
-
|
|
567
|
-
if not index._files: # type: ignore[attr-defined] # pylint: disable=protected-access
|
|
568
|
-
return None
|
|
569
|
-
|
|
570
|
-
index.build()
|
|
571
|
-
return index
|
|
572
|
-
|
|
573
|
-
def _detect_cross_file(
|
|
574
|
-
self, old_index: SemanticIndex, new_index: SemanticIndex
|
|
575
|
-
) -> list[CrossFileChange]:
|
|
576
|
-
"""Detect cross-file changes between two indexes via the Rust core."""
|
|
577
|
-
return detect_cross_file_changes(old_index, new_index)
|
|
578
|
-
|
|
579
|
-
def _parse_to_tree(
|
|
580
|
-
self, filename: str, language: str, content: str
|
|
581
|
-
) -> "SemanticNode | None":
|
|
582
|
-
"""
|
|
583
|
-
Parse *content* to a SemanticNode tree.
|
|
584
|
-
|
|
585
|
-
Re-uses the ``SemanticDiffer`` parser pipeline so both FullParse and
|
|
586
|
-
host-CST parser plugins can participate in commit-wide symbol indexing.
|
|
587
|
-
"""
|
|
588
|
-
try:
|
|
589
|
-
tree, _language = self._differ.parse(
|
|
590
|
-
content,
|
|
591
|
-
filename,
|
|
592
|
-
language_hint=language,
|
|
593
|
-
)
|
|
594
|
-
return tree
|
|
595
|
-
except PluginNotFoundError:
|
|
596
|
-
return None
|
|
597
|
-
except Exception as exc:
|
|
598
|
-
logger.debug("parse_to_tree failed for %r: %s", filename, exc)
|
|
599
|
-
return None
|
|
413
|
+
def _index_input(self, result: FileDiffResult) -> dict[str, object]:
|
|
414
|
+
"""Marshal one changed file for core's ``commit_cross_file_index``."""
|
|
415
|
+
language = result.file_diff.language
|
|
416
|
+
entry: dict[str, object] = {
|
|
417
|
+
"old_filename": result.old_path,
|
|
418
|
+
"new_filename": result.new_path,
|
|
419
|
+
"language": language,
|
|
420
|
+
}
|
|
421
|
+
for side, filename, content in (
|
|
422
|
+
("old", result.old_path, result.old_content),
|
|
423
|
+
("new", result.new_path, result.new_content),
|
|
424
|
+
):
|
|
425
|
+
tree, error = None, None
|
|
426
|
+
if content:
|
|
427
|
+
try:
|
|
428
|
+
tree = self._parse_to_tree(filename, language, content).model_dump(
|
|
429
|
+
mode="json"
|
|
430
|
+
)
|
|
431
|
+
except PluginNotFoundError as exc:
|
|
432
|
+
# A missing parser component is not a per-file index failure (core #298).
|
|
433
|
+
raise RuntimeError(
|
|
434
|
+
f"Commit semantic index unavailable for {filename!r}: {exc}"
|
|
435
|
+
) from exc
|
|
436
|
+
except (PluginError, ValueError, RuntimeError) as exc:
|
|
437
|
+
# Transport the parse failure; core decides how it affects the index.
|
|
438
|
+
error = str(exc) or type(exc).__name__
|
|
439
|
+
entry[f"{side}_tree"] = tree
|
|
440
|
+
entry[f"{side}_error"] = error
|
|
441
|
+
return entry
|
|
442
|
+
|
|
443
|
+
def _parse_to_tree(self, filename: str, language: str, content: str) -> "SemanticNode":
|
|
444
|
+
"""Parse *content* with the ``SemanticDiffer`` FullParse parser pipeline."""
|
|
445
|
+
tree, _language = self._differ.parse(
|
|
446
|
+
content,
|
|
447
|
+
filename,
|
|
448
|
+
language_hint=language,
|
|
449
|
+
)
|
|
450
|
+
return tree
|
intentumdiff/core/diffignore.py
CHANGED
|
@@ -26,14 +26,9 @@ Examples::
|
|
|
26
26
|
|
|
27
27
|
from __future__ import annotations
|
|
28
28
|
|
|
29
|
-
import logging
|
|
30
29
|
from pathlib import Path
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
logger = logging.getLogger(__name__)
|
|
34
|
-
|
|
35
|
-
if TYPE_CHECKING:
|
|
36
|
-
import pathspec
|
|
30
|
+
import json
|
|
31
|
+
from collections.abc import Mapping
|
|
37
32
|
|
|
38
33
|
#: Conventional filename — place in the repo / directory root.
|
|
39
34
|
DIFFIGNORE_FILENAME = ".diffignore"
|
|
@@ -44,44 +39,43 @@ def load_diffignore(root: str | Path) -> "DiffIgnore | None":
|
|
|
44
39
|
Look for a ``.diffignore`` file in *root* and return a :class:`DiffIgnore`
|
|
45
40
|
instance if found, or ``None`` when the file does not exist.
|
|
46
41
|
|
|
47
|
-
A
|
|
42
|
+
A configured policy that cannot be read must fail closed; only a missing
|
|
43
|
+
policy is treated as no exclusions.
|
|
48
44
|
"""
|
|
49
45
|
path = Path(root) / DIFFIGNORE_FILENAME
|
|
50
|
-
if not path.is_file():
|
|
51
|
-
return None
|
|
52
|
-
|
|
53
46
|
try:
|
|
54
47
|
text = path.read_text(encoding="utf-8")
|
|
55
|
-
except
|
|
56
|
-
|
|
48
|
+
except FileNotFoundError as exc:
|
|
49
|
+
# A broken symlink is an explicitly configured but unusable policy,
|
|
50
|
+
# not evidence that no policy exists.
|
|
51
|
+
if path.is_symlink():
|
|
52
|
+
raise RuntimeError(f"Could not read configured .diffignore {path}: {exc}") from exc
|
|
57
53
|
return None
|
|
54
|
+
except (OSError, UnicodeError) as exc:
|
|
55
|
+
raise RuntimeError(f"Could not read configured .diffignore {path}: {exc}") from exc
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
spec = pathspec.PathSpec.from_lines("gitignore", text.splitlines())
|
|
62
|
-
logger.debug("Loaded .diffignore from %s (%d pattern(s))", path, len(spec.patterns))
|
|
63
|
-
return DiffIgnore(spec)
|
|
57
|
+
return DiffIgnore(text)
|
|
64
58
|
|
|
65
59
|
|
|
66
60
|
class DiffIgnore:
|
|
67
|
-
"""
|
|
68
|
-
Wraps a ``pathspec.PathSpec`` to test whether relative file paths should
|
|
69
|
-
be excluded from the diff / index pipeline.
|
|
61
|
+
"""Thin adapter over Rust ignore rules; construct with raw file contents."""
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
only in tests.
|
|
73
|
-
"""
|
|
63
|
+
__slots__ = ("_files",)
|
|
74
64
|
|
|
75
|
-
|
|
65
|
+
def __init__(self, patterns: str = "", *, directory_rules: Mapping[str, str] | None = None) -> None:
|
|
66
|
+
if not isinstance(patterns, str):
|
|
67
|
+
raise TypeError("DiffIgnore requires raw ignore-file text")
|
|
68
|
+
self._files = [{"directory": "", "content": patterns}]
|
|
69
|
+
self._files.extend({"directory": directory, "content": content} for directory, content in (directory_rules or {}).items())
|
|
70
|
+
self._matches([]) # validate rules through the engine eagerly
|
|
76
71
|
|
|
77
|
-
def
|
|
78
|
-
|
|
72
|
+
def _matches(self, paths: list[dict]) -> list[bool]:
|
|
73
|
+
from intentumdiff.rust_core import _required_engine_json
|
|
74
|
+
result = _required_engine_json("match_ignore_rules", json.dumps({"files": self._files, "paths": paths}), result_type=list)
|
|
75
|
+
if len(result) != len(paths) or any(type(value) is not bool for value in result):
|
|
76
|
+
raise RuntimeError("Rust ignore result has invalid fields")
|
|
77
|
+
return result
|
|
79
78
|
|
|
80
79
|
def is_ignored(self, rel_path: str) -> bool:
|
|
81
|
-
"""
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*rel_path* must use **forward slashes** (POSIX style), e.g.
|
|
85
|
-
``"src/generated/foo.py"`` — not ``"src\\generated\\foo.py"``.
|
|
86
|
-
"""
|
|
87
|
-
return bool(self._spec.match_file(rel_path))
|
|
80
|
+
"""Test a repository-relative POSIX file path using Rust semantics."""
|
|
81
|
+
return self._matches([{"path": rel_path}])[0]
|