Commit graph

7374 commits

Author SHA1 Message Date
aseembits93
71d6e5e093 fix: resolve test module path for JS when tests are outside tests_project_rootdir
For JavaScript projects, generated tests are placed near the source file
(e.g., code_to_optimize/js/.../tests/codeflash-generated/) rather than
under tests_project_rootdir. This caused module_name_from_file_path to
crash with ValueError. Fall back to project_root_path when the test path
isn't under tests_project_rootdir.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 14:52:00 -07:00
Sarthak Agarwal
32decd746c
Merge pull request #1858 from codeflash-ai/fix/add_lang_ext_support_to_diff
add_lang_ext_support_to_diff
2026-03-18 18:45:09 +05:30
Kevin Turcios
948bfedfa0
Merge pull request #1852 from codeflash-ai/cf-1846-port-perf-improvements
perf: cache jedi project, batch test cache writes, fix Windows relative_to bug
2026-03-17 18:54:31 -06:00
claude[bot]
7cf183e787 fix: add else branch for parsed_dst_module to resolve mypy None narrowing
The early `parsed_dst_module = None` assignment broke mypy's type narrowing.
Add explicit `else: parsed_dst_module = dst_module_code` so mypy sees the
variable is always a `cst.Module` before the `.visit()` call.

Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
2026-03-18 00:21:47 +00:00
Kevin Turcios
bf9adf2673 fix: normalize module fallback formatting for import merge 2026-03-17 18:16:54 -06:00
Aseem Saxena
506eb44648
Merge pull request #1855 from codeflash-ai/fix/git-diff-multi-language-extension-filter
fix: git diff auto-detection filters by current language instead of hardcoding .py
2026-03-17 17:02:22 -07:00
claude[bot]
16f588c1b0 fix: use perf_counter_ns instead of time_ns for benchmark timing precision
time.time_ns() has ~15ms resolution on Windows, causing fast benchmark
functions to record 0 ns elapsed time and fail timing assertions.
time.perf_counter_ns() provides ~100ns resolution on all platforms.

Co-authored-by: Aseem Saxena <aseembits93@users.noreply.github.com>
2026-03-17 23:51:38 +00:00
Sarthak Agarwal
5ecbd46c1c add_lang_ext_support_to_diff 2026-03-18 05:10:20 +05:30
claude[bot]
ba7feb0795 fix: restore fallback behavior and fix type narrowing in add_needed_imports_from_module
- Remove silent .lstrip("\n") on fallback for cst.Module input (restores original behavior)
- Replace `parsed_dst_module is None` with `isinstance(dst_module_code, str)` for correct mypy narrowing
- Change get_jedi_project return type from object to Any for accuracy

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 21:38:11 +00:00
Mohamed Ashraf
87eedac002 fix: git diff auto-detection filters by current language instead of hardcoding .py
get_git_diff() hardcoded `.py` as the only valid file extension, causing
the auto-detect flow (no --file flag) to return 0 functions for Java,
JavaScript, and TypeScript projects. This broke the Claude Code plugin
integration where the hook runs `codeflash --subagent` without --file.

Now uses current_language_support().file_extensions to filter by the
active language's extensions dynamically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 18:40:41 +00:00
mohammed ahmed
1e92f3d2ed
Merge pull request #1814 from codeflash-ai/fix/js-replacement-stale-line-numbers-after-global-declarations
fix: re-discover function position after add_global_declarations shifts line numbers
2026-03-17 17:17:51 +02:00
Sarthak Agarwal
d10f18a4bb
Merge pull request #1836 from codeflash-ai/fix/symlink-node-modules-in-worktree
fix: symlink node_modules in worktree for JS/TS projects
2026-03-17 20:42:18 +05:30
ali
3bbaf26008
test: add unit tests for node_modules symlink in JS worktree setup
Covers setup_test_config symlinking node_modules from original repo
to worktree, including edge cases (no worktree, missing node_modules,
already existing node_modules).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 16:54:34 +02:00
ali
52a04e820c
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/symlink-node-modules-in-worktree 2026-03-17 16:41:21 +02:00
ali
040d19bf29
handle overload methods 2026-03-17 15:35:31 +02:00
ali
1282a103cd
Merge branch 'main' of github.com:codeflash-ai/codeflash into fix/js-replacement-stale-line-numbers-after-global-declarations 2026-03-17 15:11:40 +02:00
mohammed ahmed
6e867c959c
Merge pull request #1525 from codeflash-ai/feat/enable-coverage-check-all-languages
feat: enable coverage check for js/ts
2026-03-17 15:09:36 +02:00
ali
7a3808a230
enable coverage check for js/ts 2026-03-17 14:35:20 +02:00
ali
1bce740190
Merge branch 'main' of github.com:codeflash-ai/codeflash into feat/enable-coverage-check-all-languages 2026-03-17 14:35:03 +02:00
Kevin Turcios
fbd0007f13 fix: resolve Python 3.9 isinstance union type and extra blank lines in flat output
- Replace  with
   in
  _maybe_strip_docstring — the | syntax for runtime isinstance is Python 3.10+
  only and caused TypeError on 3.9
- Strip leading newlines from cst.Module.code in add_needed_imports_from_module
  fallback path so early-exit returns are consistent with the normal
  transformed_module.code.lstrip("\n") path, fixing extra blank lines after
  file headers in read_writable_code.flat output

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-17 03:18:04 -06:00
Kevin Turcios
d6c8a0a5f7
Merge pull request #1854 from codeflash-ai/cleanup/remove-dead-code
remove dead code
2026-03-17 02:35:44 -06:00
claude[bot]
96d20d376c fix: correct has_module_level_imports early-exit check in add_needed_imports_from_module
The generator expression yielded `isinstance(stmt, ...)` where `stmt` was
already filtered to be `cst.SimpleStatementLine`, so it always returned False.
This caused add_needed_imports_from_module to always skip adding imports,
breaking 11 tests in test_code_context_extractor.py.

Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
2026-03-17 08:28:54 +00:00
Kevin Turcios
7e675e46bc fix: remove extra blank line to pass ruff format 2026-03-17 02:18:56 -06:00
claude[bot]
b2ccf4cb40 fix: remove deleted cli_common.py from mypy_allowlist.txt
Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-17 08:18:45 +00:00
claude[bot]
dc8548f409 fix: remove duplicate _maybe_strip_docstring definition causing mypy no-redef error
Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-17 08:14:32 +00:00
claude[bot]
8f571ccd0f fix: resolve mypy "Name _ already defined" error in registry.py
Replace three `from X import support as _` patterns with a loop using
`importlib.import_module()`, eliminating the duplicate name binding.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-03-17 08:13:04 +00:00
claude[bot]
e820e11d20
Merge pull request #1853 from codeflash-ai/codeflash/optimize-pr1852-2026-03-17T06.54.17
️ Speed up function `re_extract_from_cache` by 18,223% in PR #1852 (`cf-1846-port-perf-improvements`)
2026-03-17 07:49:03 +00:00
claude[bot]
8dc6d9eeda fix: remove test for deleted create_pyproject_toml function
The function was removed in the dead code cleanup but the test file still
imported it and had a TestCreatePyprojectToml class, causing ImportError.

Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 07:48:19 +00:00
claude[bot]
d1a128dcda style: auto-fix ruff import sorting and remove redundant noqa comments
- Merge duplicate `from codeflash.cli_cmds.console import` lines (I001)
- Remove unused `# noqa: F401` from `support as _` imports in registry.py (RUF100)

Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 07:44:13 +00:00
Kevin Turcios
8f060237dd Move apologize_and_exit to console.py, delete cli_common.py
Function now lives alongside the console/logger it depends on.
Updated all 8 callers to import from cli_cmds.console instead.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-17 01:38:43 -06:00
Kevin Turcios
dd87a37db8 Remove dead inquirer wrapper functions from cli_common.py
inquirer_wrapper, inquirer_wrapper_path, split_string_to_cli_width,
and split_string_to_fit_width were replaced by direct inquirer usage
with CodeflashTheme and rich.prompt.Confirm. Only apologize_and_exit
remains.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-17 01:09:56 -06:00
Kevin Turcios
185ebbd348 Remove dead code identified by Skylos static analysis
- Remove orphaned api/schemas.py entirely (unused schema layer)
- Remove aiservice.py: optimize_python_code, get_jit_rewritten_code, optimize_python_code_refinement alias
- Remove CodeNormalizer ABC tombstone from normalizer.py
- Remove TestFiles.get_by_type, TestResults.get_all_ids from models.py
- Remove create_pyproject_toml from config_writer.py
- Remove markdown_pattern_python_only from models.py
- Remove LOGGING_FORMAT from logging_config.py
- Fix self-referential import in treesitter.extract_calling_function_source
- Add # noqa: F401 to side-effect support imports in registry.py

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-03-17 01:01:20 -06:00
codeflash-ai[bot]
5b52fba96a
Optimize re_extract_from_cache
The optimization added early-exit logic to `add_needed_imports_from_module` that checks whether the source module contains any module-level imports before invoking the heavyweight `GatherImportsVisitor` and downstream import-merging machinery. In the common case where a pruned module has no imports (or only nested ones inside functions), line profiling showed the gatherer and two `AddImportsVisitor`/`RemoveImportsVisitor` transforms consumed 36% of original runtime; the early exit skips all three, falling back to the destination code immediately. A second early exit after gathering verifies the visitor actually collected imports, avoiding redundant CST transformations when the source is import-free. Combined, these checks eliminate ~99% of the work when imports are absent, yielding an 18222% speedup with no semantic change because the fallback path always returned the correct destination code.
2026-03-17 06:54:22 +00:00
claude[bot]
9f20cdf33f fix: correct pending_rows type annotation to int | TestType 2026-03-17 06:33:18 +00:00
Kevin Turcios
5060c0811a perf: cache jedi project, batch test cache writes, fix Windows relative_to bug
Port valuable improvements from #1846 that remain applicable after #1660:
- Cache jedi.Project instances via @cache to avoid recreating across 5 call sites
- Fix unguarded relative_to() in get_code_optimization_context (Windows 8.3 paths)
- Pre-group references by parent function in get_function_sources_from_jedi for O(1) lookup
- Batch TestsCache writes with flush() + executemany instead of per-row commit
- Gracefully disable cache writes on sqlite3.OperationalError
- Build functions_to_optimize_by_name dict for O(1) fallback lookup in process_test_files
- Derive all_defs from all_names via is_definition() to save a redundant Jedi call
2026-03-17 00:25:52 -06:00
Kevin Turcios
a0a2a85020
Merge pull request #1660 from codeflash-ai/unstructured-inference
feat: improve function ranking with reference graph and test-based boosting
2026-03-16 23:05:28 -06:00
Kevin Turcios
8af7fdc093 fix: address review items — type annotation, optimize _find_class_node_by_name and ancestors
- Fix duplicate type annotation for test_count_cache in optimizer.py
- Replace ast.walk() with stack-based traversal in _find_class_node_by_name (21x speedup)
- Use list instead of deque in CallGraph.ancestors (34% speedup, order doesn't matter for set result)
2026-03-16 22:48:46 -06:00
Kevin Turcios
4822d1a890
Merge pull request #1851 from codeflash-ai/cf-update-claude-rules
docs: improve Claude rules based on eval results
2026-03-16 22:05:34 -06:00
Kevin Turcios
e5a487c608 docs: strengthen Claude rules based on eval results
Eval showed docstrings, tmp_path, and .resolve() rules were being
ignored. Made phrasing more explicit and added concrete examples.
2026-03-16 21:48:53 -06:00
Kevin Turcios
b809cb3463
Merge pull request #1850 from codeflash-ai/codeflash/optimize-pr1660-2026-03-17T03.31.35
️ Speed up function `_expr_matches_name` by 26% in PR #1660 (`unstructured-inference`)
2026-03-16 21:45:39 -06:00
codeflash-ai[bot]
d87b6ad9c7
Optimize _expr_matches_name
The optimization replaced recursive calls in `_get_expr_name` with an iterative loop that walks attribute chains once, collecting parts into a list and reversing them only at the end, eliminating function-call overhead that dominated 46% of original runtime (line profiler shows recursive calls at 1154 ns/hit vs. the new loop iterations at ~300 ns/hit). Additionally, `_expr_matches_name` now precomputes `"." + suffix` once instead of building it twice per invocation via f-strings, cutting redundant string allocations. The net 26% runtime improvement comes primarily from avoiding Python's recursion stack and reducing temporary object creation in the hot path, with all tests passing and only minor per-test slowdowns (typically 10–25%) offset by dramatic wins on deep attribute chains (up to 393% faster for 100-level nesting).
2026-03-17 03:31:39 +00:00
Kevin Turcios
46dd0be9a7 docs: improve Claude rules based on eval results
Expanded bug fix workflow to explicit 5-step sequence with subagent delegation, aligned type annotation rule with codebase conventions, simplified verification rule to reference prek, and expanded git/PR guidelines.
2026-03-16 20:45:32 -06:00
Saurabh Misra
e5980c1f2a
Merge pull request #1848 from codeflash-ai/java-runtime-annotations-fix
fix: filter Java runtime annotations by class name and fix ordering
2026-03-16 19:33:18 -07:00
misrasaurabh1
6c3f626c9e fix: filter Java runtime annotations by class name and fix ordering
Runtime annotations in PR descriptions were broken in two ways:
1. add_runtime_comments() ignored class/method prefixes in keys, causing
   annotations from unrelated test classes to leak across files and sum
   incorrectly at the same line number. Now filters by class names found
   in each test source file.
2. Test functions were removed before annotations were added, shifting
   line numbers so annotations landed on wrong lines. Swapped ordering
   so annotations are applied first, then function removal carries them
   along correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 17:51:57 -07:00
Saurabh Misra
f73b9a3713
Merge pull request #1847 from codeflash-ai/fix-some-files
revert config
2026-03-16 19:59:21 -04:00
claude[bot]
c0577e5732
Merge pull request #1845 from codeflash-ai/codeflash/optimize-pr1660-2026-03-16T23.30.46
️ Speed up function `collect_existing_class_names` by 109% in PR #1660 (`unstructured-inference`)
2026-03-16 23:59:16 +00:00
misrasaurabh1
e565b5f49c revert 2026-03-16 16:58:57 -07:00
claude[bot]
a508ef6a6c fix: add explicit list[ast.AST] type annotation for stack in collect_existing_class_names 2026-03-16 23:33:30 +00:00
codeflash-ai[bot]
3994f255a9
Optimize collect_existing_class_names
The optimization replaced a large multi-type `isinstance()` check (13 AST node types constructed into a tuple on every iteration) with a single `hasattr(node, "body")` test, then conditionally checked for `orelse`, `finalbody`, and `handlers` only when `body` exists. Line profiler shows the original `isinstance` block consumed ~40% of runtime across 7327 calls, while the new `hasattr` checks are ~3× cheaper per call. The nested conditionals avoid calling `getattr` with default values when attributes are absent (e.g., `orelse` is missing in 85% of nodes), cutting wasted attribute lookups from four unconditional `getattr` calls to typically one or two `hasattr` checks plus direct accesses. Across 59 test runs processing ~7300 AST nodes each, this yields a 109% speedup with identical correctness.
2026-03-16 23:30:49 +00:00
Kevin Turcios
6c82fad943
Merge pull request #1844 from codeflash-ai/bump-version-0.20.3
chore: release v0.20.3
2026-03-16 17:14:52 -06:00