refactor(server): extract amc_server package from monolithic script
Split the 860+ line bin/amc-server into a modular Python package:
amc_server/
__init__.py - Package marker
context.py - Shared constants (DATA_DIR, PORT, CLAUDE_PROJECTS_DIR, etc.)
handler.py - AMCHandler class using mixin composition
logging_utils.py - Structured logging setup with signal handlers
server.py - Main entry point (ThreadingHTTPServer)
mixins/
__init__.py - Mixin package marker
control.py - Session control (dismiss, respond via Zellij)
conversation.py - Conversation history parsing (Claude JSONL format)
discovery.py - Session discovery (Codex pane inspection, Zellij cache)
http.py - HTTP response helpers (CORS, JSON, static files)
parsing.py - Session state parsing and aggregation
state.py - Session state endpoint logic
The monolithic bin/amc-server becomes a thin launcher that just imports
and calls main(). This separation enables:
- Easier testing of individual components
- Better IDE support (proper Python package structure)
- Cleaner separation of concerns (discovery vs parsing vs control)
- ThreadingHTTPServer instead of single-threaded (handles concurrent requests)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
27
amc_server/handler.py
Normal file
27
amc_server/handler.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
|
||||
from amc_server.mixins.conversation import ConversationMixin
|
||||
from amc_server.mixins.control import SessionControlMixin
|
||||
from amc_server.mixins.discovery import SessionDiscoveryMixin
|
||||
from amc_server.mixins.http import HttpMixin
|
||||
from amc_server.mixins.parsing import SessionParsingMixin
|
||||
from amc_server.mixins.state import StateMixin
|
||||
|
||||
|
||||
class AMCHandler(
|
||||
HttpMixin,
|
||||
StateMixin,
|
||||
ConversationMixin,
|
||||
SessionControlMixin,
|
||||
SessionDiscoveryMixin,
|
||||
SessionParsingMixin,
|
||||
BaseHTTPRequestHandler,
|
||||
):
|
||||
"""HTTP handler composed from focused mixins."""
|
||||
|
||||
def handle(self):
|
||||
"""Ignore expected disconnect noise from short-lived HTTP/SSE clients."""
|
||||
try:
|
||||
super().handle()
|
||||
except (ConnectionResetError, BrokenPipeError):
|
||||
return
|
||||
Reference in New Issue
Block a user