Skip to main content
The module github.com/sightmap/sightmap/go contains the packages used by the sightmap CLI. Snapshot enrichers, analysis programs, and other Go tools can import the same component model and matcher.
Requires Go 1.25.2 or later.

Design goals

  • Shared component model and matcher. The comps and match packages give consumers the same types and matching logic.
  • Tree-level matching. Matching operates on a component tree whose nodes carry SelectorPart values. This supports offline analysis of saved trees and synthetic selectors for native-mobile nodes.
  • Embedded browser probe. The probe package exposes the browser-side probe.js source as probe.ProbeJS, including its bounds, visibility, and interactivity logic.

Package map

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

Load a corpus and match a tree

The core flow uses two API calls. sightmap.Load parses a .sightmap/ directory into a Corpus (a thread-safe handle with a compiled-query cache), and Corpus.MatchTree applies it to a component tree for a page URL.
main.go
MatchTree returns map[*comps.ComponentNode]*match.SightmapMatch. Each match contains the component Name and Memory notes. The library selects the most specific view whose route matches the URL pathname, using declaration order only to break equal-specificity ties (per the stream 1 spec). Trailing slashes on the URL path are normalized away before matching. If no view matches, global components still apply.

The Corpus handle

sightmap.Corpus is the single operational handle: load one with Load, then hold it for the life of a run. It is safe for concurrent use and caches compiled match queries by page URL, so repeated MatchTree calls reuse the compiled queries. To pick up on-disk edits in a long-lived process, call Load again and swap the handle. Load(dir) is shorthand for DirLoader(dir).Load(). For an existing in-memory corpus, StaticLoader(c *Corpus) Loader wraps it as a Loader; the LoaderFunc type, func() (*Corpus, error), also implements Loader. Per-site tooling defaults (.sightmap/config.yaml) load separately via sightmap.LoadConfig(dir) SiteConfig — this is tooling configuration, not part of the spec.

Validate and lint from Go

The Validate and Lint functions run the same checks as sightmap validate and sightmap lint:
LintWithCounts(c *Corpus, counts map[string]int) []LintWarning adds per-component match counts to lint results. The CLI uses it for sightmap lint --snapshot and sightmap lint --all-snapshots.

Where component trees come from

  • Saved captures. Auto-organized captures under .sightmap/snapshots/{view}/ include a sibling .snap.tree.json file containing the raw ComponentNode tree. sightmap snapshot --tree-out FILE writes the tree to an explicit path. Unmarshal either form into *comps.ComponentNode, as in the example above.
  • Live pages. Call browser.Connect(addr, tabID) to attach to a running session’s tab, then pass a browser.Page to browser.ExtractComponents — or use the higher-level observe.Page, which connects, extracts, matches the corpus, and computes coverage in one call.
  • Custom extraction. Call extract.BuildTree with probe, accessibility, and DOM data. Native consumers can create SelectorPart values for non-DOM trees.
The conformance directory includes component-tree fixtures, flat sightmap definitions, and expected matches. Use them to compare another implementation with the Go matcher. See Conformance fixtures.