feat(memory) + chore(workplan): complete T03 for CYA-WP-0003 — directory/project-bound memory activation wired in orchestrator with improved transparency

This commit is contained in:
2026-05-26 15:18:46 +02:00
parent d904e1bdb4
commit 7bcf28d720
2 changed files with 32 additions and 11 deletions

View File

@@ -19,6 +19,8 @@ See workplan CYA-WP-0001-T06.
from __future__ import annotations
from pathlib import Path
from rich.console import Console
from rich.panel import Panel
@@ -65,19 +67,32 @@ def handle_request(
# T03 (memory wiring): consult after context (so safety can see it in future T04 0002),
# before risk/LLM. Real T02 prefs now available; graceful.
# T03 (0003): pass activation_context so directory/project-bound memory is automatically
# activated based on cwd + git root.
memory = {}
try:
memory = recall_preferences(".")
act_ctx = {"cwd": str(Path.cwd())}
if envelope and getattr(envelope, "git", None):
git_info = envelope.git or {}
if git_info.get("workdir"):
act_ctx["git_root"] = git_info["workdir"]
memory = recall_preferences(".", activation_context=act_ctx)
except Exception:
memory = {"error": "recall failed (graceful degradation)"}
if explain_context and memory.get("items"):
try:
prov = memory.get("provenance", [{}])[0]
# Show a couple of activated items for transparency (T03 0003)
sample = ", ".join(i.get("key", "?") for i in memory.get("items", [])[:3])
act_note = ""
if prov.get("activation_context"):
act_note = f" | ctx: {prov['activation_context']}"
console.print(
Panel(
f"Phase: {memory.get('phase')} | {len(memory.get('items', []))} items | {prov.get('source', 'local')}",
title="Memory Consulted (T03)",
f"Phase: {memory.get('phase')} | {len(memory.get('items', []))} items | {prov.get('source', 'local')}{act_note}\n"
f"Sample activated: {sample}",
title="Memory Activated (T03)",
border_style="blue",
padding=(0, 1),
)
@@ -125,7 +140,7 @@ def handle_request(
# 4. Render final user-facing artifact (T06 responsibility; T03 memory surface)
mem_line = ""
if memory.get("items"):
mem_line = f"\n[dim]Memory: {len(memory.get('items', []))} prefs (phase {memory.get('phase')}, {memory.get('provenance', [{}])[0].get('source', 'local')})[/dim]"
mem_line = f"\n[dim]Memory activated: {len(memory.get('items', []))} items (phase {memory.get('phase')})[/dim]"
console.print(
Panel(
f"[bold]Suggestion:[/bold]\n{llm_response.suggestion}\n\n"