source

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package source loads and normalises Claude and Opencode sessions; detects active sessions via PID/lsof.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveResult added in v0.3.1

type ActiveResult struct {
	Confirmed map[string]bool // session IDs matched by cache
	Guessed   map[string]bool // session IDs matched by CWD fallback
}

ActiveResult holds the outcome of DetectActive split by confidence level. Confirmed: session identified via pid+lstart cache — certain. Guessed: session identified via CWD+mtime fallback — probable but not certain.

func DetectActive added in v0.3.1

func DetectActive(sessions []Session, procs []ProcInfo, cache *PIDCache) ActiveResult

DetectActive returns session IDs that are currently active, split by confidence.

For each running claude/opencode process:

  1. If the cache has a pid+lstart → sessionID mapping, use it directly (Confirmed).
  2. Otherwise fall back: session CWD must match process CWD AND last-activity timestamp must be today (>= local midnight) (Guessed).

procs must be pre-collected by the caller (avoids duplicate CollectProcs calls). Errors from CollectProcs are silently ignored — callers get empty maps on failure.

type Client

type Client int
const (
	ClientClaude Client = iota
	ClientOpencode
)

func (Client) String

func (c Client) String() string

type MetaCache added in v0.3.6

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

MetaCache is an in-process cache backed by a gob file on disk. The backing file lives at ~/.cache/aps/session-meta.gob.

func LoadMetaCache added in v0.3.6

func LoadMetaCache() *MetaCache

LoadMetaCache reads ~/.cache/aps/session-meta.gob. Returns an empty cache (never nil, never error) if file is missing or corrupt.

func (*MetaCache) Lookup added in v0.3.6

func (c *MetaCache) Lookup(path string, mtime time.Time, size int64) (MetaEntry, bool)

Lookup returns the cached entry for path if mtime AND size both match. Returns (entry, true) on hit, (zero, false) on miss.

func (*MetaCache) Save added in v0.3.6

func (c *MetaCache) Save() error

Save writes the cache to disk. Creates ~/.cache/aps/ if it does not exist.

func (*MetaCache) Store added in v0.3.6

func (c *MetaCache) Store(path string, e MetaEntry)

Store records an entry for path.

type MetaEntry added in v0.3.6

type MetaEntry struct {
	Mtime    time.Time
	Size     int64
	Title    string
	CWD      string
	MsgCount int
}

MetaEntry holds the parsed metadata for one JSONL file.

type PIDCache added in v0.3.1

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

PIDCache persists pid→sessionID mappings across aps invocations. The backing file lives at ~/.cache/aps/pid-session.txt. Format: one entry per line: "pid|lstart|sessionID"

func LoadPIDCache added in v0.3.1

func LoadPIDCache() *PIDCache

LoadPIDCache reads the cache from disk. Missing file is not an error.

func (*PIDCache) GC added in v0.3.1

func (c *PIDCache) GC(wg *sync.WaitGroup)

GC removes entries whose process is no longer running, then persists. Intended to run in a goroutine; call wg.Done when finished.

func (*PIDCache) Lookup added in v0.3.1

func (c *PIDCache) Lookup(p ProcInfo) string

Lookup returns the sessionID for a proc, or "" if not found.

func (*PIDCache) Set added in v0.3.1

func (c *PIDCache) Set(p ProcInfo, sessionID string)

Set records pid → sessionID and persists to disk.

type ProcInfo added in v0.3.1

type ProcInfo struct {
	PID    string // numeric process ID
	LStart string // process create time as Unix ms string (opaque, used only for equality)
	CWD    string // working directory
}

ProcInfo identifies a specific process instance by pid and start time. Using both fields prevents pid-reuse collisions: the same pid with a different lstart is a different process.

func CollectProcs added in v0.3.1

func CollectProcs() []ProcInfo

CollectProcs returns running claude/opencode processes with pid, lstart, and CWD. Uses gopsutil for pure-Go process inspection (no ps/lsof subprocess overhead).

type Session

type Session struct {
	Client      Client
	ID          string // UUID (Claude) or Opencode session ID
	Title       string
	CWD         string    // Absolute working directory
	CWDDisplay  string    // ~ abbreviated
	ProjectPath string    // Claude only: full path to project dir
	Time        time.Time // Used for sorting (newest first)
	MsgCount    int
	// contains filtered or unexported fields
}

func LoadClaude

func LoadClaude(pathFilter string, strictMatch bool, verbose bool) ([]Session, error)

LoadClaude returns all Claude Code sessions, optionally filtered by path.

func LoadOpencode

func LoadOpencode(pathFilter string, strictMatch bool, verbose bool) ([]Session, error)

LoadOpencode returns all Opencode sessions, optionally filtered by path. It auto-detects storage format: SQLite takes precedence over JSON.

func ReloadSession added in v0.3.1

func ReloadSession(jsonlFile string, verbose bool) (Session, error)

ReloadSession re-parses a single JSONL file and returns an updated Session. The caller is responsible for providing the correct projectPath (parent dir of jsonlFile).

Jump to

Keyboard shortcuts

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