Skip to main content
The module github.com/sightmap/sightmap/go is the reference implementation behind the sightmap CLI — and it’s importable. Consumers such as snapshot enrichers, analysis scripts, and custom agents use the library directly instead of re-implementing component matching, so semantics can’t diverge between tools.
Requires Go 1.25.2+.

Design goals

  • One canonical component model and rule matcher. Downstream consumers import this library rather than re-implementing matching.
  • Tree-level matching, not DOM queries. Matching operates against a component tree — every node carries a SelectorPart — rather than via document.querySelectorAll. That enables offline analysis of exported snapshots and native-mobile compatibility via synthetic selectors.
  • One canonical probe. The browser-side extractor (cdp-probe.js) is embedded once, in the probe package; consumers embed it from there so bounds, visibility, and interactivity logic cannot diverge.

Package map

All import paths are rooted at github.com/sightmap/sightmap/go/.

Load a corpus and match a tree

The core flow is three calls: DirLoader points at a .sightmap/ directory, NewSession wraps it in a compiled-query cache, and MatchTree applies the corpus to a component tree for a page URL.
main.go
MatchTree returns map[*comps.ComponentNode]*match.SightmapMatch — each match carries the component Name and its Memory notes. The view is selected from the URL’s pathname using the same most-specific-wins route matching the CLI uses; if no view matches, global components still apply.

Sessions

sightmap.Session is safe for concurrent use. It caches compiled match queries per (corpus generation, page URL) pair, so repeated MatchTree calls against the same URL are cheap. Useful methods beyond MatchTree: Besides DirLoader, the package provides StaticLoader (wrap an already-built *Corpus) and LoaderFunc (adapt any func() (*Corpus, error)) — handy for tests and for corpora that don’t live on disk.

Validate and lint from Go

The same checks behind sightmap validate and sightmap lint are plain functions:
LintWithCounts augments lint with real per-component match counts from a snapshot, which is how sightmap lint --snapshot works.

Where component trees come from

  • Saved captures — every capture under .sightmap/snapshots/{view}/ has a sibling .snap.tree.json file holding the raw ComponentNode tree; sightmap snapshot --tree-out FILE writes one anywhere you like. Unmarshal it straight into *comps.ComponentNode as in the example above.
  • Live pages — the browser package dials a Chrome debugging port (DialCDP), and ExtractComponents runs the embedded probe against a page to produce the same tree shape.
  • Your own extraction — the extract package builds a tree from raw probe and accessibility data with no browser dependency, and native consumers can synthesize SelectorPart values for non-DOM trees.
The conformance package ships tree-plus-corpus fixtures with expected matches. If you build a matching consumer in another language, run them to prove your semantics agree with the reference implementation — see Conformance fixtures.