mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-01-24 08:13:08 +08:00
feat: add continuous learning skill with session examples
Stop hook-based pattern extraction - no README, comments in .sh file.
This commit is contained in:
70
commands/learn.md
Normal file
70
commands/learn.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# /learn - Extract Reusable Patterns
|
||||
|
||||
Analyze the current session and extract any patterns worth saving as skills.
|
||||
|
||||
## Trigger
|
||||
|
||||
Run `/learn` at any point during a session when you've solved a non-trivial problem.
|
||||
|
||||
## What to Extract
|
||||
|
||||
Look for:
|
||||
|
||||
1. **Error Resolution Patterns**
|
||||
- What error occurred?
|
||||
- What was the root cause?
|
||||
- What fixed it?
|
||||
- Is this reusable for similar errors?
|
||||
|
||||
2. **Debugging Techniques**
|
||||
- Non-obvious debugging steps
|
||||
- Tool combinations that worked
|
||||
- Diagnostic patterns
|
||||
|
||||
3. **Workarounds**
|
||||
- Library quirks
|
||||
- API limitations
|
||||
- Version-specific fixes
|
||||
|
||||
4. **Project-Specific Patterns**
|
||||
- Codebase conventions discovered
|
||||
- Architecture decisions made
|
||||
- Integration patterns
|
||||
|
||||
## Output Format
|
||||
|
||||
Create a skill file at `~/.claude/skills/learned/[pattern-name].md`:
|
||||
|
||||
```markdown
|
||||
# [Descriptive Pattern Name]
|
||||
|
||||
**Extracted:** [Date]
|
||||
**Context:** [Brief description of when this applies]
|
||||
|
||||
## Problem
|
||||
[What problem this solves - be specific]
|
||||
|
||||
## Solution
|
||||
[The pattern/technique/workaround]
|
||||
|
||||
## Example
|
||||
[Code example if applicable]
|
||||
|
||||
## When to Use
|
||||
[Trigger conditions - what should activate this skill]
|
||||
```
|
||||
|
||||
## Process
|
||||
|
||||
1. Review the session for extractable patterns
|
||||
2. Identify the most valuable/reusable insight
|
||||
3. Draft the skill file
|
||||
4. Ask user to confirm before saving
|
||||
5. Save to `~/.claude/skills/learned/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Don't extract trivial fixes (typos, simple syntax errors)
|
||||
- Don't extract one-time issues (specific API outages, etc.)
|
||||
- Focus on patterns that will save time in future sessions
|
||||
- Keep skills focused - one pattern per skill
|
||||
54
examples/sessions/2026-01-17-debugging-memory.tmp
Normal file
54
examples/sessions/2026-01-17-debugging-memory.tmp
Normal file
@@ -0,0 +1,54 @@
|
||||
# Session: Memory Leak Investigation
|
||||
**Date:** 2026-01-17
|
||||
**Started:** 09:00
|
||||
**Last Updated:** 12:00
|
||||
|
||||
---
|
||||
|
||||
## Current State
|
||||
|
||||
Investigating memory leak in production. Heap growing unbounded over 24h period.
|
||||
|
||||
### Completed
|
||||
- [x] Set up heap snapshots in staging
|
||||
- [x] Identified leak source: event listeners not being cleaned up
|
||||
- [x] Fixed leak in WebSocket handler
|
||||
- [x] Verified fix with 4h soak test
|
||||
|
||||
### Root Cause
|
||||
WebSocket `onMessage` handlers were being added on reconnect but not removed on disconnect. After ~1000 reconnects, memory grew from 200MB to 2GB.
|
||||
|
||||
### The Fix
|
||||
```javascript
|
||||
// Before (leaking)
|
||||
socket.on('connect', () => {
|
||||
socket.on('message', handleMessage)
|
||||
})
|
||||
|
||||
// After (fixed)
|
||||
socket.on('connect', () => {
|
||||
socket.off('message', handleMessage) // Remove old listener first
|
||||
socket.on('message', handleMessage)
|
||||
})
|
||||
|
||||
// Even better - use once or cleanup on disconnect
|
||||
socket.on('disconnect', () => {
|
||||
socket.removeAllListeners('message')
|
||||
})
|
||||
```
|
||||
|
||||
### Debugging Technique Worth Saving
|
||||
1. Take heap snapshot at T=0
|
||||
2. Force garbage collection: `global.gc()`
|
||||
3. Run suspected operation N times
|
||||
4. Take heap snapshot at T=1
|
||||
5. Compare snapshots - look for objects with count = N
|
||||
|
||||
### Notes for Next Session
|
||||
- Add memory monitoring alert at 1GB threshold
|
||||
- Document this debugging pattern for team
|
||||
|
||||
### Context to Load
|
||||
```
|
||||
src/services/websocket.js
|
||||
```
|
||||
43
examples/sessions/2026-01-19-refactor-api.tmp
Normal file
43
examples/sessions/2026-01-19-refactor-api.tmp
Normal file
@@ -0,0 +1,43 @@
|
||||
# Session: API Refactor - Error Handling
|
||||
**Date:** 2026-01-19
|
||||
**Started:** 10:00
|
||||
**Last Updated:** 13:30
|
||||
|
||||
---
|
||||
|
||||
## Current State
|
||||
|
||||
Standardizing error handling across all API endpoints. Moving from ad-hoc try/catch to centralized error middleware.
|
||||
|
||||
### Completed
|
||||
- [x] Created AppError class with status codes
|
||||
- [x] Built global error handler middleware
|
||||
- [x] Migrated `/users` routes to new pattern
|
||||
- [x] Migrated `/products` routes
|
||||
|
||||
### Key Findings
|
||||
- 47 endpoints with inconsistent error responses
|
||||
- Some returning `{ error: message }`, others `{ message: message }`
|
||||
- No consistent HTTP status codes
|
||||
|
||||
### Error Response Standard
|
||||
```javascript
|
||||
{
|
||||
success: false,
|
||||
error: {
|
||||
code: 'VALIDATION_ERROR',
|
||||
message: 'Email is required',
|
||||
field: 'email' // optional, for validation errors
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Notes for Next Session
|
||||
- Migrate remaining routes: `/orders`, `/payments`, `/admin`
|
||||
- Add error logging to monitoring service
|
||||
|
||||
### Context to Load
|
||||
```
|
||||
src/middleware/errorHandler.js
|
||||
src/utils/AppError.js
|
||||
```
|
||||
76
examples/sessions/2026-01-20-feature-auth.tmp
Normal file
76
examples/sessions/2026-01-20-feature-auth.tmp
Normal file
@@ -0,0 +1,76 @@
|
||||
# Session: Auth Feature Implementation
|
||||
**Date:** 2026-01-20
|
||||
**Started:** 14:30
|
||||
**Last Updated:** 17:45
|
||||
|
||||
---
|
||||
|
||||
## Current State
|
||||
|
||||
Working on JWT authentication flow for the API. Main goal is replacing session-based auth with stateless tokens.
|
||||
|
||||
### Completed
|
||||
- [x] Set up JWT signing with RS256
|
||||
- [x] Created `/auth/login` endpoint
|
||||
- [x] Added refresh token rotation
|
||||
- [x] Fixed token expiry bug (was using seconds, needed milliseconds)
|
||||
|
||||
### In Progress
|
||||
- [ ] Add rate limiting to auth endpoints
|
||||
- [ ] Implement token blacklist for logout
|
||||
|
||||
### Blockers Encountered
|
||||
1. **jsonwebtoken version mismatch** - v9.x changed the `verify()` signature, had to update error handling
|
||||
2. **Redis TTL for refresh tokens** - Was setting TTL in seconds but passing milliseconds
|
||||
|
||||
### Key Decisions Made
|
||||
- Using RS256 over HS256 for better security with distributed services
|
||||
- Storing refresh tokens in Redis with 7-day TTL
|
||||
- Access tokens expire in 15 minutes
|
||||
|
||||
### Code Locations Modified
|
||||
- `src/middleware/auth.js` - JWT verification middleware
|
||||
- `src/routes/auth.js` - Login/logout/refresh endpoints
|
||||
- `src/services/token.service.js` - Token generation and validation
|
||||
|
||||
### Notes for Next Session
|
||||
- Need to add CSRF protection for cookie-based token storage
|
||||
- Consider adding fingerprinting for refresh token binding
|
||||
- Review rate limit values with team
|
||||
|
||||
### Context to Load
|
||||
```
|
||||
src/middleware/
|
||||
src/routes/auth.js
|
||||
src/services/token.service.js
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Session Log
|
||||
|
||||
**14:30** - Started session, goal is JWT implementation
|
||||
|
||||
**14:45** - Set up basic JWT signing. Using RS256 with key pair stored in env vars.
|
||||
|
||||
**15:20** - Login endpoint working. Discovered jsonwebtoken v9 breaking change - `verify()` now throws different error types. Updated catch block:
|
||||
```javascript
|
||||
// Old (v8)
|
||||
if (err.name === 'TokenExpiredError') { ... }
|
||||
|
||||
// New (v9)
|
||||
if (err instanceof jwt.TokenExpiredError) { ... }
|
||||
```
|
||||
|
||||
**16:00** - Refresh token rotation working but tokens expiring immediately. Bug: was passing `Date.now()` (milliseconds) to `expiresIn` which expects seconds. Fixed:
|
||||
```javascript
|
||||
// Wrong
|
||||
expiresIn: Date.now() + 900000
|
||||
|
||||
// Correct
|
||||
expiresIn: '15m'
|
||||
```
|
||||
|
||||
**17:30** - Auth flow complete. Login -> access token -> refresh -> new tokens. Ready for rate limiting tomorrow.
|
||||
|
||||
**17:45** - Saving session state.
|
||||
18
skills/continuous-learning/config.json
Normal file
18
skills/continuous-learning/config.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"min_session_length": 10,
|
||||
"extraction_threshold": "medium",
|
||||
"auto_approve": false,
|
||||
"learned_skills_path": "~/.claude/skills/learned/",
|
||||
"patterns_to_detect": [
|
||||
"error_resolution",
|
||||
"user_corrections",
|
||||
"workarounds",
|
||||
"debugging_techniques",
|
||||
"project_specific"
|
||||
],
|
||||
"ignore_patterns": [
|
||||
"simple_typos",
|
||||
"one_time_fixes",
|
||||
"external_api_issues"
|
||||
]
|
||||
}
|
||||
60
skills/continuous-learning/evaluate-session.sh
Executable file
60
skills/continuous-learning/evaluate-session.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
# Continuous Learning - Session Evaluator
|
||||
# Runs on Stop hook to extract reusable patterns from Claude Code sessions
|
||||
#
|
||||
# Why Stop hook instead of UserPromptSubmit:
|
||||
# - Stop runs once at session end (lightweight)
|
||||
# - UserPromptSubmit runs every message (heavy, adds latency)
|
||||
#
|
||||
# Hook config (in ~/.claude/settings.json):
|
||||
# {
|
||||
# "hooks": {
|
||||
# "Stop": [{
|
||||
# "matcher": "*",
|
||||
# "hooks": [{
|
||||
# "type": "command",
|
||||
# "command": "~/.claude/skills/continuous-learning/evaluate-session.sh"
|
||||
# }]
|
||||
# }]
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# Patterns to detect: error_resolution, debugging_techniques, workarounds, project_specific
|
||||
# Patterns to ignore: simple_typos, one_time_fixes, external_api_issues
|
||||
# Extracted skills saved to: ~/.claude/skills/learned/
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
CONFIG_FILE="$SCRIPT_DIR/config.json"
|
||||
LEARNED_SKILLS_PATH="${HOME}/.claude/skills/learned"
|
||||
MIN_SESSION_LENGTH=10
|
||||
|
||||
# Load config if exists
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
MIN_SESSION_LENGTH=$(jq -r '.min_session_length // 10' "$CONFIG_FILE")
|
||||
LEARNED_SKILLS_PATH=$(jq -r '.learned_skills_path // "~/.claude/skills/learned/"' "$CONFIG_FILE" | sed "s|~|$HOME|")
|
||||
fi
|
||||
|
||||
# Ensure learned skills directory exists
|
||||
mkdir -p "$LEARNED_SKILLS_PATH"
|
||||
|
||||
# Get transcript path from environment (set by Claude Code)
|
||||
transcript_path="${CLAUDE_TRANSCRIPT_PATH:-}"
|
||||
|
||||
if [ -z "$transcript_path" ] || [ ! -f "$transcript_path" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Count messages in session
|
||||
message_count=$(grep -c '"type":"user"' "$transcript_path" 2>/dev/null || echo "0")
|
||||
|
||||
# Skip short sessions
|
||||
if [ "$message_count" -lt "$MIN_SESSION_LENGTH" ]; then
|
||||
echo "[ContinuousLearning] Session too short ($message_count messages), skipping" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Signal to Claude that session should be evaluated for extractable patterns
|
||||
echo "[ContinuousLearning] Session has $message_count messages - evaluate for extractable patterns" >&2
|
||||
echo "[ContinuousLearning] Save learned skills to: $LEARNED_SKILLS_PATH" >&2
|
||||
Reference in New Issue
Block a user