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
|
@@ -1,67 +1,34 @@
|
|
|
1
|
-
"""
|
|
2
|
-
intentumdiff.lsp_server._codelens
|
|
3
|
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1
|
+
"""Rust-owned LSP CodeLens presentation, with correct source-side UTF-16 spans.
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Rust owns which changes become lenses, their titles, and byte→UTF-16
|
|
4
|
+
coordinates. This thin Python module only converts Rust JSON to lsprotocol DTOs.
|
|
6
5
|
"""
|
|
7
|
-
|
|
8
6
|
from __future__ import annotations
|
|
9
7
|
|
|
10
8
|
from lsprotocol import types as lsp_types
|
|
9
|
+
from lsprotocol.converters import get_converter
|
|
11
10
|
|
|
12
|
-
from intentumdiff.core.models import
|
|
13
|
-
|
|
14
|
-
# Change types that are surfaced as code lenses.
|
|
15
|
-
_CODELENS_CHANGE_TYPES: frozenset[str] = frozenset({
|
|
16
|
-
ChangeType.REFACTORING,
|
|
17
|
-
ChangeType.MOVE,
|
|
18
|
-
ChangeType.MOVE_TO_MODULE,
|
|
19
|
-
ChangeType.CROSS_FILE_RENAME,
|
|
20
|
-
ChangeType.REORDER,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def node_to_lsp_range(node: SemanticNode) -> lsp_types.Range:
|
|
25
|
-
"""Convert a ``SemanticNode``'s position to an LSP ``Range`` (0-indexed)."""
|
|
26
|
-
pos = node.position
|
|
27
|
-
return lsp_types.Range(
|
|
28
|
-
start=lsp_types.Position(line=pos.start_line, character=pos.start_col),
|
|
29
|
-
end=lsp_types.Position(line=pos.end_line, character=pos.end_col),
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _codelens_title(change: Change) -> str:
|
|
34
|
-
"""Build the display title for a code-lens entry."""
|
|
35
|
-
if change.refactoring_kind is not None:
|
|
36
|
-
return f"\u21bb {change.refactoring_kind.name}: {change.description}"
|
|
37
|
-
ct = change.change_type
|
|
38
|
-
name = ct.name if isinstance(ct, ChangeType) else str(ct)
|
|
39
|
-
return f"\u27f3 {name}: {change.description}"
|
|
11
|
+
from intentumdiff.core.models import SemanticDiff, SemanticNode
|
|
12
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
40
13
|
|
|
41
14
|
|
|
42
|
-
def
|
|
43
|
-
"""
|
|
15
|
+
def node_to_lsp_range(node: SemanticNode, source: str) -> lsp_types.Range:
|
|
16
|
+
"""Convert only through the source-aware Rust C ABI, never guess columns."""
|
|
17
|
+
value = _c_abi_call("lsp_utf16_range", node.model_dump_json(), source)
|
|
18
|
+
if not isinstance(value, dict):
|
|
19
|
+
raise ValueError("Rust LSP range must be an object")
|
|
20
|
+
return get_converter().structure(value, lsp_types.Range)
|
|
44
21
|
|
|
45
|
-
Emitted for changes whose ``change_type`` is in
|
|
46
|
-
``{REFACTORING, MOVE, MOVE_TO_MODULE, CROSS_FILE_RENAME, REORDER}``.
|
|
47
|
-
The ``command`` field is left empty (display-only; no action on click).
|
|
48
|
-
"""
|
|
49
|
-
lenses: list[lsp_types.CodeLens] = []
|
|
50
22
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
),
|
|
64
|
-
)
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
return lenses
|
|
23
|
+
def semantic_diff_to_codelens(
|
|
24
|
+
diff: SemanticDiff, *, old_source: str, new_source: str,
|
|
25
|
+
) -> list[lsp_types.CodeLens]:
|
|
26
|
+
"""Decode Rust's source-anchored CodeLens inventory without Python policy."""
|
|
27
|
+
value = _c_abi_call(
|
|
28
|
+
"lsp_server_codelens_utf16", diff.model_dump_json(),
|
|
29
|
+
old_source, new_source,
|
|
30
|
+
)
|
|
31
|
+
if not isinstance(value, list):
|
|
32
|
+
raise ValueError("Rust LSP CodeLens must be an array")
|
|
33
|
+
converter = get_converter()
|
|
34
|
+
return [converter.structure(row, lsp_types.CodeLens) for row in value]
|
|
@@ -1,62 +1,34 @@
|
|
|
1
|
-
"""
|
|
2
|
-
intentumdiff.lsp_server._diagnostics
|
|
3
|
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
1
|
+
"""Rust-owned LSP diagnostics output, structured into Python transport DTOs.
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Semantic classification and UTF-8 byte→UTF-16 ranges belong to the Rust core.
|
|
4
|
+
The source-aware C ABI refuses invalid spans rather than publishing displaced
|
|
5
|
+
editor annotations. Python performs no diagnostic semantic classification.
|
|
6
6
|
"""
|
|
7
|
-
|
|
8
7
|
from __future__ import annotations
|
|
9
8
|
|
|
10
9
|
from lsprotocol import types as lsp_types
|
|
10
|
+
from lsprotocol.converters import get_converter
|
|
11
11
|
|
|
12
|
-
from intentumdiff.core.models import
|
|
12
|
+
from intentumdiff.core.models import SemanticDiff, SemanticNode
|
|
13
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
13
14
|
|
|
14
|
-
# Sentinel range covering the whole document — used for parse-error diagnostics.
|
|
15
|
-
_FULL_DOC_RANGE = lsp_types.Range(
|
|
16
|
-
start=lsp_types.Position(line=0, character=0),
|
|
17
|
-
end=lsp_types.Position(line=2**31 - 1, character=0),
|
|
18
|
-
)
|
|
19
15
|
|
|
16
|
+
def node_to_lsp_range(node: SemanticNode, source: str) -> lsp_types.Range:
|
|
17
|
+
"""Marshal a Rust source-judged UTF-16 range, requiring the actual source."""
|
|
18
|
+
value = _c_abi_call("lsp_utf16_range", node.model_dump_json(), source)
|
|
19
|
+
if not isinstance(value, dict):
|
|
20
|
+
raise ValueError("Rust LSP range must be an object")
|
|
21
|
+
return get_converter().structure(value, lsp_types.Range)
|
|
20
22
|
|
|
21
|
-
def node_to_lsp_range(node: SemanticNode) -> lsp_types.Range:
|
|
22
|
-
"""Convert a ``SemanticNode``'s position to an LSP ``Range``.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
def semantic_diff_to_diagnostics(
|
|
25
|
+
diff: SemanticDiff, *, new_source: str,
|
|
26
|
+
) -> list[lsp_types.Diagnostic]:
|
|
27
|
+
"""Decode Rust's source-aware diagnostic inventory (no Python fallback)."""
|
|
28
|
+
value = _c_abi_call(
|
|
29
|
+
"lsp_server_diagnostics_utf16", diff.model_dump_json(), new_source,
|
|
30
30
|
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* ``STYLE_ONLY`` changes → ``Hint`` severity (informational, on ``new_node``).
|
|
37
|
-
* Parse errors → ``Warning`` severity (full-document range).
|
|
38
|
-
"""
|
|
39
|
-
diags: list[lsp_types.Diagnostic] = []
|
|
40
|
-
|
|
41
|
-
for change in diff.changes:
|
|
42
|
-
if change.change_type == ChangeType.STYLE_ONLY and change.new_node is not None:
|
|
43
|
-
diags.append(
|
|
44
|
-
lsp_types.Diagnostic(
|
|
45
|
-
range=node_to_lsp_range(change.new_node),
|
|
46
|
-
severity=lsp_types.DiagnosticSeverity.Hint,
|
|
47
|
-
message="Style-only change — no semantic impact",
|
|
48
|
-
source="intentumdiff",
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
for err in diff.parse_errors:
|
|
53
|
-
diags.append(
|
|
54
|
-
lsp_types.Diagnostic(
|
|
55
|
-
range=_FULL_DOC_RANGE,
|
|
56
|
-
severity=lsp_types.DiagnosticSeverity.Warning,
|
|
57
|
-
message=f"Parse error: {err}",
|
|
58
|
-
source="intentumdiff",
|
|
59
|
-
)
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
return diags
|
|
31
|
+
if not isinstance(value, list):
|
|
32
|
+
raise ValueError("Rust LSP diagnostics must be an array")
|
|
33
|
+
converter = get_converter()
|
|
34
|
+
return [converter.structure(row, lsp_types.Diagnostic) for row in value]
|
|
@@ -37,6 +37,7 @@ class _ServerState:
|
|
|
37
37
|
ref: str
|
|
38
38
|
debounce: float
|
|
39
39
|
diff_cache: dict[str, SemanticDiff] = field(default_factory=dict)
|
|
40
|
+
source_cache: dict[str, tuple[str, str]] = field(default_factory=dict)
|
|
40
41
|
pending_tasks: dict[str, asyncio.Task] = field(default_factory=dict)
|
|
41
42
|
supports_codelens_refresh: bool = False
|
|
42
43
|
|
|
@@ -45,6 +46,17 @@ class _ServerState:
|
|
|
45
46
|
# URI helpers
|
|
46
47
|
# ---------------------------------------------------------------------------
|
|
47
48
|
|
|
49
|
+
class WorkspaceContainmentError(ValueError):
|
|
50
|
+
"""A URI resolved outside the workspace root, or used explicit traversal.
|
|
51
|
+
|
|
52
|
+
A distinct type because this is a REFUSAL, not a fault: the server did its job. Logged and
|
|
53
|
+
reported separately from internal errors so an operator can tell "someone asked for a path
|
|
54
|
+
outside the workspace and we blocked it" from "the diff engine threw".
|
|
55
|
+
|
|
56
|
+
Subclasses ValueError deliberately - callers that already catch ValueError keep working.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
|
|
48
60
|
def uri_to_path(uri: str, workspace_root: Path | None = None) -> Path:
|
|
49
61
|
"""Convert a ``file://`` URI to a :class:`~pathlib.Path`.
|
|
50
62
|
|
|
@@ -57,7 +69,7 @@ def uri_to_path(uri: str, workspace_root: Path | None = None) -> Path:
|
|
|
57
69
|
path = Path(unquote(parsed.path))
|
|
58
70
|
# Reject explicit traversal components
|
|
59
71
|
if ".." in path.parts:
|
|
60
|
-
raise
|
|
72
|
+
raise WorkspaceContainmentError(f"Path traversal rejected in URI: {uri!r}")
|
|
61
73
|
# On Windows, urlparse puts a leading '/' before the drive letter —
|
|
62
74
|
# strip it so Path('C:/foo') is constructed correctly.
|
|
63
75
|
if path.parts and path.parts[0] in ("/", "\\") and len(path.parts) > 1:
|
|
@@ -72,13 +84,41 @@ def uri_to_path(uri: str, workspace_root: Path | None = None) -> Path:
|
|
|
72
84
|
try:
|
|
73
85
|
resolved.relative_to(root_resolved)
|
|
74
86
|
except ValueError:
|
|
75
|
-
raise
|
|
87
|
+
raise WorkspaceContainmentError(
|
|
76
88
|
f"URI {uri!r} resolves to {resolved!r} which is outside the "
|
|
77
89
|
f"workspace root {root_resolved!r}."
|
|
78
90
|
)
|
|
79
91
|
return resolved
|
|
80
92
|
|
|
81
93
|
|
|
94
|
+
|
|
95
|
+
def _invalidate_failed_review(server, state: _ServerState, uri: str) -> None:
|
|
96
|
+
"""Fail closed at the LSP transport: old Rust results are no longer current."""
|
|
97
|
+
from lsprotocol import types as lsp_types
|
|
98
|
+
|
|
99
|
+
# Remove old CodeLens source before attempting I/O (publishing can itself fail).
|
|
100
|
+
state.diff_cache.pop(uri, None)
|
|
101
|
+
state.source_cache.pop(uri, None)
|
|
102
|
+
server.publish_diagnostics(uri, [
|
|
103
|
+
lsp_types.Diagnostic(
|
|
104
|
+
range=lsp_types.Range(
|
|
105
|
+
start=lsp_types.Position(line=0, character=0),
|
|
106
|
+
end=lsp_types.Position(line=0, character=0),
|
|
107
|
+
),
|
|
108
|
+
severity=lsp_types.DiagnosticSeverity.Error,
|
|
109
|
+
message="IntentumDiff semantic review failed; previous results are invalid.",
|
|
110
|
+
source="intentumdiff",
|
|
111
|
+
)
|
|
112
|
+
])
|
|
113
|
+
if state.supports_codelens_refresh:
|
|
114
|
+
try:
|
|
115
|
+
server.lsp.send_request("workspace/codeLens/refresh", None)
|
|
116
|
+
except Exception: # noqa: BLE001 - result stays invalidated.
|
|
117
|
+
log.debug("intentumdiff: failed CodeLens invalidation refresh", exc_info=True)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
82
122
|
# ---------------------------------------------------------------------------
|
|
83
123
|
# Async diff scheduling
|
|
84
124
|
# ---------------------------------------------------------------------------
|
|
@@ -109,18 +149,23 @@ async def _compute_and_push(
|
|
|
109
149
|
await asyncio.sleep(state.debounce)
|
|
110
150
|
|
|
111
151
|
loop = asyncio.get_running_loop()
|
|
112
|
-
|
|
113
|
-
None, _do_diff, state, server, uri, content
|
|
152
|
+
result = await loop.run_in_executor(
|
|
153
|
+
None, _do_diff, state, server, uri, content, True
|
|
114
154
|
)
|
|
115
|
-
if
|
|
155
|
+
if result is None:
|
|
156
|
+
# A failed Rust/Wasm review must not leave previously cached semantic
|
|
157
|
+
# CodeLens or diagnostics visible as though the current edit passed.
|
|
158
|
+
_invalidate_failed_review(server, state, uri)
|
|
116
159
|
return
|
|
117
160
|
|
|
161
|
+
diff, old_source, new_source = result
|
|
118
162
|
state.diff_cache[uri] = diff
|
|
163
|
+
state.source_cache[uri] = (old_source, new_source)
|
|
119
164
|
|
|
120
165
|
# Publish diagnostics (push model — no client request needed).
|
|
121
166
|
from intentumdiff.lsp_server._diagnostics import semantic_diff_to_diagnostics
|
|
122
167
|
|
|
123
|
-
diags = semantic_diff_to_diagnostics(diff)
|
|
168
|
+
diags = semantic_diff_to_diagnostics(diff, new_source=new_source)
|
|
124
169
|
server.publish_diagnostics(uri, diags)
|
|
125
170
|
|
|
126
171
|
# Ask the client to refresh code-lens decorations when supported.
|
|
@@ -137,6 +182,12 @@ async def _compute_and_push(
|
|
|
137
182
|
raise # propagate cancellation — do not swallow
|
|
138
183
|
except Exception as exc: # noqa: BLE001
|
|
139
184
|
log.warning("intentumdiff: unhandled error during diff for %s: %s", uri, exc)
|
|
185
|
+
# Even transport/publishing faults invalidate old semantic data. Never
|
|
186
|
+
# expose a stale successful review after the current review failed.
|
|
187
|
+
try:
|
|
188
|
+
_invalidate_failed_review(server, state, uri)
|
|
189
|
+
except Exception: # noqa: BLE001 - preserve the original failure log.
|
|
190
|
+
log.warning("intentumdiff: failed to publish review error for %s", uri, exc_info=True)
|
|
140
191
|
|
|
141
192
|
|
|
142
193
|
# ---------------------------------------------------------------------------
|
|
@@ -148,7 +199,8 @@ def _do_diff(
|
|
|
148
199
|
server,
|
|
149
200
|
uri: str,
|
|
150
201
|
content: str,
|
|
151
|
-
|
|
202
|
+
include_sources: bool = False,
|
|
203
|
+
) -> SemanticDiff | tuple[SemanticDiff, str, str] | None:
|
|
152
204
|
"""Compute a ``SemanticDiff`` synchronously.
|
|
153
205
|
|
|
154
206
|
Intended to be called via ``loop.run_in_executor`` so the event loop is
|
|
@@ -167,8 +219,14 @@ def _do_diff(
|
|
|
167
219
|
file_path=str(rel_path),
|
|
168
220
|
live_content=content,
|
|
169
221
|
ref=state.ref,
|
|
222
|
+
cache_snapshot=include_sources,
|
|
170
223
|
)
|
|
171
|
-
|
|
224
|
+
diff = state.differ.diff(source)
|
|
225
|
+
if include_sources:
|
|
226
|
+
# The differ and LSP mapping must see the same old Git snapshot.
|
|
227
|
+
old_source, new_source, _, _ = source.get_content()
|
|
228
|
+
return diff, old_source, new_source
|
|
229
|
+
return diff
|
|
172
230
|
|
|
173
231
|
except Exception as exc: # noqa: BLE001
|
|
174
232
|
log.warning("intentumdiff: diff failed for %s: %s", uri, exc)
|
|
@@ -36,6 +36,7 @@ from intentumdiff.lsp_server._handlers import (
|
|
|
36
36
|
_do_diff,
|
|
37
37
|
schedule_diff,
|
|
38
38
|
uri_to_path,
|
|
39
|
+
WorkspaceContainmentError,
|
|
39
40
|
)
|
|
40
41
|
|
|
41
42
|
log = logging.getLogger(__name__)
|
|
@@ -117,6 +118,7 @@ def create_server(
|
|
|
117
118
|
def _did_close(params: lsp_types.DidCloseTextDocumentParams) -> None:
|
|
118
119
|
uri = params.text_document.uri
|
|
119
120
|
state.diff_cache.pop(uri, None)
|
|
121
|
+
state.source_cache.pop(uri, None)
|
|
120
122
|
task = state.pending_tasks.pop(uri, None)
|
|
121
123
|
if task is not None and not task.done():
|
|
122
124
|
task.cancel()
|
|
@@ -134,7 +136,20 @@ def create_server(
|
|
|
134
136
|
diff = state.diff_cache.get(uri)
|
|
135
137
|
if diff is None:
|
|
136
138
|
return []
|
|
137
|
-
|
|
139
|
+
sources = state.source_cache.get(uri)
|
|
140
|
+
if sources is None:
|
|
141
|
+
from intentumdiff.lsp_server._handlers import _invalidate_failed_review
|
|
142
|
+
_invalidate_failed_review(server, state, uri)
|
|
143
|
+
return []
|
|
144
|
+
try:
|
|
145
|
+
return semantic_diff_to_codelens(
|
|
146
|
+
diff, old_source=sources[0], new_source=sources[1],
|
|
147
|
+
)
|
|
148
|
+
except Exception as exc:
|
|
149
|
+
log.warning("intentumdiff: Rust CodeLens mapping failed for %s: %s", uri, exc)
|
|
150
|
+
from intentumdiff.lsp_server._handlers import _invalidate_failed_review
|
|
151
|
+
_invalidate_failed_review(server, state, uri)
|
|
152
|
+
return []
|
|
138
153
|
|
|
139
154
|
# ------------------------------------------------------------------
|
|
140
155
|
# Custom request: intentumdiff/semanticDiff
|
|
@@ -168,7 +183,7 @@ def create_server(
|
|
|
168
183
|
diff = _do_diff(state, server, new_uri, content)
|
|
169
184
|
else:
|
|
170
185
|
# Different URIs — read both from disk and compare.
|
|
171
|
-
from intentumdiff.sources.
|
|
186
|
+
from intentumdiff.sources.file_source import FileSource
|
|
172
187
|
|
|
173
188
|
# Derive workspace root for containment check.
|
|
174
189
|
workspace_root: Path | None = None
|
|
@@ -184,11 +199,9 @@ def create_server(
|
|
|
184
199
|
|
|
185
200
|
old_path = uri_to_path(old_uri, workspace_root=workspace_root)
|
|
186
201
|
new_path = uri_to_path(new_uri, workspace_root=workspace_root)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
old_content=old_content,
|
|
191
|
-
new_content=new_content,
|
|
202
|
+
source = FileSource(
|
|
203
|
+
old_path=old_path,
|
|
204
|
+
new_path=new_path,
|
|
192
205
|
filename=new_path.name,
|
|
193
206
|
)
|
|
194
207
|
diff = state.differ.diff(source)
|
|
@@ -198,6 +211,14 @@ def create_server(
|
|
|
198
211
|
|
|
199
212
|
return json.loads(diff.model_dump_json())
|
|
200
213
|
|
|
214
|
+
except WorkspaceContainmentError as exc:
|
|
215
|
+
# A refusal, not a fault. Logged distinctly so an operator can tell "someone asked
|
|
216
|
+
# for a path outside the workspace and we blocked it" from "the engine threw" -
|
|
217
|
+
# previously both produced the same line at the same level, which made the audit
|
|
218
|
+
# trail for a path-traversal attempt indistinguishable from routine noise.
|
|
219
|
+
log.warning("intentumdiff/semanticDiff refused (workspace containment): %s", exc)
|
|
220
|
+
return {"error": str(exc), "code": "workspace_containment"}
|
|
221
|
+
|
|
201
222
|
except Exception as exc: # noqa: BLE001
|
|
202
223
|
log.warning("intentumdiff/semanticDiff error: %s", exc)
|
|
203
224
|
return {"error": str(exc)}
|
intentumdiff/plugins/adapter.py
CHANGED
|
@@ -142,6 +142,11 @@ class ParserAdapter:
|
|
|
142
142
|
"""Filesystem path of the backing ``.wasm`` file."""
|
|
143
143
|
return self._plugin.wasm_path
|
|
144
144
|
|
|
145
|
+
@property
|
|
146
|
+
def compiled_wasm_sha256(self) -> str | None:
|
|
147
|
+
"""Identity of the exact compiled Wasm buffer, supplied by the loader."""
|
|
148
|
+
return self._plugin.compiled_wasm_sha256
|
|
149
|
+
|
|
145
150
|
@property
|
|
146
151
|
def is_trusted(self) -> bool:
|
|
147
152
|
return self._plugin.trusted
|
intentumdiff/plugins/builtins.py
CHANGED
|
@@ -20,13 +20,6 @@ def _wasm(name: str) -> str:
|
|
|
20
20
|
return str(_WASM_DIR / name)
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def _wasm_or_generic(name: str) -> str:
|
|
24
|
-
path = _WASM_DIR / name
|
|
25
|
-
if path.exists():
|
|
26
|
-
return str(path)
|
|
27
|
-
return _wasm("generic_parser.wasm")
|
|
28
|
-
|
|
29
|
-
|
|
30
23
|
# ── Parser entry points ──────────────────────────────────────────────────────
|
|
31
24
|
|
|
32
25
|
def python_parser_entry() -> str:
|
|
@@ -42,31 +35,31 @@ def generic_parser_entry() -> str:
|
|
|
42
35
|
|
|
43
36
|
|
|
44
37
|
def graphql_parser_entry() -> str:
|
|
45
|
-
return
|
|
38
|
+
return _wasm("graphql_parser.wasm")
|
|
46
39
|
|
|
47
40
|
|
|
48
41
|
def gitignore_parser_entry() -> str:
|
|
49
|
-
return
|
|
42
|
+
return _wasm("gitignore_parser.wasm")
|
|
50
43
|
|
|
51
44
|
|
|
52
45
|
def ocaml_parser_entry() -> str:
|
|
53
|
-
return
|
|
46
|
+
return _wasm("ocaml_parser.wasm")
|
|
54
47
|
|
|
55
48
|
|
|
56
49
|
def reasonml_parser_entry() -> str:
|
|
57
|
-
return
|
|
50
|
+
return _wasm("reasonml_parser.wasm")
|
|
58
51
|
|
|
59
52
|
|
|
60
53
|
def latex_parser_entry() -> str:
|
|
61
|
-
return
|
|
54
|
+
return _wasm("latex_parser.wasm")
|
|
62
55
|
|
|
63
56
|
|
|
64
57
|
def asciidoc_parser_entry() -> str:
|
|
65
|
-
return
|
|
58
|
+
return _wasm("asciidoc_parser.wasm")
|
|
66
59
|
|
|
67
60
|
|
|
68
61
|
def po_parser_entry() -> str:
|
|
69
|
-
return
|
|
62
|
+
return _wasm("po_parser.wasm")
|
|
70
63
|
|
|
71
64
|
|
|
72
65
|
def js_ts_parser_entry() -> str:
|
|
@@ -91,3 +91,7 @@ class PluginLoadError(PluginError):
|
|
|
91
91
|
def __init__(self, wasm_path: str, detail: str) -> None:
|
|
92
92
|
self.wasm_path = wasm_path
|
|
93
93
|
super().__init__(f"Failed to load plugin from {wasm_path!r}: {detail}")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PluginSecurityError(PluginLoadError):
|
|
97
|
+
"""A security gate denied loading; parser fallback must not bypass the denial."""
|
intentumdiff/plugins/hub.py
CHANGED
|
@@ -20,8 +20,7 @@ Plugins can be installed from two sources:
|
|
|
20
20
|
|
|
21
21
|
For official plugins (no ``repo``), the short name is expanded to the
|
|
22
22
|
full package in the ``buchochelliq-labs`` GitHub org:
|
|
23
|
-
``dbt`` -> ``intentumdiff-dbt``
|
|
24
|
-
-> ``https://github.com/buchochelliq-labs/intentumdiff-dbt``
|
|
23
|
+
``dbt`` -> package ``intentumdiff-dbt`` in that org
|
|
25
24
|
|
|
26
25
|
Security model
|
|
27
26
|
--------------
|