session

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: BSD-3-Clause Imports: 21 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

IsRisky reports whether EvaluateRisk returns a non-none level for s.

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 reports whether a sidecar check was attempted.
	Verified bool
	// Match reports whether the verified content matched the sidecar digest.
	Match bool
	// Err reports why verification failed when the check could not complete.
	Err error
	// Detail carries additional mismatch or verification context.
	Detail string
}

IntegrityCheckResult records the outcome of verifying a session sidecar.

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

IntegrityChecker verifies a session and returns an integrity result.

type MigrateBatchItemResult added in v0.3.0

type MigrateBatchItemResult struct {
	Mapping MigrateBatchMapping
	Result  MigrateResult
	Err     error
}

MigrateBatchItemResult records the outcome of one mapping in file order.

type MigrateBatchMapping added in v0.3.0

type MigrateBatchMapping struct {
	FromCWD string `toml:"from"`
	ToCWD   string `toml:"to"`
	Branch  string `toml:"branch"`
}

MigrateBatchMapping describes one source-to-target migration mapping loaded from TOML.

type MigrateBatchOptions added in v0.3.0

type MigrateBatchOptions struct {
	FilePath     string
	SessionsRoot string
	StateDBPath  string
	Limit        int
	Since        time.Time
	HasSince     bool
	DryRun       bool
	Confirm      bool
	PrintCreated bool
}

MigrateBatchOptions controls file-driven batch migration execution.

type MigrateBatchResult added in v0.3.0

type MigrateBatchResult struct {
	DryRun        bool
	PrintCreated  bool
	TotalMappings int
	Succeeded     int
	Failed        int
	Matched       int
	Created       int
	Skipped       int
	Items         []MigrateBatchItemResult
}

MigrateBatchResult is the aggregate result for a file-driven batch migration run.

func MigrateSessionsBatch added in v0.3.0

func MigrateSessionsBatch(opts MigrateBatchOptions) (MigrateBatchResult, error)

MigrateSessionsBatch executes one migration file in declaration order.

type MigrateOptions added in v0.3.0

type MigrateOptions struct {
	FromCWD      string
	ToCWD        string
	Branch       string
	SessionsRoot string
	StateDBPath  string
	Limit        int
	Since        time.Time
	HasSince     bool
	DryRun       bool
	Confirm      bool
	PrintCreated bool
}

MigrateOptions controls session migration planning and execution.

type MigratePlan added in v0.3.0

type MigratePlan struct {
	SourceID      string
	DestID        string
	SourceRollout string
	DestRollout   string
	SourceCWD     string
	DestCWD       string
	SourceBranch  string
	DestBranch    string
}

MigratePlan describes one source session copied to one destination session.

type MigrateResult added in v0.3.0

type MigrateResult struct {
	FromCWD      string
	ToCWD        string
	DestBranch   string
	Matched      int
	Created      int
	Skipped      int
	DryRun       bool
	PrintCreated bool
	Planned      []MigratePlan
	Warnings     []string
}

MigrateResult is the user-facing migration summary.

func MigrateSessions added in v0.3.0

func MigrateSessions(opts MigrateOptions) (MigrateResult, error)

MigrateSessions copies sessions from one cwd to another and keeps the local thread index in sync.

type Risk added in v0.2.2

type Risk struct {
	// Level is the severity assigned by the current risk policy.
	Level RiskLevel `json:"level"`
	// Reason identifies which policy produced Level.
	Reason RiskReason `json:"reason"`
	// Detail carries human-readable context for the detected issue.
	Detail string `json:"detail,omitempty"`
}

Risk describes the highest-priority issue detected for a session.

func EvaluateRisk added in v0.2.2

func EvaluateRisk(s Session, checker IntegrityChecker) Risk

EvaluateRisk returns the highest-priority risk detected for s.

Health-based risks are evaluated first. If checker is nil or s is already unhealthy, integrity verification is skipped.

type RiskLevel added in v0.2.2

type RiskLevel string

RiskLevel classifies how severe a session issue is.

const (
	// RiskNone means the session has no detected risk.
	RiskNone RiskLevel = "none"
	// RiskMedium means the session needs attention but is still partially usable.
	RiskMedium RiskLevel = "medium"
	// RiskHigh means the session is corrupted or unsafe to trust.
	RiskHigh RiskLevel = "high"
)

type RiskReason added in v0.2.2

type RiskReason string

RiskReason identifies the specific policy that made a session risky.

const (
	// RiskReasonNone means no risk policy matched.
	RiskReasonNone RiskReason = "none"
	// RiskReasonCorrupted marks unreadable or malformed session files.
	RiskReasonCorrupted RiskReason = "corrupted-session"
	// RiskReasonMissingMeta marks files without usable session metadata.
	RiskReasonMissingMeta RiskReason = "missing-meta"
	// RiskReasonIntegrityCheckError marks sidecar verification failures.
	RiskReasonIntegrityCheckError RiskReason = "integrity-check-error"
	// RiskReasonIntegrityMismatch marks hash mismatches against a sidecar.
	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.

func ScanSessionsLimited added in v0.2.5

func ScanSessionsLimited(root string, limit int, less func(a, b Session) bool) ([]Session, error)

ScanSessionsLimited scans a root and retains only the best limit sessions according to less. A limit <= 0 falls back to full ScanSessions behavior.

Jump to

Keyboard shortcuts

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