"""Spawn feature config: paths, locks, rate limiting, projects watcher.""" import threading from pathlib import Path from amc_server.config import DATA_DIR # Pending spawn registry PENDING_SPAWNS_DIR = DATA_DIR / "pending_spawns" # Pending spawn TTL: how long to keep unmatched spawn records (seconds) PENDING_SPAWN_TTL = 60 # Projects directory for spawning agents PROJECTS_DIR = Path.home() / 'projects' # Lock for serializing spawn operations (prevents Zellij race conditions) _spawn_lock = threading.Lock() # Rate limiting: track last spawn time per project (prevents spam) _spawn_timestamps: dict[str, float] = {} SPAWN_COOLDOWN_SEC = 10.0 def start_projects_watcher(): """Start background thread to refresh projects cache every 5 minutes.""" import logging from amc_server.mixins.spawn import load_projects_cache def _watch_loop(): import time while True: try: time.sleep(300) load_projects_cache() except Exception: logging.exception('Projects cache refresh failed') thread = threading.Thread(target=_watch_loop, daemon=True) thread.start()