intentumdiff-python 0.0.1__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 (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
@@ -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,
@@ -61,9 +62,11 @@ from intentumdiff.cli._shared import ( # noqa: F401
61
62
  _guardrail_result,
62
63
  _json_default,
63
64
  _load_cli_config,
65
+ _offer_incomplete_reports,
64
66
  _parse_fuel,
65
67
  _record_diagnostics_db,
66
68
  _render,
69
+ _render_many_with_profile,
67
70
  _render_with_profile,
68
71
  _resolve_repo_root,
69
72
  _warn_if_unlimited_fuel,
@@ -106,18 +109,21 @@ def _cmd_assets_git(args: argparse.Namespace) -> None:
106
109
  _emit_asset_payload(payload, json_output=args.json)
107
110
 
108
111
 
112
+ def _git_file_rule_title(diff: SemanticDiff) -> Text:
113
+ """Build a literal Rich rule title; filenames and Git statuses are data, not markup."""
114
+ label = diff.staging_status or ""
115
+ name = diff.new_filename or diff.old_filename or "(unknown file)"
116
+ return Text(f"{name} [{label}]" if label else name)
117
+
118
+
109
119
  def _cmd_git(args: argparse.Namespace) -> None:
110
- from intentumdiff.sources.git_source import _REF_STAGED, _REF_UNPUSHED
120
+ from intentumdiff.sources.git_source import StagedSource, _REF_STAGED, _REF_UNPUSHED
111
121
  from intentumdiff.vcs.git_cli import NotAGitRepositoryError
112
122
 
113
- repo_path = args.repo # '.' when not supplied
114
-
115
- # Resolve the effective new_ref from mutually-exclusive scope flags.
116
- new_ref: str = args.new # may be "", ":staged", ":unpushed", or an explicit ref
117
- if getattr(args, "staged", False):
118
- new_ref = _REF_STAGED
119
- elif getattr(args, "unpushed", False):
120
- new_ref = _REF_UNPUSHED
123
+ if getattr(args, "repo_option", None) is not None and args.repo != ".":
124
+ _err.print("[red]Name the repository once: --repo or the REPO positional.[/red]")
125
+ sys.exit(2)
126
+ repo_path = getattr(args, "repo_option", None) or args.repo # --repo, REPO or '.' (#317)
121
127
 
122
128
  # Resolve the effective new_ref from mutually-exclusive scope flags.
123
129
  new_ref: str = args.new # may be "", ":staged", ":unpushed", or an explicit ref
@@ -129,10 +135,8 @@ def _cmd_git(args: argparse.Namespace) -> None:
129
135
  # Smart --old default: HEAD for working-tree / scoped modes; HEAD~1 when an
130
136
  # explicit commit ref is given for --new so that `intentumdiff git --new HEAD`
131
137
  # means "show the last commit" rather than HEAD vs HEAD = no diff.
132
- _is_working_tree_mode = not new_ref or new_ref in (_REF_STAGED, _REF_UNPUSHED)
133
- old_ref: str = args.old if args.old is not None else (
134
- "HEAD" if _is_working_tree_mode else "HEAD~1"
135
- )
138
+ working_tree_mode = not new_ref or new_ref in (_REF_STAGED, _REF_UNPUSHED)
139
+ old_ref: str = args.old if args.old is not None else ("HEAD" if working_tree_mode else "HEAD~1")
136
140
 
137
141
  try:
138
142
  if args.file:
@@ -144,11 +148,7 @@ def _cmd_git(args: argparse.Namespace) -> None:
144
148
  ref=old_ref,
145
149
  )
146
150
  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(
151
+ source = StagedSource(
152
152
  repo_path=repo_path,
153
153
  file_path=args.file,
154
154
  ref=old_ref,
@@ -192,16 +192,37 @@ def _cmd_git(args: argparse.Namespace) -> None:
192
192
  new_ref=new_ref,
193
193
  )
194
194
  if not diffs:
195
- _console.print("[green]No parseable changes found.[/green]")
195
+ # No semantic result exists to render, but machine consumers must
196
+ # still receive a valid empty result and requested report files.
197
+ # Keep the human status on stderr so stdout stays machine-readable.
198
+ if args.format == "terminal":
199
+ if args.output:
200
+ _write_output("No parseable changes found.\n", args.output)
201
+ else:
202
+ _err.print("[green]No parseable changes found.[/green]")
203
+ elif args.format == "json":
204
+ _write_output("[]", args.output)
205
+ elif args.output:
206
+ # Empty patch/HTML/LLM output is an empty document, not a
207
+ # fabricated per-file semantic diff.
208
+ _write_output("", args.output)
209
+ result = _emit_guardrail_reports([], args)
210
+ _record_diagnostics_db([], args)
211
+ _exit_if_guardrail_result_fails(result)
196
212
  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)
213
+ if args.format == "terminal" and not args.output:
214
+ for diff in diffs:
215
+ _console.rule(_git_file_rule_title(diff))
216
+ _render_with_profile(diff, args, fuel=differ._config.plugin_fuel)
217
+ else:
218
+ # One document for machine formats and files (#280): a JSON array, or the
219
+ # joined per-file renders, so no diff overwrites another in --output.
220
+ _render_many_with_profile(
221
+ diffs,
222
+ args,
223
+ fuel=differ._config.plugin_fuel,
224
+ title=lambda diff: _git_file_rule_title(diff).plain,
225
+ )
205
226
  result = _emit_guardrail_reports(diffs, args)
206
227
  _record_diagnostics_db(diffs, args)
207
228
  _exit_if_guardrail_result_fails(result)
@@ -212,13 +233,12 @@ def _cmd_git(args: argparse.Namespace) -> None:
212
233
  _err.print(f"[red]Repository path not found:[/red] {repo_path}")
213
234
  # When the repo path looks like a git ref name (e.g. "main", "HEAD",
214
235
  # "new") the user probably typed '-- ref' instead of '--new ref'.
215
- if not Path(repo_path).is_absolute():
216
- import re as _re
217
- if _re.fullmatch(r"[A-Za-z0-9_/.\-]+", repo_path):
218
- _err.print(
219
- f"[yellow]Hint: '{repo_path}' looks like a git ref. "
220
- f"Did you mean [bold]--new {repo_path}[/bold]?[/yellow]"
221
- )
236
+ import re as _re
237
+ if not Path(repo_path).is_absolute() and _re.fullmatch(r"[A-Za-z0-9_/.\-]+", repo_path):
238
+ _err.print(
239
+ f"[yellow]Hint: '{repo_path}' looks like a git ref. "
240
+ f"Did you mean [bold]--new {repo_path}[/bold]?[/yellow]"
241
+ )
222
242
  else:
223
243
  _err.print(
224
244
  f"[red]Not a git repository:[/red] {repo_path!r} "
@@ -242,8 +262,9 @@ def _cmd_file(args: argparse.Namespace) -> None:
242
262
  config_start_path=args.new_file,
243
263
  guardrails_policy=getattr(args, "guardrails_policy", None),
244
264
  )
265
+ diff = differ.diff(source)
245
266
  if args.stream:
246
- for change in differ.diff_stream(source):
267
+ for change in diff.changes:
247
268
  ct_str = (
248
269
  change.change_type.value
249
270
  if hasattr(change.change_type, "value")
@@ -253,12 +274,12 @@ def _cmd_file(args: argparse.Namespace) -> None:
253
274
  if change.text_diff:
254
275
  line += f" [{change.text_diff}]"
255
276
  _console.print(line)
277
+ _offer_incomplete_reports([diff], args)
256
278
  else:
257
- diff = differ.diff(source)
258
279
  _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)
280
+ result = _emit_guardrail_reports(diff, args)
281
+ _record_diagnostics_db(diff, args)
282
+ _exit_if_guardrail_result_fails(result)
262
283
 
263
284
 
264
285
  def _cmd_patch(args: argparse.Namespace) -> None:
@@ -411,6 +432,34 @@ def _cmd_diagnostics_query(args: argparse.Namespace) -> None:
411
432
  def _cmd_guardrails_check(args: argparse.Namespace) -> None:
412
433
  from intentumdiff.vcs.git_cli import NotAGitRepositoryError
413
434
 
435
+ # Validate the policy BEFORE diffing anything.
436
+ #
437
+ # The policy used to be loaded lazily, per changed file. With no changed files it was
438
+ # never loaded at all, so `guardrails check --policy typo.yaml` printed
439
+ # "Guardrail check passed: 0 file(s) checked" and exited 0 - with nothing on stderr.
440
+ # A typo in the path was indistinguishable from a clean run, on a gate whose documented
441
+ # purpose is stopping API keys changing unreviewed. It failed OPEN.
442
+ #
443
+ # A gate must verify it can do its job before reporting that it did.
444
+ if args.guardrails_policy is not None:
445
+ from pathlib import Path as _Path
446
+
447
+ from intentumdiff.analysis.guardrails import load_guardrail_policy
448
+
449
+ try:
450
+ policy = load_guardrail_policy("", explicit_path=_Path(args.guardrails_policy))
451
+ except (OSError, ValueError) as exc:
452
+ _err.print(f"[red]Guardrail policy could not be loaded: {exc}[/red]")
453
+ sys.exit(2)
454
+ if not policy.rules:
455
+ # Loaded, parsed, and protects nothing. Reporting "passed" for that is the same
456
+ # false assurance as failing to load it.
457
+ _err.print(
458
+ f"[red]Guardrail policy {args.guardrails_policy} defines no protected "
459
+ f"entries, so this check cannot fail. Add rules, or drop --policy.[/red]"
460
+ )
461
+ sys.exit(2)
462
+
414
463
  try:
415
464
  differ = _differ(
416
465
  args.fuel,
@@ -454,7 +503,11 @@ def _cmd_plugins_list(_args: argparse.Namespace) -> None:
454
503
 
455
504
  # Resolve the core package provenance string once for built-in rows
456
505
  import importlib.metadata as _meta
457
- for _dist_name in ("intentumdiff",):
506
+ # The DISTRIBUTION name, which is not the import name: this package publishes as
507
+ # `intentumdiff-python` while `import intentumdiff` is the package. Looking up only the
508
+ # import name silently fell through to the bare "IntentumDiff" fallback, so every
509
+ # built-in plugin row lost its version.
510
+ for _dist_name in ("intentumdiff-python", "intentumdiff_python", "intentumdiff"):
458
511
  try:
459
512
  _core_dist = _meta.distribution(_dist_name)
460
513
  _core_prov = (
@@ -514,6 +567,7 @@ def _cmd_plugins_list(_args: argparse.Namespace) -> None:
514
567
 
515
568
  def _cmd_plugins_add(args: argparse.Namespace) -> None:
516
569
  import os as _os
570
+ import warnings as _warnings
517
571
 
518
572
  from intentumdiff.plugins.hub import (
519
573
  PluginSpec,
@@ -527,6 +581,7 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
527
581
  save_plugins_file,
528
582
  security_check_plugin,
529
583
  )
584
+ from intentumdiff.plugins.hub import logger as _hub_logger
530
585
 
531
586
  source: str = getattr(args, "source", "git")
532
587
  skip_verify: bool = getattr(args, "skip_verify", False)
@@ -540,22 +595,40 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
540
595
  "INTENTUMDIFF_ALLOW_SKIP_VERIFY=1 to prevent accidental use.[/bold red]"
541
596
  )
542
597
  sys.exit(1)
543
- _err.print(
544
- "[yellow]Warning: security verification skipped (--skip-verify).[/yellow]"
545
- )
598
+ _err.print("[yellow]Warning: security verification skipped (--skip-verify).[/yellow]")
599
+
600
+ # Preserve existing pinned Wasm/dependency provenance before pip has any
601
+ # side effects. A malformed manifest or dangling symlink is not an empty
602
+ # plugin inventory: refusing the update avoids deleting existing pins (#252).
603
+ existing_manifest: list[PluginSpec] = []
604
+ if args.save:
605
+ manifest_path = Path(args.file)
606
+ if manifest_path.exists() or manifest_path.is_symlink():
607
+ try:
608
+ existing_manifest = load_plugins_file(manifest_path)
609
+ except Exception as exc:
610
+ raise RuntimeError(
611
+ f"Refusing to overwrite invalid plugins manifest {manifest_path}: {exc}"
612
+ ) from exc
546
613
 
547
614
  # ── 1. Consult the official registry for official plugins ─────────────────
548
615
  registry_entry: RegistryEntry | None = None
549
616
  if not args.repo and not skip_verify:
550
617
  try:
551
- registry = fetch_official_registry(
552
- strict=getattr(args, "strict_registry", False),
553
- )
554
- short = (
555
- args.plugin_name[len("intentumdiff-"):]
556
- if args.plugin_name.startswith("intentumdiff-")
557
- else args.plugin_name
558
- )
618
+ # #309: an invalid manifest only skips entries; show its warning once, here, and not
619
+ # again through the logging last-resort handler.
620
+ with _warnings.catch_warnings(record=True) as caught:
621
+ _warnings.simplefilter("always")
622
+ _hub_logger.disabled = True
623
+ try:
624
+ registry = fetch_official_registry(
625
+ strict=getattr(args, "strict_registry", False),
626
+ )
627
+ finally:
628
+ _hub_logger.disabled = False
629
+ for caught_warning in caught:
630
+ _err.print("[yellow]Registry warning:[/yellow]", Text(str(caught_warning.message)))
631
+ short = args.plugin_name.removeprefix("intentumdiff-")
559
632
  registry_entry = registry.get(short)
560
633
  if registry_entry is not None:
561
634
  # #94: refuse an ABI-incompatible plugin at RESOLVE time, before any install.
@@ -650,15 +723,8 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
650
723
  # ── 6. Save to manifest ───────────────────────────────────────────────────
651
724
  if args.save:
652
725
  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
658
- existing = [
659
- s for s in existing
660
- if s.name != spec.name and s.name != spec.package_name
661
- ]
726
+ # Replace only the matching entry; retain all other pinned provenance.
727
+ existing = [s for s in existing_manifest if s.name not in (spec.name, spec.package_name)]
662
728
  existing.append(spec)
663
729
  save_plugins_file(yaml_path, existing)
664
730
  _console.print(f"[green]Saved to {yaml_path}[/green]")
@@ -688,9 +754,7 @@ def _cmd_plugins_install(args: argparse.Namespace) -> None:
688
754
  "INTENTUMDIFF_ALLOW_SKIP_VERIFY=1 to prevent accidental use.[/bold red]"
689
755
  )
690
756
  sys.exit(1)
691
- _err.print(
692
- "[yellow]Warning: security verification skipped (--skip-verify).[/yellow]"
693
- )
757
+ _err.print("[yellow]Warning: security verification skipped (--skip-verify).[/yellow]")
694
758
 
695
759
  yaml_path = Path(args.file)
696
760
  if not yaml_path.exists():
@@ -752,9 +816,7 @@ def _cmd_plugins_install(args: argparse.Namespace) -> None:
752
816
  )
753
817
  for e in errors:
754
818
  _err.print(f" [red]{e}[/red]")
755
- _err.print(
756
- f" [red]Uninstalling '{spec.package_name}'.[/red]"
757
- )
819
+ _err.print(f" [red]Uninstalling '{spec.package_name}'.[/red]")
758
820
  pip_uninstall(spec.package_name)
759
821
  security_failed.append(spec.name)
760
822
 
@@ -868,25 +930,40 @@ def _cmd_plugins_remove(args: argparse.Namespace) -> None:
868
930
 
869
931
  name = args.plugin_name
870
932
  spec = PluginSpec(name=name)
933
+ manifest_path = Path(args.file) if args.save else None
934
+ existing_manifest: list[PluginSpec] | None = None
935
+ # --save is a pinned provenance change, not best-effort decoration. Check
936
+ # the existing manifest before any irreversible pip side effects (#257).
937
+ if manifest_path is not None and (
938
+ manifest_path.exists() or manifest_path.is_symlink()
939
+ ):
940
+ try:
941
+ existing_manifest = load_plugins_file(manifest_path)
942
+ except Exception as exc:
943
+ raise RuntimeError(
944
+ f"Refusing to uninstall with invalid plugins manifest {manifest_path}: {exc}"
945
+ ) from exc
946
+
871
947
  _console.print(f"Uninstalling [cyan]{spec.package_name}[/cyan] ...")
872
948
  rc = pip_uninstall(spec.package_name)
873
949
  if rc != 0:
874
950
  _err.print(f"[red]pip uninstall failed (exit code {rc})[/red]")
875
951
  sys.exit(rc)
876
952
 
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]")
953
+ if manifest_path is not None and existing_manifest is not None:
954
+ specs = [
955
+ s for s in existing_manifest
956
+ if s.name != name and s.name != spec.package_name
957
+ ]
958
+ try:
959
+ save_plugins_file(manifest_path, specs)
960
+ except Exception as exc:
961
+ # pip has already succeeded, but the manifest is not reconciled.
962
+ # Propagate a partial failure rather than print a false success.
963
+ raise RuntimeError(
964
+ f"Plugin uninstalled but could not update {manifest_path}: {exc}"
965
+ ) from exc
966
+ _console.print(f"[green]Removed from {manifest_path}[/green]")
890
967
 
891
968
  _console.print(f"[green]Plugin '{spec.package_name}' uninstalled.[/green]")
892
969
 
@@ -1030,20 +1107,10 @@ async def _two_pass_index(
1030
1107
 
1031
1108
  if not launchable:
1032
1109
  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,
1110
+ raise RuntimeError(
1111
+ "--lsp was requested, but no LSP servers are configured for "
1112
+ f"detected languages ({langs_str}); cannot certify type enrichment"
1044
1113
  )
1045
- _print_index_result(result)
1046
- return
1047
1114
 
1048
1115
  _console.print(
1049
1116
  f"[bold]Pass 1 complete[/bold] — "
@@ -1057,6 +1124,7 @@ async def _two_pass_index(
1057
1124
 
1058
1125
  launchers: dict[str, LspServerProcess] = {}
1059
1126
  clients: dict[str, AsyncLspClient] = {}
1127
+ connection_failures: dict[str, str] = {}
1060
1128
 
1061
1129
  # Separate languages into "already running" vs "needs auto-start".
1062
1130
  manual: list[str] = []
@@ -1112,6 +1180,7 @@ async def _two_pass_index(
1112
1180
  f" [green]✓[/green] {lang} (tcp, already running @ {cfg_lsp})"
1113
1181
  )
1114
1182
  except (Exception, asyncio.CancelledError) as exc:
1183
+ connection_failures[lang] = str(exc)
1115
1184
  _err.print(f" [yellow]⚠[/yellow] {lang}: {exc} — skipped")
1116
1185
  _hint = entry.install_hint
1117
1186
  if _hint:
@@ -1120,6 +1189,8 @@ async def _two_pass_index(
1120
1189
  # Spawn approved auto-start servers.
1121
1190
  for lang in to_start:
1122
1191
  entry = user_entries.get(lang)
1192
+ launcher: LspServerProcess | None = None
1193
+ client: AsyncLspClient | None = None
1123
1194
  try:
1124
1195
  spec = entry.to_spec() if entry is not None else None
1125
1196
  launcher = LspServerProcess(lang, spec=spec)
@@ -1132,6 +1203,7 @@ async def _two_pass_index(
1132
1203
  f" [green]✓[/green] {lang} ({cfg_lsp.transport}, auto-started)"
1133
1204
  )
1134
1205
  except (Exception, asyncio.CancelledError) as exc:
1206
+ connection_failures[lang] = str(exc)
1135
1207
  _err.print(f" [yellow]⚠[/yellow] {lang}: {exc} — skipped")
1136
1208
  _hint = (
1137
1209
  entry.install_hint
@@ -1140,24 +1212,38 @@ async def _two_pass_index(
1140
1212
  )
1141
1213
  if _hint:
1142
1214
  _err.print(f" [dim]Install: {_hint}[/dim]")
1143
- if lang in launchers:
1215
+ # A launcher/client that failed before registration still owns
1216
+ # resources; do not strand it while refusing partial enrichment.
1217
+ if client is not None and lang not in clients:
1218
+ with suppress(Exception):
1219
+ await client.shutdown()
1220
+ if launcher is not None and lang not in launchers:
1144
1221
  with suppress(Exception):
1145
- await launchers.pop(lang).stop()
1222
+ await launcher.stop()
1146
1223
 
1147
- if not clients:
1148
- _console.print(
1149
- "[dim]No LSP servers connected; running plain index.[/dim]"
1224
+ if connection_failures:
1225
+ # One connected language must not mask another requested language's
1226
+ # failed server: that would yield a seemingly complete un-enriched index.
1227
+ for client in clients.values():
1228
+ with suppress(Exception):
1229
+ await client.shutdown()
1230
+ for launcher in launchers.values():
1231
+ with suppress(Exception):
1232
+ await launcher.stop()
1233
+ details = ", ".join(
1234
+ f"{language}: {reason}"
1235
+ for language, reason in sorted(connection_failures.items())
1150
1236
  )
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,
1237
+ raise RuntimeError(
1238
+ "--lsp was requested, but configured LSP servers failed to connect; "
1239
+ f"cannot certify type enrichment ({details})"
1240
+ )
1241
+
1242
+ if not clients:
1243
+ raise RuntimeError(
1244
+ "--lsp was requested, but no configured LSP server connected; "
1245
+ "cannot certify type enrichment"
1158
1246
  )
1159
- _print_index_result(result)
1160
- return
1161
1247
 
1162
1248
  # ── Pass 2: enrich with LSP ───────────────────────────────────────────────
1163
1249
  n = len(clients)
@@ -1297,6 +1383,10 @@ def _print_index_result(result: Any) -> None:
1297
1383
  f"[dim]Ignored {len(ignored_files)} file(s) via .diffignore[/dim]"
1298
1384
  )
1299
1385
 
1386
+ # A partial index must not be presented to CI as successful (#193).
1387
+ # Keep the per-file diagnostics above, but fail the process.
1388
+ if result.errors:
1389
+ raise SystemExit(1)
1300
1390
 
1301
1391
 
1302
1392
 
@@ -1784,8 +1874,7 @@ def _cmd_serve(args: argparse.Namespace) -> None:
1784
1874
  port: int = args.port
1785
1875
 
1786
1876
  # Guard against accidentally exposing the playground to the network.
1787
- _loopback = {"127.0.0.1", "::1", "localhost"}
1788
- if host not in _loopback and not getattr(args, "allow_remote", False):
1877
+ if host not in {"127.0.0.1", "::1", "localhost"} and not getattr(args, "allow_remote", False):
1789
1878
  _err.print(
1790
1879
  f"[bold red]Error:[/bold red] binding to '{host}' would expose the "
1791
1880
  "playground on the network. "
@@ -1798,24 +1887,25 @@ def _cmd_serve(args: argparse.Namespace) -> None:
1798
1887
 
1799
1888
  # Try the requested port; fall back to a free OS-assigned port if taken.
1800
1889
  import socket
1801
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as _s:
1802
- _s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1803
- try:
1804
- _s.bind((host, port))
1805
- _s.close()
1806
- except OSError:
1807
- _s.bind((host, 0))
1808
- port = _s.getsockname()[1]
1809
- _console.print(
1810
- f"[yellow]Warning:[/yellow] requested port was unavailable; "
1811
- f"binding to free port [cyan]{port}[/cyan] instead."
1812
- )
1813
-
1814
- _console.print(
1815
- f"[bold green]IntentumDiff serve[/bold green] listening on "
1816
- f"[cyan]http://{host}:{port}[/cyan] "
1817
- f"([dim]Ctrl+C to stop[/dim])"
1818
- )
1890
+ family = socket.AF_INET6 if ":" in host else socket.AF_INET # an IPv6 literal (#323)
1891
+ try:
1892
+ with socket.socket(family, socket.SOCK_STREAM) as _s:
1893
+ _s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
1894
+ try:
1895
+ _s.bind((host, port))
1896
+ except OSError:
1897
+ _s.bind((host, 0))
1898
+ port = _s.getsockname()[1]
1899
+ _console.print(
1900
+ f"[yellow]Warning:[/yellow] requested port was unavailable; "
1901
+ f"binding to free port [cyan]{port}[/cyan] instead."
1902
+ )
1903
+ except OSError as exc: # e.g. no IPv6 on this host: a diagnostic, not a traceback
1904
+ _err.print(f"[red]Error:[/red] cannot bind {host!r}: {exc}")
1905
+ sys.exit(1)
1906
+ shown = f"[{host}]" if family == socket.AF_INET6 else host
1907
+ _console.print(f"[bold green]IntentumDiff serve[/bold green] listening on "
1908
+ f"[cyan]http://{shown}:{port}[/cyan] ([dim]Ctrl+C to stop[/dim])")
1819
1909
  uvicorn.run(app, host=host, port=port, log_level="warning")
1820
1910
 
1821
1911
 
@@ -1939,24 +2029,37 @@ def _add_output_args(p: argparse.ArgumentParser) -> None:
1939
2029
  metavar="FORMAT",
1940
2030
  help="Output format: terminal (default), json, patch, html, llm",
1941
2031
  )
2032
+ # `--json` is the spelling people reach for first, and reaching for it used to fail with
2033
+ # "unrecognized arguments: --json" even though JSON output existed the whole time behind
2034
+ # `--format json`. An error that denies a feature you actually ship is worse than a missing
2035
+ # feature, because it teaches the user the tool cannot do it.
2036
+ p.add_argument(
2037
+ "--json",
2038
+ dest="format",
2039
+ action="store_const",
2040
+ const="json",
2041
+ help="Shorthand for --format json.",
2042
+ )
1942
2043
  p.add_argument(
1943
2044
  "--output", "-o",
1944
2045
  metavar="FILE",
1945
2046
  default=None,
1946
2047
  help="Write output to FILE instead of stdout",
1947
2048
  )
2049
+ p.add_argument("--report-bug", action="store_true", help="On an incomplete review, preview "
2050
+ "core's bug report and ask before opening the pre-filled issue in a browser.")
1948
2051
 
1949
2052
 
1950
2053
  def _parse_megapixels(value: str) -> int:
1951
- try:
2054
+ try: # nan is not > 0; inf and exponent overflow raise OverflowError in int() (#315)
1952
2055
  megapixels = float(value)
1953
- except ValueError:
1954
- raise argparse.ArgumentTypeError(
1955
- f"invalid megapixel value {value!r}: use a positive number"
1956
- ) from None
1957
- if megapixels <= 0:
1958
- raise argparse.ArgumentTypeError("max decoded megapixels must be positive")
1959
- return max(1, int(megapixels * 1_000_000))
2056
+ if megapixels > 0:
2057
+ return max(1, int(megapixels * 1_000_000))
2058
+ except (ValueError, OverflowError):
2059
+ pass
2060
+ raise argparse.ArgumentTypeError(
2061
+ f"invalid megapixel value {value!r}: use a finite positive number"
2062
+ )
1960
2063
 
1961
2064
 
1962
2065
  def _add_asset_diff_args(p: argparse.ArgumentParser) -> None:
@@ -2083,8 +2186,8 @@ def _add_guardrail_args(p: argparse.ArgumentParser) -> None:
2083
2186
  action="store_true",
2084
2187
  default=False,
2085
2188
  help=(
2086
- "Exit non-zero when an immutable protected config guardrail "
2087
- "violation is detected."
2189
+ "Exit 2 when any protected config guardrail violation "
2190
+ "(important or immutable) is detected."
2088
2191
  ),
2089
2192
  )
2090
2193
  p.add_argument(
@@ -2122,6 +2225,7 @@ class _GitPositionalsAction(argparse.Action):
2122
2225
  With one positional: ``git FILE`` → repo=".", file=FILE
2123
2226
  With two positionals: ``git REPO FILE`` → repo=REPO, file=FILE
2124
2227
  With zero positionals: → repo=".", file=None (commit-wide)
2228
+ More than two is a usage error: dropping the rest silently shrank the review (#318).
2125
2229
  """
2126
2230
 
2127
2231
  def __call__(
@@ -2131,7 +2235,9 @@ class _GitPositionalsAction(argparse.Action):
2131
2235
  values: list[str],
2132
2236
  option_string: str | None = None,
2133
2237
  ) -> None:
2134
- if len(values) >= 2:
2238
+ if len(values) > 2:
2239
+ parser.error(f"git takes at most two positionals ([REPO] FILE); got extra {values[2:]}")
2240
+ if len(values) == 2:
2135
2241
  namespace.repo = values[0]
2136
2242
  namespace.file = values[1]
2137
2243
  elif len(values) == 1: