Commit 093beb5
feat: Complete Claude SDK + Cost Optimizer Integration (#4)
* feat: add CostOptimizerClient for HTTP requests to ai-cost-optimizer
* feat: add retry logic and circuit breaker to CostOptimizerClient
* fix: implement HALF_OPEN recovery and fix race conditions in circuit breaker
- Add HALF_OPEN state implementation for auto-recovery after 60s
- Implement state transition: OPEN → HALF_OPEN → CLOSED on success
- Implement state transition: HALF_OPEN → OPEN on failure
- Fix race condition in onFailure() with atomic increment
- Remove unreachable code in callWithRetry()
- Add comprehensive tests for circuit recovery scenarios
- Add openedAt timestamp tracking for reset timeout
Resolves critical issues C1, C2 and important issue I1
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(orchestrator): integrate CostOptimizerClient into AgentOrchestrator
* fix(orchestrator): resolve naming collision and cost tracking bug
CRITICAL #1: Rename imports for clarity
- Change NewCostOptimizerClient → CostOptimizerClient (primary)
- Change LegacyCostOptimizerClient → Phase2CostOptimizerClient (descriptive)
- Update all variable references: newCostOptimizer → costOptimizer, legacyCostOptimizer → phase2CostOptimizer
CRITICAL #2: Add cost tracking to Phase 2 path
- Phase 2 client path was missing this.buildCosts.push(cost)
- This caused getBuildStats() to return incomplete data
- Now both code paths track costs consistently
All orchestrator tests passing (26/26)
Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat: add chat interface UI for Claude SDK frontend
* fix(chat): add accessibility, auto-scroll, unique IDs, and better error handling
- Add unique message IDs using crypto.randomUUID()
- Implement auto-scroll to latest message with useRef and useEffect
- Add ARIA labels (aria-label, aria-live, aria-busy, role="log")
- Improve error handling with specific messages for network errors, 429, and 500
- Update MessageList to use message.id as key instead of index
- Add scrollIntoView mock to test setup for jsdom compatibility
- Add comprehensive tests for accessibility features and error handling
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat: add chat API endpoint with Claude SDK service
* fix(chat): add input validation and clarify env var documentation
Addresses code review issues from Task 5:
CRITICAL fixes:
- Renamed misleading "sanitize input" test to "accept special characters"
- Added clear documentation for COST_OPTIMIZER_URL vs COST_OPTIMIZER_API_URL
* COST_OPTIMIZER_URL: Chat API endpoint (FastAPI port 8000)
* COST_OPTIMIZER_API_URL: Agent system endpoint (build-time routing)
IMPORTANT additions:
- Added comprehensive input validation:
* Empty message validation
* Message length validation (max 10,000 chars)
* History size validation (max 50 messages)
* History structure validation (role + content required)
- Added 6 new test cases covering all validation scenarios
- All 20 tests passing
Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat: add requirements extraction to ClaudeSDKService
* feat: connect chat interface to build orchestrator
* docs: add Task 7 implementation report and example flows
* fix(chat): add input sanitization and type safety for build status
CRITICAL SECURITY FIX #1: Shell Injection Prevention
- Added sanitizeUserInput() function to remove shell metacharacters (`, $, {, })
- Removes non-printable characters while preserving newlines/tabs
- Limits input length to 5000 chars to prevent DoS attacks
- Applied to all user input in formatUserRequest() before passing to orchestrator
- Prevents malicious inputs like `; rm -rf /` from being executed
CRITICAL TYPE SAFETY FIX #2: Replace 'any' with ProjectStatus
- Imported ProjectStatus type from AgentOrchestrator
- Updated ChatResponse interface: buildStatus?: ProjectStatus (was 'any')
- Restores full TypeScript type checking for build status responses
Testing:
- Added 4 new security tests for input sanitization:
* Verifies shell metacharacters are removed
* Verifies safe characters (letters, numbers, spaces, newlines, tabs) are preserved
* Verifies DoS prevention via length truncation
- All 20 tests passing in chat-orchestrator-integration.test.ts
Files changed:
- src/app/api/chat/route.ts (security + type safety)
- src/app/api/chat/__tests__/chat-orchestrator-integration.test.ts (4 new tests)
Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: add security fixes summary documentation
Added comprehensive documentation of all security fixes applied in Task 7:
- Shell injection prevention via input sanitization
- Type safety restoration (buildStatus: any → ProjectStatus)
- Test coverage for security vulnerabilities
- Manual verification results
This completes the documentation for Tasks 1-7 implementation.
* feat(deployment): add dual-platform deployment (Task 8) + health check (Task 9)
## Task 8: Deployment Files
- Add .dockerignore (reduces build context from 800MB to 100MB)
- Add Dockerfile.runpod (3-stage alpine build, non-root user, port 8080)
- Add vercel.json (Next.js config, security headers, iad1 region)
- Add deploy-dual-platform.yml (test → build → deploy workflow)
## Task 9: Health Check Endpoint
- Enhance /api/health with service connectivity checks
- Support GET and HEAD requests
- Check: api, costOptimizer (5s timeout), database
- Return: healthy/degraded/unhealthy status
- Add 23 comprehensive tests
## Platform Requirements
- Mac Silicon → RunPod: GitHub Actions with docker buildx --platform linux/amd64
- Vercel: Direct deployment with vercel --prod
Tests: 89 new tests passing (23 health + 66 chat integration)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: resolve all build errors for Vercel deployment
- Remove unused MCP server API routes (no longer needed)
- Remove /auth/callback/page.tsx (route conflict with route.ts)
- Wrap useSearchParams in Suspense boundary (Next.js 15 requirement)
- Add Organization export to cost-optimizer types
- Fix async cookies() calls for Supabase server client
- Simplify vercel.json configuration
Build passes with only deprecation warnings (metadata viewport).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6e92742 commit 093beb5
49 files changed
Lines changed: 7541 additions & 1122 deletions
File tree
- .github/workflows
- docs
- public
- src
- agents
- app
- api
- auth/github
- chat
- __tests__
- github
- pr
- repos
- health
- mcp
- health
- unified
- models
- auth
- callback
- mfa/verify
- reset-password
- chat
- __tests__
- lib/supabase
- orchestrator
- __tests__
- services
- __tests__
- cost-optimizer/database
- monitoring
- types
- tests
- api
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
| 73 | + | |
62 | 74 | | |
63 | 75 | | |
64 | 76 | | |
| |||
0 commit comments