persistence

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 5 Imported by: 0

README

Persistence Package (internal/persistence)

Session marker storage abstractions.

Overview

This package provides session marker persistence, decoupling session management from filesystem operations. This improves testability and enables alternative storage backends.

Purpose

Session markers track whether a CLI session can be resumed (e.g., Claude Code's --resume functionality).

Interface

type SessionMarkerStore interface {
    // Exists checks if a session marker exists
    Exists(sessionID string) bool

    // Create creates a session marker
    Create(sessionID string) error

    // Delete removes the session marker
    Delete(sessionID string) error

    // Dir returns the base directory
    Dir() string
}

Usage

import "github.com/hrygo/hotplex/internal/persistence"

// Create file-based marker store
store, err := persistence.NewFileMarkerStore("/var/lib/hotplex/markers")

// Check if session can be resumed
if store.Exists(sessionID) {
    // Resume session
}

// Create marker for new session
err := store.Create(sessionID)

// Clean up after session ends
err := store.Delete(sessionID)

Implementation

Type Description
FileMarkerStore Filesystem-based storage (default)
SessionMarkerStore Interface for custom backends

Files

File Purpose
markers.go Marker store interface and file implementation

Documentation

Overview

Package persistence provides session marker storage abstractions. This decouples session management from filesystem operations, improving testability and enabling alternative storage backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileMarkerStore

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

FileMarkerStore implements SessionMarkerStore using the local filesystem. Markers are stored as empty files with a .lock extension.

func NewDefaultFileMarkerStore

func NewDefaultFileMarkerStore() *FileMarkerStore

NewDefaultFileMarkerStore creates a FileMarkerStore in the default location. Uses ~/.hotplex/sessions on success, falls back to temp directory on failure.

func NewFileMarkerStore

func NewFileMarkerStore(markerDir string) (*FileMarkerStore, error)

NewFileMarkerStore creates a new FileMarkerStore with the given base directory. If the directory doesn't exist, it will be created.

func (*FileMarkerStore) Create

func (s *FileMarkerStore) Create(sessionID string) error

Create creates a session marker file.

func (*FileMarkerStore) Delete

func (s *FileMarkerStore) Delete(sessionID string) error

Delete removes a session marker file.

func (*FileMarkerStore) Dir

func (s *FileMarkerStore) Dir() string

Dir returns the marker directory path.

func (*FileMarkerStore) Exists

func (s *FileMarkerStore) Exists(sessionID string) bool

Exists checks if a session marker file exists.

type InMemoryMarkerStore

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

InMemoryMarkerStore implements SessionMarkerStore using an in-memory map. Useful for testing and scenarios where persistence is not required.

func NewInMemoryMarkerStore

func NewInMemoryMarkerStore() *InMemoryMarkerStore

NewInMemoryMarkerStore creates a new InMemoryMarkerStore.

func (*InMemoryMarkerStore) Create

func (s *InMemoryMarkerStore) Create(sessionID string) error

Create creates a session marker in memory.

func (*InMemoryMarkerStore) Delete

func (s *InMemoryMarkerStore) Delete(sessionID string) error

Delete removes a session marker from memory.

func (*InMemoryMarkerStore) Dir

func (s *InMemoryMarkerStore) Dir() string

Dir returns an empty string for in-memory store.

func (*InMemoryMarkerStore) Exists

func (s *InMemoryMarkerStore) Exists(sessionID string) bool

Exists checks if a session marker exists in memory.

type SessionMarkerStore

type SessionMarkerStore interface {
	// Exists checks if a session marker exists for the given session ID.
	Exists(sessionID string) bool

	// Create creates a session marker for the given session ID.
	// Returns an error if the marker cannot be created.
	Create(sessionID string) error

	// Delete removes the session marker for the given session ID.
	// Returns an error if the marker cannot be deleted.
	Delete(sessionID string) error

	// Dir returns the base directory where markers are stored.
	Dir() string
}

SessionMarkerStore defines the interface for session marker persistence. Session markers are used to track whether a CLI session can be resumed (e.g., Claude Code's --resume functionality).

Jump to

Keyboard shortcuts

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