77import os
88import signal
99import shlex
10+ from pathlib import Path
1011from dotenv import load_dotenv
1112from agentevolver .utils .daemon import LaunchCommandWhenAbsent
1213
@@ -98,9 +99,32 @@ def parse_args():
9899 return parser .parse_args ()
99100
100101
102+ def _require_service_env (service_name : str ):
103+ """Return (path, script) for the companion service, validating env vars."""
104+ env_prefix = service_name .upper ()
105+ service_path = os .environ .get (f'{ env_prefix } _PATH' )
106+ service_script = os .environ .get (f'{ env_prefix } _SCRIPT' )
107+ missing = []
108+ if not service_path :
109+ missing .append (f'{ env_prefix } _PATH' )
110+ if not service_script :
111+ missing .append (f'{ env_prefix } _SCRIPT' )
112+ if missing :
113+ example_hint = ""
114+ example_env = Path ("example.env" )
115+ if example_env .exists ():
116+ example_hint = (
117+ f" Copy the relevant entries from { example_env } into your .env file."
118+ )
119+ raise RuntimeError (
120+ f"Missing environment variable(s) required to launch '{ service_name } ': "
121+ f"{ ', ' .join (missing )} .{ example_hint } "
122+ )
123+ return service_path , service_script
124+
125+
101126def pty_launch (service_name : str , success_std_string = "Starting server on" ):
102- service_path = os .environ .get (f'{ service_name .upper ()} _PATH' )
103- service_script = os .environ .get (f'{ service_name .upper ()} _SCRIPT' )
127+ service_path , service_script = _require_service_env (service_name )
104128 companion = LaunchCommandWhenAbsent (
105129 full_argument_list = [service_script ],
106130 dir = service_path ,
@@ -393,4 +417,4 @@ def main():
393417 sys .exit (1 )
394418
395419if __name__ == "__main__" :
396- main ()
420+ main ()
0 commit comments