@@ -84,23 +84,15 @@ def __init__(self, dry_run: bool = False):
8484 self .dry_run = dry_run
8585 self .bot_username = os .environ .get ("GH_USER_NAME" , "" )
8686 self .gl_username = os .environ .get ("GL_USER_NAME" , "" )
87- self .instance_id = os .environ .get ("BOT_INSTANCE_ID" , "" )
88- self .config_path = os .environ .get ("BOT_CONFIG_PATH" , "rehor-config" )
87+
88+ # Auto-discover config directory and instance ID
89+ self .config_dir , self .config_name , self .instance_id = self ._discover_config ()
8990
9091 # Validate inputs
9192 self ._validate_inputs ()
9293
93- # Determine config directory
94- # Use remote-config if it exists (bot runtime), else fall back to local config
95- if REMOTE_CONFIG_DIR .exists () and (REMOTE_CONFIG_DIR / self .config_path ).exists ():
96- self .config_dir = REMOTE_CONFIG_DIR
97- logger .info (f"Using remote config at { self .config_dir } " )
98- else :
99- self .config_dir = SCRIPT_DIR / self .config_path
100- logger .info (f"Using local config at { self .config_dir } " )
101-
10294 self .agent_dir = (
103- self .config_dir / self .config_path / "agent"
95+ self .config_dir / self .config_name / "agent"
10496 if self .config_dir == REMOTE_CONFIG_DIR
10597 else self .config_dir / "agent"
10698 )
@@ -110,6 +102,53 @@ def __init__(self, dry_run: bool = False):
110102 self .repos_to_fork : List [RepoInfo ] = []
111103 self .forked_repos : Dict [str , str ] = {} # name -> fork_url
112104
105+ def _discover_config (self ) -> Tuple [Path , str , str ]:
106+ """
107+ Auto-discover config directory and instance ID.
108+
109+ Searches for project-repos.json in:
110+ 1. data/remote-config/*/agent/project-repos.json (bot runtime)
111+ 2. <config-name>/agent/project-repos.json (local dev)
112+
113+ Returns:
114+ Tuple of (config_dir, config_name, instance_id)
115+
116+ Raises:
117+ ValueError: If no valid config directory found
118+ """
119+ # Try remote-config first (bot runtime)
120+ if REMOTE_CONFIG_DIR .exists ():
121+ for subdir in REMOTE_CONFIG_DIR .iterdir ():
122+ if not subdir .is_dir ():
123+ continue
124+ candidate = subdir / "agent" / "project-repos.json"
125+ if candidate .exists ():
126+ config_name = subdir .name
127+ # Extract instance_id from config name if present
128+ # Pattern: rehor-config-instance1 -> instance1
129+ instance_id = ""
130+ if "-" in config_name :
131+ parts = config_name .split ("-" )
132+ if len (parts ) > 2 : # e.g. rehor-config-instance1
133+ instance_id = "-" .join (parts [2 :])
134+ logger .info (f"Using remote config at { REMOTE_CONFIG_DIR / config_name } " )
135+ return REMOTE_CONFIG_DIR , config_name , instance_id
136+
137+ # Fall back to local config (dev environment)
138+ # Try common config directory names
139+ for config_name in ["rehor-config" , "config" ]:
140+ local_config = SCRIPT_DIR / config_name
141+ candidate = local_config / "agent" / "project-repos.json"
142+ if candidate .exists ():
143+ logger .info (f"Using local config at { local_config } " )
144+ return local_config , config_name , ""
145+
146+ raise ValueError (
147+ "No config directory found. Expected project-repos.json in:\n "
148+ f" - { REMOTE_CONFIG_DIR } /*/agent/project-repos.json\n "
149+ f" - { SCRIPT_DIR } /<config-name>/agent/project-repos.json"
150+ )
151+
113152 def _validate_inputs (self ) -> None :
114153 """
115154 Validate required environment variables and inputs.
@@ -124,9 +163,6 @@ def _validate_inputs(self) -> None:
124163 if not re .match (r"^[a-zA-Z0-9]([a-zA-Z0-9-]{0,37}[a-zA-Z0-9])?$" , self .bot_username ):
125164 raise ValueError (f"Invalid GitHub username: { self .bot_username } " )
126165
127- if not self .config_path :
128- raise ValueError ("BOT_CONFIG_PATH cannot be empty" )
129-
130166 def detect_unforkable_repos (self ) -> OperationResult :
131167 """
132168 Scan project-repos.json for repos needing forks.
0 commit comments