source

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 16 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.2

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.2

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 ps/lsof calls). Errors from ps/lsof 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 PIDCache added in v0.3.2

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.2

func LoadPIDCache() *PIDCache

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

func (*PIDCache) GC added in v0.3.2

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.2

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.2

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

Set records pid → sessionID and persists to disk.

type ProcInfo added in v0.3.2

type ProcInfo struct {
	PID    string // numeric string from ps
	LStart string // raw lstart string from ps (opaque, used only for equality)
	CWD    string // working directory from lsof
}

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.2

func CollectProcs() []ProcInfo

CollectProcs returns running claude/opencode processes with pid, lstart, and CWD.

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.2

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