gateway / rules
Cursor rule608 starsChanged 8 months agoMITView on GitHub
The core providers module contains concrete implementations of AI provider integrations (Anthropic, OpenAI, Google, etc.) that implement the provider interfaces defined in the provider package.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/gateway.mdcCursor rule
- .cursor/rules/main.mdcCursor rule
- .cursor/rules/provider.mdcCursor rule
- .cursor/rules/types.mdcCursor rule
- add-modelSkill
- review-providerSkill
The file
Show its rules and text
We split this providers.mdc into the rules it gives an agent
33 rules. About 0 are common, 28 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈28
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
ALWAYS: create a dedicated directory for each provider: core/providers/{provider-name}/
- Very specific: line 18
ALWAYS: use the naming pattern: Provider{ProviderName} (e.g., Anthropic, OpenAI)
- Distinctive: line 26
ALWAYS: use static constants for base URLs and endpoints
- Distinctive: line 28
ALWAYS: use proper type constraints for model factories
- Very specific: line 32
ALWAYS: create a private chatModelFactories record mapping model names to factories
- Distinctive: line 35
ALWAYS: use the pattern:
- Distinctive: line 72
ALWAYS: create Zod schemas for model options validation
- Distinctive: line 73
ALWAYS: create model schemas with proper metadata
- Distinctive: line 81
ALWAYS: create base configuration schemas for each provider
- Distinctive: line 83
ALWAYS: use Zod for all configuration validation
- Very specific: line 90
ALWAYS: use descriptive names ending with OptionsType
- Very specific: line 98
ALWAYS: use the centralized HTTP client from the gateway
- Distinctive: line 140
ALWAYS: create comprehensive test suites for each provider
- Distinctive: line 141
ALWAYS: test provider instantiation with valid configurations
- Distinctive: line 142
ALWAYS: test provider instantiation with invalid configurations
- Distinctive: line 143
ALWAYS: test model factory methods
- Distinctive: line 144
ALWAYS: test error handling scenarios
- Distinctive: line 149
ALWAYS: test model instantiation with valid options
- Distinctive: line 150
ALWAYS: test model instantiation with invalid options
- Distinctive: line 151
ALWAYS: test API integration methods
- Distinctive: line 152
ALWAYS: test response transformation methods
- Distinctive: line 153
ALWAYS: test error handling for API failures
- Distinctive: line 154
ALWAYS: test configuration validation
- Distinctive: line 158
ALWAYS: test complete request flows
- Distinctive: line 159
ALWAYS: test error scenarios and edge cases
- Distinctive: line 160
ALWAYS: test streaming functionality when available
- Distinctive: line 161
ALWAYS: test caching and retry mechanisms
- Distinctive: line 168
ALWAYS: use connection pooling for HTTP clients
- Distinctive: line 184
ALWAYS: never log API keys or sensitive credentials
- Distinctive: line 200
ALWAYS: document configuration options and their effects
- Distinctive: line 202
ALWAYS: document error scenarios and handling
- Distinctive: line 206
ALWAYS: create comprehensive README files for each provider
- Distinctive: line 208
ALWAYS: document supported models and features
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
globs: core/providers/**
alwaysApply: false
---
# Core Providers Module Rules
## Module Overview
The core providers module contains concrete implementations of AI provider integrations (Anthropic, OpenAI, Google, etc.) that implement the provider interfaces defined in the provider package.
## Provider Implementation Rules
### 1. Provider Structure
- **ALWAYS** create a dedicated directory for each provider: `core/providers/{provider-name}/`
- **ALWAYS** implement the `ProviderV1` interface from `@adaline/provider`
- **ALWAYS** use the naming pattern: `Provider{ProviderName}` (e.g., `Anthropic`, `OpenAI`)
- **ALWAYS** export the provider class as the default export
- **ALWAYS** include proper TypeScript generics for configuration types
### 2. Provider Class Implementation
- **ALWAYS** implement `readonly version = "v1" as const`
- **ALWAYS** implement `readonly name = "{ProviderName}"`
- **ALWAYS** use static constants for base URLs and endpoints
- **ALWAYS** implement private model factories for both chat and embedding models
- **ALWAYS** use proper type constraints for model factories
### 3. Model Factory Pattern
- **ALWAYS** create a private `chatModelFactories` record mapping model names to factories
- **ALWAYS** create a private `embeddingModelFactories` record mapping model names to factories
- **ALWAYS** each factory should include: model class, options schema, and model schema
- **ALWAYS** use the pattern:
```typescript
private readonly chatModelFactories: Record<string, {
model: { new (options: any): ChatModelV1 };
modelOptions: z.ZodType<any>;
modelSchema: ChatModelSchemaType;
}> = {
[ModelLiteral]: {
model: ModelClass,
modelOptions: ModelOptionsSchema,
modelSchema: ModelSchema,
},
};
```
## Model Implementation Rules
### 1. Chat Model Implementation
- **ALWAYS** extend or implement the appropriate base chat model class
- **ALWAYS** implement all required methods from `ChatModelV1`
- **ALWAYS** provide proper model schemas with capabilities and limits
- **ALWAYS** implement provider-specific API integration methods
- **ALWAYS** handle provider-specific response formats and errors
### 2. Embedding Model Implementation
- **ALWAYS** extend or implement the appropriate base embedding model class
- **ALWAYS** implement all required methods from `EmbeddingModelV1`
- **ALWAYS** provide proper model schemas with capabilities and limits
- **ALWAYS** implement provider-specific API integration methods
- **ALWAYS** handle provider-specific response formats and errors
### 3. Model Schema Definition
- **ALWAYS** define model literals as constants: `ModelNameLiteral = "model-name"`
- **ALWAYS** create Zod schemas for model options validation
- **ALWAYS** create model schemas with proper metadata
- **ALWAYS** include pricing information when available
- **ALWAYS** specify supported features and limitations
## Configuration Management Rules
### 1. Configuration Schemas
- **ALWAYS** create base configuration schemas for each provider
- **ALWAYS** extend base schemas for model-specific configurations
- **ALWAYS** use Zod for all configuration validation
- **ALWAYS** provide sensible defaults for optional parameters
- **ALWAYS** validate API keys, endpoints, and other critical parameters
### 2. Configuration Types
- **ALWAYS** export configuration types for public use
- **ALWAYS** use descriptive names ending with `OptionsType`
- **ALWAYS** extend base configuration interfaces when appropriate
- **ALWAYS** provide configuration builders for complex setups
## API Integration Rules
### 1. HTTP Client Usage
- **ALWAYS** use the centralized HTTP client from the gateway
- **ALWAYS** implement proper error handling for API failures
- **ALWAYS** handle rate limits and quotas gracefully
- **ALWAYS** implement retry logic with exponential backoff
- **ALWAYS** include proper headers and authentication
### 2. Response Handling
- **ALWAYS** validate API responses before processing
- **ALWAYS** transform provider responses to standard format
- **ALWAYS** handle different response structures consistently
- **ALWAYS** preserve all relevant information from provider
- **ALWAYS** implement proper error handling for malformed responses
### 3. Streaming Support
- **ALWAYS** implement streaming for chat models when supported
- **ALWAYS** handle streaming responses properly
- **ALWAYS** implement proper cleanup for streaming connections
- **ALWAYS** handle streaming errors gracefully
## Error Handling Rules
### 1. Provider-Specific Errors
- **ALWAYS** extend appropriate error classes for provider-specific errors
- **ALWAYS** include provider name and context in error messages
- **ALWAYS** handle API rate limits and quotas gracefully
- **ALWAYS** provide retry guidance when appropriate
- **ALWAYS** log errors with full context
### 2. API Error Handling
- **ALWAYS** catch and handle HTTP errors properly
- **ALWAYS** parse error responses from providers
- **ALWAYS** provide meaningful error messages for users
- **ALWAYS** implement proper fallback mechanisms when possible
## Testing Rules
### 1. Provider Testing
- **ALWAYS** create comprehensive test suites for each provider
- **ALWAYS** test provider instantiation with valid configurations
- **ALWAYS** test provider instantiation with invalid configurations
- **ALWAYS** test model factory methods
- **ALWAYS** test error handling scenarios
- **ALWAYS** mock external API calls
### 2. Model Testing
- **ALWAYS** test model instantiation with valid options
- **ALWAYS** test model instantiation with invalid options
- **ALWAYS** test API integration methods
- **ALWAYS** test response transformation methods
- **ALWAYS** test error handling for API failures
- **ALWAYS** test configuration validation
### 3. Integration Testing
- **ALWAYS** test complete request flows
- **ALWAYS** test error scenarios and edge cases
- **ALWAYS** test streaming functionality when available
- **ALWAYS** test caching and retry mechanisms
## Performance Considerations
### 1. Resource Management
- **ALWAYS** implement proper cleanup for resources
- **ALWAYS** use connection pooling for HTTP clients
- **ALWAYS** implement request batching when possible
- **ALWAYS** cache frequently used configurations and responses
### 2. Error Recovery
- **ALWAYS** implement exponential backoff for retries
- **ALWAYS** implement circuit breakers for failing endpoints
- **ALWAYS** provide fallback mechanisms when possible
- **ALWAYS** monitor provider health and performance
## Security Considerations
### 1. API Key Management
- **ALWAYS** validate API keys before use
- **ALWAYS** never log API keys or sensitive credentials
- **ALWAYS** support secure credential storage
- **ALWAYS** implement proper access controls
### 2. Input Validation
- **ALWAYS** validate all input parameters
- **ALWAYS** sanitize user inputs before API calls
- **ALWAYS** implement rate limiting for user requests
- **ALWAYS** monitor for suspicious activity patterns
## Documentation Rules
### 1. Code Documentation
- **ALWAYS** include JSDoc comments for public methods
- **ALWAYS** document configuration options and their effects
- **ALWAYS** provide usage examples in comments
- **ALWAYS** document error scenarios and handling
### 2. README Documentation
- **ALWAYS** create comprehensive README files for each provider
- **ALWAYS** include configuration examples
- **ALWAYS** document supported models and features
- **ALWAYS** provide troubleshooting guides
- **ALWAYS** include performance considerations
globs: core/providers/\*\*
alwaysApply: false
---
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

