Skip to content

Search text

search_text

Text renderers for SearchTool dual-format ToolResult.

format_func_line(sym)

Format a function-like symbol as a compact text line.

Source code in packages/axm-ast/src/axm_ast/tools/search_text.py
Python
def format_func_line(sym: dict[str, Any]) -> str:
    """Format a function-like symbol as a compact text line."""
    params = _extract_params_block(sym.get("signature", ""))
    line = f"{sym['name']}{params}"
    ret = sym.get("return_type")
    if ret is not None:
        line += f" -> {ret}"
    return line

format_symbol_line(sym)

Render one symbol dict as a compact text line.

Source code in packages/axm-ast/src/axm_ast/tools/search_text.py
Python
def format_symbol_line(sym: dict[str, Any]) -> str:
    """Render one symbol dict as a compact text line."""
    kind = sym.get("kind", "")
    if kind in _FUNC_KINDS:
        return format_func_line(sym)
    if kind == "class":
        return str(sym["name"])
    return format_variable_line(sym)

format_text_header(*, search_filters, count, suggestion_count=0)

Build the header line for text rendering.

Source code in packages/axm-ast/src/axm_ast/tools/search_text.py
Python
def format_text_header(
    *,
    search_filters: dict[str, Any],
    count: int,
    suggestion_count: int = 0,
) -> str:
    """Build the header line for text rendering."""
    name = search_filters.get("name")
    returns = search_filters.get("returns")
    kind = search_filters.get("kind")
    inherits = search_filters.get("inherits")
    parts: list[str] = []
    if name is not None:
        parts.append(f'name~"{name}"')
    if returns is not None:
        parts.append(f"returns={returns}")
    kind_str = (
        kind if isinstance(kind, str) else (kind.value if kind is not None else None)
    )
    if kind_str is not None:
        parts.append(f"kind={kind_str}")
    if inherits is not None:
        parts.append(f"inherits={inherits}")
    sections = ["ast_search"]
    if parts:
        sections.append(" · ".join(parts))
    hits_part = f"{count} hits"
    if suggestion_count > 0:
        hits_part += f" · {suggestion_count} suggestions"
    sections.append(hits_part)
    return " | ".join(sections)

format_variable_line(sym)

Format a variable symbol as a compact text line.

Source code in packages/axm-ast/src/axm_ast/tools/search_text.py
Python
def format_variable_line(sym: dict[str, Any]) -> str:
    """Format a variable symbol as a compact text line."""
    name = sym["name"]
    ann = sym.get("annotation")
    val = sym.get("value_repr")
    if ann and val:
        return f"{name}: {ann} = {val}"
    if ann:
        return f"{name}: {ann}"
    if val:
        return f"{name} = {val}"
    return str(name)

render_suggestion_line(suggestion)

Render one suggestion as a compact ?-prefixed text line.

Source code in packages/axm-ast/src/axm_ast/tools/search_text.py
Python
def render_suggestion_line(suggestion: dict[str, Any]) -> str:
    """Render one suggestion as a compact ``?``-prefixed text line."""
    name = suggestion["name"]
    score = (
        f".{int(suggestion['score'] * 100):02d}" if suggestion["score"] < 1 else "1.0"
    )
    kind = (
        suggestion["kind"][:_KIND_ABBREV_LEN]
        if len(suggestion["kind"]) > _KIND_ABBREV_LEN
        else suggestion["kind"]
    )
    module = suggestion["module"]
    line = f"? {name} {score} {kind}"
    if module is not None:
        line += f" {module}"
    return line

render_text(symbols, *, search_filters, suggestions=None)

Group symbols by kind and render as compact text.

Source code in packages/axm-ast/src/axm_ast/tools/search_text.py
Python
def render_text(
    symbols: list[dict[str, Any]],
    *,
    search_filters: dict[str, Any],
    suggestions: list[dict[str, Any]] | None = None,
) -> str:
    """Group symbols by kind and render as compact text."""
    suggestions = suggestions or []
    header = format_text_header(
        search_filters=search_filters,
        count=len(symbols),
        suggestion_count=len(suggestions),
    )
    if not symbols and not suggestions:
        return header
    body = (
        _render_symbol_lines(symbols)
        if symbols
        else _render_suggestion_lines(suggestions)
    )
    return "\n".join([header, *body])