intentumdiff-python 0.0.2b2__py3-none-win_amd64.whl → 0.0.3b1__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. intentumdiff/__init__.py +7 -0
  2. intentumdiff/_differ_gate.py +0 -136
  3. intentumdiff/_differ_presentation.py +1 -72
  4. intentumdiff/_differ_runtime.py +0 -17
  5. intentumdiff/analysis/cross_file.py +21 -21
  6. intentumdiff/analysis/diagnostics.py +1 -164
  7. intentumdiff/analysis/guardrail_reports.py +24 -28
  8. intentumdiff/analysis/guardrails.py +2 -67
  9. intentumdiff/analysis/schema_resolver.py +23 -87
  10. intentumdiff/analysis/user_schemas.py +2 -17
  11. intentumdiff/cli/_commands.py +70 -71
  12. intentumdiff/cli/_parser.py +40 -55
  13. intentumdiff/cli/_shared.py +55 -4
  14. intentumdiff/core/commit_differ.py +65 -99
  15. intentumdiff/core/indexer.py +0 -1
  16. intentumdiff/core/models.py +226 -69
  17. intentumdiff/differ.py +125 -432
  18. intentumdiff/github_app.py +5 -8
  19. intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
  20. intentumdiff/live_server.py +17 -17
  21. intentumdiff/lsp/client.py +42 -42
  22. intentumdiff/lsp/servers.py +10 -11
  23. intentumdiff/lsp_server/_handlers.py +1 -1
  24. intentumdiff/lsp_server/server.py +0 -1
  25. intentumdiff/plugins/exceptions.py +24 -0
  26. intentumdiff/plugins/hub.py +38 -41
  27. intentumdiff/plugins/registry.py +10 -10
  28. intentumdiff/plugins/registry.schema.json +156 -15
  29. intentumdiff/plugins/registry_schema.py +47 -140
  30. intentumdiff/rust_core.py +112 -775
  31. intentumdiff/serve/_app.py +23 -25
  32. intentumdiff/sources/git_source.py +0 -183
  33. intentumdiff/vcs/git_cli.py +0 -47
  34. intentumdiff/wasm/abap_parser.wasm +0 -0
  35. intentumdiff/wasm/adf_parser.wasm +0 -0
  36. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  37. intentumdiff/wasm/asm_parser.wasm +0 -0
  38. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  39. intentumdiff/wasm/astro_parser.wasm +0 -0
  40. intentumdiff/wasm/bash_parser.wasm +0 -0
  41. intentumdiff/wasm/cpp_parser.wasm +0 -0
  42. intentumdiff/wasm/csharp_parser.wasm +0 -0
  43. intentumdiff/wasm/databricks_parser.wasm +0 -0
  44. intentumdiff/wasm/dax_parser.wasm +0 -0
  45. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  46. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  47. intentumdiff/wasm/generic_parser.wasm +0 -0
  48. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  49. intentumdiff/wasm/graphql_parser.wasm +0 -0
  50. intentumdiff/wasm/groovy_parser.wasm +0 -0
  51. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  52. intentumdiff/wasm/json_parser.wasm +0 -0
  53. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  54. intentumdiff/wasm/latex_parser.wasm +0 -0
  55. intentumdiff/wasm/make_parser.wasm +0 -0
  56. intentumdiff/wasm/mdx_parser.wasm +0 -0
  57. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  58. intentumdiff/wasm/odin_parser.wasm +0 -0
  59. intentumdiff/wasm/perl_parser.wasm +0 -0
  60. intentumdiff/wasm/php_parser.wasm +0 -0
  61. intentumdiff/wasm/plsql_parser.wasm +0 -0
  62. intentumdiff/wasm/postscript_parser.wasm +0 -0
  63. intentumdiff/wasm/powershell_parser.wasm +0 -0
  64. intentumdiff/wasm/python_parser.wasm +0 -0
  65. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  66. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  67. intentumdiff/wasm/rust_parser.wasm +0 -0
  68. intentumdiff/wasm/sas_parser.wasm +0 -0
  69. intentumdiff/wasm/sql_parser.wasm +0 -0
  70. intentumdiff/wasm/svelte_parser.wasm +0 -0
  71. intentumdiff/wasm/swift_parser.wasm +0 -0
  72. intentumdiff/wasm/tsql_parser.wasm +0 -0
  73. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  74. intentumdiff/wasm/vue_parser.wasm +0 -0
  75. intentumdiff/wasm/wasm_provenance.json +219 -219
  76. intentumdiff/wasm/wat_parser.wasm +0 -0
  77. intentumdiff/wasm/yaml_parser.wasm +0 -0
  78. intentumdiff/watcher.py +15 -17
  79. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/METADATA +38 -6
  80. intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
  81. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +2 -2
  82. intentumdiff/analysis/invariances.py +0 -208
  83. intentumdiff/analysis/keyed_profiles.py +0 -25
  84. intentumdiff/analysis/resource_profiles.py +0 -14
  85. intentumdiff/analysis/text_review.py +0 -47
  86. intentumdiff/invariances/__init__.py +0 -2
  87. intentumdiff/invariances/rules.schema.json +0 -283
  88. intentumdiff/invariances/rules.yaml +0 -349
  89. intentumdiff_python-0.0.2b2.dist-info/RECORD +0 -171
  90. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +0 -0
  91. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/entry_points.txt +0 -0
  92. {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
intentumdiff/__init__.py CHANGED
@@ -33,6 +33,8 @@ from intentumdiff.core.models import (
33
33
  GuardrailCheckResult,
34
34
  GuardrailSeverity,
35
35
  GuardrailViolation,
36
+ IncompleteReport,
37
+ IncompleteReview,
36
38
  NodePosition,
37
39
  RefactoringKind,
38
40
  ReferenceKind,
@@ -54,6 +56,7 @@ from intentumdiff.sources.string_source import StringSource
54
56
  from intentumdiff.cache.store import CacheStore
55
57
  from intentumdiff.cache.sqlite_store import SqliteCacheStore
56
58
  from intentumdiff.live_server import LiveServer
59
+ from intentumdiff.rust_core import CoreSizeLimitError
57
60
 
58
61
  __all__ = [
59
62
  # Differ
@@ -81,6 +84,8 @@ __all__ = [
81
84
  "DetectionResult",
82
85
  "FUEL_UNLIMITED",
83
86
  "SemanticDiff",
87
+ "IncompleteReview",
88
+ "IncompleteReport",
84
89
  "Change",
85
90
  "ChangeGroup",
86
91
  "ChangeGroupKind",
@@ -106,6 +111,8 @@ __all__ = [
106
111
  "Indexer",
107
112
  # Live server
108
113
  "LiveServer",
114
+ # Errors
115
+ "CoreSizeLimitError",
109
116
  # Testing
110
117
  "PluginTestHarness",
111
118
  ]
@@ -51,142 +51,6 @@ def _rust_certified_languages() -> frozenset[str]:
51
51
  }
52
52
 
53
53
 
54
- # Languages whose per-stage draft FINALIZATION routes through the Rust core (issue #57 —
55
- # the retirement path for python refinement/presentation). Grows per parity-verified
56
- # language; INTENTUMDIFF_RUST_FINALIZE_LANGS (comma-separated) adds pilots.
57
- RUST_FINALIZE_LANGUAGES: frozenset[str] = frozenset(
58
- {
59
- "go", "kotlin", "ruby", "swift", "java", "c", "cpp", "gitignore",
60
- "csharp", "elixir", "perl", "scala", "xml", "haskell",
61
- # Structured-language batch (issue #57): parity-verified clean under routing —
62
- # no engine change, per-language contracts + cross-cutting infra all green.
63
- "adf", "asciidoc", "assemblyscript", "clojure", "databricks",
64
- "databricks-workflow", "dax", "groovy", "latex", "lua", "ocaml", "odin",
65
- "php", "plsql", "po", "postscript", "qsharp", "reasonml",
66
- "sas", "squirrel", "tsql", "vbnet", "wast", "wat",
67
- "puppet", "hcl",
68
- # Body-reference variable renames corroborated by an anchored callable's param rename
69
- # (promote_corroborated_variable_renames) — the routed analogue of refactoring.py's
70
- # inferred_rename_pairs, which the default path used for dart's single-letter renames.
71
- "dart",
72
- # Structured/markup batch (#57): parity-verified clean under routing (full-suite gated).
73
- # generic was piloted too but breaks the generic-text/markdown/text fallback path
74
- # (#35/#36/#44) — deferred to its own fix.
75
- "svelte", "astro", "vue", "mdx", "scss",
76
- # dockerfile: needs the resource-profile shell-command identity keying (dockerfile_key),
77
- # now ported to Rust so an inserted RUN doesn't cross-pair positionally.
78
- "dockerfile",
79
- # asm (experimental, #57): statement-profile language — instructions key by mnemonic +
80
- # first-operand identity (asm_key) so an operand-value edit is a MODIFICATION, not churn.
81
- "asm",
82
- # css (#57): unblocked by applying semantic invariances in the routed short-circuit —
83
- # the color-canonicalization equivalence (red≡#ff0000, blue≡#0000ff) now fires under
84
- # routing. (yaml/json graceful-xfail shape + python dedent still gap-blocked.)
85
- "css",
86
- # bash (#57): bash_key ported (commands key by NAME) + the cross-key MODIFICATION split —
87
- # `:` -> `echo Hello` unpaires into DELETE+ADD with descendant scaffold folded.
88
- "bash",
89
- # delphi (#57): delphi_key ported (statements keyed by call/assign identity) + statement
90
- # review containers anchor in suppress_parent_modifications — the WriteLn edit presents
91
- # as ONE statement MODIFICATION with descendant mods folded.
92
- "delphi",
93
- # m / Power Query (#57): served by the dax parser (dax routed-green); the step-edit
94
- # contract reformulated to anti-swallowing (routed pairs the predicate edit as ONE
95
- # MODIFICATION carrying both sides — honest, not the default's DELETE+ADD split).
96
- "m",
97
- # powershell (#57/#66): unblocked by the entity-anchored matching port — reordered
98
- # functions pair by identity and surface as MOVEs (31/31 force-routed).
99
- "powershell",
100
- # json/yaml (#57): keyed-data profile port — pairs/items key by ancestor key path; array
101
- # scalars/items by CONTENT identity (not position labels), so an inserted element never
102
- # cross-pairs later unchanged values; identical-content positional churn suppresses with
103
- # evidence; yaml block↔flow representation equivalence (YAML 1.2 §3) is style, not change.
104
- "json", "yaml",
105
- # html (#57/#64): path-profile keying port — elements key by their element PATH with
106
- # identity attributes (id/name/key/…) beating same-tag ordinals, and relocated
107
- # identical-content elements keep their match (stable-same-label escape) — a text edit
108
- # inside an id-bearing or restructured element survives sibling inserts.
109
- "html",
110
- # rust (#57/#60): unlocked by the entity-anchored matching port (augment_entity_matching)
111
- # — match→if-let now surfaces as a statement-rewrite MODIFICATION instead of losing the
112
- # relocated arm bodies to DELETE+ADD churn. Full rust suite 112/112 force-routed.
113
- "rust",
114
- # abap (#57): entity-anchored grouping ported (entity_child_content_groups) — a child
115
- # modification under a same-identity form groups as "GREET changed", not a free leaf edit.
116
- "abap",
117
- # r (#57): unblocked by the any→all truthiness fix in the signature-coverage suppression —
118
- # a NEW function sharing param labels with a rename is no longer erased.
119
- "r",
120
- # zig (#57): parity-verified clean under routing post-anchors (14/14 force-routed) —
121
- # pure routing, no engine change.
122
- "zig",
123
- # sql (#57): query-profile port (sql_key + matching/changes augmentation) — clauses,
124
- # relations, and fields pair by role + normalized identity within their statement, so an
125
- # added JOIN doesn't shift FROM into a bogus MOVE and unchanged SELECT fields never churn.
126
- # The dax half of the profile is deliberately NOT ported (dax routed green without it).
127
- "sql",
128
- # freebasic/terraform (#57): parity-verified clean under routing (dedicated tests +
129
- # the cross-cutting suites in the full gate) — pure routing, no engine change.
130
- "freebasic", "terraform",
131
- # graphql (#57/#67): unblocked by porting surface_changed_in_place_entity — a matched
132
- # named entity (type/query/fragment) whose body changed carries its label into a group.
133
- "graphql",
134
- # javascript/typescript/tsx (#57): three ports close the js-family gap — (1) the
135
- # function-valued-declaration profile (const f = () => … pairs with function f(…) as
136
- # one entity) in the anchors code, (2) the style rule relabelling suppression residue
137
- # as an IGNORED_STYLE group (provenance "suppression"), and (3) moved-pair literal
138
- # update recovery (the #37 leaf score, move-pair scoped): edit-script pruning of
139
- # unmatched leaves under moved subtrees was swallowing md5→sha256 inside a hoisted
140
- # calc_hash. Same-label DELETE+ADD container churn around reported renames suppresses
141
- # under a rename-coverage truthiness guard (tighter than the python pass it ports).
142
- "javascript", "typescript", "tsx",
143
- # generic (#57): the text review and both markdown section passes were already
144
- # Rust-first; the routed short-circuit now mirrors the stage-12 orchestration
145
- # (token churn replaced wholesale by Rust line spans, markdown section passes for
146
- # .md filenames, stage-12 style-only resolution for empty results).
147
- "generic",
148
- # python (#57): the flagship, last. The certified BATCH path (sources->final in
149
- # Rust, semantic_contract rust_finalized_v1) still serves default configs FIRST;
150
- # the tier behind it is the full-Rust 9-fin routing (the stage-11 hybrid and the
151
- # transitional python stages were deleted in the stage-4b payoff).
152
- "python",
153
- # markdown (#44): the tree-sitter markdown parser takes .md off the generic
154
- # fallback — sections/headings/fences are REAL nodes (the corpus "section"
155
- # entity vocabulary and the reorder→MOVE promotion consume them natively).
156
- "markdown",
157
- # toml (#48): keyed config format — tables/pairs are labeled by header/key
158
- # identity in the parser itself, so the routed finalize pairs value edits
159
- # under stable keys natively.
160
- "toml",
161
- # ini (#48): keyed config — sections by header, settings by key, same identity
162
- # model as toml; certified on the same template.
163
- "ini",
164
- # gomod (#48): keyed dependency manifest — specs by module path, versions as
165
- # semantic children; a version bump is ONE modification under stable identity.
166
- "gomod",
167
- # make (#48): rules by target identity, assignments by variable name, recipe
168
- # lines as semantic children — a recipe edit pairs under its target.
169
- "make",
170
- # proto (#48): messages/services/enums/rpcs by name, fields by identifier with
171
- # type + field number as semantic children — the wire-compat review story.
172
- "proto",
173
- # cmake (#48): commands labeled identifier(first-arg) so target identity is
174
- # part of the command; function/macro defs by their defined name.
175
- "cmake",
176
- }
177
- )
178
-
179
-
180
- def _rust_finalize_languages() -> frozenset[str]:
181
- # The set is TOTAL (all 67 supported languages, issue #57 2026-07-15), so it now
182
- # serves as the certified-language allowlist. The INTENTUMDIFF_RUST_FINALIZE_LANGS
183
- # pilot escape hatch is retired with the campaign: it existed to force-route
184
- # candidates during per-language certification, and every candidate is routed.
185
- # New languages certify by joining RUST_FINALIZE_LANGUAGES in code, behind the
186
- # same protocol (force-routed probe -> Rust pin -> full gate -> flip).
187
- return RUST_FINALIZE_LANGUAGES
188
-
189
-
190
54
  def _strict_rust_only_enabled() -> bool:
191
55
  return os.getenv(STRICT_RUST_GATE_ENV, "").strip() == "1"
192
56
 
@@ -1,21 +1,11 @@
1
- """Tree, markdown-presentation, fallback-diff and stream helpers for intentumdiff.differ."""
1
+ """Tree and fallback-diff helpers for intentumdiff.differ."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import hashlib
6
- import json
7
5
  import logging
8
6
  from typing import Any
9
7
 
10
- from intentumdiff.analysis.text_review import (
11
- PresentationResult,
12
- )
13
8
  from intentumdiff.core.models import (
14
- Change,
15
- ChangeGroup,
16
- ChangeGroupKind,
17
- ChangeType,
18
- NodePosition,
19
9
  SemanticDiff,
20
10
  SemanticNode,
21
11
  )
@@ -44,37 +34,6 @@ def _validate_tree_ids(root: SemanticNode, context: str) -> None:
44
34
  )
45
35
 
46
36
 
47
- def _root_structural_hash(node: SemanticNode) -> str:
48
- """Return the structural hash of a SemanticNode root (already computed)."""
49
- return node.structural_hash
50
-
51
-
52
- def _node_to_dict(node: SemanticNode) -> dict[str, Any]:
53
- return json.loads(node.model_dump_json())
54
-
55
-
56
- def _compute_structural_hash_for_tree(cst_json: str) -> str:
57
- """
58
- Compute the structural hash of the FILTERED (trivia-stripped) CST.
59
- Used for the style-only shortcut before running the full diff algorithm.
60
- """
61
- from intentumdiff.plugins.loader import _structural_hash_impl
62
-
63
- return _structural_hash_impl(cst_json)
64
-
65
-
66
- def _count_cst_nodes(cst_json: str) -> int:
67
- """Count total nodes in a CST JSON string (recursive depth-first)."""
68
-
69
- def _count(node: Any) -> int:
70
- return 1 + sum(_count(c) for c in node.get("children", ()))
71
-
72
- try:
73
- return _count(json.loads(cst_json))
74
- except Exception:
75
- return 0
76
-
77
-
78
37
  def _count_semantic_nodes(root: SemanticNode) -> int:
79
38
  return 1 + len(root.descendants())
80
39
 
@@ -84,31 +43,6 @@ def _empty_semantic_tree(language: str) -> SemanticNode:
84
43
  return SemanticNode.model_validate(_c_abi_call("empty_semantic_tree", language))
85
44
 
86
45
 
87
- def _markdown_presentation(presented: PresentationResult, *, old_source: str, new_source: str,
88
- old_filename: str, new_filename: str, phase: str) -> PresentationResult:
89
- """DTO adapter for complete Rust reconciliation; core errors propagate."""
90
- from intentumdiff.rust_core import _c_abi_call, _require_source_anchored_changes
91
- result = _c_abi_call("reconcile_markdown", {
92
- "changes": [change.model_dump(mode="json") for change in presented.changes],
93
- "change_groups": [group.model_dump(mode="json") for group in presented.change_groups],
94
- "ignored_style_changes": presented.ignored_style_changes,
95
- }, old_source, new_source, old_filename, new_filename, phase)
96
- return PresentationResult(
97
- changes=[Change.model_validate(value) for value in
98
- _require_source_anchored_changes(result["changes"], "Rust Markdown reconciliation")],
99
- change_groups=[ChangeGroup.model_validate(value) for value in result["change_groups"]],
100
- ignored_style_changes=result["ignored_style_changes"],
101
- )
102
-
103
-
104
- def _markdown_section_move_presentation(presented: PresentationResult, **kwargs: Any) -> PresentationResult:
105
- return _markdown_presentation(presented, phase="moves", **kwargs)
106
-
107
-
108
- def _markdown_section_heading_rename_presentation(presented: PresentationResult, **kwargs: Any) -> PresentationResult:
109
- return _markdown_presentation(presented, phase="renames", **kwargs)
110
-
111
-
112
46
  def _has_error_node(tree: SemanticNode) -> bool:
113
47
  """Ask Rust whether a semantic tree contains a parse error."""
114
48
  from intentumdiff.rust_core import parse_errors_present
@@ -127,11 +61,6 @@ def _token_fallback_diff(
127
61
  return result.model_copy(update={"metadata": {**details, **dict(result.metadata)}})
128
62
 
129
63
 
130
- # ---------------------------------------------------------------------------
131
- # Streaming helpers
132
- # ---------------------------------------------------------------------------
133
-
134
-
135
64
  def _enrich_literal_labels(root: SemanticNode, source: str) -> SemanticNode:
136
65
  """Delegate literal-label enrichment to Rust; never reconstruct semantics."""
137
66
  from intentumdiff.rust_core import enrich_literal_labels
@@ -72,8 +72,6 @@ class _PhaseProfiler:
72
72
  }
73
73
 
74
74
 
75
- _DEFAULT_PLUGIN_FUEL = 100_000_000
76
- _EXPLICIT_FUEL_EXHAUSTION_TEST_CAP = 1_000_000
77
75
  # Hotspot thresholds are calibrated to the measured worst legitimate parser plus ~30%
78
76
  # headroom. Two effects moved the floor in 2026-07: literal-container text capture in the
79
77
  # tree-sitter converters (issue #46 — a deliberate correctness cost), and whole-binary LTO
@@ -103,21 +101,6 @@ def _attach_content_type_metadata(
103
101
  return diff.model_copy(update={"metadata": metadata})
104
102
 
105
103
 
106
- def _fuel_budget(base: int, extra: int) -> int:
107
- """Return an adaptive budget without hiding explicit low-fuel tests.
108
-
109
- Real editor/CLI fuel settings are a floor, not a guarantee that ordinary
110
- source files will fail once they cross that exact number. Tiny budgets are
111
- still respected so fuel-pressure tests can prove runaway plugins fail
112
- explicitly instead of being silently promoted to a larger cap.
113
- """
114
- if base == -1:
115
- return base
116
- if base < _EXPLICIT_FUEL_EXHAUSTION_TEST_CAP:
117
- return base
118
- return max(base, extra)
119
-
120
-
121
104
  def _drain_plugin_telemetry(plugin_adapter: Any) -> list[dict[str, Any]]:
122
105
  drain = getattr(plugin_adapter, "drain_telemetry", None)
123
106
  if not callable(drain):
@@ -46,24 +46,24 @@ def detect_cross_file_changes(
46
46
 
47
47
  result = try_rust_diff_symbol_tables(old_json, new_json)
48
48
 
49
- changes: list[CrossFileChange] = []
50
- for item in result:
51
- changes.append(
52
- CrossFileChange(
53
- change_type=ChangeType(item["change_type"]),
54
- symbol_name=item["symbol_name"],
55
- old_file=item["old_file"],
56
- new_file=item["new_file"],
57
- old_node_id=item.get("old_node_id"),
58
- new_node_id=item.get("new_node_id"),
59
- old_position=item.get("old_position"),
60
- new_position=item.get("new_position"),
61
- old_language=item.get("old_language", ""),
62
- new_language=item.get("new_language", ""),
63
- node_type=item.get("node_type", ""),
64
- symbol_kind=item.get("symbol_kind", ""),
65
- confidence=item.get("confidence", 1.0),
66
- description=item.get("description", ""),
67
- )
68
- )
69
- return changes
49
+ return [cross_file_change_from_core(item) for item in result]
50
+
51
+
52
+ def cross_file_change_from_core(item: dict) -> CrossFileChange:
53
+ """DTO mapping for one core cross-file change."""
54
+ return CrossFileChange(
55
+ change_type=ChangeType(item["change_type"]),
56
+ symbol_name=item["symbol_name"],
57
+ old_file=item["old_file"],
58
+ new_file=item["new_file"],
59
+ old_node_id=item.get("old_node_id"),
60
+ new_node_id=item.get("new_node_id"),
61
+ old_position=item.get("old_position"),
62
+ new_position=item.get("new_position"),
63
+ old_language=item.get("old_language", ""),
64
+ new_language=item.get("new_language", ""),
65
+ node_type=item.get("node_type", ""),
66
+ symbol_kind=item.get("symbol_kind", ""),
67
+ confidence=item.get("confidence", 1.0),
68
+ description=item.get("description", ""),
69
+ )
@@ -6,14 +6,10 @@ from collections.abc import Mapping, Sequence
6
6
  from dataclasses import dataclass, field
7
7
  from typing import Any
8
8
 
9
- from intentumdiff.core.models import Change, ChangeGroup, ChangeType, SemanticNode
9
+ from intentumdiff.core.models import ChangeGroup, SemanticNode
10
10
 
11
11
 
12
12
  DIAGNOSTICS_VERSION = 2
13
- _PAIR_SAMPLE_LIMIT = 8
14
- _CANDIDATE_SAMPLE_LIMIT = 8
15
-
16
-
17
13
  @dataclass
18
14
  class DiagnosticsRecorder:
19
15
  """Collect JSON-safe diagnostics events when enabled."""
@@ -101,40 +97,6 @@ class DiagnosticsRecorder:
101
97
  metadata=payload,
102
98
  )
103
99
 
104
- def record_candidate_summary(
105
- self,
106
- *,
107
- stage: str,
108
- rule_id: str,
109
- action: str = "candidate_summary",
110
- reason: str = "",
111
- evaluated_count: int = 0,
112
- accepted_count: int = 0,
113
- rejected_count: int = 0,
114
- rejection_reasons: Mapping[str, int] | None = None,
115
- accepted_samples: Sequence[Mapping[str, Any]] = (),
116
- rejected_samples: Sequence[Mapping[str, Any]] = (),
117
- metadata: Mapping[str, Any] | None = None,
118
- ) -> None:
119
- """Record bounded accepted/rejected candidate evidence."""
120
-
121
- payload = {
122
- "evaluated_count": evaluated_count,
123
- "accepted_count": accepted_count,
124
- "rejected_count": rejected_count,
125
- "rejection_reasons": dict(rejection_reasons or {}),
126
- "accepted_samples": list(accepted_samples[:_CANDIDATE_SAMPLE_LIMIT]),
127
- "rejected_samples": list(rejected_samples[:_CANDIDATE_SAMPLE_LIMIT]),
128
- **dict(metadata or {}),
129
- }
130
- self.record(
131
- stage=stage,
132
- action=action,
133
- rule_id=rule_id,
134
- reason=reason,
135
- metadata=payload,
136
- )
137
-
138
100
  def record_group(self, *, stage: str, group: ChangeGroup) -> None:
139
101
  kind = group.kind.value if hasattr(group.kind, "value") else str(group.kind)
140
102
  self.record(
@@ -158,39 +120,6 @@ class DiagnosticsRecorder:
158
120
  },
159
121
  )
160
122
 
161
- def record_change(
162
- self,
163
- *,
164
- stage: str,
165
- change: Change,
166
- action: str = "change",
167
- rule_id: str = "",
168
- reason: str = "",
169
- ) -> None:
170
- change_type = (
171
- change.change_type.value
172
- if isinstance(change.change_type, ChangeType)
173
- else str(change.change_type)
174
- )
175
- self.record(
176
- stage=stage,
177
- action=action,
178
- rule_id=rule_id,
179
- reason=reason,
180
- old_nodes=[change.old_node],
181
- new_nodes=[change.new_node],
182
- confidence=change.confidence,
183
- metadata={
184
- "change_type": change_type,
185
- "description": change.description,
186
- "refactoring_kind": (
187
- change.refactoring_kind.value
188
- if change.refactoring_kind is not None
189
- else None
190
- ),
191
- },
192
- )
193
-
194
123
  def snapshot(self) -> dict[str, Any]:
195
124
  return {
196
125
  "version": DIAGNOSTICS_VERSION,
@@ -200,98 +129,6 @@ class DiagnosticsRecorder:
200
129
  }
201
130
 
202
131
 
203
- def record_matching_delta(
204
- recorder: DiagnosticsRecorder,
205
- *,
206
- stage: str,
207
- rule_id: str,
208
- before: Sequence[Any],
209
- after: Sequence[Any],
210
- ) -> None:
211
- """Record before/after matching counts and sampled pair changes."""
212
-
213
- if not recorder.enabled:
214
- return
215
-
216
- before_pairs = {_pair_key(match): match for match in before}
217
- after_pairs = {_pair_key(match): match for match in after}
218
- added = [after_pairs[key] for key in after_pairs.keys() - before_pairs.keys()]
219
- removed = [before_pairs[key] for key in before_pairs.keys() - after_pairs.keys()]
220
- if not added and not removed and len(before_pairs) == len(after_pairs):
221
- recorder.record(
222
- stage=stage,
223
- action="augment_matching",
224
- rule_id=rule_id,
225
- reason="no matching changes",
226
- metadata={"before_pairs": len(before_pairs), "after_pairs": len(after_pairs)},
227
- )
228
- return
229
-
230
- recorder.record(
231
- stage=stage,
232
- action="augment_matching",
233
- rule_id=rule_id,
234
- reason="matching augmentation applied",
235
- metadata={
236
- "before_pairs": len(before_pairs),
237
- "after_pairs": len(after_pairs),
238
- "added_pair_count": len(added),
239
- "removed_pair_count": len(removed),
240
- "added_pairs": [_pair_digest(match) for match in added[:_PAIR_SAMPLE_LIMIT]],
241
- "removed_pairs": [
242
- _pair_digest(match) for match in removed[:_PAIR_SAMPLE_LIMIT]
243
- ],
244
- },
245
- )
246
-
247
-
248
- def _pair_key(match: Any) -> tuple[str, str]:
249
- return (match.old_node.id, match.new_node.id)
250
-
251
-
252
- def _pair_digest(match: Any) -> dict[str, Any]:
253
- return {
254
- "old_id": match.old_node.id,
255
- "new_id": match.new_node.id,
256
- "old_type": match.old_node.node_type,
257
- "new_type": match.new_node.node_type,
258
- "old_label": match.old_node.label,
259
- "new_label": match.new_node.label,
260
- }
261
-
262
-
263
- def node_digest(node: SemanticNode | None) -> dict[str, Any]:
264
- """Return a small diagnostics-safe node reference."""
265
-
266
- if node is None:
267
- return {}
268
- return {
269
- "id": node.id,
270
- "type": node.node_type,
271
- "label": node.label,
272
- }
273
-
274
-
275
- def pair_digest(
276
- old_node: SemanticNode | None,
277
- new_node: SemanticNode | None,
278
- *,
279
- score: float | None = None,
280
- reason: str = "",
281
- ) -> dict[str, Any]:
282
- """Return a small diagnostics-safe old/new candidate reference."""
283
-
284
- payload: dict[str, Any] = {
285
- "old": node_digest(old_node),
286
- "new": node_digest(new_node),
287
- }
288
- if score is not None:
289
- payload["score"] = round(score, 4)
290
- if reason:
291
- payload["reason"] = reason
292
- return payload
293
-
294
-
295
132
  def _json_safe(value: Any, *, depth: int = 0) -> Any:
296
133
  if depth > 6:
297
134
  return str(value)
@@ -22,25 +22,10 @@ def build_guardrail_check_result(
22
22
  strict: bool,
23
23
  metadata: Mapping[str, Any] | None = None,
24
24
  ) -> GuardrailCheckResult:
25
- """Build a counted, JSON-safe guardrail check result."""
25
+ """Core's guardrail check verdict for a list of violations (``guardrail_check_result``)."""
26
26
 
27
- items = list(violations)
28
- immutable_count = sum(
29
- violation.severity == GuardrailSeverity.IMMUTABLE for violation in items
30
- )
31
- important_count = sum(
32
- violation.severity == GuardrailSeverity.IMPORTANT for violation in items
33
- )
34
- return GuardrailCheckResult(
35
- violations=items,
36
- violation_count=len(items),
37
- immutable_count=immutable_count,
38
- important_count=important_count,
39
- checked_files=checked_files,
40
- strict=strict,
41
- passed=not (strict and immutable_count),
42
- metadata=metadata or {},
43
- )
27
+ items = [violation.model_dump(mode="json") for violation in violations]
28
+ return _core_check_result({"violations": items}, strict, checked_files, metadata)
44
29
 
45
30
 
46
31
  def guardrail_result_from_diffs(
@@ -50,20 +35,31 @@ def guardrail_result_from_diffs(
50
35
  checked_files: int | None = None,
51
36
  metadata: Mapping[str, Any] | None = None,
52
37
  ) -> GuardrailCheckResult:
53
- """Collect guardrail evidence from one or more semantic diffs."""
38
+ """Core's verdict over the diffs' violations; core counts the diffs as checked files."""
54
39
 
55
40
  items = [diffs] if isinstance(diffs, SemanticDiff) else list(diffs)
56
- violations = [
57
- violation
41
+ # Core reads only each diff's ``guardrail_violations``, so only that field is marshalled.
42
+ evidence = [
43
+ {"guardrail_violations": [v.model_dump(mode="json") for v in diff.guardrail_violations]}
58
44
  for diff in items
59
- for violation in diff.guardrail_violations
60
45
  ]
61
- return build_guardrail_check_result(
62
- violations,
63
- checked_files=len(items) if checked_files is None else checked_files,
64
- strict=strict,
65
- metadata=metadata,
66
- )
46
+ return _core_check_result({"diffs": evidence}, strict, checked_files, metadata)
47
+
48
+
49
+ def _core_check_result(
50
+ evidence: dict[str, Any],
51
+ strict: bool,
52
+ checked_files: int | None,
53
+ metadata: Mapping[str, Any] | None,
54
+ ) -> GuardrailCheckResult:
55
+ # Core owns the counts and the gate (``passed = !strict || no violations``, #296); the DTO
56
+ # only validates the result and rejects counts that disagree with the violations.
57
+ from intentumdiff.rust_core import _c_abi_call # noqa: PLC0415
58
+
59
+ request = {**evidence, "strict": strict, "checked_files": checked_files,
60
+ "metadata": None if metadata is None else dict(metadata)}
61
+ result = _c_abi_call("guardrail_check_result", json.dumps(request))
62
+ return GuardrailCheckResult.model_validate(result)
67
63
 
68
64
 
69
65
  def render_guardrail_json(result: GuardrailCheckResult, *, indent: int = 2) -> str: