Trace History API
The Trace History API allows you to trace the history of a specific line in a file, following the decision trail through commits, PRs, issues, and ADRs.Overview
The trace history algorithm uses a breadth-first search (BFS) to traverse the knowledge graph, starting from the commit that last modified a specific line in a file. It follows edges to related entities such as PRs, issues, and ADRs, providing a comprehensive view of the decision trail.Key Functions
trace_history_for_file_line
Parameters
db_path
: Path to the SQLite databasefile_path
: Path to the file, relative to the repository rootline_number
: Line number to check (1-based)max_results
: Maximum number of results to return (default: 3)max_hops
: Maximum number of hops in the graph traversal (default: 2)
Returns
A list of dictionaries representing the history trail, sorted by timestamp (newest first). Each dictionary contains:type
: The type of the node (commit, pr, issue, adr, file)id
: The unique identifier of the nodetitle
: The title of the nodetimestamp
: The timestamp of the node (ISO format)
- Commit:
author
,sha
- PR:
number
,state
,url
- Issue:
number
,state
,url
- ADR:
status
,decision_makers
,path
Example
trace_history
Parameters
conn
: SQLite connectionfile_path
: Path to the file, relative to the repository rootline_number
: Line number to check (1-based)max_nodes
: Maximum number of nodes to return (default: 3)max_hops
: Maximum number of hops in the graph traversal (default: 2)
Returns
Same astrace_history_for_file_line
.
get_commit_for_line
Parameters
repo_path
: Path to the Git repositoryfile_path
: Path to the file, relative to the repository rootline_number
: Line number to check (1-based)
Returns
The commit hash, or None if not found.Graph Traversal
The trace history algorithm traverses the knowledge graph using the following rules:- Start from the commit that last modified the specified line
- Follow edges to related entities:
- Commit → PR via MERGES
- Commit → File via MODIFIES
- PR → Issue via MENTIONS
- PR → Commit via MERGES (inbound)
- Issue → ADR via DECIDES (inbound)
- Issue → PR via MENTIONS (inbound)
- ADR → Issue via DECIDES
- ADR → File via DECIDES
- File → Commit via MODIFIES (inbound)
- File → ADR via DECIDES (inbound)
CLI Integration
The trace history API is integrated with the Arc Memory CLI through thearc trace file
command. This command now supports both human-readable text output and machine-readable JSON output via the --format
option:
trace_history_for_file_line
function, serialized as JSON.
See the CLI documentation for more details.
Performance
The trace history algorithm is designed for high performance, with queries typically completing in under 200 microseconds. This ensures a responsive user experience in the VS Code extension.Error Handling
All functions in the trace history API include comprehensive error handling to ensure that they gracefully handle edge cases such as:- File not found
- Line number out of range
- Git blame failures
- Database connection issues