#!/usr/bin/env python3 """ Matrix Bridge Daemon — connects Lucy's Matrix DM to the local agent API. Polling loop that listens for new messages in a Matrix room, forwards them to the AI agent framework, and sends responses back. Usage: python3 main.py # Normal mode python3 main.py --config path/to.json # Custom config python3 main.py --debug # Verbose logging """ from __future__ import annotations import argparse import logging import os import sys from config import Config from bridge import Bridge def setup_logging(debug: bool = False) -> None: """Configure logging format and level.""" level = logging.DEBUG if debug else logging.INFO logging.basicConfig( level=level, format="%(asctime)s [%(levelname)s] %(message)s", handlers=[logging.StreamHandler(sys.stdout)], ) def main() -> None: parser = argparse.ArgumentParser( description="Matrix Bridge Daemon — connects Matrix DMs to the agent API", ) parser.add_argument( "--config", default=os.path.join(os.path.dirname(__file__), "config.json"), help="Path to configuration file (default: config.json)", ) parser.add_argument( "--debug", action="store_true", help="Enable verbose DEBUG-level logging", ) args = parser.parse_args() setup_logging(debug=args.debug) log = logging.getLogger("matrix-bridge") # Load configuration try: config = Config.load(args.config) except Exception as e: log.error(f"Failed to load config from {args.config}: {e}") sys.exit(1) # Create and run the bridge bridge = Bridge(config) # Verify agent API is reachable if bridge.agent._request("GET", "/api/sessions") is not None: log.info("Agent API is reachable") else: log.warning("Agent API not reachable — will retry in main loop") bridge.run() if __name__ == "__main__": main()