diff --git a/cortex/context.py b/cortex/context.py deleted file mode 100644 index f99dcc2..0000000 --- a/cortex/context.py +++ /dev/null @@ -1,61 +0,0 @@ -import os, requests, datetime -from typing import Dict, Any, Tuple - -INTAKE_API_URL = os.getenv("INTAKE_API_URL", "http://intake:7080") -DEFAULT_SESSION_ID = os.getenv("DEFAULT_SESSION_ID", "default") -LOCAL_TZ_LABEL = os.getenv("LOCAL_TZ_LABEL", "America/New_York") - -def fetch_intake_context(session_id: str | None) -> Dict[str, Any]: - sid = session_id or DEFAULT_SESSION_ID - try: - r = requests.get(f"{INTAKE_API_URL}/summaries", params={"session_id": sid}, timeout=4) - r.raise_for_status() - data = r.json() or {} - except Exception: - data = {} - # Normalize expected fields - return { - "summary_text": data.get("summary_text", ""), - "last_message_ts": data.get("last_message_ts"), # ISO8601 or None - "session_id": sid, - "exchange_count": data.get("exchange_count", 0), - } - -def build_temporal_snapshot(last_ts_iso: str | None) -> Dict[str, Any]: - now = datetime.datetime.now() # system local time - now_str = now.strftime("%A, %b %-d, %Y, %H:%M") - elapsed_str = "unknown" - if last_ts_iso: - try: - # parse ISO (with/without tz). If it has a timezone offset, fromisoformat handles it. - last = datetime.datetime.fromisoformat(last_ts_iso.replace("Z", "+00:00")) - delta = now - last.replace(tzinfo=None) - mins = int(delta.total_seconds() // 60) - if mins < 60: - elapsed_str = f"{mins} min" - else: - hrs = mins // 60 - rem = mins % 60 - elapsed_str = f"{hrs} hr {rem} min" - except Exception: - pass - return { - "local_time_label": LOCAL_TZ_LABEL, - "local_time_now": now_str, - "elapsed_since_last": elapsed_str, - } - -def get_intake_block(session_id: str | None) -> Tuple[str, Dict[str, Any]]: - ctx = fetch_intake_context(session_id) - temporal = build_temporal_snapshot(ctx.get("last_message_ts")) - # A short, ready-to-inject block for prompts: - intake_block = ( - f"[Intake]\n" - f"Session: {ctx['session_id']}\n" - f"Exchanges: {ctx['exchange_count']}\n" - f"Local time ({temporal['local_time_label']}): {temporal['local_time_now']}\n" - f"Elapsed since last: {temporal['elapsed_since_last']}\n" - f"Recent summary: {ctx['summary_text'] or '(none)'}\n" - ) - # Also return raw dicts if you want to use fields programmatically - return intake_block, {"intake": ctx, "temporal": temporal} diff --git a/cortex/identity.json b/cortex/identity.json deleted file mode 100644 index 85ec3f5..0000000 --- a/cortex/identity.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Lyra", - "version": "0.1", - "core_values": [ - "assist Brian", - "maintain continuity", - "reason first, speak second" - ], - "personality": { - "tone": "warm but analytical", - "style": "co-pilot, collaborator" - }, - "rules": { - "never hallucinate data": true, - "reason_before_response": true, - "use_rag_when_uncertain": true - } -} diff --git a/cortex/identity.py b/cortex/identity.py deleted file mode 100644 index add7d19..0000000 --- a/cortex/identity.py +++ /dev/null @@ -1,24 +0,0 @@ -# identity.py -import json -import os - -IDENTITY_PATH = os.getenv("IDENTITY_PATH", "identity.json") - -def load_identity(): - """ - Load Lyra's identity/persona definition from identity.json. - Returns a dict or None if missing/invalid. - """ - - if not os.path.exists(IDENTITY_PATH): - print(f"[Identity] identity.json not found at {IDENTITY_PATH}") - return None - - try: - with open(IDENTITY_PATH, "r", encoding="utf-8") as f: - data = json.load(f) - print(f"[Identity] Loaded identity from {IDENTITY_PATH}") - return data - except Exception as e: - print(f"[Identity] Failed to load identity.json: {e}") - return None diff --git a/cortex/ingest_handler.py b/cortex/ingest/ingest_handler.py similarity index 100% rename from cortex/ingest_handler.py rename to cortex/ingest/ingest_handler.py diff --git a/cortex/intake_client.py b/cortex/ingest/intake_client.py similarity index 100% rename from cortex/intake_client.py rename to cortex/ingest/intake_client.py diff --git a/cortex/llm_router.py b/cortex/llm/llm_router.py similarity index 100% rename from cortex/llm_router.py rename to cortex/llm/llm_router.py diff --git a/cortex/llm/resolve_llm_url.py b/cortex/llm/resolve_llm_url.py new file mode 100644 index 0000000..e69de29 diff --git a/cortex/main.py b/cortex/main.py index aa5a527..e50bc42 100644 --- a/cortex/main.py +++ b/cortex/main.py @@ -1,6 +1,5 @@ from fastapi import FastAPI from pydantic import BaseModel -from identity import load_identity from reasoning import reason_check from reflection import reflect_notes from rag import query_rag @@ -28,7 +27,7 @@ class IngestRequest(BaseModel): # --------------------------------------------------- # Load identity # --------------------------------------------------- -IDENTITY = load_identity() +IDENTITY = None # --------------------------------------------------- # Routes MUST come after app = FastAPI() diff --git a/cortex/persona/speak.py b/cortex/persona/speak.py new file mode 100644 index 0000000..e69de29 diff --git a/cortex/reasoning.py b/cortex/reasoning/reasoning.py similarity index 100% rename from cortex/reasoning.py rename to cortex/reasoning/reasoning.py diff --git a/cortex/refine.py b/cortex/reasoning/refine.py similarity index 100% rename from cortex/refine.py rename to cortex/reasoning/refine.py diff --git a/cortex/reflection.py b/cortex/reasoning/reflection.py similarity index 100% rename from cortex/reflection.py rename to cortex/reasoning/reflection.py diff --git a/cortex/utils/config.py b/cortex/utils/config.py new file mode 100644 index 0000000..e69de29 diff --git a/cortex/log_utils.py b/cortex/utils/log_utils.py similarity index 100% rename from cortex/log_utils.py rename to cortex/utils/log_utils.py diff --git a/cortex/utils/schema.py b/cortex/utils/schema.py new file mode 100644 index 0000000..e69de29