Context
context
One-shot project context dump for AI agents.
Detects project stack (CLI, models, tests, lint, etc.), AXM tools, coding patterns, and module structure — all in a single command.
Example
from axm_ast.core.context import build_context, format_context ctx = build_context(Path("src/axm_ast"), project_root=Path(".")) print(format_context(ctx))
build_context(path, *, project_root=None)
Build complete project context in one call.
Orchestrates: analyze_package + detect_stack + detect_axm_tools + detect_patterns + rank_symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the package directory. |
required |
project_root
|
Path | None
|
Project root (for pyproject.toml, tests). Defaults to path.parent or path.parent.parent for src layout. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Complete context dict with all project info. |
Source code in packages/axm-ast/src/axm_ast/core/context.py
detect_axm_tools()
Detect installed AXM ecosystem tools.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict mapping tool name to path, only for installed tools. |
Source code in packages/axm-ast/src/axm_ast/core/context.py
detect_patterns(pkg, project_root)
Detect coding patterns in the analyzed package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
project_root
|
Path
|
Root of the project (for test detection). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of detected patterns. |
Source code in packages/axm-ast/src/axm_ast/core/context.py
detect_stack(root)
Parse pyproject.toml and categorize dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory containing pyproject.toml. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dict mapping category names to matched dependency names. |
Source code in packages/axm-ast/src/axm_ast/core/context.py
format_context(ctx)
Format context as human-readable text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
dict[str, Any]
|
Context dict from build_context. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text string. |
Source code in packages/axm-ast/src/axm_ast/core/context.py
format_context_json(ctx, *, depth=None)
Format context as JSON-serializable dict.
The depth parameter controls the level of detail returned:
None: full context with all modules and dependency graph.0: top-5 modules by PageRank (~100 tokens).1: sub-packages with aggregate counts (~500 tokens).2: modules within sub-packages (~2000 tokens).3+: all modules with symbol names listed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
dict[str, Any]
|
Context dict from build_context. |
required |
depth
|
int | None
|
Detail level. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
JSON-serializable dict. |