record

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 46 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 record keeps a replayable record of each Daisybell session: a timeline of what the AI did (events.jsonl: actions with their why, target box and cursor path, approvals, handoffs, human take-overs) plus pictures (a thumbnail per action by default, a 5-8 fps screencast on demand), and exports it as a self-contained HTML replay, a GIF or an MP4. See docs/RECORDING.md.

Privacy by default: credential fields (passwords, card numbers, one-time codes, payment iframes) are pixelated in every stored picture, a picture is dropped when they can't be located, and nothing is captured while the human drives unless asked to.

Index

Constants

View Source
const (
	EntryAction  = "action"  // an activity event (before / after)
	EntryCursor  = "cursor"  // the ghost cursor travels From → To in Ms
	EntryFrame   = "frame"   // a screencast frame (File)
	EntryThumb   = "thumb"   // the picture of an action (ID, File)
	EntryRequest = "request" // the AI asked the human: approval, handoff, question
	EntryAnswer  = "answer"  // the human's answer (never secret values)
	EntryHuman   = "human"   // the human took over (Driving true) or handed back
	EntryMode    = "mode"    // recording mode changed
	EntryNote    = "note"    // something about the recording itself (size cap reached…)
)

Entry types of events.jsonl.

View Source
const (

	// DefaultMaxTotal is the default cap on all recordings together.
	DefaultMaxTotal = 1 << 30
)

Variables

View Source
var ErrNoFFmpeg = errors.New("ffmpeg not found")

ErrNoFFmpeg is returned for MP4 when ffmpeg is not installed.

View Source
var RedactColor = color.RGBA{R: 0x1d, G: 0x23, B: 0x30, A: 0xff}

RedactColor is the solid colour painted over a hidden field in a screenshot.

Functions

func Cover

func Cover(data []byte, png bool, boxes [][4]float64, cssWidth float64) ([]byte, int, error)

Cover paints boxes solid RedactColor over an encoded picture and re-encodes it in the same format (PNG when png, else JPEG). Boxes are in CSS px from the picture's top-left corner, the picture showing cssWidth CSS px across (its pixels may be denser). It returns data unchanged when no box falls inside the picture.

func DirSize

func DirSize(dir string) int64

DirSize is the total size of the regular files under dir.

func ExportGIF

func ExportGIF(ctx context.Context, rec *Recording, out string) (string, error)

ExportGIF writes an animated GIF (pure Go, no ffmpeg needed) with the captions burned in.

func ExportHTML

func ExportHTML(rec *Recording, out string) (string, error)

ExportHTML writes the session's replay page to out (default <session>/replay.html) and returns its path. The page is self-contained: styles, script, brand tokens and (up to inlineCap) every picture are inside the one file. When the session is one part of a server run, the page links the run's other parts, whose replays are written next to theirs first if they don't exist yet.

func ExportMP4

func ExportMP4(ctx context.Context, rec *Recording, out string) (string, error)

ExportMP4 writes an H.264 MP4 through ffmpeg (ErrNoFFmpeg when it isn't installed). The captions are drawn by Daisybell, so any ffmpeg build works (no libfreetype/libass needed).

func FFmpegPath

func FFmpegPath() string

FFmpegPath returns ffmpeg's path, or "" when it isn't installed.

func MaskJPEG

func MaskJPEG(data []byte, p Probe, g FrameGeom, maxW int) ([]byte, int, image.Point, error)

MaskJPEG pixelates the probe's boxes in a JPEG and re-encodes it, scaling it down to maxW pixels wide first when it is wider (0: keep). It returns the input unchanged (and 0) when there is nothing to mask or scale.

func MaskRects

func MaskRects(p Probe, g FrameGeom, w, h int) []image.Rectangle

MaskRects maps the probe's boxes onto an image of w×h pixels showing the frame g. Boxes are shifted by any scroll between probe and frame, padded, and clipped to the image.

func Pixelate

func Pixelate(img draw.Image, rects []image.Rectangle)

Pixelate replaces each rectangle with coarse blocks (a block per ≈ the rect's height, at least 12 px), so text and digit shapes are gone, not just softened.

func RegisterTools

func RegisterTools(s *mcp.Server, r *Recorder, declare func(name string, readOnly bool))

RegisterTools adds the record tool. declare is told the tool's class (read-only: it never touches the page, so it works while the human has paused or drives).

func RenderHTML

func RenderHTML(rp *Replay) (string, error)

RenderHTML fills the replay template.

Types

type Clock

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

Clock compresses idle time: it maps the sorted real times of a recording onto playback time.

func NewClock

func NewClock(times, anchors []int64) Clock

NewClock builds the mapping from the event times (any order). Anchors are the real start times of actions: in playback consecutive anchors are at least minStep apart, so a burst of fast actions (turbo speed, no Cockpit) stays readable.

func (Clock) At

func (c Clock) At(t int64) int64

At maps a real time to playback time (between two events time runs at 1×, capped by the next).

func (Clock) Skipped

func (c Clock) Skipped() int64

Skipped is the real idle time compressed away.

type Entry

type Entry struct {
	T    int64  `json:"t"`
	Type string `json:"type"`

	ID     string           `json:"id,omitzero"`
	Phase  string           `json:"phase,omitzero"`
	Kind   string           `json:"kind,omitzero"`
	Action string           `json:"action,omitzero"`
	Why    string           `json:"why,omitzero"`
	Tab    string           `json:"tab,omitzero"`
	Target *activity.Target `json:"target,omitzero"`
	Value  string           `json:"value,omitzero"`
	Result string           `json:"result,omitzero"`
	Error  string           `json:"error,omitzero"`

	// frame / thumb: the image file (relative to the session) and its size in pixels; VW/VH is
	// the viewport in CSS px (so boxes and points can be scaled onto the image).
	File   string  `json:"file,omitzero"`
	W      int     `json:"w,omitzero"`
	H      int     `json:"h,omitzero"`
	VW     float64 `json:"vw,omitzero"`
	VH     float64 `json:"vh,omitzero"`
	Masked int     `json:"masked,omitzero"` // credential areas pixelated in this picture

	// cursor
	From *activity.Point `json:"from,omitzero"`
	To   *activity.Point `json:"to,omitzero"`
	Ms   int64           `json:"ms,omitzero"`

	// request / answer / human / mode / note
	Risk     string `json:"risk,omitzero"`
	Name     string `json:"name,omitzero"`
	Question string `json:"question,omitzero"`
	Decision string `json:"decision,omitzero"`
	Via      string `json:"via,omitzero"`
	Driving  *bool  `json:"driving,omitzero"`
	Mode     Mode   `json:"mode,omitzero"`
	Text     string `json:"text,omitzero"`
}

Entry is one line of events.jsonl. T is milliseconds since the session started.

type FrameGeom

type FrameGeom struct {
	DeviceWidth, DeviceHeight float64
	ScrollX, ScrollY          float64
	OffsetTop                 float64
	// Known says ScrollX/ScrollY are real (screencast metadata); screenshots are taken right
	// after the probe, at its scroll position.
	Known bool
}

FrameGeom places a picture on the page: the viewport it shows in CSS px, its scroll offset and the top offset of the content (Page.screencastFrame metadata; zero for screenshots).

type Meta

type Meta struct {
	ID      string    `json:"id"`
	Started time.Time `json:"started"`
	Ended   time.Time `json:"ended,omitzero"`
	Mode    Mode      `json:"mode"`
	Agent   string    `json:"agent,omitzero"`
	Version string    `json:"version,omitzero"`
	// Overlay is true when the Cockpit overlay (ghost cursor, ring, captions) is drawn in the
	// pictures themselves, so the replay doesn't draw its own on top.
	Overlay bool  `json:"overlay"`
	Frames  int   `json:"frames"`
	Bytes   int64 `json:"bytes"`
	// Run is the server run the session belongs to (the first session's id); Part is its number
	// in that run. A run is split into one session per task (a new plan, or a long idle gap).
	Run  string `json:"run,omitzero"`
	Part int    `json:"part,omitzero"`
	// Task is the task the session recorded: the first step of the AI's plan.
	Task string `json:"task,omitzero"`
}

Meta is meta.json.

type Mode

type Mode string

Mode says how much is recorded.

const (
	// ModeOff records nothing.
	ModeOff Mode = "off"
	// ModeTimeline records events and one thumbnail per action (the default: cheap, private).
	ModeTimeline Mode = "timeline"
	// ModeFull also records a screencast while the AI acts (opt-in: --record full or the tool).
	ModeFull Mode = "full"
)

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode parses --record.

type Options

type Options struct {
	Store Store
	// Mode is the starting mode (default timeline).
	Mode Mode
	// RecordHuman keeps capturing while the human drives (default: paused, for privacy).
	RecordHuman bool
	Pages       Pages
	// Human reports whether the human has taken over (the Cockpit; optional).
	Human interface{ Driving() bool }
	// FPS caps stored screencast frames per second (default 6, at most 8).
	FPS int
	// MaxWidth caps the screencast frame width in pixels (default 1280).
	MaxWidth int
	// ThumbWidth is the width of action thumbnails (default 960).
	ThumbWidth int
	// Tail keeps the screencast running after the AI's last action (default 1.5 s).
	Tail time.Duration
	// Overlay says the Cockpit overlay is drawn in the pictures.
	Overlay bool
	Version string
	// Agent names the AI (for the replay title); optional.
	Agent func() string
	// IdleSplit starts a new session (a new part of the run) when the AI acts again after this
	// long without acting (default 10 minutes; a new plan starts one too: NewTask).
	IdleSplit time.Duration
	// Typed is what the human typed in handoffs (shared with the tools): fields holding those
	// values are masked like credential fields (optional).
	Typed *guard.Typed
	// OnThumb is told when an action's thumbnail is on disk (the Cockpit's feed shows it).
	OnThumb func(session, id, rel string)
	Logger  *slog.Logger
	Now     func() time.Time
}

Options configures a Recorder.

type Pages

type Pages interface {
	Tab(id string) *browser.Tab
}

Pages finds the browser tab behind a short tab id (t1).

type PagesFunc

type PagesFunc func(id string) *browser.Tab

PagesFunc adapts a function to Pages.

func (PagesFunc) Tab

func (f PagesFunc) Tab(id string) *browser.Tab

Tab calls f.

type Probe

type Probe struct {
	Rects [][4]float64 `json:"r"`
	// Fields are the probed form fields; keep moves the sensitive ones into Rects.
	Fields []ProbeField `json:"f,omitempty"`
	SX     float64      `json:"sx"`
	SY     float64      `json:"sy"`
	VW     float64      `json:"vw"`
	VH     float64      `json:"vh"`
}

Probe is what jsProbe returns, once runProbe kept the sensitive fields.

type ProbeField

type ProbeField struct {
	Box   [4]float64       `json:"b"`
	Field credential.Field `json:"f"`
	Value string           `json:"v,omitempty"`
}

ProbeField is a form field the probe found: its box, its description and its value (compared with the handoff's typed values, then dropped by keepSensitive).

type Recorder

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

Recorder records the session. It is an activity.Bus and an activity.PreActionHook (chain it after the Cockpit's so thumbnails show what the human saw) and wraps guard.Askers to log approvals and handoffs. All methods are safe for concurrent use; Publish never blocks.

func New

func New(o Options) *Recorder

New starts a recorder. Its first session opens with the first recorded event.

func (*Recorder) BeforeInput

func (r *Recorder) BeforeInput(ctx context.Context, ev activity.Event) error

BeforeInput takes the action's thumbnail right before input: the target is in view and (with the Cockpit) the ghost cursor sits on it. Recording problems never stop an action.

func (*Recorder) Close

func (r *Recorder) Close() error

Close stops recording and finalizes the session.

func (*Recorder) Current

func (r *Recorder) Current() (*Session, error)

Current returns the session being written (opening one if needed), flushed so it can be read.

func (*Recorder) Export

func (r *Recorder) Export(ctx context.Context, id, format string) (string, *Recording, error)

Export writes a replay of a session (id "" = the current one if it recorded anything, else the last kept) in format html, gif or mp4, and returns the file path.

func (*Recorder) Flush

func (r *Recorder) Flush()

Flush writes queued events to disk (exports, tests).

func (*Recorder) Mode

func (r *Recorder) Mode() Mode

Mode is the current mode (lock-free).

func (*Recorder) NewTask

func (r *Recorder) NewTask(title string)

NewTask starts a new session for the task the AI just planned (title: the plan's first step), so a replay shows one task instead of every task of the server run. A session with no action yet just takes the title.

func (*Recorder) Publish

func (r *Recorder) Publish(ev activity.Event)

Publish records an activity event (non-blocking).

func (*Recorder) SetMode

func (r *Recorder) SetMode(m Mode)

SetMode switches mode within the current session (full ⇄ timeline).

func (*Recorder) Start

func (r *Recorder) Start(m Mode) (*Session, error)

Start begins a new session in the given mode (the previous one is finalized) and returns it.

func (*Recorder) Stop

func (r *Recorder) Stop(next Mode) (Meta, string, error)

Stop finalizes the current session (it stays on disk for export) and goes back to mode next for whatever comes after. It returns the finished session's id ("" when nothing was recorded).

func (*Recorder) Store

func (r *Recorder) Store() Store

Store is where sessions are kept.

func (*Recorder) WrapAsker

func (r *Recorder) WrapAsker(a guard.Asker) guard.Asker

WrapAsker logs the requests the AI makes to the human and their answers. Secret values never reach the log: handoffs only carry their summary, which already hides them.

type Recording

type Recording struct {
	Dir     string
	Meta    Meta
	Entries []Entry
}

Recording is a session read back from disk.

func LoadDir

func LoadDir(dir string) (*Recording, error)

LoadDir reads a session directory.

type Replay

type Replay struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	// Task is the task this session recorded (the plan's first step); Part its number in the
	// server run, and Segments every session of that run (filled by the exporter).
	Task     string          `json:"task,omitzero"`
	Part     int             `json:"part,omitzero"`
	Segments []ReplaySegment `json:"segments,omitzero"`
	Site     string          `json:"site,omitzero"`
	Agent    string          `json:"agent,omitzero"`
	Started  string          `json:"started"` // RFC 3339
	Mode     Mode            `json:"mode"`
	Overlay  bool            `json:"overlay"`
	Duration int64           `json:"duration"` // playback ms
	RealMs   int64           `json:"realMs"`
	Skipped  int64           `json:"skipped"` // idle ms compressed away
	Frames   []ReplayFrame   `json:"frames"`
	Steps    []ReplayStep    `json:"steps"`
	Marks    []ReplayMark    `json:"marks"`
	Cursor   []ReplayMove    `json:"cursor"`
	Masked   int             `json:"masked"` // pictures with credential areas pixelated
	// Images are the pictures referenced by index (data: URIs or relative paths, filled by the
	// exporter); Files are their files in the session directory.
	Images []string `json:"images"`
	Files  []string `json:"-"`
}

Replay is what the exporters render: the recording reduced to pictures, steps and marks on one playback clock. Idle stretches (the AI thinking between actions) are compressed so a replay never shows a frozen picture for long; P is the playback time in ms, T the real one.

func BuildReplay

func BuildReplay(rec *Recording) *Replay

BuildReplay turns a recording into a Replay. Images holds file paths relative to the session directory (the exporter turns them into data URIs or links).

type ReplayFrame

type ReplayFrame struct {
	P   int64   `json:"p"`
	Img int     `json:"img"`
	VW  float64 `json:"vw"`
	VH  float64 `json:"vh"`
	W   int     `json:"w"`
	H   int     `json:"h"`
	Tab string  `json:"tab,omitzero"`
}

ReplayFrame shows Images[Img] from P on.

type ReplayMark

type ReplayMark struct {
	P        int64  `json:"p"`
	Type     string `json:"type"`
	ID       string `json:"id,omitzero"`
	Kind     string `json:"kind,omitzero"`
	Risk     string `json:"risk,omitzero"`
	Name     string `json:"name,omitzero"`
	Text     string `json:"text,omitzero"`
	Decision string `json:"decision,omitzero"`
	Driving  bool   `json:"driving,omitzero"`
}

ReplayMark is something that isn't an action: a request to the human and its answer, or a human take-over (Driving) and hand-back.

type ReplayMove

type ReplayMove struct {
	P    int64          `json:"p"`
	Ms   int64          `json:"ms"`
	From activity.Point `json:"from"`
	To   activity.Point `json:"to"`
	Tab  string         `json:"tab,omitzero"`
}

ReplayMove is a cursor travel.

type ReplaySegment

type ReplaySegment struct {
	Part    int    `json:"part"`
	Task    string `json:"task,omitzero"`
	Started string `json:"started,omitzero"`
	Href    string `json:"href,omitzero"` // relative link to its replay; "" for this one
}

ReplaySegment is one session of the same server run, linked from the replay.

type ReplayStep

type ReplayStep struct {
	ID     string           `json:"id"`
	P      int64            `json:"p"`
	End    int64            `json:"end"`
	T      int64            `json:"t"`
	Kind   string           `json:"kind"`
	Action string           `json:"action,omitzero"`
	Why    string           `json:"why,omitzero"`
	Target *activity.Target `json:"target,omitzero"`
	Value  string           `json:"value,omitzero"`
	Result string           `json:"result,omitzero"`
	Error  string           `json:"error,omitzero"`
	URL    string           `json:"url,omitzero"` // page after a navigation
	Thumb  int              `json:"thumb"`        // index into Images, -1 when none
}

ReplayStep is one action, from its before (P) to its after (End).

type Session

type Session struct {
	Dir string
	// contains filtered or unexported fields
}

Session is one recording directory being written.

func (*Session) Actions

func (s *Session) Actions() int

Actions is the number of finished actions recorded.

func (*Session) Append

func (s *Session) Append(e Entry) error

Append writes one entry.

func (*Session) Close

func (s *Session) Close(now time.Time) error

Close flushes and finalizes the session.

func (*Session) Flush

func (s *Session) Flush() error

Flush pushes buffered entries to disk.

func (*Session) ID

func (s *Session) ID() string

ID is the session id (its directory name).

func (*Session) Meta

func (s *Session) Meta() Meta

Meta returns a copy of the session metadata.

func (*Session) NextFrame

func (s *Session) NextFrame() string

NextFrame names the next screencast frame file.

func (*Session) SetInfo

func (s *Session) SetInfo(agent, version string, overlay bool)

SetInfo fills in descriptive metadata.

func (*Session) SetMode

func (s *Session) SetMode(m Mode)

SetMode records a mode change.

func (*Session) SetTask

func (s *Session) SetTask(run string, part int, task string)

SetTask places the session in its run and names its task ("" keeps the current task).

func (*Session) Since

func (s *Session) Since(t time.Time) int64

Since returns the session clock for t.

func (*Session) Sync

func (s *Session) Sync() error

Sync flushes entries and rewrites meta.json (exports read both).

func (*Session) WriteImage

func (s *Session) WriteImage(rel string, data []byte) error

WriteImage stores an image file (frames/… or thumbs/…) unless the size cap was reached.

type Store

type Store struct {
	Root string
	// Keep is how many server runs are kept, with all their sessions (default 20).
	Keep int
	// MaxSession caps the bytes of one session (default 300 MB); past it pictures stop.
	MaxSession int64
	// MaxTotal caps the bytes of all recordings (default 1 GB): the oldest sessions are deleted
	// first when a new one starts.
	MaxTotal int64
}

Store is the recordings directory (~/.daisybell/recordings), one directory per session (a task of a server run).

func (Store) Dir

func (st Store) Dir(id string) string

Dir returns a session's directory.

func (Store) List

func (st Store) List() []string

List returns the session ids, newest first.

func (Store) Load

func (st Store) Load(id string) (*Recording, error)

Load reads a session.

func (Store) LoadMeta

func (st Store) LoadMeta(id string) (Meta, error)

LoadMeta reads a session's meta.json.

func (Store) Open

func (st Store) Open(now time.Time, mode Mode, run string) (*Session, error)

Open starts a new session of run ("" starts a new run), first making room: see Prune.

func (Store) Prune

func (st Store) Prune(run string)

Prune makes room for a new session of run: it keeps the newest sessions while they belong to at most Keep runs (counting run, which is about to grow) and, together with room for a new session, fit in MaxTotal. Older sessions are deleted, oldest first. Directories that are not sessions are left alone.

func (Store) Remove

func (st Store) Remove(id string) error

Remove deletes one session.

func (Store) Segments

func (st Store) Segments(run string) []Meta

Segments returns the sessions of run, oldest first.

func (Store) Usage

func (st Store) Usage() (bytes int64, sessions int)

Usage is the total size of all sessions in bytes, and how many there are.

type ToolInput

type ToolInput struct {
	Action  string `json:"action" jsonschema:"start (adds a screencast), stop, export or status"`
	Format  string `json:"format,omitempty" jsonschema:"html (default), gif or mp4 (needs ffmpeg)"`
	Session string `json:"session,omitempty" jsonschema:"recording id (default: current, else last)"`
}

ToolInput is the input of the record tool.

Jump to

Keyboard shortcuts

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