Trace source
trace_source
TraceSourceHook — enriched BFS trace with function source code.
Protocol hook that calls trace_flow(detail="source") and returns
the complete trace as HookResult metadata. Registered as
ast:trace-source via axm.hooks entry point.
TraceSourceHook
dataclass
Run trace_flow(detail="source") and return the enriched trace.
Reads working_dir from context and entry from params.
The result is injected into session context via inject_result.
Supports SWE-bench, pytest, and simple symbol entry formats.
Automatically scopes analyze_package to the test directory
for faster analysis on large repos.
Source code in packages/axm-ast/src/axm_ast/hooks/trace_source.py
execute(context, **params)
Execute the hook action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
dict[str, object]
|
Session context dictionary (must contain |
required |
**params
|
object
|
Must include |
{}
|
Returns:
| Type | Description |
|---|---|
HookResult
|
HookResult with |
Source code in packages/axm-ast/src/axm_ast/hooks/trace_source.py
parse_entry(entry)
Parse a test entry string into (symbol_name, test_dir).
Supports three formats:
- SWE-bench:
"test_name (module.path.ClassName)"→("test_name", "module")(first dotted component) - Pytest:
"tests/path/file.py::Class::method"→("method", "tests/path")(directory of the test file) - Simple symbol:
"HttpResponse"→("HttpResponse", None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
str
|
Raw entry string from protocol params. (Can be comma-separated list, in which case only the first item is traced.) |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str | None]
|
Tuple of (symbol_name, test_dir_relative_or_None). |
Source code in packages/axm-ast/src/axm_ast/hooks/trace_source.py
resolve_scope(base_path, test_dir)
Resolve the analysis scope directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
Path
|
Repository root or explicit path param. |
required |
test_dir
|
str | None
|
Relative test directory from |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the directory to analyze. |
Path
|
Falls back to base_path if scoped dir doesn't exist. |