intentumdiff-python 0.0.1__py3-none-manylinux_2_39_x86_64.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.so +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,99 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://intentumdiff.dev/schemas/registry.schema.json",
4
+ "title": "IntentumDiff plugin registry manifest",
5
+ "description": "Schema for the official plugin registry (buchochelliq-labs/intentumdiff-registry/registry.yaml) that `intentumdiff.plugins.hub` fetches. The registry is the root of trust: adding a plugin is a PR whose CI vets it against this schema plus checksum/capability/provenance verification (#95). The known fields mirror the RegistryEntry the client already parses; `trust_tier`, `capabilities`, `abi_target` (#94), and `provenance_manifest_ref` (#89) formalise the trust/compat surface.",
6
+ "type": "object",
7
+ "required": ["version", "plugins"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "version": {
11
+ "type": "integer",
12
+ "minimum": 1,
13
+ "description": "Registry schema version. 1 is the current contract."
14
+ },
15
+ "plugins": {
16
+ "type": "object",
17
+ "description": "Plugins keyed by their package-safe registry name (matches the RegistryEntry name).",
18
+ "propertyNames": { "$ref": "#/$defs/plugin_name" },
19
+ "additionalProperties": { "$ref": "#/$defs/entry" }
20
+ }
21
+ },
22
+ "$defs": {
23
+ "plugin_name": {
24
+ "type": "string",
25
+ "pattern": "^(?:intentumdiff-)?[A-Za-z0-9][A-Za-z0-9._-]{0,127}$",
26
+ "description": "Package-safe plugin name (mirrors _PLUGIN_NAME_RE in hub.py); never a URL, path, or requirement expression."
27
+ },
28
+ "sha256": {
29
+ "type": "string",
30
+ "pattern": "^[a-f0-9]{64}$",
31
+ "description": "Lowercase hex SHA-256 digest."
32
+ },
33
+ "dep_hash": {
34
+ "type": "string",
35
+ "pattern": "^sha256:[a-f0-9]{64}$",
36
+ "description": "A pip --require-hashes value: 'sha256:' + lowercase hex digest."
37
+ },
38
+ "entry": {
39
+ "type": "object",
40
+ "additionalProperties": false,
41
+ "description": "One plugin's registry metadata. All fields are optional — the plugin name is the mapping key. Trust is asserted here: an entry with wasm_checksums (and trust_tier 'official') installs verified; an entry without warns as unverified.",
42
+ "properties": {
43
+ "source": {
44
+ "enum": ["git", "pypi"],
45
+ "default": "git",
46
+ "description": "Install source. git: tag/branch/commit ref. pypi: version string."
47
+ },
48
+ "ref": {
49
+ "type": "string",
50
+ "description": "git: tag/branch/commit SHA (default 'main'). pypi: version (e.g. '1.2.3'); empty = latest."
51
+ },
52
+ "repo": {
53
+ "type": "string",
54
+ "description": "Custom git repo URL (git source only). Empty = the official org URL is derived from the name (which also makes is_official true)."
55
+ },
56
+ "description": {
57
+ "type": "string",
58
+ "description": "Human-readable one-line summary for the discovery catalog."
59
+ },
60
+ "wasm_checksums": {
61
+ "type": "object",
62
+ "description": "Expected SHA-256 of each bundled .wasm, keyed by filename. Verified on every install. Absent = unverified (install warns).",
63
+ "propertyNames": { "pattern": "^[A-Za-z0-9._-]+\\.wasm$" },
64
+ "additionalProperties": { "$ref": "#/$defs/sha256" }
65
+ },
66
+ "dep_hashes": {
67
+ "type": "object",
68
+ "description": "Approved dependency hashes for plugins that cannot be fully self-contained, keyed by 'package==version'. Passed to pip as --require-hashes; the main package wheel must be included.",
69
+ "propertyNames": { "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*==[^=\\s]+$" },
70
+ "additionalProperties": { "$ref": "#/$defs/dep_hash" }
71
+ },
72
+ "allowed_dependencies": {
73
+ "type": "array",
74
+ "description": "Reviewed package names (no version) that may appear in dep_hashes besides the main plugin package.",
75
+ "items": { "type": "string" }
76
+ },
77
+ "trust_tier": {
78
+ "enum": ["official", "community"],
79
+ "default": "official",
80
+ "description": "official = org-built/scanned, checksums present, installs verified. community = listed but unverified; install warns. Wired to hub.py's is_official / checksum-present-or-warn logic (#95)."
81
+ },
82
+ "capabilities": {
83
+ "type": "array",
84
+ "description": "Declared plugin capabilities (e.g. the WIT interfaces implemented), scanned at vetting time.",
85
+ "items": { "type": "string" },
86
+ "uniqueItems": true
87
+ },
88
+ "abi_target": {
89
+ "type": "string",
90
+ "description": "The plugin contract / host-utils version the plugin implements (#94). The host refuses a plugin whose abi_target is incompatible with the engine's contract version — caught at resolve time, not instantiation."
91
+ },
92
+ "provenance_manifest_ref": {
93
+ "type": "string",
94
+ "description": "Reference to the plugin's Wasm provenance manifest (#89): filename -> SHA-256 + source commit for every bundled artifact, so downstream consumers can verify provenance."
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
@@ -0,0 +1,280 @@
1
+ """Validate the plugin registry manifest against its published schema (#95).
2
+
3
+ The JSON Schema (``registry.schema.json``, packaged alongside this module) is the documented
4
+ contract. This module is its dependency-free ENFORCEMENT: :func:`validate_registry` checks the
5
+ security-load-bearing subset (required top-level shape, name/checksum/dep-hash patterns, the
6
+ trust-tier and source enums, no unknown fields) so the #95 CI vetting pipeline can block a
7
+ malformed or untrusted registry entry BEFORE it is published — the registry is the root of
8
+ trust. Stdlib-only (no ``jsonschema`` dependency), matching the thin-binding rule.
9
+
10
+ Returns a list of human-readable error strings (empty == valid) rather than raising, so a
11
+ vetting run can report every problem in one pass.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import re
18
+ from importlib import resources
19
+ from typing import Any
20
+
21
+ _NAME_RE = re.compile(r"^(?:intentumdiff-)?[A-Za-z0-9][A-Za-z0-9._-]{0,127}$")
22
+ _WASM_FILE_RE = re.compile(r"^[A-Za-z0-9._-]+\.wasm$")
23
+ _SHA256_RE = re.compile(r"^[a-f0-9]{64}$")
24
+ _DEP_HASH_RE = re.compile(r"^sha256:[a-f0-9]{64}$")
25
+ _DEP_KEY_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*==[^=\s]+$")
26
+
27
+ _SOURCE_VALUES = frozenset({"git", "pypi"})
28
+ _TRUST_TIERS = frozenset({"official", "community"})
29
+
30
+ #: The plugin-contract ABI version this host implements. Mirrors ``package
31
+ #: intentdiff:plugin@X`` in ``plugins/wit/plugin.wit``; the drift-guard test
32
+ #: ``test_host_contract_version_matches_the_wit`` pins them together so a WIT bump forces a
33
+ #: conscious host bump (#94: the host must know which contract version it speaks).
34
+ HOST_CONTRACT_VERSION = "1.0.0"
35
+
36
+ _VERSION_RE = re.compile(r"^(\d+)\.(\d+)\.(\d+)$")
37
+
38
+
39
+ def _parse_version(value: str) -> tuple[int, int, int] | None:
40
+ match = _VERSION_RE.match(value.strip())
41
+ if match is None:
42
+ return None
43
+ return (int(match.group(1)), int(match.group(2)), int(match.group(3)))
44
+
45
+
46
+ def abi_compatible(target: str, host: str = HOST_CONTRACT_VERSION) -> bool:
47
+ """Whether a plugin built against contract *target* can run on *host* (#94).
48
+
49
+ Semver contract compatibility: same MAJOR (a major bump is a breaking WIT change) and the
50
+ host's MINOR is at least the target's — minor bumps are additive, so a newer host still
51
+ serves an older plugin, but a host older than the plugin's minor lacks the WIT features the
52
+ plugin was built against. PATCH is interface-irrelevant. A malformed version (either side)
53
+ is treated as INCOMPATIBLE — fail closed rather than load an unknowable ABI.
54
+ """
55
+ parsed_target = _parse_version(target)
56
+ parsed_host = _parse_version(host)
57
+ if parsed_target is None or parsed_host is None:
58
+ return False
59
+ return parsed_target[0] == parsed_host[0] and parsed_target[1] <= parsed_host[1]
60
+
61
+ _ENTRY_FIELDS = frozenset(
62
+ {
63
+ "source",
64
+ "ref",
65
+ "repo",
66
+ "description",
67
+ "wasm_checksums",
68
+ "dep_hashes",
69
+ "allowed_dependencies",
70
+ "trust_tier",
71
+ "capabilities",
72
+ "abi_target",
73
+ "provenance_manifest_ref",
74
+ }
75
+ )
76
+ _TOP_LEVEL_FIELDS = frozenset({"version", "plugins"})
77
+
78
+
79
+ def load_schema() -> dict[str, Any]:
80
+ """Return the packaged registry JSON Schema."""
81
+ text = resources.files("intentumdiff.plugins").joinpath("registry.schema.json").read_text(
82
+ encoding="utf-8"
83
+ )
84
+ return json.loads(text)
85
+
86
+
87
+ def _validate_entry(name: str, entry: Any, errors: list[str]) -> None:
88
+ where = f"plugins[{name!r}]"
89
+ if not isinstance(entry, dict):
90
+ errors.append(f"{where}: entry must be a mapping")
91
+ return
92
+
93
+ unknown = set(entry) - _ENTRY_FIELDS
94
+ if unknown:
95
+ errors.append(f"{where}: unknown field(s): {', '.join(sorted(unknown))}")
96
+
97
+ source = entry.get("source", "git")
98
+ if source not in _SOURCE_VALUES:
99
+ errors.append(f"{where}.source: {source!r} not in {sorted(_SOURCE_VALUES)}")
100
+
101
+ trust = entry.get("trust_tier", "official")
102
+ if trust not in _TRUST_TIERS:
103
+ errors.append(f"{where}.trust_tier: {trust!r} not in {sorted(_TRUST_TIERS)}")
104
+
105
+ for str_field in ("ref", "repo", "description", "abi_target", "provenance_manifest_ref"):
106
+ if str_field in entry and not isinstance(entry[str_field], str):
107
+ errors.append(f"{where}.{str_field}: must be a string")
108
+
109
+ checksums = entry.get("wasm_checksums", {})
110
+ if not isinstance(checksums, dict):
111
+ errors.append(f"{where}.wasm_checksums: must be a mapping")
112
+ else:
113
+ for fname, digest in checksums.items():
114
+ if not _WASM_FILE_RE.match(str(fname)):
115
+ errors.append(f"{where}.wasm_checksums: {fname!r} is not a .wasm filename")
116
+ if not (isinstance(digest, str) and _SHA256_RE.match(digest)):
117
+ errors.append(f"{where}.wasm_checksums[{fname!r}]: not a lowercase SHA-256 hex")
118
+
119
+ dep_hashes = entry.get("dep_hashes", {})
120
+ if not isinstance(dep_hashes, dict):
121
+ errors.append(f"{where}.dep_hashes: must be a mapping")
122
+ else:
123
+ for key, value in dep_hashes.items():
124
+ if not _DEP_KEY_RE.match(str(key)):
125
+ errors.append(f"{where}.dep_hashes: {key!r} is not 'package==version'")
126
+ if not (isinstance(value, str) and _DEP_HASH_RE.match(value)):
127
+ errors.append(f"{where}.dep_hashes[{key!r}]: not 'sha256:<hex>'")
128
+
129
+ for list_field in ("allowed_dependencies", "capabilities"):
130
+ if list_field in entry:
131
+ value = entry[list_field]
132
+ if not (isinstance(value, list) and all(isinstance(i, str) for i in value)):
133
+ errors.append(f"{where}.{list_field}: must be a list of strings")
134
+
135
+
136
+ def validate_registry(data: Any) -> list[str]:
137
+ """Return every schema violation in *data* (empty list == a valid registry manifest)."""
138
+ errors: list[str] = []
139
+ if not isinstance(data, dict):
140
+ return ["registry: top level must be a mapping"]
141
+
142
+ unknown = set(data) - _TOP_LEVEL_FIELDS
143
+ if unknown:
144
+ errors.append(f"registry: unknown top-level field(s): {', '.join(sorted(unknown))}")
145
+
146
+ version = data.get("version")
147
+ if not isinstance(version, int) or isinstance(version, bool) or version < 1:
148
+ errors.append("registry.version: required integer >= 1")
149
+
150
+ plugins = data.get("plugins")
151
+ if not isinstance(plugins, dict):
152
+ errors.append("registry.plugins: required mapping of name -> entry")
153
+ return errors
154
+
155
+ for name, entry in plugins.items():
156
+ if not _NAME_RE.match(str(name)):
157
+ errors.append(f"plugins: {name!r} is not a package-safe plugin name")
158
+ _validate_entry(str(name), entry, errors)
159
+
160
+ return errors
161
+
162
+
163
+ def _effective_tier(entry: dict) -> str:
164
+ """The trust tier a catalog should display — mirrors ``RegistryEntry.effective_trust_tier``
165
+ without importing hub.py (this module is the lower-level contract layer)."""
166
+ declared = entry.get("trust_tier") or "official"
167
+ if declared == "community" or entry.get("repo") or not entry.get("wasm_checksums"):
168
+ return "community"
169
+ return "official"
170
+
171
+
172
+ def _install_target(name: str, entry: dict) -> str:
173
+ ref = entry.get("ref", "")
174
+ if entry.get("source") == "pypi":
175
+ return f"intentumdiff-{name}=={ref}" if ref else f"intentumdiff-{name}"
176
+ return name
177
+
178
+
179
+ def render_catalog_markdown(registry: Any, *, title: str = "IntentumDiff plugin catalog") -> str:
180
+ """Render a browsable Markdown discovery catalog from a registry manifest (#95).
181
+
182
+ The manifest stays the source of truth; this is a generated VIEW — official plugins first,
183
+ then community, each with its description, source, ABI target, capabilities, and install
184
+ command. Robust to missing optional fields (older entries).
185
+ """
186
+ plugins: dict = registry.get("plugins", {}) if isinstance(registry, dict) else {}
187
+ official = sorted(n for n, e in plugins.items() if _effective_tier(e) == "official")
188
+ community = sorted(n for n, e in plugins.items() if _effective_tier(e) == "community")
189
+
190
+ lines: list[str] = [f"# {title}", ""]
191
+ lines.append(f"_{len(plugins)} plugins — generated from the registry manifest._")
192
+ lines.append("")
193
+
194
+ def _section(heading: str, names: list[str], note: str) -> None:
195
+ lines.append(f"## {heading} ({len(names)})")
196
+ lines.append("")
197
+ if note:
198
+ lines.append(f"> {note}")
199
+ lines.append("")
200
+ if not names:
201
+ lines.append("_None._")
202
+ lines.append("")
203
+ return
204
+ for name in names:
205
+ entry = plugins[name]
206
+ lines.append(f"### {name}")
207
+ desc = entry.get("description")
208
+ if desc:
209
+ lines.append("")
210
+ lines.append(str(desc))
211
+ lines.append("")
212
+ lines.append(f"- **Source**: {entry.get('source', 'git')} `{entry.get('ref', 'main')}`")
213
+ if entry.get("abi_target"):
214
+ lines.append(f"- **ABI target**: `{entry['abi_target']}`")
215
+ caps = entry.get("capabilities") or []
216
+ if caps:
217
+ lines.append(f"- **Capabilities**: {', '.join(f'`{c}`' for c in caps)}")
218
+ lines.append(f"- **Install**: `intentumdiff plugins add {_install_target(name, entry)}`")
219
+ lines.append("")
220
+
221
+ _section("Official", official, "Org-built and scanned; checksums verified on install.")
222
+ _section(
223
+ "Community",
224
+ community,
225
+ "Listed but unverified (custom source or no checksums). "
226
+ "Install only if you trust the source.",
227
+ )
228
+ return "\n".join(lines).rstrip() + "\n"
229
+
230
+
231
+ def _load_registry_document(path: str) -> Any:
232
+ """Parse a registry manifest from a ``.yaml``/``.json`` file."""
233
+ from pathlib import Path
234
+
235
+ text = Path(path).read_text(encoding="utf-8")
236
+ if path.endswith((".yaml", ".yml")):
237
+ import yaml # pyyaml is already a runtime dep (hub.py)
238
+
239
+ return yaml.safe_load(text)
240
+ return json.loads(text)
241
+
242
+
243
+ def main(argv: list[str] | None = None) -> int:
244
+ """CLI for the #95 vetting pipeline: validate a registry manifest, exit non-zero on any
245
+ violation. The plugins-repo PR gate runs ``python -m intentumdiff.plugins.registry_schema
246
+ registry.yaml`` (alongside the checksum/capability/provenance checks) to block a bad entry
247
+ before merge."""
248
+ import argparse
249
+
250
+ parser = argparse.ArgumentParser(description=main.__doc__)
251
+ parser.add_argument("manifest", help="path to registry.yaml (or .json)")
252
+ parser.add_argument(
253
+ "--catalog",
254
+ action="store_true",
255
+ help="after validating, print the Markdown discovery catalog to stdout (#95)",
256
+ )
257
+ args = parser.parse_args(argv)
258
+
259
+ try:
260
+ data = _load_registry_document(args.manifest)
261
+ except (OSError, ValueError) as exc:
262
+ print(f"ERROR: could not read {args.manifest}: {exc}")
263
+ return 2
264
+
265
+ errors = validate_registry(data)
266
+ if errors:
267
+ print(f"Registry manifest {args.manifest} is INVALID ({len(errors)} problem(s)):")
268
+ for err in errors:
269
+ print(f" - {err}")
270
+ return 1
271
+ if args.catalog:
272
+ print(render_catalog_markdown(data), end="")
273
+ return 0
274
+ count = len(data.get("plugins", {})) if isinstance(data, dict) else 0
275
+ print(f"Registry manifest {args.manifest} is valid ({count} plugin(s)).")
276
+ return 0
277
+
278
+
279
+ if __name__ == "__main__":
280
+ raise SystemExit(main())