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
- Variables
- func Cover(data []byte, png bool, boxes [][4]float64, cssWidth float64) ([]byte, int, error)
- func DirSize(dir string) int64
- func ExportGIF(ctx context.Context, rec *Recording, out string) (string, error)
- func ExportHTML(rec *Recording, out string) (string, error)
- func ExportMP4(ctx context.Context, rec *Recording, out string) (string, error)
- func FFmpegPath() string
- func MaskJPEG(data []byte, p Probe, g FrameGeom, maxW int) ([]byte, int, image.Point, error)
- func MaskRects(p Probe, g FrameGeom, w, h int) []image.Rectangle
- func Pixelate(img draw.Image, rects []image.Rectangle)
- func RegisterTools(s *mcp.Server, r *Recorder, declare func(name string, readOnly bool))
- func RenderHTML(rp *Replay) (string, error)
- type Clock
- type Entry
- type FrameGeom
- type Meta
- type Mode
- type Options
- type Pages
- type PagesFunc
- type Probe
- type ProbeField
- type Recorder
- func (r *Recorder) BeforeInput(ctx context.Context, ev activity.Event) error
- func (r *Recorder) Close() error
- func (r *Recorder) Current() (*Session, error)
- func (r *Recorder) Export(ctx context.Context, id, format string) (string, *Recording, error)
- func (r *Recorder) Flush()
- func (r *Recorder) Mode() Mode
- func (r *Recorder) NewTask(title string)
- func (r *Recorder) Publish(ev activity.Event)
- func (r *Recorder) SetMode(m Mode)
- func (r *Recorder) Start(m Mode) (*Session, error)
- func (r *Recorder) Stop(next Mode) (Meta, string, error)
- func (r *Recorder) Store() Store
- func (r *Recorder) WrapAsker(a guard.Asker) guard.Asker
- type Recording
- type Replay
- type ReplayFrame
- type ReplayMark
- type ReplayMove
- type ReplaySegment
- type ReplayStep
- type Session
- func (s *Session) Actions() int
- func (s *Session) Append(e Entry) error
- func (s *Session) Close(now time.Time) error
- func (s *Session) Flush() error
- func (s *Session) ID() string
- func (s *Session) Meta() Meta
- func (s *Session) NextFrame() string
- func (s *Session) SetInfo(agent, version string, overlay bool)
- func (s *Session) SetMode(m Mode)
- func (s *Session) SetTask(run string, part int, task string)
- func (s *Session) Since(t time.Time) int64
- func (s *Session) Sync() error
- func (s *Session) WriteImage(rel string, data []byte) error
- type Store
- func (st Store) Dir(id string) string
- func (st Store) List() []string
- func (st Store) Load(id string) (*Recording, error)
- func (st Store) LoadMeta(id string) (Meta, error)
- func (st Store) Open(now time.Time, mode Mode, run string) (*Session, error)
- func (st Store) Prune(run string)
- func (st Store) Remove(id string) error
- func (st Store) Segments(run string) []Meta
- func (st Store) Usage() (bytes int64, sessions int)
- type ToolInput
Constants ¶
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.
const (
// DefaultMaxTotal is the default cap on all recordings together.
DefaultMaxTotal = 1 << 30
)
Variables ¶
var ErrNoFFmpeg = errors.New("ffmpeg not found")
ErrNoFFmpeg is returned for MP4 when ffmpeg is not installed.
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 ¶
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 ExportGIF ¶
ExportGIF writes an animated GIF (pure Go, no ffmpeg needed) with the captions burned in.
func ExportHTML ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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).
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 ¶
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.
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 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 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 (*Recorder) BeforeInput ¶
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) Current ¶
Current returns the session being written (opening one if needed), flushed so it can be read.
func (*Recorder) Export ¶
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) NewTask ¶
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) Start ¶
Start begins a new session in the given mode (the previous one is finalized) and returns it.
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 ¶
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) SetTask ¶
SetTask places the session in its run and names its task ("" keeps the current task).
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) Open ¶
Open starts a new session of run ("" starts a new run), first making room: see Prune.
func (Store) Prune ¶
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.
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.