watch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package watch turns dsecrat's one-shot analysis into continuous monitoring. It re-runs the engine against a target on an interval, diffs each run against the previous one, and emits only the *delta* — findings that newly appeared or cleared — through the normal connectors. This is what makes the spec's "continuous re-scan / drift / clean-yesterday-vulnerable-today" controls real without adding any new detection logic: the modules are unchanged, only the scheduling and diffing are new.

The core is split so it stays testable with zero wall-clock dependence:

  • Diff is a pure function over two reports.
  • Run performs a single scan+diff+dispatch cycle.
  • Loop drives Run on a caller-supplied tick channel and stops on context cancellation, so a test can feed synthetic ticks and assert deterministic behavior; the CLI supplies a real time.Ticker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delta

type Delta struct {
	New     []engine.Finding
	Cleared []engine.Finding
}

Delta is the difference between two consecutive scans: findings that appeared this run (New) and findings present last run but gone now (Cleared).

func Diff

func Diff(prev, cur *engine.Report) Delta

Diff computes the New/Cleared delta between a previous and current report. A nil previous report means every current finding is New (the first run). The returned slices are sorted most-severe-first for stable, readable output.

func (Delta) Changed

func (d Delta) Changed() bool

Changed reports whether the delta carries any change at all.

type EngineScanner

type EngineScanner struct {
	Engine  *engine.Engine
	Target  *engine.Target
	Modules []string
}

EngineScanner adapts an engine + target into a Scanner, running the named modules (empty = all).

func (EngineScanner) Scan

func (e EngineScanner) Scan(ctx context.Context) *engine.Report

Scan runs one analysis pass.

type Observer

type Observer interface {
	OnCycle(rep *engine.Report, d Delta)
}

Observer is notified after every cycle, whether or not the delta changed. The CLI uses it to print a heartbeat line; tests use it to record cycles.

type ObserverFunc

type ObserverFunc func(rep *engine.Report, d Delta)

ObserverFunc adapts a function to Observer.

func (ObserverFunc) OnCycle

func (f ObserverFunc) OnCycle(rep *engine.Report, d Delta)

OnCycle implements Observer.

type Scanner

type Scanner interface {
	Scan(ctx context.Context) *engine.Report
}

Scanner produces a report for the watched target. It abstracts the engine so tests can inject a deterministic sequence of reports.

type Watcher

type Watcher struct {
	Scanner    Scanner
	Connectors []connector.Connector
	Observer   Observer

	// OnlyDeltas, when true (the default behavior chosen by the CLI), dispatches
	// to connectors only when the delta is non-empty, so a stable target stays
	// quiet. When false, every cycle's full report is dispatched.
	OnlyDeltas bool
	// contains filtered or unexported fields
}

Watcher runs continuous monitoring over one target.

func (*Watcher) Loop

func (w *Watcher) Loop(ctx context.Context, tick <-chan time.Time) int

Loop drives Run once immediately, then once per received tick, until the context is cancelled. The tick channel is injected so production passes a time.Ticker.C while tests pass a hand-fed channel — the loop itself contains no clock. It returns the number of cycles completed.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) Delta

Run performs exactly one scan+diff+dispatch cycle and returns the delta. It is the unit of work Loop repeats; calling it directly is how tests exercise a deterministic sequence without any timing.

Jump to

Keyboard shortcuts

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