Files
Cortex-Inara/cortex/session_logger.py
Scott Idem 2f675ee4bf Initial commit — Cortex API + Inara identity
Cortex: FastAPI backend serving Inara via Claude/Gemini CLI backends.
Includes SSE streaming chat, session persistence, Google Chat webhook
handler, and Docker support.

Inara: Identity files (persona, soul, protocols, memory, context tiers)
mounted read-only into the container at runtime.

Features in initial cut:
- /chat endpoint with SSE keepalive + LLM fallback
- Session store with rolling history window
- Markdown rendering, copy-to-clipboard, links open in new tab
- Stacked right-column input controls (height selector, enter toggle,
  note mode with public/private) — semi-hidden until textarea grows
- /note endpoint for injecting public context into session history
- Docker Compose config (local dev runs natively; Docker for server)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 03:41:00 -05:00

23 lines
699 B
Python

from pathlib import Path
from datetime import datetime
from config import settings
def log_turn(session_id: str, user_msg: str, assistant_msg: str) -> None:
today = datetime.now().strftime("%Y-%m-%d")
sessions_dir = settings.inara_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()
with open(log_file, "a") as f:
if is_new:
f.write(f"# Session Log — {today}\n")
f.write(
f"\n### [{timestamp}] `{session_id}`\n"
f"**Scott:** {user_msg}\n\n"
f"**Inara:** {assistant_msg}\n"
)