Files
Cortex-Inara/cortex/session_logger.py
Scott Idem 0ffcd57c95 fix: multi-user distillation + datetime in context + session log labels
Distillation was silently operating on scott/inara for all users due to
ContextVar defaults. All three distill endpoints now require ?user=&persona=
query params and validate them via persona.validate(). Memory distiller
signatures changed from Optional to required positional args — no more
global settings fallback. Scheduler now iterates all users/personas instead
of hardcoding the primary user.

- context_loader: inject current date/time as first system prompt section
- session_logger: use get_user()/get_persona() from context instead of
  settings globals so Holly/Brian sessions show correct speaker labels
- memory_distiller: system prompts now reference u.title()/p.title()
  instead of settings.user_name/settings.agent_name
- distill router: Query(...) enforces params; _resolve() validates persona
- scheduler: _all_personas() helper iterates every user/persona for distill
- app.js: runDistill() now appends ?user=&persona= via _fileParams

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 18:44:51 -04:00

35 lines
1.0 KiB
Python

from datetime import datetime
from persona import persona_path, get_user, get_persona
def log_turn(
session_id: str,
user_msg: str,
assistant_msg: str,
backend_label: str = "",
host: str = "",
) -> None:
today = datetime.now().strftime("%Y-%m-%d")
sessions_dir = persona_path() / "sessions"
sessions_dir.mkdir(exist_ok=True)
log_file = sessions_dir / f"{today}.md"
timestamp = datetime.now().strftime("%H:%M")
is_new = not log_file.exists()
meta_parts = [p for p in [backend_label, host] if p]
meta = f" · {' / '.join(meta_parts)}" if meta_parts else ""
# Use the actual user/persona names from the current request context
user_label = get_user().title()
persona_label = get_persona().title()
with open(log_file, "a") as f:
if is_new:
f.write(f"# Session Log — {today}\n")
f.write(
f"\n### [{timestamp}] `{session_id}`{meta}\n"
f"**{user_label}:** {user_msg}\n\n"
f"**{persona_label}:** {assistant_msg}\n"
)