Documentation
¶
Overview ¶
Package db provides SQLite database operations.
Index ¶
- Constants
- Variables
- func DefaultExecutor() string
- func DefaultPath() string
- func IsInProgress(status string) bool
- type Attachment
- type DB
- func (db *DB) AddAttachment(taskID int64, filename, mimeType string, data []byte) (*Attachment, error)
- func (db *DB) AddDependency(blockerID, blockedID int64, autoQueue bool) error
- func (db *DB) AllocatePort(taskID int64) (int, error)
- func (db *DB) AppendTaskLog(taskID int64, lineType, content string) error
- func (db *DB) ClearArchiveState(taskID int64) error
- func (db *DB) ClearTaskLogs(taskID int64) error
- func (db *DB) ClearTaskTmuxIDs(taskID int64) error
- func (db *DB) ClearTaskWorktreePath(taskID int64) error
- func (db *DB) CompleteOnboarding() error
- func (db *DB) CountAttachments(taskID int64) (int, error)
- func (db *DB) CountTasksByProject(projectName string) (int, error)
- func (db *DB) CountTasksByStatus(status string) (int, error)
- func (db *DB) CreateProject(p *Project) error
- func (db *DB) CreateTask(t *Task) error
- func (db *DB) CreateTaskType(t *TaskType) error
- func (db *DB) DeleteAttachment(id int64) error
- func (db *DB) DeleteProject(id int64) error
- func (db *DB) DeleteTask(id int64) error
- func (db *DB) DeleteTaskType(id int64) error
- func (db *DB) GetActiveTaskPorts() (map[int]bool, error)
- func (db *DB) GetAllDependencies(taskID int64) (blockers []*Task, blockedBy []*Task, err error)
- func (db *DB) GetAllSettings() (map[string]string, error)
- func (db *DB) GetAttachment(id int64) (*Attachment, error)
- func (db *DB) GetBlockedBy(taskID int64) ([]*Task, error)
- func (db *DB) GetBlockers(taskID int64) ([]*Task, error)
- func (db *DB) GetConversationHistoryLogs(taskID int64) ([]*TaskLog, error)
- func (db *DB) GetDependency(blockerID, blockedID int64) (*Dependency, error)
- func (db *DB) GetExecutorUsageByProject(project string) (map[string]int, error)
- func (db *DB) GetLastExecutorForProject(project string) (string, error)
- func (db *DB) GetLastQuestion(taskID int64) (string, error)
- func (db *DB) GetLastTaskTypeForProject(project string) (string, error)
- func (db *DB) GetLastUsedProject() (string, error)
- func (db *DB) GetMostRecentlyCreatedTask() (*Task, error)
- func (db *DB) GetNextQueuedTask() (*Task, error)
- func (db *DB) GetOpenBlockerCount(taskID int64) (int, error)
- func (db *DB) GetProjectByName(name string) (*Project, error)
- func (db *DB) GetProjectByPath(cwd string) (*Project, error)
- func (db *DB) GetProjectContext(projectName string) (string, error)
- func (db *DB) GetQueuedTasks() ([]*Task, error)
- func (db *DB) GetRetryFeedback(taskID int64) (string, error)
- func (db *DB) GetSetting(key string) (string, error)
- func (db *DB) GetStaleWorktreeTasks(maxAge time.Duration) ([]*Task, error)
- func (db *DB) GetTagsList() ([]string, error)
- func (db *DB) GetTask(id int64) (*Task, error)
- func (db *DB) GetTaskLogCount(taskID int64) (int, error)
- func (db *DB) GetTaskLogs(taskID int64, limit int) ([]*TaskLog, error)
- func (db *DB) GetTaskLogsSince(taskID int64, sinceID int64) ([]*TaskLog, error)
- func (db *DB) GetTaskType(id int64) (*TaskType, error)
- func (db *DB) GetTaskTypeByName(name string) (*TaskType, error)
- func (db *DB) HasContinuationMarker(taskID int64) (bool, error)
- func (db *DB) IsBlocked(taskID int64) (bool, error)
- func (db *DB) IsFirstRun() bool
- func (db *DB) ListAttachments(taskID int64) ([]*Attachment, error)
- func (db *DB) ListAttachmentsWithData(taskID int64) ([]*Attachment, error)
- func (db *DB) ListProjects() ([]*Project, error)
- func (db *DB) ListTaskTypes() ([]*TaskType, error)
- func (db *DB) ListTasks(opts ListTasksOptions) ([]*Task, error)
- func (db *DB) MarkTaskStarted(id int64) error
- func (db *DB) Path() string
- func (db *DB) ProcessCompletedBlocker(blockerID int64) ([]*Task, error)
- func (db *DB) RecoverStaleTmuxRefs(activeSessions map[string]bool, validWindowIDs map[string]bool) (int, int, error)
- func (db *DB) RemoveDependency(blockerID, blockedID int64) error
- func (db *DB) RetryTask(id int64, feedback string) error
- func (db *DB) SaveArchiveState(taskID int64, archiveRef, archiveCommit, worktreePath, branchName string) error
- func (db *DB) SearchTasks(query string, limit int) ([]*Task, error)
- func (db *DB) SetAutoQueue(blockerID, blockedID int64, autoQueue bool) error
- func (db *DB) SetEventEmitter(emitter EventEmitter)
- func (db *DB) SetLastExecutorForProject(project, executor string) error
- func (db *DB) SetLastTaskTypeForProject(project, taskType string) error
- func (db *DB) SetLastUsedProject(project string) error
- func (db *DB) SetProjectContext(projectName string, context string) error
- func (db *DB) SetSetting(key, value string) error
- func (db *DB) UpdateProject(p *Project) error
- func (db *DB) UpdateTask(t *Task) error
- func (db *DB) UpdateTaskClaudeSessionID(taskID int64, sessionID string) error
- func (db *DB) UpdateTaskDaemonSession(taskID int64, daemonSession string) error
- func (db *DB) UpdateTaskDangerousMode(taskID int64, dangerousMode bool) error
- func (db *DB) UpdateTaskLastAccessedAt(taskID int64) error
- func (db *DB) UpdateTaskPRInfo(taskID int64, prURL string, prNumber int, prInfoJSON string) error
- func (db *DB) UpdateTaskPaneIDs(taskID int64, claudePaneID, shellPaneID string) error
- func (db *DB) UpdateTaskPinned(taskID int64, pinned bool) error
- func (db *DB) UpdateTaskStartedAt(taskID int64, t time.Time) error
- func (db *DB) UpdateTaskStatus(id int64, status string) error
- func (db *DB) UpdateTaskSummary(taskID int64, summary string) error
- func (db *DB) UpdateTaskType(t *TaskType) error
- func (db *DB) UpdateTaskWindowID(taskID int64, windowID string) error
- type Dependency
- type EventEmitter
- type ListTasksOptions
- type LocalTime
- type Project
- type ProjectAction
- type Task
- type TaskLog
- type TaskType
Constants ¶
const ( StatusBacklog = "backlog" // Created but not yet started StatusQueued = "queued" // Waiting to be processed StatusProcessing = "processing" // Currently being executed StatusBlocked = "blocked" // Needs input/clarification StatusDone = "done" // Completed StatusArchived = "archived" // Archived (hidden from view) )
Task statuses
const ( TypeCode = "code" TypeWriting = "writing" TypeThinking = "thinking" )
Task types (default values, actual types are stored in task_types table)
const ( ExecutorClaude = "claude" // Claude Code CLI (default) ExecutorCodex = "codex" // OpenAI Codex CLI ExecutorGemini = "gemini" // Google Gemini CLI ExecutorOpenClaw = "openclaw" // OpenClaw AI assistant (https://openclaw.ai) ExecutorOpenCode = "opencode" // OpenCode AI assistant (https://opencode.ai) ExecutorPi = "pi" // Pi coding agent (https://github.com/mariozechner/pi-coding-agent) )
Task executors
const ( PortRangeStart = 3100 // First port in the allocation range PortRangeEnd = 4099 // Last port in the allocation range (1000 ports total) )
Port allocation constants
Variables ¶
var DefaultProjectColors = []string{
"#C678DD",
"#61AFEF",
"#56B6C2",
"#98C379",
"#E5C07B",
"#E06C75",
"#D19A66",
"#ABB2BF",
}
DefaultProjectColors is a palette of distinct colors for projects. These are assigned to projects that don't have a color set.
var ErrProjectNotFound = fmt.Errorf("project not found")
ErrProjectNotFound is returned when a task is created with a non-existent project.
Functions ¶
func DefaultExecutor ¶
func DefaultExecutor() string
DefaultExecutor returns the default executor if none is specified.
func IsInProgress ¶
IsInProgress returns true if the task is actively being worked on.
Types ¶
type Attachment ¶
type Attachment struct {
ID int64
TaskID int64
Filename string
MimeType string
Size int64
Data []byte
CreatedAt LocalTime
}
Attachment represents a file attached to a task.
type DB ¶
DB wraps the SQLite database connection.
func (*DB) AddAttachment ¶
func (db *DB) AddAttachment(taskID int64, filename, mimeType string, data []byte) (*Attachment, error)
AddAttachment adds a file attachment to a task.
func (*DB) AddDependency ¶
AddDependency creates a dependency where blockerID blocks blockedID. Returns an error if the dependency already exists or would create a cycle.
func (*DB) AllocatePort ¶
AllocatePort assigns an available port to a task. Returns the allocated port, or an error if no ports are available.
func (*DB) AppendTaskLog ¶
AppendTaskLog appends a log entry to a task.
func (*DB) ClearArchiveState ¶
ClearArchiveState clears the archive state for a task after unarchiving.
func (*DB) ClearTaskLogs ¶
ClearTaskLogs clears all logs for a task.
func (*DB) ClearTaskTmuxIDs ¶
ClearTaskTmuxIDs clears all tmux-related IDs for a task. This should be called before retrying/restarting a task to prevent stale references. Clears: tmux_window_id, claude_pane_id, shell_pane_id
func (*DB) ClearTaskWorktreePath ¶
ClearTaskWorktreePath clears just the worktree_path for a task. Used during async archive cleanup to avoid overwriting other fields.
func (*DB) CompleteOnboarding ¶
CompleteOnboarding marks the onboarding as complete.
func (*DB) CountAttachments ¶
CountAttachments returns the number of attachments for a task.
func (*DB) CountTasksByProject ¶
CountTasksByProject returns the number of tasks associated with a project name.
func (*DB) CountTasksByStatus ¶
CountTasksByStatus returns the count of tasks with a given status.
func (*DB) CreateProject ¶
CreateProject creates a new project.
func (*DB) CreateTaskType ¶
CreateTaskType creates a new task type.
func (*DB) DeleteAttachment ¶
DeleteAttachment removes an attachment.
func (*DB) DeleteProject ¶
DeleteProject deletes a project.
func (*DB) DeleteTaskType ¶
DeleteTaskType deletes a task type (only non-builtin types can be deleted).
func (*DB) GetActiveTaskPorts ¶
GetActiveTaskPorts returns all ports currently in use by active (non-done, non-archived) tasks.
func (*DB) GetAllDependencies ¶
GetAllDependencies returns all dependencies for a given task (both blockers and blocked).
func (*DB) GetAllSettings ¶
GetAllSettings returns all settings as a map.
func (*DB) GetAttachment ¶
func (db *DB) GetAttachment(id int64) (*Attachment, error)
GetAttachment retrieves an attachment by ID.
func (*DB) GetBlockedBy ¶
GetBlockedBy returns all tasks that are blocked by the given task.
func (*DB) GetBlockers ¶
GetBlockers returns all tasks that block the given task.
func (*DB) GetConversationHistoryLogs ¶
GetConversationHistoryLogs retrieves only logs relevant for building conversation history. This is much more efficient than GetTaskLogs for the executor's prompt building, as it skips large output/tool log content that isn't needed for conversation context. Only fetches: continuation markers, questions, and user feedback.
func (*DB) GetDependency ¶
func (db *DB) GetDependency(blockerID, blockedID int64) (*Dependency, error)
GetDependency returns the dependency between two tasks, or nil if none exists.
func (*DB) GetExecutorUsageByProject ¶
GetExecutorUsageByProject returns a map of executor names to their usage counts for a project. This counts how many tasks have been created with each executor for the given project.
func (*DB) GetLastExecutorForProject ¶
GetLastExecutorForProject returns the last used executor for a project.
func (*DB) GetLastQuestion ¶
GetLastQuestion retrieves the most recent question log for a task.
func (*DB) GetLastTaskTypeForProject ¶
GetLastTaskTypeForProject returns the last used task type for a project.
func (*DB) GetLastUsedProject ¶
GetLastUsedProject returns the last used project name.
func (*DB) GetMostRecentlyCreatedTask ¶
GetMostRecentlyCreatedTask returns the task with the most recent created_at timestamp. This is used to get the last task's project for defaulting in new task forms.
func (*DB) GetNextQueuedTask ¶
GetNextQueuedTask returns the next task to process.
func (*DB) GetOpenBlockerCount ¶
GetOpenBlockerCount returns the number of incomplete blockers for a task.
func (*DB) GetProjectByName ¶
GetProjectByName returns a project by name or alias.
func (*DB) GetProjectByPath ¶
GetProjectByPath returns a project whose path matches the given directory. It checks if cwd equals or is a subdirectory of any project's path.
func (*DB) GetProjectContext ¶
GetProjectContext returns the auto-generated context for a project. This context is cached exploration results that can be reused across tasks.
func (*DB) GetQueuedTasks ¶
GetQueuedTasks returns all queued tasks (waiting to be processed).
func (*DB) GetRetryFeedback ¶
GetRetryFeedback returns the feedback from the most recent retry, or empty string if not a retry. Looks for "Feedback: ..." log entry after "--- Continuation ---" marker.
func (*DB) GetSetting ¶
GetSetting returns a setting value.
func (*DB) GetStaleWorktreeTasks ¶
GetStaleWorktreeTasks returns done/archived tasks that have worktree paths set and were completed more than maxAge ago. These are candidates for cleanup.
func (*DB) GetTagsList ¶
GetTagsList returns all unique tags used across all tasks.
func (*DB) GetTaskLogCount ¶
GetTaskLogCount returns the number of logs for a task. This is a fast operation useful for checking if logs have changed.
func (*DB) GetTaskLogs ¶
GetTaskLogs retrieves logs for a task.
func (*DB) GetTaskLogsSince ¶
GetTaskLogsSince retrieves logs after a given ID.
func (*DB) GetTaskType ¶
GetTaskType retrieves a task type by ID.
func (*DB) GetTaskTypeByName ¶
GetTaskTypeByName retrieves a task type by name.
func (*DB) HasContinuationMarker ¶
HasContinuationMarker checks if a task has any continuation markers. This is a fast EXISTS-style query to avoid loading logs just to check.
func (*DB) IsFirstRun ¶
IsFirstRun returns true if this is the first time the app is being used. This is determined by checking if onboarding has been completed.
func (*DB) ListAttachments ¶
func (db *DB) ListAttachments(taskID int64) ([]*Attachment, error)
ListAttachments retrieves all attachments for a task (without data for efficiency).
func (*DB) ListAttachmentsWithData ¶
func (db *DB) ListAttachmentsWithData(taskID int64) ([]*Attachment, error)
ListAttachmentsWithData retrieves all attachments for a task including data.
func (*DB) ListProjects ¶
ListProjects returns all projects, with "personal" always first.
func (*DB) ListTaskTypes ¶
ListTaskTypes returns all task types ordered by sort_order.
func (*DB) ListTasks ¶
func (db *DB) ListTasks(opts ListTasksOptions) ([]*Task, error)
ListTasks retrieves tasks with optional filters.
func (*DB) MarkTaskStarted ¶
MarkTaskStarted sets the started_at timestamp if not already set.
func (*DB) ProcessCompletedBlocker ¶
ProcessCompletedBlocker checks tasks blocked by the completed task and updates their status if they become unblocked. Returns the list of tasks that were unblocked.
func (*DB) RecoverStaleTmuxRefs ¶
func (db *DB) RecoverStaleTmuxRefs(activeSessions map[string]bool, validWindowIDs map[string]bool) (int, int, error)
RecoverStaleTmuxRefs clears stale daemon_session and tmux_window_id references from tasks. Called automatically on daemon startup to recover from crashes. Returns (staleDaemonCount, staleWindowCount) of cleaned references.
func (*DB) RemoveDependency ¶
RemoveDependency removes a dependency between two tasks.
func (*DB) RetryTask ¶
RetryTask clears logs, appends feedback to body, and re-queues a task. Also clears stale tmux window/pane IDs to prevent duplicate window issues.
func (*DB) SaveArchiveState ¶
func (db *DB) SaveArchiveState(taskID int64, archiveRef, archiveCommit, worktreePath, branchName string) error
SaveArchiveState saves the archive state for a task. This stores the git ref, commit hash, worktree path, and branch name that were active at the time of archiving.
func (*DB) SearchTasks ¶
SearchTasks searches for tasks by query string across title, project, ID, and PR number. This is used by the command palette to search all tasks, not just the preloaded ones.
func (*DB) SetAutoQueue ¶
SetAutoQueue updates the auto_queue flag for a dependency.
func (*DB) SetEventEmitter ¶
func (db *DB) SetEventEmitter(emitter EventEmitter)
SetEventEmitter sets the event emitter for this database. This is called by the executor to enable event emission.
func (*DB) SetLastExecutorForProject ¶
SetLastExecutorForProject saves the last used executor for a project.
func (*DB) SetLastTaskTypeForProject ¶
SetLastTaskTypeForProject saves the last used task type for a project.
func (*DB) SetLastUsedProject ¶
SetLastUsedProject saves the last used project name.
func (*DB) SetProjectContext ¶
SetProjectContext saves auto-generated context for a project. This overwrites any existing context.
func (*DB) SetSetting ¶
SetSetting sets a setting value.
func (*DB) UpdateProject ¶
UpdateProject updates a project.
func (*DB) UpdateTaskClaudeSessionID ¶
UpdateTaskClaudeSessionID updates only the Claude session ID for a task.
func (*DB) UpdateTaskDaemonSession ¶
UpdateTaskDaemonSession updates the tmux daemon session name for a task. This is used to track which daemon session owns the task's tmux window, so we can properly kill the Claude process when the task completes.
func (*DB) UpdateTaskDangerousMode ¶
UpdateTaskDangerousMode updates only the dangerous_mode flag for a task.
func (*DB) UpdateTaskLastAccessedAt ¶
UpdateTaskLastAccessedAt updates the last_accessed_at timestamp for a task. This is used to track when a task was last accessed/opened in the UI, enabling the command palette to show recently visited tasks first.
func (*DB) UpdateTaskPRInfo ¶
UpdateTaskPRInfo updates only the PR-related fields for a task. This is used to persist PR state from GitHub API responses without touching other fields.
func (*DB) UpdateTaskPaneIDs ¶
UpdateTaskPaneIDs updates the tmux pane IDs for a task. This is used to track the unique pane IDs (e.g., "%1234") for reliable pane identification when joining/breaking panes between the daemon and the TUI.
func (*DB) UpdateTaskPinned ¶
UpdateTaskPinned updates only the pinned flag for a task.
func (*DB) UpdateTaskStartedAt ¶
UpdateTaskStartedAt updates the started_at timestamp for a task. This is primarily used for testing.
func (*DB) UpdateTaskStatus ¶
UpdateTaskStatus updates a task's status.
func (*DB) UpdateTaskSummary ¶
UpdateTaskSummary updates the task summary and distillation timestamp.
func (*DB) UpdateTaskType ¶
UpdateTaskType updates a task type.
type Dependency ¶
type Dependency struct {
ID int64 `json:"id"`
BlockerID int64 `json:"blocker_id"`
BlockedID int64 `json:"blocked_id"`
AutoQueue bool `json:"auto_queue"` // If true, auto-queue blocked task when unblocked
CreatedAt time.Time `json:"created_at"`
}
Dependency represents a blocking relationship between two tasks. The blocker task must be completed before the blocked task can proceed.
type EventEmitter ¶
type EventEmitter interface {
EmitTaskCreated(task *Task)
EmitTaskUpdated(task *Task, changes map[string]interface{})
EmitTaskDeleted(taskID int64, title string)
EmitTaskPinned(task *Task)
EmitTaskUnpinned(task *Task)
}
EventEmitter is an interface for emitting task events. This allows the DB to emit events without depending on the events package.
type ListTasksOptions ¶
type ListTasksOptions struct {
Status string
Type string
Project string
Limit int
Offset int
IncludeClosed bool // Include closed tasks even when Status is empty
}
ListTasksOptions defines options for listing tasks.
type LocalTime ¶
LocalTime wraps time.Time and converts from UTC to local timezone when scanning.
type Project ¶
type Project struct {
ID int64
Name string
Path string
Aliases string // comma-separated
Instructions string // project-specific instructions for AI
Actions []ProjectAction // actions triggered on task events (stored as JSON)
Color string // hex color for display (e.g., "#61AFEF")
ClaudeConfigDir string // override CLAUDE_CONFIG_DIR for this project
UseWorktrees bool // whether to use git worktrees for task isolation (default true)
CreatedAt LocalTime
}
Project represents a configured project.
func (*Project) GetAction ¶
func (p *Project) GetAction(trigger string) *ProjectAction
GetAction returns the action for a given trigger, or nil if not found.
func (*Project) UsesWorktrees ¶
UsesWorktrees returns whether this project uses git worktrees for task isolation. Defaults to true for backward compatibility.
type ProjectAction ¶
type ProjectAction struct {
Trigger string `json:"trigger"` // "on_create", "on_status:queued", etc.
Instructions string `json:"instructions"` // prompt/instructions for this action
}
ProjectAction defines an action that runs on tasks for a project.
type Task ¶
type Task struct {
ID int64
Title string
Body string
Status string
Type string
Project string
Executor string // Task executor: "claude" (default), "codex", "gemini"
WorktreePath string
BranchName string
Port int // Unique port for running the application in this task's worktree
ClaudeSessionID string // Claude session ID for resuming conversations
DaemonSession string // tmux daemon session name (e.g., "task-daemon-12345")
TmuxWindowID string // tmux window ID (e.g., "@1234") for unique window identification
ClaudePaneID string // tmux pane ID (e.g., "%1234") for the Claude/executor pane
ShellPaneID string // tmux pane ID (e.g., "%1235") for the shell pane
PRURL string // Pull request URL (if associated with a PR)
PRNumber int // Pull request number (if associated with a PR)
PRInfoJSON string // Cached PR state as JSON (state, checks, mergeable, etc.)
DangerousMode bool // Whether task is running in dangerous mode (--dangerously-skip-permissions)
Pinned bool // Whether the task is pinned to the top of its column
Tags string // Comma-separated tags for categorization (e.g., "customer-support,email,influence-kit")
SourceBranch string // Existing branch to checkout for worktree (e.g., "fix/ui-overflow") instead of creating new branch
Summary string // Distilled summary of what was accomplished (for search and context)
CreatedAt LocalTime
UpdatedAt LocalTime
StartedAt *LocalTime
CompletedAt *LocalTime
// Distillation tracking
LastDistilledAt *LocalTime // When task was last distilled for learnings
// UI tracking
LastAccessedAt *LocalTime // When task was last accessed/opened in the UI
// Archive state for preserving worktree state when archiving
ArchiveRef string // Git ref storing stashed changes (e.g., "refs/task-archive/123")
ArchiveCommit string // Commit hash at time of archiving
ArchiveWorktreePath string // Original worktree path before archiving
ArchiveBranchName string // Original branch name before archiving
}
Task represents a task in the database.
func (*Task) HasArchiveState ¶
HasArchiveState returns true if the task has saved archive state.
type TaskLog ¶
type TaskLog struct {
ID int64
TaskID int64
LineType string // "output", "tool", "error", "system"
Content string
CreatedAt LocalTime
}
TaskLog represents a log entry for a task.
type TaskType ¶
type TaskType struct {
ID int64
Name string // e.g., "code", "writing", "thinking"
Label string // Display label
Instructions string // Prompt template for this type
SortOrder int // For UI ordering
IsBuiltin bool // Protect default types from deletion
CreatedAt LocalTime
}
TaskType represents a configurable task type with its prompt instructions.