Files
museion/docs/devlog/20261021-issue26-promote-consult-learnings_log.md
T
AlexKucera 0e5c28ad95
CI / ci (push) Canceled after 0s
feat(mentor): promote & consult Learnings (#26)
Only the writer's explicit confirmation promotes a Fix Card into a
Learning — one confirm, one entry, never a repetition counter. The
Learning is a plain markdown file under <home>/learnings/<type>s/
carrying the card's teaching fields (pattern, problem, diagnostic
question, the demonstration example) plus promotion provenance; the
instance-bound anchor and mechanical replacement stay on the card.
Every pass consults these files via query_learnings; the Learnings
pane replaces its placeholder. Promote consults the on-disk card as
the truth and rejects symlinked learnings paths before any write
(finish-audit round). Dismiss/decay follows in #27.

Closes #26
2026-10-21 12:13:24 +02:00

70 lines
6.9 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: Promote & consult Learnings (S4.1, S4.3, S4.4)
> **Date:** 2026-10-21
> **Type:** issue
> **Reference:** AlexKucera/Museion#26 (blocked-by #25 verified closed before start)
## Goal
Ship #26: only the writer's explicit confirmation promotes a Fix Card into a Learning — one confirm, one entry, never a repetition counter — carrying the card's teaching fields plus promotion provenance into plain markdown files under the Home's `learnings/<type>s/`, consulted by every pass via `query_learnings`, plus the Learnings pane replacing its M1 placeholder. Dismiss/decay stays #27.
## What Was Done
- `FixCardStore.promote(pieceURL:card:now:)` — rejects a symlinked learnings component before any write, consults the ON-DISK card as the truth (not-found / already-stamped throw before anything is written), writes ONE Learning `<learningsDir>/<yyyyMMdd>-<slug(pattern)>.md` (collision -2/-3), then restamps the card JSON in place with `promotedAt` (close()'s rewrite pattern; learning-first ordering deliberate — the inverse would lock re-promotion after a crash).
- `StoredFixCard.promotedAt: Date?` (snake_case `promoted_at`; pre-#26 cards decode nil); `learningsDir(home:type:)` public seam + private `homeAndType` shared with `learnings(piecePath:)`.
- `learningMarkdown` — the pinned file shape: flat single-line frontmatter (pattern/problem/diagnostic_question?/demonstration-fix?/lane/emitter/piece?/pass?/engine?/promoted/from_card; newlines flatten) + readable body (`# pattern`, Problem/Diagnostic lines, `**Example.**` for demonstrations, italic provenance footer).
- `PostsModel.promoteCard` → `FixCardPromoteOutcome` (.promoted | .refused) — guards already-promoted + open session, failure → `lastError`, success → `refreshCards`; touches no text.
- `FixCardsWindow.CardRow` — Promote button (open cards between primary action and Skip; closed unpromoted cards alone; `· promoted` in meta, never re-offers) + per-row sheet.
- `PromoteAskSheet.swift` (new) — the design contract's `#promoteDialog`: "Promote to Learnings?", type-pluralized body line, preview showing exactly what lands (pattern, problem, diagnostic, demonstration example, provenance), Cancel/Promote, refusal inline orange.
- `LearningsPaneView.swift` (new) — list-only pane (Archive posture): `LearningsIndex` (nonisolated) scans type dirs → groups (dir name lowercased section heads) → entries newest-first (YYYYMMDD desc, undated last), lenient `Post.frontmatter` reads, scan detached off MainActor with a `Task.isCancelled` gate; WorkspaceView placeholder swapped.
- Tests: `MCPToolsPromoteTests.swift` (9 store pins incl. the audit pins), `LearningsPaneTests.swift` (4 pins incl. symlinked type-dir fixture), 2 model pins in `FixCardApplyTests`.
- Docs: Museion/AGENTS.md ×4 bullets, MuseionTests/AGENTS.md, CHANGELOG (Unreleased), CONTEXT.md Learning definition, PRD S4.1 AC + v2 parking-lot entries.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Learning carries TEACHING fields only — anchor + mechanical fix stay on the card JSON | Anchor is apply-machinery (a Learning informs, never gets applied); a mechanical fix is a literal replacement string from one instance that teaches nothing; demonstration fix IS the example and travels. User-approved mid-session revision (CONTEXT.md/PRD updated). |
| Deterministic generation, no LLM call | Card fields are already persona-authored generalizations (promote is format conversion, not thinking); the ask's preview must equal what lands; promote stays local/atomic (works engine-down); deterministic output is what keeps learnings git-diffable. Parked in PRD v2 lot with revisit trigger: if card fields generalize badly, fix pass-persona doctrine first. |
| On-disk card as truth in promote (finish-audit Medium) | A stale palette copy (async refresh gap) or vanished card JSON could double-write Learnings; the disk check before any write is the only real one-confirm-one-entry guarantee. |
| Symlink guard on the learnings path (finish-audit security LOW) | Reviewer empirically verified a pre-planted `learnings/posts` symlink turned promote into a file-plant primitive; one guard at the single write site, read side already skipped links. |
| Promote button outlives the card (offered on closed cards) | The design contract's promote-resolved buttons; the Learning is the durable artifact. |
| Button order Promote-left/Cancel-right | House `ApplyAskSheet` precedent (repo overrides the HTML order). |
| Pane without FSEvents watcher | Re-scans on pane re-entry; ponytail ceiling, commented. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Subagent hand-off patches mangled ("No valid patches in input") | The terminal backend collapses `git diff` output — even through redirects — into a stat+context summary | Byte-copied the changed files from the worktrees instead; later diffs taken with `git diff --output=<file>` + read_file |
| Ponytail reviewer claimed `??`/`&&` precedence made `isPlainDirectory`'s symlink check dead | Misread of NilCoalescing vs LogicalConjunction precedence (2 of 3 reviewers + a scratch probe confirmed it parses correctly) | No change; probe settled it; the unpinned behavior got a symlink fixture instead |
| Audit-flip first attempt duplicated the pane's scan | Patch added the guard AFTER an assignment instead of between await and assign | Rewrote the task body to `let scanned = await …; guard !Task.isCancelled; groups = scanned` |
| Full-suite grep counted "failed" hits | Test NAMES containing "failed" match `grep "Test case .* failed"` | Parsed with python regex over the log instead |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/FixCardStore.swift` | promote + promotedAt + learningsDir + learningMarkdown (teaching shape) |
| `Museion/PostsModel.swift` | promoteCard + FixCardPromoteOutcome |
| `Museion/FixCardsWindow.swift` | Promote button + promoted meta in CardRow |
| `Museion/PromoteAskSheet.swift` | new — the blocking promote ask |
| `Museion/LearningsPaneView.swift` | new — LearningsIndex + list-only pane |
| `Museion/WorkspaceView.swift` | placeholder → LearningsPaneView |
| `MuseionTests/MCPToolsPromoteTests.swift` | new — 9 store pins |
| `MuseionTests/LearningsPaneTests.swift` | new — 4 pane pins |
| `MuseionTests/FixCardApplyTests.swift` | +2 model pins |
| `MuseionTests/MCPToolsTests.swift` | helpers widened internal, card(provenance:) |
| `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | DOX pass |
| `CHANGELOG.md`, `CONTEXT.md`, `PRD.md` | entry, Learning definition, S4.1 AC + parking lot |
## Open Items & Next Steps
- [ ] #27 Dismiss & Decay (S4.2) — now unblocked; decay keys land on the #26 frontmatter
- [ ] FixCardStore at 532 lines / 335-line type body — warning-level lint only (error gates 1000/350); split when the next slice forces it
- [ ] Dogfood: run a real pass, promote a card, verify the engine's critique of the NEXT piece reflects the learning
---
*Log written by write-log skill*