INNER CODE UNIT · Python

_walk_workspace_files

ApodexAI/FrontierAgent · apodex/tui/app.py:169

def _walk_workspace_files(root: Path, limit: int) -> tuple[str, ...]:
    """Index files under ``root`` for ``@`` completion. Runs off the UI thread.

    ``os.scandir`` rather than ``os.walk`` + ``Path.is_symlink``: the dirent
    already carries the entry type, so skipping links costs no extra ``lstat``
    per file. That is the difference between a large checkout indexing in
    milliseconds and the indexer spending a syscall on every file twice.
    """
    # ``rstrip`` rather than ``len(str(root)) + 1``: the filesystem root prints
    # as "/", which already carries its separator, so the naive +1 ate the
    # first character of every indexed path under ``--cwd /``.
    base = str(root).rstrip(os.sep)
    prefix_length = len(base) + 1
    found: list[str] = []
    stack: list[str] = [str(root)]
    while stack and len(found) < limit:
        try:
            entries = list(os.scandir(stack.pop()))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…