tasks

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

doctor.go — whole-board integrity checking and repair.

Doctor scans every task file and reports problems the normal per-command paths only warn about (or cannot see at all): unparseable files, duplicate ids (e.g. after a git merge of two branches that each created the same id), filename↔frontmatter id drift, dangling depends_on references, dependency cycles, and CRLF line endings. With fix enabled it repairs what is safe to repair mechanically.

frontmatter.go — task-file parsing and serialisation.

Task files are YAML frontmatter ("---" fenced) followed by a free-form Markdown body. Parsing works on yaml.Node so that unknown frontmatter keys (and their order) survive a read-modify-write cycle untouched — North only overlays the keys it owns. CRLF line endings are tolerated on read; files are always written with LF.

snapshot.go — tolerant whole-board loading.

A Snapshot parses every task file on the board exactly once. Files that fail to parse (or carry a duplicate id) become Warnings instead of aborting the load, so one bad file can never take down list/board/TUI. All read paths — listing, lookups, counts, dependents — derive from a Snapshot; mutations still operate per-file.

Package tasks holds task operations over the board: create, read, list, edit, status changes, state changes (draft/active/archive), delete.

Every task is one Markdown file. North uses two orthogonal axes: the task's state is the folder it lives in (drafts/ tasks/ archive/), and its status is a frontmatter key (ready/in_progress/blocked/done/failed). Both axes are freeform — any value can move to any other in one step, in any state. Each mutation optionally makes a local git commit when auto_commit is set.

Index

Constants

This section is empty.

Variables

SortKeys lists every ordering in display order.

Functions

func Cleanup

func Cleanup(boardDir string, olderThanDays int) ([]*models.Task, error)

Cleanup archives active done tasks (optionally only those older than N days). olderThanDays <= 0 means archive all active done tasks.

func Create

func Create(boardDir, title, assignee string, labels, dependsOn []string, body string) (*models.Task, error)

Create makes a task in drafts/ with status ready.

func Delete

func Delete(boardDir, taskID string) error

Delete removes a task file.

func Dependents

func Dependents(boardDir, taskID string) ([]*models.Task, error)

Dependents returns every task whose DependsOn slice contains taskID (exact match), scanning all state folders. Returns an empty non-nil slice if none are found.

func Edit

func Edit(boardDir, taskID string, opts EditOpts) (*models.Task, error)

Edit changes a task's fields/body. UpdatedAt is bumped.

func Get

func Get(boardDir, taskID string) (*models.Task, error)

Get returns one task by id (searches all state folders).

func ParseState

func ParseState(value string) (models.TaskState, error)

ParseState coerces a string to a TaskState, raising Invalid on unknown values.

func ParseStatus

func ParseStatus(value string) (models.TaskStatus, error)

ParseStatus coerces a string to a TaskStatus, raising Invalid on unknown values.

func RenderEditorDoc

func RenderEditorDoc(d EditorDoc) (string, error)

RenderEditorDoc serialises an EditorDoc to frontmatter+body file content.

func SetState

func SetState(boardDir, taskID string, newState string) (*models.Task, error)

SetState moves a task's file between state folders (draft/active/archive), preserving status. Freeform: any valid state is reachable from any other.

func SetStatus

func SetStatus(boardDir, taskID string, newStatus string) (*models.Task, error)

SetStatus changes a task's workflow status (frontmatter only; the file stays in its state folder). Freeform on both axes: any valid status is reachable from any other, in any state — though status is only visible on the board while the task is active.

func Sort

func Sort(ts []*models.Task, key SortKey, desc bool)

Sort orders tasks by key, descending when desc is set. Ties fall back to ascending numeric id. Unassigned tasks sort last under the assignee key regardless of direction.

Types

type EditOpts

type EditOpts struct {
	Title      *string
	Assignee   *string
	Labels     *[]string
	DependsOn  *[]string
	Body       *string
	AppendBody *string // appended to the body with a blank-line separator
}

EditOpts carries optional field changes for Edit. Nil fields are unchanged.

type EditorDoc

type EditorDoc struct {
	Title     string
	Assignee  string
	Labels    []string
	DependsOn []string
	Body      string
}

EditorDoc is the editable subset of a task exchanged with the TUI's $EDITOR flow: the same on-disk format (YAML frontmatter + body), restricted to the fields the editor may change. id/state/status are managed by their own commands and are deliberately absent.

func ParseEditorDoc

func ParseEditorDoc(content string) (EditorDoc, error)

ParseEditorDoc parses editor output written in the task-file format.

type Issue

type Issue struct {
	Kind   string // unparseable | duplicate-id | id-drift | dangling-dep | cycle | crlf
	File   string // filename (base) the issue is about ("" for board-wide issues)
	Detail string
	Fixed  bool // true when fix mode repaired it
}

Issue is one problem found by Doctor.

func Doctor

func Doctor(boardDir string, fix bool) ([]Issue, error)

Doctor checks the whole board and returns every issue found, most severe first. With fix true it also repairs: CRLF files are rewritten with LF, duplicate ids are renumbered to fresh ids (the first holder keeps the id, so existing depends_on references stay valid), and drifted filenames are renamed to match their frontmatter id. Unparseable files, dangling deps, and cycles are report-only.

func (Issue) String

func (i Issue) String() string

type Snapshot

type Snapshot struct {
	Tasks    []*models.Task // sorted by state (board order), then id
	Warnings []Warning
	// contains filtered or unexported fields
}

Snapshot is a one-shot, tolerant parse of the whole board.

func Load

func Load(boardDir string) (*Snapshot, error)

Load reads every task file on the board. Only filesystem-level failures return an error; per-file parse problems and duplicate ids become Warnings.

func (*Snapshot) Dependents

func (s *Snapshot) Dependents(id string) []*models.Task

Dependents returns every task whose DependsOn contains id (exact match). Returns an empty non-nil slice if none are found.

func (*Snapshot) Filter

func (s *Snapshot) Filter(states []models.TaskState, status string) []*models.Task

Filter returns tasks in the given states (all when empty), optionally narrowed to one status ("" for any). Order follows Snapshot.Tasks.

func (*Snapshot) Get

func (s *Snapshot) Get(id string) *models.Task

Get returns the task with the given id, or nil.

func (*Snapshot) StateCount

func (s *Snapshot) StateCount(state models.TaskState) int

StateCount reports how many tasks are in a given state.

func (*Snapshot) StatusCounts

func (s *Snapshot) StatusCounts() []StatusCount

StatusCounts returns counts of active tasks per status, in board order.

type SortKey

type SortKey string

SortKey names a task ordering.

const (
	SortID       SortKey = "id"
	SortUpdated  SortKey = "updated"
	SortTitle    SortKey = "title"
	SortAssignee SortKey = "assignee"
)

func ParseSortKey

func ParseSortKey(value string) (SortKey, error)

ParseSortKey coerces a string to a SortKey, raising Invalid on unknown values.

type StatusCount

type StatusCount struct {
	Status string
	Count  int
}

StatusCount is one row of the board summary.

type Warning

type Warning struct {
	File string // filename (base) the warning is about
	Err  string // human-readable problem
}

Warning describes a task file the snapshot could not fully use.

func (Warning) String

func (w Warning) String() string

Jump to

Keyboard shortcuts

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