Documentation
¶
Overview ¶
Package state manages persistent state for nightshift runs. Tracks run history per project and task to support staleness calculation, duplicate run prevention, and task assignment tracking.
Index ¶
- type AssignedTask
- type ProjectState
- type RunRecord
- type State
- func (s *State) AddRunRecord(record RunRecord)
- func (s *State) ClearAllAssigned()
- func (s *State) ClearAssigned(taskID string)
- func (s *State) ClearStaleAssignments(maxAge time.Duration) int
- func (s *State) DaysSinceLastRun(projectPath, taskType string) int
- func (s *State) GetAssigned(taskID string) (AssignedTask, bool)
- func (s *State) GetProjectState(projectPath string) *ProjectState
- func (s *State) GetRunHistory(n int) []RunRecord
- func (s *State) GetTodayRuns() []RunRecord
- func (s *State) GetTodaySummary() TodaySummary
- func (s *State) IsAssigned(taskID string) bool
- func (s *State) LastProjectRun(projectPath string) time.Time
- func (s *State) LastTaskRun(projectPath, taskType string) time.Time
- func (s *State) ListAssigned() []AssignedTask
- func (s *State) MarkAssigned(taskID, project, taskType string)
- func (s *State) ProjectCount() int
- func (s *State) RecordProjectRun(projectPath string)
- func (s *State) RecordTaskRun(projectPath, taskType string)
- func (s *State) StalenessBonus(projectPath, taskType string) float64
- func (s *State) WasProcessedToday(projectPath string) bool
- type TodaySummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssignedTask ¶
type AssignedTask struct {
TaskID string `json:"task_id"`
Project string `json:"project"`
TaskType string `json:"task_type"`
AssignedAt time.Time `json:"assigned_at"`
}
AssignedTask represents a task currently assigned/in-progress.
type ProjectState ¶
type ProjectState struct {
Path string `json:"path"`
LastRun time.Time `json:"last_run"`
TaskHistory map[string]time.Time `json:"task_history"` // task type -> last run
RunCount int `json:"run_count"`
}
ProjectState tracks state for a single project.
type RunRecord ¶
type RunRecord struct {
ID string `json:"id"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Provider string `json:"provider,omitempty"`
Project string `json:"project"`
Tasks []string `json:"tasks"`
TokensUsed int `json:"tokens_used"`
Status string `json:"status"` // success, failed, partial
Error string `json:"error,omitempty"`
Branch string `json:"branch,omitempty"`
}
RunRecord represents a single nightshift run for history tracking.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State manages persistent nightshift state.
func (*State) AddRunRecord ¶
AddRunRecord adds a run record to history.
func (*State) ClearAllAssigned ¶
func (s *State) ClearAllAssigned()
ClearAllAssigned removes all assigned tasks (e.g., on daemon restart).
func (*State) ClearAssigned ¶
ClearAssigned removes a task from the assigned list.
func (*State) ClearStaleAssignments ¶
ClearStaleAssignments removes assignments older than the given duration.
func (*State) DaysSinceLastRun ¶
DaysSinceLastRun returns days since a task type was last run for a project. Returns -1 if the task has never run (treated as maximally stale).
func (*State) GetAssigned ¶
func (s *State) GetAssigned(taskID string) (AssignedTask, bool)
GetAssigned returns the assigned task info, if any.
func (*State) GetProjectState ¶
func (s *State) GetProjectState(projectPath string) *ProjectState
GetProjectState returns the state for a project (or nil if not tracked).
func (*State) GetRunHistory ¶
GetRunHistory returns the last N run records (most recent first).
func (*State) GetTodayRuns ¶
GetTodayRuns returns all runs from today.
func (*State) GetTodaySummary ¶
func (s *State) GetTodaySummary() TodaySummary
GetTodaySummary returns a summary of today's activity.
func (*State) IsAssigned ¶
IsAssigned checks if a task is currently assigned.
func (*State) LastProjectRun ¶
LastProjectRun returns when a project was last processed.
func (*State) LastTaskRun ¶
LastTaskRun returns when a task type was last run for a project.
func (*State) ListAssigned ¶
func (s *State) ListAssigned() []AssignedTask
ListAssigned returns all currently assigned tasks.
func (*State) MarkAssigned ¶
MarkAssigned marks a task as assigned/in-progress.
func (*State) ProjectCount ¶
ProjectCount returns the number of tracked projects.
func (*State) RecordProjectRun ¶
RecordProjectRun marks a project as having been processed.
func (*State) RecordTaskRun ¶
RecordTaskRun marks a specific task type as having run for a project.
func (*State) StalenessBonus ¶
StalenessBonus calculates the staleness bonus for task selection. Formula: days since last run * 0.1 (capped at reasonable max). Tasks that have never run get a high bonus.
func (*State) WasProcessedToday ¶
WasProcessedToday returns true if the project was already processed today.