#!/usr/bin/env bash
# Meerkat TaskPanel SessionStart hook — generated by `install.sh --target claude`.
#
# Runs at the start of every Claude Code session: it starts the board (taskd
# autostarts on first use), lists this agent's claimable cards, and restates the
# eight shared rules. Non-fatal on purpose — a cold board or a missing CLI must
# never block the session.
set -u

name="${TASKCTL_AGENT:-{{AGENT}}}"
shim="{{SHIM}}"

echo
echo "== Meerkat TaskPanel =="

if [ -x "$shim" ] && command -v node >/dev/null 2>&1; then
  echo "-- claimable for $name --"
  "$shim" issue candidates --assignee "$name" 2>&1 || true
else
  echo "-- claimable for $name --"
  # PATH-independent fallback: the shim lives under the user's home and is *not* on
  # PATH, so a bare `taskctl` here would be a command the user cannot run. Name
  # the shim by absolute path, and offer the repo CLI for the case where the shim
  # is missing but node is present.
  echo "(taskctl shim or node not found — try: $shim issue candidates --assignee $name)"
  echo "  or: node {{REPO}}/src/cli/index.mjs --actor-kind claude --agent $name issue candidates --assignee $name"
fi

echo
echo "-- the eight rules --"
cat <<'RULES'
1. claim-first — read `issue candidates --assignee <me>`, then take exactly one with `issue move <ref> in_progress`. A supervisor handoff already holds the claim: obey the handoff and heartbeat; do not re-claim
2. claim only what is yours — never someone else's card, a `backlog` card, an `epic`, or one with an unfinished `depends_on` blocker
3. one card at a time — hold at most one claimed card
4. keep the heartbeat fresh — pulse it with `issue heartbeat <ref>` every ≤10 minutes; never leave a card idle in `in_progress`
5. deliver with a report — the delivery gate refuses `in_review` without a report for the current round
6. self-review is not acceptance — stop at `in_review`; the card's `acceptance_mode` names the closer (the loop after an APPROVE, a person, or the deliverer for `off`)
7. never preempt on conflict — on `VERSION_CONFLICT` or staleness re-read once, never blind-retry
8. stay traceable — carry the session id on every write
RULES
