Skip to content

feat: add 'skim learn' command for CLI error pattern detection and correction rules #64

@dean0x

Description

@dean0x

Learn Command — CLI Error Pattern Detection

Parent: #19 (Phase B)
Category: B6 — Platform Integration

Context

GRANITE's learn system analyzes CLI error history from agent sessions to detect patterns (unknown flags, command not found, missing args, permission denied) and generates correction rules. This helps agents avoid repeating the same mistakes.

This is a quality-of-life feature that compounds over time — the more an agent uses skim, the fewer errors it makes.

Design

Subcommand

skim learn                     # Analyze recent sessions, print findings
skim learn --generate          # Generate correction rules file
skim learn --since 7d          # Analyze last 7 days

Output

Skim Learn — CLI Error Patterns (last 24h)

Detected 8 error patterns across 3 sessions:

  cargo test --nocapture (5x)
    Correction: cargo test -- --nocapture
    Pattern: missing -- separator before test runner flags

  git log --onleline (2x)
    Correction: git log --oneline
    Pattern: typo in flag name

  ruff check --fix --unsafe (1x)
    Correction: ruff check --fix --unsafe-fixes
    Pattern: truncated flag name

Generated: .claude/rules/cli-corrections.md

How It Works

  1. Session scanning: Parse agent session JSONL files for Bash tool calls
  2. Error detection: Identify non-zero exit codes followed by similar retry commands
  3. Pattern classification: Categorize errors (typo, missing separator, wrong flag, missing arg)
  4. Correction extraction: Find the successful command that followed the error
  5. Deduplication: Group identical patterns, track frequency
  6. Rule generation: Output markdown rules that agents can reference

Exclusions

  • TDD cycles (compile-test-fix loops) are NOT errors — exclude rapid test/fix alternation
  • Path exploration (cd attempts) are NOT errors — exclude sequential directory navigation
  • Single-occurrence errors below confidence threshold

Generated Rules File

# CLI Corrections (auto-generated by skim learn)

- Always use `--` before test runner flags: `cargo test -- --nocapture`
- Use `--unsafe-fixes` not `--unsafe` with ruff check
- Git log flag is `--oneline` (one L, not two)

Key Files

  • New crates/rskim/src/cmd/learn.rs — Learn engine
  • New crates/rskim/src/learn/detector.rs — Error pattern detection
  • New crates/rskim/src/learn/classifier.rs — Pattern classification
  • Extend crates/rskim/src/main.rs — Add learn subcommand

Acceptance Criteria

  • skim learn scans Claude Code session files and reports error patterns
  • Patterns classified by type (typo, missing separator, wrong flag, missing arg)
  • Frequency tracking (shows how often each error occurs)
  • --generate produces a markdown rules file
  • TDD cycles excluded from error detection
  • Works with zero sessions (helpful message, not error)

Size: M

Depends on: B0-1 (#39)

Blocks: nothing (additive)

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase-bPhase B: Command Output OptimizationpolishPolish & deferred work

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions