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.
Design goals
- Shared component model and matcher. The
compsandmatchpackages give consumers the same types and matching logic. - Tree-level matching. Matching operates on a component tree whose nodes carry
SelectorPartvalues. This supports offline analysis of saved trees and synthetic selectors for native-mobile nodes. - Embedded browser probe. The
probepackage exposes the browser-sideprobe.jssource asprobe.ProbeJS, including its bounds, visibility, and interactivity logic.
Package map
All import paths are rooted atgithub.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
TheValidate 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.jsonfile containing the rawComponentNodetree.sightmap snapshot --tree-out FILEwrites 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 abrowser.Pagetobrowser.ExtractComponents— or use the higher-levelobserve.Page, which connects, extracts, matches the corpus, and computes coverage in one call. - Custom extraction. Call
extract.BuildTreewith probe, accessibility, and DOM data. Native consumers can createSelectorPartvalues 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.Related
- CLI overview: the commands built on these packages
- Curator vs. consumer: where a library consumer fits
- Schema reference: the YAML format