omnirank 0.5.0__py3-none-any.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.
- omnirank/__init__.py +14 -0
- omnirank/__main__.py +6 -0
- omnirank/adapters/__init__.py +202 -0
- omnirank/adapters/astro.py +338 -0
- omnirank/adapters/base.py +372 -0
- omnirank/adapters/html.py +561 -0
- omnirank/adapters/jsx.py +340 -0
- omnirank/adapters/nextjs.py +692 -0
- omnirank/aeo/__init__.py +9 -0
- omnirank/aeo/extract.py +383 -0
- omnirank/aeo/propose.py +84 -0
- omnirank/aeo/rules.py +964 -0
- omnirank/aeo/runner.py +148 -0
- omnirank/applicability.py +98 -0
- omnirank/apply/__init__.py +23 -0
- omnirank/apply/engine.py +1254 -0
- omnirank/apply/journal.py +139 -0
- omnirank/apply/patch.py +144 -0
- omnirank/audit.py +185 -0
- omnirank/bands.py +106 -0
- omnirank/brief/__init__.py +0 -0
- omnirank/brief/analyze.py +197 -0
- omnirank/brief/constants.py +89 -0
- omnirank/brief/cost.py +62 -0
- omnirank/brief/egress.py +23 -0
- omnirank/brief/fetchpages.py +239 -0
- omnirank/brief/render.py +151 -0
- omnirank/brief/runner.py +369 -0
- omnirank/brief/serp.py +274 -0
- omnirank/brief/text.py +181 -0
- omnirank/cli.py +844 -0
- omnirank/clock.py +22 -0
- omnirank/cms/__init__.py +1 -0
- omnirank/cms/runner.py +170 -0
- omnirank/cms/wordpress.py +495 -0
- omnirank/cms/wordpress_apply.py +508 -0
- omnirank/cms/wordpress_plan.py +280 -0
- omnirank/config.py +81 -0
- omnirank/connect/__init__.py +4 -0
- omnirank/connect/bing.py +284 -0
- omnirank/connect/cloud_setup.py +43 -0
- omnirank/connect/confirm.py +242 -0
- omnirank/connect/constants.py +226 -0
- omnirank/connect/doctor.py +270 -0
- omnirank/connect/ga4.py +749 -0
- omnirank/connect/ga4_ai.py +123 -0
- omnirank/connect/google_auth.py +657 -0
- omnirank/connect/gsc.py +630 -0
- omnirank/connect/gsc_reports.py +169 -0
- omnirank/connect/http.py +310 -0
- omnirank/connect/indexnow.py +373 -0
- omnirank/connect/naver.py +536 -0
- omnirank/connect/runner.py +515 -0
- omnirank/connect/runner_ga4_ai.py +59 -0
- omnirank/connect/runner_more.py +489 -0
- omnirank/connect/runner_regional.py +260 -0
- omnirank/connect/secrets.py +190 -0
- omnirank/connect/urlcheck.py +41 -0
- omnirank/connect/yandex.py +350 -0
- omnirank/crawl/__init__.py +11 -0
- omnirank/crawl/analyze.py +493 -0
- omnirank/crawl/crawler.py +491 -0
- omnirank/crawl/custom.py +175 -0
- omnirank/crawl/export.py +67 -0
- omnirank/crawl/fetcher.py +212 -0
- omnirank/crawl/parse.py +102 -0
- omnirank/crawl/render.py +148 -0
- omnirank/crawl/robotsgate.py +198 -0
- omnirank/crawl/runner.py +295 -0
- omnirank/crawl/sitemap.py +99 -0
- omnirank/crawl/text.py +20 -0
- omnirank/crawl/urls.py +100 -0
- omnirank/crawlers.py +564 -0
- omnirank/data/ai_crawlers.json +269 -0
- omnirank/data/ai_referrers.json +42 -0
- omnirank/fetch.py +107 -0
- omnirank/fixes/__init__.py +92 -0
- omnirank/fixes/base.py +232 -0
- omnirank/fixes/canonical.py +243 -0
- omnirank/fixes/schema.py +126 -0
- omnirank/formats.py +134 -0
- omnirank/framework.py +223 -0
- omnirank/gates/__init__.py +48 -0
- omnirank/gates/aeo.py +114 -0
- omnirank/gates/contradictions.py +280 -0
- omnirank/gates/crawler_policy.py +85 -0
- omnirank/gates/geo.py +152 -0
- omnirank/gates/hygiene.py +81 -0
- omnirank/gates/jsonld.py +282 -0
- omnirank/gates/onpage.py +177 -0
- omnirank/gates/perf.py +115 -0
- omnirank/gates/security.py +264 -0
- omnirank/gates/seo.py +118 -0
- omnirank/gates/site.py +248 -0
- omnirank/geo_artifacts.py +199 -0
- omnirank/html.py +79 -0
- omnirank/keywords/__init__.py +5 -0
- omnirank/keywords/constants.py +69 -0
- omnirank/keywords/engine.py +384 -0
- omnirank/keywords/report.py +143 -0
- omnirank/keywords/runner.py +160 -0
- omnirank/keywords/source.py +60 -0
- omnirank/keywords/text.py +45 -0
- omnirank/locator.py +480 -0
- omnirank/logs/__init__.py +0 -0
- omnirank/logs/analyze.py +127 -0
- omnirank/logs/bots.py +69 -0
- omnirank/logs/ipranges.py +191 -0
- omnirank/logs/parse.py +452 -0
- omnirank/logs/paths.py +22 -0
- omnirank/logs/privacy.py +105 -0
- omnirank/logs/runner.py +179 -0
- omnirank/mcp_server.py +1480 -0
- omnirank/netguard.py +525 -0
- omnirank/packs/__init__.py +6 -0
- omnirank/packs/backlinks.py +535 -0
- omnirank/packs/blog.py +544 -0
- omnirank/packs/blog_cross.py +468 -0
- omnirank/packs/crawlers.py +23 -0
- omnirank/packs/entity.py +492 -0
- omnirank/packs/feeds.py +150 -0
- omnirank/packs/frontmatter.py +59 -0
- omnirank/packs/gsc.py +421 -0
- omnirank/packs/local.py +879 -0
- omnirank/packs/mdscan.py +326 -0
- omnirank/packs/miniyaml.py +378 -0
- omnirank/packs/model.py +46 -0
- omnirank/packs/product.py +979 -0
- omnirank/packs/refresh.py +165 -0
- omnirank/packs/runner.py +277 -0
- omnirank/packs/sitescan.py +294 -0
- omnirank/packs/textsafe.py +79 -0
- omnirank/packs/xmlsafe.py +92 -0
- omnirank/page.py +42 -0
- omnirank/registry.py +302 -0
- omnirank/report.py +251 -0
- omnirank/report_cmd/__init__.py +7 -0
- omnirank/report_cmd/delta.py +58 -0
- omnirank/report_cmd/files.py +64 -0
- omnirank/report_cmd/model.py +208 -0
- omnirank/report_cmd/notify.py +195 -0
- omnirank/report_cmd/pdf.py +83 -0
- omnirank/report_cmd/portfolio.py +342 -0
- omnirank/report_cmd/render.py +379 -0
- omnirank/report_cmd/runner.py +267 -0
- omnirank/robots.py +172 -0
- omnirank/scanner/__init__.py +10 -0
- omnirank/scanner/badge.py +90 -0
- omnirank/scanner/cache.py +69 -0
- omnirank/scanner/cli.py +96 -0
- omnirank/scanner/engine.py +289 -0
- omnirank/scanner/limits.py +98 -0
- omnirank/scanner/server.py +143 -0
- omnirank/scanner/service.py +328 -0
- omnirank/schema/__init__.py +13 -0
- omnirank/schema/catalog.py +679 -0
- omnirank/schema/catalog_specs.py +350 -0
- omnirank/schema/core.py +306 -0
- omnirank/schema/extract.py +396 -0
- omnirank/schema/gate.py +121 -0
- omnirank/schema/runner.py +213 -0
- omnirank/schema/validate.py +504 -0
- omnirank/schema/vocab.py +305 -0
- omnirank/schemas/omnirank.config.schema.json +268 -0
- omnirank/track/__init__.py +0 -0
- omnirank/track/ai_prompts.py +207 -0
- omnirank/track/analysis.py +197 -0
- omnirank/track/constants.py +155 -0
- omnirank/track/cost.py +229 -0
- omnirank/track/discover.py +277 -0
- omnirank/track/discover_cli.py +309 -0
- omnirank/track/discover_constants.py +95 -0
- omnirank/track/engines.py +216 -0
- omnirank/track/estimate_view.py +212 -0
- omnirank/track/history.py +261 -0
- omnirank/track/runner.py +586 -0
- omnirank/track/stats.py +138 -0
- omnirank/track/storage.py +128 -0
- omnirank-0.5.0.dist-info/METADATA +47 -0
- omnirank-0.5.0.dist-info/RECORD +183 -0
- omnirank-0.5.0.dist-info/WHEEL +5 -0
- omnirank-0.5.0.dist-info/entry_points.txt +2 -0
- omnirank-0.5.0.dist-info/top_level.txt +1 -0
omnirank/aeo/runner.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Implementation of ``omnirank aeo``. Reads a URL or a local HTML file; writes nothing.
|
|
2
|
+
|
|
3
|
+
Exit codes: 0 no findings; 1 findings reported; 2 usage error, unreadable input or a
|
|
4
|
+
page that could not be fetched.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
from dataclasses import asdict
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from ..fetch import fetch, make_client
|
|
14
|
+
from ..framework import detect
|
|
15
|
+
from ..locator import locate
|
|
16
|
+
from .propose import AeoResult, analyse
|
|
17
|
+
|
|
18
|
+
HTML_SUFFIXES = {".html", ".htm"}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _err(message: str) -> None:
|
|
22
|
+
print(f"omnirank: {message}", file=sys.stderr)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _why(got) -> str:
|
|
26
|
+
"""Why a fetch failed: the transport error when there was no response, else the status."""
|
|
27
|
+
if got.status == 0:
|
|
28
|
+
return got.text.strip() or "no response"
|
|
29
|
+
return f"status {got.status}"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _label(path: Path, root: Path | None) -> str:
|
|
33
|
+
if root is not None:
|
|
34
|
+
try:
|
|
35
|
+
return path.resolve().relative_to(root.resolve()).as_posix()
|
|
36
|
+
except ValueError:
|
|
37
|
+
pass
|
|
38
|
+
return path.name if path.is_absolute() else path.as_posix()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _resolve_source(args) -> tuple[str, str | None, str, list[str]] | None:
|
|
42
|
+
"""(html, source_path, display label, notes) or None after printing an error."""
|
|
43
|
+
root = Path(args.root) if args.root else None
|
|
44
|
+
if args.file:
|
|
45
|
+
path = Path(args.file)
|
|
46
|
+
if not path.is_file():
|
|
47
|
+
_err(f"file not found: {path}")
|
|
48
|
+
return None
|
|
49
|
+
try:
|
|
50
|
+
text = path.read_text(encoding="utf-8")
|
|
51
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
52
|
+
_err(f"cannot read {path}: {exc}")
|
|
53
|
+
return None
|
|
54
|
+
label = _label(path, root)
|
|
55
|
+
return text, label, label, []
|
|
56
|
+
url = args.url
|
|
57
|
+
if not url.startswith(("http://", "https://")):
|
|
58
|
+
_err(f"expected an absolute http(s) URL or --file, got {url!r}")
|
|
59
|
+
return None
|
|
60
|
+
notes: list[str] = []
|
|
61
|
+
if root is not None:
|
|
62
|
+
found = locate(url, detection=detect(root), root=root)
|
|
63
|
+
suffix = Path(found.path).suffix.lower() if found.path else ""
|
|
64
|
+
if found.path and found.confidence in ("exact", "inferred") and suffix in HTML_SUFFIXES:
|
|
65
|
+
try:
|
|
66
|
+
text = (root / found.path).read_text(encoding="utf-8")
|
|
67
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
68
|
+
_err(f"cannot read located source {found.path}: {exc}")
|
|
69
|
+
return None
|
|
70
|
+
notes.append(f"source located with {found.confidence} confidence: {found.path}")
|
|
71
|
+
return text, found.path, found.path, notes
|
|
72
|
+
notes.append("source file not located as plain HTML under --root"
|
|
73
|
+
+ (f" ({found.path} is not an .html file)" if found.path else "")
|
|
74
|
+
+ "; findings refer to the fetched page and no diff is produced")
|
|
75
|
+
with make_client() as client:
|
|
76
|
+
got = fetch(client, url)
|
|
77
|
+
if not got.ok:
|
|
78
|
+
_err(f"could not fetch {url} ({_why(got)})")
|
|
79
|
+
return None
|
|
80
|
+
return got.text, None, url, notes
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _finding_json(f, label: str) -> dict:
|
|
84
|
+
d = asdict(f)
|
|
85
|
+
d.pop("edits", None)
|
|
86
|
+
d.pop("note", None)
|
|
87
|
+
d["has_diff"] = f.has_edit
|
|
88
|
+
d["location"] = f"{label}:{f.line}" if f.line else label
|
|
89
|
+
return d
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def to_dict(result: AeoResult, label: str, notes: list[str]) -> dict:
|
|
93
|
+
return {
|
|
94
|
+
"target": label, "lang": result.lang, "intent": result.intent,
|
|
95
|
+
"entity": result.entity, "questions": result.questions, "skipped": result.skipped,
|
|
96
|
+
"findings": [_finding_json(f, label) for f in result.findings],
|
|
97
|
+
"diff": result.diff, "notes": notes,
|
|
98
|
+
"writes": False,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def render(result: AeoResult, label: str, notes: list[str]) -> str:
|
|
103
|
+
page = (f" page: lang={result.lang or '-'} intent={result.intent} "
|
|
104
|
+
f"entity={result.entity or '-'} question headings={len(result.questions)}")
|
|
105
|
+
lines = [f"omnirank aeo: {label}", page]
|
|
106
|
+
lines += [f" note: {n}" for n in notes]
|
|
107
|
+
if result.skipped:
|
|
108
|
+
lines.append(f" skipped: {result.skipped} (no AEO findings are produced for this page)")
|
|
109
|
+
return "\n".join(lines)
|
|
110
|
+
if not result.findings:
|
|
111
|
+
lines.append(" no findings")
|
|
112
|
+
for f in result.findings:
|
|
113
|
+
where = f"{label}:{f.line}" if f.line else label
|
|
114
|
+
lines.append(f" {f.evidence} {f.id} {where} (rule {f.rule}, {f.severity})")
|
|
115
|
+
lines.append(f" {f.message}")
|
|
116
|
+
if f.before is not None:
|
|
117
|
+
lines.append(f" before: {f.before}")
|
|
118
|
+
if f.after is not None:
|
|
119
|
+
lines.append(f" after: {f.after}")
|
|
120
|
+
if f.todo:
|
|
121
|
+
lines.append(f" todo: {f.todo}")
|
|
122
|
+
if not f.has_edit and not f.todo:
|
|
123
|
+
lines.append(" (advice only: no diff)")
|
|
124
|
+
if result.diff:
|
|
125
|
+
lines += ["", " proposed diff (preview only; nothing is written):", result.diff.rstrip("\n")]
|
|
126
|
+
elif result.findings:
|
|
127
|
+
lines.append(" no diff: no finding has a safe mechanical edit for this source")
|
|
128
|
+
return "\n".join(lines)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def run_aeo(args) -> int:
|
|
132
|
+
if bool(args.url) == bool(args.file):
|
|
133
|
+
_err("give exactly one of a URL or --file PATH")
|
|
134
|
+
return 2
|
|
135
|
+
resolved = _resolve_source(args)
|
|
136
|
+
if resolved is None:
|
|
137
|
+
return 2
|
|
138
|
+
text, source_path, label, notes = resolved
|
|
139
|
+
try:
|
|
140
|
+
result = analyse(text, source_path=source_path)
|
|
141
|
+
except ValueError as exc: # a malformed OMNIRANK_AS_OF
|
|
142
|
+
_err(str(exc))
|
|
143
|
+
return 2
|
|
144
|
+
if args.json:
|
|
145
|
+
print(json.dumps(to_dict(result, label, notes), indent=2, ensure_ascii=False))
|
|
146
|
+
else:
|
|
147
|
+
print(render(result, label, notes))
|
|
148
|
+
return 1 if result.findings else 0
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""The safety axis: may THIS finding-instance's fix be applied unattended?
|
|
2
|
+
|
|
3
|
+
Orthogonal to `registry.FixTier`, which is the epistemic axis and a static
|
|
4
|
+
property of the finding id. Applicability is per-instance and is the MINIMUM of
|
|
5
|
+
four ceilings:
|
|
6
|
+
|
|
7
|
+
applicability = min(
|
|
8
|
+
tier_ceiling(fix_tier), # mechanical -> safe, templated -> unsafe,
|
|
9
|
+
# everything else -> display-only
|
|
10
|
+
confidence_ceiling(locator), # exact -> safe, inferred -> unsafe,
|
|
11
|
+
# none -> display-only
|
|
12
|
+
blast_radius_ceiling(routes), # 1 route -> safe, <=20 -> unsafe,
|
|
13
|
+
# more or unknown -> display-only
|
|
14
|
+
surface_ceiling(finding_id), # protected surfaces are hard-capped
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
Only `min`. Every input can demote; none can promote. This is the load-bearing
|
|
18
|
+
idea in the whole design: a fix's safety is not a property of the rule, it is a
|
|
19
|
+
property of the rule PLUS how confidently the edit was located PLUS how far it
|
|
20
|
+
fans out. `seo.canonical.missing` is a constant-string edit and is catastrophic
|
|
21
|
+
when the head owner is a layout serving 10,000 routes.
|
|
22
|
+
|
|
23
|
+
There are three values and there will never be a fourth. Gradations invite the
|
|
24
|
+
argument that some fixes are "mostly safe"; theoretically any fix can be seen as
|
|
25
|
+
dangerous, even a whitespace one, and a fourth level just relocates the debate.
|
|
26
|
+
"""
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
from typing import Literal
|
|
30
|
+
|
|
31
|
+
from .registry import NEVER_APPLICABLE, PROTECTED_SURFACES, FixTier, tier_for
|
|
32
|
+
|
|
33
|
+
Applicability = Literal["safe", "unsafe", "display-only"]
|
|
34
|
+
|
|
35
|
+
# How sure the locator is that it found the right file. Declared here rather
|
|
36
|
+
# than in locator.py because it is one of the four inputs below, and this keeps
|
|
37
|
+
# locator -> applicability -> registry acyclic.
|
|
38
|
+
LocatorConfidence = Literal["exact", "inferred", "none"]
|
|
39
|
+
|
|
40
|
+
_RANK: dict[Applicability, int] = {"display-only": 0, "unsafe": 1, "safe": 2}
|
|
41
|
+
_BY_RANK: dict[int, Applicability] = {0: "display-only", 1: "unsafe", 2: "safe"}
|
|
42
|
+
|
|
43
|
+
TIER_CEILING: dict[FixTier, Applicability] = {
|
|
44
|
+
"mechanical": "safe",
|
|
45
|
+
"templated": "unsafe",
|
|
46
|
+
"drafted": "display-only",
|
|
47
|
+
"advisory": "display-only",
|
|
48
|
+
"infrastructure": "display-only",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
CONFIDENCE_CEILING: dict[LocatorConfidence, Applicability] = {
|
|
52
|
+
"exact": "safe",
|
|
53
|
+
"inferred": "unsafe",
|
|
54
|
+
"none": "display-only",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# A file serving exactly one route can carry a route-specific literal safely.
|
|
58
|
+
MAX_SAFE_BLAST_RADIUS = 1
|
|
59
|
+
# Beyond this many routes the edit stops being reviewable at all.
|
|
60
|
+
MAX_UNSAFE_BLAST_RADIUS = 20
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def blast_radius_ceiling(routes_served: int | None) -> Applicability:
|
|
64
|
+
"""How far the edit fans out, as a ceiling.
|
|
65
|
+
|
|
66
|
+
`None` means "we could not prove how many routes this file serves" -- which
|
|
67
|
+
is NOT the same as zero, and is treated as the worst case. Declining to
|
|
68
|
+
guess here is the difference between a self-canonical and a site collapsing
|
|
69
|
+
to one indexed page.
|
|
70
|
+
"""
|
|
71
|
+
if routes_served is None or routes_served < 1:
|
|
72
|
+
return "display-only"
|
|
73
|
+
if routes_served <= MAX_SAFE_BLAST_RADIUS:
|
|
74
|
+
return "safe"
|
|
75
|
+
if routes_served <= MAX_UNSAFE_BLAST_RADIUS:
|
|
76
|
+
return "unsafe"
|
|
77
|
+
return "display-only"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def surface_ceiling(finding_id: str) -> Applicability:
|
|
81
|
+
"""The hard cap protected surfaces impose, which no flag ever lifts."""
|
|
82
|
+
if finding_id in NEVER_APPLICABLE:
|
|
83
|
+
return "display-only"
|
|
84
|
+
if finding_id in PROTECTED_SURFACES:
|
|
85
|
+
return "unsafe"
|
|
86
|
+
return "safe"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def compute_applicability(finding_id: str, *, locator_confidence: LocatorConfidence,
|
|
90
|
+
routes_served: int | None) -> Applicability:
|
|
91
|
+
"""The minimum of every ceiling that applies to this finding-instance."""
|
|
92
|
+
ceilings = (
|
|
93
|
+
TIER_CEILING[tier_for(finding_id)],
|
|
94
|
+
CONFIDENCE_CEILING[locator_confidence],
|
|
95
|
+
blast_radius_ceiling(routes_served),
|
|
96
|
+
surface_ceiling(finding_id),
|
|
97
|
+
)
|
|
98
|
+
return _BY_RANK[min(_RANK[ceiling] for ceiling in ceilings)]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Write the MECHANICAL fixes `prescribe` previews: `omnirank apply` / `undo`.
|
|
2
|
+
|
|
3
|
+
`engine` decides and writes; `patch` applies diffs strictly; `journal` records
|
|
4
|
+
every write so it can be undone. See docs/apply.md.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from .engine import (
|
|
9
|
+
ApplyAborted,
|
|
10
|
+
Candidate,
|
|
11
|
+
Decision,
|
|
12
|
+
FileChange,
|
|
13
|
+
UndoRefused,
|
|
14
|
+
check_target,
|
|
15
|
+
decide,
|
|
16
|
+
plan,
|
|
17
|
+
preflight,
|
|
18
|
+
undo,
|
|
19
|
+
write,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = ["ApplyAborted", "Candidate", "Decision", "FileChange", "UndoRefused",
|
|
23
|
+
"check_target", "decide", "plan", "preflight", "undo", "write"]
|