Commit graph

6259 commits

Author SHA1 Message Date
Kevin Turcios
82b40029c7
Merge pull request #1499 from codeflash-ai/codeflash/optimize-pr1498-2026-02-16T20.49.33
️ Speed up function `_parse_and_collect_imports` by 69% in PR #1498 (`cf-simplify-context-extraction`)
2026-02-16 16:03:22 -05:00
claude[bot]
bfa55cb128 fix: handle ast.Match (Python 3.10+) in collect_imports traversal
The optimized collect_imports missed match/case statements where imports
can legally appear. Add hasattr-guarded handling for ast.Match nodes.

Co-authored-by: Kevin Turcios <KRRT7@users.noreply.github.com>
2026-02-16 21:02:03 +00:00
Kevin Turcios
cc77394bf4
Merge pull request #1500 from codeflash-ai/codeflash/optimize-pr1498-2026-02-16T20.53.40
️ Speed up function `collect_existing_class_names` by 351% in PR #1498 (`cf-simplify-context-extraction`)
2026-02-16 15:59:32 -05:00
Kevin Turcios
ea14b2f548
Update codeflash/languages/python/context/code_context_extractor.py
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-02-16 15:59:22 -05:00
claude[bot]
69d32681f7 style: auto-fix linting issues 2026-02-16 20:55:52 +00:00
codeflash-ai[bot]
4ff98658c2
Optimize collect_existing_class_names
The optimized code achieves a **350% speedup** (2.36ms → 523μs) by replacing the generic `ast.walk()` traversal with a targeted stack-based iteration that only visits nodes where class definitions can appear.

**Key Performance Improvement:**

The original implementation uses `ast.walk(tree)`, which performs an exhaustive depth-first traversal of **every single node** in the AST—including expressions, literals, operators, and other leaf nodes that can never contain class definitions. For a typical Python module, this means checking thousands of irrelevant nodes.

The optimized version uses a stack-based approach that only descends into structural nodes (ClassDef, FunctionDef, If, For, While, With, Try blocks) where classes can actually be defined. This dramatically reduces the number of nodes visited and `isinstance()` checks performed.

**Why This Matters:**

From the test results, we see consistent 200-700% speedups across all scenarios:
- Empty modules: 579% faster (5.37μs → 791ns) - minimal traversal overhead
- Simple cases: 200-400% faster - fewer nodes to check
- Complex nested structures: 405% faster (37.2μs → 7.37μs) - targeted descent pays off
- Large modules (500 classes): 280% faster (869μs → 228μs) - scales better
- Mixed workloads: 558% faster (799μs → 121μs) - avoids non-class nodes

**Impact on Workloads:**

Based on the function references showing this is called from `build_testgen_context`, this optimization benefits test generation workflows that analyze Python code structure. Since class extraction is likely performed repeatedly during code analysis, the 4x speedup directly improves overall test generation throughput. The optimization is particularly effective for large codebases with many classes and complex nesting patterns, as demonstrated by the benchmark results.
2026-02-16 20:53:44 +00:00
claude[bot]
29c0a66a9b fix: resolve mypy type errors in collect_imports 2026-02-16 20:52:37 +00:00
claude[bot]
73e71d00e7 style: auto-fix linting issues 2026-02-16 20:51:51 +00:00
codeflash-ai[bot]
bace6112a4
Optimize _parse_and_collect_imports
The optimization achieves a **68% runtime improvement** (23.5ms → 14.0ms) by replacing the expensive `ast.walk()` traversal with a targeted recursive collection strategy.

**Key Performance Improvement:**

The original code uses `ast.walk(tree)` which visits **every single node** in the AST tree (12,947 hits shown in line profiler), consuming 71.7% of total runtime. This includes unnecessary nodes like expressions, literals, and operators that can never contain `ImportFrom` statements.

The optimized version implements a custom `collect_imports()` function that:
1. **Only traverses module body and control flow structures** where imports can legally appear (function/class definitions, if/while/for blocks, try/except)
2. **Skips irrelevant AST nodes** like expressions, literals, and operators entirely
3. **Recursively processes nested bodies** (body, orelse, finalbody, handlers) in a depth-first manner

**Why This Works:**

In Python, `from X import Y` statements can only appear:
- At module level
- Inside function/class definitions
- Within control flow blocks (if/while/for/try)

By checking `isinstance()` for only these container node types and recursively descending into their body attributes, we avoid traversing the entire AST subtree for each construct. This dramatically reduces the number of nodes visited while maintaining correctness.

**Test Case Performance:**

The optimization excels across all scales:
- **Small imports** (single statements): 60-77% faster
- **Large import lists** (100-500 items): 74-104% faster  
- **Many code blocks** (500-1000 lines): 70-77% faster
- **Mixed code/imports** at scale: 70% faster

The performance gain is particularly pronounced when the AST contains large amounts of non-import code (functions, classes, expressions), as shown by the `test_mixed_imports_and_code_large_scale` case improving from 9.31ms to 5.45ms (70.8% faster).

**Impact on Workloads:**

Given the function_references show this is used in code context extraction benchmarks, this optimization will significantly speed up any workflow that analyzes Python imports from large codebases or performs repeated import analysis during development workflows.
2026-02-16 20:49:37 +00:00
Kevin Turcios
fadf6d4139 fix: restore progressive fallback for context token limits
Re-add graceful degradation when context exceeds token limits instead
of raising ValueError immediately. Read-only context falls back to
removing docstrings then removing entirely. Testgen context falls back
to removing docstrings then removing enrichment before raising.
2026-02-16 15:18:38 -05:00
Kevin Turcios
8566cf0510 fix: update mypy allowlist paths and fix BaseSuite type narrowing
Update stale context/ paths in mypy_allowlist.txt to match the
languages/python/context/ move. Add assert to narrow BaseSuite to
IndentedBlock in prune_cst for mypy.
2026-02-16 15:10:58 -05:00
Kevin Turcios
b1ec82413e refactor: delegate PythonSupport context methods to canonical pipeline
Replace duplicate implementations in extract_code_context() and
find_helper_functions() with calls to get_code_optimization_context()
and get_function_sources_from_jedi() from the canonical context module.
2026-02-16 15:02:44 -05:00
Kevin Turcios
547c02e8bc refactor: move context extraction modules to languages/python/context/
Move code_context_extractor.py and unused_definition_remover.py from
codeflash/context/ to codeflash/languages/python/context/ and update
all import sites.
2026-02-16 14:49:04 -05:00
Kevin Turcios
fa00422fea refactor: simplify and deduplicate code_context_extractor
Consolidate three enricher functions (get_imported_class_definitions,
get_external_base_class_inits, get_external_class_inits) into a single
enrich_testgen_context that parses code context once. Extract shared
helpers, unify prune_cst variants, deduplicate loop bodies, and remove
dead UsedNameCollector class.
2026-02-16 13:34:07 -05:00
mohammed ahmed
b4ea8b6bd6
Update packages/codeflash/runtime/loop-runner.js
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-02-16 19:26:51 +02:00
ali
d13cdb559b
fallback to directly require the jest-runner module inside the loop runner 2026-02-16 19:11:27 +02:00
ali
bfe4224de8
just for testing 2026-02-16 18:35:31 +02:00
ali
5e25b7f3b6
debugging for failed workflow 2026-02-16 18:29:17 +02:00
ali
2d73cf88bb
typo 2026-02-16 14:55:49 +02:00
ali
066980b06f
Merge branch 'fix/jest30-pnpm-resolution' of github.com:codeflash-ai/codeflash into fix/jest30-pnpm-resolution 2026-02-16 14:36:55 +02:00
ali
2fb4b2dbfd
cleaning up 2026-02-16 14:36:39 +02:00
mohammed ahmed
56941357c9
Update packages/codeflash/runtime/loop-runner.js
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
2026-02-16 14:35:33 +02:00
mohammed ahmed
31e7116b84
Merge branch 'main' into fix/jest30-pnpm-resolution 2026-02-16 14:34:23 +02:00
ali
2e77f85834
fix: resolve jest-runner from project's node_modules for Jest 30 compatibility
The loop-runner was loading jest-runner from codeflash's node_modules (v29)
instead of the project's (v30), causing "runtime.enterTestCode is not a function"
errors. This fix:

- Adds recursive search to find jest-runner in any node_modules structure
- Works with npm, yarn, and pnpm (including non-hoisted deps)
- Prefers higher versions when multiple are found
- Removes internal looping in capturePerf when using external loop-runner
- Creates fresh TestRunner per batch to avoid Jest 30 state corruption

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 14:31:08 +02:00
Kevin Turcios
d578d9969b
Merge pull request #1494 from codeflash-ai/add-private-tessl-tiles
feat: add private tessl tiles for rules, docs, and skills
2026-02-14 22:01:50 -05:00
Kevin Turcios
869fbe1766 chore: add eval scenarios for codeflash-docs tile
5 scenarios testing: code serialization format, candidate lifecycle/DAG,
deterministic patches, effort levels/selection criteria, and function
representation/concurrency model.
2026-02-14 21:29:22 -05:00
Kevin Turcios
ff2abd29f2 chore: add eval scenarios for codeflash-skills tile
5 scenarios testing: sequential debugging, Result type + effort config,
test patterns, domain type conventions, and deduplication/repair mechanics.
Also adds tessl-labs/tessl-skill-eval-scenarios dev dependency.
2026-02-14 21:24:54 -05:00
Kevin Turcios
289b75c555 chore: add tessl-managed gitignore for codex and gemini skill symlinks 2026-02-14 21:08:25 -05:00
Kevin Turcios
18ad00be59 chore: improve skills to 100% review score and bump to v0.2.0
- Add trigger hints and code snippets to both skills
- Add checkpoints after each step
- Extract module reference and troubleshooting into linked files
- Bump codeflash-skills tile to 0.2.0
2026-02-14 21:07:24 -05:00
Kevin Turcios
6718e66582 feat: add private tessl tiles for codeflash rules, docs, and skills
Three private tiles in the codeflash workspace:
- codeflash-rules: 6 steering rules (code-style, architecture, optimization-patterns, git-conventions, testing-rules, language-rules)
- codeflash-docs: 7 doc pages (domain-types, optimization-pipeline, context-extraction, verification, ai-service, configuration)
- codeflash-skills: 2 skills (debug-optimization-failure, add-codeflash-feature)
2026-02-14 20:55:06 -05:00
Kevin Turcios
90601c3324
Merge pull request #1492 from codeflash-ai/tessl/setup-1771114839280
Setup repository to use Tessl
2026-02-14 20:20:11 -05:00
tessl-app[bot]
9282e254ea
Add MCP config for .mcp.json 2026-02-15 00:20:41 +00:00
tessl-app[bot]
9af75a66bb
Initialize tessl.json with matched tiles 2026-02-15 00:20:40 +00:00
Kevin Turcios
dbba5e00cb
Merge pull request #1491 from codeflash-ai/replace-ghaw-with-foundry-detector
chore: replace gh-aw duplicate detector with claude-code-action + Serena
2026-02-14 19:06:02 -05:00
Kevin Turcios
02b9a5e226 chore: replace gh-aw duplicate detector with claude-code-action + Serena
gh-aw doesn't support Azure Foundry auth. Use claude-code-action directly
with use_foundry and Serena MCP server for semantic code analysis.
2026-02-14 19:05:47 -05:00
Kevin Turcios
de78ffe6c3
Merge pull request #1490 from codeflash-ai/fix-duplicate-detector-foundry
fix: configure duplicate code detector for Azure Foundry
2026-02-14 18:29:00 -05:00
Kevin Turcios
0bb62d647f docs: add new-branch-from-main rule to git guidelines 2026-02-14 18:28:15 -05:00
Kevin Turcios
9961a02411 docs: add new-branch-from-main rule to git guidelines 2026-02-14 18:27:21 -05:00
Kevin Turcios
ef661394b7 fix: configure duplicate code detector for Azure Foundry auth
Pass ANTHROPIC_FOUNDRY_API_KEY and ANTHROPIC_FOUNDRY_BASE_URL env vars
so Claude Code CLI authenticates via Azure Foundry instead of direct API.
2026-02-14 18:26:00 -05:00
Kevin Turcios
b3c3a30dd9
Merge pull request #1487 from codeflash-ai/add-duplicate-code-detector
chore: add gh-aw duplicate code detector workflow
2026-02-14 18:15:01 -05:00
Kevin Turcios
f819d6061e chore: add gh-aw duplicate code detector workflow
Adds automated duplicate code detection using GitHub Agentic Workflows
with Serena semantic analysis, configured for Python.
2026-02-14 18:14:16 -05:00
Kevin Turcios
53f8658b9d
Merge pull request #1486 from codeflash-ai/restructure-claude-md
refactor: restructure CLAUDE.md for effective context usage
2026-02-14 17:38:24 -05:00
Kevin Turcios
0650973d8c refactor: restructure CLAUDE.md for effective context usage
- Remove commands block from CLAUDE.md (standard tool usage Claude knows)
- Remove dead @AGENTS.md reference
- Add optimization pipeline overview with module pointers
- Add domain glossary (optimization candidate, addressable time, candidate
  forest, replay test, tracer, worktree mode)
- Extract mypy workflow to .claude/skills/fix-mypy.md (on-demand)
- Create .claude/skills/fix-prek.md for prek workflow (on-demand)
- Add key entry points table to architecture.md
- Create path-scoped rules: optimization-patterns.md, language-patterns.md
- Remove redundancy from source-code.md and across rules files
- Move "never use pip" convention to code-style.md
2026-02-14 17:37:51 -05:00
Kevin Turcios
42a1150ffd
Merge pull request #1481 from codeflash-ai/include-external-class-inits-in-testgen
feat: include external class __init__ signatures with transitive type deps in testgen context
2026-02-13 17:51:03 -05:00
Kevin Turcios
4f44286787 chore: upgrade all dependencies in lockfile 2026-02-13 10:26:50 -05:00
Kevin Turcios
15c307a97c fix: normalize jest mock paths with pathlib for Windows compat
os.path.relpath returns backslashes on Windows. The backslash-to-slash
conversion happened after the ./ / ../ prefix check, so the check
failed and prepended ./ producing ./../src/... paths. Use
Path.as_posix() instead of manual string replacement.
2026-02-13 10:10:50 -05:00
Kevin Turcios
29a5324148 docs: distinguish local vs CI prek commands in CLAUDE.md 2026-02-13 09:57:32 -05:00
Kevin Turcios
83c6d5cdd2 fix: import jest patterns from source module instead of re-export
The formatter correctly removed the unused re-exports from
parse_test_output.py. Update the test to import directly from
codeflash.languages.javascript.parse.
2026-02-13 09:55:14 -05:00
Kevin Turcios
c3fe9ec43d style: clean up imports in parse_test_output 2026-02-13 09:48:22 -05:00
Kevin Turcios
6de75e7bab chore: disable ruff B009 globally to avoid conflict with mypy [misc] 2026-02-13 09:48:18 -05:00