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.
- intentumdiff/__init__.py +2 -0
- intentumdiff/__main__.py +12 -0
- intentumdiff/_differ_presentation.py +35 -682
- intentumdiff/_differ_runtime.py +13 -47
- intentumdiff/analysis/compile_commands.py +26 -141
- intentumdiff/analysis/cross_file.py +2 -4
- intentumdiff/analysis/guardrail_reports.py +7 -5
- intentumdiff/analysis/guardrails.py +110 -122
- intentumdiff/analysis/invariances.py +4 -1003
- intentumdiff/analysis/schema_resolver.py +49 -273
- intentumdiff/analysis/text_review.py +4 -3
- intentumdiff/analysis/user_schemas.py +55 -237
- intentumdiff/api.py +21 -0
- intentumdiff/cache/sqlite_store.py +5 -23
- intentumdiff/cli/__init__.py +59 -0
- intentumdiff/cli/_commands.py +174 -67
- intentumdiff/cli/_parser.py +11 -1
- intentumdiff/cli/_shared.py +96 -112
- intentumdiff/content_type.py +13 -30
- intentumdiff/core/commit_differ.py +105 -220
- intentumdiff/core/diffignore.py +28 -34
- intentumdiff/core/index.py +16 -18
- intentumdiff/core/indexer.py +148 -168
- intentumdiff/core/models.py +53 -14
- intentumdiff/differ.py +278 -605
- intentumdiff/github_app.py +35 -19
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +180 -17
- intentumdiff/lsp/client.py +7 -1
- intentumdiff/lsp/enricher.py +19 -119
- intentumdiff/lsp/exceptions.py +6 -7
- intentumdiff/lsp_server/_codelens.py +24 -57
- intentumdiff/lsp_server/_diagnostics.py +23 -51
- intentumdiff/lsp_server/_handlers.py +66 -8
- intentumdiff/lsp_server/server.py +28 -7
- intentumdiff/plugins/adapter.py +5 -0
- intentumdiff/plugins/builtins.py +7 -14
- intentumdiff/plugins/exceptions.py +4 -0
- intentumdiff/plugins/hub.py +1 -2
- intentumdiff/plugins/loader.py +229 -215
- intentumdiff/plugins/registry.py +249 -197
- intentumdiff/rust_core.py +744 -784
- intentumdiff/serve/_app.py +3 -10
- intentumdiff/sources/base.py +24 -0
- intentumdiff/sources/file_source.py +15 -2
- intentumdiff/sources/git_source.py +120 -58
- intentumdiff/sources/live_buffer_source.py +45 -5
- intentumdiff/sources/patch_source.py +36 -109
- intentumdiff/vcs/_safe_path.py +7 -0
- intentumdiff/vcs/base.py +6 -0
- intentumdiff/vcs/git_backend.py +1 -1
- intentumdiff/vcs/git_cli.py +38 -18
- intentumdiff/vcs/hg_backend.py +1 -1
- intentumdiff/vcs/perforce_backend.py +7 -1
- intentumdiff/vcs/svn_backend.py +1 -1
- intentumdiff/wasm/abap_parser.wasm +0 -0
- intentumdiff/wasm/adf_parser.wasm +0 -0
- intentumdiff/wasm/asciidoc_parser.wasm +0 -0
- intentumdiff/wasm/asm_parser.wasm +0 -0
- intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
- intentumdiff/wasm/astro_parser.wasm +0 -0
- intentumdiff/wasm/bash_parser.wasm +0 -0
- intentumdiff/wasm/clojure_parser.wasm +0 -0
- intentumdiff/wasm/cmake_parser.wasm +0 -0
- intentumdiff/wasm/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/css_parser.wasm +0 -0
- intentumdiff/wasm/dart_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/delphi_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_parser.wasm +0 -0
- intentumdiff/wasm/elixir_parser.wasm +0 -0
- intentumdiff/wasm/freebasic_parser.wasm +0 -0
- intentumdiff/wasm/generic_parser.wasm +0 -0
- intentumdiff/wasm/gitignore_parser.wasm +0 -0
- intentumdiff/wasm/go_parser.wasm +0 -0
- intentumdiff/wasm/gomod_parser.wasm +0 -0
- intentumdiff/wasm/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_parser.wasm +0 -0
- intentumdiff/wasm/haskell_parser.wasm +0 -0
- intentumdiff/wasm/html_parser.wasm +0 -0
- intentumdiff/wasm/html_renderer.wasm +0 -0
- intentumdiff/wasm/ini_parser.wasm +0 -0
- intentumdiff/wasm/java_parser.wasm +0 -0
- intentumdiff/wasm/js_ts_parser.wasm +0 -0
- intentumdiff/wasm/json_parser.wasm +0 -0
- intentumdiff/wasm/kotlin_parser.wasm +0 -0
- intentumdiff/wasm/latex_parser.wasm +0 -0
- intentumdiff/wasm/llm_renderer.wasm +0 -0
- intentumdiff/wasm/lua_parser.wasm +0 -0
- intentumdiff/wasm/make_parser.wasm +0 -0
- intentumdiff/wasm/markdown_parser.wasm +0 -0
- intentumdiff/wasm/mdx_parser.wasm +0 -0
- intentumdiff/wasm/ocaml_parser.wasm +0 -0
- intentumdiff/wasm/odin_parser.wasm +0 -0
- intentumdiff/wasm/parser_manifest.json +81 -2
- intentumdiff/wasm/patch_renderer.wasm +0 -0
- intentumdiff/wasm/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/po_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/proto_parser.wasm +0 -0
- intentumdiff/wasm/puppet_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/r_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/ruby_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/scala_parser.wasm +0 -0
- intentumdiff/wasm/scss_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/squirrel_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_parser.wasm +0 -0
- intentumdiff/wasm/terminal_renderer.wasm +0 -0
- intentumdiff/wasm/terraform_parser.wasm +0 -0
- intentumdiff/wasm/toml_parser.wasm +0 -0
- intentumdiff/wasm/tsql_parser.wasm +0 -0
- intentumdiff/wasm/vbnet_parser.wasm +0 -0
- intentumdiff/wasm/vue_parser.wasm +0 -0
- intentumdiff/wasm/wasm_provenance.json +884 -0
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/xml_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/wasm/zig_parser.wasm +0 -0
- intentumdiff_python-0.0.2b2.dist-info/METADATA +156 -0
- intentumdiff_python-0.0.2b2.dist-info/RECORD +171 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/WHEEL +1 -1
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
- intentumdiff/core/cst_serializer.py +0 -101
- intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
- intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.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
|
|
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,18 +36,15 @@ 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
|
|
47
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
51
48
|
|
|
52
49
|
logger = logging.getLogger(__name__)
|
|
53
50
|
|
|
@@ -119,15 +116,10 @@ def user_schemas_enabled(env: Mapping[str, str] | None = None) -> bool:
|
|
|
119
116
|
}
|
|
120
117
|
|
|
121
118
|
|
|
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
119
|
def load_user_schema_profiles(
|
|
128
120
|
env: Mapping[str, str] | None = None,
|
|
129
121
|
) -> tuple[tuple[UserSchemaProfile, ...], tuple[str, ...]]:
|
|
130
|
-
"""Load
|
|
122
|
+
"""Load and validate every registered descriptor.
|
|
131
123
|
|
|
132
124
|
Returns ``(profiles, errors)``. A descriptor file that fails validation
|
|
133
125
|
contributes an error message and NO profiles (fail closed, never partially
|
|
@@ -142,91 +134,54 @@ def load_user_schema_profiles(
|
|
|
142
134
|
for entry in sorted(directory.iterdir()):
|
|
143
135
|
if entry.suffix.lower() in _DESCRIPTOR_SUFFIXES and entry.is_file():
|
|
144
136
|
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
137
|
profiles: list[UserSchemaProfile] = []
|
|
155
138
|
errors: list[str] = []
|
|
156
|
-
seen_ids: dict[str, str] = {}
|
|
157
139
|
for path in files:
|
|
158
140
|
loaded, file_errors = _load_descriptor_file(path)
|
|
159
141
|
if file_errors:
|
|
160
142
|
errors.extend(file_errors)
|
|
161
143
|
continue
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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)
|
|
144
|
+
profiles.extend(loaded)
|
|
145
|
+
selected = _schema_operation("select_unique", profiles=[_profile_payload(p) for p in profiles])
|
|
146
|
+
profiles = [profiles[index] for index in selected]
|
|
175
147
|
for message in errors:
|
|
176
148
|
logger.warning("user schema descriptor rejected: %s", message)
|
|
177
149
|
result = (tuple(profiles), tuple(errors))
|
|
178
|
-
_CACHE[key] = result
|
|
179
150
|
return result
|
|
180
151
|
|
|
181
152
|
|
|
153
|
+
def _profile_payload(profile: UserSchemaProfile) -> dict[str, Any]:
|
|
154
|
+
value = asdict(profile)
|
|
155
|
+
value["identity_fields"] = sorted(profile.identity_fields)
|
|
156
|
+
return value
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _schema_operation(operation: str, **payload: Any) -> Any:
|
|
160
|
+
return _c_abi_call("schema_profiles", json.dumps({"operation": operation, **payload}))
|
|
161
|
+
|
|
162
|
+
|
|
182
163
|
def match_user_profile(
|
|
183
|
-
profiles: tuple[UserSchemaProfile, ...],
|
|
184
|
-
*,
|
|
185
|
-
filename: str,
|
|
186
|
-
content: str,
|
|
164
|
+
profiles: tuple[UserSchemaProfile, ...], *, filename: str, content: str,
|
|
187
165
|
declared_url: str | None = None,
|
|
188
166
|
) -> UserSchemaProfile | None:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
|
167
|
+
index = _schema_operation(
|
|
168
|
+
"match", profiles=[_profile_payload(p) for p in profiles], filename=filename,
|
|
169
|
+
content=content, declared_url=declared_url,
|
|
219
170
|
)
|
|
171
|
+
return profiles[index] if index is not None else None
|
|
220
172
|
|
|
221
173
|
|
|
222
174
|
def _load_descriptor_file(
|
|
223
175
|
path: Path,
|
|
224
176
|
) -> tuple[tuple[UserSchemaProfile, ...], tuple[str, ...]]:
|
|
225
177
|
try:
|
|
226
|
-
raw_text = path.
|
|
227
|
-
documents = [doc for doc in yaml.safe_load_all(raw_text) if doc is not None]
|
|
178
|
+
raw_text = path.read_bytes().decode("utf-8")
|
|
228
179
|
except Exception as exc: # noqa: BLE001 - any parse failure fails the file closed
|
|
229
180
|
return ((), (f"{path}: unreadable descriptor ({exc})",))
|
|
181
|
+
parsed = _schema_operation("parse_documents", raw_text=raw_text)
|
|
182
|
+
if parsed["error"]:
|
|
183
|
+
return (), (f"{path}: unreadable descriptor ({parsed['error']})",)
|
|
184
|
+
documents = parsed["documents"]
|
|
230
185
|
profiles: list[UserSchemaProfile] = []
|
|
231
186
|
errors: list[str] = []
|
|
232
187
|
for index, document in enumerate(documents):
|
|
@@ -244,173 +199,36 @@ def _load_descriptor_file(
|
|
|
244
199
|
|
|
245
200
|
|
|
246
201
|
def _validate_descriptor(
|
|
247
|
-
document: Any,
|
|
248
|
-
path: Path,
|
|
249
|
-
index: int,
|
|
250
|
-
raw_text: str,
|
|
202
|
+
document: Any, path: Path, index: int, raw_text: str,
|
|
251
203
|
) -> tuple[UserSchemaProfile | None, tuple[str, ...]]:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
|
204
|
+
# Filesystem access stays in the host. The engine validates the descriptor
|
|
205
|
+
# and supplied schema contents and derives all profile/identity fields.
|
|
206
|
+
schema = None
|
|
207
|
+
schema_path = None
|
|
208
|
+
schema_raw = None
|
|
209
|
+
schema_ref = document.get("schema") if isinstance(document, dict) else None
|
|
210
|
+
if isinstance(schema_ref, str) and schema_ref.strip():
|
|
211
|
+
resolved = (path.parent / schema_ref).resolve()
|
|
212
|
+
try:
|
|
213
|
+
schema_raw = resolved.read_bytes().decode("utf-8")
|
|
214
|
+
schema = json.loads(schema_raw)
|
|
215
|
+
schema_path = str(resolved)
|
|
216
|
+
except FileNotFoundError:
|
|
217
|
+
return None, (f"{path}#{index}: schema file not found: {resolved}",)
|
|
218
|
+
except Exception as exc: # noqa: BLE001 - host read/decode error
|
|
219
|
+
return None, (f"{path}#{index}: schema file unreadable ({exc})",)
|
|
220
|
+
result = _schema_operation(
|
|
221
|
+
"validate", document=document, path=str(path), index=index, raw_text=raw_text,
|
|
222
|
+
schema=schema, schema_path=schema_path, schema_raw=schema_raw,
|
|
338
223
|
)
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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)
|
|
224
|
+
if result["errors"]:
|
|
225
|
+
return None, tuple(result["errors"])
|
|
226
|
+
value = result["profile"]
|
|
227
|
+
for key in ("filename_patterns", "root_markers", "schema_urls", "important_paths", "scaffold_paths"):
|
|
228
|
+
value[key] = tuple(value[key])
|
|
229
|
+
value["identity_fields"] = frozenset(value["identity_fields"])
|
|
230
|
+
value["keyed_elements"] = {tag: tuple(fields) for tag, fields in value["keyed_elements"].items()}
|
|
231
|
+
return UserSchemaProfile(**value), ()
|
|
414
232
|
|
|
415
233
|
|
|
416
234
|
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
|
-
"""
|
|
104
|
-
|
|
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
|
-
|
|
111
|
-
table, language, since, before, min_size, max_size, limit, file_glob
|
|
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)
|
intentumdiff/cli/__init__.py
CHANGED
|
@@ -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
|
|