Documentation
¶
Overview ¶
Package desknudge is the desk nudge: the clock that counts toward the interval, the files and locks it keeps on this desk, the panel it builds from the service's desk panel view, and the picks that complete a row.
The service computes the interval and the answer counts from every answer, and every rule behind the panel's rows. This package holds only the desk's own rules: the clock, kept blind to input, the picks, the files and the locks.
Index ¶
- Constants
- Variables
- func Answers() []string
- func IsAnswer(value string) bool
- func SetLogger(handler slog.Handler)
- func StderrHandler() slog.Handler
- type AnswerRow
- type Answered
- type Change
- type Completes
- type Desk
- func (d *Desk) Answer(ctx context.Context, answer, nudgeID string) (Answered, error)
- func (d *Desk) LabelOf(answer string) string
- func (d *Desk) Pause() (bool, error)
- func (d *Desk) Pick(ctx context.Context, key string, minutes *int, read func()) (Panel, error)
- func (d *Desk) Resume() (bool, error)
- func (d *Desk) Show() Panel
- func (d *Desk) Status() Status
- type HeldPick
- type Interval
- type MinutesStep
- type Nudge
- type NudgeAnswer
- type Panel
- type PanelState
- type Paths
- type Phase
- type PickError
- type Pill
- type QueuedAnswer
- type ReadyNudge
- type RecentNudge
- type Record
- type Row
- type StaleReason
- type State
- type Status
- type Suggestion
- type View
- type ViewVersionError
- type Watch
Constants ¶
const ( StepToday = "today" StepMinutes = "minutes" StepDone = "done" )
The steps a panel document holds.
const ( KindNote = "note" KindAnswer = "answer" KindLogMinutes = "log_minutes" KindAdjustMinutes = "adjust_minutes" )
The kinds a row of the panel carries beyond what a completion completes.
const ( KindPursuit = "pursuit" KindHabit = "habit" )
The completion kinds that the watch completes by an owner of their own. The view's completion_kind definition holds the whole set, and every other kind is an entry of a review register.
const ( PickDone = 0 PickFailed = 1 PickRefused = 2 )
The exit codes of a pick, which `doit desk-nudge panel pick` exits with.
const ( Unreachable = "unreachable" LoginRefused = "login" NothingToDraw = "nothing_to_draw" Unreadable = "unreadable" )
Why a firing has no suggestion, each with what the panel says instead.
const PanelSchemaVersion = 3
PanelSchemaVersion is the panel's shape, which schemas/desk-nudge-panel.schema.json describes.
const RecordSchemaVersion = 3
RecordSchemaVersion is the shape of a line in desk-nudge-events.jsonl, which schemas/desk-nudge-record.schema.json describes.
const StateVersion = 2
StateVersion is the state file's shape. It stays 2 with the Python watch's field names, so either watch reads the other's clock: an older doit's Python watch after a revert, and this watch after an upgrade.
const StatusSchemaVersion = 2
StatusSchemaVersion is the shape of `doit desk-nudge status --json`, which schemas/desk-nudge-status.schema.json describes.
Variables ¶
var ErrAnotherWatch = errors.New("another watch is running on this desk, so this one exits")
ErrAnotherWatch is a watch already running on this desk.
var ErrHeldElsewhere = errors.New("held by another process")
ErrHeldElsewhere is a lock that another process holds.
var ErrNoWatch = errors.New("no desk nudge watch is running")
ErrNoWatch is no watch answering on the socket.
var ErrNothingToAnswer = errors.New("nothing to answer")
ErrNothingToAnswer is no nudge to answer: none is ready, or the id names none that this desk fired lately.
var ErrUnreadableState = errors.New("unreadable state")
ErrUnreadableState is a state file that is not version 2's: not JSON, not an object, or another version.
var ErrWatchServesNoPicks = errors.New("a watch holds this desk and answers no pick")
ErrWatchServesNoPicks is a watch that holds this desk and answers nothing on the socket, such as an older doit's Python watch still running through an upgrade.
Functions ¶
func StderrHandler ¶
StderrHandler logs to stderr, with journald's priorities where stderr is the journal stream that $JOURNAL_STREAM names.
Types ¶
type AnswerRow ¶
type AnswerRow struct {
NudgeID string `json:"nudge_id"`
Answer string `json:"answer"`
FiredAt string `json:"fired_at"`
AnsweredAt string `json:"answered_at"`
Machine string `json:"machine"`
}
AnswerRow is one answer as the service stores it.
type Answered ¶
type Answered struct {
// contains filtered or unexported fields
}
Answered is what became of one answer: taken on the desk, then stored by the service or not.
type Change ¶
type Change struct {
Records []Record
// Closes is the nudge this change ended.
Closes *Nudge
// Fire is present time reaching the interval, so a firing begins.
Fire bool
}
Change is what one change to the state asks of the effects around it.
type Completes ¶
type Completes struct {
Kind string `json:"kind"`
Ref string `json:"ref"`
ItemID *string `json:"item_id"`
}
Completes is what picking an entry completes, as the view gives it.
type Desk ¶
type Desk struct {
Paths Paths
Now func() time.Time
// Open is the service this desk's login names, opened afresh for each
// request so a new login is taken at once.
Open func(context.Context) (*service.Client, error)
Machine string
Actor string
// Version is the doit release this binary is.
Version string
}
Desk is this desk: its files, its clock, the service it asks, and who it is.
func (*Desk) Answer ¶
Answer takes one answer, ends the nudge it answers, and stores it, keeping it to send again where a later send could store it.
It is the one path for every answer to a nudge. With no id it answers the ready nudge. It answers ErrNothingToAnswer where none is ready and the id names none that this desk fired. An answer already kept on this desk is sent as it was kept, because that row is the one the service stores. One saved line is written per answer, by the writer that drops it from the queue or whose send the service added.
func (*Desk) Pause ¶
Pause holds the clock where it stands, ending a nudge in hand, and reports whether it was running.
func (*Desk) Pick ¶
Pick acts on one panel row by its key, and answers the next step: a done step once something is completed, or a timed pursuit's minutes. minutes logs a timed pursuit at once. read is called once a completion went through, so the parts are read again.
The watch owns the vocabulary of keys. An answer key and a minutes key are read as the watch wrote them, and any other key is resolved against the panel's parts, whose completes says what to run.
func (*Desk) Resume ¶
Resume carries on the count from where Pause held it, and reports whether it was paused.
type Interval ¶
type Interval struct {
IntervalMinutes float64 `json:"interval_minutes"`
AnswerCounts map[string]int `json:"answer_counts"`
}
Interval is the service's interval and answer counts, as GET /desk-nudge and an answer's reply carry them.
type MinutesStep ¶
MinutesStep is the timed pursuit that a minutes step logs. The step's rows log an amount, or reopen the step one adjustment above or below it.
type Nudge ¶
type Nudge struct {
NudgeID string `json:"nudge_id"`
FiredAt string `json:"fired_at"`
CountedMinutes float64 `json:"counted_minutes"`
IntervalMinutes float64 `json:"interval_minutes"`
Suggestion *Suggestion `json:"suggestion"`
ReadyUntil *string `json:"ready_until"`
}
Nudge is the nudge in hand, from its firing until an answer, a pick or its expiry ends it.
type NudgeAnswer ¶
type NudgeAnswer struct {
Answer string `json:"answer"`
Label string `json:"label"`
Key string `json:"key"`
}
NudgeAnswer is one answer to the ready nudge, and the key that picks it.
type Panel ¶
type Panel struct {
SchemaVersion int `json:"schema_version"`
Step string `json:"step"`
Message *string `json:"message"`
// ReadAt is when the watch began the read that the view comes from, on this desk's clock.
ReadAt *string `json:"read_at"`
// GeneratedAt is when the service computed the view.
GeneratedAt *string `json:"generated_at"`
StaleSince *string `json:"stale_since"`
StaleReason *StaleReason `json:"stale_reason"`
// View is the service's desk panel view whole, with its own schema_version, or null before the first read.
View json.RawMessage `json:"view"`
// Rows are what the step draws, in order, so no reader holds the rule that lists them.
Rows []Row `json:"rows"`
Nudge *ReadyNudge `json:"nudge"`
Picked []HeldPick `json:"picked"`
Minutes *MinutesStep `json:"minutes"`
}
Panel is one step of the desk nudge's panel: the view as the watch last read it, what only this desk knows, and the rows the step draws. The watch keeps the today step in desk-nudge-panel.json, `panel show --json` prints it, and `panel pick --json` prints the step a pick leads to.
type PanelState ¶
type PanelState struct {
Picked []HeldPick `json:"picked"`
}
PanelState holds each panel key picked, with when its completion ended. A read of the panel that begins after that lets it go.
type Paths ¶
type Paths struct {
// State is the clock, which the waybar pill reads.
State string
// StateLock is taken around each change to State.
StateLock string
// WatchLock is held for a watch's whole life, so a second one refuses to start.
WatchLock string
// Records is one line per moment the nudge records, appended and never rotated, for a log shipper.
Records string
// Panel is the panel as the watch last built it, which panel show reads with no watch.
Panel string
// Socket is where the watch answers the CLI.
Socket string
}
Paths are the files the desk nudge keeps on this desk.
func DeskPaths ¶
func DeskPaths() Paths
DeskPaths are this desk's, under $XDG_STATE_HOME, $XDG_CACHE_HOME and the runtime directory.
type PickError ¶
PickError is a pick that did nothing or did not go through. Its notification is already shown, and its picked line written.
type Pill ¶
type Pill struct {
Text string `json:"text"`
Class Phase `json:"class"`
StaleAfter *string `json:"stale_after"`
}
Pill is what the waybar pill reads from the state file.
type QueuedAnswer ¶
QueuedAnswer is an answer the service did not store, which the watch sends again.
type ReadyNudge ¶
type ReadyNudge struct {
NudgeID string `json:"nudge_id"`
FiredAt string `json:"fired_at"`
ReadyUntil *string `json:"ready_until"`
Answers []NudgeAnswer `json:"answers"`
}
ReadyNudge is the nudge that is ready, with the key that answers it for each answer.
type RecentNudge ¶
RecentNudge is a nudge that ended lately, which a late answer can still name.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is one line of the records file. Its fields keep the order they were given, so ts, event and the schema version lead every line.
func (Record) MarshalJSON ¶
type Row ¶
type Row struct {
Key *string `json:"key"`
Kind string `json:"kind"`
Text string `json:"text"`
Group *string `json:"group"`
Minutes *int `json:"minutes"`
Suggested bool `json:"suggested"`
}
Row is one line of a step as a terminal or a board draws it.
type StaleReason ¶
StaleReason is why the latest read of the view failed.
type State ¶
type State struct {
Version int `json:"version"`
Phase Phase `json:"phase"`
CountedSeconds float64 `json:"counted_seconds"`
LastTick *string `json:"last_tick"`
IntervalMinutes float64 `json:"interval_minutes"`
AnswerCounts map[string]int `json:"answer_counts"`
Nudge *Nudge `json:"nudge"`
QueuedAnswers []QueuedAnswer `json:"queued_answers"`
RecentNudges []RecentNudge `json:"recent_nudges"`
Panel PanelState `json:"panel"`
Pill Pill `json:"pill"`
}
State is the state file, $XDG_STATE_HOME/doit/desk-nudge.json.
type Status ¶
type Status struct {
SchemaVersion int `json:"schema_version"`
Phase Phase `json:"phase"`
WatchRunning bool `json:"watch_running"`
CountedMinutes float64 `json:"counted_minutes"`
IntervalMinutes float64 `json:"interval_minutes"`
MinutesLeft *int `json:"minutes_left"`
NudgeID *string `json:"nudge_id"`
FiredAt *string `json:"fired_at"`
ReadyUntil *string `json:"ready_until"`
Suggestion *Suggestion `json:"suggestion"`
AnswerCounts map[string]int `json:"answer_counts"`
QueuedAnswerCount int `json:"queued_answer_count"`
Pill Pill `json:"pill"`
}
Status is where the clock stands, read from this desk's state file with no request.
type Suggestion ¶
type Suggestion struct {
Pursuit string
ItemID *string
Label string
Error string
Message string
Detail string
}
Suggestion is what a firing suggested: the pursuit the draw offered first, or why none was drawn. Each marshals as its own shape, which the record and status schemas describe.
func (Suggestion) MarshalJSON ¶
func (s Suggestion) MarshalJSON() ([]byte, error)
func (*Suggestion) UnmarshalJSON ¶
func (s *Suggestion) UnmarshalJSON(data []byte) error
type View ¶
type View struct {
SchemaVersion int `json:"schema_version"`
GeneratedAt string `json:"generated_at"`
Suggestion json.RawMessage `json:"suggestion"`
SuggestionReason *string `json:"suggestion_reason"`
Answers json.RawMessage `json:"answers"`
Totals json.RawMessage `json:"totals"`
Pursuits json.RawMessage `json:"pursuits"`
Habits json.RawMessage `json:"habits"`
Lanes json.RawMessage `json:"lanes"`
Problems json.RawMessage `json:"problems"`
// contains filtered or unexported fields
}
View is the service's desk panel view, as schemas/desk-panel-view.schema.json describes it. It names the parts the watch reads, and keeps the document as the service answered it, so a part added to the service's answer reaches the panel with no change here.
func (*View) UnmarshalJSON ¶
UnmarshalJSON reads the parts and keeps the document whole.
type ViewVersionError ¶
type ViewVersionError struct{ Version int }
ViewVersionError is a desk panel view at a version that this doit does not read.
func (*ViewVersionError) Error ¶
func (e *ViewVersionError) Error() string
type Watch ¶
type Watch struct {
// Executable is the binary whose replacement ends the watch, so the unit starts the new one.
Executable string
// contains filtered or unexported fields
}
Watch counts the time since the last nudge ended and fires the nudge at the interval. Each request and program runs off the tick, in a goroutine of its own.
func (*Watch) Pick ¶
Pick runs one pick for the socket, and asks for the parts to be read again once it went through.
func (*Watch) Run ¶
Run holds the watch lock, serves the socket, and ticks until ctx ends or the binary is replaced. Either way it drains what is under way, then returns nil.
func (*Watch) Start ¶
Start writes started, then finishes a nudge that a stopped watch left firing. A ready one stays on the pill, unchimed.