indexlocate.py

clew/indexlocate.py

Find the index already built for a repository, without building one.

find_index

Path | None clew.indexlocate.find_index(Path repo_root, str|None explicit=None)

The existing index for a repository.

clew/indexlocate.py:24

Source · 9 lines
def find_index(repo_root: Path, explicit: str | None = None) -> Path | None:
    """@brief Find the index. @return Path or None."""
    if explicit:
        candidate = Path(explicit).expanduser().resolve()
        return candidate if candidate.is_file() else None
    local = repo_root / "clew.db"
    return registered_index(repo_root) or (local if local.is_file() else None)

Activity · 5 steps
lines 26–26◇ if explicitlines 27–27candidate = Path(explicit).expanduser().resolve()lines 28–28return candidate if candidate.is_file() else Nonelines 29–29local = repo_root / "clew.db"lines 30–30return registered_index(repo_root) or (local if local.is_file() else None)

Requirements

REQ-DDB-GUARD-010

Flows

registered_index

Path | None clew.indexlocate.registered_index(Path repo_root)

The database the MCP target registry has allocated for a repository.

clew/indexlocate.py:38

Show on the map →

Called by find_index

Calls none

Source · 18 lines
def registered_index(repo_root: Path) -> Path | None:
    """IMPORTED LAZILY AND GUARDED: the registry lives under `mcp_server`, whose package import
    pulls the optional MCP SDK. A core-only install still runs; it just cannot find an
    agent-built database.

    @brief Registered database.
    @return Path or None.
    """
    try:
        from .mcp_server.state import TargetRegistry
    except ImportError:
        return None
    wanted = str(Path(repo_root).expanduser().resolve())
    for target in TargetRegistry().targets():
        path = Path(target.db_path)
        if str(Path(target.repo_path).expanduser().resolve()) == wanted and path.is_file():
            return path
    return None

1 more lines, not shown

Activity · 10 steps
lines 46–46trylines 47–47from .mcp_server.state import TargetRegistrylines 48–48except ImportErrorlines 49–49return Nonelines 50–50wanted = str(Path(repo_root).expanduser().resolve())lines 51–51◇ for target in TargetRegistry().targets()lines 52–52path = Path(target.db_path)lines 53–53◇ if str(Path(target.repo_path).expanduser().resolve()) == wanted and path.is_file()lines 54–54return pathlines 55–55return None

Flows