session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package session manages lifecycle operations (start, delete, continue, promote, spawn).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WorkerSpawnRegistry

func WorkerSpawnRegistry(master state.Manifest, overrides *agent.ConfigOverrides) (*agent.Registry, error)

WorkerSpawnRegistry resolves the worker agent layout for a master. Workers inherit the master's primary agent. The companion is strictly opt-in via overrides.Companion — when no companion override is given, the worker has no companion regardless of the user's [roles.companion] config. When the resolved primary and companion are the same agent, this fails before any tmux work, naming both roles in the error.

func WorkerSpawnRegistryWithBase

func WorkerSpawnRegistryWithBase(master state.Manifest, base *agent.Registry, overrides *agent.ConfigOverrides) (*agent.Registry, error)

Types

type ContinueResult

type ContinueResult struct {
	SessionID      string
	Reattach       bool // true if session was already running
	Master         bool
	RevivedWorkers []string // worker IDs auto-continued on master cascade
	FailedWorkers  []string // worker IDs that failed to auto-continue
}

ContinueResult holds the outcome of a Continue operation.

type Service

type Service struct {
	Store    *state.Store
	Client   *tmux.Client
	RepoRoot string
	Registry *agent.Registry

	// CLIResolver resolves the questmaster launch command. Defaults to config.ResolveQuestmasterCmd.
	CLIResolver func(repoRoot string) (string, error)
	// Now returns the current unix timestamp. Defaults to time.Now().Unix().
	Now func() int64
	// RandSuffix returns a random int for session ID dedup.
	RandSuffix func() int64
}

Service provides session lifecycle operations backed by state and tmux.

func NewService

func NewService(store *state.Store, client *tmux.Client, repoRoot string, registry ...*agent.Registry) *Service

NewService creates a session service with production defaults.

func (*Service) Continue

func (s *Service) Continue(ctx context.Context, sessionID string) (ContinueResult, error)

Continue resumes a stopped session or reattaches to a running one.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, sessionID string) error

Delete removes a session completely: kills tmux, cleans runtime, removes manifest.

func (*Service) DeleteWorkers

func (s *Service) DeleteWorkers(ctx context.Context, masterID string) error

DeleteWorkers removes every worker recorded on a master manifest. Missing or non-master manifests are no-ops so Delete keeps its historical behavior for stale and corrupt manifest state.

func (*Service) Deregister

func (s *Service) Deregister(sessionID string) error

Deregister removes a session from its parent master's worker list and cleans up. Returns an error if manifest deletion fails (stale manifest would linger). "Manifest not found" is tolerated — the desired state is already achieved.

func (*Service) Promote

func (s *Service) Promote(ctx context.Context, sessionID string) error

Promote converts a worker or standalone session to a master session. Handles both the legacy classic layout (in-place companion-pane respawn, single window) and the current sidebar layout (replace the tracker pane in the workspace window, kill the hidden companion window).

func (*Service) Resize

func (s *Service) Resize(ctx context.Context, sessionID string) error

Resize resets the pane layout to canonical widths for the given session. Finds the left pane (tracker or companion) and the shell pane by role, then resizes left to leftPaneWidth and shell to shellPaneWidth.

func (*Service) Spawn

func (s *Service) Spawn(ctx context.Context, masterID string, opts SpawnOpts) (StartResult, error)

Spawn creates a new worker session owned by the given master.

func (*Service) Start

func (s *Service) Start(ctx context.Context, opts StartOpts) (StartResult, error)

Start creates and launches a new party session.

type SpawnOpts

type SpawnOpts struct {
	Title string
	Cwd   string
	// ResumeIDs maps agent name → resume ID.
	ResumeIDs map[string]string
	// Prompt is the worker's first user turn.
	Prompt string
	// SystemBrief is a rare worker-only system override appended after
	// the built-in worker system prompt.
	SystemBrief string
	Detached    bool
	Registry    *agent.Registry
}

SpawnOpts configures a worker session spawned from a master.

type StartOpts

type StartOpts struct {
	Title            string
	Cwd              string
	Master           bool
	IncludeCompanion bool
	MasterID         string // parent master session ID (for worker spawn)
	// ResumeIDs maps agent name → resume ID (e.g. {"claude": "abc", "codex": "xyz"}).
	ResumeIDs   map[string]string
	Prompt      string
	SystemBrief string
	Detached    bool
}

StartOpts configures a new session launch.

Prompt is the initial user-turn message (Claude `-- <prompt>`, Codex positional). SystemBrief is a rare standalone/worker system override that is appended after the built-in standalone or worker system prompt.

type StartResult

type StartResult struct {
	SessionID  string
	RuntimeDir string
}

StartResult holds the outcome of a Start operation.

Jump to

Keyboard shortcuts

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