intentumdiff-python 0.0.1__py3-none-macosx_11_0_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 (165) hide show
  1. intentumdiff/__init__.py +134 -0
  2. intentumdiff/_differ_gate.py +210 -0
  3. intentumdiff/_differ_presentation.py +786 -0
  4. intentumdiff/_differ_runtime.py +320 -0
  5. intentumdiff/analysis/__init__.py +1 -0
  6. intentumdiff/analysis/compile_commands.py +151 -0
  7. intentumdiff/analysis/cross_file.py +71 -0
  8. intentumdiff/analysis/diagnostics.py +309 -0
  9. intentumdiff/analysis/guardrail_reports.py +254 -0
  10. intentumdiff/analysis/guardrails.py +318 -0
  11. intentumdiff/analysis/invariances.py +1207 -0
  12. intentumdiff/analysis/keyed_profiles.py +25 -0
  13. intentumdiff/analysis/resource_profiles.py +14 -0
  14. intentumdiff/analysis/schema_resolver.py +816 -0
  15. intentumdiff/analysis/text_review.py +46 -0
  16. intentumdiff/analysis/user_schemas.py +430 -0
  17. intentumdiff/assets.py +45 -0
  18. intentumdiff/cache/__init__.py +37 -0
  19. intentumdiff/cache/duckdb_store.py +98 -0
  20. intentumdiff/cache/sqlite_store.py +149 -0
  21. intentumdiff/cache/store.py +190 -0
  22. intentumdiff/cli/__init__.py +199 -0
  23. intentumdiff/cli/_commands.py +2141 -0
  24. intentumdiff/cli/_parser.py +1061 -0
  25. intentumdiff/cli/_shared.py +644 -0
  26. intentumdiff/content_type.py +59 -0
  27. intentumdiff/core/__init__.py +1 -0
  28. intentumdiff/core/commit_differ.py +599 -0
  29. intentumdiff/core/config.py +51 -0
  30. intentumdiff/core/cst_serializer.py +101 -0
  31. intentumdiff/core/diffignore.py +87 -0
  32. intentumdiff/core/index.py +189 -0
  33. intentumdiff/core/indexer.py +792 -0
  34. intentumdiff/core/models.py +837 -0
  35. intentumdiff/differ.py +2195 -0
  36. intentumdiff/github_app.py +287 -0
  37. intentumdiff/intentumdiff_rust_core/__init__.py +7 -0
  38. intentumdiff/intentumdiff_rust_core/ffi.py +8 -0
  39. intentumdiff/intentumdiff_rust_core/libintentumdiff_rust_core.dylib +0 -0
  40. intentumdiff/invariances/__init__.py +2 -0
  41. intentumdiff/invariances/rules.schema.json +283 -0
  42. intentumdiff/invariances/rules.yaml +349 -0
  43. intentumdiff/live_server.py +1314 -0
  44. intentumdiff/lsp/__init__.py +67 -0
  45. intentumdiff/lsp/client.py +544 -0
  46. intentumdiff/lsp/config.py +96 -0
  47. intentumdiff/lsp/enricher.py +227 -0
  48. intentumdiff/lsp/exceptions.py +27 -0
  49. intentumdiff/lsp/launcher.py +273 -0
  50. intentumdiff/lsp/servers.py +356 -0
  51. intentumdiff/lsp_server/__init__.py +14 -0
  52. intentumdiff/lsp_server/_codelens.py +67 -0
  53. intentumdiff/lsp_server/_diagnostics.py +62 -0
  54. intentumdiff/lsp_server/_handlers.py +175 -0
  55. intentumdiff/lsp_server/server.py +205 -0
  56. intentumdiff/plugins/__init__.py +1 -0
  57. intentumdiff/plugins/adapter.py +397 -0
  58. intentumdiff/plugins/builtins.py +323 -0
  59. intentumdiff/plugins/exceptions.py +93 -0
  60. intentumdiff/plugins/hub.py +1155 -0
  61. intentumdiff/plugins/language_metadata.py +250 -0
  62. intentumdiff/plugins/loader.py +1252 -0
  63. intentumdiff/plugins/registry.py +1079 -0
  64. intentumdiff/plugins/registry.schema.json +99 -0
  65. intentumdiff/plugins/registry_schema.py +280 -0
  66. intentumdiff/plugins/wit/plugin.wit +351 -0
  67. intentumdiff/rust_core.py +2370 -0
  68. intentumdiff/serve/__init__.py +19 -0
  69. intentumdiff/serve/_app.py +485 -0
  70. intentumdiff/serve/_static/index.html +326 -0
  71. intentumdiff/serve/_static/playground.js +567 -0
  72. intentumdiff/sources/__init__.py +1 -0
  73. intentumdiff/sources/base.py +28 -0
  74. intentumdiff/sources/file_source.py +48 -0
  75. intentumdiff/sources/git_source.py +375 -0
  76. intentumdiff/sources/live_buffer_source.py +113 -0
  77. intentumdiff/sources/patch_source.py +126 -0
  78. intentumdiff/sources/string_source.py +44 -0
  79. intentumdiff/testing.py +165 -0
  80. intentumdiff/vcs/__init__.py +37 -0
  81. intentumdiff/vcs/_safe_path.py +50 -0
  82. intentumdiff/vcs/base.py +136 -0
  83. intentumdiff/vcs/git_backend.py +97 -0
  84. intentumdiff/vcs/git_cli.py +100 -0
  85. intentumdiff/vcs/hg_backend.py +94 -0
  86. intentumdiff/vcs/perforce_backend.py +109 -0
  87. intentumdiff/vcs/svn_backend.py +105 -0
  88. intentumdiff/wasm/.gitkeep +2 -0
  89. intentumdiff/wasm/abap_parser.wasm +0 -0
  90. intentumdiff/wasm/adf_parser.wasm +0 -0
  91. intentumdiff/wasm/asciidoc_parser.wasm +0 -0
  92. intentumdiff/wasm/asm_parser.wasm +0 -0
  93. intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
  94. intentumdiff/wasm/astro_parser.wasm +0 -0
  95. intentumdiff/wasm/bash_parser.wasm +0 -0
  96. intentumdiff/wasm/clojure_parser.wasm +0 -0
  97. intentumdiff/wasm/cmake_parser.wasm +0 -0
  98. intentumdiff/wasm/cpp_parser.wasm +0 -0
  99. intentumdiff/wasm/csharp_parser.wasm +0 -0
  100. intentumdiff/wasm/css_parser.wasm +0 -0
  101. intentumdiff/wasm/dart_parser.wasm +0 -0
  102. intentumdiff/wasm/databricks_parser.wasm +0 -0
  103. intentumdiff/wasm/dax_parser.wasm +0 -0
  104. intentumdiff/wasm/delphi_parser.wasm +0 -0
  105. intentumdiff/wasm/dockerfile_parser.wasm +0 -0
  106. intentumdiff/wasm/elixir_parser.wasm +0 -0
  107. intentumdiff/wasm/freebasic_parser.wasm +0 -0
  108. intentumdiff/wasm/generic_parser.wasm +0 -0
  109. intentumdiff/wasm/gitignore_parser.wasm +0 -0
  110. intentumdiff/wasm/go_parser.wasm +0 -0
  111. intentumdiff/wasm/gomod_parser.wasm +0 -0
  112. intentumdiff/wasm/graphql_parser.wasm +0 -0
  113. intentumdiff/wasm/groovy_parser.wasm +0 -0
  114. intentumdiff/wasm/haskell_parser.wasm +0 -0
  115. intentumdiff/wasm/html_parser.wasm +0 -0
  116. intentumdiff/wasm/ini_parser.wasm +0 -0
  117. intentumdiff/wasm/java_parser.wasm +0 -0
  118. intentumdiff/wasm/js_ts_parser.wasm +0 -0
  119. intentumdiff/wasm/json_parser.wasm +0 -0
  120. intentumdiff/wasm/kotlin_parser.wasm +0 -0
  121. intentumdiff/wasm/latex_parser.wasm +0 -0
  122. intentumdiff/wasm/lua_parser.wasm +0 -0
  123. intentumdiff/wasm/make_parser.wasm +0 -0
  124. intentumdiff/wasm/markdown_parser.wasm +0 -0
  125. intentumdiff/wasm/mdx_parser.wasm +0 -0
  126. intentumdiff/wasm/ocaml_parser.wasm +0 -0
  127. intentumdiff/wasm/odin_parser.wasm +0 -0
  128. intentumdiff/wasm/parser_manifest.json +590 -0
  129. intentumdiff/wasm/perl_parser.wasm +0 -0
  130. intentumdiff/wasm/php_parser.wasm +0 -0
  131. intentumdiff/wasm/plsql_parser.wasm +0 -0
  132. intentumdiff/wasm/po_parser.wasm +0 -0
  133. intentumdiff/wasm/postscript_parser.wasm +0 -0
  134. intentumdiff/wasm/powershell_parser.wasm +0 -0
  135. intentumdiff/wasm/proto_parser.wasm +0 -0
  136. intentumdiff/wasm/puppet_parser.wasm +0 -0
  137. intentumdiff/wasm/python_parser.wasm +0 -0
  138. intentumdiff/wasm/qsharp_parser.wasm +0 -0
  139. intentumdiff/wasm/r_parser.wasm +0 -0
  140. intentumdiff/wasm/reasonml_parser.wasm +0 -0
  141. intentumdiff/wasm/ruby_parser.wasm +0 -0
  142. intentumdiff/wasm/rust_parser.wasm +0 -0
  143. intentumdiff/wasm/sas_parser.wasm +0 -0
  144. intentumdiff/wasm/scala_parser.wasm +0 -0
  145. intentumdiff/wasm/scss_parser.wasm +0 -0
  146. intentumdiff/wasm/sql_parser.wasm +0 -0
  147. intentumdiff/wasm/squirrel_parser.wasm +0 -0
  148. intentumdiff/wasm/svelte_parser.wasm +0 -0
  149. intentumdiff/wasm/swift_parser.wasm +0 -0
  150. intentumdiff/wasm/terraform_parser.wasm +0 -0
  151. intentumdiff/wasm/toml_parser.wasm +0 -0
  152. intentumdiff/wasm/tsql_parser.wasm +0 -0
  153. intentumdiff/wasm/vbnet_parser.wasm +0 -0
  154. intentumdiff/wasm/vue_parser.wasm +0 -0
  155. intentumdiff/wasm/wat_parser.wasm +0 -0
  156. intentumdiff/wasm/xml_parser.wasm +0 -0
  157. intentumdiff/wasm/yaml_parser.wasm +0 -0
  158. intentumdiff/wasm/zig_parser.wasm +0 -0
  159. intentumdiff/watcher.py +259 -0
  160. intentumdiff_python-0.0.1.dist-info/METADATA +112 -0
  161. intentumdiff_python-0.0.1.dist-info/RECORD +165 -0
  162. intentumdiff_python-0.0.1.dist-info/WHEEL +4 -0
  163. intentumdiff_python-0.0.1.dist-info/entry_points.txt +80 -0
  164. intentumdiff_python-0.0.1.dist-info/licenses/LICENSE +21 -0
  165. intentumdiff_python-0.0.1.dist-info/sboms/intentumdiff-rust-core.cyclonedx.json +10968 -0
@@ -0,0 +1,1061 @@
1
+ """
2
+ intentumdiff.cli
3
+ ~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Command-line interface for IntentumDiff.
6
+
7
+ Usage
8
+ -----
9
+ intentumdiff git <repo> <file> [--old REF] [--new REF] [--format FORMAT] [--output FILE]
10
+ intentumdiff file <old-file> <new-file> [--format FORMAT] [--output FILE]
11
+ intentumdiff patch [PATCH_FILE] [--base BASE_FILE]
12
+ intentumdiff string <old> <new> [--lang LANG]
13
+ intentumdiff plugins List installed parser and renderer plugins
14
+
15
+ Formats: terminal (default), terminal-color, json, patch, html, llm
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ import sys
22
+ from typing import NoReturn
23
+
24
+ try: # rich-click is a runtime dependency, but this fallback keeps source-tree tests robust.
25
+ import rich_click as click
26
+ _CLICK_RUNTIME_AVAILABLE = True
27
+ except ModuleNotFoundError: # pragma: no cover - exercised only in minimal dev envs.
28
+ _CLICK_RUNTIME_AVAILABLE = False
29
+ click = None # type: ignore[assignment]
30
+
31
+
32
+ from intentumdiff import (
33
+ __version__,
34
+ )
35
+ from intentumdiff.cli._commands import ( # noqa: F401
36
+ _add_asset_diff_args,
37
+ _add_diagnostics_arg,
38
+ _add_diagnostics_db_arg,
39
+ _add_fuel_arg,
40
+ _add_guardrail_args,
41
+ _add_output_args,
42
+ _add_profile_phases_arg,
43
+ _add_resolve_references_arg,
44
+ _cmd_assets_diff,
45
+ _cmd_assets_git,
46
+ _cmd_cache_clear,
47
+ _cmd_cache_export,
48
+ _cmd_cache_inspect,
49
+ _cmd_cache_list,
50
+ _cmd_cache_stats,
51
+ _cmd_diagnostics_hotspots,
52
+ _cmd_diagnostics_query,
53
+ _cmd_diagnostics_summary,
54
+ _cmd_file,
55
+ _cmd_gist_diff,
56
+ _cmd_git,
57
+ _cmd_github_pr,
58
+ _cmd_guardrails_check,
59
+ _cmd_index,
60
+ _cmd_live_server,
61
+ _cmd_lsp_server,
62
+ _cmd_patch,
63
+ _cmd_plugins_add,
64
+ _cmd_plugins_install,
65
+ _cmd_plugins_list,
66
+ _cmd_plugins_remove,
67
+ _cmd_security_check,
68
+ _cmd_serve,
69
+ _cmd_string,
70
+ _cmd_watch,
71
+ _GitPositionalsAction,
72
+ )
73
+ from intentumdiff.cli._shared import ( # noqa: F401
74
+ _cmd_shell,
75
+ _err,
76
+ _parse_fuel,
77
+ _run_parsed_command,
78
+ _version_text,
79
+ _warn_if_unlimited_fuel,
80
+ )
81
+
82
+
83
+ def _build_parser() -> argparse.ArgumentParser:
84
+ parser = argparse.ArgumentParser(
85
+ prog="intentumdiff",
86
+ description=(
87
+ "Semantic code review: detect intent, moves, refactorings, and "
88
+ "style changes."
89
+ ),
90
+ )
91
+ parser.add_argument("--version", action="version", version=_version_text())
92
+ parser.add_argument(
93
+ "--no-banner",
94
+ action="store_true",
95
+ default=False,
96
+ help="Suppress the interactive IntentumDiff banner.",
97
+ )
98
+
99
+ sub = parser.add_subparsers(dest="command", metavar="COMMAND")
100
+ sub.required = True
101
+
102
+ shell_p = sub.add_parser(
103
+ "shell",
104
+ help="Start the interactive IntentumDiff command shell.",
105
+ description=(
106
+ "Start a lightweight IntentumDiff shell. Commands entered at the "
107
+ "prompt use the same parser and behavior as the normal CLI."
108
+ ),
109
+ )
110
+ shell_p.add_argument(
111
+ "--no-banner",
112
+ action="store_true",
113
+ default=argparse.SUPPRESS,
114
+ help="Start the shell without the IntentumDiff banner.",
115
+ )
116
+ shell_p.set_defaults(func=_cmd_shell)
117
+
118
+ # ── git ──────────────────────────────────────────────────────────────────
119
+ git_p = sub.add_parser("git", help="Diff a file between two git commits.")
120
+ git_p.set_defaults(repo=".", file=None)
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.",
126
+ )
127
+ 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(
141
+ "--staged", action="store_true", default=False,
142
+ help="Diff HEAD against the git index (staged files only).",
143
+ )
144
+ git_p.add_argument(
145
+ "--unpushed", action="store_true", default=False,
146
+ help="Diff the remote tracking branch against HEAD (commits not yet pushed).",
147
+ )
148
+ _add_output_args(git_p)
149
+ _add_fuel_arg(git_p)
150
+ _add_resolve_references_arg(git_p)
151
+ _add_diagnostics_arg(git_p)
152
+ _add_diagnostics_db_arg(git_p)
153
+ _add_profile_phases_arg(git_p)
154
+ _add_guardrail_args(git_p)
155
+ git_p.add_argument(
156
+ "--parallel",
157
+ nargs="?",
158
+ const=True,
159
+ type=int,
160
+ default=None,
161
+ metavar="N",
162
+ help=(
163
+ "Parallelise commit-wide diff across threads. "
164
+ "Omit N to use cpu_count(); pass N for an explicit worker count."
165
+ ),
166
+ )
167
+ git_p.set_defaults(func=_cmd_git)
168
+
169
+ # ── assets ─────────────────────────────────────────────────────────────
170
+ assets_p = sub.add_parser(
171
+ "assets",
172
+ help="Perceptual diffs for non-text assets.",
173
+ )
174
+ assets_sub = assets_p.add_subparsers(dest="assets_command", metavar="ACTION")
175
+ assets_sub.required = True
176
+
177
+ assets_diff_p = assets_sub.add_parser(
178
+ "diff",
179
+ help="Compare two image assets and generate perceptual artifacts.",
180
+ )
181
+ assets_diff_p.add_argument("--before", required=True, metavar="PATH")
182
+ assets_diff_p.add_argument("--after", required=True, metavar="PATH")
183
+ assets_diff_p.add_argument(
184
+ "--file-path",
185
+ default=None,
186
+ metavar="PATH",
187
+ help="Logical repository path to include in JSON output.",
188
+ )
189
+ _add_asset_diff_args(assets_diff_p)
190
+ assets_diff_p.set_defaults(func=_cmd_assets_diff)
191
+
192
+ assets_git_p = assets_sub.add_parser(
193
+ "git",
194
+ help="Discover changed image assets in git and generate perceptual diffs.",
195
+ )
196
+ assets_git_p.add_argument(
197
+ "--repo",
198
+ default=".",
199
+ metavar="PATH",
200
+ help="Repository path.",
201
+ )
202
+ assets_git_p.add_argument("--base", default=None, metavar="REF")
203
+ assets_git_p.add_argument(
204
+ "--head",
205
+ default="",
206
+ metavar="REF",
207
+ help="Head ref, or omit for working-tree changes.",
208
+ )
209
+ assets_git_p.add_argument(
210
+ "--staged",
211
+ action="store_true",
212
+ default=False,
213
+ help="Compare HEAD/base against the git index.",
214
+ )
215
+ assets_git_p.add_argument(
216
+ "--unpushed",
217
+ action="store_true",
218
+ default=False,
219
+ help="Compare the upstream tracking branch against HEAD.",
220
+ )
221
+ _add_asset_diff_args(assets_git_p)
222
+ assets_git_p.set_defaults(func=_cmd_assets_git)
223
+
224
+ # ── file ─────────────────────────────────────────────────────────────────
225
+ file_p = sub.add_parser("file", help="Diff two local files.")
226
+ file_p.add_argument("old_file", metavar="OLD", help="Path to the old file.")
227
+ file_p.add_argument("new_file", metavar="NEW", help="Path to the new file.")
228
+ _add_output_args(file_p)
229
+ _add_fuel_arg(file_p)
230
+ _add_resolve_references_arg(file_p)
231
+ _add_diagnostics_arg(file_p)
232
+ _add_diagnostics_db_arg(file_p)
233
+ _add_profile_phases_arg(file_p)
234
+ _add_guardrail_args(file_p)
235
+ file_p.add_argument(
236
+ "--stream",
237
+ action="store_true",
238
+ help="Yield changes as they are computed rather than waiting for the full diff.",
239
+ )
240
+ file_p.set_defaults(func=_cmd_file)
241
+
242
+ # ── patch ─────────────────────────────────────────────────────────────────
243
+ patch_p = sub.add_parser("patch", help="Diff from a unified diff patch (stdin or file).")
244
+ patch_p.add_argument("patch_file", nargs="?", default="-", metavar="PATCH",
245
+ help="Path to patch file, or '-' / omit to read from stdin.")
246
+ patch_p.add_argument("--base", metavar="BASE", default=None,
247
+ help="Path to the original file (needed to reconstruct context).")
248
+ _add_output_args(patch_p)
249
+ _add_fuel_arg(patch_p)
250
+ _add_resolve_references_arg(patch_p)
251
+ _add_diagnostics_arg(patch_p)
252
+ _add_diagnostics_db_arg(patch_p)
253
+ _add_profile_phases_arg(patch_p)
254
+ _add_guardrail_args(patch_p)
255
+ patch_p.set_defaults(func=_cmd_patch)
256
+
257
+ # ── string ────────────────────────────────────────────────────────────────
258
+ str_p = sub.add_parser("string", help="Diff two in-memory strings (useful for scripting).")
259
+ str_p.add_argument("old", metavar="OLD", help="Old source code string.")
260
+ str_p.add_argument("new", metavar="NEW", help="New source code string.")
261
+ str_p.add_argument("--lang", metavar="LANG", default=None,
262
+ help="Language hint (e.g. python, sql).")
263
+ _add_output_args(str_p)
264
+ _add_fuel_arg(str_p)
265
+ _add_resolve_references_arg(str_p)
266
+ _add_diagnostics_arg(str_p)
267
+ _add_diagnostics_db_arg(str_p)
268
+ _add_profile_phases_arg(str_p)
269
+ _add_guardrail_args(str_p)
270
+ str_p.set_defaults(func=_cmd_string)
271
+
272
+ github_pr_p = sub.add_parser(
273
+ "github-pr",
274
+ help="Parse a GitHub pull request URL into an IntentumDiff review target.",
275
+ )
276
+ github_pr_p.add_argument("url", metavar="URL", help="https://github.com/OWNER/REPO/pull/NUMBER")
277
+ github_pr_p.set_defaults(func=_cmd_github_pr)
278
+
279
+ gist_diff_p = sub.add_parser(
280
+ "gist-diff",
281
+ help="Parse a GitHub Gist URL into an IntentumDiff diff target.",
282
+ )
283
+ gist_diff_p.add_argument("url", metavar="URL", help="https://gist.github.com/OWNER/GIST_ID")
284
+ gist_diff_p.add_argument("--format", default="html", choices=("json", "html"))
285
+ gist_diff_p.set_defaults(func=_cmd_gist_diff)
286
+
287
+ guardrails_p = sub.add_parser(
288
+ "guardrails",
289
+ help="Check protected config guardrail policy.",
290
+ )
291
+ guardrails_sub = guardrails_p.add_subparsers(
292
+ dest="guardrails_cmd",
293
+ metavar="ACTION",
294
+ )
295
+ guardrails_sub.required = True
296
+ check_p = guardrails_sub.add_parser(
297
+ "check",
298
+ help="Run guardrail policy checks for a git diff.",
299
+ )
300
+ check_p.add_argument(
301
+ "repo",
302
+ nargs="?",
303
+ default=".",
304
+ help="Repository path to check.",
305
+ )
306
+ check_p.add_argument("--old", default="HEAD~1", metavar="REF")
307
+ check_p.add_argument("--new", default="HEAD", metavar="REF")
308
+ check_p.add_argument(
309
+ "--policy",
310
+ dest="guardrails_policy",
311
+ default=None,
312
+ metavar="PATH",
313
+ help="Use a specific intentumdiff.yaml policy file.",
314
+ )
315
+ check_p.add_argument(
316
+ "--strict",
317
+ action="store_true",
318
+ default=False,
319
+ help="Exit 2 when immutable guardrail violations are found.",
320
+ )
321
+ _add_fuel_arg(check_p)
322
+ check_p.add_argument(
323
+ "--format",
324
+ choices=("terminal", "json", "sarif"),
325
+ default="terminal",
326
+ help="Guardrail check report format.",
327
+ )
328
+ check_p.add_argument(
329
+ "--output",
330
+ metavar="FILE",
331
+ default=None,
332
+ help="Write guardrail check report to FILE.",
333
+ )
334
+ check_p.add_argument(
335
+ "--annotations",
336
+ choices=("github", "none"),
337
+ default="none",
338
+ help="Emit GitHub Actions annotations in addition to the report.",
339
+ )
340
+ check_p.set_defaults(func=_cmd_guardrails_check)
341
+
342
+ # ── plugins ───────────────────────────────────────────────────────────────
343
+ plugins_p = sub.add_parser(
344
+ "plugins",
345
+ help="Manage parser and renderer plugins.",
346
+ )
347
+ # Default to 'list' when called without a subcommand
348
+ plugins_p.set_defaults(func=_cmd_plugins_list, file="intentumdiff_plugins.yaml")
349
+ plugins_sub = plugins_p.add_subparsers(dest="plugins_cmd", metavar="ACTION")
350
+
351
+ # plugins list
352
+ pl_list = plugins_sub.add_parser("list", help="List installed plugins (default).")
353
+ pl_list.set_defaults(func=_cmd_plugins_list)
354
+
355
+ # plugins add
356
+ pl_add = plugins_sub.add_parser(
357
+ "add",
358
+ help="Download and install a plugin from the official org or a custom repo.",
359
+ )
360
+ pl_add.add_argument(
361
+ "plugin_name", metavar="NAME",
362
+ help="Short name (e.g. dbt) or full package name (intentumdiff-dbt).",
363
+ )
364
+ pl_add.add_argument(
365
+ "--ref", default="main", metavar="REF",
366
+ help="Git tag/branch/commit or PyPI version to install (default: main).",
367
+ )
368
+ pl_add.add_argument(
369
+ "--source", default="git", choices=["git", "pypi"],
370
+ help="Installation source: 'git' (default) or 'pypi'.",
371
+ )
372
+ pl_add.add_argument(
373
+ "--repo", default="", metavar="URL",
374
+ help="Custom git repo URL. Omit to use the official intentumdiff registry org.",
375
+ )
376
+ pl_add.add_argument(
377
+ "--file", default="intentumdiff_plugins.yaml", metavar="FILE",
378
+ help="Plugins manifest to update (default: intentumdiff_plugins.yaml).",
379
+ )
380
+ pl_add.add_argument(
381
+ "--no-save", dest="save", action="store_false",
382
+ help="Install without updating intentumdiff_plugins.yaml.",
383
+ )
384
+ pl_add.add_argument(
385
+ "--skip-verify", dest="skip_verify", action="store_true",
386
+ help="Skip Wasm checksum and capability checks (not recommended).",
387
+ )
388
+ pl_add.add_argument(
389
+ "--allow-source-plugin", dest="allow_source_plugin", action="store_true",
390
+ help="Allow installing from VCS/local/direct-URL sources (disables binary-only check).",
391
+ )
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
+ )
400
+ 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,
406
+ )
407
+
408
+ # plugins install
409
+ pl_install = plugins_sub.add_parser(
410
+ "install",
411
+ help="Install all plugins declared in intentumdiff_plugins.yaml.",
412
+ )
413
+ pl_install.add_argument(
414
+ "--file", default="intentumdiff_plugins.yaml", metavar="FILE",
415
+ help="Plugins manifest to read (default: intentumdiff_plugins.yaml).",
416
+ )
417
+ pl_install.add_argument(
418
+ "--upgrade", action="store_true",
419
+ help="Pass --upgrade to pip so already-installed plugins are updated.",
420
+ )
421
+ pl_install.add_argument(
422
+ "--skip-verify", dest="skip_verify", action="store_true",
423
+ help="Skip Wasm checksum and capability checks (not recommended).",
424
+ )
425
+ pl_install.add_argument(
426
+ "--allow-source-plugin", dest="allow_source_plugin", action="store_true",
427
+ help="Allow installing from VCS/local/direct-URL sources (disables binary-only check).",
428
+ )
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
+ )
437
+ pl_install.set_defaults(
438
+ skip_verify=False,
439
+ allow_source_plugin=False,
440
+ strict_registry=False,
441
+ func=_cmd_plugins_install,
442
+ )
443
+
444
+ # plugins remove
445
+ pl_remove = plugins_sub.add_parser(
446
+ "remove",
447
+ help="Uninstall a plugin and remove it from intentumdiff_plugins.yaml.",
448
+ )
449
+ pl_remove.add_argument(
450
+ "plugin_name", metavar="NAME",
451
+ help="Short name or full package name to uninstall.",
452
+ )
453
+ pl_remove.add_argument(
454
+ "--file", default="intentumdiff_plugins.yaml", metavar="FILE",
455
+ help="Plugins manifest to update (default: intentumdiff_plugins.yaml).",
456
+ )
457
+ pl_remove.add_argument(
458
+ "--no-save", dest="save", action="store_false",
459
+ help="Uninstall without updating intentumdiff_plugins.yaml.",
460
+ )
461
+ pl_remove.set_defaults(save=True, func=_cmd_plugins_remove)
462
+
463
+ # ── security-check ────────────────────────────────────────────────────────
464
+ sc_p = sub.add_parser(
465
+ "security-check",
466
+ help="Check installed packages against the OSV advisory database.",
467
+ description=(
468
+ "Queries the OSV (Open Source Vulnerabilities) API for known "
469
+ "vulnerabilities in installed packages. Results are cached for "
470
+ "24 hours.\n\n"
471
+ "By default this command reads from cache if it is fresh. Use "
472
+ "--refresh to force an immediate re-check — this is also the "
473
+ "documented way to unblock plugin loading after a failed advisory "
474
+ "check."
475
+ ),
476
+ )
477
+ sc_p.add_argument(
478
+ "--refresh",
479
+ action="store_true",
480
+ default=False,
481
+ help=(
482
+ "Bypass the 24-hour cache and force a fresh OSV fetch. "
483
+ "Use this to unblock plugin loading after a network failure "
484
+ "caused the advisory check to fail."
485
+ ),
486
+ )
487
+ sc_p.set_defaults(func=_cmd_security_check)
488
+
489
+ # ── index ─────────────────────────────────────────────────────────────
490
+ index_p = sub.add_parser(
491
+ "index",
492
+ help="Pre-index a git repository to warm the parse and symbol-index cache.",
493
+ description=(
494
+ "Walk every text file in the repository at the given ref, "
495
+ "parse each one, and store the results in the local cache "
496
+ "directory. Subsequent diff calls will be faster because the "
497
+ "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)."
501
+ ),
502
+ )
503
+ index_p.add_argument(
504
+ "repo",
505
+ nargs="?",
506
+ default=".",
507
+ metavar="REPO",
508
+ help="Path to the git repository to index (default: current directory).",
509
+ )
510
+ index_p.add_argument(
511
+ "--ref",
512
+ default="HEAD",
513
+ metavar="REF",
514
+ help="Git ref to index (default: HEAD).",
515
+ )
516
+ index_p.add_argument(
517
+ "--cache-path",
518
+ default=".intentumdiff-cache",
519
+ metavar="PATH",
520
+ dest="cache_path",
521
+ help="Cache directory (default: .intentumdiff-cache inside the repo).",
522
+ )
523
+ index_p.add_argument(
524
+ "--force",
525
+ action="store_true",
526
+ default=False,
527
+ help="Re-index even if a cached symbol index already exists for this commit.",
528
+ )
529
+ index_p.add_argument(
530
+ "--fuel",
531
+ type=_parse_fuel,
532
+ default=None,
533
+ metavar="N",
534
+ help="Wasm fuel budget per parser call. Use -1, 'inf', or 'infinite' to remove the cap.",
535
+ )
536
+ index_p.add_argument(
537
+ "--lsp",
538
+ action="store_true",
539
+ default=False,
540
+ help=(
541
+ "Enable LSP type enrichment via a two-pass index. "
542
+ "Pass 1 detects languages; Pass 2 starts the required servers "
543
+ "(from lsp_servers.json in the repo root, or built-in defaults) "
544
+ "and re-indexes with type information attached."
545
+ ),
546
+ )
547
+ index_p.add_argument(
548
+ "--trust-repo-lsp-config",
549
+ dest="trust_repo_lsp_config",
550
+ action="store_true",
551
+ default=False,
552
+ help=(
553
+ "Allow custom LSP server commands defined in lsp_servers.json "
554
+ "inside the repository root. Without this flag, any "
555
+ "repo-local lsp_servers.json is ignored and only built-in "
556
+ "known-good server specs are used. Use this flag only in "
557
+ "repositories you control."
558
+ ),
559
+ )
560
+ index_p.set_defaults(func=_cmd_index)
561
+
562
+ # ── cache ─────────────────────────────────────────────────────────────
563
+ cache_p = sub.add_parser(
564
+ "cache",
565
+ help="Inspect or manage the local cache database.",
566
+ )
567
+ cache_p.set_defaults(cache_path=".intentumdiff-cache")
568
+ cache_sub = cache_p.add_subparsers(dest="cache_command", metavar="SUBCOMMAND")
569
+ cache_sub.required = True
570
+
571
+ _cache_path_arg = dict(
572
+ dest="cache_path",
573
+ default=".intentumdiff-cache",
574
+ metavar="PATH",
575
+ help="Cache directory (default: .intentumdiff-cache).",
576
+ )
577
+
578
+ # cache stats
579
+ cs = cache_sub.add_parser("stats", help="Show cache size, row counts, and hit/miss metrics.")
580
+ cs.add_argument("--cache-path", **_cache_path_arg)
581
+ cs.set_defaults(func=_cmd_cache_stats)
582
+
583
+ # cache clear
584
+ cc = cache_sub.add_parser("clear", help="Delete cache entries.")
585
+ cc.add_argument("--cache-path", **_cache_path_arg)
586
+ cc.add_argument("--parse", action="store_true", help="Clear the parse-tree cache.")
587
+ cc.add_argument("--diff", action="store_true", help="Clear the diff-result cache.")
588
+ cc.add_argument("--index", action="store_true", help="Clear the symbol-index cache.")
589
+ cc.add_argument(
590
+ "--all",
591
+ action="store_true",
592
+ help="Clear all cache tables (equivalent to --parse --diff --index).",
593
+ )
594
+ cc.set_defaults(func=_cmd_cache_clear)
595
+
596
+ # cache list
597
+ cl = cache_sub.add_parser("list", help="List cache entries with optional filters.")
598
+ cl.add_argument("--cache-path", **_cache_path_arg)
599
+ cl.add_argument(
600
+ "--table", choices=["parse", "diff", "index", "hover"],
601
+ metavar="TABLE", default=None,
602
+ help="Restrict to one table: parse, diff, index, hover.",
603
+ )
604
+ cl.add_argument("--language", metavar="LANG", default=None,
605
+ help="Filter diff_cache by language (e.g. python).")
606
+ cl.add_argument("--file", metavar="GLOB", default=None,
607
+ help="Filter diff_cache filenames by glob pattern (e.g. '*.py').")
608
+ cl.add_argument("--since", metavar="YYYY-MM-DD", default=None,
609
+ help="Only entries created on or after this date.")
610
+ cl.add_argument("--before", metavar="YYYY-MM-DD", default=None,
611
+ help="Only entries created on or before this date.")
612
+ cl.add_argument("--min-size", type=int, metavar="BYTES", default=None,
613
+ dest="min_size", help="Minimum compressed size in bytes.")
614
+ cl.add_argument("--max-size", type=int, metavar="BYTES", default=None,
615
+ dest="max_size", help="Maximum compressed size in bytes.")
616
+ cl.add_argument("--limit", type=int, default=50, metavar="N",
617
+ help="Maximum rows per table (default: 50).")
618
+ cl.add_argument("--verbose", action="store_true",
619
+ help="Show full key and all metadata columns.")
620
+ cl.set_defaults(func=_cmd_cache_list)
621
+
622
+ # cache inspect
623
+ ci = cache_sub.add_parser(
624
+ "inspect",
625
+ help="Show metadata and payload summary for one cache entry.",
626
+ )
627
+ ci.add_argument("key", metavar="KEY",
628
+ help="Full 64-char key or unambiguous prefix.")
629
+ ci.add_argument("--cache-path", **_cache_path_arg)
630
+ ci.add_argument(
631
+ "--table", choices=["parse", "diff", "index", "hover"],
632
+ metavar="TABLE", default=None,
633
+ help="Restrict key lookup to one table.",
634
+ )
635
+ ci.set_defaults(func=_cmd_cache_inspect)
636
+
637
+ # cache export
638
+ ce = cache_sub.add_parser("export", help="Export cache entries as NDJSON.")
639
+ ce.add_argument("--cache-path", **_cache_path_arg)
640
+ ce.add_argument(
641
+ "--table",
642
+ choices=["parse", "diff", "index", "hover", "all"],
643
+ default="all", metavar="TABLE",
644
+ help="Table to export: parse, diff, index, hover, or all (default).",
645
+ )
646
+ ce.add_argument("--output", metavar="FILE", default=None,
647
+ help="Output file path. Defaults to stdout.")
648
+ ce.set_defaults(func=_cmd_cache_export)
649
+
650
+ # ── diagnostics ───────────────────────────────────────────────────────
651
+ diagnostics_p = sub.add_parser(
652
+ "diagnostics",
653
+ help="Query local DuckDB fuel diagnostics.",
654
+ description=(
655
+ "Inspect normalized parser fuel telemetry recorded with "
656
+ "--diagnostics-db. The VS Code UI keeps recent workspace history; "
657
+ "this command queries durable local DuckDB history."
658
+ ),
659
+ )
660
+ diagnostics_sub = diagnostics_p.add_subparsers(dest="diagnostics_command", metavar="SUBCOMMAND")
661
+ diagnostics_sub.required = True
662
+ _diagnostics_db_arg = dict(
663
+ dest="db",
664
+ default=".intentumdiff/diagnostics.duckdb",
665
+ metavar="FILE",
666
+ help="Diagnostics DuckDB path (default: .intentumdiff/diagnostics.duckdb).",
667
+ )
668
+
669
+ diag_summary = diagnostics_sub.add_parser(
670
+ "summary",
671
+ help="Show recent runs and aggregate fuel by language.",
672
+ )
673
+ diag_summary.add_argument("--db", **_diagnostics_db_arg)
674
+ diag_summary.add_argument("--limit", type=int, default=10, metavar="N")
675
+ diag_summary.add_argument("--format", choices=("terminal", "json"), default="terminal")
676
+ diag_summary.add_argument("--output", metavar="FILE", default=None)
677
+ diag_summary.set_defaults(func=_cmd_diagnostics_summary)
678
+
679
+ diag_hotspots = diagnostics_sub.add_parser(
680
+ "hotspots",
681
+ help="Show highest normalized parser fuel hotspots.",
682
+ )
683
+ diag_hotspots.add_argument("--db", **_diagnostics_db_arg)
684
+ diag_hotspots.add_argument("--limit", type=int, default=20, metavar="N")
685
+ diag_hotspots.add_argument("--format", choices=("terminal", "json"), default="terminal")
686
+ diag_hotspots.add_argument("--output", metavar="FILE", default=None)
687
+ diag_hotspots.set_defaults(func=_cmd_diagnostics_hotspots)
688
+
689
+ diag_query = diagnostics_sub.add_parser(
690
+ "query",
691
+ help="Run a read-only SQL query against diagnostics tables.",
692
+ )
693
+ diag_query.add_argument("sql", metavar="SQL")
694
+ diag_query.add_argument("--db", **_diagnostics_db_arg)
695
+ diag_query.add_argument("--format", choices=("terminal", "json"), default="json")
696
+ diag_query.add_argument("--output", metavar="FILE", default=None)
697
+ diag_query.set_defaults(func=_cmd_diagnostics_query)
698
+
699
+ # ── watch ─────────────────────────────────────────────────────────────────
700
+ watch_p = sub.add_parser(
701
+ "watch",
702
+ help="Watch files/directories and show a semantic diff on each save.",
703
+ description=(
704
+ "Re-diffs each changed file against its last committed state "
705
+ "(WorkingTreeSource) whenever the file is modified on disk. "
706
+ "Uses OS-native file-system events (watchdog). "
707
+ "Press Ctrl+C to stop."
708
+ ),
709
+ )
710
+ watch_p.add_argument(
711
+ "paths",
712
+ nargs="*",
713
+ default=["."],
714
+ metavar="PATH",
715
+ help="Files or directories to watch (default: current directory).",
716
+ )
717
+ watch_p.add_argument(
718
+ "--ref",
719
+ default="HEAD",
720
+ metavar="REF",
721
+ help="Git ref to compare the working tree against (default: HEAD).",
722
+ )
723
+ watch_p.add_argument(
724
+ "--debounce",
725
+ type=float,
726
+ default=0.3,
727
+ metavar="SEC",
728
+ help="Debounce delay in seconds — coalesces rapid editor saves (default: 0.3).",
729
+ )
730
+ _add_output_args(watch_p)
731
+ _add_fuel_arg(watch_p)
732
+ # ── LiveServer options ────────────────────────────────────────────────
733
+ live_group = watch_p.add_argument_group(
734
+ "live server",
735
+ "Options for the persistent keystroke-level LiveServer (optional).",
736
+ )
737
+ live_group.add_argument(
738
+ "--live",
739
+ action="store_true",
740
+ default=False,
741
+ help=(
742
+ "Also start a LiveServer socket alongside the file watcher. "
743
+ "Prints the socket address to stdout."
744
+ ),
745
+ )
746
+ live_group.add_argument(
747
+ "--live-stdin",
748
+ action="store_true",
749
+ default=False,
750
+ help=(
751
+ "Run in LiveServer stdin mode: read JSON requests from stdin and "
752
+ "write responses to stdout. No file watcher is started. "
753
+ "Useful when a socket is unavailable."
754
+ ),
755
+ )
756
+ live_group.add_argument(
757
+ "--live-socket",
758
+ metavar="PATH",
759
+ default=None,
760
+ help="Custom Unix-socket path for the LiveServer (default: auto-generated).",
761
+ )
762
+ live_group.add_argument(
763
+ "--live-debounce",
764
+ type=float,
765
+ default=0.15,
766
+ metavar="SEC",
767
+ help="LiveServer debounce delay in seconds (default: 0.15).",
768
+ )
769
+ live_group.add_argument(
770
+ "--live-stream",
771
+ action="store_true",
772
+ default=False,
773
+ help=(
774
+ "Send progressive ChangeStreamEvent responses instead of a single "
775
+ "SemanticDiff per request."
776
+ ),
777
+ )
778
+ watch_p.set_defaults(func=_cmd_watch)
779
+
780
+ # -- live-server --------------------------------------------------------
781
+ live_p = sub.add_parser(
782
+ "live-server",
783
+ help="Start the editor-ready LiveServer JSON protocol.",
784
+ description=(
785
+ "Run IntentumDiff as a persistent JSON LiveServer endpoint. "
786
+ "Stdio is the default transport and writes JSON protocol messages "
787
+ "only to stdout."
788
+ ),
789
+ )
790
+ live_p.add_argument(
791
+ "repo",
792
+ nargs="?",
793
+ default=".",
794
+ help="Repository root for repository-relative live buffer paths.",
795
+ )
796
+ live_transport = live_p.add_mutually_exclusive_group()
797
+ live_transport.add_argument(
798
+ "--stdio",
799
+ action="store_true",
800
+ default=False,
801
+ help="Use stdin/stdout transport (default).",
802
+ )
803
+ live_transport.add_argument(
804
+ "--socket",
805
+ nargs="?",
806
+ const="",
807
+ default=None,
808
+ metavar="PATH",
809
+ help="Listen on a Unix socket or Windows named pipe; omit PATH to auto-generate.",
810
+ )
811
+ live_p.add_argument(
812
+ "--ref",
813
+ default="HEAD",
814
+ metavar="REF",
815
+ help="Default git ref to compare live buffers against (default: HEAD).",
816
+ )
817
+ live_p.add_argument(
818
+ "--debounce",
819
+ type=float,
820
+ default=0.15,
821
+ metavar="SEC",
822
+ help="Keystroke debounce delay in seconds (default: 0.15).",
823
+ )
824
+ live_p.add_argument(
825
+ "--stream",
826
+ action="store_true",
827
+ default=False,
828
+ help="Stream progressive semantic events by default for diff requests.",
829
+ )
830
+ _add_fuel_arg(live_p)
831
+ live_p.set_defaults(func=_cmd_live_server)
832
+
833
+ # ── lsp-server ────────────────────────────────────────────────────────────
834
+ lsp_p = sub.add_parser(
835
+ "lsp-server",
836
+ help="Start a pygls Language Server (stdio or TCP) for editor integration.",
837
+ description=(
838
+ "Run IntentumDiff as an LSP server backed by pygls. "
839
+ "Editors connect via stdio (default) or TCP, and receive semantic "
840
+ "diagnostics and code-lens decorations as you type. "
841
+ "Requires: pip install 'intentumdiff[lsp-server]'"
842
+ ),
843
+ )
844
+ _transport_group = lsp_p.add_mutually_exclusive_group()
845
+ _transport_group.add_argument(
846
+ "--stdio",
847
+ action="store_true",
848
+ default=False,
849
+ help="Use stdin/stdout transport (default when neither --stdio nor --tcp is given).",
850
+ )
851
+ _transport_group.add_argument(
852
+ "--tcp",
853
+ type=int,
854
+ metavar="PORT",
855
+ default=None,
856
+ help="Listen on TCP localhost:PORT instead of stdio.",
857
+ )
858
+ lsp_p.add_argument(
859
+ "--ref",
860
+ default="HEAD",
861
+ metavar="REF",
862
+ help="Git ref to compare live buffers against (default: HEAD).",
863
+ )
864
+ lsp_p.add_argument(
865
+ "--debounce",
866
+ type=float,
867
+ default=0.15,
868
+ metavar="SEC",
869
+ help="Keystroke debounce delay in seconds (default: 0.15).",
870
+ )
871
+ _add_fuel_arg(lsp_p)
872
+ lsp_p.add_argument(
873
+ "--cache-path",
874
+ metavar="DIR",
875
+ default=None,
876
+ help="Directory for the diff cache (optional).",
877
+ )
878
+ lsp_p.set_defaults(func=_cmd_lsp_server)
879
+
880
+ # ── serve ─────────────────────────────────────────────────────────────
881
+ serve_p = sub.add_parser(
882
+ "serve",
883
+ help="Start the HTTP diff playground server.",
884
+ description=(
885
+ "Start a local HTTP server exposing POST /diff "
886
+ "(JSON body: {old, new, language}) → SemanticDiff JSON, "
887
+ "plus a Monaco-editor web UI at http://HOST:PORT/."
888
+ ),
889
+ )
890
+ serve_p.add_argument(
891
+ "--host",
892
+ default="127.0.0.1",
893
+ metavar="HOST",
894
+ help="Host to bind (default: 127.0.0.1).",
895
+ )
896
+ serve_p.add_argument(
897
+ "--port",
898
+ type=int,
899
+ default=7234,
900
+ metavar="PORT",
901
+ help="Port to bind (default: 7234).",
902
+ )
903
+ _add_fuel_arg(serve_p)
904
+ serve_p.add_argument(
905
+ "--cache-path",
906
+ metavar="DIR",
907
+ default=None,
908
+ help="Directory for the diff cache (optional).",
909
+ )
910
+ serve_p.add_argument(
911
+ "--cors-origins",
912
+ dest="cors_origins",
913
+ metavar="ORIGIN",
914
+ nargs="+",
915
+ default=None,
916
+ help=(
917
+ "Allowed CORS origins (e.g. http://localhost:3000). "
918
+ "When omitted, no CORS headers are emitted. "
919
+ "Use with care — do not pass '*' in production."
920
+ ),
921
+ )
922
+ serve_p.add_argument(
923
+ "--allow-remote",
924
+ dest="allow_remote",
925
+ action="store_true",
926
+ default=False,
927
+ help=(
928
+ "Allow binding to a non-loopback address. "
929
+ "Required when --host is not 127.0.0.1 or ::1. "
930
+ "Use only when you understand the exposure."
931
+ ),
932
+ )
933
+ serve_p.set_defaults(func=_cmd_serve)
934
+
935
+ return parser
936
+
937
+
938
+ # ---------------------------------------------------------------------------
939
+ # Entry point
940
+ # ---------------------------------------------------------------------------
941
+
942
+
943
+ _CLICK_CONTEXT_SETTINGS = {
944
+ "help_option_names": [],
945
+ "ignore_unknown_options": True,
946
+ "allow_extra_args": True,
947
+ }
948
+
949
+
950
+ if _CLICK_RUNTIME_AVAILABLE:
951
+
952
+ def _click_command(command: str, *, help_text: str) -> click.Command:
953
+ @click.command(
954
+ name=command,
955
+ help=help_text,
956
+ context_settings=_CLICK_CONTEXT_SETTINGS,
957
+ )
958
+ @click.pass_context
959
+ def _delegate(ctx: click.Context) -> None:
960
+ parser = _build_parser()
961
+ words = [command, *ctx.args]
962
+ args = parser.parse_args(words)
963
+ parent_no_banner = bool((ctx.obj or {}).get("no_banner"))
964
+ if parent_no_banner:
965
+ args.no_banner = True
966
+ args._argv = words
967
+ _run_parsed_command(args)
968
+
969
+ return _delegate
970
+
971
+
972
+ @click.group(
973
+ context_settings={"help_option_names": ["-h", "--help"]},
974
+ invoke_without_command=False,
975
+ help=(
976
+ "Semantic code review: detect intent, moves, refactorings, "
977
+ "style changes, and guardrail risks."
978
+ ),
979
+ )
980
+ @click.version_option(__version__, "--version", message="IntentumDiff %(version)s")
981
+ @click.option(
982
+ "--no-banner",
983
+ is_flag=True,
984
+ default=False,
985
+ help="Suppress the interactive IntentumDiff banner.",
986
+ )
987
+ @click.pass_context
988
+ def _click_cli(ctx: click.Context, no_banner: bool) -> None:
989
+ ctx.ensure_object(dict)
990
+ ctx.obj["no_banner"] = no_banner
991
+
992
+
993
+ for _name, _help in [
994
+ ("shell", "Start the interactive IntentumDiff command shell."),
995
+ ("git", "Diff files or commits in a git repository."),
996
+ ("assets", "Perceptual diffs for non-text assets."),
997
+ ("file", "Diff two local files."),
998
+ ("patch", "Diff from a unified diff patch."),
999
+ ("string", "Diff two in-memory strings."),
1000
+ ("github-pr", "Parse a GitHub pull request URL into a review target."),
1001
+ ("gist-diff", "Parse a GitHub Gist URL into a diff target."),
1002
+ ("guardrails", "Check protected config guardrail policy."),
1003
+ ("plugins", "Manage parser and renderer plugins."),
1004
+ ("security-check", "Check installed packages against OSV advisories."),
1005
+ ("index", "Pre-index a git repository to warm caches."),
1006
+ ("cache", "Inspect or manage the local cache database."),
1007
+ ("diagnostics", "Query local DuckDB fuel diagnostics."),
1008
+ ("watch", "Watch files/directories and show semantic diffs on save."),
1009
+ ("live-server", "Start the editor-ready LiveServer JSON protocol."),
1010
+ ("lsp-server", "Start the pygls Language Server for editor integration."),
1011
+ ("serve", "Start the HTTP diff playground server."),
1012
+ ]:
1013
+ _click_cli.add_command(_click_command(_name, help_text=_help))
1014
+
1015
+ def _legacy_click_main(argv: list[str] | None = None) -> NoReturn:
1016
+ normalized = _normalize_argv(argv)
1017
+ try:
1018
+ _click_cli.main(
1019
+ args=normalized,
1020
+ prog_name="intentumdiff",
1021
+ standalone_mode=False,
1022
+ obj={},
1023
+ )
1024
+ sys.exit(0)
1025
+ except KeyboardInterrupt:
1026
+ sys.exit(130)
1027
+ except click.ClickException as exc:
1028
+ exc.show()
1029
+ sys.exit(exc.exit_code)
1030
+ except click.exceptions.Exit as exc:
1031
+ sys.exit(exc.exit_code)
1032
+ except Exception as exc: # noqa: BLE001
1033
+ _err.print(f"[red]Error:[/red] {exc}")
1034
+ sys.exit(1)
1035
+ else:
1036
+
1037
+ def _legacy_click_main(argv: list[str] | None = None) -> NoReturn:
1038
+ parser = _build_parser()
1039
+ normalized = _normalize_argv(argv)
1040
+ try:
1041
+ args = parser.parse_args(normalized)
1042
+ args._argv = normalized
1043
+ _run_parsed_command(args, show_banner=True)
1044
+ sys.exit(0)
1045
+ except KeyboardInterrupt:
1046
+ sys.exit(130)
1047
+ except argparse.ArgumentError as exc:
1048
+ _err.print(f"[red]Error:[/red] {exc}")
1049
+ sys.exit(2)
1050
+ except Exception as exc: # noqa: BLE001
1051
+ _err.print(f"[red]Error:[/red] {exc}")
1052
+ sys.exit(1)
1053
+
1054
+
1055
+ def _normalize_argv(argv: list[str] | None) -> list[str] | None:
1056
+ raw = sys.argv[1:] if argv is None else list(argv)
1057
+ if len(raw) >= 2 and raw[0] == "git" and raw[1] == "assets":
1058
+ return ["assets", "git", *raw[2:]]
1059
+ return raw
1060
+
1061
+