intentumdiff-python 0.0.2b2__py3-none-win_arm64.whl → 0.0.3b1__py3-none-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- intentumdiff/__init__.py +7 -0
- intentumdiff/_differ_gate.py +0 -136
- intentumdiff/_differ_presentation.py +1 -72
- intentumdiff/_differ_runtime.py +0 -17
- intentumdiff/analysis/cross_file.py +21 -21
- intentumdiff/analysis/diagnostics.py +1 -164
- intentumdiff/analysis/guardrail_reports.py +24 -28
- intentumdiff/analysis/guardrails.py +2 -67
- intentumdiff/analysis/schema_resolver.py +23 -87
- intentumdiff/analysis/user_schemas.py +2 -17
- intentumdiff/cli/_commands.py +70 -71
- intentumdiff/cli/_parser.py +40 -55
- intentumdiff/cli/_shared.py +55 -4
- intentumdiff/core/commit_differ.py +65 -99
- intentumdiff/core/indexer.py +0 -1
- intentumdiff/core/models.py +226 -69
- intentumdiff/differ.py +125 -432
- intentumdiff/github_app.py +5 -8
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +17 -17
- intentumdiff/lsp/client.py +42 -42
- intentumdiff/lsp/servers.py +10 -11
- intentumdiff/lsp_server/_handlers.py +1 -1
- intentumdiff/lsp_server/server.py +0 -1
- intentumdiff/plugins/exceptions.py +24 -0
- intentumdiff/plugins/hub.py +38 -41
- intentumdiff/plugins/registry.py +10 -10
- intentumdiff/plugins/registry.schema.json +156 -15
- intentumdiff/plugins/registry_schema.py +47 -140
- intentumdiff/rust_core.py +112 -775
- intentumdiff/serve/_app.py +23 -25
- intentumdiff/sources/git_source.py +0 -183
- intentumdiff/vcs/git_cli.py +0 -47
- 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/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_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/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_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/make_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/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_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/wasm_provenance.json +219 -219
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/watcher.py +15 -17
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/METADATA +38 -6
- intentumdiff_python-0.0.3b1.dist-info/RECORD +164 -0
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +2 -2
- intentumdiff/analysis/invariances.py +0 -208
- intentumdiff/analysis/keyed_profiles.py +0 -25
- intentumdiff/analysis/resource_profiles.py +0 -14
- intentumdiff/analysis/text_review.py +0 -47
- intentumdiff/invariances/__init__.py +0 -2
- intentumdiff/invariances/rules.schema.json +0 -283
- intentumdiff/invariances/rules.yaml +0 -349
- intentumdiff_python-0.0.2b2.dist-info/RECORD +0 -171
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/WHEEL +0 -0
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.2b2.dist-info → intentumdiff_python-0.0.3b1.dist-info}/licenses/LICENSE +0 -0
|
@@ -3,24 +3,21 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
-
from collections.abc import Iterable
|
|
7
6
|
from dataclasses import dataclass
|
|
8
7
|
from pathlib import Path
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
from intentumdiff.analysis.diagnostics import DiagnosticsRecorder
|
|
12
|
-
from intentumdiff.analysis.keyed_profiles import KEYED_DATA_LANGUAGES
|
|
13
|
-
from intentumdiff.analysis.resource_profiles import RESOURCE_PROFILE_LANGUAGES
|
|
14
11
|
from intentumdiff.core.models import (
|
|
15
12
|
DiffConfig,
|
|
16
13
|
GuardrailSeverity,
|
|
17
|
-
GuardrailViolation,
|
|
18
14
|
SemanticDiff,
|
|
19
15
|
SemanticNode,
|
|
20
16
|
)
|
|
21
17
|
|
|
22
18
|
GUARDRAIL_POLICY_FILENAME = "intentumdiff.yaml"
|
|
23
|
-
|
|
19
|
+
# Which languages a protected rule may target is Rust policy: core's
|
|
20
|
+
# parse_guardrail_policy rejects unsupported languages (GUARDRAIL_RULE_LANGUAGES).
|
|
24
21
|
|
|
25
22
|
|
|
26
23
|
@dataclass(frozen=True)
|
|
@@ -198,68 +195,6 @@ def apply_guardrails_to_diff(
|
|
|
198
195
|
return result
|
|
199
196
|
|
|
200
197
|
|
|
201
|
-
def _evaluate_policy_rules(
|
|
202
|
-
diff: SemanticDiff,
|
|
203
|
-
old_tree: SemanticNode,
|
|
204
|
-
new_tree: SemanticNode,
|
|
205
|
-
rules: Iterable[ProtectedRule],
|
|
206
|
-
) -> list[GuardrailViolation]:
|
|
207
|
-
"""Rust-authoritative (#91 A1.3b): rule matching + violation construction run in
|
|
208
|
-
the Rust core (``evaluate_guardrail_rules_json``), which reuses the same
|
|
209
|
-
semantic-path derivation. Python marshals the parsed policy + the diff's
|
|
210
|
-
changed-node ids in and rebuilds GuardrailViolation objects out; the Python
|
|
211
|
-
matching mirror (rule loop, ``_semantic_paths``, ``_node_value_summary``,
|
|
212
|
-
``_file_matches``) was deleted. Engine failures raise; only a successful empty result means no violations.
|
|
213
|
-
"""
|
|
214
|
-
from intentumdiff.rust_core import try_rust_evaluate_guardrail_rules
|
|
215
|
-
|
|
216
|
-
request = {
|
|
217
|
-
"language": diff.language,
|
|
218
|
-
"old_filename": diff.old_filename,
|
|
219
|
-
"new_filename": diff.new_filename,
|
|
220
|
-
"old_tree": json.loads(old_tree.model_dump_json()),
|
|
221
|
-
"new_tree": json.loads(new_tree.model_dump_json()),
|
|
222
|
-
"changes": [
|
|
223
|
-
{
|
|
224
|
-
"old_node_id": change.old_node.id if change.old_node is not None else None,
|
|
225
|
-
"new_node_id": change.new_node.id if change.new_node is not None else None,
|
|
226
|
-
}
|
|
227
|
-
for change in diff.changes
|
|
228
|
-
],
|
|
229
|
-
"rules": [
|
|
230
|
-
{
|
|
231
|
-
"rule_id": rule.rule_id,
|
|
232
|
-
"severity": rule.severity.value,
|
|
233
|
-
"language": rule.language,
|
|
234
|
-
"path": rule.path,
|
|
235
|
-
"message": rule.message,
|
|
236
|
-
"files": list(rule.files),
|
|
237
|
-
}
|
|
238
|
-
for rule in rules
|
|
239
|
-
],
|
|
240
|
-
}
|
|
241
|
-
violations = try_rust_evaluate_guardrail_rules(request)
|
|
242
|
-
if not violations:
|
|
243
|
-
return []
|
|
244
|
-
return [
|
|
245
|
-
GuardrailViolation(
|
|
246
|
-
rule_id=item["rule_id"],
|
|
247
|
-
severity=GuardrailSeverity(item["severity"]),
|
|
248
|
-
file=item["file"],
|
|
249
|
-
language=item["language"],
|
|
250
|
-
semantic_path=item["semantic_path"],
|
|
251
|
-
node_type=item.get("node_type", ""),
|
|
252
|
-
old_node_id=item.get("old_node_id"),
|
|
253
|
-
new_node_id=item.get("new_node_id"),
|
|
254
|
-
position=item.get("position"),
|
|
255
|
-
old_value=item.get("old_value", ""),
|
|
256
|
-
new_value=item.get("new_value", ""),
|
|
257
|
-
message=item.get("message", ""),
|
|
258
|
-
)
|
|
259
|
-
for item in violations
|
|
260
|
-
]
|
|
261
|
-
|
|
262
|
-
|
|
263
198
|
def _is_policy_file(filename: str | None) -> bool:
|
|
264
199
|
return Path(filename or "").name.lower() == GUARDRAIL_POLICY_FILENAME
|
|
265
200
|
|
|
@@ -6,6 +6,7 @@ import hashlib
|
|
|
6
6
|
import ipaddress
|
|
7
7
|
import json
|
|
8
8
|
import logging
|
|
9
|
+
import math
|
|
9
10
|
import os
|
|
10
11
|
import socket
|
|
11
12
|
import ssl
|
|
@@ -32,66 +33,8 @@ logger = logging.getLogger(__name__)
|
|
|
32
33
|
DEFAULT_SCHEMA_TTL_SECONDS = 86_400
|
|
33
34
|
DEFAULT_TIMEOUT_SECONDS = 5.0
|
|
34
35
|
DEFAULT_MAX_BYTES = 5 * 1024 * 1024
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"git",
|
|
38
|
-
"id",
|
|
39
|
-
"job_cluster_key",
|
|
40
|
-
"key",
|
|
41
|
-
"local",
|
|
42
|
-
"name",
|
|
43
|
-
"operationid",
|
|
44
|
-
"package",
|
|
45
|
-
"task",
|
|
46
|
-
"task_key",
|
|
47
|
-
}
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
DBT_SCHEMA_BASE = "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/latest"
|
|
51
|
-
DBT_SCHEMA_URLS = {
|
|
52
|
-
"dbt_cloud": f"{DBT_SCHEMA_BASE}/dbt_cloud-latest.json",
|
|
53
|
-
"dbt_project": f"{DBT_SCHEMA_BASE}/dbt_project-latest.json",
|
|
54
|
-
"dbt_yml_files": f"{DBT_SCHEMA_BASE}/dbt_yml_files-latest.json",
|
|
55
|
-
"dependencies": f"{DBT_SCHEMA_BASE}/dependencies-latest.json",
|
|
56
|
-
"packages": f"{DBT_SCHEMA_BASE}/packages-latest.json",
|
|
57
|
-
"selectors": f"{DBT_SCHEMA_BASE}/selectors-latest.json",
|
|
58
|
-
}
|
|
59
|
-
ADVISORY_ADF_NO_RAW_SCHEMA_URL = (
|
|
60
|
-
"https://learn.microsoft.com/en-sg/answers/questions/2125264/"
|
|
61
|
-
"are-there-json-schemas-for-adf-source-files"
|
|
62
|
-
)
|
|
63
|
-
DATABRICKS_BUNDLE_SCHEMA_URL = (
|
|
64
|
-
"https://raw.githubusercontent.com/databricks/cli/main/bundle/schema/jsonschema.json"
|
|
65
|
-
)
|
|
66
|
-
OPENAPI_31_SCHEMA_URL = "https://spec.openapis.org/oas/3.1/schema/2022-10-07"
|
|
67
|
-
OPENAPI_30_SCHEMA_URL = "https://spec.openapis.org/oas/3.0/schema/2021-09-28"
|
|
68
|
-
KUBERNETES_SCHEMA_URL = "https://json.schemastore.org/kubernetes.json"
|
|
69
|
-
GITHUB_WORKFLOW_SCHEMA_URL = "https://json.schemastore.org/github-workflow.json"
|
|
70
|
-
AZURE_PIPELINES_SCHEMA_URL = "https://json.schemastore.org/azure-pipelines.json"
|
|
71
|
-
DBT_IDENTITY_FIELDS = frozenset(
|
|
72
|
-
{
|
|
73
|
-
"exposure",
|
|
74
|
-
"macro",
|
|
75
|
-
"metric",
|
|
76
|
-
"model",
|
|
77
|
-
"models",
|
|
78
|
-
"name",
|
|
79
|
-
"package_name",
|
|
80
|
-
"packages",
|
|
81
|
-
"project_name",
|
|
82
|
-
"resource_type",
|
|
83
|
-
"selector",
|
|
84
|
-
"selectors",
|
|
85
|
-
"seed",
|
|
86
|
-
"snapshot",
|
|
87
|
-
"snapshots",
|
|
88
|
-
"source",
|
|
89
|
-
"sources",
|
|
90
|
-
"test",
|
|
91
|
-
"tests",
|
|
92
|
-
"version",
|
|
93
|
-
}
|
|
94
|
-
)
|
|
36
|
+
# Schema identity, provider selection and the built-in provider URL catalogue are owned
|
|
37
|
+
# by core (``schema_profiles``); this module only performs the host fetch/cache I/O.
|
|
95
38
|
|
|
96
39
|
|
|
97
40
|
@dataclass(frozen=True)
|
|
@@ -300,12 +243,6 @@ def _identity_fields_for(
|
|
|
300
243
|
return frozenset({*candidate.identity_fields, *derive_identity_fields(schema)})
|
|
301
244
|
|
|
302
245
|
|
|
303
|
-
def schema_cache_fingerprint(resolution: SchemaResolution | None) -> str:
|
|
304
|
-
if resolution is None:
|
|
305
|
-
return "schema:none"
|
|
306
|
-
return resolution.cache_fingerprint
|
|
307
|
-
|
|
308
|
-
|
|
309
246
|
def schema_resolution_metadata(
|
|
310
247
|
resolution: SchemaResolution | None,
|
|
311
248
|
) -> dict[str, Any] | None:
|
|
@@ -337,7 +274,7 @@ def _fetch_or_cache(
|
|
|
337
274
|
url = candidate.url
|
|
338
275
|
if url is None:
|
|
339
276
|
raise ValueError("schema candidate has no URL to fetch")
|
|
340
|
-
cached = _read_cache(candidate, root)
|
|
277
|
+
cached = _read_cache(candidate, root, now)
|
|
341
278
|
if cached and now - cached["fetched_at"] < ttl:
|
|
342
279
|
return _resolution_from_cache(candidate, cached, "cache_hit")
|
|
343
280
|
|
|
@@ -389,19 +326,11 @@ def _resolve_from_cache(
|
|
|
389
326
|
*,
|
|
390
327
|
allow_stale: bool,
|
|
391
328
|
) -> SchemaResolution:
|
|
392
|
-
cached = _read_cache(candidate, root)
|
|
393
|
-
if not cached:
|
|
329
|
+
cached = _read_cache(candidate, root, now)
|
|
330
|
+
if not cached or (not allow_stale and now - cached["fetched_at"] >= ttl):
|
|
394
331
|
return SchemaResolution(
|
|
395
|
-
provider_id=candidate.provider_id,
|
|
396
|
-
|
|
397
|
-
status="cache_miss",
|
|
398
|
-
identity_fields=candidate.identity_fields,
|
|
399
|
-
)
|
|
400
|
-
if not allow_stale and now - cached["fetched_at"] >= ttl:
|
|
401
|
-
return SchemaResolution(
|
|
402
|
-
provider_id=candidate.provider_id,
|
|
403
|
-
source_url=candidate.url,
|
|
404
|
-
status="cache_stale",
|
|
332
|
+
provider_id=candidate.provider_id, source_url=candidate.url,
|
|
333
|
+
status="cache_miss" if not cached else "cache_stale",
|
|
405
334
|
identity_fields=candidate.identity_fields,
|
|
406
335
|
)
|
|
407
336
|
status = "cache_hit" if now - cached["fetched_at"] < ttl else "stale_cache"
|
|
@@ -432,21 +361,28 @@ def _resolution_from_cache(
|
|
|
432
361
|
)
|
|
433
362
|
|
|
434
363
|
|
|
435
|
-
def _read_cache(candidate: SchemaCandidate, root: Path) -> dict[str, Any] | None:
|
|
364
|
+
def _read_cache(candidate: SchemaCandidate, root: Path, now: float) -> dict[str, Any] | None:
|
|
365
|
+
"""A complete cache record, or None (a cache miss) for a missing or malformed one (#307)."""
|
|
436
366
|
path = _cache_file(candidate, root)
|
|
437
367
|
try:
|
|
438
368
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
369
|
+
except (OSError, ValueError, RecursionError):
|
|
370
|
+
data = None
|
|
371
|
+
stamp = data.get("fetched_at") if isinstance(data, dict) else None
|
|
372
|
+
if (type(stamp) in (int, float) and math.isfinite(stamp) and stamp <= now
|
|
373
|
+
and isinstance(data.get("schema"), dict)):
|
|
374
|
+
return data
|
|
375
|
+
if path.exists():
|
|
376
|
+
logger.warning("Ignoring malformed schema cache record %s", path)
|
|
443
377
|
return None
|
|
444
378
|
|
|
445
379
|
|
|
446
380
|
def _write_cache(candidate: SchemaCandidate, root: Path, data: Mapping[str, Any]) -> None:
|
|
447
381
|
path = _cache_file(candidate, root)
|
|
448
382
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
449
|
-
path.
|
|
383
|
+
temporary = path.with_name(f"{path.name}.{os.getpid()}.tmp") # readers never see a partial
|
|
384
|
+
temporary.write_text(json.dumps(data, sort_keys=True, indent=2), encoding="utf-8")
|
|
385
|
+
os.replace(temporary, path)
|
|
450
386
|
|
|
451
387
|
|
|
452
388
|
def _cache_file(candidate: SchemaCandidate, root: Path) -> Path:
|
|
@@ -536,9 +472,9 @@ def _schema_commands_allowed(env: Mapping[str, str]) -> bool:
|
|
|
536
472
|
|
|
537
473
|
def _schema_ttl_seconds(env: Mapping[str, str]) -> int:
|
|
538
474
|
raw = env.get("INTENTUMDIFF_SCHEMA_CACHE_TTL_SECONDS", "")
|
|
539
|
-
try:
|
|
475
|
+
try: # nan / inf / exponent overflow fall back to the default (#307)
|
|
540
476
|
return max(0, int(float(raw)))
|
|
541
|
-
except ValueError:
|
|
477
|
+
except (ValueError, OverflowError):
|
|
542
478
|
return DEFAULT_SCHEMA_TTL_SECONDS
|
|
543
479
|
|
|
544
480
|
|
|
@@ -51,23 +51,8 @@ logger = logging.getLogger(__name__)
|
|
|
51
51
|
USER_SCHEMA_DIR_ENV = "INTENTUMDIFF_USER_SCHEMA_DIR"
|
|
52
52
|
USER_SCHEMAS_TOGGLE_ENV = "INTENTUMDIFF_USER_SCHEMAS"
|
|
53
53
|
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
BUILTIN_PROVIDER_ROOTS = frozenset(
|
|
57
|
-
{
|
|
58
|
-
"adf",
|
|
59
|
-
"azure-pipelines",
|
|
60
|
-
"databricks",
|
|
61
|
-
"dbt",
|
|
62
|
-
"embedded",
|
|
63
|
-
"github-actions",
|
|
64
|
-
"kubernetes",
|
|
65
|
-
"none",
|
|
66
|
-
"openapi",
|
|
67
|
-
"user",
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
|
|
54
|
+
# Built-in provider roots (and the collision rule for registered language ids) are owned
|
|
55
|
+
# by core `schema_profiles` "validate" (#298).
|
|
71
56
|
_DESCRIPTOR_SUFFIXES = (".yml", ".yaml", ".json")
|
|
72
57
|
|
|
73
58
|
|
intentumdiff/cli/_commands.py
CHANGED
|
@@ -62,6 +62,7 @@ from intentumdiff.cli._shared import ( # noqa: F401
|
|
|
62
62
|
_guardrail_result,
|
|
63
63
|
_json_default,
|
|
64
64
|
_load_cli_config,
|
|
65
|
+
_offer_incomplete_reports,
|
|
65
66
|
_parse_fuel,
|
|
66
67
|
_record_diagnostics_db,
|
|
67
68
|
_render,
|
|
@@ -119,14 +120,10 @@ def _cmd_git(args: argparse.Namespace) -> None:
|
|
|
119
120
|
from intentumdiff.sources.git_source import StagedSource, _REF_STAGED, _REF_UNPUSHED
|
|
120
121
|
from intentumdiff.vcs.git_cli import NotAGitRepositoryError
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if getattr(args, "staged", False):
|
|
127
|
-
new_ref = _REF_STAGED
|
|
128
|
-
elif getattr(args, "unpushed", False):
|
|
129
|
-
new_ref = _REF_UNPUSHED
|
|
123
|
+
if getattr(args, "repo_option", None) is not None and args.repo != ".":
|
|
124
|
+
_err.print("[red]Name the repository once: --repo or the REPO positional.[/red]")
|
|
125
|
+
sys.exit(2)
|
|
126
|
+
repo_path = getattr(args, "repo_option", None) or args.repo # --repo, REPO or '.' (#317)
|
|
130
127
|
|
|
131
128
|
# Resolve the effective new_ref from mutually-exclusive scope flags.
|
|
132
129
|
new_ref: str = args.new # may be "", ":staged", ":unpushed", or an explicit ref
|
|
@@ -138,10 +135,8 @@ def _cmd_git(args: argparse.Namespace) -> None:
|
|
|
138
135
|
# Smart --old default: HEAD for working-tree / scoped modes; HEAD~1 when an
|
|
139
136
|
# explicit commit ref is given for --new so that `intentumdiff git --new HEAD`
|
|
140
137
|
# means "show the last commit" rather than HEAD vs HEAD = no diff.
|
|
141
|
-
|
|
142
|
-
old_ref: str = args.old if args.old is not None else (
|
|
143
|
-
"HEAD" if _is_working_tree_mode else "HEAD~1"
|
|
144
|
-
)
|
|
138
|
+
working_tree_mode = not new_ref or new_ref in (_REF_STAGED, _REF_UNPUSHED)
|
|
139
|
+
old_ref: str = args.old if args.old is not None else ("HEAD" if working_tree_mode else "HEAD~1")
|
|
145
140
|
|
|
146
141
|
try:
|
|
147
142
|
if args.file:
|
|
@@ -238,13 +233,12 @@ def _cmd_git(args: argparse.Namespace) -> None:
|
|
|
238
233
|
_err.print(f"[red]Repository path not found:[/red] {repo_path}")
|
|
239
234
|
# When the repo path looks like a git ref name (e.g. "main", "HEAD",
|
|
240
235
|
# "new") the user probably typed '-- ref' instead of '--new ref'.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)
|
|
236
|
+
import re as _re
|
|
237
|
+
if not Path(repo_path).is_absolute() and _re.fullmatch(r"[A-Za-z0-9_/.\-]+", repo_path):
|
|
238
|
+
_err.print(
|
|
239
|
+
f"[yellow]Hint: '{repo_path}' looks like a git ref. "
|
|
240
|
+
f"Did you mean [bold]--new {repo_path}[/bold]?[/yellow]"
|
|
241
|
+
)
|
|
248
242
|
else:
|
|
249
243
|
_err.print(
|
|
250
244
|
f"[red]Not a git repository:[/red] {repo_path!r} "
|
|
@@ -280,6 +274,7 @@ def _cmd_file(args: argparse.Namespace) -> None:
|
|
|
280
274
|
if change.text_diff:
|
|
281
275
|
line += f" [{change.text_diff}]"
|
|
282
276
|
_console.print(line)
|
|
277
|
+
_offer_incomplete_reports([diff], args)
|
|
283
278
|
else:
|
|
284
279
|
_render_with_profile(diff, args, fuel=differ._config.plugin_fuel)
|
|
285
280
|
result = _emit_guardrail_reports(diff, args)
|
|
@@ -572,6 +567,7 @@ def _cmd_plugins_list(_args: argparse.Namespace) -> None:
|
|
|
572
567
|
|
|
573
568
|
def _cmd_plugins_add(args: argparse.Namespace) -> None:
|
|
574
569
|
import os as _os
|
|
570
|
+
import warnings as _warnings
|
|
575
571
|
|
|
576
572
|
from intentumdiff.plugins.hub import (
|
|
577
573
|
PluginSpec,
|
|
@@ -585,6 +581,7 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
|
|
|
585
581
|
save_plugins_file,
|
|
586
582
|
security_check_plugin,
|
|
587
583
|
)
|
|
584
|
+
from intentumdiff.plugins.hub import logger as _hub_logger
|
|
588
585
|
|
|
589
586
|
source: str = getattr(args, "source", "git")
|
|
590
587
|
skip_verify: bool = getattr(args, "skip_verify", False)
|
|
@@ -598,9 +595,7 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
|
|
|
598
595
|
"INTENTUMDIFF_ALLOW_SKIP_VERIFY=1 to prevent accidental use.[/bold red]"
|
|
599
596
|
)
|
|
600
597
|
sys.exit(1)
|
|
601
|
-
_err.print(
|
|
602
|
-
"[yellow]Warning: security verification skipped (--skip-verify).[/yellow]"
|
|
603
|
-
)
|
|
598
|
+
_err.print("[yellow]Warning: security verification skipped (--skip-verify).[/yellow]")
|
|
604
599
|
|
|
605
600
|
# Preserve existing pinned Wasm/dependency provenance before pip has any
|
|
606
601
|
# side effects. A malformed manifest or dangling symlink is not an empty
|
|
@@ -620,14 +615,20 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
|
|
|
620
615
|
registry_entry: RegistryEntry | None = None
|
|
621
616
|
if not args.repo and not skip_verify:
|
|
622
617
|
try:
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
)
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
618
|
+
# #309: an invalid manifest only skips entries; show its warning once, here, and not
|
|
619
|
+
# again through the logging last-resort handler.
|
|
620
|
+
with _warnings.catch_warnings(record=True) as caught:
|
|
621
|
+
_warnings.simplefilter("always")
|
|
622
|
+
_hub_logger.disabled = True
|
|
623
|
+
try:
|
|
624
|
+
registry = fetch_official_registry(
|
|
625
|
+
strict=getattr(args, "strict_registry", False),
|
|
626
|
+
)
|
|
627
|
+
finally:
|
|
628
|
+
_hub_logger.disabled = False
|
|
629
|
+
for caught_warning in caught:
|
|
630
|
+
_err.print("[yellow]Registry warning:[/yellow]", Text(str(caught_warning.message)))
|
|
631
|
+
short = args.plugin_name.removeprefix("intentumdiff-")
|
|
631
632
|
registry_entry = registry.get(short)
|
|
632
633
|
if registry_entry is not None:
|
|
633
634
|
# #94: refuse an ABI-incompatible plugin at RESOLVE time, before any install.
|
|
@@ -723,10 +724,7 @@ def _cmd_plugins_add(args: argparse.Namespace) -> None:
|
|
|
723
724
|
if args.save:
|
|
724
725
|
yaml_path = Path(args.file)
|
|
725
726
|
# Replace only the matching entry; retain all other pinned provenance.
|
|
726
|
-
existing = [
|
|
727
|
-
s for s in existing_manifest
|
|
728
|
-
if s.name != spec.name and s.name != spec.package_name
|
|
729
|
-
]
|
|
727
|
+
existing = [s for s in existing_manifest if s.name not in (spec.name, spec.package_name)]
|
|
730
728
|
existing.append(spec)
|
|
731
729
|
save_plugins_file(yaml_path, existing)
|
|
732
730
|
_console.print(f"[green]Saved to {yaml_path}[/green]")
|
|
@@ -756,9 +754,7 @@ def _cmd_plugins_install(args: argparse.Namespace) -> None:
|
|
|
756
754
|
"INTENTUMDIFF_ALLOW_SKIP_VERIFY=1 to prevent accidental use.[/bold red]"
|
|
757
755
|
)
|
|
758
756
|
sys.exit(1)
|
|
759
|
-
_err.print(
|
|
760
|
-
"[yellow]Warning: security verification skipped (--skip-verify).[/yellow]"
|
|
761
|
-
)
|
|
757
|
+
_err.print("[yellow]Warning: security verification skipped (--skip-verify).[/yellow]")
|
|
762
758
|
|
|
763
759
|
yaml_path = Path(args.file)
|
|
764
760
|
if not yaml_path.exists():
|
|
@@ -820,9 +816,7 @@ def _cmd_plugins_install(args: argparse.Namespace) -> None:
|
|
|
820
816
|
)
|
|
821
817
|
for e in errors:
|
|
822
818
|
_err.print(f" [red]{e}[/red]")
|
|
823
|
-
_err.print(
|
|
824
|
-
f" [red]Uninstalling '{spec.package_name}'.[/red]"
|
|
825
|
-
)
|
|
819
|
+
_err.print(f" [red]Uninstalling '{spec.package_name}'.[/red]")
|
|
826
820
|
pip_uninstall(spec.package_name)
|
|
827
821
|
security_failed.append(spec.name)
|
|
828
822
|
|
|
@@ -1880,8 +1874,7 @@ def _cmd_serve(args: argparse.Namespace) -> None:
|
|
|
1880
1874
|
port: int = args.port
|
|
1881
1875
|
|
|
1882
1876
|
# Guard against accidentally exposing the playground to the network.
|
|
1883
|
-
|
|
1884
|
-
if host not in _loopback and not getattr(args, "allow_remote", False):
|
|
1877
|
+
if host not in {"127.0.0.1", "::1", "localhost"} and not getattr(args, "allow_remote", False):
|
|
1885
1878
|
_err.print(
|
|
1886
1879
|
f"[bold red]Error:[/bold red] binding to '{host}' would expose the "
|
|
1887
1880
|
"playground on the network. "
|
|
@@ -1894,24 +1887,25 @@ def _cmd_serve(args: argparse.Namespace) -> None:
|
|
|
1894
1887
|
|
|
1895
1888
|
# Try the requested port; fall back to a free OS-assigned port if taken.
|
|
1896
1889
|
import socket
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
_s.
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
f"[
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1890
|
+
family = socket.AF_INET6 if ":" in host else socket.AF_INET # an IPv6 literal (#323)
|
|
1891
|
+
try:
|
|
1892
|
+
with socket.socket(family, socket.SOCK_STREAM) as _s:
|
|
1893
|
+
_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
1894
|
+
try:
|
|
1895
|
+
_s.bind((host, port))
|
|
1896
|
+
except OSError:
|
|
1897
|
+
_s.bind((host, 0))
|
|
1898
|
+
port = _s.getsockname()[1]
|
|
1899
|
+
_console.print(
|
|
1900
|
+
f"[yellow]Warning:[/yellow] requested port was unavailable; "
|
|
1901
|
+
f"binding to free port [cyan]{port}[/cyan] instead."
|
|
1902
|
+
)
|
|
1903
|
+
except OSError as exc: # e.g. no IPv6 on this host: a diagnostic, not a traceback
|
|
1904
|
+
_err.print(f"[red]Error:[/red] cannot bind {host!r}: {exc}")
|
|
1905
|
+
sys.exit(1)
|
|
1906
|
+
shown = f"[{host}]" if family == socket.AF_INET6 else host
|
|
1907
|
+
_console.print(f"[bold green]IntentumDiff serve[/bold green] listening on "
|
|
1908
|
+
f"[cyan]http://{shown}:{port}[/cyan] ([dim]Ctrl+C to stop[/dim])")
|
|
1915
1909
|
uvicorn.run(app, host=host, port=port, log_level="warning")
|
|
1916
1910
|
|
|
1917
1911
|
|
|
@@ -2052,18 +2046,20 @@ def _add_output_args(p: argparse.ArgumentParser) -> None:
|
|
|
2052
2046
|
default=None,
|
|
2053
2047
|
help="Write output to FILE instead of stdout",
|
|
2054
2048
|
)
|
|
2049
|
+
p.add_argument("--report-bug", action="store_true", help="On an incomplete review, preview "
|
|
2050
|
+
"core's bug report and ask before opening the pre-filled issue in a browser.")
|
|
2055
2051
|
|
|
2056
2052
|
|
|
2057
2053
|
def _parse_megapixels(value: str) -> int:
|
|
2058
|
-
try:
|
|
2054
|
+
try: # nan is not > 0; inf and exponent overflow raise OverflowError in int() (#315)
|
|
2059
2055
|
megapixels = float(value)
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2056
|
+
if megapixels > 0:
|
|
2057
|
+
return max(1, int(megapixels * 1_000_000))
|
|
2058
|
+
except (ValueError, OverflowError):
|
|
2059
|
+
pass
|
|
2060
|
+
raise argparse.ArgumentTypeError(
|
|
2061
|
+
f"invalid megapixel value {value!r}: use a finite positive number"
|
|
2062
|
+
)
|
|
2067
2063
|
|
|
2068
2064
|
|
|
2069
2065
|
def _add_asset_diff_args(p: argparse.ArgumentParser) -> None:
|
|
@@ -2190,8 +2186,8 @@ def _add_guardrail_args(p: argparse.ArgumentParser) -> None:
|
|
|
2190
2186
|
action="store_true",
|
|
2191
2187
|
default=False,
|
|
2192
2188
|
help=(
|
|
2193
|
-
"Exit
|
|
2194
|
-
"
|
|
2189
|
+
"Exit 2 when any protected config guardrail violation "
|
|
2190
|
+
"(important or immutable) is detected."
|
|
2195
2191
|
),
|
|
2196
2192
|
)
|
|
2197
2193
|
p.add_argument(
|
|
@@ -2229,6 +2225,7 @@ class _GitPositionalsAction(argparse.Action):
|
|
|
2229
2225
|
With one positional: ``git FILE`` → repo=".", file=FILE
|
|
2230
2226
|
With two positionals: ``git REPO FILE`` → repo=REPO, file=FILE
|
|
2231
2227
|
With zero positionals: → repo=".", file=None (commit-wide)
|
|
2228
|
+
More than two is a usage error: dropping the rest silently shrank the review (#318).
|
|
2232
2229
|
"""
|
|
2233
2230
|
|
|
2234
2231
|
def __call__(
|
|
@@ -2238,7 +2235,9 @@ class _GitPositionalsAction(argparse.Action):
|
|
|
2238
2235
|
values: list[str],
|
|
2239
2236
|
option_string: str | None = None,
|
|
2240
2237
|
) -> None:
|
|
2241
|
-
if len(values)
|
|
2238
|
+
if len(values) > 2:
|
|
2239
|
+
parser.error(f"git takes at most two positionals ([REPO] FILE); got extra {values[2:]}")
|
|
2240
|
+
if len(values) == 2:
|
|
2242
2241
|
namespace.repo = values[0]
|
|
2243
2242
|
namespace.file = values[1]
|
|
2244
2243
|
elif len(values) == 1:
|