JavaScript SDK Code Analyzer
A specialized skill for efficiently searching and analyzing JavaScript SDK code across repositories, with built-in support for LLM integration patterns and code optimization workflows.
Description
This skill enables AI agents to analyze, refactor, and optimize JavaScript codebases with a focus on SDK development patterns. It emphasizes DRY and SOLID principles, functional programming paradigms, and best practices for integrating Large Language Models into JavaScript applications. The skill is particularly useful for cursor-based code navigation and automated code quality analysis.
Instructions
When working with JavaScript SDK code, follow these steps and guidelines:
1. Code Analysis and Quality Assessment
**Identify Code Smells**: Scan for violations of DRY (Don't Repeat Yourself) and SOLID principles**Check Modularity**: Verify that functions and classes adhere to single-responsibility principle**Assess Readability**: Evaluate variable/function naming conventions, comment quality, and code structure**Review Error Handling**: Ensure robust error handling with proper validation and sanitization**Security Audit**: Check for exposed sensitive information, injection vulnerabilities, and insecure API key storage2. LLM Integration Best Practices
When encountering or implementing LLM integrations:
**Verify SDK Usage**: Ensure dedicated, well-maintained SDKs/libraries are used for LLM APIs**Validate Prompt Construction**: Check for proper use of builder patterns (e.g., `PromptBuilder` class)**Confirm Async Patterns**: Verify all API calls use `async/await` correctly**Check Streaming Implementation**: For large outputs, ensure streaming is enabled (`stream: true`)**Inspect Response Parsing**: Validate robust parsing with error handling for malformed responses**Rate Limiting**: Verify presence of rate limiting and throttling mechanisms**Secure Credentials**: Confirm API keys are stored in environment variables, not hardcoded3. SDK Architecture Review
Analyze the following key components:
**PromptBuilder Class**: Helper class for incremental prompt construction**Feedback & Exemplar Classes**: Data classes with proper encapsulation and scoring**MemoryBase Class**: Foundation for memory management with score updating and Softmax probability**FeedbackMemory & ExemplarFactory**: Specialized memory management classes**gen Function**: Generic LLM API communication handler**ERM Class**: Core optimizer class for prompt evaluation and refinement**Utility Functions**: Helper functions like `softmax` and `sampleIndices`4. Code Optimization Workflow
When optimizing JavaScript SDK code:
1. **Identify repetitive patterns** that can be abstracted into reusable functions/classes
2. **Refactor large functions** into smaller, single-purpose units
3. **Implement declarative patterns** where procedural code exists
4. **Add proper error boundaries** around async operations
5. **Introduce structured logging** (recommend `winston` or similar)
6. **Ensure immutability** in data transformations
7. **Add comprehensive JSDoc comments** for public APIs
5. Testing and Validation
**Check for test coverage** of core functionality**Validate async error handling** with both success and failure scenarios**Test LLM integration** with mock responses before live API calls**Verify rate limiting** behavior under load**Ensure security validations** for all user inputs6. Documentation Standards
When analyzing or generating documentation:
**API Documentation**: Ensure all public methods have JSDoc comments with parameter types and return values**Architecture Diagrams**: Recommend creating visual representations of SDK component relationships**Usage Examples**: Verify presence of practical code examples for key workflows**Configuration Guide**: Document all configurable parameters (temperature, threshold, beta, etc.)**Security Guidelines**: Include secure credential management and input validation recommendations7. Output Format
When providing analysis or suggestions, use this format:
```javascript
// **Issue Category**: [Security/Performance/Maintainability/etc.]
// **Severity**: [High/Medium/Low]
// **Location**: [File path and line number if applicable]
// **Description**: [Clear explanation of the issue]
// **Recommendation**: [Specific actionable fix]
// **Example**: [Code snippet demonstrating the fix]
```
Example Usage
Scenario: Analyzing a Prompt Optimization Workflow
Given a JavaScript file implementing ERM (Evaluation and Refinement Module):
1. **Verify async handling** in `optimize()` method
2. **Check memory management** in `FeedbackMemory` and `ExemplarFactory` classes
3. **Validate prompt construction** using `PromptBuilder` pattern
4. **Inspect error handling** around LLM API calls in `gen()` function
5. **Review logging implementation** for debugging support
6. **Assess configurability** of optimization parameters
Scenario: Refactoring LLM Integration Code
When encountering inline LLM API calls:
1. **Extract into dedicated service class** with proper dependency injection
2. **Implement retry logic** with exponential backoff
3. **Add response validation** layer with schema checking
4. **Introduce caching** for repeated identical requests
5. **Wrap in error boundaries** with user-friendly error messages
6. **Add telemetry** for monitoring API usage and performance
Constraints
Focus on ES6+ JavaScript syntax and modern patternsPrioritize readability over clever one-linersAlways consider security implications of LLM integrationsMaintain backward compatibility when suggesting refactors unless breaking changes are explicitly requestedRecommend TypeScript migration for large codebases lacking type safetyEnsure all suggestions align with popular linting configurations (ESLint with Airbnb/Standard)Key Principles
**DRY**: Eliminate code duplication through abstraction**SOLID**: Single responsibility, open/closed, Liskov substitution, interface segregation, dependency inversion**Functional**: Favor pure functions and immutability**Async**: Always use promises and async/await for I/O operations**Security**: Validate inputs, sanitize outputs, secure credentials**Observability**: Structured logging, error tracking, performance metrics