mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
refactor .basic-memory project file structure
This commit is contained in:
@@ -35,5 +35,9 @@ def init_db(
|
||||
|
||||
asyncio.run(_init_db())
|
||||
|
||||
@app.command()
|
||||
def hello(name: str):
|
||||
print(f"Hello {name}")
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
app()
|
||||
+12
-18
@@ -14,14 +14,14 @@ DATA_DIR_NAME = "data"
|
||||
class ProjectConfig(BaseSettings):
|
||||
"""Configuration for a specific basic-memory project."""
|
||||
|
||||
name: str = Field(default="default")
|
||||
path: Path = Field(
|
||||
default_factory=lambda: Path.home() / ".basic-memory" / "projects" / "default",
|
||||
description="Path to project files",
|
||||
# Default to ~/.basic-memory but allow override with env var
|
||||
home: Path = Field(
|
||||
default_factory=lambda: Path.home() / ".basic-memory",
|
||||
description="Base path for basic-memory files",
|
||||
)
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_prefix="BASIC_MEMORY_", # env vars like BASIC_MEMORY_DB_URL
|
||||
env_prefix="BASIC_MEMORY_",
|
||||
extra="ignore",
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
@@ -29,26 +29,20 @@ class ProjectConfig(BaseSettings):
|
||||
|
||||
@property
|
||||
def knowledge_dir(self) -> Path:
|
||||
"""Get knowledge directory path based on project path."""
|
||||
knowledge_path = self.path / KNOWLEDGE_DIR_NAME
|
||||
knowledge_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
return knowledge_path
|
||||
"""Get knowledge directory path."""
|
||||
return self.home / KNOWLEDGE_DIR_NAME
|
||||
|
||||
@property
|
||||
def documents_dir(self) -> Path:
|
||||
"""Get documents directory path based on project path."""
|
||||
documents_path = self.path / DOCUMENTS_DIR_NAME
|
||||
documents_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
return documents_path
|
||||
"""Get documents directory path."""
|
||||
return self.home / DOCUMENTS_DIR_NAME
|
||||
|
||||
@property
|
||||
def database_path(self) -> Path:
|
||||
"""Get SQLite database URL based on project path."""
|
||||
db_path = self.path / DATA_DIR_NAME / DATABASE_NAME
|
||||
db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
return db_path
|
||||
"""Get SQLite database path."""
|
||||
return self.home / DATA_DIR_NAME / DATABASE_NAME
|
||||
|
||||
@field_validator("path")
|
||||
@field_validator("home")
|
||||
@classmethod
|
||||
def ensure_path_exists(cls, v: Path) -> Path:
|
||||
"""Ensure project path exists."""
|
||||
|
||||
@@ -6,6 +6,7 @@ Creates and configures the shared MCP instance and handles server startup.
|
||||
import sys
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.config import config
|
||||
# Import shared mcp instance
|
||||
from basic_memory.mcp.server import mcp
|
||||
|
||||
@@ -14,14 +15,15 @@ from basic_memory.mcp.tools import knowledge, search, documents
|
||||
__all__ = ["mcp", "knowledge", "search", "documents"]
|
||||
|
||||
|
||||
def setup_logging(log_file: str = "basic-memory-mcp.log"):
|
||||
def setup_logging(home_dir: str = config.home, log_file: str = "basic-memory.log"):
|
||||
"""Configure logging for the application."""
|
||||
# Remove default handler
|
||||
logger.remove()
|
||||
|
||||
log = f"{home_dir}/{log_file}"
|
||||
|
||||
# Add file handler with rotation
|
||||
logger.add(
|
||||
log_file,
|
||||
log,
|
||||
rotation="100 MB",
|
||||
retention="10 days",
|
||||
backtrace=True,
|
||||
@@ -38,6 +40,9 @@ def setup_logging(log_file: str = "basic-memory-mcp.log"):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup_logging()
|
||||
|
||||
home_dir = config.home
|
||||
setup_logging(home_dir)
|
||||
logger.info("Starting Basic Memory MCP server")
|
||||
logger.info(f"Home directory: {home_dir}" )
|
||||
mcp.run()
|
||||
Reference in New Issue
Block a user