intentumdiff-python 0.0.1__py3-none-win_arm64.whl → 0.0.2b2__py3-none-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. intentumdiff/__init__.py +2 -0
  2. intentumdiff/__main__.py +12 -0
  3. intentumdiff/_differ_presentation.py +35 -682
  4. intentumdiff/_differ_runtime.py +13 -47
  5. intentumdiff/analysis/compile_commands.py +26 -141
  6. intentumdiff/analysis/cross_file.py +2 -4
  7. intentumdiff/analysis/guardrail_reports.py +7 -5
  8. intentumdiff/analysis/guardrails.py +110 -122
  9. intentumdiff/analysis/invariances.py +4 -1003
  10. intentumdiff/analysis/schema_resolver.py +49 -273
  11. intentumdiff/analysis/text_review.py +4 -3
  12. intentumdiff/analysis/user_schemas.py +55 -237
  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 +174 -67
  17. intentumdiff/cli/_parser.py +11 -1
  18. intentumdiff/cli/_shared.py +96 -112
  19. intentumdiff/content_type.py +13 -30
  20. intentumdiff/core/commit_differ.py +105 -220
  21. intentumdiff/core/diffignore.py +28 -34
  22. intentumdiff/core/index.py +16 -18
  23. intentumdiff/core/indexer.py +148 -168
  24. intentumdiff/core/models.py +53 -14
  25. intentumdiff/differ.py +278 -605
  26. intentumdiff/github_app.py +35 -19
  27. intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
  28. intentumdiff/live_server.py +180 -17
  29. intentumdiff/lsp/client.py +7 -1
  30. intentumdiff/lsp/enricher.py +19 -119
  31. intentumdiff/lsp/exceptions.py +6 -7
  32. intentumdiff/lsp_server/_codelens.py +24 -57
  33. intentumdiff/lsp_server/_diagnostics.py +23 -51
  34. intentumdiff/lsp_server/_handlers.py +66 -8
  35. intentumdiff/lsp_server/server.py +28 -7
  36. intentumdiff/plugins/adapter.py +5 -0
  37. intentumdiff/plugins/builtins.py +7 -14
  38. intentumdiff/plugins/exceptions.py +4 -0
  39. intentumdiff/plugins/hub.py +1 -2
  40. intentumdiff/plugins/loader.py +229 -215
  41. intentumdiff/plugins/registry.py +249 -197
  42. intentumdiff/rust_core.py +744 -784
  43. intentumdiff/serve/_app.py +3 -10
  44. intentumdiff/sources/base.py +24 -0
  45. intentumdiff/sources/file_source.py +15 -2
  46. intentumdiff/sources/git_source.py +120 -58
  47. intentumdiff/sources/live_buffer_source.py +45 -5
  48. intentumdiff/sources/patch_source.py +36 -109
  49. intentumdiff/vcs/_safe_path.py +7 -0
  50. intentumdiff/vcs/base.py +6 -0
  51. intentumdiff/vcs/git_backend.py +1 -1
  52. intentumdiff/vcs/git_cli.py +38 -18
  53. intentumdiff/vcs/hg_backend.py +1 -1
  54. intentumdiff/vcs/perforce_backend.py +7 -1
  55. intentumdiff/vcs/svn_backend.py +1 -1
  56. intentumdiff/wasm/abap_parser.wasm +0 -0
  57. intentumdiff/wasm/adf_parser.wasm +0 -0
  58. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  59. intentumdiff/wasm/asm_parser.wasm +0 -0
  60. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  61. intentumdiff/wasm/astro_parser.wasm +0 -0
  62. intentumdiff/wasm/bash_parser.wasm +0 -0
  63. intentumdiff/wasm/clojure_parser.wasm +0 -0
  64. intentumdiff/wasm/cmake_parser.wasm +0 -0
  65. intentumdiff/wasm/cpp_parser.wasm +0 -0
  66. intentumdiff/wasm/csharp_parser.wasm +0 -0
  67. intentumdiff/wasm/css_parser.wasm +0 -0
  68. intentumdiff/wasm/dart_parser.wasm +0 -0
  69. intentumdiff/wasm/databricks_parser.wasm +0 -0
  70. intentumdiff/wasm/dax_parser.wasm +0 -0
  71. intentumdiff/wasm/delphi_parser.wasm +0 -0
  72. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  73. intentumdiff/wasm/elixir_parser.wasm +0 -0
  74. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  75. intentumdiff/wasm/generic_parser.wasm +0 -0
  76. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  77. intentumdiff/wasm/go_parser.wasm +0 -0
  78. intentumdiff/wasm/gomod_parser.wasm +0 -0
  79. intentumdiff/wasm/graphql_parser.wasm +0 -0
  80. intentumdiff/wasm/groovy_parser.wasm +0 -0
  81. intentumdiff/wasm/haskell_parser.wasm +0 -0
  82. intentumdiff/wasm/html_parser.wasm +0 -0
  83. intentumdiff/wasm/html_renderer.wasm +0 -0
  84. intentumdiff/wasm/ini_parser.wasm +0 -0
  85. intentumdiff/wasm/java_parser.wasm +0 -0
  86. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  87. intentumdiff/wasm/json_parser.wasm +0 -0
  88. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  89. intentumdiff/wasm/latex_parser.wasm +0 -0
  90. intentumdiff/wasm/llm_renderer.wasm +0 -0
  91. intentumdiff/wasm/lua_parser.wasm +0 -0
  92. intentumdiff/wasm/make_parser.wasm +0 -0
  93. intentumdiff/wasm/markdown_parser.wasm +0 -0
  94. intentumdiff/wasm/mdx_parser.wasm +0 -0
  95. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  96. intentumdiff/wasm/odin_parser.wasm +0 -0
  97. intentumdiff/wasm/parser_manifest.json +81 -2
  98. intentumdiff/wasm/patch_renderer.wasm +0 -0
  99. intentumdiff/wasm/perl_parser.wasm +0 -0
  100. intentumdiff/wasm/php_parser.wasm +0 -0
  101. intentumdiff/wasm/plsql_parser.wasm +0 -0
  102. intentumdiff/wasm/po_parser.wasm +0 -0
  103. intentumdiff/wasm/postscript_parser.wasm +0 -0
  104. intentumdiff/wasm/powershell_parser.wasm +0 -0
  105. intentumdiff/wasm/proto_parser.wasm +0 -0
  106. intentumdiff/wasm/puppet_parser.wasm +0 -0
  107. intentumdiff/wasm/python_parser.wasm +0 -0
  108. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  109. intentumdiff/wasm/r_parser.wasm +0 -0
  110. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  111. intentumdiff/wasm/ruby_parser.wasm +0 -0
  112. intentumdiff/wasm/rust_parser.wasm +0 -0
  113. intentumdiff/wasm/sas_parser.wasm +0 -0
  114. intentumdiff/wasm/scala_parser.wasm +0 -0
  115. intentumdiff/wasm/scss_parser.wasm +0 -0
  116. intentumdiff/wasm/sql_parser.wasm +0 -0
  117. intentumdiff/wasm/squirrel_parser.wasm +0 -0
  118. intentumdiff/wasm/svelte_parser.wasm +0 -0
  119. intentumdiff/wasm/swift_parser.wasm +0 -0
  120. intentumdiff/wasm/terminal_renderer.wasm +0 -0
  121. intentumdiff/wasm/terraform_parser.wasm +0 -0
  122. intentumdiff/wasm/toml_parser.wasm +0 -0
  123. intentumdiff/wasm/tsql_parser.wasm +0 -0
  124. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  125. intentumdiff/wasm/vue_parser.wasm +0 -0
  126. intentumdiff/wasm/wasm_provenance.json +884 -0
  127. intentumdiff/wasm/wat_parser.wasm +0 -0
  128. intentumdiff/wasm/xml_parser.wasm +0 -0
  129. intentumdiff/wasm/yaml_parser.wasm +0 -0
  130. intentumdiff/wasm/zig_parser.wasm +0 -0
  131. intentumdiff_python-0.0.2b2.dist-info/METADATA +156 -0
  132. intentumdiff_python-0.0.2b2.dist-info/RECORD +171 -0
  133. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/WHEEL +1 -1
  134. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
  135. intentumdiff/core/cst_serializer.py +0 -101
  136. intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
  137. intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
  138. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/entry_points.txt +0 -0
  139. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/licenses/LICENSE +0 -0
@@ -27,8 +27,11 @@ not handled by the allowed list.
27
27
 
28
28
  from __future__ import annotations
29
29
 
30
+ import hashlib
30
31
  import importlib.metadata
31
32
  import logging
33
+ import os
34
+ import platform
32
35
  import re
33
36
  import threading
34
37
  import time
@@ -44,7 +47,7 @@ from intentumdiff.plugins.adapter import (
44
47
  ParserAdapter,
45
48
  RendererAdapter,
46
49
  )
47
- from intentumdiff.plugins.exceptions import PluginFuelExhausted, PluginNotFoundError
50
+ from intentumdiff.plugins.exceptions import PluginFuelExhausted, PluginNotFoundError, PluginLoadError, PluginSandboxViolation, PluginSecurityError
48
51
  from intentumdiff.plugins.language_metadata import fallback_language_info
49
52
  from intentumdiff.plugins.loader import LoadedPlugin, load_plugin
50
53
 
@@ -66,10 +69,72 @@ PhaseRecorder = Callable[[str, float], None]
66
69
  # installs safe even when stale entry-point metadata still lists the plugin.
67
70
  _DISABLED_BUILTIN_PARSER_ENTRYPOINTS: frozenset[str] = frozenset({"freebasic"})
68
71
 
72
+ def arch_incompatible_reason(
73
+ entry_point_name: str, wasm_path: str | Path | None = None,
74
+ ) -> str | None:
75
+ """Delegate architecture policy to Rust using the actual staged Wasm digest.
76
+
77
+ Python only resolves and hashes host files. With no concrete component, the
78
+ legacy Rust API must remain fail-closed for unverified PowerShell on ARM64.
79
+ """
80
+ from intentumdiff.rust_core import _c_abi_call
81
+ system, machine = platform.system(), platform.machine()
82
+ legacy = _c_abi_call("parser_availability", entry_point_name, "", system, machine)
83
+ reason = legacy["reason"]
84
+ if reason is None or wasm_path is None:
85
+ return reason
86
+ try:
87
+ digest = hashlib.sha256(Path(wasm_path).read_bytes()).hexdigest()
88
+ except OSError:
89
+ return reason # Unreadable bytes cannot lift a Rust-owned restriction.
90
+ checked = _c_abi_call(
91
+ "parser_availability_with_digest", entry_point_name, "", system, machine, digest,
92
+ )
93
+ if not isinstance(checked, dict) or "reason" not in checked:
94
+ raise PluginLoadError(str(wasm_path), "malformed Rust digest availability response")
95
+ return checked["reason"]
96
+
97
+
98
+ def unavailable_parser_for(filename: str) -> tuple[str, str] | None:
99
+ """Explain a Rust-owned platform exclusion only when its bytes are excluded."""
100
+ from intentumdiff.rust_core import _c_abi_call
101
+ system, machine = platform.system(), platform.machine()
102
+ legacy = _c_abi_call("parser_availability", "", filename, system, machine)["unavailable"]
103
+ if legacy is None:
104
+ return None
105
+ # The built-in path is transport metadata, not a Python semantic policy.
106
+ # A third-party parser may have a different path; never presume it verified.
107
+ name = legacy[0]
108
+ staged = _wasm_dir() / f"{name}_parser.wasm"
109
+ try:
110
+ digest = hashlib.sha256(staged.read_bytes()).hexdigest()
111
+ except OSError:
112
+ return tuple(legacy)
113
+ checked = _c_abi_call(
114
+ "parser_availability_with_digest", "", filename, system, machine, digest,
115
+ )
116
+ if not isinstance(checked, dict) or "unavailable" not in checked:
117
+ raise PluginLoadError(str(staged), "malformed Rust digest availability response")
118
+ unavailable = checked["unavailable"]
119
+ return tuple(unavailable) if unavailable is not None else None
120
+
121
+
69
122
  # Normalised names of first-party packages whose entry-point callables are
70
123
  # trusted plugin metadata.
71
124
  _TRUSTED_PLUGIN_PACKAGE_NAMES: frozenset[str] = frozenset(
72
125
  {
126
+ # The DISTRIBUTION name, which is not the import name. The wheel is published as
127
+ # `intentumdiff-python` (the polyglot-binding convention) while the import package
128
+ # is `intentumdiff`, and entry points report the DISTRIBUTION.
129
+ #
130
+ # Omitting it made the package fail its own first-party check: all 69 built-in
131
+ # parsers were treated as untrusted third-party plugins and refused with a security
132
+ # warning naming the package itself as the culprit. Every invocation printed ~69
133
+ # error lines before producing output. Shipped in 0.0.1 and only found by installing
134
+ # the published wheel — no test in the repo could see it, because in a source
135
+ # checkout the distribution resolves differently.
136
+ "intentumdiff-python",
137
+ "intentumdiff_python",
73
138
  "intentumdiff",
74
139
  "intentumdiff-dbt",
75
140
  "intentumdiff_dbt",
@@ -223,10 +288,27 @@ def _is_trusted_entry_point(ep: importlib.metadata.EntryPoint) -> bool:
223
288
 
224
289
 
225
290
  def _wasm_dir() -> Path:
226
- """Return the directory containing built-in .wasm files."""
291
+ """Return the directory containing built-in .wasm files.
292
+
293
+ THE one place that knows where components live. Five call sites derived this
294
+ independently and four got it right; the CLI's copy used `Path(__file__).parent`
295
+ from inside `cli/`, resolving to `intentumdiff/cli/wasm/` — a directory that does
296
+ not exist. Every renderer lookup silently found nothing, and the user was told
297
+ "No renderer plugin found" for components that ship, load, and report the exact
298
+ format requested.
299
+
300
+ Re-deriving a path is how that happens. Call this instead.
301
+ """
227
302
  return Path(__file__).parent.parent / "wasm"
228
303
 
229
304
 
305
+ #: Public alias. `_wasm_dir` is private by name and was therefore copied rather than
306
+ #: imported; this gives callers outside this module something to use.
307
+ def builtin_wasm_dir() -> Path:
308
+ """Directory containing the built-in .wasm components."""
309
+ return _wasm_dir()
310
+
311
+
230
312
  # ---------------------------------------------------------------------------
231
313
  # Secure wasm-path resolution
232
314
  # ---------------------------------------------------------------------------
@@ -275,7 +357,7 @@ def _wasm_path_from_ep(ep: importlib.metadata.EntryPoint) -> str:
275
357
  "execute arbitrary code before Wasm sandboxing is in effect. "
276
358
  f"The plugin author must add '{_WASM_PATH_METADATA_FIELD}: <relative/path.wasm>' "
277
359
  "to their package metadata. "
278
- "See: https://docs.intentumdiff.dev/plugins/metadata"
360
+ "See: https://buchochelliq-labs.github.io/intentumdiff-docs/extending/"
279
361
  )
280
362
 
281
363
  # Locate the file via importlib.metadata without importing anything.
@@ -423,6 +505,21 @@ class PluginRegistry:
423
505
  self._parser_load_errors.extend(load_errors)
424
506
  return self._parser_catalog
425
507
 
508
+ @staticmethod
509
+ def _catalog_descriptors(entries):
510
+ descriptors = []
511
+ for entry in entries:
512
+ metadata = [_fallback_info_for_catalog(entry, language) for language in entry.language_guesses]
513
+ descriptors.append({
514
+ "id": entry.resolved_path,
515
+ "aliases": [entry.plugin_id, *entry.entry_names],
516
+ "languages": list(entry.language_guesses),
517
+ "filenames": [info.default_filename for info in metadata],
518
+ "extensions": [extension for info in metadata for extension in info.language_file_extensions],
519
+ "priority": 0, # Discovery metadata has no declared priority; ignore cache warmth.
520
+ })
521
+ return descriptors
522
+
426
523
  def _candidate_entries(
427
524
  self,
428
525
  filename: str,
@@ -434,31 +531,17 @@ class PluginRegistry:
434
531
  ) -> list[_ParserCatalogEntry]:
435
532
  with _record_phase(phase_recorder, "parser_candidate_shortlist"):
436
533
  entries = self._catalog(phase_recorder)
437
- language_filter = set(candidates or [])
438
- if language_hint:
439
- language_filter.add(language_hint)
440
-
441
- result: list[_ParserCatalogEntry] = []
442
- for entry in entries:
443
- if plugin_id is not None:
444
- if plugin_id == entry.plugin_id or plugin_id in entry.entry_names:
445
- result.append(entry)
446
- continue
447
- if language_filter:
448
- if language_filter.intersection(entry.language_guesses):
449
- result.append(entry)
450
- continue
451
- if _entry_matches_filename(entry, filename):
452
- result.append(entry)
453
-
454
- if result or plugin_id is not None or language_filter:
455
- # The generic parser is the designated FALLBACK: when a specific parser
456
- # also matched the filename (CMakeLists.txt matches both generic's .txt
457
- # and the cmake plugin), catalog order must not let generic claim the
458
- # file first — it detect-claims everything.
459
- result.sort(key=lambda e: "generic" in e.language_guesses)
460
- return result
461
- return list(entries)
534
+ import json
535
+ from intentumdiff.rust_core import _required_engine_json
536
+
537
+ descriptors = self._catalog_descriptors(entries)
538
+ indices = _required_engine_json("parser_candidate_shortlist", json.dumps({
539
+ "entries": descriptors,
540
+ "query": {"filename": filename, "language_hint": language_hint, "plugin_id": plugin_id, "candidates": candidates or []},
541
+ }), result_type=list)
542
+ if any(type(index) is not int or not 0 <= index < len(entries) for index in indices) or len(set(indices)) != len(indices):
543
+ raise RuntimeError("Rust parser shortlist returned invalid indices")
544
+ return [entries[index] for index in indices]
462
545
 
463
546
  def _load_catalog_entry(
464
547
  self,
@@ -507,6 +590,7 @@ class PluginRegistry:
507
590
  language_hint: str | None = None,
508
591
  plugin_id: str | None = None,
509
592
  phase_recorder: PhaseRecorder | None = None,
593
+ old_content: str = "",
510
594
  ) -> tuple[ParserAdapter, str]:
511
595
  """
512
596
  Return ``(parser, language)`` for a given file.
@@ -516,113 +600,67 @@ class PluginRegistry:
516
600
 
517
601
  Raises ``PluginNotFoundError`` if no parser can handle the file.
518
602
  """
519
- allowed = self._config.allowed_plugins
520
-
521
- if plugin_id:
522
- for entry in self._candidate_entries(
523
- filename,
524
- language_hint=language_hint,
525
- plugin_id=plugin_id,
526
- phase_recorder=phase_recorder,
527
- ):
603
+ import json
604
+ from intentumdiff.rust_core import _required_engine_json
605
+
606
+ entries = self._catalog(phase_recorder)
607
+ request = {"entries": self._catalog_descriptors(entries), "filename": filename,
608
+ "content": content[:2048], "old_content": old_content[:2048], "language_hint": language_hint, "plugin_id": plugin_id,
609
+ "strict": self._config.strict_plugins, "allowed_plugins": self._config.allowed_plugins}
610
+ events = []
611
+ parsers = {}
612
+ errors = {}
613
+ while True:
614
+ with _record_phase(phase_recorder, "parser_candidate_shortlist"):
615
+ action = _required_engine_json("filename_selection_next", json.dumps({
616
+ "request": request, "events": events,
617
+ }), result_type=dict)
618
+ kind = action["kind"]
619
+ if kind == "load":
620
+ index = action["index"]
528
621
  try:
529
- parser = self._load_catalog_entry(entry, phase_recorder=phase_recorder)
530
- if allowed is not None and parser.grammar_id not in allowed:
531
- continue
532
- if language_hint:
533
- if language_hint in parser.language_ids:
534
- return parser, language_hint
535
- continue
536
- with _record_phase(phase_recorder, "parser_plugin_language_detection"):
537
- lang = parser.detect_language(filename, content[:2048])
538
- if lang:
539
- return parser, lang
540
- except PluginFuelExhausted:
541
- # Terminal, never a skip. Fuel exhaustion (now possible during
542
- # instantiation since the wasmtime 47 binding) means THIS plugin hit
543
- # the user's CPU cap — trying the next candidate would either
544
- # mis-parse the file or dress the fuel problem up as
545
- # PluginNotFoundError('unknown'). The whole point of the fuel
546
- # contract is to fail explicitly rather than degrade silently.
547
- raise
622
+ parser = self._load_catalog_entry(entries[index], phase_recorder=phase_recorder)
623
+ event = {"kind": "loaded", "index": index, "grammar_id": parser.grammar_id,
624
+ "languages": list(parser.language_ids), "priority": parser.priority}
625
+ parsers[index] = parser
548
626
  except Exception as exc:
549
- logger.debug(
550
- "Skipping parser candidate %s after load failure: %s",
551
- ",".join(entry.entry_names),
552
- exc,
553
- )
554
- continue
555
- raise PluginNotFoundError(plugin_id, filename)
556
-
557
- if language_hint:
558
- for entry in self._candidate_entries(
559
- filename,
560
- language_hint=language_hint,
561
- phase_recorder=phase_recorder,
562
- ):
627
+ errors[len(events)] = exc
628
+ event = {"kind": "load_failed", "index": index,
629
+ "terminal": isinstance(exc, (PluginFuelExhausted, PluginSandboxViolation, PluginSecurityError))}
630
+ events.append(event)
631
+ elif kind == "probe":
632
+ index = action["index"]
563
633
  try:
564
- parser = self._load_catalog_entry(entry, phase_recorder=phase_recorder)
565
- except PluginFuelExhausted:
566
- # Terminal, never a skip. Fuel exhaustion (now possible during
567
- # instantiation since the wasmtime 47 binding) means THIS plugin hit
568
- # the user's CPU cap — trying the next candidate would either
569
- # mis-parse the file or dress the fuel problem up as
570
- # PluginNotFoundError('unknown'). The whole point of the fuel
571
- # contract is to fail explicitly rather than degrade silently.
572
- raise
573
- except Exception as exc:
574
- logger.debug(
575
- "Skipping parser candidate %s after load failure: %s",
576
- ",".join(entry.entry_names),
577
- exc,
578
- )
579
- continue
580
- if allowed is not None and parser.grammar_id not in allowed:
581
- continue
582
- if language_hint in parser.language_ids:
583
- return parser, language_hint
584
- if language_hint in entry.language_guesses and "generic" in parser.language_ids:
585
- return parser, language_hint
586
- if self._config.strict_plugins:
587
- raise PluginNotFoundError(language_hint, filename)
588
-
589
- primary_entries = self._candidate_entries(filename, phase_recorder=phase_recorder)
590
- matched_paths: set[str] = set()
591
- for entries in (
592
- primary_entries,
593
- [entry for entry in self._catalog() if entry not in primary_entries],
594
- ):
595
- for entry in entries:
596
- if entry.resolved_path in matched_paths:
597
- continue
598
- matched_paths.add(entry.resolved_path)
599
- try:
600
- parser = self._load_catalog_entry(entry, phase_recorder=phase_recorder)
601
- except PluginFuelExhausted:
602
- # Terminal, never a skip. Fuel exhaustion (now possible during
603
- # instantiation since the wasmtime 47 binding) means THIS plugin hit
604
- # the user's CPU cap — trying the next candidate would either
605
- # mis-parse the file or dress the fuel problem up as
606
- # PluginNotFoundError('unknown'). The whole point of the fuel
607
- # contract is to fail explicitly rather than degrade silently.
608
- raise
634
+ with _record_phase(phase_recorder, "parser_plugin_language_detection"):
635
+ language = parsers[index].detect_language(filename, action["sample"])
636
+ event = {"kind": "probed", "index": index, "language": language}
609
637
  except Exception as exc:
610
- logger.debug(
611
- "Skipping parser candidate %s after load failure: %s",
612
- ",".join(entry.entry_names),
613
- exc,
614
- )
615
- continue
616
- if allowed is not None and parser.grammar_id not in allowed:
617
- continue
618
- with _record_phase(phase_recorder, "parser_plugin_language_detection"):
619
- lang = parser.detect_language(filename, content[:2048])
620
- if lang:
621
- return parser, lang
622
- if entries is primary_entries and primary_entries:
638
+ errors[len(events)] = exc
639
+ event = {"kind": "probe_failed", "index": index}
640
+ events.append(event)
641
+ elif kind == "selected":
642
+ return parsers[action["index"]], action["language"]
643
+ elif kind == "failure":
644
+ raise errors[action["event"]]
645
+ elif kind == "not_found":
646
+ missing = action["identity"]
623
647
  break
624
-
625
- raise PluginNotFoundError("unknown", filename)
648
+ else:
649
+ raise RuntimeError(f"Invalid Rust filename selection action: {kind!r}")
650
+
651
+ excluded = unavailable_parser_for(filename)
652
+ if excluded is not None:
653
+ name, reason = excluded
654
+ # The one place this is worth saying out loud: the user is diffing a file whose
655
+ # parser we deliberately did not load. Without it they see "unknown language" and
656
+ # have no way to learn why, which looks like a broken product rather than a known
657
+ # platform limitation.
658
+ logger.warning(
659
+ "No semantic parser for %s on %s/%s: the %r parser is excluded here because "
660
+ "%s. This file falls back to token-level diffing.",
661
+ filename, platform.system(), platform.machine(), name, reason,
662
+ )
663
+ raise PluginNotFoundError(missing, filename)
626
664
 
627
665
  def detect_by_content(
628
666
  self,
@@ -641,50 +679,32 @@ class PluginRegistry:
641
679
  Optional pre-filter. When supplied, only parsers whose
642
680
  ``language_ids`` overlap with *candidates* are consulted.
643
681
  """
644
- if plugin_id:
645
- parser = self.get_parser_by_id(plugin_id)
646
- allowed = self._config.allowed_plugins
647
- if allowed is not None and parser.grammar_id not in allowed:
648
- raise PluginNotFoundError(plugin_id)
649
- if candidates and not any(c in parser.language_ids for c in candidates):
650
- raise PluginNotFoundError(plugin_id)
651
- lang = parser.detect_language("", content[:4096])
652
- if not lang or (candidates and lang not in candidates):
653
- raise PluginNotFoundError(plugin_id)
654
- return [
655
- DetectionResult(
656
- language=lang,
657
- grammar_id=parser.grammar_id,
658
- confidence=1.0,
659
- )
660
- ]
661
-
662
- ranked = sorted(self.parsers, key=lambda p: p.priority, reverse=True)
663
- allowed = self._config.allowed_plugins
664
- raw_results: list[tuple[str, str, int, bool]] = []
665
- for parser in ranked:
666
- if allowed is not None and parser.grammar_id not in allowed:
667
- continue
668
- if candidates and not any(c in parser.language_ids for c in candidates):
669
- continue
670
- lang = parser.detect_language("", content[:4096])
671
- if lang:
672
- preferred = bool(
673
- preferred_plugins
674
- and preferred_plugins.get(lang) == parser.plugin_id
675
- )
676
- raw_results.append((lang, parser.grammar_id, parser.priority, preferred))
677
- raw_results.sort(key=lambda item: (not item[3], -item[2], item[0], item[1]))
678
- results: list[DetectionResult] = []
679
- for rank, (lang, grammar_id, _priority, _preferred) in enumerate(raw_results):
680
- results.append(
681
- DetectionResult(
682
- language=lang,
683
- grammar_id=grammar_id,
684
- confidence=round(1.0 / (rank + 1), 3),
685
- )
686
- )
687
- return results
682
+ import json
683
+ from intentumdiff.rust_core import _required_engine_json
684
+
685
+ parsers = self.parsers
686
+ request = {
687
+ "entries": [{"plugin_id": parser.plugin_id, "grammar_id": parser.grammar_id,
688
+ "languages": list(parser.language_ids), "priority": parser.priority}
689
+ for parser in parsers],
690
+ "content": content,
691
+ "allowed_plugins": self._config.allowed_plugins,
692
+ "candidates": candidates or [],
693
+ "preferred_plugins": preferred_plugins or {},
694
+ "plugin_id": plugin_id,
695
+ }
696
+ plan = _required_engine_json("content_detection_plan", json.dumps(request), result_type=dict)
697
+ # Loading and calling host adapters is I/O; probe eligibility and sample size
698
+ # come from Rust. Exceptions (including fuel exhaustion) propagate unchanged.
699
+ observations = [{"index": index,
700
+ "language": parsers[index].detect_language("", plan["sample"])}
701
+ for index in plan["indices"]]
702
+ outcome = _required_engine_json("content_detection_finish", json.dumps({
703
+ "request": request, "observations": observations,
704
+ }), result_type=dict)
705
+ if outcome["not_found"] is not None:
706
+ raise PluginNotFoundError(outcome["not_found"])
707
+ return [DetectionResult.model_validate(result) for result in outcome["results"]]
688
708
 
689
709
  def example_for(self, language: str, plugin_id: str | None = None) -> dict[str, str] | None:
690
710
  """Return the ``{old, new}`` playground example from the parser that
@@ -878,26 +898,6 @@ def _fallback_info_for_catalog(
878
898
  )
879
899
 
880
900
 
881
- def _entry_matches_filename(entry: _ParserCatalogEntry, filename: str) -> bool:
882
- if not filename:
883
- return False
884
- name = Path(filename).name.lower()
885
- full = filename.replace("\\", "/").lower()
886
- for language_id in entry.language_guesses:
887
- info = _fallback_info_for_catalog(entry, language_id)
888
- if name == info.default_filename.lower() or full.endswith(
889
- "/" + info.default_filename.lower()
890
- ):
891
- return True
892
- for extension in info.language_file_extensions:
893
- normalized = extension.lower()
894
- if normalized.startswith("."):
895
- if name.endswith(normalized):
896
- return True
897
- elif name == normalized:
898
- return True
899
- return False
900
-
901
901
 
902
902
  def _discover_parser_catalog(
903
903
  *,
@@ -913,7 +913,25 @@ def _discover_parser_catalog(
913
913
  if ep.name in _DISABLED_BUILTIN_PARSER_ENTRYPOINTS and _is_trusted_entry_point(ep):
914
914
  logger.debug("Skipping disabled first-party parser entry point: %s", ep.name)
915
915
  continue
916
- wasm_path = _wasm_path_from_ep(ep)
916
+ incompatible = arch_incompatible_reason(ep.name)
917
+ if incompatible is not None:
918
+ # A trusted staged replacement may now be compatible. Resolve
919
+ # its host path without compiling Wasm, then ask the same Rust
920
+ # policy again using its real SHA-256. On any error retain the
921
+ # original fail-closed exclusion and keep discovery silent.
922
+ try:
923
+ wasm_path = _wasm_path_from_ep(ep)
924
+ incompatible = arch_incompatible_reason(ep.name, wasm_path)
925
+ except Exception:
926
+ pass
927
+ if incompatible is not None:
928
+ logger.debug(
929
+ "Parser %r is unavailable on %s/%s: %s",
930
+ ep.name, platform.system(), platform.machine(), incompatible,
931
+ )
932
+ continue
933
+ else:
934
+ wasm_path = _wasm_path_from_ep(ep)
917
935
  resolved = str(Path(wasm_path).resolve())
918
936
  existing = by_path.get(resolved)
919
937
  if existing is not None:
@@ -961,10 +979,17 @@ def _add_first_party_parser_entrypoint_fallbacks(
961
979
  for name, callable_name in _FIRST_PARTY_PARSER_ENTRYPOINT_FALLBACKS.items():
962
980
  if name in existing_names:
963
981
  continue
982
+ # The SAME architecture gate as entry-point discovery. This fallback builds catalog
983
+ # entries directly from builtin callables, bypassing that path entirely - which is
984
+ # exactly how powershell kept reaching the catalog on Windows/aarch64 while the gate
985
+ # itself correctly reported "excluded". Two ways in, one of them guarded, is no guard.
964
986
  entry_callable = getattr(builtins, callable_name, None)
965
987
  if entry_callable is None:
966
988
  continue
967
989
  wasm_path = entry_callable()
990
+ if arch_incompatible_reason(name, wasm_path) is not None:
991
+ logger.debug("Fallback skipped for %r: unverified staged component on this platform", name)
992
+ continue
968
993
  if not Path(wasm_path).exists():
969
994
  continue
970
995
  resolved = str(Path(wasm_path).resolve())
@@ -1034,6 +1059,7 @@ def _load_parsers(
1034
1059
  def _load_renderers(fuel: int = 10_000_000) -> list[RendererAdapter]:
1035
1060
  """Discover and instantiate all registered renderer plugins."""
1036
1061
  adapters: list[RendererAdapter] = []
1062
+ failed: list[str] = []
1037
1063
  for ep in importlib.metadata.entry_points(group=_RENDERER_GROUP):
1038
1064
  try:
1039
1065
  wasm_path = _wasm_path_from_ep(ep)
@@ -1044,6 +1070,22 @@ def _load_renderers(fuel: int = 10_000_000) -> list[RendererAdapter]:
1044
1070
  logger.debug("Loaded renderer plugin: %s (%s)", ep.name, wasm_path)
1045
1071
  except Exception as exc:
1046
1072
  logger.warning("Failed to load renderer plugin %r: %s", ep.name, exc)
1073
+ failed.append(ep.name)
1074
+ # A renderer that fails to load used to be a warning and nothing else: the adapter was
1075
+ # simply omitted and every caller carried on with a smaller set. CI ran the whole suite
1076
+ # with ZERO renderers and reported green - each test touching --format html|patch|llm|
1077
+ # terminal was skipping, hitting a Python fallback, or asserting on degraded output, and
1078
+ # nothing distinguished those from real coverage (#22).
1079
+ #
1080
+ # Opt-in rather than always-on, because a user with a partial install should still get a
1081
+ # working diff - degrading is right for THEM and wrong for a gate. CI sets this so an
1082
+ # incomplete component set stops the run where the cause is legible.
1083
+ if failed and os.environ.get("INTENTUMDIFF_REQUIRE_ALL_COMPONENTS") == "1":
1084
+ raise PluginLoadError(
1085
+ f"{len(failed)} renderer plugin(s) failed to load: {', '.join(sorted(failed))}. "
1086
+ "INTENTUMDIFF_REQUIRE_ALL_COMPONENTS=1 is set, so an incomplete component set is "
1087
+ "an error rather than a silent downgrade - stage the components, or unset it."
1088
+ )
1047
1089
  return adapters
1048
1090
 
1049
1091
 
@@ -1059,7 +1101,12 @@ def _load_enrichers(fuel: int = 10_000_000) -> list[EnricherAdapter]:
1059
1101
  adapters.append(adapter)
1060
1102
  logger.debug("Loaded enricher plugin: %s (%s)", ep.name, wasm_path)
1061
1103
  except Exception as exc:
1062
- logger.warning("Failed to load enricher plugin %r: %s", ep.name, exc)
1104
+ # An installed extension that fails to load is not equivalent to an
1105
+ # absent extension. Continuing would certify incomplete semantics (#237).
1106
+ raise PluginLoadError(
1107
+ f"{_ENRICHER_GROUP}:{ep.name}",
1108
+ f"registered enricher failed to load: {exc}",
1109
+ ) from exc
1063
1110
  return adapters
1064
1111
 
1065
1112
 
@@ -1075,5 +1122,10 @@ def _load_diff_analyzers(fuel: int = 10_000_000) -> list[DiffAnalyzerAdapter]:
1075
1122
  adapters.append(adapter)
1076
1123
  logger.debug("Loaded diff-analyzer plugin: %s (%s)", ep.name, wasm_path)
1077
1124
  except Exception as exc:
1078
- logger.warning("Failed to load diff-analyzer plugin %r: %s", ep.name, exc)
1125
+ # Do not silently remove a registered semantic pass from the review
1126
+ # pipeline or treat a partial plugin set as a complete result (#236).
1127
+ raise PluginLoadError(
1128
+ f"{_DIFF_ANALYZER_GROUP}:{ep.name}",
1129
+ f"registered diff analyzer failed to load: {exc}",
1130
+ ) from exc
1079
1131
  return adapters