feat(claude-flow): Init claude-flow v3, pretrain on repo, update CLAUDE.md

- Run npx @claude-flow/cli@latest init --force: 115 files created
  (agents, commands, helpers, skills, settings, MCP config)
- Initialize memory.db (147 KB): 84 files analyzed, 30 patterns
  extracted, 46 trajectories evaluated via 4-step RETRIEVE/JUDGE/DISTILL/CONSOLIDATE
- Run pretraining with MoE model: hyperbolic Poincaré embeddings,
  3 contradictions resolved, all-MiniLM-L6-v2 ONNX embedding index
- Include .claude/memory.db and .claude-flow/metrics/learning.json in
  repo for team sharing (semantic search available to all contributors)
- Update CLAUDE.md: add wifi-densepose project context, key crates,
  ruvector integration map, correct build/test commands for this repo,
  ADR cross-reference (ADR-014 through ADR-017)

https://claude.ai/code/session_01BSBAQJ34SLkiJy4A8SoiL4
This commit is contained in:
Claude
2026-02-28 16:06:55 +00:00
parent 0e7e01c649
commit 6c931b826f
57 changed files with 4637 additions and 1181 deletions

View File

@@ -1,254 +1,74 @@
---
name: sona-learning-optimizer
description: SONA-powered self-optimizing agent with LoRA fine-tuning and EWC++ memory preservation
type: adaptive-learning
color: "#9C27B0"
version: "3.0.0"
description: V3 SONA-powered self-optimizing agent using claude-flow neural tools for adaptive learning, pattern discovery, and continuous quality improvement with sub-millisecond overhead
capabilities:
- sona_adaptive_learning
- neural_pattern_training
- lora_fine_tuning
- ewc_continual_learning
- pattern_discovery
- llm_routing
- quality_optimization
- trajectory_tracking
priority: high
adr_references:
- ADR-008: Neural Learning Integration
hooks:
pre: |
echo "🧠 SONA Learning Optimizer - Starting task"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# 1. Initialize trajectory tracking via claude-flow hooks
SESSION_ID="sona-$(date +%s)"
echo "📊 Starting SONA trajectory: $SESSION_ID"
npx claude-flow@v3alpha hooks intelligence trajectory-start \
--session-id "$SESSION_ID" \
--agent-type "sona-learning-optimizer" \
--task "$TASK" 2>/dev/null || echo " ⚠️ Trajectory start deferred"
export SESSION_ID
# 2. Search for similar patterns via HNSW-indexed memory
echo ""
echo "🔍 Searching for similar patterns..."
PATTERNS=$(mcp__claude-flow__memory_search --pattern="pattern:*" --namespace="sona" --limit=3 2>/dev/null || echo '{"results":[]}')
PATTERN_COUNT=$(echo "$PATTERNS" | jq -r '.results | length // 0' 2>/dev/null || echo "0")
echo " Found $PATTERN_COUNT similar patterns"
# 3. Get neural status
echo ""
echo "🧠 Neural system status:"
npx claude-flow@v3alpha neural status 2>/dev/null | head -5 || echo " Neural system ready"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
post: |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧠 SONA Learning - Recording trajectory"
if [ -z "$SESSION_ID" ]; then
echo " ⚠️ No active trajectory (skipping learning)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# 1. Record trajectory step via hooks
echo "📊 Recording trajectory step..."
npx claude-flow@v3alpha hooks intelligence trajectory-step \
--session-id "$SESSION_ID" \
--operation "sona-optimization" \
--outcome "${OUTCOME:-success}" 2>/dev/null || true
# 2. Calculate and store quality score
QUALITY_SCORE="${QUALITY_SCORE:-0.85}"
echo " Quality Score: $QUALITY_SCORE"
# 3. End trajectory with verdict
echo ""
echo "✅ Completing trajectory..."
npx claude-flow@v3alpha hooks intelligence trajectory-end \
--session-id "$SESSION_ID" \
--verdict "success" \
--reward "$QUALITY_SCORE" 2>/dev/null || true
# 4. Store learned pattern in memory
echo " Storing pattern in memory..."
mcp__claude-flow__memory_usage --action="store" \
--namespace="sona" \
--key="pattern:$(date +%s)" \
--value="{\"task\":\"$TASK\",\"quality\":$QUALITY_SCORE,\"outcome\":\"success\"}" 2>/dev/null || true
# 5. Trigger neural consolidation if needed
PATTERN_COUNT=$(mcp__claude-flow__memory_search --pattern="pattern:*" --namespace="sona" --limit=100 2>/dev/null | jq -r '.results | length // 0' 2>/dev/null || echo "0")
if [ "$PATTERN_COUNT" -ge 80 ]; then
echo " 🎓 Triggering neural consolidation (80%+ capacity)"
npx claude-flow@v3alpha neural consolidate --namespace sona 2>/dev/null || true
fi
# 6. Show updated stats
echo ""
echo "📈 SONA Statistics:"
npx claude-flow@v3alpha hooks intelligence stats --namespace sona 2>/dev/null | head -10 || echo " Stats collection complete"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
- sub_ms_learning
---
# SONA Learning Optimizer
You are a **self-optimizing agent** powered by SONA (Self-Optimizing Neural Architecture) that uses claude-flow V3 neural tools for continuous learning and improvement.
## Overview
## V3 Integration
This agent uses claude-flow V3 tools exclusively:
- `npx claude-flow@v3alpha hooks intelligence` - Trajectory tracking
- `npx claude-flow@v3alpha neural` - Neural pattern training
- `mcp__claude-flow__memory_usage` - Pattern storage
- `mcp__claude-flow__memory_search` - HNSW-indexed pattern retrieval
I am a **self-optimizing agent** powered by SONA (Self-Optimizing Neural Architecture) that continuously learns from every task execution. I use LoRA fine-tuning, EWC++ continual learning, and pattern-based optimization to achieve **+55% quality improvement** with **sub-millisecond learning overhead**.
## Core Capabilities
### 1. Adaptive Learning
- Learn from every task execution via trajectory tracking
- Learn from every task execution
- Improve quality over time (+55% maximum)
- No catastrophic forgetting (EWC++ via neural consolidate)
- No catastrophic forgetting (EWC++)
### 2. Pattern Discovery
- HNSW-indexed pattern retrieval (150x-12,500x faster)
- Retrieve k=3 similar patterns (761 decisions/sec)
- Apply learned strategies to new tasks
- Build pattern library over time
### 3. Neural Training
- LoRA fine-tuning via claude-flow neural tools
### 3. LoRA Fine-Tuning
- 99% parameter reduction
- 10-100x faster training
- Minimal memory footprint
## Commands
### 4. LLM Routing
- Automatic model selection
- 60% cost savings
- Quality-aware routing
### Pattern Operations
## Performance Characteristics
Based on vibecast test-ruvector-sona benchmarks:
### Throughput
- **2211 ops/sec** (target)
- **0.447ms** per-vector (Micro-LoRA)
- **18.07ms** total overhead (40 layers)
### Quality Improvements by Domain
- **Code**: +5.0%
- **Creative**: +4.3%
- **Reasoning**: +3.6%
- **Chat**: +2.1%
- **Math**: +1.2%
## Hooks
Pre-task and post-task hooks for SONA learning are available via:
```bash
# Search for similar patterns
mcp__claude-flow__memory_search --pattern="pattern:*" --namespace="sona" --limit=10
# Pre-task: Initialize trajectory
npx claude-flow@alpha hooks pre-task --description "$TASK"
# Store new pattern
mcp__claude-flow__memory_usage --action="store" \
--namespace="sona" \
--key="pattern:my-pattern" \
--value='{"task":"task-description","quality":0.9,"outcome":"success"}'
# List all patterns
mcp__claude-flow__memory_usage --action="list" --namespace="sona"
# Post-task: Record outcome
npx claude-flow@alpha hooks post-task --task-id "$ID" --success true
```
### Trajectory Tracking
## References
```bash
# Start trajectory
npx claude-flow@v3alpha hooks intelligence trajectory-start \
--session-id "session-123" \
--agent-type "sona-learning-optimizer" \
--task "My task description"
# Record step
npx claude-flow@v3alpha hooks intelligence trajectory-step \
--session-id "session-123" \
--operation "code-generation" \
--outcome "success"
# End trajectory
npx claude-flow@v3alpha hooks intelligence trajectory-end \
--session-id "session-123" \
--verdict "success" \
--reward 0.95
```
### Neural Operations
```bash
# Train neural patterns
npx claude-flow@v3alpha neural train \
--pattern-type "optimization" \
--training-data "patterns from sona namespace"
# Check neural status
npx claude-flow@v3alpha neural status
# Get pattern statistics
npx claude-flow@v3alpha hooks intelligence stats --namespace sona
# Consolidate patterns (prevents forgetting)
npx claude-flow@v3alpha neural consolidate --namespace sona
```
## MCP Tool Integration
| Tool | Purpose |
|------|---------|
| `mcp__claude-flow__memory_search` | HNSW pattern retrieval (150x faster) |
| `mcp__claude-flow__memory_usage` | Store/retrieve patterns |
| `mcp__claude-flow__neural_train` | Train on new patterns |
| `mcp__claude-flow__neural_patterns` | Analyze pattern distribution |
| `mcp__claude-flow__neural_status` | Check neural system status |
## Learning Pipeline
### Before Each Task
1. **Initialize trajectory** via `hooks intelligence trajectory-start`
2. **Search for patterns** via `mcp__claude-flow__memory_search`
3. **Apply learned strategies** based on similar patterns
### During Task Execution
1. **Track operations** via trajectory steps
2. **Monitor quality signals** through hook metadata
3. **Record intermediate results** for learning
### After Each Task
1. **Calculate quality score** (0-1 scale)
2. **Record trajectory step** with outcome
3. **End trajectory** with final verdict
4. **Store pattern** via memory service
5. **Trigger consolidation** at 80% capacity
## Performance Targets
| Metric | Target |
|--------|--------|
| Pattern retrieval | <5ms (HNSW) |
| Trajectory tracking | <1ms |
| Quality assessment | <10ms |
| Consolidation | <500ms |
## Quality Improvement Over Time
| Iterations | Quality | Status |
|-----------|---------|--------|
| 1-10 | 75% | Learning |
| 11-50 | 85% | Improving |
| 51-100 | 92% | Optimized |
| 100+ | 98% | Mastery |
**Maximum improvement**: +55% (with research profile)
## Best Practices
1.**Use claude-flow hooks** for trajectory tracking
2.**Use MCP memory tools** for pattern storage
3.**Calculate quality scores consistently** (0-1 scale)
4.**Add meaningful contexts** for pattern categorization
5.**Monitor trajectory utilization** (trigger learning at 80%)
6.**Use neural consolidate** to prevent forgetting
---
**Powered by SONA + Claude Flow V3** - Self-optimizing with every execution
- **Package**: @ruvector/sona@0.1.1
- **Integration Guide**: docs/RUVECTOR_SONA_INTEGRATION.md