Documentation
¶
Overview ¶
Package capture plays a scripted scenario against a painter-drawn scene and records every step as a frame of one animated, resolution-independent SVG (and, through the player page or the capture/webm subpackage, as an HTML page or a video of the same frames). It is the harness behind "agentscope capture": the scene and its steps are the caller's, the recording, the glyph outlines, the output formats and the safe file writing are here.
A capture is deterministic: the same scene and steps give the same bytes on every machine, whatever its time zone (see Options.Zone). This package pulls in no video encoder; capture/webm holds that.
Index ¶
- Constants
- func DefaultOutDir(app string) (string, error)
- func HTML(r *Result, title, lang string) ([]byte, error)
- func InsideGitTree(p string) (bool, error)
- func ParseSize(s string) (w, h int, err error)
- func RefuseGitTree(out string) error
- func ResolveFormat(format, out string) (string, error)
- func Size(w, h int) (int, int, error)
- func WriteFile(out string, data []byte) error
- type Options
- type Result
- type Scene
- type Step
Constants ¶
const ( MinSize = 320 MaxSize = 4096 )
Size bounds: a capture is a picture of a window, not an allocation attack.
const ( FormatSVG = "svg" FormatWebM = "webm" FormatHTML = "html" )
Format names.
const DefaultSize = "1280x720"
DefaultSize is the captured window, in logical pixels, when none is given.
Variables ¶
This section is empty.
Functions ¶
func DefaultOutDir ¶
DefaultOutDir is the durable directory captures of app go to: under the user's config directory, never inside a repository.
func HTML ¶
HTML wraps a recording in the self-contained player page of this module: the same SVG, inlined, with play/pause, a seek bar and the keyboard controls. lang is the page chrome's language ("en" or "fr").
func InsideGitTree ¶
InsideGitTree reports whether p, or a directory above it, holds a .git.
func RefuseGitTree ¶
RefuseGitTree is the guard every writer shares: it refuses a path inside a git work tree, and a path it cannot place. A caller runs it before an expensive render, so the refusal costs nothing.
func ResolveFormat ¶
ResolveFormat settles the output format from --format and the --out path. An empty format is inferred from the extension (.svg, .webm or .html) and is svg when the path has neither; a named format must not contradict a known extension.
Types ¶
type Options ¶
type Options struct {
// W and H are the window, in logical pixels, each MinSize to MaxSize. Both
// zero means DefaultSize.
W, H int
// Title is the document's <title>.
Title string
// Zone is the location the process-wide time.Local is pinned to while the
// steps run and the scene is drawn: a scene that writes times with
// time.Local (or a library that does) then gives the same bytes on every
// machine. nil means UTC. A live window never goes through Run and keeps
// its own zone.
Zone *time.Location
}
Options tune Run. The zero value is DefaultSize in UTC with no title.
type Result ¶
type Result struct {
SVG []byte
Frames int // frames recorded, one per step
Duration time.Duration // the loop length
Stats svg.Stats // the assembly: slots, pictures, shared subtrees, sizes
Raster int // elements that embed a PNG; 0 means fully vector
Doc *svg.Document // the assembly, whose Frame(i) is the still of slot i
Texts []string // every distinct string drawn: the outlines hide them from a text scan
Observed []int // what Run's observe returned after each step; nil without one
}
Result is one recorded scenario.
func Run ¶
func Run[E any](setup func() (Scene, E), steps []Step[E], o Options, observe func(E) int) (*Result, error)
Run plays steps against the scene and state that setup returns: each step's Do runs, the scene is recorded as one frame with its text as glyph outlines, and the frame is held for the step's Hold. The frames are assembled into one animated SVG. o.W and o.H, settled by Size, are the window the scene must be built at. setup is called once, after the zone is pinned and the size validated, so a scene that reads time.Local while it is built is as reproducible as one that reads it while it draws. observe, when non-nil, is called after each Do and its value kept in Result.Observed (a language selector, a page number: whatever a caller wants to know about each frame). Run reads no clock, file or network.