Documentation
¶
Overview ¶
Package session defines session domain types and interfaces. Active session names are unique by slug, which identifies their tmux session and clone directory.
Index ¶
- Constants
- Variables
- func CloneProtocolNames() []string
- func NameWithSuffix(name, suffix string) string
- func NormalizeTags(tags []string) ([]string, error)
- func ParseTags(s string) ([]string, error)
- func Slugify(name string) string
- func ToSessionName(raw string, fallbacks ...string) string
- func ValidateName(name string) error
- func ValidateServerName(name string) error
- func ValidateTag(tag string) error
- type CloneProtocol
- type Ref
- type Session
- func (s *Session) ActivatedAt() time.Time
- func (s *Session) CanRecycle() bool
- func (s *Session) ClearMeta(key string)
- func (s *Session) EditTags(add, remove []string) error
- func (s *Session) GetMeta(key string) string
- func (s *Session) Group() string
- func (s *Session) HasAllTags(required []string) bool
- func (s *Session) HasTag(tag string) bool
- func (s *Session) InboxTopic() string
- func (s *Session) MarkActive(now time.Time)
- func (s *Session) MarkCorrupted(now time.Time)
- func (s *Session) MarkRecycled(now time.Time)
- func (s *Session) SetGroup(group string)
- func (s *Session) SetMeta(key, value string)
- type State
- type Store
Constants ¶
const ( MetaTmuxSession = "tmux_session" // tmux session name // DiscoverSession reads legacy "tmux_pane" metadata as a fallback so sessions // persisted before the tmux_window rename remain discoverable; the fallback can // be dropped after one release cycle. MetaTmuxWindow = "tmux_window" )
Metadata keys for terminal integration.
const ( CloneStrategyFull = "full" CloneStrategyWorktree = "worktree" )
Clone strategy constants.
const LocalServer = "local"
LocalServer is the server name of this machine in a Ref. No entry under servers: may use it.
const MaxNameLength = 60
MaxNameLength keeps a long title from producing an unwieldy tmux name or path.
const MaxTagLength = 40
MaxTagLength keeps a tag short enough to show as a chip beside a session name.
const MetaActivatedAt = "activated_at" // start of the current active lifecycle
Metadata keys for session lifecycle.
const MetaGroup = "group" // user-assigned group for tree view grouping
Metadata keys for session organization.
const (
MetaWorktreeBranch = "worktree_branch" // branch name used by the git worktree
)
Metadata keys for worktree sessions.
Variables ¶
var ( ErrNotFound = errors.New("session not found") ErrDuplicateName = errors.New("session name already exists") // ErrNotActive is a session that is recycled or corrupted, so it has no // checkout to open a terminal in. ErrNotActive = errors.New("session is not active") )
Sentinel errors for session operations.
var ErrInvalidCloneProtocol = fmt.Errorf("not a valid CloneProtocol, try [%s]", strings.Join(_CloneProtocolNames, ", "))
var ErrInvalidTag = errors.New("invalid tag")
ErrInvalidTag wraps every error ValidateTag returns.
Functions ¶
func CloneProtocolNames ¶ added in v0.66.0
func CloneProtocolNames() []string
CloneProtocolNames returns a list of possible string values of CloneProtocol.
func NameWithSuffix ¶
NameWithSuffix appends "-suffix", shortening name to stay within MaxNameLength.
func NormalizeTags ¶ added in v0.67.0
NormalizeTags trims each tag and drops empty ones and repeats. Tags compare case-insensitively, and the first spelling wins.
func ParseTags ¶ added in v0.67.0
ParseTags splits a comma-separated list, as typed into an editor or a flag, and normalizes it.
func Slugify ¶
Slugify lowercases name, folds accents, and joins the remaining letters and digits with single hyphens: "Café/Menu" -> "cafe-menu".
func ToSessionName ¶
ToSessionName turns generated text into a valid, length-capped slug, trying each fallback when raw has no letters or digits. It returns "" if none does.
func ValidateName ¶
ValidateName checks a name's length and characters, not its uniqueness.
func ValidateServerName ¶ added in v0.68.0
ValidateServerName checks a name under servers:. A name is letters, digits, and _ . -, starts with a letter or digit, and is not LocalServer, so a "<server>:<id>" Ref stays one plain argument on a command line and in a hive:// link.
func ValidateTag ¶ added in v0.67.0
ValidateTag checks one tag. A comma is refused because editors and command lines use it to separate tags.
Types ¶
type CloneProtocol ¶ added in v0.66.0
type CloneProtocol string
CloneProtocol is the transport hive uses for clone URLs it generates.
ENUM(https, ssh)
const ( // CloneProtocolHttps is a CloneProtocol of type https. CloneProtocolHttps CloneProtocol = "https" // CloneProtocolSsh is a CloneProtocol of type ssh. CloneProtocolSsh CloneProtocol = "ssh" )
func ParseCloneProtocol ¶ added in v0.66.0
func ParseCloneProtocol(name string) (CloneProtocol, error)
ParseCloneProtocol attempts to convert a string to a CloneProtocol.
func (*CloneProtocol) AppendText ¶ added in v0.66.0
func (x *CloneProtocol) AppendText(b []byte) ([]byte, error)
AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.
Implementations must not retain b, nor mutate any bytes within b[:len(b)].
func (CloneProtocol) IsValid ¶ added in v0.66.0
func (x CloneProtocol) IsValid() bool
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (CloneProtocol) MarshalText ¶ added in v0.66.0
func (x CloneProtocol) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method.
func (CloneProtocol) String ¶ added in v0.66.0
func (x CloneProtocol) String() string
String implements the Stringer interface.
func (*CloneProtocol) UnmarshalText ¶ added in v0.66.0
func (x *CloneProtocol) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method.
type Ref ¶ added in v0.68.0
Ref names one session among every server a client works with. A session id is unique only on its own server.
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"
Tags []string `json:"tags,omitempty"`
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) ActivatedAt ¶ added in v0.61.0
ActivatedAt returns when the current active lifecycle started. Sessions from before activation tracking use UpdatedAt because reuse already refreshed it.
func (*Session) CanRecycle ¶
CanRecycle returns true if the session can be marked for recycling.
func (*Session) EditTags ¶ added in v0.67.0
EditTags adds and then removes tags. Removing a tag the session does not carry is not an error. Only the added tags are validated, so a tag stored before validation existed can still be removed.
func (*Session) GetMeta ¶
GetMeta returns the value for the given metadata key, or empty string if not set.
func (*Session) Group ¶
Group returns the user-assigned group for tree view organization, or empty string if unset.
func (*Session) HasAllTags ¶ added in v0.67.0
HasAllTags reports whether the session carries every tag in required.
func (*Session) HasTag ¶ added in v0.67.0
HasTag reports whether the session carries tag, ignoring case.
func (*Session) InboxTopic ¶
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) MarkActive ¶ added in v0.61.0
MarkActive starts a new active lifecycle while retaining the reusable clone.
func (*Session) MarkCorrupted ¶
MarkCorrupted transitions the session to the corrupted state.
func (*Session) MarkRecycled ¶
MarkRecycled transitions the session to the recycled state.
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
// Update reads a session, applies edit, and saves the result as one
// write that no other process can interleave with. Returns ErrNotFound
// if not found, and edit's error unchanged.
Update(ctx context.Context, id string, edit func(*Session) error) (Session, error)
// Delete removes a session by ID. Returns ErrNotFound if not found.
Delete(ctx context.Context, id string) error
// ReplaceRecycled removes the recycled session recycledID and saves next
// as one write, so two rows never share one clone. Returns ErrNotFound and
// saves nothing if recycledID is gone or no longer recycled, as when
// another create took the clone first.
ReplaceRecycled(ctx context.Context, recycledID string, next Session) error
}
Store defines persistence operations for sessions.