infrastructure capa

infrastructure-dom-reduce

Bounded structural reduction of HTML: keeps tags and the attributes selectors are built from, drops script/style/svg/noscript/template/iframe subtrees and comments entirely, and truncates every text node and kept attribute value. Two jobs at once — it makes a large page fit a small model's context, and it is the mechanism that keeps page CONTENT (conversation text, identifiers) out of whatever reads the result. Built on lol_html (Cloudflare's streaming HTML rewriter) rather than a hand-rolled parser.

Bounded structural reduction of HTML: keeps tags and the attributes selectors are built from, drops script/style/svg/noscript/template/iframe subtrees and comments entirely, and truncates every text node and kept attribute value. Two jobs at once — it makes a large page fit a small model's context, and it is the mechanism that keeps page CONTENT (conversation text, identifiers) out of whatever reads the result. Built on lol_html (Cloudflare's streaming HTML rewriter) rather than a hand-rolled parser.

Tierinfrastructure
Roleunclassified (baselined)
Pathcrates/infrastructure/dom-reduce
Edition2021
Targetsinfrastructure_dom_reduce, large_page
Public items4 across 0 modules
Tests18

What it is for

Bounded structural reduction of HTML.

# Why this exists

Two problems with one shape. A captured page is large — the live capture that motivated this crate was 2 MB, overwhelmingly CSS and inline data. A local 7B model has a few thousand tokens of usable context. And a page's text is the part that must not travel: conversation content, account identifiers, client material.

Both are solved by keeping the skeleton and discarding the flesh. Selectors are built from tag names and a small set of attributes; none of them need the text. So this keeps structure, truncates every text node and attribute value hard, and drops whole subtrees that are pure noise for selector purposes.

# Why lol_html

This estate does not hand-roll what a library already does (Gate 0.5). A first draft of this crate hand-rolled an HTML tokenizer; it was deleted unbuilt. lol_html (Cloudflare's streaming HTML rewriter, CSS-selector based) is the library crate: it already parses real-world HTML correctly, including cases a bounded tokenizer regex-walk gets wrong (nested quotes, self-closing rules, CDATA, encoding). Reduction happens as a rewrite pass — element/text handlers that drop or truncate — rather than a second parse.

# What "bounded" means here

Three caps, in the order they can fire. max_input_bytes (8 MB) cuts the input on a character boundary before the parser sees any of it, so no amount of pathological markup makes reduction unbounded in time; it leaves roughly 4x headroom over the 2 MB capture this crate was built for, because a backstop that fires on the design case is a working limit in disguise. Then:

The input is fed to the rewriter in fixed-size chunks rather than in one call. After every chunk, output size is checked against max_output_bytes; once it is met or exceeded, feeding stops without finishing the document — the remainder of a pathological or enormous input is never processed. A max_allowed_memory_usage backstop on the rewriter itself guards against a single buffered token (e.g. one absurdly long unterminated tag) blowing past the output cap before a chunk boundary is even reached. That backstop is configured to error, never to bail out gracefully: lol_html's graceful bail-out stops rewriting and passes the remaining input through verbatim — measured at 8 KB of a raw attribute value reaching the output, with nothing for reduce to observe. Any early stop — input cut, output cap, memory backstop, or a parser error — sets Reduction::truncated. A silent cap reads as "this is the whole page", which is how a model gets asked about markup it never saw.

# What it is not

Not a sanitizer. It reduces exposure by discarding, but a truncated text node or attribute value still carries its first characters. Treat the output as sensitive, just far less so than the input.

# Measured reduction

Against the generated page in tests/large_page.rs — 792 KB, deep nesting, over-long attributes, interleaved script/style — the default ReduceConfig cuts output to the 60 KB cap, a 92% reduction, dropping 251 elements while truncating 126 text nodes and 125 attribute values. Run the test to reproduce those figures; it prints them.

The input is generated rather than captured, deliberately: a committed "real page" fixture is where a browser capture carrying conversation content or a logged-in sidebar eventually lands. See the note at the top of that test.

No number is recorded here for a real 2 MB SPA capture — the workload this crate was built for. Such a page is expected to reduce further, since subtree-dropping and attribute-filtering carry more of the load when the mass is inline CSS and data rather than text. That remains an expectation, not a measurement, until one is measured.

Capabilities

crate root

Bounded structural reduction of HTML.

Item
fn reduce(html : & str, cfg : & ReduceConfig) -> Reduction

ReduceConfig

Bounded structural reduction of HTML.

Item
pub struct ReduceConfig
ReduceConfig :: fn default() -> Self

Reduction

Bounded structural reduction of HTML.

Item
pub struct Reduction

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

No public modules: the crate root is its whole surface.

Public surface

`crate root`

ItemWhat it is
pub struct ReduceConfigTuning
ReduceConfig :: fn default() -> Self
pub struct ReductionThe result, with the counts that make the reduction auditable.
fn reduce(html : & str, cfg : & ReduceConfig) -> ReductionReduce html to its selector-relevant skeleton.

No pub use re-exports: every item above is declared in this crate.

Boundary

Depends on no other workspace tier.

Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)infrastructure
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/infrastructure/dom-reduce
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
lol_html^3.0.1noalways

Development. None.

Build. None.

Depended on by. Nothing in this workspace.

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
libinfrastructure_dom_reduce`src/lib.rs`
testlarge_page`tests/large_page.rs`

Error model

No public error type was detected: no public item declares a type named *Error, and no public signature returns one.

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

No workspace crate depends on this one.

Verification

KindCount
Unit tests17
Integration tests1
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root300

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc34
Public modules with a //! block00
pie showData
    title Public items with rustdoc
    "Documented" : 3
    "No rustdoc detected" : 1

Metrics

MetricValue
Rust source files1
Source lines569
Code lines374
Public API items4
Public modules0
Tests18
Examples0
Cargo features0
Direct runtime dependencies1
Workspace reverse dependencies0
pie showData
    title Public API by kind
    "function" : 1
    "method" : 1
    "struct" : 2
pie showData
    title Rust source composition
    "Code" : 374
    "Blank or comment" : 195

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

Todas las infrastructure · Manual