---
description: Check task folder for open tasks and output directly if found
allowed-tools: Bash
---

# Employee Heartbeat — Task Check

This command is designed for `/loop`. It scans the employee's task folder and outputs task info directly when open tasks exist.

```bash
# Resolve coordinator and detect agent from EXE_SESSION_NAME env var or tmux session name
COORDINATOR=$(node -e "const fs=require('fs'), os=require('os'), path=require('path'); try { const r=JSON.parse(fs.readFileSync(path.join(os.homedir(),'.exe-os','exe-employees.json'),'utf8')); const c=r.find(e => String(e.role||'').toLowerCase()==='coo'); console.log(c?.name || 'exe'); } catch { console.log('exe'); }" 2>/dev/null)
SESSION_KEY="${EXE_SESSION_NAME:-$(tmux display-message -p '#{session_name}' 2>/dev/null)}"
if [ -z "$SESSION_KEY" ]; then
  AGENT="UNKNOWN"
elif [[ "$SESSION_KEY" == *-* ]]; then
  AGENT=$(echo "${SESSION_KEY%%-*}" | sed -E 's/[0-9]+$//')
else
  AGENT="$COORDINATOR"
fi

# Skip if no agent or coordinator/default
if [ "$AGENT" = "UNKNOWN" ] || [ "$AGENT" = "$COORDINATOR" ] || [ "$AGENT" = "exe" ] || [ "$AGENT" = "default" ]; then
  exit 0
fi

# Idle detection: stay silent if agent had activity within last 120 seconds
ACTIVITY_FILE="${HOME}/.exe-os/session-cache/last-activity-${SESSION_KEY}.json"
if [ -f "$ACTIVITY_FILE" ]; then
  IDLE_CHECK=$(SESSION_KEY="$SESSION_KEY" node -e "
    try {
      const a = JSON.parse(require('fs').readFileSync(process.env.HOME+'/.exe-os/session-cache/last-activity-'+process.env.SESSION_KEY+'.json','utf8'));
      const diff = Date.now() - a.timestamp;
      console.log(diff < 120000 ? 'busy' : 'idle');
    } catch { console.log('idle'); }
  " 2>/dev/null)
  if [ "$IDLE_CHECK" = "busy" ]; then
    exit 0
  fi
fi

# Use canonical scanner — single source of truth for task status detection
node "$(npm root -g)/@askexenow/exe-os/dist/bin/scan-tasks.js" "exe/$AGENT" --format=mandatory 2>/dev/null
```

**If the script outputs task info:** read the task file and begin working immediately. Do not ask what to do.
**If the script outputs nothing:** no tasks — stay silent.
