Documentation
¶
Overview ¶
Package store is Fort's SQLite state store (backlog AO-016, spec §6.6): run, node_run, route_decision, and an append-only event log. The event log is the source the fort-ui live feed replays from.
Index ¶
- Variables
- type BacklogItem
- type ConversationDetail
- type ConversationTargetDispatch
- type ConversationTurnTarget
- type CreateConversationTurnParams
- type Event
- type NodeRun
- type PlaybookRevision
- type RouteDecision
- type Run
- type Store
- func (s *Store) AddConversationParticipant(participant conversation.Participant) error
- func (s *Store) AllNodeRuns() ([]NodeRun, error)
- func (s *Store) AnswerConversationTarget(id string, message conversation.Message) (bool, error)
- func (s *Store) AppendConversationMessage(message conversation.Message) (conversation.Message, error)
- func (s *Store) AppendEvent(e Event) (int64, error)
- func (s *Store) CheckInvite(codeHash string, now time.Time) error
- func (s *Store) Close() error
- func (s *Store) ConversationContext(conversationID string, throughMessageID int64) (string, error)
- func (s *Store) CreateBacklogItem(b BacklogItem) error
- func (s *Store) CreateConversation(item conversation.Conversation, participants []conversation.Participant) error
- func (s *Store) CreateConversationTurn(params CreateConversationTurnParams) (conversation.Turn, []conversation.Target, string, error)
- func (s *Store) CreateInvite(codeHash string, expires time.Time) error
- func (s *Store) CreateProject(project conversation.Project) error
- func (s *Store) CreateRun(r Run) error
- func (s *Store) CreateSchedule(definition scheduler.Definition) error
- func (s *Store) DecideWaitingGate(id, status, output string) (bool, error)
- func (s *Store) DeleteBacklogItem(id string) error
- func (s *Store) DeleteConversation(id string) error
- func (s *Store) DeleteProject(id string) error
- func (s *Store) Events(runID string) ([]Event, error)
- func (s *Store) EventsSince(cursor int64) ([]Event, error)
- func (s *Store) FailInterruptedConversationTargets(reason string) (int, error)
- func (s *Store) FailInterruptedDirectRuns(reason string) (int, error)
- func (s *Store) GetBacklogItem(id string) (BacklogItem, error)
- func (s *Store) GetConversation(id string) (ConversationDetail, error)
- func (s *Store) GetConversationTargetDispatch(id string) (ConversationTargetDispatch, error)
- func (s *Store) GetRun(id string) (Run, error)
- func (s *Store) LatestPlaybookRevisions() ([]PlaybookRevision, error)
- func (s *Store) ListBacklog() ([]BacklogItem, error)
- func (s *Store) ListConversationTargetDispatches(states ...conversation.TargetState) ([]ConversationTargetDispatch, error)
- func (s *Store) ListConversations(scope string) ([]conversation.Conversation, error)
- func (s *Store) ListProjects() ([]conversation.Project, error)
- func (s *Store) ListRuns() ([]Run, error)
- func (s *Store) ListSchedules() ([]scheduler.Definition, error)
- func (s *Store) MarkInviteUsed(codeHash string, now time.Time) error
- func (s *Store) MoveConversation(id, projectID string) error
- func (s *Store) NodeRuns(runID string) ([]NodeRun, error)
- func (s *Store) PlaybookRevision(id string, revision int) (PlaybookRevision, error)
- func (s *Store) RemoveConversationParticipant(conversationID, participantID string, removedAt time.Time) error
- func (s *Store) RenameConversation(id, title string) error
- func (s *Store) RenameProject(id, name string) error
- func (s *Store) RetryConversationTarget(originalID, newID, newRunID string, createdAt time.Time) (ConversationTargetDispatch, error)
- func (s *Store) RouteDecisions(taskID string) ([]RouteDecision, error)
- func (s *Store) SavePlaybookRevision(id, data string) (PlaybookRevision, error)
- func (s *Store) SavePlaybookRevisionIfLatest(id string, expected int, data string) (PlaybookRevision, error)
- func (s *Store) SaveRouteDecision(d RouteDecision) error
- func (s *Store) ScheduleOccurrencesBetween(start, end time.Time) ([]scheduler.Occurrence, error)
- func (s *Store) SeedPlaybookRevisions(revisions []PlaybookRevision) error
- func (s *Store) SetConversationState(id string, state conversation.ConversationState) error
- func (s *Store) TouchConversationTargetActivity(id string, observedAt time.Time) error
- func (s *Store) TransitionConversationTarget(id string, from, to conversation.TargetState, errorMessage string) (bool, error)
- func (s *Store) TransitionConversationTargetWithCode(id string, from, to conversation.TargetState, errorCode, errorMessage string) (bool, error)
- func (s *Store) TransitionScheduleOccurrence(id string, from, to scheduler.OccurrenceState, runID, errorMessage string) (bool, error)
- func (s *Store) UpdateBacklogAgent(id, agent string) error
- func (s *Store) UpdateRunStatus(id, status string, exitCode int, errMsg string) error
- func (s *Store) UpdateScheduleFire(id string, lastFireAt, nextFireAt time.Time) error
- func (s *Store) UpsertNodeRun(n NodeRun) error
- func (s *Store) UpsertScheduleOccurrence(occurrence scheduler.Occurrence) error
- func (s *Store) WaitingGates() ([]NodeRun, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInviteInvalid = errors.New("store: invite invalid or already used") ErrInviteExpired = errors.New("store: invite expired") )
Invite errors distinguish the join responses (spec 024): 401 vs 410.
var ErrPlaybookRevisionStale = errors.New("store: stale playbook revision")
ErrPlaybookRevisionStale identifies a failed compare-and-append. Callers can map it to a conflict without depending on SQLite or matching error text.
Functions ¶
This section is empty.
Types ¶
type BacklogItem ¶ added in v0.7.0
type BacklogItem struct {
ID string
Title string
Body string
Agent string // optional forced agent
Machine string // optional pinned host
Labels []string
Source string // "user" | "agent"
CreatedAt time.Time
}
BacklogItem is a task queued for later dispatch (spec 025). It becomes a run only when dispatched (dragged onto the board / the Run action).
type ConversationDetail ¶ added in v0.13.0
type ConversationDetail struct {
Conversation conversation.Conversation `json:"conversation"`
Participants []conversation.Participant `json:"participants"`
Messages []conversation.Message `json:"messages"`
Turns []conversation.Turn `json:"turns"`
Targets []conversation.Target `json:"targets"`
}
type ConversationTargetDispatch ¶ added in v0.13.0
type ConversationTargetDispatch struct {
Target conversation.Target
Turn conversation.Turn
Conversation conversation.Conversation
Participant conversation.Participant
}
type ConversationTurnTarget ¶ added in v0.13.0
type CreateConversationTurnParams ¶ added in v0.13.0
type Event ¶
type Event struct {
ID int64
RunID string
NodeID string // DAG step this event came from (spec 027); "" for run-level/single-run events
Type string
Data string
Code int
CreatedAt time.Time
}
Event is one append-only event row.
type NodeRun ¶
type NodeRun struct {
ID string // runID:nodeID
RunID string
NodeID string
Type string
Status string
Input string
Output string
Attempts int
CreatedAt time.Time
UpdatedAt time.Time
}
NodeRun is a persisted DAG node execution (Phase 2).
type PlaybookRevision ¶ added in v0.12.0
PlaybookRevision stores one opaque, immutable definition revision. The core store owns durability while the bounded control adapter owns validation and JSON interpretation (spec 036).
type RouteDecision ¶
type RouteDecision struct {
ID string
TaskID string
Route string
MatchedRule string
IsDefault bool
Reason string
CreatedAt time.Time
}
RouteDecision is a persisted routing outcome.
type Run ¶
type Run struct {
ID string
Title string
Body string // markdown body from a multiline compose (spec 031); "" if title-only
Agent string
Profile string // exact Fort-owned profile requested for a direct run
Model string // provider model derived from Profile; empty means configured default
Status string
MatchedRule string
Machine string // resolved target host (spec 022); "" = local/single-machine
FlowID string
ExitCode int
Error string
CreatedAt time.Time
UpdatedAt time.Time
}
Run is a persisted execution (a routed task or a flow run).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the SQLite database.
func (*Store) AddConversationParticipant ¶ added in v0.13.0
func (s *Store) AddConversationParticipant(participant conversation.Participant) error
func (*Store) AllNodeRuns ¶ added in v0.11.0
AllNodeRuns returns every node_run row grouped by run (the board's checkpoint-summary source, spec 033).
func (*Store) AnswerConversationTarget ¶ added in v0.13.0
func (*Store) AppendConversationMessage ¶ added in v0.13.0
func (s *Store) AppendConversationMessage(message conversation.Message) (conversation.Message, error)
func (*Store) AppendEvent ¶
AppendEvent appends an event (append-only) and returns its id.
func (*Store) CheckInvite ¶ added in v0.6.0
CheckInvite verifies codeHash names an unused, unexpired invite. It does not consume it — the join flow persists the registry first and only then calls MarkInviteUsed (spec 024 ordering).
func (*Store) ConversationContext ¶ added in v0.13.0
func (*Store) CreateBacklogItem ¶ added in v0.7.0
func (s *Store) CreateBacklogItem(b BacklogItem) error
CreateBacklogItem inserts a pending item.
func (*Store) CreateConversation ¶ added in v0.13.0
func (s *Store) CreateConversation(item conversation.Conversation, participants []conversation.Participant) error
func (*Store) CreateConversationTurn ¶ added in v0.13.0
func (s *Store) CreateConversationTurn(params CreateConversationTurnParams) (conversation.Turn, []conversation.Target, string, error)
func (*Store) CreateInvite ¶ added in v0.6.0
CreateInvite records a hashed single-use invite code.
func (*Store) CreateProject ¶ added in v0.13.0
func (s *Store) CreateProject(project conversation.Project) error
func (*Store) CreateSchedule ¶ added in v0.13.0
func (s *Store) CreateSchedule(definition scheduler.Definition) error
func (*Store) DecideWaitingGate ¶ added in v0.13.0
DecideWaitingGate atomically changes one waiting gate to a terminal decision. The false result means another caller already decided or reset that gate.
func (*Store) DeleteBacklogItem ¶ added in v0.7.0
DeleteBacklogItem removes an item (called after it is dispatched or discarded).
func (*Store) DeleteConversation ¶ added in v0.13.0
func (*Store) DeleteProject ¶ added in v0.13.0
func (*Store) EventsSince ¶
EventsSince returns events with id greater than the cursor (the UI feed tail).
func (*Store) FailInterruptedConversationTargets ¶ added in v0.13.0
func (*Store) FailInterruptedDirectRuns ¶ added in v0.13.0
FailInterruptedDirectRuns reconciles direct tasks left running by an earlier daemon lifetime. Flow runs are intentionally excluded: their durable node_run state is the input to graph.Resume after a restart.
func (*Store) GetBacklogItem ¶ added in v0.7.0
func (s *Store) GetBacklogItem(id string) (BacklogItem, error)
GetBacklogItem returns one item by id.
func (*Store) GetConversation ¶ added in v0.13.0
func (s *Store) GetConversation(id string) (ConversationDetail, error)
func (*Store) GetConversationTargetDispatch ¶ added in v0.13.0
func (s *Store) GetConversationTargetDispatch(id string) (ConversationTargetDispatch, error)
func (*Store) LatestPlaybookRevisions ¶ added in v0.12.0
func (s *Store) LatestPlaybookRevisions() ([]PlaybookRevision, error)
LatestPlaybookRevisions returns the newest immutable revision for every id, ordered deterministically by id.
func (*Store) ListBacklog ¶ added in v0.7.0
func (s *Store) ListBacklog() ([]BacklogItem, error)
ListBacklog returns pending items, newest first.
func (*Store) ListConversationTargetDispatches ¶ added in v0.13.0
func (s *Store) ListConversationTargetDispatches(states ...conversation.TargetState) ([]ConversationTargetDispatch, error)
func (*Store) ListConversations ¶ added in v0.13.0
func (s *Store) ListConversations(scope string) ([]conversation.Conversation, error)
func (*Store) ListProjects ¶ added in v0.13.0
func (s *Store) ListProjects() ([]conversation.Project, error)
func (*Store) ListSchedules ¶ added in v0.13.0
func (s *Store) ListSchedules() ([]scheduler.Definition, error)
func (*Store) MarkInviteUsed ¶ added in v0.6.0
MarkInviteUsed consumes the invite. The WHERE used_at IS NULL guard makes consumption single-use even under concurrent joins.
func (*Store) MoveConversation ¶ added in v0.13.0
func (*Store) PlaybookRevision ¶ added in v0.12.0
func (s *Store) PlaybookRevision(id string, revision int) (PlaybookRevision, error)
PlaybookRevision returns exactly revision; edits never rewrite old rows.
func (*Store) RemoveConversationParticipant ¶ added in v0.13.0
func (*Store) RenameConversation ¶ added in v0.13.0
func (*Store) RenameProject ¶ added in v0.13.0
func (*Store) RetryConversationTarget ¶ added in v0.13.0
func (*Store) RouteDecisions ¶
func (s *Store) RouteDecisions(taskID string) ([]RouteDecision, error)
RouteDecisions returns the decisions recorded for a task, oldest first.
func (*Store) SavePlaybookRevision ¶ added in v0.12.0
func (s *Store) SavePlaybookRevision(id, data string) (PlaybookRevision, error)
SavePlaybookRevision appends the next immutable revision for id.
func (*Store) SavePlaybookRevisionIfLatest ¶ added in v0.12.0
func (s *Store) SavePlaybookRevisionIfLatest(id string, expected int, data string) (PlaybookRevision, error)
SavePlaybookRevisionIfLatest appends only when expected is still the latest revision (zero means the id does not exist). The compare and insert share one transaction, preventing stale whole-document edits from becoming revisions.
func (*Store) SaveRouteDecision ¶
func (s *Store) SaveRouteDecision(d RouteDecision) error
SaveRouteDecision persists a routing decision.
func (*Store) ScheduleOccurrencesBetween ¶ added in v0.13.0
func (*Store) SeedPlaybookRevisions ¶ added in v0.12.0
func (s *Store) SeedPlaybookRevisions(revisions []PlaybookRevision) error
SeedPlaybookRevisions atomically installs an initial catalog when the table is empty. Existing catalogs are left untouched, so startup is idempotent and a crash can never expose a partially seeded set.
func (*Store) SetConversationState ¶ added in v0.13.0
func (s *Store) SetConversationState(id string, state conversation.ConversationState) error
func (*Store) TouchConversationTargetActivity ¶ added in v0.13.0
func (*Store) TransitionConversationTarget ¶ added in v0.13.0
func (s *Store) TransitionConversationTarget(id string, from, to conversation.TargetState, errorMessage string) (bool, error)
func (*Store) TransitionConversationTargetWithCode ¶ added in v0.13.0
func (s *Store) TransitionConversationTargetWithCode(id string, from, to conversation.TargetState, errorCode, errorMessage string) (bool, error)
func (*Store) TransitionScheduleOccurrence ¶ added in v0.13.0
func (*Store) UpdateBacklogAgent ¶ added in v0.11.0
UpdateBacklogAgent reassigns an item to an agent ("" clears the pin, spec 033).
func (*Store) UpdateRunStatus ¶
UpdateRunStatus updates a run's terminal fields.
func (*Store) UpdateScheduleFire ¶ added in v0.13.0
func (*Store) UpsertNodeRun ¶
UpsertNodeRun inserts or updates a node run (keyed by id = runID:nodeID).
func (*Store) UpsertScheduleOccurrence ¶ added in v0.13.0
func (s *Store) UpsertScheduleOccurrence(occurrence scheduler.Occurrence) error
func (*Store) WaitingGates ¶
WaitingGates returns every gate node currently awaiting a human decision, across all runs (the gate-inbox source).