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>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import os
|
|
from http.server import ThreadingHTTPServer
|
|
|
|
from amc_server.auth import generate_auth_token
|
|
from amc_server.config import DATA_DIR, PORT
|
|
from amc_server.spawn_config import start_projects_watcher
|
|
from amc_server.handler import AMCHandler
|
|
from amc_server.logging_utils import LOGGER, configure_logging, install_signal_handlers
|
|
from amc_server.mixins.spawn import load_projects_cache
|
|
|
|
|
|
def main():
|
|
configure_logging()
|
|
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
|
LOGGER.info("Starting AMC server")
|
|
|
|
# Initialize spawn feature
|
|
load_projects_cache()
|
|
generate_auth_token()
|
|
start_projects_watcher()
|
|
|
|
server = ThreadingHTTPServer(("127.0.0.1", PORT), AMCHandler)
|
|
install_signal_handlers(server)
|
|
LOGGER.info("AMC server listening on http://127.0.0.1:%s", PORT)
|
|
|
|
# Write PID file
|
|
pid_file = DATA_DIR / "server.pid"
|
|
pid_file.write_text(str(os.getpid()))
|
|
|
|
try:
|
|
server.serve_forever()
|
|
except KeyboardInterrupt:
|
|
LOGGER.info("AMC server interrupted; shutting down")
|
|
except Exception:
|
|
LOGGER.exception("AMC server crashed")
|
|
raise
|
|
finally:
|
|
pid_file.unlink(missing_ok=True)
|
|
server.server_close()
|
|
LOGGER.info("AMC server stopped")
|