runner

package
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 40 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package runner wires the crawl engine, analyzer registry, and report builder into a single entry point used by both the CLI and the MCP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRegistry

func BuildRegistry(fetcher crawler.Fetcher, opts RegistryOptions) *analyze.Registry

BuildRegistry constructs the default analyzer registry. The fetcher is used by analyzers that retrieve additional resources (e.g. the sitemap analyzer). opts turns on the opt-in analyzer modes; the zero value leaves every one of them off.

func Run

func Run(ctx context.Context, cfg config.Config, seed string, runOpts ...RunOption) (*report.Report, error)

Run performs a full crawl + analysis for the given config and seed, returning a Report. The seed argument overrides cfg.Seed when non-empty. runOpts add optional behavior (progress reporting, pause control) for callers that need it; the CLI passes none.

Types

type AnalyzerInfo

type AnalyzerInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

AnalyzerInfo describes one registered analyzer.

func ListAnalyzers

func ListAnalyzers() []AnalyzerInfo

ListAnalyzers returns metadata for every registered analyzer.

type Control

type Control struct {
	// contains filtered or unexported fields
}

Control pauses and resumes the crawl inside a Run started with WithControl. Run hides the engine, so Control forwards to it while the crawl phase runs. Calls before the crawl phase are queued (a pause made during the sitemap pre-pass takes effect when crawling starts); calls after it ends do nothing and return false.

Lock order: Control.mu is taken before the engine's locks (Pause and Resume emit a progress event while it is held). Nothing on the progress path takes Control.mu. Active takes no Control lock, but through Engine.ActiveTime it briefly takes the engine's ps.mu and then the activeClock's mutex, one after the other. A caller may therefore call Active while holding its own job lock (that adds a job lock → ps.mu edge, noted in the Engine lock order), but must not call Pause or Resume while holding a lock its progress callback takes.

func NewControl

func NewControl() *Control

NewControl returns a Control to pass to WithControl.

func (*Control) Active

func (c *Control) Active() time.Duration

Active reports the crawl's active time (pauses excluded): 0 before the crawl phase, live during it, frozen after it. Safe to call while holding any lock.

func (*Control) Pause

func (c *Control) Pause() bool

Pause pauses the crawl, or queues the pause if crawling hasn't started. It returns false once the crawl phase is over.

func (*Control) Resume

func (c *Control) Resume(rate float64) bool

Resume resumes a paused crawl at rate requests per second (0 keeps the current rate), or cancels a queued pause (a rate given then is kept and applied when crawling starts). It returns false once the crawl phase is over.

type Phase

type Phase string

Phase is the stage a Run is in.

const (
	PhaseSitemap   Phase = "sitemap"   // discovery pre-pass, before the crawl
	PhaseCrawling  Phase = "crawling"  // Engine.Crawl is running
	PhaseAnalyzing Phase = "analyzing" // analyzers and report building
)

type Progress

type Progress struct {
	crawler.Progress
	Phase Phase `json:"phase"`
	// SitemapFound is true when the pre-pass parsed a sitemap. SitemapTotal counts its
	// in-scope URLs; SitemapFetched counts the distinct ones fetched so far.
	SitemapFound   bool `json:"sitemap_found"`
	SitemapTotal   int  `json:"sitemap_total"`
	SitemapFetched int  `json:"sitemap_fetched"`
	// OffSitemap is Fetched - SitemapFetched: fetched pages the sitemap doesn't list.
	OffSitemap int `json:"off_sitemap"`
	// InSitemap reports whether CurrentURL (or where it redirected) is in the sitemap.
	InSitemap bool `json:"in_sitemap"`
}

Progress is crawler.Progress plus the run phase and progress against the site's sitemap.

func (Progress) TapeOffChar

func (p Progress) TapeOffChar() byte

TapeOffChar is the tape_off character for the page this event reports. The web server builds the live tape_off with it; Run builds Coverage.TapeOff with the same rule.

type RegistryOptions added in v0.5.0

type RegistryOptions struct {
	// Specialized enables the lower-confidence AI-search heuristics (AEO direct-answer-lead,
	// GEO quotable-density), the WordPress analyzer's active endpoint probes, and the Shopify
	// analyzer's /products.json probe.
	Specialized bool
	// SecurityAudit enables the security analyzer's TLS, certificate, and cookie audit.
	SecurityAudit bool
	// IgnoreExternalTagging suppresses the utm analyzer's tagging-quality warnings for
	// links leaving the crawled domain. Unlike the other fields it is on by default in
	// config (analyzers.ignore_external_tagging); the struct's zero value turns it off.
	IgnoreExternalTagging bool
	// SitemapOptions configure the sitemap analyzer. runner.Run passes sitemap.WithURLs here
	// so the analyzer reuses the pre-pass's sitemap instead of fetching it again.
	SitemapOptions []sitemap.Option
}

RegistryOptions turns on the analyzer modes that are off by default. Each corresponds to a config flag under `analyzers`; they are grouped here so adding one doesn't grow BuildRegistry's parameter list into a row of anonymous booleans.

type RunOption

type RunOption func(*runSettings)

RunOption customizes one Run call. The CLI and MCP server call Run without any; the web server uses options for what only it needs (live progress, pause and resume), so Run's signature stays the same for every caller.

func WithControl

func WithControl(c *Control) RunOption

WithControl lets the caller pause and resume this Run's crawl through c.

func WithPauseOnThrottle

func WithPauseOnThrottle() RunOption

WithPauseOnThrottle makes the crawl pause itself after sustained 429/503 responses (see crawler.Options.PauseOnThrottle). Only for callers that can resume it, like the web UI.

func WithProgress

func WithProgress(fn func(Progress)) RunOption

WithProgress makes Run report progress to fn: one call per phase change, one per page the crawl records, and one per pause or resume, serialized and in order. fn runs on crawl goroutines (or, for a pause or resume, on the goroutine that asked for it) while the engine holds its locks, so it must return quickly and must not call a Control method.

type SitemapPreview

type SitemapPreview struct {
	Found     bool     `json:"found"`
	Total     int      `json:"total"`   // in-scope sitemap URLs
	Sources   []string `json:"sources"` // sitemap files that parsed, sorted; never null
	ViaRobots bool     `json:"via_robots"`
}

SitemapPreview is what the sitemap pre-pass would find for a crawl, without crawling.

func PreviewSitemap

func PreviewSitemap(ctx context.Context, cfg config.Config, seed string) (SitemapPreview, error)

PreviewSitemap runs only the sitemap discovery step for cfg and seed: the same robots.txt handling, User-Agent, rate limit and scope rules a crawl would apply. Errors are config errors (bad regex, bad seed); a missing sitemap is Found == false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL