application

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 14 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 application is the persistence-neutral facade shared by the CLI, the TUI, and the HTTP API — the Go counterpart of lib/tasks/application.rb and the operation objects it composes.

It accepts typed Go inputs and returns typed results. Adapter concerns — argv, terminal rendering, HTTP status mapping — deliberately stay outside it, and so does everything the store owns: validation, transactions, rollback, eligibility, the claim compare-and-set. What lives here is COMPOSITION: the operation objects, argument normalization, the creation defaults that belong to the runtime rather than to persistence, the WAITING default behind a human delegation, the blocker note behind a release, and the project commands that run several store calls and must report one outcome.

The rule that keeps the boundary honest: if a behavior can be expressed as a rule about the FILE, it belongs to the store. If it can only be expressed as a rule about two store calls, or about what a caller asked for, it belongs here.

Index

Constants

View Source
const DefaultUrgentDays = 3

DefaultUrgentDays is Quadrants::DEFAULT_URGENT_DAYS, passed through so a caller that does not care can supply 0.

View Source
const FieldBody = store.FieldBody

FieldBody is the body patch the release-note composition needs.

View Source
const NoteEncodingError = "release note is not valid UTF-8 text"

NoteEncodingError is the typed refusal for note bytes this process cannot even trim.

The blocker note is the whole point of a blocked agent's escape hatch, and it is appended AFTER the release has already been written. So unusable text has to degrade to a "not applied" the caller already handles, never to a panic on top of a completed, half-composed write.

Variables

View Source
var NamedViews = []string{"agenda", "next", "quadrants", "inbox"}

NamedViews is TaskQueries::NAMED_VIEWS.

Functions

func PatchFieldSupported

func PatchFieldSupported(target Store, field store.PatchField) bool

PatchFieldSupported reports whether a store can patch a field at all.

Asking BEFORE the transaction is what keeps an unimplemented field from falling through the store's switch and returning a status no vocabulary contains — a failure that would reach the user as an empty error.

Types

type Application

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

Application is the facade. It holds only immutable construction settings; a mutable store is built per operation and never retained.

func New

func New(options Options) (*Application, error)

New validates the options and builds an application.

func NewWithStore

func NewWithStore(built func() *store.Store, context func() temporal.Context) (*Application, error)

NewWithStore is the convenience for the common case: one live/archive pair, one clock, no injected seams.

func (*Application) ApproveTask

func (a *Application) ApproveTask(id, expectedRevision string, operation *OperationContext) Outcome

ApproveTask accepts a proposal.

func (*Application) ArchivePreview

func (a *Application) ArchivePreview(operation *OperationContext) (store.ArchivePreview, bool)

ArchivePreview is what a sweep would move right now.

func (*Application) ArchiveProject

func (a *Application) ArchiveProject(id string, operation *OperationContext) Outcome

ArchiveProject sweeps a project's subtree into the archive and reports the moved stable ids. Undecided proposals block the sweep: a proposal archived without a decision is a decision nobody made.

func (*Application) ArchiveSweep

func (a *Application) ArchiveSweep(expected *store.ArchivePreview,
	operation *OperationContext) (ArchiveOutcome, bool)

ArchiveSweep moves every fully closed subtree to the archive file, pinned to the preview the caller showed the user.

func (*Application) Baseline

func (a *Application) Baseline(id string, field store.PatchField) (string, bool)

Baseline is the value a caller reads before proposing a patch, and false when the task or the field has none.

It is exported because the conflict check is only meaningful when the SAME expression produces the value on both sides of the decision.

func (*Application) ClaimTask

func (a *Application) ClaimTask(command DelegationCommand, operation *OperationContext) Outcome

ClaimTask is the atomic pickup. A lost race is a conflict naming the winning holder and its timestamp; a win carries the full canonical task, so a worker claims and reads its authority in one step.

func (*Application) CompleteProject

func (a *Application) CompleteProject(id string, operation *OperationContext) Outcome

CompleteProject closes a project's open tasks and reports how many.

Zero closed is a CLEAN result for a project that was already fully closed — and the same zero the store returns after a rollback. Only the latter records a rollback, so asking for one is what keeps a reverted write from masquerading as a no-op success, with its stage intact so a failed write is not reported as a validation failure.

func (*Application) CreateProject

func (a *Application) CreateProject(title string, operation *OperationContext) Outcome

CreateProject creates a new empty project: a section under the top-level "Projects" root.

When no root exists yet — an empty or rootless store — it is created first, top-level and appended at the end, then the project beneath it, so an agent is never stranded. A blank title is refused, and so is a title that duplicates an existing project or area: those names are the project-ref candidate set, so a duplicate would make later refs ambiguous.

func (*Application) CreateTask

func (a *Application) CreateTask(command CreateCommand, operation *OperationContext) Outcome

CreateTask creates one live task in one checked store transaction.

func (*Application) DecideProposal

func (a *Application) DecideProposal(decision ProposalDecision, operation *OperationContext) Outcome

DecideProposal is the typed decision seam both verbs share.

A malformed decision is a REFUSAL rather than a panic. Ruby raises ArgumentError from the command constructor and the application rescues it into an :invalid result; the rescue is the behavior that matters, so this build simply never raises.

func (*Application) DelegateTask

func (a *Application) DelegateTask(command DelegationCommand, operation *OperationContext) Outcome

DelegateTask hands a task to a person (kind "human" plus an email assignee) or to the agent pool (kind "agent" plus refine/research/implement).

A human delegation moves the task to WAITING — the next action is genuinely outside the owner's control, which is what WAITING means — unless KeepState opts out.

func (*Application) DeleteTask

func (a *Application) DeleteTask(command DeleteCommand, _ *OperationContext) Outcome

DeleteTask is the undoable hard delete of one live task.

A task with descendants is refused unless Cascade is set. ExpectedRevision is optional — empty skips the concurrency check, which is the CLI convenience, and a supplied value guards the whole subtree.

func (*Application) GetProject

func (a *Application) GetProject(id string, operation *OperationContext) (taskquery.ProjectView, bool, error)

GetProject is one project or area section, and false when the id is neither.

func (*Application) GetTask

func (a *Application) GetTask(id string, includeArchive bool, operation *OperationContext) (store.Item, bool, error)

GetTask resolves a STABLE ID. Fuzzy title and L<line> resolution are CLI-only conveniences and deliberately absent: a missing id is an ordinary "not found" so a transport maps it to its own response rather than to an error.

func (*Application) GetTaskResult

func (a *Application) GetTaskResult(id string, source store.Source, operation *OperationContext) ReadResult[store.Item]

GetTaskResult is the exact-source resource read.

func (*Application) HistoryStep

func (a *Application) HistoryStep(delta int) (store.HistoryOutcome, string, bool)

HistoryStep applies one undo (-1) or redo (+1).

func (*Application) HostContext

func (a *Application) HostContext() string

HostContext is the configured machine context, or "" when there is none.

func (*Application) ListProjects

func (a *Application) ListProjects(operation *OperationContext) ([]taskquery.ProjectView, error)

ListProjects is projects and areas rolled up over their open tasks. It lives here so the CLI and a transport share one definition of what a project is and how the list is ordered.

func (*Application) ListProjectsResult

func (a *Application) ListProjectsResult(operation *OperationContext) ReadResult[[]taskquery.ProjectView]

ListProjectsResult is ListProjects with the change token.

func (*Application) ListSections

func (a *Application) ListSections(operation *OperationContext) ([]record.Record, error)

ListSections is every live section record, in file order.

func (*Application) ListSectionsResult

func (a *Application) ListSectionsResult(operation *OperationContext) ReadResult[[]record.Record]

ListSectionsResult is ListSections with the change token.

func (*Application) ListTasks

func (a *Application) ListTasks(filter query.Filter, operation *OperationContext) ([]store.Item, error)

ListTasks answers a parsed filter. The archive half is captured exactly when the filter's scope reaches it, so an ordinary read never pays for it.

func (*Application) ListTasksResult

func (a *Application) ListTasksResult(filter query.Filter, operation *OperationContext) ReadResult[[]store.Item]

ListTasksResult is ListTasks with the change token. An empty list is `ok`, not `not_found`: the question had an answer.

func (*Application) MoveTask

func (a *Application) MoveTask(id string, placement store.Placement, label string,
	operation *OperationContext) (Outcome, bool)

MoveTask relocates one subtree, guarded by the revision the caller read.

func (*Application) PatchTask

func (a *Application) PatchTask(patch Patch, operation *OperationContext) Outcome

PatchTask applies one field-owned semantic change.

func (*Application) PrepareCreateTask

func (a *Application) PrepareCreateTask(command CreateCommand) CreateCommand

PrepareCreateTask applies the creation defaults that belong to the application RUNTIME rather than to persistence — today, only the host context. The store receives a complete command and stays unaware of hostnames and configuration.

It is exported for the same reason Ruby exports it: the CLI's dry-run path must use the SAME preparation a real create uses, so its preview cannot disagree with what the store would persist.

func (*Application) ProjectResult

func (a *Application) ProjectResult(id string, operation *OperationContext) ReadResult[taskquery.ProjectView]

ProjectResult is GetProject with the change token, mapped to not_found when the id is not a project or area.

func (*Application) Queries

func (a *Application) Queries(includeArchive bool, operation *OperationContext) (*taskquery.Queries, error)

Queries builds a read model over ONE fresh snapshot. Every read method here goes through it, so no application read can mix fields from two reads.

func (*Application) ReadStatusResult

func (a *Application) ReadStatusResult(operation *OperationContext) ReadResult[struct{}]

ReadStatusResult is the safe foundation for /meta and readiness: store health and its change token, and nothing a transport would have to be told about.

func (*Application) ReadTasks

func (a *Application) ReadTasks(operation *OperationContext) (*ReadModel, error)

ReadTasks captures one live read. It deliberately gets a fresh store like every other application read, so a long-lived presenter cannot retain anything the next read would have to invalidate.

func (*Application) RejectTask

func (a *Application) RejectTask(id, expectedRevision string, notes []string, operation *OperationContext) Outcome

RejectTask declines a proposal into CANCELLED. Notes append withdrawal rationale to the body in the same write — the application-level mirror of the repeatable CLI `reject --note`.

func (*Application) ReleaseTask

func (a *Application) ReleaseTask(command DelegationCommand, operation *OperationContext) Outcome

ReleaseTask hands a claim back to the agent-ready queue. A worker must supply the id matching the live claim; the owner passes Force to clear a stale one. A Note appends a blocker line to the body in the same undo step.

func (*Application) RenameProject

func (a *Application) RenameProject(id, title string, _ *OperationContext) Outcome

RenameProject renames a project or area section. A blank title is invalid; a missing section is not_found.

func (*Application) SetWorkRef

func (a *Application) SetWorkRef(command DelegationCommand, operation *OperationContext) Outcome

SetWorkRef records where the work lives. One reference: setting overwrites, and an empty ref (or "off"/"none") clears it. The owner may always write it; a worker only while its claim matches.

func (*Application) TaskResultFromMutation

func (a *Application) TaskResultFromMutation(outcome Outcome, id string, operation *OperationContext) (ReadResult[store.Item], error)

TaskResultFromMutation rebuilds a canonical resource from the immutable post-mutation snapshot a write produced.

This is what keeps a response and its global revision tied to the exact write instead of racing a second read after the lock is released.

func (*Application) UndelegateTask

func (a *Application) UndelegateTask(command DelegationCommand, operation *OperationContext) Outcome

UndelegateTask clears the marker, revoking any live claim. Lifecycle state is untouched: undelegating does not automatically leave WAITING, the owner decides when to.

func (*Application) UpdateTask

func (a *Application) UpdateTask(id string, changes []store.Change, label string,
	operation *OperationContext) (Outcome, bool)

UpdateTask applies several field changes to one task ATOMICALLY, guarded by the revision the caller read.

Atomicity is the point, not a convenience. `z now` clears the hold AND the available-from date; landing those as two patches would leave an observable intermediate state where the task is released but still dated, and would cost the user two undos for one keystroke.

func (*Application) ViewTasks

func (a *Application) ViewTasks(name string, operation *OperationContext) ([]store.Item, error)

ViewTasks answers one named selection. The names live here rather than in each adapter so a CLI, an HTTP handler, and the TUI cannot each invent their own idea of what "next" means.

type ArchiveOutcome

type ArchiveOutcome struct {
	store.ArchiveResult
	RollbackReason string
	RollbackStage  store.RollbackStage
}

ArchiveOutcome is a sweep plus the rollback record a failed one leaves.

type ArchiveSweeper

type ArchiveSweeper interface {
	ArchivePreviewFor(today string) store.ArchivePreview
	ArchiveSweep(today string, expected *store.ArchivePreview) store.ArchiveResult
}

ArchiveSweeper is the list-wide archive: preview what a sweep would move, then move it, pinned to the preview the user was shown.

The pin is the whole safety property. A user reads "would move 3 roots and 7 descendants", walks away, comes back, and presses y — and by then the list may have changed. Passing the preview back means the store refuses rather than archiving a set the user never saw.

type CoalescingPatcher

type CoalescingPatcher interface {
	PatchTaskCoalesced(id string, field store.PatchField, value, expected, label, today, coalesceKey string) store.MutationResult
}

CoalescingPatcher is a patch that carries a journal coalesce key.

This is the single most load-bearing gap. Every composed application operation — the WAITING default behind a human delegation, the blocker note behind a release — is a SECOND write that must land in the SAME undo step as the first. Ruby does that with `coalesce_key:`; without it here, one user action costs two undos.

type CreateCommand

type CreateCommand struct {
	Title      string
	Priority   string
	Tags       []string
	Deferred   bool
	Scheduled  string
	Deadline   string
	State      string
	Project    string
	ParentID   string
	Recurrence string
	Lead       string
	Body       string
	Notes      []string

	// ScheduledValue and DeadlineValue carry a COMPLETE temporal value — the
	// date, the local time, its zone and its fold — for a caller that has
	// already parsed one.
	//
	// `Scheduled` and `Deadline` above stay the primary spelling, because a
	// transport supplies text and turning text into a value is this layer's job.
	// What they cannot express is a time of DAY: `createTemporalValues` builds
	// `temporal.Value{Date: date}` from them and there is nowhere to put 17:00,
	// Europe/London, or a fold. So an HTTP client asking for a 17:00 deadline
	// used to get an all-day one, and the API had to refuse the request outright
	// rather than store a value the client did not ask for.
	//
	// These are optional and pointer-typed so absent stays distinguishable from
	// "the zero value", and when one is set it WINS over the string for its
	// field: it is strictly more information about the same thing. The pointee is
	// copied when the command is accepted, so a caller that reuses its value
	// cannot change what was submitted.
	ScheduledValue *temporal.Value
	DeadlineValue  *temporal.Value

	// SkipHostContext opts out of the configured host context. Ruby spells this
	// `apply_host_context: true`, whose default is the interesting value; the
	// polarity is flipped here so the ZERO VALUE is the default behavior and a
	// caller building a command with a struct literal gets the host context
	// without having to know it must ask for it.
	SkipHostContext bool
}

CreateCommand is one immutable, transport-neutral request to create a live task — lib/tasks/create_task.rb.

`Body` and `Notes` are the two spellings of the initial note: one string with embedded newlines, or an ordered list. Supplying both is refused, so the persisted order is never implicit.

type DelegationAction

type DelegationAction string

DelegationAction is the closed five-verb vocabulary — DelegationCommand::ACTIONS.

const (
	ActionDelegate   DelegationAction = "delegate"
	ActionUndelegate DelegationAction = "undelegate"
	ActionClaim      DelegationAction = "claim"
	ActionRelease    DelegationAction = "release"
	ActionWorkRef    DelegationAction = "work_ref"
)

The five delegation verbs.

type DelegationCommand

type DelegationCommand struct {
	ID     string
	Action DelegationAction

	Kind     string
	Mode     string
	Assignee string
	Worker   string

	// WorkRef is the reference to record. An empty string CLEARS it — that is
	// the same instruction Ruby spells as nil, `off`, or `none`, and the two
	// clear words normalize to it. There is deliberately no way to set a work
	// ref to the empty string: the store refuses a blank reference anyway, so
	// the only meaning "" could carry is the one it has here.
	WorkRef string

	Note      string
	KeepState bool
	Force     bool

	ExpectedRevision string
}

DelegationCommand is one immutable delegation intent — lib/tasks/delegation_command.rb.

KeepState and Note are the two composition flags, and they are the reason this object belongs to the application rather than to the store: a human delegation moves the task to WAITING unless the owner keeps the state, and a release may carry a blocker note appended in the same undo step. Both compose two writes; everything else here the store owns.

func (DelegationCommand) Agent

func (c DelegationCommand) Agent() bool

Agent reports a delegation to the agent pool.

func (DelegationCommand) ClearsWorkRef

func (c DelegationCommand) ClearsWorkRef() bool

ClearsWorkRef reports the clearing form of the work_ref verb.

func (DelegationCommand) Human

func (c DelegationCommand) Human() bool

Human reports a delegation to a named person.

type DelegationSummary

type DelegationSummary struct {
	// Action is the verb performed, and TaskID the stable id it touched. Both
	// are always set, including on a refusal.
	Action DelegationAction
	TaskID string

	// Previous is the delegation marker as it stood BEFORE the write, and nil
	// when the task carried none.
	Previous map[string]string
	// Delegation is the marker after the write, and nil when it was cleared.
	Delegation map[string]string

	// Task is the canonical post-write task, and nil only when the task
	// vanished under a concurrent write. State is its lifecycle state.
	Task  *store.Item
	State string

	// StateChanged reports that this operation moved the task to (or out of)
	// WAITING as the composed half of a delegation.
	StateChanged bool

	// NoteRequested reports that a release carried a blocker note at all;
	// NoteApplied whether that note was appended. The pair is Ruby's
	// conditionally-present `note_applied` key made explicit: a false
	// NoteApplied means something different when no note was asked for.
	NoteRequested bool
	NoteApplied   bool

	// Holder and At describe the claim that BLOCKED this operation. They are
	// the whole content of a conflict.
	Holder string
	At     string
}

DelegationSummary is the composed outcome of one delegation verb, rich enough that a CLI, HTTP, or TUI adapter TRANSLATES rather than re-derives.

type DeleteCommand

type DeleteCommand struct {
	ID               string
	Cascade          bool
	ExpectedRevision string
	HistoryLabel     string
}

DeleteCommand is one immutable request to hard-delete a live task — lib/tasks/delete_task.rb.

ExpectedRevision is an opaque store-produced value: nil-equivalent ("") skips the optimistic-concurrency check, which is the CLI convenience, while a supplied value guards the whole subtree. Cascade opts into removing a task that still has descendants; deleting never reparents children.

type Deleter

type Deleter interface {
	DeleteTask(id string, cascade bool, expectedRevision, historyLabel string) store.MutationResult
}

Deleter is the undoable hard delete of one live task.

type FieldPatcher

type FieldPatcher interface {
	PatchesField(field store.PatchField) bool
}

FieldPatcher is a store that publishes its own patchable field set. A store that implements it is believed over the default above, which is what lets the vocabulary widen from the side that owns it — as *store.Store now does, across all fourteen fields it patches.

type HistoryStepper

type HistoryStepper interface {
	HistoryStep(delta int) (store.HistoryOutcome, string)
}

HistoryStepper is undo and redo over the journal.

type OperationContext

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

OperationContext is immutable metadata identifying where an operation came from — lib/tasks/operation_context.rb — plus the temporal context that operation reads its clock from.

Passing one is optional at every entry point: a nil *OperationContext is the "no context supplied" case Ruby spells as `context: nil`. What Ruby cannot express and this can is that an invalid context is refused at CONSTRUCTION rather than at every call site, so no application method needs a validate_operation_context of its own.

func NewOperationContext

func NewOperationContext(operationID string, source OperationSource, actor string) (*OperationContext, error)

NewOperationContext validates and builds a context. The operation id is required and the source must be one of cli/tui/api.

func (*OperationContext) Actor

func (c *OperationContext) Actor() string

Actor is the optional acting identity.

func (*OperationContext) OperationID

func (c *OperationContext) OperationID() string

OperationID is the caller-supplied correlation id.

func (*OperationContext) Source

func (c *OperationContext) Source() OperationSource

Source is the originating surface.

func (*OperationContext) TemporalContext

func (c *OperationContext) TemporalContext() (temporal.Context, bool)

TemporalContext is the pinned clock, and false when this context carries none.

func (*OperationContext) WithTemporalContext

func (c *OperationContext) WithTemporalContext(context temporal.Context) *OperationContext

WithTemporalContext returns a copy that pins the clock this operation reads.

type OperationSource

type OperationSource string

OperationSource names where a domain operation originated.

const (
	SourceCLI OperationSource = "cli"
	SourceTUI OperationSource = "tui"
	SourceAPI OperationSource = "api"
)

The three surfaces.

type Options

type Options struct {
	// Factory is required.
	Factory StoreFactory

	// TemporalContext is the clock every operation reads. nil means "now, UTC",
	// which is the same default Ruby falls back to when no factory is injected.
	TemporalContext func() temporal.Context

	// HostContext is the machine's own @context, applied to a capture unless
	// the command opts out. It must be an @-prefixed word or empty.
	HostContext string

	// DelegationKeySource mints the per-operation journal coalescing token.
	// It is injectable for exactly the reason the store's IDSource is: the
	// token is persisted into journal bytes, so an unpinnable one makes two
	// identical runs produce different journals.
	DelegationKeySource func() string

	// QueryOptions are passed to every taskquery built here — the link
	// shorthand and system configuration a read surface needs.
	QueryOptions []taskquery.Option
}

Options is the immutable construction settings of one application.

type Outcome

type Outcome struct {
	store.MutationResult

	// Delegation is the rich per-operation summary of a delegation verb, or nil
	// for every other operation.
	Delegation *DelegationSummary

	// Project is the count a project lifecycle command reports, or nil.
	Project *ProjectSummary
}

Outcome is the application-level result of a mutation.

It embeds the store's MutationResult unchanged — status, errors, touched ids, the post-write snapshot, the global revision, and the rollback record all keep one vocabulary across the whole system — and adds only what the application itself composed.

Ruby merges the composed facts into MutationResult's untyped `summary` Hash. That is not available here: the store's Summary is a typed struct this package does not own and must not widen. Naming the composed half separately is also the more honest shape — Delegation is present exactly when a delegation verb produced it.

func (Outcome) Conflict

func (o Outcome) Conflict() bool

func (Outcome) Invalid

func (o Outcome) Invalid() bool

func (Outcome) NoChange

func (o Outcome) NoChange() bool

The refusal predicates an adapter branches on. The store publishes OK, Changed, ExitCode and FirstError; these are the remaining members of the same vocabulary, named here so no surface has to compare status strings.

func (Outcome) NotFound

func (o Outcome) NotFound() bool

func (Outcome) RolledBackValidation

func (o Outcome) RolledBackValidation() bool

RolledBackValidation reports the write that LANDED and was refused by the post-write check. `check` is the actionable next step only in this case.

func (Outcome) RolledBackWrite

func (o Outcome) RolledBackWrite() bool

func (Outcome) Stale

func (o Outcome) Stale() bool

type Patch

type Patch struct {
	ID       string
	Field    store.PatchField
	Value    string
	Expected string
	// HistoryLabel names the undo step. Empty means the store's default.
	HistoryLabel string
	// CoalesceKey merges this write into a neighbouring journal entry — the
	// editor-session behavior, where a burst of field saves is one undo step.
	CoalesceKey string
	// Typed carries the value's REAL shape for the fields a string cannot
	// express: `deferred` (a bool) and `contexts`/`tags` (ordered lists).
	//
	// When it is set, Value is ignored. Both spellings exist because the CLI
	// and the API only ever send text, and making them construct a typed value
	// would be ceremony; the editor genuinely cannot.
	Typed *store.PatchValue
}

Patch is one single-field command — the Go shape of lib/tasks/task_patch.rb.

A single-field command keeps the field-owned expectation while sharing the store transaction a whole-task changeset uses. That is what lets an editor save one field without turning an unrelated concurrent edit into a whole-task conflict.

Expected is the baseline the caller read before deciding. Ruby carries it inside an EditSnapshot that also holds every other field and the task's revision; here it is the one value the conflict check actually compares, which is also the only value the store publishes for the purpose.

func TypedPatch

func TypedPatch(id string, field store.PatchField, value store.PatchValue,
	expected, label, coalesceKey string) Patch

TypedPatch builds a patch carrying a value shape a string cannot express.

type Placement

type Placement struct {
	ParentID string
	BeforeID string
}

Placement is an immutable structural destination for one task subtree — lib/tasks/task_placement.rb. The store resolves these stable ids under its mutation lock; an adapter must not translate them into record indexes. An empty BeforeID means append as the destination parent's last child.

func (Placement) Appends

func (p Placement) Appends() bool

Appends reports the append form: no anchor, so the subtree lands last.

type Placer

type Placer interface {
	ApplyChangeset(changeset store.Changeset) store.MutationResult
	TaskRevision(id string) (string, bool)
}

Placer is a whole-task atomic changeset plus the revision that guards it.

Ordering needs both: a move is a `location` change guarded by the revision the caller read, so a task that changed underneath refuses instead of landing somewhere the user did not choose.

type ProjectSummary

type ProjectSummary struct {
	Closed   int
	Archived int
}

ProjectSummary is what a project lifecycle command counted: the tasks a completion closed, or the records an archive sweep moved.

type ProjectWriter

type ProjectWriter interface {
	CreateProject(title string) store.MutationResult
	RenameSection(id, title string) (touched string, found bool)
	CompleteProject(id, today string) (closed int, found bool)
	ArchiveProject(id, today string) (moved []string, proposedDescendants bool, found bool)
	LastRollback() (reason string, stage store.RollbackStage)
}

ProjectWriter is the four project lifecycle operations.

They are the only store calls in the whole application layer that report failure through a bare boolean or count rather than a MutationResult, which is why LastRollback exists: for these, the store's recorded rollback is the ONLY evidence that a mutation wrote and reverted.

type ProposalAction

type ProposalAction string

ProposalAction is the closed approve/reject vocabulary.

const (
	ProposalApprove ProposalAction = "approve"
	ProposalReject  ProposalAction = "reject"
)

The two decisions.

type ProposalDecider

type ProposalDecider interface {
	DecideProposal(id, action string, notes []string, expectedRevision, today string) store.MutationResult
}

ProposalDecider approves or declines one proposal.

type ProposalDecision

type ProposalDecision struct {
	ID               string
	Action           ProposalAction
	ExpectedRevision string
	Notes            []string
}

ProposalDecision is one immutable intent to accept or decline a proposal — lib/tasks/proposal_decision.rb. Notes are only meaningful on reject, where they are withdrawal rationale appended to the body in the same write.

type ReadModel

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

ReadModel is ONE coherent live read for presentation adapters — the Go counterpart of Tasks::TaskReadModel.

It is not a store wrapper. It is built from a single snapshot and exposes no store and no persistence operation, so a TUI that holds one across a paint cannot accidentally write through it or re-read half of it.

func (*ReadModel) FieldBaselines

func (m *ReadModel) FieldBaselines(id string, fields []store.PatchField) (map[store.PatchField]string, bool)

FieldBaselines exposes field expectations from the same coherent snapshot that supplied Items and Queries.

func (*ReadModel) Items

func (m *ReadModel) Items() []store.Item

Items is the live tasks this model was built over, in file order.

func (*ReadModel) NodeFor

func (m *ReadModel) NodeFor(item store.Item) *taskquery.Node

NodeFor is where an item sits in the structural tree.

func (*ReadModel) Queries

func (m *ReadModel) Queries() *taskquery.Queries

Queries is the read model over the same snapshot, for every derived answer — availability, links, the tree, body lines.

func (*ReadModel) Sections

func (m *ReadModel) Sections() []record.Record

Sections is every live section record, in file order.

func (*ReadModel) Snapshot

func (m *ReadModel) Snapshot() *store.Snapshot

Snapshot is the exact read behind every answer this model gives.

func (*ReadModel) Stale

func (m *ReadModel) Stale() bool

Stale reports that the live file no longer matches the snapshot this model was built from.

A long-lived presenter must gate refreshes on THIS rather than on a mutating store's own change detection: any read that lets a store self-reload consumes its change signal, and a model kept until the next tick would then stay stale forever.

func (*ReadModel) TaskFor

func (m *ReadModel) TaskFor(id string) (store.Item, bool)

TaskFor is the canonical task for a stable id.

func (*ReadModel) ViewTasks

func (m *ReadModel) ViewTasks(name string) ([]store.Item, error)

ViewTasks answers a named selection from the SAME snapshot, so a multi-view adapter never parses a second read to render one screen.

type ReadResult

type ReadResult[T any] struct {
	Status        ReadStatus
	Data          T
	StoreRevision string
	Errors        []store.Entry
	Warnings      []store.Entry
}

ReadResult is the immutable outcome of a coherent application read — lib/tasks/application_read_result.rb.

Ruby's version carries an untyped `data` and deep-freezes it. This one is generic instead: the immutability Ruby buys with freeze is bought here by the data being a value the caller owns a copy of, and what is gained is that a caller reading `result.Data.Title` is checked by the compiler rather than by a test.

func (ReadResult[T]) NotFound

func (r ReadResult[T]) NotFound() bool

NotFound reports a well-formed read whose subject does not exist.

func (ReadResult[T]) OK

func (r ReadResult[T]) OK() bool

OK reports a read that produced data.

func (ReadResult[T]) StoreInvalid

func (r ReadResult[T]) StoreInvalid() bool

StoreInvalid reports bytes that parsed but failed validation.

func (ReadResult[T]) Unavailable

func (r ReadResult[T]) Unavailable() bool

Unavailable reports a store that could not be read at all.

func (ReadResult[T]) UnsupportedSchema

func (r ReadResult[T]) UnsupportedSchema() bool

UnsupportedSchema reports a store this build must not interpret.

type ReadStatus

type ReadStatus string

ReadStatus is ApplicationReadResult::STATUSES.

const (
	ReadOK                ReadStatus = "ok"
	ReadNotFound          ReadStatus = "not_found"
	ReadUnsupportedSchema ReadStatus = "unsupported_schema"
	ReadStoreInvalid      ReadStatus = "store_invalid"
	ReadUnavailable       ReadStatus = "unavailable"
)

The read vocabulary. An HTTP adapter maps these to 200/404/503 without ever receiving a store, a path, or a second change-token read.

type Releaser

type Releaser interface {
	Release(id, worker string, force bool, coalesceKey string) store.MutationResult
}

Releaser hands a claim back to the agent-ready queue.

type Store

type Store interface {
	// Org and Archive are the resolved paths. The application needs Org to
	// answer ReadModel.Stale, which is a question about the file rather than
	// about any snapshot.
	Org() string
	Archive() string

	ReadSnapshot(includeArchive bool) (*store.Snapshot, error)
	CheckedReadSnapshot() (store.CheckedRead, error)

	CreateTask(command store.CreateCommand, today string) store.MutationResult
	PatchTask(id string, field store.PatchField, value, expected, label, today string) store.MutationResult
	ExpectedFor(id string, field store.PatchField) (string, bool)

	Delegate(id, kind, mode, assignee, coalesceKey string) store.MutationResult
	Claim(id, worker, coalesceKey string) store.MutationResult
}

Store is the persistence seam every application operation runs through.

It is deliberately an interface owned by THIS package rather than a concrete *store.Store. The application layer composes store operations; it must never re-implement the store's validation, transaction, or rollback rules, and an interface it declares is the cheapest way to keep that honest — anything the application could only do by reaching past this interface is, by construction, store work.

The method set here is what `*store.Store` implements TODAY. Capabilities the store is still growing are declared below as small optional interfaces the application type-asserts for, so a store that gains one is picked up without a change here, and a store that lacks one produces an explicit typed refusal rather than a silently different behavior.

type StoreFactory

type StoreFactory func() Store

StoreFactory builds a FRESH store for every application operation.

Ruby's StoreFactory exists because Store keeps read caches for interactive clients, so one long-lived instance in an HTTP or CLI application object would let request-local reads leak into later calls. The Go store has no such cache today, and the factory is kept anyway for two reasons that outlive that: an operation that gets its own store cannot be handed a stale one by a neighbour, and a future concurrent API surface gets per-request isolation by construction rather than by review.

type TypedPatcher

type TypedPatcher interface {
	Patch(request store.PatchRequest) store.MutationResult
}

TypedPatcher applies a patch whose value is not a string.

The string spelling `Store.PatchTask` takes covers every field whose value IS a string, with "" meaning nil for the clearable ones. It cannot express the three shapes the task editor needs: `deferred` is a bool, and `contexts` and `tags` are ordered lists. Sending those as text reaches the store's own refusal ("contexts must be a list of tags") about a value the user never typed — so the editor either has to refuse the field, which is half-work, or the application layer has to carry the value's real shape.

This is the narrow way to carry it: `store.PatchRequest` is the store's OWN typed entry point and already exists, so no store file changes and no existing string caller moves. A store that lacks the method produces a typed refusal rather than a silently different behavior, exactly like every other optional capability here.

type Undelegator

type Undelegator interface {
	Undelegate(id, coalesceKey string) store.MutationResult
}

Undelegator clears a delegation marker, revoking any live claim.

type WorkRefWriter

type WorkRefWriter interface {
	SetWorkRef(id, workRef, worker, coalesceKey string) store.MutationResult
}

WorkRefWriter records (or, with an empty ref, clears) where the work lives.

Jump to

Keyboard shortcuts

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