#+TITLE: Flight Plan: Flatten & Generalize Memex Environment Architecture
#+AUTHOR: Gemini CLI
#+DATE: 2026-04-01
#+FILETAGS: :psf:arch:refactor:generalization:
#+STARTUP: content

* Overview
Refactor the =.env.example= and secure local =.env= to remove the legacy PARA structure and replace it with a generalized, anchor-based architecture. Move towards a unified =MEMEX_DIR= foundation while ensuring portability for different users and folder structures.

* Phase A: Analysis (The Scientist)
:PROPERTIES:
:STATUS: COMPLETE
:END:
** Findings
- Current =.env= relies on hardcoded absolute paths (=/home/user/memex/...=).
- Direct removal of PARA variables breaks skills (=org-skill-project-foundry=, etc.).
- The kernel's =context-resolve-path= already supports =$= expansion but needs to be the standard for all internal path lookups.

* Phase B: Blueprint (The Architect)
:PROPERTIES:
:STATUS: PENDING_AUTHORIZATION
:END:
** [Coder] Surgical Implementation Tasks
1. *Generalize .env.example:*
   - Define =MEMEX_DIR= as the single mandatory anchor.
   - Use variable references for all sub-directories (e.g., =PROJECTS_DIR="${MEMEX_DIR}/projects"=).
   - Add documentation explaining how to override these for custom structures.
2. *Harden Path Resolution (README.org):*
   - Update =load-all-skills= to use =context-resolve-path= when reading the =SKILLS_DIR= environment variable.
   - This ensures that if a user sets =SKILLS_DIR="$MEMEX_DIR/notes"=, the Lisp kernel expands it correctly regardless of the OS or username.
3. *Sync Secure .env (~/.local/share/opencortex/.env):*
   - Refactor the user's secure file to use this dynamic derivation.

** [Tester] Verification Strategy
1. *Portability Test:* Temporarily set =MEMEX_DIR=/tmp/memex-test= in the environment and verify that =(opencortex:context-get-skill-source "test")= attempts to read from the correct expanded path.
2. *Boot Test:* Restart daemon and ensure all skills load via the new expanded paths.

* NEXT Authorization Gate
** Sovereign, do you approve this Generalized Flattening plan?
- [ ] APPROVED
- [ ] REJECTED
