"""
Simple configuration for Continuity.
Just key=value format, no complexity.
"""
from pathlib import Path
[docs]
class ContinuityConfig:
"""Simple configuration container."""
def __init__(self, ai_agent_nickname=None, human_user=None):
"""Initialize with defaults.
Args:
ai_agent_nickname: Nickname for AI agent (optional)
human_user: Human username (optional)
"""
# User settings
self.ai_agent_nickname = ai_agent_nickname or "Ada"
self.human_user = human_user or "human"
# System defaults
self.max_posts_per_thread = 20
self.max_message_preview = 200
self.status_timeout = 10
self.default_editor = "vim"
self.default_viewer = "less"
[docs]
@classmethod
def load(cls, config_path=None):
"""Load config from file or use defaults."""
config = cls()
# Use .continuity/config, searching up directory tree if needed
if config_path is None:
config_path = cls._find_project_config_path()
if config_path and config_path.exists():
with open(config_path) as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
if "=" in line:
key, value = line.split("=", 1)
key = key.strip()
value = value.strip().strip("\"'")
if hasattr(config, key):
setattr(config, key, value)
return config
@classmethod
def _find_project_config_path(cls):
"""Find project config by searching up directory tree."""
try:
current_dir = Path.cwd()
except (OSError, FileNotFoundError):
# Can't determine directory - no config
return None
# Check for project-specific .continuity folder
project_continuity = current_dir / ".continuity"
if project_continuity.exists():
return project_continuity / "config"
# Walk up the directory tree looking for .continuity
for parent in current_dir.parents:
project_continuity = parent / ".continuity"
if project_continuity.exists():
return project_continuity / "config"
# No project found - return None
return None
[docs]
def save(self, config_path):
"""Save config to file.
Args:
config_path: Path to config file
"""
# Ensure parent directory exists
config_path.parent.mkdir(parents=True, exist_ok=True)
# Write config in key=value format
with open(config_path, "w", encoding="utf-8") as f:
f.write("# Continuity Configuration\n")
f.write(f"ai_agent_nickname={self.ai_agent_nickname}\n")
f.write(f"human_user={self.human_user}\n")
f.write(f"max_posts_per_thread={self.max_posts_per_thread}\n")
f.write(f"max_message_preview={self.max_message_preview}\n")
f.write(f"status_timeout={self.status_timeout}\n")
f.write(f"default_editor={self.default_editor}\n")
f.write(f"default_viewer={self.default_viewer}\n")
[docs]
def get_storage_path(self):
"""Return .continuity path in project directory."""
# Find project root by searching up directory tree
try:
current_dir = Path.cwd()
except (OSError, FileNotFoundError) as err:
# Can't determine directory
raise RuntimeError("Cannot determine current directory") from err
# Check current directory first
if (current_dir / ".continuity").exists():
return current_dir / ".continuity"
# Walk up the directory tree
for parent in current_dir.parents:
if (parent / ".continuity").exists():
return parent / ".continuity"
# No project found
raise RuntimeError("No continuity project found. Run 'continuity init' first.")
[docs]
def get_project_root(self) -> Path:
"""Return the project root directory (contains .continuity folder)."""
try:
current_dir = Path.cwd()
except (OSError, FileNotFoundError) as err:
raise RuntimeError("Cannot determine current directory") from err
# Check current directory first
if (current_dir / ".continuity").exists():
return current_dir
# Walk up the directory tree
for parent in current_dir.parents:
if (parent / ".continuity").exists():
return parent
# No project found
raise RuntimeError("No continuity project found. Run 'continuity init' first.")
[docs]
def get_project_name(self) -> str:
"""Return the current project name (directory name)."""
return self.get_project_root().name
@property
def ai_user(self):
"""Internal AI username."""
return "agent"