feat: unified multi-language hook with single codeflash trigger#34
Open
mashraf-222 wants to merge 5 commits intomainfrom
Open
feat: unified multi-language hook with single codeflash trigger#34mashraf-222 wants to merge 5 commits intomainfrom
mashraf-222 wants to merge 5 commits intomainfrom
Conversation
…tection - Replace 3 per-language code paths (JS/Java/Python ~320 lines) with unified architecture - Add detect_any_config() that checks all config types at each directory level - Add find_codeflash_binary() with venv -> PATH -> uv run -> npx resolution - Add detect_changed_languages() for language-aware NOT-CONFIGURED setup messages - Single codeflash --subagent trigger for configured projects regardless of language - Reduce script from 463 lines to 297 lines Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Restructure suggest-optimize.sh: move function definitions above guard,
wrap preamble and main flow in BASH_SOURCE guard for testability
- Create test_helper.bash with shared setup/teardown and load_hook_functions
- Create suggest_optimize.bats with 19 tests covering:
- detect_any_config: codeflash.toml, pyproject.toml, package.json, multiple
configs, missing configs, skipping without codeflash section
- find_codeflash_binary: PATH, venv, not installed, venv-over-PATH priority
- detect_changed_languages: python, java, javascript (js/ts/jsx/tsx), mixed,
unrecognized files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolves merge conflict by keeping the unified multi-language architecture (detect_any_config, find_codeflash_binary, single trigger) and integrating main's OAuth PKCE login features (has_api_key, OAUTH_SCRIPT, LOGIN_STEP, API key check before running). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Set CHECK_DIR before sourcing find-venv.sh (moved after detect_any_config) - Update integration tests to match unified hook behavior: - "NOT installed" tests use restricted PATH with mock uv/npx - JS tests assert "codeflash --subagent" instead of "npx codeflash --subagent" - No-venv tests assert install prompt instead of "create venv" prompt - Not-configured tests no longer embed install assertions - Add not_installed_path() and setup_mock_uv_no_codeflash() test helpers All 51 tests pass (19 unit + 25 integration + 7 find-venv). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In CI there's no API key, so has_api_key() returns false and the hook shows the OAuth login prompt instead of reaching the auto-allow message. The Python auto-allow test already passed CODEFLASH_API_KEY=cf-test-key; now the JS tests do too. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces 3 separate per-language code paths in the hook script with a single unified architecture. The hook now detects any codeflash config, finds the binary, and fires one
codeflash --subagentcall — the CLI handles multi-language dispatch.This PR is part of a 3-repo change set:
codeflash --subagentcallThe hook delegates all language-specific logic to the CLI. When new languages are added to Codeflash, the hook works automatically without changes.
What Changed
Unified Hook (
scripts/suggest-optimize.sh)detect_any_config()— Walks up from CWD to find any codeflash config file (pyproject.toml with[tool.codeflash], codeflash.toml, package.json with codeflash key). Returns on first match.find_codeflash_binary()— Locates the codeflash binary by checking uv, npx, pip, and PATH in order.codeflash --subagentcall instead of 3 language-specific invocations.Net reduction: 463 → 297 lines (-166 lines). Simpler AND more capable.
Plugin Metadata
Tests
19 bats-core tests in
tests/suggest_optimize.batscovering:All tests pass locally.
Related PRs
codeflash — Multi-language orchestration loop
This is the CLI-side counterpart that makes the unified hook possible. Previously, the hook needed per-language logic because the CLI could only process one language per invocation. The codeflash PR adds
find_all_config_files()and a multi-language orchestration loop tomain.py, so the CLI now discovers all language configs and runs a full optimization pass for each. That's why this hook can now fire a singlecodeflash --subagentand let the CLI handle everything — the complexity moved from the hook into the CLI where it belongs.optimize-me — Mixed-language test fixture
The optimize-me repo was extended with Java and JS/TS subprojects so there's a real mixed-language project to validate the full flow: this hook detects a config → triggers the CLI → the CLI discovers all three language configs → runs optimization passes. The E2E validation was performed by running the hook flow against the optimize-me fixture and confirming all languages were discovered and processed.
Generated with Claude Code