adapters

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoAdapterDetected is returned when no adapter can handle the current environment
	ErrNoAdapterDetected = errors.New("no adapter detected for current environment")

	// ErrAdapterNotFound is returned when a specific adapter is not registered
	ErrAdapterNotFound = errors.New("adapter not found")

	// ErrSessionNotFound is returned when a session file cannot be located
	ErrSessionNotFound = errors.New("session file not found")
)

Functions

func ListAdapters

func ListAdapters() []string

ListAdapters returns the names of all registered adapters

func Register

func Register(adapter Adapter)

Register adds an adapter to the registry Panics if an adapter with the same name is already registered

func ResetRegistry

func ResetRegistry()

ResetRegistry clears all registered adapters (for testing only)

Types

type Adapter

type Adapter interface {
	// Name returns the adapter name (e.g., "claude-code")
	Name() string

	// Detect checks if this adapter can handle the current environment
	// Returns true if the agent's session files are present and readable
	Detect() bool

	// FindSessionFile locates the session file for correlation
	// Called after ox agent prime to find the matching agent session
	// agentID is the unique identifier written during prime
	// since filters to sessions created after this time
	FindSessionFile(agentID string, since time.Time) (string, error)

	// Read reads all entries from a session file
	// Returns entries in chronological order
	Read(sessionPath string) ([]RawEntry, error)

	// ReadMetadata extracts session metadata (agent version, model) from a session file.
	// Returns nil if metadata cannot be determined.
	ReadMetadata(sessionPath string) (*SessionMetadata, error)

	// Watch monitors a session file for new entries (for real-time capture)
	// The returned channel receives entries as they appear
	// The channel is closed when ctx is canceled or an error occurs
	Watch(ctx context.Context, sessionPath string) (<-chan RawEntry, error)
}

Adapter reads conversation data from a coding agent's session files

func DetectAdapter

func DetectAdapter() (Adapter, error)

DetectAdapter finds the appropriate adapter for the current environment Iterates through all registered adapters and returns the first one that detects Returns ErrNoAdapterDetected if no adapter can handle the environment

func GetAdapter

func GetAdapter(name string) (Adapter, error)

GetAdapter returns a specific adapter by name. Accepts canonical names ("claude-code"), display names ("Claude Code"), and shorthand ("claude"). Case-insensitive for aliases. Returns ErrAdapterNotFound if no adapter with that name is registered.

type ClaudeCodeAdapter

type ClaudeCodeAdapter struct{}

ClaudeCodeAdapter reads Claude Code session files stored as JSONL in ~/.claude/projects/<project-hash>/*.jsonl

func (*ClaudeCodeAdapter) Detect

func (a *ClaudeCodeAdapter) Detect() bool

Detect checks if Claude Code session files are present

func (*ClaudeCodeAdapter) FindSessionFile

func (a *ClaudeCodeAdapter) FindSessionFile(agentID string, since time.Time) (string, error)

FindSessionFile locates the most recent session file matching criteria. It searches through all project directories for JSONL files modified after 'since', then scans for content matching the agentID (from ox agent prime output).

func (*ClaudeCodeAdapter) Name

func (a *ClaudeCodeAdapter) Name() string

Name returns the adapter identifier

func (*ClaudeCodeAdapter) Read

func (a *ClaudeCodeAdapter) Read(sessionPath string) ([]RawEntry, error)

Read parses all entries from a Claude Code JSONL session file

func (*ClaudeCodeAdapter) ReadMetadata

func (a *ClaudeCodeAdapter) ReadMetadata(sessionPath string) (*SessionMetadata, error)

ReadMetadata extracts session metadata (agent version, model) from a Claude Code session. It scans the session file for version and model information from the JSONL entries.

func (*ClaudeCodeAdapter) Watch

func (a *ClaudeCodeAdapter) Watch(ctx context.Context, sessionPath string) (<-chan RawEntry, error)

Watch monitors a session file for new entries using fsnotify. It uses debouncing to avoid reading partial writes when multiple file system events fire rapidly during a single write operation.

type RawEntry

type RawEntry struct {
	// Timestamp when this entry was created
	Timestamp time.Time

	// Role identifies the speaker: "user", "assistant", "system", "tool"
	Role string

	// Content is the message text or tool output
	Content string

	// ToolName is the name of the tool invoked (only for role="tool")
	ToolName string

	// ToolInput is the input provided to the tool (only for role="tool")
	ToolInput string

	// Raw contains the original data for debugging and auditing
	Raw json.RawMessage
}

RawEntry represents a conversation turn from any agent

type SessionMetadata

type SessionMetadata struct {
	// AgentVersion is the version of the coding agent (e.g., "1.0.3" for Claude Code)
	AgentVersion string

	// Model is the LLM model used (e.g., "claude-sonnet-4-20250514")
	Model string
}

SessionMetadata contains metadata extracted from agent session files. This captures which agent and model were used for the session.

Jump to

Keyboard shortcuts

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