session

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package session provides session state capture and restoration.

Index

Constants

View Source
const StateVersion = 1

StateVersion is the schema version for migrations

Variables

This section is empty.

Functions

func ClearPromptHistory

func ClearPromptHistory(sessionName string) error

ClearPromptHistory removes all prompts for a session.

func Delete

func Delete(name string) error

Delete removes a saved session.

func Exists

func Exists(name string) bool

Exists checks if a saved session exists.

func GetRedactionConfig added in v1.7.0

func GetRedactionConfig() *redaction.Config

GetRedactionConfig returns the current redaction config (or nil if disabled).

func ListSessionDirs

func ListSessionDirs() ([]string, error)

ListSessionDirs returns all sessions that have prompt history.

func ResolveExplicitSessionName added in v1.7.0

func ResolveExplicitSessionName(input string, sessions []tmux.Session, allowPrefix bool) (string, string, error)

func Restore

func Restore(state *SessionState, opts RestoreOptions) error

Restore recreates a session from saved state.

func RestoreAgents

func RestoreAgents(sessionName string, state *SessionState, cmds AgentCommands) error

RestoreAgents launches the agents in the restored session. This is separated from Restore to allow for customization.

func Save

func Save(state *SessionState, opts SaveOptions) (string, error)

Save writes a session state to disk.

func SavePrompt

func SavePrompt(entry PromptEntry) error

SavePrompt saves a prompt to the session's prompt history.

func SessionDir

func SessionDir(sessionName string) (string, error)

SessionDir returns the path to the session-specific directory. Creates the directory if it doesn't exist.

func SetRedactionConfig added in v1.7.0

func SetRedactionConfig(cfg *redaction.Config)

SetRedactionConfig sets the global redaction config for session prompt persistence. Pass nil to disable redaction.

func StorageDir

func StorageDir() string

StorageDir returns the path to the session storage directory. Uses ~/.ntm/sessions by default. Falls back to temp directory if home directory is unavailable.

Types

type AgentCommands

type AgentCommands struct {
	Claude string
	Codex  string
	Gemini string
}

AgentCommands defines the launch commands for agents.

type AgentConfig

type AgentConfig struct {
	Claude   int `json:"cc"`
	Codex    int `json:"cod"`
	Gemini   int `json:"gmi"`
	Cursor   int `json:"cursor"`
	Windsurf int `json:"windsurf"`
	Aider    int `json:"aider"`
	User     int `json:"user"`
}

AgentConfig represents agent counts by type.

func (AgentConfig) Total

func (a AgentConfig) Total() int

Total returns the total number of agents.

type ConfigSnapshot

type ConfigSnapshot struct {
	ClaudeCmd string `json:"claude_cmd,omitempty"`
	CodexCmd  string `json:"codex_cmd,omitempty"`
	GeminiCmd string `json:"gemini_cmd,omitempty"`
}

ConfigSnapshot captures relevant config at save time.

type PaneState

type PaneState struct {
	Title       string `json:"title"`             // e.g., "myproject__cc_1"
	Index       int    `json:"index"`             // Pane index
	WindowIndex int    `json:"window_index"`      // Window index
	AgentType   string `json:"agent_type"`        // "cc", "cod", "gmi", "user"
	Model       string `json:"model,omitempty"`   // Model variant if any
	Command     string `json:"command,omitempty"` // The agent launch command
	Active      bool   `json:"active"`            // Was this the active pane?
	Width       int    `json:"width,omitempty"`   // Pane width
	Height      int    `json:"height,omitempty"`  // Pane height
	PaneID      string `json:"pane_id,omitempty"` // Original pane ID
}

PaneState represents the state of a single pane.

type PromptEntry

type PromptEntry struct {
	ID        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Session   string    `json:"session"`
	Content   string    `json:"content"`
	Targets   []string  `json:"targets"` // Pane IDs or "all"
	Source    string    `json:"source"`  // "cli", "template", "file"
	Template  string    `json:"template,omitempty"`
	FilePath  string    `json:"file_path,omitempty"`
}

PromptEntry represents a saved prompt that was sent to agents.

func GetLatestPrompts

func GetLatestPrompts(sessionName string, limit int) ([]PromptEntry, error)

GetLatestPrompts returns the N most recent prompts for a session.

type PromptHistory

type PromptHistory struct {
	Session  string        `json:"session"`
	Prompts  []PromptEntry `json:"prompts"`
	UpdateAt time.Time     `json:"updated_at"`
}

PromptHistory contains all prompts for a session.

func LoadPromptHistory

func LoadPromptHistory(sessionName string) (*PromptHistory, error)

LoadPromptHistory loads the prompt history for a session.

type ResolveExplicitSessionNameError added in v1.7.0

type ResolveExplicitSessionNameError struct {
	Kind      ResolveExplicitSessionNameErrorKind
	Input     string
	Matches   []string // ambiguous
	Available []string // not_found
}

func (*ResolveExplicitSessionNameError) Error added in v1.7.0

type ResolveExplicitSessionNameErrorKind added in v1.7.0

type ResolveExplicitSessionNameErrorKind string
const (
	ResolveExplicitSessionNameErrorNoSessions ResolveExplicitSessionNameErrorKind = "no_sessions"
	ResolveExplicitSessionNameErrorNotFound   ResolveExplicitSessionNameErrorKind = "not_found"
	ResolveExplicitSessionNameErrorAmbiguous  ResolveExplicitSessionNameErrorKind = "ambiguous"
)

type RestoreOptions

type RestoreOptions struct {
	Name         string // Name to restore as (defaults to saved name)
	SkipGitCheck bool   // Skip git branch verification
	Force        bool   // Force restore even if session exists
}

RestoreOptions configures how a session is restored.

type SaveOptions

type SaveOptions struct {
	Name        string // Custom name (defaults to session name)
	Overwrite   bool   // Overwrite existing save
	IncludeGit  bool   // Include git context
	Description string // Optional description
}

SaveOptions configures how a session is saved.

type SavedSession

type SavedSession struct {
	Name      string    `json:"name"`
	SavedAt   time.Time `json:"saved_at"`
	WorkDir   string    `json:"cwd"`
	Agents    int       `json:"agents"`
	GitBranch string    `json:"git_branch,omitempty"`
	FilePath  string    `json:"file_path"`
	FileSize  int64     `json:"file_size"`
}

SavedSession represents a saved session entry.

func List

func List() ([]SavedSession, error)

List returns all saved sessions.

type SessionState

type SessionState struct {
	// Identity
	Name    string    `json:"name"`
	SavedAt time.Time `json:"saved_at"`

	// Context
	WorkDir   string `json:"cwd"`
	GitBranch string `json:"git_branch,omitempty"`
	GitRemote string `json:"git_remote,omitempty"`
	GitCommit string `json:"git_commit,omitempty"`

	// Agent Configuration (counts by type)
	Agents AgentConfig `json:"agents"`

	// Pane Details (for exact recreation)
	Panes []PaneState `json:"panes"`

	// Layout
	Layout string `json:"layout"` // "tiled", "even-horizontal", etc.

	// Metadata
	CreatedAt time.Time `json:"created_at,omitempty"` // Original session creation
	Version   int       `json:"version"`              // Schema version for migrations

	// Optional: Configuration snapshot
	Config *ConfigSnapshot `json:"config,omitempty"`
}

SessionState represents a complete session snapshot for restoration.

func Capture

func Capture(sessionName string) (*SessionState, error)

Capture captures the current state of a tmux session.

func Load

func Load(name string) (*SessionState, error)

Load reads a session state from disk.

Jump to

Keyboard shortcuts

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