Documentation
¶
Overview ¶
Package taskquery is the read model over a store snapshot: the structural tree, effective availability, and the selections the read surfaces render. It is the Go counterpart of lib/tasks/tree.rb and the read half of lib/tasks/task_queries.rb.
Nothing here writes. The whole package answers questions about a snapshot a caller is already holding, so two renderings of the same snapshot can never disagree.
Index ¶
- Constants
- Variables
- func ClosedStates() []string
- func Headline(item store.Item) string
- func Important(item store.Item) bool
- func OpenStates() []string
- func Quadrant(item store.Item, today temporal.Date, urgentDays int) string
- func Recurring(item store.Item) bool
- func StateOrder() []string
- func Urgent(item store.Item, today temporal.Date, urgentDays int) bool
- type APITime
- type Availability
- type Node
- type Option
- type Override
- type ProjectView
- type Queries
- func (q *Queries) APITimeFor(value temporal.Value, present bool) (APITime, bool)
- func (q *Queries) AgendaItems() []store.Item
- func (q *Queries) ArchiveItems() []store.Item
- func (q *Queries) AvailabilityAfter(item store.Item, override Override) Availability
- func (q *Queries) AvailabilityFor(item store.Item) Availability
- func (q *Queries) Body(item store.Item) []string
- func (q *Queries) Context() temporal.Context
- func (q *Queries) DeadlineValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) Deferred(item store.Item) bool
- func (q *Queries) FindLive(id string) (store.Item, bool)
- func (q *Queries) InboxItems() []store.Item
- func (q *Queries) LeadAnchorValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) LeadOpens(item store.Item) (temporal.Date, bool)
- func (q *Queries) LeadOpensAt(item store.Item) (time.Time, bool)
- func (q *Queries) LeadOpensValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) LeadWindowValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) Links(item store.Item) []links.Link
- func (q *Queries) List(filter query.Filter) []store.Item
- func (q *Queries) LiveItems() []store.Item
- func (q *Queries) NextItems() []store.Item
- func (q *Queries) NodeFor(item store.Item) *Node
- func (q *Queries) Project(item store.Item) (string, bool)
- func (q *Queries) ProjectView(id string) (ProjectView, bool)
- func (q *Queries) Projects() []ProjectView
- func (q *Queries) QuadrantItems() []store.Item
- func (q *Queries) QuadrantOf(item store.Item, urgentDays int) string
- func (q *Queries) Record(item store.Item) (record.Record, bool)
- func (q *Queries) ReservedLists() []ProjectView
- func (q *Queries) ScheduledValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) SectionView(id string) (ProjectView, bool)
- func (q *Queries) Snapshot() *store.Snapshot
- func (q *Queries) Today() temporal.Date
- func (q *Queries) Tree() Tree
- type Tree
Constants ¶
const ( ReasonAvailable = "available" ReasonScheduled = "scheduled" ReasonOnHold = "on_hold" ReasonAncestorScheduled = "ancestor_scheduled" ReasonAncestorOnHold = "ancestor_on_hold" ReasonProposed = "proposed" ReasonClosed = "closed" )
The reasons, in the order lib/tasks/task_queries.rb declares them.
const DefaultUrgentDays = 3
DefaultUrgentDays is the deadline window that counts as urgent.
const DeferTag = "defer"
DeferTag is the semantic tag that means someday/maybe. It rides ALONGSIDE the task's real state rather than replacing it, the same way important and urgent do, so a deferred NEXT action is still a NEXT action when it comes back.
Variables ¶
var QuadrantLabels = [][2]string{
{"Q1", "Q1 · Important + Urgent (do now)"},
{"Q2", "Q2 · Important, Not Urgent (schedule)"},
{"Q3", "Q3 · Urgent, Not Important (delegate)"},
{"Q4", "Q4 · Neither (eliminate)"},
}
QuadrantLabels are the canonical headings, shared so the CLI and TUI never drift. Each frontend applies its own formatting around the text.
Functions ¶
func ClosedStates ¶
func ClosedStates() []string
ClosedStates is the finished vocabulary. `recur` reads it to refuse a live repeater on a task `done` can never reach to roll — dead recurrence that would sit in the file forever looking like a schedule.
func Headline ¶
Headline is the item's summary rendered from its own fields, star-less: state, optional priority cookie, title, trailing tag cluster in STORED order. One derivation, so the string can never fork between a read command and the report a mutation prints.
func OpenStates ¶
func OpenStates() []string
OpenStates is the accepted-and-not-finished vocabulary, which is the default scope for every ref.
func Recurring ¶
Recurring reports a VALID repeater cookie. A cookie that does not match the grammar reads as non-recurring so completion closes the task normally — Check still reports the bad cookie.
func StateOrder ¶
func StateOrder() []string
StateOrder is the order the grouped human views print states in.
Types ¶
type APITime ¶
type APITime struct {
Local string
Timezone string
Fold int
EffectiveTimezone string
Instant string
}
APITime is TemporalValue#api_time: the stored halves plus what they resolve to for THIS reader. Both are needed — the stored zone is what the user wrote, the effective zone and instant are what it means right now.
type Availability ¶
type Availability struct {
Reason string
BlockerID string
Scheduled temporal.Date
Value *temporal.Value
AvailableAt time.Time
}
Availability is the effective answer for one item: why it is or is not workable now, and what would change that.
func (Availability) Available ¶
func (a Availability) Available() bool
Available reports whether the item can be worked on now.
type Node ¶
type Node struct {
Title string
Line int
Level int
// ID is the record's stable 8-hex id — a task's or a section's. Sections
// carry no Item, so the id lives on the node itself; it is what the
// outliner's fold state and selection follow for section rows.
ID string
Item *store.Item // nil for a section
Body []string
Children []*Node
Parent *Node
}
Node is one record in the structural index: a section or a task, with its own body lines and its children. Hierarchy comes straight from each record's `parent` pointer — no star counting, no block inference — so a whole class of boundary bugs is structurally absent.
func (*Node) OpenProject ¶
OpenProject is the task's project FOR GROUPING: the nearest ancestor headline that is a section or an OPEN task, climbing past closed ancestors. A closed ancestor is transparent, the same way the outliner hoists open descendants out of a closed parent. Deferred tasks count as open — a deferred project still owns its subtasks.
type Option ¶
type Option func(*Queries)
Option configures a read model at construction. The variadic form is deliberate: a reader that does not care about link configuration should not have to name it.
func WithLinkConfig ¶
WithLinkConfig supplies the configured shorthand templates (`link.<name>`) and self-hosted system hosts (`system.<name>`).
type Override ¶
type Override struct {
// Deferred replaces the task's own indefinite-hold marker.
Deferred *bool
// Scheduled replaces the task's own available-from value when ScheduledSet.
Scheduled *temporal.Value
// ScheduledSet distinguishes "clear it" (nil) from "leave it alone".
ScheduledSet bool
// Lead replaces the task's own lead span; "" clears it.
Lead *string
}
Override is the own-field substitution a PREVIEW applies before asking for an availability answer: "if this write landed, what would this task's availability be?"
It is Ruby's `availability_after(item, deferred:, scheduled:, lead:)`, and it is deliberately own-field only. Ancestor precedence still comes from the read model rather than being duplicated in the CLI, so a dry-run cannot disagree with the write it previews about who blocks whom.
Each field is a pointer because "not overridden" and "overridden to the clearing value" are different questions. Scheduled is a pointer to a value: nil with ScheduledSet true means "the write clears the available-from date".
type ProjectView ¶
type ProjectView struct {
ID string
Title string
ParentID string
HasParentID bool
Kind string
Line int
OpenCount int
NextCount int
NextDate temporal.Date
HasNextDate bool
NextTime APITime
HasNextTime bool
NextAt time.Time
Stuck bool
Body string
HasBody bool
TaskIDs []string
HeldCount int
}
ProjectView is the canonical project/area resource: a section rolled up over its open, non-deferred descendant tasks at any depth.
Kind distinguishes a project (a section under the top-level "Projects" heading) from an area (any other top-level list that currently holds open work). Stuck flags a project or area with no open NEXT action — including one with zero open tasks. Line is the physical coordinate for adapters; like the task resource it never appears in the JSON, keeping reusable resources free of file positions. NextDate is the soonest deadline-or-scheduled date across the rolled-up open tasks, the key the listing sorts on (absent sorts last). HeldCount counts open descendant tasks excluded from the rollup because they are deferred or held (own or inherited hold); the archive refusal treats them as open work too, so a parked-but-open project cannot be swept by accident.
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
Queries is the read model over one snapshot for one reader.
func New ¶
New builds the read model. The tree indexes the LIVE file only; archive items have no structural context by construction, which is why an archived item's availability is `closed` without a walk.
func (*Queries) APITimeFor ¶
APITimeFor renders a value's time half, or ok=false for an all-day value, which has no wall time to report.
func (*Queries) AgendaItems ¶
AgendaItems is the `agenda` view: every OPEN, AVAILABLE item carrying a date, soonest first, priority breaking ties, file order breaking those.
func (*Queries) ArchiveItems ¶
ArchiveItems is the swept file's tasks in file order. Only the surfaces that deliberately widen to closed history read it.
func (*Queries) AvailabilityAfter ¶
func (q *Queries) AvailabilityAfter(item store.Item, override Override) Availability
AvailabilityAfter is the availability an item WOULD have if the named own fields took the given values. Never cached: it answers about a task that does not exist yet.
func (*Queries) AvailabilityFor ¶
func (q *Queries) AvailabilityFor(item store.Item) Availability
AvailabilityFor is the effective availability of an item INCLUDING every task ancestor. Closed ancestors stay transparent to lifecycle hoisting, but their own timed or indefinite blocker still participates in this walk — a hold on a finished parent is still a hold the subtree inherited.
func (*Queries) Body ¶
Body is the item's own body lines. It never includes a child's body — children are separate records.
func (*Queries) DeadlineValue ¶
func (*Queries) FindLive ¶
FindLive is the live item with this id, if any. Availability names a blocker by id; a renderer that wants its title has to look it up.
func (*Queries) InboxItems ¶
InboxItems is the `inbox` view: unfiled captures that are workable now, in file order. There is no ranking — an inbox is a queue to triage, not a list to choose from.
func (*Queries) LeadAnchorValue ¶
LeadAnchorValue is the stamp a lead is measured back from: the deadline when there is one, otherwise the available-from date.
func (*Queries) LeadOpens ¶
LeadOpens is the date this task's OWN lead window opens. It is present even while an ancestor's gate or a hold is what currently hides the task, and absent once `activate` has released the current occurrence.
func (*Queries) LeadOpensAt ¶
LeadOpensAt is the same window as an instant, which is the only shape a clock lead can be expressed in.
func (*Queries) LeadOpensValue ¶
LeadOpensValue is the window's explaining value: the date, plus the wall time when a CLOCK lead put the opening at an instant no date can express. A renderer needs the whole value, not only its date, or a clock lead would print the day it opens and lose the hour.
func (*Queries) LeadWindowValue ¶
LeadWindowValue is where this task's lead window sits for its CURRENT anchor, whether or not `activate` has already released it. That is the question `show` asks: the record still carries the span, and a reader looking at the record wants to see the date it produces. LeadOpensValue answers the other question — "is a window still holding this task back" — and is what the availability-shaped surfaces read.
func (*Queries) Links ¶
Links is every web link the task points at: stored formal links first, then its title and body. URL dedupe keeps the first position while allowing a later labelled spelling to upgrade an unlabelled one in place.
func (*Queries) LiveItems ¶
LiveItems is the live file's tasks in file order — the population ref resolution addresses. The archive is deliberately absent: a ref names something you can still act on.
func (*Queries) NextItems ¶
NextItems is the `next` view: every available NEXT action, ranked by priority. Ties keep file order — Ruby's sort_by is unstable, so this has to be an explicitly stable sort or same-priority rows shuffle between runs, and the canonical order the API and the TUI share would be nondeterministic.
func (*Queries) Project ¶
Project is the task's project FOR DISPLAY: the title of the nearest ancestor headline that is a section or an open task. A task whose every ancestor is a closed task, and which has no section above it, has none — it falls out of the Projects view rather than heading a dead group.
func (*Queries) ProjectView ¶
func (q *Queries) ProjectView(id string) (ProjectView, bool)
ProjectView is a single project, area or reserved GTD list by section id, or ok=false when the id is not such a section: a task, the Projects heading, a nested sub-section, or an area with no open work today.
func (*Queries) Projects ¶
func (q *Queries) Projects() []ProjectView
Projects is every project and area as a rolled-up view.
Projects are the section children of the top-level "Projects" heading, listed even when empty — an empty project is a commitment you have not started, and hiding it is how a project goes quietly missing. Areas are the other top-level lists that currently hold open, non-deferred work, excluding the reserved GTD lists (see reservedListTitles), the Projects heading itself, and everything inside its subtree (a nested sub-section rolls up into its project rather than listing beside it).
Sorted projects before areas, then by soonest date (dateless last), then title, then file order.
func (*Queries) QuadrantItems ¶
QuadrantItems is the `quadrants` view: every OPEN, AVAILABLE task in file order, each paired with the quadrant it falls in. Order is the file's — the grouping is the view, not a sort.
func (*Queries) QuadrantOf ¶
QuadrantOf classifies against this reader's own today.
func (*Queries) ReservedLists ¶ added in v1.8.0
func (q *Queries) ReservedLists() []ProjectView
ReservedLists is every addressable reserved GTD list — the top-level sections the Projects listing deliberately omits, minus Inbox, which stays unaddressable. Callers that resolve a section by ref use it to widen the listing's candidate set without widening the listing itself.
func (*Queries) ScheduledValue ¶
ScheduledValue and DeadlineValue are the stored date plus whatever wall time and zone qualify it. They are built from the RECORD rather than the item so the time object travels with the date it belongs to.
func (*Queries) SectionView ¶ added in v1.8.0
func (q *Queries) SectionView(id string) (ProjectView, bool)
SectionView is a rolled-up view of ANY live section by id — not just the projects and areas the Projects listing admits. The outline renders every section as a selectable row, and the row's actions (rename, capture, complete, archive) all take a bare section id, so the view exists for sections the listing would exclude: Inbox, the Projects heading, nested sub-sections, and areas with no open work.
Kind is resolved the same way the listing resolves it — "project" for a child of the Projects root, "area" for any other top-level section — and falls back to "list" for everything nested deeper.
func (*Queries) Snapshot ¶
Snapshot is the exact read this model was built over. A caller that already holds the queries can ask for the underlying records — the section list, the raw live half — without capturing a SECOND snapshot that could disagree with the one every other answer came from.