undo

package
v0.18.4 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package undo implements the append-only transaction journal from SPEC §6.3. Each forward mutation records one transaction capturing the before-images of every task line it touched (added, changed, or removed), keyed by ULID. Undo pops the last transaction and restores those before-images. The journal is written under the tasks.txt lock, in the same critical section as the mutation, so "last" is well-defined across processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(s *store.Store, t Txn) error

Append writes a transaction to the journal. Caller holds the lock.

func ReplaceLast added in v0.4.0

func ReplaceLast(s *store.Store, next Txn) error

ReplaceLast atomically removes the most recent transaction and appends next (the redo entry) in a single atomic write. Caller holds the lock. Called by undo AFTER the reverted tasks file is durably written, so the journal only drops the entry once the revert is committed.

Types

type Change

type Change struct {
	ID     string `json:"id"`
	Before string `json:"before,omitempty"`
	After  string `json:"after,omitempty"`
}

Change records one task's before/after raw lines. An empty Before means the task was newly added (undo deletes it); an empty After means it was removed (undo re-adds it).

type Txn

type Txn struct {
	Op      string   `json:"op"`      // human label, e.g. "add", "done", "archive"
	TS      string   `json:"ts"`      // RFC3339 timestamp
	Changes []Change `json:"changes"` // ULID-keyed before/after lines
}

Txn is a single undoable transaction.

func Peek added in v0.4.0

func Peek(s *store.Store) (Txn, bool, error)

Peek returns the most recent transaction without modifying the journal, or ok=false if the journal is empty. Caller holds the lock. It is non-destructive by design: undo must apply (and durably write) the reverted tasks file BEFORE the journal entry is removed, so a write failure can't lose the inverse (SPEC §6.3 — "a crash can't leave a mutation without its inverse"). Pair it with ReplaceLast once the tasks write has succeeded.

Jump to

Keyboard shortcuts

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