Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions codeflash/code_utils/git_worktree_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from codeflash.cli_cmds.console import logger
from codeflash.code_utils.compat import codeflash_cache_dir
from codeflash.code_utils.git_utils import check_running_in_git_repo, git_root_dir
from codeflash.code_utils.git_utils import git_root_dir

worktree_dirs = codeflash_cache_dir / "worktrees"
patches_dir = codeflash_cache_dir / "patches"
Expand Down Expand Up @@ -53,10 +53,7 @@ def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) ->
cw.remove_option("user", "email")


def create_detached_worktree(module_root: Path) -> Optional[Path]:
if not check_running_in_git_repo(module_root):
logger.warning("Module is not in a git repository. Skipping worktree creation.")
return None
def create_detached_worktree() -> Optional[Path]:
git_root = git_root_dir()
current_time_str = time.strftime("%Y%m%d-%H%M%S")
worktree_dir = worktree_dirs / f"{git_root.name}-{current_time_str}"
Expand Down
5 changes: 2 additions & 3 deletions codeflash/discovery/functions_to_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from codeflash.discovery.discover_unit_tests import discover_unit_tests
from codeflash.languages.language_enum import Language
from codeflash.languages.registry import get_language_support, get_supported_extensions, is_language_supported
from codeflash.lsp.helpers import is_LSP_enabled
from codeflash.lsp.helpers import is_LSP_enabled, is_subagent_mode
from codeflash.models.function_types import FunctionParent, FunctionToOptimize
from codeflash.telemetry.posthog_cf import ph

Expand Down Expand Up @@ -759,8 +759,7 @@ def was_function_previously_optimized(
Tuple of (filtered_functions_dict, remaining_count)

"""
if is_LSP_enabled():
# was_function_previously_optimized is for the checking the optimization duplicates in the github action, no need to do this in the LSP mode
if is_LSP_enabled() or is_subagent_mode():
return False

# Check optimization status if repository info is provided
Expand Down
2 changes: 2 additions & 0 deletions codeflash/languages/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,8 @@ def process_single_candidate(
# Display runtime information
if is_LSP_enabled():
lsp_log(LspMarkdownMessage(markdown=tree_to_markdown(tree)))
elif is_subagent_mode():
logger.info(tree_to_markdown(tree))
else:
console.print(tree)
if self.args.benchmark and benchmark_tree:
Expand Down
6 changes: 3 additions & 3 deletions codeflash/languages/javascript/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,9 @@ def run_jest_benchmarking_tests(
# Create result with combined stdout
result = subprocess.CompletedProcess(args=result.args, returncode=result.returncode, stdout=stdout, stderr="")
if result.returncode != 0:
logger.info(f"Jest benchmarking failed with return code {result.returncode}")
logger.info(f"Jest benchmarking stdout: {result.stdout}")
logger.info(f"Jest benchmarking stderr: {result.stderr}")
logger.debug(f"Jest benchmarking failed with return code {result.returncode}")
logger.debug(f"Jest benchmarking stdout: {result.stdout}")
logger.debug(f"Jest benchmarking stderr: {result.stderr}")

except subprocess.TimeoutExpired:
logger.warning(f"Jest benchmarking timed out after {total_timeout}s")
Expand Down
23 changes: 14 additions & 9 deletions codeflash/optimization/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import copy
import os
import sys
import tempfile
import time
from collections import defaultdict
Expand Down Expand Up @@ -780,15 +781,19 @@ def worktree_mode(self) -> None:
if self.current_worktree:
return

if check_running_in_git_repo(self.args.module_root):
worktree_dir = create_detached_worktree(self.args.module_root)
if worktree_dir is None:
logger.warning("Failed to create worktree. Skipping optimization.")
return
self.current_worktree = worktree_dir
self.mirror_paths_for_worktree_mode(worktree_dir)
# make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty
Path(self.args.tests_root).mkdir(parents=True, exist_ok=True)
if not check_running_in_git_repo(self.args.module_root):
logger.error("Worktree creation failed because the current directory is not part of a Git repository.")
sys.exit(1)

worktree_dir = create_detached_worktree()
if worktree_dir is None:
logger.error("Failed to create a worktree.")
sys.exit(1)

self.current_worktree = worktree_dir
self.mirror_paths_for_worktree_mode(worktree_dir)
# make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty
Path(self.args.tests_root).mkdir(parents=True, exist_ok=True)

def mirror_paths_for_worktree_mode(self, worktree_dir: Path) -> None:
original_args = copy.deepcopy(self.args)
Expand Down
Loading