feat(retrospection) + chore(workplan): complete T04 for CYA-WP-0003 — added 'cya retrospect' guided reflection flow with goal capture

This commit is contained in:
2026-05-26 15:26:54 +02:00
parent f2c555284f
commit 6cbd055b1a
3 changed files with 147 additions and 12 deletions

View File

@@ -25,7 +25,12 @@ from rich.console import Console
from rich.panel import Panel
from cya.context.collector import collect, render_explanation
from cya.memory import recall_preferences
from cya.memory import (
recall_preferences,
remember_retrospection_outcome,
KIND_RETROSPECTION,
KIND_INTERACTION_GOAL,
)
from cya.safety.risk import classify, get_user_confirmation
from cya.llm.adapter import AssistanceRequest, FakeLLMAdapter
@@ -157,4 +162,103 @@ def handle_request(
)
__all__ = ["handle_request"]
def run_retrospection(scope: str = ".", limit: int = 8) -> None:
"""Guided retrospection session (T04 of CYA-WP-0003).
Helps the user review recent memory usage in the given scope,
reflect, and record new interaction goals or preferences.
These are stored using the retrospection-aware memory helper.
"""
console.print(
Panel(
"[bold cyan]Retrospection Session[/bold cyan]\n\n"
f"Scope: [green]{scope}[/green]\n"
"We will look at recent memory items and help you reflect.\n"
"Your answers will be stored as durable retrospection memory.",
title="cya retrospect",
border_style="magenta",
padding=(1, 2),
)
)
# Recall recent items, with bias toward retrospection kinds if present
try:
recent = recall_preferences(
scope,
limit=limit,
kinds=[KIND_RETROSPECTION, KIND_INTERACTION_GOAL, "preference"],
)
items = recent.get("items", [])
except Exception as e:
console.print(f"[red]Could not load memory: {e}[/red]")
return
if not items:
console.print(
"[yellow]No memory items found in this scope yet.[/yellow]\n"
"You can create some with normal usage or explicit remembers."
)
return
console.print(
Panel(
"\n".join(
f"• [bold]{item.get('key')}[/bold]: {item.get('value')}"
for item in items[:5]
),
title=f"Recent Memory in {scope} (showing up to 5)",
border_style="blue",
)
)
# Simple guided reflection
console.print("\n[bold]Reflection time[/bold]")
what_worked = typer.prompt(
"What worked well in recent assistance? (short answer or 'skip')",
default="",
show_default=False,
)
if what_worked and what_worked.lower() not in ("skip", "s", ""):
remember_retrospection_outcome(
"what_worked", what_worked, scope=scope
)
console.print("[green]Recorded.[/green]")
what_to_change = typer.prompt(
"What should change in future interactions? (e.g. 'be more concise', 'always show alternatives')",
default="",
show_default=False,
)
if what_to_change and what_to_change.lower() not in ("skip", "s", ""):
remember_retrospection_outcome(
"interaction_goal", what_to_change, scope=scope
)
console.print("[green]Recorded as interaction goal.[/green]")
safety_note = typer.prompt(
"Any standing safety or preference rules for this project? (optional)",
default="",
show_default=False,
)
if safety_note and safety_note.lower() not in ("skip", "s", ""):
remember_retrospection_outcome(
"safety_preference", safety_note, scope=scope
)
console.print("[green]Recorded as safety preference.[/green]")
console.print(
Panel(
"Thank you. Your reflections have been stored as retrospection memory.\n"
"They will be preferentially activated in future sessions in this scope.\n\n"
"You can review them anytime with:\n"
f" [bold]cya --explain-context \"...\"[/bold] (in this directory)\n"
f" or inspect the JSON files in [cyan]~/.config/cya/memory/[/cyan]",
title="Retrospection Complete",
border_style="green",
padding=(1, 2),
)
)
__all__ = ["handle_request", "run_retrospection"]