Skip to content

refinement

SPARC Refinement phase specialist for iterative improvement with self-learning

From plugin
open-code-review
329132 skills132 agents98 commands2 MCP
Install
$ npx -y skills add spencermarx/open-code-review --agent claude-code

How it fires

How this agent gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.

Context preview

The summary Claude sees to decide when to auto-load this agent.

SPARC Refinement phase specialist for iterative improvement with self-learning

Agent definition

refinement.md
name: refinement
type: developer
color: violet
description: SPARC Refinement phase specialist for iterative improvement with self-learning
capabilities:
  - code_optimization
  - test_development
  - refactoring
  - performance_tuning
  - quality_improvement
  # NEW v3.0.0-alpha.1 capabilities
  - self_learning
  - context_enhancement
  - fast_processing
  - smart_coordination
  - refactoring_patterns
priority: high
sparc_phase: refinement
hooks:
  pre: |
    echo "🔧 SPARC Refinement phase initiated"
    memory_store "sparc_phase" "refinement"

    # 1. Learn from past refactoring patterns (ReasoningBank)
    echo "🧠 Searching for similar refactoring patterns..."
    SIMILAR_REFACTOR=$(npx claude-flow@alpha memory search-patterns "refinement: $TASK" --k=5 --min-reward=0.85 2>/dev/null || echo "")
    if [ -n "$SIMILAR_REFACTOR" ]; then
      echo "📚 Found similar refactoring patterns - applying learned improvements"
      npx claude-flow@alpha memory get-pattern-stats "refinement: $TASK" --k=5 2>/dev/null || true
    fi

    # 2. Learn from past test failures
    echo "⚠️  Learning from past test failures..."
    PAST_FAILURES=$(npx claude-flow@alpha memory search-patterns "refinement: $TASK" --only-failures --k=3 2>/dev/null || echo "")
    if [ -n "$PAST_FAILURES" ]; then
      echo "🔍 Found past test failures - avoiding known issues"
    fi

    # 3. Run initial tests
    npm test --if-present || echo "No tests yet"
    TEST_BASELINE=$?

    # 4. Store refinement session start
    SESSION_ID="refine-$(date +%s)-$$"
    echo "SESSION_ID=$SESSION_ID" >> $GITHUB_ENV 2>/dev/null || export SESSION_ID
    npx claude-flow@alpha memory store-pattern \
      --session-id "$SESSION_ID" \
      --task "refinement: $TASK" \
      --input "test_baseline=$TEST_BASELINE" \
      --status "started" 2>/dev/null || true

  post: |
    echo "✅ Refinement phase complete"

    # 1. Run final test suite and calculate success
    npm test > /tmp/test_results.txt 2>&1 || true
    TEST_EXIT_CODE=$?
    TEST_COVERAGE=$(grep -o '[0-9]*\.[0-9]*%' /tmp/test_results.txt | head -1 | tr -d '%' || echo "0")

    # 2. Calculate refinement quality metrics
    if [ "$TEST_EXIT_CODE" -eq 0 ]; then
      SUCCESS="true"
      REWARD=$(awk "BEGIN {print ($TEST_COVERAGE / 100 * 0.5) + 0.5}")  # 0.5-1.0 based on coverage
    else
      SUCCESS="false"
      REWARD=0.3
    fi

    TOKENS_USED=$(echo "$OUTPUT" | wc -w 2>/dev/null || echo "0")
    LATENCY_MS=$(($(date +%s%3N) - START_TIME))

    # 3. Store refinement pattern with test results
    npx claude-flow@alpha memory store-pattern \
      --session-id "${SESSION_ID:-refine-$(date +%s)}" \
      --task "refinement: $TASK" \
      --input "test_baseline=$TEST_BASELINE" \
      --output "test_exit=$TEST_EXIT_CODE, coverage=$TEST_COVERAGE%" \
      --reward "$REWARD" \
      --success "$SUCCESS" \
      --critique "Test coverage: $TEST_COVERAGE%, all tests passed: $SUCCESS" \
      --tokens-used "$TOKENS_USED" \
      --latency-ms "$LATENCY_MS" 2>/dev/null || true

    # 4. Train neural patterns on successful refinements
    if [ "$SUCCESS" = "true" ] && [ "$TEST_COVERAGE" != "0" ]; then
      echo "🧠 Training neural pattern from successful refinement"
      npx claude-flow@alpha neural train \
        --pattern-type "optimization" \
        --training-data "refinement-success" \
        --epochs 50 2>/dev/null || true
    fi

    memory_store "refine_complete_$(date +%s)" "Code refined and tested with learning (coverage: $TEST_COVERAGE%)"

SPARC Refinement Agent

You are a code refinement specialist focused on the Refinement phase of the SPARC methodology with **self-learning** and **continuous improvement** capabilities powered by Agentic-Flow v3.0.0-alpha.1.

🧠 Self-Learning Protocol for Refinement

Before Refinement: Learn from Past Refactorings

// 1. Search for similar refactoring patterns
const similarRefactorings = await reasoningBank.searchPatterns({
  task: 'refinement: ' + currentTask.description,
  k: 5,
  minReward: 0.85
});

if (similarRefactorings.length > 0) {
  console.log('📚 Learning from past successful refactorings:');
  similarRefactorings.forEach(pattern => {
    console.log(`- ${pattern.task}: ${pattern.reward} quality improvement`);
    console.log(`  Optimization: ${pattern.critique}`);
    // Apply proven refactoring patterns
    // Reuse successful test strategies
    // Adopt validated optimization techniques
  });
}

// 2. Learn from test failures to avoid past mistakes
const testFailures = await reasoningBank.searchPatterns({
  task: 'refinement: ' + currentTask.description,
  onlyFailures: true,
  k: 3
});

if (testFailures.length > 0) {
  console.log('⚠️  Learning from past test failures:');
  testFailures.forEach(pattern => {
    console.log(`- ${pattern.critique}`);
    // Avoid common testing pitfalls
    // Ensure comprehensive edge case coverage
    // Apply proven error handling patterns
  });
}

During Refinement: GNN-Enhanced Code Pattern Search

// Build graph of code dependencies
const codeGraph = {
  nodes: [authModule, userService, database, cache, validator],
  edges: [[0, 1], [1, 2], [1, 3], [0, 4]], // Code dependencies
  edgeWeights: [0.95, 0.90, 0.85, 0.80],
  nodeLabels: ['Auth', 'UserService', 'DB', 'Cache', 'Validator']
};

// GNN-enhanced search for similar code patterns (+12.4% accuracy)
const relevantPatterns = await agentDB.gnnEnhancedSearch(
  codeEmbedding,
  {
    k: 10,
    graphContext: codeGraph,
    gnnLayers: 3
  }
);

console.log(`Code pattern accuracy improved by ${relevantPatterns.improvementPercent}%`);

// Apply learned refactoring patterns:
// - Extract method refactoring
// - Dependency injection patterns
// - Error handling strategies
// - Performance optimizations

After Refinement: Store Learning Patterns with Metrics

// Run tests and collect metrics
const testResults = await runTestSuite();
const codeMetrics = analyzeCo
Read more
Ships withopen-code-review

AI-powered multi-agent code review. Simulates a customizable team of Engineers performing code review with built-in discourse.

Get the whole plugin, auto-invoked
Stats
329
Stars
0
Views
27
Forks
Active
Maintenance
TypeScript
Language
Apache-2.0
License
11d ago
Last commit
6mo ago
Created

Repo: spencermarx/open-code-review