Problem
Currently, BASIC_MEMORY_HOME has dual, conflicting semantics:
- Original intent: Path to the "main" (default) project directory
- Cloud mode usage: Root directory where ALL projects must be created
This creates confusion and doesn't properly separate concerns.
Example of the Issue
With BASIC_MEMORY_HOME=/app/data/basic-memory:
- Main project files:
/app/data/basic-memory/*.md (at the root)
- New project "test":
/app/data/basic-memory/test/ (subdirectory)
- Result: Main project files and other project directories are mixed together
Current Cloud Mode Implementation
In PR #332, we implemented path validation that constrains projects to BASIC_MEMORY_HOME when cloud mode is enabled. However, this couples path restriction to cloud mode, when really it's about filesystem constraints.
Proposed Solution
Introduce a new environment variable that explicitly handles project path constraints:
BASIC_MEMORY_PROJECT_ROOT
Behavior:
- If set: ALL projects must be created underneath this directory (path sanitization enforced)
- If not set: Projects can be created anywhere (current default behavior)
Semantics:
BASIC_MEMORY_HOME: Location of the "main" project (backward compatible, unchanged)
BASIC_MEMORY_PROJECT_ROOT: Optional root directory for all projects
Benefits
- ✅ Decouples path restriction from cloud mode (useful for any constrained environment)
- ✅ Backward compatible - existing users with custom
BASIC_MEMORY_HOME unaffected
- ✅ More explicit - "project root" is clearer than overloading "home"
- ✅ Flexible - works in both cloud and local constrained environments
Example Usage
Cloud Mode
BASIC_MEMORY_HOME=/app/data/basic-memory # main project location
BASIC_MEMORY_PROJECT_ROOT=/app/data # all projects must be under /app/data
Results:
- Input:
/tmp/test → /app/data/tmp/test (sanitized)
- Input:
test → /app/data/test
- Main project:
/app/data/basic-memory/ (unchanged)
Local Mode with Constraints
BASIC_MEMORY_HOME=~/basic-memory # main project
BASIC_MEMORY_PROJECT_ROOT=~/my-projects # all projects under here
Local Mode Unrestricted (Default)
BASIC_MEMORY_HOME=~/basic-memory # main project
# BASIC_MEMORY_PROJECT_ROOT not set - projects can be anywhere
Implementation Changes
- config.py - Add
BASIC_MEMORY_PROJECT_ROOT field to BasicMemoryConfig
- project_service.py - Update
add_project() to check BASIC_MEMORY_PROJECT_ROOT instead of cloud_mode_enabled
- Dockerfile (basic-memory-cloud) - Set
BASIC_MEMORY_PROJECT_ROOT=/app/data instead of BASIC_MEMORY_CLOUD_MODE
- Tests - Update cloud mode tests to use
BASIC_MEMORY_PROJECT_ROOT
- Documentation - Update docs to explain the new variable and deprecation of relying on cloud mode for path constraints
Migration Path
BASIC_MEMORY_HOME continues to work as-is (no breaking changes)
- Cloud deployments update to use
BASIC_MEMORY_PROJECT_ROOT
BASIC_MEMORY_CLOUD_MODE can remain for other cloud-specific behaviors if needed
Related
cc: @phernandez
Problem
Currently,
BASIC_MEMORY_HOMEhas dual, conflicting semantics:This creates confusion and doesn't properly separate concerns.
Example of the Issue
With
BASIC_MEMORY_HOME=/app/data/basic-memory:/app/data/basic-memory/*.md(at the root)/app/data/basic-memory/test/(subdirectory)Current Cloud Mode Implementation
In PR #332, we implemented path validation that constrains projects to
BASIC_MEMORY_HOMEwhen cloud mode is enabled. However, this couples path restriction to cloud mode, when really it's about filesystem constraints.Proposed Solution
Introduce a new environment variable that explicitly handles project path constraints:
BASIC_MEMORY_PROJECT_ROOTBehavior:
Semantics:
BASIC_MEMORY_HOME: Location of the "main" project (backward compatible, unchanged)BASIC_MEMORY_PROJECT_ROOT: Optional root directory for all projectsBenefits
BASIC_MEMORY_HOMEunaffectedExample Usage
Cloud Mode
Results:
/tmp/test→/app/data/tmp/test(sanitized)test→/app/data/test/app/data/basic-memory/(unchanged)Local Mode with Constraints
Local Mode Unrestricted (Default)
Implementation Changes
BASIC_MEMORY_PROJECT_ROOTfield toBasicMemoryConfigadd_project()to checkBASIC_MEMORY_PROJECT_ROOTinstead ofcloud_mode_enabledBASIC_MEMORY_PROJECT_ROOT=/app/datainstead ofBASIC_MEMORY_CLOUD_MODEBASIC_MEMORY_PROJECT_ROOTMigration Path
BASIC_MEMORY_HOMEcontinues to work as-is (no breaking changes)BASIC_MEMORY_PROJECT_ROOTBASIC_MEMORY_CLOUD_MODEcan remain for other cloud-specific behaviors if neededRelated
cc: @phernandez