#!/usr/bin/env bash
# Tier 3 — when a feature.manifest.ts is edited, remind the agent to surface
# drift and follow manifest-first ordering. Non-blocking (stderr exit 0 is
# visible in transcript; we don't want this to kill the agent's flow).

set -euo pipefail

input=$(cat)
file_path=$(printf '%s' "$input" | jq -r '.tool_input.file_path // ""')

if [[ "$file_path" != *"feature.manifest.ts" ]]; then
  exit 0
fi

feature=$(echo "$file_path" | sed -nE 's|.*packages/([^/]+)/src/feature\.manifest\.ts$|\1|p')

cat >&2 <<EOF
[post-manifest-edit] feature.manifest.ts changed (${feature:-unknown feature})

Manifest-first ordering reminder:
  (1) manifest entry      ← you just did this
  (2) contracts           — xInputSchema, xOutputSchema, IXUseCase
  (3) tests (red)         — colocated *.test.ts
  (4) implementation      — use-case + controller + DI binding

Surface drift now:
  pnpm --filter @repo/${feature:-<feature>} test typecheck lint
  pnpm conformance
EOF

exit 0
