Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / function

describe_repository

codeintel.describe.describe_repository

PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.

PHAROS at 975a38dMIT license

Around this symbol

Search all symbols

Loading

Calls (4)
SymbolFileResolved by
_candidatesdescribe.pysame file
DescribeStatsdescribe.pysame file
groundeddescribe.pysame file
with_descriptiontext.pythrough an import
Inside (1)
SymbolFileResolved by
describedescribe.pysame file
codeintel.describe.describe_repositorybackend/app/codeintel/describe.py, lines 103–162Open source
def describe_repository(db: Session, repository_id, checkout: Path, llm, embedder: Embedder | None, *,                        only_undocumented: bool = True, limit: int | None = None,                        progress: Callable[[str], None] = lambda _msg: None) -> DescribeStats:    """Describe the repository's source functions that have no cached description.    ``checkout`` must be the indexed commit's working tree (the code is read    from it, never fetched). ``llm`` has ``complete(instructions, prompt, schema)``    and an optional ``model`` attribute (see ``app.learning.llm.CodexCLI``).    """    stats = DescribeStats()    todo = _candidates(db, repository_id, only_undocumented, limit)    stats.candidates = len(todo)    files: dict[str, list[str]] = {}    model_name = getattr(llm, "model", None) or "codex"    for start in range(0, len(todo), BATCH):        batch = todo[start:start + BATCH]        issued: dict[str, tuple[DocumentChunk, str, str]] = {}        for i, (chunk, sha) in enumerate(batch, start=1):            path = (chunk.chunk_metadata or {}).get("path", "")            if path not in files:                try:                    files[path] = (checkout / path).read_text(encoding="utf-8", errors="replace").splitlines()                except OSError:                    files[path] = []            code = "\n".join(files[path][(chunk.start_line or 1) - 1:chunk.end_line or 0])[:MAX_CODE_CHARS]            if code.strip():                issued[f"C{start + i}"] = (chunk, sha, code)        if not issued:            continue        prompt = "\n\n".join(f"## {cid} ({chunk.language}, {(chunk.chunk_metadata or {}).get('path')})\n{code}"                             for cid, (chunk, _sha, code) in issued.items())        try:            answer = llm.complete(INSTRUCTIONS, prompt, SCHEMA)        except Exception as exc:  # LLMUnavailable, a bad answer: skip this batch, keep the rest            stats.failed_batches += 1            logger.warning("describe batch failed: %s", exc)            continue        written: list[tuple[DocumentChunk, str]] = []        for item in answer.get("items", []):            if item.get("id") not in issued:                continue            chunk, sha, code = issued.pop(item["id"])            text = " ".join((item.get("description") or "").split())[:MAX_DESCRIPTION_CHARS]            if not text or not grounded(text, code):                stats.rejected += 1                continue            db.merge(ChunkDescription(content_sha=sha, symbol_name=chunk.symbol_name, description=text,                                      model=model_name))            chunk.semantic_summary = with_description(chunk.semantic_summary or "", text)            written.append((chunk, text))            if len(stats.examples) < 5:                stats.examples.append({"symbol": chunk.symbol_name, "description": text})        if written and embedder is not None:            vectors = embedder.embed_documents([c.semantic_summary for c, _ in written])            for (chunk, _), vector in zip(written, vectors, strict=True):                chunk.embedding = vector                chunk.embedding_model = embedder.model_id            stats.reembedded += len(written)        stats.described += len(written)        db.commit()

Shows the first 60 of 63 lines. The rest is on GitHub at this commit.

What the index recorded

Signature
def describe_repository(db: Session, repository_id, checkout: Path, llm, embedder: Embedder | None, *, only_undocumented: bool, limit: int | None, progress: Callable[[str], None]) -> DescribeStats:
File
backend/app/codeintel/describe.py
Lines
103–165
Parser
python-ast
Git blob
9e70d40ab4a4d664b1b0e8b0ac225e7a134fa3f2
Call sites
26 named, 7 resolved, 19 left unlinked
Outside this subset
5 more edges reach code outside the graph shown here

Read it on GitHub at this commit