88
99import os
1010import sys
11- from pathlib import Path
12- from typing import TYPE_CHECKING
11+ from typing import TYPE_CHECKING , Callable
1312
1413if "--subagent" in sys .argv :
1514 os .environ ["CODEFLASH_SUBAGENT_MODE" ] = "true"
1615 import warnings
1716
1817 warnings .filterwarnings ("ignore" )
1918
20- from codeflash .cli_cmds .cli import parse_args , process_pyproject_config
21- from codeflash .cli_cmds .console import paneled_text
22- from codeflash .code_utils import env_utils
23- from codeflash .code_utils .checkpoint import ask_should_use_checkpoint_get_functions
24- from codeflash .code_utils .config_parser import parse_config_file
25- from codeflash .code_utils .version_check import check_for_newer_minor_version
26-
2719if TYPE_CHECKING :
2820 from argparse import Namespace
2921
3022
3123def main () -> None :
3224 """Entry point for the codeflash command-line interface."""
25+ # Fast path: --version exits before importing the full stack
26+ if len (sys .argv ) == 2 and sys .argv [1 ] == "--version" :
27+ from codeflash .version import __version__
28+
29+ print (f"Codeflash version { __version__ } " )
30+ return
31+
32+ from pathlib import Path
33+
34+ from codeflash .cli_cmds .cli import parse_args , process_pyproject_config
35+ from codeflash .code_utils import env_utils
36+ from codeflash .code_utils .checkpoint import ask_should_use_checkpoint_get_functions
37+ from codeflash .code_utils .config_parser import parse_config_file
38+ from codeflash .code_utils .version_check import check_for_newer_minor_version
3339 from codeflash .telemetry import posthog_cf
3440 from codeflash .telemetry .sentry import init_sentry
3541
@@ -89,7 +95,7 @@ def main() -> None:
8995 ask_run_end_to_end_test (args )
9096 else :
9197 # Check for first-run experience (no config exists)
92- loaded_args = _handle_config_loading (args )
98+ loaded_args = _handle_config_loading (args , process_pyproject_config )
9399 if loaded_args is None :
94100 sys .exit (0 )
95101 args = loaded_args
@@ -105,14 +111,17 @@ def main() -> None:
105111 optimizer .run_with_args (args )
106112
107113
108- def _handle_config_loading (args : Namespace ) -> Namespace | None :
114+ def _handle_config_loading (
115+ args : Namespace , process_pyproject_config : Callable [[Namespace ], Namespace ]
116+ ) -> Namespace | None :
109117 """Handle config loading with first-run experience support.
110118
111119 If no config exists and not in CI, triggers the first-run experience.
112120 Otherwise, loads config normally.
113121
114122 Args:
115123 args: CLI args namespace.
124+ process_pyproject_config: Config processing function.
116125
117126 Returns:
118127 Updated args with config loaded, or None if user cancelled first-run.
@@ -157,6 +166,7 @@ def print_codeflash_banner() -> None:
157166 Renders the Codeflash ASCII logo inside a non-expanding panel titled with
158167 https://codeflash.ai, using bold gold text for visual emphasis.
159168 """
169+ from codeflash .cli_cmds .console import paneled_text
160170 from codeflash .cli_cmds .console_constants import CODEFLASH_LOGO
161171
162172 paneled_text (
0 commit comments