Split the monolithic context.py (117 lines) into five purpose-specific modules following single-responsibility principle: - config.py: Server-level constants (DATA_DIR, SESSIONS_DIR, PORT, STALE_EVENT_AGE, _state_lock) - agents.py: Agent-specific paths and caches (CLAUDE_PROJECTS_DIR, CODEX_SESSIONS_DIR, discovery caches) - auth.py: Authentication token generation/validation for spawn endpoint - spawn_config.py: Spawn feature configuration (PENDING_SPAWNS_DIR, rate limiting, projects watcher thread) - zellij.py: Zellij binary resolution and session management constants This refactoring improves: - Code navigation: Find relevant constants by domain, not alphabetically - Testing: Each module can be tested in isolation - Import clarity: Mixins import only what they need - Future maintenance: Changes to one domain don't risk breaking others All mixins updated to import from new module locations. Tests updated to use new import paths. Includes PROPOSED_CODE_FILE_REORGANIZATION_PLAN.md documenting the rationale and mapping from old to new locations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""Zellij integration: binary resolution, plugin path, session name, cache."""
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
# Plugin path for zellij-send-keys
|
|
ZELLIJ_PLUGIN = Path.home() / ".config" / "zellij" / "plugins" / "zellij-send-keys.wasm"
|
|
|
|
|
|
def _resolve_zellij_bin():
|
|
"""Resolve zellij binary even when PATH is minimal (eg launchctl)."""
|
|
from_path = shutil.which("zellij")
|
|
if from_path:
|
|
return from_path
|
|
|
|
common_paths = (
|
|
"/opt/homebrew/bin/zellij", # Apple Silicon Homebrew
|
|
"/usr/local/bin/zellij", # Intel Homebrew
|
|
"/usr/bin/zellij",
|
|
)
|
|
for candidate in common_paths:
|
|
p = Path(candidate)
|
|
if p.exists() and p.is_file():
|
|
return str(p)
|
|
return "zellij" # Fallback for explicit error reporting by subprocess
|
|
|
|
|
|
ZELLIJ_BIN = _resolve_zellij_bin()
|
|
|
|
# Default Zellij session for spawning
|
|
ZELLIJ_SESSION = 'infra'
|
|
|
|
# Cache for Zellij session list (avoid calling zellij on every request)
|
|
_zellij_cache = {"sessions": None, "expires": 0}
|