Skip to content

Commit d21a088

Browse files
mashraf-222claude
andcommitted
fix: address review feedback — git root boundary, JS opt-in, help flag
- Stop upward config walk at git repo root to prevent picking up configs from parent directories outside the project - Require "codeflash" key in package.json for JS/TS multi-language discovery, matching Python's [tool.codeflash] opt-in model - Remove accidental add_help=False from optimize subparser Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1175a98 commit d21a088

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

codeflash/cli_cmds/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def _build_parser() -> ArgumentParser:
410410
compare_parser.add_argument("--timeout", type=int, default=600, help="Benchmark timeout in seconds (default: 600)")
411411
compare_parser.add_argument("--config-file", type=str, dest="config_file", help="Path to pyproject.toml")
412412

413-
trace_optimize = subparsers.add_parser("optimize", help="Trace and optimize your project.", add_help=False)
413+
trace_optimize = subparsers.add_parser("optimize", help="Trace and optimize your project.")
414414

415415
trace_optimize.add_argument(
416416
"--max-function-count",

codeflash/code_utils/config_parser.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,16 @@ def _check_dir_for_configs(dir_path: Path, configs: list[LanguageConfig], seen_l
206206
package_json = dir_path / "package.json"
207207
if package_json.exists():
208208
try:
209-
result = parse_package_json_config(package_json)
210-
if result is not None:
211-
config, path = result
212-
lang = Language(config.get("language", "javascript"))
213-
seen_languages.add(lang)
214-
configs.append(LanguageConfig(config=config, config_path=path, language=lang))
209+
import json
210+
211+
pkg_data = json.loads(package_json.read_text(encoding="utf-8"))
212+
if isinstance(pkg_data, dict) and "codeflash" in pkg_data:
213+
result = parse_package_json_config(package_json)
214+
if result is not None:
215+
config, path = result
216+
lang = Language(config.get("language", "javascript"))
217+
seen_languages.add(lang)
218+
configs.append(LanguageConfig(config=config, config_path=path, language=lang))
215219
except Exception:
216220
logger.debug("Failed to parse JS/TS config in %s", dir_path, exc_info=True)
217221

@@ -237,11 +241,30 @@ def find_all_config_files(start_dir: Path | None = None) -> list[LanguageConfig]
237241
configs: list[LanguageConfig] = []
238242
seen_languages: set[Language] = set()
239243

240-
# Walk upward from start_dir to filesystem root (closest config wins per language)
244+
# Determine the git root as the upward walk boundary.
245+
# Without this, a pyproject.toml in ~ would be picked up from any subdirectory.
246+
git_root: Path | None = None
247+
try:
248+
import subprocess
249+
250+
result = subprocess.run(
251+
["git", "rev-parse", "--show-toplevel"],
252+
capture_output=True,
253+
text=True,
254+
cwd=start_dir,
255+
)
256+
if result.returncode == 0:
257+
git_root = Path(result.stdout.strip()).resolve()
258+
except Exception:
259+
pass
260+
261+
# Walk upward from start_dir to git root (closest config wins per language)
241262
dir_path = start_dir.resolve()
242263
while True:
243264
_check_dir_for_configs(dir_path, configs, seen_languages)
244265

266+
if git_root is not None and dir_path == git_root:
267+
break
245268
parent = dir_path.parent
246269
if parent == dir_path:
247270
break

0 commit comments

Comments
 (0)