model

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Truncate

func Truncate(s string, n int) string

Truncate returns the first n runes of s, or s unchanged if shorter.

Types

type ConversationMessage

type ConversationMessage struct {
	Role      string // "user" or "assistant"
	Text      string // first text block, truncated to 300 chars
	Timestamp time.Time
}

ConversationMessage holds a single human-readable message from the conversation.

type DesktopMeta

type DesktopMeta struct {
	Title          string
	DesktopID      string // Desktop's own session ID (distinct from cliSessionId)
	PermissionMode string
	IsArchived     bool
	CreatedAt      time.Time
}

DesktopMeta holds metadata from Claude Desktop's session JSON files.

type Session

type Session struct {
	// Identity
	SessionID string
	JSONLPath string

	// Runtime
	CWD         string // working directory
	Version     string // agent version
	Model       string // model being used
	GitBranch   string
	IsSidechain bool // true = sub-agent spawned by another session

	// Git / worktree
	IsWorktree bool
	MainRepo   string // main repo path if worktree

	// Status
	Status        SessionStatus
	CurrentTool   string    // name of tool currently executing, if any
	LastActivity  time.Time // timestamp of last JSONL entry
	LastSummaryAt time.Time // timestamp of last compaction summary entry
	TotalMessages int
	RecentTools   []ToolCall // last N tool calls

	// Conversation preview
	RecentMessages []ConversationMessage // last 10 human-readable messages

	// Last file written/edited
	LastFileWrite   string    // absolute path of most recent Write/Edit/NotebookEdit
	LastFileWriteAt time.Time // timestamp of that tool call

	// Counts
	UserMessages      int
	AssistantMessages int

	// Activity timeline (for sparkline)
	EntryTimestamps []time.Time

	// Cost tracking
	CostUSD             float64 // cumulative cost from JSONL entries
	InputTokens         int
	OutputTokens        int
	CacheCreationTokens int
	CacheReadTokens     int

	// Agent identity
	Agent string // "claude" or "pi" — which coding agent produced this session
	Name  string // session display name (from pi session_info or custom)

	// Desktop metadata (non-nil if session was started via Claude Desktop)
	Desktop *DesktopMeta
}

Session holds all observable information about a coding agent instance.

func (*Session) Clone

func (s *Session) Clone() *Session

Clone returns a deep copy of the Session suitable for use as a base in incremental parsing. Slice fields are copied so the original is not mutated.

type SessionCache

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

SessionCache caches parsed JSONL sessions keyed by file path. On subsequent calls, only files whose mtime changed are re-parsed. Shared by all agent providers (Claude, pi, etc.).

func NewSessionCache

func NewSessionCache() *SessionCache

NewSessionCache creates an empty session cache.

func (*SessionCache) GetIncremental

func (c *SessionCache) GetIncremental(path string) (*Session, int64, time.Time)

GetIncremental returns the cached session and byte offset for incremental parsing. If the file is unchanged, returns (session, 0, mtime) — a full cache hit. If the file has changed and a previous entry exists, returns (session, offset, mtime) where session is a Clone of the previous state and offset is the byte position to resume from. If no previous entry exists, returns (nil, 0, mtime) — a full miss.

func (*SessionCache) Prune

func (c *SessionCache) Prune(seen map[string]struct{})

Prune removes cache entries for files no longer present in the seen set.

func (*SessionCache) Put

func (c *SessionCache) Put(path string, mtime time.Time, size int64, s *Session)

Put stores a session in the cache with the given mtime and byte offset.

type SessionStatus

type SessionStatus int

SessionStatus represents the current activity of a coding agent session.

const (
	StatusUnknown          SessionStatus = iota
	StatusWaitingForUser                 // Agent responded, awaiting human input
	StatusThinking                       // Agent is generating a response
	StatusExecutingTool                  // Agent invoked a tool, waiting for result
	StatusProcessingResult               // Tool result received, agent is thinking
	StatusIdle                           // Session file exists but process not running
)

func (SessionStatus) String

func (s SessionStatus) String() string

type ToolCall

type ToolCall struct {
	Name      string
	Timestamp time.Time
}

ToolCall holds info about a single tool invocation.

Jump to

Keyboard shortcuts

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