feat: multi-persona support (single Cortex, multiple users)

- Add cortex/persona.py: ContextVar-based per-request routing with
  path traversal protection and persona validation
- Migrate inara/ → personas/inara/ (git history preserved via git mv)
- config.py: add personas_root(), inara_path() delegates to personas/inara
- All 14 settings.inara_path() call sites replaced with persona_path()
- ChatRequest + OrchestrateRequest: add persona field (default: "inara")
  with validation at request entry before any processing
- memory_distiller: add optional persona param for future per-persona distill
- cron_runner/tools/cron: stamp persona on jobs, prefix APScheduler IDs
  (persona:job_id) to prevent collisions across personas
- scheduler: _load_user_crons() iterates all personas at startup

Adding a new persona: create personas/<name>/ with IDENTITY.md + SOUL.md.
Auth: handled at nginx level (inject X-Cortex-Persona header per subdomain).
Future: persona maps to Aether account_id_random for full integration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-03-20 21:50:02 -04:00
parent 6316ffa1d4
commit 5cadb836fa
40 changed files with 634 additions and 289 deletions

View File

@@ -17,7 +17,7 @@ import secrets
from datetime import datetime, timezone
from pathlib import Path
from config import settings
from persona import persona_path, get_persona
from cron_runner import load_crons, save_crons, parse_schedule
@@ -61,8 +61,10 @@ def _cron_add(label: str, schedule: str, job_type: str, payload: str) -> str:
return "Bad type: must be 'remind' or 'note'."
crons = load_crons()
current_persona = get_persona()
job = {
"id": _short_id(),
"persona": current_persona,
"label": label,
"schedule": schedule,
"type": job_type,
@@ -72,39 +74,42 @@ def _cron_add(label: str, schedule: str, job_type: str, payload: str) -> str:
"last_run": None,
}
crons.append(job)
save_crons(crons)
save_crons(crons, current_persona)
# Register with the live scheduler
_scheduler_add(job, sched_kwargs)
return f"Created and scheduled: {job['id']} {schedule} [{job_type}] {label}"
return f"Created and scheduled: {job['id']} {schedule} [{job_type}] {label} (persona: {current_persona})"
def _cron_remove(cron_id: str) -> str:
crons = load_crons()
persona = get_persona()
crons = load_crons(persona)
before = len(crons)
crons = [c for c in crons if c["id"] != cron_id]
if len(crons) == before:
return f"Not found: {cron_id}"
save_crons(crons)
_scheduler_remove(cron_id)
save_crons(crons, persona)
_scheduler_remove(f"{persona}:{cron_id}")
return f"Removed: {cron_id}"
def _cron_toggle(cron_id: str) -> str:
crons = load_crons()
persona = get_persona()
crons = load_crons(persona)
for c in crons:
if c["id"] == cron_id:
c["enabled"] = not c.get("enabled", True)
save_crons(crons)
save_crons(crons, persona)
action = "resumed" if c["enabled"] else "paused"
_scheduler_resume(cron_id) if c["enabled"] else _scheduler_pause(cron_id)
sched_id = f"{persona}:{cron_id}"
_scheduler_resume(sched_id) if c["enabled"] else _scheduler_pause(sched_id)
return f"{action.capitalize()}: {cron_id} {c['label']}"
return f"Not found: {cron_id}"
def _reminders_clear() -> str:
p = settings.inara_path() / "REMINDERS.md"
p = persona_path() / "REMINDERS.md"
p.write_text("")
return "Reminders cleared."
@@ -120,10 +125,11 @@ def _scheduler_add(job: dict, sched_kwargs: dict) -> None:
from cron_runner import run_job
s = sched_module.get_scheduler()
if s and s.running:
sched_id = f"{job.get('persona', 'inara')}:{job['id']}"
s.add_job(
lambda j=job: asyncio.ensure_future(run_job(j)),
"cron",
id=job["id"],
id=sched_id,
replace_existing=True,
**sched_kwargs,
)

View File

@@ -17,11 +17,11 @@ import asyncio
from datetime import datetime, timezone
from pathlib import Path
from config import settings
from persona import persona_path
def _scratch_path() -> Path:
return settings.inara_path() / "SCRATCH.md"
return persona_path() / "SCRATCH.md"
def _now_label() -> str:

View File

@@ -20,11 +20,11 @@ import asyncio
from datetime import datetime, timezone
from pathlib import Path
from config import settings
from persona import persona_path
def _tasks_path() -> Path:
return settings.inara_path() / "TASKS.json"
return persona_path() / "TASKS.json"
def _now() -> str: