# CYA-WP-0003: Contextual Memory Activation and Retrospection Loops for Continuous Optimization
## Goal
Build on the real memory foundation delivered in CYA-WP-0002 to make memory **actively useful** for context-aware assistance, with two primary advances:
1.**Directory- and project-bound memory activation**: Automatically and intelligently surface relevant memory when the user is working in a specific directory or project, without requiring explicit recall every time.
2.**Regular retrospection loops**: Enable structured, recurring reflection sessions between the user and `cya` that turn memory into a vehicle for continuous improvement — reviewing what worked, setting interaction goals, and evolving preferences over time.
This workplan directly addresses two remaining gaps identified in the post-0002 Intent-vs-Scope analysis:
- Moving from passive memory storage to **proactive, contextually activated** memory.
- Establishing the foundation for true **longitudinal adaptation** and a user-driven optimization loop.
## Background & References
-`INTENT.md` — especially the "Personalized Console Helper" section and the explicit call for `phase-memory` to support "project-specific memory" and "recurring workflows".
-`MemoryVision.md` — defines primary memory kinds relevant to cya, including Project/Directory Memory and Workflow Recipes.
-`history/2026-05-27-CYA-Intent-Scope-Gap-Analysis-Post-0002.md` — identifies remaining gaps in contextual activation and longitudinal value after 0002.
- CYA-WP-0002 — delivered the real (persisting) memory implementation and explicit ports.
- Current memory ports in `src/cya/memory/__init__.py` (the `scope` parameter is the natural starting point for directory binding).
- Deeply aligned the two ideas with INTENT.md (Personalized Console Helper, project-specific memory, recurring workflows, user control) and MemoryVision.md (Project/Directory Memory, Workflow Recipes, activation planning, explainability requirements).
- Defined clear models:
- **Memory Activation**: Automatic, scope-aware (cwd + git root) surfacing of relevant items (preferences, patterns, safety signals) with strong provenance and user control.
- **Retrospection Loops**: Deliberate reflection sessions that produce higher-order memory (`interaction_goal`, retrospection outcomes) which preferentially influence future activation and behavior.
- The two mechanisms reinforce each other: normal use generates candidates for retrospection; retrospection produces high-quality memory that improves future activation.
- Identified minimal port/data model extensions for T02 (richer `kind` support and activation hints in recall, standardized retrospection record kinds).
- In the orchestrator (and context collection path), automatically activate relevant memory based on the current working directory and git root.
- Make activation smart but transparent: surface what was activated and why (especially via `--explain-context`).
- Allow users to influence activation (e.g., "always include these memories in this project").
**Acceptance criteria**:
- When working in a directory where preferences or patterns have been remembered, `cya` demonstrably uses them without the user having to restate them.
- Activation is visible and controllable.
### T04 — Build the retrospection interaction flow
- Heavily update README with before/after examples of directory-bound activation and retrospection sessions.
- Document the new interaction patterns in AGENTS.md and MemoryVision.md.
- Register extension points and any new technical debt.
- Provide clear guidance for phase-memory owners on how retrospection data can flow into richer profiles.
**Acceptance criteria**:
- A reader can understand and try the new capabilities from the README alone.
- The concepts are clearly connected back to INTENT and MemoryVision.
## Dependencies & Cross-Repo Coordination
- **phase-memory**: The concepts here are designed to be consumable and eventually enriched by richer phase-memory capabilities (profiles, phases, activation planning). Close coordination recommended during T01/T02.
- **markitect-tool**: May become relevant if retrospection outcomes or directory contexts are expressed as memory profiles.
- State Hub: For tracking this as the direct follow-on to CYA-WP-0002.
**Status: active** — activated for ralph-workplan loop execution (HEUREKA promise). This workplan directly continues the memory journey from CYA-WP-0002, moving from basic real memory to proactive, contextually activated memory with built-in retrospection for continuous user-driven optimization.