Search docs

Concepts

Safe repository discovery

Learn how repository inventory bounds file discovery.

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).

python
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 raise InspectionError(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_skipped informational diagnostics. Windows junctions are also skipped.
  • Nested directory traversal is sorted by name; output files, directories, and skipped are 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 .gitignore parser: files such as .spawn/meta.json and configuration under .github remain visible to evidence-based analyzers.
  • With default exclusions, discovery also prunes literal top-level directories listed in .git/info/exclude when 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 Diagnostic including a relative path. Deliberate directory exclusions appear in skipped without diagnostics, to avoid giving every normal repository a PARTIAL status 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 yields discovery.symlink_race, including Linux systems where O_DIRECTORY reports ENOTDIR rather than ELOOP. 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
ESC