[M3] Plant state machine: activity -> stage + health + mood - #13
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 #3
Implements M3 — Plant state machine:
internal/plantturns agitstat.Activityplus rememberedStateinto a fully-resolvedPlantState. Pure, deterministic, no I/O.What changed
Compute(act, state, now)— the brain. Same inputs → samePlantState, every time. Takes an explicitnowclock (matchinggitstat's pure-function style) so wilt math is testable without wall-clock flake.seed → sprout → leafy → tall → blooming) — streak-driven:>=1/3/7/14consecutive days climb the ladder. A busy-day shortcut (>= 3commits in the window) sprouts a bare seed on your first productive day even before a streak exists.healthy → thirsty → wilting) — by whole calendar days since the last commit: healthy through yesterday, thirsty on days 2–3, wilting from day 4+. No commits at all = a calm, healthySeed(nothing to wilt yet).State.HighestStagekeeps a mature plant from collapsing to a sprout on one slow day. While healthy/thirsty it holds its remembered peak; once wilting it slips exactly one stage below peak so neglect becomes visible — but never belowSproutonce anything has grown. Live growth always beats stale memory, andUpdatedHighestStageis returned for M5 to persist.Tuning thresholdsblock — per the issue's "easy to tune in one place".String()forStage/Health(they can surface in CLI/prompt output).Design note
Statelives in theplantpackage (notstore) on purpose: it keepsComputefree of any I/O dependency and fully unit-testable in isolation. The store package (M5) maps its persisted JSON onto this shape.Tests
17 table-driven cases in
plant_test.go: stage-by-streak across every boundary, busy-day shortcut (and just under it), health across all recency bands, no-commits seed, memory floor holding while healthy, memory floor slipping one stage when wilting, floor never dropping below sprout, live growth beating stale memory, mood prioritization (wilt vs bloom), determinism (25 repeats identical), clock skew, and stable stage/health strings.Verification (Go 1.23.4, matching CI)
gofmt -l .cleango vet ./...cleango build ./...okgo test ./... -count=1okDone when (from the issue)
plant.Compute(activity, state)yields the right stage/health across a table of test cases. ✅Also refreshed README step 2 with an "Implemented — M3" note mirroring the M2 annotation. No behavior change to the binary — M4 render will consume
PlantStatenext.