intentumdiff-python 0.0.1__py3-none-win_amd64.whl → 0.0.2b2__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 +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
intentumdiff/github_app.py
CHANGED
|
@@ -35,6 +35,14 @@ class GitHubAppReviewResult:
|
|
|
35
35
|
summary_markdown: str
|
|
36
36
|
html_report: str
|
|
37
37
|
|
|
38
|
+
def __post_init__(self) -> None:
|
|
39
|
+
for name in ("checked_files", "semantic_changes", "guardrail_violations"):
|
|
40
|
+
value = getattr(self, name)
|
|
41
|
+
if type(value) is not int or value < 0:
|
|
42
|
+
raise GitHubAppError(f"Review {name} must be a non-negative integer")
|
|
43
|
+
if type(self.passed) is not bool:
|
|
44
|
+
raise GitHubAppError("Review passed must be a boolean")
|
|
45
|
+
|
|
38
46
|
|
|
39
47
|
def verify_webhook_signature(secret: str, body: bytes, signature_header: str | None) -> bool:
|
|
40
48
|
"""Return True when *signature_header* matches GitHub's sha256 HMAC."""
|
|
@@ -107,6 +115,8 @@ def build_check_run_payload(
|
|
|
107
115
|
passed: bool,
|
|
108
116
|
details_url: str | None = None,
|
|
109
117
|
) -> dict[str, Any]:
|
|
118
|
+
if type(passed) is not bool:
|
|
119
|
+
raise GitHubAppError("Review passed must be a boolean")
|
|
110
120
|
conclusion = "success" if passed else "failure"
|
|
111
121
|
payload: dict[str, Any] = {
|
|
112
122
|
"name": name,
|
|
@@ -124,15 +134,23 @@ def build_check_run_payload(
|
|
|
124
134
|
|
|
125
135
|
|
|
126
136
|
def build_review_result_from_payload(payload: Mapping[str, Any]) -> GitHubAppReviewResult:
|
|
127
|
-
"""
|
|
137
|
+
"""Render explicit review evidence; never infer a successful engine result."""
|
|
128
138
|
|
|
129
139
|
review = payload.get("intentumdiff_review")
|
|
130
140
|
if not isinstance(review, Mapping):
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
raise GitHubAppError("Explicit intentumdiff_review evidence is required")
|
|
142
|
+
evidence = GitHubAppReviewResult(
|
|
143
|
+
checked_files=review.get("checked_files"),
|
|
144
|
+
semantic_changes=review.get("semantic_changes"),
|
|
145
|
+
guardrail_violations=review.get("guardrail_violations"),
|
|
146
|
+
passed=review.get("passed"),
|
|
147
|
+
summary_markdown="",
|
|
148
|
+
html_report="",
|
|
149
|
+
)
|
|
150
|
+
checked_files = evidence.checked_files
|
|
151
|
+
semantic_changes = evidence.semantic_changes
|
|
152
|
+
guardrail_violations = evidence.guardrail_violations
|
|
153
|
+
passed = evidence.passed
|
|
136
154
|
summary_markdown = render_github_app_summary(
|
|
137
155
|
checked_files=checked_files,
|
|
138
156
|
semantic_changes=semantic_changes,
|
|
@@ -251,14 +269,6 @@ def decode_webhook_body(body: bytes) -> dict[str, Any]:
|
|
|
251
269
|
return payload
|
|
252
270
|
|
|
253
271
|
|
|
254
|
-
def _non_negative_int(value: Any, *, default: int) -> int:
|
|
255
|
-
try:
|
|
256
|
-
parsed = int(value)
|
|
257
|
-
except (TypeError, ValueError):
|
|
258
|
-
return default
|
|
259
|
-
return max(parsed, 0)
|
|
260
|
-
|
|
261
|
-
|
|
262
272
|
def create_app() -> Any:
|
|
263
273
|
"""Create the optional FastAPI app without making FastAPI a core dependency."""
|
|
264
274
|
|
|
@@ -276,12 +286,18 @@ def create_app() -> Any:
|
|
|
276
286
|
x_hub_signature_256: str | None = Header(default=None),
|
|
277
287
|
) -> dict[str, Any]:
|
|
278
288
|
body = await request.body()
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
# A missing signing key must never disable authentication by accident.
|
|
290
|
+
secret = getattr(request.app.state, "webhook_secret", None)
|
|
291
|
+
if not isinstance(secret, str) or not secret:
|
|
292
|
+
raise HTTPException(status_code=503, detail="webhook signing secret not configured")
|
|
293
|
+
if not verify_webhook_signature(secret, body, x_hub_signature_256):
|
|
281
294
|
raise HTTPException(status_code=401, detail="invalid signature")
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
295
|
+
try:
|
|
296
|
+
payload = decode_webhook_body(body)
|
|
297
|
+
if x_github_event == "pull_request":
|
|
298
|
+
return build_pull_request_check_response(payload)
|
|
299
|
+
except (GitHubAppError, UnicodeDecodeError, json.JSONDecodeError) as exc:
|
|
300
|
+
raise HTTPException(status_code=422, detail=str(exc)) from exc
|
|
285
301
|
return {"ok": True, "event": x_github_event}
|
|
286
302
|
|
|
287
303
|
return app
|
|
Binary file
|
intentumdiff/live_server.py
CHANGED
|
@@ -80,7 +80,7 @@ if TYPE_CHECKING:
|
|
|
80
80
|
from intentumdiff.differ import SemanticDiffer
|
|
81
81
|
from rich.console import Console as RichConsole
|
|
82
82
|
|
|
83
|
-
from intentumdiff.core.models import ChangeStreamEvent, EditDelta
|
|
83
|
+
from intentumdiff.core.models import ChangeStreamEvent, ChangeStreamPhase, EditDelta
|
|
84
84
|
from intentumdiff.sources.live_buffer_source import LiveBufferSource
|
|
85
85
|
|
|
86
86
|
logger = logging.getLogger(__name__)
|
|
@@ -124,6 +124,14 @@ class _ParsedRequest:
|
|
|
124
124
|
stream: bool | None = None
|
|
125
125
|
|
|
126
126
|
|
|
127
|
+
class _RustLiveDecline(RuntimeError):
|
|
128
|
+
"""Transport the Rust Core's typed incomplete-result response unchanged."""
|
|
129
|
+
|
|
130
|
+
def __init__(self, code: str, message: str) -> None:
|
|
131
|
+
super().__init__(message)
|
|
132
|
+
self.code = code
|
|
133
|
+
|
|
134
|
+
|
|
127
135
|
def _make_socket_dir() -> str:
|
|
128
136
|
"""Return (and create) a private directory for the server's socket file."""
|
|
129
137
|
runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "")
|
|
@@ -144,10 +152,37 @@ def _make_socket_dir() -> str:
|
|
|
144
152
|
return sock_dir
|
|
145
153
|
|
|
146
154
|
|
|
155
|
+
# AF_UNIX addresses are a fixed-size struct field, not a string: sun_path is 104 bytes on
|
|
156
|
+
# macOS and 108 on Linux, INCLUDING the NUL. Exceeding it raises "AF_UNIX path too long" at
|
|
157
|
+
# bind() - not at connect, so the server simply never starts.
|
|
158
|
+
#
|
|
159
|
+
# macOS makes this easy to hit without doing anything unusual: TMPDIR there is a per-session
|
|
160
|
+
# path like /var/folders/xy/9k4n.../T/, and this module then adds a per-pid directory and a
|
|
161
|
+
# 16-character token. A GitHub macOS runner blows the limit outright, and so does any user
|
|
162
|
+
# whose temp path is a little long.
|
|
163
|
+
_SUN_PATH_MAX = 104 if sys.platform == "darwin" else 108
|
|
164
|
+
|
|
165
|
+
|
|
147
166
|
def _make_socket_path(pid: int, token: str) -> str:
|
|
148
|
-
"""Return a private socket path incorporating a random token.
|
|
149
|
-
|
|
150
|
-
|
|
167
|
+
"""Return a private socket path incorporating a random token.
|
|
168
|
+
|
|
169
|
+
Falls back to a shorter base if the preferred path would not fit in sun_path. The
|
|
170
|
+
fallback keeps the security properties that matter - an owner-only directory and an
|
|
171
|
+
unguessable name - and trades only the length of the token.
|
|
172
|
+
"""
|
|
173
|
+
path = os.path.join(_make_socket_dir(), f"intentumdiff-live-{token[:16]}.sock")
|
|
174
|
+
if len(os.fsencode(path)) < _SUN_PATH_MAX:
|
|
175
|
+
return path
|
|
176
|
+
|
|
177
|
+
# Shortest base that is private per user and short on every POSIX system we support.
|
|
178
|
+
short = os.path.join(tempfile.gettempdir() if len(tempfile.gettempdir()) < 12 else "/tmp",
|
|
179
|
+
f"imd-{pid}")
|
|
180
|
+
os.makedirs(short, mode=0o700, exist_ok=True) # nosemgrep: python.lang.security.audit.insecure-file-permissions.insecure-file-permissions
|
|
181
|
+
try:
|
|
182
|
+
os.chmod(short, 0o700) # nosemgrep: python.lang.security.audit.insecure-file-permissions.insecure-file-permissions
|
|
183
|
+
except OSError:
|
|
184
|
+
pass
|
|
185
|
+
return os.path.join(short, f"{token[:8]}.sock")
|
|
151
186
|
|
|
152
187
|
|
|
153
188
|
def _has_unix_socket() -> bool:
|
|
@@ -734,7 +769,16 @@ class LiveServer:
|
|
|
734
769
|
_write_line_bytes(conn, {"error": "request line too large"})
|
|
735
770
|
buf = b""
|
|
736
771
|
break
|
|
737
|
-
|
|
772
|
+
try:
|
|
773
|
+
line = line_bytes.decode("utf-8", errors="strict").strip()
|
|
774
|
+
except UnicodeDecodeError:
|
|
775
|
+
_write_line_bytes(
|
|
776
|
+
conn,
|
|
777
|
+
self._error_response(
|
|
778
|
+
0, "invalid_utf8", "Request line must be valid UTF-8"
|
|
779
|
+
),
|
|
780
|
+
)
|
|
781
|
+
continue
|
|
738
782
|
if not line:
|
|
739
783
|
continue
|
|
740
784
|
try:
|
|
@@ -905,9 +949,16 @@ class LiveServer:
|
|
|
905
949
|
use_stream = self._stream_analysis if request.stream is None else request.stream
|
|
906
950
|
try:
|
|
907
951
|
if use_stream:
|
|
908
|
-
|
|
952
|
+
# Stream transport shares the SAME Rust-certified complete diff
|
|
953
|
+
# and typed decline contract as non-streaming. Emit only FINAL
|
|
954
|
+
# events from that result; never finalize a fallback as success.
|
|
955
|
+
diff = self._compute_diff(source, request)
|
|
956
|
+
for change in diff.changes:
|
|
909
957
|
if self._is_stale(request):
|
|
910
958
|
return
|
|
959
|
+
event = ChangeStreamEvent(
|
|
960
|
+
phase=ChangeStreamPhase.FINAL, action="add", change=change
|
|
961
|
+
)
|
|
911
962
|
send_fn({
|
|
912
963
|
"op": "diff",
|
|
913
964
|
"seq": request.seq,
|
|
@@ -935,6 +986,8 @@ class LiveServer:
|
|
|
935
986
|
"guardrail_violation_count": len(diff.guardrail_violations),
|
|
936
987
|
},
|
|
937
988
|
})
|
|
989
|
+
except _RustLiveDecline as exc:
|
|
990
|
+
send_fn(self._error_response(request.seq, exc.code, str(exc), op="diff"))
|
|
938
991
|
except FileNotFoundError as exc:
|
|
939
992
|
send_fn(
|
|
940
993
|
self._error_response(
|
|
@@ -960,10 +1013,10 @@ class LiveServer:
|
|
|
960
1013
|
) -> Any:
|
|
961
1014
|
"""Return the ``SemanticDiff`` for a non-streaming request.
|
|
962
1015
|
|
|
963
|
-
The
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1016
|
+
The Rust handler returns a certified diff DTO or a typed/legacy decline.
|
|
1017
|
+
Declines and fallback-marked/incomplete DTOs never become successful live
|
|
1018
|
+
semantic reviews. Explicit diagnostics may use the routed Rust pipeline,
|
|
1019
|
+
but its incomplete results are likewise rejected.
|
|
967
1020
|
"""
|
|
968
1021
|
from intentumdiff import rust_core
|
|
969
1022
|
from intentumdiff.core.models import SemanticDiff
|
|
@@ -980,9 +1033,47 @@ class LiveServer:
|
|
|
980
1033
|
self._differ._config.model_dump_json(),
|
|
981
1034
|
_wasm_dir(),
|
|
982
1035
|
)
|
|
1036
|
+
if "fallback_code" in native:
|
|
1037
|
+
# Rust owns completeness: a typed decline is an error, never
|
|
1038
|
+
# permission to recover a purportedly successful Python diff.
|
|
1039
|
+
raise _RustLiveDecline(
|
|
1040
|
+
str(native["fallback_code"]),
|
|
1041
|
+
str(native.get("fallback") or "Rust Core declined an incomplete diff"),
|
|
1042
|
+
)
|
|
983
1043
|
if "diff" in native:
|
|
984
|
-
|
|
985
|
-
|
|
1044
|
+
# Validate raw Rust inventories and flags before Pydantic can
|
|
1045
|
+
# default omitted arrays/booleans into manufactured success.
|
|
1046
|
+
# This is the existing batch transport validator, not a
|
|
1047
|
+
# second Python semantic evaluator.
|
|
1048
|
+
try:
|
|
1049
|
+
rust_core._require_complete_batch_diff_dto(native["diff"])
|
|
1050
|
+
except (TypeError, ValueError) as exc:
|
|
1051
|
+
raise _RustLiveDecline(
|
|
1052
|
+
"native_diff_uncertified",
|
|
1053
|
+
f"{request.path}: malformed Rust Core live diff: {exc}",
|
|
1054
|
+
) from exc
|
|
1055
|
+
diff = SemanticDiff.model_validate(native["diff"])
|
|
1056
|
+
if diff.is_fallback or diff.parse_errors:
|
|
1057
|
+
raise _RustLiveDecline(
|
|
1058
|
+
"native_parse_incomplete",
|
|
1059
|
+
f"{request.path}: Rust Core returned an incomplete diff "
|
|
1060
|
+
f"({'; '.join(diff.parse_errors) or 'source fallback'})",
|
|
1061
|
+
)
|
|
1062
|
+
return diff
|
|
1063
|
+
# A legacy untyped decline is NOT permission to turn an uncertified
|
|
1064
|
+
# native result into a successful Python-path semantic review.
|
|
1065
|
+
raise _RustLiveDecline(
|
|
1066
|
+
"native_diff_uncertified",
|
|
1067
|
+
f"{request.path}: {native.get('fallback') or 'Rust Core returned no certified diff'}",
|
|
1068
|
+
)
|
|
1069
|
+
diff = self._differ.diff(source)
|
|
1070
|
+
if diff.is_fallback or diff.parse_errors:
|
|
1071
|
+
raise _RustLiveDecline(
|
|
1072
|
+
"native_parse_incomplete",
|
|
1073
|
+
f"{request.path}: diagnostic diff is incomplete "
|
|
1074
|
+
f"({'; '.join(diff.parse_errors) or 'source fallback'})",
|
|
1075
|
+
)
|
|
1076
|
+
return diff
|
|
986
1077
|
|
|
987
1078
|
def _compute_review(
|
|
988
1079
|
self,
|
|
@@ -993,10 +1084,10 @@ class LiveServer:
|
|
|
993
1084
|
) -> Any:
|
|
994
1085
|
"""Return the ``CommitDiff`` for a non-streaming review.
|
|
995
1086
|
|
|
996
|
-
The
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1087
|
+
The Rust Core certifies the non-streamed commit review and Python only
|
|
1088
|
+
validates/transports its DTO. Native declines must not fall through to
|
|
1089
|
+
another success path. Explicit diagnostics use routed Rust-backed review;
|
|
1090
|
+
the final completeness check also applies to that result.
|
|
1000
1091
|
"""
|
|
1001
1092
|
from intentumdiff import rust_core
|
|
1002
1093
|
from intentumdiff.core.models import CommitDiff
|
|
@@ -1009,8 +1100,33 @@ class LiveServer:
|
|
|
1009
1100
|
review_config.model_dump_json(),
|
|
1010
1101
|
_wasm_dir(),
|
|
1011
1102
|
)
|
|
1103
|
+
if "fallback_code" in native:
|
|
1104
|
+
raise _RustLiveDecline(
|
|
1105
|
+
str(native["fallback_code"]),
|
|
1106
|
+
str(native.get("fallback") or "Rust Core declined an incomplete commit review"),
|
|
1107
|
+
)
|
|
1012
1108
|
if "commit_diff" in native:
|
|
1109
|
+
# Reuse the certified commit-byte contract. Validation happens
|
|
1110
|
+
# on the raw native object, before Pydantic can supply empty
|
|
1111
|
+
# file inventories or coerce malformed semantic flags.
|
|
1112
|
+
try:
|
|
1113
|
+
raw_commit = json.dumps(
|
|
1114
|
+
native["commit_diff"], separators=(",", ":")
|
|
1115
|
+
).encode("utf-8")
|
|
1116
|
+
rust_core._require_native_commit_diff_json(raw_commit, "live review")
|
|
1117
|
+
except (rust_core._InvalidNativeCommitDto, TypeError, ValueError) as exc:
|
|
1118
|
+
raise _RustLiveDecline(
|
|
1119
|
+
"native_review_uncertified",
|
|
1120
|
+
f"{new_ref or 'working tree'}: malformed Rust Core live review: {exc}",
|
|
1121
|
+
) from exc
|
|
1013
1122
|
return CommitDiff.model_validate(native["commit_diff"])
|
|
1123
|
+
# A native refusal must not become a fabricated successful review
|
|
1124
|
+
# through a second, routed Python orchestration path.
|
|
1125
|
+
raise _RustLiveDecline(
|
|
1126
|
+
"native_review_uncertified",
|
|
1127
|
+
f"{new_ref or 'working tree'}: "
|
|
1128
|
+
f"{native.get('fallback') or 'Rust Core returned no certified commit review'}",
|
|
1129
|
+
)
|
|
1014
1130
|
return commit_differ.diff_commit(
|
|
1015
1131
|
repo_path=self._repo_path, old_ref=old_ref, new_ref=new_ref
|
|
1016
1132
|
)
|
|
@@ -1047,9 +1163,40 @@ class LiveServer:
|
|
|
1047
1163
|
if op == "cancel":
|
|
1048
1164
|
send_fn(self._cancel_request(request, seq))
|
|
1049
1165
|
return True
|
|
1050
|
-
|
|
1166
|
+
if op == "asset_diff":
|
|
1167
|
+
send_fn(self._asset_diff_request(request, seq))
|
|
1168
|
+
return True
|
|
1169
|
+
# `invalid_op`, not `unknown_op`: the native server has always answered an unrouted op
|
|
1170
|
+
# with that code, and it is the spelling the extension lists as non-retryable — so the
|
|
1171
|
+
# python server's own spelling made the extension auto-retry a request that can never
|
|
1172
|
+
# succeed. Two servers on one protocol have to name the same failure the same way.
|
|
1173
|
+
send_fn(self._error_response(seq, "invalid_op", f"unknown op: {op!r}", op=str(op)))
|
|
1051
1174
|
return True
|
|
1052
1175
|
|
|
1176
|
+
def _asset_diff_request(self, request: dict[str, Any], seq: int) -> dict[str, Any]:
|
|
1177
|
+
"""Perceptual image diff — the engine does the pixel work, this only marshals the request.
|
|
1178
|
+
|
|
1179
|
+
The extension previously synthesised an asset "review" and never asked for artifacts,
|
|
1180
|
+
so the panel always reported PERCEPTUAL DIFF PENDING while the engine sat there able
|
|
1181
|
+
to answer. This is the missing call.
|
|
1182
|
+
|
|
1183
|
+
Two request shapes, both engine-served:
|
|
1184
|
+
|
|
1185
|
+
* ``path`` (+ optional ``ref``) — one tracked image against a git ref. This is what a
|
|
1186
|
+
reviewing editor has: a repo-relative path and a base. The *before* bytes are in the
|
|
1187
|
+
object store, and materialising them is git work, so the engine does it.
|
|
1188
|
+
* ``before_path`` + ``after_path`` — two files that already exist on disk.
|
|
1189
|
+
|
|
1190
|
+
Request parsing, the path-containment guard and the self-ignoring artifact cache live in
|
|
1191
|
+
the core's ``live_handle_asset_diff``, so this server and the native live-server binary
|
|
1192
|
+
answer from ONE implementation. A second copy here would be a second place for the
|
|
1193
|
+
containment rule to drift — and the rule is what stops a protocol method that accepts
|
|
1194
|
+
file paths from becoming an arbitrary-file reader.
|
|
1195
|
+
"""
|
|
1196
|
+
from intentumdiff import rust_core
|
|
1197
|
+
|
|
1198
|
+
return rust_core.live_handle_asset_diff(self._repo_path, self._ref, request, seq)
|
|
1199
|
+
|
|
1053
1200
|
def _process_review_request(
|
|
1054
1201
|
self,
|
|
1055
1202
|
request: dict[str, Any],
|
|
@@ -1100,6 +1247,20 @@ class LiveServer:
|
|
|
1100
1247
|
commit_diff = self._compute_review(
|
|
1101
1248
|
review_config, commit_differ, old_ref, new_ref
|
|
1102
1249
|
)
|
|
1250
|
+
# Streamed file events are provisional. Rust's completeness flags
|
|
1251
|
+
# must be checked before publishing an ok:true whole-commit result.
|
|
1252
|
+
incomplete_files = [
|
|
1253
|
+
f"{item.new_filename or item.old_filename}: "
|
|
1254
|
+
f"{'; '.join(item.parse_errors) or 'source fallback'}"
|
|
1255
|
+
for item in commit_diff.file_diffs
|
|
1256
|
+
if item.is_fallback or item.parse_errors
|
|
1257
|
+
]
|
|
1258
|
+
if commit_diff.parse_errors or incomplete_files:
|
|
1259
|
+
raise _RustLiveDecline(
|
|
1260
|
+
"native_parse_incomplete",
|
|
1261
|
+
"Incomplete commit review: "
|
|
1262
|
+
+ "; ".join([*commit_diff.parse_errors, *incomplete_files]),
|
|
1263
|
+
)
|
|
1103
1264
|
with self._lock:
|
|
1104
1265
|
if seq < self._latest_review_seq:
|
|
1105
1266
|
return
|
|
@@ -1123,6 +1284,8 @@ class LiveServer:
|
|
|
1123
1284
|
})
|
|
1124
1285
|
except _ReviewCancelled:
|
|
1125
1286
|
return
|
|
1287
|
+
except _RustLiveDecline as exc:
|
|
1288
|
+
send_fn(self._error_response(seq, exc.code, str(exc), op="review"))
|
|
1126
1289
|
except Exception as exc:
|
|
1127
1290
|
logger.warning(
|
|
1128
1291
|
"LiveServer review error for seq=%d: %s",
|
intentumdiff/lsp/client.py
CHANGED
|
@@ -374,6 +374,7 @@ class AsyncLspClient:
|
|
|
374
374
|
"rootUri": self._root_uri,
|
|
375
375
|
"workspaceFolders": [{"uri": self._root_uri, "name": "workspace"}],
|
|
376
376
|
"capabilities": {
|
|
377
|
+
"general": {"positionEncodings": ["utf-16"]},
|
|
377
378
|
"textDocument": {
|
|
378
379
|
"hover": {
|
|
379
380
|
"contentFormat": ["plaintext", "markdown"],
|
|
@@ -385,7 +386,12 @@ class AsyncLspClient:
|
|
|
385
386
|
},
|
|
386
387
|
"clientInfo": {"name": "IntentumDiff", "version": "0.1"},
|
|
387
388
|
}
|
|
388
|
-
await self._send_request("initialize", init_params)
|
|
389
|
+
result = await self._send_request("initialize", init_params)
|
|
390
|
+
if not isinstance(result, dict) or not isinstance(result.get("capabilities", {}), dict):
|
|
391
|
+
raise LspConnectionError("Invalid LSP initialize capabilities")
|
|
392
|
+
encoding = result.get("capabilities", {}).get("positionEncoding", "utf-16")
|
|
393
|
+
if encoding != "utf-16":
|
|
394
|
+
raise LspConnectionError(f"Unsupported LSP position encoding: {encoding}")
|
|
389
395
|
self._send_notification("initialized", {})
|
|
390
396
|
|
|
391
397
|
def _next_request_id(self) -> int:
|
intentumdiff/lsp/enricher.py
CHANGED
|
@@ -13,16 +13,14 @@ Usage
|
|
|
13
13
|
type_map = await enricher.enrich(uri, source_text, root_node)
|
|
14
14
|
# type_map: dict[node_id, type_string]
|
|
15
15
|
|
|
16
|
-
The
|
|
17
|
-
``_NAME_TYPES`` (identifiers, names, symbols …). It uses
|
|
16
|
+
The Rust engine selects hover targets and result node IDs. This adapter uses
|
|
18
17
|
``asyncio.gather`` to parallelise all hover requests for a single file,
|
|
19
18
|
which keeps latency proportional to the server's response time rather than
|
|
20
19
|
the number of nodes.
|
|
21
20
|
|
|
22
|
-
LSP failures
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- Any other exception — logged as a debug message; the node is skipped.
|
|
21
|
+
LSP transport failures fail closed: connection errors and hover timeouts are
|
|
22
|
+
reported to the indexer instead of being converted into an empty type map.
|
|
23
|
+
A successful hover response with no type remains a legitimate None result.
|
|
26
24
|
"""
|
|
27
25
|
|
|
28
26
|
from __future__ import annotations
|
|
@@ -32,49 +30,10 @@ import logging
|
|
|
32
30
|
import pathlib
|
|
33
31
|
|
|
34
32
|
from intentumdiff.lsp.client import AsyncLspClient
|
|
35
|
-
from intentumdiff.lsp.exceptions import LspConnectionError, LspTimeoutError
|
|
36
33
|
from intentumdiff.core.models import SemanticNode
|
|
37
34
|
|
|
38
35
|
logger = logging.getLogger(__name__)
|
|
39
36
|
|
|
40
|
-
# Node types whose *own* position is hovered and whose *own* id gets the result.
|
|
41
|
-
# Kept narrow: only specific name nodes the refactoring rules sub-classify.
|
|
42
|
-
# Generic ``identifier``/``name``/``symbol`` are excluded — they appear
|
|
43
|
-
# hundreds of times per file but are never directly read for ``type_info`` by
|
|
44
|
-
# any refactoring rule.
|
|
45
|
-
_NAME_TYPES = frozenset(
|
|
46
|
-
{
|
|
47
|
-
"function_name",
|
|
48
|
-
"class_name",
|
|
49
|
-
"variable_name",
|
|
50
|
-
"method_name", # some parsers emit method_name instead of function_name
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
# Declaration/parameter node types whose ``type_info`` is read by refactoring
|
|
55
|
-
# rules (EXTRACT_VARIABLE, INTRODUCE_PARAMETER_OBJECT). The enricher hovers
|
|
56
|
-
# at the *first name-leaf child's* position but stores the result under the
|
|
57
|
-
# *declaration node's* id so it lands on the node the rules inspect.
|
|
58
|
-
_DECL_NODE_TYPES = frozenset(
|
|
59
|
-
{
|
|
60
|
-
"assignment",
|
|
61
|
-
"variable_declaration",
|
|
62
|
-
"let_declaration",
|
|
63
|
-
"const_declaration",
|
|
64
|
-
"local_variable_declaration",
|
|
65
|
-
"variable_declarator",
|
|
66
|
-
}
|
|
67
|
-
)
|
|
68
|
-
_PARAM_NODE_TYPES = frozenset(
|
|
69
|
-
{
|
|
70
|
-
"parameter",
|
|
71
|
-
"typed_parameter",
|
|
72
|
-
"typed_identifier",
|
|
73
|
-
"required_parameter",
|
|
74
|
-
"optional_parameter",
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
|
|
78
37
|
# Maximum concurrent hover requests per file. Most servers handle far more,
|
|
79
38
|
# but we cap to avoid overwhelming a slow server.
|
|
80
39
|
_MAX_CONCURRENT = 50
|
|
@@ -111,17 +70,13 @@ class TypeEnricher:
|
|
|
111
70
|
Sends ``textDocument/didOpen``, fires all hover requests concurrently,
|
|
112
71
|
then sends ``textDocument/didClose``.
|
|
113
72
|
|
|
114
|
-
|
|
115
|
-
|
|
73
|
+
Raises transport errors; only a completed query with no type results
|
|
74
|
+
produces an empty dict.
|
|
116
75
|
"""
|
|
117
76
|
uri = _path_to_uri(file_path)
|
|
77
|
+
await self._client.did_open(uri, self._language, source_text)
|
|
118
78
|
try:
|
|
119
|
-
await self.
|
|
120
|
-
except LspConnectionError as exc:
|
|
121
|
-
logger.warning("LSP type enrichment skipped (%s): %s", file_path, exc)
|
|
122
|
-
return {}
|
|
123
|
-
try:
|
|
124
|
-
result = await self._query_all(uri, root)
|
|
79
|
+
result = await self._query_all(uri, root, source_text)
|
|
125
80
|
finally:
|
|
126
81
|
try:
|
|
127
82
|
await self._client.did_close(uri)
|
|
@@ -131,62 +86,10 @@ class TypeEnricher:
|
|
|
131
86
|
|
|
132
87
|
# ── Internal ──────────────────────────────────────────────────────────────
|
|
133
88
|
|
|
134
|
-
def
|
|
135
|
-
"""Return the
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if child.is_leaf() and child.node_type in all_name_types:
|
|
139
|
-
return child
|
|
140
|
-
found = self._first_name_leaf(child)
|
|
141
|
-
if found is not None:
|
|
142
|
-
return found
|
|
143
|
-
return None
|
|
144
|
-
|
|
145
|
-
def _collect_hover_targets(
|
|
146
|
-
self, root: SemanticNode
|
|
147
|
-
) -> list[tuple[SemanticNode, SemanticNode]]:
|
|
148
|
-
"""Return ``(result_node, position_node)`` pairs to hover.
|
|
149
|
-
|
|
150
|
-
* For **name-type leaves** (:data:`_NAME_TYPES`): hover at the leaf
|
|
151
|
-
position, store result under the leaf's id.
|
|
152
|
-
* For **declaration/parameter nodes** (:data:`_DECL_NODE_TYPES`,
|
|
153
|
-
:data:`_PARAM_NODE_TYPES`): hover at the first name-leaf child's
|
|
154
|
-
position, but store the result under the *declaration node's* id.
|
|
155
|
-
This makes ``type_info`` land on the node that refactoring rules
|
|
156
|
-
actually inspect (e.g. the ``assignment`` node for
|
|
157
|
-
EXTRACT_VARIABLE).
|
|
158
|
-
|
|
159
|
-
Result node ids are deduplicated so each node is queried at most once.
|
|
160
|
-
"""
|
|
161
|
-
seen: set[str] = set()
|
|
162
|
-
targets: list[tuple[SemanticNode, SemanticNode]] = []
|
|
163
|
-
|
|
164
|
-
for node in [root, *root.descendants()]:
|
|
165
|
-
if node.id in seen:
|
|
166
|
-
continue
|
|
167
|
-
if node.node_type in _NAME_TYPES and node.is_leaf():
|
|
168
|
-
seen.add(node.id)
|
|
169
|
-
targets.append((node, node))
|
|
170
|
-
elif node.node_type in (_DECL_NODE_TYPES | _PARAM_NODE_TYPES):
|
|
171
|
-
leaf = self._first_name_leaf(node)
|
|
172
|
-
if leaf is not None:
|
|
173
|
-
seen.add(node.id)
|
|
174
|
-
targets.append((node, leaf))
|
|
175
|
-
|
|
176
|
-
return targets
|
|
177
|
-
|
|
178
|
-
def _hover_triples(self, root: SemanticNode) -> list[tuple[str, int, int]]:
|
|
179
|
-
"""``(result_node_id, line, col)`` hover targets — Rust core first (issue 100 S2),
|
|
180
|
-
with :meth:`_collect_hover_targets` as the Python fallback/oracle."""
|
|
181
|
-
from intentumdiff.rust_core import try_rust_collect_hover_targets
|
|
182
|
-
|
|
183
|
-
rust_triples = try_rust_collect_hover_targets(root)
|
|
184
|
-
if rust_triples is not None:
|
|
185
|
-
return rust_triples
|
|
186
|
-
return [
|
|
187
|
-
(rn.id, pn.position.start_line, pn.position.start_col)
|
|
188
|
-
for rn, pn in self._collect_hover_targets(root)
|
|
189
|
-
]
|
|
89
|
+
def _hover_triples(self, root: SemanticNode, source_text: str) -> list[tuple[str, int, int]]:
|
|
90
|
+
"""Return the Rust engine's target decisions; failures propagate."""
|
|
91
|
+
from intentumdiff.rust_core import collect_lsp_hover_targets
|
|
92
|
+
return collect_lsp_hover_targets(root, source_text)
|
|
190
93
|
|
|
191
94
|
async def _query_node(
|
|
192
95
|
self,
|
|
@@ -200,23 +103,20 @@ class TypeEnricher:
|
|
|
200
103
|
async with sem:
|
|
201
104
|
try:
|
|
202
105
|
type_str = await self._client.hover(uri, line, col)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
"LSP hover failed for node %s at %d:%d — %s",
|
|
209
|
-
node_id, line, col, exc,
|
|
210
|
-
)
|
|
211
|
-
return node_id, None
|
|
106
|
+
except Exception as exc: # noqa: BLE001
|
|
107
|
+
raise RuntimeError(
|
|
108
|
+
f"LSP hover failed for node {node_id} at {line}:{col}: {exc}"
|
|
109
|
+
) from exc
|
|
110
|
+
return node_id, type_str
|
|
212
111
|
|
|
213
112
|
async def _query_all(
|
|
214
113
|
self,
|
|
215
114
|
uri: str,
|
|
216
115
|
root: SemanticNode,
|
|
116
|
+
source_text: str,
|
|
217
117
|
) -> dict[str, str]:
|
|
218
118
|
"""Fire all hover requests concurrently; collect non-None results."""
|
|
219
|
-
targets = self._hover_triples(root)
|
|
119
|
+
targets = self._hover_triples(root, source_text)
|
|
220
120
|
if not targets:
|
|
221
121
|
return {}
|
|
222
122
|
|
intentumdiff/lsp/exceptions.py
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
intentumdiff.lsp.exceptions
|
|
3
3
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
LSP transport exceptions used to report failures through the public indexer.
|
|
6
6
|
|
|
7
|
-
Both subclass ``Exception`` directly
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
fails is diffed without type information rather than aborting.
|
|
7
|
+
Both subclass ``Exception`` directly so callers can distinguish connection
|
|
8
|
+
failures and timeouts. A requested type-enrichment failure must not be
|
|
9
|
+
reported as a successfully completed bare semantic index.
|
|
11
10
|
"""
|
|
12
11
|
|
|
13
12
|
from __future__ import annotations
|
|
@@ -16,12 +15,12 @@ from __future__ import annotations
|
|
|
16
15
|
class LspConnectionError(Exception):
|
|
17
16
|
"""Raised when the TCP connection to the LSP server cannot be established.
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
Type enrichment cannot certify the file while connection is unavailable.
|
|
20
19
|
"""
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
class LspTimeoutError(Exception):
|
|
24
23
|
"""Raised when an LSP request does not receive a response within the timeout.
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
The failing hover request is not silently treated as unknown type.
|
|
27
26
|
"""
|