Documentation
¶
Overview ¶
Package tasks is the installation-wide task authority: one SQLite database shared by every session, the CLI and the serve process. The owner sees and edits everything; an agent only reaches its own checklist, its own open requests to the owner and its project's backlog, through Actor-scoped methods that enforce that inside the transaction.
Index ¶
- Constants
- Variables
- func LoadZone(name string) (*time.Location, error)
- func NewTool(scope *Scope) core.Tool
- func NextSlot(rule Rule, after time.Time, loc *time.Location) (time.Time, error)
- func ResolveWall(y int, m time.Month, d, h, mi int, loc *time.Location) (time.Time, bool, error)
- type Actor
- type AgentInput
- type AgentPatch
- type AgentTask
- type AgentView
- type ConflictError
- type Counts
- type CreateInput
- type Delivery
- type Destination
- type Filter
- type LegacySchedule
- type ListResult
- type Notice
- type NoticeChange
- type NoticeKind
- type Occurrence
- type OccurrenceConflictError
- type OccurrenceSpec
- type ParseError
- type Parsed
- type Patch
- type Place
- type Project
- type Record
- type Repo
- func (r *Repo) AgentAsk(ctx context.Context, a Actor, in AgentInput) (AgentTask, error)
- func (r *Repo) AgentClaim(ctx context.Context, a Actor, id int64) (AgentTask, error)
- func (r *Repo) AgentCreate(ctx context.Context, a Actor, in AgentInput) (AgentTask, error)
- func (r *Repo) AgentDone(ctx context.Context, a Actor, id int64) (AgentTask, error)
- func (r *Repo) AgentGet(ctx context.Context, a Actor, id int64) (AgentTask, error)
- func (r *Repo) AgentList(ctx context.Context, a Actor) (AgentView, error)
- func (r *Repo) AgentSchedule(ctx context.Context, a Actor, in AgentInput, when When, tz string) (Record, error)
- func (r *Repo) AgentUpdate(ctx context.Context, a Actor, id int64, p AgentPatch) (AgentTask, error)
- func (r *Repo) AssignOccurrence(ctx context.Context, id int64, dest Destination) (Occurrence, error)
- func (r *Repo) Checklist(ctx context.Context, sessionID string) ([]Task, error)
- func (r *Repo) ClearSessionDiscard(ctx context.Context, sessionID string) error
- func (r *Repo) Close() error
- func (r *Repo) CompleteForSession(ctx context.Context, sessionID string, id int64) error
- func (r *Repo) ConfirmOccurrence(ctx context.Context, id, revision int64, action string) (Occurrence, error)
- func (r *Repo) Create(ctx context.Context, in CreateInput) (Record, error)
- func (r *Repo) Delete(ctx context.Context, id, revision int64, deliver string) error
- func (r *Repo) FailOccurrence(ctx context.Context, id int64, reason, note string) (Occurrence, error)
- func (r *Repo) Get(ctx context.Context, id int64) (Record, error)
- func (r *Repo) ImportLegacySchedules(ctx context.Context, items []LegacySchedule) (bool, error)
- func (r *Repo) LateRuns(ctx context.Context, taskID int64) ([]Occurrence, error)
- func (r *Repo) LegacySchedulesImported(ctx context.Context) (bool, error)
- func (r *Repo) List(ctx context.Context, f Filter) (ListResult, error)
- func (r *Repo) MarkDeliveryUncertain(ctx context.Context, noticeID string) (bool, error)
- func (r *Repo) MarkSessionDiscarding(ctx context.Context, sessionID string) error
- func (r *Repo) MaterializeDue(ctx context.Context, limit int) ([]Occurrence, error)
- func (r *Repo) NextDueAt(ctx context.Context) (int64, error)
- func (r *Repo) Notice(ctx context.Context, id string) (Notice, error)
- func (r *Repo) Occurrence(ctx context.Context, id int64) (Occurrence, error)
- func (r *Repo) OccurrenceForNotice(ctx context.Context, noticeID string) (Occurrence, bool, error)
- func (r *Repo) OpenNotices(ctx context.Context) ([]Notice, error)
- func (r *Repo) Path() string
- func (r *Repo) Pause(ctx context.Context, taskID, revision int64) (Record, error)
- func (r *Repo) ReadyOccurrences(ctx context.Context) ([]Occurrence, error)
- func (r *Repo) RegateOnRestart(ctx context.Context) (int, error)
- func (r *Repo) Requests(ctx context.Context, sessionID string) ([]Task, error)
- func (r *Repo) RerouteOccurrence(ctx context.Context, id, revision int64, dest Destination) (Occurrence, error)
- func (r *Repo) ReserveSession(ctx context.Context, id int64, candidate string) (string, error)
- func (r *Repo) ResetChecklist(ctx context.Context, sessionID string) error
- func (r *Repo) Resume(ctx context.Context, taskID, revision int64) (Record, error)
- func (r *Repo) Revision(ctx context.Context) (int64, error)
- func (r *Repo) RunNow(ctx context.Context, taskID, revision, dueAt int64) (Occurrence, error)
- func (r *Repo) Runs(ctx context.Context, taskID, beforeID int64, limit int) ([]Occurrence, error)
- func (r *Repo) ScheduledFor(ctx context.Context, sessionID string, ownerIDs []string) ([]Record, error)
- func (r *Repo) SessionDiscarding(ctx context.Context, sessionID string) (bool, error)
- func (r *Repo) SessionDiscards(ctx context.Context) ([]string, error)
- func (r *Repo) SetClock(now func() time.Time)
- func (r *Repo) SetNoticeState(ctx context.Context, id string, c NoticeChange) (bool, error)
- func (r *Repo) SettleSessionDeleted(ctx context.Context, sessionID string) (int, error)
- func (r *Repo) SkipNext(ctx context.Context, taskID, revision, dueAt int64) (Occurrence, error)
- func (r *Repo) SlotDue(ctx context.Context, taskID int64) (bool, error)
- func (r *Repo) TaskNotices(ctx context.Context, taskID int64, limit int) ([]Notice, error)
- func (r *Repo) TaskProjects(ctx context.Context) ([]Project, error)
- func (r *Repo) Update(ctx context.Context, id, revision int64, p Patch) (Record, error)
- func (r *Repo) Watch(ctx context.Context, interval time.Duration, fn func(revision int64))
- type Rule
- type RunFailure
- type ScheduleDef
- type Scope
- func (s *Scope) Actor() Actor
- func (s *Scope) ChangedChecklist() ([]Task, bool)
- func (s *Scope) Checklist() []Task
- func (s *Scope) MarkDone(id int) error
- func (s *Scope) Repo() *Repo
- func (s *Scope) Requests() []Task
- func (s *Scope) ResetChecklist() error
- func (s *Scope) SessionID() string
- func (s *Scope) WithTZ(tz string) *Scope
- type SpecSubtask
- type Subtask
- type SubtaskInput
- type Target
- type Task
- type When
Constants ¶
const ( StatusPending = "pending" StatusInProgress = "in_progress" StatusDone = "done" )
Task statuses. The UI maps pending→open and in_progress→working.
const ( NoticePending = "pending" NoticeHeld = "held" NoticeSent = "sent" NoticeDelivered = "delivered" NoticeFailed = "failed" )
Notice states. pending is waiting for the dispatcher (with a Reason when an attempt could not deliver it); held waits for its saved session to be opened; sent reserves a delivery attempt and waits to be seen in the persisted transcript; delivered is there; failed is terminal.
const ( ReasonSessionDeleted = "session_deleted" ReasonSessionLimit = "session_limit" ReasonQuestionPending = "question_pending" )
Reasons a notice is not delivered.
const ( DeliverWake = "wake" DeliverHold = "hold" )
Deliver modes for a recipient that is saved but not loaded: wake resumes it, hold waits until the owner opens it. Anything else means hold: a session is never woken without the owner choosing to.
const ( MethodRun = "run" MethodAppend = "append" )
Delivery methods. run starts (or steers into) a turn; append only adds the notice to the transcript, used after the owner discarded its steer.
const ( WhenOnce = "once" WhenRepeat = "repeat" )
When kinds.
const ( TargetSession = "session" TargetOwner = "owner" TargetNew = "new" )
Target kinds: an exact session, an owner entity (resolved to its current conversation when a run is released), or a new session in a project.
const ( BusySteer = "steer" BusyWait = "wait" LateAsk = "ask" LateRun = "run" LateSkip = "skip" )
Delivery policies. Busy: steer into a working session or wait until it is idle. Saved: see DeliverWake/DeliverHold. Late: what a run found 10 minutes or more after its due time does.
const ( OccLate = "late" OccReady = "ready" OccAssigned = "assigned" OccDone = "done" OccFailed = "failed" OccSkipped = "skipped" )
Occurrence states. late waits for the owner's decision; ready is authorized and waits for its child and assignment; assigned has both; failed could not be sent and needs the owner; done and skipped are final.
const ( TriggerTimer = "timer" TriggerRunNow = "run_now" TriggerSkipNext = "skip_next" TriggerLegacy = "legacy" )
What consumed an occurrence's slot.
const ( ReasonLateSkip = "late_skip" ReasonOwnerSkip = "owner_skip" ReasonRegated = "regated" ReasonChildDone = "child_done" ReasonChildRemoved = "child_removed" ReasonScheduleDeleted = "schedule_deleted" ReasonSuperseded = "superseded" ReasonLegacyDelivered = "legacy_delivered" ReasonTemplateInvalid = "template_invalid" ReasonRerouted = "rerouted" ReasonDeletedDuringDeliver = "session_deleted_during_delivery" ReasonDeletedAfterDeliver = "session_deleted_after_delivery" // ReasonUncertain: the assignment was reserved for delivery but its // admission was never recorded, so it may or may not have reached its // session. It is never sent again without the owner. ReasonUncertain = "delivery_uncertain" )
Occurrence reasons. Failure codes that the serve layer decides (owner missing, session limit, …) are free-form strings stored as given.
const ( FreqDaily = "daily" FreqWeekdays = "weekdays" FreqWeekly = "weekly" FreqMonthly = "monthly" )
Recurrence frequencies.
const DatabaseName = "tasks.sqlite"
DatabaseName is the file inside the config directory.
const LateAfter = 10 * time.Minute
LateAfter is the first-observation delay from which a run is late: exactly ten minutes is late, a millisecond less is not.
const NoticeSourceName = "tasks"
NoticeSourceName is custom.source_name on a notice's transcript message.
Variables ¶
var ( // ErrNotFound covers both "does not exist" and "not visible to you": an // agent must not be able to tell them apart. ErrNotFound = errors.New("not available") // ErrForbidden is a visible task the caller may not change. ErrForbidden = errors.New("not allowed to change this task") // ErrClaimed means another session claimed the task first. ErrClaimed = errors.New("task already claimed") // ErrInvalid wraps validation failures (message says which). ErrInvalid = errors.New("invalid task") // ErrSchemaTooNew means the database was written by a newer moa: reads work, // writes are refused and nothing is reset. ErrSchemaTooNew = errors.New("tasks database was written by a newer moa; update moa to change tasks") ErrUnavailable = errors.New("tasks database unavailable") )
Sentinel errors. Handlers map them to 404/403/409/400.
var ErrNoticeNotFound = fmt.Errorf("notice %w", ErrNotFound)
ErrNoticeNotFound is an unknown notice ID.
var ErrOccurrenceNotFound = fmt.Errorf("run %w", ErrNotFound)
ErrOccurrenceNotFound is an unknown occurrence ID.
Functions ¶
func LoadZone ¶ added in v0.45.0
LoadZone validates an IANA zone name. "Local" and empty names are refused: a schedule never silently follows the server's zone.
func NewTool ¶
NewTool returns the tasks tool for one session. Who is asking is the scope's identity, injected at bootstrap; the arguments cannot name another session or project.
func NextSlot ¶ added in v0.45.0
NextSlot is the first instant of rule strictly after after, in loc. Days are walked in civil-date space, never by adding 24h to an instant, and each is resolved with ResolveWall, so the repeated hour of a DST overlap is never a second slot and a gap slot moves forward instead of disappearing.
func ResolveWall ¶ added in v0.45.0
ResolveWall returns the instant of the civil date and wall time y-m-d h:mi in loc. The civil date must exist (31 February is an error, not 3 March). When the wall time happens twice (clocks going back) the earlier instant wins; when it does not happen at all (clocks going forward) it is moved forward by the length of the gap, keeping its minutes, and adjusted is true. time.Date is not used to pick: its choice in both cases is unspecified.
Types ¶
type Actor ¶ added in v0.45.0
type Actor struct {
SessionID string
ProjectKey string // core.CodebaseKey(cwd); "" when unknown
ProjectCWD string
// TZ is the IANA zone of the device that created the session, "" when
// unknown. Scheduling by the agent uses it (UTC when unknown).
TZ string
}
Actor is the identity an agent's tool call acts with. It is injected by bootstrap; the model never supplies it.
type AgentInput ¶ added in v0.45.0
type AgentInput struct {
Title string
Description string
DependsOn []int64
Subtasks []SubtaskInput
}
AgentInput creates a checklist task or a request.
type AgentPatch ¶ added in v0.45.0
type AgentPatch struct {
Title *string
Description *string
Status *string // pending or in_progress; completing goes through Done
DependsOn *[]int64
Subtasks *[]SubtaskInput
}
AgentPatch is a partial agent edit of a task it may edit.
type AgentTask ¶ added in v0.45.0
type AgentTask struct {
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Status string `json:"status"`
Place Place `json:"place"`
CompletionNote string `json:"completion_note,omitempty"`
Subtasks []Subtask `json:"subtasks,omitempty"`
// WaitsFor lists readable tasks this one waits for.
WaitsFor []int64 `json:"waits_for,omitempty"`
// PrivateBlockers counts open tasks this one waits for that the agent
// cannot read: shown as "Blocked by a private task", with no title, note or
// usable ID.
PrivateBlockers int `json:"private_blockers,omitempty"`
Unblocks []int64 `json:"unblocks,omitempty"`
// A template the agent created for itself: when it runs.
When *When `json:"when,omitempty"`
TZ string `json:"tz,omitempty"`
Next int64 `json:"next,omitempty"`
ScheduleState string `json:"schedule_state,omitempty"`
}
AgentTask is what an agent may know about a task: never who else is involved, and never the identity of a task it cannot read. A dependency on such a task is only a count.
type AgentView ¶ added in v0.45.0
type AgentView struct {
Checklist []AgentTask `json:"checklist"`
Requests []AgentTask `json:"requests"`
Backlog []AgentTask `json:"backlog"`
// Scheduled are the templates this session created for itself. They are
// not on its checklist: each run arrives as its own task.
Scheduled []AgentTask `json:"scheduled,omitempty"`
}
AgentView is the default listing of an agent.
type ConflictError ¶ added in v0.45.0
type ConflictError struct{ Current Record }
ConflictError is a stale revision. Current is the task as it is now, so the caller can show it instead of guessing.
func (*ConflictError) Error ¶ added in v0.45.0
func (e *ConflictError) Error() string
type Counts ¶ added in v0.45.0
type Counts struct {
OpenRequests int `json:"open_requests"`
// LateOccurrences are runs waiting for the owner's Run or Skip, counted
// per run (a paused template's included); Attention adds them to the
// open requests for the footer.
LateOccurrences int `json:"late_occurrences"`
Attention int `json:"attention"`
You int `json:"you"`
Backlog int `json:"backlog"`
Agents int `json:"agents"`
}
Counts summarizes a listing. OpenRequests is the number the sidebar shows: only requests agents made that are still open.
type CreateInput ¶ added in v0.45.0
type CreateInput struct {
Title string
Description string
Place Place
Status string // default pending
// ProjectKey wins over ProjectCWD; with only a CWD the key is derived from
// it (core.CodebaseKey), so worktrees of one repo share a project.
ProjectKey string
ProjectCWD string
RequesterSessionID string // PlaceYou only: makes it a request from that session
AssigneeSessionID string // PlaceAgent only
Subtasks []SubtaskInput
WaitsFor []int64
// Deliver is the owner's choice for a saved recipient: DeliverWake or
// DeliverHold ("" means hold). A loaded recipient gets the notice at once.
Deliver string
// Schedule makes the task a scheduled template: a private task of yours
// that the scheduler turns into runs. It has no requester or assignee.
Schedule *ScheduleDef
}
CreateInput is a task written by the owner (UI, REST or CLI).
type Delivery ¶ added in v0.45.0
type Delivery struct {
Busy string `json:"busy"`
Saved string `json:"saved"`
Late string `json:"late"`
}
Delivery is a template's delivery policy.
func DecodeDelivery ¶ added in v0.45.0
DecodeDelivery parses a delivery object strictly; missing fields take the schedule defaults (steer, wake, ask).
type Destination ¶ added in v0.45.0
Destination is the session a run was resolved to, with its actual project.
type Filter ¶ added in v0.45.0
type Filter struct {
// ProjectKey limits backlog and agent tasks to one project. Tasks in You
// are the owner's own and are always returned.
ProjectKey string
IncludeAgents bool
IncludeArchived bool
}
Filter narrows an owner listing.
type LegacySchedule ¶ added in v0.45.0
type LegacySchedule struct {
ID string
SessionID string
Text string
DueAt int64 // Unix ms
TZ string
CreatedAt int64 // Unix ms, 0 for now
// Delivered: the old scheduler's prompt for it is already in the
// session's transcript. It is imported as settled, never offered again.
Delivered bool
}
LegacySchedule is one pending record of the old schedules.json.
type ListResult ¶ added in v0.45.0
type ListResult struct {
Tasks []Record `json:"tasks"`
Counts Counts `json:"counts"`
Revision int64 `json:"revision"`
}
ListResult is an owner listing with the global revision it was read at.
type Notice ¶ added in v0.45.0
type Notice struct {
ID string `json:"id"`
TaskID int64 `json:"task_id"`
Kind NoticeKind `json:"kind"`
RecipientSessionID string `json:"recipient_session_id"`
State string `json:"state"`
Reason string `json:"reason,omitempty"`
CreatedAt int64 `json:"created_at"`
DeliveredAt int64 `json:"delivered_at,omitempty"`
Deliver string `json:"-"`
Method string `json:"-"`
Title string `json:"-"`
Text string `json:"-"`
SteerID string `json:"-"`
UpdatedAt int64 `json:"-"`
}
Notice is one event for a session, written in the same transaction as the gesture that caused it. Title and Text are rendered at commit, so the notice still says what happened after its task is gone.
type NoticeChange ¶ added in v0.45.0
type NoticeChange struct {
From []string
State string
Reason string
Method string // "" keeps the current one
SteerID string
// Admitted records that the session accepted the notice's input. For a
// scheduled assignment it stamps the run's admitted_at; delivered implies it.
Admitted bool
}
NoticeChange is a state transition. From lists the states it may leave, so a transition decided on a stale read (delivered meanwhile, say) changes nothing.
type NoticeKind ¶ added in v0.45.0
type NoticeKind string
NoticeKind says which owner gesture a notice reports.
const ( NoticeAssigned NoticeKind = "assigned" NoticeUpdated NoticeKind = "updated" NoticeRequestDone NoticeKind = "request_done" NoticeAgentDone NoticeKind = "agent_done" NoticeAgentDeleted NoticeKind = "agent_deleted" )
type Occurrence ¶ added in v0.45.0
type Occurrence struct {
ID int64 `json:"id"`
ScheduleTaskID int64 `json:"schedule_task_id"`
Revision int64 `json:"revision"`
DueAt int64 `json:"at"`
State string `json:"state"`
Trigger string `json:"trigger"`
Reason string `json:"reason,omitempty"`
Note string `json:"note,omitempty"`
ChildTaskID int64 `json:"child_task_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
NoticeID string `json:"notice_id,omitempty"`
ObservedAt int64 `json:"observed_at"`
ConfirmedAt int64 `json:"confirmed_at,omitempty"`
AdmittedAt int64 `json:"admitted_at,omitempty"`
CompletedAt int64 `json:"completed_at,omitempty"`
MissedCount int `json:"missed_count,omitempty"`
DefinitionRevision int64 `json:"-"`
Spec OccurrenceSpec `json:"-"`
// ReservedSessionID is the session a run for a new session creates, set
// before it exists and kept for good. SessionID is where the run is
// delivered now; a reroute changes it and the snapshot's target.
ReservedSessionID string `json:"-"`
CreatedAt int64 `json:"-"`
UpdatedAt int64 `json:"-"`
}
Occurrence is one consumed slot of a template: its history row and, once authorized, the link to its child task and current assignment notice.
type OccurrenceConflictError ¶ added in v0.45.0
type OccurrenceConflictError struct {
Current Occurrence
Msg string
}
OccurrenceConflictError is a stale occurrence revision or state. Msg, when set, says why in the owner's words.
func (*OccurrenceConflictError) Error ¶ added in v0.45.0
func (e *OccurrenceConflictError) Error() string
type OccurrenceSpec ¶ added in v0.45.0
type OccurrenceSpec struct {
V int `json:"v"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Subtasks []SpecSubtask `json:"subtasks,omitempty"`
WaitsFor []int64 `json:"waits_for,omitempty"`
ProjectKey string `json:"project_key,omitempty"`
ProjectCWD string `json:"project_cwd,omitempty"`
When When `json:"when"`
TZ string `json:"tz"`
Target Target `json:"target"`
Delivery Delivery `json:"delivery"`
CreatedBySessionID string `json:"created_by_session_id,omitempty"`
}
OccurrenceSpec is the snapshot of a template taken when its slot is consumed. Later edits of the template never reach it; only the owner's reroute changes it, replacing its target with the chosen session.
type ParseError ¶ added in v0.45.0
type ParseError struct {
Code string `json:"code"`
Msg string `json:"error"`
At int64 `json:"at,omitempty"`
}
ParseError is a "when" that could not be read. Code is one of unknown, repeat, invalid or past; At is the instant that was in the past.
func (*ParseError) Error ¶ added in v0.45.0
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶ added in v0.45.0
func (e *ParseError) Unwrap() error
type Parsed ¶ added in v0.45.0
type Parsed struct {
When When `json:"when"`
TZ string `json:"tz"`
Next int64 `json:"next"`
Alt int64 `json:"alt,omitempty"`
Adjusted bool `json:"adjusted,omitempty"`
}
Parsed is a natural-language "when" resolved in a zone: the canonical definition, the first instant it fires and, for a once time whose hour was not qualified, the same time in the other half of the day.
type Patch ¶ added in v0.45.0
type Patch struct {
Title *string
Description *string
Status *string
Place *Place // a move: an explicit gesture, see applyMove
ProjectKey *string
ProjectCWD *string
AssigneeSessionID *string
CompletionNote *string
Subtasks *[]SubtaskInput
WaitsFor *[]int64
// Notify is "Save and notify": the saved task is sent to its assignee (or
// to the requester of a request). Assigning or completing notifies anyway.
Notify bool
Deliver string // see CreateInput.Deliver
// Schedule replaces a template's definition, from its next unconsumed
// slot on. Only a template accepts it.
Schedule *ScheduleDef
}
Patch is a partial owner edit; nil fields are left alone.
type Place ¶ added in v0.45.0
type Place string
Place says who a task belongs to, and therefore who can see it.
const ( // PlaceYou is the owner's. With a requester it is a request an agent asked // for; without one it is a private note no agent ever sees. PlaceYou Place = "you" // PlaceBacklog is a project's shared pool; agents of that project can claim. PlaceBacklog Place = "backlog" // PlaceAgent is one session's checklist (or a task assigned to it). PlaceAgent Place = "agent" )
type Record ¶ added in v0.45.0
type Record struct {
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Status string `json:"status"`
Place Place `json:"place"`
ProjectKey string `json:"project_key,omitempty"`
ProjectCWD string `json:"project_cwd,omitempty"`
RequesterSessionID string `json:"requester_session_id,omitempty"`
AssigneeSessionID string `json:"assignee_session_id,omitempty"`
CompletionNote string `json:"completion_note,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
CompletedAt int64 `json:"completed_at,omitempty"`
ArchivedAt int64 `json:"archived_at,omitempty"`
Revision int64 `json:"revision"`
Subtasks []Subtask `json:"subtasks,omitempty"`
WaitsFor []int64 `json:"waits_for,omitempty"`
Unblocks []int64 `json:"unblocks,omitempty"`
// NoticeState is set in listings when the task's latest notice has not
// reached its session (held, pending or failed).
NoticeState string `json:"notice_state,omitempty"`
// Scheduled template fields, set only on a template.
When *When `json:"when,omitempty"`
TZ string `json:"tz,omitempty"`
Target *Target `json:"target,omitempty"`
Delivery *Delivery `json:"delivery,omitempty"`
Next int64 `json:"next,omitempty"`
ScheduleState string `json:"schedule_state,omitempty"`
CreatedBySessionID string `json:"created_by_session_id,omitempty"`
LateCount int `json:"late_count,omitempty"`
Failure *RunFailure `json:"failure,omitempty"`
// A run's child task links back to its template and occurrence.
ParentTaskID int64 `json:"parent_task_id,omitempty"`
OccurrenceID int64 `json:"occurrence_id,omitempty"`
// contains filtered or unexported fields
}
Record is a task as the owner sees it, with its relations.
type Repo ¶ added in v0.45.0
type Repo struct {
// contains filtered or unexported fields
}
Repo is the shared task database. It opens lazily: a process that never touches tasks never creates the file, and reads of a database that does not exist yet see no tasks instead of creating one.
func New ¶ added in v0.45.0
New returns a repository on path. Nothing touches the disk until first use.
func Shared ¶ added in v0.45.0
func Shared() *Repo
Shared returns the process-wide repository for the current config directory. Runtime, CLI and serve all go through it, so there is one writer connection per process and never a per-session copy.
func (*Repo) AgentAsk ¶ added in v0.45.0
AgentAsk files a request to the owner. It does not block the agent.
func (*Repo) AgentClaim ¶ added in v0.45.0
AgentClaim takes a pending backlog task of the agent's own project. It is the only write an agent has on the backlog. Of two sessions claiming at once, one wins and the others get "not available", the same answer as for a task assigned directly to someone else.
func (*Repo) AgentCreate ¶ added in v0.45.0
AgentCreate adds a task to the agent's own checklist.
func (*Repo) AgentDone ¶ added in v0.45.0
AgentDone completes a task of the agent's own checklist. Not a backlog task it merely sees, and never a request to the owner: only the owner answers those.
func (*Repo) AgentList ¶ added in v0.45.0
AgentList returns the agent's checklist (done ones included until they are archived), its own requests to the owner, and the pending backlog of its project. Nothing else.
func (*Repo) AgentSchedule ¶ added in v0.45.0
func (r *Repo) AgentSchedule(ctx context.Context, a Actor, in AgentInput, when When, tz string) (Record, error)
AgentSchedule schedules a task for the agent's own session: a template the owner owns and sees, which this session can read and which runs here. The target and the creator are the actor, never something the model says.
func (*Repo) AgentUpdate ¶ added in v0.45.0
AgentUpdate edits a checklist task or a still-open request of the agent.
func (*Repo) AssignOccurrence ¶ added in v0.45.0
func (r *Repo) AssignOccurrence(ctx context.Context, id int64, dest Destination) (Occurrence, error)
AssignOccurrence is the scheduler's T1: for a ready run, the child task on dest's checklist, its one assignment notice and the links commit together. An already assigned or finished run is returned as it is, so a retry after a lost response creates nothing. A snapshotted dependency that no longer exists fails the run (template_invalid) instead of being dropped.
func (*Repo) Checklist ¶ added in v0.45.0
Checklist is the flat projection of the agent's checklist that the session WebSocket and /tasks carry.
func (*Repo) ClearSessionDiscard ¶ added in v0.45.0
ClearSessionDiscard withdraws the intent of a delete whose file was not unlinked: the session and its work stay as they were.
func (*Repo) CompleteForSession ¶ added in v0.45.0
CompleteForSession is the owner completing, from that session's /tasks, a task the session owns or asked for. It reaches nothing outside the session.
func (*Repo) ConfirmOccurrence ¶ added in v0.45.0
func (r *Repo) ConfirmOccurrence(ctx context.Context, id, revision int64, action string) (Occurrence, error)
ConfirmOccurrence answers a late run: "run" authorizes it (once), "skip" settles it. revision is the occurrence's; of two answers one wins.
func (*Repo) Delete ¶ added in v0.45.0
Delete removes a task with its subtasks and dependency edges. Deleting an open request tells nobody: the owner decided that. Deleting a session's open task tells that session; a finished one tells nobody. deliver is as in CreateInput.
func (*Repo) FailOccurrence ¶ added in v0.45.0
func (r *Repo) FailOccurrence(ctx context.Context, id int64, reason, note string) (Occurrence, error)
FailOccurrence marks a ready run as not sent: its target could not be resolved or provisioned. The owner decides what happens next.
func (*Repo) Get ¶ added in v0.45.0
Get returns one task with its relations, archived or not. The owner's view: agents go through Actor methods.
func (*Repo) ImportLegacySchedules ¶ added in v0.45.0
ImportLegacySchedules turns every pending legacy record into a once template for its session, all in one transaction with the installation's import flag. A record already due becomes a late run straight away, however little it is overdue, so a prompt the old scheduler may have been sending when it stopped is never re-sent without the owner's OK; one whose prompt is known to be in its session (Delivered) is imported as a skipped run of a finished template. It returns false when the import had already happened.
func (*Repo) LateRuns ¶ added in v0.45.0
LateRuns returns every run of a template waiting for the owner's answer, oldest first, whatever page of Runs they fall on.
func (*Repo) LegacySchedulesImported ¶ added in v0.45.0
LegacySchedulesImported reports whether the one-time import has happened.
func (*Repo) List ¶ added in v0.45.0
List returns the owner's view. Archived tasks are left out unless asked for, and never counted.
func (*Repo) MarkDeliveryUncertain ¶ added in v0.45.0
MarkDeliveryUncertain settles a scheduled assignment that was reserved for delivery (sent) but whose admission was never recorded, once no attempt is in flight: it may or may not have reached its session, so it is never sent again on its own, whatever its transcript says. Its run becomes the owner's decision (late, delivery_uncertain): Run sends it again, which may duplicate the work; Skip settles it. Like a re-gated run, it gives up its child and assignment, so Run goes through T1 again. A run whose template is gone cannot be answered and is skipped. It reports whether the notice was settled.
func (*Repo) MarkSessionDiscarding ¶ added in v0.45.0
MarkSessionDiscarding records, before a saved session's file is unlinked, that its delete is under way: the runs bound to it are neither given it again nor re-gated while the intent stands. Invisible to readers: it does not change the revision.
func (*Repo) MaterializeDue ¶ added in v0.45.0
MaterializeDue consumes every enabled template whose cursor is at or before now (at most limit of them), and returns the occurrences it created. It is the scheduler's T0: safe to repeat, and safe against another process doing the same, because each consumption checks the cursor it read.
func (*Repo) NextDueAt ¶ added in v0.45.0
NextDueAt is the earliest cursor of an enabled template, 0 when none.
func (*Repo) Occurrence ¶ added in v0.45.0
Occurrence returns one run.
func (*Repo) OccurrenceForNotice ¶ added in v0.45.0
OccurrenceForNotice returns the run whose current assignment is noticeID. The dispatcher uses it to apply the run's frozen delivery policy (busy wait). A superseded notice of a rerouted run maps to nothing.
func (*Repo) OpenNotices ¶ added in v0.45.0
OpenNotices returns every notice the dispatcher still has work for, oldest first so a session receives them in the order they happened.
func (*Repo) Pause ¶ added in v0.45.0
Pause stops a recurring template from consuming slots. Runs already authorized continue; late decisions stay answerable.
func (*Repo) ReadyOccurrences ¶ added in v0.45.0
func (r *Repo) ReadyOccurrences(ctx context.Context) ([]Occurrence, error)
ReadyOccurrences lists the authorized runs still waiting for their child and assignment, oldest first.
func (*Repo) RegateOnRestart ¶ added in v0.45.0
RegateOnRestart re-applies the late policy, at startup recovery, to runs that were authorized on time but never reached their session and whose due time is now ten minutes or more ago. ask returns them to late (their undelivered child and notice are withdrawn, so Run goes through T1 again), skip settles them, run lets them continue. Runs the owner confirmed or ran by hand, and runs already reserved or admitted, are never re-gated.
func (*Repo) Requests ¶ added in v0.45.0
Requests is the flat projection of the session's open and answered requests to the owner.
func (*Repo) RerouteOccurrence ¶ added in v0.45.0
func (r *Repo) RerouteOccurrence(ctx context.Context, id, revision int64, dest Destination) (Occurrence, error)
RerouteOccurrence sends a failed, never admitted run to another existing session: the same child moves there and gets one new assignment notice. The old notice stays failed and is no longer the run's. Only the latest run of its template can be sent: a newer one already stands for the recurrence, which has one pending candidate.
func (*Repo) ReserveSession ¶ added in v0.45.0
ReserveSession records the ID a ready run for a new session creates its session with, before the session exists: candidate the first time, the recorded one ever after, whatever happens to the run. Invisible to readers: it does not change the revision.
func (*Repo) ResetChecklist ¶ added in v0.45.0
ResetChecklist deletes the session's checklist. Its requests, the backlog and the owner's notes are untouched.
func (*Repo) Resume ¶ added in v0.45.0
Resume re-enables a recurring template. The paused dates are not caught up: the next slot is strictly after now.
func (*Repo) Revision ¶ added in v0.45.0
Revision is the global change counter: it grows with every committed change by any process. 0 when the database does not exist yet.
func (*Repo) RunNow ¶ added in v0.45.0
RunNow consumes the template's next slot now, as an authorized run: it is that slot early, not an extra run. dueAt and revision are what the owner saw, so a retried request cannot consume the following slot.
func (*Repo) Runs ¶ added in v0.45.0
Runs returns a template's runs newest first, before beforeID when it is not 0.
func (*Repo) ScheduledFor ¶ added in v0.45.0
func (r *Repo) ScheduledFor(ctx context.Context, sessionID string, ownerIDs []string) ([]Record, error)
ScheduledFor lists the templates that concern a session: the ones that target it, the ones it scheduled for itself, and the ones aimed at an owner whose conversation it is (ownerIDs). They are not on its checklist; each run arrives there as its own task.
func (*Repo) SessionDiscarding ¶ added in v0.45.0
SessionDiscarding reports whether a session's delete is under way: a run must not be given it meanwhile.
func (*Repo) SessionDiscards ¶ added in v0.45.0
SessionDiscards lists the sessions whose delete a start must finish or undo.
func (*Repo) SetClock ¶ added in v0.45.0
SetClock replaces the clock; tests use it to age tasks past the archive window and to cross schedule boundaries without sleeping. It is safe to call while other goroutines use the repository.
func (*Repo) SetNoticeState ¶ added in v0.45.0
SetNoticeState applies c and reports whether it matched. A change bumps the global revision, so /api/tasks/ws tells open task details to refresh.
func (*Repo) SettleSessionDeleted ¶ added in v0.45.0
SettleSessionDeleted settles every unfinished run bound to a deleted session (see boundToSession), whatever gate it waits at, and clears the session's discard intent. Undelivered work fails (session_deleted) and can be sent elsewhere; work reserved or admitted is skipped with an unknown outcome. Finished history is unchanged.
func (*Repo) SkipNext ¶ added in v0.45.0
SkipNext records the next slot of an active recurring template as skipped and moves on to the following one.
func (*Repo) SlotDue ¶ added in v0.45.0
SlotDue reports whether a recurring template has a slot due that the planner has not taken yet: a delivery of one of its older runs would be superseded by it, and waits for it instead.
func (*Repo) TaskNotices ¶ added in v0.45.0
TaskNotices returns the latest notices of a task, newest first.
func (*Repo) TaskProjects ¶ added in v0.45.0
TaskProjects lists the projects tasks already refer to, most recent first wins for the display path.
func (*Repo) Update ¶ added in v0.45.0
Update applies an owner edit. revision must be the one the caller last saw: a stale form gets a *ConflictError carrying the current task instead of overwriting a change the CLI or an agent made in between.
func (*Repo) Watch ¶ added in v0.45.0
Watch reports changes made by any process, including this one, until ctx ends: fn gets the new global revision. It compares PRAGMA data_version on one persistent reader connection, which SQLite bumps whenever a different connection commits — so a CLI write is noticed without WAL or filesystem watchers, and a local write (a different connection from this reader) is noticed too. A local commit also wakes the loop early instead of waiting for the next tick. Before the database exists it only polls for the file.
type Rule ¶ added in v0.45.0
type Rule struct {
Freq string `json:"freq"`
DOW *int `json:"dow,omitempty"`
DOM *int `json:"dom,omitempty"`
H int `json:"h"`
Mi int `json:"mi"`
}
Rule is a recurring wall-clock rule, interpreted in its schedule's IANA zone. DOW (0 = Sunday) is only for weekly, DOM (1–31) only for monthly.
type RunFailure ¶ added in v0.45.0
type RunFailure struct {
OccurrenceID int64 `json:"occurrence_id"`
Reason string `json:"reason"`
Note string `json:"note,omitempty"`
}
RunFailure is the newest unresolved failed run of a template.
type ScheduleDef ¶ added in v0.45.0
type ScheduleDef struct {
When When
TZ string
Target Target
Delivery Delivery
CreatedBySessionID string
}
ScheduleDef is the calendar definition of a template. CreatedBySessionID is provenance (an agent's own schedule), never a requester.
type Scope ¶ added in v0.45.0
type Scope struct {
// contains filtered or unexported fields
}
Scope binds the shared repository to one session. The session's identity is fixed at construction by bootstrap; nothing the model says can change it.
func (*Scope) Actor ¶ added in v0.45.0
Actor is the identity used for authorization. The project key is resolved lazily: it runs git, and most sessions never touch tasks.
func (*Scope) ChangedChecklist ¶ added in v0.45.0
ChangedChecklist returns the checklist and true when it differs from the last projection this scope handed out. Serve's change watcher uses it so a commit by the CLI (or by the tool itself, already announced) does not re-publish an identical list.
func (*Scope) Checklist ¶ added in v0.45.0
Checklist is the session's flat checklist projection. It records what it handed out, so ChangedChecklist reports only real changes.
func (*Scope) MarkDone ¶ added in v0.45.0
MarkDone completes a task of this session (checklist or its own request), for /tasks done. It reaches nothing outside the session.
func (*Scope) Requests ¶ added in v0.45.0
Requests is the session's flat list of requests to the owner.
func (*Scope) ResetChecklist ¶ added in v0.45.0
ResetChecklist clears this session's checklist only.
type SpecSubtask ¶ added in v0.45.0
type SpecSubtask struct {
Title string `json:"title"`
}
SpecSubtask is a subtask line as frozen in an occurrence.
type SubtaskInput ¶ added in v0.45.0
SubtaskInput is a subtask as written by a caller; the whole list replaces the previous one.
type Target ¶ added in v0.45.0
type Target struct {
Kind string `json:"kind"`
ID string `json:"id,omitempty"` // session or owner entity ID
Project string `json:"project,omitempty"` // new: project key
CWD string `json:"cwd,omitempty"` // new: canonical directory
Model string `json:"model,omitempty"` // new: full model spec
Thinking string `json:"thinking,omitempty"` // new: thinking level
}
Target is who receives a run.
func DecodeTarget ¶ added in v0.45.0
DecodeTarget parses a canonical target object strictly.
type Task ¶
type Task struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Status string `json:"status"` // "pending", "in_progress", "done"
DependsOn []int `json:"depends_on,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"` // unix millis
CompletedAt int64 `json:"completed_at,omitempty"` // unix millis
}
Task is the flat projection of a session checklist. Its JSON is what tasks_update and InitData.tasks have always carried, and installed clients (Pulse) parse exactly these fields: add to it only with omitempty.
type When ¶ added in v0.45.0
type When struct {
Kind string `json:"kind"`
At int64 `json:"at,omitempty"`
Rule *Rule `json:"rule,omitempty"`
}
When says when a template runs: a fixed instant once, or a wall-clock rule.
func DecodeWhen ¶ added in v0.45.0
DecodeWhen parses a canonical when object strictly: unknown fields, fractional or missing numbers and incompatible fields are errors, never defaults.