This is a bit late, but: it seems you can detect bundles using the mdls command. Specifically, the (multi-line) output of:
mdls -name kMDItemContentTypeTree /Path/To/Directory
Will contain the string
"com.apple.package"
(including the quotation marks, at least as of Lion) somewhere if the directory is a package. If the package is also a bundle, the output will also contain
"com.apple.bundle"
and, last but not least, if it is specifically an application bundle, the output will also contain
"com.apple.application-bundle"
(That's according to some very limited testing, but from what Apple's documentation on Uniform Type Identifiers, and the man page for mdls, this should hold true. And for the items I tested, this was true for non-Apple-provided bundles as well, which is what you would expect given the purpose of UTIs.)