"""Entry point for the dev agent. Loads configuration, builds the agent, and stays up until told to stop. Shutdown is deliberate rather than abrupt: L8's durability guarantees assume the process may die at any moment, but a clean stop still beats relying on them. """ import os import signal import sys from pathlib import Path from types import FrameType from nisse_dev.agent import build_agent from nisse_dev.config import AgentConfig, ConfigError from nisse_dev.envfile import load_env_file def main() -> int: load_env_file(Path(os.environ.get("NISSE_ENV", ".env")).expanduser()) try: config = AgentConfig.load() except ConfigError as exc: # Fail here rather than twenty minutes into a milestone on the one # call that needed the missing value. print(f"nisse-dev: {exc}", file=sys.stderr) return 2 if config.loop == "new": from nisse_dev.loop.build import build_loop_agent agent = build_loop_agent(config) else: agent = build_agent(config) def shutdown(_signum: int, _frame: FrameType | None) -> None: print("nisse-dev: stopping", file=sys.stderr) agent.stop() signal.signal(signal.SIGINT, shutdown) signal.signal(signal.SIGTERM, shutdown) agent.start() print(f"nisse-dev: ready as {agent.account} on {config.project}", file=sys.stderr) agent.wait() return 0 if __name__ == "__main__": raise SystemExit(main())