intentumdiff-python 0.0.2b2__py3-none-win_arm64.whl → 0.0.3b1__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.
Files changed (92) hide show
  1. intentumdiff/__init__.py +7 -0
  2. intentumdiff/_differ_gate.py +0 -136
  3. intentumdiff/_differ_presentation.py +1 -72
  4. intentumdiff/_differ_runtime.py +0 -17
  5. intentumdiff/analysis/cross_file.py +21 -21
  6. intentumdiff/analysis/diagnostics.py +1 -164
  7. intentumdiff/analysis/guardrail_reports.py +24 -28
  8. intentumdiff/analysis/guardrails.py +2 -67
  9. intentumdiff/analysis/schema_resolver.py +23 -87
  10. intentumdiff/analysis/user_schemas.py +2 -17
  11. intentumdiff/cli/_commands.py +70 -71
  12. intentumdiff/cli/_parser.py +40 -55
  13. intentumdiff/cli/_shared.py +55 -4
  14. intentumdiff/core/commit_differ.py +65 -99
  15. intentumdiff/core/indexer.py +0 -1
  16. intentumdiff/core/models.py +226 -69
  17. intentumdiff/differ.py +125 -432
  18. intentumdiff/github_app.py +5 -8
  19. intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
  20. intentumdiff/live_server.py +17 -17
  21. intentumdiff/lsp/client.py +42 -42
  22. intentumdiff/lsp/servers.py +10 -11
  23. intentumdiff/lsp_server/_handlers.py +1 -1
  24. intentumdiff/lsp_server/server.py +0 -1
  25. intentumdiff/plugins/exceptions.py +24 -0
  26. intentumdiff/plugins/hub.py +38 -41
  27. intentumdiff/plugins/registry.py +10 -10
  28. intentumdiff/plugins/registry.schema.json +156 -15
  29. intentumdiff/plugins/registry_schema.py +47 -140
  30. intentumdiff/rust_core.py +112 -775
  31. intentumdiff/serve/_app.py +23 -25
  32. intentumdiff/sources/git_source.py +0 -183
  33. intentumdiff/vcs/git_cli.py +0 -47
  34. intentumdiff/wasm/abap_parser.wasm +0 -0
  35. intentumdiff/wasm/adf_parser.wasm +0 -0
  36. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  37. intentumdiff/wasm/asm_parser.wasm +0 -0
  38. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  39. intentumdiff/wasm/astro_parser.wasm +0 -0
  40. intentumdiff/wasm/bash_parser.wasm +0 -0
  41. intentumdiff/wasm/cpp_parser.wasm +0 -0
  42. intentumdiff/wasm/csharp_parser.wasm +0 -0
  43. intentumdiff/wasm/databricks_parser.wasm +0 -0
  44. intentumdiff/wasm/dax_parser.wasm +0 -0
  45. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  46. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  47. intentumdiff/wasm/generic_parser.wasm +0 -0
  48. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  49. intentumdiff/wasm/graphql_parser.wasm +0 -0
  50. intentumdiff/wasm/groovy_parser.wasm +0 -0
  51. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  52. intentumdiff/wasm/json_parser.wasm +0 -0
  53. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  54. intentumdiff/wasm/latex_parser.wasm +0 -0
  55. intentumdiff/wasm/make_parser.wasm +0 -0
  56. intentumdiff/wasm/mdx_parser.wasm +0 -0
  57. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  58. intentumdiff/wasm/odin_parser.wasm +0 -0
  59. intentumdiff/wasm/perl_parser.wasm +0 -0
  60. intentumdiff/wasm/php_parser.wasm +0 -0
  61. intentumdiff/wasm/plsql_parser.wasm +0 -0
  62. intentumdiff/wasm/postscript_parser.wasm +0 -0
  63. intentumdiff/wasm/powershell_parser.wasm +0 -0
  64. intentumdiff/wasm/python_parser.wasm +0 -0
  65. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  66. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  67. intentumdiff/wasm/rust_parser.wasm +0 -0
  68. intentumdiff/wasm/sas_parser.wasm +0 -0
  69. intentumdiff/wasm/sql_parser.wasm +0 -0
  70. intentumdiff/wasm/svelte_parser.wasm +0 -0
  71. intentumdiff/wasm/swift_parser.wasm +0 -0
  72. intentumdiff/wasm/tsql_parser.wasm +0 -0
  73. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  74. intentumdiff/wasm/vue_parser.wasm +0 -0
  75. intentumdiff/wasm/wasm_provenance.json +219 -219
  76. intentumdiff/wasm/wat_parser.wasm +0 -0
  77. intentumdiff/wasm/yaml_parser.wasm +0 -0
  78. intentumdiff/watcher.py +15 -17
  79. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/METADATA +38 -6
  80. intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
  81. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +2 -2
  82. intentumdiff/analysis/invariances.py +0 -208
  83. intentumdiff/analysis/keyed_profiles.py +0 -25
  84. intentumdiff/analysis/resource_profiles.py +0 -14
  85. intentumdiff/analysis/text_review.py +0 -47
  86. intentumdiff/invariances/__init__.py +0 -2
  87. intentumdiff/invariances/rules.schema.json +0 -283
  88. intentumdiff/invariances/rules.yaml +0 -349
  89. intentumdiff_python-0.0.2b2.dist-info/RECORD +0 -171
  90. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +0 -0
  91. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/entry_points.txt +0 -0
  92. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
intentumdiff/differ.py CHANGED
@@ -40,9 +40,6 @@ from pydantic import ValidationError
40
40
  from intentumdiff._differ_gate import (
41
41
  RUST_CERTIFIED_LANGUAGES as RUST_CERTIFIED_LANGUAGES,
42
42
  )
43
- from intentumdiff._differ_gate import (
44
- RUST_FINALIZE_LANGUAGES as RUST_FINALIZE_LANGUAGES,
45
- )
46
43
  from intentumdiff._differ_gate import (
47
44
  STRICT_RUST_GATE_ENV as STRICT_RUST_GATE_ENV,
48
45
  )
@@ -55,18 +52,9 @@ from intentumdiff._differ_gate import (
55
52
  from intentumdiff._differ_gate import (
56
53
  _rust_certified_languages as _rust_certified_languages,
57
54
  )
58
- from intentumdiff._differ_gate import (
59
- _rust_finalize_languages as _rust_finalize_languages,
60
- )
61
- from intentumdiff._differ_gate import (
62
- _strict_rust_only_enabled as _strict_rust_only_enabled,
63
- )
64
55
  from intentumdiff._differ_gate import (
65
56
  _validate_git_ref as _validate_git_ref,
66
57
  )
67
- from intentumdiff._differ_presentation import (
68
- _count_cst_nodes as _count_cst_nodes,
69
- )
70
58
  from intentumdiff._differ_presentation import (
71
59
  _count_semantic_nodes as _count_semantic_nodes,
72
60
  )
@@ -79,39 +67,15 @@ from intentumdiff._differ_presentation import (
79
67
  from intentumdiff._differ_presentation import (
80
68
  _has_error_node as _has_error_node,
81
69
  )
82
- from intentumdiff._differ_presentation import (
83
- _markdown_section_heading_rename_presentation as _markdown_section_heading_rename_presentation,
84
- )
85
- from intentumdiff._differ_presentation import (
86
- _markdown_section_move_presentation as _markdown_section_move_presentation,
87
- )
88
- from intentumdiff._differ_presentation import (
89
- _node_to_dict as _node_to_dict,
90
- )
91
- from intentumdiff._differ_presentation import (
92
- _root_structural_hash as _root_structural_hash,
93
- )
94
70
  from intentumdiff._differ_presentation import (
95
71
  _token_fallback_diff as _token_fallback_diff,
96
72
  )
97
73
  from intentumdiff._differ_presentation import (
98
74
  _validate_tree_ids as _validate_tree_ids,
99
75
  )
100
- from intentumdiff._differ_runtime import (
101
- _DEFAULT_PLUGIN_FUEL as _DEFAULT_PLUGIN_FUEL,
102
- )
103
- from intentumdiff._differ_runtime import (
104
- _EXPLICIT_FUEL_EXHAUSTION_TEST_CAP as _EXPLICIT_FUEL_EXHAUSTION_TEST_CAP,
105
- )
106
76
  from intentumdiff._differ_runtime import (
107
77
  _FUEL_HOTSPOT_ABSOLUTE as _FUEL_HOTSPOT_ABSOLUTE,
108
78
  )
109
- from intentumdiff._differ_runtime import (
110
- _FUEL_HOTSPOT_PER_KB as _FUEL_HOTSPOT_PER_KB,
111
- )
112
- from intentumdiff._differ_runtime import (
113
- _FUEL_HOTSPOT_PER_LINE as _FUEL_HOTSPOT_PER_LINE,
114
- )
115
79
  from intentumdiff._differ_runtime import (
116
80
  _apply_file_lifecycle_to_diff as _apply_file_lifecycle_to_diff,
117
81
  )
@@ -124,12 +88,6 @@ from intentumdiff._differ_runtime import (
124
88
  from intentumdiff._differ_runtime import (
125
89
  _drain_plugin_telemetry as _drain_plugin_telemetry,
126
90
  )
127
- from intentumdiff._differ_runtime import (
128
- _fuel_budget as _fuel_budget,
129
- )
130
- from intentumdiff._differ_runtime import (
131
- _fuel_hotspot_for_call as _fuel_hotspot_for_call,
132
- )
133
91
  from intentumdiff._differ_runtime import (
134
92
  _infer_file_lifecycle as _infer_file_lifecycle,
135
93
  )
@@ -155,7 +113,6 @@ from intentumdiff.analysis.guardrails import (
155
113
  # resource) are now Rust-authoritative — no Python enricher on the diff path (#90).
156
114
  from intentumdiff.analysis.schema_resolver import (
157
115
  resolve_schema,
158
- schema_cache_fingerprint,
159
116
  schema_resolution_metadata,
160
117
  )
161
118
  from intentumdiff.analysis.user_schemas import (
@@ -165,10 +122,8 @@ from intentumdiff.analysis.user_schemas import (
165
122
  from intentumdiff.cache.store import CacheStore
166
123
  from intentumdiff.core.models import (
167
124
  Change,
168
- ChangeGroupKind,
169
125
  ChangeStreamEvent,
170
126
  ChangeStreamPhase,
171
- ChangeType,
172
127
  DetectionResult,
173
128
  DiffConfig,
174
129
  LanguageInfoGroup,
@@ -181,16 +136,13 @@ from intentumdiff.plugins.exceptions import (
181
136
  PluginNotFoundError,
182
137
  PluginOutputError,
183
138
  )
184
- from intentumdiff.plugins.loader import _strip_trivia_impl
185
139
  from intentumdiff.plugins.registry import PluginRegistry
186
140
  from intentumdiff.rust_core import (
187
- RustCoreCommitJsonAttempt,
188
141
  enrich_node_facts,
142
+ fuel_budget,
189
143
  try_register_user_xml_dialects,
190
144
  try_rust_core_batch_diff,
191
145
  try_rust_core_batch_diffs,
192
- try_rust_core_commit_json,
193
- try_rust_core_working_tree_commit_json,
194
146
  try_rust_profile_label_enrichment,
195
147
  )
196
148
  from intentumdiff.sources.base import Source
@@ -374,24 +326,22 @@ class SemanticDiffer:
374
326
  return diff.model_copy(update={"metadata": metadata})
375
327
 
376
328
  def _rust_core_python_batch_skip_reason(self) -> str | None:
377
- if not self._config.experimental_rust_core:
378
- return "disabled"
379
329
  if self._config.diagnostics:
380
330
  return "diagnostics require Python pipeline"
381
331
  if self._config.extra_trivia_types:
382
332
  return "extra trivia types require Python pipeline"
383
333
  if self._config.extra_grammars.get("python"):
384
334
  return "custom Python grammar requires Python pipeline"
385
- allowed = self._config.allowed_plugins
386
- if allowed is not None and not any(
387
- plugin_id in allowed
388
- for plugin_id in (
389
- "python",
390
- "python-parser",
391
- "python_parser",
392
- "intentumdiff:python:python",
393
- )
394
- ):
335
+ # Core's allowlist rule (#311) on the batch parser's catalogue identity, the one
336
+ # filename selection sees: resolved path, catalogue id + entry names, languages.
337
+ from intentumdiff.plugins.builtins import python_parser_entry
338
+ from intentumdiff.rust_core import parser_allowlist_matches
339
+
340
+ path = str(Path(python_parser_entry()).resolve())
341
+ identity = next(({"plugin_id": path, "aliases": [e.plugin_id, *e.entry_names],
342
+ "languages": list(e.language_guesses)}
343
+ for e in self._registry._catalog() if e.resolved_path == path), {})
344
+ if not parser_allowlist_matches(self._config.allowed_plugins, identity)["matches"]:
395
345
  return "Python parser is not allowed by plugin policy"
396
346
  if self._registry.get_enrichers("python"):
397
347
  return "enrichers require Python pipeline"
@@ -399,14 +349,6 @@ class SemanticDiffer:
399
349
  return "diff analyzers require Python pipeline"
400
350
  return None
401
351
 
402
- @staticmethod
403
- def _rust_core_parallel_workers(parallel: int | bool) -> int | None:
404
- if parallel is True:
405
- return os.cpu_count() or 1
406
- if isinstance(parallel, int) and parallel > 0:
407
- return parallel
408
- return None
409
-
410
352
  @staticmethod
411
353
  def _rust_core_batch_parallel_plan(
412
354
  file_count: int,
@@ -616,164 +558,20 @@ class SemanticDiffer:
616
558
  return diff.model_dump_json(indent=2)
617
559
 
618
560
  if output_format == "terminal":
619
- # Inline Python renderer — always available, no ANSI codes.
620
- from io import StringIO
561
+ # Core's terminal presentation, exactly as the CLI renders it: source text such as
562
+ # `[/].py` or `[red]` stays literal instead of becoming Rich markup (#306).
563
+ from intentumdiff.rust_core import render_cli_review
621
564
 
622
- from rich.console import Console as _Console
623
-
624
- buf = StringIO()
625
- console = _Console(file=buf, highlight=False, no_color=True)
626
- console.print(
627
- f"Semantic diff: {diff.old_filename} -> {diff.new_filename} ({diff.language})"
628
- )
629
- for change in diff.changes:
630
- ct_str = (
631
- change.change_type.value
632
- if isinstance(change.change_type, ChangeType)
633
- else str(change.change_type)
634
- )
635
- console.print(f" {ct_str:14} {change.description}")
636
- return buf.getvalue()
565
+ return render_cli_review(diff, width=80, color=False)
637
566
 
638
567
  try:
639
568
  renderer = self._registry.get_renderer(output_format)
640
569
  except KeyError as exc:
641
570
  raise ValueError(str(exc)) from exc
642
571
  diff_json = diff.model_dump_json()
643
- adaptive_fuel = _fuel_budget(self._config.plugin_fuel, 20_000_000 + len(diff_json) * 100)
572
+ adaptive_fuel = fuel_budget(self._config.plugin_fuel, len(diff_json.encode("utf-8")))
644
573
  return renderer.render(diff_json, fuel=adaptive_fuel)
645
574
 
646
- def _diff_commit_certified_json(
647
- self,
648
- repo_path: str | os.PathLike[str] = ".",
649
- old_ref: str = "HEAD",
650
- new_ref: str = "",
651
- ) -> RustCoreCommitJsonAttempt:
652
- """Return Rust-certified CommitDiff JSON bytes for narrow Python batches."""
653
- _validate_git_ref(old_ref)
654
- _validate_git_ref(new_ref)
655
- rust_batch_skip_reason = self._rust_core_python_batch_skip_reason()
656
- if rust_batch_skip_reason is not None:
657
- _raise_rust_only_gate_error(rust_batch_skip_reason)
658
- return RustCoreCommitJsonAttempt(fallback_reason=rust_batch_skip_reason)
659
-
660
- if not new_ref:
661
- rust_batch_parallel, rust_batch_workers, _rust_batch_parallel_auto = (
662
- True,
663
- self._rust_core_parallel_workers(self._config.parallel),
664
- True,
665
- )
666
- working_tree_attempt = try_rust_core_working_tree_commit_json(
667
- repo_path=repo_path,
668
- old_ref=old_ref,
669
- config=self._config,
670
- parallel=rust_batch_parallel,
671
- max_workers=rust_batch_workers,
672
- )
673
- if working_tree_attempt.used:
674
- return working_tree_attempt
675
- if working_tree_attempt.fallback_reason and not (
676
- "does not expose diff_working_tree_python_commit_json"
677
- in working_tree_attempt.fallback_reason
678
- or working_tree_attempt.fallback_reason.startswith("unavailable:")
679
- ):
680
- _raise_rust_only_gate_error(working_tree_attempt.fallback_reason)
681
- return working_tree_attempt
682
-
683
- from intentumdiff.plugins.builtins import python_parser_entry
684
- from intentumdiff.sources.git_source import (
685
- collect_working_tree_python_sources_fast,
686
- iter_changed_sources,
687
- )
688
-
689
- source_started = time.perf_counter()
690
- fast_collection = (
691
- collect_working_tree_python_sources_fast(repo_path, old_ref) if not new_ref else None
692
- )
693
- if fast_collection is None:
694
- sources = list(iter_changed_sources(repo_path, old_ref, new_ref))
695
- fast_fallback_reason = None
696
- else:
697
- sources, fast_fallback_reason = fast_collection
698
- source_collection_ms = (time.perf_counter() - source_started) * 1000
699
- if fast_fallback_reason is not None:
700
- _raise_rust_only_gate_error(fast_fallback_reason)
701
- return RustCoreCommitJsonAttempt(fallback_reason=fast_fallback_reason)
702
- if not sources:
703
- return RustCoreCommitJsonAttempt()
704
-
705
- parser_wasm_path = python_parser_entry()
706
- request_files: list[dict[str, Any]] = []
707
- source_filter_started = time.perf_counter()
708
- for old_content, new_content, old_path, new_path, staging_status in sources:
709
- effective_new_path = new_path if new_path is not None else old_path
710
- file_lifecycle = _infer_file_lifecycle(old_content, new_content, staging_status)
711
- old_path_lower = old_path.lower()
712
- effective_new_path_lower = effective_new_path.lower()
713
- if not (
714
- old_path_lower.endswith((".py", ".pyi"))
715
- or effective_new_path_lower.endswith((".py", ".pyi"))
716
- ):
717
- fallback_attempt = RustCoreCommitJsonAttempt(
718
- fallback_reason="certified commit JSON requires all changed files to be Python"
719
- )
720
- _raise_rust_only_gate_error(fallback_attempt.fallback_reason)
721
- return fallback_attempt
722
- # Protected guardrail rules currently apply only to config/profile
723
- # languages, not Python. Avoid a per-file policy search here; any
724
- # actual policy-file change is excluded by the Python-only gate.
725
- request_file: dict[str, Any] = {
726
- "old_source": old_content,
727
- "new_source": new_content,
728
- "old_filename": old_path,
729
- "new_filename": effective_new_path,
730
- "language": "python",
731
- "parser_plugin_id": "python",
732
- "parser_wasm_path": parser_wasm_path,
733
- "file_lifecycle": file_lifecycle,
734
- }
735
- if staging_status is not None:
736
- request_file["staging_status"] = staging_status
737
- request_files.append(request_file)
738
- source_filter_ms = (time.perf_counter() - source_filter_started) * 1000
739
-
740
- rust_batch_parallel, rust_batch_workers, _rust_batch_parallel_auto = (
741
- self._rust_core_batch_parallel_plan(len(request_files), self._config.parallel)
742
- )
743
- attempt = try_rust_core_commit_json(
744
- files=request_files,
745
- old_ref=old_ref,
746
- new_ref=new_ref,
747
- config=self._config,
748
- parallel=rust_batch_parallel,
749
- max_workers=rust_batch_workers,
750
- )
751
- if not attempt.used:
752
- _raise_rust_only_gate_error(attempt.fallback_reason)
753
- return attempt
754
- adapter_phase_timings = [
755
- {
756
- "name": "source_collection",
757
- "duration_ms": round(source_collection_ms, 3),
758
- "shared": True,
759
- },
760
- {
761
- "name": "rust_core_commit_source_filtering",
762
- "duration_ms": round(source_filter_ms, 3),
763
- "shared": True,
764
- },
765
- *attempt.adapter_phase_timings,
766
- ]
767
- control = dict(attempt.control)
768
- control["source_collection_ms"] = round(source_collection_ms, 3)
769
- control["source_filter_ms"] = round(source_filter_ms, 3)
770
- return RustCoreCommitJsonAttempt(
771
- control=control,
772
- commit_diff_json=attempt.commit_diff_json,
773
- adapter_phase_timings=adapter_phase_timings,
774
- backend_version=attempt.backend_version,
775
- )
776
-
777
575
  def diff_commit(
778
576
  self,
779
577
  repo_path: str | os.PathLike[str] = ".",
@@ -814,7 +612,6 @@ class SemanticDiffer:
814
612
  sources = list(iter_changed_sources(policy_root, old_ref, new_ref))
815
613
  source_collection_ms = (time.perf_counter() - source_started) * 1000
816
614
  rust_batch_results: dict[int, SemanticDiff] = {}
817
- rust_batch_attempted: set[int] = set()
818
615
  rust_batch_skip_reason = self._rust_core_python_batch_skip_reason()
819
616
  if rust_batch_skip_reason is None and sources:
820
617
  from intentumdiff.plugins.builtins import python_parser_entry
@@ -860,7 +657,6 @@ class SemanticDiffer:
860
657
  time.perf_counter() - rust_batch_source_filter_started
861
658
  ) * 1000
862
659
  if request_files:
863
- rust_batch_attempted = set(request_to_source_index)
864
660
  (
865
661
  rust_batch_parallel,
866
662
  rust_batch_workers,
@@ -986,10 +782,7 @@ class SemanticDiffer:
986
782
  continue
987
783
  # Files the commit BATCH attempted but declined re-run through the normal
988
784
  # differ with the Rust core ON: the batch re-attempt is one cheap native
989
- # call and the per-stage finalize routing then serves. (The old
990
- # experimental_rust_core=False fallback differ meant "python pipeline";
991
- # post-retirement it means the token-fallback kill switch — a comment-only
992
- # commit came back as a token ADDITION instead of style-only.)
785
+ # call and the per-stage finalize routing then serves.
993
786
  run_differ = self
994
787
  try:
995
788
  results.append(
@@ -1223,10 +1016,6 @@ class SemanticDiffer:
1223
1016
  _dialects = user_xml_dialects_payload(_user_profiles)
1224
1017
  # Empty configuration must clear previously registered native dialects.
1225
1018
  try_register_user_xml_dialects(_dialects)
1226
- schema_fingerprint = schema_cache_fingerprint(schema_resolution)
1227
- cache_schema_suffix = (
1228
- "" if schema_fingerprint == "schema:none" else f"|{schema_fingerprint}"
1229
- )
1230
1019
  schema_metadata = schema_resolution_metadata(schema_resolution)
1231
1020
  if schema_metadata is not None:
1232
1021
  diagnostics.summary["schema"] = schema_metadata
@@ -1251,9 +1040,6 @@ class SemanticDiffer:
1251
1040
  reason="C/C++ compile database context resolved",
1252
1041
  metadata=compile_metadata,
1253
1042
  )
1254
- compile_cache_suffix = (
1255
- "" if compile_metadata is None else f"|compile:{compile_metadata['fingerprint']}"
1256
- )
1257
1043
 
1258
1044
  # Both physical sides may carry protection. Display aliases must not
1259
1045
  # hide the source policy on moves out of protected directories (#262).
@@ -1265,8 +1051,7 @@ class SemanticDiffer:
1265
1051
  cache_grammar_id = parser.grammar_id
1266
1052
 
1267
1053
  if (
1268
- self._config.experimental_rust_core
1269
- and language in _rust_certified_languages()
1054
+ language in _rust_certified_languages()
1270
1055
  and not diagnostics.enabled
1271
1056
  # ``test_matching_engine`` is the dual-run truthiness override.
1272
1057
  # When set, it forces the matching stage to either Rust or
@@ -1350,13 +1135,9 @@ class SemanticDiffer:
1350
1135
  # Stages 3-6 are skipped: the plugin handles its own CST construction
1351
1136
  # and trivia filtering. The style-only shortcut is not available here
1352
1137
  # because there is no host-side CST to hash.
1353
- max_source_bytes = max(
1354
- len(old_content.encode("utf-8")),
1355
- len(new_content.encode("utf-8")),
1356
- )
1357
- adaptive_fuel = _fuel_budget(
1138
+ adaptive_fuel = fuel_budget( # core's pair policy scales by both sides' bytes (#308)
1358
1139
  self._config.plugin_fuel,
1359
- 50_000_000 + max_source_bytes * 150_000,
1140
+ len(old_content.encode("utf-8")) + len(new_content.encode("utf-8")),
1360
1141
  )
1361
1142
  logger.debug("full-parse mode for %r via %r", filename, parser.grammar_id)
1362
1143
 
@@ -1437,27 +1218,15 @@ class SemanticDiffer:
1437
1218
  # Rust owns profile enrichment. Missing ABI handlers are fatal:
1438
1219
  # accepting un-enriched trees silently changes identity matching
1439
1220
  # and can suppress a meaningful diff. Never substitute Python logic.
1440
- # Gated by language so non-profile diffs pay no tree-JSON roundtrip.
1441
- if language.lower() in {"json", "yaml"}:
1442
- _identity_fields = tuple(schema_resolution.identity_fields)
1443
- old_tree = try_rust_profile_label_enrichment(
1444
- old_tree, old_raw, language, identity_fields=_identity_fields
1445
- )
1446
- new_tree = try_rust_profile_label_enrichment(
1447
- new_tree, new_raw, language, identity_fields=_identity_fields
1448
- )
1449
- if language.lower() in {"css", "scss", "html", "xml", "mdx"}:
1450
- old_tree = try_rust_profile_label_enrichment(old_tree, old_raw, language)
1451
- new_tree = try_rust_profile_label_enrichment(new_tree, new_raw, language)
1452
- if language.lower() in {"hcl", "puppet"}:
1453
- old_tree = try_rust_profile_label_enrichment(old_tree, old_raw, language)
1454
- new_tree = try_rust_profile_label_enrichment(new_tree, new_raw, language)
1455
- if language.lower() == "sql":
1456
- old_tree = try_rust_profile_label_enrichment(old_tree, old_raw, language)
1457
- new_tree = try_rust_profile_label_enrichment(new_tree, new_raw, language)
1458
- if language.lower() in {"asm", "bash", "delphi"}:
1459
- old_tree = try_rust_profile_label_enrichment(old_tree, old_raw, language)
1460
- new_tree = try_rust_profile_label_enrichment(new_tree, new_raw, language)
1221
+ # Every language is sent: core decides which profile family (if any)
1222
+ # applies and returns other trees unchanged.
1223
+ _identity_fields = tuple(sorted(schema_resolution.identity_fields))
1224
+ old_tree = try_rust_profile_label_enrichment(
1225
+ old_tree, old_raw, language, identity_fields=_identity_fields
1226
+ )
1227
+ new_tree = try_rust_profile_label_enrichment(
1228
+ new_tree, new_raw, language, identity_fields=_identity_fields
1229
+ )
1461
1230
  _validate_tree_ids(old_tree, filename)
1462
1231
  _validate_tree_ids(new_tree, filename)
1463
1232
  diagnostics.record(
@@ -1512,216 +1281,140 @@ class SemanticDiffer:
1512
1281
  policy_old_filename=policy_old_filename,
1513
1282
  diagnostics=diagnostics,
1514
1283
  )
1515
- # ── 9. GumTree matching ────────────────────────────────────────────────
1516
- # The matching engine is selected by (in priority order):
1517
- # 1. ``DiffConfig.test_matching_engine`` — test-only hard override used
1518
- # by the dual-run truthiness matrix to certify both contracts.
1519
- # 2. The production default: Rust's language-agnostic matcher
1520
- # (``intentumdiff_rust_core.diff_semantic_tree_json``) when the Rust
1521
- # core is available and diagnostics are off. This is migration
1522
- # step 2 of ``docs/ENGINE_BOUNDARY_AUDIT.md``. The four engine
1523
- # gaps that previously blocked this swap (Python dedent, JS
1524
- # calc_hash MOVE, YAML block↔flow, C# var↔explicit) are closed —
1525
- # see ``the retired NOISE_SUPPRESSION_RETUNE doc (git history)`` Phases A–D.
1526
- # 3. (retired) The python GumTree oracle was deleted with the transitional
1527
- # layer (issue #57 payoff, stage 4b) — no python matching fallback exists.
1284
+ # ── 9. Matching + finalize routing ─────────────────────────────────────
1285
+ # Rust owns matching and finalization; there is no Python matching path.
1286
+ # ``DiffConfig.test_matching_engine`` is a test-only override of the routing
1287
+ # decision below ("python" is retired and raises).
1528
1288
  test_engine = self._config.test_matching_engine
1529
- rust_attempt: Any = None
1530
- # Skip Rust matching when either tree is empty (file add/delete
1531
- # lifecycle). The Rust language-agnostic matcher treats empty-root
1532
- # ↔ content-root as a structural match, which produces a single
1533
- # MODIFICATION instead of the correct ADDITION (or DELETION) for
1534
- # the file-lifecycle case. Letting the Python oracle handle these
1535
- # edge cases preserves the ADDITION/DELETION shape that downstream
1536
- # tests and review UIs depend on.
1537
- either_tree_empty = (
1538
- not old_tree.children or not new_tree.children
1539
- )
1540
- use_rust_matching = (
1541
- test_engine == "rust"
1542
- or (
1543
- test_engine is None
1544
- and self._config.experimental_rust_core
1545
- and not diagnostics.enabled
1546
- and not either_tree_empty
1547
- )
1548
- )
1549
1289
  # ── 9-fin. Rust finalize routing (issue #57) ──────────────────────────
1550
- # Certified languages skip the python edit-script/refinement/presentation stages
1551
- # entirely: the Rust core runs the certified batch's refine+finalize from the
1552
- # semantic trees and returns the finished review. Eligibility is independent of
1553
- # the matching-engine choice (issue #57 payoff, fallback-tier closure):
1290
+ # Every parser language (first-party, dbt, third-party plugins) is finalized
1291
+ # by core: there is no Python language allowlist in front of it. The Rust
1292
+ # core runs the certified batch's refine+finalize from the semantic trees and
1293
+ # returns the finished review:
1554
1294
  # - empty-tree lifecycle is handled INSIDE Rust finalize (DELETION+ADDITION
1555
- # root pair, python parity), so either_tree_empty no longer excludes;
1295
+ # root pair);
1556
1296
  # - enriched trees flow through routing (enrichment ran at stage 7b);
1557
1297
  # - registered diff analyzers run on the ROUTED diff below, mirroring 13.5.
1558
1298
  # Diagnostics mode routes too (issue #57 payoff, stage 4a): the shell-side
1559
1299
  # records (parse, trees, guardrails, finalize summary below) still fire; the
1560
1300
  # per-pass refinement trace is Rust-internal (INTENTUMDIFF_FINALIZE_DEBUG probe)
1561
1301
  # until #54 formalizes it into the recorder.
1562
- rust_finalize_eligible = test_engine == "rust" or (
1563
- test_engine is None and self._config.experimental_rust_core
1564
- )
1565
- if rust_finalize_eligible and language in _rust_finalize_languages():
1566
- from intentumdiff.rust_core import try_rust_finalize_review
1567
-
1568
- with profiler.phase("rust_finalize_review"):
1569
- finalize_result = try_rust_finalize_review(
1570
- old_tree=old_tree,
1571
- new_tree=new_tree,
1572
- old_source=old_content,
1573
- new_source=new_content,
1574
- language=language,
1575
- config=self._config,
1576
- collect_trace=diagnostics.enabled,
1577
- )
1578
- if finalize_result is not None:
1579
- if finalize_result.get("fallback_diff") is not None:
1580
- fallback_diff = finalize_result["fallback_diff"].model_copy(update={
1581
- "old_filename": filename,
1582
- "new_filename": new_filename if new_filename is not None else filename})
1583
- fallback_diff = _apply_file_lifecycle_to_diff(fallback_diff, file_lifecycle)
1584
- return apply_guardrails_to_diff(fallback_diff, old_tree=None, new_tree=None,
1585
- old_source=old_raw, new_source=new_raw, config=self._config,
1586
- policy_filename=policy_source_filename,
1587
- policy_old_filename=policy_old_filename, diagnostics=diagnostics)
1588
- diagnostics.record(
1589
- stage="finalize",
1590
- action="rust_finalize_review",
1591
- rule_id="rust_core.finalize_review_v1",
1592
- reason="routed per-stage finalize served the review",
1593
- metadata={
1594
- "engine_owner": "rust",
1595
- "change_count": len(finalize_result["changes"]),
1596
- "is_style_only": finalize_result["is_style_only"],
1597
- },
1598
- )
1599
- # Per-pass trace (issue #54): every probed refine/finalize pass reports
1600
- # its surviving change count; the recorder mirrors the python pipeline's
1601
- # per-stage observability on the Rust path.
1602
- for entry in finalize_result.get("trace") or []:
1603
- diagnostics.record_count(
1604
- stage="finalize",
1605
- action=str(entry.get("pass", "")),
1606
- rule_id="rust_core.finalize_pass",
1607
- reason="rust finalize pass completed",
1608
- count=int(entry.get("changes_after", 0)),
1609
- )
1610
- from intentumdiff.rust_core import complete_routed_review
1611
-
1612
- routed = complete_routed_review(
1613
- finalized=finalize_result, old_tree=old_tree, new_tree=new_tree,
1614
- old_source=old_content, new_source=new_content,
1615
- old_filename=filename,
1616
- new_filename=new_filename if new_filename is not None else filename,
1617
- language=language, schema_metadata=schema_metadata,
1618
- compile_metadata=compile_metadata,
1619
- )
1620
- for group in routed.change_groups:
1621
- diagnostics.record_group(stage="invariance", group=group)
1622
- routed = _apply_file_lifecycle_to_diff(routed, file_lifecycle)
1623
- routed = apply_guardrails_to_diff(
1624
- routed,
1625
- old_tree=old_tree,
1626
- new_tree=new_tree,
1627
- old_source=old_content,
1628
- new_source=new_content,
1629
- config=self._config,
1630
- policy_filename=policy_source_filename,
1631
- policy_old_filename=policy_old_filename,
1632
- diagnostics=diagnostics,
1633
- )
1634
- # Diff-analyzer pass on the routed diff (stage 13.5 mirror; issue #57
1635
- # payoff): analyzers are diff->diff Wasm transforms over the final
1636
- # SemanticDiff JSON, so the routed review feeds them identically.
1637
- with profiler.phase("diff_analyzers"):
1638
- routed = self._run_diff_analyzers_on_routed(
1639
- routed, language, filename, adaptive_fuel
1640
- )
1641
- return _attach_run_telemetry(routed, engine_telemetry, diagnostics)
1642
- # The Rust finalize declined (tree_too_large / backend unavailable). The
1643
- # transitional python pipeline is retired (issue #57 payoff, stage 4b) —
1644
- # degrade honestly to the coarse token-level diff, same as parse errors.
1645
- logger.warning(
1646
- "Rust finalize declined for %r (%s) — Rust source fallback",
1647
- filename,
1648
- language,
1302
+ if test_engine == "python":
1303
+ raise NotImplementedError(
1304
+ "test_matching_engine='python' was retired with the transitional "
1305
+ "python pipeline (issue #57); the Rust finalize routing serves every "
1306
+ "certified language."
1649
1307
  )
1650
- _raise_rust_only_gate_error("rust finalize declined")
1308
+ from intentumdiff.rust_core import try_rust_finalize_review
1309
+
1310
+ with profiler.phase("rust_finalize_review"):
1311
+ finalize_result = try_rust_finalize_review(
1312
+ old_tree=old_tree,
1313
+ new_tree=new_tree,
1314
+ old_source=old_content,
1315
+ new_source=new_content,
1316
+ language=language,
1317
+ config=self._config,
1318
+ collect_trace=diagnostics.enabled,
1319
+ )
1320
+ if finalize_result is not None:
1321
+ if finalize_result.get("fallback_diff") is not None:
1322
+ fallback_diff = finalize_result["fallback_diff"].model_copy(update={
1323
+ "old_filename": filename,
1324
+ "new_filename": new_filename if new_filename is not None else filename})
1325
+ fallback_diff = _apply_file_lifecycle_to_diff(fallback_diff, file_lifecycle)
1326
+ return apply_guardrails_to_diff(fallback_diff, old_tree=None, new_tree=None,
1327
+ old_source=old_raw, new_source=new_raw, config=self._config,
1328
+ policy_filename=policy_source_filename,
1329
+ policy_old_filename=policy_old_filename, diagnostics=diagnostics)
1651
1330
  diagnostics.record(
1652
- stage="fallback",
1653
- action="token_fallback",
1654
- rule_id="pipeline.finalize_declined",
1655
- reason="rust finalize declined; python pipeline retired (#57)",
1331
+ stage="finalize",
1332
+ action="rust_finalize_review",
1333
+ rule_id="rust_core.finalize_review_v1",
1334
+ reason="routed per-stage finalize served the review",
1335
+ metadata={
1336
+ "engine_owner": "rust",
1337
+ "change_count": len(finalize_result["changes"]),
1338
+ "is_style_only": finalize_result["is_style_only"],
1339
+ },
1656
1340
  )
1657
- fallback_metadata: dict[str, Any] = {
1658
- "fallback_reason": "rust_finalize_declined",
1659
- }
1660
- if diagnostics.enabled:
1661
- diagnostics.summary.update(
1662
- {"early_exit": "token_fallback", "final_change_count": None}
1341
+ # Per-pass trace (issue #54): every probed refine/finalize pass reports
1342
+ # its surviving change count; the recorder mirrors the python pipeline's
1343
+ # per-stage observability on the Rust path.
1344
+ for entry in finalize_result.get("trace") or []:
1345
+ diagnostics.record_count(
1346
+ stage="finalize",
1347
+ action=str(entry.get("pass", "")),
1348
+ rule_id="rust_core.finalize_pass",
1349
+ reason="rust finalize pass completed",
1350
+ count=int(entry.get("changes_after", 0)),
1663
1351
  )
1664
- fallback_metadata["diagnostics"] = diagnostics.snapshot()
1665
- fallback_diff = _token_fallback_diff(
1666
- old_raw,
1667
- new_raw,
1668
- filename,
1669
- new_filename if new_filename is not None else filename,
1670
- language,
1671
- metadata=fallback_metadata,
1352
+ from intentumdiff.rust_core import complete_routed_review
1353
+
1354
+ routed = complete_routed_review(
1355
+ finalized=finalize_result, old_tree=old_tree, new_tree=new_tree,
1356
+ old_source=old_content, new_source=new_content,
1357
+ old_filename=filename,
1358
+ new_filename=new_filename if new_filename is not None else filename,
1359
+ language=language, schema_metadata=schema_metadata,
1360
+ compile_metadata=compile_metadata,
1672
1361
  )
1673
- fallback_diff = _apply_file_lifecycle_to_diff(fallback_diff, file_lifecycle)
1674
- return apply_guardrails_to_diff(
1675
- fallback_diff,
1676
- old_tree=None,
1677
- new_tree=None,
1678
- old_source=old_raw,
1679
- new_source=new_raw,
1362
+ for group in routed.change_groups:
1363
+ diagnostics.record_group(stage="invariance", group=group)
1364
+ routed = _apply_file_lifecycle_to_diff(routed, file_lifecycle)
1365
+ routed = apply_guardrails_to_diff(
1366
+ routed,
1367
+ old_tree=old_tree,
1368
+ new_tree=new_tree,
1369
+ old_source=old_content,
1370
+ new_source=new_content,
1680
1371
  config=self._config,
1681
1372
  policy_filename=policy_source_filename,
1682
1373
  policy_old_filename=policy_old_filename,
1683
1374
  diagnostics=diagnostics,
1684
1375
  )
1685
- if test_engine == "python":
1686
- raise NotImplementedError(
1687
- "test_matching_engine='python' was retired with the transitional "
1688
- "python pipeline (issue #57); the Rust finalize routing serves every "
1689
- "certified language."
1690
- )
1691
-
1692
- # Rust core disabled (DiffConfig kill switch / INTENTUMDIFF_RUST_CORE=0): the
1693
- # transitional python pipeline is retired (issue #57 payoff) — semantic
1694
- # diffing REQUIRES the Rust core; degrade honestly to the token-level diff.
1376
+ # Diff-analyzer pass on the routed diff (stage 13.5 mirror; issue #57
1377
+ # payoff): analyzers are diff->diff Wasm transforms over the final
1378
+ # SemanticDiff JSON, so the routed review feeds them identically.
1379
+ with profiler.phase("diff_analyzers"):
1380
+ routed = self._run_diff_analyzers_on_routed(
1381
+ routed, language, filename, adaptive_fuel
1382
+ )
1383
+ return _attach_run_telemetry(routed, engine_telemetry, diagnostics)
1384
+ # The Rust finalize declined (tree_too_large / backend unavailable). The
1385
+ # transitional python pipeline is retired (issue #57 payoff, stage 4b) —
1386
+ # degrade honestly to the coarse token-level diff, same as parse errors.
1695
1387
  logger.warning(
1696
- "Rust core disabled for %r — Rust source fallback (python pipeline retired)",
1388
+ "Rust finalize declined for %r (%s) — Rust source fallback",
1697
1389
  filename,
1390
+ language,
1698
1391
  )
1699
- _raise_rust_only_gate_error("rust core disabled")
1392
+ _raise_rust_only_gate_error("rust finalize declined")
1700
1393
  diagnostics.record(
1701
1394
  stage="fallback",
1702
1395
  action="token_fallback",
1703
- rule_id="pipeline.rust_core_disabled",
1704
- reason="rust core disabled; python pipeline retired (#57)",
1396
+ rule_id="pipeline.finalize_declined",
1397
+ reason="rust finalize declined; python pipeline retired (#57)",
1705
1398
  )
1706
- disabled_metadata: dict[str, Any] = {
1707
- "fallback_reason": "rust_core_disabled",
1399
+ fallback_metadata: dict[str, Any] = {
1400
+ "fallback_reason": "rust_finalize_declined",
1708
1401
  }
1709
1402
  if diagnostics.enabled:
1710
1403
  diagnostics.summary.update(
1711
1404
  {"early_exit": "token_fallback", "final_change_count": None}
1712
1405
  )
1713
- disabled_metadata["diagnostics"] = diagnostics.snapshot()
1714
- disabled_diff = _token_fallback_diff(
1406
+ fallback_metadata["diagnostics"] = diagnostics.snapshot()
1407
+ fallback_diff = _token_fallback_diff(
1715
1408
  old_raw,
1716
1409
  new_raw,
1717
1410
  filename,
1718
1411
  new_filename if new_filename is not None else filename,
1719
1412
  language,
1720
- metadata=disabled_metadata,
1413
+ metadata=fallback_metadata,
1721
1414
  )
1722
- disabled_diff = _apply_file_lifecycle_to_diff(disabled_diff, file_lifecycle)
1415
+ fallback_diff = _apply_file_lifecycle_to_diff(fallback_diff, file_lifecycle)
1723
1416
  return apply_guardrails_to_diff(
1724
- disabled_diff,
1417
+ fallback_diff,
1725
1418
  old_tree=None,
1726
1419
  new_tree=None,
1727
1420
  old_source=old_raw,