# Plan: Background Pattern Detection & Proactive Proposal

**Goal:** Maven continuously monitors facts written to the store, detects recurring patterns (behavioral, operational, temporal), and proposes new routines, reminders, or config changes back to the user via the existing `ProposedRoutine` / tool-proposal mechanism.

**Done when:**
- Background analyzer reads `RecentFacts` and `Events` on a slow cadence (every 10min, not every tick)
- New patterns beyond the existing action-lexicon `internal/pattern/extractor.go` — e.g. time-of-day correlations, service-down + user-awake sequences, repeated tool invocations
- Proposals land as `ProposedRoutine` rows in the store (reusing `store.CreateProposedRoutine`) or `ProposeTool` calls
- User confirms via voice or mavweb — existing `pendingRoutineConfirm` / `resolveConfirm` path re-used
- False-positive rate measured and acceptable (proposals are parked, never auto-enabled)

**Scope:**
- New `internal/analyzer/` package — runs on a separate ticker (10-30min), reads from `ipc.CoreAPI` (or direct `store.Store` for performance)
- Extends `internal/pattern/` detector with multi-signal patterns (not just action+object interval)
- Reuses existing `store.Events`, `store.ProposedRoutine`, `store.Tools` tables
- Daemon wiring: new `analyzer` goroutine in `cmd/mavend/main.go` alongside tick loop

**Steps:**
1. Create `internal/analyzer/` with periodic scan — `Analyzer.Run(ctx)` goroutine
2. Implement new detectors:
   - Time-of-day behavioral patterns ("you always water plants at 9pm" → remind at 8:45pm)
   - Service-down + user-present correlation ("service X died while you were away, you fixed it when you sat down" → propose auto-remediation tool)
   - Repeated tool use patterns ("you restart plex every Tuesday" → propose a routine)
3. Register proposals via existing `store.CreateProposedRoutine` (reuses `internal/voice/reactiveHandler:detectPattern` pattern) and `ipc.ProposeTool`
4. Wire analyzer goroutine in `cmd/mavend/main.go` — starts after unlock alongside `tl.run(ctx)`
5. Add `analyzer_interval` to `config.Config` (default 10min)
6. Add voice confirm path — proposals detected in background trigger a nudge with a yes/no prompt, reusing `pendingRoutineConfirm` from `cmd/mavend/voice.go:resolveConfirm`
7. Test with seeded events in `internal/store/events_test.go` pattern
