#!/bin/bash
# PostToolUse hook - capture noteworthy tool executions

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

cd "$PROJECT_ROOT"

# Get tool name and arguments from environment
TOOL_NAME="${CLAUDE_TOOL_NAME:-}"
TOOL_ARGS="${CLAUDE_TOOL_ARGS:-}"

# Only capture for file-modifying tools
case "$TOOL_NAME" in
  Edit|Write|NotebookEdit)
    IMPORTANCE=7
    TAGS="auto-capture,write"
    ;;
  Bash|PowerShell)
    IMPORTANCE=6
    TAGS="auto-capture,shell"
    ;;
  *)
    exit 0
    ;;
esac

# Capture to project memory
npx tsx -e "
import { saveMemory } from './src/index.js';

const content = 'Tool used: ${TOOL_NAME}';
const filepath = saveMemory('project', content, 'pattern', undefined, {
  importance: ${IMPORTANCE},
  tags: '${TAGS}'.split(',')
});

console.log('captured:', filepath);
" 2>/dev/null || true