033 — Plugin-Based Domain Parsers (no host hardcode in core)¶
Status: ACCEPTED Date: 2026-06-18 Extends: 008-declarative-career-site-extraction.md, 021-career-site-monitor-scraper-split.md, 022-cloakbrowser-advanced-bypass.md Closes: Hard rule "no hardcoded domain-specific hosts in core composition" (AGENTS.md).
Context¶
Three places in infrastructure/sources/ contain hardcoded if/elif branches keyed on
hostname or substring match against a URL:
site_defaults.py:10-60— five host-specific blocks (career.habr.com,hh.ru,hh.kz,yandex.ru + /jobs,www.tbank.ru + /career,ozon.tech + /vacancies). Each block picks aurl_filter,waitstrategy,include_if_detail_pageflag, etc.declarative.py:70-77—if spec.parser_kind == "greenhouse" or ("greenhouse.io" in url.lower())and a parallel block foralfabank.ru.monitors/greenhouse.py:103-108—if host == "boards-api.greenhouse.io"/if host == "boards.greenhouse.io".
AGENTS.md explicitly forbids "hardcoded domain-specific hosts or parser switches" in
config.py and by spirit anywhere in core composition. The current code violates that
rule, and each new site is a code change to infrastructure/, not a config change.
ADR-008 already introduced the declarative path (CareerSiteConfig + selector-based
extraction) but kept the URL → parser dispatch in Python if/elif. ADR-021 split
monitor/scraper but did not address URL → site_specific_parser routing. ADR-022 wired
CloakBrowser as one tier of the bypass chain. None of them addressed the per-site
runtime defaults (wait strategies, url_filter regex, render flag).
Decision¶
Replace all three host-keyed dispatch sites with a single registry:
@register_site_parser(
"habr_career",
domain_pattern=r"^https?://career\.habr\.com/",
version="1.0",
requires_extras=(),
)
def _habr_defaults(url: str) -> SiteRuntimeDefaults:
return SiteRuntimeDefaults(
url_filter=r"career\.habr\.com/vacancies/\d{5,}",
render=False,
wait="domcontentloaded",
)
Concretely:
- New Protocol
SiteParserinapplication/contracts.py—match(url) -> bool,runtime_defaults(url) -> SiteRuntimeDefaults. - New
register_site_parser(name, *, domain_pattern, version, requires_extras=())decorator inapplication/registry.py. Mirrors@register_parsershape. CareerSiteSpecgains an optionalsite_parser: str | None = Nonefield. If set, the named site parser is looked up viaresolve_site_parser(url). IfNoneand the URL matches a registered site parser'sdomain_pattern, that one is auto-picked.apply_runtime_defaults(spec)insite_defaults.pybecomes a thin wrapper:parser = resolve_site_parser(spec.url); return parser.runtime_defaults(spec.url) if parser else spec.declarative.py:70-77andmonitors/greenhouse.py:103-108either:- register their known URLs as
site_parser("greenhouse_board_api", domain_pattern=...)/site_parser("alfabank_career", ...)and route through the registry, or - keep the small per-monitor dispatch where it is a documented domain-specific optimization (with a unit test pinning the host).
config/sources.schema.jsonaddssite_parser: string | nullto thecareer_siteoneOf branch.config/all_sources_full.yamlships one example usingsite_parser: habr_careerto document the convention.
Consequences¶
- (+) Zero
if/elif host == ...ininfrastructure/. All dispatch is inapplication/registry.pyand goes through the sameregister_*decorator shape used by every other protocol. - (+) Adding a site = a new
@register_site_parserin a plugin module, or one YAML entry. No core code change. - (+) CI module-boundary check (
scripts/check_module_boundaries.py) can grow a rule "no string equality on URL hosts insideinfrastructure/". - (=) ADR-008 declarative path is unchanged; site parsers are a thinner layer on top.
- (=) ADR-021 monitor/scraper split is unchanged; site parsers only own URL-level runtime defaults, not discovery/extraction logic.
- (-) One more registry to keep documented;
site_parsers/gets a newregistry.pyand one example plugin per known site. - (-)
config/sources.schema.jsonmigration: existing YAMLs still work (site_parser is optional), but downstream tooling should learn the new field.