Skip to content

API Reference parrot.knowledge.wiki.symbols

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

parrot.knowledge.wiki.symbols

View source

Symbol plane models and id grammar for the wiki structural backend.

This module is the foundation contract for FEAT-498 (ast-grep structural plane): every extraction, storage and service layer downstream shares the :class:SymbolRecord / :class:SymbolRef / :class:StructuralOutline models and the sym:<rel>#<qualname>[~n] id grammar defined here.

Nothing in this module reads the filesystem or imports anything beyond pydantic and the standard library, to avoid import cycles with languages/base.py and repo_scan.py (both of which import from here).

Class StructuralOutline

Result of the ast-grep structural extraction seam for one file.

Fields:

Field Type Default Description
summary str '' Short summary line for the page.
symbols list[SymbolRecord] Extracted symbol records.
refs list[SymbolRef] Extracted unresolved references.
imports list[str] Raw import specifiers — same contract as :attr:parrot.knowledge.wiki.languages.base.LanguageOutline.imports, resolved later by :meth:LanguageScanner.resolve_import.

Class SymbolKind

Kind of a symbol extracted from a source file.

Mirrors the design's §4.4 symbol table across the five supported languages (Python, TypeScript/JavaScript, PHP, Rust, Perl), plus Svelte single-file components (FEAT-609).

Class SymbolRecord

A single extracted symbol (class, function, method, ...).

Fields:

Field Type Default Description
rel_path str POSIX path relative to the repository root.
language str Scanner name that produced this record (python, javascript, php, rust, perl).
kind SymbolKind Symbol kind.
name str Local identifier as written in the source.
qualname str Fully-qualified name, e.g. "UserService.get_user" or "App\Models\User::getFullName".
parent str | None None Container qualname, or None for top-level symbols.
signature str '' Parameters (and return type) as written in the source.
doc str '' First line of the symbol's documentation/docstring.
exported bool False Whether the symbol is exported/public (export, pub, public).
is_async bool False Whether the symbol is declared async.
start_line int 1-based inclusive start line.
end_line int 1-based inclusive end line.
start_byte int Byte offset of the symbol's first byte in the file.
end_byte int Byte offset just past the symbol's last byte.
node_kind str '' The tree-sitter/ast-grep node kind that produced this record, or "" when derived from Python's stdlib ast.
decorators list[str] Decorator/attribute strings attached to the symbol.
content_hash str SHA-1 hex digest of the symbol's source text.
depth int 1 Nesting depth — 1 for top-level, 2 for direct members, etc.
namespace str | None None Runtime-only provenance (never persisted, excluded from model_dump) set by FederatedWikiStore on rows read from a foreign namespace (FEAT-609).

Class SymbolRef

An unresolved reference from one symbol to another symbol or name.

Fields:

Field Type Default Description
src_qualname str Qualname of the symbol that holds the reference.
rel str Kind of reference — "calls", "extends", "implements" or "uses".
target_text str The reference target as written in the source (e.g. "BaseService", "helper", "self.repo.get").
line int 1-based line number where the reference occurs.

Function parse_sym_id

Invert :func:sym_concept_id.

parse_sym_id(concept_id: str) -> tuple[str, str, int]

Parameter Type Default Description
concept_id str A sym:<rel_path>#<qualname>[~<ordinal>] id.

Returns: tuple[str, str, int] — (rel_path, qualname, ordinal) — ordinal is 1 when no ~<n> suffix is present.

Raises:

  • ValueError — If concept_id does not start with "sym:" or has no # separator.

Function sha1_of_text

Compute the SHA-1 hex digest of UTF-8 encoded text.

Same digest family as :meth:parrot.knowledge.wiki.sources.SourceCollectionManager._compute_hash, but computed in-memory over already-decoded text instead of a file path.

sha1_of_text(text: str) -> str

Parameter Type Default Description
text str Text to hash.

Returns: str — Lowercase hex SHA-1 digest.

Function sym_concept_id

Build a sym: concept id.

sym_concept_id(rel_path: str, qualname: str, ordinal: int = 1) -> str

Parameter Type Default Description
rel_path str POSIX path relative to the repository root.
qualname str Fully-qualified symbol name.
ordinal int 1 1-based source-order occurrence of qualname within rel_path. The first occurrence (ordinal <= 1) keeps the clean id; repeats get a ~<ordinal> suffix.

Returns: str — "sym:<rel_path>#<qualname>" for the first occurrence, or "sym:<rel_path>#<qualname>~<ordinal>" for repeats.

Function symbol_from_page

Decode a sym: page dict back into a :class:SymbolRecord.

Best-effort inverse of :func:symbol_to_page_fields, used by the page-based default implementations of symbols_for/ find_symbols/search_symbols_fts (ArangoDB, InMemory — SQLite answers from its native symbols table instead). Fields the rendered markdown does not carry precisely (start_byte, end_byte, is_async, decorators, node_kind, depth) degrade to their model defaults rather than raising — this is the intentionally-lossy path; only SQLite's native table is full-fidelity.

symbol_from_page(page: dict[str, Any]) -> SymbolRecord | None

Parameter Type Default Description
page dict[str, Any] A page dict as returned by get_page/list_pages for a category == "symbol" row (node_id holds rel_path, title holds qualname, summary holds doc).

Returns: SymbolRecord | None — A reconstructed :class:SymbolRecord, or None when page is not a well-formed sym: page (wrong category, or a body that does not match the expected section layout).

Function symbol_to_page_fields

Build the sym: page's title/summary/body fields.

Used by the ingest pipeline (repo_scan.build_symbol_pages, TASK-2748) to construct the :class:~parrot.knowledge.wiki.store.WikiPageRecord for one symbol, and by the page-based default store methods (:func:symbol_from_page) to decode it back.

The body's structure (spec §7 "sym: page body") is a fixed sequence of "\n\n"-separated sections in this exact order — kept stable on purpose so :func:symbol_from_page can invert it positionally rather than by fragile regex matching of the rendered markdown:

  1. # <qualname>
  2. **kind** <kind> · **language** <language> · **file** <rel>:L<start>-<end> · **exported** <bool>
  3. <signature> (may be empty)
  4. <doc> (may be empty)
  5. ## Source (excerpt)
  6. <source excerpt, capped at 2000 chars>

symbol_to_page_fields(record: SymbolRecord, *, source_excerpt: str = '') -> dict[str, str]

Parameter Type Default Description
record SymbolRecord Symbol to render.
source_excerpt str '' Raw source text of the symbol's node; capped and appended as the trailing "Source (excerpt)" section. Empty when the caller does not have (or want to store) source text.

Returns: dict[str, str] — {"title": qualname, "summary": doc, "body": <rendered body>}.

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