gtd

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gtd is the GTD service: entries derived from items, captured by the user or opened by other services, and the verbs that move them.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEntry = errors.New("no such entry")
	ErrVerb    = errors.New("the entry's state refuses the verb")
	// ErrArgs is a request the service cannot read: an unknown verb or view, or a missing or bad argument.
	ErrArgs = errors.New("bad entry request")
	// ErrPluginDisabled refuses a change to an entry whose unit's plugin is disabled.
	ErrPluginDisabled = errors.New("the unit's plugin is disabled")
)

Functions

func Accepts

func Accepts(e gtd.Entry, verb gtd.Verb) error

Accepts says whether e's state takes verb with no handler: ErrArgs for an unknown verb, ErrVerb naming the verb and the state for a refused one. approve, delegate, answer, edit and retry move nothing on their own, so it refuses them.

func Delta

func Delta(all []gtd.Entry, q gtd.Query, changed func(gtd.ID) bool) (in []gtd.Entry, removed []gtd.ID)

Delta is the incremental page of q over all, the entries a store holds for q and every entry changed after the client's position (changed says which): the changed entries in q's view, and the changed ids out of it. A change to a project, or to one of its actions, counts as a change to all its actions, since the sequential rule may move another one into Next. Removed may name ids the client never held.

Types

type CardFacts

type CardFacts struct {
	Cards card.Store
	// Enabled says whether a provider's plugin is enabled; nil: every one is.
	Enabled func(unit.ProviderID) bool
	// Me is the user's identity now; nil: nobody.
	Me func() gtd.Me
}

CardFacts reads a unit's facts from its stored card (#unit-card).

func (CardFacts) UnitFacts

func (f CardFacts) UnitFacts(ctx context.Context, u unit.Unit) (gtd.UnitFacts, bool, error)

UnitFacts is u's facts from its card; ok is false for a disabled plugin's unit. A unit with no card stored has no facts beyond its identity.

type Deps

type Deps struct {
	Store Store
	Items Items
	Facts Facts
	Me    gtd.Me
	Clock port.Clock
	// StaleWaitingDays is how many working days a waiting entry waits before AutoFocus stars it.
	StaleWaitingDays int
	// Disabled are the providers whose plugin is disabled now; nil: none is.
	Disabled func() []unit.ProviderID
}

Deps is what the service runs on.

type Facts

type Facts interface {
	UnitFacts(ctx context.Context, u unit.Unit) (gtd.UnitFacts, bool, error)
}

Facts reads a unit's facts; ok false: plugin disabled.

type Items

type Items interface {
	Items(ctx context.Context, u unit.Unit) ([]items.Item, error)
}

Items is the items ledger's reader.

type OpenRequest

type OpenRequest struct {
	Kind     gtd.Kind
	Title    string
	Unit     *unit.Unit
	Origin   string
	Contexts []string
}

type Page

type Page struct {
	Epoch    string
	Rev      uint64
	Full     bool
	Entries  []gtd.Entry
	Removed  []gtd.ID
	Counters gtd.Counters
}

type ProjectDeps

type ProjectDeps struct {
	Store    ProjectStore
	Dossiers ProjectDossiers // nil keeps no dossiers
}

type ProjectDossiers

type ProjectDossiers interface {
	Open(ctx context.Context, slug string) error
	Resolved(ctx context.Context, slug string, at time.Time) error
}

ProjectDossiers opens a new project's dossier and starts its lifecycle once the project ends (#dossier).

type ProjectState

type ProjectState struct {
	gtd.ProjectStatus
	Due bool // past its review interval
}

ProjectState is a project's status at the service's now.

type ProjectStore

type ProjectStore interface {
	// SlugTaken says whether a project, done or not, holds slug.
	SlugTaken(ctx context.Context, slug string) (bool, error)
	// CurrentRun is the Review run with a step still open.
	CurrentRun(ctx context.Context) (gtd.ReviewRun, bool, error)
	PutRun(ctx context.Context, r gtd.ReviewRun) error
}

ProjectStore keeps what the projects need beyond their entries: the slugs taken and the Review's runs.

type Reader

type Reader interface {
	Entries(ctx context.Context, q gtd.Query) ([]gtd.Entry, error)
	// EntriesSince is the page of q after position since: Full when since is from another epoch or too old;
	// else the entries of q changed after Rev and the ids that left q. Counts in the same read transaction.
	EntriesSince(ctx context.Context, q gtd.Query, since Since) (Page, error)
	Entry(ctx context.Context, id gtd.ID) (gtd.Entry, error) // ErrNoEntry; ErrVerb is a verb the entry's state refuses, naming both
	EntriesOf(ctx context.Context, u unit.Unit) ([]gtd.Entry, error)
	Counts(ctx context.Context, area string) (gtd.Counters, error) // stored views only
}

Reader is the read half of Store.

type Request

type Request struct {
	Verb   gtd.Verb
	Args   map[string]string
	Source string
}

type Result

type Result struct {
	Entry gtd.Entry
	Lines []string
}

type Review

type Review struct {
	ID        string
	StartedAt time.Time
	Steps     []ReviewStep
	Done      bool
}

Review is the weekly Review as it stands: its steps in order, each with its count. ID is empty while nothing was left to review when it started, so nothing was recorded.

type ReviewStep

type ReviewStep struct {
	gtd.ReviewStep
	Count int
	Done  bool
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(d Deps) *Service

func (*Service) Capture

func (s *Service) Capture(ctx context.Context, title, notes string, u *unit.Unit) (gtd.Entry, error)

Capture files a new entry in the Inbox.

func (*Service) Close

func (s *Service) Close(ctx context.Context, id gtd.ID, to gtd.State) error

Close moves an entry opened by Open or Capture to Done or Trash; a derived entry, or one whose unit's plugin is disabled, refuses it.

func (*Service) Counts

func (s *Service) Counts(ctx context.Context, area string) (gtd.Counters, error)

Counts is Store.Counts plus each ViewSource.Count but review's; Badge is Inbox plus Outbox.

func (*Service) CountsWhere added in v0.2.0

func (s *Service) CountsWhere(ctx context.Context, area string, keep func(gtd.Entry) (bool, error)) (gtd.Counters, error)

CountsWhere is Counts over the entries keep holds: each view, area and context counts only the entries of its list that keep takes, so a client's filter narrows the counters as it narrows the lists.

func (*Service) Do

func (s *Service) Do(ctx context.Context, id gtd.ID, req Request) (Result, error)

Do runs req.Verb on entry id: a registered handler first, else the state change. An entry of a unit whose plugin is disabled refuses every verb with ErrPluginDisabled but dismiss, which moves a derived entry, or one whose units are all of disabled plugins, to the Trash whole, and detaches a disabled plugin's units from any other.

func (*Service) Entries

func (s *Service) Entries(ctx context.Context, q gtd.Query) ([]gtd.Entry, error)

Entries is q's view, from its registered ViewSource or the store; the outbox is empty while none serves it. A disabled plugin's entries are left out, as hidden says.

func (*Service) EntriesSince

func (s *Service) EntriesSince(ctx context.Context, q gtd.Query, since Since) (Page, error)

EntriesSince is q's page after since with the counters of q's area: a registered ViewSource's view is always Full, at the store's position.

func (*Service) Entry

func (s *Service) Entry(ctx context.Context, id gtd.ID) (gtd.Entry, error)

Entry reads id from the ViewSource its prefix names, or the store.

func (*Service) Handles

func (s *Service) Handles(kind gtd.Kind, verb gtd.Verb) bool

Handles says whether a handler is registered for verb on entries of kind.

func (*Service) Nudged

func (s *Service) Nudged(ctx context.Context, ids []gtd.ID, u unit.Unit, at time.Time) error

Nudged records a nudge sent at at on the live waiting entries ids names, or, with no ids, on every live waiting entry of u. It reads them under the service's lock, so it never writes back a copy older than a concurrent Sync's, and it never moves LastNudge back.

func (*Service) Open

func (s *Service) Open(ctx context.Context, r OpenRequest) (gtd.Entry, error)

Open creates an entry another service owns the content of (messages): Kind, Inbox, random id.

func (*Service) ProjectsStatus

func (s *Service) ProjectsStatus(ctx context.Context) (map[gtd.ID]ProjectState, error)

ProjectsStatus is each live project's next action, open actions and review mark, over one read of the open set.

func (*Service) Register

func (s *Service) Register(kind gtd.Kind, verb gtd.Verb, h VerbHandler)

Register makes h run verb on entries of kind, before any state change.

func (*Service) RegisterView

func (s *Service) RegisterView(v gtd.View, prefix string, src ViewSource)

RegisterView serves v from src; ids starting with prefix are read from it.

func (*Service) Retitle

func (s *Service) Retitle(ctx context.Context, id gtd.ID, title string) error

Retitle renames an entry opened by Open or Capture, as one change; a derived entry refuses it.

func (*Service) Review

func (s *Service) Review(ctx context.Context) (Review, error)

Review is the current Review, or a new one: a step whose count is 0 at its start starts done, and a new Review is recorded once a step is left to do.

func (*Service) ReviewStepDone

func (s *Service) ReviewStepDone(ctx context.Context, step string) (Review, error)

ReviewStepDone marks step done in the current Review, recording the Review once every step is.

func (*Service) ServeProjects

func (s *Service) ServeProjects(d ProjectDeps)

ServeProjects runs the project verbs on s (project with its position, sequential, reviewed), resolves an ending project's dossier, and serves the review view and the Review.

func (*Service) Serves

func (s *Service) Serves(v gtd.View) bool

Serves says whether v is served: a stored view, the outbox, or a view a ViewSource serves.

func (*Service) SetMe

func (s *Service) SetMe(me gtd.Me)

SetMe replaces the user's identity the next Sync reconciles with.

func (*Service) Sync

func (s *Service) Sync(ctx context.Context, units []unit.Unit) error

Sync reconciles the units named by a TopicItems, TopicSourceEvents or TopicCards note, then AutoFocus and Wake for all, in one Apply. A unit whose plugin is disabled keeps its entries as they are. A snooze that ends reconciles its entry's units after waking it, so a still-muted unit snoozes it again before anything sees it in the Inbox.

type Since

type Since struct {
	Epoch string
	Rev   uint64
}

type Store

type Store interface {
	Reader
	// Apply writes cs in one transaction, bumps Rev and notes port.TopicEntries; with no effective change
	// it writes and notes nothing.
	Apply(ctx context.Context, cs []gtd.Change, evs ...port.Event) error
}

type VerbHandler

type VerbHandler func(ctx context.Context, e gtd.Entry, req Request) (Result, error)

VerbHandler runs a verb another service owns (answer/approve/dismiss on messages, approve/dismiss on drafts).

type ViewSource

type ViewSource interface {
	Entries(ctx context.Context, q gtd.Query) ([]gtd.Entry, error)
	Entry(ctx context.Context, id gtd.ID) (gtd.Entry, bool, error)
	Count(ctx context.Context, area string) (int, error)
}

ViewSource serves a view whose entries live elsewhere (outbox with prefix "draft:", review). Its ids carry its prefix; Count is what the view's counter shows.

Directories

Path Synopsis
Package gtdtest holds an in-memory entry store and the contract suite every entry store passes.
Package gtdtest holds an in-memory entry store and the contract suite every entry store passes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL