journal

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 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 journal carries the two path facts every surface needs about the undo journal: the canonical identity of a store file, and the directory a store's history lives in. It is the read-only half of lib/tasks/journal.rb — there is deliberately no write path here.

Index

Constants

View Source
const Limit = 50

Limit is Store::UNDO_LIMIT: the deepest undo history the journal retains.

View Source
const Version = 1

Version is the journal's own format version. A bump invalidates the whole history rather than replaying states this build cannot interpret.

Variables

This section is empty.

Functions

func Canonical

func Canonical(org string) string

Canonical is the absolute, symlink-resolved path — the stable identity of a task file across the different ways callers spell it.

When the file does not exist yet (first-run capture bootstraps it) the containing directory — which does exist — is resolved instead, so the identity stays stable once the file appears. Otherwise a /tmp → /private/tmp style symlink, unresolved while the file is missing and resolved afterward, would shift the journal key between a capture and its undo.

func DirFor

func DirFor(org string, env determinism.Env) string

DirFor is the journal directory for an org file: XDG_STATE_HOME (the standard home for persist-but-non-precious state), namespaced by a digest of the org's CANONICAL path so distinct task files never share a history — and, just as importantly, so two spellings of the same file (a symlink, a relative path) resolve to one history rather than silently diverging.

Types

type Index

type Index struct {
	Cursor int
	States []State
}

Index is the whole timeline plus the cursor into it — the state that matches the live files right now.

type Journal

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

Journal is the durable undo history: the index, the blobs, the plan a caller would apply, and — once Writable has supplied the two values a writer needs — the record, commit and interning half in write.go.

The journal is convenience state, not the source of truth: tasks.jsonl is. Every method runs under the store's file lock and index.json is replaced atomically, so concurrent processes never corrupt it. A crash in the narrow window between rewriting the files and committing the cursor can leave the cursor one step stale; that degrades to a refused undo, never to a mangled task file.

func Open

func Open(dir, org string) *Journal

Open builds the read view over one store's history. `org` is canonicalized so two spellings of the same file resolve to one history rather than silently diverging.

func (*Journal) Barrier

func (j *Journal) Barrier(snapshot Snapshot) bool

Barrier establishes a schema barrier: the current files become the only journal baseline, so an ordinary undo can never restore an older schema.

func (*Journal) Commit

func (j *Journal) Commit(to int) bool

Commit moves the cursor after the caller has rewritten the files for an undo or a redo. Undo and redo are explicit history boundaries, so all segment metadata is stripped: even a redo back to the exact former tip must not resume coalescing with the editor session that preceded the history move.

func (*Journal) Load

func (j *Journal) Load() Index

Load reads the index, degrading to an EMPTY history for every kind of trouble: missing, unreadable, wrong version, someone else's org, a cursor out of range. That is the contract the whole journal is built on — history is convenience state, and journal trouble degrades to "nothing to undo", never to a crash or to replaying a history that is not yours.

func (*Journal) Plan

func (j *Journal) Plan(delta int) (Step, bool)

Plan describes an undo (delta -1) or redo (delta +1) without performing it. A missing step, an unreadable blob, or a blob whose bytes no longer hash to its name all degrade to ok=false — nothing to undo — upholding the contract that journal trouble never crashes a command.

func (*Journal) Record

func (j *Journal) Record(label string, before, after Snapshot, coalesceKey string, repair bool) bool

Record persists a completed mutation. `before` and `after` are the bytes of both files at each moment, a nil half meaning that file is absent. It drops any redo tail, appends or safely replaces the keyed tip, and caps history at `limit` undo steps.

If `before` does not match the recorded tip, an out-of-band edit slipped in since the last record: the stale chain can no longer be safely replayed — undoing across it would clobber that edit — so it is discarded and a fresh baseline starts at `before`.

It reports success, and a failure is not an error the caller propagates. History is convenience state: an unreadable or non-repairable journal must never roll back a task mutation that was already durably written.

func (*Journal) Rollback

func (j *Journal) Rollback(step Step) bool

Rollback undoes a Commit that reported failure, restoring the cursor and the state metadata Plan captured. It reports whether the journal is back at the planned state.

The guard is not an optimization. Atomic replacement ordinarily leaves the old index untouched when it fails, so the common case is that nothing landed and there is nothing to restore — rewriting anyway would burn a write, and worse, would fail for the same reason the commit just did. Only when the on-disk index has actually MOVED (a wrapper or filesystem that installed the file and then reported failure) is it rewritten, and then exactly once.

func (*Journal) Writable

func (j *Journal) Writable(limit int, coalesceScope string) *Journal

Writable turns the read view into the full journal by supplying the two values only a writer needs: how deep the history may get, and the coalescing scope this process owns.

The scope is deliberately local to one owner. Persisting it on a keyed tip is what stops an unrelated process from extending another process's coalesced step — the tip records who was allowed to keep appending to it.

type Snapshot

type Snapshot struct {
	Org     *string
	Archive *string
}

Snapshot is the bytes of both files at one moment. A nil half means that file is absent, which is a real state: an archive that does not exist yet is not the same as an empty one.

func (Snapshot) Equal

func (s Snapshot) Equal(other Snapshot) bool

Equal compares two snapshots including absence, which is what the undo conflict gate turns on.

type State

type State struct {
	OrgSHA        *string `json:"org_sha"`
	ArchiveSHA    *string `json:"archive_sha"`
	Label         *string `json:"label,omitempty"`
	Repair        *bool   `json:"repair,omitempty"`
	CoalesceKey   *string `json:"coalesce_key,omitempty"`
	CoalesceScope *string `json:"coalesce_scope,omitempty"`
}

State is one point in the timeline: the content addresses of both files at that moment, plus the label of the mutation that produced it. states[0] is the baseline and carries no label.

type Step

type Step struct {
	Label  string
	Repair bool
	Expect Snapshot
	Target Snapshot
	To     int
	// contains filtered or unexported fields
}

Step is a planned undo or redo: the label of the mutation being reverted or replayed, the snapshot the live files must currently match, and the snapshot to move to.

Jump to

Keyboard shortcuts

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