Commit graph

7341 commits

Author SHA1 Message Date
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]
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]
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
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
aseembits93
92adcb0ca5 chore: bump version to 0.20.3
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 16:12:57 -07:00
Saurabh Misra
4e55159d04
Merge pull request #1842 from codeflash-ai/remove-optimizer-tag-subagent
refactor: remove optimized-code tag from subagent XML output
2026-03-16 19:03:00 -04:00
aseembits93
56e19a3589 cleaning up 2026-03-16 16:01:20 -07:00
aseembits93
c544ce6fc7 refactor: remove optimized-code tag from subagent XML output
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 15:58:06 -07:00
Kevin Turcios
85d0d7c526 fix: normalize HASHING context in re_extract_from_cache
re_extract_from_cache was always calling add_needed_imports_from_module,
but HASHING context should use ast.unparse(ast.parse()) to normalize
whitespace for consistent hashing, matching extract_all_contexts_from_files.
2026-03-16 14:59:01 -06:00
Kevin Turcios
2cafadb980 fix: deduplicate test count calls, guard None, and log effort escalation
Build test_count_cache once before ranking instead of calling
existing_unit_test_count O(2N) times. Guard for None function_to_tests
and add debug logging when effort is escalated from medium to high.
2026-03-16 14:41:55 -06:00
Kevin Turcios
1d1d183075 fix: move Path import into TYPE_CHECKING block in code_extractor.py
Fixes ruff TC003 — Path is only used in annotations which are strings
at runtime due to `from __future__ import annotations`.
2026-03-16 14:04:27 -06:00
Kevin Turcios
e55e552698
Merge pull request #1840 from codeflash-ai/codeflash/optimize-pr1837-2026-03-16T19.38.09
️ Speed up function `_should_use_raw_project_class_context` by 42% in PR #1837 (`codeflash/optimize-pr1660-2026-03-16T18.33.59`)
2026-03-16 14:01:31 -06:00
Kevin Turcios
c7e34264dd
Merge pull request #1837 from codeflash-ai/codeflash/optimize-pr1660-2026-03-16T18.33.59
️ Speed up function `_parse_and_collect_imports` by 12% in PR #1660 (`unstructured-inference`)
2026-03-16 13:59:18 -06:00
Kevin Turcios
299853b684
Merge pull request #1838 from codeflash-ai/codeflash/optimize-pr1660-2026-03-16T19.13.06
️ Speed up function `collect_existing_class_names` by 188% in PR #1660 (`unstructured-inference`)
2026-03-16 13:59:09 -06:00
Saurabh Misra
eadb3a280c
Merge pull request #1839 from codeflash-ai/codeflash/optimize-pr1838-2026-03-16T19.35.10
️ Speed up function `_should_use_raw_project_class_context` by 51% in PR #1838 (`codeflash/optimize-pr1660-2026-03-16T19.13.06`)
2026-03-16 15:58:36 -04:00
claude[bot]
f7d0e79b3b style: fix trailing whitespace on blank lines (W293) 2026-03-16 19:41:58 +00:00
claude[bot]
f9732eea6f style: auto-fix ruff SIM110 linting issue in _is_namedtuple_class 2026-03-16 19:38:14 +00:00
codeflash-ai[bot]
63ff5756c1
Optimize _should_use_raw_project_class_context
The optimization reorders checks in `_should_use_raw_project_class_context` to perform cheap O(1) checks before expensive body iterations. Moving the `decorator_list` check from near the end to the very start eliminates ~60% of body scans when decorators are present (line profiler shows the single-pass loop dropped from 2.84ms to 2.60ms per hit). Folding the manual `_class_has_explicit_init` and `_has_descriptor_like_class_fields` calls into one body traversal with early returns cuts redundant iterations, and checking for namedtuple/dataclass before computing size metrics avoids the `_get_class_start_line` computation in ~15% of cases. This achieves a 42% runtime improvement (737µs → 518µs) with no functional regressions.
2026-03-16 19:38:13 +00:00
codeflash-ai[bot]
2d5eec2949
Optimize _should_use_raw_project_class_context
The optimization replaced `any()` generator expressions with explicit early-return for-loops in four helper functions (`_is_namedtuple_class`, `_class_has_explicit_init`, `_has_descriptor_like_class_fields`, and `_has_non_property_method_decorator`), eliminating the overhead of building generator objects and calling the `any()` builtin. Line profiler data shows `_class_has_explicit_init` dropped from 1.85 ms to 0.96 ms (48% faster), and `_is_namedtuple_class` improved from 97 µs to 53 µs (46% faster), because the optimized code avoids allocating iterator state and returns immediately upon finding a match instead of completing the generator. The 51% overall runtime improvement (1.43 ms → 948 µs) comes from these cumulative reductions in per-call overhead across thousands of invocations during AST traversal. Test suite confirms no behavioral changes across all edge cases including dataclasses, decorators, and size-limit boundaries.
2026-03-16 19:35:14 +00:00
claude[bot]
de334f725e fix: resolve TC003 and mypy operator error in code_context_extractor 2026-03-16 19:23:46 +00:00
claude[bot]
667a0a768d fix: resolve TC003 and mypy operator error in code_context_extractor 2026-03-16 19:19:40 +00:00
claude[bot]
dc9b41d90a style: auto-fix ruff linting issues in collect_existing_class_names 2026-03-16 19:16:21 +00:00
codeflash-ai[bot]
d8ec825d41
Optimize collect_existing_class_names
The optimization replaces `ast.walk(tree)` — which visits every node in the AST — with a manual stack-based traversal that only descends into container node types (`Module`, `ClassDef`, `FunctionDef`, control-flow statements, etc.) where `ClassDef` nodes can appear. This eliminates traversal of leaf nodes like `Name`, `Constant`, `Load`, and `Store`, which constitute the bulk of an AST but never contain class definitions. The profiler shows the original single-line comprehension spent 100% of runtime (117.7 ms) in `ast.walk`, while the optimized version completes in 36.1 ms (3.26× faster) by skipping ~60–80% of nodes depending on AST density. Tests confirm correctness across nested classes, control-flow scopes, and large trees with 1000+ classes.
2026-03-16 19:13:10 +00:00
claude[bot]
fa19e38efd style: add return type annotation and fix trailing whitespace in ImportCollector 2026-03-16 18:37:14 +00:00
codeflash-ai[bot]
8208a54b8b
Optimize _parse_and_collect_imports
The optimization replaced `ast.walk()` (which visits every node in the AST) with a custom `ImportCollector` visitor that only processes `ImportFrom` nodes, eliminating ~18,000 unnecessary node type-checks on a representative 48-parse benchmark where only ~3,400 nodes were actually relevant. This cuts the import-collection phase from 84.4 ms to 69.3 ms (18% faster) as seen in the profiler, while the broader pipeline improves 11% end-to-end. A few tests with minimal or deeply nested imports show slight regressions (~10%) because visitor dispatch overhead dominates when there are very few target nodes, but these cases are rare in production codebases where the hot-path callers (`build_testgen_context`, `enrich_testgen_context`) process multi-file contexts with dozens of imports.
2026-03-16 18:34:06 +00:00
Kevin Turcios
6281cd8a66 perf: fix mutation, deduplicate defs collection, and cache modules for fallback paths
Eliminates in-place mutation of caller's helpers_of_helpers dict, reuses
collect_top_level_defs_with_usages across remove + prune, and caches
parsed modules so RO/TESTGEN token-limit fallbacks avoid re-parsing files.
2026-03-16 10:36:29 -06:00
Kevin Turcios
5671562da2 perf: eliminate redundant CST parsing in get_code_optimization_context
Parse each file once instead of up to 16 times by:
- Making remove_unused_definitions_by_function_names accept/return cst.Module
- Making parse_code_and_prune_cst and add_needed_imports_from_module accept cst.Module
- Threading the parsed Module through process_file_context
- Adding extract_all_contexts_from_files that processes all 4 context types
  (READ_WRITABLE, READ_ONLY, HASHING, TESTGEN) in a single per-file pass
2026-03-16 10:11:58 -06:00
Kevin Turcios
17f4bbd6f9 refactor: simplify context extraction system (-1232 lines, -18 mypy errors)
Reduce complexity across the 4 core context extraction files through
31 incremental experiments: dead code removal, AST visitor simplification
(return False pattern), duplicated logic extraction, verbose docstring
condensation, and helper function decomposition.
2026-03-16 09:26:58 -06:00
Kevin Turcios
f71c580787 research: extract duplicated attr-reference collection from detect_unused_helper_functions 2026-03-16 01:29:35 -06:00
Kevin Turcios
c2c21da0c0 research: replace prune_cst boolean params with PruneConfig dataclass 2026-03-16 01:27:32 -06:00
Kevin Turcios
282f2ba713 Improve testgen constructor context extraction 2026-03-16 00:47:17 -06:00
Kevin Turcios
cee12fe430 fix ranking boost ordering and statement helper extraction 2026-03-15 23:29:35 -06:00