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.
- intentumdiff/__init__.py +134 -0
- intentumdiff/_differ_gate.py +210 -0
- intentumdiff/_differ_presentation.py +786 -0
- intentumdiff/_differ_runtime.py +320 -0
- intentumdiff/analysis/__init__.py +1 -0
- intentumdiff/analysis/compile_commands.py +151 -0
- intentumdiff/analysis/cross_file.py +71 -0
- intentumdiff/analysis/diagnostics.py +309 -0
- intentumdiff/analysis/guardrail_reports.py +254 -0
- intentumdiff/analysis/guardrails.py +318 -0
- intentumdiff/analysis/invariances.py +1207 -0
- intentumdiff/analysis/keyed_profiles.py +25 -0
- intentumdiff/analysis/resource_profiles.py +14 -0
- intentumdiff/analysis/schema_resolver.py +816 -0
- intentumdiff/analysis/text_review.py +46 -0
- intentumdiff/analysis/user_schemas.py +430 -0
- intentumdiff/assets.py +45 -0
- intentumdiff/cache/__init__.py +37 -0
- intentumdiff/cache/duckdb_store.py +98 -0
- intentumdiff/cache/sqlite_store.py +149 -0
- intentumdiff/cache/store.py +190 -0
- intentumdiff/cli/__init__.py +199 -0
- intentumdiff/cli/_commands.py +2141 -0
- intentumdiff/cli/_parser.py +1061 -0
- intentumdiff/cli/_shared.py +644 -0
- intentumdiff/content_type.py +59 -0
- intentumdiff/core/__init__.py +1 -0
- intentumdiff/core/commit_differ.py +599 -0
- intentumdiff/core/config.py +51 -0
- intentumdiff/core/cst_serializer.py +101 -0
- intentumdiff/core/diffignore.py +87 -0
- intentumdiff/core/index.py +189 -0
- intentumdiff/core/indexer.py +792 -0
- intentumdiff/core/models.py +837 -0
- intentumdiff/differ.py +2195 -0
- intentumdiff/github_app.py +287 -0
- intentumdiff/intentumdiff_rust_core/__init__.py +7 -0
- intentumdiff/intentumdiff_rust_core/ffi.py +8 -0
- intentumdiff/intentumdiff_rust_core/libintentumdiff_rust_core.so +0 -0
- intentumdiff/invariances/__init__.py +2 -0
- intentumdiff/invariances/rules.schema.json +283 -0
- intentumdiff/invariances/rules.yaml +349 -0
- intentumdiff/live_server.py +1314 -0
- intentumdiff/lsp/__init__.py +67 -0
- intentumdiff/lsp/client.py +544 -0
- intentumdiff/lsp/config.py +96 -0
- intentumdiff/lsp/enricher.py +227 -0
- intentumdiff/lsp/exceptions.py +27 -0
- intentumdiff/lsp/launcher.py +273 -0
- intentumdiff/lsp/servers.py +356 -0
- intentumdiff/lsp_server/__init__.py +14 -0
- intentumdiff/lsp_server/_codelens.py +67 -0
- intentumdiff/lsp_server/_diagnostics.py +62 -0
- intentumdiff/lsp_server/_handlers.py +175 -0
- intentumdiff/lsp_server/server.py +205 -0
- intentumdiff/plugins/__init__.py +1 -0
- intentumdiff/plugins/adapter.py +397 -0
- intentumdiff/plugins/builtins.py +323 -0
- intentumdiff/plugins/exceptions.py +93 -0
- intentumdiff/plugins/hub.py +1155 -0
- intentumdiff/plugins/language_metadata.py +250 -0
- intentumdiff/plugins/loader.py +1252 -0
- intentumdiff/plugins/registry.py +1079 -0
- intentumdiff/plugins/registry.schema.json +99 -0
- intentumdiff/plugins/registry_schema.py +280 -0
- intentumdiff/plugins/wit/plugin.wit +351 -0
- intentumdiff/rust_core.py +2370 -0
- intentumdiff/serve/__init__.py +19 -0
- intentumdiff/serve/_app.py +485 -0
- intentumdiff/serve/_static/index.html +326 -0
- intentumdiff/serve/_static/playground.js +567 -0
- intentumdiff/sources/__init__.py +1 -0
- intentumdiff/sources/base.py +28 -0
- intentumdiff/sources/file_source.py +48 -0
- intentumdiff/sources/git_source.py +375 -0
- intentumdiff/sources/live_buffer_source.py +113 -0
- intentumdiff/sources/patch_source.py +126 -0
- intentumdiff/sources/string_source.py +44 -0
- intentumdiff/testing.py +165 -0
- intentumdiff/vcs/__init__.py +37 -0
- intentumdiff/vcs/_safe_path.py +50 -0
- intentumdiff/vcs/base.py +136 -0
- intentumdiff/vcs/git_backend.py +97 -0
- intentumdiff/vcs/git_cli.py +100 -0
- intentumdiff/vcs/hg_backend.py +94 -0
- intentumdiff/vcs/perforce_backend.py +109 -0
- intentumdiff/vcs/svn_backend.py +105 -0
- intentumdiff/wasm/.gitkeep +2 -0
- intentumdiff/wasm/abap_parser.wasm +0 -0
- intentumdiff/wasm/adf_parser.wasm +0 -0
- intentumdiff/wasm/asciidoc_parser.wasm +0 -0
- intentumdiff/wasm/asm_parser.wasm +0 -0
- intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
- intentumdiff/wasm/astro_parser.wasm +0 -0
- intentumdiff/wasm/bash_parser.wasm +0 -0
- intentumdiff/wasm/clojure_parser.wasm +0 -0
- intentumdiff/wasm/cmake_parser.wasm +0 -0
- intentumdiff/wasm/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/css_parser.wasm +0 -0
- intentumdiff/wasm/dart_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/delphi_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_parser.wasm +0 -0
- intentumdiff/wasm/elixir_parser.wasm +0 -0
- intentumdiff/wasm/freebasic_parser.wasm +0 -0
- intentumdiff/wasm/generic_parser.wasm +0 -0
- intentumdiff/wasm/gitignore_parser.wasm +0 -0
- intentumdiff/wasm/go_parser.wasm +0 -0
- intentumdiff/wasm/gomod_parser.wasm +0 -0
- intentumdiff/wasm/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_parser.wasm +0 -0
- intentumdiff/wasm/haskell_parser.wasm +0 -0
- intentumdiff/wasm/html_parser.wasm +0 -0
- intentumdiff/wasm/ini_parser.wasm +0 -0
- intentumdiff/wasm/java_parser.wasm +0 -0
- intentumdiff/wasm/js_ts_parser.wasm +0 -0
- intentumdiff/wasm/json_parser.wasm +0 -0
- intentumdiff/wasm/kotlin_parser.wasm +0 -0
- intentumdiff/wasm/latex_parser.wasm +0 -0
- intentumdiff/wasm/lua_parser.wasm +0 -0
- intentumdiff/wasm/make_parser.wasm +0 -0
- intentumdiff/wasm/markdown_parser.wasm +0 -0
- intentumdiff/wasm/mdx_parser.wasm +0 -0
- intentumdiff/wasm/ocaml_parser.wasm +0 -0
- intentumdiff/wasm/odin_parser.wasm +0 -0
- intentumdiff/wasm/parser_manifest.json +590 -0
- intentumdiff/wasm/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/po_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/proto_parser.wasm +0 -0
- intentumdiff/wasm/puppet_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/r_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/ruby_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/scala_parser.wasm +0 -0
- intentumdiff/wasm/scss_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/squirrel_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_parser.wasm +0 -0
- intentumdiff/wasm/terraform_parser.wasm +0 -0
- intentumdiff/wasm/toml_parser.wasm +0 -0
- intentumdiff/wasm/tsql_parser.wasm +0 -0
- intentumdiff/wasm/vbnet_parser.wasm +0 -0
- intentumdiff/wasm/vue_parser.wasm +0 -0
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/xml_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/wasm/zig_parser.wasm +0 -0
- intentumdiff/watcher.py +259 -0
- intentumdiff_python-0.0.1.dist-info/METADATA +112 -0
- intentumdiff_python-0.0.1.dist-info/RECORD +165 -0
- intentumdiff_python-0.0.1.dist-info/WHEEL +4 -0
- intentumdiff_python-0.0.1.dist-info/entry_points.txt +80 -0
- intentumdiff_python-0.0.1.dist-info/licenses/LICENSE +21 -0
- 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())
|