Files
museion/docs/devlog/20261021-issue27-dismiss-decay-learnings_log.md
T
AlexKucera 78c8844184
CI / ci (push) Canceled after 0s
feat(mentor): dismiss & decay Learnings (#27)
Dismissed patterns fade instead of haunting. Dismissing a Learning
stamps decay state into its own frontmatter (dismissed date,
dismiss_count, dismissed_at_pass — every other line preserved
verbatim, hand-editable, git-diffable) and hides it from every pass:
query_learnings serves only visible learnings. Resurfacing is an
output clock, not a calendar — a per-type counter under
<home>/learnings/pass-counts.json, ticked by every completed pass
(cancels and refusals never advance, so never tick), returns the
Learning after 10 subsequent passes of its content type; each
re-dismiss doubles the interval (10→20→40…), and a per-Learning
resurface_after frontmatter key overrides the base. Hand-edited decay
state reads leniently: garbage means visible, absurd values clamp, a
hand-edit can never trap the pane or the rail. The Learnings pane
rows dismiss (no confirm — low-stakes, self-healing), dim while
hidden with a resurfaces-in-N countdown, and foreign unclocked type
dirs neither offer Dismiss nor show a verdict — their clock can never
advance. Two review waves (two-axis implement review + three-reviewer
finish-audit: security clean) produced five fixes, each pinned or
noted in the session log.

Closes #27
2026-10-21 14:19:43 +02:00

69 lines
7.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# M3: Dismiss & Decay (S4.2) — issue #27
> **Date:** 2026-10-21
> **Type:** issue
> **Reference:** AlexKucera/museion#27 (M3 milestone)
## Goal
Ship #27: dismissed Learnings fade instead of haunting — a dismissed Learning stops feeding passes and resurfaces after 10 subsequent completed passes of its content type (an output clock, not a calendar), each re-dismiss doubles the interval (10→20→40…), a per-Learning `resurface_after` frontmatter key overrides the base, and decay state lives in frontmatter — surviving restarts, hand-editable (PRD S4.2, G8; ADR-0005 file home).
## What Was Done
- `Museion/LearningDecay.swift` (new, own file — FixCardStore sits at its type-body ceiling): the decay engine, nonisolated. Pass clock `<home>/learnings/pass-counts.json` (flat {typeDir: count}, keys via `passKey`); `recordPass(home:type:)` ticks it (symlink-guarded); `passesHidden(_:currentPass:)` is the ONE pure visibility verdict (nil = visible, positive = passes remaining) shared by the consult rail, the pane rows, and the dismiss stamp; `dismiss(home:typeDir:file:)` stamps `dismissed`/`dismiss_count`/`dismissed_at_pass` into the Learning's own frontmatter via `stampingFrontmatter` (mergedFrontmatter's line-walk generalized; set-overwrite in place, insert before closing `---`, no block → fresh prepend, every other line verbatim — leading hand-edit lines above the block included).
- `FixCardStore.learnings(piecePath:)` — the `query_learnings` consult rail — now filters hidden learnings through the same verdict (replacing the #26 ponytail pass-through note); `learningsDir` keys through `passKey`; `formatted` widened internal (dismiss's date stamp shares it).
- `PostStore.advancePassState` ticks the type's clock after its stamped write — `try?`, because a failed tick must never fail a completed pass and a lagging clock only delays resurfacing (safe direction). Cancelled/refused passes never advance, so never tick.
- `LearningsPaneView` — `Entry.resurfacesIn` (currentPass param, nil = foreign dir → never a verdict); visible rows in clocked dirs carry a mono-11 Dismiss (no confirm — low-stakes, self-healing); dismissed rows dim 0.45 with "dismissed · resurfaces in N passes"; scan refactored into `rescan()` reused post-dismiss; orange lastError strip; `scannedHome` gate so a stale dismiss task can't overwrite a repointed Home's groups or error state.
- `Post.ContentType` → CaseIterable (drives `isClocked`); `MCPServer` query_learnings description documents the decay contract.
- Tests: `LearningDecayTests` (new) — clock ticking (re-runs included, per-type, fresh home), stamp shape (frontmatter keys + anchor pinned, other keys + body byte-identical, rail exclusion), resurface boundary (hidden through +9, visible at +10), doubling to 20 with re-anchoring, `resurface_after` override, lenient edges (garbage ints, clamps so no arithmetic can trap, corrupt clock), every refusal guard (hostile paths, missing file, symlinked dir AND file, foreign dir, re-while-hidden), fresh-block prepend, leading-blank preservation. `LearningsPaneTests` — resurfacesIn math pins + scan carrying the clock + foreign-dir no-verdict.
- Docs: Museion/AGENTS.md, MuseionTests/AGENTS.md, CHANGELOG entry.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Output clock = one JSON file per Home (`pass-counts.json`), not per-Learning counting | One counter per content type is the honest unit ("passes of that content type"); ticking every Learning's frontmatter per pass would be O(n) writes per pass. Flat JSON is hand-editable and reads leniently (corrupt → 0, only delays resurfacing). |
| Tick lives in `advancePassState`, every completed pass counts (re-runs included) | One call site, monotonic with the existing completed-pass record; a re-run IS a pass that consulted the learnings. `try?` — the clock must never fail a pass. |
| Re-dismiss only after resurface (store refuses while hidden) | Doubling needs a fresh anchor at the current clock; also makes a double-click's second stamp harmless. |
| Foreign (unclocked) type dirs: store refuses dismiss AND pane shows no verdict/button | Their clock reads 0 forever — a dismiss or a displayed countdown there could never advance (permanent hide / lying UI). |
| Interval = (resurface_after ?? 10) « min(dismiss_count−1, 30); values clamp to [0, 1e9] | Override replaces the base, doubling compounds from it; caps keep every hand-edit from trapping Int arithmetic (max ~1.07e18 < Int.max). |
| Decay keys in the Learning's own frontmatter (`dismissed_at_pass` anchor + `dismiss_count` + `resurface_after`) | AC4: hand-editable, git-diffable, survives restarts; deleting the anchor re-activates the Learning. |
| No-confirm dismiss in the pane | Low-stakes and self-healing (it decays back); CONTEXT.md's Dismiss is not a trust-gated action (unlike Apply/Promote). |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Pane rendered a decay countdown in foreign dirs that could never advance | Scan fed every entry a clock; foreign dirs are never ticked | `Entry.currentPass: Int?` — nil = unclocked = never a verdict, mirroring the store's refusal (review finding; pinned) |
| `stampingFrontmatter` dropped lines above the opening `---`, contradicting its "verbatim" contract | `splitFrontmatter` starts at the first non-empty `---` line; leading hand-edit blanks fall in neither block nor body | Prefix recovered via exact `range(of: block)` and re-prepended; pin added and flip-verified (fails with fix off) |
| Stale `lastError` could leak from an old Home after repoint | Failure assignment ran outside `scannedHome` gate rescan enforces | Gated on `scannedHome == home` (no pin — race window, no view-state harness) |
| "resurfaces in 1 passes" copy bug | No pluralization at pane meta + store refusal | Ternary at both sites |
| Test-side `stamped()` DateFormatter helper duplicated prod `FixCardStore.formatted` | Reinvention the same diff internalized | Helper deleted; 6 call sites call the prod function (format literals still pinned) |
| `LearningDecayTests` crossed file/type-body ceilings by one line | New pin pushed it over | Trimmed a redundant assert + comment line |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/LearningDecay.swift` | New — decay engine: clock, verdict, dismiss, frontmatter rewrite |
| `Museion/FixCardStore.swift` | Consult rail filters hidden learnings; `learningsDir` via `passKey`; `formatted` internal |
| `Museion/PostStore.swift` | `advancePassState` ticks the decay clock (`try?`) |
| `Museion/LearningsPaneView.swift` | Dismiss button, dimmed countdown rows, rescan, error strip, scannedHome gate, foreign-dir gating |
| `Museion/PostLibrary.swift` | `ContentType` CaseIterable |
| `Museion/MCPServer.swift` | query_learnings description documents decay |
| `MuseionTests/LearningDecayTests.swift` | New — 15 decay pins |
| `MuseionTests/LearningsPaneTests.swift` | resurfacesIn + clock-carrying scan + foreign-dir pins |
| `MuseionTests/MCPToolsPromoteTests.swift` | `stamped` helper deleted (prod `formatted` direct) |
| `Museion/AGENTS.md`, `MuseionTests/AGENTS.md`, `CHANGELOG.md` | DOX + changelog |
## Open Items & Next Steps
- [ ] None for #27 — all four acceptance criteria met and pinned.
- M3 (critique memory) is now fully shipped (S4.1–S4.4 across #26 + #27); the Sessions rail placeholder is #28's.
---
*Implementation landed in an interrupted working session; this session resumed it, verified the full suite, and ran two review waves (two-axis implement review + three-reviewer finish-audit: ponytail/security/general — security clean, five findings fixed, all documented above). Verified green on the final tree: `xcodebuild test` (unit + UI) TEST SUCCEEDED, swiftformat 0/75, swiftlint 0 violations in touched files; GitNexus detect-changes symbol set = intended scope, graph re-analyzed (4,079 nodes).*
*Log written by write-log skill*