Skip to content

feat: unified multi-language hook with single codeflash trigger#34

Open
mashraf-222 wants to merge 5 commits intomainfrom
feat/multi-language-support
Open

feat: unified multi-language hook with single codeflash trigger#34
mashraf-222 wants to merge 5 commits intomainfrom
feat/multi-language-support

Conversation

@mashraf-222
Copy link
Contributor

@mashraf-222 mashraf-222 commented Mar 19, 2026

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 --subagent call — the CLI handles multi-language dispatch.

This PR is part of a 3-repo change set:

  • codeflash — Multi-language orchestration loop, config discovery, and language-agnostic git diff
  • codeflash-cc-plugin (this PR) — Unified hook that triggers a single codeflash --subagent call
  • optimize-me — Mixed-language test fixture (Python + Java + JS/TS) for E2E validation

The 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.
  • Single trigger — One codeflash --subagent call instead of 3 language-specific invocations.
  • BASH_SOURCE guard pattern — Functions above the guard for testability, preamble and main flow inside the guard so sourcing the file for tests doesn't trigger execution.

Net reduction: 463 → 297 lines (-166 lines). Simpler AND more capable.

Plugin Metadata

  • Updated marketplace.json and plugin.json to reflect multi-language support.
  • Updated optimizer agent prompt and skill definitions.

Tests

19 bats-core tests in tests/suggest_optimize.bats covering:

  • Config detection (pyproject.toml, codeflash.toml, package.json)
  • Binary discovery (uv, npx, pip, PATH)
  • Guard pattern verification
  • Edge cases (no config found, binary not installed)

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 to main.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 single codeflash --subagent and 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

mashraf-222 and others added 2 commits March 18, 2026 22:22
…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>
mashraf-222 and others added 3 commits March 19, 2026 03:47
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant