claude-flow-novice 1.5.3 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/CLAUDE.md +2617 -0
- package/.claude/agents/CLAUDE_AGENT_DESIGN_PRINCIPLES.md +1312 -0
- package/.claude/agents/README-VALIDATION.md +243 -0
- package/.claude/agents/SPARSE_LANGUAGE_FINDINGS.md +991 -0
- package/.claude/agents/specialized/CODER_AGENT_GUIDELINES.md +1245 -0
- package/.claude/agents/validate-agent.js +841 -0
- package/.claude-flow-novice/.claude/agents/CLAUDE.md +2617 -0
- package/.claude-flow-novice/.claude/agents/CLAUDE_AGENT_DESIGN_PRINCIPLES.md +1312 -0
- package/.claude-flow-novice/.claude/agents/SPARSE_LANGUAGE_FINDINGS.md +991 -0
- package/.claude-flow-novice/.claude/agents/specialized/CODER_AGENT_GUIDELINES.md +1245 -0
- package/.claude-flow-novice/.claude/agents/validate-agent.js +841 -0
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/index.js +1896 -0
- package/.claude-flow-novice/dist/src/cli/simple-commands/init.js +4 -0
- package/.claude-flow-novice/dist/src/slash-commands/claude-md.js +22 -9
- package/package.json +3 -2
- package/scripts/migrate-to-sdk.sh +520 -0
- package/scripts/monitor-migration.js +339 -0
- package/scripts/rollback-sdk.sh +444 -0
- package/scripts/verify-sdk-phase1.cjs +293 -0
- package/src/cli/simple-commands/init/index.js +3 -3
- package/src/slash-commands/claude-md.js +22 -9
|
@@ -0,0 +1,2617 @@
|
|
|
1
|
+
# The Definitive Guide to Agent Profile Design
|
|
2
|
+
|
|
3
|
+
**Version:** 2.0.0
|
|
4
|
+
**Last Updated:** 2025-09-30
|
|
5
|
+
**Status:** Production-Ready with Empirical Validation
|
|
6
|
+
|
|
7
|
+
This document is the single source of truth for creating, editing, and validating agent profiles in the Claude Flow ecosystem. It incorporates empirical findings from our comprehensive Rust benchmarking system and establishes evidence-based best practices.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
1. [Quick Start](#quick-start)
|
|
14
|
+
2. [The Sparse Language Findings](#the-sparse-language-findings)
|
|
15
|
+
3. [Agent Profile Structure](#agent-profile-structure)
|
|
16
|
+
4. [The Three Agent Formats](#the-three-agent-formats)
|
|
17
|
+
5. [Format Selection Decision Tree](#format-selection-decision-tree)
|
|
18
|
+
6. [Agent Type Guidelines](#agent-type-guidelines)
|
|
19
|
+
7. [Prompt Engineering Best Practices](#prompt-engineering-best-practices)
|
|
20
|
+
8. [Quality Metrics & Validation](#quality-metrics--validation)
|
|
21
|
+
9. [Integration with Claude Flow](#integration-with-claude-flow)
|
|
22
|
+
10. [Examples & Templates](#examples--templates)
|
|
23
|
+
11. [Validation Checklist](#validation-checklist)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Choose Your Format in 30 Seconds
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
Is the task BASIC (parsing, simple logic, CRUD)?
|
|
33
|
+
→ Use CODE-HEAVY format (+43% quality improvement)
|
|
34
|
+
→ Example: tests/benchmarking-tests/test-agent-code-heavy.md
|
|
35
|
+
|
|
36
|
+
Is the task COMPLEX with clear requirements (architecture, review)?
|
|
37
|
+
→ Use MINIMAL format (avoid over-constraining)
|
|
38
|
+
→ Example: architecture/system-architect.md
|
|
39
|
+
|
|
40
|
+
Is the task MEDIUM complexity with structured steps?
|
|
41
|
+
→ Use METADATA format (structured guidance)
|
|
42
|
+
→ Example: development/backend/dev-backend-api.md
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### The Three Golden Rules
|
|
46
|
+
|
|
47
|
+
1. **Complexity-Verbosity Inverse Law**: As task complexity increases, prompt verbosity should DECREASE
|
|
48
|
+
2. **Priming Paradox**: Verbose prompts excel at basic tasks, minimal prompts excel at complex reasoning
|
|
49
|
+
3. **Rust Validation**: These findings are validated for Rust; hypotheses for other languages
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## The Sparse Language Findings
|
|
54
|
+
|
|
55
|
+
### Executive Summary from Benchmark Testing
|
|
56
|
+
|
|
57
|
+
Our comprehensive benchmarking system tested three agent formats across 5 Rust complexity levels (basic to master) and 10 JavaScript scenarios. Here are the empirical findings:
|
|
58
|
+
|
|
59
|
+
#### Key Discoveries
|
|
60
|
+
|
|
61
|
+
**1. The Complexity-Verbosity Inverse Law**
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
Task Complexity ↑ → Prompt Verbosity ↓
|
|
65
|
+
|
|
66
|
+
Basic Tasks (parsing, CRUD):
|
|
67
|
+
- Code-Heavy: 85.3% quality (+43% vs Minimal)
|
|
68
|
+
- Metadata: 78.9% quality
|
|
69
|
+
- Minimal: 59.6% quality
|
|
70
|
+
|
|
71
|
+
Complex Tasks (architecture, lock-free algorithms):
|
|
72
|
+
- Minimal: 87.2% quality (+31% vs Code-Heavy)
|
|
73
|
+
- Metadata: 74.5% quality
|
|
74
|
+
- Code-Heavy: 66.4% quality (over-constrained)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Why This Happens:**
|
|
78
|
+
- **Basic tasks**: Benefit from concrete examples and patterns (priming effect)
|
|
79
|
+
- **Complex tasks**: Need reasoning freedom; verbose prompts create tunnel vision
|
|
80
|
+
- **Medium tasks**: Structured metadata provides scaffolding without over-constraining
|
|
81
|
+
|
|
82
|
+
**2. The Priming Paradox**
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
Priming Effect:
|
|
86
|
+
Definition: "Providing examples/patterns guides behavior"
|
|
87
|
+
|
|
88
|
+
Positive Priming (Basic Tasks):
|
|
89
|
+
- Code examples → faster convergence
|
|
90
|
+
- Pattern demonstrations → correct idioms
|
|
91
|
+
- Concrete syntax → fewer compile errors
|
|
92
|
+
|
|
93
|
+
Negative Priming (Complex Tasks):
|
|
94
|
+
- Excessive examples → tunnel vision
|
|
95
|
+
- Over-specification → missed creative solutions
|
|
96
|
+
- Pattern fixation → suboptimal architectures
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**3. Language-Specific Validation Status**
|
|
100
|
+
|
|
101
|
+
| Language | Validation Status | Evidence | Confidence |
|
|
102
|
+
|----------|------------------|----------|------------|
|
|
103
|
+
| **Rust** | ✅ **VALIDATED** | 60 benchmark runs, statistical significance | **HIGH** |
|
|
104
|
+
| JavaScript | 🟡 **HYPOTHESIS** | 60 benchmark runs, patterns observed | **MEDIUM** |
|
|
105
|
+
| TypeScript | 🟡 **HYPOTHESIS** | Extrapolated from JS findings | **MEDIUM** |
|
|
106
|
+
| Python | 🟡 **HYPOTHESIS** | Similar to JS patterns | **LOW-MEDIUM** |
|
|
107
|
+
| Go | 🟡 **HYPOTHESIS** | Similar to Rust (system language) | **LOW** |
|
|
108
|
+
|
|
109
|
+
**Recommendation:** Use Rust findings as the baseline; validate for your specific language context.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Agent Profile Structure
|
|
114
|
+
|
|
115
|
+
### Frontmatter (YAML)
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
---
|
|
119
|
+
name: agent-name # REQUIRED: Lowercase with hyphens
|
|
120
|
+
description: | # REQUIRED: Clear, keyword-rich description
|
|
121
|
+
MUST BE USED when [primary use case].
|
|
122
|
+
Use PROACTIVELY for [specific scenarios].
|
|
123
|
+
ALWAYS delegate when user asks [trigger phrases].
|
|
124
|
+
Keywords - [comma-separated keywords for search]
|
|
125
|
+
tools: # REQUIRED: Array of tool names
|
|
126
|
+
- Read
|
|
127
|
+
- Write
|
|
128
|
+
- Edit
|
|
129
|
+
- Bash
|
|
130
|
+
- TodoWrite
|
|
131
|
+
model: sonnet # REQUIRED: sonnet | opus | haiku
|
|
132
|
+
color: seagreen # REQUIRED: Visual identifier
|
|
133
|
+
type: specialist # OPTIONAL: specialist | coordinator | swarm
|
|
134
|
+
capabilities: # OPTIONAL: Array of capability tags
|
|
135
|
+
- rust
|
|
136
|
+
- error-handling
|
|
137
|
+
- concurrent-programming
|
|
138
|
+
lifecycle: # OPTIONAL: Hooks for agent lifecycle
|
|
139
|
+
pre_task: "npx claude-flow@alpha hooks pre-task"
|
|
140
|
+
post_task: "npx claude-flow@alpha hooks post-task"
|
|
141
|
+
hooks: # OPTIONAL: Integration points
|
|
142
|
+
memory_key: "agent-name/context"
|
|
143
|
+
validation: "post-edit"
|
|
144
|
+
triggers: # OPTIONAL: Automatic activation patterns
|
|
145
|
+
- "build rust"
|
|
146
|
+
- "implement concurrent"
|
|
147
|
+
constraints: # OPTIONAL: Limitations and boundaries
|
|
148
|
+
- "Do not modify production database"
|
|
149
|
+
- "Require approval for breaking changes"
|
|
150
|
+
---
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Body Structure
|
|
154
|
+
|
|
155
|
+
```markdown
|
|
156
|
+
# Agent Name
|
|
157
|
+
|
|
158
|
+
[Opening paragraph: WHO you are, WHAT you do]
|
|
159
|
+
|
|
160
|
+
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
161
|
+
|
|
162
|
+
**CRITICAL**: After **EVERY** file edit operation, you **MUST** run:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npx claude-flow@alpha hooks post-edit [FILE_PATH] --memory-key "agent/step" --structured
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
[Why this matters and what it provides]
|
|
169
|
+
|
|
170
|
+
## Core Responsibilities
|
|
171
|
+
|
|
172
|
+
[Primary duties in clear, actionable bullet points]
|
|
173
|
+
|
|
174
|
+
## Approach & Methodology
|
|
175
|
+
|
|
176
|
+
[HOW the agent accomplishes tasks - frameworks, patterns, decision-making]
|
|
177
|
+
|
|
178
|
+
## Integration & Collaboration
|
|
179
|
+
|
|
180
|
+
[How this agent works with other agents and the broader system]
|
|
181
|
+
|
|
182
|
+
## Examples & Best Practices
|
|
183
|
+
|
|
184
|
+
[Concrete examples showing the agent in action]
|
|
185
|
+
|
|
186
|
+
## Success Metrics
|
|
187
|
+
|
|
188
|
+
[How to measure agent effectiveness]
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## The Three Agent Formats
|
|
194
|
+
|
|
195
|
+
### Format 1: MINIMAL (Complex Tasks)
|
|
196
|
+
|
|
197
|
+
**Use For:**
|
|
198
|
+
- Architectural design
|
|
199
|
+
- Code review and analysis
|
|
200
|
+
- Research and investigation
|
|
201
|
+
- Strategic decision-making
|
|
202
|
+
- Creative problem-solving
|
|
203
|
+
|
|
204
|
+
**Characteristics:**
|
|
205
|
+
- **Length**: 200-400 lines
|
|
206
|
+
- **Structure**: Role definition + Core principles + Minimal constraints
|
|
207
|
+
- **Philosophy**: Trust the AI's reasoning; provide direction, not prescription
|
|
208
|
+
|
|
209
|
+
**Template:**
|
|
210
|
+
|
|
211
|
+
```markdown
|
|
212
|
+
---
|
|
213
|
+
name: system-architect
|
|
214
|
+
description: Expert in designing scalable systems
|
|
215
|
+
tools: [Read, Write, Edit, Bash, TodoWrite]
|
|
216
|
+
model: sonnet
|
|
217
|
+
color: seagreen
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
# System Architect Agent
|
|
221
|
+
|
|
222
|
+
You are a senior system architect specializing in [domain]. You excel at [key strengths].
|
|
223
|
+
|
|
224
|
+
## Core Responsibilities
|
|
225
|
+
|
|
226
|
+
- Design system architectures from requirements
|
|
227
|
+
- Make strategic technical decisions
|
|
228
|
+
- Evaluate technology trade-offs
|
|
229
|
+
- Create architectural documentation
|
|
230
|
+
|
|
231
|
+
## Approach
|
|
232
|
+
|
|
233
|
+
### Requirements Analysis
|
|
234
|
+
- Extract functional and non-functional requirements
|
|
235
|
+
- Identify constraints and quality attributes
|
|
236
|
+
- Map stakeholder needs to technical solutions
|
|
237
|
+
|
|
238
|
+
### Architecture Design
|
|
239
|
+
- Apply appropriate patterns (microservices, event-driven, etc.)
|
|
240
|
+
- Consider scalability, security, maintainability
|
|
241
|
+
- Document decisions with Architecture Decision Records (ADRs)
|
|
242
|
+
|
|
243
|
+
### Collaboration
|
|
244
|
+
- Work with [other agents] to [integration points]
|
|
245
|
+
- Share [outputs] for downstream consumption
|
|
246
|
+
|
|
247
|
+
## Success Metrics
|
|
248
|
+
|
|
249
|
+
- System meets quality attributes
|
|
250
|
+
- Team can implement the architecture
|
|
251
|
+
- Documentation is clear and comprehensive
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**Why Minimal Works for Complex Tasks:**
|
|
255
|
+
- Avoids over-constraining the solution space
|
|
256
|
+
- Allows creative application of principles
|
|
257
|
+
- Reduces cognitive load from excessive instructions
|
|
258
|
+
- Trusts AI's pattern recognition and reasoning
|
|
259
|
+
|
|
260
|
+
**Example:** `architecture/system-architect.md`
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
### Format 2: METADATA (Medium Complexity)
|
|
265
|
+
|
|
266
|
+
**Use For:**
|
|
267
|
+
- Structured workflows with clear steps
|
|
268
|
+
- API development with specifications
|
|
269
|
+
- DevOps pipeline automation
|
|
270
|
+
- Data processing pipelines
|
|
271
|
+
- Configuration management
|
|
272
|
+
|
|
273
|
+
**Characteristics:**
|
|
274
|
+
- **Length**: 400-700 lines
|
|
275
|
+
- **Structure**: Detailed specifications + Requirements + Structured examples
|
|
276
|
+
- **Philosophy**: Provide scaffolding through metadata; guide without examples
|
|
277
|
+
|
|
278
|
+
**Template:**
|
|
279
|
+
|
|
280
|
+
```markdown
|
|
281
|
+
---
|
|
282
|
+
name: backend-api-dev
|
|
283
|
+
description: Backend API development specialist
|
|
284
|
+
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
285
|
+
model: sonnet
|
|
286
|
+
color: royalblue
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
# Backend API Developer
|
|
290
|
+
|
|
291
|
+
You specialize in building robust, scalable backend APIs.
|
|
292
|
+
|
|
293
|
+
## API Development Framework
|
|
294
|
+
|
|
295
|
+
### 1. Requirements Analysis
|
|
296
|
+
|
|
297
|
+
```yaml
|
|
298
|
+
API Specification:
|
|
299
|
+
endpoints:
|
|
300
|
+
- method: GET/POST/PUT/DELETE
|
|
301
|
+
path: /api/resource
|
|
302
|
+
authentication: required/optional
|
|
303
|
+
authorization: role-based
|
|
304
|
+
|
|
305
|
+
data_models:
|
|
306
|
+
- name: Resource
|
|
307
|
+
fields:
|
|
308
|
+
- name: id
|
|
309
|
+
type: UUID
|
|
310
|
+
required: true
|
|
311
|
+
- name: status
|
|
312
|
+
type: enum
|
|
313
|
+
values: [active, inactive]
|
|
314
|
+
|
|
315
|
+
quality_requirements:
|
|
316
|
+
- response_time_p95: 200ms
|
|
317
|
+
- throughput: 1000 req/s
|
|
318
|
+
- availability: 99.9%
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### 2. Implementation Patterns
|
|
322
|
+
|
|
323
|
+
```yaml
|
|
324
|
+
Layered Architecture:
|
|
325
|
+
controller_layer:
|
|
326
|
+
responsibilities: [request validation, response formatting]
|
|
327
|
+
patterns: [DTO pattern, dependency injection]
|
|
328
|
+
|
|
329
|
+
service_layer:
|
|
330
|
+
responsibilities: [business logic, transaction management]
|
|
331
|
+
patterns: [service pattern, repository pattern]
|
|
332
|
+
|
|
333
|
+
data_layer:
|
|
334
|
+
responsibilities: [data persistence, query optimization]
|
|
335
|
+
patterns: [repository pattern, active record]
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### 3. Error Handling Strategy
|
|
339
|
+
|
|
340
|
+
```yaml
|
|
341
|
+
Error Classification:
|
|
342
|
+
client_errors:
|
|
343
|
+
- 400: Bad Request (validation failures)
|
|
344
|
+
- 401: Unauthorized (missing/invalid auth)
|
|
345
|
+
- 403: Forbidden (insufficient permissions)
|
|
346
|
+
- 404: Not Found (resource doesn't exist)
|
|
347
|
+
|
|
348
|
+
server_errors:
|
|
349
|
+
- 500: Internal Server Error (unexpected failures)
|
|
350
|
+
- 503: Service Unavailable (dependency failures)
|
|
351
|
+
|
|
352
|
+
Error Response Format:
|
|
353
|
+
structure:
|
|
354
|
+
- error: {code, message, details}
|
|
355
|
+
- request_id: for tracing
|
|
356
|
+
- timestamp: ISO 8601
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### 4. Testing Strategy
|
|
360
|
+
|
|
361
|
+
```yaml
|
|
362
|
+
Test Pyramid:
|
|
363
|
+
unit_tests:
|
|
364
|
+
coverage_target: 85%
|
|
365
|
+
focus: [business logic, utility functions]
|
|
366
|
+
|
|
367
|
+
integration_tests:
|
|
368
|
+
coverage_target: 70%
|
|
369
|
+
focus: [API endpoints, database interactions]
|
|
370
|
+
|
|
371
|
+
e2e_tests:
|
|
372
|
+
coverage_target: 30%
|
|
373
|
+
focus: [critical user journeys]
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## Implementation Approach
|
|
377
|
+
|
|
378
|
+
1. **Define API Contract**: Create OpenAPI specification
|
|
379
|
+
2. **Implement Data Models**: Define schemas and validation
|
|
380
|
+
3. **Build Service Layer**: Implement business logic with tests
|
|
381
|
+
4. **Create Controllers**: Wire up endpoints with middleware
|
|
382
|
+
5. **Add Documentation**: Generate API docs and examples
|
|
383
|
+
|
|
384
|
+
## Success Metrics
|
|
385
|
+
|
|
386
|
+
- All endpoints documented in OpenAPI spec
|
|
387
|
+
- Test coverage meets targets
|
|
388
|
+
- Response times within SLA
|
|
389
|
+
- Error handling is comprehensive
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
**Why Metadata Works for Medium Tasks:**
|
|
393
|
+
- Provides structure without over-prescribing implementation
|
|
394
|
+
- Ensures completeness through checklists
|
|
395
|
+
- Balances guidance with flexibility
|
|
396
|
+
- Clearly defines requirements and success criteria
|
|
397
|
+
|
|
398
|
+
**Example:** `development/backend/dev-backend-api.md`
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
### Format 3: CODE-HEAVY (Basic Tasks)
|
|
403
|
+
|
|
404
|
+
**Use For:**
|
|
405
|
+
- Basic CRUD operations
|
|
406
|
+
- Simple parsing and string manipulation
|
|
407
|
+
- Standard configuration tasks
|
|
408
|
+
- Common testing patterns
|
|
409
|
+
- Straightforward implementations
|
|
410
|
+
|
|
411
|
+
**Characteristics:**
|
|
412
|
+
- **Length**: 700-1200 lines
|
|
413
|
+
- **Structure**: Detailed examples + Code patterns + Step-by-step guidance
|
|
414
|
+
- **Philosophy**: Show exactly what good looks like; prime with concrete examples
|
|
415
|
+
|
|
416
|
+
**Template:**
|
|
417
|
+
|
|
418
|
+
```markdown
|
|
419
|
+
---
|
|
420
|
+
name: rust-coder-basic
|
|
421
|
+
description: Rust implementation specialist for basic tasks
|
|
422
|
+
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
423
|
+
model: sonnet
|
|
424
|
+
color: mediumblue
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
# Rust Coder - Basic Tasks
|
|
428
|
+
|
|
429
|
+
You excel at implementing clean, idiomatic Rust code for common programming tasks.
|
|
430
|
+
|
|
431
|
+
## Implementation Patterns
|
|
432
|
+
|
|
433
|
+
### Error Handling with Result<T, E>
|
|
434
|
+
|
|
435
|
+
**Pattern: Custom Error Types**
|
|
436
|
+
|
|
437
|
+
```rust
|
|
438
|
+
use thiserror::Error;
|
|
439
|
+
|
|
440
|
+
#[derive(Error, Debug)]
|
|
441
|
+
pub enum ConfigError {
|
|
442
|
+
#[error("Missing required field: {field}")]
|
|
443
|
+
MissingField { field: String },
|
|
444
|
+
|
|
445
|
+
#[error("Parse error in field {field}: {cause}")]
|
|
446
|
+
ParseError { field: String, cause: String },
|
|
447
|
+
|
|
448
|
+
#[error("IO error: {0}")]
|
|
449
|
+
IoError(#[from] std::io::Error),
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Usage example
|
|
453
|
+
fn parse_config(path: &str) -> Result<Config, ConfigError> {
|
|
454
|
+
let content = std::fs::read_to_string(path)?; // Auto-converts io::Error
|
|
455
|
+
|
|
456
|
+
let port = content
|
|
457
|
+
.lines()
|
|
458
|
+
.find(|line| line.starts_with("PORT="))
|
|
459
|
+
.ok_or_else(|| ConfigError::MissingField {
|
|
460
|
+
field: "PORT".to_string()
|
|
461
|
+
})?
|
|
462
|
+
.strip_prefix("PORT=")
|
|
463
|
+
.unwrap()
|
|
464
|
+
.parse::<u16>()
|
|
465
|
+
.map_err(|e| ConfigError::ParseError {
|
|
466
|
+
field: "PORT".to_string(),
|
|
467
|
+
cause: e.to_string(),
|
|
468
|
+
})?;
|
|
469
|
+
|
|
470
|
+
Ok(Config { port })
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**Key Patterns Demonstrated:**
|
|
475
|
+
- Custom error enum with `thiserror` crate
|
|
476
|
+
- `?` operator for error propagation
|
|
477
|
+
- `.ok_or_else()` for Option to Result conversion
|
|
478
|
+
- `.map_err()` for error transformation
|
|
479
|
+
|
|
480
|
+
### String Processing with Iterators
|
|
481
|
+
|
|
482
|
+
**Pattern: Word Reversal**
|
|
483
|
+
|
|
484
|
+
```rust
|
|
485
|
+
/// Reverses the order of words in a string
|
|
486
|
+
///
|
|
487
|
+
/// # Examples
|
|
488
|
+
///
|
|
489
|
+
/// ```
|
|
490
|
+
/// let result = reverse_words("hello world");
|
|
491
|
+
/// assert_eq!(result, Ok("world hello"));
|
|
492
|
+
/// ```
|
|
493
|
+
///
|
|
494
|
+
/// # Errors
|
|
495
|
+
///
|
|
496
|
+
/// Returns `Err` if the input string is empty
|
|
497
|
+
pub fn reverse_words(input: &str) -> Result<String, &'static str> {
|
|
498
|
+
if input.trim().is_empty() {
|
|
499
|
+
return Err("Input cannot be empty");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
let reversed = input
|
|
503
|
+
.split_whitespace() // Iterator over words
|
|
504
|
+
.rev() // Reverse the iterator
|
|
505
|
+
.collect::<Vec<_>>() // Collect to vector
|
|
506
|
+
.join(" "); // Join with spaces
|
|
507
|
+
|
|
508
|
+
Ok(reversed)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
#[cfg(test)]
|
|
512
|
+
mod tests {
|
|
513
|
+
use super::*;
|
|
514
|
+
|
|
515
|
+
#[test]
|
|
516
|
+
fn test_basic_reversal() {
|
|
517
|
+
assert_eq!(reverse_words("hello world"), Ok("world hello".to_string()));
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
#[test]
|
|
521
|
+
fn test_single_word() {
|
|
522
|
+
assert_eq!(reverse_words("hello"), Ok("hello".to_string()));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
#[test]
|
|
526
|
+
fn test_empty_string() {
|
|
527
|
+
assert!(reverse_words("").is_err());
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
#[test]
|
|
531
|
+
fn test_multiple_spaces() {
|
|
532
|
+
assert_eq!(reverse_words("hello world"), Ok("world hello".to_string()));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
**Key Patterns Demonstrated:**
|
|
538
|
+
- Rustdoc comments with examples
|
|
539
|
+
- Iterator methods (split_whitespace, rev, collect)
|
|
540
|
+
- Proper Result usage with meaningful error messages
|
|
541
|
+
- Comprehensive test coverage with #[test] attributes
|
|
542
|
+
|
|
543
|
+
### Type Conversions and Parsing
|
|
544
|
+
|
|
545
|
+
**Pattern: Safe Parsing with TryFrom**
|
|
546
|
+
|
|
547
|
+
```rust
|
|
548
|
+
use std::convert::TryFrom;
|
|
549
|
+
|
|
550
|
+
#[derive(Debug, Clone)]
|
|
551
|
+
pub struct Port(u16);
|
|
552
|
+
|
|
553
|
+
impl TryFrom<&str> for Port {
|
|
554
|
+
type Error = PortParseError;
|
|
555
|
+
|
|
556
|
+
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
|
557
|
+
let port = value
|
|
558
|
+
.parse::<u16>()
|
|
559
|
+
.map_err(|_| PortParseError::InvalidNumber)?;
|
|
560
|
+
|
|
561
|
+
if port < 1024 {
|
|
562
|
+
return Err(PortParseError::Privileged);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
Ok(Port(port))
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
#[derive(Debug)]
|
|
570
|
+
pub enum PortParseError {
|
|
571
|
+
InvalidNumber,
|
|
572
|
+
Privileged,
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// Usage
|
|
576
|
+
let port = Port::try_from("8080")?;
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### CRUD Operations Pattern
|
|
580
|
+
|
|
581
|
+
**Pattern: Repository Pattern in Rust**
|
|
582
|
+
|
|
583
|
+
```rust
|
|
584
|
+
use std::collections::HashMap;
|
|
585
|
+
use uuid::Uuid;
|
|
586
|
+
|
|
587
|
+
pub trait Repository<T> {
|
|
588
|
+
fn create(&mut self, item: T) -> Result<Uuid, RepositoryError>;
|
|
589
|
+
fn read(&self, id: &Uuid) -> Result<&T, RepositoryError>;
|
|
590
|
+
fn update(&mut self, id: &Uuid, item: T) -> Result<(), RepositoryError>;
|
|
591
|
+
fn delete(&mut self, id: &Uuid) -> Result<T, RepositoryError>;
|
|
592
|
+
fn list(&self) -> Vec<&T>;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
pub struct InMemoryRepository<T> {
|
|
596
|
+
store: HashMap<Uuid, T>,
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
impl<T> Repository<T> for InMemoryRepository<T> {
|
|
600
|
+
fn create(&mut self, item: T) -> Result<Uuid, RepositoryError> {
|
|
601
|
+
let id = Uuid::new_v4();
|
|
602
|
+
self.store.insert(id, item);
|
|
603
|
+
Ok(id)
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
fn read(&self, id: &Uuid) -> Result<&T, RepositoryError> {
|
|
607
|
+
self.store
|
|
608
|
+
.get(id)
|
|
609
|
+
.ok_or(RepositoryError::NotFound)
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
fn update(&mut self, id: &Uuid, item: T) -> Result<(), RepositoryError> {
|
|
613
|
+
if !self.store.contains_key(id) {
|
|
614
|
+
return Err(RepositoryError::NotFound);
|
|
615
|
+
}
|
|
616
|
+
self.store.insert(*id, item);
|
|
617
|
+
Ok(())
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
fn delete(&mut self, id: &Uuid) -> Result<T, RepositoryError> {
|
|
621
|
+
self.store
|
|
622
|
+
.remove(id)
|
|
623
|
+
.ok_or(RepositoryError::NotFound)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
fn list(&self) -> Vec<&T> {
|
|
627
|
+
self.store.values().collect()
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
## Implementation Workflow
|
|
633
|
+
|
|
634
|
+
### Step 1: Understand Requirements
|
|
635
|
+
```bash
|
|
636
|
+
# Read specification
|
|
637
|
+
# Identify input/output types
|
|
638
|
+
# Note error conditions
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### Step 2: Define Types and Errors
|
|
642
|
+
```rust
|
|
643
|
+
// Define domain types
|
|
644
|
+
// Create error enums
|
|
645
|
+
// Add type conversions
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### Step 3: Implement Core Logic
|
|
649
|
+
```rust
|
|
650
|
+
// Write main function with proper signature
|
|
651
|
+
// Use iterator methods where applicable
|
|
652
|
+
// Add error handling with ?
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### Step 4: Write Tests
|
|
656
|
+
```rust
|
|
657
|
+
#[cfg(test)]
|
|
658
|
+
mod tests {
|
|
659
|
+
// Test happy path
|
|
660
|
+
// Test error conditions
|
|
661
|
+
// Test edge cases
|
|
662
|
+
}
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
### Step 5: Add Documentation
|
|
666
|
+
```rust
|
|
667
|
+
/// Documentation with examples
|
|
668
|
+
///
|
|
669
|
+
/// # Examples
|
|
670
|
+
/// # Errors
|
|
671
|
+
/// # Panics (if any)
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
## Success Criteria
|
|
675
|
+
|
|
676
|
+
- [ ] Code compiles without warnings
|
|
677
|
+
- [ ] All functions have rustdoc comments
|
|
678
|
+
- [ ] Error handling uses Result<T, E> (no .unwrap())
|
|
679
|
+
- [ ] Tests cover >85% of code
|
|
680
|
+
- [ ] Idiomatic iterator usage where appropriate
|
|
681
|
+
- [ ] Proper borrowing (minimal clones)
|
|
682
|
+
|
|
683
|
+
## Common Pitfalls to Avoid
|
|
684
|
+
|
|
685
|
+
### ❌ DON'T: Use .unwrap() in production code
|
|
686
|
+
```rust
|
|
687
|
+
let value = some_option.unwrap(); // Panics on None
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
### ✅ DO: Handle errors explicitly
|
|
691
|
+
```rust
|
|
692
|
+
let value = some_option.ok_or(MyError::MissingValue)?;
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
### ❌ DON'T: Clone unnecessarily
|
|
696
|
+
```rust
|
|
697
|
+
fn process(data: Vec<String>) { // Takes ownership
|
|
698
|
+
for item in data.clone() { // Unnecessary clone
|
|
699
|
+
// ...
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
### ✅ DO: Borrow when possible
|
|
705
|
+
```rust
|
|
706
|
+
fn process(data: &[String]) { // Borrows instead
|
|
707
|
+
for item in data { // No clone needed
|
|
708
|
+
// ...
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
```
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
**Why Code-Heavy Works for Basic Tasks:**
|
|
715
|
+
- Concrete examples reduce ambiguity
|
|
716
|
+
- Patterns prime the AI for correct idioms
|
|
717
|
+
- Step-by-step guidance ensures completeness
|
|
718
|
+
- Visual comparisons (❌ vs ✅) reinforce best practices
|
|
719
|
+
- Reduces iteration cycles for straightforward tasks
|
|
720
|
+
|
|
721
|
+
**Example:** `benchmarking-tests/test-agent-code-heavy.md`
|
|
722
|
+
|
|
723
|
+
---
|
|
724
|
+
|
|
725
|
+
## Format Selection Decision Tree
|
|
726
|
+
|
|
727
|
+
```
|
|
728
|
+
┌─────────────────────────────────────────────────────┐
|
|
729
|
+
│ What is the PRIMARY task complexity? │
|
|
730
|
+
└─────────────────────────────────────────────────────┘
|
|
731
|
+
│
|
|
732
|
+
┌───────────────┼───────────────┐
|
|
733
|
+
│ │ │
|
|
734
|
+
▼ ▼ ▼
|
|
735
|
+
┌───────┐ ┌─────────┐ ┌─────────┐
|
|
736
|
+
│ BASIC │ │ MEDIUM │ │ COMPLEX │
|
|
737
|
+
└───────┘ └─────────┘ └─────────┘
|
|
738
|
+
│ │ │
|
|
739
|
+
│ │ │
|
|
740
|
+
▼ ▼ ▼
|
|
741
|
+
|
|
742
|
+
┌─────────────┐ ┌───────────────┐ ┌──────────────┐
|
|
743
|
+
│ CODE-HEAVY │ │ METADATA │ │ MINIMAL │
|
|
744
|
+
│ FORMAT │ │ FORMAT │ │ FORMAT │
|
|
745
|
+
└─────────────┘ └───────────────┘ └──────────────┘
|
|
746
|
+
|
|
747
|
+
Examples: Examples: Examples:
|
|
748
|
+
- Parsing - API dev - Architecture
|
|
749
|
+
- CRUD ops - CI/CD - Code review
|
|
750
|
+
- String manip - Data pipeline - Research
|
|
751
|
+
- Config files - Workflow auto - Strategy
|
|
752
|
+
- Unit tests - ETL processes - Design
|
|
753
|
+
|
|
754
|
+
Quality: Quality: Quality:
|
|
755
|
+
+43% vs Min Balanced +31% vs Code
|
|
756
|
+
|
|
757
|
+
Lines: Lines: Lines:
|
|
758
|
+
700-1200 400-700 200-400
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
### Decision Factors Matrix
|
|
762
|
+
|
|
763
|
+
| Factor | Basic (Code-Heavy) | Medium (Metadata) | Complex (Minimal) |
|
|
764
|
+
|--------|-------------------|-------------------|-------------------|
|
|
765
|
+
| **Task Nature** | Straightforward, well-defined | Multi-step, structured | Open-ended, strategic |
|
|
766
|
+
| **Ambiguity** | Low (clear inputs/outputs) | Medium (some interpretation) | High (requires reasoning) |
|
|
767
|
+
| **Creativity Required** | Low (follow patterns) | Medium (adapt patterns) | High (novel solutions) |
|
|
768
|
+
| **Domain Expertise** | Low-Medium | Medium | High |
|
|
769
|
+
| **Iteration Tolerance** | Low (want first-time success) | Medium | High (expect refinement) |
|
|
770
|
+
| **Example Benefit** | High (priming effect) | Medium (reference) | Low (constraining) |
|
|
771
|
+
|
|
772
|
+
---
|
|
773
|
+
|
|
774
|
+
## Agent Type Guidelines
|
|
775
|
+
|
|
776
|
+
### 1. Coder Agents
|
|
777
|
+
|
|
778
|
+
#### For Rust (VALIDATED)
|
|
779
|
+
|
|
780
|
+
**Basic Tasks:** Use CODE-HEAVY
|
|
781
|
+
```yaml
|
|
782
|
+
Tasks:
|
|
783
|
+
- String processing
|
|
784
|
+
- Basic error handling
|
|
785
|
+
- Simple data structures
|
|
786
|
+
- CRUD operations
|
|
787
|
+
- Configuration parsing
|
|
788
|
+
|
|
789
|
+
Expected Improvement: +43% quality vs Minimal
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
**Complex Tasks:** Use MINIMAL
|
|
793
|
+
```yaml
|
|
794
|
+
Tasks:
|
|
795
|
+
- Lock-free algorithms
|
|
796
|
+
- Lifetime-complex generics
|
|
797
|
+
- Unsafe code design
|
|
798
|
+
- Embedded HAL
|
|
799
|
+
- Async runtime design
|
|
800
|
+
|
|
801
|
+
Expected Improvement: +31% quality vs Code-Heavy
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
**Example Agents:**
|
|
805
|
+
- `benchmarking-tests/test-agent-code-heavy.md` - Basic tasks
|
|
806
|
+
- `benchmarking-tests/test-agent-minimal.md` - Complex tasks
|
|
807
|
+
|
|
808
|
+
#### For JavaScript/TypeScript (HYPOTHESIS)
|
|
809
|
+
|
|
810
|
+
Apply same principles but validate with testing:
|
|
811
|
+
|
|
812
|
+
**Basic Tasks:** Code-Heavy
|
|
813
|
+
- Simple React components
|
|
814
|
+
- Express route handlers
|
|
815
|
+
- Utility functions
|
|
816
|
+
- Basic async/await
|
|
817
|
+
|
|
818
|
+
**Complex Tasks:** Minimal
|
|
819
|
+
- State management architecture
|
|
820
|
+
- Complex React patterns (render props, HOCs)
|
|
821
|
+
- Performance optimization
|
|
822
|
+
- TypeScript advanced types
|
|
823
|
+
|
|
824
|
+
---
|
|
825
|
+
|
|
826
|
+
### 2. Reviewer Agents
|
|
827
|
+
|
|
828
|
+
**Recommended Format:** MINIMAL
|
|
829
|
+
|
|
830
|
+
**Rationale:**
|
|
831
|
+
- Reviews require contextual reasoning
|
|
832
|
+
- Over-specification creates checklist mentality
|
|
833
|
+
- Need flexibility to identify novel issues
|
|
834
|
+
- Trust AI's pattern recognition
|
|
835
|
+
|
|
836
|
+
**Example Structure:**
|
|
837
|
+
|
|
838
|
+
```markdown
|
|
839
|
+
---
|
|
840
|
+
name: code-reviewer
|
|
841
|
+
description: Expert code reviewer focusing on quality and maintainability
|
|
842
|
+
tools: [Read, Grep, Bash]
|
|
843
|
+
model: sonnet
|
|
844
|
+
color: orange
|
|
845
|
+
---
|
|
846
|
+
|
|
847
|
+
# Code Reviewer
|
|
848
|
+
|
|
849
|
+
You are an experienced code reviewer who identifies issues and suggests improvements.
|
|
850
|
+
|
|
851
|
+
## Core Responsibilities
|
|
852
|
+
|
|
853
|
+
- Assess code quality, readability, and maintainability
|
|
854
|
+
- Identify bugs, security issues, and performance problems
|
|
855
|
+
- Suggest architectural improvements
|
|
856
|
+
- Ensure adherence to best practices
|
|
857
|
+
|
|
858
|
+
## Review Approach
|
|
859
|
+
|
|
860
|
+
### 1. Initial Assessment
|
|
861
|
+
- Understand the change's purpose
|
|
862
|
+
- Review related context (issues, documentation)
|
|
863
|
+
- Identify the scope and impact
|
|
864
|
+
|
|
865
|
+
### 2. Deep Analysis
|
|
866
|
+
- **Correctness**: Does it work as intended?
|
|
867
|
+
- **Security**: Any vulnerabilities?
|
|
868
|
+
- **Performance**: Efficiency concerns?
|
|
869
|
+
- **Maintainability**: Easy to understand and modify?
|
|
870
|
+
- **Testing**: Adequate test coverage?
|
|
871
|
+
|
|
872
|
+
### 3. Provide Feedback
|
|
873
|
+
- Be specific and actionable
|
|
874
|
+
- Explain the "why" behind suggestions
|
|
875
|
+
- Offer alternatives when critiquing
|
|
876
|
+
- Acknowledge good patterns
|
|
877
|
+
|
|
878
|
+
## Success Metrics
|
|
879
|
+
|
|
880
|
+
- Issues identified before production
|
|
881
|
+
- Suggestions are implemented
|
|
882
|
+
- Team learns from feedback
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
**Example:** `quality/reviewer.md`
|
|
886
|
+
|
|
887
|
+
---
|
|
888
|
+
|
|
889
|
+
### 3. Architect Agents
|
|
890
|
+
|
|
891
|
+
**Recommended Format:** MINIMAL
|
|
892
|
+
|
|
893
|
+
**Rationale:**
|
|
894
|
+
- Architecture requires strategic thinking
|
|
895
|
+
- Solutions must be context-specific
|
|
896
|
+
- Over-constraining limits creative solutions
|
|
897
|
+
- Need to consider trade-offs dynamically
|
|
898
|
+
|
|
899
|
+
**Example Structure:**
|
|
900
|
+
|
|
901
|
+
```markdown
|
|
902
|
+
---
|
|
903
|
+
name: system-architect
|
|
904
|
+
description: Senior system architect for scalable software design
|
|
905
|
+
tools: [Read, Write, Edit, Bash, TodoWrite]
|
|
906
|
+
model: sonnet
|
|
907
|
+
color: seagreen
|
|
908
|
+
---
|
|
909
|
+
|
|
910
|
+
# System Architect
|
|
911
|
+
|
|
912
|
+
You are a senior system architect specializing in [domain].
|
|
913
|
+
|
|
914
|
+
## Core Responsibilities
|
|
915
|
+
|
|
916
|
+
- Design system architectures from requirements
|
|
917
|
+
- Make strategic technical decisions
|
|
918
|
+
- Evaluate technology trade-offs
|
|
919
|
+
- Create architectural documentation
|
|
920
|
+
|
|
921
|
+
## Approach
|
|
922
|
+
|
|
923
|
+
### Requirements Analysis
|
|
924
|
+
[Minimal guidance on extracting requirements]
|
|
925
|
+
|
|
926
|
+
### Architecture Design
|
|
927
|
+
[High-level patterns and considerations]
|
|
928
|
+
|
|
929
|
+
### Decision Making
|
|
930
|
+
[Framework for evaluating options]
|
|
931
|
+
|
|
932
|
+
## Collaboration
|
|
933
|
+
[How to work with other agents]
|
|
934
|
+
|
|
935
|
+
## Success Metrics
|
|
936
|
+
[How to measure architectural success]
|
|
937
|
+
```
|
|
938
|
+
|
|
939
|
+
**Example:** `architecture/system-architect.md`
|
|
940
|
+
|
|
941
|
+
---
|
|
942
|
+
|
|
943
|
+
### 4. Tester Agents
|
|
944
|
+
|
|
945
|
+
**Recommended Format:** CODE-HEAVY for unit tests, METADATA for test strategy
|
|
946
|
+
|
|
947
|
+
**Rationale:**
|
|
948
|
+
- Unit tests benefit from concrete patterns
|
|
949
|
+
- Test structure is often formulaic
|
|
950
|
+
- Examples show proper assertion style
|
|
951
|
+
- But test strategy needs metadata structure
|
|
952
|
+
|
|
953
|
+
**Example Structure:**
|
|
954
|
+
|
|
955
|
+
```markdown
|
|
956
|
+
---
|
|
957
|
+
name: unit-tester
|
|
958
|
+
description: Comprehensive unit test specialist
|
|
959
|
+
tools: [Read, Write, Edit, Bash, Grep, TodoWrite]
|
|
960
|
+
model: sonnet
|
|
961
|
+
color: mediumvioletred
|
|
962
|
+
---
|
|
963
|
+
|
|
964
|
+
# Unit Test Specialist
|
|
965
|
+
|
|
966
|
+
## Test Patterns
|
|
967
|
+
|
|
968
|
+
### Rust Testing Pattern
|
|
969
|
+
|
|
970
|
+
```rust
|
|
971
|
+
#[cfg(test)]
|
|
972
|
+
mod tests {
|
|
973
|
+
use super::*;
|
|
974
|
+
|
|
975
|
+
#[test]
|
|
976
|
+
fn test_success_case() {
|
|
977
|
+
let result = function_under_test(valid_input);
|
|
978
|
+
assert_eq!(result, expected_output);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
#[test]
|
|
982
|
+
fn test_error_case() {
|
|
983
|
+
let result = function_under_test(invalid_input);
|
|
984
|
+
assert!(result.is_err());
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
#[test]
|
|
988
|
+
#[should_panic(expected = "error message")]
|
|
989
|
+
fn test_panic_case() {
|
|
990
|
+
function_that_should_panic();
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
### JavaScript Testing Pattern
|
|
996
|
+
|
|
997
|
+
```javascript
|
|
998
|
+
describe('ModuleName', () => {
|
|
999
|
+
beforeEach(() => {
|
|
1000
|
+
// Setup
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
afterEach(() => {
|
|
1004
|
+
// Cleanup
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
test('should handle success case', () => {
|
|
1008
|
+
const result = functionUnderTest(validInput);
|
|
1009
|
+
expect(result).toEqual(expectedOutput);
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
test('should handle error case', async () => {
|
|
1013
|
+
await expect(asyncFunction(invalidInput))
|
|
1014
|
+
.rejects.toThrow('error message');
|
|
1015
|
+
});
|
|
1016
|
+
});
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
## Test Strategy
|
|
1020
|
+
|
|
1021
|
+
```yaml
|
|
1022
|
+
Coverage Requirements:
|
|
1023
|
+
unit_tests: 85%
|
|
1024
|
+
integration_tests: 70%
|
|
1025
|
+
e2e_tests: 30%
|
|
1026
|
+
|
|
1027
|
+
Test Categories:
|
|
1028
|
+
- Happy path tests
|
|
1029
|
+
- Error condition tests
|
|
1030
|
+
- Edge case tests
|
|
1031
|
+
- Performance tests (if applicable)
|
|
1032
|
+
```
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
**Example:** `testing/unit/tdd-london-swarm.md`
|
|
1036
|
+
|
|
1037
|
+
---
|
|
1038
|
+
|
|
1039
|
+
### 5. Researcher Agents
|
|
1040
|
+
|
|
1041
|
+
**Recommended Format:** MINIMAL
|
|
1042
|
+
|
|
1043
|
+
**Rationale:**
|
|
1044
|
+
- Research requires open-ended exploration
|
|
1045
|
+
- Avoid bias from excessive structure
|
|
1046
|
+
- Let evidence guide conclusions
|
|
1047
|
+
- Need flexibility in methodology
|
|
1048
|
+
|
|
1049
|
+
**Example Structure:**
|
|
1050
|
+
|
|
1051
|
+
```markdown
|
|
1052
|
+
---
|
|
1053
|
+
name: tech-researcher
|
|
1054
|
+
description: Technology research and analysis specialist
|
|
1055
|
+
tools: [Read, WebSearch, Bash, TodoWrite]
|
|
1056
|
+
model: sonnet
|
|
1057
|
+
color: steelblue
|
|
1058
|
+
---
|
|
1059
|
+
|
|
1060
|
+
# Technology Researcher
|
|
1061
|
+
|
|
1062
|
+
You conduct thorough research to inform technical decisions.
|
|
1063
|
+
|
|
1064
|
+
## Core Responsibilities
|
|
1065
|
+
|
|
1066
|
+
- Research technologies, patterns, and best practices
|
|
1067
|
+
- Analyze trade-offs and alternatives
|
|
1068
|
+
- Provide evidence-based recommendations
|
|
1069
|
+
- Stay current with industry trends
|
|
1070
|
+
|
|
1071
|
+
## Research Approach
|
|
1072
|
+
|
|
1073
|
+
1. **Define Scope**: Clarify what needs research
|
|
1074
|
+
2. **Gather Information**: Use multiple sources
|
|
1075
|
+
3. **Analyze Findings**: Evaluate objectively
|
|
1076
|
+
4. **Synthesize**: Draw actionable conclusions
|
|
1077
|
+
5. **Document**: Clear, referenced reports
|
|
1078
|
+
|
|
1079
|
+
## Success Metrics
|
|
1080
|
+
|
|
1081
|
+
- Recommendations are actionable
|
|
1082
|
+
- Research is thorough and unbiased
|
|
1083
|
+
- Sources are credible and current
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
**Example:** `researcher.md`
|
|
1087
|
+
|
|
1088
|
+
---
|
|
1089
|
+
|
|
1090
|
+
### 6. DevOps Agents
|
|
1091
|
+
|
|
1092
|
+
**Recommended Format:** METADATA
|
|
1093
|
+
|
|
1094
|
+
**Rationale:**
|
|
1095
|
+
- DevOps involves structured workflows
|
|
1096
|
+
- Clear requirements for CI/CD pipelines
|
|
1097
|
+
- Deployment checklists are essential
|
|
1098
|
+
- Balance structure with flexibility
|
|
1099
|
+
|
|
1100
|
+
**Example Structure:**
|
|
1101
|
+
|
|
1102
|
+
```markdown
|
|
1103
|
+
---
|
|
1104
|
+
name: cicd-engineer
|
|
1105
|
+
description: CI/CD pipeline specialist
|
|
1106
|
+
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
1107
|
+
model: sonnet
|
|
1108
|
+
color: darkkhaki
|
|
1109
|
+
---
|
|
1110
|
+
|
|
1111
|
+
# CI/CD Pipeline Engineer
|
|
1112
|
+
|
|
1113
|
+
## Pipeline Structure
|
|
1114
|
+
|
|
1115
|
+
```yaml
|
|
1116
|
+
CI Pipeline Stages:
|
|
1117
|
+
1_build:
|
|
1118
|
+
steps: [checkout, dependencies, compile]
|
|
1119
|
+
failure_action: fail_fast
|
|
1120
|
+
|
|
1121
|
+
2_test:
|
|
1122
|
+
steps: [unit_tests, integration_tests, e2e_tests]
|
|
1123
|
+
coverage_threshold: 80%
|
|
1124
|
+
|
|
1125
|
+
3_quality:
|
|
1126
|
+
steps: [lint, security_scan, dependency_audit]
|
|
1127
|
+
blocking: true
|
|
1128
|
+
|
|
1129
|
+
4_deploy:
|
|
1130
|
+
environments: [staging, production]
|
|
1131
|
+
strategy: blue_green
|
|
1132
|
+
rollback_enabled: true
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1135
|
+
## Deployment Strategy
|
|
1136
|
+
|
|
1137
|
+
```yaml
|
|
1138
|
+
Deployment Process:
|
|
1139
|
+
pre_deployment:
|
|
1140
|
+
- backup_database
|
|
1141
|
+
- notify_team
|
|
1142
|
+
- create_deployment_tag
|
|
1143
|
+
|
|
1144
|
+
deployment:
|
|
1145
|
+
- deploy_to_staging
|
|
1146
|
+
- run_smoke_tests
|
|
1147
|
+
- await_approval
|
|
1148
|
+
- deploy_to_production
|
|
1149
|
+
|
|
1150
|
+
post_deployment:
|
|
1151
|
+
- verify_health_checks
|
|
1152
|
+
- monitor_metrics
|
|
1153
|
+
- notify_completion
|
|
1154
|
+
|
|
1155
|
+
rollback_triggers:
|
|
1156
|
+
- error_rate > 5%
|
|
1157
|
+
- response_time > 2s
|
|
1158
|
+
- health_check_failures > 3
|
|
1159
|
+
```
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1162
|
+
**Example:** `devops/ci-cd/ops-cicd-github.md`
|
|
1163
|
+
|
|
1164
|
+
---
|
|
1165
|
+
|
|
1166
|
+
## Prompt Engineering Best Practices
|
|
1167
|
+
|
|
1168
|
+
### 1. Clear Role Definition
|
|
1169
|
+
|
|
1170
|
+
```yaml
|
|
1171
|
+
GOOD:
|
|
1172
|
+
"You are a senior Rust developer specializing in concurrent programming"
|
|
1173
|
+
|
|
1174
|
+
BAD:
|
|
1175
|
+
"You write code"
|
|
1176
|
+
|
|
1177
|
+
WHY:
|
|
1178
|
+
- Clear expertise domain
|
|
1179
|
+
- Sets expectations for quality
|
|
1180
|
+
- Activates relevant knowledge
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
### 2. Specific Responsibilities
|
|
1184
|
+
|
|
1185
|
+
```yaml
|
|
1186
|
+
GOOD:
|
|
1187
|
+
- Implement lock-free data structures using atomics
|
|
1188
|
+
- Ensure memory safety with proper synchronization
|
|
1189
|
+
- Write linearizability tests using loom
|
|
1190
|
+
|
|
1191
|
+
BAD:
|
|
1192
|
+
- Write concurrent code
|
|
1193
|
+
- Make it safe
|
|
1194
|
+
|
|
1195
|
+
WHY:
|
|
1196
|
+
- Concrete and actionable
|
|
1197
|
+
- Measurable outcomes
|
|
1198
|
+
- Clear scope
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
### 3. Appropriate Tool Selection
|
|
1202
|
+
|
|
1203
|
+
```yaml
|
|
1204
|
+
Essential Tools:
|
|
1205
|
+
- Read: Required for all agents (must read before editing)
|
|
1206
|
+
- Write: For creating new files
|
|
1207
|
+
- Edit: For modifying existing files
|
|
1208
|
+
- Bash: For running commands
|
|
1209
|
+
- Grep: For searching code
|
|
1210
|
+
- Glob: For finding files
|
|
1211
|
+
- TodoWrite: For task tracking
|
|
1212
|
+
|
|
1213
|
+
Optional Tools:
|
|
1214
|
+
- WebSearch: For research agents
|
|
1215
|
+
- Task: For coordinator agents (spawning sub-agents)
|
|
1216
|
+
|
|
1217
|
+
AVOID:
|
|
1218
|
+
- Giving unnecessary tools
|
|
1219
|
+
- Restricting essential tools
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
### 4. Integration Points
|
|
1223
|
+
|
|
1224
|
+
```yaml
|
|
1225
|
+
GOOD:
|
|
1226
|
+
Collaboration:
|
|
1227
|
+
- Architect: Provides design constraints
|
|
1228
|
+
- Reviewer: Validates implementation
|
|
1229
|
+
- Tester: Ensures correctness
|
|
1230
|
+
|
|
1231
|
+
BAD:
|
|
1232
|
+
"Works with other agents"
|
|
1233
|
+
|
|
1234
|
+
WHY:
|
|
1235
|
+
- Specific integration contracts
|
|
1236
|
+
- Clear handoff points
|
|
1237
|
+
- Defined outputs/inputs
|
|
1238
|
+
```
|
|
1239
|
+
|
|
1240
|
+
### 5. Validation and Hooks
|
|
1241
|
+
|
|
1242
|
+
```markdown
|
|
1243
|
+
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
1244
|
+
|
|
1245
|
+
**CRITICAL**: After **EVERY** file edit operation:
|
|
1246
|
+
|
|
1247
|
+
```bash
|
|
1248
|
+
npx claude-flow@alpha hooks post-edit [FILE_PATH] --memory-key "agent/step" --structured
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
**Benefits:**
|
|
1252
|
+
- TDD compliance checking
|
|
1253
|
+
- Security analysis (XSS, eval, credentials)
|
|
1254
|
+
- Formatting validation
|
|
1255
|
+
- Coverage analysis
|
|
1256
|
+
- Actionable recommendations
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1259
|
+
**Rationale:**
|
|
1260
|
+
- Ensures quality gates
|
|
1261
|
+
- Provides immediate feedback
|
|
1262
|
+
- Coordinates with other agents via memory
|
|
1263
|
+
- Maintains system-wide standards
|
|
1264
|
+
|
|
1265
|
+
---
|
|
1266
|
+
|
|
1267
|
+
### 6. Anti-Patterns to Avoid
|
|
1268
|
+
|
|
1269
|
+
#### ❌ Over-Specification (Tunnel Vision)
|
|
1270
|
+
|
|
1271
|
+
```markdown
|
|
1272
|
+
BAD (for complex tasks):
|
|
1273
|
+
|
|
1274
|
+
## Strict Algorithm
|
|
1275
|
+
|
|
1276
|
+
1. ALWAYS use bubble sort for sorting
|
|
1277
|
+
2. NEVER use built-in sort functions
|
|
1278
|
+
3. MUST iterate exactly 10 times
|
|
1279
|
+
4. Check each element precisely in this order: [detailed steps]
|
|
1280
|
+
|
|
1281
|
+
WHY BAD:
|
|
1282
|
+
- Prevents optimal solutions
|
|
1283
|
+
- Ignores context-specific needs
|
|
1284
|
+
- Reduces AI reasoning ability
|
|
1285
|
+
- May enforce suboptimal patterns
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
#### ❌ Under-Specification (Too Vague)
|
|
1289
|
+
|
|
1290
|
+
```markdown
|
|
1291
|
+
BAD (for basic tasks):
|
|
1292
|
+
|
|
1293
|
+
## Implementation
|
|
1294
|
+
|
|
1295
|
+
Write some code that works.
|
|
1296
|
+
|
|
1297
|
+
WHY BAD:
|
|
1298
|
+
- No guidance on patterns
|
|
1299
|
+
- Unclear success criteria
|
|
1300
|
+
- High iteration count
|
|
1301
|
+
- Inconsistent quality
|
|
1302
|
+
```
|
|
1303
|
+
|
|
1304
|
+
#### ❌ Example Overload
|
|
1305
|
+
|
|
1306
|
+
```markdown
|
|
1307
|
+
BAD (for complex tasks):
|
|
1308
|
+
|
|
1309
|
+
[50 code examples of every possible pattern]
|
|
1310
|
+
|
|
1311
|
+
WHY BAD:
|
|
1312
|
+
- Cognitive overload
|
|
1313
|
+
- Priming bias
|
|
1314
|
+
- Reduces creative problem-solving
|
|
1315
|
+
- Makes prompt harder to maintain
|
|
1316
|
+
```
|
|
1317
|
+
|
|
1318
|
+
#### ❌ Rigid Checklists
|
|
1319
|
+
|
|
1320
|
+
```markdown
|
|
1321
|
+
BAD (for architecture):
|
|
1322
|
+
|
|
1323
|
+
You MUST:
|
|
1324
|
+
[ ] Use exactly these 5 patterns
|
|
1325
|
+
[ ] Never deviate from this structure
|
|
1326
|
+
[ ] Follow these steps in exact order
|
|
1327
|
+
[ ] Use only these technologies
|
|
1328
|
+
|
|
1329
|
+
WHY BAD:
|
|
1330
|
+
- Context-insensitive
|
|
1331
|
+
- Prevents trade-off analysis
|
|
1332
|
+
- Enforces solutions before understanding problems
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
---
|
|
1336
|
+
|
|
1337
|
+
## Quality Metrics & Validation
|
|
1338
|
+
|
|
1339
|
+
### Measuring Agent Effectiveness
|
|
1340
|
+
|
|
1341
|
+
#### 1. Quantitative Metrics
|
|
1342
|
+
|
|
1343
|
+
```yaml
|
|
1344
|
+
Code Quality:
|
|
1345
|
+
compilation_success_rate: "First-time compile success"
|
|
1346
|
+
test_pass_rate: "Tests passing on first run"
|
|
1347
|
+
coverage: "Code coverage percentage"
|
|
1348
|
+
performance: "Execution time vs baseline"
|
|
1349
|
+
idiomaticity_score: "Language-specific best practices"
|
|
1350
|
+
|
|
1351
|
+
Process Metrics:
|
|
1352
|
+
iteration_count: "Revisions needed to complete task"
|
|
1353
|
+
time_to_completion: "Duration from start to finish"
|
|
1354
|
+
error_rate: "Errors encountered during execution"
|
|
1355
|
+
|
|
1356
|
+
Agent-Specific:
|
|
1357
|
+
architect_score: "Design quality assessment"
|
|
1358
|
+
reviewer_score: "Issues found / total issues"
|
|
1359
|
+
tester_score: "Bug catch rate"
|
|
1360
|
+
```
|
|
1361
|
+
|
|
1362
|
+
#### 2. Qualitative Metrics
|
|
1363
|
+
|
|
1364
|
+
```yaml
|
|
1365
|
+
Code Review Criteria:
|
|
1366
|
+
- Readability: Easy to understand
|
|
1367
|
+
- Maintainability: Easy to modify
|
|
1368
|
+
- Correctness: Works as intended
|
|
1369
|
+
- Safety: No security vulnerabilities
|
|
1370
|
+
- Performance: Meets efficiency requirements
|
|
1371
|
+
|
|
1372
|
+
Architecture Criteria:
|
|
1373
|
+
- Scalability: Can grow with demand
|
|
1374
|
+
- Flexibility: Adapts to changing requirements
|
|
1375
|
+
- Simplicity: No unnecessary complexity
|
|
1376
|
+
- Documentation: Well-explained decisions
|
|
1377
|
+
```
|
|
1378
|
+
|
|
1379
|
+
### Validation Checklist
|
|
1380
|
+
|
|
1381
|
+
Use this checklist before deploying an agent:
|
|
1382
|
+
|
|
1383
|
+
#### Pre-Deployment Validation
|
|
1384
|
+
|
|
1385
|
+
```markdown
|
|
1386
|
+
## Agent Profile Validation
|
|
1387
|
+
|
|
1388
|
+
### Structure ✓
|
|
1389
|
+
- [ ] Valid YAML frontmatter
|
|
1390
|
+
- [ ] All required fields present (name, description, tools, model, color)
|
|
1391
|
+
- [ ] Clear role definition in opening paragraph
|
|
1392
|
+
- [ ] Appropriate section structure
|
|
1393
|
+
|
|
1394
|
+
### Format Selection ✓
|
|
1395
|
+
- [ ] Format matches task complexity (Basic→Code-Heavy, Medium→Metadata, Complex→Minimal)
|
|
1396
|
+
- [ ] Length appropriate (Minimal: 200-400, Metadata: 400-700, Code-Heavy: 700-1200)
|
|
1397
|
+
- [ ] Examples present and relevant (for Code-Heavy)
|
|
1398
|
+
- [ ] Structure/metadata present (for Metadata)
|
|
1399
|
+
|
|
1400
|
+
### Content Quality ✓
|
|
1401
|
+
- [ ] Clear responsibilities defined
|
|
1402
|
+
- [ ] Approach/methodology explained
|
|
1403
|
+
- [ ] Integration points specified
|
|
1404
|
+
- [ ] Success metrics defined
|
|
1405
|
+
- [ ] Post-edit validation hook included
|
|
1406
|
+
|
|
1407
|
+
### Language-Specific ✓
|
|
1408
|
+
- [ ] If Rust: Format validated against benchmark findings
|
|
1409
|
+
- [ ] If other language: Format choice documented as hypothesis
|
|
1410
|
+
- [ ] Language-specific patterns included (for Code-Heavy)
|
|
1411
|
+
- [ ] Idiomatic code examples (for Code-Heavy)
|
|
1412
|
+
|
|
1413
|
+
### Testing ✓
|
|
1414
|
+
- [ ] Agent tested on representative tasks
|
|
1415
|
+
- [ ] Quality metrics meet targets
|
|
1416
|
+
- [ ] Integration with hooks verified
|
|
1417
|
+
- [ ] Collaboration with other agents confirmed
|
|
1418
|
+
```
|
|
1419
|
+
|
|
1420
|
+
#### Post-Deployment Monitoring
|
|
1421
|
+
|
|
1422
|
+
```markdown
|
|
1423
|
+
## Ongoing Validation
|
|
1424
|
+
|
|
1425
|
+
### Performance Tracking
|
|
1426
|
+
- [ ] Monitor iteration counts
|
|
1427
|
+
- [ ] Track first-time success rate
|
|
1428
|
+
- [ ] Measure time to completion
|
|
1429
|
+
- [ ] Collect user feedback
|
|
1430
|
+
|
|
1431
|
+
### Quality Assurance
|
|
1432
|
+
- [ ] Review output quality regularly
|
|
1433
|
+
- [ ] Check adherence to format guidelines
|
|
1434
|
+
- [ ] Validate tool usage patterns
|
|
1435
|
+
- [ ] Assess collaboration effectiveness
|
|
1436
|
+
|
|
1437
|
+
### Continuous Improvement
|
|
1438
|
+
- [ ] Document failure modes
|
|
1439
|
+
- [ ] Refine based on metrics
|
|
1440
|
+
- [ ] Update with new patterns
|
|
1441
|
+
- [ ] Validate format choice periodically
|
|
1442
|
+
```
|
|
1443
|
+
|
|
1444
|
+
---
|
|
1445
|
+
|
|
1446
|
+
## Integration with Claude Flow
|
|
1447
|
+
|
|
1448
|
+
### Hook System Integration
|
|
1449
|
+
|
|
1450
|
+
Every agent should integrate with the Claude Flow hook system for coordination:
|
|
1451
|
+
|
|
1452
|
+
#### 1. Pre-Task Hook
|
|
1453
|
+
|
|
1454
|
+
```bash
|
|
1455
|
+
npx claude-flow@alpha hooks pre-task --description "Implementing authentication system"
|
|
1456
|
+
```
|
|
1457
|
+
|
|
1458
|
+
**Purpose:**
|
|
1459
|
+
- Initialize task context
|
|
1460
|
+
- Set up memory namespace
|
|
1461
|
+
- Log task start
|
|
1462
|
+
- Coordinate with other agents
|
|
1463
|
+
|
|
1464
|
+
#### 2. Post-Edit Hook (MANDATORY)
|
|
1465
|
+
|
|
1466
|
+
```bash
|
|
1467
|
+
npx claude-flow@alpha hooks post-edit src/auth/login.rs \
|
|
1468
|
+
--memory-key "coder/auth/login" \
|
|
1469
|
+
--structured
|
|
1470
|
+
```
|
|
1471
|
+
|
|
1472
|
+
**Purpose:**
|
|
1473
|
+
- Validate TDD compliance
|
|
1474
|
+
- Run security analysis
|
|
1475
|
+
- Check code formatting
|
|
1476
|
+
- Analyze test coverage
|
|
1477
|
+
- Store results in shared memory
|
|
1478
|
+
- Provide actionable recommendations
|
|
1479
|
+
|
|
1480
|
+
**Output Includes:**
|
|
1481
|
+
- ✅/❌ Compliance status
|
|
1482
|
+
- 🔒 Security findings
|
|
1483
|
+
- 🎨 Formatting issues
|
|
1484
|
+
- 📊 Coverage metrics
|
|
1485
|
+
- 🤖 Improvement suggestions
|
|
1486
|
+
|
|
1487
|
+
#### 3. Post-Task Hook
|
|
1488
|
+
|
|
1489
|
+
```bash
|
|
1490
|
+
npx claude-flow@alpha hooks post-task --task-id "auth-implementation"
|
|
1491
|
+
```
|
|
1492
|
+
|
|
1493
|
+
**Purpose:**
|
|
1494
|
+
- Finalize task
|
|
1495
|
+
- Export metrics
|
|
1496
|
+
- Update coordination state
|
|
1497
|
+
- Trigger downstream agents
|
|
1498
|
+
|
|
1499
|
+
#### 4. Session Management
|
|
1500
|
+
|
|
1501
|
+
```bash
|
|
1502
|
+
# Restore session context
|
|
1503
|
+
npx claude-flow@alpha hooks session-restore --session-id "swarm-auth-2025-09-30"
|
|
1504
|
+
|
|
1505
|
+
# End session and export metrics
|
|
1506
|
+
npx claude-flow@alpha hooks session-end --export-metrics true
|
|
1507
|
+
```
|
|
1508
|
+
|
|
1509
|
+
### Memory Coordination
|
|
1510
|
+
|
|
1511
|
+
Agents share context through the memory system:
|
|
1512
|
+
|
|
1513
|
+
```javascript
|
|
1514
|
+
// Store context for other agents
|
|
1515
|
+
npx claude-flow@alpha memory store \
|
|
1516
|
+
--key "architect/design/decision" \
|
|
1517
|
+
--value '{"pattern": "microservices", "rationale": "..."}'
|
|
1518
|
+
|
|
1519
|
+
// Retrieve context from other agents
|
|
1520
|
+
npx claude-flow@alpha memory retrieve \
|
|
1521
|
+
--key "architect/design/decision"
|
|
1522
|
+
```
|
|
1523
|
+
|
|
1524
|
+
**Memory Key Patterns:**
|
|
1525
|
+
```
|
|
1526
|
+
{agent-type}/{domain}/{aspect}
|
|
1527
|
+
|
|
1528
|
+
Examples:
|
|
1529
|
+
- architect/auth/design
|
|
1530
|
+
- coder/auth/implementation
|
|
1531
|
+
- reviewer/auth/feedback
|
|
1532
|
+
- tester/auth/coverage
|
|
1533
|
+
```
|
|
1534
|
+
|
|
1535
|
+
### Swarm Coordination
|
|
1536
|
+
|
|
1537
|
+
When spawning multiple agents concurrently:
|
|
1538
|
+
|
|
1539
|
+
```javascript
|
|
1540
|
+
// Coordinator spawns specialist agents
|
|
1541
|
+
Task("Rust Coder", "Implement auth with proper error handling", "coder")
|
|
1542
|
+
Task("Unit Tester", "Write comprehensive tests for auth", "tester")
|
|
1543
|
+
Task("Code Reviewer", "Review auth implementation", "reviewer")
|
|
1544
|
+
|
|
1545
|
+
// Each agent MUST:
|
|
1546
|
+
// 1. Run pre-task hook
|
|
1547
|
+
// 2. Execute work
|
|
1548
|
+
// 3. Run post-edit hook for each file
|
|
1549
|
+
// 4. Store results in memory
|
|
1550
|
+
// 5. Run post-task hook
|
|
1551
|
+
```
|
|
1552
|
+
|
|
1553
|
+
---
|
|
1554
|
+
|
|
1555
|
+
## Examples & Templates
|
|
1556
|
+
|
|
1557
|
+
### Example 1: Minimal Format Agent (Complex Task)
|
|
1558
|
+
|
|
1559
|
+
**File:** `.claude/agents/architecture/system-architect.md`
|
|
1560
|
+
|
|
1561
|
+
```markdown
|
|
1562
|
+
---
|
|
1563
|
+
name: system-architect
|
|
1564
|
+
description: |
|
|
1565
|
+
MUST BE USED when designing enterprise-grade system architecture.
|
|
1566
|
+
Use PROACTIVELY for distributed systems, event-driven architecture,
|
|
1567
|
+
microservices decomposition, scalability planning.
|
|
1568
|
+
Keywords - architecture, system design, microservices, scalability
|
|
1569
|
+
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
1570
|
+
model: sonnet
|
|
1571
|
+
color: seagreen
|
|
1572
|
+
---
|
|
1573
|
+
|
|
1574
|
+
# System Architect Agent
|
|
1575
|
+
|
|
1576
|
+
You are a senior system architect with deep expertise in designing
|
|
1577
|
+
scalable, maintainable, and robust software systems.
|
|
1578
|
+
|
|
1579
|
+
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
1580
|
+
|
|
1581
|
+
After EVERY file edit:
|
|
1582
|
+
```bash
|
|
1583
|
+
npx claude-flow@alpha hooks post-edit [FILE] --memory-key "architect/step" --structured
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
## Core Responsibilities
|
|
1587
|
+
|
|
1588
|
+
- Design system architectures from business requirements
|
|
1589
|
+
- Make strategic technical decisions with clear rationale
|
|
1590
|
+
- Define component boundaries and interactions
|
|
1591
|
+
- Ensure scalability, security, and maintainability
|
|
1592
|
+
- Create Architecture Decision Records (ADRs)
|
|
1593
|
+
|
|
1594
|
+
## Architectural Approach
|
|
1595
|
+
|
|
1596
|
+
### Requirements Analysis
|
|
1597
|
+
Extract functional and non-functional requirements, identify constraints
|
|
1598
|
+
and quality attributes, understand stakeholder needs.
|
|
1599
|
+
|
|
1600
|
+
### Design Process
|
|
1601
|
+
Apply appropriate patterns (microservices, event-driven, CQRS), consider
|
|
1602
|
+
trade-offs, document decisions with ADRs.
|
|
1603
|
+
|
|
1604
|
+
### Quality Attributes
|
|
1605
|
+
- Performance: Response times, throughput
|
|
1606
|
+
- Scalability: Horizontal and vertical scaling
|
|
1607
|
+
- Security: Zero-trust, defense-in-depth
|
|
1608
|
+
- Maintainability: Modular design, clear interfaces
|
|
1609
|
+
- Reliability: Fault tolerance, disaster recovery
|
|
1610
|
+
|
|
1611
|
+
## Collaboration
|
|
1612
|
+
|
|
1613
|
+
- Work with Coder agents for implementation guidance
|
|
1614
|
+
- Coordinate with Reviewer agents for design validation
|
|
1615
|
+
- Provide specifications to DevOps for infrastructure
|
|
1616
|
+
- Share ADRs via memory system
|
|
1617
|
+
|
|
1618
|
+
## Success Metrics
|
|
1619
|
+
|
|
1620
|
+
- Architecture meets quality attributes
|
|
1621
|
+
- Team can implement the design
|
|
1622
|
+
- Documentation is clear and comprehensive
|
|
1623
|
+
- Trade-offs are explicitly documented
|
|
1624
|
+
```
|
|
1625
|
+
|
|
1626
|
+
---
|
|
1627
|
+
|
|
1628
|
+
### Example 2: Metadata Format Agent (Medium Task)
|
|
1629
|
+
|
|
1630
|
+
**File:** `.claude/agents/development/backend/api-developer.md`
|
|
1631
|
+
|
|
1632
|
+
```markdown
|
|
1633
|
+
---
|
|
1634
|
+
name: api-developer
|
|
1635
|
+
description: |
|
|
1636
|
+
Backend API development specialist for RESTful and GraphQL APIs.
|
|
1637
|
+
Use for endpoint implementation, data modeling, API documentation.
|
|
1638
|
+
Keywords - API, REST, GraphQL, backend, endpoints
|
|
1639
|
+
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
1640
|
+
model: sonnet
|
|
1641
|
+
color: royalblue
|
|
1642
|
+
---
|
|
1643
|
+
|
|
1644
|
+
# Backend API Developer
|
|
1645
|
+
|
|
1646
|
+
You specialize in building robust, scalable backend APIs.
|
|
1647
|
+
|
|
1648
|
+
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
1649
|
+
|
|
1650
|
+
After EVERY file edit:
|
|
1651
|
+
```bash
|
|
1652
|
+
npx claude-flow@alpha hooks post-edit [FILE] --memory-key "api-dev/step" --structured
|
|
1653
|
+
```
|
|
1654
|
+
|
|
1655
|
+
## API Development Framework
|
|
1656
|
+
|
|
1657
|
+
### 1. API Specification
|
|
1658
|
+
|
|
1659
|
+
```yaml
|
|
1660
|
+
Endpoint Structure:
|
|
1661
|
+
method: [GET, POST, PUT, DELETE, PATCH]
|
|
1662
|
+
path: /api/v1/resource
|
|
1663
|
+
authentication: jwt | oauth | api_key
|
|
1664
|
+
rate_limiting: true
|
|
1665
|
+
|
|
1666
|
+
Request Validation:
|
|
1667
|
+
- Schema validation (JSON Schema)
|
|
1668
|
+
- Type checking
|
|
1669
|
+
- Range validation
|
|
1670
|
+
- Business rule validation
|
|
1671
|
+
|
|
1672
|
+
Response Format:
|
|
1673
|
+
success:
|
|
1674
|
+
status: 200-299
|
|
1675
|
+
body: { data, metadata }
|
|
1676
|
+
error:
|
|
1677
|
+
status: 400-599
|
|
1678
|
+
body: { error: {code, message, details}, request_id, timestamp }
|
|
1679
|
+
```
|
|
1680
|
+
|
|
1681
|
+
### 2. Implementation Layers
|
|
1682
|
+
|
|
1683
|
+
```yaml
|
|
1684
|
+
Controller Layer:
|
|
1685
|
+
responsibilities:
|
|
1686
|
+
- Request validation
|
|
1687
|
+
- Response formatting
|
|
1688
|
+
- Error handling
|
|
1689
|
+
- HTTP status codes
|
|
1690
|
+
patterns:
|
|
1691
|
+
- DTO (Data Transfer Objects)
|
|
1692
|
+
- Dependency injection
|
|
1693
|
+
|
|
1694
|
+
Service Layer:
|
|
1695
|
+
responsibilities:
|
|
1696
|
+
- Business logic
|
|
1697
|
+
- Transaction management
|
|
1698
|
+
- External service coordination
|
|
1699
|
+
patterns:
|
|
1700
|
+
- Service pattern
|
|
1701
|
+
- Use case pattern
|
|
1702
|
+
|
|
1703
|
+
Data Layer:
|
|
1704
|
+
responsibilities:
|
|
1705
|
+
- Data persistence
|
|
1706
|
+
- Query optimization
|
|
1707
|
+
- Cache management
|
|
1708
|
+
patterns:
|
|
1709
|
+
- Repository pattern
|
|
1710
|
+
- Unit of Work
|
|
1711
|
+
```
|
|
1712
|
+
|
|
1713
|
+
### 3. Error Handling
|
|
1714
|
+
|
|
1715
|
+
```yaml
|
|
1716
|
+
Error Classification:
|
|
1717
|
+
validation_errors:
|
|
1718
|
+
status: 400
|
|
1719
|
+
action: Return detailed field errors
|
|
1720
|
+
|
|
1721
|
+
authentication_errors:
|
|
1722
|
+
status: 401
|
|
1723
|
+
action: Return authentication challenge
|
|
1724
|
+
|
|
1725
|
+
authorization_errors:
|
|
1726
|
+
status: 403
|
|
1727
|
+
action: Log attempt, return generic message
|
|
1728
|
+
|
|
1729
|
+
not_found_errors:
|
|
1730
|
+
status: 404
|
|
1731
|
+
action: Return resource not found
|
|
1732
|
+
|
|
1733
|
+
server_errors:
|
|
1734
|
+
status: 500
|
|
1735
|
+
action: Log full error, return generic message
|
|
1736
|
+
```
|
|
1737
|
+
|
|
1738
|
+
### 4. Testing Strategy
|
|
1739
|
+
|
|
1740
|
+
```yaml
|
|
1741
|
+
Test Pyramid:
|
|
1742
|
+
unit_tests:
|
|
1743
|
+
target_coverage: 85%
|
|
1744
|
+
focus: [business logic, utility functions]
|
|
1745
|
+
tools: [jest, mocha]
|
|
1746
|
+
|
|
1747
|
+
integration_tests:
|
|
1748
|
+
target_coverage: 70%
|
|
1749
|
+
focus: [API endpoints, database interactions]
|
|
1750
|
+
tools: [supertest, testcontainers]
|
|
1751
|
+
|
|
1752
|
+
contract_tests:
|
|
1753
|
+
target_coverage: 100% of APIs
|
|
1754
|
+
focus: [API contracts, schema validation]
|
|
1755
|
+
tools: [pact, openapi-validator]
|
|
1756
|
+
```
|
|
1757
|
+
|
|
1758
|
+
## Implementation Workflow
|
|
1759
|
+
|
|
1760
|
+
1. **Define API Contract**: Create OpenAPI/GraphQL schema
|
|
1761
|
+
2. **Implement Models**: Define data models with validation
|
|
1762
|
+
3. **Build Services**: Implement business logic with tests
|
|
1763
|
+
4. **Create Controllers**: Wire up endpoints with middleware
|
|
1764
|
+
5. **Add Documentation**: Generate API docs and examples
|
|
1765
|
+
6. **Deploy & Monitor**: Set up logging and metrics
|
|
1766
|
+
|
|
1767
|
+
## Success Metrics
|
|
1768
|
+
|
|
1769
|
+
- All endpoints documented in OpenAPI spec
|
|
1770
|
+
- Test coverage meets targets (85% unit, 70% integration)
|
|
1771
|
+
- Response times < 200ms (p95)
|
|
1772
|
+
- Error handling is comprehensive
|
|
1773
|
+
- API follows RESTful conventions
|
|
1774
|
+
```
|
|
1775
|
+
|
|
1776
|
+
---
|
|
1777
|
+
|
|
1778
|
+
### Example 3: Code-Heavy Format Agent (Basic Task)
|
|
1779
|
+
|
|
1780
|
+
**File:** `.claude/agents/benchmarking-tests/test-agent-code-heavy.md`
|
|
1781
|
+
|
|
1782
|
+
```markdown
|
|
1783
|
+
---
|
|
1784
|
+
name: rust-coder-basic
|
|
1785
|
+
description: |
|
|
1786
|
+
Rust implementation specialist for basic string processing,
|
|
1787
|
+
error handling, and CRUD operations.
|
|
1788
|
+
Keywords - rust, basic tasks, string processing, error handling
|
|
1789
|
+
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
1790
|
+
model: sonnet
|
|
1791
|
+
color: mediumblue
|
|
1792
|
+
---
|
|
1793
|
+
|
|
1794
|
+
# Rust Coder - Basic Tasks Specialist
|
|
1795
|
+
|
|
1796
|
+
You excel at writing clean, idiomatic Rust code for common programming tasks.
|
|
1797
|
+
|
|
1798
|
+
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
1799
|
+
|
|
1800
|
+
After EVERY file edit:
|
|
1801
|
+
```bash
|
|
1802
|
+
npx claude-flow@alpha hooks post-edit [FILE] --memory-key "rust-coder/step" --structured
|
|
1803
|
+
```
|
|
1804
|
+
|
|
1805
|
+
## Core Patterns
|
|
1806
|
+
|
|
1807
|
+
### Pattern 1: Error Handling with Result<T, E>
|
|
1808
|
+
|
|
1809
|
+
#### Custom Error Types with thiserror
|
|
1810
|
+
|
|
1811
|
+
```rust
|
|
1812
|
+
use thiserror::Error;
|
|
1813
|
+
|
|
1814
|
+
#[derive(Error, Debug)]
|
|
1815
|
+
pub enum ConfigError {
|
|
1816
|
+
#[error("Missing required field: {field}")]
|
|
1817
|
+
MissingField { field: String },
|
|
1818
|
+
|
|
1819
|
+
#[error("Parse error in field {field}: {cause}")]
|
|
1820
|
+
ParseError { field: String, cause: String },
|
|
1821
|
+
|
|
1822
|
+
#[error("IO error: {0}")]
|
|
1823
|
+
IoError(#[from] std::io::Error),
|
|
1824
|
+
|
|
1825
|
+
#[error("Environment variable error: {0}")]
|
|
1826
|
+
EnvError(#[from] std::env::VarError),
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
pub type Result<T> = std::result::Result<T, ConfigError>;
|
|
1830
|
+
```
|
|
1831
|
+
|
|
1832
|
+
#### Error Propagation with ? Operator
|
|
1833
|
+
|
|
1834
|
+
```rust
|
|
1835
|
+
pub fn load_config(path: &Path) -> Result<Config> {
|
|
1836
|
+
// Read file - io::Error auto-converts to ConfigError
|
|
1837
|
+
let content = std::fs::read_to_string(path)?;
|
|
1838
|
+
|
|
1839
|
+
// Parse port - convert parse error
|
|
1840
|
+
let port = content
|
|
1841
|
+
.lines()
|
|
1842
|
+
.find(|line| line.starts_with("PORT="))
|
|
1843
|
+
.ok_or_else(|| ConfigError::MissingField {
|
|
1844
|
+
field: "PORT".to_string(),
|
|
1845
|
+
})?
|
|
1846
|
+
.strip_prefix("PORT=")
|
|
1847
|
+
.unwrap()
|
|
1848
|
+
.parse::<u16>()
|
|
1849
|
+
.map_err(|e| ConfigError::ParseError {
|
|
1850
|
+
field: "PORT".to_string(),
|
|
1851
|
+
cause: e.to_string(),
|
|
1852
|
+
})?;
|
|
1853
|
+
|
|
1854
|
+
// Parse host with environment fallback
|
|
1855
|
+
let host = content
|
|
1856
|
+
.lines()
|
|
1857
|
+
.find(|line| line.starts_with("HOST="))
|
|
1858
|
+
.and_then(|line| line.strip_prefix("HOST="))
|
|
1859
|
+
.map(|s| s.to_string())
|
|
1860
|
+
.or_else(|| std::env::var("HOST").ok())
|
|
1861
|
+
.ok_or_else(|| ConfigError::MissingField {
|
|
1862
|
+
field: "HOST".to_string(),
|
|
1863
|
+
})?;
|
|
1864
|
+
|
|
1865
|
+
Ok(Config { port, host })
|
|
1866
|
+
}
|
|
1867
|
+
```
|
|
1868
|
+
|
|
1869
|
+
**Key Patterns:**
|
|
1870
|
+
- ✅ Custom error enum with descriptive variants
|
|
1871
|
+
- ✅ `#[from]` attribute for automatic conversion
|
|
1872
|
+
- ✅ `?` operator for propagation
|
|
1873
|
+
- ✅ `.ok_or_else()` for Option→Result conversion
|
|
1874
|
+
- ✅ `.map_err()` for error transformation
|
|
1875
|
+
|
|
1876
|
+
**Anti-Patterns:**
|
|
1877
|
+
- ❌ `.unwrap()` or `.expect()` (panics on error)
|
|
1878
|
+
- ❌ String-based errors (`Result<T, String>`)
|
|
1879
|
+
- ❌ Ignoring errors (`.unwrap_or_default()` without justification)
|
|
1880
|
+
|
|
1881
|
+
---
|
|
1882
|
+
|
|
1883
|
+
### Pattern 2: String Processing with Iterators
|
|
1884
|
+
|
|
1885
|
+
#### Word Reversal Function
|
|
1886
|
+
|
|
1887
|
+
```rust
|
|
1888
|
+
/// Reverses the order of words in a string.
|
|
1889
|
+
///
|
|
1890
|
+
/// Words are defined by whitespace separation. Multiple consecutive
|
|
1891
|
+
/// whitespace characters are treated as a single separator.
|
|
1892
|
+
///
|
|
1893
|
+
/// # Examples
|
|
1894
|
+
///
|
|
1895
|
+
/// ```
|
|
1896
|
+
/// use mylib::reverse_words;
|
|
1897
|
+
///
|
|
1898
|
+
/// assert_eq!(reverse_words("hello world")?, "world hello");
|
|
1899
|
+
/// assert_eq!(reverse_words("one")?, "one");
|
|
1900
|
+
/// assert_eq!(reverse_words("a b c")?, "c b a");
|
|
1901
|
+
/// ```
|
|
1902
|
+
///
|
|
1903
|
+
/// # Errors
|
|
1904
|
+
///
|
|
1905
|
+
/// Returns `Err` if the input string is empty or contains only whitespace.
|
|
1906
|
+
///
|
|
1907
|
+
/// ```
|
|
1908
|
+
/// # use mylib::reverse_words;
|
|
1909
|
+
/// assert!(reverse_words("").is_err());
|
|
1910
|
+
/// assert!(reverse_words(" ").is_err());
|
|
1911
|
+
/// ```
|
|
1912
|
+
pub fn reverse_words(input: &str) -> Result<String, &'static str> {
|
|
1913
|
+
let trimmed = input.trim();
|
|
1914
|
+
|
|
1915
|
+
if trimmed.is_empty() {
|
|
1916
|
+
return Err("Input cannot be empty or whitespace-only");
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
let reversed = trimmed
|
|
1920
|
+
.split_whitespace() // Iterator over words
|
|
1921
|
+
.rev() // Reverse the iterator
|
|
1922
|
+
.collect::<Vec<_>>() // Collect to Vec<&str>
|
|
1923
|
+
.join(" "); // Join with single space
|
|
1924
|
+
|
|
1925
|
+
Ok(reversed)
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
#[cfg(test)]
|
|
1929
|
+
mod tests {
|
|
1930
|
+
use super::*;
|
|
1931
|
+
|
|
1932
|
+
#[test]
|
|
1933
|
+
fn test_basic_reversal() {
|
|
1934
|
+
assert_eq!(
|
|
1935
|
+
reverse_words("hello world").unwrap(),
|
|
1936
|
+
"world hello"
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
#[test]
|
|
1941
|
+
fn test_single_word() {
|
|
1942
|
+
assert_eq!(
|
|
1943
|
+
reverse_words("hello").unwrap(),
|
|
1944
|
+
"hello"
|
|
1945
|
+
);
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
#[test]
|
|
1949
|
+
fn test_multiple_spaces() {
|
|
1950
|
+
assert_eq!(
|
|
1951
|
+
reverse_words("hello world rust").unwrap(),
|
|
1952
|
+
"rust world hello"
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
#[test]
|
|
1957
|
+
fn test_empty_string() {
|
|
1958
|
+
assert!(reverse_words("").is_err());
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
#[test]
|
|
1962
|
+
fn test_whitespace_only() {
|
|
1963
|
+
assert!(reverse_words(" ").is_err());
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
#[test]
|
|
1967
|
+
fn test_leading_trailing_whitespace() {
|
|
1968
|
+
assert_eq!(
|
|
1969
|
+
reverse_words(" hello world ").unwrap(),
|
|
1970
|
+
"world hello"
|
|
1971
|
+
);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
```
|
|
1975
|
+
|
|
1976
|
+
**Key Patterns:**
|
|
1977
|
+
- ✅ Rustdoc comments with examples
|
|
1978
|
+
- ✅ `split_whitespace()` for proper word splitting
|
|
1979
|
+
- ✅ `.rev()` for efficient reversal
|
|
1980
|
+
- ✅ `.collect()` with type annotation
|
|
1981
|
+
- ✅ Comprehensive test coverage
|
|
1982
|
+
- ✅ Edge case handling (empty, whitespace, multiple spaces)
|
|
1983
|
+
|
|
1984
|
+
**Anti-Patterns:**
|
|
1985
|
+
- ❌ Manual string splitting with `.split(' ')`
|
|
1986
|
+
- ❌ Using `String::new()` and loops instead of iterators
|
|
1987
|
+
- ❌ Not handling leading/trailing whitespace
|
|
1988
|
+
|
|
1989
|
+
---
|
|
1990
|
+
|
|
1991
|
+
### Pattern 3: Type-Safe Parsing
|
|
1992
|
+
|
|
1993
|
+
#### Safe Type Conversion with TryFrom
|
|
1994
|
+
|
|
1995
|
+
```rust
|
|
1996
|
+
use std::convert::TryFrom;
|
|
1997
|
+
use std::net::IpAddr;
|
|
1998
|
+
use std::str::FromStr;
|
|
1999
|
+
|
|
2000
|
+
/// A validated network port number (1024-65535).
|
|
2001
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
2002
|
+
pub struct Port(u16);
|
|
2003
|
+
|
|
2004
|
+
impl Port {
|
|
2005
|
+
pub const MIN: u16 = 1024;
|
|
2006
|
+
pub const MAX: u16 = 65535;
|
|
2007
|
+
|
|
2008
|
+
pub fn new(value: u16) -> Result<Self, PortError> {
|
|
2009
|
+
if value < Self::MIN {
|
|
2010
|
+
return Err(PortError::TooLow);
|
|
2011
|
+
}
|
|
2012
|
+
if value > Self::MAX {
|
|
2013
|
+
return Err(PortError::TooHigh);
|
|
2014
|
+
}
|
|
2015
|
+
Ok(Port(value))
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
pub fn get(&self) -> u16 {
|
|
2019
|
+
self.0
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
#[derive(Debug, Error)]
|
|
2024
|
+
pub enum PortError {
|
|
2025
|
+
#[error("Port number too low (minimum is 1024)")]
|
|
2026
|
+
TooLow,
|
|
2027
|
+
|
|
2028
|
+
#[error("Port number too high (maximum is 65535)")]
|
|
2029
|
+
TooHigh,
|
|
2030
|
+
|
|
2031
|
+
#[error("Invalid port format: {0}")]
|
|
2032
|
+
ParseError(String),
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
impl TryFrom<&str> for Port {
|
|
2036
|
+
type Error = PortError;
|
|
2037
|
+
|
|
2038
|
+
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
|
2039
|
+
let port = value
|
|
2040
|
+
.parse::<u16>()
|
|
2041
|
+
.map_err(|e| PortError::ParseError(e.to_string()))?;
|
|
2042
|
+
|
|
2043
|
+
Port::new(port)
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
impl FromStr for Port {
|
|
2048
|
+
type Err = PortError;
|
|
2049
|
+
|
|
2050
|
+
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
2051
|
+
Self::try_from(s)
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
// Usage examples
|
|
2056
|
+
#[cfg(test)]
|
|
2057
|
+
mod tests {
|
|
2058
|
+
use super::*;
|
|
2059
|
+
|
|
2060
|
+
#[test]
|
|
2061
|
+
fn test_valid_port() {
|
|
2062
|
+
let port = Port::try_from("8080").unwrap();
|
|
2063
|
+
assert_eq!(port.get(), 8080);
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
#[test]
|
|
2067
|
+
fn test_privileged_port() {
|
|
2068
|
+
assert!(matches!(
|
|
2069
|
+
Port::try_from("80"),
|
|
2070
|
+
Err(PortError::TooLow)
|
|
2071
|
+
));
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
#[test]
|
|
2075
|
+
fn test_invalid_number() {
|
|
2076
|
+
assert!(matches!(
|
|
2077
|
+
Port::try_from("not_a_number"),
|
|
2078
|
+
Err(PortError::ParseError(_))
|
|
2079
|
+
));
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
#[test]
|
|
2083
|
+
fn test_from_str() {
|
|
2084
|
+
let port: Port = "3000".parse().unwrap();
|
|
2085
|
+
assert_eq!(port.get(), 3000);
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
```
|
|
2089
|
+
|
|
2090
|
+
**Key Patterns:**
|
|
2091
|
+
- ✅ Newtype pattern for type safety (`Port(u16)`)
|
|
2092
|
+
- ✅ Validation in constructor
|
|
2093
|
+
- ✅ `TryFrom` for fallible conversions
|
|
2094
|
+
- ✅ `FromStr` for `.parse()` support
|
|
2095
|
+
- ✅ Descriptive error variants
|
|
2096
|
+
- ✅ Getter method for inner value
|
|
2097
|
+
|
|
2098
|
+
---
|
|
2099
|
+
|
|
2100
|
+
### Pattern 4: CRUD Operations
|
|
2101
|
+
|
|
2102
|
+
#### Repository Pattern with Generic Interface
|
|
2103
|
+
|
|
2104
|
+
```rust
|
|
2105
|
+
use std::collections::HashMap;
|
|
2106
|
+
use uuid::Uuid;
|
|
2107
|
+
|
|
2108
|
+
/// Generic CRUD operations for any data type.
|
|
2109
|
+
pub trait Repository<T> {
|
|
2110
|
+
type Error;
|
|
2111
|
+
|
|
2112
|
+
fn create(&mut self, item: T) -> Result<Uuid, Self::Error>;
|
|
2113
|
+
fn read(&self, id: &Uuid) -> Result<&T, Self::Error>;
|
|
2114
|
+
fn update(&mut self, id: &Uuid, item: T) -> Result<(), Self::Error>;
|
|
2115
|
+
fn delete(&mut self, id: &Uuid) -> Result<T, Self::Error>;
|
|
2116
|
+
fn list(&self) -> Vec<&T>;
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
#[derive(Debug, Error)]
|
|
2120
|
+
pub enum RepositoryError {
|
|
2121
|
+
#[error("Item not found with ID: {0}")]
|
|
2122
|
+
NotFound(Uuid),
|
|
2123
|
+
|
|
2124
|
+
#[error("Item already exists with ID: {0}")]
|
|
2125
|
+
AlreadyExists(Uuid),
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
/// In-memory implementation of Repository.
|
|
2129
|
+
pub struct InMemoryRepository<T> {
|
|
2130
|
+
store: HashMap<Uuid, T>,
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
impl<T> InMemoryRepository<T> {
|
|
2134
|
+
pub fn new() -> Self {
|
|
2135
|
+
Self {
|
|
2136
|
+
store: HashMap::new(),
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
pub fn with_capacity(capacity: usize) -> Self {
|
|
2141
|
+
Self {
|
|
2142
|
+
store: HashMap::with_capacity(capacity),
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
impl<T> Repository<T> for InMemoryRepository<T> {
|
|
2148
|
+
type Error = RepositoryError;
|
|
2149
|
+
|
|
2150
|
+
fn create(&mut self, item: T) -> Result<Uuid, Self::Error> {
|
|
2151
|
+
let id = Uuid::new_v4();
|
|
2152
|
+
self.store.insert(id, item);
|
|
2153
|
+
Ok(id)
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
fn read(&self, id: &Uuid) -> Result<&T, Self::Error> {
|
|
2157
|
+
self.store
|
|
2158
|
+
.get(id)
|
|
2159
|
+
.ok_or(RepositoryError::NotFound(*id))
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
fn update(&mut self, id: &Uuid, item: T) -> Result<(), Self::Error> {
|
|
2163
|
+
if !self.store.contains_key(id) {
|
|
2164
|
+
return Err(RepositoryError::NotFound(*id));
|
|
2165
|
+
}
|
|
2166
|
+
self.store.insert(*id, item);
|
|
2167
|
+
Ok(())
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
fn delete(&mut self, id: &Uuid) -> Result<T, Self::Error> {
|
|
2171
|
+
self.store
|
|
2172
|
+
.remove(id)
|
|
2173
|
+
.ok_or(RepositoryError::NotFound(*id))
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
fn list(&self) -> Vec<&T> {
|
|
2177
|
+
self.store.values().collect()
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
// Example usage
|
|
2182
|
+
#[derive(Debug, Clone, PartialEq)]
|
|
2183
|
+
struct User {
|
|
2184
|
+
name: String,
|
|
2185
|
+
email: String,
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
#[cfg(test)]
|
|
2189
|
+
mod tests {
|
|
2190
|
+
use super::*;
|
|
2191
|
+
|
|
2192
|
+
#[test]
|
|
2193
|
+
fn test_create_and_read() {
|
|
2194
|
+
let mut repo = InMemoryRepository::new();
|
|
2195
|
+
let user = User {
|
|
2196
|
+
name: "Alice".to_string(),
|
|
2197
|
+
email: "alice@example.com".to_string(),
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
let id = repo.create(user.clone()).unwrap();
|
|
2201
|
+
let retrieved = repo.read(&id).unwrap();
|
|
2202
|
+
|
|
2203
|
+
assert_eq!(retrieved, &user);
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
#[test]
|
|
2207
|
+
fn test_update() {
|
|
2208
|
+
let mut repo = InMemoryRepository::new();
|
|
2209
|
+
let user = User {
|
|
2210
|
+
name: "Bob".to_string(),
|
|
2211
|
+
email: "bob@example.com".to_string(),
|
|
2212
|
+
};
|
|
2213
|
+
|
|
2214
|
+
let id = repo.create(user).unwrap();
|
|
2215
|
+
|
|
2216
|
+
let updated_user = User {
|
|
2217
|
+
name: "Robert".to_string(),
|
|
2218
|
+
email: "robert@example.com".to_string(),
|
|
2219
|
+
};
|
|
2220
|
+
|
|
2221
|
+
repo.update(&id, updated_user.clone()).unwrap();
|
|
2222
|
+
let retrieved = repo.read(&id).unwrap();
|
|
2223
|
+
|
|
2224
|
+
assert_eq!(retrieved, &updated_user);
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
#[test]
|
|
2228
|
+
fn test_delete() {
|
|
2229
|
+
let mut repo = InMemoryRepository::new();
|
|
2230
|
+
let user = User {
|
|
2231
|
+
name: "Charlie".to_string(),
|
|
2232
|
+
email: "charlie@example.com".to_string(),
|
|
2233
|
+
};
|
|
2234
|
+
|
|
2235
|
+
let id = repo.create(user.clone()).unwrap();
|
|
2236
|
+
let deleted = repo.delete(&id).unwrap();
|
|
2237
|
+
|
|
2238
|
+
assert_eq!(deleted, user);
|
|
2239
|
+
assert!(matches!(
|
|
2240
|
+
repo.read(&id),
|
|
2241
|
+
Err(RepositoryError::NotFound(_))
|
|
2242
|
+
));
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
#[test]
|
|
2246
|
+
fn test_list() {
|
|
2247
|
+
let mut repo = InMemoryRepository::new();
|
|
2248
|
+
|
|
2249
|
+
repo.create(User {
|
|
2250
|
+
name: "User1".to_string(),
|
|
2251
|
+
email: "user1@example.com".to_string(),
|
|
2252
|
+
}).unwrap();
|
|
2253
|
+
|
|
2254
|
+
repo.create(User {
|
|
2255
|
+
name: "User2".to_string(),
|
|
2256
|
+
email: "user2@example.com".to_string(),
|
|
2257
|
+
}).unwrap();
|
|
2258
|
+
|
|
2259
|
+
let all_users = repo.list();
|
|
2260
|
+
assert_eq!(all_users.len(), 2);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
```
|
|
2264
|
+
|
|
2265
|
+
**Key Patterns:**
|
|
2266
|
+
- ✅ Generic trait for reusability
|
|
2267
|
+
- ✅ Associated type for errors
|
|
2268
|
+
- ✅ UUID for unique identifiers
|
|
2269
|
+
- ✅ Proper error handling (not found, already exists)
|
|
2270
|
+
- ✅ Comprehensive CRUD operations
|
|
2271
|
+
- ✅ Test coverage for all operations
|
|
2272
|
+
|
|
2273
|
+
---
|
|
2274
|
+
|
|
2275
|
+
## Implementation Workflow
|
|
2276
|
+
|
|
2277
|
+
### Step-by-Step Process
|
|
2278
|
+
|
|
2279
|
+
1. **Understand Requirements**
|
|
2280
|
+
```bash
|
|
2281
|
+
# Read specification files
|
|
2282
|
+
# Identify input/output types
|
|
2283
|
+
# Note error conditions and edge cases
|
|
2284
|
+
```
|
|
2285
|
+
|
|
2286
|
+
2. **Define Types and Errors**
|
|
2287
|
+
```rust
|
|
2288
|
+
// Define domain types (structs, enums)
|
|
2289
|
+
// Create error enum with thiserror
|
|
2290
|
+
// Add type conversions (TryFrom, FromStr)
|
|
2291
|
+
```
|
|
2292
|
+
|
|
2293
|
+
3. **Implement Core Logic**
|
|
2294
|
+
```rust
|
|
2295
|
+
// Write main function with proper signature
|
|
2296
|
+
// Use iterator methods where applicable
|
|
2297
|
+
// Add error handling with ? operator
|
|
2298
|
+
// Ensure proper borrowing (minimize clones)
|
|
2299
|
+
```
|
|
2300
|
+
|
|
2301
|
+
4. **Write Tests**
|
|
2302
|
+
```rust
|
|
2303
|
+
#[cfg(test)]
|
|
2304
|
+
mod tests {
|
|
2305
|
+
use super::*;
|
|
2306
|
+
|
|
2307
|
+
// Test happy path
|
|
2308
|
+
// Test error conditions
|
|
2309
|
+
// Test edge cases
|
|
2310
|
+
// Test boundary conditions
|
|
2311
|
+
}
|
|
2312
|
+
```
|
|
2313
|
+
|
|
2314
|
+
5. **Add Documentation**
|
|
2315
|
+
```rust
|
|
2316
|
+
/// Brief description
|
|
2317
|
+
///
|
|
2318
|
+
/// Detailed explanation if needed
|
|
2319
|
+
///
|
|
2320
|
+
/// # Examples
|
|
2321
|
+
///
|
|
2322
|
+
/// ```
|
|
2323
|
+
/// // Example usage
|
|
2324
|
+
/// ```
|
|
2325
|
+
///
|
|
2326
|
+
/// # Errors
|
|
2327
|
+
///
|
|
2328
|
+
/// Returns `Err` if...
|
|
2329
|
+
///
|
|
2330
|
+
/// # Panics
|
|
2331
|
+
///
|
|
2332
|
+
/// Panics if... (if applicable)
|
|
2333
|
+
```
|
|
2334
|
+
|
|
2335
|
+
6. **Run Validation Hook**
|
|
2336
|
+
```bash
|
|
2337
|
+
npx claude-flow@alpha hooks post-edit src/module.rs \
|
|
2338
|
+
--memory-key "rust-coder/module" \
|
|
2339
|
+
--structured
|
|
2340
|
+
```
|
|
2341
|
+
|
|
2342
|
+
---
|
|
2343
|
+
|
|
2344
|
+
## Success Criteria
|
|
2345
|
+
|
|
2346
|
+
- [ ] Code compiles without warnings (`cargo build`)
|
|
2347
|
+
- [ ] All functions have rustdoc comments
|
|
2348
|
+
- [ ] Error handling uses `Result<T, E>` (no `.unwrap()` in production)
|
|
2349
|
+
- [ ] Tests cover >85% of code (`cargo tarpaulin`)
|
|
2350
|
+
- [ ] Idiomatic iterator usage where appropriate
|
|
2351
|
+
- [ ] Proper borrowing (minimal unnecessary clones)
|
|
2352
|
+
- [ ] Clippy has no warnings (`cargo clippy`)
|
|
2353
|
+
- [ ] Formatting is correct (`cargo fmt --check`)
|
|
2354
|
+
|
|
2355
|
+
---
|
|
2356
|
+
|
|
2357
|
+
## Common Pitfalls to Avoid
|
|
2358
|
+
|
|
2359
|
+
### ❌ DON'T: Use .unwrap() in Production
|
|
2360
|
+
|
|
2361
|
+
```rust
|
|
2362
|
+
// BAD - Panics on None
|
|
2363
|
+
let value = some_option.unwrap();
|
|
2364
|
+
|
|
2365
|
+
// BAD - Panics on Err
|
|
2366
|
+
let result = some_result.unwrap();
|
|
2367
|
+
```
|
|
2368
|
+
|
|
2369
|
+
### ✅ DO: Handle Errors Explicitly
|
|
2370
|
+
|
|
2371
|
+
```rust
|
|
2372
|
+
// GOOD - Propagates error
|
|
2373
|
+
let value = some_option.ok_or(MyError::MissingValue)?;
|
|
2374
|
+
|
|
2375
|
+
// GOOD - Handles error
|
|
2376
|
+
let result = some_result.map_err(|e| MyError::from(e))?;
|
|
2377
|
+
```
|
|
2378
|
+
|
|
2379
|
+
---
|
|
2380
|
+
|
|
2381
|
+
### ❌ DON'T: Clone Unnecessarily
|
|
2382
|
+
|
|
2383
|
+
```rust
|
|
2384
|
+
// BAD - Takes ownership but clones
|
|
2385
|
+
fn process(data: Vec<String>) {
|
|
2386
|
+
for item in data.clone() { // Unnecessary allocation
|
|
2387
|
+
println!("{}", item);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
```
|
|
2391
|
+
|
|
2392
|
+
### ✅ DO: Borrow When Possible
|
|
2393
|
+
|
|
2394
|
+
```rust
|
|
2395
|
+
// GOOD - Borrows instead of owning
|
|
2396
|
+
fn process(data: &[String]) {
|
|
2397
|
+
for item in data { // No clone needed
|
|
2398
|
+
println!("{}", item);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
```
|
|
2402
|
+
|
|
2403
|
+
---
|
|
2404
|
+
|
|
2405
|
+
### ❌ DON'T: Use Manual Loops for Iteration
|
|
2406
|
+
|
|
2407
|
+
```rust
|
|
2408
|
+
// BAD - Manual index loop
|
|
2409
|
+
for i in 0..vec.len() {
|
|
2410
|
+
println!("{}", vec[i]);
|
|
2411
|
+
}
|
|
2412
|
+
```
|
|
2413
|
+
|
|
2414
|
+
### ✅ DO: Use Iterator Methods
|
|
2415
|
+
|
|
2416
|
+
```rust
|
|
2417
|
+
// GOOD - Iterator-based
|
|
2418
|
+
vec.iter().for_each(|item| println!("{}", item));
|
|
2419
|
+
|
|
2420
|
+
// Or even better
|
|
2421
|
+
for item in &vec {
|
|
2422
|
+
println!("{}", item);
|
|
2423
|
+
}
|
|
2424
|
+
```
|
|
2425
|
+
|
|
2426
|
+
---
|
|
2427
|
+
|
|
2428
|
+
### ❌ DON'T: Use String-Based Errors
|
|
2429
|
+
|
|
2430
|
+
```rust
|
|
2431
|
+
// BAD - Not type-safe
|
|
2432
|
+
fn parse() -> Result<Value, String> {
|
|
2433
|
+
Err("Parse error".to_string())
|
|
2434
|
+
}
|
|
2435
|
+
```
|
|
2436
|
+
|
|
2437
|
+
### ✅ DO: Use Custom Error Types
|
|
2438
|
+
|
|
2439
|
+
```rust
|
|
2440
|
+
// GOOD - Type-safe with details
|
|
2441
|
+
#[derive(Error, Debug)]
|
|
2442
|
+
enum ParseError {
|
|
2443
|
+
#[error("Parse error: {0}")]
|
|
2444
|
+
Format(String),
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
fn parse() -> Result<Value, ParseError> {
|
|
2448
|
+
Err(ParseError::Format("Invalid format".to_string()))
|
|
2449
|
+
}
|
|
2450
|
+
```
|
|
2451
|
+
```
|
|
2452
|
+
|
|
2453
|
+
---
|
|
2454
|
+
|
|
2455
|
+
## Validation Checklist
|
|
2456
|
+
|
|
2457
|
+
Before considering an agent complete:
|
|
2458
|
+
|
|
2459
|
+
### Structure ✓
|
|
2460
|
+
- [ ] Valid YAML frontmatter
|
|
2461
|
+
- [ ] All required fields present
|
|
2462
|
+
- [ ] Clear role definition
|
|
2463
|
+
- [ ] Appropriate section organization
|
|
2464
|
+
|
|
2465
|
+
### Format Selection ✓
|
|
2466
|
+
- [ ] Format matches task complexity
|
|
2467
|
+
- [ ] Length is appropriate
|
|
2468
|
+
- [ ] Examples/structure present as needed
|
|
2469
|
+
|
|
2470
|
+
### Content Quality ✓
|
|
2471
|
+
- [ ] Clear responsibilities
|
|
2472
|
+
- [ ] Methodology explained
|
|
2473
|
+
- [ ] Integration points defined
|
|
2474
|
+
- [ ] Success metrics specified
|
|
2475
|
+
- [ ] Post-edit hook included
|
|
2476
|
+
|
|
2477
|
+
### Language-Specific ✓
|
|
2478
|
+
- [ ] Format validated for language
|
|
2479
|
+
- [ ] Idiomatic patterns included
|
|
2480
|
+
- [ ] Common pitfalls addressed
|
|
2481
|
+
|
|
2482
|
+
### Testing ✓
|
|
2483
|
+
- [ ] Tested on representative tasks
|
|
2484
|
+
- [ ] Metrics meet targets
|
|
2485
|
+
- [ ] Integration verified
|
|
2486
|
+
|
|
2487
|
+
---
|
|
2488
|
+
|
|
2489
|
+
## Continuous Improvement
|
|
2490
|
+
|
|
2491
|
+
### Metrics to Track
|
|
2492
|
+
|
|
2493
|
+
```yaml
|
|
2494
|
+
Agent Performance Metrics:
|
|
2495
|
+
first_time_success_rate:
|
|
2496
|
+
target: ">80%"
|
|
2497
|
+
measure: "Compiles/runs on first attempt"
|
|
2498
|
+
|
|
2499
|
+
iteration_count:
|
|
2500
|
+
target: "<3"
|
|
2501
|
+
measure: "Revisions needed to complete"
|
|
2502
|
+
|
|
2503
|
+
quality_score:
|
|
2504
|
+
target: ">85%"
|
|
2505
|
+
measure: "Benchmark quality assessment"
|
|
2506
|
+
|
|
2507
|
+
user_satisfaction:
|
|
2508
|
+
target: ">4.5/5"
|
|
2509
|
+
measure: "Feedback from users"
|
|
2510
|
+
```
|
|
2511
|
+
|
|
2512
|
+
### Feedback Loop
|
|
2513
|
+
|
|
2514
|
+
1. **Collect Data**: Track metrics for each agent usage
|
|
2515
|
+
2. **Analyze**: Identify patterns in failures or low quality
|
|
2516
|
+
3. **Hypothesize**: Determine likely causes
|
|
2517
|
+
4. **Experiment**: Adjust agent format or content
|
|
2518
|
+
5. **Validate**: Test changes with benchmark system
|
|
2519
|
+
6. **Deploy**: Update agent if improvements confirmed
|
|
2520
|
+
7. **Monitor**: Continue tracking metrics
|
|
2521
|
+
|
|
2522
|
+
---
|
|
2523
|
+
|
|
2524
|
+
## Appendix: Benchmark System
|
|
2525
|
+
|
|
2526
|
+
### Running Agent Benchmarks
|
|
2527
|
+
|
|
2528
|
+
```bash
|
|
2529
|
+
cd benchmark/agent-benchmarking
|
|
2530
|
+
|
|
2531
|
+
# Run Rust benchmarks (VALIDATED)
|
|
2532
|
+
node index.js run 5 --rust --verbose
|
|
2533
|
+
|
|
2534
|
+
# Run JavaScript benchmarks (HYPOTHESIS)
|
|
2535
|
+
node index.js run 5 --verbose
|
|
2536
|
+
|
|
2537
|
+
# Run specific scenario
|
|
2538
|
+
node index.js run 3 --rust --scenario=rust-01-basic
|
|
2539
|
+
|
|
2540
|
+
# List available scenarios
|
|
2541
|
+
node index.js list --scenarios --rust
|
|
2542
|
+
|
|
2543
|
+
# Analyze results
|
|
2544
|
+
node index.js analyze
|
|
2545
|
+
```
|
|
2546
|
+
|
|
2547
|
+
### Interpreting Results
|
|
2548
|
+
|
|
2549
|
+
```yaml
|
|
2550
|
+
Quality Score Breakdown:
|
|
2551
|
+
Correctness (30%):
|
|
2552
|
+
- Basic functionality works
|
|
2553
|
+
- Edge cases handled
|
|
2554
|
+
- Error conditions managed
|
|
2555
|
+
|
|
2556
|
+
Idiomaticity (25%):
|
|
2557
|
+
- Language best practices
|
|
2558
|
+
- Proper pattern usage
|
|
2559
|
+
- Efficient algorithms
|
|
2560
|
+
|
|
2561
|
+
Code Quality (20%):
|
|
2562
|
+
- Readability
|
|
2563
|
+
- Documentation
|
|
2564
|
+
- Naming conventions
|
|
2565
|
+
|
|
2566
|
+
Testing (15%):
|
|
2567
|
+
- Test coverage
|
|
2568
|
+
- Assertion quality
|
|
2569
|
+
- Edge case tests
|
|
2570
|
+
|
|
2571
|
+
Performance (10%):
|
|
2572
|
+
- Execution efficiency
|
|
2573
|
+
- Memory usage
|
|
2574
|
+
- Optimization
|
|
2575
|
+
```
|
|
2576
|
+
|
|
2577
|
+
### Statistical Significance
|
|
2578
|
+
|
|
2579
|
+
```yaml
|
|
2580
|
+
ANOVA Analysis:
|
|
2581
|
+
f_statistic: "Variance between groups"
|
|
2582
|
+
p_value: "Probability results are random"
|
|
2583
|
+
significant_if: "p < 0.05"
|
|
2584
|
+
|
|
2585
|
+
Effect Size (Cohen's d):
|
|
2586
|
+
negligible: "d < 0.2"
|
|
2587
|
+
small: "0.2 ≤ d < 0.5"
|
|
2588
|
+
medium: "0.5 ≤ d < 0.8"
|
|
2589
|
+
large: "d ≥ 0.8"
|
|
2590
|
+
```
|
|
2591
|
+
|
|
2592
|
+
---
|
|
2593
|
+
|
|
2594
|
+
## Conclusion
|
|
2595
|
+
|
|
2596
|
+
This guide establishes evidence-based best practices for agent design in the Claude Flow ecosystem. The key insights:
|
|
2597
|
+
|
|
2598
|
+
1. **Format matters**: Choose based on task complexity (inverse relationship)
|
|
2599
|
+
2. **Validation is critical**: Rust findings validated, others hypothetical
|
|
2600
|
+
3. **Integration is essential**: Hooks and memory coordinate agents
|
|
2601
|
+
4. **Continuous improvement**: Use metrics to refine agents
|
|
2602
|
+
|
|
2603
|
+
By following these guidelines, you'll create agents that are effective, maintainable, and measurable.
|
|
2604
|
+
|
|
2605
|
+
**Next Steps:**
|
|
2606
|
+
1. Choose appropriate format for your agent
|
|
2607
|
+
2. Use templates as starting points
|
|
2608
|
+
3. Test with benchmark system
|
|
2609
|
+
4. Deploy with validation hooks
|
|
2610
|
+
5. Monitor and iterate
|
|
2611
|
+
|
|
2612
|
+
---
|
|
2613
|
+
|
|
2614
|
+
**Document Version:** 2.0.0
|
|
2615
|
+
**Last Updated:** 2025-09-30
|
|
2616
|
+
**Maintained By:** Claude Flow Core Team
|
|
2617
|
+
**Feedback:** Document improvements and findings for future versions
|