session

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package session defines session domain types and interfaces.

Index

Constants

View Source
const (
	MetaTmuxSession = "tmux_session" // tmux session name
	MetaTmuxPane    = "tmux_pane"    // tmux pane identifier
)

Metadata keys for terminal integration.

View Source
const (
	CloneStrategyFull     = "full"
	CloneStrategyWorktree = "worktree"
)

Clone strategy constants.

View Source
const (
	MetaGroup = "group" // user-assigned group for tree view grouping
)

Metadata keys for session organization.

View Source
const (
	MetaWorktreeBranch = "worktree_branch" // branch name used by the git worktree
)

Metadata keys for worktree sessions.

Variables

View Source
var (
	ErrNotFound      = errors.New("session not found")
	ErrDuplicateName = errors.New("session name already exists")
)

Sentinel errors for session operations.

Functions

func Slugify

func Slugify(name string) string

Slugify converts a name to a URL-safe slug for use in directory paths and tmux session names. "My Session Name" -> "my-session-name" "dev/test-thing" -> "dev-test-thing"

func ValidateName added in v0.45.0

func ValidateName(name string) error

ValidateName returns an error if name contains characters outside the allowed set. Slugify maps all non-alphanumeric characters to hyphens, so the derived slug is always safe for tmux session names and git branch names regardless of what permitted characters appear in the raw name.

Types

type Session

type Session struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Slug          string            `json:"slug"`
	Path          string            `json:"path"`
	Remote        string            `json:"remote"`
	State         State             `json:"state"`
	CloneStrategy string            `json:"clone_strategy,omitempty"` // "full" (default) or "worktree"
	Metadata      map[string]string `json:"metadata,omitempty"`       // integration data (e.g., tmux session name)
	CreatedAt     time.Time         `json:"created_at"`
	UpdatedAt     time.Time         `json:"updated_at"`
}

Session represents an isolated git environment for an AI agent.

Terminology:

  • Session: The hive-managed git clone + terminal environment
  • Agent: The AI tool (Claude, Aider, etc.) running within the session
  • Tmux session: The terminal multiplexer session (if tmux integration enabled)

Relationship: Hive Session → spawns → Tmux Session → runs → Agent

Future: Hive will support multiple agents per session, enabling concurrent agents like a primary assistant and a test runner.

func (*Session) CanRecycle

func (s *Session) CanRecycle() bool

CanRecycle returns true if the session can be marked for recycling.

func (*Session) GetMeta

func (s *Session) GetMeta(key string) string

GetMeta returns the value for the given metadata key, or empty string if not set.

func (*Session) Group added in v0.33.0

func (s *Session) Group() string

Group returns the user-assigned group for tree view organization, or empty string if unset.

func (*Session) InboxTopic

func (s *Session) InboxTopic() string

InboxTopic returns the conventional inbox topic name for this session.

Format: agent.<session-id>.inbox

The "agent" prefix refers to the AI agent running in the session. When multi-agent support is added, named agents will use: agent.<session-id>.<agent-name>.inbox

Example: agent.26kj0c.inbox

func (*Session) MarkCorrupted

func (s *Session) MarkCorrupted(now time.Time)

MarkCorrupted transitions the session to the corrupted state.

func (*Session) MarkRecycled

func (s *Session) MarkRecycled(now time.Time)

MarkRecycled transitions the session to the recycled state.

func (*Session) SetGroup added in v0.33.0

func (s *Session) SetGroup(group string)

SetGroup sets the user-assigned group for tree view organization. An empty value clears the group assignment.

func (*Session) SetMeta

func (s *Session) SetMeta(key, value string)

SetMeta sets a metadata key-value pair, initializing the map if needed.

type State

type State string

State represents the lifecycle state of a session.

const (
	StateActive    State = "active"
	StateRecycled  State = "recycled"
	StateCorrupted State = "corrupted"
)

type Store

type Store interface {
	// List returns all sessions.
	List(ctx context.Context) ([]Session, error)
	// Get returns a session by ID. Returns ErrNotFound if not found.
	Get(ctx context.Context, id string) (Session, error)
	// Save creates or updates a session.
	Save(ctx context.Context, s Session) error
	// Delete removes a session by ID. Returns ErrNotFound if not found.
	Delete(ctx context.Context, id string) error
}

Store defines persistence operations for sessions.

Jump to

Keyboard shortcuts

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