Implementation: spawn.inspection.discovery. This module performs filesystem
inventory only. It does not parse manifests, import project modules, execute
commands, access the network, or write to an inspected project. The inventory
uses the existing DiscoveryInventory and Diagnostic types from the #53
contract (called “Issue #1” in some v1.1.0 planning instructions).
from spawn.inspection.discovery import discover_repository, validate_inspection_root
inventory = discover_repository("./existing-project")
# or: discover_repository(validate_inspection_root("./existing-project"))- Roots are resolved to absolute directories and checked with
scandir. Invalid or inaccessible roots raiseInspectionError(exit_code=7). An explicitly supplied root symlink is resolved once; descendants are not. - Entries are examined without following symlinks; neither file nor directory
symlinks are included. Broken links, self-loops, and out-of-root links are
skipped with
discovery.symlink_skippedinformational diagnostics. Windows junctions are also skipped. - Nested directory traversal is sorted by name; output
files,directories, andskippedare sorted relative POSIX-style paths (a/b.py). Entries of excluded directories are not visited. The root itself is not listed. Spaces, Unicode, and punctuation in names are preserved. On POSIX, a literal backslash in a filename remains a backslash character, not a separator. The implementation uses an explicit work stack rather than recursive Python calls; very deep trees are still subject to host filesystem path limits. - Default excluded directory basenames, at any depth (case-insensitive):
.git,.hg,.svn,node_modules,vendor,dist,build,coverage,htmlcov,target,.next,.nuxt,.cache,.turbo,__pycache__,.venv,venv,env,.uv,.tox,.nox,.pytest_cache,.ruff_cache,.mypy_cache. These include Spawn's own ignored virtual-environment, test, build, and cache directories, plus common third-party dependency/build directories. This is not a full.gitignoreparser: files such as.spawn/meta.jsonand configuration under.githubremain visible to evidence-based analyzers. - With default exclusions, discovery also prunes literal top-level directories
listed in
.git/info/excludewhen a supported Git index shows no tracked paths inside them. A negation, unreadable metadata, or an unsupported index leaves this optimization disabled. Discovery does not run Git. - Custom exclusions replace the defaults:
discover_repository(path, excluded_directories={"private", "target"}). Pass()to include the default-excluded directories; a single string such as"private"is accepted as shorthand. Only single directory basenames are supported. - Skipped symlinks, unsupported entry types, missing entries and permission /
IO errors are associated with a
Diagnosticincluding a relativepath. Deliberate directory exclusions appear inskippedwithout diagnostics, to avoid giving every normal repository aPARTIALstatus just for.git. Analyzers open ordinary inventory files through the bounded repository reader. - On POSIX systems with supported dirfd operations, scanning starts from an
anchored root descriptor; nested directories are re-opened relative to it
with
O_NOFOLLOW. The bounded reader also opens each directory component and the final file without following links. On Windows, local drive paths use handle-relative opens of one component at a time, rejecting reparse points on the opened handle. Directory enumeration uses that same type of handle. If the filesystem or platform cannot provide these operations, inspection fails closed. A symlink swap detected during descriptor-based descent yieldsdiscovery.symlink_race, including Linux systems whereO_DIRECTORYreportsENOTDIRrather thanELOOP. As with any filesystem walk, concurrent mutations can change results. File symlink targets are never opened to check their permissions or contents, including inaccessible targets.
Diagnostic codes#
| Code | Meaning |
|---|---|
discovery.symlink_skipped |
Symbolic link or junction deliberately not followed |
discovery.permission_denied |
Entry cannot be accessed because of permissions |
discovery.entry_disappeared |
Entry removed or ceased to be a directory during scan |
discovery.symlink_race |
Directory became a symbolic link while descending |
discovery.filesystem_error |
Other recoverable filesystem problem |
discovery.unsupported_entry_type |
Socket, FIFO, device or other non-file/dir entry |