Commit graph

7745 commits

Author SHA1 Message Date
claude[bot]
b0f949aa33 style: normalize f-string quotes in add_codeflash_dependency_multimodule 2026-03-26 06:06:12 +00:00
HeshamHM28
f65578db3f fix mutli module 2026-03-26 08:00:35 +02:00
HeshamHM28
ec1e4d3bc0 fall back to project root when Java module_root directory doesn't exist 2026-03-26 07:38:13 +02:00
HeshamHM28
e7d07d073f Auto config 2026-03-26 06:38:33 +02:00
Sarthak Agarwal
d5f82bb48b
Merge pull request #1897 from codeflash-ai/cf-fix-tsx-syntax-validation
fix: use file-aware parser in validate_syntax for TSX support
2026-03-26 04:23:18 +05:30
mohammed ahmed
5a81195384
Merge pull request #1889 from codeflash-ai/cf-worktree-subagent-fixes
fix: harden worktree creation and improve subagent mode support
2026-03-26 00:26:52 +02:00
mohammed ahmed
607200ab03
Merge pull request #1896 from codeflash-ai/cf-fix-formatter-temp-file-extension
fix: pass language to format_generated_code for correct temp file extension
2026-03-26 00:26:38 +02:00
ali
50c8a74d14
use result failure instead of exiting the process 2026-03-26 00:03:49 +02:00
mohammed ahmed
bd0e96f2c0
Merge pull request #1900 from codeflash-ai/cf-fix-monorepo-module-resolution
fix: add monorepo root node_modules to Jest moduleDirectories
2026-03-25 23:54:20 +02:00
claude[bot]
5d2c959f42 fix: remove unreachable non-str branch in _compile_ok
The function signature `source: str` guarantees str input, making
the isinstance guard and its else branch dead code (mypy unreachable error).

Co-authored-by: mohammed ahmed <undefined@users.noreply.github.com>
2026-03-25 18:17:45 +00:00
ali
c9855e419b
fix: convert import statements inside function bodies to require() calls
AI-generated tests sometimes place `import X from 'Y'` inside jest.mock()
callbacks, describe() blocks, or other function bodies. This is invalid
JavaScript syntax (import must be top-level). Add a post-processing step
that converts indented import statements to equivalent require() calls.

Affects ~79/1026 Strapi log files showing "import/export cannot be used
outside of module code" SWC syntax errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 20:15:21 +02:00
mohammed ahmed
3346a052ff
Merge pull request #1905 from codeflash-ai/codeflash/optimize-pr1897-2026-03-25T18.07.00
️ Speed up function `_compile_ok` by 24,733% in PR #1897 (`cf-fix-tsx-syntax-validation`)
2026-03-25 20:12:54 +02:00
codeflash-ai[bot]
c82d8ecdd9
Optimize _compile_ok
Added a bounded cache (max 4096 entries) that stores boolean compile results keyed by source string, so repeated validation of identical code skips the expensive `compile()` call. The profiler shows `compile()` consumed ~99.6% of original runtime at ~226 µs per hit; cache hits now return in ~150–200 ns, yielding a 247× speedup when the same source is validated multiple times (common in workflows that re-validate unchanged snippets). Non-string inputs bypass the cache entirely to preserve original exception behavior, and the cache bound prevents unbounded memory growth in pipelines that see many unique sources.
2026-03-25 18:07:04 +00:00
claude[bot]
17d833b20e
Merge pull request #1902 from codeflash-ai/codeflash/optimize-pr1897-2026-03-25T17.23.56
️ Speed up method `PythonSupport.validate_syntax` by 573% in PR #1897 (`cf-fix-tsx-syntax-validation`)
2026-03-25 17:57:23 +00:00
claude[bot]
11c527537f
Merge pull request #1904 from codeflash-ai/codeflash/optimize-pr1902-2026-03-25T17.35.13
️ Speed up function `_compile_ok` by 134% in PR #1902 (`codeflash/optimize-pr1897-2026-03-25T17.23.56`)
2026-03-25 17:57:11 +00:00
Aseem Saxena
7dc862611e
Merge pull request #1893 from codeflash-ai/cf-auth-login-subcommand
feat: add `auth login` subcommand
2026-03-25 10:40:38 -07:00
codeflash-ai[bot]
c60c051dac
Optimize _compile_ok
Removing the `@lru_cache(maxsize=1024)` decorator eliminated per-call overhead from argument hashing and dictionary lookups that exceeded the benefit of caching, since `compile()` is already fast (~15-30 µs for typical inputs) and the function is called with mostly unique source strings in practice. The 134% speedup (26.9 ms → 11.5 ms) reflects that cache management cost dominated total runtime when processing diverse code snippets through the `validate_syntax` caller. Test results show consistent small wins across all cases, with the largest gains on short/invalid inputs where cache overhead was proportionally highest (e.g., null-byte test improved 23.9%). The single regression is the unhashable-input test (43.8% slower) because TypeError now originates from `compile()` rather than cache-key construction, but this is an edge case with negligible absolute impact.
2026-03-25 17:35:17 +00:00
claude[bot]
432d8118da fix: remove duplicate _compile_ok function definition 2026-03-25 17:26:44 +00:00
codeflash-ai[bot]
b608ed53a0
Optimize PythonSupport.validate_syntax
The optimized code extracts `compile()` into a standalone `_compile_ok` function decorated with `@lru_cache(maxsize=1024)`, enabling memoization of syntax validation results for identical source strings. This eliminates redundant AST parsing and compilation work when the same code snippet is validated multiple times, which profiler data shows was responsible for 99.3% of the original function's runtime. The test suite demonstrates a 572% overall speedup because many assertions validate repeated or similar snippets that now hit the cache, with individual test improvements ranging from 939% to 61109% on cases involving large or duplicate inputs. Memory overhead is bounded by the cache size, and correctness is preserved since `compile()` behavior remains unchanged.
2026-03-25 17:24:00 +00:00
ali
1a5216ed54
fix: add monorepo root node_modules to Jest moduleDirectories
In monorepo setups (e.g., Strapi), workspace packages are hoisted to the
root node_modules. When Jest runs from a subpackage, it can't resolve
these packages because its default moduleDirectories only includes the
local node_modules. This adds the monorepo root's node_modules to
moduleDirectories in the runtime Jest config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 19:05:20 +02:00
ali
0641930f25
fix: use cross-context type detection in V8 serializer self-test
The V8 serialization self-test used `instanceof Map` which fails in
Jest's sandboxed VM context where the Map class from v8.deserialize
differs from the test environment's Map class. This incorrectly
disabled V8 serialization, falling through to msgpack which often
also isn't resolvable in monorepo setups.

Replaced all `instanceof` checks in the serializer with
`Object.prototype.toString.call()` for cross-VM-context compatibility,
matching the pattern already used in the msgpack codepath.

Trace IDs: 003e1410, fe2ae122, fde51112 (153 affected logs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 18:47:38 +02:00
ali
8b7ebee5fa
fix: skip object literal methods during JS/TS function discovery
Shorthand method definitions inside object literals (e.g., `{ encrypt(data) {} }`)
were being discovered as optimizable functions. Since bare method syntax is only
valid inside class bodies or object literals, extracting them as standalone code
produced syntactically invalid JavaScript, failing context extraction.

Now skip method_definition nodes whose parent is an `object` node, matching
the existing skip for arrow functions in `pair` nodes.

Trace IDs: 04f07244, 01ac202f, 024a3d42, 04da127a (~274 affected logs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 18:44:08 +02:00
ali
9664307d59
fix: use file-aware parser in validate_syntax for TSX support
TypeScriptSupport.validate_syntax() always used the TYPESCRIPT parser,
which cannot parse JSX syntax. TSX files (.tsx) containing JSX were
incorrectly rejected as syntactically invalid, blocking optimization
of React components.

Added optional file_path parameter to validate_syntax across all
language support classes. When provided, the correct parser is selected
based on file extension (e.g., TSX parser for .tsx files).

Trace IDs: 00c25f79, 02697f98, fdfc6a8d (113 affected logs total)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 18:38:21 +02:00
ali
f95a06afe6
fix: pass language to format_generated_code for correct temp file extension
format_generated_code was called without the language parameter in
process_review(), defaulting to "python". This created temp files with
.py extension when formatting JS/TS code, causing prettier to fail.

Trace IDs: 11e9745d, 1578f081, 7e8abab2 (73 affected logs total)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 18:05:28 +02:00
claude[bot]
2857e84790 fix: remove invalid get_shell_rc_path patches from auth tests
Co-authored-by: Aseem Saxena <undefined@users.noreply.github.com>
2026-03-25 00:55:39 +00:00
aseembits93
ec8ad93110 login and status subcommand 2026-03-24 17:51:48 -07:00
Aseem Saxena
630dcfc126
Merge pull request #1894 from codeflash-ai/codeflash/optimize-auth_login-mn55wrey
️ Speed up function `auth_login` by 1,583%
2026-03-24 15:05:25 -07:00
codeflash-ai[bot]
7985f16000
Optimize auth_login
The optimization removed redundant operations that duplicated logic already inside `save_api_key_to_rc`. Previously, `auth_login` called `get_shell_rc_path()` (which performs `Path.home()` filesystem operations) and conditionally invoked `shell_rc_path.touch()` on Windows, then passed the result to `save_api_key_to_rc`. The optimized version calls `save_api_key_to_rc(api_key)` directly, because that function already internally calls `get_shell_rc_path()` and safely handles file creation via context managers. Line profiler shows `get_shell_rc_path()` dropped from ~1 ms to negligible per-call overhead, and `shell_rc_path.touch()` overhead was eliminated entirely. Runtime improved from 19 ms to 1.13 ms (1582% speedup) with no regressions across all test scenarios.
2026-03-24 22:04:24 +00:00
aseembits93
9ce18aca33 feat: add auth login subcommand for standalone OAuth authentication
Adds `codeflash auth login` CLI subcommand that performs the full OAuth
PKCE flow, prints the authentication URL, and saves the API key.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 13:44:16 -07:00
Mohamed Ashraf
970c9f86da fix: use 3 package components for tracer instrumentation scope (TODO-39)
Changed detect_packages_from_source() from min(2, len) to min(3, len)
so com.aerospike.client.util produces prefix com.aerospike.client
instead of com.aerospike. This reduces instrumentation to the actual
source package instead of the entire organization namespace.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:50:40 +00:00
Mohamed Ashraf
12921447b9 fix: capture real line numbers in tracer and track dropped captures (TODO-34, TODO-38)
TODO-34: TracingClassVisitor hardcoded line number to 0 because ASM's
visitMethod() doesn't provide line info. Added a pre-scan pass in
TracingTransformer.instrumentClass() that collects first line numbers
via visitLineNumber() before the instrumentation pass.

TODO-38: Serialization timeouts/failures silently dropped captures with
no visibility. Added AtomicInteger droppedCaptures counter and included
it in flush() metadata output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:50:31 +00:00
Mohamed Ashraf
5942ae9e16 fix: prefer closer config file over parent Java build file in monorepos (TODO-37)
Java detection in parse_config_file() short-circuited before the existing
depth-comparison logic, so a parent pom.xml would override a closer
package.json or pyproject.toml. Now all config sources are detected first
and the closest one to CWD wins.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:50:18 +00:00
Mohamed Ashraf
3c63b60ae4 fix: preserve pom.xml formatting in config writer and align write/remove priority
Replace xml.etree.ElementTree with text-based regex manipulation in
_write_maven_properties() and _remove_java_build_config(). ElementTree
destroys XML comments, mangles namespace declarations (ns0: prefixes),
and reformats whitespace. The new approach reads/writes pom.xml as plain
text, only touching codeflash.* property lines.

Also extracts duplicated key_map to shared _MAVEN_KEY_MAP constant and
aligns remove priority to check pom.xml first (matching write order).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 16:30:22 +00:00
ali
0f24be96d8
better message 2026-03-24 16:32:07 +02:00
ali
c799fde846
typo 2026-03-24 15:39:29 +02:00
ali
21f6e6c0c5
fix: harden worktree creation and improve subagent mode support
- Make worktree creation mandatory by exiting on failure instead of silently skipping
- Remove redundant git repo check from create_detached_worktree (caller handles it)
- Skip duplicate optimization checks in subagent mode (same as LSP)
- Log optimization results as markdown in subagent mode instead of Rich tree
- Disable custom benchmark loop overrides for subagent runs
- Downgrade Jest benchmarking failure logs from info to debug

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 15:37:00 +02:00
Kevin Turcios
6f6c0398b3
Merge pull request #1886 from codeflash-ai/codeflash-core
feat: introduce codeflash_core engine with Rich console UI
2026-03-24 04:43:21 -05:00
claude[bot]
347316fb12 style: move pathlib.Path to TYPE_CHECKING block in models.py
Fixes TC003 ruff lint error.

Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
2026-03-24 09:29:46 +00:00
Kevin Turcios
8b8d614572 Address PR review round 2: fix future exceptions, danom naming, test_command passthrough
- Wrap Future.result() in try/except in generate_tests_and_candidates to prevent
  plugin errors from aborting the entire optimization session
- Rename danom/_*.py files to remove leading underscores per project conventions
- Pass pytest_cmd through to TestConfig.test_command in resolve_test_config
2026-03-24 04:22:26 -05:00
claude[bot]
673d907f6e fix: resolve mypy type errors in codeflash_core
- Remove dead __post_init__ from FunctionToOptimize (file_path is typed as Path; str coercion was unreachable per mypy)
- Move TaskID import to runtime so DummyTask.id can be properly typed
- Remove stale type: ignore[union-attr] from strategy_evaluation

Co-authored-by: Kevin Turcios <undefined@users.noreply.github.com>
2026-03-24 09:11:46 +00:00
Kevin Turcios
136bcea403 Address PR review: remove k8bot, fix naming conventions, clean up unreachable code
- Remove k8bot strategy (nonexistent module)
- Guard PythonPlugin import with try/except ImportError
- Move logging.basicConfig into setup_logging() to avoid import-time side effects
- Rename underscore-prefixed names (_spinners, _DummyTask, etc.) to public
- Fix _pending_code_markdown → pending_code_markdown attribute access
- Simplify unreachable isinstance branch in review_and_repair_tests
- Export setup_logging from ui package
2026-03-24 04:02:03 -05:00
Kevin Turcios
f95bd5ee48 Apply ruff format to codeflash_core 2026-03-24 03:31:58 -05:00
Kevin Turcios
68a9bed026 Fix ruff lint errors in codeflash_core 2026-03-24 03:30:14 -05:00
Kevin Turcios
8e0cb59ab1 Wire Rich UI into optimizer, strategy, and evaluation pipeline
Spinners on discovery, indexing, context extraction, test/candidate
generation, baseline runs, and benchmarking. Per-function rule headers,
per-candidate progress logging, diff display on success, and a paneled
summary at the end.
2026-03-24 03:27:29 -05:00
Kevin Turcios
1fb1fb453d Update uv.lock 2026-03-24 03:24:51 -05:00
Kevin Turcios
614beee088 Add Rich-based console UI to codeflash_core
Spinner progress bars, paneled text, syntax-highlighted code display,
and RichHandler logging. Matches original codeflash patterns without
LSP/subagent concerns.
2026-03-24 03:22:42 -05:00
Kevin Turcios
be90440fdd Register codeflash_core in pyproject.toml and add missing deps
Add attrs and requests to dependencies. Include src/codeflash_core
in the sdist build target.
2026-03-24 02:03:38 -05:00
Kevin Turcios
08dc1f5c11 Add codeflash_core package under src/ layout
Bring the language-agnostic optimization engine from codeflash-next-gen.
Includes protocols, strategy, config, models, AI client, telemetry,
ranking, verification, and diff modules. TUI artifacts stripped.
2026-03-24 02:01:30 -05:00
Sarthak Agarwal
cab52ba128
Merge pull request #1883 from codeflash-ai/node_modules_symlink
node modules symlink to avoid reinstallation of npm package
2026-03-23 21:38:21 +05:30
Kevin Turcios
f7ee7b3707
Merge pull request #1884 from codeflash-ai/early-dedup
feat: early dedup of optimization candidates before benchmark loop
2026-03-23 02:07:17 -05:00