source

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package source defines the custom source contract for agentwatch. Sources implement the Source interface to feed session data into a Monitor.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRegistered = errors.New("source: name already registered")

ErrAlreadyRegistered is returned by Register when a name is already in use.

Functions

This section is empty.

Types

type Cursor

type Cursor string

Cursor is an opaque position marker returned by Parse. The monitor stores and returns it to the source on the next call but never inspects it. Sources may encode byte offsets, mtimes, hashes, or any other source-specific continuation token as a string.

type Factory

type Factory func() (Source, error)

Factory is a constructor function that returns a new Source instance.

type Registry

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

Registry maps source names to their Factory functions. It is safe for concurrent use.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty Registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Factory, bool)

Get returns the Factory for name and true, or nil and false if not found.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the sorted list of registered source names.

func (*Registry) Register

func (r *Registry) Register(name string, f Factory) error

Register associates name with f. It returns ErrAlreadyRegistered if name is already present.

type SessionHandle

type SessionHandle struct {
	ID         string    `json:"id"`
	Path       string    `json:"path"`
	WorkingDir string    `json:"workingDir"`
	StartedAt  time.Time `json:"startedAt"`
	Source     string    `json:"source"`
}

SessionHandle is a lightweight descriptor returned by Discover. It identifies a single agent session without exposing parsing state.

type Source

type Source interface {
	// Name returns the unique identifier for this source (e.g. "claude", "codex").
	Name() string

	// Discover returns the set of sessions currently visible to this source.
	// It is called periodically by the monitor to detect new sessions.
	Discover(ctx context.Context) ([]SessionHandle, error)

	// Parse reads new data for the session identified by h, starting from
	// cursor c. It returns the parsed update, the next cursor position, and
	// any error. If no new data is available, it returns a zero SourceUpdate
	// and the same cursor.
	Parse(ctx context.Context, h SessionHandle, c Cursor) (SourceUpdate, Cursor, error)
}

Source is the interface implemented by all session data providers.

type SourceUpdate

type SourceUpdate struct {
	SessionID string `json:"sessionId"`
	Slug      string `json:"slug,omitempty"`

	Activity session.Activity `json:"activity"`
	Model    string           `json:"model,omitempty"`

	ContextTokens    int  `json:"contextTokens"`
	OutputTokens     int  `json:"outputTokens,omitempty"`
	MaxContextTokens int  `json:"maxContextTokens"`
	TokenEstimated   bool `json:"tokenEstimated"`

	MessageCountDelta  int    `json:"messageCountDelta,omitempty"`
	ToolCallCountDelta int    `json:"toolCallCountDelta,omitempty"`
	CurrentTool        string `json:"currentTool,omitempty"`

	WorkingDir string `json:"workingDir,omitempty"`
	Branch     string `json:"branch,omitempty"`

	StartedAt      time.Time `json:"startedAt"`
	LastActivityAt time.Time `json:"lastActivityAt"`

	Subagents []session.SubagentState `json:"subagents,omitempty"`

	Terminal  bool      `json:"terminal"`
	EndReason string    `json:"endReason,omitempty"`
	EndedAt   time.Time `json:"endedAt,omitempty"`
}

SourceUpdate carries incremental session data returned by Parse. Delta fields (MessageCountDelta, ToolCallCountDelta) represent the change since the previous Parse call; the monitor accumulates them.

Jump to

Keyboard shortcuts

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