Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)
find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -print -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print
I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity
find /top/dir -type d \
-exec shbash -c '
echo "Considering $*";
z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit);
[[[ -n "$z" ]]] && echo "$z";
echo[[ "$z" | grep -F=~ "Found flag file" >/dev/null]] || ({ echo "No flag found"; exit 11; )}
' _ {} \; \
-printf "Pruning tree\n" -prune \
-o \
-type f -name '*proj*.tgz' -print
The real solution requires the non-POSIX find -maxdepth. The debugging version also requires non-POSIX find -printf. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.