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
  • ๐Ÿ“ Doc Impact โ€” Documentation health: doc refs, undocumented symbols, stale signatures
  • ๐Ÿ“– 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, positional args, entry points, test callers, lazy imports)
  • ๐Ÿš€ Flows โ€” Entry point detection (cyclopts, click, Flask, FastAPI, pytest, __main__), BFS execution flow tracing with cross-module resolution and optional source code enrichment (detail=source)
  • ๐Ÿ”€ 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

Installation

uv add axm-ast

Quick Start

# One-shot project context for AI agents
axm-ast context src/mylib
axm-ast context src/mylib --depth none  # full context (all modules + dependency graph)
axm-ast context src/mylib --depth 0     # 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 --detail source  # include function source code
axm-ast flows tests/ --trace test_foo --cross-module  # resolve sibling-package imports
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 symbol by name across a package (supports dotted paths, --source for source code)
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 (--detail source for code enrichment)
axm-ast diff Structural branch diff at symbol level (base..head)
axm-ast docs One-shot documentation tree dump (README + mkdocs + docs/)
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.3.0.tar.gz (245.0 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.3.0-py3-none-any.whl (125.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for axm_ast-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f09d0fcc88c87d3082224a36ff854dbb9650fc218cdcbebd5562db1d4405afb9
MD5 163f11cdb4e6cf9008686383c7e1be8b
BLAKE2b-256 7263c2d4c35645680ba7d12228e8d5768b2cb6bc0238fca64ab26476b96a2c5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for axm_ast-0.3.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.3.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for axm_ast-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d430f385a133aaf3050dd7ee2f8dd93b49a54dc74234fb8c8caa5bc6419d0a7
MD5 f0120426a2ba5d6c8242918537cbd740
BLAKE2b-256 0115e5a454a0c67423693dad429e7fbde0a76ef79c1a35cdb00ef5b9fa41b866

See more details on using hashes here.

Provenance

The following attestation bundles were made for axm_ast-0.3.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