Documentation
¶
Overview ¶
Package domain defines the shared vocabulary for Taskronin entities and operations.
Index ¶
- Constants
- Variables
- func BlockSpanText(text string) string
- func EffectImplied(kind string, deleted, undeleted bool) bool
- func EncodeCursor(c Cursor) string
- func FormatETag(g Generation, v Version) string
- func ParseTokenExpiry(s string, now time.Time, zone civil.Zone) (sql.Null[time.Time], error)
- func ValidOpIDPrefix(s string) bool
- type Action
- type Actor
- type ActorKind
- type BlockID
- type BlockSpan
- type BlockStatus
- type BlockView
- type CancelReason
- type Channel
- type Code
- type Cursor
- type DuePhase
- type EntityKind
- type EntityRef
- type EntryID
- type EntryKind
- type EntryView
- type Error
- type Event
- type EventID
- type Expect
- type FieldError
- type Focus
- type Generation
- type Interruption
- type InterruptionID
- type LogEntry
- type Moment
- type OpID
- type OpKind
- type OpRecord
- type OpSeq
- type OpState
- type OutcomeSource
- type PlaceHow
- type Priority
- type RevertConflict
- type Scopes
- type TagID
- type Task
- type TaskDetail
- type TaskID
- type TaskStatus
- type TaskView
- type TimeBlock
- type Token
- type TokenID
- type TriageReason
- type TriageRow
- type UserOutcome
- type Version
- type View
Constants ¶
const DeferFutureDetail = "defer must be in the future"
DeferFutureDetail is the stable validation detail shared with API clients.
Variables ¶
var TriageOrder = [...]TriageReason{ ReasonSlipped, ReasonOverdue, ReasonDue, ReasonContinue, ReasonSurfaced, ReasonReopened, ReasonManual, ReasonNew, }
TriageOrder lists reasons from highest to lowest priority.
Functions ¶
func BlockSpanText ¶
BlockSpanText uses an en dash for the clock range in a block effect payload. An optional ISO date is preserved for the caller to format.
func EffectImplied ¶
EffectImplied reports whether a deletion or restore of the same task already accounts for this effect in the operation's display. AIDEV-NOTE: J§4.4 is shared by cli.printOp, cli.printAIChanges and web.flashLines.
func EncodeCursor ¶
EncodeCursor returns unpadded base64url JSON, using the offset form when Keys is nil and ID is zero. Keys must be JSON-encodable; otherwise it panics.
func FormatETag ¶
func FormatETag(g Generation, v Version) string
FormatETag returns the quoted strong ETag for g and v.
func ParseTokenExpiry ¶
ParseTokenExpiry parses the token expiry grammar shared by `tkr token create --expires` and `tkr init --mcp-token`: "never" (no expiry, an invalid sql.Null), a whole number of hours or days ("12h", "30d"; 1h to 100 years after now), or a date YYYY-MM-DD, which expires at 00:00 of that day in zone. The expiry must be after now. Errors are user-facing predicates ("must be ...") for the caller to prefix with the flag or prompt name.
AIDEV-NOTE: final review B-I3. One grammar for both commands: init used to accept Go durations (720h, 1h30m) but not the "30d" that token create suggests. Keep the two call sites on this function.
func ValidOpIDPrefix ¶
ValidOpIDPrefix reports whether s is 1 to 32 lowercase hex characters, the leading part of an op ID as `tkr` prints it.
Types ¶
type Action ¶
type Action string
Action identifies the change recorded in an event.
const ( // ActInsert inserts an entity. ActInsert Action = "insert" // ActUpdate updates entity fields. ActUpdate Action = "update" // ActMove changes task ordering. ActMove Action = "move" // ActTombstone marks an entity deleted. ActTombstone Action = "tombstone" // ActUntombstone restores a deleted entity. ActUntombstone Action = "untombstone" // ActAdd adds a member to a collection. ActAdd Action = "add" // ActRemove removes a member from a collection. ActRemove Action = "remove" // ActSet replaces a value or set. ActSet Action = "set" // ActRevoke revokes a token. ActRevoke Action = "revoke" // ActPurge purges entity content. ActPurge Action = "purge" )
type Actor ¶
type Actor struct {
Kind ActorKind
TokenID TokenID // zero for system and web-session owner
TokenName string // set only for ActorToken
Scopes Scopes
Channel Channel
MutationsPerHour int // zero means unlimited
RemoteKey string // "socket" or client IP; password-gate bucket key
}
Actor describes the authenticated caller of an operation.
func SystemActor ¶
func SystemActor() Actor
SystemActor returns the internal actor with channel system and no scopes.
type BlockSpan ¶
BlockSpan is the half-open interval [Start, End) on Date, with 0 <= Start < End <= 1440.
type BlockStatus ¶
type BlockStatus string
BlockStatus is the lifecycle state of a time block.
const ( // BlockPlanned marks a scheduled block. BlockPlanned BlockStatus = "planned" // BlockDone marks a block with task completion. BlockDone BlockStatus = "done" // BlockWorked marks a block with work recorded. BlockWorked BlockStatus = "worked" // BlockMissed marks a block without work. BlockMissed BlockStatus = "missed" // BlockCancelled marks a cancelled block. BlockCancelled BlockStatus = "cancelled" )
func (BlockStatus) Valid ¶
func (s BlockStatus) Valid() bool
Valid reports whether s is a declared block status.
type BlockView ¶
type BlockView struct {
TimeBlock
TaskTitle string
TaskVersion Version // task precondition for reblock (R4-7)
Current bool // planned and [start,end) contains now
Started bool // start instant <= now
Ended bool // end instant <= now
NeedsReblock bool // planned, ended, no non-deleted entry for (task, date)
}
BlockView adds the associated task and derived interval state to a block.
type CancelReason ¶
type CancelReason string
CancelReason explains a block cancellation.
const ( // CancelUser denotes an explicit cancellation. CancelUser CancelReason = "user" // CancelTaskClosed denotes cancellation when a task closes. CancelTaskClosed CancelReason = "task_closed" // CancelDeferred denotes cancellation when a task is deferred. CancelDeferred CancelReason = "deferred" // CancelRescheduled denotes cancellation when a block is rescheduled. CancelRescheduled CancelReason = "rescheduled" )
func (CancelReason) Valid ¶
func (r CancelReason) Valid() bool
Valid reports whether r is a declared cancellation reason.
type Channel ¶
type Channel string
Channel identifies the calling interface. It is informational, except that token management refuses the trusted, in-process web channel.
const ( // ChanCLI denotes the command-line interface. ChanCLI Channel = "cli" // ChanTUI denotes the terminal interface. ChanTUI Channel = "tui" // ChanWeb denotes the in-process web interface. ChanWeb Channel = "web" // ChanMCP denotes the MCP interface. ChanMCP Channel = "mcp" // ChanAPI denotes the HTTP API. ChanAPI Channel = "api" // ChanSystem denotes an internal operation. ChanSystem Channel = "system" )
type Code ¶
type Code string
Code is a stable service error code.
const ( // CodeMalformed denotes malformed input (400). CodeMalformed Code = "malformed" // CodeUnauthenticated denotes missing or invalid authentication (401). CodeUnauthenticated Code = "unauthenticated" // CodeForbidden denotes insufficient authority (403). CodeForbidden Code = "forbidden" // CodePeerRejected denotes a rejected socket peer (403). CodePeerRejected Code = "peer_rejected" // CodePasswordRequired denotes missing password confirmation (403). CodePasswordRequired Code = "password_required" // CodePasswordInvalid denotes invalid password confirmation (403). CodePasswordInvalid Code = "password_invalid" // CodeNotFound denotes an unknown entity (404). CodeNotFound Code = "not_found" // CodeDeleted denotes a mutation involving a tombstoned entity (409). CodeDeleted Code = "deleted" // CodeConflict denotes a state or invariant conflict (409). CodeConflict Code = "conflict" // CodeRevertConflict denotes conflicting changes that prevent revert (409). CodeRevertConflict Code = "revert_conflict" // CodeNotRevertible denotes an operation that cannot be reverted (409). CodeNotRevertible Code = "not_revertible" // CodePrecondition denotes a stale entity precondition (412). CodePrecondition Code = "precondition_failed" // CodeTooLarge denotes an oversized request body (413). CodeTooLarge Code = "body_too_large" // CodeUnsupportedMedia denotes an unsupported content type (415). CodeUnsupportedMedia Code = "unsupported_media_type" // CodeValidation denotes invalid field values (422). CodeValidation Code = "validation" // CodeIdemMismatch denotes a reused idempotency key with different input (422). CodeIdemMismatch Code = "idempotency_mismatch" // CodeNothingToUndo denotes an empty undo stack (409). CodeNothingToUndo Code = "nothing_to_undo" // CodeNothingToRedo denotes an empty redo stack (409). CodeNothingToRedo Code = "nothing_to_redo" // CodePreconditionReq denotes a missing precondition (428). CodePreconditionReq Code = "precondition_required" // CodeIdemRequired denotes a missing idempotency key (428). CodeIdemRequired Code = "idempotency_key_required" // CodeGenerationMismatch denotes a precondition for a different database generation (412). CodeGenerationMismatch Code = "generation_mismatch" // CodeRateLimited denotes a rate limit (429). CodeRateLimited Code = "rate_limited" // CodeInternal denotes an internal failure (500). CodeInternal Code = "internal" // CodeBusy denotes temporary unavailability (503). CodeBusy Code = "busy" )
func ErrorCodes ¶
func ErrorCodes() []Code
ErrorCodes returns every defined service error code. Adapter drift tests also check this catalog against the declarations so additions cannot be omitted.
type Cursor ¶
Cursor describes either a keyset position or an offset position. Lists validate their own key types, ranges, and pagination mode.
func DecodeCursor ¶
DecodeCursor parses one version-1 cursor with exact field names and preserves numbers in Keys as json.Number. Invalid input returns CodeMalformed.
type EntityKind ¶
type EntityKind string
EntityKind identifies the entity affected by an event.
const ( // EntTask denotes a task. EntTask EntityKind = "task" // EntTriage denotes a task triage reason. EntTriage EntityKind = "triage" // EntTaskTags denotes a task's tag set. EntTaskTags EntityKind = "task_tags" // EntEntry denotes a log entry. EntEntry EntityKind = "entry" // EntBlock denotes a time block. EntBlock EntityKind = "block" // EntFocus denotes the singleton focus row. EntFocus EntityKind = "focus" // EntInterruption denotes an interruption. EntInterruption EntityKind = "interruption" // EntToken denotes an authentication token. EntToken EntityKind = "token" // EntSetting denotes a setting. EntSetting EntityKind = "setting" // EntAuth denotes authentication configuration. EntAuth EntityKind = "auth" )
type EntityRef ¶
type EntityRef struct {
Entity EntityKind
ID int64
}
EntityRef identifies an entity by kind and ID.
type Error ¶
type Error struct {
Code Code
Detail string // safe for users; never contains secrets
Fields []FieldError
Conflicts []RevertConflict
Current any // current representation for a failed precondition
RetryAfter time.Duration
Err error // wrapped cause; logged, never sent
}
Error carries a service error's safe detail, structured context, and private cause.
func AsError ¶
AsError finds a wrapped domain error, or returns an internal error with err as its private cause and false.
func ValidationError ¶
func ValidationError(fields ...FieldError) *Error
ValidationError constructs a validation error with the supplied field failures.
type Event ¶
type Event struct {
ID EventID
OpID OpID
Entity EntityKind
EntityID int64 // task ID for triage/tags; 1 for focus; 0 for setting
TaskID sql.Null[TaskID] // denormalized for task history
Action Action
Before json.RawMessage // changed columns only; null for insert/add
After json.RawMessage // changed columns only; null for tombstone-less removes
Derived bool // recompute effects; revert re-derives them
}
Event records changed fields for an operation's effect on one entity.
type Expect ¶
type Expect struct {
Gen Generation
Version Version
}
Expect is the generation and row version required by an entity precondition.
type FieldError ¶
type FieldError struct{ Field, Message string }
FieldError identifies a field and its validation failure.
type Focus ¶
type Focus struct {
TaskID sql.Null[TaskID]
Date sql.Null[civil.Date]
SetAt sql.Null[time.Time]
Version Version
}
Focus is the singleton current-focus row.
type Generation ¶
type Generation string
Generation identifies a database generation with 16 lowercase hex characters.
func NewGeneration ¶
func NewGeneration() Generation
NewGeneration returns a cryptographically random database generation.
type Interruption ¶
type Interruption struct {
ID InterruptionID
At time.Time
Date civil.Date
FromTaskID sql.Null[TaskID]
FromBlockID sql.Null[BlockID]
ToTaskID TaskID
OpID OpID
DeletedAt sql.Null[time.Time]
}
Interruption records a switch of focus away from a task or block.
type LogEntry ¶
type LogEntry struct {
ID EntryID
TaskID sql.Null[TaskID]
Kind EntryKind
Title string
Notes string
WorkDate civil.Date
OccurredMin sql.Null[civil.Minute]
Reopened bool
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt sql.Null[time.Time]
PurgedAt sql.Null[time.Time]
Version Version
}
LogEntry records work or completion, optionally linked to a task.
type OpID ¶
type OpID [16]byte
OpID is a random operation identifier, stored as 32 lowercase hex characters.
func (OpID) MarshalText ¶
MarshalText encodes id as 32 lowercase hex characters.
func (*OpID) UnmarshalText ¶
UnmarshalText decodes exactly 32 lowercase hex characters.
type OpKind ¶
type OpKind string
OpKind names an operation as <area>.<verb>.
const ( // OpTaskAdd captures a task. OpTaskAdd OpKind = "task.add" // OpTaskUpdate updates task fields. OpTaskUpdate OpKind = "task.update" // OpTaskDue changes a task's due moment. OpTaskDue OpKind = "task.due" // OpTaskPlace places a task in the task order. OpTaskPlace OpKind = "task.place" // OpTaskAcceptNew acknowledges a new task. OpTaskAcceptNew OpKind = "task.accept_new" // OpTaskDefer changes a task's deferral. OpTaskDefer OpKind = "task.defer" // OpTaskManual requests manual triage. OpTaskManual OpKind = "task.manual" // OpTaskComplete completes a task. OpTaskComplete OpKind = "task.complete" // OpTaskReopen reopens a task. OpTaskReopen OpKind = "task.reopen" // OpTaskDrop drops a task. OpTaskDrop OpKind = "task.drop" // OpTaskDelete tombstones a task. OpTaskDelete OpKind = "task.delete" // OpTaskUndelete restores a tombstoned task. OpTaskUndelete OpKind = "task.undelete" // OpBlockCreate creates a time block. OpBlockCreate OpKind = "block.create" // OpBlockReblock reschedules a block. OpBlockReblock OpKind = "block.reblock" // OpBlockUnblock cancels a block. OpBlockUnblock OpKind = "block.unblock" // OpBlockOutcome changes a block's outcome policy. OpBlockOutcome OpKind = "block.outcome" // OpEntryAdd adds a log entry. OpEntryAdd OpKind = "entry.add" // OpEntryUpdate updates a log entry. OpEntryUpdate OpKind = "entry.update" // OpEntryRelink changes an entry's task link. OpEntryRelink OpKind = "entry.relink" // OpEntryDelete tombstones a log entry. OpEntryDelete OpKind = "entry.delete" // OpEntryUndelete restores a tombstoned log entry. OpEntryUndelete OpKind = "entry.undelete" // OpFocusSet changes the current focus. OpFocusSet OpKind = "focus.set" // OpRevert reverts an operation. OpRevert OpKind = "op.revert" // OpUndo undoes an operation on the actor's stack. OpUndo OpKind = "op.undo" // OpRedo redoes an operation on the actor's stack. OpRedo OpKind = "op.redo" // OpAIReview acknowledges AI changes. OpAIReview OpKind = "ai.review" // OpTokenCreate creates an authentication token. OpTokenCreate OpKind = "token.create" // OpTokenRevoke revokes an authentication token. OpTokenRevoke OpKind = "token.revoke" // OpSettingsUpdate updates settings. OpSettingsUpdate OpKind = "settings.update" // OpSettingsRetentionLowered records a retention reduction. OpSettingsRetentionLowered OpKind = "settings.retention_lowered" // OpAuthPassword changes the owner's password. OpAuthPassword OpKind = "auth.password" // OpPurgeTask purges task content. OpPurgeTask OpKind = "purge.task" // OpPurgeEntry purges entry content. OpPurgeEntry OpKind = "purge.entry" // OpSystemReconcile reconciles time-dependent state. OpSystemReconcile OpKind = "system.reconcile" // OpSystemLedgerReplay reapplies purge-ledger records. OpSystemLedgerReplay OpKind = "system.ledger_replay" // OpSystemImport records an import. OpSystemImport OpKind = "system.import" // OpSystemRestore records a restore. OpSystemRestore OpKind = "system.restore" )
func (OpKind) ReversalLabel ¶
ReversalLabel describes the net direction of the reversal chain given by via. opMark is the complete optional operation mark, including its CLI styling.
func (OpKind) ReversalText ¶
ReversalText describes a reversal of the root operation. A caller can omit the operation ID for a compact banner.
type OpRecord ¶
type OpRecord struct {
Seq OpSeq
ID OpID
Kind OpKind
Actor string // Actor.Key()
Channel Channel
At time.Time
Scopes Scopes // permissions required by this operation and its revert
Revertible bool
State OpState
RevertsOpID sql.Null[OpID] // set on revert, undo, and redo
Via string // empty, revert, undo, or redo
}
OpRecord is the persisted metadata for an operation.
type OutcomeSource ¶
type OutcomeSource string
OutcomeSource identifies how a resolved block outcome was selected.
const ( // OutcomeAuto denotes an automatically derived outcome. OutcomeAuto OutcomeSource = "auto" // OutcomeUser denotes a user-selected outcome. OutcomeUser OutcomeSource = "user" )
func (OutcomeSource) Valid ¶
func (s OutcomeSource) Valid() bool
Valid reports whether s is a declared outcome source.
type PlaceHow ¶
type PlaceHow string
PlaceHow selects how a task is positioned in the global order.
const ( // PlaceKeep retains the task's position. PlaceKeep PlaceHow = "keep" // PlaceTop places the task at the top. PlaceTop PlaceHow = "top" // PlaceBottom places the task at the bottom. PlaceBottom PlaceHow = "bottom" // PlaceBefore places the task before another task. PlaceBefore PlaceHow = "before" // PlaceAfter places the task after another task. PlaceAfter PlaceHow = "after" )
type RevertConflict ¶
type RevertConflict struct {
OpID OpID
Kind OpKind
Actor string
At time.Time
Entity EntityKind
EntityID int64
}
RevertConflict describes a later operation that conflicts with a revert.
type Scopes ¶
type Scopes uint8
Scopes is a bit set of permissions.
const ( // ScopeRead permits reading. ScopeRead Scopes = 1 << iota // ScopeCapture permits capturing tasks and entries. ScopeCapture Scopes = 1 << iota // ScopeWrite permits ordinary mutations. ScopeWrite Scopes = 1 << iota // ScopeDestroy permits destructive mutations. ScopeDestroy Scopes = 1 << iota // ScopeAdmin permits administration. ScopeAdmin Scopes = 1 << iota // AllScopes contains every declared permission. AllScopes Scopes = ScopeRead | ScopeCapture | ScopeWrite | ScopeDestroy | ScopeAdmin // MCPDefaultScopes contains the default permissions for MCP tokens. MCPDefaultScopes Scopes = ScopeRead | ScopeCapture | ScopeWrite )
func ParseScopes ¶
ParseScopes parses comma-separated permission names; an empty string means no permissions, as used by system operations.
type Task ¶
type Task struct {
ID TaskID
Title, Notes string
Status TaskStatus
Rank int64
LastPlacedAt sql.Null[time.Time]
LastPlacedSeq sql.Null[OpSeq] // ordering and acknowledgement use sequence numbers
DeferDate sql.Null[civil.Date]
DeferMin sql.Null[civil.Minute]
DueDate sql.Null[civil.Date]
DueMin sql.Null[civil.Minute]
DueAck DuePhase
DueAckDate sql.Null[civil.Date]
Project string // empty means none
Priority Priority
Origin string // creator's Actor.Key()
CompletedAt sql.Null[time.Time]
CompletedDate sql.Null[civil.Date]
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt sql.Null[time.Time]
PurgedAt sql.Null[time.Time] // set by ScrubEntities
Version Version
}
Task is the persisted state of a task.
type TaskDetail ¶
type TaskDetail struct {
TaskView
Entries []EntryView // non-deleted, newest first
Blocks []BlockView // all non-deleted
Interruptions []Interruption
}
TaskDetail adds associated live entries, blocks, and interruptions to a task view.
type TaskStatus ¶
type TaskStatus string
TaskStatus is the lifecycle state of a task.
const ( // StatusOpen marks an open task. StatusOpen TaskStatus = "open" // StatusDone marks a completed task. StatusDone TaskStatus = "done" // StatusDropped marks a dropped task. StatusDropped TaskStatus = "dropped" )
func (TaskStatus) Valid ¶
func (s TaskStatus) Valid() bool
Valid reports whether s is a declared task status.
type TaskView ¶
type TaskView struct {
Task
Reasons []TriageRow // highest first
Tags []string // sorted, case-insensitive
View View
Deferred bool // defer moment is after now
DuePhase DuePhase
DueSoon bool // due date is within the configured due-soon window
SlipsLifetime int
SlipsSinceTriage int
}
TaskView adds derived state and display metadata to a task.
type TimeBlock ¶
type TimeBlock struct {
ID BlockID
TaskID TaskID
Span BlockSpan
Status BlockStatus
OutcomeSource OutcomeSource // empty while planned or cancelled
CancelReason CancelReason // empty unless cancelled
Slipped bool
SlippedAt sql.Null[time.Time] // retained after unslip
SlippedSeq sql.Null[OpSeq] // operation that last slipped it
CreatedAt time.Time
ResolvedAt sql.Null[time.Time] // set on every status change; null while planned
ResolvedSeq sql.Null[OpSeq]
DeletedAt sql.Null[time.Time] // set only by reverting the creating operation
Version Version
}
TimeBlock is a scheduled task interval and its resolution state.
type Token ¶
type Token struct {
ID TokenID
Name string
SecretHash [32]byte
Scopes Scopes
IsOwner bool
MutationsPerHour int
CreatedAt time.Time
ExpiresAt sql.Null[time.Time]
LastUsedAt sql.Null[time.Time]
RevokedAt sql.Null[time.Time]
}
Token stores authentication token metadata and its secret hash.
type TriageReason ¶
type TriageReason string
TriageReason explains why a task needs triage.
const ( // ReasonSlipped marks a slipped task. ReasonSlipped TriageReason = "slipped" // ReasonOverdue marks an overdue task. ReasonOverdue TriageReason = "overdue" // ReasonDue marks a due task. ReasonDue TriageReason = "due" // ReasonContinue marks work to continue. ReasonContinue TriageReason = "continue" // ReasonSurfaced marks an elapsed deferral. ReasonSurfaced TriageReason = "surfaced" // ReasonReopened marks a reopened task. ReasonReopened TriageReason = "reopened" // ReasonManual marks an explicit triage request. ReasonManual TriageReason = "manual" // ReasonNew marks a newly captured task. ReasonNew TriageReason = "new" )
func (TriageReason) Rank ¶
func (r TriageReason) Rank() int
Rank returns the reason's priority (8 through 1), or zero for an unknown reason.
func (TriageReason) Valid ¶
func (r TriageReason) Valid() bool
Valid reports whether r is a declared triage reason.
type TriageRow ¶
type TriageRow struct {
TaskID TaskID
Reason TriageReason
Since time.Time // informational
Seq OpSeq // operation that added the reason; used for ordering
}
TriageRow records one reason a task needs triage.
type UserOutcome ¶
type UserOutcome string
UserOutcome is a requested block outcome policy.
const ( // SetWorked explicitly marks a block worked. SetWorked UserOutcome = "worked" // SetMissed explicitly marks a block missed. SetMissed UserOutcome = "missed" // SetAuto restores automatic outcome derivation. SetAuto UserOutcome = "auto" )
func (UserOutcome) Valid ¶
func (o UserOutcome) Valid() bool
Valid reports whether o is a declared user outcome.
type View ¶
type View string
View selects a task classification for a list.
const ( // ViewTriage selects tasks needing triage. ViewTriage View = "triage" // ViewBacklog selects backlog tasks. ViewBacklog View = "backlog" // ViewUpcoming selects deferred tasks. ViewUpcoming View = "upcoming" // ViewDone selects completed tasks. ViewDone View = "done" // ViewDropped selects dropped tasks. ViewDropped View = "dropped" // ViewDeleted selects deleted tasks. ViewDeleted View = "deleted" // ViewAll selects all tasks. ViewAll View = "all" )