assign

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package assign implements intelligent work assignment for multi-agent workflows.

Package assign provides bead-to-agent assignment functionality.

Index

Constants

This section is empty.

Variables

View Source
var DefaultCapabilities = map[tmux.AgentType]map[TaskType]float64{
	tmux.AgentClaude: {
		TaskRefactor:      0.95,
		TaskAnalysis:      0.90,
		TaskDocs:          0.85,
		TaskDocumentation: 0.85,
		TaskBug:           0.80,
		TaskFeature:       0.85,
		TaskTesting:       0.75,
		TaskTask:          0.80,
		TaskChore:         0.70,
		TaskEpic:          0.90,
	},
	tmux.AgentCodex: {
		TaskRefactor:      0.75,
		TaskAnalysis:      0.70,
		TaskDocs:          0.70,
		TaskDocumentation: 0.70,
		TaskBug:           0.90,
		TaskFeature:       0.90,
		TaskTesting:       0.85,
		TaskTask:          0.85,
		TaskChore:         0.80,
		TaskEpic:          0.60,
	},
	tmux.AgentGemini: {
		TaskRefactor:      0.75,
		TaskAnalysis:      0.85,
		TaskDocs:          0.90,
		TaskDocumentation: 0.90,
		TaskBug:           0.75,
		TaskFeature:       0.80,
		TaskTesting:       0.80,
		TaskTask:          0.75,
		TaskChore:         0.75,
		TaskEpic:          0.75,
	},
}

DefaultCapabilities defines baseline scores for agent/task combinations. Scores range from 0.0 (unsuitable) to 1.0 (optimal).

Functions

func ExtractFilePaths

func ExtractFilePaths(title, description string) []string

ExtractFilePaths extracts file paths from a bead title and description. Patterns detected: - Explicit paths: src/api/handler.go, lib/utils.ts - Glob patterns: internal/**/*.go, *.json - Package references: internal/cli, pkg/api

func GetAgentScore

func GetAgentScore(agentType tmux.AgentType, taskType TaskType) float64

GetAgentScore returns the score for a given agent type and task type using the global capability matrix.

func GetAgentScoreByString

func GetAgentScoreByString(agentType string, taskType string) float64

GetAgentScoreByString returns the score using string identifiers, useful for integration with existing code that uses strings.

func ParseAgentType

func ParseAgentType(s string) tmux.AgentType

ParseAgentType converts a string to AgentType. Supports both short codes (cc, cod, gmi) and full names (claude, codex, gemini).

Types

type Agent

type Agent struct {
	ID           string         // Unique identifier (pane ID or name)
	AgentType    tmux.AgentType // cc, cod, gmi
	Model        string         // Specific model if known
	ContextUsage float64        // 0.0-1.0 (how much context is used)
	Idle         bool           // Whether agent is idle and available
	CurrentTask  string         // ID of current task if not idle
	Assignments  int            // Number of tasks already assigned this session
}

Agent represents an available worker agent.

type Assignment

type Assignment struct {
	Bead       Bead    `json:"bead"`
	Agent      Agent   `json:"agent"`
	Score      float64 `json:"score"`      // Combined score (0.0-1.0)
	Reason     string  `json:"reason"`     // Human-readable explanation
	Confidence float64 `json:"confidence"` // Confidence in this assignment (0.0-1.0)
}

Assignment represents a recommended bead-to-agent assignment.

func AssignTasksFunc

func AssignTasksFunc(beads []Bead, agents []Agent, strategy string) []Assignment

AssignTasksFunc is the function signature matching the bead requirements. This is a convenience wrapper around Matcher.AssignTasks.

type Bead

type Bead struct {
	ID          string   // Unique identifier (e.g., "bd-1tv6")
	Title       string   // Human-readable title
	Priority    int      // 0-4 (P0 = critical, P4 = low)
	TaskType    TaskType // Inferred or explicit task type
	UnblocksIDs []string // IDs of items this unblocks when completed
	Labels      []string // Additional labels/tags
}

Bead represents a work item to be assigned.

type CapabilityMatrix

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

CapabilityMatrix manages agent capability scores with support for configuration overrides and learned adjustments.

func GlobalMatrix

func GlobalMatrix() *CapabilityMatrix

GlobalMatrix returns the global capability matrix for advanced configuration.

func NewCapabilityMatrix

func NewCapabilityMatrix() *CapabilityMatrix

NewCapabilityMatrix creates a new matrix initialized with default capabilities.

func (*CapabilityMatrix) ClearLearned

func (m *CapabilityMatrix) ClearLearned()

ClearLearned removes all learned scores.

func (*CapabilityMatrix) ClearOverrides

func (m *CapabilityMatrix) ClearOverrides()

ClearOverrides removes all configuration overrides.

func (*CapabilityMatrix) GetScore

func (m *CapabilityMatrix) GetScore(agentType tmux.AgentType, taskType TaskType) float64

GetScore returns the effective score for an agent/task combination. Priority: learned > overrides > base > 0.5 (default)

func (*CapabilityMatrix) SetLearned

func (m *CapabilityMatrix) SetLearned(agentType tmux.AgentType, taskType TaskType, score float64)

SetLearned sets a learned score adjustment based on agent performance.

func (*CapabilityMatrix) SetOverride

func (m *CapabilityMatrix) SetOverride(agentType tmux.AgentType, taskType TaskType, score float64)

SetOverride sets a configuration override for a specific agent/task.

type FileReservationManager

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

FileReservationManager handles file path reservations for bead assignments.

func NewFileReservationManager

func NewFileReservationManager(client *agentmail.Client, projectKey string) *FileReservationManager

NewFileReservationManager creates a new file reservation manager.

func (*FileReservationManager) ReleaseByPaths

func (m *FileReservationManager) ReleaseByPaths(ctx context.Context, agentName string, paths []string) error

ReleaseByPaths releases reservations by path patterns.

func (*FileReservationManager) ReleaseForBead

func (m *FileReservationManager) ReleaseForBead(ctx context.Context, agentName string, reservationIDs []int) error

ReleaseForBead releases all reservations held by an agent for a bead.

func (*FileReservationManager) RenewReservations

func (m *FileReservationManager) RenewReservations(ctx context.Context, agentName string, extendSeconds int) error

RenewReservations extends the TTL for an agent's reservations.

func (*FileReservationManager) ReserveForBead

func (m *FileReservationManager) ReserveForBead(ctx context.Context, beadID, beadTitle, beadDescription, agentName string) (*FileReservationResult, error)

ReserveForBead reserves file paths mentioned in a bead for an agent.

func (*FileReservationManager) SetTTL

func (m *FileReservationManager) SetTTL(seconds int)

SetTTL sets the TTL for reservations in seconds.

type FileReservationResult

type FileReservationResult struct {
	BeadID         string                          `json:"bead_id"`
	AgentName      string                          `json:"agent_name"`
	RequestedPaths []string                        `json:"requested_paths"`
	GrantedPaths   []string                        `json:"granted_paths"`
	Conflicts      []agentmail.ReservationConflict `json:"conflicts,omitempty"`
	ReservationIDs []int                           `json:"reservation_ids"`
	Success        bool                            `json:"success"`
	Error          string                          `json:"error,omitempty"`
}

FileReservationResult contains the result of a file reservation attempt.

type Matcher

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

Matcher performs bead-to-agent assignment.

func NewMatcher

func NewMatcher() *Matcher

NewMatcher creates a new Matcher with the global capability matrix.

func NewMatcherWithMatrix

func NewMatcherWithMatrix(matrix *CapabilityMatrix) *Matcher

NewMatcherWithMatrix creates a Matcher with a custom capability matrix.

func (*Matcher) AssignTasks

func (m *Matcher) AssignTasks(beads []Bead, agents []Agent, strategy Strategy) []Assignment

AssignTasks matches beads to agents based on the specified strategy. Returns assignments sorted by score (highest first).

func (*Matcher) WithConfig

func (m *Matcher) WithConfig(config MatcherConfig) *Matcher

WithConfig sets the matcher configuration.

type MatcherConfig

type MatcherConfig struct {
	MaxContextUsage float64 // Maximum context usage to consider agent available (default: 0.9)
	MinConfidence   float64 // Minimum confidence to include in results (default: 0.3)
}

MatcherConfig configures the assignment algorithm.

func DefaultMatcherConfig

func DefaultMatcherConfig() MatcherConfig

DefaultMatcherConfig returns sensible defaults.

type Strategy

type Strategy string

Strategy represents work assignment strategies.

const (
	// StrategyBalanced spreads work evenly across agents.
	StrategyBalanced Strategy = "balanced"
	// StrategySpeed assigns to any available agent quickly.
	StrategySpeed Strategy = "speed"
	// StrategyQuality assigns to the highest-scoring agent for the task.
	StrategyQuality Strategy = "quality"
	// StrategyDependency prioritizes blockers and dependency chains.
	StrategyDependency Strategy = "dependency"
	// StrategyRoundRobin distributes work evenly across agents in round-robin fashion.
	StrategyRoundRobin Strategy = "round-robin"
)

func ParseStrategy

func ParseStrategy(s string) Strategy

ParseStrategy converts a string to Strategy with validation.

type TaskType

type TaskType string

TaskType represents categories of work for capability matching.

const (
	TaskRefactor      TaskType = "refactor"
	TaskAnalysis      TaskType = "analysis"
	TaskDocs          TaskType = "docs"
	TaskDocumentation TaskType = "documentation" // alias for docs
	TaskBug           TaskType = "bug"
	TaskFeature       TaskType = "feature"
	TaskTesting       TaskType = "testing"
	TaskTask          TaskType = "task"
	TaskChore         TaskType = "chore"
	TaskEpic          TaskType = "epic"
)

func ParseTaskType

func ParseTaskType(s string) TaskType

ParseTaskType converts a string to TaskType.

Jump to

Keyboard shortcuts

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