Documentation
¶
Overview ¶
Package db handles database operations for Drover
Package db provides database utilities for Drover
Index ¶
- func ExtractBaseID(id string) string
- func GenerateHierarchicalID(baseID string, level int, sequence int) string
- func GetIDDepth(id string) int
- func GetParentIDFromHierarchicalID(id string) string
- func IsSubTask(id string) bool
- func ParseHierarchicalID(id string) (string, int, int, error)
- func ValidateHierarchicalID(id string, maxDepth int) error
- type ConversationStore
- type FileSpec
- type Operator
- type Plan
- type PlanStatus
- type PlanStep
- type ProjectStatus
- type SessionExport
- type SessionShare
- type Store
- func (s *Store) AddFeedback(planID string, feedback string) error
- func (s *Store) AddGuidance(taskID, message string) (*types.GuidanceMessage, error)
- func (s *Store) ApprovePlan(planID, approvedBy string) error
- func (s *Store) CancelTask(taskID, reason string) error
- func (s *Store) ClaimTask(workerID string) (*types.Task, error)
- func (s *Store) ClaimTaskForEpic(workerID, epicID string) (*types.Task, error)
- func (s *Store) ClearGuidance(taskID string) error
- func (s *Store) Close() error
- func (s *Store) CompleteCheckpoint(taskID string, verdict types.TaskVerdict, reason string) error
- func (s *Store) CompleteTask(taskID string) error
- func (s *Store) ConversationStore() ConversationStore
- func (s *Store) CreateCheckpoint(checkpoint *types.TaskCheckpoint) error
- func (s *Store) CreateEpic(title, description string) (*types.Epic, error)
- func (s *Store) CreateOperator(name string) (*Operator, error)
- func (s *Store) CreateSessionShare(sessionJSON, createdBy string, expiresHours int) (*SessionShare, error)
- func (s *Store) CreateSubTask(title, description, parentID string, priority int, blockedBy []string) (*types.Task, error)
- func (s *Store) CreateSubTaskWithSequence(title, description, parentID string, sequence int, priority int, ...) (*types.Task, error)
- func (s *Store) CreateTask(title, description, epicID string, priority int, blockedBy []string) (*types.Task, error)
- func (s *Store) CreateTaskWithOperator(title, description, epicID string, priority int, blockedBy []string, ...) (*types.Task, error)
- func (s *Store) CreateTaskWithTestConfig(title, description, epicID string, priority int, blockedBy []string, ...) (*types.Task, error)
- func (s *Store) CreateWorktree(taskID, path, branch string) error
- func (s *Store) DeleteCheckpoint(taskID string) error
- func (s *Store) DeleteOperator(name string) error
- func (s *Store) DeletePlan(planID string) error
- func (s *Store) DeleteSessionShare(token string) error
- func (s *Store) DeleteWorktree(taskID string) error
- func (s *Store) FindOrphanedCheckpoints(heartbeatTimeout int64) ([]*types.TaskCheckpoint, error)
- func (s *Store) GetBlockedBy(taskID string) ([]string, error)
- func (s *Store) GetCheckpoint(taskID string) (*types.TaskCheckpoint, error)
- func (s *Store) GetOperatorByAPIKey(apiKey string) (*Operator, error)
- func (s *Store) GetOperatorByName(name string) (*Operator, error)
- func (s *Store) GetOrphanedWorktrees(worktreeDir string) ([]string, error)
- func (s *Store) GetParentTask(taskID string) (*types.Task, error)
- func (s *Store) GetPendingGuidance(taskID string) ([]*types.GuidanceMessage, error)
- func (s *Store) GetPlan(planID string) (*Plan, error)
- func (s *Store) GetPlanByTaskID(taskID string) (*Plan, error)
- func (s *Store) GetProjectStatus() (*ProjectStatus, error)
- func (s *Store) GetRecentCompletedTasks(epicID string, limit int, maxAgeSeconds int64) ([]*types.Task, error)
- func (s *Store) GetSessionShareByToken(token string) (*SessionShare, error)
- func (s *Store) GetSubTasks(parentID string) ([]*types.Task, error)
- func (s *Store) GetTask(taskID string) (*types.Task, error)
- func (s *Store) GetTaskStatus(taskID string) (types.TaskStatus, error)
- func (s *Store) GetTaskTree(taskID string) (*types.Task, error)
- func (s *Store) GetWorktreeStats() (map[string]int64, error)
- func (s *Store) GetWorktreesForCleanup(completedOnly bool) ([]*WorktreeInfo, error)
- func (s *Store) HasSubTasks(taskID string) (bool, error)
- func (s *Store) ImportSession(session *SessionExport) error
- func (s *Store) IncrementShareAccess(token string) error
- func (s *Store) IncrementTaskAttempts(taskID string) error
- func (s *Store) InitSchema() error
- func (s *Store) ListAllDependencies() ([]types.TaskDependency, error)
- func (s *Store) ListEpics() ([]*types.Epic, error)
- func (s *Store) ListOperators() ([]*Operator, error)
- func (s *Store) ListPlans(status PlanStatus) ([]*Plan, error)
- func (s *Store) ListTasks() ([]*types.Task, error)
- func (s *Store) ListTasksByEpic(epicID string) ([]*types.Task, error)
- func (s *Store) ListWorktrees() ([]*WorktreeInfo, error)
- func (s *Store) MarkGuidanceDelivered(guidanceIDs []string) error
- func (s *Store) MigrateSchema() error
- func (s *Store) PauseTask(taskID string) error
- func (s *Store) QueryEvents(eventTypes []string, epicID, taskID string, since, until int64, limit int) ([]map[string]any, error)
- func (s *Store) RecordEvent(id string, eventType string, timestamp int64, taskID, epicID string, ...) error
- func (s *Store) RejectPlan(planID, reason string) error
- func (s *Store) ResetTasks(statusesToReset []types.TaskStatus) (int, error)
- func (s *Store) ResetTasksByIDs(taskIDs []string) (int, error)
- func (s *Store) ResolveTask(taskID string, note string) error
- func (s *Store) ResumeTask(taskID string) error
- func (s *Store) RetryTask(taskID string, force bool) error
- func (s *Store) SavePlan(plan *Plan) error
- func (s *Store) SetTaskTestConfig(taskID, testMode, testScope, testCommand string) error
- func (s *Store) SetTaskVerdict(taskID string, verdict types.TaskVerdict, reason string) error
- func (s *Store) TouchWorktree(taskID string) error
- func (s *Store) UpdateCheckpoint(taskID string, output string, heartbeat int64) error
- func (s *Store) UpdateOperatorLastActive(name string) error
- func (s *Store) UpdatePlanStatus(planID string, status PlanStatus, reason string) error
- func (s *Store) UpdateTaskStatus(taskID string, status types.TaskStatus, lastError string) error
- func (s *Store) UpdateWorktreeDiskSize(taskID string, size int64) error
- func (s *Store) UpdateWorktreeStatus(taskID, status string) error
- type WorktreeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractBaseID ¶
ExtractBaseID returns the base ID without sequence numbers
Examples:
"task-123.1.2" -> "task-123" "task-123.1" -> "task-123" "task-123" -> "task-123"
func GenerateHierarchicalID ¶
GenerateHierarchicalID creates a new hierarchical ID baseID: parent task ID (e.g., "task-123") level: depth level (1 or 2) sequence: position among siblings (1-indexed)
Examples:
GenerateHierarchicalID("task-123", 1, 1) -> "task-123.1"
GenerateHierarchicalID("task-123.1", 2, 2) -> "task-123.1.2"
func GetIDDepth ¶
GetIDDepth returns the depth level of a hierarchical ID Returns:
0 = base task (no dots) 1 = first-level sub-task 2 = second-level sub-task
func GetParentIDFromHierarchicalID ¶
GetParentIDFromHierarchicalID returns the parent task ID from a hierarchical ID Returns empty string if the ID is already a base task (no parent)
Examples:
"task-123.1" -> "task-123" "task-123.1.2" -> "task-123.1" "task-123" -> ""
func ParseHierarchicalID ¶
ParseHierarchicalID extracts components from a hierarchical ID Returns: (baseID, level1Seq, level2Seq, error)
Examples:
"task-123" -> ("task-123", 0, 0, nil)
"task-123.1" -> ("task-123", 1, 0, nil)
"task-123.1.2" -> ("task-123", 1, 2, nil)
"task-123.5.10" -> ("task-123", 5, 10, nil)
"invalid" -> ("", 0, 0, error)
func ValidateHierarchicalID ¶
ValidateHierarchicalID checks if an ID is valid and within depth limit maxDepth: maximum allowed depth (typically 2)
Types ¶
type ConversationStore ¶
type ConversationStore interface {
CreateConversation(ctx context.Context, taskID, worktree string) (*types.Conversation, error)
GetConversation(ctx context.Context, conversationID string) (*types.Conversation, error)
GetConversationByTask(ctx context.Context, taskID string) (*types.Conversation, error)
UpdateConversationStatus(ctx context.Context, conversationID string, status types.ConversationStatus) error
DeleteConversation(ctx context.Context, conversationID string) error
AppendTurn(ctx context.Context, turn *types.ConversationTurn) error
GetRecentTurns(ctx context.Context, conversationID string, limit int) ([]*types.ConversationTurn, error)
GetTurnsByTokenBudget(ctx context.Context, conversationID string, maxTokens int) ([]*types.ConversationTurn, error)
GetTurnsByRange(ctx context.Context, conversationID string, start, end int) ([]*types.ConversationTurn, error)
SearchTurns(ctx context.Context, query string, limit int) ([]*types.ConversationSearchResult, error)
SearchTurnsInConversation(ctx context.Context, conversationID, query string, limit int) ([]*types.ConversationSearchResult, error)
BuildContext(ctx context.Context, taskID string, options *conversation.BuildContextOptions) (*types.ConversationContext, error)
ResumeConversation(ctx context.Context, taskID string) (*types.ConversationContext, error)
GetStats(ctx context.Context, conversationID string) (*types.ConversationStats, error)
PruneConversation(ctx context.Context, conversationID string, options *conversation.PruneOptions) (int, error)
ArchiveConversation(ctx context.Context, conversationID string) error
}
ConversationStore interface for db.Store
type FileSpec ¶
type FileSpec struct {
Path string `json:"path"`
Operation string `json:"operation"`
Reason string `json:"reason,omitempty"`
EstimatedLines int `json:"estimated_lines,omitempty"`
}
FileSpec represents a file operation
type Plan ¶
type Plan struct {
ID string `json:"id"`
TaskID string `json:"task_id"`
Title string `json:"title"`
Description string `json:"description"`
Steps []PlanStep `json:"steps"`
FilesToCreate []FileSpec `json:"files_to_create,omitempty"`
FilesToModify []FileSpec `json:"files_to_modify,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
EstimatedTime time.Duration `json:"estimated_time,omitempty"`
Complexity string `json:"complexity,omitempty"`
RiskFactors []string `json:"risk_factors,omitempty"`
Status PlanStatus `json:"status"`
ApprovedBy string `json:"approved_by,omitempty"`
ApprovedAt *time.Time `json:"approved_at,omitempty"`
RejectionReason string `json:"rejection_reason,omitempty"`
Revision int `json:"revision"`
ParentPlanID string `json:"parent_plan_id,omitempty"`
Feedback []string `json:"feedback,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy string `json:"created_by,omitempty"`
}
Plan represents a stored implementation plan
type PlanStatus ¶
type PlanStatus string
PlanStatus represents the approval status of a plan
const ( PlanStatusDraft PlanStatus = "draft" PlanStatusPending PlanStatus = "pending" PlanStatusApproved PlanStatus = "approved" PlanStatusRejected PlanStatus = "rejected" PlanStatusExecuting PlanStatus = "executing" PlanStatusCompleted PlanStatus = "completed" PlanStatusFailed PlanStatus = "failed" )
type PlanStep ¶
type PlanStep struct {
Order int `json:"order"`
Title string `json:"title"`
Description string `json:"description"`
Command string `json:"command,omitempty"`
Files []string `json:"files,omitempty"`
Dependencies []int `json:"dependencies,omitempty"`
EstimatedTime time.Duration `json:"estimated_time,omitempty"`
Verification string `json:"verification,omitempty"`
}
PlanStep represents a single step in the implementation plan
type ProjectStatus ¶
type ProjectStatus struct {
Total int
Ready int
Claimed int
InProgress int
Paused int
Blocked int
Completed int
Failed int
}
ProjectStatus summarizes the current state
type SessionExport ¶
type SessionExport struct {
Version string `json:"version"`
ExportedAt string `json:"exportedAt"`
Repository string `json:"repository"`
Tasks []*types.Task `json:"tasks"`
Epics []*types.Epic `json:"epics"`
Dependencies []types.TaskDependency `json:"dependencies"`
Worktrees []*WorktreeInfo `json:"worktrees"`
}
SessionExport represents a complete exported session
type Store ¶
Store manages database operations
func (*Store) AddFeedback ¶
AddFeedback adds feedback to a plan
func (*Store) AddGuidance ¶
func (s *Store) AddGuidance(taskID, message string) (*types.GuidanceMessage, error)
AddGuidance adds a guidance message to a task's queue
func (*Store) ApprovePlan ¶
ApprovePlan approves a plan
func (*Store) CancelTask ¶
CancelTask cancels a running or ready task
func (*Store) ClaimTask ¶
ClaimTask attempts to atomically claim a ready task
Uses UPDATE with ORDER BY and LIMIT to atomically find and claim a task in a single operation, avoiding race conditions between SELECT and UPDATE.
func (*Store) ClaimTaskForEpic ¶
ClaimTaskForEpic attempts to atomically claim a ready task, optionally filtered by epic
Uses UPDATE with ORDER BY and LIMIT to atomically find and claim a task in a single operation, avoiding race conditions between SELECT and UPDATE. If epicID is empty, claims any ready task. If epicID is set, only claims tasks in that epic.
func (*Store) ClearGuidance ¶
ClearGuidance removes all guidance messages for a task
func (*Store) CompleteCheckpoint ¶
CompleteCheckpoint marks a task checkpoint as completed
func (*Store) CompleteTask ¶
CompleteTask marks a task as completed and unblocks dependents
func (*Store) ConversationStore ¶
func (s *Store) ConversationStore() ConversationStore
ConversationStore returns the conversation store for this database
func (*Store) CreateCheckpoint ¶
func (s *Store) CreateCheckpoint(checkpoint *types.TaskCheckpoint) error
CreateCheckpoint creates a new checkpoint for a task
func (*Store) CreateEpic ¶
CreateEpic creates a new epic
func (*Store) CreateOperator ¶
CreateOperator creates a new operator with an API key
func (*Store) CreateSessionShare ¶
func (s *Store) CreateSessionShare(sessionJSON, createdBy string, expiresHours int) (*SessionShare, error)
CreateSessionShare creates a new shareable session link
func (*Store) CreateSubTask ¶
func (s *Store) CreateSubTask(title, description, parentID string, priority int, blockedBy []string) (*types.Task, error)
CreateSubTask creates a new sub-task with a hierarchical ID
func (*Store) CreateSubTaskWithSequence ¶
func (s *Store) CreateSubTaskWithSequence(title, description, parentID string, sequence int, priority int, blockedBy []string) (*types.Task, error)
CreateSubTaskWithSequence creates a new sub-task with a specific hierarchical ID This is used when the user specifies a sequence number via CLI syntax (e.g., task-123.5)
func (*Store) CreateTask ¶
func (s *Store) CreateTask(title, description, epicID string, priority int, blockedBy []string) (*types.Task, error)
CreateTask creates a new task with optional dependencies
func (*Store) CreateTaskWithOperator ¶
func (s *Store) CreateTaskWithOperator(title, description, epicID string, priority int, blockedBy []string, operator string) (*types.Task, error)
CreateTaskWithOperator creates a new task with an operator (user/creator)
func (*Store) CreateTaskWithTestConfig ¶
func (s *Store) CreateTaskWithTestConfig(title, description, epicID string, priority int, blockedBy []string, operator, testMode, testScope, testCommand string) (*types.Task, error)
CreateTaskWithTestConfig creates a new task with test configuration
func (*Store) CreateWorktree ¶
CreateWorktree records a new worktree in the database
func (*Store) DeleteCheckpoint ¶
DeleteCheckpoint removes a task's checkpoint
func (*Store) DeleteOperator ¶
DeleteOperator deletes an operator by name
func (*Store) DeletePlan ¶
DeletePlan deletes a plan
func (*Store) DeleteSessionShare ¶
DeleteSessionShare deletes a session share by token
func (*Store) DeleteWorktree ¶
DeleteWorktree removes a worktree record from the database
func (*Store) FindOrphanedCheckpoints ¶
func (s *Store) FindOrphanedCheckpoints(heartbeatTimeout int64) ([]*types.TaskCheckpoint, error)
FindOrphanedCheckpoints finds checkpoints that are in Running state but the worker is no longer alive
func (*Store) GetBlockedBy ¶
GetBlockedBy returns the list of task IDs that block the given task
func (*Store) GetCheckpoint ¶
func (s *Store) GetCheckpoint(taskID string) (*types.TaskCheckpoint, error)
GetCheckpoint retrieves a task's checkpoint
func (*Store) GetOperatorByAPIKey ¶
GetOperatorByAPIKey retrieves an operator by API key
func (*Store) GetOperatorByName ¶
GetOperatorByName retrieves an operator by name
func (*Store) GetOrphanedWorktrees ¶
GetOrphanedWorktrees returns worktrees that exist on disk but not in the database or have no corresponding task (task was deleted)
func (*Store) GetParentTask ¶
GetParentTask retrieves the parent task of a sub-task
func (*Store) GetPendingGuidance ¶
func (s *Store) GetPendingGuidance(taskID string) ([]*types.GuidanceMessage, error)
GetPendingGuidance retrieves undelivered guidance messages for a task
func (*Store) GetPlanByTaskID ¶
GetPlanByTaskID retrieves the latest plan for a specific task
func (*Store) GetProjectStatus ¶
func (s *Store) GetProjectStatus() (*ProjectStatus, error)
GetProjectStatus returns overall project status
func (*Store) GetRecentCompletedTasks ¶
func (s *Store) GetRecentCompletedTasks(epicID string, limit int, maxAgeSeconds int64) ([]*types.Task, error)
GetRecentCompletedTasks returns recently completed tasks for context carrying epicID: filter to tasks in the same epic (empty string = all epics) limit: maximum number of tasks to return maxAge: only return tasks completed within this duration (in seconds, 0 = no limit)
func (*Store) GetSessionShareByToken ¶
func (s *Store) GetSessionShareByToken(token string) (*SessionShare, error)
GetSessionShareByToken retrieves a session share by its token
func (*Store) GetSubTasks ¶
GetSubTasks retrieves all direct sub-tasks of a parent task
func (*Store) GetTaskStatus ¶
func (s *Store) GetTaskStatus(taskID string) (types.TaskStatus, error)
GetTaskStatus returns the current status of a task
func (*Store) GetTaskTree ¶
GetTaskTree retrieves a task with all its descendants (sub-tasks recursively)
func (*Store) GetWorktreeStats ¶
GetWorktreeStats returns statistics about worktrees
func (*Store) GetWorktreesForCleanup ¶
func (s *Store) GetWorktreesForCleanup(completedOnly bool) ([]*WorktreeInfo, error)
GetWorktreesForCleanup returns worktrees that can be cleaned up
func (*Store) HasSubTasks ¶
HasSubTasks returns true if a task has any sub-tasks
func (*Store) ImportSession ¶
func (s *Store) ImportSession(session *SessionExport) error
ImportSession imports a session from an export
func (*Store) IncrementShareAccess ¶
IncrementShareAccess increments the access count for a session share
func (*Store) IncrementTaskAttempts ¶
IncrementTaskAttempts increments the attempt counter for a task
func (*Store) InitSchema ¶
InitSchema creates the database schema
func (*Store) ListAllDependencies ¶
func (s *Store) ListAllDependencies() ([]types.TaskDependency, error)
ListAllDependencies returns all task dependencies in the database
func (*Store) ListOperators ¶
ListOperators returns all operators
func (*Store) ListPlans ¶
func (s *Store) ListPlans(status PlanStatus) ([]*Plan, error)
ListPlans lists all plans, optionally filtered by status
func (*Store) ListTasksByEpic ¶
ListTasksByEpic returns tasks filtered by epic ID If epicID is empty, returns all tasks
func (*Store) ListWorktrees ¶
func (s *Store) ListWorktrees() ([]*WorktreeInfo, error)
ListWorktrees returns all worktrees with their task information
func (*Store) MarkGuidanceDelivered ¶
MarkGuidanceDelivered marks guidance messages as delivered
func (*Store) MigrateSchema ¶
MigrateSchema runs database migrations for existing databases This adds new columns that weren't in the original schema
func (*Store) QueryEvents ¶
func (s *Store) QueryEvents(eventTypes []string, epicID, taskID string, since, until int64, limit int) ([]map[string]any, error)
QueryEvents retrieves events from the database with optional filtering
func (*Store) RecordEvent ¶
func (s *Store) RecordEvent(id string, eventType string, timestamp int64, taskID, epicID string, dataJSON string) error
RecordEvent records an event in the database
func (*Store) RejectPlan ¶
RejectPlan rejects a plan
func (*Store) ResetTasks ¶
func (s *Store) ResetTasks(statusesToReset []types.TaskStatus) (int, error)
ResetTasks resets tasks with given statuses back to ready
func (*Store) ResetTasksByIDs ¶
ResetTasksByIDs resets specific tasks by their IDs back to ready status
func (*Store) ResolveTask ¶
ResolveTask removes all blockers for a blocked task, setting it to ready
func (*Store) ResumeTask ¶
ResumeTask resumes a paused task
func (*Store) RetryTask ¶
RetryTask resets a failed task to ready status for retry If force is true, also resets the attempt counter
func (*Store) SetTaskTestConfig ¶
SetTaskTestConfig updates the test configuration for a task
func (*Store) SetTaskVerdict ¶
SetTaskVerdict sets the structured verdict for a task
func (*Store) TouchWorktree ¶
TouchWorktree updates the last_used_at timestamp
func (*Store) UpdateCheckpoint ¶
UpdateCheckpoint updates a task's checkpoint (typically heartbeat or output)
func (*Store) UpdateOperatorLastActive ¶
UpdateOperatorLastActive updates the last active timestamp
func (*Store) UpdatePlanStatus ¶
func (s *Store) UpdatePlanStatus(planID string, status PlanStatus, reason string) error
UpdatePlanStatus updates the status of a plan
func (*Store) UpdateTaskStatus ¶
UpdateTaskStatus updates a task's status
func (*Store) UpdateWorktreeDiskSize ¶
UpdateWorktreeDiskSize updates the disk size of a worktree
func (*Store) UpdateWorktreeStatus ¶
UpdateWorktreeStatus updates the status of a worktree