fix: show session friendly name in resume message and status bar

/history/{session_id} now returns a 'name' field alongside messages.
resumeSession() uses data.name first, then the sessionNames map, then
raw ID as fallback — so named sessions display correctly even on page
load before the sessions panel has been opened.

'Resumed session X' message also now shows the friendly name.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-05-05 19:14:59 -04:00
parent 5d23d04e7e
commit 0b96772fa6
3 changed files with 20 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ from pydantic import BaseModel
from context_loader import load_context
from llm_client import complete
from session_logger import log_turn
from session_store import load as load_session, save as save_session, list_all, generate_session_id, delete as delete_session, rename as rename_session
from session_store import load as load_session, save as save_session, list_all, generate_session_id, delete as delete_session, rename as rename_session, get_name as get_session_name
from config import settings
from persona import set_context, validate as validate_persona
from auth_utils import COOKIE_NAME, decode_token
@@ -264,7 +264,8 @@ async def get_history(
persona: str = Query("inara"),
) -> dict:
_set_ctx(user, persona)
return {"session_id": session_id, "messages": load_session(session_id)}
name = get_session_name(session_id)
return {"session_id": session_id, "name": name, "messages": load_session(session_id)}
@router.get("/sessions")

View File

@@ -73,6 +73,17 @@ def save(session_id: str, messages: list[dict]) -> None:
path.write_text(json.dumps(data, indent=2))
def get_name(session_id: str) -> str:
"""Return the friendly name for a session, or '' if none set."""
path = _path(session_id)
if not path.exists():
return ""
try:
return json.loads(path.read_text()).get("name", "")
except Exception:
return ""
def rename(session_id: str, name: str) -> bool:
"""Set (or clear) the friendly name on a session. Returns False if not found."""
path = _path(session_id)

View File

@@ -642,9 +642,13 @@
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
// Prefer name from API response, fall back to sessionNames map, then raw ID
const displayName = data.name || sessionNames.get(id) || id;
sessionNames.set(id, displayName);
messagesEl.innerHTML = '';
sessionId = id;
sessionEl.textContent = `session: ${sessionNames.get(id) || id}`;
sessionEl.textContent = `session: ${displayName}`;
currentHistory = [];
for (let i = 0; i < data.messages.length; i++) {
@@ -662,7 +666,7 @@
}
}
if (!silent) addMessage('system', `Resumed session ${id}`);
if (!silent) addMessage('system', `Resumed session: ${displayName}`);
scrollToBottom();
sessionsPanel.classList.remove('open');
sessionsBackdrop.classList.remove('open');