Follow calls from a selected function and generate Mermaid sequence diagrams with source locations, control flow, and unresolved targets using Tree-sitter static analysis.
English | 简体中文
Installation · Usage · Support matrix
Concept illustration of the static-analysis workflow.
calltrace sequence examples/python --entry "UserService.login" --depth 4Tree-sitter parsing, reference resolution, and depth-limited traversal turn source files into an inspectable call sequence. Analysis runs locally and reads source without executing the target project or installing its dependencies.
- Python, JavaScript, TypeScript, Java and Go through Tree-sitter grammars.
- Entry selection by short name, qualified name or a file-qualified symbol ID. Ambiguous entries list candidates instead of guessing.
- Basic cross-file imports, lexical bindings and provable local receivers.
- Ordered nested calls, branches, loops, async/await annotations and recursion boundaries.
- Depth-limited traversal with retained unknown calls and source evidence.
- Deterministic JSON and Mermaid output, with no LLM or network service required during analysis.
The diagram represents static structure, not recorded runtime execution. Dynamic dispatch, external libraries, reflection, ambiguous overloads and unsupported bindings remain unresolved.
Functions imported from a Python module containing a wildcard import remain unresolved, because that import can replace the module's declared names.
Requires Python 3.11 or later.
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"On Windows PowerShell:
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e ".[dev]"
.\.venv\Scripts\python.exe -m calltrace sequence examples/python --entry UserService.login --depth 4Node.js is only needed for development-time Mermaid validation and rendering.
calltrace sequence PROJECT --entry "Class.method" --depth 4
calltrace trace PROJECT --entry "src/auth.py::login" --depth 3 --output output/logintrace is an alias for sequence. Depth defaults to 3; the entry is depth 0. Depth 0 shows only the entry, and depth 1 includes its direct calls. A complete symbol ID can disambiguate overloaded or same-named functions.
The default output directory is PROJECT/.calltrace/<entry>/:
| File | Contents |
|---|---|
callgraph.json |
Symbols and unique call sites within the selected traversal, with source evidence and project diagnostics |
sequence.json |
Sequence intermediate representation; the renderer's only input |
sequence.mmd |
Generated Mermaid sequence diagram |
unresolved.json |
Unknown targets, source expressions, reasons and candidates |
report.md |
Counts, unresolved calls, expansion boundaries and diagnostics |
An explicit output directory replaces the default; its five generated files are overwritten on subsequent runs. JSON schema version is 0.1. Paths in artifacts are project-relative, and source files are decoded as UTF-8.
| State | Meaning |
|---|---|
exact |
A unique binding under the supported static rules; not a proof of runtime behavior |
heuristic |
Reserved in the data model; v0.1 does not generate heuristic guesses |
unresolved |
The target cannot be established; the call remains visible and is not expanded |
confidence=1.0 is a rule marker for exact, not a calibrated probability. An empty unresolved list does not establish whole-program completeness.
Exit codes: 0 means output was generated without project diagnostics; 1 indicates diagnostics or an I/O failure; 2 indicates invalid arguments or a missing/ambiguous entry. Exit code 0 may still include unresolved calls and depth boundaries.
calltrace sequence examples/python --entry UserService.login --depth 4The included fixture produces five resolved call sites and one unresolved call. The diagram retains await find_user(email), both branches, the recursive audit call and the unknown provider.notify(email) target. The Chinese README includes the generated Mermaid diagram in full.
Install the development extra to include the test runner and build tool:
python -m pip install -e ".[dev]"
python -m pytest -qcalltrace sequence examples/python --entry UserService.login --depth 4
npm ci
npm run validate:mermaid
python -m buildThe first command generates the example diagram. Validation uses the pinned official Mermaid parser and fails if no diagrams are present.
To render the example:
npx --no-install mmdc -i examples/python/.calltrace/UserService.login/sequence.mmd -o examples/python/.calltrace/UserService.login/sequence.svgIf browser downloads are unavailable, set PUPPETEER_SKIP_DOWNLOAD=true during npm installation and point PUPPETEER_EXECUTABLE_PATH to an installed Chrome executable. Syntax validation does not launch a browser.
Source discovery, syntax extraction, reference resolution, call graph traversal, sequence IR and rendering are separate layers. The analyzer never renders Mermaid directly, and the renderer never reads project source.
There is no whole-program type inference, runtime instrumentation, framework-specific dependency injection, UI or distributed tracing. Constructor internals are not expanded. self/this, callbacks and unknown receivers are treated conservatively. Anonymous IDs depend on source positions. Go build tags/workspaces and TypeScript path mappings are not fully modeled.
See the detailed support matrix and upstream review for supported import patterns and design references (currently in Chinese).
MIT. The implementation is original; the upstream review records conceptual references rather than copied code. Dependencies retain their own licenses.
