Documentation
¶
Overview ¶
Package state manages journal processing state via an external JSON file.
Package state manages journal processing state via an external JSON file.
Instead of embedding markers (<!-- normalized: ... -->) inside journal files, which causes false positives when journal content includes those exact strings, state is tracked in .context/journal/.state.json.
Index ¶
- Constants
- Variables
- type FileState
- type JournalState
- func (s *JournalState) Clear(filename, stage string) bool
- func (s *JournalState) ClearEnriched(filename string)
- func (s *JournalState) CountUnenriched(journalDir string) int
- func (s *JournalState) Enriched(filename string) bool
- func (s *JournalState) Exported(filename string) bool
- func (s *JournalState) FencesVerified(filename string) bool
- func (s *JournalState) Locked(filename string) bool
- func (s *JournalState) Mark(filename, stage string) bool
- func (s *JournalState) MarkEnriched(filename string)
- func (s *JournalState) MarkExported(filename string)
- func (s *JournalState) MarkFencesVerified(filename string)
- func (s *JournalState) MarkNormalized(filename string)
- func (s *JournalState) Normalized(filename string) bool
- func (s *JournalState) Rename(oldName, newName string)
- func (s *JournalState) Save(journalDir string) error
Constants ¶
const CurrentVersion = 1
CurrentVersion is the schema version for the state file.
Variables ¶
var ValidStages = []string{ journal.StageExported, journal.StageEnriched, journal.StageNormalized, journal.StageFencesVerified, journal.StageLocked, }
ValidStages lists the recognized stage names for Mark and Clear.
Functions ¶
This section is empty.
Types ¶
type FileState ¶
type FileState struct {
Exported string `json:"exported,omitempty"`
Enriched string `json:"enriched,omitempty"`
Normalized string `json:"normalized,omitempty"`
FencesVerified string `json:"fences_verified,omitempty"`
Locked string `json:"locked,omitempty"`
}
FileState tracks processing stages for a single journal entry. Values are date strings (YYYY-MM-DD) indicating when the stage completed.
type JournalState ¶
type JournalState struct {
Version int `json:"version"`
Entries map[string]FileState `json:"entries"`
}
JournalState is the top-level state file structure.
func Load ¶
func Load(journalDir string) (*JournalState, error)
Load reads the state file from the journal directory.
If the file does not exist, an empty state is returned (not an error).
Parameters:
- journalDir: path to the journal directory
Returns:
- *JournalState: loaded or empty state
- error: non-nil if the file exists but cannot be read or parsed
func (*JournalState) Clear ¶
func (s *JournalState) Clear(filename, stage string) bool
Clear removes a stage value, resetting it to empty.
Parameters:
- filename: journal entry filename
- stage: one of ValidStages
Returns:
- bool: false if stage is not recognized
func (*JournalState) ClearEnriched ¶
func (s *JournalState) ClearEnriched(filename string)
ClearEnriched removes the enriched date for a file, resetting it to unenriched. Used when --force re-export discards frontmatter.
Parameters:
- filename: journal entry filename
func (*JournalState) CountUnenriched ¶
func (s *JournalState) CountUnenriched(journalDir string) int
CountUnenriched counts .md files in the directory that lack an enriched date in the state file.
Parameters:
- journalDir: path to the journal directory
Returns:
- int: number of unenriched Markdown files
func (*JournalState) Enriched ¶
func (s *JournalState) Enriched(filename string) bool
Enriched reports whether the file has been enriched.
Parameters:
- filename: journal entry filename
Returns:
- bool: true if the file has an enriched date
func (*JournalState) Exported ¶
func (s *JournalState) Exported(filename string) bool
Exported reports whether the file has been exported.
Parameters:
- filename: journal entry filename
Returns:
- bool: true if the file has an exported date
func (*JournalState) FencesVerified ¶
func (s *JournalState) FencesVerified(filename string) bool
FencesVerified reports whether the file's fences have been verified.
Parameters:
- filename: journal entry filename
Returns:
- bool: true if the file has a fences-verified date
func (*JournalState) Locked ¶
func (s *JournalState) Locked(filename string) bool
Locked reports whether the file is protected from export regeneration.
Parameters:
- filename: journal entry filename
Returns:
- bool: true if the file has a lock date recorded
func (*JournalState) Mark ¶
func (s *JournalState) Mark(filename, stage string) bool
Mark sets an arbitrary stage to today's date.
Parameters:
- filename: journal entry filename (e.g., "2026-01-21-session.md")
- stage: one of ValidStages (exported, enriched, normalized, fences_verified, locked)
Returns:
- bool: false if stage is not recognized
func (*JournalState) MarkEnriched ¶
func (s *JournalState) MarkEnriched(filename string)
MarkEnriched records that a file was enriched.
Parameters:
- filename: journal entry filename
func (*JournalState) MarkExported ¶
func (s *JournalState) MarkExported(filename string)
MarkExported records that a file was exported.
Parameters:
- filename: journal entry filename (e.g., "2026-01-21-session.md")
func (*JournalState) MarkFencesVerified ¶
func (s *JournalState) MarkFencesVerified(filename string)
MarkFencesVerified records that a file's fences were verified.
Parameters:
- filename: journal entry filename
func (*JournalState) MarkNormalized ¶
func (s *JournalState) MarkNormalized(filename string)
MarkNormalized records that a file was normalized.
Parameters:
- filename: journal entry filename
func (*JournalState) Normalized ¶
func (s *JournalState) Normalized(filename string) bool
Normalized reports whether the file has been normalized.
Parameters:
- filename: journal entry filename
Returns:
- bool: true if the file has a normalized date
func (*JournalState) Rename ¶
func (s *JournalState) Rename(oldName, newName string)
Rename moves state from an old filename to a new one, preserving all fields. If old does not exist in state, this is a no-op.
Parameters:
- oldName: current filename in state
- newName: target filename
func (*JournalState) Save ¶
func (s *JournalState) Save(journalDir string) error
Save writes the state file atomically (temp + rename) to the journal directory.
Parameters:
- journalDir: path to the journal directory
Returns:
- error: non-nil if marshalling or file write fails