session

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package session implements scanning, filtering, and deletion for Codex sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRisky added in v0.2.2

func IsRisky(s Session, checker IntegrityChecker) bool

Types

type DeleteOptions

type DeleteOptions struct {
	DryRun       bool
	Confirm      bool
	Yes          bool
	Hard         bool
	MaxBatch     int
	TrashRoot    string
	SessionsRoot string
}

DeleteOptions controls delete mode and safety gates.

type DeleteResult

type DeleteResult struct {
	SessionID   string `json:"session_id"`
	Path        string `json:"path"`
	Destination string `json:"destination,omitempty"`
	Status      string `json:"status"`
	Error       string `json:"error,omitempty"`
}

DeleteResult is a per-session execution result entry.

type DeleteSummary

type DeleteSummary struct {
	Action        string         `json:"action"`
	Simulation    bool           `json:"simulation"`
	MatchedCount  int            `json:"matched_count"`
	Succeeded     int            `json:"succeeded"`
	Failed        int            `json:"failed"`
	Skipped       int            `json:"skipped"`
	AffectedBytes int64          `json:"affected_bytes"`
	Results       []DeleteResult `json:"results"`
	ErrorSummary  string         `json:"error_summary,omitempty"`
}

DeleteSummary aggregates delete execution status and accounting.

func DeleteSessions

func DeleteSessions(candidates []Session, sel Selector, opts DeleteOptions) (DeleteSummary, error)

DeleteSessions executes dry-run, soft-delete, or hard-delete over matched sessions.

type Health

type Health string

Health describes scanner quality classification for a session file.

const (
	// HealthOK means the session file is readable and has a valid session_meta line.
	HealthOK Health = "ok"
	// HealthCorrupted means the session file cannot be parsed as expected.
	HealthCorrupted Health = "corrupted"
	// HealthMissingMeta means the file is readable but does not contain valid session metadata.
	HealthMissingMeta Health = "missing-meta"
)

type IntegrityCheckResult added in v0.2.2

type IntegrityCheckResult struct {
	Verified bool
	Match    bool
	Err      error
	Detail   string
}

func SHA256SidecarChecker added in v0.2.2

func SHA256SidecarChecker(s Session) IntegrityCheckResult

SHA256SidecarChecker verifies session integrity via "<session>.sha256" sidecar file. Sidecar formats accepted:

  • "<hexhash>"
  • "<hexhash> <filename>"

type IntegrityChecker added in v0.2.2

type IntegrityChecker func(Session) IntegrityCheckResult

type Risk added in v0.2.2

type Risk struct {
	Level  RiskLevel  `json:"level"`
	Reason RiskReason `json:"reason"`
	Detail string     `json:"detail,omitempty"`
}

func EvaluateRisk added in v0.2.2

func EvaluateRisk(s Session, checker IntegrityChecker) Risk

type RiskLevel added in v0.2.2

type RiskLevel string
const (
	RiskNone   RiskLevel = "none"
	RiskMedium RiskLevel = "medium"
	RiskHigh   RiskLevel = "high"
)

type RiskReason added in v0.2.2

type RiskReason string
const (
	RiskReasonNone                RiskReason = "none"
	RiskReasonCorrupted           RiskReason = "corrupted-session"
	RiskReasonMissingMeta         RiskReason = "missing-meta"
	RiskReasonIntegrityCheckError RiskReason = "integrity-check-error"
	RiskReasonIntegrityMismatch   RiskReason = "integrity-mismatch"
)

type Selector

type Selector struct {
	ID           string        `json:"id,omitempty"`
	IDPrefix     string        `json:"id_prefix,omitempty"`
	HostContains string        `json:"host_contains,omitempty"`
	PathContains string        `json:"path_contains,omitempty"`
	HeadContains string        `json:"head_contains,omitempty"`
	OlderThan    time.Duration `json:"older_than,omitempty"`
	HasOlderThan bool          `json:"has_older_than,omitempty"`
	Health       Health        `json:"health,omitempty"`
	HasHealth    bool          `json:"has_health,omitempty"`
}

Selector defines user-provided filters used by list and delete operations.

func (Selector) HasAnyFilter

func (s Selector) HasAnyFilter() bool

HasAnyFilter reports whether at least one filter is set.

type Session

type Session struct {
	SessionID string    `json:"session_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	SizeBytes int64     `json:"size_bytes"`
	Path      string    `json:"path"`
	HostDir   string    `json:"host_dir,omitempty"`
	Health    Health    `json:"health"`
	Head      string    `json:"head,omitempty"`
}

Session is the normalized metadata row returned by scanner and list commands.

func FilterSessions

func FilterSessions(sessions []Session, sel Selector, now time.Time) []Session

FilterSessions applies selector constraints and returns results ordered by UpdatedAt desc.

func ScanSessions

func ScanSessions(root string) ([]Session, error)

ScanSessions walks the sessions root and parses each .jsonl file into Session metadata.

Jump to

Keyboard shortcuts

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