Check semantic extraction cache for a list of absolute file paths. Returns (cached_nodes, cached_edges, cached_hyperedges, uncached_files). Uncached files need Claude extraction; cached files are merged directly. ``mode`` selects the cache namespace: ``None`` (the default) reads ``
(
files: list[str],
root: Path = Path("."),
mode: str | None = None,
prompt: "str | Path | None" = None,
prompt_file: "str | Path | None" = None,
cache_root: "Path | None" = None,
)
| 1958 | |
| 1959 | |
| 1960 | def check_semantic_cache( |
| 1961 | files: list[str], |
| 1962 | root: Path = Path("."), |
| 1963 | mode: str | None = None, |
| 1964 | prompt: "str | Path | None" = None, |
| 1965 | prompt_file: "str | Path | None" = None, |
| 1966 | cache_root: "Path | None" = None, |
| 1967 | ) -> tuple[list[dict], list[dict], list[dict], list[str]]: |
| 1968 | """Check semantic extraction cache for a list of absolute file paths. |
| 1969 | |
| 1970 | Returns (cached_nodes, cached_edges, cached_hyperedges, uncached_files). |
| 1971 | Uncached files need Claude extraction; cached files are merged directly. |
| 1972 | |
| 1973 | ``mode`` selects the cache namespace: ``None`` (the default) reads |
| 1974 | ``cache/semantic/`` — byte-identical to the historical behavior, so |
| 1975 | existing callers that omit it (including older installed skill flows) |
| 1976 | are unaffected. A non-None mode (e.g. ``"deep"``) reads |
| 1977 | ``cache/semantic-{mode}/`` instead, so deep-mode results never shadow |
| 1978 | (or get shadowed by) standard-mode entries for the same content (#1894). |
| 1979 | |
| 1980 | ``prompt`` is the extraction prompt this run will use for the uncached |
| 1981 | files — the prompt text (Python path) or a Path to the prompt file the |
| 1982 | agent loaded (skill path, ``references/extraction-spec.md``). Supplying it |
| 1983 | restricts hits to entries produced by that same prompt, so an upgrade that |
| 1984 | changed the prompt re-extracts instead of replaying the older vintage |
| 1985 | (#1939). Entries written before fingerprinting existed still hit — their |
| 1986 | vintage is unknowable and dropping them would re-bill a whole corpus — but |
| 1987 | a warning reports how many were served. Omitting ``prompt`` keeps the |
| 1988 | historical behavior for existing callers. |
| 1989 | |
| 1990 | ``cache_root`` decouples *where* the cache is read from the key-anchor |
| 1991 | ``root``, mirroring :func:`load_cached` and :func:`save_semantic_cache` |
| 1992 | (#1774 / #1990). With ``--out``, pass the corpus as ``root`` (so content-hash |
| 1993 | keys and relative-path resolution stay anchored to the source tree) and the |
| 1994 | output directory as ``cache_root``. Omitting it keeps ``root`` for both. |
| 1995 | """ |
| 1996 | global _legacy_semantic_hits |
| 1997 | kind = "semantic" if mode is None else f"semantic-{mode}" |
| 1998 | cached_nodes: list[dict] = [] |
| 1999 | cached_edges: list[dict] = [] |
| 2000 | cached_hyperedges: list[dict] = [] |
| 2001 | uncached: list[str] = [] |
| 2002 | legacy_before = _legacy_semantic_hits |
| 2003 | corrupt_before = _corrupt_cache_entries |
| 2004 | |
| 2005 | for fpath in files: |
| 2006 | p = Path(fpath) |
| 2007 | if not p.is_absolute(): |
| 2008 | p = Path(root) / p |
| 2009 | result = load_cached(p, root, kind=kind, cache_root=cache_root, |
| 2010 | prompt=prompt, prompt_file=prompt_file) |
| 2011 | if result is not None: |
| 2012 | cached_nodes.extend(result.get("nodes", [])) |
| 2013 | cached_edges.extend(result.get("edges", [])) |
| 2014 | cached_hyperedges.extend(result.get("hyperedges", [])) |
| 2015 | else: |
| 2016 | uncached.append(fpath) |
| 2017 |