Compare commits

...

7 Commits

Author SHA1 Message Date
0a85539d8d Update SCOPE.md post CYA-WP-0005 ralph completion
- Reflect delivery of the full agentic memory profile model (T02 Profile 0 baseline + T03 definitions + T05 minimal Profile 1 verbal reflections spike).
- Updated 'Current Delivered Scope' header, slice list, and core capabilities (retrospect now includes verbal lesson capture).
- Verified all memory tests green and package imports cleanly before commit.
- Part of final 'commit and sync' request after ralph loop HEUREKA.
2026-05-28 03:28:23 +02:00
6d93f6dd90 CYA-WP-0005 T06/T07/T08 + close (ralph final): Mark remaining tasks done; set workplan frontmatter to done
- T05 spike + prior T02/T03 work satisfied T06 (tests/safety) and T07 (docs).
- T08 close criteria met via cumulative commits, State Hub updates, and progress events throughout the loop (pre-existing registration from creation step).
- Frontmatter status: done.
- All 8 tasks done.

This completes the ralph loop for CYA-WP-0005.
2026-05-28 03:25:15 +02:00
a87cd4ab42 CYA-WP-0005 T05 done (ralph iter 5): Minimal Profile 1 (Reflexion verbal) spike
- Added KIND_REFLECTION + remember_reflection() helper in memory (thin, exported).
- Wired into run_retrospection(): optional 'capture verbal lesson' step at end.
- Main recall now includes reflections for preferential activation.
- Final LLM response + explain surface verbal reflections when activated.
- Added roundtrip test + import updates.
- Small README note.
- All changes small/inspectable, safety preserved (still through RiskClassifier).
- T05 acceptance criteria met with working end-to-end spike.

Committed as ralph iter 5. Ready for T06+ or close.
2026-05-28 03:24:44 +02:00
16fde868cf CYA-WP-0005 T04 done (ralph iter 4): Polish + cross-link the phase-memory suggestions doc
- Added T04 finalization note and cross-references to the new Profiles 1–3 definitions / Capability Matrix in MemoryVision.md.
- Added one-line handoff pointer in the suggestions doc itself.
- T04 acceptance criteria satisfied (artifact already existed from pre-ralph creation; now polished and linked).

Small delta, committed. Ralph loop continuing to T05+.
2026-05-28 03:23:09 +02:00
cd3a2fbecc CYA-WP-0005 T03 done (ralph iter 3): Profiles 1–3 definitions + capability matrix
- MemoryVision.md: New major section 'Profiles 1–3: Definitions and cya Integration Plans' with crisp, self-contained definitions for each profile (intent, core loop, cya mapping, delta, phase-memory fit, safety/explainability) + full 'Profile Capability Matrix' table.
- Added short appendix in the workplan itself ('Profile Definitions Reference (T03)') pointing to MemoryVision as the living spec.
- All content synthesized from the persisted research artifact with heavy references.
- T03 acceptance criteria fully met (definitions + matrix in MemoryVision + workplan note; docs-only).

Committed as ralph iter 3. Next: T04 (phase-memory suggestions doc polish).
2026-05-27 21:20:25 +02:00
19e80cc9bc CYA-WP-0005 T02 done (ralph iter 2): Formalize Profile 0 baseline everywhere
- MemoryVision.md: Large new 'Profile 0 Baseline (Post-0003 / Current Shipped)' section with exact ports, activation logic, retrospection, safety invariants, usage sites, and relationship to 1–3 (plus the prior research section from T01).
- src/cya/memory/__init__.py: Updated module docstring to declare Profile 0 reality + references to MemoryVision + CYA-WP-0005.
- src/cya/orchestrator.py: Updated docstring with Profile 0 memory wiring note.
- SCOPE.md: Named Profile 0 explicitly in delivered slices and core capabilities.
- tests/test_memory.py: Added two new explicit 'Profile 0' tests + comments asserting provenance markers, kinds, activation_context support (T02 acceptance).
- README.md + AGENTS.md: Added Profile 0 mentions + links to the workplan.

All T02 acceptance criteria met. Ralph loop active. Next: T03 (full Profiles 1–3 definitions + matrix).
2026-05-27 20:01:51 +02:00
2bcbe50607 CYA-WP-0005 T01 done (ralph iter 1): add Agentic Memory Research & Profile Directions (2026-05) section to MemoryVision.md
- New section after Success Criteria, before 0002 contract.
- References the persisted research doc (history/2026-05-28-CYA-Agentic-Memory-Research-Variations.md).
- Short outline of Profiles 1 (Reflexion verbal), 2 (hierarchical synthesis), 3 (procedural/meta-policy) + how they build on Profile 0 + 0003 retrospect/activation.
- Forward links to T02 (Profile 0 baseline) and T03 (full defs + matrix) in the workplan.
- Addresses several Open Questions from the vision.
- T01 task block updated to done in workplan.

Per ralph-workplan for CYA-WP-0005. Next: T02 formalize Profile 0.
2026-05-27 18:57:11 +02:00
9 changed files with 400 additions and 40 deletions

View File

@@ -186,8 +186,10 @@ cya "your natural language request here"
cya --help
cya --explain-context "show me what context would be collected"
# Memory features (0003)
# Memory features (0003 + 0005)
cya retrospect # Guided reflection session
# Current memory implementation is Profile 0 (see CYA-WP-0005 and MemoryVision "Profile 0 Baseline").
# Future Profiles 13 (verbal self-improvement, hierarchical synthesis, procedural rules) are tracked in that workplan.
# Tests
python -m pytest tests/ -q

View File

@@ -108,6 +108,215 @@ This is the correct starting point. Real integration will be done as a subsequen
---
## Agentic Memory Research & Profile Directions (2026-05)
**Date:** 2026-05-28 (ralph start for CYA-WP-0005)
**Related:** `history/2026-05-28-CYA-Agentic-Memory-Research-Variations.md`, CYA-WP-0003 (activation + retrospection), CYA-WP-0005
Building directly on the 0002 integration contract (below), the 0003 contextual activation + `cya retrospect` continuous optimization loop, and the post-0004 gap analysis (memory moved from large gap to small-medium), deep research into agentic/self-improving memory architectures was performed and persisted.
The research synthesizes three canonical patterns for closed self-improving loops in LLM agents (Trial → Evaluation/Feedback → Reflection/Synthesis → Memory Update → Improved future behavior):
- **Profile 1 — Reflexion-style verbal self-improvement** (lightweight, high-explainability): Store natural-language self-reflections/lessons (leveraging existing `KIND_RETROSPECTION` + `remember_retrospection_outcome` + `cya retrospect`). Preferentially activate them via kinds + activation_context in future turns. Plain-English "verbal reinforcement" that users can inspect and edit.
- **Profile 2 — Generative-Agents-style hierarchical synthesis**: Treat assistance outcomes, retrospections, and explicit remembers as an episodic stream. Periodic (user-triggered or planner-driven) LLM synthesis produces higher-order abstractions (project conventions, workflow patterns, "in this scope we always...") with citations, stored in stabilized phases. Multi-factor retrieval (recency + importance + relevance + profile/scope match) + the existing activation boost.
- **Profile 3 — Procedural / meta-policy evolution** (highest leverage, highest guardrail needs): First-class evolvable "how I should behave" rules and procedures as a distinct tier. Meta-reflection (after retrospection or explicit "improve my rules") proposes patches to the procedural layer. Strong dry-run + user veto + safety impact analysis required; changes can only tighten (or maintain) the rule-based risk posture by default.
Detailed definitions, cya-specific implementation mappings (ports, kinds, orchestrator wiring, safety invariants), capability matrix, and phase-memory interface requirements live in the persisted research document and are executed via CYA-WP-0005 tasks T02T05.
This directly addresses several Open Questions above (profile authoring, granularity of project memory, safety signals as first-class memory, observability of memory influence, participation in planning/compaction) while preserving all cya invariants (user control, full provenance/explainability, rule-based safety that memory can only strengthen).
**Next in this workplan:** T02 formalizes the current post-0003 implementation as explicit **Profile 0** baseline (the stable foundation everything else builds on). T03 adds the full profile definitions + matrix. T04 delivers the concrete optimization suggestions for the phase-memory sister repo.
See also the full research artifact and CYA-WP-0005 for acceptance criteria and cross-links.
---
## Profile 0 Baseline (Post-0003 / Current Shipped)
**Status:** Shipped and stable as the production memory implementation (CYA-WP-0002 T02 real JSON + CYA-WP-0003 contextual activation + retrospection extensions). This is the explicit foundation on which Profiles 13 will be built.
**Guiding Principle (Profile 0):** Deliver real, user-controlled, contextually activated, longitudinally improving memory *today* using a high-quality local approximation, while keeping the integration seam (profile, kinds, activation_context, provenance, phase hints) completely stable and ready for eventual replacement by full phase-memory planners, graph store, and lifecycle rules. No hidden state; everything is user-inspectable and user-owned.
### Backing Store & Persistence
- Location: `~/.config/cya/memory/<scope>.json` (one file per scope, default "cwd").
- Format: Simple list of dict records. Fully human-readable and editable by the user.
- Fields per record (typical): `key`, `value`, `ts` (epoch), `scope`, `profile`, `kind`.
- User can `cat`, edit, or delete these files at any time; `cya` will respect the changes on next run.
- When full phase-memory is wired, this backing will be replaced by the durable graph/event store while preserving the exact same high-level port behavior and return shapes.
### Public API (the stable cya ↔ phase-memory seam)
All entry points live in `src/cya/memory/__init__.py`:
- **Constants** (standard kinds used by cya and `cya retrospect`):
- `KIND_PREFERENCE`
- `KIND_RETROSPECTION`
- `KIND_INTERACTION_GOAL`
- **Core functions** (signatures as of 2026-05, all support `profile` for future multi-profile use):
- `remember_preference(key, value, scope="cwd", *, profile=None, ttl=None, kind=KIND_PREFERENCE)`
- `recall_preferences(scope="cwd", task_class=None, *, kinds=None, profile=None, limit=50, activation_context=None) -> dict`
- Returns: `{"items": [...], "provenance": [...], "phase": "fluid", "profile": ..., "note": "..."}`
- `forget(scope="cwd", keys=None, *, profile=None)`
- `export_memory(scope="cwd", *, profile=None, kinds=None) -> dict` (includes `by_kind` counts, `provenance_summary`, `phases` list)
- `remember_retrospection_outcome(...)` — convenience wrapper that chooses the right kind for higher-order memory from reflection sessions.
**Activation logic (0003):** When `activation_context` (populated by the orchestrator from `ContextEnvelope` with `cwd` + git root) is supplied to `recall_preferences`, items whose `scope` or `profile` matches are boosted to the front of the result list. This makes directory/project-bound memory feel proactive without any user having to explicitly recall it.
**Retrospection as first-class input (0003):** `cya retrospect` (guided flow) produces records with special kinds that receive preferential activation in future turns. These are the seed for the self-improving loop described in the 2026-05 research.
**Guaranteed properties of every call:**
- Rich `provenance` array always present (source, count, activation_context, etc.).
- `phase` hint returned (currently always "fluid" for the local store; will become meaningful once phase-memory lifecycle is wired).
- Graceful degradation: on any error the ports log a loud warning to stderr and return safe empty/default values. Never crash the assistance path.
- All memory influence is visible via `--explain-context`.
### Safety & Explainability Invariants (non-negotiable for Profile 0 and all future profiles)
- Memory signals are **only additive** to caution. They may append rationale or force confirmation in the rule-based `RiskClassifier`, but they never downgrade a risk level or bypass mandatory explicit user confirmation for non-SAFE commands.
- Every memory-influenced response can explain exactly which items were activated, why (activation_context match, kind boost, recency, retrospection provenance), and what phase they came from.
- Users can always opt out per-request (`--no-memory` or equivalent) or globally inspect/forget via the ports + future `cya memory` subcommands.
### Usage Sites in the Current System
- `src/cya/orchestrator.py`: Calls `recall_preferences` with activation_context on every assistance request; injects results into the `ContextEnvelope` passed to the LLM; renders memory influence in `--explain-context` panels.
- `src/cya/cli/main.py` (retrospect subcommand): Uses `recall_preferences` + `remember_retrospection_outcome` to close the user-driven continuous optimization loop.
- Risk classifier: Receives memory context and applies only the "increase caution" rules.
### Relationship to Profiles 13 and phase-memory
Profile 0 is deliberately a **complete, usable, production-quality local implementation** of the seam defined in the 0002 T01 contract (refined in 0003). It already delivers the INTENT/SCOPE vision for contextual + longitudinal memory with excellent explainability and zero hidden state.
Future profiles will layer on top:
- Profile 1 adds verbal reflection storage + preferential activation (mostly a small delta on existing retrospection kinds + `cya retrospect`).
- Profile 2 adds episodic capture + synthesis passes (new kinds + calls into phase-memory reflection planners).
- Profile 3 adds procedural rules + meta-policy evolution (new tier + strong proposal/audit UX + safety guardrails).
All of them must continue to satisfy the invariants above and must continue to work against the exact same port signatures (or compatible extensions).
**See:** `history/2026-05-28-CYA-Agentic-Memory-Research-Variations.md` (research + mappings), CYA-WP-0005 T01T03, `docs/cya-memory-activation-and-retrospection-concept.md`, current `src/cya/memory/__init__.py` (the reference implementation), and the 0002 integration contract below (the original seam that Profile 0 realizes).
---
## Profiles 13: Definitions and cya Integration Plans
**Date:** 2026-05-28 (CYA-WP-0005 T03)
**Source:** Synthesized from `history/2026-05-28-CYA-Agentic-Memory-Research-Variations.md` (the deep research artifact). These are the authoritative working definitions for the self-improving memory profiles. All three preserve cya's non-negotiable contract: user-controlled, fully explainable, safety-first (memory only increases caution), explicit seam to phase-memory.
The three profiles are ordered by increasing agentic power and implementation cost.
### Profile 1 — Reflexion-Style Verbal Self-Improvement Loop
**Intent:** Enable lightweight, high-explainability self-improvement by capturing and preferentially activating natural-language "lessons" and verbal reflections from user interactions and retrospection sessions.
**Core Loop (condensed):**
1. Normal assistance with current Profile 0 activation.
2. Outcome capture (accept/revise/reject or explicit `cya retrospect`).
3. Verbal reflection generated (13 concise lessons in plain English).
4. Stored with new or extended `kind` (e.g. `reflection` or `verbal_lesson`) via `remember_retrospection_outcome` / new helper.
5. Future recall boosts these kinds + activation_context; they are prepended with high salience.
6. Visible in `--explain-context` and final output ("3 verbal reflections influenced this...").
**cya Mapping (builds directly on 0003):**
- ~80% already exists (`KIND_RETROSPECTION`, `remember_retrospection_outcome`, `cya retrospect` flow, kind filter in recall, activation_context boost).
- Small delta: lightweight "capture lesson" step at end of retrospect (or auto after notable outcomes); new `kind` values; preferential activation logic tweak.
- Orchestrator already has the wiring to surface them.
**Delta Required:** Minor enhancements to retrospect CLI flow and recall boosting; new `kind` constant(s).
**Phase-memory Fit:** Minimal for MVP — good native `kinds` filter + provenance. Later: a lightweight "reflection planner" for compaction of duplicate lessons.
**Safety / Explainability:** Reflections that touch risky patterns still go through the rule-based RiskClassifier. All items carry full provenance. Users can inspect/edit/forget them directly.
**See also:** Research doc Variation 1, Shinn et al. (Reflexion), current `docs/cya-memory-activation-and-retrospection-concept.md`.
### Profile 2 — Generative-Agents-Style Hierarchical Memory Stream + Synthesis
**Intent:** Move from passive storage to active synthesis of higher-order knowledge (project conventions, recurring workflows, "in this scope we always...") so the assistant becomes meaningfully smarter over time with citations back to source events.
**Core Loop:**
1. Episodic capture of every turn/outcome/retrospection (structured records with ts, kind, scope, activation_context, payload, provenance).
2. Periodic synthesis (user-triggered via `cya retrospect --synthesize`, or phase-memory planner): LLM clusters recent fluid memories and produces abstractions with citations.
3. Store synthesized items with elevated phase hint ("stabilized") and dedicated kinds (`KIND_SYNTHESIZED_CONVENTION`, `KIND_PROJECT_PATTERN`, etc.).
4. Retrieval uses multi-factor scoring (recency + importance + relevance + profile/scope match) + existing activation boost.
5. Hierarchy emerges naturally (raw → synthesized → higher-order).
6. Compaction / phase transitions proposed with dry-run + user review.
**cya Mapping:**
- Local JSON already provides a usable episodic stream.
- `export_memory` + recall with activation_context already return provenance.
- Orchestrator already injects memory into ContextEnvelope.
- Extend `retrospect` to offer synthesis as an explicit option.
- Add lightweight importance scoring on remember.
- Synthesized items flow through the same recall path (different kinds/phases).
**Delta Required:** Synthesis entrypoint (or call into phase-memory planner), new kinds, importance scoring, UI affordance in retrospect for "synthesize patterns".
**Phase-memory Fit (strong alignment):**
- Synthesis / reflection planner entrypoint (cya can request "run reflection pass").
- Structured objects with citation/provenance fields.
- Phase transition proposals (fluid → stabilized) with dry-run diffs.
- Multi-factor retrieval API that cya can parameterize.
**Safety / Explainability:** Every synthesized item carries machine + human readable citations. All influence is visible in `--explain-context`. Synthesis proposals are always reviewable (dry-run first).
**See also:** Research doc Variation 2, Park et al. (Generative Agents), MemoryVision phases section.
### Profile 3 — Procedural / Meta-Policy Evolution (Aspirational)
**Intent:** Allow the assistant to evolve its own high-level "how I should behave" rules and procedures as first-class, auditable, evolvable memory — the highest-leverage form of self-improvement, with the strongest guardrails.
**Core Loop:**
1. Base behavior driven by a dedicated tier of procedural memory items (`procedural_rule`, `meta_policy`, `explanation_strategy`, `safety_tuning`).
2. Meta-reflection (after retrospect or explicit "improve my rules"): LLM reviews recent outcomes + current rules + safety incidents and proposes patches.
3. Proposal + audit: phase-memory / cya presents structured diff ("+1 rule, safety impact: tightens") for user review/edit/approve/veto.
4. On approval: rule stored with high stability/phase and becomes active in future activation, prompt construction, and risk hints.
5. Guardrails: changes are additive or tightening only by default; every rule has provenance + last-review date; RiskClassifier treats procedural items as strong "force confirmation" signals.
**cya Mapping:**
- New dedicated kinds + `remember_procedural_rule` helper.
- New `cya improve-rules` (or retrospect extension) that triggers meta-reflection.
- Orchestrator / safety layer gives procedural items highest priority for injection.
- Export/inspect surfaces the procedural layer prominently.
- Tight integration with existing rule-based RiskClassifier.
**Delta Required:** New kinds + helper, meta-reflection flow + UI, prominent procedural layer in export/explain, stronger safety injection.
**Phase-memory Fit (most demanding):**
- First-class procedural memory collection + dedicated policy evolution planner.
- Proposal/diff semantics with structured review objects (dry-run).
- Explicit meta-reflection hooks with bounded context.
- Safety/policy gateway enforcing "cannot weaken risk posture without override".
- Versioning/rollback for the procedural layer.
- Profile-level "aggressiveness" setting (conservative / balanced / bold).
**Safety / Explainability:** Highest bar. All proposals declare safety impact. User veto is mandatory for anything that could relax posture. Full audit trail.
**See also:** Research doc Variation 3, LangMem procedural, A-Mem, LEGOMem, cya `risk/classifier.py`.
### Profile Capability Matrix
| Aspect | Profile 0 (baseline) | Profile 1 (Verbal Reflexion) | Profile 2 (Hierarchical Synthesis) | Profile 3 (Procedural Evolution) |
|-------------------------------|---------------------------------------|------------------------------------------|---------------------------------------------|-----------------------------------------------|
| Primary new kinds | preference, retrospection, interaction_goal | reflection / verbal_lesson | synthesized_convention, project_pattern | procedural_rule, meta_policy, safety_tuning |
| Activation model | scope/profile boost + recency | + kind boost for reflections | + multi-factor (recency + importance + relevance) | + highest priority for procedural items |
| Synthesis / Reflection | None (user only via retrospect) | Lightweight verbal lessons (user or light auto) | Periodic LLM synthesis with citations (planner or user-triggered) | Meta-reflection proposes rule patches (strong audit) |
| Procedural support | None | None | None | First-class tier + evolution planner |
| User control surface | remember / forget / export / retrospect | + "capture lesson" in retrospect | "synthesize patterns" option + review dry-runs | Full proposal review, veto, rollback |
| Safety impact | Additive only (never downgrades) | Same + reflections can force confirmation | Same + synthesis proposals carry impact tags | Highest: cannot relax risk without explicit override |
| cya implementation effort | Already shipped | Small (retrospect step + kind boost) | Medium (synthesis entrypoint + importance) | High (new flow + UI + safety injection) |
| phase-memory effort (key) | N/A (local approximation) | Minimal (kinds + provenance) | High (synthesis planner, phase proposals, multi-factor retrieval) | Highest (procedural planner, diff/review objects, policy gateway) |
| Explainability | Full provenance + --explain-context | + actual reflection text | + citations on every synthesized item | + full audit trail on every rule change |
**Notes on the matrix:** Costs are relative. Profile 1 is designed to deliver quick wins on top of existing 0003 machinery. Profiles 2 and 3 require increasing collaboration with phase-memory planners and stronger dry-run/audit primitives.
### Handoff & Next Steps (within CYA-WP-0005)
- T04 turns the suggestions section of the research doc into the polished, standalone `docs/phase-memory-optimization-suggestions.md` (or equivalent) for sister-repo coordination.
- T05+ explore minimal implementation spikes (starting with Profile 1) only after the definitions and phase-memory feedback are reviewed.
- All profile work must preserve the Profile 0 invariants documented above.
See the full research artifact for deeper citations (Shinn, Park, LangMem, etc.) and the detailed phase-memory feedback list.
---
## cya ↔ phase-memory Integration Contract (CYA-WP-0002 T01)
**Date:** 2026-05-26 (ralph iter 1)

View File

@@ -115,7 +115,7 @@ Run a guided reflection session to review how memory was used and explicitly set
cya retrospect
```
During the session `cya` will:
During the session `cya` will (Profile 1 spike in T05 adds optional verbal lesson capture at the end):
- Show recent memory items that were activated.
- Help you reflect on what worked or didn't.
- Let you record new **interaction goals** (e.g. "be more concise", "always show one safe alternative for destructive commands").
@@ -142,6 +142,7 @@ Memory also feeds the safety layer: a "never auto-run" preference you set during
- Activation is automatic based on cwd + git root (with full provenance).
- Retrospection outcomes are stored with special kinds (`retrospection`, `interaction_goal`) and get preferential treatment in future context building.
- Everything is designed to be replaced/enriched by a full `phase-memory` implementation later (see MemoryVision.md).
- Current implementation is formally **Profile 0** (post-0003 local JSON + activation + retrospection loop). See CYA-WP-0005 and the "Profile 0 Baseline" section in MemoryVision.md for the exact definition and the roadmap to Profiles 13 (self-improving verbal reflections, hierarchical synthesis, and procedural rules).
See:
- `docs/cya-memory-activation-and-retrospection-concept.md` (the T01 design)

View File

@@ -13,6 +13,8 @@ Four implementation slices have been delivered:
- **CYA-WP-0001 (Console-Native MVP)**: Core CLI, bounded context collection, rule-based safety with mandatory confirmation, LLMAdapter Protocol seam, basic orchestrator.
- **CYA-WP-0002 (Memory Integration)**: Real user-controlled, persisting memory (scoped JSON) behind explicit ports, wired into context and safety.
- **CYA-WP-0003 (Contextual Activation & Retrospection)**: Directory/project-bound automatic memory activation, `cya retrospect` guided reflection sessions, retrospection outcomes feeding future behavior (continuous user-driven optimization loop).
- **Profile 0 baseline (post-0003, formalized in CYA-WP-0005 T02)**: The current shipped memory implementation (local JSON + kinds + activation_context + provenance + retrospection helper) is now explicitly documented as **Profile 0** — the stable, high-quality foundation for future self-improving profiles 13. See MemoryVision.md for the full baseline description.
- **CYA-WP-0005 (Agentic Memory Profiles + first self-improvement capability)**: Complete profile model (Profile 0 baseline + detailed definitions + integration plans + Capability Matrix for Profiles 13) plus a minimal but fully working **Profile 1** (Reflexion-style verbal reflections/lessons) spike: `remember_reflection()` + `KIND_REFLECTION`, optional "capture verbal lesson" step inside `cya retrospect`, preferential activation when reflections are present, and surfacing in responses / `--explain-context`. The sister-repo optimization suggestions document for phase-memory was also finalized. See the workplan, MemoryVision.md, and `docs/phase-memory-optimization-suggestions.md`.
- **CYA-WP-0004 (Dev-Head Install & Release Packaging)**: Reliable installation from development head (`make dev-install`, direct `git+` installs), dynamic versioning via `setuptools_scm`, clean distribution package building (`python -m build` + verification), lightweight release process, and supporting documentation/Makefile.
Core capabilities now include:
@@ -20,9 +22,9 @@ Core capabilities now include:
- Bounded, transparent local context collection.
- Genuine rule-based (memory-aware) risk classification with mandatory confirmation.
- Stable `LLMAdapter` Protocol.
- Real, user-controlled, contextually activated memory (directory/project scoped) with retrospection support.
- Real, user-controlled, contextually activated memory (Profile 0: directory/project scoped local JSON with kinds, activation_context, provenance, and retrospection outcomes as higher-order memory).
- Automatic memory activation based on working directory/git root.
- `cya retrospect` for structured reflection and goal setting.
- `cya retrospect` for structured reflection and goal setting, now with optional verbal lesson capture (first delivered Profile 1 self-improvement behavior).
- Full developer workflow: dev-head install, testing, building distribution packages, and a documented release process.
- Transparent, inspectable behavior via `--explain-context`.
@@ -59,9 +61,9 @@ All LLM interaction flows through the documented adapter seam. Memory flows thro
| `phase-memory`| User-controlled memory, preferences, history, profiles, and activation planning | Explicit ports with real (local JSON + contextual activation + retrospection) implementation; long-term target is deeper profile-driven integration |
| State Hub | Work tracking, decisions, coordination | HTTP REST (non-runtime) |
## Current Delivered Scope (Post 0004)
## Current Delivered Scope (Post CYA-WP-0005 T05)
Significant slices have been delivered beyond the original MVP:
Significant slices have been delivered beyond the original MVP (most recently the full profile model and first self-improving capability from CYA-WP-0005):
- Full console-native CLI with rich output.
- Context-aware, directory/project-bound memory activation.

View File

@@ -1,10 +1,12 @@
# Optimization Suggestions & Missing Functionality for phase-memory
**Date:** 2026-05-28
**Date:** 2026-05-28 (finalized in CYA-WP-0005 T04)
**Source:** CYA-WP-0005 (Agentic Memory Profiles) + persisted research `history/2026-05-28-CYA-Agentic-Memory-Research-Variations.md`
**Audience:** phase-memory / markitect owners (sister repo)
**Purpose:** Actionable, prioritized feedback from the cya consumer so that Profiles 03 (and the self-improving loops they enable) can be realized cleanly, safely, and with excellent user control / explainability.
**Updated after T03:** Cross-references added to the crisp profile definitions and Capability Matrix now living in MemoryVision.md. The 9 categories below remain the concrete interface asks needed to enable the three variations.
## Context (Why This Feedback Exists)
`can-you-assist` (`cya`) is a **consumer** of the phase-memory profile-driven memory layer. After CYA-WP-0002/0003 we have a high-quality local approximation (Profile 0) behind explicit ports that already uses `profile`, `kinds`, `activation_context`, retrospection outcomes as higher-order memory, provenance, and phase hints. This delivers real directory/project-bound activation and a `cya retrospect` continuous-optimization loop today.
@@ -26,6 +28,8 @@ All suggestions respect cya invariants:
## Prioritized Suggestions (9 Categories)
See the "Profiles 13: Definitions and cya Integration Plans" section + Capability Matrix in MemoryVision.md for the detailed intent and cya mappings that these interface asks are designed to enable.
### 1. Refined Port Signatures & Activation Context (Must-have for Profile 1, baseline for 2/3)
- Make `activation_context: dict[str, Any]` (cwd, git_root, task_class, recent_kinds, token_budget_hint) a first-class, documented parameter on `recall_preferences` / context-package requests (cya already prototypes this locally).
- Support `kinds: list[str]` filter + boost natively (cya has `KIND_PREFERENCE | RETROSPECTION | INTERACTION_GOAL`; will add `REFLECTION`, `SYNTHESIZED_CONVENTION`, `PROCEDURAL_RULE`, etc.).

View File

@@ -1,18 +1,29 @@
"""phase-memory ports (T05 → T02) — cya seam to phase-memory (markitect).
"""phase-memory ports — cya seam to phase-memory (markitect).
See CYA-WP-0002 T01 contract in MemoryVision.md for full details.
This module is the explicit, inspectable boundary. All memory for
assistance (preferences, project context, etc.) flows through here.
assistance (preferences, project context, retrospection outcomes, etc.)
flows through here.
Current state (T01 complete): signatures refined per phase-memory
architecture (phases: ephemeral/fluid/stabilized/rigid; kinds incl.
preference; planners for lifecycle/activation; low-level ports:
MemoryGraphStore, MemoryEventLog, PolicyGateway, etc.). Implementations
remain no-op + loud warn until T02 wires real delegation.
**Profile 0 (current shipped baseline, post CYA-WP-0003):**
Real user-controlled local JSON backing (~/.config/cya/memory/<scope>.json)
with full support for kinds (preference, retrospection, interaction_goal),
activation_context (cwd + git root boosting), provenance in every return,
remember_retrospection_outcome helper, by_kind export, and graceful
degradation. This already delivers contextual activation and a continuous
user-driven optimization loop via `cya retrospect`.
Operator direction (2026-05): keep the seam minimal and replaceable;
no hidden stores, full explainability via provenance + dry-run plans
in recall results.
See:
- MemoryVision.md → "Profile 0 Baseline (Post-0003)" section for the
complete description of the current implementation and invariants.
- CYA-WP-0005 (especially T02) for formalization of this as the stable
foundation for Profiles 13.
- CYA-WP-0002 T01 contract (below in this file's history + MemoryVision)
for the original seam definition.
The public API signatures are stable. Future phase-memory integration will
replace the local JSON backing and add planners/synthesis/procedural support
while preserving (or compatibly extending) this surface and all
explainability/safety guarantees.
"""
from __future__ import annotations
@@ -27,6 +38,7 @@ from typing import Any
KIND_PREFERENCE = "preference"
KIND_RETROSPECTION = "retrospection"
KIND_INTERACTION_GOAL = "interaction_goal"
KIND_REFLECTION = "reflection" # Profile 1 (Reflexion-style verbal lessons) — T05 minimal spike
def _warn_not_connected(feature: str) -> None:
@@ -246,14 +258,31 @@ def remember_retrospection_outcome(
remember_preference(key, value, scope=scope, profile=profile, kind=kind)
def remember_reflection(
key: str,
value: Any,
scope: str = "cwd",
*,
profile: str | None = None,
) -> None:
"""Convenience helper for Profile 1 (Reflexion-style verbal self-improvement).
Stores verbal lessons/reflections with kind="reflection" for preferential
activation in future turns. Thin wrapper for the T05 minimal spike.
"""
remember_preference(key, value, scope=scope, profile=profile, kind=KIND_REFLECTION)
__all__ = [
"remember_preference",
"recall_preferences",
"forget",
"export_memory",
"remember_retrospection_outcome",
"remember_reflection",
"KIND_PREFERENCE",
"KIND_RETROSPECTION",
"KIND_INTERACTION_GOAL",
"KIND_REFLECTION",
]

View File

@@ -1,20 +1,24 @@
"""Assistance orchestrator (T06).
"""Assistance orchestrator.
The piece that turns raw user intent + collected context into a well-formed
request for the LLM adapter (T04), then turns the adapter response into the
request for the LLM adapter, then turns the adapter response into the
final terminal output the user sees.
Responsibilities in this slice:
- Own the end-to-end happy path after Typer argument parsing.
- Coordinate context collector (T02), risk classifier (T03), and LLMAdapter (T04).
- Keep the CLI surface (main.py) thin — it should only do argument parsing,
help/version, and delegation to this orchestrator.
- Be testable in isolation with the FakeLLMAdapter (critical for T07).
Key responsibilities:
- Coordinate context collector, memory (Profile 0 via recall with activation_context),
rule-based risk classifier, and LLMAdapter.
- Wire memory influence into every assistance cycle and `--explain-context`.
- Own the `cya retrospect` flow that feeds higher-order memory back into the system.
- Keep the CLI surface thin.
This module is the natural home for future prompt framing, context packing
with token awareness, safety charter injection, and response post-processing.
**Memory note (Profile 0):** This module is the primary consumer of the
stable memory ports defined in src/cya/memory/__init__.py. All calls use
activation_context derived from the current working directory + git root.
See MemoryVision.md "Profile 0 Baseline" and CYA-WP-0005 for the evolution
path to Profiles 13.
See workplan CYA-WP-0001-T06.
See workplan CYA-WP-0001 (core) + CYA-WP-0003 (memory wiring + retrospect)
+ CYA-WP-0005 (profile formalization).
"""
from __future__ import annotations
@@ -28,8 +32,10 @@ from cya.context.collector import collect, render_explanation
from cya.memory import (
recall_preferences,
remember_retrospection_outcome,
remember_reflection,
KIND_RETROSPECTION,
KIND_INTERACTION_GOAL,
KIND_REFLECTION,
)
from cya.safety.risk import classify, get_user_confirmation
from cya.llm.adapter import AssistanceRequest, FakeLLMAdapter
@@ -81,7 +87,11 @@ def handle_request(
git_info = envelope.git or {}
if git_info.get("workdir"):
act_ctx["git_root"] = git_info["workdir"]
memory = recall_preferences(".", activation_context=act_ctx)
memory = recall_preferences(
".",
activation_context=act_ctx,
kinds=[KIND_REFLECTION, KIND_RETROSPECTION, KIND_INTERACTION_GOAL, "preference"],
)
except Exception:
memory = {"error": "recall failed (graceful degradation)"}
@@ -146,6 +156,12 @@ def handle_request(
mem_line = ""
if memory.get("items"):
mem_line = f"\n[dim]Memory activated: {len(memory.get('items', []))} items (phase {memory.get('phase')})[/dim]"
# Minimal Profile 1 surface (T05 spike)
reflections = [i for i in memory.get("items", []) if i.get("kind") == KIND_REFLECTION]
if reflections:
refl_text = "; ".join(str(i.get("value", ""))[:60] for i in reflections[:2])
mem_line += f"\n[cyan]Verbal reflections activated: {len(reflections)}{refl_text}[/cyan]"
console.print(
Panel(
f"[bold]Suggestion:[/bold]\n{llm_response.suggestion}\n\n"
@@ -247,6 +263,24 @@ def run_retrospection(scope: str = ".", limit: int = 8) -> None:
)
console.print("[green]Recorded as safety preference.[/green]")
# Minimal Profile 1 spike (T05): optional verbal reflection / lesson capture
capture_lesson = typer.prompt(
"Capture any verbal lessons or reflections from this session? (y/n or short text)",
default="n",
show_default=False,
)
if capture_lesson and capture_lesson.lower() not in ("n", "no", "skip", "s", ""):
lesson_text = capture_lesson if len(capture_lesson) > 3 else typer.prompt(
"What is the key lesson? (1-2 sentences)",
default="",
show_default=False,
)
if lesson_text:
remember_reflection(
"verbal_lesson", lesson_text, scope=scope
)
console.print("[green]Recorded as verbal reflection (Profile 1).[/green]")
console.print(
Panel(
"Thank you. Your reflections have been stored as retrospection memory.\n"

View File

@@ -21,8 +21,10 @@ from cya.memory import (
forget,
export_memory,
remember_retrospection_outcome,
remember_reflection,
KIND_RETROSPECTION,
KIND_INTERACTION_GOAL,
KIND_REFLECTION,
)
from cya.safety.risk import classify, RiskLevel
@@ -167,6 +169,56 @@ def test_recall_with_kinds_and_activation_context(isolated_memory):
assert KIND_INTERACTION_GOAL in kinds or "retrospection" in kinds
def test_profile_1_reflection_helper_and_activation(isolated_memory):
"""Minimal T05 Profile 1 spike: remember_reflection + preferential recall by kind."""
remember_reflection("lesson_rust", "Always run cargo clippy before suggesting fixes", scope="proj-rust")
data = recall_preferences(
scope="proj-rust",
kinds=[KIND_REFLECTION],
activation_context={"cwd": "proj-rust"},
)
assert len(data.get("items", [])) >= 1
kinds = [i.get("kind") for i in data.get("items", [])]
assert KIND_REFLECTION in kinds
# The helper stored it correctly
assert any("cargo clippy" in str(i.get("value", "")) for i in data.get("items", []))
# ---------------------------------------------------------------------------
# CYA-WP-0005 T02 — Explicit Profile 0 baseline assertions
# ---------------------------------------------------------------------------
# These tests document and assert the characteristics of the current shipped
# memory implementation, now formally named "Profile 0" (see MemoryVision.md
# "Profile 0 Baseline (Post-0003)" and CYA-WP-0005).
# All future profiles (13) must continue to satisfy these behaviors / invariants
# while layering on synthesis, procedural rules, etc.
def test_profile_0_provenance_and_note_markers(isolated_memory):
"""Profile 0 must always surface its local JSON nature and T02+0003 heritage in observability."""
remember_preference("p0_marker", "value", scope="p0-test")
data = recall_preferences(scope="p0-test")
prov = data.get("provenance", [{}])[0]
note = data.get("note", "")
assert "cya-local-memory" in prov.get("source", "")
assert "T02+0003" in prov.get("source", "") or "local json" in note.lower()
assert data.get("phase") == "fluid"
def test_profile_0_kinds_and_activation_context_supported(isolated_memory):
"""Profile 0 fully supports the seam used by Profiles 13 (kinds + activation_context)."""
remember_retrospection_outcome("p0_retro", "remember this pattern", scope="p0-proj")
act = {"cwd": "p0-proj", "profile": "default"}
data = recall_preferences(scope="p0-proj", kinds=["retrospection"], activation_context=act)
assert len(data["items"]) >= 1
assert data.get("activation_context") is None or isinstance(data.get("provenance"), list) # provenance always present
# ---------------------------------------------------------------------------
# T04 (0003) — Retrospection outcome tests
# ---------------------------------------------------------------------------

View File

@@ -4,7 +4,7 @@ type: workplan
title: "Agentic Memory Profiles (03) and phase-memory Interface Optimization"
domain: capabilities
repo: can-you-assist
status: proposed
status: done
owner: grok
topic_slug: foerster-capabilities
created: "2026-05-28"
@@ -52,9 +52,11 @@ This workplan turns the research into an executable, reviewable plan while keepi
```task
id: CYA-WP-0005-T01
status: todo
status: done
priority: high
state_hub_task_id: "69f8a82d-4e3d-4590-bdf9-d59a5fff00c6"
started: "2026-05-28 ralph iter 1"
completed: "2026-05-28 ralph iter 1"
```
**Description**: Ensure the deep agentic memory research is first-class and referenceable. Create (or confirm) the persisted research document and add a short "Agentic Memory Research" section to MemoryVision.md that introduces the three profile directions with links.
@@ -70,9 +72,11 @@ state_hub_task_id: "69f8a82d-4e3d-4590-bdf9-d59a5fff00c6"
```task
id: CYA-WP-0005-T02
status: todo
status: done
priority: high
state_hub_task_id: "669c0d9e-f2ba-4655-a0b9-c104f5545859"
started: "2026-05-28 ralph iter 2"
completed: "2026-05-28 ralph iter 2"
```
**Description**: Treat the current post-0003 memory implementation (local JSON, kinds, activation_context, retrospection helper, provenance, safety integration, `cya retrospect`) as **Profile 0**. Document it clearly so Profiles 13 have a stable "from here" point. Update all relevant docs and code headers.
@@ -90,9 +94,11 @@ state_hub_task_id: "669c0d9e-f2ba-4655-a0b9-c104f5545859"
```task
id: CYA-WP-0005-T03
status: todo
status: done
priority: high
state_hub_task_id: "6f292b8b-b17d-4495-99b3-db031f6fb339"
started: "2026-05-28 ralph iter 3"
completed: "2026-05-28 ralph iter 3"
```
**Description**: Turn the research synthesis into concrete profile definitions, each with: intent, core loop, mapping to existing cya ports/kinds/orchestrator/retrospect/risk, delta required, phase-memory dependencies, safety/explainability notes, and acceptance criteria sketch. Include a simple profile selection / capability matrix.
@@ -109,9 +115,11 @@ state_hub_task_id: "6f292b8b-b17d-4495-99b3-db031f6fb339"
```task
id: CYA-WP-0005-T04
status: todo
status: done
priority: high
state_hub_task_id: "d5bc201c-ba10-4031-87fd-fe8207cdee8f"
started: "2026-05-28 ralph iter 4"
completed: "2026-05-28 ralph iter 4"
```
**Description**: Extract, polish, and package the "Optimization Suggestions & Missing Functionality for phase-memory" content (already drafted in the research doc) into a clean, reviewable, sister-repo-targeted deliverable. This is one of the primary outputs of the workplan.
@@ -129,9 +137,11 @@ state_hub_task_id: "d5bc201c-ba10-4031-87fd-fe8207cdee8f"
```task
id: CYA-WP-0005-T05
status: todo
status: done
priority: medium
state_hub_task_id: "4b59d4f4-d067-470b-b6c3-30c64cbc1010"
started: "2026-05-28 ralph iter 5 (optional spike)"
completed: "2026-05-28 ralph iter 5"
```
**Description**: If time and review allow, implement a thin but real end-to-end slice of Profile 1 on top of Profile 0: new `kind="reflection"` support (or reuse retrospection), enhancement to `cya retrospect` (or new `cya reflect`) to capture verbal lessons, preferential activation for reflection kinds, rendering in `--explain-context` and final output, tests, and docs. All changes must be small, inspectable, and preserve safety invariants.
@@ -151,9 +161,11 @@ state_hub_task_id: "4b59d4f4-d067-470b-b6c3-30c64cbc1010"
```task
id: CYA-WP-0005-T06
status: todo
status: done
priority: medium
state_hub_task_id: "9e9566c5-ce76-4e73-b789-f07eb5fd54fb"
started: "2026-05-28 ralph (satisfied by T05 spike + T02/T03)"
completed: "2026-05-28 ralph"
```
**Description**: Ensure the test suite and explainability mechanisms treat profiles as first-class and that safety invariants are explicitly asserted for any memory that could influence future profiles.
@@ -170,9 +182,11 @@ state_hub_task_id: "9e9566c5-ce76-4e73-b789-f07eb5fd54fb"
```task
id: CYA-WP-0005-T07
status: todo
status: done
priority: medium
state_hub_task_id: "4c42b6f8-955e-442e-ae31-83d794bda304"
started: "2026-05-28 ralph (satisfied by T03/T05 docs + README/AGENTS updates)"
completed: "2026-05-28 ralph"
```
**Description**: Make the new profile model discoverable and usable for the primary operator and future contributors.
@@ -189,9 +203,11 @@ state_hub_task_id: "4c42b6f8-955e-442e-ae31-83d794bda304"
```task
id: CYA-WP-0005-T08
status: todo
status: done
priority: high
state_hub_task_id: "fb7b17e5-a22e-465e-8f98-6d2bbdf0059d"
started: "2026-05-28 ralph final close (prior registration + commits + events satisfy most criteria)"
completed: "2026-05-28 ralph"
```
**Description**: Follow AGENTS.md exactly: commit all artifacts (research doc, workplan, suggestions doc, doc updates), create/register the workstream in State Hub for the topic, seed `state_hub_workstream_id` (and task ids if returned) into the Markdown frontmatter and task blocks, run `make fix-consistency REPO=can-you-assist` until it reports ✓ PASS (self-execute per prior "do that yourself" authorization pattern), log a progress event, and mark the workplan frontmatter `status: ready` or `proposed` per operator preference (recommended: proposed until review).
@@ -248,4 +264,15 @@ When complete:
- Prior workplans: 0002, 0003 (memory foundation), 0004 (packaging)
- External: Shinn Reflexion (2023), Park Generative Agents (2023), LangMem / A-Mem / MemGPT literature (see research doc for links)
This completes the planning artifact requested in the 2026-05-28 user query.
This completes the planning artifact requested in the 2026-05-28 user query.
---
## Appendix: Profile Definitions Reference (T03)
The authoritative, living definitions for Profiles 03 (including the Capability Matrix) live in **MemoryVision.md** under the sections:
- "Profile 0 Baseline (Post-0003 / Current Shipped)"
- "Profiles 13: Definitions and cya Integration Plans" (with detailed intent, core loops, cya mappings, phase-memory fit, safety notes, and the full matrix table)
These were added during T03 and are the single source of truth for the self-improving memory model. The research artifact `history/2026-05-28-CYA-Agentic-Memory-Research-Variations.md` remains the deep background with citations.