[M5] Persistent state + streaks - #15
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5
Gives the plant memory between runs by fleshing out
internal/storeand wiring it into the default render flow.What changed
internal/store(was a stub) — full load/save of a versioned JSON state file.$XDG_CONFIG_HOME/commit-sprout/state.json, falling back to~/.config/commit-sprout/state.json(a non-absoluteXDG_CONFIG_HOMEis ignored)."leafy"), best streak, and last-seen commit hash/time.Sync→Rename, so a crash or full disk never leaves a corrupt/half-written file. No stray temp files on success.versionfield for future migrations; missing files and corrupt/garbled JSON recover to defaults (no error), and the next save heals the file. Legacyversion: 0, unknown stage names, and negative streaks are normalized on load.plantinterop:State.Plant()projects onto the pureplant.State;State.FromPlant(...)folds a computed result back, ratcheting highest-stage/best-streak upward only (never regresses) and recording the latest commit.cmd/root.go— real load → compute → render → save pipeline (replaces the old zeroplant.State{}). Persistence is best-effort: load errors fall back to a fresh plant, save errors warn on stderr but never fail the command. New--no-saveflag for read-only runs.--no-save.Checklist (from #5)
internal/storeloads/saves JSON at~/.config/commit-sprout/state.json(XDG-aware)Testing
gofmt -l .clean,go vet ./...clean,go build ./...andgo test ./...all green.Plant/FromPlantratchet & no-regress).highest_stage: leafy/best_streak: 3; a later stale run with a rememberedbloomingstate correctly renderstall (wilting)(memory floor holds — one stage below peak, not a collapse to seed) and leaves highest-stage/best-streak intact;--no-saveleaves the file byte-for-byte untouched.Not merging — Phase 1 next cycle handles the merge after CI.
Notes / scope
last_commit_hashfield for forward-compat, butgitstat.Activitydoesn't currently expose a hash publicly, so it's persisted best-effort (empty for now) andlast_commit_timeis the field actually populated today. Plumbing a public hash throughgitstatwould be its own change beyond M5's store scope.