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.
- intentumdiff/__init__.py +9 -0
- intentumdiff/__main__.py +12 -0
- intentumdiff/_differ_gate.py +0 -136
- intentumdiff/_differ_presentation.py +17 -735
- intentumdiff/_differ_runtime.py +13 -64
- intentumdiff/analysis/compile_commands.py +26 -141
- intentumdiff/analysis/cross_file.py +23 -25
- intentumdiff/analysis/diagnostics.py +1 -164
- intentumdiff/analysis/guardrail_reports.py +31 -33
- intentumdiff/analysis/guardrails.py +111 -188
- intentumdiff/analysis/schema_resolver.py +72 -360
- intentumdiff/analysis/user_schemas.py +57 -254
- intentumdiff/api.py +21 -0
- intentumdiff/cache/sqlite_store.py +5 -23
- intentumdiff/cli/__init__.py +59 -0
- intentumdiff/cli/_commands.py +243 -137
- intentumdiff/cli/_parser.py +51 -56
- intentumdiff/cli/_shared.py +151 -116
- intentumdiff/content_type.py +13 -30
- intentumdiff/core/commit_differ.py +137 -286
- intentumdiff/core/diffignore.py +28 -34
- intentumdiff/core/index.py +16 -18
- intentumdiff/core/indexer.py +148 -169
- intentumdiff/core/models.py +279 -83
- intentumdiff/differ.py +366 -1000
- intentumdiff/github_app.py +40 -27
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +197 -34
- intentumdiff/lsp/client.py +49 -43
- intentumdiff/lsp/enricher.py +19 -119
- intentumdiff/lsp/exceptions.py +6 -7
- intentumdiff/lsp/servers.py +10 -11
- intentumdiff/lsp_server/_codelens.py +24 -57
- intentumdiff/lsp_server/_diagnostics.py +23 -51
- intentumdiff/lsp_server/_handlers.py +67 -9
- intentumdiff/lsp_server/server.py +28 -8
- intentumdiff/plugins/adapter.py +5 -0
- intentumdiff/plugins/builtins.py +7 -14
- intentumdiff/plugins/exceptions.py +28 -0
- intentumdiff/plugins/hub.py +39 -43
- intentumdiff/plugins/loader.py +229 -215
- intentumdiff/plugins/registry.py +259 -207
- intentumdiff/plugins/registry.schema.json +156 -15
- intentumdiff/plugins/registry_schema.py +47 -140
- intentumdiff/rust_core.py +623 -1326
- intentumdiff/serve/_app.py +26 -35
- intentumdiff/sources/base.py +24 -0
- intentumdiff/sources/file_source.py +15 -2
- intentumdiff/sources/git_source.py +64 -185
- 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 +0 -27
- 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/watcher.py +15 -17
- intentumdiff_python-0.0.3b1.dist-info/METADATA +188 -0
- intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +1 -1
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
- intentumdiff/analysis/invariances.py +0 -1207
- intentumdiff/analysis/keyed_profiles.py +0 -25
- intentumdiff/analysis/resource_profiles.py +0 -14
- intentumdiff/analysis/text_review.py +0 -46
- intentumdiff/core/cst_serializer.py +0 -101
- intentumdiff/invariances/__init__.py +0 -2
- intentumdiff/invariances/rules.schema.json +0 -283
- intentumdiff/invariances/rules.yaml +0 -349
- 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.3b1.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
intentumdiff/core/index.py
CHANGED
|
@@ -17,9 +17,7 @@ repository snapshot (or any other collection of files). It provides:
|
|
|
17
17
|
The heavy lifting (symbol-table + reference-table extraction) is delegated to
|
|
18
18
|
the Rust core (``index-engine-lib``, via the native ``build_symbol_table_json``
|
|
19
19
|
/ ``build_reference_table_json`` entrypoints). Rust is authoritative — the
|
|
20
|
-
former pure-Python extraction mirror was deleted (#91);
|
|
21
|
-
tables are simply empty ("if Python didn't exist, the engine still lives in
|
|
22
|
-
Rust"). Cross-file diffing lives in ``intentumdiff.analysis.cross_file``, also a
|
|
20
|
+
former pure-Python extraction mirror was deleted (#91); engine failures raise instead of manufacturing empty tables. Cross-file diffing lives in ``intentumdiff.analysis.cross_file``, also a
|
|
23
21
|
thin wrapper over the same Rust core.
|
|
24
22
|
"""
|
|
25
23
|
|
|
@@ -81,24 +79,23 @@ class SemanticIndex:
|
|
|
81
79
|
Rust-authoritative (#91): extraction runs in the native
|
|
82
80
|
``build_symbol_table_json`` / ``build_reference_table_json`` entrypoints
|
|
83
81
|
(the same code the index-engine Wasm plugin wraps). The former Python
|
|
84
|
-
extraction mirror was deleted.
|
|
85
|
-
|
|
86
|
-
engine still lives in Rust".
|
|
82
|
+
extraction mirror was deleted. Required engine failures raise. Both tables are published atomically
|
|
83
|
+
only after successful engine calls and DTO validation.
|
|
87
84
|
"""
|
|
88
85
|
from intentumdiff.rust_core import (
|
|
89
86
|
try_rust_build_reference_table,
|
|
90
87
|
try_rust_build_symbol_table,
|
|
91
88
|
)
|
|
92
89
|
|
|
93
|
-
self._symbols = {}
|
|
94
|
-
self._references = {}
|
|
95
90
|
files_json = self.to_files_json()
|
|
96
91
|
symbol_json = try_rust_build_symbol_table(files_json)
|
|
97
|
-
if symbol_json is not None:
|
|
98
|
-
self.load_symbol_table_json(symbol_json)
|
|
99
92
|
reference_json = try_rust_build_reference_table(files_json)
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
# Validate DTOs on a temporary index before publishing either table.
|
|
94
|
+
candidate = SemanticIndex()
|
|
95
|
+
candidate.load_symbol_table_json(symbol_json)
|
|
96
|
+
candidate.load_reference_table_json(reference_json)
|
|
97
|
+
self._symbols = candidate._symbols
|
|
98
|
+
self._references = candidate._references
|
|
102
99
|
self._built = True
|
|
103
100
|
return self
|
|
104
101
|
|
|
@@ -144,12 +141,13 @@ class SemanticIndex:
|
|
|
144
141
|
refs = self._references.get(name, [])
|
|
145
142
|
if not resolve:
|
|
146
143
|
return refs
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
145
|
+
result = _c_abi_call(
|
|
146
|
+
"resolve_references",
|
|
147
|
+
json.dumps([definition.model_dump(mode="json") for definition in self._symbols.get(name, [])]),
|
|
148
|
+
json.dumps([reference.model_dump(mode="json") for reference in refs]),
|
|
149
|
+
)
|
|
150
|
+
return [ReferenceUsage.model_validate(reference) for reference in result]
|
|
153
151
|
|
|
154
152
|
# ------------------------------------------------------------------
|
|
155
153
|
# Serialisation helpers (feed the native index-engine primitives)
|
intentumdiff/core/indexer.py
CHANGED
|
@@ -30,17 +30,11 @@ Pass a no-op lambda to suppress events for a specific call::
|
|
|
30
30
|
|
|
31
31
|
Caching
|
|
32
32
|
-------
|
|
33
|
-
When the
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
the Wasm call entirely.
|
|
39
|
-
|
|
40
|
-
* **Symbol-index cache** — after :meth:`Indexer.index_repo` finishes, the
|
|
41
|
-
resulting symbol and reference tables are stored in SQLite keyed by
|
|
42
|
-
``(repo_root, commit_sha)``. A subsequent call for the *same* commit returns
|
|
43
|
-
the cached index immediately (unless *force=True*).
|
|
33
|
+
When ``DiffConfig.cache_path`` is set, the verified parser-level cache remains
|
|
34
|
+
available through ``SemanticDiffer``. The historical repository symbol-index
|
|
35
|
+
cache and LSP hover-map cache are bypassed in 0.0.2: their keys do not capture
|
|
36
|
+
Rust/parser identity, indexing completeness, or LSP workspace/server state.
|
|
37
|
+
Returning a stale index is worse than recomputing it. See Python #189-192.
|
|
44
38
|
"""
|
|
45
39
|
|
|
46
40
|
from __future__ import annotations
|
|
@@ -53,10 +47,10 @@ from pathlib import Path
|
|
|
53
47
|
from typing import TYPE_CHECKING, Any, Callable
|
|
54
48
|
|
|
55
49
|
from intentumdiff.core.diffignore import load_diffignore
|
|
50
|
+
from intentumdiff.rust_core import attach_lsp_type_map
|
|
56
51
|
|
|
57
52
|
if TYPE_CHECKING:
|
|
58
53
|
from intentumdiff.core.index import SemanticIndex
|
|
59
|
-
from intentumdiff.core.models import SemanticNode
|
|
60
54
|
from intentumdiff.differ import SemanticDiffer
|
|
61
55
|
|
|
62
56
|
logger = logging.getLogger(__name__)
|
|
@@ -164,41 +158,62 @@ def _make_index_key(repo_root: str, commit_sha: str) -> str:
|
|
|
164
158
|
return hashlib.sha256(encoded).hexdigest()
|
|
165
159
|
|
|
166
160
|
|
|
167
|
-
def _parse_catfile_output(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
161
|
+
def _parse_catfile_output(buf: bytes) -> dict[str, str | None]:
|
|
162
|
+
"""Decode complete Git batch responses; None marks an intentionally skipped binary.
|
|
163
|
+
|
|
164
|
+
A missing object, bad header, or truncated content is not a binary file.
|
|
165
|
+
Such failures must abort indexing instead of silently dropping source files.
|
|
166
|
+
"""
|
|
167
|
+
blobs: dict[str, str | None] = {}
|
|
173
168
|
i = 0
|
|
174
169
|
n = len(buf)
|
|
175
170
|
while i < n:
|
|
176
171
|
nl = buf.find(b"\n", i)
|
|
177
172
|
if nl == -1:
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
raise RuntimeError("Incomplete git cat-file batch response header")
|
|
174
|
+
try:
|
|
175
|
+
header = buf[i:nl].decode("ascii", errors="strict")
|
|
176
|
+
except UnicodeDecodeError as exc:
|
|
177
|
+
raise RuntimeError("Invalid git cat-file batch response header") from exc
|
|
180
178
|
i = nl + 1
|
|
181
179
|
parts = header.split()
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
if len(parts) == 2 and parts[1] == "missing":
|
|
181
|
+
raise RuntimeError(f"Git blob {parts[0]} is missing")
|
|
182
|
+
if len(parts) != 3 or parts[1] != "blob":
|
|
183
|
+
raise RuntimeError(f"Unexpected git cat-file batch response: {header!r}")
|
|
184
|
+
sha = parts[0]
|
|
185
|
+
if sha in blobs:
|
|
186
|
+
raise RuntimeError(f"Duplicate git cat-file batch response for {sha}")
|
|
185
187
|
try:
|
|
186
188
|
size = int(parts[2])
|
|
187
|
-
except ValueError:
|
|
188
|
-
|
|
189
|
+
except ValueError as exc:
|
|
190
|
+
raise RuntimeError(f"Invalid git cat-file batch size for {sha}") from exc
|
|
191
|
+
if size < 0 or i + size >= n or buf[i + size] != 0x0A:
|
|
192
|
+
raise RuntimeError(f"Truncated git cat-file batch payload for {sha}")
|
|
189
193
|
content_bytes = buf[i : i + size]
|
|
190
|
-
i += size + 1 #
|
|
191
|
-
if b"\x00" in content_bytes[:8192]:
|
|
194
|
+
i += size + 1 # consume the required trailing newline
|
|
195
|
+
if b"\x00" in content_bytes[:8192]:
|
|
196
|
+
blobs[sha] = None # binary: intentionally excluded from text indexing
|
|
192
197
|
continue
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
|
|
199
|
+
# Some recognized binaries (for example PDFs) contain no NUL bytes.
|
|
200
|
+
# Use the Rust-owned content classifier on the original blob before
|
|
201
|
+
# decoding; otherwise their binary payload aborts the entire Git index
|
|
202
|
+
# as "invalid UTF-8" (#253). An opaque octet-stream is *not* proof
|
|
203
|
+
# that a source file is safely skippable: still decode it strictly.
|
|
204
|
+
from intentumdiff.content_type import detect_content_type # noqa: PLC0415
|
|
205
|
+
|
|
206
|
+
content_type = detect_content_type(content_bytes)
|
|
207
|
+
if not content_type["is_text"] and content_type["mime"] != "application/octet-stream":
|
|
208
|
+
blobs[sha] = None
|
|
195
209
|
continue
|
|
196
210
|
try:
|
|
197
|
-
|
|
198
|
-
except UnicodeDecodeError:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
211
|
+
blobs[sha] = content_bytes.decode("utf-8", errors="strict")
|
|
212
|
+
except UnicodeDecodeError as exc:
|
|
213
|
+
raise RuntimeError(
|
|
214
|
+
f"Invalid UTF-8 in Git blob {sha}: refusing lossy symbol indexing"
|
|
215
|
+
) from exc
|
|
216
|
+
return blobs
|
|
202
217
|
|
|
203
218
|
|
|
204
219
|
def _collect_blob_files(
|
|
@@ -206,61 +221,77 @@ def _collect_blob_files(
|
|
|
206
221
|
ref: str,
|
|
207
222
|
diffignore: Any,
|
|
208
223
|
) -> "tuple[list[tuple[str, str]], list[str]]":
|
|
209
|
-
"""Return
|
|
224
|
+
"""Return every non-ignored text path at *ref*, including shared-content blobs.
|
|
210
225
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
Returns ``(files, ignored_files)`` where *ignored_files* are the paths excluded
|
|
216
|
-
by *diffignore*.
|
|
226
|
+
Git stores identical file contents under one blob SHA. Batch-read each unique
|
|
227
|
+
SHA once, then expand that content against the original ls-tree path list;
|
|
228
|
+
collapsing SHA -> one path silently drops files from semantic indexing.
|
|
217
229
|
"""
|
|
218
230
|
from intentumdiff.vcs.git_cli import run_git_bytes # noqa: PLC0415
|
|
219
231
|
|
|
220
232
|
ignored_files: list[str] = []
|
|
221
|
-
|
|
222
|
-
#
|
|
223
|
-
|
|
233
|
+
paths_in_tree_order: list[tuple[str, str]] = []
|
|
234
|
+
# Git's -z output always terminates every record with NUL. Validating
|
|
235
|
+
# the later cat-file blobs cannot discover paths lost from this inventory.
|
|
236
|
+
tree_bytes = run_git_bytes(repo_root, ["ls-tree", "-r", "-z", ref])
|
|
237
|
+
if tree_bytes and not tree_bytes.endswith(b"\x00"):
|
|
238
|
+
raise RuntimeError("Incomplete git ls-tree -z output: missing NUL delimiter")
|
|
239
|
+
for entry in tree_bytes.split(b"\x00"):
|
|
224
240
|
if not entry:
|
|
225
241
|
continue
|
|
226
|
-
meta,
|
|
242
|
+
meta, separator, raw_path = entry.partition(b"\t")
|
|
227
243
|
parts = meta.split()
|
|
228
|
-
if
|
|
244
|
+
if separator != b"\t" or not raw_path or len(parts) != 3:
|
|
245
|
+
raise RuntimeError(f"Malformed git ls-tree entry: {entry[:128]!r}")
|
|
246
|
+
if parts[1] == b"commit":
|
|
247
|
+
# Gitlinks are submodules, not readable blobs at this tree.
|
|
229
248
|
continue
|
|
230
|
-
|
|
249
|
+
if parts[1] != b"blob":
|
|
250
|
+
raise RuntimeError(f"Unexpected git ls-tree object type: {parts[1]!r}")
|
|
251
|
+
# Git may store arbitrary filename bytes on Unix. Replacing undecodable
|
|
252
|
+
# bytes invents a different path and can collapse distinct files (#238).
|
|
253
|
+
try:
|
|
254
|
+
path = raw_path.decode("utf-8", errors="strict")
|
|
255
|
+
except UnicodeDecodeError as exc:
|
|
256
|
+
raise RuntimeError(
|
|
257
|
+
"Invalid UTF-8 in git ls-tree path: refusing lossy indexing"
|
|
258
|
+
) from exc
|
|
259
|
+
try:
|
|
260
|
+
sha = parts[2].decode("ascii", errors="strict")
|
|
261
|
+
except UnicodeDecodeError as exc:
|
|
262
|
+
raise RuntimeError(
|
|
263
|
+
f"Invalid ASCII object ID in git ls-tree for {path!r}"
|
|
264
|
+
) from exc
|
|
231
265
|
if diffignore and diffignore.is_ignored(path):
|
|
232
266
|
ignored_files.append(path)
|
|
233
267
|
continue
|
|
234
|
-
|
|
268
|
+
paths_in_tree_order.append((path, sha))
|
|
235
269
|
|
|
236
|
-
if not
|
|
270
|
+
if not paths_in_tree_order:
|
|
237
271
|
return [], ignored_files
|
|
238
272
|
|
|
239
|
-
|
|
273
|
+
# The caller needs all paths, but cat-file needs only one request per blob.
|
|
274
|
+
shas_input = "\n".join(dict.fromkeys(sha for _, sha in paths_in_tree_order)).encode()
|
|
240
275
|
out = run_git_bytes(repo_root, ["cat-file", "--batch"], input_bytes=shas_input)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
"""Return a copy of *node* tree with ``type_info`` set from *type_map*.
|
|
249
|
-
|
|
250
|
-
``SemanticNode`` is frozen so we must rebuild changed nodes from the leaves
|
|
251
|
-
up. Only nodes whose id appears in *type_map* are rebuilt.
|
|
252
|
-
"""
|
|
253
|
-
from intentumdiff.core.models import SemanticNode # noqa: PLC0415
|
|
254
|
-
|
|
255
|
-
new_children = [_attach_type_info(c, type_map) for c in node.children]
|
|
256
|
-
if node.id in type_map or new_children != list(node.children):
|
|
257
|
-
return node.model_copy(
|
|
258
|
-
update={
|
|
259
|
-
"children": new_children,
|
|
260
|
-
**({"type_info": type_map[node.id]} if node.id in type_map else {}),
|
|
261
|
-
}
|
|
276
|
+
decoded_by_sha = _parse_catfile_output(out)
|
|
277
|
+
requested = set(sha for _, sha in paths_in_tree_order)
|
|
278
|
+
missing = requested.difference(decoded_by_sha)
|
|
279
|
+
if missing:
|
|
280
|
+
raise RuntimeError(
|
|
281
|
+
"Incomplete git cat-file batch response: missing blob(s) "
|
|
282
|
+
+ ", ".join(sorted(missing)[:5])
|
|
262
283
|
)
|
|
263
|
-
|
|
284
|
+
unexpected = set(decoded_by_sha).difference(requested)
|
|
285
|
+
if unexpected:
|
|
286
|
+
raise RuntimeError(
|
|
287
|
+
"Unexpected git cat-file batch blob(s): " + ", ".join(sorted(unexpected)[:5])
|
|
288
|
+
)
|
|
289
|
+
files: list[tuple[str, str]] = []
|
|
290
|
+
for path, sha in paths_in_tree_order:
|
|
291
|
+
content = decoded_by_sha[sha]
|
|
292
|
+
if content is not None: # only known binary blobs may be omitted
|
|
293
|
+
files.append((path, content))
|
|
294
|
+
return files, ignored_files
|
|
264
295
|
|
|
265
296
|
|
|
266
297
|
# ---------------------------------------------------------------------------
|
|
@@ -363,8 +394,8 @@ class Indexer:
|
|
|
363
394
|
Progress callback for this call. Falls back to the callback
|
|
364
395
|
passed to ``__init__`` when ``None``.
|
|
365
396
|
force:
|
|
366
|
-
|
|
367
|
-
|
|
397
|
+
Retained for API compatibility. Indexing always recomputes the
|
|
398
|
+
symbol index in 0.0.2 (the unproven cache is disabled).
|
|
368
399
|
|
|
369
400
|
Returns
|
|
370
401
|
-------
|
|
@@ -372,41 +403,13 @@ class Indexer:
|
|
|
372
403
|
Fully built index. Check :attr:`IndexResult.from_cache` to
|
|
373
404
|
determine whether the symbol table was loaded from cache.
|
|
374
405
|
"""
|
|
375
|
-
from intentumdiff.vcs.git_cli import
|
|
376
|
-
resolve_repo_root,
|
|
377
|
-
run_git_bytes,
|
|
378
|
-
)
|
|
406
|
+
from intentumdiff.vcs.git_cli import resolve_repo_root # noqa: PLC0415
|
|
379
407
|
|
|
380
408
|
repo_root = resolve_repo_root(repo_path)
|
|
381
|
-
commit_sha = (
|
|
382
|
-
run_git_bytes(repo_root, ["rev-parse", "--verify", ref]).decode().strip()
|
|
383
|
-
)
|
|
384
409
|
callback = on_progress or self._on_progress
|
|
385
410
|
|
|
386
|
-
#
|
|
387
|
-
|
|
388
|
-
index_key = _make_index_key(repo_root, commit_sha)
|
|
389
|
-
cached = self._differ._cache.get_symbol_index(index_key)
|
|
390
|
-
if cached is not None:
|
|
391
|
-
logger.debug(
|
|
392
|
-
"Symbol index cache hit for %s @ %s",
|
|
393
|
-
repo_root,
|
|
394
|
-
commit_sha[:8],
|
|
395
|
-
)
|
|
396
|
-
from intentumdiff.core.index import SemanticIndex # noqa: PLC0415
|
|
397
|
-
|
|
398
|
-
sem_index = SemanticIndex()
|
|
399
|
-
symbols_json, refs_json = cached
|
|
400
|
-
sem_index.load_symbol_table_json(symbols_json)
|
|
401
|
-
sem_index.load_reference_table_json(refs_json)
|
|
402
|
-
return IndexResult(
|
|
403
|
-
files_indexed=0,
|
|
404
|
-
files_skipped=0,
|
|
405
|
-
errors=[],
|
|
406
|
-
semantic_index=sem_index,
|
|
407
|
-
from_cache=True,
|
|
408
|
-
)
|
|
409
|
-
|
|
411
|
+
# Always re-index: historical symbol-cache entries lack Rust/parser
|
|
412
|
+
# identity and failed-file provenance (#189, #190).
|
|
410
413
|
# ── Collect all text files in commit tree ─────────────────────────
|
|
411
414
|
diffignore = load_diffignore(repo_root)
|
|
412
415
|
files, ignored_files = _collect_blob_files(repo_root, ref, diffignore)
|
|
@@ -415,13 +418,7 @@ class Indexer:
|
|
|
415
418
|
result.files_ignored = len(ignored_files)
|
|
416
419
|
result.ignored_files = ignored_files
|
|
417
420
|
|
|
418
|
-
#
|
|
419
|
-
if self._differ._cache is not None:
|
|
420
|
-
index_key = _make_index_key(repo_root, commit_sha)
|
|
421
|
-
self._store_symbol_index(
|
|
422
|
-
result.semantic_index, index_key, result.files_indexed
|
|
423
|
-
)
|
|
424
|
-
|
|
421
|
+
# Do not persist an index whose provenance/completeness cannot be verified.
|
|
425
422
|
return result
|
|
426
423
|
|
|
427
424
|
def index_directory(
|
|
@@ -448,6 +445,8 @@ class Indexer:
|
|
|
448
445
|
directory = Path(directory)
|
|
449
446
|
callback = on_progress or self._on_progress
|
|
450
447
|
|
|
448
|
+
from intentumdiff.content_type import detect_content_type # noqa: PLC0415
|
|
449
|
+
|
|
451
450
|
diffignore = load_diffignore(directory)
|
|
452
451
|
ignored_files: list[str] = []
|
|
453
452
|
files: list[tuple[str, str]] = []
|
|
@@ -459,9 +458,25 @@ class Indexer:
|
|
|
459
458
|
ignored_files.append(rel_posix)
|
|
460
459
|
continue
|
|
461
460
|
try:
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
raw = path.read_bytes()
|
|
462
|
+
# Rust owns content-type classification. A confirmed binary asset
|
|
463
|
+
# is not a source file and must not be UTF-8-decoded (#250).
|
|
464
|
+
content_type = detect_content_type(raw)
|
|
465
|
+
if not content_type["is_text"]:
|
|
466
|
+
if content_type["mime"] == "application/octet-stream" and b"\x00" not in raw:
|
|
467
|
+
# Opaque bytes without a recognized format are not proof
|
|
468
|
+
# that a text source is absent. Reject invalid UTF-8 rather
|
|
469
|
+
# than allowing corrupt source to disappear from the index.
|
|
470
|
+
raw.decode("utf-8", errors="strict")
|
|
471
|
+
continue
|
|
472
|
+
content = raw.decode("utf-8", errors="strict")
|
|
473
|
+
except (OSError, UnicodeError) as exc:
|
|
474
|
+
# Host-I/O and decoding failures are not intentional ignores or unsupported
|
|
475
|
+
# parser. Returning a successful partial directory index would
|
|
476
|
+
# conceal source files from downstream semantic analysis (#203).
|
|
477
|
+
raise RuntimeError(
|
|
478
|
+
f"Failed to read directory index source {rel_posix!r}: {exc}"
|
|
479
|
+
) from exc
|
|
465
480
|
files.append((rel_posix, content))
|
|
466
481
|
|
|
467
482
|
result = self._index_files(files, on_progress=callback)
|
|
@@ -589,44 +604,13 @@ class Indexer:
|
|
|
589
604
|
for fast local servers, lower for shared or rate-limited servers.
|
|
590
605
|
"""
|
|
591
606
|
import asyncio
|
|
592
|
-
from intentumdiff.vcs.git_cli import
|
|
593
|
-
resolve_repo_root,
|
|
594
|
-
run_git_bytes,
|
|
595
|
-
)
|
|
607
|
+
from intentumdiff.vcs.git_cli import resolve_repo_root # noqa: PLC0415
|
|
596
608
|
|
|
597
609
|
repo_root = resolve_repo_root(repo_path)
|
|
598
|
-
commit_sha = (
|
|
599
|
-
run_git_bytes(repo_root, ["rev-parse", "--verify", ref]).decode().strip()
|
|
600
|
-
)
|
|
601
610
|
callback = on_progress or self._on_progress
|
|
602
611
|
|
|
603
|
-
#
|
|
604
|
-
#
|
|
605
|
-
lsp_index_key = _make_index_key(repo_root, "lsp:" + commit_sha)
|
|
606
|
-
|
|
607
|
-
# ── Fast path: cached LSP symbol index ────────────────────────────
|
|
608
|
-
if not force and self._differ._cache is not None:
|
|
609
|
-
cached = self._differ._cache.get_symbol_index(lsp_index_key)
|
|
610
|
-
if cached is not None:
|
|
611
|
-
logger.debug(
|
|
612
|
-
"LSP symbol index cache hit for %s @ %s",
|
|
613
|
-
repo_root,
|
|
614
|
-
commit_sha[:8],
|
|
615
|
-
)
|
|
616
|
-
from intentumdiff.core.index import SemanticIndex # noqa: PLC0415
|
|
617
|
-
|
|
618
|
-
sem_index = SemanticIndex()
|
|
619
|
-
symbols_json, refs_json = cached
|
|
620
|
-
sem_index.load_symbol_table_json(symbols_json)
|
|
621
|
-
sem_index.load_reference_table_json(refs_json)
|
|
622
|
-
return IndexResult(
|
|
623
|
-
files_indexed=0,
|
|
624
|
-
files_skipped=0,
|
|
625
|
-
errors=[],
|
|
626
|
-
semantic_index=sem_index,
|
|
627
|
-
from_cache=True,
|
|
628
|
-
)
|
|
629
|
-
|
|
612
|
+
# Always re-index: LSP type state, parser identity and failed-file
|
|
613
|
+
# provenance are missing from historical cache keys (#189, #190).
|
|
630
614
|
# Collect files (parallel blob reads; same filtering as index_repo)
|
|
631
615
|
diffignore = load_diffignore(repo_root)
|
|
632
616
|
files, ignored_files = await asyncio.to_thread(
|
|
@@ -642,9 +626,7 @@ class Indexer:
|
|
|
642
626
|
result.files_ignored = len(ignored_files)
|
|
643
627
|
result.ignored_files = ignored_files
|
|
644
628
|
|
|
645
|
-
|
|
646
|
-
self._store_symbol_index(result.semantic_index, lsp_index_key, result.files_indexed)
|
|
647
|
-
|
|
629
|
+
# An LSP-enriched index is not reusable without server/workspace identity.
|
|
648
630
|
return result
|
|
649
631
|
|
|
650
632
|
async def _index_files_lsp(
|
|
@@ -684,7 +666,6 @@ class Indexer:
|
|
|
684
666
|
# Error: any other exception
|
|
685
667
|
|
|
686
668
|
sem = asyncio.Semaphore(max(1, file_concurrency))
|
|
687
|
-
cache = self._differ._cache
|
|
688
669
|
differ = self._differ # captured for executor
|
|
689
670
|
|
|
690
671
|
# Use a single-worker executor so Wasm parse calls are serialised.
|
|
@@ -725,22 +706,20 @@ class Indexer:
|
|
|
725
706
|
enricher = enrichers.get(language)
|
|
726
707
|
enriched_count = 0
|
|
727
708
|
if enricher is not None:
|
|
728
|
-
#
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
enriched_count = len(type_map)
|
|
743
|
-
node = _attach_type_info(node, type_map)
|
|
709
|
+
# Hover-map caching lacks file/workspace/server provenance
|
|
710
|
+
# and cannot certify a type result (#191).
|
|
711
|
+
try:
|
|
712
|
+
type_map = await enricher.enrich(filename, content, node)
|
|
713
|
+
if not isinstance(type_map, dict):
|
|
714
|
+
raise TypeError("LSP enricher returned an invalid type-map DTO")
|
|
715
|
+
if type_map:
|
|
716
|
+
# Rust owns semantic-tree mutation and validation.
|
|
717
|
+
node = attach_lsp_type_map(node, type_map)
|
|
718
|
+
enriched_count = len(type_map)
|
|
719
|
+
except Exception as exc: # noqa: BLE001
|
|
720
|
+
# Do not turn a requested enrichment failure into an
|
|
721
|
+
# apparently successful bare semantic index (#192).
|
|
722
|
+
return filename, "ERROR", exc, 0
|
|
744
723
|
return filename, language, node, enriched_count
|
|
745
724
|
|
|
746
725
|
tasks = [asyncio.create_task(_process_one(f, c)) for f, c in files]
|