Skip to content

API Reference parrot.tools.repo.graph_search

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.repo.graph_search

View source

Worktree-aware resolution and opening of the wiki retrieval plane.

Backs the graph-backed search_code / related_code tools (spec §3 Module 4, §8 Q5). The plane is rooted at a checkout and can be large, so a per-worktree build is a non-starter — when repo_root is a git worktree, this module resolves the checkout the plane should be shared from instead of rebuilding it.

Both functions are module-level async defs, not toolkit methods — AbstractToolkit._generate_tools() (tools/toolkit.py:537) turns every public async def method into an LLM-callable tool, so this plumbing stays outside the class entirely.

This module never builds the plane (spec §1 Non-Goals: "this toolkit is a pure consumer") and never raises: any failure degrades to a (None, reason) pair or, for resolve_plane_root, to repo_root unchanged.

Alias RepoSearchHit

Re-exported from parrot.tools.repo.models.RepoSearchHit.

Attribute logger

Function map_neighbor_hit

Map one store.neighbors() edge dict onto RepoSearchHit.

map_neighbor_hit(edge: dict[str, Any]) -> RepoSearchHit

Parameter Type Default Description
edge dict[str, Any] A dict as returned by BaseWikiStore.neighbors() — carries concept_id, rel, direction, and — when the target is a known page — title/summary/token_count.

Returns: RepoSearchHit — The equivalent RepoSearchHit. No score is available from a neighbor edge, so score is always 0.0.

Function map_search_hit

Map a WikiSearchResult onto the toolkit's RepoSearchHit shape.

Field names do NOT line up between the two models: page_id comes from node_id (not page_id, which does not exist on the search result), path comes from title, and summary comes from snippet (not summary, which likewise does not exist there). outline is always empty — an API outline needs a page read, which a search result does not carry.

map_search_hit(result: Any) -> RepoSearchHit

Parameter Type Default Description
result Any A WikiSearchResult-shaped object (duck-typed via Any so this module has no import-time dependency on the wiki package).

Returns: RepoSearchHit — The equivalent RepoSearchHit.

Function open_plane

Open the wiki retrieval plane for repo_root, worktree-aware.

NEVER builds the plane — spec §1 Non-Goals. When the plane is absent, unbuilt, or fails to open, returns (None, <reason>) so the caller can degrade with a reason the model can read.

open_plane(repo_root: Path) -> tuple[Any | None, str]

Parameter Type Default Description
repo_root Path The checkout the toolkit is confined to.

Returns: tuple[Any | None, str] — (store, wiki_name) on success; (None, reason) otherwise.

Function resolve_plane_root

Return the checkout whose wiki plane should be queried.

For a git worktree this is the MAIN checkout, so the (large) plane is shared rather than rebuilt per worktree — spec §8 Q5. For a plain checkout, and for anything that is not a git repository at all, this is repo_root itself.

Never raises: a missing git, a non-repo directory, or an unexpected git version all fall back to repo_root.

resolve_plane_root(repo_root: Path) -> Path

Parameter Type Default Description
repo_root Path The checkout the toolkit is confined to.

Returns: Path — The directory to resolve the wiki project config against.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally