feat: AI auto-fix + Gemini Flash provider #93

Merged
chihlasm merged 14 commits from feat/ai-autofix-gemini into main 2026-02-27 07:32:24 +00:00
chihlasm commented 2026-02-26 22:36:15 +00:00 (Migrated from github.com)

Summary

  • Gemini 2.5 Flash as primary AI provider with Claude Haiku as fallback, behind a unified AIProvider abstraction (ai_provider.py)
  • AI-powered auto-fix for validation errors — "Fix with AI" button in the tree editor's validation panel generates structural fixes using AI, with a review modal for applying each fix
  • Migrated existing AI tree generator from direct Anthropic SDK calls to the new provider abstraction

New env vars for deployment

Variable Default Notes
AI_PROVIDER gemini "gemini" or "anthropic"
GOOGLE_AI_API_KEY Required for Gemini (falls back to Anthropic if missing)

Backend changes

  • ai_provider.pyGeminiProvider + AnthropicProvider + get_ai_provider() factory with fallback
  • ai_fix_service.py — Builds targeted prompts per failing node (full tree outline + node detail + error), validates fix by substituting into tree copy, retries once with corrective prompt
  • POST /ai/fix-tree endpoint — rate limited (10/min), requires engineer role
  • ai_fix.py schemas — Request/response Pydantic models
  • Refactored ai_tree_generator_service.py to use provider abstraction
  • Config: AI_PROVIDER, GOOGLE_AI_API_KEY, AI_MODEL_GEMINI, AI_MODEL_ANTHROPIC

Frontend changes

  • "Fix with AI" button in ValidationSummary (appears when there are fixable structural errors)
  • AIFixReviewModal — before/after JSON diff per fix, Apply/Skip per fix, Apply All
  • TreeEditorPage orchestrates the flow: validate → fix → review → apply → re-validate

Test plan

  • 639 backend tests pass (including 47 new AI-specific tests)
  • Frontend build passes clean
  • Set GOOGLE_AI_API_KEY in Railway Shared Variables
  • Verify AI Flow Builder still works with Gemini provider
  • Create a flow with validation errors, click "Fix with AI", verify fixes are proposed and can be applied

🤖 Generated with Claude Code

## Summary - **Gemini 2.5 Flash as primary AI provider** with Claude Haiku as fallback, behind a unified `AIProvider` abstraction (`ai_provider.py`) - **AI-powered auto-fix for validation errors** — "Fix with AI" button in the tree editor's validation panel generates structural fixes using AI, with a review modal for applying each fix - **Migrated existing AI tree generator** from direct Anthropic SDK calls to the new provider abstraction ## New env vars for deployment | Variable | Default | Notes | |----------|---------|-------| | `AI_PROVIDER` | `gemini` | `"gemini"` or `"anthropic"` | | `GOOGLE_AI_API_KEY` | — | Required for Gemini (falls back to Anthropic if missing) | ## Backend changes - `ai_provider.py` — `GeminiProvider` + `AnthropicProvider` + `get_ai_provider()` factory with fallback - `ai_fix_service.py` — Builds targeted prompts per failing node (full tree outline + node detail + error), validates fix by substituting into tree copy, retries once with corrective prompt - `POST /ai/fix-tree` endpoint — rate limited (10/min), requires engineer role - `ai_fix.py` schemas — Request/response Pydantic models - Refactored `ai_tree_generator_service.py` to use provider abstraction - Config: `AI_PROVIDER`, `GOOGLE_AI_API_KEY`, `AI_MODEL_GEMINI`, `AI_MODEL_ANTHROPIC` ## Frontend changes - "Fix with AI" button in `ValidationSummary` (appears when there are fixable structural errors) - `AIFixReviewModal` — before/after JSON diff per fix, Apply/Skip per fix, Apply All - `TreeEditorPage` orchestrates the flow: validate → fix → review → apply → re-validate ## Test plan - [ ] 639 backend tests pass (including 47 new AI-specific tests) - [ ] Frontend build passes clean - [ ] Set `GOOGLE_AI_API_KEY` in Railway Shared Variables - [ ] Verify AI Flow Builder still works with Gemini provider - [ ] Create a flow with validation errors, click "Fix with AI", verify fixes are proposed and can be applied 🤖 Generated with [Claude Code](https://claude.com/claude-code)
railway-app[bot] commented 2026-02-26 22:36:25 +00:00 (Migrated from github.com)

🚅 Deployed to the patherly-pr-93 environment in selfless-grace

Service Status Web Updated (UTC)
patherly Success (View Logs) Web Feb 27, 2026 at 5:15 am
hopeful-liberation Success (View Logs) Web Feb 27, 2026 at 5:15 am
<!-- railway-bot-comment-version=2 --> <!-- railway-project-id="22b9b58c-271b-42e5-a10e-6fdec8d00134" railway-project-name="selfless-grace" --> 🚅 Deployed to the [patherly-pr-93](https://railway.com/project/22b9b58c-271b-42e5-a10e-6fdec8d00134?environmentId=a41d743f-2e8d-43bf-abee-07a6387faf78) environment in **[selfless-grace](https://railway.com/project/22b9b58c-271b-42e5-a10e-6fdec8d00134)** | **Service** | **Status** | **Web** | **Updated** (UTC) | | :--- | :--- | :--- | :--- | | patherly | ✅ Success ([View Logs](https://railway.com/project/22b9b58c-271b-42e5-a10e-6fdec8d00134/service/95f556ff-5264-4116-a0c2-618a2fc53ba4?id=3cfc2aa6-4732-4d2e-9e88-e7f3379b1d68&environmentId=a41d743f-2e8d-43bf-abee-07a6387faf78)) | [Web](https://patherly-patherly-pr-93.up.railway.app) | Feb 27, 2026 at 5:15 am | | hopeful-liberation | ✅ Success ([View Logs](https://railway.com/project/22b9b58c-271b-42e5-a10e-6fdec8d00134/service/e1db2ee3-d241-4f45-abe4-c9c5fdf483d5?id=f82e7f4e-e612-438f-8b18-70d7e821c7b9&environmentId=a41d743f-2e8d-43bf-abee-07a6387faf78)) | [Web](https://hopeful-liberation-patherly-pr-93.up.railway.app) | Feb 27, 2026 at 5:15 am |
Sign in to join this conversation.