session

package
v0.3.49 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 18 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 TitleFromPrompt added in v0.3.10

func TitleFromPrompt(prompt string) string

TitleFromPrompt derives a short, human-readable session title from a user's first message. It strips code and URLs, collapses whitespace, and keeps the leading clause. It returns "" when nothing usable remains, so callers can keep the title blank rather than persist a meaningless value.

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 unless a per-spawn override is provided.

func WorkerSpawnRegistryWithBase

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

Types

type ContinueResult

type ContinueResult struct {
	SessionID      string   `json:"session_id"`
	Reattach       bool     `json:"reattach"` // true if session was already running
	Master         bool     `json:"master"`
	RevivedWorkers []string `json:"revived_workers,omitempty"` // worker IDs auto-continued on master cascade
	FailedWorkers  []string `json:"failed_workers,omitempty"`  // 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) Promote

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

Promote converts a worker or standalone session to a master session.

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 questmaster session.

type SpawnOpts

type SpawnOpts struct {
	Title string
	Cwd   string
	// DisplayColor is an explicit named color selected for this worker.
	DisplayColor 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
	FromApp     bool
	// Model overrides the worker's primary agent model.
	Model string
	// ReasoningEffort overrides the worker's primary agent reasoning effort.
	ReasoningEffort string
}

SpawnOpts configures a worker session spawned from a master.

type StartOpts

type StartOpts struct {
	Title    string
	Cwd      string
	Shell    bool
	Master   bool
	MasterID string // parent master session ID (for worker spawn)
	// DisplayColor is the named display color persisted with session metadata.
	DisplayColor string
	// ResumeIDs maps agent name → resume ID (e.g. {"claude": "abc", "codex": "xyz"}).
	ResumeIDs   map[string]string
	Prompt      string
	SystemBrief string
	Detached    bool
	FromApp     bool
	// Model overrides the primary agent's model (worker spawn only). Empty
	// leaves the role default in place.
	Model string
	// ReasoningEffort overrides the primary agent's reasoning effort. Empty
	// leaves the role default in place.
	ReasoningEffort string
}

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
	Cwd        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