#!/usr/bin/env bash
# SWE-agent ACI command: find_file <name> [dir]
#
# Routes the classic SWE-agent "find files by name" slot to `prism find <name>`
# (files by name/glob). The bundle is the agent's FRONT DOOR for file lookup,
# so on any prism failure we FAIL OPEN to the real `find` (spec §10 Step 4) —
# the agent never loses the lookup capability mid-trajectory.
#
# `prism find` scopes to the repo, so [dir] only narrows the real-find fallback.
#
# No `set -e`: a non-zero prism must fall through to the real tool, not abort.
set -u

name=${1:-}
dir=${2:-.}

# Prefer prism when reachable AND it succeeds; otherwise fall back to find.
if command -v prism >/dev/null 2>&1; then
  if prism find "$name"; then
    exit 0
  fi
fi

# Fail-open: real find by name (glob honored by -name) mirrors classic ACI.
exec find "$dir" -name "$name"
