#!/bin/bash
# PostToolUse hook for the Section 10 capstone.
# Appends one line to outputs/run-log.md whenever Claude writes
# or edits a file under outputs/. Avoids logging itself.
set -e

input=$(cat)

tool=$(printf '%s' "$input" | sed -n 's/.*"tool_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')
path=$(printf '%s' "$input" | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')

# Only log writes/edits to files under outputs/, and never log run-log.md itself.
[ -z "$path" ] && exit 0
case "$path" in
  *outputs/run-log.md) exit 0 ;;
  *outputs/*) ;;
  *) exit 0 ;;
esac

mkdir -p outputs
ts=$(date "+%Y-%m-%d %H:%M:%S")
printf '[%s] %s %s\n' "$ts" "$tool" "$path" >> outputs/run-log.md
