Help us shape the future of Go! Take the 2026 Go Developer Survey

activity

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package activity is the desktop app's user-facing audit log. Any backend subsystem — a source refresh, a session launch, an action run, a config reload — records a well-formed Event through a Recorder, and the frontend records its own via the ActivityService. Events persist in the pipeline SQLite store and surface, newest first, in the Activity view.

The ergonomic constructors (RefreshFailed, SessionCreated, AutoAction, …) are the "mixin" surface: an emit site names what happened and passes the few facts it has, and the constructor assembles the category, severity, and human copy. New event shapes are added as new constructors, not new call-site formatting.

Index

Constants

View Source
const (
	MetadataLinkURL             = "link.url"
	MetadataLinkItemProfileID   = "link.item.profileId"
	MetadataLinkItemSourceKind  = "link.item.sourceKind"
	MetadataLinkItemSourceScope = "link.item.sourceScope"
	MetadataLinkItemExternalID  = "link.item.externalId"
)

Link metadata uses link.url for an external destination and the link.item.* group for one internal inbox reference.

Variables

View Source
var ErrInvalidCategory = fmt.Errorf("not a valid Category, try [%s]", strings.Join(_CategoryNames, ", "))
View Source
var ErrInvalidSeverity = fmt.Errorf("not a valid Severity, try [%s]", strings.Join(_SeverityNames, ", "))

Functions

func CategoryNames

func CategoryNames() []string

CategoryNames returns a list of possible string values of Category.

func SeverityNames

func SeverityNames() []string

SeverityNames returns a list of possible string values of Severity.

Types

type Category

type Category string

Category is the semantic bucket of an event. It drives the Activity view's filter pills and, for non-error events, the row's icon and accent color.

ENUM(refresh, session, auto_action, action, config, system)

const (
	// CategoryRefresh is a Category of type refresh.
	CategoryRefresh Category = "refresh"
	// CategorySession is a Category of type session.
	CategorySession Category = "session"
	// CategoryAutoAction is a Category of type auto_action.
	CategoryAutoAction Category = "auto_action"
	// CategoryAction is a Category of type action.
	CategoryAction Category = "action"
	// CategoryConfig is a Category of type config.
	CategoryConfig Category = "config"
	// CategorySystem is a Category of type system.
	CategorySystem Category = "system"
)

func ParseCategory

func ParseCategory(name string) (Category, error)

ParseCategory attempts to convert a string to a Category.

func (*Category) AppendText

func (x *Category) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (Category) IsValid

func (x Category) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Category) MarshalText

func (x Category) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Category) String

func (x Category) String() string

String implements the Stringer interface.

func (*Category) UnmarshalText

func (x *Category) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Event

type Event struct {
	ID        int64    `json:"id"`
	CreatedAt int64    `json:"createdAt"`
	Category  Category `json:"category"`
	Severity  Severity `json:"severity"`
	Title     string   `json:"title"`
	Body      string   `json:"body,omitempty"`
	Source    string   `json:"source,omitempty"`
	// Metadata is opaque to storage. Keys under "link." are reserved for the
	// Activity view's generic destinations; other keys carry event-specific
	// data such as a retryable session draft.
	Metadata map[string]string `json:"metadata,omitempty"`
}

Event is one activity-log entry. ID and CreatedAt are assigned by the store on append; constructors and callers leave them zero. CreatedAt is unix milliseconds (see the activity_event migration for why milliseconds).

func ActionFailed

func ActionFailed(label, reason string) Event

ActionFailed records an action (auto or manual) that failed, capturing the error reason.

func ActionRun

func ActionRun(label, detail string) Event

ActionRun records a manually confirmed action that succeeded. detail is an optional command/summary line.

func AutoAction

func AutoAction(label, rule, target string) Event

AutoAction records an automatic action applied without confirmation. rule is the action/rule id and target the item it acted on.

func ConfigReloaded

func ConfigReloaded(file string, actions int) Event

ConfigReloaded records a config file reload, reporting the resulting action count.

func FlowRuntimeFailed

func FlowRuntimeFailed(flowID string, err error) Event

FlowRuntimeFailed records a flow the engine could not put into service. The last known-good version of that flow keeps running, which is exactly why this has to be recorded: without it the failure is invisible and the app silently executes an older graph than the one on disk.

func RefreshFailed

func RefreshFailed(source, reason string) Event

RefreshFailed records a source refresh that errored, capturing the reason (an error string or stderr excerpt).

func ScheduleRun

func ScheduleRun(name, workspace, status, detail string) Event

status is schedule.Status's string form rather than the type: the audit log is a sink every subsystem writes to and takes no dependency on any of them, so an unrecognized status records as plain info instead of failing.

func SessionCreateFailed

func SessionCreateFailed(name, repo, step, reason string, retry map[string]string) Event

SessionCreateFailed records a session the app accepted and could not create. Unlike ActionFailed there is nothing to show afterwards, so retry carries the submitted form and makes the row the way back to it (ADR a-failed-session-creation-is-a-retryable-draft).

func SessionCreated

func SessionCreated(name, agent, repo string) Event

SessionCreated records a hive session created by an action. agent and repo are optional and folded into the metadata line when present.

func (e Event) WithLink(link Link) Event

WithLink adds the generic link metadata the Activity view understands.

type ItemLink struct {
	ProfileID   string
	SourceKind  string
	SourceScope string
	ExternalID  string
}

ItemLink is the stable source identity of an inbox item. All fields travel together because an external id can be repeated across profiles and sources.

type Link struct {
	URL  string
	Item *ItemLink
}

Link declares the destinations associated with an activity event. URL opens outside the app. Item identifies an inbox row to select inside the app.

type RecordInput

type RecordInput struct {
	Category string            `json:"category"`
	Severity string            `json:"severity"`
	Title    string            `json:"title"`
	Body     string            `json:"body"`
	Source   string            `json:"source"`
	Metadata map[string]string `json:"metadata"`
}

RecordInput is the frontend-facing shape for recording an event over the Wails boundary. Category and severity are plain strings resolved (case -insensitively) by RecordInput.Event; empty values default to system/info.

func (RecordInput) Event

func (in RecordInput) Event() (Event, error)

Event validates the input and converts it to a domain Event.

type Recorder

type Recorder interface {
	Record(ctx context.Context, e Event)
}

Recorder reports audit events without propagating persistence failures.

type Severity

type Severity string

Severity is the emphasis of an event, independent of its category: a refresh that failed is Category=refresh, Severity=error. It selects error/auto row styling and bridges to the toast system's matching severities.

ENUM(info, success, warning, error, auto)

const (
	// SeverityInfo is a Severity of type info.
	SeverityInfo Severity = "info"
	// SeveritySuccess is a Severity of type success.
	SeveritySuccess Severity = "success"
	// SeverityWarning is a Severity of type warning.
	SeverityWarning Severity = "warning"
	// SeverityError is a Severity of type error.
	SeverityError Severity = "error"
	// SeverityAuto is a Severity of type auto.
	SeverityAuto Severity = "auto"
)

func ParseSeverity

func ParseSeverity(name string) (Severity, error)

ParseSeverity attempts to convert a string to a Severity.

func (*Severity) AppendText

func (x *Severity) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (Severity) IsValid

func (x Severity) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Severity) MarshalText

func (x Severity) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (Severity) String

func (x Severity) String() string

String implements the Stringer interface.

func (*Severity) UnmarshalText

func (x *Severity) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

Jump to

Keyboard shortcuts

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