Skip to content

Flows text

flows_text

Text renderers for FlowsTool dual-format ToolResult.

render_compact_text(entry, compact, depth, cross_module, count, truncated)

Render compact text: header + raw format_flow_compact output.

Source code in packages/axm-ast/src/axm_ast/tools/flows_text.py
Python
def render_compact_text(  # noqa: PLR0913
    entry: str,
    compact: str,
    depth: int,
    cross_module: bool,
    count: int,
    truncated: bool,
) -> str:
    """Render compact text: header + raw format_flow_compact output."""
    params = _trace_params(entry, depth, cross_module, truncated)
    hdr = _header("compact", params, count, "steps")

    return f"{hdr}\n\n{compact}"

render_entry_points_text(entries, count)

Render entry points grouped by module with default elision.

Source code in packages/axm-ast/src/axm_ast/tools/flows_text.py
Python
def render_entry_points_text(entries: list[dict[str, Any]], count: int) -> str:
    """Render entry points grouped by module with default elision."""
    hdr = _header("entry_points", "", count, "entries").replace(" |  | ", " | ")

    if not entries:
        return hdr

    by_module: dict[str, list[str]] = {}
    for e in entries:
        by_module.setdefault(e["module"], []).append(_format_entry(e))

    lines = [hdr, ""]
    for module, names in sorted(by_module.items()):
        lines.append(f"{module}: {' '.join(names)}")

    lines.append("")
    lines.append(
        "Legend: name (export, line=1) | name:LINE (export)"
        " | @FW name:LINE (decorator) | \u25b6name:LINE (main_guard)"
    )
    return "\n".join(lines)

render_source_text(entry, steps, depth, cross_module, count, truncated)

Render trace tree with inline source blocks.

Source code in packages/axm-ast/src/axm_ast/tools/flows_text.py
Python
def render_source_text(  # noqa: PLR0913
    entry: str,
    steps: list[dict[str, Any]],
    depth: int,
    cross_module: bool,
    count: int,
    truncated: bool,
) -> str:
    """Render trace tree with inline source blocks."""
    params = _trace_params(entry, depth, cross_module, truncated)
    hdr = _header("source", params, count, "steps")

    lines = [hdr, ""]
    for step in steps:
        lines.append(_format_step_line(step))
        source = step.get("source")
        if source:
            indent = "  " * (step["depth"] + 1)
            for src_line in source.splitlines():
                lines.append(f"{indent}{src_line}")

    return "\n".join(lines)

render_trace_text(entry, steps, depth, cross_module, count, truncated)

Render trace steps as indented tree text.

Source code in packages/axm-ast/src/axm_ast/tools/flows_text.py
Python
def render_trace_text(  # noqa: PLR0913
    entry: str,
    steps: list[dict[str, Any]],
    depth: int,
    cross_module: bool,
    count: int,
    truncated: bool,
) -> str:
    """Render trace steps as indented tree text."""
    params = _trace_params(entry, depth, cross_module, truncated)
    hdr = _header("trace_flow", params, count, "steps")

    lines = [hdr, ""]
    for step in steps:
        lines.append(_format_step_line(step))

    return "\n".join(lines)