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>
This commit is contained in:
@@ -5,14 +5,29 @@ Manual memory distillation endpoints.
|
||||
POST /distill/mid — summarize short → MEMORY_MID.md (LLM)
|
||||
POST /distill/long — integrate mid → MEMORY_LONG.md (LLM)
|
||||
POST /distill/all — run all three in sequence
|
||||
|
||||
All endpoints require ?user=<username>&persona=<name> query params so distillation
|
||||
targets the correct persona. Without them, the request is rejected (no silent fallback
|
||||
to server defaults — that caused wrong-user distillation in a multi-user setup).
|
||||
"""
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from memory_distiller import distill_short, distill_mid, distill_long
|
||||
from persona import validate as validate_persona, set_context
|
||||
import scheduler
|
||||
|
||||
router = APIRouter(prefix="/distill")
|
||||
|
||||
|
||||
def _resolve(user: str, persona: str) -> tuple[str, str]:
|
||||
"""Validate and set persona context. Raises 404 if the persona doesn't exist."""
|
||||
try:
|
||||
u, p = validate_persona(user, persona)
|
||||
except Exception:
|
||||
raise HTTPException(status_code=404, detail=f"Persona not found: {user}/{persona}")
|
||||
set_context(u, p)
|
||||
return u, p
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
async def distill_status() -> dict:
|
||||
"""Show auto-distillation schedule and next run times."""
|
||||
@@ -29,29 +44,45 @@ async def distill_status() -> dict:
|
||||
|
||||
|
||||
@router.post("/short")
|
||||
async def do_distill_short() -> dict:
|
||||
return {"ok": True, **distill_short()}
|
||||
async def do_distill_short(
|
||||
user: str = Query(...),
|
||||
persona: str = Query(...),
|
||||
) -> dict:
|
||||
u, p = _resolve(user, persona)
|
||||
return {"ok": True, **distill_short(u, p)}
|
||||
|
||||
|
||||
@router.post("/mid")
|
||||
async def do_distill_mid() -> dict:
|
||||
result = await distill_mid()
|
||||
async def do_distill_mid(
|
||||
user: str = Query(...),
|
||||
persona: str = Query(...),
|
||||
) -> dict:
|
||||
u, p = _resolve(user, persona)
|
||||
result = await distill_mid(u, p)
|
||||
return {"ok": "error" not in result, **result}
|
||||
|
||||
|
||||
@router.post("/long")
|
||||
async def do_distill_long() -> dict:
|
||||
result = await distill_long()
|
||||
async def do_distill_long(
|
||||
user: str = Query(...),
|
||||
persona: str = Query(...),
|
||||
) -> dict:
|
||||
u, p = _resolve(user, persona)
|
||||
result = await distill_long(u, p)
|
||||
return {"ok": "error" not in result, **result}
|
||||
|
||||
|
||||
@router.post("/all")
|
||||
async def do_distill_all() -> dict:
|
||||
short_result = distill_short()
|
||||
mid_result = await distill_mid()
|
||||
async def do_distill_all(
|
||||
user: str = Query(...),
|
||||
persona: str = Query(...),
|
||||
) -> dict:
|
||||
u, p = _resolve(user, persona)
|
||||
short_result = distill_short(u, p)
|
||||
mid_result = await distill_mid(u, p)
|
||||
if "error" in mid_result:
|
||||
return {"ok": False, "short": short_result, "mid": mid_result}
|
||||
long_result = await distill_long()
|
||||
long_result = await distill_long(u, p)
|
||||
return {
|
||||
"ok": "error" not in long_result,
|
||||
"short": short_result,
|
||||
|
||||
Reference in New Issue
Block a user