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:
@@ -84,34 +84,38 @@ def start() -> None:
|
||||
|
||||
|
||||
def _load_user_crons() -> None:
|
||||
"""Register all enabled user-defined cron jobs from CRONS.json."""
|
||||
"""Register all enabled user-defined cron jobs across all personas."""
|
||||
import asyncio
|
||||
try:
|
||||
from cron_runner import load_crons, parse_schedule, run_job
|
||||
from persona import list_personas
|
||||
except ImportError as e:
|
||||
logger.warning("could not import cron_runner: %s", e)
|
||||
logger.warning("could not import cron modules: %s", e)
|
||||
return
|
||||
|
||||
crons = load_crons()
|
||||
loaded = 0
|
||||
for job in crons:
|
||||
if not job.get("enabled", True):
|
||||
continue
|
||||
try:
|
||||
kwargs = parse_schedule(job["schedule"])
|
||||
_scheduler.add_job(
|
||||
lambda j=job: asyncio.ensure_future(run_job(j)),
|
||||
"cron",
|
||||
id=job["id"],
|
||||
replace_existing=True,
|
||||
**kwargs,
|
||||
)
|
||||
loaded += 1
|
||||
except Exception as e:
|
||||
logger.warning("cron job %s skipped: %s", job.get("id"), e)
|
||||
total = 0
|
||||
for persona_name in list_personas():
|
||||
for job in load_crons(persona_name):
|
||||
if not job.get("enabled", True):
|
||||
continue
|
||||
# Ensure persona is stamped on the job for run_job() to resolve paths
|
||||
job.setdefault("persona", persona_name)
|
||||
try:
|
||||
kwargs = parse_schedule(job["schedule"])
|
||||
sched_id = f"{persona_name}:{job['id']}"
|
||||
_scheduler.add_job(
|
||||
lambda j=job: asyncio.ensure_future(run_job(j)),
|
||||
"cron",
|
||||
id=sched_id,
|
||||
replace_existing=True,
|
||||
**kwargs,
|
||||
)
|
||||
total += 1
|
||||
except Exception as e:
|
||||
logger.warning("cron %s/%s skipped: %s", persona_name, job.get("id"), e)
|
||||
|
||||
if loaded:
|
||||
logger.info("loaded %d user cron job(s)", loaded)
|
||||
if total:
|
||||
logger.info("loaded %d user cron job(s) across %d persona(s)", total, len(list_personas()))
|
||||
|
||||
|
||||
def stop() -> None:
|
||||
|
||||
Reference in New Issue
Block a user