#!/bin/sh
# epic TaskStart hook for Cline
#
# Cline calls this when a new task begins.
# Restores context from the previous session so the harness is warm.
# stdin: JSON with task metadata
# stdout: JSON {"cancel": false}

set -u

BINARY=""
if command -v epic >/dev/null 2>&1; then
  BINARY="epic"
elif [ -x "$HOME/.cargo/bin/epic" ]; then
  BINARY="$HOME/.cargo/bin/epic"
fi

if [ -n "$BINARY" ]; then
  HOOK_INPUT='{"tool_name":"TaskStart","tool_input":{},"tool_output":{},"conversation_summary":null,"pending_tasks":[],"context_usage":null}'
  printf '%s' "$HOOK_INPUT" | "$BINARY" resume >/dev/null 2>&1
else
  cat >/dev/null
fi

printf '{"cancel":false}'
