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.
Files changed (150) hide show
  1. intentumdiff/__init__.py +9 -0
  2. intentumdiff/__main__.py +12 -0
  3. intentumdiff/_differ_gate.py +0 -136
  4. intentumdiff/_differ_presentation.py +17 -735
  5. intentumdiff/_differ_runtime.py +13 -64
  6. intentumdiff/analysis/compile_commands.py +26 -141
  7. intentumdiff/analysis/cross_file.py +23 -25
  8. intentumdiff/analysis/diagnostics.py +1 -164
  9. intentumdiff/analysis/guardrail_reports.py +31 -33
  10. intentumdiff/analysis/guardrails.py +111 -188
  11. intentumdiff/analysis/schema_resolver.py +72 -360
  12. intentumdiff/analysis/user_schemas.py +57 -254
  13. intentumdiff/api.py +21 -0
  14. intentumdiff/cache/sqlite_store.py +5 -23
  15. intentumdiff/cli/__init__.py +59 -0
  16. intentumdiff/cli/_commands.py +243 -137
  17. intentumdiff/cli/_parser.py +51 -56
  18. intentumdiff/cli/_shared.py +151 -116
  19. intentumdiff/content_type.py +13 -30
  20. intentumdiff/core/commit_differ.py +137 -286
  21. intentumdiff/core/diffignore.py +28 -34
  22. intentumdiff/core/index.py +16 -18
  23. intentumdiff/core/indexer.py +148 -169
  24. intentumdiff/core/models.py +279 -83
  25. intentumdiff/differ.py +366 -1000
  26. intentumdiff/github_app.py +40 -27
  27. intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
  28. intentumdiff/live_server.py +197 -34
  29. intentumdiff/lsp/client.py +49 -43
  30. intentumdiff/lsp/enricher.py +19 -119
  31. intentumdiff/lsp/exceptions.py +6 -7
  32. intentumdiff/lsp/servers.py +10 -11
  33. intentumdiff/lsp_server/_codelens.py +24 -57
  34. intentumdiff/lsp_server/_diagnostics.py +23 -51
  35. intentumdiff/lsp_server/_handlers.py +67 -9
  36. intentumdiff/lsp_server/server.py +28 -8
  37. intentumdiff/plugins/adapter.py +5 -0
  38. intentumdiff/plugins/builtins.py +7 -14
  39. intentumdiff/plugins/exceptions.py +28 -0
  40. intentumdiff/plugins/hub.py +39 -43
  41. intentumdiff/plugins/loader.py +229 -215
  42. intentumdiff/plugins/registry.py +259 -207
  43. intentumdiff/plugins/registry.schema.json +156 -15
  44. intentumdiff/plugins/registry_schema.py +47 -140
  45. intentumdiff/rust_core.py +623 -1326
  46. intentumdiff/serve/_app.py +26 -35
  47. intentumdiff/sources/base.py +24 -0
  48. intentumdiff/sources/file_source.py +15 -2
  49. intentumdiff/sources/git_source.py +64 -185
  50. intentumdiff/sources/live_buffer_source.py +45 -5
  51. intentumdiff/sources/patch_source.py +36 -109
  52. intentumdiff/vcs/_safe_path.py +7 -0
  53. intentumdiff/vcs/base.py +6 -0
  54. intentumdiff/vcs/git_backend.py +1 -1
  55. intentumdiff/vcs/git_cli.py +0 -27
  56. intentumdiff/vcs/hg_backend.py +1 -1
  57. intentumdiff/vcs/perforce_backend.py +7 -1
  58. intentumdiff/vcs/svn_backend.py +1 -1
  59. intentumdiff/wasm/abap_parser.wasm +0 -0
  60. intentumdiff/wasm/adf_parser.wasm +0 -0
  61. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  62. intentumdiff/wasm/asm_parser.wasm +0 -0
  63. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  64. intentumdiff/wasm/astro_parser.wasm +0 -0
  65. intentumdiff/wasm/bash_parser.wasm +0 -0
  66. intentumdiff/wasm/clojure_parser.wasm +0 -0
  67. intentumdiff/wasm/cmake_parser.wasm +0 -0
  68. intentumdiff/wasm/cpp_parser.wasm +0 -0
  69. intentumdiff/wasm/csharp_parser.wasm +0 -0
  70. intentumdiff/wasm/css_parser.wasm +0 -0
  71. intentumdiff/wasm/dart_parser.wasm +0 -0
  72. intentumdiff/wasm/databricks_parser.wasm +0 -0
  73. intentumdiff/wasm/dax_parser.wasm +0 -0
  74. intentumdiff/wasm/delphi_parser.wasm +0 -0
  75. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  76. intentumdiff/wasm/elixir_parser.wasm +0 -0
  77. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  78. intentumdiff/wasm/generic_parser.wasm +0 -0
  79. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  80. intentumdiff/wasm/go_parser.wasm +0 -0
  81. intentumdiff/wasm/gomod_parser.wasm +0 -0
  82. intentumdiff/wasm/graphql_parser.wasm +0 -0
  83. intentumdiff/wasm/groovy_parser.wasm +0 -0
  84. intentumdiff/wasm/haskell_parser.wasm +0 -0
  85. intentumdiff/wasm/html_parser.wasm +0 -0
  86. intentumdiff/wasm/html_renderer.wasm +0 -0
  87. intentumdiff/wasm/ini_parser.wasm +0 -0
  88. intentumdiff/wasm/java_parser.wasm +0 -0
  89. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  90. intentumdiff/wasm/json_parser.wasm +0 -0
  91. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  92. intentumdiff/wasm/latex_parser.wasm +0 -0
  93. intentumdiff/wasm/llm_renderer.wasm +0 -0
  94. intentumdiff/wasm/lua_parser.wasm +0 -0
  95. intentumdiff/wasm/make_parser.wasm +0 -0
  96. intentumdiff/wasm/markdown_parser.wasm +0 -0
  97. intentumdiff/wasm/mdx_parser.wasm +0 -0
  98. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  99. intentumdiff/wasm/odin_parser.wasm +0 -0
  100. intentumdiff/wasm/parser_manifest.json +81 -2
  101. intentumdiff/wasm/patch_renderer.wasm +0 -0
  102. intentumdiff/wasm/perl_parser.wasm +0 -0
  103. intentumdiff/wasm/php_parser.wasm +0 -0
  104. intentumdiff/wasm/plsql_parser.wasm +0 -0
  105. intentumdiff/wasm/po_parser.wasm +0 -0
  106. intentumdiff/wasm/postscript_parser.wasm +0 -0
  107. intentumdiff/wasm/powershell_parser.wasm +0 -0
  108. intentumdiff/wasm/proto_parser.wasm +0 -0
  109. intentumdiff/wasm/puppet_parser.wasm +0 -0
  110. intentumdiff/wasm/python_parser.wasm +0 -0
  111. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  112. intentumdiff/wasm/r_parser.wasm +0 -0
  113. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  114. intentumdiff/wasm/ruby_parser.wasm +0 -0
  115. intentumdiff/wasm/rust_parser.wasm +0 -0
  116. intentumdiff/wasm/sas_parser.wasm +0 -0
  117. intentumdiff/wasm/scala_parser.wasm +0 -0
  118. intentumdiff/wasm/scss_parser.wasm +0 -0
  119. intentumdiff/wasm/sql_parser.wasm +0 -0
  120. intentumdiff/wasm/squirrel_parser.wasm +0 -0
  121. intentumdiff/wasm/svelte_parser.wasm +0 -0
  122. intentumdiff/wasm/swift_parser.wasm +0 -0
  123. intentumdiff/wasm/terminal_renderer.wasm +0 -0
  124. intentumdiff/wasm/terraform_parser.wasm +0 -0
  125. intentumdiff/wasm/toml_parser.wasm +0 -0
  126. intentumdiff/wasm/tsql_parser.wasm +0 -0
  127. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  128. intentumdiff/wasm/vue_parser.wasm +0 -0
  129. intentumdiff/wasm/wasm_provenance.json +884 -0
  130. intentumdiff/wasm/wat_parser.wasm +0 -0
  131. intentumdiff/wasm/xml_parser.wasm +0 -0
  132. intentumdiff/wasm/yaml_parser.wasm +0 -0
  133. intentumdiff/wasm/zig_parser.wasm +0 -0
  134. intentumdiff/watcher.py +15 -17
  135. intentumdiff_python-0.0.3b1.dist-info/METADATA +188 -0
  136. intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
  137. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +1 -1
  138. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
  139. intentumdiff/analysis/invariances.py +0 -1207
  140. intentumdiff/analysis/keyed_profiles.py +0 -25
  141. intentumdiff/analysis/resource_profiles.py +0 -14
  142. intentumdiff/analysis/text_review.py +0 -46
  143. intentumdiff/core/cst_serializer.py +0 -101
  144. intentumdiff/invariances/__init__.py +0 -2
  145. intentumdiff/invariances/rules.schema.json +0 -283
  146. intentumdiff/invariances/rules.yaml +0 -349
  147. intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
  148. intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
  149. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/entry_points.txt +0 -0
  150. {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 to build two ``SemanticIndex`` objects.
14
- 3. Calls ``detect_cross_file_changes()`` (Rust core) to detect
15
- ``MOVE_TO_MODULE`` / ``SPLIT_MODULE`` / ``CROSS_FILE_RENAME`` changes.
16
- 4. Returns a ``CommitDiff`` with both the per-file diffs and the cross-file
17
- changes.
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, CrossFileChange, DiffConfig, SemanticDiff
41
+ from intentumdiff.core.models import CommitDiff, DiffConfig, SemanticDiff
42
42
  from intentumdiff.differ import SemanticDiffer
43
- from intentumdiff.analysis.cross_file import detect_cross_file_changes
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
- Performs the gitignore pre-pass (so deletions are classifiable) and
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
- def _looks_binary(text: str) -> bool:
179
- # Content is decoded with errors="replace"; a NUL byte (valid UTF-8
180
- # U+0000) survives and reliably marks binary/image assets, as does a
181
- # high ratio of U+FFFD replacement characters. Feeding such content to
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); this NUL-byte check catches any
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 _looks_binary(new_content) or _looks_binary(old_content):
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
- Applies the gitignore-deletion tagging (when *repo_path* is supplied so
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
- deleted_paths: set[str] = set()
250
- gitignore_spec = None
251
- if repo_path is not None:
252
- deleted_paths, gitignore_spec = self._collect_gitignore_state(
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=results,
258
- errors=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
- deleted_paths=deleted_paths,
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
- deleted_paths: set[str] | None = None,
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=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
- Run a full semantic diff using an arbitrary :class:`VcsBackend`.
387
-
388
- Called by :meth:`diff_commit` when a *backend* is provided. The
389
- gitignore pre-pass is skipped because it is git-specific.
390
- """
391
- changed_files = backend.list_changed_files(old_ref, new_ref)
392
-
393
- file_diffs = []
394
- parse_errors: list[str] = []
395
- old_file_contents: list[tuple[str, str, str]] = []
396
- new_file_contents: list[tuple[str, str, str]] = []
397
- changed_file_count = 0
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
- self._raise_if_all_parsers_failed(changed_file_count, file_diffs, parse_errors)
429
-
430
- cross_file_changes: list[CrossFileChange] = []
431
- if old_file_contents:
432
- old_index = self._build_index(old_file_contents)
433
- new_index = self._build_index(new_file_contents)
434
- if old_index is not None and new_index is not None:
435
- cross_file_changes = self._detect_cross_file(old_index, new_index)
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 or parse_errors:
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 _collect_gitignore_state(
467
- self,
468
- repo_path: "str | os.PathLike[str]",
469
- old_ref: str,
470
- new_ref: str,
471
- ) -> "tuple[set[str], object]":
472
- """
473
- Lightweight pre-scan of the commit diff.
474
-
475
- Returns a 2-tuple ``(deleted_paths, gitignore_spec)``:
476
-
477
- * ``deleted_paths`` — set of file paths that git marks as deleted (change
478
- type ``"D"``). Used later to distinguish genuine deletions from files
479
- evicted by a ``.gitignore`` rule change.
480
- * ``gitignore_spec`` — a compiled ``pathspec.PathSpec`` built from the
481
- *new* content of any ``.gitignore`` file modified in this commit, or
482
- ``None`` when no ``.gitignore`` changed. Only root-level and
483
- subdirectory ``.gitignore`` files that appear in the commit diff are
484
- considered; ``.git/info/exclude`` is outside the commit tree and is
485
- therefore ignored.
486
- """
487
- deleted_paths: set[str] = set()
488
- gitignore_spec = None
489
- try:
490
- import subprocess
491
-
492
- from intentumdiff.sources.git_source import _parse_name_status_z
493
- from intentumdiff.vcs.git_cli import resolve_repo_root, run_git_bytes
494
-
495
- root = resolve_repo_root(repo_path)
496
- # old -> new (or old -> working tree when new_ref is ""); a=old, b=new,
497
- # matching the former old_commit.diff(None|new_commit).
498
- args = ["diff", "--name-status", "-z", old_ref]
499
- if new_ref:
500
- args.append(new_ref)
501
- for code, a_path, b_path in _parse_name_status_z(run_git_bytes(root, args)):
502
- if code[:1] == "D":
503
- deleted_paths.add(a_path)
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
@@ -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
- from typing import TYPE_CHECKING
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 warning is logged (but not raised) if the file exists but cannot be read.
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 OSError as exc:
56
- logger.warning("Could not read %s: %s", path, exc)
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
- import pathspec # lazy — keep import-time fast when diffignore is absent
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
- Instances are created by :func:`load_diffignore`; construct one directly
72
- only in tests.
73
- """
63
+ __slots__ = ("_files",)
74
64
 
75
- __slots__ = ("_spec",)
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 __init__(self, spec: "pathspec.PathSpec") -> None:
78
- self._spec = spec
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
- Return ``True`` if *rel_path* is matched by any pattern in the file.
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]