intentumdiff-python 0.0.1__py3-none-win_arm64.whl → 0.0.3b1__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.
Files changed (150) hide show
  1. intentumdiff/__init__.py +9 -0
  2. intentumdiff/__main__.py +12 -0
  3. intentumdiff/_differ_gate.py +0 -136
  4. intentumdiff/_differ_presentation.py +17 -735
  5. intentumdiff/_differ_runtime.py +13 -64
  6. intentumdiff/analysis/compile_commands.py +26 -141
  7. intentumdiff/analysis/cross_file.py +23 -25
  8. intentumdiff/analysis/diagnostics.py +1 -164
  9. intentumdiff/analysis/guardrail_reports.py +31 -33
  10. intentumdiff/analysis/guardrails.py +111 -188
  11. intentumdiff/analysis/schema_resolver.py +72 -360
  12. intentumdiff/analysis/user_schemas.py +57 -254
  13. intentumdiff/api.py +21 -0
  14. intentumdiff/cache/sqlite_store.py +5 -23
  15. intentumdiff/cli/__init__.py +59 -0
  16. intentumdiff/cli/_commands.py +243 -137
  17. intentumdiff/cli/_parser.py +51 -56
  18. intentumdiff/cli/_shared.py +151 -116
  19. intentumdiff/content_type.py +13 -30
  20. intentumdiff/core/commit_differ.py +137 -286
  21. intentumdiff/core/diffignore.py +28 -34
  22. intentumdiff/core/index.py +16 -18
  23. intentumdiff/core/indexer.py +148 -169
  24. intentumdiff/core/models.py +279 -83
  25. intentumdiff/differ.py +366 -1000
  26. intentumdiff/github_app.py +40 -27
  27. intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
  28. intentumdiff/live_server.py +197 -34
  29. intentumdiff/lsp/client.py +49 -43
  30. intentumdiff/lsp/enricher.py +19 -119
  31. intentumdiff/lsp/exceptions.py +6 -7
  32. intentumdiff/lsp/servers.py +10 -11
  33. intentumdiff/lsp_server/_codelens.py +24 -57
  34. intentumdiff/lsp_server/_diagnostics.py +23 -51
  35. intentumdiff/lsp_server/_handlers.py +67 -9
  36. intentumdiff/lsp_server/server.py +28 -8
  37. intentumdiff/plugins/adapter.py +5 -0
  38. intentumdiff/plugins/builtins.py +7 -14
  39. intentumdiff/plugins/exceptions.py +28 -0
  40. intentumdiff/plugins/hub.py +39 -43
  41. intentumdiff/plugins/loader.py +229 -215
  42. intentumdiff/plugins/registry.py +259 -207
  43. intentumdiff/plugins/registry.schema.json +156 -15
  44. intentumdiff/plugins/registry_schema.py +47 -140
  45. intentumdiff/rust_core.py +623 -1326
  46. intentumdiff/serve/_app.py +26 -35
  47. intentumdiff/sources/base.py +24 -0
  48. intentumdiff/sources/file_source.py +15 -2
  49. intentumdiff/sources/git_source.py +64 -185
  50. intentumdiff/sources/live_buffer_source.py +45 -5
  51. intentumdiff/sources/patch_source.py +36 -109
  52. intentumdiff/vcs/_safe_path.py +7 -0
  53. intentumdiff/vcs/base.py +6 -0
  54. intentumdiff/vcs/git_backend.py +1 -1
  55. intentumdiff/vcs/git_cli.py +0 -27
  56. intentumdiff/vcs/hg_backend.py +1 -1
  57. intentumdiff/vcs/perforce_backend.py +7 -1
  58. intentumdiff/vcs/svn_backend.py +1 -1
  59. intentumdiff/wasm/abap_parser.wasm +0 -0
  60. intentumdiff/wasm/adf_parser.wasm +0 -0
  61. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  62. intentumdiff/wasm/asm_parser.wasm +0 -0
  63. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  64. intentumdiff/wasm/astro_parser.wasm +0 -0
  65. intentumdiff/wasm/bash_parser.wasm +0 -0
  66. intentumdiff/wasm/clojure_parser.wasm +0 -0
  67. intentumdiff/wasm/cmake_parser.wasm +0 -0
  68. intentumdiff/wasm/cpp_parser.wasm +0 -0
  69. intentumdiff/wasm/csharp_parser.wasm +0 -0
  70. intentumdiff/wasm/css_parser.wasm +0 -0
  71. intentumdiff/wasm/dart_parser.wasm +0 -0
  72. intentumdiff/wasm/databricks_parser.wasm +0 -0
  73. intentumdiff/wasm/dax_parser.wasm +0 -0
  74. intentumdiff/wasm/delphi_parser.wasm +0 -0
  75. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  76. intentumdiff/wasm/elixir_parser.wasm +0 -0
  77. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  78. intentumdiff/wasm/generic_parser.wasm +0 -0
  79. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  80. intentumdiff/wasm/go_parser.wasm +0 -0
  81. intentumdiff/wasm/gomod_parser.wasm +0 -0
  82. intentumdiff/wasm/graphql_parser.wasm +0 -0
  83. intentumdiff/wasm/groovy_parser.wasm +0 -0
  84. intentumdiff/wasm/haskell_parser.wasm +0 -0
  85. intentumdiff/wasm/html_parser.wasm +0 -0
  86. intentumdiff/wasm/html_renderer.wasm +0 -0
  87. intentumdiff/wasm/ini_parser.wasm +0 -0
  88. intentumdiff/wasm/java_parser.wasm +0 -0
  89. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  90. intentumdiff/wasm/json_parser.wasm +0 -0
  91. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  92. intentumdiff/wasm/latex_parser.wasm +0 -0
  93. intentumdiff/wasm/llm_renderer.wasm +0 -0
  94. intentumdiff/wasm/lua_parser.wasm +0 -0
  95. intentumdiff/wasm/make_parser.wasm +0 -0
  96. intentumdiff/wasm/markdown_parser.wasm +0 -0
  97. intentumdiff/wasm/mdx_parser.wasm +0 -0
  98. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  99. intentumdiff/wasm/odin_parser.wasm +0 -0
  100. intentumdiff/wasm/parser_manifest.json +81 -2
  101. intentumdiff/wasm/patch_renderer.wasm +0 -0
  102. intentumdiff/wasm/perl_parser.wasm +0 -0
  103. intentumdiff/wasm/php_parser.wasm +0 -0
  104. intentumdiff/wasm/plsql_parser.wasm +0 -0
  105. intentumdiff/wasm/po_parser.wasm +0 -0
  106. intentumdiff/wasm/postscript_parser.wasm +0 -0
  107. intentumdiff/wasm/powershell_parser.wasm +0 -0
  108. intentumdiff/wasm/proto_parser.wasm +0 -0
  109. intentumdiff/wasm/puppet_parser.wasm +0 -0
  110. intentumdiff/wasm/python_parser.wasm +0 -0
  111. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  112. intentumdiff/wasm/r_parser.wasm +0 -0
  113. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  114. intentumdiff/wasm/ruby_parser.wasm +0 -0
  115. intentumdiff/wasm/rust_parser.wasm +0 -0
  116. intentumdiff/wasm/sas_parser.wasm +0 -0
  117. intentumdiff/wasm/scala_parser.wasm +0 -0
  118. intentumdiff/wasm/scss_parser.wasm +0 -0
  119. intentumdiff/wasm/sql_parser.wasm +0 -0
  120. intentumdiff/wasm/squirrel_parser.wasm +0 -0
  121. intentumdiff/wasm/svelte_parser.wasm +0 -0
  122. intentumdiff/wasm/swift_parser.wasm +0 -0
  123. intentumdiff/wasm/terminal_renderer.wasm +0 -0
  124. intentumdiff/wasm/terraform_parser.wasm +0 -0
  125. intentumdiff/wasm/toml_parser.wasm +0 -0
  126. intentumdiff/wasm/tsql_parser.wasm +0 -0
  127. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  128. intentumdiff/wasm/vue_parser.wasm +0 -0
  129. intentumdiff/wasm/wasm_provenance.json +884 -0
  130. intentumdiff/wasm/wat_parser.wasm +0 -0
  131. intentumdiff/wasm/xml_parser.wasm +0 -0
  132. intentumdiff/wasm/yaml_parser.wasm +0 -0
  133. intentumdiff/wasm/zig_parser.wasm +0 -0
  134. intentumdiff/watcher.py +15 -17
  135. intentumdiff_python-0.0.3b1.dist-info/METADATA +188 -0
  136. intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
  137. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +1 -1
  138. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
  139. intentumdiff/analysis/invariances.py +0 -1207
  140. intentumdiff/analysis/keyed_profiles.py +0 -25
  141. intentumdiff/analysis/resource_profiles.py +0 -14
  142. intentumdiff/analysis/text_review.py +0 -46
  143. intentumdiff/core/cst_serializer.py +0 -101
  144. intentumdiff/invariances/__init__.py +0 -2
  145. intentumdiff/invariances/rules.schema.json +0 -283
  146. intentumdiff/invariances/rules.yaml +0 -349
  147. intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
  148. intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
  149. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/entry_points.txt +0 -0
  150. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
@@ -119,29 +119,28 @@ def _build_parser() -> argparse.ArgumentParser:
119
119
  git_p = sub.add_parser("git", help="Diff a file between two git commits.")
120
120
  git_p.set_defaults(repo=".", file=None)
121
121
  git_p.add_argument(
122
- "_git_pos", nargs="*", action=_GitPositionalsAction,
123
- metavar="[REPO] [FILE]",
124
- help="Optional repository root followed by file path. "
125
- "Omit FILE to diff all changed files; omit REPO to use current directory.",
122
+ "_git_pos", nargs="*", action=_GitPositionalsAction, metavar="[[REPO] FILE]",
123
+ help="FILE to review (one positional), or REPO FILE (two). With no positional every "
124
+ "changed file is reviewed; use --repo for a repository other than the current one.",
126
125
  )
127
126
  git_p.add_argument(
128
- "--old", default=None, metavar="REF",
129
- help=(
130
- "Old git ref to compare from. "
131
- "Defaults to HEAD when --new is the working tree (default mode) or a scope flag, "
132
- "and to HEAD~1 when --new is an explicit commit ref."
133
- ),
134
- )
135
- git_p.add_argument("--new", default="", metavar="REF",
136
- help=(
137
- "New git ref (default: working tree; HEAD plus staged). "
138
- "Pass a commit ref to do commit-to-commit diff."
139
- ))
140
- git_p.add_argument(
127
+ "--repo", dest="repo_option", default=None, metavar="REPO",
128
+ help="Repository to review (default: current directory); all changed files without FILE.",
129
+ )
130
+ git_p.add_argument("--old", default=None, metavar="REF", help=(
131
+ "Old git ref to compare from. "
132
+ "Defaults to HEAD when --new is the working tree (default mode) or a scope flag, "
133
+ "and to HEAD~1 when --new is an explicit commit ref."))
134
+ # One new side only: --staged/--unpushed/--new silently overrode each other (#319).
135
+ git_scope = git_p.add_mutually_exclusive_group()
136
+ git_scope.add_argument("--new", default="", metavar="REF", help=(
137
+ "New git ref (default: working tree; HEAD plus staged). "
138
+ "Pass a commit ref to do commit-to-commit diff."))
139
+ git_scope.add_argument(
141
140
  "--staged", action="store_true", default=False,
142
141
  help="Diff HEAD against the git index (staged files only).",
143
142
  )
144
- git_p.add_argument(
143
+ git_scope.add_argument(
145
144
  "--unpushed", action="store_true", default=False,
146
145
  help="Diff the remote tracking branch against HEAD (commits not yet pushed).",
147
146
  )
@@ -222,7 +221,13 @@ def _build_parser() -> argparse.ArgumentParser:
222
221
  assets_git_p.set_defaults(func=_cmd_assets_git)
223
222
 
224
223
  # ── file ─────────────────────────────────────────────────────────────────
225
- file_p = sub.add_parser("file", help="Diff two local files.")
224
+ # `diff` is the first thing anyone types, and it used to fail with
225
+ # "No such command 'diff'. Did you mean 'gist-diff'?" — a suggestion that points away from
226
+ # the two commands that actually diff things. Aliasing it to `file` costs nothing and
227
+ # removes a dead end from the very first interaction with the tool.
228
+ file_p = sub.add_parser(
229
+ "file", aliases=["diff"], help="Diff two local files (alias: diff)."
230
+ )
226
231
  file_p.add_argument("old_file", metavar="OLD", help="Path to the old file.")
227
232
  file_p.add_argument("new_file", metavar="NEW", help="Path to the new file.")
228
233
  _add_output_args(file_p)
@@ -235,7 +240,7 @@ def _build_parser() -> argparse.ArgumentParser:
235
240
  file_p.add_argument(
236
241
  "--stream",
237
242
  action="store_true",
238
- help="Yield changes as they are computed rather than waiting for the full diff.",
243
+ help="Print changes one by one (the full diff is computed first; not incremental).",
239
244
  )
240
245
  file_p.set_defaults(func=_cmd_file)
241
246
 
@@ -316,7 +321,7 @@ def _build_parser() -> argparse.ArgumentParser:
316
321
  "--strict",
317
322
  action="store_true",
318
323
  default=False,
319
- help="Exit 2 when immutable guardrail violations are found.",
324
+ help="Exit 2 when any guardrail violation (important or immutable) is found.",
320
325
  )
321
326
  _add_fuel_arg(check_p)
322
327
  check_p.add_argument(
@@ -389,20 +394,14 @@ def _build_parser() -> argparse.ArgumentParser:
389
394
  "--allow-source-plugin", dest="allow_source_plugin", action="store_true",
390
395
  help="Allow installing from VCS/local/direct-URL sources (disables binary-only check).",
391
396
  )
392
- pl_add.add_argument(
393
- "--strict-registry", dest="strict_registry", action="store_true",
394
- help=(
395
- "Require the official registry ref to be a full 40-character commit SHA. "
396
- "Rejects mutable refs (branch names, tags) for reproducible, tamper-evident installs. "
397
- "Recommended for CI and production environments."
398
- ),
399
- )
397
+ pl_add.add_argument("--yes", action="store_true", help="Confirm --skip-verify (#314).")
398
+ pl_add.add_argument("--strict-registry", dest="strict_registry", action="store_true", help=(
399
+ "Require the official registry ref to be a full 40-character commit SHA. "
400
+ "Rejects mutable refs (branch names, tags) for reproducible, tamper-evident installs. "
401
+ "Recommended for CI and production environments."))
400
402
  pl_add.set_defaults(
401
- save=True,
402
- skip_verify=False,
403
- allow_source_plugin=False,
404
- strict_registry=False,
405
- func=_cmd_plugins_add,
403
+ save=True, skip_verify=False, allow_source_plugin=False, strict_registry=False,
404
+ yes=False, func=_cmd_plugins_add,
406
405
  )
407
406
 
408
407
  # plugins install
@@ -426,19 +425,11 @@ def _build_parser() -> argparse.ArgumentParser:
426
425
  "--allow-source-plugin", dest="allow_source_plugin", action="store_true",
427
426
  help="Allow installing from VCS/local/direct-URL sources (disables binary-only check).",
428
427
  )
429
- pl_install.add_argument(
430
- "--strict-registry", dest="strict_registry", action="store_true",
431
- help=(
432
- "Require the official registry ref to be a full 40-character commit SHA. "
433
- "Rejects mutable refs for reproducible, tamper-evident installs. "
434
- "Recommended for CI and production environments."
435
- ),
436
- )
428
+ # No --strict-registry here: install reads manifest pins and never consults the registry,
429
+ # so the flag had no effect (#314). Pins are checked by `plugins add --strict-registry`.
430
+ pl_install.add_argument("--yes", action="store_true", help="Confirm --skip-verify.")
437
431
  pl_install.set_defaults(
438
- skip_verify=False,
439
- allow_source_plugin=False,
440
- strict_registry=False,
441
- func=_cmd_plugins_install,
432
+ skip_verify=False, allow_source_plugin=False, yes=False, func=_cmd_plugins_install,
442
433
  )
443
434
 
444
435
  # plugins remove
@@ -489,15 +480,15 @@ def _build_parser() -> argparse.ArgumentParser:
489
480
  # ── index ─────────────────────────────────────────────────────────────
490
481
  index_p = sub.add_parser(
491
482
  "index",
492
- help="Pre-index a git repository to warm the parse and symbol-index cache.",
483
+ help="Pre-index a git repository to warm the parse cache.",
493
484
  description=(
494
485
  "Walk every text file in the repository at the given ref, "
495
486
  "parse each one, and store the results in the local cache "
496
487
  "directory. Subsequent diff calls will be faster because the "
497
488
  "Wasm parse step is skipped for already-cached files.\n\n"
498
- "The symbol index is also persisted so that a second call for "
499
- "the same commit returns immediately from cache (use --force to "
500
- "rebuild)."
489
+ "Only the parse cache is reused: the symbol index is rebuilt on every "
490
+ "run (a cached index is never trusted without proof that it is "
491
+ "complete for the commit), so a repeated call re-indexes."
501
492
  ),
502
493
  )
503
494
  index_p.add_argument(
@@ -524,7 +515,7 @@ def _build_parser() -> argparse.ArgumentParser:
524
515
  "--force",
525
516
  action="store_true",
526
517
  default=False,
527
- help="Re-index even if a cached symbol index already exists for this commit.",
518
+ help="Accepted for compatibility; the symbol index is always rebuilt.",
528
519
  )
529
520
  index_p.add_argument(
530
521
  "--fuel",
@@ -703,7 +694,7 @@ def _build_parser() -> argparse.ArgumentParser:
703
694
  description=(
704
695
  "Re-diffs each changed file against its last committed state "
705
696
  "(WorkingTreeSource) whenever the file is modified on disk. "
706
- "Uses OS-native file-system events (watchdog). "
697
+ "Uses watchdog file-system events; a deleted file is reported, not reviewed. "
707
698
  "Press Ctrl+C to stop."
708
699
  ),
709
700
  )
@@ -771,8 +762,8 @@ def _build_parser() -> argparse.ArgumentParser:
771
762
  action="store_true",
772
763
  default=False,
773
764
  help=(
774
- "Send progressive ChangeStreamEvent responses instead of a single "
775
- "SemanticDiff per request."
765
+ "Send ChangeStreamEvent responses instead of a single SemanticDiff "
766
+ "per request (events follow the completed diff; not incremental)."
776
767
  ),
777
768
  )
778
769
  watch_p.set_defaults(func=_cmd_watch)
@@ -825,7 +816,7 @@ def _build_parser() -> argparse.ArgumentParser:
825
816
  "--stream",
826
817
  action="store_true",
827
818
  default=False,
828
- help="Stream progressive semantic events by default for diff requests.",
819
+ help="Send ChangeStreamEvents (after the completed diff) by default for diff requests.",
829
820
  )
830
821
  _add_fuel_arg(live_p)
831
822
  live_p.set_defaults(func=_cmd_live_server)
@@ -995,6 +986,10 @@ if _CLICK_RUNTIME_AVAILABLE:
995
986
  ("git", "Diff files or commits in a git repository."),
996
987
  ("assets", "Perceptual diffs for non-text assets."),
997
988
  ("file", "Diff two local files."),
989
+ # Registered here as well as aliased on the argparse parser: this Click group is what
990
+ # rejects unknown commands, so without an entry here `diff` still fails before argparse
991
+ # is ever consulted — and fails suggesting `gist-diff`.
992
+ ("diff", "Diff two local files (alias for 'file')."),
998
993
  ("patch", "Diff from a unified diff patch."),
999
994
  ("string", "Diff two in-memory strings."),
1000
995
  ("github-pr", "Parse a GitHub pull request URL into a review target."),
@@ -1002,7 +997,7 @@ if _CLICK_RUNTIME_AVAILABLE:
1002
997
  ("guardrails", "Check protected config guardrail policy."),
1003
998
  ("plugins", "Manage parser and renderer plugins."),
1004
999
  ("security-check", "Check installed packages against OSV advisories."),
1005
- ("index", "Pre-index a git repository to warm caches."),
1000
+ ("index", "Pre-index a git repository to warm the parse cache."),
1006
1001
  ("cache", "Inspect or manage the local cache database."),
1007
1002
  ("diagnostics", "Query local DuckDB fuel diagnostics."),
1008
1003
  ("watch", "Watch files/directories and show semantic diffs on save."),
@@ -23,6 +23,8 @@ import os
23
23
  import shlex
24
24
  import sys
25
25
  import time
26
+ import webbrowser
27
+ from collections.abc import Callable
26
28
  from contextlib import suppress
27
29
  from pathlib import Path
28
30
  from typing import Any
@@ -37,7 +39,6 @@ except ModuleNotFoundError: # pragma: no cover - exercised only in minimal dev
37
39
  from rich import box
38
40
  from rich.console import Console
39
41
  from rich.panel import Panel
40
- from rich.table import Table
41
42
  from rich.text import Text
42
43
 
43
44
  from intentumdiff import (
@@ -300,131 +301,52 @@ def _record_diagnostics_db(
300
301
 
301
302
 
302
303
  def _render_terminal(diff: SemanticDiff) -> None:
303
- if diff.guardrail_violations:
304
- guardrail_table = Table(
305
- title="Protected semantic changes",
306
- title_style="bold red",
307
- box=box.SIMPLE_HEAVY,
308
- border_style="red",
309
- )
310
- guardrail_table.add_column("Severity", style="bold", no_wrap=True)
311
- guardrail_table.add_column("Location", style="cyan")
312
- guardrail_table.add_column("Message")
313
- guardrail_table.add_column("Value", style="dim")
314
- for violation in diff.guardrail_violations:
315
- color = "red" if violation.severity == GuardrailSeverity.IMMUTABLE else "yellow"
316
- old_new = ""
317
- if violation.old_value or violation.new_value:
318
- old_new = f"{violation.old_value!r} -> {violation.new_value!r}"
319
- guardrail_table.add_row(
320
- f"[{color}]{violation.severity.value.upper()}[/{color}]",
321
- f"{violation.file}::{violation.semantic_path}",
322
- violation.message,
323
- old_new,
324
- )
325
- _console.print(guardrail_table)
326
- _console.print()
327
-
328
- if not diff.has_semantic_changes:
329
- state_style = "green"
330
- state_title = "No changes detected"
331
- state_message = "IntentumDiff found no semantic differences."
332
- if diff.is_style_only:
333
- state_style = "yellow"
334
- state_title = "Style-only change"
335
- state_message = "Formatting changed, but no semantic differences were found."
336
- elif diff.is_fallback:
337
- state_style = "yellow"
338
- state_title = "Token fallback used"
339
- state_message = "Parse errors were detected, so IntentumDiff used token-level fallback."
340
- _console.print(
341
- Panel(
342
- state_message,
343
- title=f"[bold {state_style}]{state_title}[/bold {state_style}]",
344
- border_style=state_style,
345
- box=box.ROUNDED,
346
- expand=False,
347
- )
348
- )
349
- return
350
- scope_label = (diff.staging_status or "working tree").replace("_", " ")
351
- header = Table.grid(padding=(0, 2))
352
- header.add_column(style="bold")
353
- header.add_column()
354
- header.add_row("Old", diff.old_filename or "<unknown>")
355
- header.add_row("New", diff.new_filename or "<unknown>")
356
- header.add_row("Language", diff.language or "unknown")
357
- header.add_row("Scope", scope_label)
358
- header.add_row("Changes", str(len(diff.changes)))
359
- _console.print(
360
- Panel(
361
- header,
362
- title="[bold cyan]Semantic diff[/bold cyan]",
363
- border_style="cyan",
364
- box=box.ROUNDED,
365
- expand=False,
366
- )
304
+ from intentumdiff.rust_core import render_cli_review
305
+
306
+ # Python owns host I/O and terminal settings; Rust owns all presentation layout.
307
+ rendered = render_cli_review(
308
+ diff,
309
+ width=max(16, min(300, _console.width)),
310
+ # Direct writes bypass Rich's Win32 renderer on legacy consoles.
311
+ color=bool(
312
+ _console.is_terminal
313
+ and _console.color_system
314
+ and not _console.legacy_windows
315
+ and "NO_COLOR" not in os.environ
316
+ ),
367
317
  )
368
- _console.print()
318
+ _console.file.write(rendered)
319
+ _console.file.flush()
369
320
 
370
- changes_table = Table(
371
- box=box.SIMPLE,
372
- border_style="dim",
373
- header_style="bold",
374
- show_header=True,
375
- )
376
- changes_table.add_column("Type", no_wrap=True)
377
- changes_table.add_column("Description", overflow="fold")
378
- for change in diff.changes:
379
- from intentumdiff.core.models import ChangeType
380
- ct = (
381
- change.change_type.value
382
- if isinstance(change.change_type, ChangeType)
383
- else str(change.change_type)
384
- )
385
- color_map = {
386
- "ADDITION": "green",
387
- "DELETION": "red",
388
- "MODIFICATION": "yellow",
389
- "MOVE": "cyan",
390
- "REFACTORING": "magenta",
391
- "STYLE_ONLY": "dim",
392
- }
393
- color = color_map.get(ct, "white")
394
- changes_table.add_row(f"[{color}]{ct}[/{color}]", change.description)
395
- _console.print(changes_table)
396
- return
397
321
 
398
322
  def _render(diff: SemanticDiff, fmt: str, output: str | None, fuel: int | None = None) -> None:
399
323
  if fmt == "terminal" and not output:
400
324
  _render_terminal(diff)
401
325
  return
326
+ _write_output(_render_text(diff, fmt, fuel=fuel), output)
327
+
402
328
 
329
+ def _render_text(diff: SemanticDiff, fmt: str, fuel: int | None = None) -> str:
330
+ """Render one diff to text for a file or a machine-readable stream (every format except
331
+ interactive terminal output). Multi-file callers combine these and write once (#280)."""
403
332
  if fmt == "terminal":
404
- # Render to plain text file (no ANSI)
405
- with open(output, "w", encoding="utf-8") as fh:
406
- plain = Console(file=fh, highlight=False)
407
- plain.print(
408
- f"Semantic diff: {diff.old_filename} -> "
409
- f"{diff.new_filename} ({diff.language})"
410
- )
411
- for violation in diff.guardrail_violations:
412
- plain.print(
413
- f" GUARDRAIL {violation.severity.value.upper()} "
414
- f"{violation.file}::{violation.semantic_path} {violation.message}"
415
- )
416
- for change in diff.changes:
417
- plain.print(f" {change.change_type.value:14} {change.description}")
418
- return
333
+ from intentumdiff.rust_core import render_cli_review
334
+
335
+ return render_cli_review(diff, width=80, color=False)
419
336
 
420
337
  if fmt == "json":
421
- _write_output(diff.model_dump_json(indent=2), output)
422
- return
338
+ return diff.model_dump_json(indent=2)
423
339
 
424
340
  # For patch / html / llm — delegate to the matching Wasm renderer plugin
425
341
  from intentumdiff.plugins.loader import load_plugin
426
342
 
427
- wasm_dir = Path(__file__).parent / "wasm"
343
+ # Was `Path(__file__).parent / "wasm"`, which from inside `cli/` resolves to
344
+ # intentumdiff/cli/wasm/ — a directory that has never existed. The glob below found
345
+ # nothing, the fallback scan iterated the same empty path, and --format patch/html/llm
346
+ # reported "No renderer plugin found" for components that ship and load fine.
347
+ from intentumdiff.plugins.registry import builtin_wasm_dir
348
+
349
+ wasm_dir = builtin_wasm_dir()
428
350
  candidates = list(wasm_dir.glob(f"{fmt.replace('-', '_')}_renderer.wasm"))
429
351
  if not candidates:
430
352
  # Fallback: scan for any renderer plugin that reports this format name
@@ -441,11 +363,10 @@ def _render(diff: SemanticDiff, fmt: str, output: str | None, fuel: int | None =
441
363
 
442
364
  try:
443
365
  diff_json = diff.model_dump_json()
366
+ from intentumdiff.rust_core import fuel_budget # core's policy: -1 stays -1 (#308)
444
367
  plugin_fuel = fuel if fuel is not None else 100_000_000
445
- adaptive_fuel = max(plugin_fuel, 20_000_000 + len(diff_json) * 100)
446
- pl = load_plugin(candidates[0], adaptive_fuel)
447
- result = pl.call_render(diff_json)
448
- _write_output(result, output)
368
+ pl = load_plugin(candidates[0], fuel_budget(plugin_fuel, len(diff_json.encode("utf-8"))))
369
+ return pl.call_render(diff_json)
449
370
  except Exception as exc:
450
371
  _err.print(f"[red]Renderer error: {exc}[/red]")
451
372
  sys.exit(1)
@@ -486,6 +407,120 @@ def _render_with_profile(
486
407
  started = time.perf_counter()
487
408
  _render(diff, args.format, args.output, fuel=fuel)
488
409
  _emit_phase_profiles(diff, render_ms=(time.perf_counter() - started) * 1000)
410
+ _offer_incomplete_reports([diff], args)
411
+
412
+
413
+ # Fixed CLI wording around core's report (core #252). Everything else the report flow
414
+ # prints is core-authored text (message, title, body_markdown); nothing local is added.
415
+ _REPORT_PREVIEW_HEADER = "Bug report preview (nothing has been sent):"
416
+ _REPORT_TRUNCATED_NOTE = ("The pre-filled issue URL was shortened to fit. The full report body "
417
+ "is printed above: paste it into the issue.")
418
+ _REPORT_PROMPT = "Open this pre-filled GitHub issue in your browser? [y/N] "
419
+ _REPORT_NOT_OPENED = "Nothing was opened."
420
+ _REPORT_HOW_TO = ("No terminal is attached, so nothing was opened. To preview and report this "
421
+ "bug, rerun the command in a terminal with --report-bug.")
422
+ _REPORT_HINT = "To preview a pre-filled bug report, rerun the command with --report-bug."
423
+
424
+
425
+ def _offer_incomplete_reports(diffs: list[SemanticDiff], args: argparse.Namespace) -> None:
426
+ """Offer core's bug report for incomplete reviews; open the URL only on an explicit yes.
427
+
428
+ Writes to stderr only, so stdout (and JSON, which carries ``completeness`` and
429
+ ``incomplete`` as core sent them) is untouched. Without a TTY nothing is opened.
430
+ """
431
+ interactive = sys.stdin.isatty() and sys.stdout.isatty()
432
+ opted_in = bool(getattr(args, "report_bug", False))
433
+ offer = opted_in or (interactive and args.format == "terminal")
434
+ for diff in diffs:
435
+ if diff.completeness != "incomplete" or diff.incomplete is None:
436
+ continue
437
+ report = diff.incomplete.report
438
+ _write_stderr(diff.incomplete.message)
439
+ if not offer:
440
+ _write_stderr(_REPORT_HOW_TO if not interactive else _REPORT_HINT)
441
+ continue
442
+ _write_stderr(_REPORT_PREVIEW_HEADER, report.title, report.body_markdown)
443
+ if report.truncated:
444
+ _write_stderr(_REPORT_TRUNCATED_NOTE)
445
+ if not interactive:
446
+ _write_stderr(_REPORT_HOW_TO)
447
+ continue
448
+ sys.stderr.write(_REPORT_PROMPT)
449
+ sys.stderr.flush()
450
+ if sys.stdin.readline().strip().lower() in ("y", "yes"):
451
+ webbrowser.open(report.issue_url)
452
+ else:
453
+ _write_stderr(_REPORT_NOT_OPENED)
454
+
455
+
456
+ def _write_stderr(*blocks: str) -> None:
457
+ """Write text literally (no Rich markup: core's Markdown may contain brackets)."""
458
+ sys.stderr.write("".join(f"{block}\n" for block in blocks if block))
459
+ sys.stderr.flush()
460
+
461
+
462
+ def _combine_html_reviews(pages: list[tuple[str, str]]) -> str:
463
+ """One valid HTML document with independent, sandboxed renderer pages.
464
+
465
+ The Wasm HTML renderer emits a complete HTML document per diff. Joining
466
+ those documents produces malformed HTML; using sandboxed srcdoc frames
467
+ retains each renderer's own CSS without reinterpreting any diff semantics.
468
+ """
469
+ from html import escape
470
+
471
+ if len(pages) <= 1:
472
+ return pages[0][1] if pages else ""
473
+ frames = []
474
+ for filename, document in pages:
475
+ name = escape(filename)
476
+ attribute = escape(filename, quote=True)
477
+ content = escape(document, quote=True)
478
+ frames.append(
479
+ '<section class="review"><h2>' + name + '</h2>'
480
+ '<iframe title="' + attribute + '" sandbox="allow-scripts" '
481
+ 'loading="lazy" srcdoc="' + content + '"></iframe></section>'
482
+ )
483
+ return (
484
+ '<!doctype html>\n<html lang="en"><head><meta charset="utf-8">'
485
+ '<title>IntentumDiff Git review</title>'
486
+ '<style>body{font:16px system-ui,sans-serif;margin:1.5rem}'
487
+ 'section.review{margin:1.5rem 0;border:1px solid #888;border-radius:6px;'
488
+ 'padding:1rem}iframe{display:block;width:100%;height:70vh;border:0}'
489
+ 'h2{font-size:1.1rem}</style></head><body>\n'
490
+ + '\n'.join(frames) + '\n</body></html>\n'
491
+ )
492
+
493
+
494
+ def _render_many_with_profile(
495
+ diffs: list[SemanticDiff],
496
+ args: argparse.Namespace,
497
+ *,
498
+ fuel: int | None = None,
499
+ title: Callable[[SemanticDiff], str] | None = None,
500
+ ) -> None:
501
+ """Render several diffs as one document without dropping any file (#280).
502
+
503
+ JSON is always an array. HTML embeds each original Wasm-rendered page in a
504
+ sandboxed frame. Other formats join renders, with per-file titles for
505
+ terminal output to a file.
506
+ """
507
+ parts: list[str] = []
508
+ for diff in diffs:
509
+ started = time.perf_counter()
510
+ text = _render_text(diff, args.format, fuel=fuel)
511
+ if args.format == "terminal" and title is not None:
512
+ text = f"== {title(diff)} ==\n{text}"
513
+ parts.append(text)
514
+ _emit_phase_profiles(diff, render_ms=(time.perf_counter() - started) * 1000)
515
+ if args.format == "json":
516
+ _write_output("[\n" + ",\n".join(parts) + "\n]", args.output)
517
+ elif args.format == "html":
518
+ labels = [title(diff) if title is not None else f"Diff {i + 1}"
519
+ for i, diff in enumerate(diffs)]
520
+ _write_output(_combine_html_reviews(list(zip(labels, parts, strict=True))), args.output)
521
+ else:
522
+ _write_output("\n".join(parts), args.output)
523
+ _offer_incomplete_reports(diffs, args)
489
524
 
490
525
 
491
526
  def _has_immutable_guardrail(diff: SemanticDiff) -> bool:
@@ -543,7 +578,7 @@ def _emit_guardrail_reports(
543
578
  def _exit_if_guardrail_result_fails(result: GuardrailCheckResult) -> None:
544
579
  if result.passed:
545
580
  return
546
- _err.print("[bold red]Immutable semantic guardrail violation detected.[/bold red]")
581
+ _err.print("[bold red]Guardrail check failed: protected semantic change detected.[/bold red]")
547
582
  sys.exit(2)
548
583
 
549
584
 
@@ -5,14 +5,12 @@ to route changed files — text goes to the semantic parser, binary/image assets
5
5
  go to the perceptual asset diff — and to enrich diff metadata with the detected
6
6
  MIME type. Detection inspects the leading bytes of a file, not its extension.
7
7
 
8
- Falls back to a NUL-byte heuristic if the Rust core is unavailable, so callers
9
- never crash when the native extension is missing.
8
+ A missing or failing Rust engine raises; routing never uses a Python fallback.
10
9
  """
11
10
 
12
11
  from __future__ import annotations
13
12
 
14
- import json
15
- from typing import Any, TypedDict
13
+ from typing import TypedDict
16
14
 
17
15
  #: How many leading bytes to sniff. A few KB is plenty for magic-byte detection.
18
16
  HEAD_BYTES = 8192
@@ -25,33 +23,18 @@ class ContentType(TypedDict):
25
23
  is_text: bool
26
24
 
27
25
 
28
- def _fallback(head: bytes) -> ContentType:
29
- is_text = b"\x00" not in head[:HEAD_BYTES]
30
- return {
31
- "mime": "text/plain" if is_text else "application/octet-stream",
32
- "extension": "",
33
- "category": "text" if is_text else "binary",
34
- "is_text": is_text,
35
- }
36
-
37
-
38
26
  def detect_content_type(head: bytes) -> ContentType:
39
- """Return the detected content type for a file's leading bytes."""
40
- sample = bytes(head[:HEAD_BYTES])
41
- try:
42
- from intentumdiff.rust_core import _load_backend
43
-
44
- backend = _load_backend()
45
- raw = backend.detect_content_type_json(sample)
46
- parsed: dict[str, Any] = json.loads(raw)
47
- return {
48
- "mime": str(parsed.get("mime", "application/octet-stream")),
49
- "extension": str(parsed.get("extension", "")),
50
- "category": str(parsed.get("category", "binary")),
51
- "is_text": bool(parsed.get("is_text", False)),
52
- }
53
- except Exception: # noqa: BLE001 — detection must never break the diff pipeline.
54
- return _fallback(sample)
27
+ """Return Rust's detected content type; propagate required engine failures."""
28
+ from intentumdiff.rust_core import _required_engine_json
29
+
30
+ result = _required_engine_json(
31
+ "detect_content_type_json",
32
+ bytes(head[:HEAD_BYTES]),
33
+ result_type=dict,
34
+ )
35
+ if any(not isinstance(result.get(key), str) for key in ("mime", "extension", "category")) or type(result.get("is_text")) is not bool:
36
+ raise RuntimeError("Rust content-type result has invalid fields")
37
+ return ContentType(**{key: result[key] for key in ContentType.__annotations__})
55
38
 
56
39
 
57
40
  def is_text_bytes(head: bytes) -> bool: