INNER CODE UNIT · Python

_shared_completion

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

def _shared_completion(candidates: list[str], fragment: str) -> str:
    """Longest prefix every candidate shares — never shorter than ``fragment``.

    ``@`` matching is case-insensitive, so the shared prefix has to be measured
    on the folded spellings. Measuring it on the raw ones returns "" for a set
    like ``["README.md", "requirements.txt"]``, which replaced a typed ``@re``
    with a bare ``@`` — deleting the user's input instead of completing it.
    """
    if not candidates:
        return fragment
    shared = commonprefix([name.casefold() for name in candidates])
    if len(shared) <= len(fragment):
        return fragment
    # Case folding can change length (``ß`` → ``ss``), so the offset is only
    # trustworthy once it round-trips against every candidate.
    completed = candidates[0][:len(shared)]
    folded = completed.casefold()
    if not all(name.casefold().startswith(folded) for name in candidates):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…