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 Notify(ctx context.Context, summary, body string)
- func SetLogger(handler slog.Handler)
- func StderrHandler() slog.Handler
- type AnswerRow
- type Answered
- type Change
- type Completes
- type Desk
- type EndedPick
- type HeldPick
- type Interval
- type MinutesStep
- type Nudge
- type NudgeAnswer
- type PageCode
- type Panel
- type PanelState
- type Paths
- type Phase
- type PickError
- type Pill
- type QueuedAnswer
- type ReadyNudge
- type RecentNudge
- type Record
- type Row
- type RunningPick
- type ShownPick
- 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" // KindTick is a habit's checklist item, whose key records one set and // whose untick_key takes the latest set back. KindTick = "tick" )
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 ( ActionComplete = "complete" ActionTick = "tick" ActionUntick = "untick" )
What a pick does, as its picked line names it.
const ( PickDone = 0 PickFailed = 1 PickRefused = 2 )
The exit codes of a pick, which `doit desk-nudge panel pick` exits with.
const ( OutcomeDone = "done" OutcomeSkipped = "skipped" OutcomeRefused = "refused" OutcomeUncertain = "uncertain" )
The outcomes of a pick. A refused pick recorded nothing, so its row is free again. An uncertain one may have landed, so its row is held until the next read.
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 PickCommitting = "committing"
PickCommitting is the state of a pick whose commit runs. Once it ends, its state is its outcome.
const RecordSchemaVersion = 5
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 = 4
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 ErrWatchServesNoPage = errors.New("the desk nudge watch serves no panel page")
ErrWatchServesNoPage is a watch that answers on the socket and mints no code for the panel page, such as an older doit's Go watch still running through an upgrade.
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 Notify ¶ added in v0.5.0
Notify shows a passing notice, for a command whose stderr nobody reads, such as one a waybar pill or a key starts.
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) Resume ¶
Resume carries on the count from where Pause held it, and reports whether it was paused.
type EndedPick ¶ added in v0.4.0
type EndedPick struct {
ID string `json:"id"`
Key string `json:"key"`
Text string `json:"text"`
Action string `json:"action"`
Minutes *int `json:"minutes"`
Outcome string `json:"outcome"`
Message string `json:"message"`
EndedAt string `json:"ended_at"`
}
EndedPick is how a pick came out, which the panel shows on its row. A done or uncertain one shows until a view read begins after it ended. A refused or skipped one shows until its key is picked again, or a view read begins on a later day.
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 PageCode ¶ added in v0.5.0
PageCode is the panel page's URL carrying a one-use code, which opens the page until ExpiresAt.
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"`
// Picks are the running picks, and how each one that ended came out, while the panel shows it.
Picks []ShownPick `json:"picks"`
}
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 ¶
PanelState holds each panel key picked, with when its completion ended. A read of the panel that begins after that lets it go. Ended holds how each pick ended, which the panel shows on its row.
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.
func (Paths) AskPageCode ¶ added in v0.5.0
AskPageCode asks the watch for the panel page's URL with a fresh one-use code. Where nothing answers, it is ErrNoWatch or ErrWatchServesNoPicks, as AskPick's is. Where the watch has no such route, or answers in a shape that this doit cannot read, it is ErrWatchServesNoPage. A refusal is a *PickError carrying the exit code the watch named, and why.
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"`
// Ticks and Target are a checklist item's sets today, as the view was read, and its daily target.
Ticks *int `json:"ticks"`
Target *int `json:"target"`
// UntickKey takes a checklist item's latest set back.
UntickKey *string `json:"untick_key"`
// Picks are the running picks of the row's keys, and how each one that ended came out.
Picks []ShownPick `json:"picks"`
}
Row is one line of a step as a terminal or a board draws it.
type RunningPick ¶ added in v0.6.0
type RunningPick struct {
ID string `json:"id"`
Key string `json:"key"`
Text string `json:"text"`
Action string `json:"action"`
Completes Completes `json:"completes"`
Minutes *int `json:"minutes"`
// PickedAt is when it was picked, whose day on the desk the commit lands on.
PickedAt string `json:"picked_at"`
StartedAt string `json:"started_at"`
// Log is a pursuit's journal entry once its on_log is about to run, which a restart sends again under the same id.
Log map[string]any `json:"log,omitempty"`
}
RunningPick is a pick whose commit has begun and not ended. The state file holds it before its command runs, so a restart reads what may already have run.
type ShownPick ¶ added in v0.4.0
type ShownPick struct {
ID string `json:"id"`
Key string `json:"key"`
Text string `json:"text"`
Action string `json:"action"`
State string `json:"state"`
Minutes *int `json:"minutes"`
Message *string `json:"message"`
EndedAt *string `json:"ended_at"`
}
ShownPick is a pick as the panel shows it: committing, or the outcome it ended with.
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"`
// RunningPicks are the picks whose commit began and has not ended, in the order they began.
RunningPicks []RunningPick `json:"running_picks"`
}
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 or the page, and asks for the parts to be read again once it ran. notifyDone is whether a pick that went through is notified, which the page's own row says already.
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, and takes up the picks it left running. A ready nudge stays on the pill, unchimed.