-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
phase-bPhase B: Command Output OptimizationPhase B: Command Output OptimizationpolishPolish & deferred workPolish & deferred work
Description
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 daysOutput
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
- Session scanning: Parse agent session JSONL files for Bash tool calls
- Error detection: Identify non-zero exit codes followed by similar retry commands
- Pattern classification: Categorize errors (typo, missing separator, wrong flag, missing arg)
- Correction extraction: Find the successful command that followed the error
- Deduplication: Group identical patterns, track frequency
- 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— Addlearnsubcommand
Acceptance Criteria
skim learnscans 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)
--generateproduces 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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
phase-bPhase B: Command Output OptimizationPhase B: Command Output OptimizationpolishPolish & deferred workPolish & deferred work