mirror of
https://github.com/harivansh-afk/claude-continual-learning.git
synced 2026-04-18 13:04:01 +00:00
fix hook
This commit is contained in:
parent
5d04193911
commit
8d87270023
1 changed files with 46 additions and 7 deletions
|
|
@ -5,12 +5,20 @@
|
||||||
# It spawns a background process to analyze the session and update learnings.
|
# It spawns a background process to analyze the session and update learnings.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
LOG_FILE="${CLAUDE_PROJECT_DIR:-.}/.claude/hooks/session-end.log"
|
||||||
|
|
||||||
|
log() {
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
# Read hook input from stdin (JSON with session info)
|
# Read hook input from stdin (JSON with session info)
|
||||||
INPUT=$(cat)
|
INPUT=$(cat)
|
||||||
|
|
||||||
|
log "Hook triggered with input: $INPUT"
|
||||||
|
|
||||||
# Extract transcript path using jq (required dependency)
|
# Extract transcript path using jq (required dependency)
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &> /dev/null; then
|
||||||
# jq not available, skip silently
|
log "ERROR: jq not available"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -18,30 +26,61 @@ TRANSCRIPT=$(echo "$INPUT" | jq -r '.transcript_path // empty')
|
||||||
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty')
|
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty')
|
||||||
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
|
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
|
||||||
|
|
||||||
|
log "Transcript: $TRANSCRIPT"
|
||||||
|
log "Session ID: $SESSION_ID"
|
||||||
|
log "Project dir: $PROJECT_DIR"
|
||||||
|
|
||||||
# Validate transcript exists
|
# Validate transcript exists
|
||||||
if [ -z "$TRANSCRIPT" ] || [ ! -f "$TRANSCRIPT" ]; then
|
if [ -z "$TRANSCRIPT" ]; then
|
||||||
|
log "ERROR: No transcript path in input"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$TRANSCRIPT" ]; then
|
||||||
|
log "ERROR: Transcript file does not exist: $TRANSCRIPT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only run retrospective if session was substantial (more than 10 lines)
|
# Only run retrospective if session was substantial (more than 10 lines)
|
||||||
LINE_COUNT=$(wc -l < "$TRANSCRIPT" 2>/dev/null || echo "0")
|
LINE_COUNT=$(wc -l < "$TRANSCRIPT" 2>/dev/null || echo "0")
|
||||||
|
log "Transcript line count: $LINE_COUNT"
|
||||||
if [ "$LINE_COUNT" -lt 10 ]; then
|
if [ "$LINE_COUNT" -lt 10 ]; then
|
||||||
|
log "Session too short, skipping retrospective"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if learnings.md exists (system is properly set up)
|
# Check if learnings.md exists (system is properly set up)
|
||||||
LEARNINGS_FILE="$PROJECT_DIR/.claude/skills/codebase-agent/learnings.md"
|
LEARNINGS_FILE="$PROJECT_DIR/.claude/skills/codebase-agent/learnings.md"
|
||||||
if [ ! -f "$LEARNINGS_FILE" ]; then
|
if [ ! -f "$LEARNINGS_FILE" ]; then
|
||||||
|
log "ERROR: learnings.md not found at $LEARNINGS_FILE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run retrospective in background using claude -p
|
log "Starting retrospective analysis in background..."
|
||||||
# This uses Claude Code's existing authentication
|
|
||||||
|
# Run retrospective in background using claude with skill invocation
|
||||||
|
# Use nohup to ensure the process survives after hook exits
|
||||||
|
# cd to project dir since --cwd is not a valid flag
|
||||||
(
|
(
|
||||||
claude -p "Run /retrospective to analyze the session and extract learnings. The session transcript is at: $TRANSCRIPT" \
|
cd "$PROJECT_DIR" && nohup claude --dangerously-skip-permissions -p "$(cat <<EOF
|
||||||
--cwd "$PROJECT_DIR" \
|
Analyze the coding session that just ended and extract valuable learnings.
|
||||||
2>/dev/null
|
|
||||||
|
Session transcript is at: $TRANSCRIPT
|
||||||
|
|
||||||
|
Your task:
|
||||||
|
1. Read the transcript file to understand what happened in the session
|
||||||
|
2. Identify patterns (what worked), failures (what to avoid), edge cases, and technology insights
|
||||||
|
3. Read the current learnings file at: $LEARNINGS_FILE
|
||||||
|
4. Add any NEW valuable learnings to the appropriate sections - skip generic knowledge
|
||||||
|
5. Use the format: ### Title, then bullet points for Context, Learning, Example (optional), Session date
|
||||||
|
|
||||||
|
Be selective - only add genuinely useful, project-specific insights that will help future sessions.
|
||||||
|
EOF
|
||||||
|
)" \
|
||||||
|
>> "$LOG_FILE" 2>&1 &
|
||||||
) &
|
) &
|
||||||
|
|
||||||
|
log "Background process spawned"
|
||||||
|
|
||||||
# Exit immediately - don't wait for background process
|
# Exit immediately - don't wait for background process
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue