haddock-development/claude-reflect-system / reflect
reflect
VerifiedAnalyzes conversation transcripts to extract user corrections, patterns, and preferences, then proposes skill improvements. Use this skill when users provide corrections, express preferences about code style, or when patterns emerge from successful approaches. Can be triggered manually with /reflect or automatically at session end when enabled.
| File | Kind | Size |
|---|---|---|
| .state/auto-reflection.json | config | 54 B |
| .state/last-reflection.timestamp | other | 0 B |
| README.md | markdown | 7.3 KB |
| SKILL.md | skill md | 2.8 KB |
| USER_GUIDE.md | markdown | 21.4 KB |
| commands/reflect-meta.md | markdown | 1.6 KB |
| commands/reflect-promote.md | markdown | 1.8 KB |
| commands/reflect-stats.md | markdown | 772 B |
| references/signal-patterns.md | markdown | 6.0 KB |
| scripts/extract_signals.pyexecutable | script | 12.3 KB |
| scripts/hook-stop.shexecutable | script | 2.2 KB |
| scripts/learning_ledger.py | script | 12.6 KB |
| scripts/meta_learning.py | script | 14.8 KB |
| scripts/present_review.pyexecutable | script | 9.9 KB |
| scripts/promote_learning.py | script | 8.0 KB |
| scripts/reflect.pyexecutable | script | 5.3 KB |
| scripts/scope_analyzer.py | script | 8.3 KB |
| scripts/semantic_detector.py | script | 8.1 KB |
| scripts/toggle-off.shexecutable | script | 431 B |
| scripts/toggle-on.shexecutable | script | 499 B |
| scripts/toggle-status.shexecutable | script | 2.5 KB |
| scripts/update_skill.pyexecutable | script | 8.2 KB |
scripts/reflect.py
View on GitHub#!/usr/bin/env python3
"""
Main reflection orchestration engine.
Coordinates signal extraction, skill updates, and user review.
"""
import json
import sys
import os
from pathlib import Path
from datetime import datetime
import subprocess
# Add scripts directory to path for imports
sys.path.insert(0, str(Path(__file__).parent))
from extract_signals import extract_signals
from update_skill import update_skill
from present_review import present_review
def main():
"""Main reflection workflow"""
# 1. Get transcript path from env or argument
transcript_path = os.getenv('TRANSCRIPT_PATH') or (sys.argv[1] if len(sys.argv) > 1 else None)
print("π§ Reflection Analysis Starting...")
# 2. Extract signals from transcript
try:
signals_by_skill = extract_signals(transcript_path)
except Exception as e:
print(f"β Error extracting signals: {e}")
return 1
if not signals_by_skill:
print("β No improvement suggestions found")
return 0
print(f"Found signals in {len(signals_by_skill)} skill(s)")
# 3. Present for review
try:
approved_changes = present_review(signals_by_skill)
except KeyboardInterrupt:
print("\n\nReview interrupted by user")
return 1
except Exception as e:
print(f"β Error during review: {e}")
return 1
if not approved_changes:
print("\nNo changes approved")
return 0
# 4. Apply changes with backups
success_count = 0
for change in approved_changes:
try:
if update_skill(change):
success_count += 1
except Exception as e:
print(f"β Error updating {change['skill_name']}: {e}")
if success_count == 0:
print("\nβ No skills were updated successfully")
return 1
# 5. Git commit
try:
commit_changes(approved_changes)
except Exception as e:
print(f"Warning: Git commit failed: {e}")
print("Changes were applied but not committed. Commit manually if needed.")
print(f"\nβ {success_count} skill(s) updated successfully")
# 6. Update reflection timestamp
update_last_reflection_timestamp()
return 0
def commit_changes(changes):
"""Commit skill updates to git"""
skills_dir = Path.home() / '.claude' / 'skills'
# Check if git repo exists
if not (skills_dir / '.git').exists():
print("\nNote: Skills directory is not a git repository")
print("Initialize with: cd ~/.claude/skills && git init")
return
skill_names = [c['skill_name'] for c in changes]
# Build commit message
message_lines = ["refactor(skills): apply reflection learnings\n"]
message_lines.append("Signals detected:")
for change in changes:
proposed = change.get('proposed_updates', {})
high_count = len(proposed.get('high_confidence', []))
medium_count = len(proposed.get('medium_confidence', []))
low_count = len(proposed.get('low_confidence', []))
if high_count:
message_lines.append(f"- HIGH ({high_count}): {change['skill_name']}")
if medium_count:
message_lines.append(f"- MEDIUM ({medium_count}): {change['skill_name']}")
if low_count:
message_lines.append(f"- LOW ({low_count}): {change['skill_name']}")
message_lines.append(f"\nSkills updated: {', '.join(skill_names)}\n")
# Add session info if available
session_id = os.getenv('SESSION_ID', 'unknown')
auto_reflected = os.getenv('AUTO_REFLECTED', 'false')
message_lines.append(f"Session: {session_id}")
message_lines.append(f"Auto-reflected: {auto_reflected}\n")
message_lines.append("π€ Generated with [Claude Code](https://claude.com/claude-code)")
message_lines.append("Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>")
commit_message = "\n".join(message_lines)
try:
# Stage all changes in skills directory
subprocess.run(['git', 'add', '.'], cwd=skills_dir, check=True, capture_output=True)
# Commit
subprocess.run(['git', 'commit', '-m', commit_message], cwd=skills_dir, check=True, capture_output=True)
print("\nβ Changes committed to git")
# Note: We don't auto-push for safety
# User can push manually if they want
print(" (Run 'cd ~/.claude/skills && git push' to push to remote)")
except subprocess.CalledProcessError as e:
# Check if it's just "nothing to commit"
if b'nothing to commit' in e.stdout or b'nothing to commit' in e.stderr:
print("\nNote: Git reported nothing to commit (files may be unchanged)")
else:
raise
def update_last_reflection_timestamp():
"""Update the last reflection timestamp to prevent duplicates"""
timestamp_file = Path.home() / '.claude' / 'skills' / 'reflect' / '.state' / 'last-reflection.timestamp'
try:
with open(timestamp_file, 'w') as f:
f.write(datetime.now().isoformat())
except Exception as e:
print(f"Warning: Could not update timestamp: {e}")
if __name__ == '__main__':
try:
sys.exit(main())
except KeyboardInterrupt:
print("\n\nReflection cancelled by user")
sys.exit(1)
except Exception as e:
print(f"\nβ Unexpected error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 469k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why β repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" β or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself β your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |