task

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package task defines backend-agnostic DTOs and interfaces for issue tracking. All UI, mode, and orchestration code consumes these types instead of beads-specific types. Backend implementations (beads, future linear/github/etc.) adapt their native types to these DTOs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Services returns the task-layer services produced by this backend.
	Services() BackendServices

	// CheckCompatibility verifies that the backend's data store is compatible
	// with this version of perles. Returns *VersionIncompatibleError if the
	// data store version is too old, nil if compatible.
	CheckCompatibility() error

	// FlushCaches invalidates all internal caches so subsequent queries
	// hit the data store instead of returning stale results.
	FlushCaches(ctx context.Context) error

	// Close releases all backend resources (database connections, etc.).
	Close() error
}

Backend is the top-level interface for a task-tracking backend. Each backend (beads, github, linear, etc.) implements this interface. The composition root creates a Backend via a factory function and passes it to the application layer, which uses Services() for task operations and FlushCaches() when the underlying data store changes on disk.

type BackendCapabilities

type BackendCapabilities struct {
	SupportsQuery        bool   // Can execute structured queries
	QueryLanguageName    string // "BQL", "JQL", etc. — shown in UI
	SupportsDependencies bool   // BlockedBy/Blocks tracking
	SupportsTree         bool   // Parent/child hierarchy
	SupportsComments     bool
	SupportsLabels       bool
	SupportsPriority     bool
	SupportsDesignField  bool
	SupportsNotesField   bool
}

BackendCapabilities describes what a backend supports. This lets the UI gracefully degrade for backends that lack certain features.

type BackendServices

type BackendServices struct {
	TaskExecutor      TaskExecutor
	QueryExecutor     QueryExecutor
	QueryHelpers      QueryHelpers        // nil if backend has no structured query language
	SyntaxHighlighter SyntaxHighlighter   // nil if backend has no query syntax highlighting
	Capabilities      BackendCapabilities // what the backend supports
	WatcherConfig     WatcherConfig       // file watcher configuration
	DBPath            string              // path to data store file (for watcher)
}

BackendServices holds all task-layer services produced by a backend. Each backend implementation (beads, etc.) constructs these internally and exposes them via a Services() method.

type Comment

type Comment struct {
	ID        int       `json:"id"`
	Author    string    `json:"author"`
	Text      string    `json:"text"`
	CreatedAt time.Time `json:"created_at"`
}

Comment represents a comment on an issue.

type CreateResult

type CreateResult struct {
	ID    string `json:"id"`
	Title string `json:"title"`
}

CreateResult holds the result of a create operation.

type DependencyEdge

type DependencyEdge struct {
	TargetID string
	Type     string // "parent-child", "blocks", "discovered-from"
}

DependencyEdge represents one edge in a dependency graph.

type DependencyGraph

type DependencyGraph struct {
	Forward map[string][]DependencyEdge
	Reverse map[string][]DependencyEdge
}

DependencyGraph holds the full dependency graph for all issues. Forward edges: issue_id -> depends_on_id Reverse edges: depends_on_id -> issue_id

type Issue

type Issue struct {
	ID                 string    `json:"id"`
	TitleText          string    `json:"title"`
	DescriptionText    string    `json:"description"`
	Design             string    `json:"design"`
	AcceptanceCriteria string    `json:"acceptance_criteria"`
	Notes              string    `json:"notes"`
	Status             Status    `json:"status"`
	Priority           Priority  `json:"priority"`
	Type               IssueType `json:"type"`
	Assignee           string    `json:"assignee"`
	Labels             []string  `json:"labels"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
	ClosedAt           time.Time `json:"closed_at"`
	CloseReason        string    `json:"close_reason,omitempty"`
	ParentID           string    `json:"parent_id"`

	// Dependency tracking
	BlockedBy      []string `json:"blocked_by"`
	Blocks         []string `json:"blocks"`
	Children       []string `json:"children"`
	DiscoveredFrom []string `json:"discovered_from"`
	Discovered     []string `json:"discovered"`

	// Comments (populated on demand)
	Comments     []Comment `json:"comments,omitempty"`
	CommentCount int       `json:"comment_count,omitempty"`

	// Extensions allows backends to carry provider-specific data without
	// polluting the shared type. For example, beads agent fields (HookBead,
	// RoleBead, etc.) are stored here for round-tripping. UI code should
	// not read these directly.
	Extensions map[string]any `json:"extensions,omitempty"`
}

Issue is the canonical task DTO used throughout the application. Backend implementations map their native types to this struct.

func BuildIssue

func BuildIssue(id string, opts ...IssueOption) Issue

BuildIssue creates a task.Issue with sensible defaults and applies options. Defaults: TitleText="Issue {id}", Type=TypeTask, Priority=PriorityMedium, Status=StatusOpen.

Example:

issue := task.BuildIssue("bd-1",
    task.WithTitle("Fix auth bug"),
    task.WithType(task.TypeBug),
    task.WithPriority(task.PriorityHigh),
    task.WithLabels("security", "urgent"),
)

func BuildIssuePtr

func BuildIssuePtr(id string, opts ...IssueOption) *Issue

BuildIssuePtr is like BuildIssue but returns a pointer.

type IssueOption

type IssueOption func(*Issue)

IssueOption configures a task.Issue during construction.

func WithAcceptanceCriteria

func WithAcceptanceCriteria(ac string) IssueOption

WithAcceptanceCriteria sets the acceptance criteria.

func WithAssignee

func WithAssignee(a string) IssueOption

WithAssignee sets the issue assignee.

func WithBlockedBy

func WithBlockedBy(ids ...string) IssueOption

WithBlockedBy sets the issue IDs that block this issue.

func WithBlocks

func WithBlocks(ids ...string) IssueOption

WithBlocks sets the issue IDs that this issue blocks.

func WithChildren

func WithChildren(ids ...string) IssueOption

WithChildren sets the child issue IDs.

func WithCloseReason

func WithCloseReason(reason string) IssueOption

WithCloseReason sets the close reason.

func WithClosedAt

func WithClosedAt(t time.Time) IssueOption

WithClosedAt sets the closed_at timestamp.

func WithCommentCount

func WithCommentCount(n int) IssueOption

WithCommentCount sets the comment count without populating comments.

func WithComments

func WithComments(comments ...Comment) IssueOption

WithComments sets the issue comments.

func WithCreatedAt

func WithCreatedAt(t time.Time) IssueOption

WithCreatedAt sets the created_at timestamp.

func WithDescription

func WithDescription(desc string) IssueOption

WithDescription sets the issue description.

func WithDesign

func WithDesign(design string) IssueOption

WithDesign sets the issue design field.

func WithDiscovered

func WithDiscovered(ids ...string) IssueOption

WithDiscovered sets the discovered issue IDs.

func WithDiscoveredFrom

func WithDiscoveredFrom(ids ...string) IssueOption

WithDiscoveredFrom sets the discovered-from issue IDs.

func WithExtension

func WithExtension(key string, value any) IssueOption

WithExtension sets a single extension key-value pair. Initializes the Extensions map if nil.

func WithExtensions

func WithExtensions(ext map[string]any) IssueOption

WithExtensions sets the entire extensions map.

func WithLabels

func WithLabels(labels ...string) IssueOption

WithLabels sets the issue labels.

func WithNotes

func WithNotes(notes string) IssueOption

WithNotes sets the issue notes.

func WithParentID

func WithParentID(id string) IssueOption

WithParentID sets the parent issue ID.

func WithPriority

func WithPriority(p Priority) IssueOption

WithPriority sets the issue priority.

func WithStatus

func WithStatus(s Status) IssueOption

WithStatus sets the issue status.

func WithTitle

func WithTitle(title string) IssueOption

WithTitle sets the issue title.

func WithType

func WithType(t IssueType) IssueOption

WithType sets the issue type.

func WithUpdatedAt

func WithUpdatedAt(t time.Time) IssueOption

WithUpdatedAt sets the updated_at timestamp.

type IssueType

type IssueType string

IssueType categorizes the nature of work.

const (
	TypeBug     IssueType = "bug"
	TypeFeature IssueType = "feature"
	TypeTask    IssueType = "task"
	TypeEpic    IssueType = "epic"
	TypeChore   IssueType = "chore"
)

type Priority

type Priority int

Priority represents issue urgency (0 = critical, 4 = backlog).

const (
	PriorityCritical Priority = 0
	PriorityHigh     Priority = 1
	PriorityMedium   Priority = 2
	PriorityLow      Priority = 3
	PriorityBacklog  Priority = 4
)

type QueryExecutor

type QueryExecutor interface {
	Execute(query string) ([]Issue, error)
}

QueryExecutor executes queries and returns matching issues. Each backend defines its own query language/strategy. The query string format is backend-dependent (BQL for beads, etc.).

type QueryHelpers

type QueryHelpers interface {
	// BuildIDQuery constructs a query to fetch issues by their IDs.
	BuildIDQuery(ids []string) string

	// IsStructuredQuery returns true if the input looks like a structured query
	// (e.g. BQL) vs a plain text search.
	IsStructuredQuery(input string) bool

	// ValidateQuery validates a query string, returning an error if invalid.
	ValidateQuery(query string) error
}

QueryHelpers provides optional utility functions that backends may implement. If a backend does not support structured queries, these methods should return sensible defaults or errors.

type ServerDownError

type ServerDownError struct {
	Host string
	Port int
}

ServerDownError indicates the backend's server is not reachable. This is used by backends that require an external server process (e.g., Dolt in server mode).

func (*ServerDownError) Error

func (e *ServerDownError) Error() string

type Status

type Status string

Status represents the lifecycle state of an issue.

const (
	StatusOpen       Status = "open"
	StatusInProgress Status = "in_progress"
	StatusClosed     Status = "closed"
	StatusDeferred   Status = "deferred"
	StatusBlocked    Status = "blocked"
)

type SyntaxHighlighter

type SyntaxHighlighter interface {
	// NewSyntaxLexer returns a syntax lexer for highlighting query input.
	// The returned value should implement the vimtextarea.SyntaxLexer interface.
	NewSyntaxLexer() any
}

SyntaxHighlighter provides query syntax highlighting for the UI. Backends that support structured query languages implement this to provide syntax highlighting in the search input.

type TaskExecutor

type TaskExecutor interface {
	TaskReader
	TaskWriter
}

TaskExecutor combines read and write operations on issues.

type TaskReader

type TaskReader interface {
	ShowIssue(issueID string) (*Issue, error)
	GetComments(issueID string) ([]Comment, error)
}

TaskReader provides read access to individual issues and their comments.

type TaskWriter

type TaskWriter interface {
	UpdateStatus(issueID string, status Status) error
	UpdatePriority(issueID string, priority Priority) error
	UpdateType(issueID string, issueType IssueType) error
	UpdateTitle(issueID, title string) error
	UpdateDescription(issueID, description string) error
	UpdateNotes(issueID, notes string) error
	CloseIssue(issueID, reason string) error
	ReopenIssue(issueID string) error
	SetLabels(issueID string, labels []string) error
	AddComment(issueID, author, text string) error
	CreateEpic(title, description string, labels []string) (CreateResult, error)
	CreateTask(title, description, parentID, assignee string, labels []string) (CreateResult, error)
	DeleteIssues(issueIDs []string) error
	AddDependency(taskID, dependsOnID string) error
	UpdateIssue(issueID string, opts UpdateOptions) error
}

TaskWriter provides write access to issues.

type UpdateOptions

type UpdateOptions struct {
	Title       *string
	Description *string
	Notes       *string
	Priority    *Priority
	Status      *Status
	Labels      *[]string  // nil = unchanged, &[]string{} = clear all
	Assignee    *string    // nil = unchanged
	Type        *IssueType // nil = unchanged
}

UpdateOptions specifies which fields to update on an issue. Nil pointer fields are skipped (not sent to the backend).

type VersionIncompatibleError

type VersionIncompatibleError struct {
	Current  string // version found in the data store (or "unknown")
	Required string // minimum version required by this backend
}

VersionIncompatibleError indicates the backend data store version is too old for this version of perles.

func (*VersionIncompatibleError) Error

func (e *VersionIncompatibleError) Error() string

type WatcherConfig

type WatcherConfig struct {
	// RelevantFiles lists the base filenames that should trigger a refresh.
	// For example: ["beads.db", "beads.db-wal"] for SQLite backends.
	RelevantFiles []string

	// DebounceDuration is how long to wait after the last filesystem event
	// before publishing a change notification. Zero means use default (100ms).
	DebounceDuration time.Duration
}

WatcherConfig holds backend-specific file watcher configuration.

Jump to

Keyboard shortcuts

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