fix: allow mining directories without local mempalace.yaml

When no mempalace.yaml or mempal.yaml exists in the source directory,
return a default config (wing = directory name, room = general) instead
of calling sys.exit(1). This lets users mine any directory into their
palace without requiring init first.

Closes #14.
This commit is contained in:
Matt Van Horn
2026-04-07 16:36:27 -07:00
committed by Igor Lins e Silva
parent 4de9e135ce
commit e8e93b53c0
2 changed files with 32 additions and 6 deletions
+17 -5
View File
@@ -264,16 +264,28 @@ def load_config(project_dir: str) -> dict:
"""Load mempalace.yaml from project directory (falls back to mempal.yaml)."""
import yaml
config_path = Path(project_dir).expanduser().resolve() / "mempalace.yaml"
resolved_project_dir = Path(project_dir).expanduser().resolve()
config_path = resolved_project_dir / "mempalace.yaml"
if not config_path.exists():
# Fallback to legacy name
legacy_path = Path(project_dir).expanduser().resolve() / "mempal.yaml"
legacy_path = resolved_project_dir / "mempal.yaml"
if legacy_path.exists():
config_path = legacy_path
else:
print(f"ERROR: No mempalace.yaml found in {project_dir}")
print(f"Run: mempalace init {project_dir}")
sys.exit(1)
print(
f" No mempalace.yaml found in {resolved_project_dir} "
"— using auto-detected defaults"
)
return {
"wing": resolved_project_dir.name,
"rooms": [
{
"name": "general",
"description": "All project files",
"keywords": ["general"],
}
],
}
with open(config_path) as f:
return yaml.safe_load(f)
+15 -1
View File
@@ -6,7 +6,7 @@ from pathlib import Path
import chromadb
import yaml
from mempalace.miner import mine, scan_project, status
from mempalace.miner import load_config, mine, scan_project, status
from mempalace.palace import NORMALIZE_VERSION, file_already_mined
@@ -52,6 +52,20 @@ def test_project_mining():
shutil.rmtree(tmpdir, ignore_errors=True)
def test_load_config_uses_defaults_when_yaml_missing():
tmpdir = tempfile.mkdtemp()
try:
project_root = Path(tmpdir).resolve()
config = load_config(str(project_root))
assert isinstance(config, dict)
assert "wing" in config
assert "rooms" in config
assert config["wing"] == project_root.name
finally:
shutil.rmtree(tmpdir)
def test_scan_project_respects_gitignore():
tmpdir = tempfile.mkdtemp()
try: