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
@@ -28,7 +28,7 @@ A descriptor registers one of three modes (all offline-first):
28
28
  ``$schema`` URL so internal dialects resolve **offline** instead of via the
29
29
  guarded fetch path.
30
30
 
31
- The registry is thin shell + config: descriptors are validated here and their
31
+ The registry is thin shell + config: descriptors are validated in the shared Rust engine and their
32
32
  identity fields are marshaled through the existing ``SchemaResolution`` channel
33
33
  into the Rust core's keyed matching. Malformed descriptors fail closed — the
34
34
  whole file is rejected with a clear error and built-in resolution proceeds.
@@ -36,41 +36,23 @@ whole file is rejected with a clear error and built-in resolution proceeds.
36
36
 
37
37
  from __future__ import annotations
38
38
 
39
- import fnmatch
40
- import hashlib
41
39
  import json
42
40
  import logging
43
41
  import os
44
- import re
45
42
  from collections.abc import Mapping
46
- from dataclasses import dataclass, field
43
+ from dataclasses import asdict, dataclass, field
47
44
  from pathlib import Path
48
45
  from typing import Any
49
46
 
50
- import yaml
47
+ from intentumdiff.rust_core import _c_abi_call
51
48
 
52
49
  logger = logging.getLogger(__name__)
53
50
 
54
51
  USER_SCHEMA_DIR_ENV = "INTENTUMDIFF_USER_SCHEMA_DIR"
55
52
  USER_SCHEMAS_TOGGLE_ENV = "INTENTUMDIFF_USER_SCHEMAS"
56
53
 
57
- # Provider-id roots owned by built-in detection; a registered language_id must
58
- # not collide with these (the invariance guard from issue #63's acceptance).
59
- BUILTIN_PROVIDER_ROOTS = frozenset(
60
- {
61
- "adf",
62
- "azure-pipelines",
63
- "databricks",
64
- "dbt",
65
- "embedded",
66
- "github-actions",
67
- "kubernetes",
68
- "none",
69
- "openapi",
70
- "user",
71
- }
72
- )
73
-
54
+ # Built-in provider roots (and the collision rule for registered language ids) are owned
55
+ # by core `schema_profiles` "validate" (#298).
74
56
  _DESCRIPTOR_SUFFIXES = (".yml", ".yaml", ".json")
75
57
 
76
58
 
@@ -119,15 +101,10 @@ def user_schemas_enabled(env: Mapping[str, str] | None = None) -> bool:
119
101
  }
120
102
 
121
103
 
122
- # Cache keyed by a stat snapshot of every descriptor file, so edits (and test
123
- # tmp dirs) invalidate naturally without a process restart.
124
- _CACHE: dict[tuple[Any, ...], tuple[tuple[UserSchemaProfile, ...], tuple[str, ...]]] = {}
125
-
126
-
127
104
  def load_user_schema_profiles(
128
105
  env: Mapping[str, str] | None = None,
129
106
  ) -> tuple[tuple[UserSchemaProfile, ...], tuple[str, ...]]:
130
- """Load, validate, and cache every registered descriptor.
107
+ """Load and validate every registered descriptor.
131
108
 
132
109
  Returns ``(profiles, errors)``. A descriptor file that fails validation
133
110
  contributes an error message and NO profiles (fail closed, never partially
@@ -142,91 +119,54 @@ def load_user_schema_profiles(
142
119
  for entry in sorted(directory.iterdir()):
143
120
  if entry.suffix.lower() in _DESCRIPTOR_SUFFIXES and entry.is_file():
144
121
  files.append(entry)
145
- key = tuple(
146
- (str(path), stat.st_mtime_ns, stat.st_size)
147
- for path in files
148
- for stat in (path.stat(),)
149
- )
150
- cached = _CACHE.get(key)
151
- if cached is not None:
152
- return cached
153
-
154
122
  profiles: list[UserSchemaProfile] = []
155
123
  errors: list[str] = []
156
- seen_ids: dict[str, str] = {}
157
124
  for path in files:
158
125
  loaded, file_errors = _load_descriptor_file(path)
159
126
  if file_errors:
160
127
  errors.extend(file_errors)
161
128
  continue
162
- for profile in loaded:
163
- if profile.language_id in seen_ids:
164
- # First registration wins (project dir precedes home dir).
165
- if seen_ids[profile.language_id] != str(path):
166
- logger.warning(
167
- "user schema %r in %s shadowed by earlier registration in %s",
168
- profile.language_id,
169
- path,
170
- seen_ids[profile.language_id],
171
- )
172
- continue
173
- seen_ids[profile.language_id] = str(path)
174
- profiles.append(profile)
129
+ profiles.extend(loaded)
130
+ selected = _schema_operation("select_unique", profiles=[_profile_payload(p) for p in profiles])
131
+ profiles = [profiles[index] for index in selected]
175
132
  for message in errors:
176
133
  logger.warning("user schema descriptor rejected: %s", message)
177
134
  result = (tuple(profiles), tuple(errors))
178
- _CACHE[key] = result
179
135
  return result
180
136
 
181
137
 
138
+ def _profile_payload(profile: UserSchemaProfile) -> dict[str, Any]:
139
+ value = asdict(profile)
140
+ value["identity_fields"] = sorted(profile.identity_fields)
141
+ return value
142
+
143
+
144
+ def _schema_operation(operation: str, **payload: Any) -> Any:
145
+ return _c_abi_call("schema_profiles", json.dumps({"operation": operation, **payload}))
146
+
147
+
182
148
  def match_user_profile(
183
- profiles: tuple[UserSchemaProfile, ...],
184
- *,
185
- filename: str,
186
- content: str,
149
+ profiles: tuple[UserSchemaProfile, ...], *, filename: str, content: str,
187
150
  declared_url: str | None = None,
188
151
  ) -> UserSchemaProfile | None:
189
- """First profile claiming the document, by declared ``$schema`` URL first
190
- (mode 3), then filename patterns / root markers (modes 1 and 2)."""
191
- if declared_url:
192
- for profile in profiles:
193
- if declared_url in profile.schema_urls:
194
- return profile
195
- normalized_path = filename.replace("\\", "/").lower()
196
- basename = normalized_path.rsplit("/", 1)[-1]
197
- for profile in profiles:
198
- if profile.filename_patterns:
199
- if not any(
200
- fnmatch.fnmatch(basename, pattern) or fnmatch.fnmatch(normalized_path, pattern)
201
- for pattern in profile.filename_patterns
202
- ):
203
- continue
204
- if _root_markers_match(profile.root_markers, content):
205
- return profile
206
- elif profile.root_markers and _root_markers_match(profile.root_markers, content):
207
- return profile
208
- return None
209
-
210
-
211
- def _root_markers_match(markers: tuple[str, ...], content: str) -> bool:
212
- """Heuristic top-level-key check, consistent with the built-in provider
213
- detectors (regex over raw text — no full parse on the hot path)."""
214
- if not markers:
215
- return True
216
- return all(
217
- re.search(rf'^\s*"?{re.escape(marker)}"?\s*:', content, re.MULTILINE)
218
- for marker in markers
152
+ index = _schema_operation(
153
+ "match", profiles=[_profile_payload(p) for p in profiles], filename=filename,
154
+ content=content, declared_url=declared_url,
219
155
  )
156
+ return profiles[index] if index is not None else None
220
157
 
221
158
 
222
159
  def _load_descriptor_file(
223
160
  path: Path,
224
161
  ) -> tuple[tuple[UserSchemaProfile, ...], tuple[str, ...]]:
225
162
  try:
226
- raw_text = path.read_text(encoding="utf-8")
227
- documents = [doc for doc in yaml.safe_load_all(raw_text) if doc is not None]
163
+ raw_text = path.read_bytes().decode("utf-8")
228
164
  except Exception as exc: # noqa: BLE001 - any parse failure fails the file closed
229
165
  return ((), (f"{path}: unreadable descriptor ({exc})",))
166
+ parsed = _schema_operation("parse_documents", raw_text=raw_text)
167
+ if parsed["error"]:
168
+ return (), (f"{path}: unreadable descriptor ({parsed['error']})",)
169
+ documents = parsed["documents"]
230
170
  profiles: list[UserSchemaProfile] = []
231
171
  errors: list[str] = []
232
172
  for index, document in enumerate(documents):
@@ -244,173 +184,36 @@ def _load_descriptor_file(
244
184
 
245
185
 
246
186
  def _validate_descriptor(
247
- document: Any,
248
- path: Path,
249
- index: int,
250
- raw_text: str,
187
+ document: Any, path: Path, index: int, raw_text: str,
251
188
  ) -> tuple[UserSchemaProfile | None, tuple[str, ...]]:
252
- where = f"{path}#{index}"
253
- if not isinstance(document, dict):
254
- return (None, (f"{where}: descriptor must be a mapping",))
255
- errors: list[str] = []
256
-
257
- language_id = document.get("language_id")
258
- if not isinstance(language_id, str) or not language_id.strip():
259
- errors.append(f"{where}: 'language_id' is required and must be a string")
260
- language_id = ""
261
- else:
262
- language_id = language_id.strip()
263
- root = language_id.split(":", 1)[0].lower()
264
- if root in BUILTIN_PROVIDER_ROOTS:
265
- errors.append(
266
- f"{where}: language_id {language_id!r} collides with the "
267
- f"built-in provider root {root!r}"
268
- )
269
-
270
- match = document.get("match") or {}
271
- if not isinstance(match, dict):
272
- errors.append(f"{where}: 'match' must be a mapping")
273
- match = {}
274
- filename_patterns = _string_tuple(
275
- match.get("filename_patterns"), f"{where}: match.filename_patterns", errors
276
- )
277
- root_markers = _string_tuple(match.get("root_markers"), f"{where}: match.root_markers", errors)
278
- schema_urls = _string_tuple(match.get("schema_urls"), f"{where}: match.schema_urls", errors)
279
- namespace = match.get("namespace")
280
- if namespace is not None and (not isinstance(namespace, str) or not namespace.strip()):
281
- errors.append(f"{where}: match.namespace must be a non-empty string")
282
- namespace = None
283
- root_element = match.get("root_element")
284
- if root_element is not None and (not isinstance(root_element, str) or not root_element.strip()):
285
- errors.append(f"{where}: match.root_element must be a non-empty string")
286
- root_element = None
287
- has_match = (
288
- filename_patterns or root_markers or schema_urls or namespace or root_element
289
- )
290
- if not has_match:
291
- errors.append(f"{where}: 'match' needs filename_patterns, root_markers, or schema_urls")
292
-
293
- identity: set[str] = set(
294
- _string_tuple(document.get("identity_fields"), f"{where}: identity_fields", errors)
295
- )
296
- keyed_arrays = document.get("keyed_arrays") or {}
297
- if not isinstance(keyed_arrays, dict):
298
- errors.append(f"{where}: 'keyed_arrays' must be a mapping of path -> identity fields")
299
- keyed_arrays = {}
300
- for array_path, key_fields in keyed_arrays.items():
301
- fields = key_fields if isinstance(key_fields, list) else [key_fields]
302
- for key_field in fields:
303
- if not isinstance(key_field, str) or not key_field.strip():
304
- errors.append(f"{where}: keyed_arrays[{array_path!r}] entries must be strings")
305
- else:
306
- identity.add(key_field.strip())
307
-
308
- keyed_elements: dict[str, tuple[str, ...]] = {}
309
- raw_keyed_elements = document.get("keyed_elements") or {}
310
- if not isinstance(raw_keyed_elements, dict):
311
- errors.append(f"{where}: 'keyed_elements' must be a mapping of element tag -> key fields")
312
- raw_keyed_elements = {}
313
- for tag, key_fields in raw_keyed_elements.items():
314
- fields = key_fields if isinstance(key_fields, list) else [key_fields]
315
- clean: list[str] = []
316
- for key_field in fields:
317
- if not isinstance(key_field, str) or not key_field.strip():
318
- errors.append(f"{where}: keyed_elements[{tag!r}] entries must be strings")
319
- else:
320
- clean.append(key_field.strip())
321
- if not isinstance(tag, str) or not tag.strip():
322
- errors.append(f"{where}: keyed_elements tags must be strings")
323
- elif clean:
324
- keyed_elements[tag.strip()] = tuple(clean)
325
- if keyed_elements and not namespace and not root_element:
326
- # The engine-side dialect predicate matches by namespace/root element -
327
- # filename alone cannot reach the Rust matcher. Fail closed.
328
- errors.append(
329
- f"{where}: an XML dialect (keyed_elements) needs match.namespace "
330
- "or match.root_element"
331
- )
332
-
333
- important_paths = _string_tuple(
334
- document.get("important_paths"), f"{where}: important_paths", errors
335
- )
336
- scaffold_paths = _string_tuple(
337
- document.get("scaffold_paths"), f"{where}: scaffold_paths", errors
189
+ # Filesystem access stays in the host. The engine validates the descriptor
190
+ # and supplied schema contents and derives all profile/identity fields.
191
+ schema = None
192
+ schema_path = None
193
+ schema_raw = None
194
+ schema_ref = document.get("schema") if isinstance(document, dict) else None
195
+ if isinstance(schema_ref, str) and schema_ref.strip():
196
+ resolved = (path.parent / schema_ref).resolve()
197
+ try:
198
+ schema_raw = resolved.read_bytes().decode("utf-8")
199
+ schema = json.loads(schema_raw)
200
+ schema_path = str(resolved)
201
+ except FileNotFoundError:
202
+ return None, (f"{path}#{index}: schema file not found: {resolved}",)
203
+ except Exception as exc: # noqa: BLE001 - host read/decode error
204
+ return None, (f"{path}#{index}: schema file unreadable ({exc})",)
205
+ result = _schema_operation(
206
+ "validate", document=document, path=str(path), index=index, raw_text=raw_text,
207
+ schema=schema, schema_path=schema_path, schema_raw=schema_raw,
338
208
  )
339
-
340
- schema_dict: dict[str, Any] | None = None
341
- schema_path: str | None = None
342
- schema_ref = document.get("schema")
343
- if schema_ref is not None:
344
- if not isinstance(schema_ref, str) or not schema_ref.strip():
345
- errors.append(f"{where}: 'schema' must be a local file path")
346
- else:
347
- resolved = (path.parent / schema_ref).resolve()
348
- try:
349
- loaded = json.loads(resolved.read_text(encoding="utf-8"))
350
- except FileNotFoundError:
351
- errors.append(f"{where}: schema file not found: {resolved}")
352
- loaded = None
353
- except Exception as exc: # noqa: BLE001
354
- errors.append(f"{where}: schema file unreadable ({exc})")
355
- loaded = None
356
- if loaded is not None:
357
- if not isinstance(loaded, dict):
358
- errors.append(f"{where}: schema file must contain a JSON object")
359
- else:
360
- schema_dict = loaded
361
- schema_path = str(resolved)
362
- # Same conservative hint extraction the resolver applies to
363
- # remote provider schemas — local, no fetch.
364
- from intentumdiff.analysis.schema_resolver import derive_identity_fields
365
-
366
- identity |= derive_identity_fields(loaded)
367
-
368
- if not identity and not keyed_elements:
369
- errors.append(
370
- f"{where}: no identity source — provide identity_fields, keyed_arrays, "
371
- "or a local schema that yields identity hints"
372
- )
373
- if errors:
374
- return (None, tuple(errors))
375
-
376
- digest = hashlib.sha256()
377
- digest.update(raw_text.encode("utf-8"))
378
- if schema_path:
379
- digest.update(Path(schema_path).read_bytes())
380
- return (
381
- UserSchemaProfile(
382
- language_id=language_id,
383
- source_path=str(path),
384
- filename_patterns=filename_patterns,
385
- root_markers=root_markers,
386
- schema_urls=schema_urls,
387
- identity_fields=frozenset(identity),
388
- important_paths=important_paths,
389
- scaffold_paths=scaffold_paths,
390
- schema=schema_dict,
391
- schema_path=schema_path,
392
- keyed_elements=keyed_elements,
393
- namespace=namespace.strip() if isinstance(namespace, str) else None,
394
- root_element=root_element.strip() if isinstance(root_element, str) else None,
395
- fingerprint=f"user:{language_id}:{digest.hexdigest()[:16]}",
396
- ),
397
- (),
398
- )
399
-
400
-
401
- def _string_tuple(value: Any, where: str, errors: list[str]) -> tuple[str, ...]:
402
- if value is None:
403
- return ()
404
- if not isinstance(value, list):
405
- errors.append(f"{where} must be a list of strings")
406
- return ()
407
- result: list[str] = []
408
- for item in value:
409
- if not isinstance(item, str) or not item.strip():
410
- errors.append(f"{where} entries must be non-empty strings")
411
- else:
412
- result.append(item.strip())
413
- return tuple(result)
209
+ if result["errors"]:
210
+ return None, tuple(result["errors"])
211
+ value = result["profile"]
212
+ for key in ("filename_patterns", "root_markers", "schema_urls", "important_paths", "scaffold_paths"):
213
+ value[key] = tuple(value[key])
214
+ value["identity_fields"] = frozenset(value["identity_fields"])
215
+ value["keyed_elements"] = {tag: tuple(fields) for tag, fields in value["keyed_elements"].items()}
216
+ return UserSchemaProfile(**value), ()
414
217
 
415
218
 
416
219
  def user_xml_dialects_payload(
intentumdiff/api.py ADDED
@@ -0,0 +1,21 @@
1
+ """Thin public adapters for complete shared-engine operations."""
2
+ from __future__ import annotations
3
+ from intentumdiff.core.models import SemanticDiff
4
+
5
+
6
+ def review_text(old: str, new: str, *, filename: str = 'document.txt',
7
+ new_filename: str | None = None) -> SemanticDiff:
8
+ """Review plain text or Markdown without loading parser components.
9
+
10
+ Use SemanticDiffer for language-aware parsing. Rust owns all comparison,
11
+ Markdown reconciliation, source evidence, and lifecycle decisions here.
12
+ """
13
+ from intentumdiff.rust_core import _c_abi_call, _require_complete_batch_diff_dto
14
+
15
+ # Rust owns the authoritative change inventory and semantic flags. Check
16
+ # transport completeness before Pydantic can apply no-change defaults.
17
+ response = _c_abi_call(
18
+ 'review_text', old, new, filename,
19
+ filename if new_filename is None else new_filename,
20
+ )
21
+ return SemanticDiff.model_validate(_require_complete_batch_diff_dto(response))
@@ -100,30 +100,12 @@ class SqliteCacheStore(CacheStore):
100
100
  max_size: int | None = None,
101
101
  limit: int = 50,
102
102
  ) -> list[dict]:
103
- """Metadata rows (no BLOBs) with optional filters. The ``file_glob`` filter
104
- is applied here (fnmatch) over an over-fetched result set, matching the
105
- retired Python behaviour and keeping the glob off the SQL surface."""
106
- # Validate before crossing the FFI boundary so a bad limit is a ValueError
107
- # (matching the retired Python), not a pyo3 TypeError on the i64 argument.
108
- if not isinstance(limit, int) or limit < 1:
103
+ """Return metadata selected and limited by Rust (case-sensitive filename glob)."""
104
+ if not isinstance(limit, int) or isinstance(limit, bool) or limit < 1:
109
105
  raise ValueError("limit must be a positive integer")
110
- raw = self._rust.list_entries(
111
- table, language, since, before, min_size, max_size, limit, file_glob is not None
112
- )
113
- entries = json.loads(raw)
114
- if file_glob and table == "diff_cache":
115
- import fnmatch # noqa: PLC0415
116
-
117
- filtered: list[dict] = []
118
- for entry in entries:
119
- if fnmatch.fnmatch(
120
- entry.get("old_filename", ""), file_glob
121
- ) or fnmatch.fnmatch(entry.get("new_filename", ""), file_glob):
122
- filtered.append(entry)
123
- if len(filtered) >= limit:
124
- break
125
- return filtered
126
- return entries[:limit]
106
+ return json.loads(self._rust.list_entries_filtered(
107
+ table, language, since, before, min_size, max_size, limit, file_glob
108
+ ))
127
109
 
128
110
  def get_entry_metadata(self, key: str, table: str) -> dict | None:
129
111
  raw = self._rust.get_entry_metadata(key, table)
@@ -17,6 +17,8 @@ Formats: terminal (default), terminal-color, json, patch, html, llm
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
+ import sys
21
+ from contextlib import suppress
20
22
  from typing import NoReturn
21
23
 
22
24
  from intentumdiff.cli._commands import ( # noqa: F401
@@ -191,7 +193,64 @@ __all__ = [
191
193
  ]
192
194
 
193
195
 
196
+ #: The pre-rebrand distribution. Installing IntentumDiff does not remove it, because pip
197
+ #: treats a renamed project as an unrelated package.
198
+ _RETIRED_DISTRIBUTION = "intentdiff"
199
+
200
+
201
+ def _warn_if_retired_distribution_installed() -> None:
202
+ """
203
+ Warn when the pre-rebrand ``intentdiff`` distribution is installed alongside this one.
204
+
205
+ Both projects install the same ``intentumdiff`` import package, so whichever pip laid down
206
+ last wins and the resolved distribution name may be the retired one — which is NOT in the
207
+ first-party trust allowlist. Every bundled parser is then rejected as untrusted third-party
208
+ code, and the user sees a stream of ``native_fallback`` errors and no diff at all.
209
+
210
+ Nothing in that chain names the actual cause, and the failure is total rather than partial,
211
+ so it reads as "the tool is broken" rather than "you have two installs". This is the same
212
+ defect class that made 0.0.1 unusable: a package failing its own trust check because of how
213
+ its distribution name resolves.
214
+ """
215
+ try:
216
+ from importlib.metadata import distribution
217
+
218
+ distribution(_RETIRED_DISTRIBUTION)
219
+ except Exception: # noqa: BLE001 - absence is the normal case, and any lookup failure is fine
220
+ return
221
+ _err.print(
222
+ f"[yellow]Warning:[/yellow] the retired '{_RETIRED_DISTRIBUTION}' distribution is "
223
+ "installed alongside IntentumDiff. They share an import package, so parsers may be "
224
+ f"rejected as untrusted and diffs may fail. Run: pip uninstall {_RETIRED_DISTRIBUTION}"
225
+ )
226
+
227
+
228
+ def _use_utf8_streams() -> None:
229
+ """Make stdout/stderr able to carry the characters we actually emit.
230
+
231
+ On Windows a non-redirected console is cp1252, and we emit U+2192 (the arrow in
232
+ "old -> new"), spinner glyphs, and box-drawing characters. Writing any of them raises:
233
+
234
+ UnicodeEncodeError: 'charmap' codec can't encode character '→'
235
+
236
+ Observed as: `--format llm` failing outright, `intentumdiff index` dying with a charmap
237
+ error that masked "not a git repository", and mojibake in `plugins list` and the
238
+ token-level-fallback warning. One cause, four symptoms.
239
+
240
+ errors="replace" rather than strict: a console that genuinely cannot represent a glyph
241
+ should show a placeholder, never abort a completed diff. The results were correct; only
242
+ the printing failed.
243
+ """
244
+ for stream in (sys.stdout, sys.stderr):
245
+ reconfigure = getattr(stream, "reconfigure", None)
246
+ if reconfigure is not None: # not present when the stream is replaced in tests
247
+ with suppress(Exception):
248
+ reconfigure(encoding="utf-8", errors="replace")
249
+
250
+
194
251
  def main(argv: list[str] | None = None) -> NoReturn:
252
+ _use_utf8_streams()
253
+ _warn_if_retired_distribution_installed()
195
254
  _legacy_click_main(argv)
196
255
 
197
256