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 ReservedListTitle(title string) 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) PriorityThenDueBefore(left, right store.Item) bool
- 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) ProjectsIncluding(includeClosed bool) []ProjectView
- func (q *Queries) QuadrantItems() []store.Item
- func (q *Queries) QuadrantOf(item store.Item, urgentDays int) string
- func (q *Queries) RankByPriorityThenDue(items []store.Item) []store.Item
- func (q *Queries) RecentRejects() []store.Item
- 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.
const RejectedRecentDays = 30
RejectedRecentDays is what "recent" means for a declined proposal, in both the CLI's `list --rejected` and the TUI's show-rejected toggle: the decline happened within this many days of the reader's today, counting today as day zero. One number, in one place, so the two surfaces can never disagree about which rejects are still reachable — and so a store that has been running for years does not turn the restore list into an archive browser.
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 ReservedListTitle ¶ added in v1.17.0
ReservedListTitle reports whether a top-level section title is one of the saved GTD lists whose membership is already expressed by task state. These lists remain addressable sections, but callers should not present them as a project or area label beside the task's own state.
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
// State and Closed are the section lifecycle pair when this node is a
// section. Tasks carry lifecycle on their Item, sections carry it here
// so row builders can ask a node directly without a second lookup.
State string
Closed string
HasClosed bool
}
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.
func (*Node) Project ¶
Project is the nearest ancestor headline: a task's project, or a subtask's parent task.
func (*Node) ProjectSection ¶ added in v1.17.0
ProjectSection climbs ancestors to the section that is a child of the Projects root, or nil when there is none. It is the resolver the task detail rail uses to name the project a task belongs to.
func (*Node) TopLevelSection ¶ added in v1.17.0
TopLevelSection returns the outermost section containing this node. It is nil for a detached task or section. Presentation callers use it only after ProjectSection returns nil, so a task filed under Projects still names its concrete project rather than the Projects root.
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
State string
Closed string
HasClosed bool
}
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.
func (ProjectView) IsClosed ¶ added in v1.17.0
func (v ProjectView) IsClosed() bool
IsClosed reports whether the project section is closed (DONE or CANCELLED).
func (ProjectView) Open ¶ added in v1.17.0
func (v ProjectView) Open() bool
Open reports whether the project is still open.
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) List ¶
List selects the items a filter names, in file order — except for the two QUEUE scopes (`--agent-ready` and `--proposed`), which come back in the shared triage order below.
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) PriorityThenDueBefore ¶ added in v1.9.0
PriorityThenDueBefore is RankByPriorityThenDue's comparator on its own, for callers that already own a sort — a row builder ordering rows rather than items, say — and must order by the same rule rather than a lookalike.
It is deliberately NOT a total order: it reports nothing about two items that tie on priority and date, leaving the caller's stable sort to preserve whatever order they arrived in.
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) ProjectsIncluding ¶ added in v1.17.0
func (q *Queries) ProjectsIncluding(includeClosed bool) []ProjectView
ProjectsIncluding is Projects with an explicit closed filter. When includeClosed is false, closed projects are omitted — the default for every existing caller. When true, they are included.
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) RankByPriorityThenDue ¶ added in v1.9.0
RankByPriorityThenDue is the shared TRIAGE order: the one ranking every surface uses when a queue exists to be decided rather than browsed.
priority A > B > C > none within a band, the soonest date boundary first an undated row after every dated row in its band canonical file/DFS order as the final tiebreak
It is a core function, not an adapter detail, because the ORDER is part of what the list means: the agent-ready queue is taken from the top, and the Approvals queue is scanned from the top. A sort that lived in whichever surface happened to print it would drift between CLI, TUI and HTTP the first time one of them grew a new caller.
The date used is agendaSortKey — the deadline boundary if there is one, else the moment an available-from date opens, else a sentinel far future, which is exactly what puts undated rows last inside their band. Priority strictly dominates the date: a C due tomorrow still ranks below an undated A.
The sort is stable, so items tying on both keys keep the order the snapshot handed over, which is file order for a flat list and DFS order for a walked tree. Callers that want file/DFS order untouched simply do not call this.
func (*Queries) RecentRejects ¶ added in v1.9.0
RecentRejects is the shared answer to "which declines can still be restored": every CANCELLED task carrying the decline marker, live first then recently archived, newest decline first. The CLI's `--rejected` scope and the TUI's toggle both read THIS, so "recent" is one rule with one implementation.
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.