adapters
code_context_agent.tools.graph.adapters ¶
Input adapters for converting tool outputs to graph elements.
This module provides functions to ingest outputs from: - LSP tools (symbols, references, definitions) - AST-grep tools (pattern matches, rule pack results) - ripgrep tools (text matches) - Test file mappings
ingest_lsp_symbols ¶
Convert lsp_document_symbols output to CodeNodes and containment edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols_result | dict[str, Any] | JSON result from lsp_document_symbols tool | required |
file_path | str | Path to the source file | required |
Returns:
| Type | Description |
|---|---|
tuple[list[CodeNode], list[CodeEdge]] | Tuple of (nodes, edges) where edges represent containment relationships |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_lsp_references ¶
Convert lsp_references output to reference edges.
Creates edges from each reference location back to the source symbol. The source is the referrer, target is the referenced symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
references_result | dict[str, Any] | JSON result from lsp_references tool | required |
source_node_id | str | ID of the symbol being referenced | required |
Returns:
| Type | Description |
|---|---|
list[CodeEdge] | List of CodeEdge objects representing references |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_lsp_definition ¶
Convert lsp_definition output to import/call edges.
Creates edges from the usage location to the definition location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
definition_result | dict[str, Any] | JSON result from lsp_definition tool | required |
from_file | str | File where the symbol is used | required |
from_line | int | Line where the symbol is used | required |
Returns:
| Type | Description |
|---|---|
list[CodeEdge] | List of CodeEdge objects representing the definition relationship |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_astgrep_matches ¶
Convert astgrep_scan output to CodeNodes.
Each match becomes a PATTERN_MATCH node with the pattern in metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matches_result | dict[str, Any] | JSON result from astgrep_scan tool | required |
Returns:
| Type | Description |
|---|---|
list[CodeNode] | List of CodeNode objects representing pattern matches |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_astgrep_rule_pack ¶
Convert astgrep_scan_rule_pack output to CodeNodes.
Each match becomes a PATTERN_MATCH node with rule_id and category in metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_pack_result | dict[str, Any] | JSON result from astgrep_scan_rule_pack tool | required |
Returns:
| Type | Description |
|---|---|
list[CodeNode] | List of CodeNode objects representing categorized matches |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_rg_matches ¶
Convert rg_search output to preliminary CodeNodes.
Creates nodes for text matches that can be refined by LSP later.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rg_result | dict[str, Any] | JSON result from rg_search tool | required |
Returns:
| Type | Description |
|---|---|
list[CodeNode] | List of CodeNode objects representing text matches |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_inheritance ¶
Extract inheritance relationships from LSP hover info.
Parses type signatures to find extends/implements relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hover_content | str | The hover content string (may be markdown) | required |
class_node_id | str | ID of the class node | required |
file_path | str | Path to the file containing the class | required |
Returns:
| Type | Description |
|---|---|
list[CodeEdge] | List of CodeEdge objects representing inheritance |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_test_mapping ¶
Create test coverage edges based on file naming conventions.
Maps test files to production files using common naming patterns: - test_foo.py -> foo.py - foo_test.py -> foo.py - foo.test.ts -> foo.ts - tests/foo.js -> foo.js
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_files | list[str] | List of test file paths | required |
production_files | list[str] | List of production file paths | required |
Returns:
| Type | Description |
|---|---|
list[CodeEdge] | List of CodeEdge objects representing test-to-production relationships |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_git_cochanges ¶
Convert git_files_changed_together output to co-change edges.
Creates bidirectional edges between files that frequently change together, with weight based on co-change frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cochanges_result | dict[str, Any] | JSON result from git_files_changed_together tool | required |
min_percentage | float | Minimum co-change percentage to create an edge (default 20%) | 20.0 |
Returns:
| Type | Description |
|---|---|
list[CodeEdge] | List of CodeEdge objects representing co-change relationships |
Example
result = json.loads(git_files_changed_together("/repo", "src/auth.py")) edges = ingest_git_cochanges(result, min_percentage=15.0)
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_git_hotspots ¶
Convert git_hotspots output to file nodes with churn metadata.
Creates FILE nodes for each hotspot with commit frequency in metadata. This helps identify files that may need attention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hotspots_result | dict[str, Any] | JSON result from git_hotspots tool | required |
Returns:
| Type | Description |
|---|---|
list[CodeNode] | List of CodeNode objects representing hotspot files |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_git_contributors ¶
Extract contributor metadata from git_contributors or git_blame_summary.
Returns metadata that can be attached to file or repo nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contributors_result | dict[str, Any] | JSON result from git_contributors or git_blame_summary | required |
_file_path | str | None | Reserved for future use (file context for blame results) | None |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary of contributor metadata suitable for node metadata |
Source code in src/code_context_agent/tools/graph/adapters.py
ingest_clone_results ¶
Convert clone detection results into SIMILAR_TO edges.
Creates edges between files that share duplicate code blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clone_result | dict[str, Any] | JSON result from detect_clones tool | required |
Returns:
| Type | Description |
|---|---|
list[CodeEdge] | List of CodeEdge objects with SIMILAR_TO type |