claude-flow-novice 1.5.21 → 1.5.22
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 +186 -2386
- package/.claude/agents/agent-principles/agent-type-guidelines.md +328 -0
- package/.claude/agents/agent-principles/format-selection.md +204 -0
- package/.claude/agents/agent-principles/prompt-engineering.md +371 -0
- package/.claude/agents/agent-principles/quality-metrics.md +294 -0
- package/.claude/agents/frontend/README.md +574 -53
- package/.claude/agents/frontend/interaction-tester.md +850 -108
- package/.claude/agents/frontend/react-frontend-engineer.md +130 -0
- package/.claude/agents/frontend/state-architect.md +240 -152
- package/.claude/agents/frontend/ui-designer.md +292 -68
- package/.claude/agents/researcher.md +1 -1
- package/.claude/agents/swarm/test-coordinator.md +383 -0
- package/.claude/agents/task-coordinator.md +126 -0
- package/.claude/settings.json +7 -7
- package/.claude-flow-novice/dist/src/hooks/enhanced-hooks-cli.js +168 -167
- package/.claude-flow-novice/dist/src/providers/tiered-router.js +118 -0
- package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -0
- package/.claude-flow-novice/dist/src/providers/types.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/zai-provider.js +268 -0
- package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -0
- package/package.json +1 -1
- package/src/cli/simple-commands/init/templates/CLAUDE.md +25 -0
- package/src/hooks/enhanced-hooks-cli.js +23 -3
- package/src/hooks/enhanced-post-edit-pipeline.js +154 -75
- /package/.claude/agents/{CLAUDE_AGENT_DESIGN_PRINCIPLES.md → agent-principles/CLAUDE_AGENT_DESIGN_PRINCIPLES.md} +0 -0
package/.claude/agents/CLAUDE.md
CHANGED
|
@@ -11,1550 +11,218 @@ This document is the single source of truth for creating, editing, and validatin
|
|
|
11
11
|
## Table of Contents
|
|
12
12
|
|
|
13
13
|
1. [Quick Start](#quick-start)
|
|
14
|
-
2. [
|
|
14
|
+
2. [Core Universal Principles](#core-universal-principles)
|
|
15
15
|
3. [Agent Profile Structure](#agent-profile-structure)
|
|
16
|
-
4. [
|
|
17
|
-
5. [
|
|
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)
|
|
16
|
+
4. [Examples & Templates](#examples--templates)
|
|
17
|
+
5. [Specialized Guidance](#specialized-guidance)
|
|
24
18
|
|
|
25
19
|
---
|
|
26
20
|
|
|
27
21
|
## Quick Start
|
|
28
22
|
|
|
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
23
|
### The Three Golden Rules
|
|
46
24
|
|
|
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
|
-
```
|
|
25
|
+
1. **Complexity-Verbosity Inverse Law**: As task complexity increases, prompt verbosity should DECREASE
|
|
26
|
+
2. **Priming Paradox**: Verbose prompts excel at basic tasks, minimal prompts excel at complex reasoning
|
|
27
|
+
3. **Rust Validation**: These findings are validated for Rust; hypotheses for other languages
|
|
1200
28
|
|
|
1201
|
-
###
|
|
29
|
+
### Format Selection in 30 Seconds
|
|
1202
30
|
|
|
1203
31
|
```yaml
|
|
1204
|
-
|
|
1205
|
-
|
|
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
|
-
```
|
|
32
|
+
Is the task BASIC (parsing, simple logic, CRUD)?
|
|
33
|
+
→ Use CODE-HEAVY format (+43% quality improvement)
|
|
1221
34
|
|
|
1222
|
-
|
|
35
|
+
Is the task COMPLEX with clear requirements (architecture, review)?
|
|
36
|
+
→ Use MINIMAL format (avoid over-constraining)
|
|
1223
37
|
|
|
1224
|
-
|
|
1225
|
-
|
|
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
|
|
38
|
+
Is the task MEDIUM complexity with structured steps?
|
|
39
|
+
→ Use METADATA format (structured guidance)
|
|
1238
40
|
```
|
|
1239
41
|
|
|
1240
|
-
|
|
42
|
+
**For detailed format guidance:** See [Format Selection Principles](./agent-principles/format-selection.md)
|
|
1241
43
|
|
|
1242
|
-
|
|
1243
|
-
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
44
|
+
---
|
|
1244
45
|
|
|
1245
|
-
|
|
46
|
+
## Core Universal Principles
|
|
1246
47
|
|
|
1247
|
-
|
|
1248
|
-
npx claude-flow@alpha hooks post-edit [FILE_PATH] --memory-key "agent/step" --structured
|
|
1249
|
-
```
|
|
48
|
+
### 1. Agent Profile Structure **REQUIRED FORMAT**
|
|
1250
49
|
|
|
1251
|
-
|
|
1252
|
-
- TDD compliance checking
|
|
1253
|
-
- Security analysis (XSS, eval, credentials)
|
|
1254
|
-
- Formatting validation
|
|
1255
|
-
- Coverage analysis
|
|
1256
|
-
- Actionable recommendations
|
|
1257
|
-
```
|
|
50
|
+
Every agent MUST include:
|
|
1258
51
|
|
|
1259
|
-
|
|
1260
|
-
- Ensures quality gates
|
|
1261
|
-
- Provides immediate feedback
|
|
1262
|
-
- Coordinates with other agents via memory
|
|
1263
|
-
- Maintains system-wide standards
|
|
52
|
+
#### Frontmatter (YAML)
|
|
1264
53
|
|
|
54
|
+
```yaml
|
|
1265
55
|
---
|
|
56
|
+
name: agent-name # REQUIRED: Lowercase with hyphens
|
|
57
|
+
description: | # REQUIRED: Clear, keyword-rich description
|
|
58
|
+
MUST BE USED when [primary use case].
|
|
59
|
+
Use PROACTIVELY for [specific scenarios].
|
|
60
|
+
ALWAYS delegate when user asks [trigger phrases].
|
|
61
|
+
Keywords - [comma-separated keywords for search]
|
|
62
|
+
tools: [Read, Write, Edit, Bash, TodoWrite, mcp__claude-flow__swarm_init, mcp__claude-flow__agent_spawn] # REQUIRED: Comma-separated list, can include MCP commands
|
|
63
|
+
model: sonnet # REQUIRED: sonnet | opus | haiku
|
|
64
|
+
color: seagreen # REQUIRED: Visual identifier
|
|
65
|
+
type: specialist # OPTIONAL: specialist | coordinator | swarm
|
|
66
|
+
capabilities: # OPTIONAL: Array of capability tags
|
|
67
|
+
- rust
|
|
68
|
+
- error-handling
|
|
69
|
+
lifecycle: # OPTIONAL: Hooks for agent lifecycle
|
|
70
|
+
pre_task: "npx claude-flow@alpha hooks pre-task"
|
|
71
|
+
post_task: "npx claude-flow@alpha hooks post-task"
|
|
72
|
+
hooks: # OPTIONAL: Integration points
|
|
73
|
+
memory_key: "agent-name/context"
|
|
74
|
+
validation: "post-edit"
|
|
75
|
+
triggers: # OPTIONAL: Automatic activation patterns
|
|
76
|
+
- "build rust"
|
|
77
|
+
- "implement concurrent"
|
|
78
|
+
constraints: # OPTIONAL: Limitations and boundaries
|
|
79
|
+
- "Do not modify production database"
|
|
80
|
+
---
|
|
81
|
+
```
|
|
1266
82
|
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
#### ❌ Over-Specification (Tunnel Vision)
|
|
83
|
+
#### Body Structure
|
|
1270
84
|
|
|
1271
85
|
```markdown
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
## Strict Algorithm
|
|
86
|
+
# Agent Name
|
|
1275
87
|
|
|
1276
|
-
|
|
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]
|
|
88
|
+
[Opening paragraph: WHO you are, WHAT you do]
|
|
1280
89
|
|
|
1281
|
-
|
|
1282
|
-
- Prevents optimal solutions
|
|
1283
|
-
- Ignores context-specific needs
|
|
1284
|
-
- Reduces AI reasoning ability
|
|
1285
|
-
- May enforce suboptimal patterns
|
|
1286
|
-
```
|
|
90
|
+
## 🚨 MANDATORY POST-EDIT VALIDATION
|
|
1287
91
|
|
|
1288
|
-
|
|
92
|
+
**CRITICAL**: After **EVERY** file edit operation, you **MUST** run:
|
|
1289
93
|
|
|
1290
|
-
```
|
|
1291
|
-
|
|
94
|
+
```bash
|
|
95
|
+
npx claude-flow@alpha hooks post-edit [FILE_PATH] --memory-key "agent/step" --structured
|
|
96
|
+
```
|
|
1292
97
|
|
|
1293
|
-
|
|
98
|
+
[Why this matters and what it provides]
|
|
1294
99
|
|
|
1295
|
-
|
|
100
|
+
## Core Responsibilities
|
|
1296
101
|
|
|
1297
|
-
|
|
1298
|
-
- No guidance on patterns
|
|
1299
|
-
- Unclear success criteria
|
|
1300
|
-
- High iteration count
|
|
1301
|
-
- Inconsistent quality
|
|
1302
|
-
```
|
|
102
|
+
[Primary duties in clear, actionable bullet points]
|
|
1303
103
|
|
|
1304
|
-
|
|
104
|
+
## Approach & Methodology
|
|
1305
105
|
|
|
1306
|
-
|
|
1307
|
-
BAD (for complex tasks):
|
|
106
|
+
[HOW the agent accomplishes tasks - frameworks, patterns, decision-making]
|
|
1308
107
|
|
|
1309
|
-
|
|
108
|
+
## Integration & Collaboration
|
|
1310
109
|
|
|
1311
|
-
|
|
1312
|
-
- Cognitive overload
|
|
1313
|
-
- Priming bias
|
|
1314
|
-
- Reduces creative problem-solving
|
|
1315
|
-
- Makes prompt harder to maintain
|
|
1316
|
-
```
|
|
110
|
+
[How this agent works with other agents and the broader system]
|
|
1317
111
|
|
|
1318
|
-
|
|
112
|
+
## Success Metrics
|
|
1319
113
|
|
|
1320
|
-
|
|
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
|
|
114
|
+
[How to measure agent effectiveness]
|
|
1333
115
|
```
|
|
1334
116
|
|
|
1335
117
|
---
|
|
1336
118
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
### Measuring Agent Effectiveness
|
|
119
|
+
### 2. The Complexity-Verbosity Inverse Law
|
|
1340
120
|
|
|
1341
|
-
|
|
121
|
+
**Empirical Finding:** Task complexity and prompt verbosity have an inverse relationship.
|
|
1342
122
|
|
|
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
123
|
```
|
|
124
|
+
Basic Tasks (parsing, CRUD):
|
|
125
|
+
- Code-Heavy: 85.3% quality (+43% vs Minimal)
|
|
126
|
+
- Best approach: Detailed examples with step-by-step guidance
|
|
1361
127
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
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
|
|
128
|
+
Complex Tasks (architecture, lock-free algorithms):
|
|
129
|
+
- Minimal: 87.2% quality (+31% vs Code-Heavy)
|
|
130
|
+
- Best approach: High-level principles with reasoning freedom
|
|
1377
131
|
```
|
|
1378
132
|
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
133
|
+
**Why This Matters:**
|
|
134
|
+
- Basic tasks benefit from concrete patterns (priming effect)
|
|
135
|
+
- Complex tasks need creative freedom (over-specification creates tunnel vision)
|
|
136
|
+
- Medium tasks need structured scaffolding without over-constraining
|
|
1382
137
|
|
|
1383
|
-
|
|
138
|
+
**For detailed analysis:** See [Format Selection Principles](./agent-principles/format-selection.md)
|
|
1384
139
|
|
|
1385
|
-
|
|
1386
|
-
## Agent Profile Validation
|
|
140
|
+
---
|
|
1387
141
|
|
|
1388
|
-
###
|
|
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
|
|
142
|
+
### 3. Mandatory Post-Edit Validation
|
|
1393
143
|
|
|
1394
|
-
|
|
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)
|
|
144
|
+
**UNIVERSAL REQUIREMENT:** Every agent MUST run post-edit hooks after file modifications.
|
|
1399
145
|
|
|
1400
|
-
|
|
1401
|
-
- [
|
|
1402
|
-
-
|
|
1403
|
-
|
|
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
|
|
146
|
+
```bash
|
|
147
|
+
npx claude-flow@alpha hooks post-edit [FILE_PATH] \
|
|
148
|
+
--memory-key "agent-name/context" \
|
|
149
|
+
--structured
|
|
1418
150
|
```
|
|
1419
151
|
|
|
1420
|
-
|
|
152
|
+
**Benefits:**
|
|
153
|
+
- TDD compliance verification
|
|
154
|
+
- Security analysis (XSS, eval(), hardcoded credentials)
|
|
155
|
+
- Formatting validation
|
|
156
|
+
- Test coverage analysis
|
|
157
|
+
- Cross-agent memory coordination
|
|
158
|
+
- Actionable recommendations
|
|
1421
159
|
|
|
1422
|
-
|
|
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
|
-
```
|
|
160
|
+
**For integration details:** See [Prompt Engineering Best Practices](./agent-principles/prompt-engineering.md)
|
|
1443
161
|
|
|
1444
162
|
---
|
|
1445
163
|
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
### Hook System Integration
|
|
1449
|
-
|
|
1450
|
-
Every agent should integrate with the Claude Flow hook system for coordination:
|
|
164
|
+
### 4. Integration with Claude Flow
|
|
1451
165
|
|
|
1452
|
-
####
|
|
166
|
+
#### Hook System
|
|
1453
167
|
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
168
|
+
Every agent integrates with:
|
|
169
|
+
- **Pre-task hooks**: Initialize context, set up memory namespace
|
|
170
|
+
- **Post-edit hooks**: Validate quality, coordinate with other agents
|
|
171
|
+
- **Post-task hooks**: Finalize task, export metrics
|
|
172
|
+
- **Session management**: Persist state across sessions
|
|
1457
173
|
|
|
1458
|
-
|
|
1459
|
-
- Initialize task context
|
|
1460
|
-
- Set up memory namespace
|
|
1461
|
-
- Log task start
|
|
1462
|
-
- Coordinate with other agents
|
|
174
|
+
#### Memory Coordination
|
|
1463
175
|
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
176
|
+
```javascript
|
|
177
|
+
// Memory key pattern: {agent-type}/{domain}/{aspect}
|
|
178
|
+
"architect/auth/design"
|
|
179
|
+
"coder/auth/implementation"
|
|
180
|
+
"reviewer/auth/feedback"
|
|
181
|
+
"tester/auth/coverage"
|
|
1470
182
|
```
|
|
1471
183
|
|
|
1472
|
-
|
|
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
|
|
184
|
+
#### Swarm Coordination
|
|
1488
185
|
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
186
|
+
When spawning multiple agents:
|
|
187
|
+
1. Run pre-task hook
|
|
188
|
+
2. Execute work
|
|
189
|
+
3. Run post-edit hook for each file
|
|
190
|
+
4. Store results in memory
|
|
191
|
+
5. Run post-task hook
|
|
1492
192
|
|
|
1493
|
-
**
|
|
1494
|
-
- Finalize task
|
|
1495
|
-
- Export metrics
|
|
1496
|
-
- Update coordination state
|
|
1497
|
-
- Trigger downstream agents
|
|
193
|
+
**For detailed integration:** See [Prompt Engineering Best Practices](./agent-principles/prompt-engineering.md)
|
|
1498
194
|
|
|
1499
|
-
|
|
195
|
+
---
|
|
1500
196
|
|
|
1501
|
-
|
|
1502
|
-
# Restore session context
|
|
1503
|
-
npx claude-flow@alpha hooks session-restore --session-id "swarm-auth-2025-09-30"
|
|
197
|
+
## Agent Profile Structure
|
|
1504
198
|
|
|
1505
|
-
|
|
1506
|
-
npx claude-flow@alpha hooks session-end --export-metrics true
|
|
1507
|
-
```
|
|
199
|
+
### The Three Formats
|
|
1508
200
|
|
|
1509
|
-
|
|
201
|
+
1. **MINIMAL (200-400 lines)**: For complex, strategic tasks requiring reasoning freedom
|
|
202
|
+
2. **METADATA (400-700 lines)**: For medium complexity with structured workflows
|
|
203
|
+
3. **CODE-HEAVY (700-1200 lines)**: For basic tasks benefiting from concrete examples
|
|
1510
204
|
|
|
1511
|
-
|
|
205
|
+
**Detailed format specifications:** [Format Selection Principles](./agent-principles/format-selection.md)
|
|
1512
206
|
|
|
1513
|
-
|
|
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
|
-
```
|
|
207
|
+
### Format Selection Decision Tree
|
|
1523
208
|
|
|
1524
|
-
**Memory Key Patterns:**
|
|
1525
209
|
```
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
-
|
|
210
|
+
Task Complexity Assessment
|
|
211
|
+
│
|
|
212
|
+
┌───┴────┐
|
|
213
|
+
│ │
|
|
214
|
+
BASIC COMPLEX
|
|
215
|
+
│ │
|
|
216
|
+
CODE-HEAVY MINIMAL
|
|
1533
217
|
```
|
|
1534
218
|
|
|
1535
|
-
|
|
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
|
-
```
|
|
219
|
+
**Full decision tree and factors:** [Format Selection Principles](./agent-principles/format-selection.md)
|
|
1552
220
|
|
|
1553
221
|
---
|
|
1554
222
|
|
|
1555
223
|
## Examples & Templates
|
|
1556
224
|
|
|
1557
|
-
### Example 1: Minimal Format
|
|
225
|
+
### Example 1: Minimal Format (Complex Tasks)
|
|
1558
226
|
|
|
1559
227
|
**File:** `.claude/agents/architecture/system-architect.md`
|
|
1560
228
|
|
|
@@ -1563,8 +231,7 @@ Task("Code Reviewer", "Review auth implementation", "reviewer")
|
|
|
1563
231
|
name: system-architect
|
|
1564
232
|
description: |
|
|
1565
233
|
MUST BE USED when designing enterprise-grade system architecture.
|
|
1566
|
-
Use PROACTIVELY for distributed systems, event-driven architecture
|
|
1567
|
-
microservices decomposition, scalability planning.
|
|
234
|
+
Use PROACTIVELY for distributed systems, event-driven architecture.
|
|
1568
235
|
Keywords - architecture, system design, microservices, scalability
|
|
1569
236
|
tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
|
|
1570
237
|
model: sonnet
|
|
@@ -1623,907 +290,81 @@ trade-offs, document decisions with ADRs.
|
|
|
1623
290
|
- Trade-offs are explicitly documented
|
|
1624
291
|
```
|
|
1625
292
|
|
|
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`)
|
|
293
|
+
**For more examples:** [Format Selection Principles](./agent-principles/format-selection.md)
|
|
2354
294
|
|
|
2355
295
|
---
|
|
2356
296
|
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
### ❌ DON'T: Use .unwrap() in Production
|
|
2360
|
-
|
|
2361
|
-
```rust
|
|
2362
|
-
// BAD - Panics on None
|
|
2363
|
-
let value = some_option.unwrap();
|
|
297
|
+
### Example 2: Metadata Format (Medium Tasks)
|
|
2364
298
|
|
|
2365
|
-
|
|
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
|
-
```
|
|
299
|
+
**For complete example:** See API Developer template in [Format Selection Principles](./agent-principles/format-selection.md)
|
|
2378
300
|
|
|
2379
301
|
---
|
|
2380
302
|
|
|
2381
|
-
###
|
|
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
|
|
303
|
+
### Example 3: Code-Heavy Format (Basic Tasks)
|
|
2393
304
|
|
|
2394
|
-
|
|
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
|
-
```
|
|
305
|
+
**For complete example:** See Rust Coder template in [Format Selection Principles](./agent-principles/format-selection.md)
|
|
2402
306
|
|
|
2403
307
|
---
|
|
2404
308
|
|
|
2405
|
-
|
|
309
|
+
## Specialized Guidance
|
|
2406
310
|
|
|
2407
|
-
|
|
2408
|
-
// BAD - Manual index loop
|
|
2409
|
-
for i in 0..vec.len() {
|
|
2410
|
-
println!("{}", vec[i]);
|
|
2411
|
-
}
|
|
2412
|
-
```
|
|
311
|
+
### By Agent Type
|
|
2413
312
|
|
|
2414
|
-
|
|
313
|
+
Different agent types have different format requirements:
|
|
2415
314
|
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
315
|
+
- **Coder Agents**: Code-Heavy for basic tasks, Minimal for complex algorithms
|
|
316
|
+
- **Reviewer Agents**: Minimal format (requires contextual reasoning)
|
|
317
|
+
- **Architect Agents**: Minimal format (strategic thinking)
|
|
318
|
+
- **Tester Agents**: Code-Heavy for unit tests, Metadata for test strategy
|
|
319
|
+
- **Researcher Agents**: Minimal format (open-ended exploration)
|
|
320
|
+
- **DevOps Agents**: Metadata format (structured workflows)
|
|
2419
321
|
|
|
2420
|
-
|
|
2421
|
-
for item in &vec {
|
|
2422
|
-
println!("{}", item);
|
|
2423
|
-
}
|
|
2424
|
-
```
|
|
322
|
+
**Full type-specific guidance:** [Agent Type Guidelines](./agent-principles/agent-type-guidelines.md)
|
|
2425
323
|
|
|
2426
324
|
---
|
|
2427
325
|
|
|
2428
|
-
###
|
|
326
|
+
### Prompt Engineering
|
|
2429
327
|
|
|
2430
|
-
|
|
2431
|
-
// BAD - Not type-safe
|
|
2432
|
-
fn parse() -> Result<Value, String> {
|
|
2433
|
-
Err("Parse error".to_string())
|
|
2434
|
-
}
|
|
2435
|
-
```
|
|
328
|
+
Key principles for effective agent prompts:
|
|
2436
329
|
|
|
2437
|
-
|
|
330
|
+
1. **Clear Role Definition**: Establish expertise domain
|
|
331
|
+
2. **Specific Responsibilities**: Concrete, actionable duties
|
|
332
|
+
3. **Appropriate Tool Selection**: Only essential tools
|
|
333
|
+
4. **Integration Points**: Explicit collaboration contracts
|
|
334
|
+
5. **Validation Hooks**: Mandatory quality gates
|
|
2438
335
|
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
Format(String),
|
|
2445
|
-
}
|
|
336
|
+
**Anti-patterns to avoid:**
|
|
337
|
+
- Over-specification (tunnel vision)
|
|
338
|
+
- Under-specification (too vague)
|
|
339
|
+
- Example overload (cognitive burden)
|
|
340
|
+
- Rigid checklists (context-insensitive)
|
|
2446
341
|
|
|
2447
|
-
|
|
2448
|
-
Err(ParseError::Format("Invalid format".to_string()))
|
|
2449
|
-
}
|
|
2450
|
-
```
|
|
2451
|
-
```
|
|
342
|
+
**Detailed best practices:** [Prompt Engineering Best Practices](./agent-principles/prompt-engineering.md)
|
|
2452
343
|
|
|
2453
344
|
---
|
|
2454
345
|
|
|
2455
|
-
|
|
346
|
+
### Quality Metrics & Validation
|
|
2456
347
|
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
### Structure ✓
|
|
348
|
+
**Pre-Deployment Checklist:**
|
|
2460
349
|
- [ ] Valid YAML frontmatter
|
|
2461
|
-
- [ ] All required fields present
|
|
2462
|
-
- [ ] Clear role definition
|
|
2463
|
-
- [ ] Appropriate section organization
|
|
2464
|
-
|
|
2465
|
-
### Format Selection ✓
|
|
2466
350
|
- [ ] Format matches task complexity
|
|
2467
|
-
- [ ]
|
|
2468
|
-
- [ ]
|
|
2469
|
-
|
|
2470
|
-
### Content Quality ✓
|
|
2471
|
-
- [ ] Clear responsibilities
|
|
2472
|
-
- [ ] Methodology explained
|
|
2473
|
-
- [ ] Integration points defined
|
|
2474
|
-
- [ ] Success metrics specified
|
|
351
|
+
- [ ] Clear responsibilities defined
|
|
352
|
+
- [ ] Integration points specified
|
|
2475
353
|
- [ ] Post-edit hook included
|
|
2476
354
|
|
|
2477
|
-
|
|
2478
|
-
-
|
|
2479
|
-
-
|
|
2480
|
-
-
|
|
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
|
-
```
|
|
355
|
+
**Ongoing Monitoring:**
|
|
356
|
+
- First-time success rate (>80%)
|
|
357
|
+
- Iteration count (<3)
|
|
358
|
+
- Quality score (>85%)
|
|
359
|
+
- User satisfaction (>4.5/5)
|
|
2511
360
|
|
|
2512
|
-
|
|
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
|
|
361
|
+
**Comprehensive validation guide:** [Quality Metrics & Validation](./agent-principles/quality-metrics.md)
|
|
2521
362
|
|
|
2522
363
|
---
|
|
2523
364
|
|
|
2524
|
-
##
|
|
365
|
+
## Benchmark System
|
|
2525
366
|
|
|
2526
|
-
### Running
|
|
367
|
+
### Running Benchmarks
|
|
2527
368
|
|
|
2528
369
|
```bash
|
|
2529
370
|
cd benchmark/agent-benchmarking
|
|
@@ -2534,75 +375,25 @@ node index.js run 5 --rust --verbose
|
|
|
2534
375
|
# Run JavaScript benchmarks (HYPOTHESIS)
|
|
2535
376
|
node index.js run 5 --verbose
|
|
2536
377
|
|
|
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
378
|
# Analyze results
|
|
2544
379
|
node index.js analyze
|
|
2545
380
|
```
|
|
2546
381
|
|
|
2547
|
-
|
|
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
|
-
```
|
|
382
|
+
**Detailed benchmarking guide:** [Quality Metrics & Validation](./agent-principles/quality-metrics.md)
|
|
2591
383
|
|
|
2592
384
|
---
|
|
2593
385
|
|
|
2594
386
|
## Conclusion
|
|
2595
387
|
|
|
2596
|
-
|
|
388
|
+
### Key Takeaways
|
|
2597
389
|
|
|
2598
390
|
1. **Format matters**: Choose based on task complexity (inverse relationship)
|
|
2599
|
-
2. **Validation is critical**:
|
|
2600
|
-
3. **Integration is essential**:
|
|
391
|
+
2. **Validation is critical**: Hooks ensure quality and coordination
|
|
392
|
+
3. **Integration is essential**: Memory and swarm systems enable collaboration
|
|
2601
393
|
4. **Continuous improvement**: Use metrics to refine agents
|
|
2602
394
|
|
|
2603
|
-
|
|
395
|
+
### Next Steps
|
|
2604
396
|
|
|
2605
|
-
**Next Steps:**
|
|
2606
397
|
1. Choose appropriate format for your agent
|
|
2607
398
|
2. Use templates as starting points
|
|
2608
399
|
3. Test with benchmark system
|
|
@@ -2611,7 +402,16 @@ By following these guidelines, you'll create agents that are effective, maintain
|
|
|
2611
402
|
|
|
2612
403
|
---
|
|
2613
404
|
|
|
405
|
+
## Reference Documents
|
|
406
|
+
|
|
407
|
+
- **[Format Selection Principles](./agent-principles/format-selection.md)**: Detailed format guidance, benchmarking findings, decision tree
|
|
408
|
+
- **[Agent Type Guidelines](./agent-principles/agent-type-guidelines.md)**: Type-specific recommendations for coders, reviewers, architects, testers, researchers, DevOps
|
|
409
|
+
- **[Prompt Engineering Best Practices](./agent-principles/prompt-engineering.md)**: Effective prompt patterns, anti-patterns, integration with Claude Flow
|
|
410
|
+
- **[Quality Metrics & Validation](./agent-principles/quality-metrics.md)**: Validation checklists, benchmark system, continuous improvement
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
2614
414
|
**Document Version:** 2.0.0
|
|
2615
415
|
**Last Updated:** 2025-09-30
|
|
2616
416
|
**Maintained By:** Claude Flow Core Team
|
|
2617
|
-
**Feedback:** Document improvements and findings for future versions
|
|
417
|
+
**Feedback:** Document improvements and findings for future versions
|