File size: 6,251 Bytes
40d7073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# RuVector Hooks for Claude Code

Self-learning intelligence hooks that enhance Claude Code with Q-learning, vector memory, and automatic agent routing.

## Quick Start

```bash
# Full setup: hooks + pretrain + optimized agents
npx ruvector hooks init --pretrain --build-agents quality

# Or step by step:
npx ruvector hooks init          # Setup hooks
npx ruvector hooks pretrain      # Analyze repository
npx ruvector hooks build-agents  # Generate agent configs
```

## What It Does

RuVector hooks integrate with Claude Code to provide:

| Feature | Description |
|---------|-------------|
| **Agent Routing** | Suggests the best agent for each file type based on learned patterns |
| **Co-edit Patterns** | Predicts "likely next files" from git history |
| **Vector Memory** | Semantic recall of project context |
| **Command Analysis** | Risk assessment for bash commands |
| **Self-Learning** | Q-learning improves suggestions over time |

## Commands

### Initialization

```bash
# Full configuration
npx ruvector hooks init

# With pretrain and agent building
npx ruvector hooks init --pretrain --build-agents security

# Minimal (basic hooks only)
npx ruvector hooks init --minimal

# Options
--force           # Overwrite existing settings
--minimal         # Basic hooks only
--pretrain        # Run pretrain after init
--build-agents    # Generate optimized agents (quality|speed|security|testing|fullstack)
--no-claude-md    # Skip CLAUDE.md creation
--no-permissions  # Skip permissions config
--no-env          # Skip environment variables
--no-gitignore    # Skip .gitignore update
--no-mcp          # Skip MCP server config
--no-statusline   # Skip status line config
```

### Pretrain

Analyze your repository to bootstrap intelligence:

```bash
npx ruvector hooks pretrain

# Options
--depth <n>     # Git history depth (default: 100)
--verbose       # Show detailed progress
--skip-git      # Skip git history analysis
--skip-files    # Skip file structure analysis
```

**What it learns:**
- File type β†’ Agent mapping (`.rs` β†’ rust-developer)
- Co-edit patterns from git history
- Directory β†’ Agent mapping
- Project context memories

### Build Agents

Generate optimized `.claude/agents/` configurations:

```bash
npx ruvector hooks build-agents --focus quality

# Focus modes
--focus quality   # Code quality, best practices (default)
--focus speed     # Rapid development, prototyping
--focus security  # OWASP, input validation, encryption
--focus testing   # TDD, comprehensive coverage
--focus fullstack # Balanced frontend/backend/database

# Options
--output <dir>    # Output directory (default: .claude/agents)
--format <fmt>    # yaml, json, or md (default: yaml)
--include-prompts # Include system prompts in agent configs
```

### Verification & Diagnostics

```bash
# Check if hooks are working
npx ruvector hooks verify

# Diagnose and fix issues
npx ruvector hooks doctor
npx ruvector hooks doctor --fix
```

### Data Management

```bash
# View statistics
npx ruvector hooks stats

# Export intelligence data
npx ruvector hooks export -o backup.json
npx ruvector hooks export --include-all

# Import intelligence data
npx ruvector hooks import backup.json
npx ruvector hooks import backup.json --merge
```

### Memory Operations

```bash
# Store context in vector memory
npx ruvector hooks remember "API uses JWT auth" -t project

# Semantic search memory
npx ruvector hooks recall "authentication"

# Route a task to best agent
npx ruvector hooks route "implement user login"
```

## Hook Events

| Event | Trigger | RuVector Action |
|-------|---------|-----------------|
| **PreToolUse** | Before Edit/Write/Bash | Agent routing, file analysis, command risk |
| **PostToolUse** | After Edit/Write/Bash | Q-learning update, pattern recording |
| **SessionStart** | Conversation begins | Load intelligence, display stats |
| **Stop** | Conversation ends | Save learning data |
| **UserPromptSubmit** | User sends message | Context suggestions |
| **PreCompact** | Before context compaction | Preserve important context |
| **Notification** | Any notification | Track events for learning |

## Generated Files

After running `hooks init`:

```
your-project/
β”œβ”€β”€ .claude/
β”‚   β”œβ”€β”€ settings.json      # Hooks configuration
β”‚   β”œβ”€β”€ statusline.sh      # Status bar script
β”‚   └── agents/            # Generated agents (with --build-agents)
β”‚       β”œβ”€β”€ rust-specialist.yaml
β”‚       β”œβ”€β”€ typescript-specialist.yaml
β”‚       β”œβ”€β”€ test-architect.yaml
β”‚       └── project-coordinator.yaml
β”œβ”€β”€ .ruvector/
β”‚   └── intelligence.json  # Learning data
β”œβ”€β”€ CLAUDE.md              # Project documentation
└── .gitignore             # Updated with .ruvector/
```

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `RUVECTOR_INTELLIGENCE_ENABLED` | `true` | Enable/disable intelligence |
| `RUVECTOR_LEARNING_RATE` | `0.1` | Q-learning rate (0.0-1.0) |
| `RUVECTOR_MEMORY_BACKEND` | `rvlite` | Memory storage backend |
| `INTELLIGENCE_MODE` | `treatment` | A/B testing mode |

## Example Output

### Agent Routing
```
🧠 Intelligence Analysis:
   πŸ“ src/api/routes.ts
   πŸ€– Recommended: typescript-developer (85% confidence)
      β†’ learned from 127 .ts files in repo
   πŸ“Ž Likely next files:
      - src/api/handlers.ts (12 co-edits)
      - src/types/api.ts (8 co-edits)
```

### Command Analysis
```
🧠 Command Analysis:
   πŸ“¦ Category: rust
   🏷️  Type: test
   βœ… Risk: LOW
```

## Best Practices

1. **Run pretrain on existing repos** β€” Bootstrap intelligence before starting work
2. **Use focus modes** β€” Match agent generation to your current task
3. **Export before major changes** β€” Backup learning data
4. **Let it learn** β€” Intelligence improves with each edit

## Troubleshooting

```bash
# Check setup
npx ruvector hooks verify

# Fix common issues
npx ruvector hooks doctor --fix

# Reset and reinitialize
npx ruvector hooks init --force --pretrain
```

## Links

- [RuVector GitHub](https://github.com/ruvnet/ruvector)
- [npm Package](https://www.npmjs.com/package/ruvector)
- [Claude Code Documentation](https://docs.anthropic.com/claude-code)