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.
Files changed (139) hide show
  1. intentumdiff/__init__.py +2 -0
  2. intentumdiff/__main__.py +12 -0
  3. intentumdiff/_differ_presentation.py +35 -682
  4. intentumdiff/_differ_runtime.py +13 -47
  5. intentumdiff/analysis/compile_commands.py +26 -141
  6. intentumdiff/analysis/cross_file.py +2 -4
  7. intentumdiff/analysis/guardrail_reports.py +7 -5
  8. intentumdiff/analysis/guardrails.py +110 -122
  9. intentumdiff/analysis/invariances.py +4 -1003
  10. intentumdiff/analysis/schema_resolver.py +49 -273
  11. intentumdiff/analysis/text_review.py +4 -3
  12. intentumdiff/analysis/user_schemas.py +55 -237
  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 +174 -67
  17. intentumdiff/cli/_parser.py +11 -1
  18. intentumdiff/cli/_shared.py +96 -112
  19. intentumdiff/content_type.py +13 -30
  20. intentumdiff/core/commit_differ.py +105 -220
  21. intentumdiff/core/diffignore.py +28 -34
  22. intentumdiff/core/index.py +16 -18
  23. intentumdiff/core/indexer.py +148 -168
  24. intentumdiff/core/models.py +53 -14
  25. intentumdiff/differ.py +278 -605
  26. intentumdiff/github_app.py +35 -19
  27. intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
  28. intentumdiff/live_server.py +180 -17
  29. intentumdiff/lsp/client.py +7 -1
  30. intentumdiff/lsp/enricher.py +19 -119
  31. intentumdiff/lsp/exceptions.py +6 -7
  32. intentumdiff/lsp_server/_codelens.py +24 -57
  33. intentumdiff/lsp_server/_diagnostics.py +23 -51
  34. intentumdiff/lsp_server/_handlers.py +66 -8
  35. intentumdiff/lsp_server/server.py +28 -7
  36. intentumdiff/plugins/adapter.py +5 -0
  37. intentumdiff/plugins/builtins.py +7 -14
  38. intentumdiff/plugins/exceptions.py +4 -0
  39. intentumdiff/plugins/hub.py +1 -2
  40. intentumdiff/plugins/loader.py +229 -215
  41. intentumdiff/plugins/registry.py +249 -197
  42. intentumdiff/rust_core.py +744 -784
  43. intentumdiff/serve/_app.py +3 -10
  44. intentumdiff/sources/base.py +24 -0
  45. intentumdiff/sources/file_source.py +15 -2
  46. intentumdiff/sources/git_source.py +120 -58
  47. intentumdiff/sources/live_buffer_source.py +45 -5
  48. intentumdiff/sources/patch_source.py +36 -109
  49. intentumdiff/vcs/_safe_path.py +7 -0
  50. intentumdiff/vcs/base.py +6 -0
  51. intentumdiff/vcs/git_backend.py +1 -1
  52. intentumdiff/vcs/git_cli.py +38 -18
  53. intentumdiff/vcs/hg_backend.py +1 -1
  54. intentumdiff/vcs/perforce_backend.py +7 -1
  55. intentumdiff/vcs/svn_backend.py +1 -1
  56. intentumdiff/wasm/abap_parser.wasm +0 -0
  57. intentumdiff/wasm/adf_parser.wasm +0 -0
  58. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  59. intentumdiff/wasm/asm_parser.wasm +0 -0
  60. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  61. intentumdiff/wasm/astro_parser.wasm +0 -0
  62. intentumdiff/wasm/bash_parser.wasm +0 -0
  63. intentumdiff/wasm/clojure_parser.wasm +0 -0
  64. intentumdiff/wasm/cmake_parser.wasm +0 -0
  65. intentumdiff/wasm/cpp_parser.wasm +0 -0
  66. intentumdiff/wasm/csharp_parser.wasm +0 -0
  67. intentumdiff/wasm/css_parser.wasm +0 -0
  68. intentumdiff/wasm/dart_parser.wasm +0 -0
  69. intentumdiff/wasm/databricks_parser.wasm +0 -0
  70. intentumdiff/wasm/dax_parser.wasm +0 -0
  71. intentumdiff/wasm/delphi_parser.wasm +0 -0
  72. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  73. intentumdiff/wasm/elixir_parser.wasm +0 -0
  74. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  75. intentumdiff/wasm/generic_parser.wasm +0 -0
  76. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  77. intentumdiff/wasm/go_parser.wasm +0 -0
  78. intentumdiff/wasm/gomod_parser.wasm +0 -0
  79. intentumdiff/wasm/graphql_parser.wasm +0 -0
  80. intentumdiff/wasm/groovy_parser.wasm +0 -0
  81. intentumdiff/wasm/haskell_parser.wasm +0 -0
  82. intentumdiff/wasm/html_parser.wasm +0 -0
  83. intentumdiff/wasm/html_renderer.wasm +0 -0
  84. intentumdiff/wasm/ini_parser.wasm +0 -0
  85. intentumdiff/wasm/java_parser.wasm +0 -0
  86. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  87. intentumdiff/wasm/json_parser.wasm +0 -0
  88. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  89. intentumdiff/wasm/latex_parser.wasm +0 -0
  90. intentumdiff/wasm/llm_renderer.wasm +0 -0
  91. intentumdiff/wasm/lua_parser.wasm +0 -0
  92. intentumdiff/wasm/make_parser.wasm +0 -0
  93. intentumdiff/wasm/markdown_parser.wasm +0 -0
  94. intentumdiff/wasm/mdx_parser.wasm +0 -0
  95. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  96. intentumdiff/wasm/odin_parser.wasm +0 -0
  97. intentumdiff/wasm/parser_manifest.json +81 -2
  98. intentumdiff/wasm/patch_renderer.wasm +0 -0
  99. intentumdiff/wasm/perl_parser.wasm +0 -0
  100. intentumdiff/wasm/php_parser.wasm +0 -0
  101. intentumdiff/wasm/plsql_parser.wasm +0 -0
  102. intentumdiff/wasm/po_parser.wasm +0 -0
  103. intentumdiff/wasm/postscript_parser.wasm +0 -0
  104. intentumdiff/wasm/powershell_parser.wasm +0 -0
  105. intentumdiff/wasm/proto_parser.wasm +0 -0
  106. intentumdiff/wasm/puppet_parser.wasm +0 -0
  107. intentumdiff/wasm/python_parser.wasm +0 -0
  108. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  109. intentumdiff/wasm/r_parser.wasm +0 -0
  110. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  111. intentumdiff/wasm/ruby_parser.wasm +0 -0
  112. intentumdiff/wasm/rust_parser.wasm +0 -0
  113. intentumdiff/wasm/sas_parser.wasm +0 -0
  114. intentumdiff/wasm/scala_parser.wasm +0 -0
  115. intentumdiff/wasm/scss_parser.wasm +0 -0
  116. intentumdiff/wasm/sql_parser.wasm +0 -0
  117. intentumdiff/wasm/squirrel_parser.wasm +0 -0
  118. intentumdiff/wasm/svelte_parser.wasm +0 -0
  119. intentumdiff/wasm/swift_parser.wasm +0 -0
  120. intentumdiff/wasm/terminal_renderer.wasm +0 -0
  121. intentumdiff/wasm/terraform_parser.wasm +0 -0
  122. intentumdiff/wasm/toml_parser.wasm +0 -0
  123. intentumdiff/wasm/tsql_parser.wasm +0 -0
  124. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  125. intentumdiff/wasm/vue_parser.wasm +0 -0
  126. intentumdiff/wasm/wasm_provenance.json +884 -0
  127. intentumdiff/wasm/wat_parser.wasm +0 -0
  128. intentumdiff/wasm/xml_parser.wasm +0 -0
  129. intentumdiff/wasm/yaml_parser.wasm +0 -0
  130. intentumdiff/wasm/zig_parser.wasm +0 -0
  131. intentumdiff_python-0.0.2b2.dist-info/METADATA +156 -0
  132. intentumdiff_python-0.0.2b2.dist-info/RECORD +171 -0
  133. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/WHEEL +1 -1
  134. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
  135. intentumdiff/core/cst_serializer.py +0 -101
  136. intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
  137. intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
  138. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/entry_points.txt +0 -0
  139. {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/licenses/LICENSE +0 -0
@@ -35,6 +35,7 @@ except ModuleNotFoundError: # pragma: no cover - exercised only in minimal dev
35
35
 
36
36
  from rich.panel import Panel
37
37
  from rich.table import Table
38
+ from rich.text import Text
38
39
 
39
40
  from intentumdiff import (
40
41
  FileSource,
@@ -64,6 +65,7 @@ from intentumdiff.cli._shared import ( # noqa: F401
64
65
  _parse_fuel,
65
66
  _record_diagnostics_db,
66
67
  _render,
68
+ _render_many_with_profile,
67
69
  _render_with_profile,
68
70
  _resolve_repo_root,
69
71
  _warn_if_unlimited_fuel,
@@ -106,8 +108,15 @@ def _cmd_assets_git(args: argparse.Namespace) -> None:
106
108
  _emit_asset_payload(payload, json_output=args.json)
107
109
 
108
110
 
111
+ def _git_file_rule_title(diff: SemanticDiff) -> Text:
112
+ """Build a literal Rich rule title; filenames and Git statuses are data, not markup."""
113
+ label = diff.staging_status or ""
114
+ name = diff.new_filename or diff.old_filename or "(unknown file)"
115
+ return Text(f"{name} [{label}]" if label else name)
116
+
117
+
109
118
  def _cmd_git(args: argparse.Namespace) -> None:
110
- from intentumdiff.sources.git_source import _REF_STAGED, _REF_UNPUSHED
119
+ from intentumdiff.sources.git_source import StagedSource, _REF_STAGED, _REF_UNPUSHED
111
120
  from intentumdiff.vcs.git_cli import NotAGitRepositoryError
112
121
 
113
122
  repo_path = args.repo # '.' when not supplied
@@ -144,11 +153,7 @@ def _cmd_git(args: argparse.Namespace) -> None:
144
153
  ref=old_ref,
145
154
  )
146
155
  elif new_ref == _REF_STAGED:
147
- # Staged single-file: use WorkingTreeSource pointing at the index.
148
- # WorkingTreeSource reads the committed version for old_content and
149
- # the on-disk file for new_content — for staged-only accuracy the
150
- # user should rely on commit-wide mode or pass an explicit --new ref.
151
- source = WorkingTreeSource(
156
+ source = StagedSource(
152
157
  repo_path=repo_path,
153
158
  file_path=args.file,
154
159
  ref=old_ref,
@@ -192,16 +197,37 @@ def _cmd_git(args: argparse.Namespace) -> None:
192
197
  new_ref=new_ref,
193
198
  )
194
199
  if not diffs:
195
- _console.print("[green]No parseable changes found.[/green]")
200
+ # No semantic result exists to render, but machine consumers must
201
+ # still receive a valid empty result and requested report files.
202
+ # Keep the human status on stderr so stdout stays machine-readable.
203
+ if args.format == "terminal":
204
+ if args.output:
205
+ _write_output("No parseable changes found.\n", args.output)
206
+ else:
207
+ _err.print("[green]No parseable changes found.[/green]")
208
+ elif args.format == "json":
209
+ _write_output("[]", args.output)
210
+ elif args.output:
211
+ # Empty patch/HTML/LLM output is an empty document, not a
212
+ # fabricated per-file semantic diff.
213
+ _write_output("", args.output)
214
+ result = _emit_guardrail_reports([], args)
215
+ _record_diagnostics_db([], args)
216
+ _exit_if_guardrail_result_fails(result)
196
217
  return
197
- for diff in diffs:
198
- if args.format == "terminal" and not args.output:
199
- label = diff.staging_status or ""
200
- rule_title = diff.new_filename or diff.old_filename
201
- if label:
202
- rule_title = f"{rule_title} [{label}]"
203
- _console.rule(rule_title)
204
- _render_with_profile(diff, args, fuel=differ._config.plugin_fuel)
218
+ if args.format == "terminal" and not args.output:
219
+ for diff in diffs:
220
+ _console.rule(_git_file_rule_title(diff))
221
+ _render_with_profile(diff, args, fuel=differ._config.plugin_fuel)
222
+ else:
223
+ # One document for machine formats and files (#280): a JSON array, or the
224
+ # joined per-file renders, so no diff overwrites another in --output.
225
+ _render_many_with_profile(
226
+ diffs,
227
+ args,
228
+ fuel=differ._config.plugin_fuel,
229
+ title=lambda diff: _git_file_rule_title(diff).plain,
230
+ )
205
231
  result = _emit_guardrail_reports(diffs, args)
206
232
  _record_diagnostics_db(diffs, args)
207
233
  _exit_if_guardrail_result_fails(result)
@@ -242,8 +268,9 @@ def _cmd_file(args: argparse.Namespace) -> None:
242
268
  config_start_path=args.new_file,
243
269
  guardrails_policy=getattr(args, "guardrails_policy", None),
244
270
  )
271
+ diff = differ.diff(source)
245
272
  if args.stream:
246
- for change in differ.diff_stream(source):
273
+ for change in diff.changes:
247
274
  ct_str = (
248
275
  change.change_type.value
249
276
  if hasattr(change.change_type, "value")
@@ -254,11 +281,10 @@ def _cmd_file(args: argparse.Namespace) -> None:
254
281
  line += f" [{change.text_diff}]"
255
282
  _console.print(line)
256
283
  else:
257
- diff = differ.diff(source)
258
284
  _render_with_profile(diff, args, fuel=differ._config.plugin_fuel)
259
- result = _emit_guardrail_reports(diff, args)
260
- _record_diagnostics_db(diff, args)
261
- _exit_if_guardrail_result_fails(result)
285
+ result = _emit_guardrail_reports(diff, args)
286
+ _record_diagnostics_db(diff, args)
287
+ _exit_if_guardrail_result_fails(result)
262
288
 
263
289
 
264
290
  def _cmd_patch(args: argparse.Namespace) -> None:
@@ -411,6 +437,34 @@ def _cmd_diagnostics_query(args: argparse.Namespace) -> None:
411
437
  def _cmd_guardrails_check(args: argparse.Namespace) -> None:
412
438
  from intentumdiff.vcs.git_cli import NotAGitRepositoryError
413
439
 
440
+ # Validate the policy BEFORE diffing anything.
441
+ #
442
+ # The policy used to be loaded lazily, per changed file. With no changed files it was
443
+ # never loaded at all, so `guardrails check --policy typo.yaml` printed
444
+ # "Guardrail check passed: 0 file(s) checked" and exited 0 - with nothing on stderr.
445
+ # A typo in the path was indistinguishable from a clean run, on a gate whose documented
446
+ # purpose is stopping API keys changing unreviewed. It failed OPEN.
447
+ #
448
+ # A gate must verify it can do its job before reporting that it did.
449
+ if args.guardrails_policy is not None:
450
+ from pathlib import Path as _Path
451
+
452
+ from intentumdiff.analysis.guardrails import load_guardrail_policy
453
+
454
+ try:
455
+ policy = load_guardrail_policy("", explicit_path=_Path(args.guardrails_policy))
456
+ except (OSError, ValueError) as exc:
457
+ _err.print(f"[red]Guardrail policy could not be loaded: {exc}[/red]")
458
+ sys.exit(2)
459
+ if not policy.rules:
460
+ # Loaded, parsed, and protects nothing. Reporting "passed" for that is the same
461
+ # false assurance as failing to load it.
462
+ _err.print(
463
+ f"[red]Guardrail policy {args.guardrails_policy} defines no protected "
464
+ f"entries, so this check cannot fail. Add rules, or drop --policy.[/red]"
465
+ )
466
+ sys.exit(2)
467
+
414
468
  try:
415
469
  differ = _differ(
416
470
  args.fuel,
@@ -454,7 +508,11 @@ def _cmd_plugins_list(_args: argparse.Namespace) -> None:
454
508
 
455
509
  # Resolve the core package provenance string once for built-in rows
456
510
  import importlib.metadata as _meta
457
- for _dist_name in ("intentumdiff",):
511
+ # The DISTRIBUTION name, which is not the import name: this package publishes as
512
+ # `intentumdiff-python` while `import intentumdiff` is the package. Looking up only the
513
+ # import name silently fell through to the bare "IntentumDiff" fallback, so every
514
+ # built-in plugin row lost its version.
515
+ for _dist_name in ("intentumdiff-python", "intentumdiff_python", "intentumdiff"):
458
516
  try:
459
517
  _core_dist = _meta.distribution(_dist_name)
460
518
  _core_prov = (
@@ -544,6 +602,20 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
544
602
  "[yellow]Warning: security verification skipped (--skip-verify).[/yellow]"
545
603
  )
546
604
 
605
+ # Preserve existing pinned Wasm/dependency provenance before pip has any
606
+ # side effects. A malformed manifest or dangling symlink is not an empty
607
+ # plugin inventory: refusing the update avoids deleting existing pins (#252).
608
+ existing_manifest: list[PluginSpec] = []
609
+ if args.save:
610
+ manifest_path = Path(args.file)
611
+ if manifest_path.exists() or manifest_path.is_symlink():
612
+ try:
613
+ existing_manifest = load_plugins_file(manifest_path)
614
+ except Exception as exc:
615
+ raise RuntimeError(
616
+ f"Refusing to overwrite invalid plugins manifest {manifest_path}: {exc}"
617
+ ) from exc
618
+
547
619
  # ── 1. Consult the official registry for official plugins ─────────────────
548
620
  registry_entry: RegistryEntry | None = None
549
621
  if not args.repo and not skip_verify:
@@ -650,13 +722,9 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
650
722
  # ── 6. Save to manifest ───────────────────────────────────────────────────
651
723
  if args.save:
652
724
  yaml_path = Path(args.file)
653
- existing: list = []
654
- if yaml_path.exists():
655
- with suppress(Exception):
656
- existing = load_plugins_file(yaml_path)
657
- # Replace if already present, otherwise append
725
+ # Replace only the matching entry; retain all other pinned provenance.
658
726
  existing = [
659
- s for s in existing
727
+ s for s in existing_manifest
660
728
  if s.name != spec.name and s.name != spec.package_name
661
729
  ]
662
730
  existing.append(spec)
@@ -868,25 +936,40 @@ def _cmd_plugins_remove(args: argparse.Namespace) -> None:
868
936
 
869
937
  name = args.plugin_name
870
938
  spec = PluginSpec(name=name)
939
+ manifest_path = Path(args.file) if args.save else None
940
+ existing_manifest: list[PluginSpec] | None = None
941
+ # --save is a pinned provenance change, not best-effort decoration. Check
942
+ # the existing manifest before any irreversible pip side effects (#257).
943
+ if manifest_path is not None and (
944
+ manifest_path.exists() or manifest_path.is_symlink()
945
+ ):
946
+ try:
947
+ existing_manifest = load_plugins_file(manifest_path)
948
+ except Exception as exc:
949
+ raise RuntimeError(
950
+ f"Refusing to uninstall with invalid plugins manifest {manifest_path}: {exc}"
951
+ ) from exc
952
+
871
953
  _console.print(f"Uninstalling [cyan]{spec.package_name}[/cyan] ...")
872
954
  rc = pip_uninstall(spec.package_name)
873
955
  if rc != 0:
874
956
  _err.print(f"[red]pip uninstall failed (exit code {rc})[/red]")
875
957
  sys.exit(rc)
876
958
 
877
- if args.save:
878
- yaml_path = Path(args.file)
879
- if yaml_path.exists():
880
- try:
881
- specs = load_plugins_file(yaml_path)
882
- specs = [
883
- s for s in specs
884
- if s.name != name and s.name != spec.package_name
885
- ]
886
- save_plugins_file(yaml_path, specs)
887
- _console.print(f"[green]Removed from {yaml_path}[/green]")
888
- except Exception as exc:
889
- _err.print(f"[yellow]Warning: could not update {yaml_path}: {exc}[/yellow]")
959
+ if manifest_path is not None and existing_manifest is not None:
960
+ specs = [
961
+ s for s in existing_manifest
962
+ if s.name != name and s.name != spec.package_name
963
+ ]
964
+ try:
965
+ save_plugins_file(manifest_path, specs)
966
+ except Exception as exc:
967
+ # pip has already succeeded, but the manifest is not reconciled.
968
+ # Propagate a partial failure rather than print a false success.
969
+ raise RuntimeError(
970
+ f"Plugin uninstalled but could not update {manifest_path}: {exc}"
971
+ ) from exc
972
+ _console.print(f"[green]Removed from {manifest_path}[/green]")
890
973
 
891
974
  _console.print(f"[green]Plugin '{spec.package_name}' uninstalled.[/green]")
892
975
 
@@ -1030,20 +1113,10 @@ async def _two_pass_index(
1030
1113
 
1031
1114
  if not launchable:
1032
1115
  langs_str = ", ".join(sorted(detected)) or "none"
1033
- _console.print(
1034
- f"[dim]No LSP servers configured for detected languages "
1035
- f"({langs_str}). Running plain index.[/dim]"
1036
- )
1037
- result = await _index_with_progress(
1038
- indexer,
1039
- repo_path=repo_path,
1040
- ref=ref,
1041
- force=args.force,
1042
- lsp_clients={},
1043
- initial_total=_file_count,
1116
+ raise RuntimeError(
1117
+ "--lsp was requested, but no LSP servers are configured for "
1118
+ f"detected languages ({langs_str}); cannot certify type enrichment"
1044
1119
  )
1045
- _print_index_result(result)
1046
- return
1047
1120
 
1048
1121
  _console.print(
1049
1122
  f"[bold]Pass 1 complete[/bold] — "
@@ -1057,6 +1130,7 @@ async def _two_pass_index(
1057
1130
 
1058
1131
  launchers: dict[str, LspServerProcess] = {}
1059
1132
  clients: dict[str, AsyncLspClient] = {}
1133
+ connection_failures: dict[str, str] = {}
1060
1134
 
1061
1135
  # Separate languages into "already running" vs "needs auto-start".
1062
1136
  manual: list[str] = []
@@ -1112,6 +1186,7 @@ async def _two_pass_index(
1112
1186
  f" [green]✓[/green] {lang} (tcp, already running @ {cfg_lsp})"
1113
1187
  )
1114
1188
  except (Exception, asyncio.CancelledError) as exc:
1189
+ connection_failures[lang] = str(exc)
1115
1190
  _err.print(f" [yellow]⚠[/yellow] {lang}: {exc} — skipped")
1116
1191
  _hint = entry.install_hint
1117
1192
  if _hint:
@@ -1120,6 +1195,8 @@ async def _two_pass_index(
1120
1195
  # Spawn approved auto-start servers.
1121
1196
  for lang in to_start:
1122
1197
  entry = user_entries.get(lang)
1198
+ launcher: LspServerProcess | None = None
1199
+ client: AsyncLspClient | None = None
1123
1200
  try:
1124
1201
  spec = entry.to_spec() if entry is not None else None
1125
1202
  launcher = LspServerProcess(lang, spec=spec)
@@ -1132,6 +1209,7 @@ async def _two_pass_index(
1132
1209
  f" [green]✓[/green] {lang} ({cfg_lsp.transport}, auto-started)"
1133
1210
  )
1134
1211
  except (Exception, asyncio.CancelledError) as exc:
1212
+ connection_failures[lang] = str(exc)
1135
1213
  _err.print(f" [yellow]⚠[/yellow] {lang}: {exc} — skipped")
1136
1214
  _hint = (
1137
1215
  entry.install_hint
@@ -1140,24 +1218,38 @@ async def _two_pass_index(
1140
1218
  )
1141
1219
  if _hint:
1142
1220
  _err.print(f" [dim]Install: {_hint}[/dim]")
1143
- if lang in launchers:
1221
+ # A launcher/client that failed before registration still owns
1222
+ # resources; do not strand it while refusing partial enrichment.
1223
+ if client is not None and lang not in clients:
1144
1224
  with suppress(Exception):
1145
- await launchers.pop(lang).stop()
1225
+ await client.shutdown()
1226
+ if launcher is not None and lang not in launchers:
1227
+ with suppress(Exception):
1228
+ await launcher.stop()
1146
1229
 
1147
- if not clients:
1148
- _console.print(
1149
- "[dim]No LSP servers connected; running plain index.[/dim]"
1230
+ if connection_failures:
1231
+ # One connected language must not mask another requested language's
1232
+ # failed server: that would yield a seemingly complete un-enriched index.
1233
+ for client in clients.values():
1234
+ with suppress(Exception):
1235
+ await client.shutdown()
1236
+ for launcher in launchers.values():
1237
+ with suppress(Exception):
1238
+ await launcher.stop()
1239
+ details = ", ".join(
1240
+ f"{language}: {reason}"
1241
+ for language, reason in sorted(connection_failures.items())
1150
1242
  )
1151
- result = await _index_with_progress(
1152
- indexer,
1153
- repo_path=repo_path,
1154
- ref=ref,
1155
- force=args.force,
1156
- lsp_clients={},
1157
- initial_total=_file_count,
1243
+ raise RuntimeError(
1244
+ "--lsp was requested, but configured LSP servers failed to connect; "
1245
+ f"cannot certify type enrichment ({details})"
1246
+ )
1247
+
1248
+ if not clients:
1249
+ raise RuntimeError(
1250
+ "--lsp was requested, but no configured LSP server connected; "
1251
+ "cannot certify type enrichment"
1158
1252
  )
1159
- _print_index_result(result)
1160
- return
1161
1253
 
1162
1254
  # ── Pass 2: enrich with LSP ───────────────────────────────────────────────
1163
1255
  n = len(clients)
@@ -1297,6 +1389,10 @@ def _print_index_result(result: Any) -> None:
1297
1389
  f"[dim]Ignored {len(ignored_files)} file(s) via .diffignore[/dim]"
1298
1390
  )
1299
1391
 
1392
+ # A partial index must not be presented to CI as successful (#193).
1393
+ # Keep the per-file diagnostics above, but fail the process.
1394
+ if result.errors:
1395
+ raise SystemExit(1)
1300
1396
 
1301
1397
 
1302
1398
 
@@ -1939,6 +2035,17 @@ def _add_output_args(p: argparse.ArgumentParser) -> None:
1939
2035
  metavar="FORMAT",
1940
2036
  help="Output format: terminal (default), json, patch, html, llm",
1941
2037
  )
2038
+ # `--json` is the spelling people reach for first, and reaching for it used to fail with
2039
+ # "unrecognized arguments: --json" even though JSON output existed the whole time behind
2040
+ # `--format json`. An error that denies a feature you actually ship is worse than a missing
2041
+ # feature, because it teaches the user the tool cannot do it.
2042
+ p.add_argument(
2043
+ "--json",
2044
+ dest="format",
2045
+ action="store_const",
2046
+ const="json",
2047
+ help="Shorthand for --format json.",
2048
+ )
1942
2049
  p.add_argument(
1943
2050
  "--output", "-o",
1944
2051
  metavar="FILE",
@@ -222,7 +222,13 @@ def _build_parser() -> argparse.ArgumentParser:
222
222
  assets_git_p.set_defaults(func=_cmd_assets_git)
223
223
 
224
224
  # ── file ─────────────────────────────────────────────────────────────────
225
- file_p = sub.add_parser("file", help="Diff two local files.")
225
+ # `diff` is the first thing anyone types, and it used to fail with
226
+ # "No such command 'diff'. Did you mean 'gist-diff'?" — a suggestion that points away from
227
+ # the two commands that actually diff things. Aliasing it to `file` costs nothing and
228
+ # removes a dead end from the very first interaction with the tool.
229
+ file_p = sub.add_parser(
230
+ "file", aliases=["diff"], help="Diff two local files (alias: diff)."
231
+ )
226
232
  file_p.add_argument("old_file", metavar="OLD", help="Path to the old file.")
227
233
  file_p.add_argument("new_file", metavar="NEW", help="Path to the new file.")
228
234
  _add_output_args(file_p)
@@ -995,6 +1001,10 @@ if _CLICK_RUNTIME_AVAILABLE:
995
1001
  ("git", "Diff files or commits in a git repository."),
996
1002
  ("assets", "Perceptual diffs for non-text assets."),
997
1003
  ("file", "Diff two local files."),
1004
+ # Registered here as well as aliased on the argparse parser: this Click group is what
1005
+ # rejects unknown commands, so without an entry here `diff` still fails before argparse
1006
+ # is ever consulted — and fails suggesting `gist-diff`.
1007
+ ("diff", "Diff two local files (alias for 'file')."),
998
1008
  ("patch", "Diff from a unified diff patch."),
999
1009
  ("string", "Diff two in-memory strings."),
1000
1010
  ("github-pr", "Parse a GitHub pull request URL into a review target."),
@@ -23,6 +23,7 @@ import os
23
23
  import shlex
24
24
  import sys
25
25
  import time
26
+ from collections.abc import Callable
26
27
  from contextlib import suppress
27
28
  from pathlib import Path
28
29
  from typing import Any
@@ -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
@@ -444,8 +366,7 @@ def _render(diff: SemanticDiff, fmt: str, output: str | None, fuel: int | None =
444
366
  plugin_fuel = fuel if fuel is not None else 100_000_000
445
367
  adaptive_fuel = max(plugin_fuel, 20_000_000 + len(diff_json) * 100)
446
368
  pl = load_plugin(candidates[0], adaptive_fuel)
447
- result = pl.call_render(diff_json)
448
- _write_output(result, output)
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)
@@ -488,6 +409,69 @@ def _render_with_profile(
488
409
  _emit_phase_profiles(diff, render_ms=(time.perf_counter() - started) * 1000)
489
410
 
490
411
 
412
+ def _combine_html_reviews(pages: list[tuple[str, str]]) -> str:
413
+ """One valid HTML document with independent, sandboxed renderer pages.
414
+
415
+ The Wasm HTML renderer emits a complete HTML document per diff. Joining
416
+ those documents produces malformed HTML; using sandboxed srcdoc frames
417
+ retains each renderer's own CSS without reinterpreting any diff semantics.
418
+ """
419
+ from html import escape
420
+
421
+ if len(pages) <= 1:
422
+ return pages[0][1] if pages else ""
423
+ frames = []
424
+ for filename, document in pages:
425
+ name = escape(filename)
426
+ attribute = escape(filename, quote=True)
427
+ content = escape(document, quote=True)
428
+ frames.append(
429
+ '<section class="review"><h2>' + name + '</h2>'
430
+ '<iframe title="' + attribute + '" sandbox="allow-scripts" '
431
+ 'loading="lazy" srcdoc="' + content + '"></iframe></section>'
432
+ )
433
+ return (
434
+ '<!doctype html>\n<html lang="en"><head><meta charset="utf-8">'
435
+ '<title>IntentumDiff Git review</title>'
436
+ '<style>body{font:16px system-ui,sans-serif;margin:1.5rem}'
437
+ 'section.review{margin:1.5rem 0;border:1px solid #888;border-radius:6px;'
438
+ 'padding:1rem}iframe{display:block;width:100%;height:70vh;border:0}'
439
+ 'h2{font-size:1.1rem}</style></head><body>\n'
440
+ + '\n'.join(frames) + '\n</body></html>\n'
441
+ )
442
+
443
+
444
+ def _render_many_with_profile(
445
+ diffs: list[SemanticDiff],
446
+ args: argparse.Namespace,
447
+ *,
448
+ fuel: int | None = None,
449
+ title: Callable[[SemanticDiff], str] | None = None,
450
+ ) -> None:
451
+ """Render several diffs as one document without dropping any file (#280).
452
+
453
+ JSON is always an array. HTML embeds each original Wasm-rendered page in a
454
+ sandboxed frame. Other formats join renders, with per-file titles for
455
+ terminal output to a file.
456
+ """
457
+ parts: list[str] = []
458
+ for diff in diffs:
459
+ started = time.perf_counter()
460
+ text = _render_text(diff, args.format, fuel=fuel)
461
+ if args.format == "terminal" and title is not None:
462
+ text = f"== {title(diff)} ==\n{text}"
463
+ parts.append(text)
464
+ _emit_phase_profiles(diff, render_ms=(time.perf_counter() - started) * 1000)
465
+ if args.format == "json":
466
+ _write_output("[\n" + ",\n".join(parts) + "\n]", args.output)
467
+ elif args.format == "html":
468
+ labels = [title(diff) if title is not None else f"Diff {i + 1}"
469
+ for i, diff in enumerate(diffs)]
470
+ _write_output(_combine_html_reviews(list(zip(labels, parts, strict=True))), args.output)
471
+ else:
472
+ _write_output("\n".join(parts), args.output)
473
+
474
+
491
475
  def _has_immutable_guardrail(diff: SemanticDiff) -> bool:
492
476
  return any(
493
477
  violation.severity == GuardrailSeverity.IMMUTABLE