Skip to main content

AST introspection CLI for AI agents โ€” powered by tree-sitter

Project description

axm-ast

Python AST introspection CLI for AI agents, powered by tree-sitter.

CI axm-audit axm-init Coverage PyPI Python 3.12+ Docs


Features

  • ๐Ÿ”ฌ Describe โ€” Full package introspection: functions, classes, imports, variables
  • ๐Ÿ—œ Compress โ€” AI-friendly compressed view: signatures + docstrings + __all__
  • ๐Ÿ“Š Graph โ€” Import dependency graph with Mermaid output
  • ๐Ÿ” Search โ€” Semantic symbol lookup by name, return type, kind, or base class
  • ๐Ÿ“ž Callers โ€” "Who calls this function?" via tree-sitter call-site detection
  • ๐Ÿ“‹ Context โ€” One-shot project dump: stack, patterns, module ranking
  • ๐Ÿ’ฅ Impact โ€” Change impact analysis: callers + graph + test mapping
  • ๐Ÿ“– Docs โ€” One-shot documentation tree dump with progressive disclosure (toc/summary/full) and page filtering
  • ๐Ÿ’€ Dead code โ€” Detect unreferenced symbols with smart exemptions (dict dispatch, entry points, test callers, lazy imports)
  • ๐Ÿš€ Flows โ€” Entry point detection (cyclopts, click, Flask, FastAPI, pytest, __main__) and BFS execution flow tracing
  • ๐Ÿ”€ Diff โ€” Structural branch diff at symbol level (added/modified/removed via git worktrees)
  • ๐Ÿ—๏ธ Workspace โ€” Multi-package workspace support (auto-detects uv workspaces)
  • โญ Rank โ€” PageRank-based symbol importance scoring
  • ๐Ÿ“„ Stub โ€” .pyi-like stub generation for any package

Installation

uv add axm-ast

Quick Start

# One-shot project context for AI agents
axm-ast context src/mylib
axm-ast context src/mylib --slim    # compact top-5 overview

# Describe a package at different detail levels
axm-ast describe src/mylib
axm-ast describe src/mylib --detail full
axm-ast describe src/mylib --compress
axm-ast describe src/mylib --detail toc               # table-of-contents
axm-ast describe src/mylib --modules core,tools        # filter by module
axm-ast describe src/mylib --detail toc --modules core # combined

# Visualize import graph as Mermaid
axm-ast graph src/mylib --format mermaid

# Find all callers of a function
axm-ast callers src/mylib --symbol my_function

# Change impact analysis
axm-ast impact src/mylib --symbol my_function

# Workspace: cross-package analysis (auto-detected)
axm-ast context /path/to/workspace   # all packages at once
axm-ast callers /path/to/workspace --symbol ToolResult
axm-ast graph /path/to/workspace --format mermaid

# Detect dead code
axm-ast dead-code src/mylib
axm-ast dead-code src/mylib --json
axm-ast dead-code src/mylib --include-tests  # also scan test modules as targets

# Dump all project documentation in one shot
axm-ast docs .
axm-ast docs . --detail toc              # heading scan (~500 tokens)
axm-ast docs . --detail summary          # headings + first sentences
axm-ast docs . --pages architecture      # filter by page name
axm-ast docs . --tree                    # tree only
axm-ast docs . --json                    # JSON output

# Structural diff between branches
axm-ast diff main..feature src/mylib
axm-ast diff main..feature src/mylib --json

# Detect entry points and trace execution flows
axm-ast flows src/mylib
axm-ast flows src/mylib --trace main          # BFS flow from entry point
axm-ast flows src/mylib --trace main --json

Example: axm-ast context

๐Ÿ“‹ mylib
  layout: src (16 modules, 151 functions, 9 classes)
  python: >=3.12

๐Ÿ”ง Stack
  cli: cyclopts     models: pydantic     tests: pytest
  lint: ruff         types: mypy          packaging: hatchling

๐Ÿ“ฆ Modules (ranked)
  cli               โ˜…โ˜…โ˜…โ˜…โ˜…  (describe, inspect, graph, search, callers...)
  core.analyzer     โ˜…โ˜…โ˜…โ˜…โ˜†  (analyze_package, build_import_graph...)
  core.context      โ˜…โ˜…โ˜…โ˜…โ˜†  (detect_stack, build_context...)
  core.docs         โ˜…โ˜…โ˜…โ˜†โ˜†  (discover_docs, build_docs_tree...)

Example: axm-ast impact

๐Ÿ’ฅ Impact analysis for 'analyze_package' โ€” HIGH

  ๐Ÿ“ Defined in: core.analyzer (L38)
  ๐Ÿ“ž Direct callers (7): cli, core.context, core.impact
  ๐Ÿ“„ Affected modules (5): axm_ast, cli, core, core.context, core.impact
  ๐Ÿงช Tests to rerun (7): test_analyzer, test_callers, test_compress...
  ๐Ÿ“ฆ Re-exported in (5): axm_ast, cli, core, core.context, core.impact

CLI Commands

Command Description
axm-ast describe Introspect a package (toc / summary / detailed / full / compress), optional --modules filter
axm-ast inspect Inspect a single module file
axm-ast graph Visualize import dependency graph (text / mermaid / json)
axm-ast search Search symbols by name, return type, kind, or base class
axm-ast callers Find all call-sites of a symbol
axm-ast context One-shot project context dump for AI agents
axm-ast impact Change impact analysis for a symbol
axm-ast dead-code Detect unreferenced symbols with smart exemptions
axm-ast flows Detect entry points and trace execution flows
axm-ast diff Structural branch diff at symbol level (base..head)
axm-ast docs One-shot documentation tree dump (README + mkdocs + docs/)
axm-ast stub Generate .pyi-like stubs
axm-ast version Show version

All commands support --json for machine-readable output.

Python API

from axm_ast import analyze_package, search_symbols

pkg = analyze_package("src/mylib")
results = search_symbols(pkg, returns="str")
for fn in results:
    print(f"{fn.name}: {fn.signature}")

Use get_package instead of analyze_package to avoid re-parsing the same package multiple times in a session:

from axm_ast.core import get_package, clear_cache

pkg = get_package("src/mylib")  # parses on first call
pkg = get_package("src/mylib")  # cache hit โ€” instant
clear_cache()                    # force re-parse on next call

Development

This package is part of the axm-forge workspace.

git clone https://github.com/axm-protocols/axm-forge.git
cd axm-forge
uv sync --all-groups
uv run --package axm-ast --directory packages/axm-ast pytest -x -q

๐Ÿ“– Full documentation

License

Apache-2.0 โ€” ยฉ 2026 axm-protocols

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axm_ast-0.1.0.tar.gz (125.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axm_ast-0.1.0-py3-none-any.whl (85.4 kB view details)

Uploaded Python 3

File details

Details for the file axm_ast-0.1.0.tar.gz.

File metadata

  • Download URL: axm_ast-0.1.0.tar.gz
  • Upload date:
  • Size: 125.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for axm_ast-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8420cc0d1fa9568172d317dab0a7d66d26bb59dd241c7d7a7a57c7e86465c66
MD5 2ccdb332bd75326250a152cefd1c617b
BLAKE2b-256 3a8e0635f4669a4f9e7cb73892075084eac99b58dde017a28ebebe50e76e3b00

See more details on using hashes here.

Provenance

The following attestation bundles were made for axm_ast-0.1.0.tar.gz:

Publisher: publish.yml on axm-protocols/axm-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file axm_ast-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: axm_ast-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 85.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for axm_ast-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 225cb11f6550a3d96617654b65a578b946f590f8ff940a55b5a591318bc8e6f9
MD5 7f7fb3bb68a2b87ca99ed8b6c3755bf3
BLAKE2b-256 2c81a791f086c17f340a527fa749ab7a04c252dd804aa8e97e2d437a97e79c88

See more details on using hashes here.

Provenance

The following attestation bundles were made for axm_ast-0.1.0-py3-none-any.whl:

Publisher: publish.yml on axm-protocols/axm-forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page