hive

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package hive provides the service layer for orchestrating hive operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderUserCommandWindows added in v0.32.0

func RenderUserCommandWindows(renderer *tmpl.Renderer, windows []config.WindowConfig, data map[string]any) ([]coretmux.RenderedWindow, error)

RenderUserCommandWindows renders windows from a UserCommand using the provided template data map. Unlike RenderWindows, it accepts map[string]any to include .Form and session variables.

func RenderWindows added in v0.32.0

func RenderWindows(renderer *tmpl.Renderer, windows []config.WindowConfig, data SpawnData) ([]coretmux.RenderedWindow, error)

RenderWindows renders a slice of WindowConfig templates against SpawnData, producing fully-resolved RenderedWindow values ready for the tmux Client.

Types

type App

type App struct {
	Sessions *SessionService
	Messages *MessageService
	Context  *ContextService
	Doctor   *DoctorService

	Bus      *eventbus.EventBus
	Terminal *terminal.Manager
	Plugins  *plugins.Manager
	Config   *config.Config
	DB       *db.DB
	KV       kv.KV
	Renderer *tmpl.Renderer
	Build    BuildInfo
}

App is the central entry point for all hive operations. Commands and TUI consume App instead of cherry-picking raw dependencies.

func NewApp

func NewApp(
	sessions *SessionService,
	msgStore messaging.Store,
	cfg *config.Config,
	bus *eventbus.EventBus,
	termMgr *terminal.Manager,
	pluginMgr *plugins.Manager,
	database *db.DB,
	kvStore kv.KV,
	renderer *tmpl.Renderer,
	pluginInfos []doctor.PluginInfo,
) *App

NewApp constructs an App from explicit dependencies.

type BuildInfo added in v0.32.0

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

BuildInfo holds build-time metadata set by the main package.

type ContextService

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

ContextService manages per-repository context directories.

func NewContextService

func NewContextService(cfg *config.Config, gitClient git.Git) *ContextService

NewContextService creates a new ContextService.

func (c *ContextService) CreateSymlink(ctxDir string) (bool, error)

CreateSymlink creates a symlink from the current directory to the context directory. Returns true if the symlink already existed and pointed to the correct target.

func (*ContextService) Init

func (c *ContextService) Init(ctxDir string) ([]string, error)

Init creates the context directory and standard subdirectories. Returns the list of subdirectories that were newly created.

func (*ContextService) Prune

func (c *ContextService) Prune(ctxDir string, olderThan time.Duration) (int, error)

Prune deletes files in the context directory older than the given duration. Returns the number of files removed.

func (*ContextService) ResolveDir

func (c *ContextService) ResolveDir(ctx context.Context, repo string, shared bool) (string, error)

ResolveDir determines the context directory for the given repo spec. If repo is "owner/repo", it resolves directly. If shared is true, returns the shared dir. Otherwise detects from the current directory's git remote.

type CreateOptions

type CreateOptions struct {
	Name          string // Session name (used in path)
	SessionID     string // Session ID (auto-generated if empty)
	Prompt        string // Prompt to pass to spawned terminal (batch only)
	Remote        string // Git remote URL to clone (auto-detected if empty)
	Source        string // Source directory for file copying
	UseBatchSpawn bool   // Use batch_spawn commands instead of spawn
	// SkipSpawn skips the configured spawn strategy (spawn: / batch_spawn: / windows:).
	// The caller is responsible for launching any terminal or tmux session. Use this
	// when the session directory is needed but terminal management happens elsewhere
	// (e.g. CreateSessionWithWindows, which creates the tmux session itself).
	SkipSpawn bool
}

CreateOptions configures session creation.

type DoctorService

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

DoctorService runs health checks on the hive setup.

func NewDoctorService

func NewDoctorService(store session.Store, cfg *config.Config, pluginInfos []doctor.PluginInfo) *DoctorService

NewDoctorService creates a new DoctorService.

func (*DoctorService) RunChecks

func (d *DoctorService) RunChecks(ctx context.Context, configPath string, autofix bool) []doctor.Result

RunChecks executes all doctor checks and returns results.

type FileCopier

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

FileCopier copies files from a source directory to a destination.

func NewFileCopier

func NewFileCopier(log zerolog.Logger, stdout io.Writer) *FileCopier

NewFileCopier creates a new FileCopier.

func (*FileCopier) CopyFiles

func (c *FileCopier) CopyFiles(ctx context.Context, rule config.Rule, sourceDir, destDir string) error

CopyFiles copies files matching the rule's copy patterns from sourceDir to destDir.

type HookRunner

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

HookRunner executes repository-specific setup hooks.

func NewHookRunner

func NewHookRunner(log zerolog.Logger, executor executil.Executor, stdout, stderr io.Writer) *HookRunner

NewHookRunner creates a new HookRunner.

func (*HookRunner) RunHooks

func (h *HookRunner) RunHooks(ctx context.Context, rule config.Rule, path string) error

RunHooks executes the commands from a matched rule.

type MessageService

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

MessageService wraps messaging.Store with domain logic.

func NewMessageService

func NewMessageService(store messaging.Store, cfg *config.Config, bus *eventbus.EventBus) *MessageService

NewMessageService creates a new MessageService.

func (*MessageService) Acknowledge

func (m *MessageService) Acknowledge(ctx context.Context, consumerID string, messageIDs []string) error

Acknowledge marks messages as read by a consumer.

func (*MessageService) GenerateTopic

func (m *MessageService) GenerateTopic(prefix string) string

GenerateTopic creates a new topic name using the configured prefix and a random suffix.

func (*MessageService) GetUnread

func (m *MessageService) GetUnread(ctx context.Context, consumerID string, topic string) ([]messaging.Message, error)

GetUnread returns messages not yet acknowledged by consumer.

func (*MessageService) ListTopics

func (m *MessageService) ListTopics(ctx context.Context) ([]string, error)

ListTopics returns all topic names.

func (*MessageService) Prune

func (m *MessageService) Prune(ctx context.Context, olderThan time.Duration) (int, error)

Prune removes messages older than the given duration.

func (*MessageService) Publish

func (m *MessageService) Publish(ctx context.Context, msg messaging.Message, topics []string) error

Publish adds a message to multiple topics.

func (*MessageService) Subscribe

func (m *MessageService) Subscribe(ctx context.Context, topic string, since time.Time) ([]messaging.Message, error)

Subscribe returns all messages for a topic, optionally filtered by since timestamp.

type RecycleData

type RecycleData struct {
	DefaultBranch string
}

RecycleData contains template data for recycle commands.

type Recycler

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

Recycler handles resetting a session environment for reuse.

func NewRecycler

func NewRecycler(log zerolog.Logger, executor executil.Executor, renderer *tmpl.Renderer) *Recycler

NewRecycler creates a new Recycler.

func (*Recycler) Recycle

func (r *Recycler) Recycle(ctx context.Context, path string, commands []string, data RecycleData, w io.Writer) error

Recycle executes recycle commands sequentially in the session directory. Commands are rendered as Go templates with the provided data. Output is written to the provided writer. If w is nil, output is discarded.

type SessionClient added in v0.32.0

type SessionClient interface {
	CreateSession(ctx context.Context, name, workDir string, windows []coretmux.RenderedWindow, background bool) error
	OpenSession(ctx context.Context, name, workDir string, windows []coretmux.RenderedWindow, background bool, targetWindow string) error
	AddWindows(ctx context.Context, name, workDir string, windows []coretmux.RenderedWindow) error
	AttachOrSwitch(ctx context.Context, name string) error
}

SessionClient is the interface used by consumers that create/open tmux sessions.

type SessionService

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

SessionService orchestrates hive session operations.

func NewSessionService

func NewSessionService(
	sessions session.Store,
	gitClient git.Git,
	cfg *config.Config,
	bus *eventbus.EventBus,
	exec executil.Executor,
	renderer *tmpl.Renderer,
	log zerolog.Logger,
	stdout, stderr io.Writer,
) *SessionService

NewSessionService creates a new SessionService.

func (*SessionService) AddWindowsToTmuxSession added in v0.32.0

func (s *SessionService) AddWindowsToTmuxSession(ctx context.Context, tmuxName, workDir string, windows []action.WindowSpec, background bool) error

AddWindowsToTmuxSession adds windows to an existing tmux session, converting action.WindowSpec to coretmux.RenderedWindow. Satisfies the command.WindowSpawner interface.

func (*SessionService) CreateSession

func (s *SessionService) CreateSession(ctx context.Context, opts CreateOptions) (*session.Session, error)

CreateSession creates a new session or recycles an existing one.

func (*SessionService) CreateSessionWithWindows added in v0.32.0

func (s *SessionService) CreateSessionWithWindows(ctx context.Context, req action.NewSessionRequest, windows []action.WindowSpec, background bool) error

CreateSessionWithWindows creates a new Hive session, optionally runs shCmd in its directory, then opens tmux windows in it. Non-zero shCmd exit aborts window creation. Satisfies the command.WindowSpawner interface.

func (*SessionService) DeleteSession

func (s *SessionService) DeleteSession(ctx context.Context, id string) error

DeleteSession removes a session and its directory.

func (*SessionService) DetectRemote

func (s *SessionService) DetectRemote(ctx context.Context, dir string) (string, error)

DetectRemote gets the git remote URL from the specified directory.

func (*SessionService) DetectSession

func (s *SessionService) DetectSession(ctx context.Context) (string, error)

DetectSession returns the session ID for the current working directory. Returns empty string if not in a hive session.

func (*SessionService) GetSession

func (s *SessionService) GetSession(ctx context.Context, id string) (session.Session, error)

GetSession returns a session by ID.

func (*SessionService) Git

func (s *SessionService) Git() git.Git

Git returns the git client for use in background operations.

func (*SessionService) ListSessions

func (s *SessionService) ListSessions(ctx context.Context) ([]session.Session, error)

ListSessions returns all sessions.

func (*SessionService) OpenTmuxSession added in v0.32.0

func (s *SessionService) OpenTmuxSession(ctx context.Context, name, path, remote, targetWindow string, background bool) error

OpenTmuxSession opens (or creates) a tmux session for the given session parameters. It resolves the spawn strategy, renders window templates, and delegates to the spawner.

func (*SessionService) Prune

func (s *SessionService) Prune(ctx context.Context, all bool) (int, error)

Prune removes recycled and corrupted sessions and their directories. If all is true, deletes ALL recycled sessions. If all is false, respects max_recycled limit per repository (keeps newest N).

func (*SessionService) RecycleSession

func (s *SessionService) RecycleSession(ctx context.Context, id string, w io.Writer) error

RecycleSession marks a session for recycling and runs recycle commands. The session directory is not moved; only the DB record state changes. Output is written to w. If w is nil, output is discarded.

func (*SessionService) RenameSession

func (s *SessionService) RenameSession(ctx context.Context, id, newName string) error

RenameSession changes the name (and slug) of an existing session.

func (*SessionService) SilenceOutput added in v0.32.0

func (s *SessionService) SilenceOutput() (restore func())

SilenceOutput redirects all output to io.Discard and returns a restore function that reverts to the previous writers. Call before starting the TUI to prevent hook and spawn output from corrupting the terminal display.

type SpawnData

type SpawnData struct {
	Path       string // Absolute path to session directory
	Name       string // Session name (display name)
	Prompt     string // User-provided prompt (batch only)
	Slug       string // Session slug (URL-safe version of name)
	ContextDir string // Path to context directory
	Owner      string // Repository owner
	Repo       string // Repository name
}

SpawnData is the template context for spawn commands.

type Spawner

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

Spawner handles terminal spawning with template rendering.

func NewSpawner

func NewSpawner(log zerolog.Logger, executor executil.Executor, renderer *tmpl.Renderer, tmuxClient SessionClient, stdout, stderr io.Writer) *Spawner

NewSpawner creates a new Spawner.

func (*Spawner) AddWindowsToTmuxSession added in v0.32.0

func (s *Spawner) AddWindowsToTmuxSession(ctx context.Context, tmuxName, workDir string, windows []coretmux.RenderedWindow, background bool) error

AddWindowsToTmuxSession adds pre-rendered windows to an existing tmux session. If background is false, switches to the session after adding windows.

func (*Spawner) OpenWindows added in v0.32.0

func (s *Spawner) OpenWindows(ctx context.Context, windows []config.WindowConfig, data SpawnData, background bool, targetWindow string) error

OpenWindows renders window templates and opens (or creates) a tmux session. If the session already exists, it attaches to it (optionally selecting targetWindow).

func (*Spawner) Spawn

func (s *Spawner) Spawn(ctx context.Context, commands []string, data SpawnData) error

Spawn executes spawn commands sequentially with template rendering.

func (*Spawner) SpawnWindows added in v0.32.0

func (s *Spawner) SpawnWindows(ctx context.Context, windows []config.WindowConfig, data SpawnData, background bool) error

SpawnWindows renders window templates and creates a tmux session.

Directories

Path Synopsis
Package plugins provides a plugin system for extending Hive with additional commands and status providers.
Package plugins provides a plugin system for extending Hive with additional commands and status providers.
beads
Package beads provides a Beads issue tracker plugin for Hive.
Package beads provides a Beads issue tracker plugin for Hive.
claude
Package claude provides Claude Code integration for Hive.
Package claude provides Claude Code integration for Hive.
contextdir
Package contextdir provides commands for opening context directories.
Package contextdir provides commands for opening context directories.
github
Package github provides a GitHub plugin for Hive.
Package github provides a GitHub plugin for Hive.
lazygit
Package lazygit provides a lazygit plugin for Hive.
Package lazygit provides a lazygit plugin for Hive.
neovim
Package neovim provides a Neovim plugin for Hive.
Package neovim provides a Neovim plugin for Hive.
tmux
Package tmux provides a tmux plugin for Hive with default session management commands.
Package tmux provides a tmux plugin for Hive with default session management commands.
Package scripts embeds and extracts bundled helper scripts (hive-tmux, agent-send).
Package scripts embeds and extracts bundled helper scripts (hive-tmux, agent-send).

Jump to

Keyboard shortcuts

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