Skip to content

Commit 8c1b4f6

Browse files
algolia-botFluf22
andcommitted
chore: agentic config prep (generated)
algolia/api-clients-automation#5825 Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
1 parent 2297458 commit 8c1b4f6

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed

AGENTS.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# RUBY CLIENT - AI AGENT INSTRUCTIONS
2+
3+
## ⚠️ CRITICAL: CHECK YOUR REPOSITORY FIRST
4+
5+
Before making ANY changes, verify you're in the correct repository:
6+
7+
```bash
8+
git remote -v
9+
```
10+
11+
-**CORRECT**: `origin .../algolia/api-clients-automation.git` → You may proceed
12+
-**WRONG**: `origin .../algolia/algoliasearch-client-ruby.git` → STOP! This is the PUBLIC repository
13+
14+
**If you're in `algoliasearch-client-ruby`**: Do NOT make changes here. All changes must go through `api-clients-automation`. PRs and commits made directly to the public repo will be discarded on next release.
15+
16+
## ⚠️ BEFORE ANY EDIT: Check If File Is Generated
17+
18+
Before editing ANY file, verify it's hand-written by checking `config/generation.config.mjs`:
19+
20+
```javascript
21+
// In generation.config.mjs - patterns WITHOUT '!' are GENERATED (do not edit)
22+
'clients/algoliasearch-client-ruby/lib/algolia/**', // Generated
23+
'!clients/algoliasearch-client-ruby/lib/algolia/transport/**', // Hand-written ✓
24+
'!clients/algoliasearch-client-ruby/lib/algolia/error.rb', // Hand-written ✓
25+
```
26+
27+
**Hand-written (safe to edit):**
28+
29+
- `lib/algolia/transport/**` - Transport, retry strategy, HTTP handling
30+
- `lib/algolia/api_client.rb` - Core API client
31+
- `lib/algolia/api_error.rb` - API error class
32+
- `lib/algolia/configuration.rb` - Configuration
33+
- `lib/algolia/error.rb` - Error base class
34+
- `lib/algolia/logger_helper.rb` - Logging utilities
35+
- `lib/algolia/user_agent.rb` - User agent handling
36+
37+
**Generated (DO NOT EDIT):**
38+
39+
- `lib/algolia/api/**` - API client classes
40+
- `lib/algolia/models/**` - API models
41+
- `Gemfile.lock`, `version.rb`
42+
43+
## Language Conventions
44+
45+
### Naming
46+
47+
- **Files**: `snake_case.rb`
48+
- **Classes/Modules**: `PascalCase`
49+
- **Methods/Variables**: `snake_case`
50+
- **Constants**: `UPPER_SNAKE_CASE`
51+
- **Predicates**: `method_name?` (returns boolean)
52+
- **Dangerous methods**: `method_name!` (mutates or raises)
53+
54+
### Formatting
55+
56+
- RubyFmt for formatting
57+
- Run: `yarn cli format ruby clients/algoliasearch-client-ruby`
58+
59+
### Ruby Idioms
60+
61+
- Use `attr_reader`, `attr_accessor` for accessors
62+
- Prefer `||=` for memoization
63+
- Use `&.` safe navigation operator
64+
- Blocks over lambdas for callbacks
65+
66+
### Dependencies
67+
68+
- **HTTP**: Faraday (with Net::HTTP adapter)
69+
- **Build**: Bundler + gemspec
70+
- **Versions**: Ruby 3.4+
71+
72+
## Client Patterns
73+
74+
### Transport Architecture
75+
76+
```ruby
77+
# lib/algolia/transport/
78+
class Transport
79+
def initialize(config)
80+
@http_requester = HttpRequester.new(config.app_id, config.api_key)
81+
@retry_strategy = RetryStrategy.new(config.hosts)
82+
end
83+
84+
def request(method, path, body, opts)
85+
# Retry with host failover
86+
end
87+
end
88+
```
89+
90+
### Retry Strategy
91+
92+
```ruby
93+
# lib/algolia/transport/retry_strategy.rb
94+
class RetryStrategy
95+
# Host states: :up, :down, :timed_out
96+
# Retries on network errors
97+
# 4xx errors not retried
98+
end
99+
```
100+
101+
### Configuration
102+
103+
```ruby
104+
# Configuration object pattern
105+
config = Algolia::Configuration.new(
106+
app_id: 'APP_ID',
107+
api_key: 'API_KEY',
108+
hosts: [...],
109+
read_timeout: 5,
110+
write_timeout: 30
111+
)
112+
```
113+
114+
## Common Gotchas
115+
116+
### Symbol vs String Keys
117+
118+
```ruby
119+
# API returns string keys, use with_indifferent_access or symbols
120+
response[:hits] # May not work
121+
response['hits'] # Works
122+
response.hits # Works if using model objects
123+
```
124+
125+
### Block Syntax
126+
127+
```ruby
128+
# Use do..end for multi-line, braces for single-line
129+
client.search { |r| r.query = 'test' }
130+
131+
client.search do |params|
132+
params.query = 'test'
133+
params.hits_per_page = 10
134+
end
135+
```
136+
137+
### Error Handling
138+
139+
```ruby
140+
begin
141+
response = client.search(params)
142+
rescue Algolia::AlgoliaError => e
143+
# Base error class
144+
rescue Algolia::ApiError => e
145+
# API returned error
146+
puts e.status_code
147+
puts e.message
148+
end
149+
```
150+
151+
### Nil Safety
152+
153+
```ruby
154+
# Use safe navigation
155+
result&.hits&.first&.object_id
156+
157+
# Or explicit checks
158+
if result && result.hits && result.hits.any?
159+
result.hits.first.object_id
160+
end
161+
```
162+
163+
### Deprecated Operations
164+
165+
Some operations in `ingestion_client.rb` and `search_client.rb` are deprecated. Check method documentation before use.
166+
167+
## Build & Test Commands
168+
169+
```bash
170+
# From repo root (api-clients-automation)
171+
yarn cli build clients ruby # Build Ruby client
172+
yarn cli cts generate ruby # Generate CTS tests
173+
yarn cli cts run ruby # Run CTS tests
174+
yarn cli playground ruby search # Interactive playground
175+
yarn cli format ruby clients/algoliasearch-client-ruby
176+
177+
# From client directory
178+
cd clients/algoliasearch-client-ruby
179+
bundle install # Install dependencies
180+
bundle exec rake test # Run tests
181+
bundle exec rubocop # Run linter
182+
```

0 commit comments

Comments
 (0)