activity

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: 5 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 activity is the tiny contract between the action engine and whoever wants to watch it (the Cockpit, recorders, tests). Every acting tool call publishes a "before" event right before input reaches the page and an "after" event once the page settled, both carrying the agent's `why` and the target element. See docs/ACTIVITY-EVENTS.md.

The package has no dependencies on the browser so subscribers can import it freely.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Announce

func Announce(ctx context.Context, bus Bus, hook PreActionHook, ev Event) error

Announce publishes ev as the "before" event of an action and runs the pre-action hook (bus and hook may be nil). An error from the hook means: don't act. The engine and the tools that act without it (navigate, tabs, dialogs) share this, so every action is reported the same way.

func Finish

func Finish(bus Bus, ev Event, result string, err error)

Finish publishes the "after" event of an action: its one-line result, or its error.

func NewID

func NewID() string

NewID returns a process-unique event id ("a17").

Types

type Box

type Box struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	W float64 `json:"w"`
	H float64 `json:"h"`
}

Box is a rectangle in CSS pixels relative to the top-level viewport (client coordinates of the tab's main frame, already including iframe offsets). It is what an overlay in the main frame needs to point at the element.

type Bus

type Bus interface {
	Publish(Event)
}

Bus receives events. Publish must not block for long: the action engine calls it inline.

type Buses

type Buses []Bus

Buses fans events out to several buses (nil entries are skipped).

func (Buses) Publish

func (bs Buses) Publish(ev Event)

Publish delivers ev to every bus in order.

type Event

type Event struct {
	ID   string    `json:"id"`
	Time time.Time `json:"time"`
	// Tab is the short tab id (t1, t2...).
	Tab  string `json:"tab"`
	Kind Kind   `json:"kind"`
	// Action is the concrete operation: click, type, select, back, accept...
	Action string `json:"action,omitempty"`
	// Why is the agent's short explanation (≤ 80 chars), shown to the human.
	Why    string  `json:"why,omitempty"`
	Target *Target `json:"target,omitempty"`
	// Value is the text typed / option chosen, when not sensitive. Empty for passwords.
	Value string `json:"value,omitempty"`
	Phase Phase  `json:"phase"`
	// Result is the one-line outcome (after only), e.g. `clicked button "Save"`.
	Result string `json:"result,omitempty"`
	// Error is set when the action failed (after only).
	Error string `json:"error,omitempty"`
}

Event is one step of an action. A "before" and its "after" share the same ID.

type Hooks

type Hooks []PreActionHook

Hooks runs several pre-action hooks in order; the first error stops the chain.

func (Hooks) BeforeInput

func (hs Hooks) BeforeInput(ctx context.Context, ev Event) error

BeforeInput runs each hook in turn.

type Hub

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

Hub is an in-memory Bus fanning events out to subscribers. Slow subscribers lose events rather than blocking the action engine.

func NewHub

func NewHub() *Hub

NewHub returns an empty hub.

func (*Hub) Publish

func (h *Hub) Publish(ev Event)

Publish delivers ev to every subscriber whose buffer has room.

func (*Hub) Subscribe

func (h *Hub) Subscribe(buf int) (<-chan Event, func())

Subscribe returns a channel of events (buffered by buf) and a cancel func that closes it.

type Kind

type Kind string

Kind is the tool that produced an event.

const (
	KindNavigate Kind = "navigate"
	KindAct      Kind = "act"
	KindFill     Kind = "fill"
	KindTabs     Kind = "tabs"
	KindDialog   Kind = "dialog"
	// KindMock and KindEmulate change what the page receives or how it is shown (debug group):
	// the human sees them in the feed (SPEC §2.5).
	KindMock    Kind = "mock"
	KindEmulate Kind = "emulate"
	// KindRetouch changes how a site looks (retouch group: preview, save, discard, toggle).
	KindRetouch Kind = "retouch"
)

type Nop

type Nop struct{}

Nop is a Bus and PreActionHook that does nothing.

func (Nop) BeforeInput

func (Nop) BeforeInput(context.Context, Event) error

func (Nop) Publish

func (Nop) Publish(Event)

type Phase

type Phase string

Phase tells whether input is about to happen or has happened.

const (
	PhaseBefore Phase = "before"
	PhaseAfter  Phase = "after"
)

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Point is a position in CSS pixels relative to the top-level viewport.

type PreActionHook

type PreActionHook interface {
	BeforeInput(ctx context.Context, ev Event) error
}

PreActionHook runs after the target was scrolled into view and verified, immediately before trusted input is dispatched. ev is the "before" event (target box included). The Cockpit uses it to animate the ghost cursor to the target; returning an error aborts the action and the error is reported to the agent (e.g. the human paused).

type Target

type Target struct {
	Ref  string `json:"ref,omitempty"`
	Role string `json:"role,omitempty"`
	Name string `json:"name,omitempty"`
	// Box is nil when the action has no on-screen target (navigate, press without ref...).
	Box *Box `json:"box,omitempty"`
	// Point is where the pointer will land (center of the visible part), when pointer input is
	// used.
	Point *Point `json:"point,omitempty"`
}

Target is the element an action is aimed at.

Jump to

Keyboard shortcuts

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