Index
code_context_agent.tools.graph ¶
Code graph analysis package.
Provides tools for building and analyzing code graphs using NetworkX: - Graph construction from LSP, AST-grep, and ripgrep results - Analysis algorithms (clustering, centrality, traversal) - Progressive disclosure for AI context generation - Export to Mermaid and JSON formats
CodeAnalyzer ¶
Analyzer for code graphs using NetworkX algorithms.
Provides methods for finding important code (centrality), detecting logical modules (clustering), and analyzing relationships between code elements.
Initialize the analyzer with a code graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph | CodeGraph | The CodeGraph to analyze | required |
Source code in src/code_context_agent/tools/graph/analysis.py
find_hotspots ¶
Find code hotspots using betweenness centrality.
Hotspots are code elements that lie on many shortest paths between other elements - they are often bottlenecks or central integration points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_k | int | Number of top hotspots to return | 10 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of dictionaries with node info and betweenness score |
Source code in src/code_context_agent/tools/graph/analysis.py
find_foundations ¶
Find foundational code using PageRank.
Foundations are code elements that are heavily depended upon by other important code - the core infrastructure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_k | int | Number of top foundations to return | 10 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of dictionaries with node info and PageRank score |
Source code in src/code_context_agent/tools/graph/analysis.py
find_trusted_foundations ¶
Find foundational code using TrustRank (noise-resistant PageRank).
TrustRank propagates trust from seed nodes, making it more resistant to noise than standard PageRank. If no seed nodes provided, uses entry points as seeds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed_nodes | list[str] | None | List of trusted node IDs (defaults to entry points) | None |
top_k | int | Number of top results to return | 10 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of dictionaries with node info and trust score |
Source code in src/code_context_agent/tools/graph/analysis.py
find_entry_points ¶
Find likely entry points in the code.
Entry points are nodes with no incoming call edges but outgoing calls - they initiate execution flow.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of dictionaries with entry point node info |
Source code in src/code_context_agent/tools/graph/analysis.py
detect_modules ¶
Detect logical modules using Louvain community detection.
Uses the Louvain algorithm to find communities of densely connected code elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution | float | Clustering resolution (< 1 = larger clusters, > 1 = smaller) | 1.0 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of module dictionaries with members and metrics |
Source code in src/code_context_agent/tools/graph/analysis.py
find_clusters_by_pattern ¶
Find clusters of nodes matching a specific AST-grep rule.
Groups nodes by their rule_id metadata to find related business logic patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_id | str | The rule identifier to filter by | required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of matching nodes grouped by file |
Source code in src/code_context_agent/tools/graph/analysis.py
find_clusters_by_category ¶
Find all nodes matching a business logic category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category | str | Category to filter by (e.g., "db", "auth", "http") | required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of matching nodes with their locations |
Source code in src/code_context_agent/tools/graph/analysis.py
find_triangles ¶
Find tightly-coupled code triads using triangle detection.
Triangles in the call/import graph indicate three pieces of code that all depend on each other — potential cohesion or coupling issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_k | int | Maximum number of triangles to return | 10 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of triangle dictionaries with the three node IDs |
Source code in src/code_context_agent/tools/graph/analysis.py
get_similar_nodes ¶
Find nodes similar to a given node based on graph structure.
Uses personalized PageRank to find nodes closely related to the target node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | str | The node to find similar nodes for | required |
top_k | int | Number of similar nodes to return | 5 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of similar nodes with similarity scores |
Source code in src/code_context_agent/tools/graph/analysis.py
calculate_coupling ¶
Calculate coupling strength between two nodes.
Considers shared neighbors, direct edges, and path length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_a | str | First node ID | required |
node_b | str | Second node ID | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with coupling metrics |
Source code in src/code_context_agent/tools/graph/analysis.py
get_dependency_chain ¶
Get the dependency chain from/to a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | str | Starting node | required |
direction | str | "outgoing" (what this depends on) or "incoming" (what depends on this) | 'outgoing' |
max_depth | int | Maximum depth to traverse | 5 |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with nodes and edges in the chain |
Source code in src/code_context_agent/tools/graph/analysis.py
find_unused_symbols ¶
Find symbols with zero incoming cross-file references.
Identifies functions, classes, and methods that are defined but never referenced from other files — dead code candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_types | list[str] | None | Filter to specific types (default: function, class, method) | None |
exclude_patterns | list[str] | None | Regex patterns to exclude from results | None |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | List of unused symbol dicts with id, name, file_path, node_type |
Source code in src/code_context_agent/tools/graph/analysis.py
find_refactoring_candidates ¶
Identify refactoring opportunities by combining multiple signals.
Combines: - Clone pairs (SIMILAR_TO edges) -> "extract shared helper" - Code smell pattern matches (rule_id contains "code_smell") -> structural issues - Unused symbols -> "dead code removal"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_k | int | Maximum number of candidates to return | 10 |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]] | Ranked list of refactoring candidates with type, files, and rationale. |
Source code in src/code_context_agent/tools/graph/analysis.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
ProgressiveExplorer ¶
Staged exploration of code graph for AI context generation.
Tracks what has been explored and suggests next steps for progressive disclosure of codebase structure.
Initialize the explorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph | CodeGraph | The CodeGraph to explore | required |
analyzer | CodeAnalyzer | None | Optional CodeAnalyzer (created if not provided) | None |
Source code in src/code_context_agent/tools/graph/disclosure.py
get_overview ¶
Get high-level codebase structure (Level 0).
Provides entry points, hotspots, modules, and foundations for initial orientation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with overview information |
Source code in src/code_context_agent/tools/graph/disclosure.py
expand_node ¶
Expand exploration from a specific node (Level 1+).
Uses BFS to discover nodes within the specified depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | str | The node to expand from | required |
depth | int | Number of hops to expand | 1 |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with discovered nodes, edges, and suggestions |
Source code in src/code_context_agent/tools/graph/disclosure.py
expand_module ¶
Explore an entire detected module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_id | int | The module ID from detect_modules() | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with module details and internal structure |
Source code in src/code_context_agent/tools/graph/disclosure.py
get_path_between ¶
Find shortest path between two nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | str | Source node ID | required |
target | str | Target node ID | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with path information |
Source code in src/code_context_agent/tools/graph/disclosure.py
explore_category ¶
Explore all nodes in a business logic category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category | str | Category to explore (e.g., "db", "auth", "http") | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with categorized nodes |
Source code in src/code_context_agent/tools/graph/disclosure.py
get_exploration_status ¶
Get the current exploration status.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with exploration statistics |
Source code in src/code_context_agent/tools/graph/disclosure.py
CodeEdge ¶
Bases: FrozenModel
An edge in the code graph representing a relationship.
Attributes:
| Name | Type | Description |
|---|---|---|
source | str | Source node ID |
target | str | Target node ID |
edge_type | EdgeType | Classification of the relationship |
weight | float | Edge weight for algorithms (default 1.0) |
metadata | dict[str, Any] | Additional properties (line where relationship occurs, etc.) |
to_dict ¶
CodeGraph ¶
Multi-layer code graph supporting multiple relationship types.
Wraps a NetworkX MultiDiGraph to support: - Multiple edge types between the same node pair - Node/edge attributes for metadata - Filtered views for specific relationship types
Initialize an empty code graph.
Source code in src/code_context_agent/tools/graph/model.py
add_node ¶
Add a node to the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node | CodeNode | The CodeNode to add | required |
Source code in src/code_context_agent/tools/graph/model.py
add_edge ¶
Add an edge to the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge | CodeEdge | The CodeEdge to add | required |
Source code in src/code_context_agent/tools/graph/model.py
has_node ¶
has_edge ¶
Check if an edge exists in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | str | Source node ID | required |
target | str | Target node ID | required |
edge_type | EdgeType | None | Optional edge type to check for specifically | None |
Source code in src/code_context_agent/tools/graph/model.py
get_node_data ¶
Get the data associated with a node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id | str | The node ID to look up | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None | Dictionary of node attributes or None if not found |
Source code in src/code_context_agent/tools/graph/model.py
get_nodes_by_type ¶
Get all node IDs of a specific type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_type | NodeType | The type to filter by | required |
Returns:
| Type | Description |
|---|---|
list[str] | List of node IDs matching the type |
Source code in src/code_context_agent/tools/graph/model.py
get_edges_by_type ¶
Get all edges of a specific type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_type | EdgeType | The type to filter by | required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, str, dict[str, Any]]] | List of (source, target, data) tuples |
Source code in src/code_context_agent/tools/graph/model.py
get_view ¶
Get a filtered view of the graph for analysis algorithms.
Creates a simple DiGraph (not Multi) with only the specified edge types. Multiple edges between the same nodes are aggregated by summing weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_types | list[EdgeType] | None | List of edge types to include (None = all types) | None |
Returns:
| Type | Description |
|---|---|
DiGraph | A NetworkX DiGraph suitable for analysis algorithms |
Source code in src/code_context_agent/tools/graph/model.py
nodes ¶
Return nodes, optionally with data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bool | If True, return (node_id, data) tuples | False |
Returns:
| Type | Description |
|---|---|
Any | Node view from underlying NetworkX graph |
Source code in src/code_context_agent/tools/graph/model.py
edges ¶
Return edges, optionally with data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | bool | If True, return (source, target, data) tuples | False |
Returns:
| Type | Description |
|---|---|
Any | Edge view from underlying NetworkX graph |
Source code in src/code_context_agent/tools/graph/model.py
to_node_link_data ¶
Export graph as node-link JSON format.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary suitable for JSON serialization |
from_node_link_data classmethod ¶
Create a CodeGraph from node-link JSON format.
Handles both old NetworkX format ("links" key) and new 3.6+ format ("edges" key) for backward compatibility with saved graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | dict[str, Any] | Dictionary from node_link_data or JSON | required |
Returns:
| Type | Description |
|---|---|
CodeGraph | New CodeGraph instance |
Source code in src/code_context_agent/tools/graph/model.py
describe ¶
Get a quick summary of the graph.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with node count, edge count, type distributions, and density. |
Source code in src/code_context_agent/tools/graph/model.py
CodeNode ¶
Bases: FrozenModel
A node in the code graph representing a code element.
Attributes:
| Name | Type | Description |
|---|---|---|
id | str | Unique identifier (typically "file_path:symbol_name" or "file_path:line") |
name | str | Human-readable display name |
node_type | NodeType | Classification of the code element |
file_path | str | Absolute path to the source file |
line_start | int | Starting line number (0-indexed) |
line_end | int | Ending line number (0-indexed) |
metadata | dict[str, Any] | Additional properties (docstring, visibility, rule_id, etc.) |
to_dict ¶
EdgeType ¶
Bases: Enum
Types of relationships between code elements.
NodeType ¶
Bases: Enum
Types of nodes in the code graph.
code_graph_analyze ¶
code_graph_analyze(
graph_id,
analysis_type,
top_k=10,
node_a="",
node_b="",
resolution=1.0,
category="",
)
Run graph algorithms to surface structural insights about the codebase.
USE THIS TOOL: - After populating graph with code_graph_ingest_* tools - To find important code that isn't obvious from file names - To understand code relationships and architecture
DO NOT USE: - On an empty graph (ingest data first) - For simple lookups (use code_graph_explore instead)
Analysis types provide different perspectives:
Centrality (finds important code): - "hotspots": Betweenness centrality. Finds bottleneck code that many paths go through. High score = integration point, likely to cause cascading changes. Use for: risk assessment, refactoring targets. - "foundations": PageRank. Finds core infrastructure that other important code depends on. High score = foundational code. Use for: understanding dependencies, documentation priority. - "entry_points": Nodes with no incoming edges but outgoing calls. These start execution flows. Use for: understanding app structure.
Clustering (finds groupings): - "modules": Louvain community detection. Finds densely connected groups = logical modules/layers. Use for: architecture diagrams, understanding boundaries.
Relationships (between specific nodes): - "coupling": Measures how tightly two nodes are connected. Use for: understanding change impact, identifying tight coupling. - "similar": Personalized PageRank from a node. Finds related code. Use for: understanding a node's neighborhood. - "dependencies": BFS from a node. Shows what it depends on. Use for: understanding impact of changes.
Filtering: - "category": Finds all nodes in a business logic category. Use for: focused analysis on db/auth/validation/etc.
Code Health: - "unused_symbols": Finds functions/classes/methods with zero cross-file references. Dead code candidates. Use category param for node type filter. - "refactoring": Combines clone detection, code smells, and unused symbols into ranked refactoring opportunities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the graph to analyze (must have data from ingestion) | required |
analysis_type | str | Algorithm to run. One of: - "hotspots": Returns ranked list by betweenness score - "foundations": Returns ranked list by PageRank score - "entry_points": Returns list of entry point nodes - "modules": Returns list of detected modules with members - "coupling": Returns coupling metrics (requires node_a, node_b) - "similar": Returns similar nodes (requires node_a) - "category": Returns nodes in category (requires category) - "dependencies": Returns dependency chain (requires node_a) - "trust": TrustRank-based foundations (noise-resistant PageRank from entry points) - "triangles": Find tightly-coupled code triads - "unused_symbols": Dead code detection (zero cross-file references) - "refactoring": Combined refactoring opportunity ranking | required |
top_k | int | Maximum results for ranked analyses (hotspots, foundations, similar). Default 10. Use 20-30 for comprehensive analysis. | 10 |
node_a | str | Required for "coupling", "similar", "dependencies". Node ID format: "file_path:symbol_name" | '' |
node_b | str | Required for "coupling" analysis. Second node to compare. | '' |
resolution | float | For "modules" only. Controls cluster granularity: - < 1.0: Fewer, larger clusters (e.g., 0.5 for high-level layers) - = 1.0: Default clustering - > 1.0: More, smaller clusters (e.g., 1.5 for fine-grained) | 1.0 |
category | str | Required for "category" analysis. Category name from AST-grep rule packs: "db", "auth", "http", "validation", etc. | '' |
Returns:
| Name | Type | Description |
|---|---|---|
str | JSON with analysis results. Format varies by type: | |
str | hotspots/foundations: | |
str | {"results": [{"id": "...", "score": 0.85, "name": "...", ...}]} | |
modules | str | |
str | {"module_count": 5, "results": [ | |
str | ]} | |
coupling | str | |
str | {"results": {"coupling": 2.5, "shared_neighbors": 3, "path_length": 2}} |
Output Size: 1-10KB depending on top_k and analysis type
Workflow Examples:
Find bottleneck code
hotspots = code_graph_analyze("main", "hotspots", top_k=15)
Results ranked by betweenness - top items are integration points¶
Detect architecture layers
modules = code_graph_analyze("main", "modules", resolution=0.8)
Each module is a logical grouping - name based on key_nodes¶
Understand coupling
coupling = code_graph_analyze("main", "coupling", node_a="src/api.py:handler", node_b="src/db.py:repository")
High coupling score = tightly connected, changes propagate¶
Find all database operations
db_ops = code_graph_analyze("main", "category", category="db")
Returns all nodes tagged as "db" from AST-grep ingestion¶
Source code in src/code_context_agent/tools/graph/tools.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
code_graph_create ¶
Initialize an empty code graph for structural analysis of a codebase.
USE THIS TOOL: - At the start of analysis, BEFORE running LSP/AST-grep tools - When you need to unify results from multiple discovery tools - When you want to run graph algorithms (hotspots, modules, coupling)
DO NOT USE: - If a graph with this ID already exists (will overwrite it) - For simple single-file analysis (use LSP tools directly)
The graph is stored in memory for the session. Populate it using: - code_graph_ingest_lsp: Add symbols, references, definitions from LSP - code_graph_ingest_astgrep: Add business logic patterns - code_graph_ingest_tests: Add test coverage relationships
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | Unique identifier for this graph. Use descriptive names: - "main": Primary analysis graph for the whole codebase - "feature_auth": Graph focused on authentication code - "module_api": Graph for API layer only | required |
description | str | Human-readable description of what this graph represents. Helps when managing multiple graphs. | '' |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | {"status": "success", "graph_id": "...", "message": "..."} |
Output Size: ~100 bytes
Workflow
- code_graph_create("main") # Initialize
- lsp_start(...) + lsp_document_symbols(...) # Discover
- code_graph_ingest_lsp(...) # Populate
- code_graph_analyze("main", "hotspots") # Analyze
- code_graph_save("main", ".code-context/graph.json") # Persist
Example
code_graph_create("main", "Full codebase analysis") code_graph_create("backend", "Backend services only")
Source code in src/code_context_agent/tools/graph/tools.py
code_graph_explore ¶
code_graph_explore(
graph_id,
action,
node_id="",
module_id=-1,
target_node="",
depth=1,
category="",
)
Progressively explore the code graph to build context incrementally.
USE THIS TOOL: - ALWAYS start with "overview" action first - When you need to understand the codebase step by step - To get suggestions on where to explore next - To track what you've already explored
DO NOT USE: - For running analysis algorithms (use code_graph_analyze instead) - On an empty graph (ingest data first)
Progressive disclosure pattern: 1. "overview" → Get entry points, hotspots, modules, foundations 2. Pick interesting nodes from overview 3. "expand_node" → See neighbors and relationships 4. Repeat until sufficient context is gathered
The explorer tracks visited nodes and suggests what to explore next.
Actions:
Starting point: - "overview": Returns high-level structure. Includes: - entry_points: Where execution starts - hotspots: Bottleneck code (top 5) - modules: Detected clusters with key nodes - foundations: Core infrastructure (top 5) Always start here to orient yourself.
Drill-down: - "expand_node": BFS expansion from a node. See immediate neighbors and their relationships. Good for understanding a specific area. - "expand_module": Deep-dive into a detected module. Shows internal structure and external connections. - "category": Explore all nodes in a business logic category. Groups results by file.
Navigation: - "path": Find shortest path between two nodes. Useful for understanding how components connect. - "status": Check exploration coverage (% of nodes visited). - "reset": Clear exploration state to start fresh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the graph to explore (must have data from ingestion) | required |
action | str | Exploration action. One of: - "overview": No additional params needed - "expand_node": Requires node_id, optional depth - "expand_module": Requires module_id (from overview/modules analysis) - "path": Requires node_id (source) and target_node - "category": Requires category (e.g., "db", "auth") - "status": No additional params - "reset": No additional params | required |
node_id | str | For "expand_node": Node ID to expand from. For "path": Source node. Format: "file_path:symbol_name" | '' |
module_id | int | For "expand_module": Module ID from detect_modules results. Typically 0, 1, 2, etc. from the overview. | -1 |
target_node | str | For "path": Destination node ID. | '' |
depth | int | For "expand_node": How many hops to expand. - depth=1: Direct neighbors only (fast, focused) - depth=2: Neighbors of neighbors (broader context) - depth=3+: Rarely needed, can be large | 1 |
category | str | For "category": Business logic category name. Values from AST-grep: "db", "auth", "http", "validation", etc. | '' |
Returns:
| Name | Type | Description |
|---|---|---|
str | JSON with exploration results. Always includes "explored_count". | |
overview | str | |
str | { "entry_points": [...], "hotspots": [...], "modules": [{"module_id": 0, "size": 15, "key_nodes": [...]}], "foundations": [...], "explored_count": 25 | |
str | } | |
expand_node | str | |
str | { "center": "src/api.py:handler", "discovered_nodes": [...], "edges": [...], "suggested_next": [...], # What to explore next "explored_count": 40 | |
str | } |
Output Size: 2-20KB depending on action and graph size
Workflow Example:
1. Start with overview¶
overview = code_graph_explore("main", "overview")
Look at entry_points and hotspots¶
2. Expand from interesting hotspot¶
details = code_graph_explore("main", "expand_node", node_id=overview["hotspots"][0]["id"], depth=2)
See neighbors and suggested_next¶
3. Explore a module¶
module_details = code_graph_explore("main", "expand_module", module_id=0)
See internal structure and external connections¶
4. Check coverage¶
status = code_graph_explore("main", "status")
coverage_percent shows how much of graph was explored¶
Source code in src/code_context_agent/tools/graph/tools.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
code_graph_export ¶
Export the code graph for visualization or external analysis.
USE THIS TOOL: - To generate Mermaid diagrams for CONTEXT.md architecture section - To save graph data for external visualization tools - After analysis, to capture the graph structure
DO NOT USE: - For persistence (use code_graph_save instead) - On empty graphs (ingest data first)
Export formats:
"mermaid" (recommended for documentation): Generates Mermaid diagram syntax that can be embedded in markdown. - Selects top nodes by degree (most connected = most important) - Uses shapes based on node type: - [name]: Classes (rectangles) - (name): Functions/methods (rounded) - [[name]]: Files (stadium shape) - Edge styles by relationship: - → : calls - -.-> : imports - ==> : inherits
"json" (for external tools): NetworkX node-link format. Can be loaded into other graph tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the graph to export (must exist) | required |
format | str | Export format: - "mermaid": Mermaid diagram syntax (for markdown embedding) - "json": NetworkX node-link JSON (for external tools) | 'json' |
include_metadata | bool | For "json" format only. Whether to include node/edge metadata (file_path, line numbers, etc.). Set False for smaller output. | True |
max_nodes | int | For "mermaid" format only. Maximum nodes to include. Mermaid diagrams become unreadable with too many nodes. Recommended: 15 for CONTEXT.md, up to 50 for detailed diagrams. Nodes are selected by degree (most connected first). | 100 |
Returns:
| Type | Description |
|---|---|
str | For "mermaid": |
str | { "status": "success", "format": "mermaid", "diagram": "graph TD\n node1[Name] → node2..." |
str | } |
str | For "json": |
str | { "status": "success", "format": "json", "graph": {"nodes": [...], "links": [...]} |
str | } |
Output Size
- mermaid: 1-5KB (limited by max_nodes)
- json: 10-500KB (depends on graph size)
Workflow Example:
Export for CONTEXT.md architecture diagram¶
result = code_graph_export("main", format="mermaid", max_nodes=15) mermaid_code = result["diagram"]
Embed in markdown:¶
```mermaid¶
{mermaid_code}¶
```¶
Export for external visualization¶
result = code_graph_export("main", format="json", include_metadata=True)
Use with Gephi, D3.js, etc.¶
Source code in src/code_context_agent/tools/graph/tools.py
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | |
code_graph_ingest_astgrep ¶
Add AST-grep pattern matches to the graph as categorized business logic nodes.
USE THIS TOOL: - After running astgrep_scan_rule_pack to add business logic patterns - After running astgrep_scan for custom pattern matches - When you want graph analysis to consider business logic categories
DO NOT USE: - Before code_graph_create (graph must exist first) - With empty AST-grep results (check match count first)
AST-grep matches become nodes with rich metadata: - category: "db", "auth", "http", "validation", etc. - severity: "error" (writes), "warning" (reads), "hint" (definitions) - rule_id: The specific pattern that matched
This metadata enables category-based analysis: - code_graph_analyze("main", "category", category="db") - code_graph_explore("main", "category", category="auth")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
astgrep_result | str | The raw JSON string output from astgrep_scan or astgrep_scan_rule_pack. Pass the exact return value. | required |
result_type | str | Source of the AST-grep result: - "rule_pack" (default): From astgrep_scan_rule_pack. Results include category, severity, rule_id metadata. Use this for business logic detection. - "scan": From astgrep_scan ad-hoc patterns. Results have pattern info but no category metadata. | 'rule_pack' |
Returns:
| Type | Description |
|---|---|
str | JSON with ingestion results: |
str | { "status": "success", "nodes_added": 25, "categories": ["db", "auth", "validation"], "total_nodes": 175 |
str | } |
Output Size: ~300 bytes
Common Errors
- "Graph not found": Call code_graph_create first
- "Invalid JSON": AST-grep result is malformed
Workflow Example
Run rule pack for Python business logic¶
matches = astgrep_scan_rule_pack("py_business_logic", repo_path)
Ingest into graph¶
code_graph_ingest_astgrep("main", matches, "rule_pack")
Now analyze by category¶
db_ops = code_graph_analyze("main", "category", category="db") auth_ops = code_graph_analyze("main", "category", category="auth")
Source code in src/code_context_agent/tools/graph/tools.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
code_graph_ingest_clones ¶
Add clone detection results to the graph as SIMILAR_TO edges.
USE THIS TOOL: - After calling detect_clones to find duplicate code blocks - To enable refactoring candidate analysis in code_graph_analyze
DO NOT USE: - Before code_graph_create (graph must exist first) - With empty clone results
Creates SIMILAR_TO edges between files sharing duplicate code. These edges are used by: - code_graph_analyze("main", "refactoring") for refactoring candidates
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
clone_result | str | The raw JSON string output from detect_clones tool. | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | {"status": "success", "edges_added": N, "total_edges": M} |
Output Size: ~150 bytes
Source code in src/code_context_agent/tools/graph/tools.py
code_graph_ingest_git ¶
Add git history data to the code graph as nodes, edges, or metadata.
USE THIS TOOL: - After calling git_hotspots to add churn metadata to FILE nodes - After calling git_files_changed_together to add COCHANGES edges - After calling git_contributors or git_blame_summary to add ownership metadata
DO NOT USE: - Before code_graph_create (graph must exist first) - With error-status git results
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
git_result | str | The raw JSON string output from a git tool. Pass the exact return value from git_hotspots, git_files_changed_together, git_contributors, or git_blame_summary. | required |
result_type | str | Type of git result being ingested: - "hotspots": From git_hotspots. Creates/updates FILE nodes with churn metadata. - "cochanges": From git_files_changed_together. Creates COCHANGES edges. Uses min_percentage to filter low-coupling pairs. - "contributors": From git_contributors or git_blame_summary. Returns ownership metadata dict. | required |
source_file | str | For "contributors" type. If provided and the node exists, attaches contributor metadata to the FILE node at this path. | '' |
min_percentage | float | For "cochanges" type. Minimum co-change percentage to create an edge (default 20.0). Lower = more edges. | 20.0 |
Returns:
| Type | Description |
|---|---|
str | JSON with ingestion results varying by type. |
Output Size: ~200 bytes
Workflow Examples:
Ingesting hotspots (creates/updates FILE nodes): hotspots = git_hotspots(repo_path, limit=30) code_graph_ingest_git("main", hotspots, "hotspots")
Ingesting co-changes (creates COCHANGES edges): coupling = git_files_changed_together(repo_path, "src/auth.py") code_graph_ingest_git("main", coupling, "cochanges", min_percentage=15.0)
Ingesting contributors (returns metadata): blame = git_blame_summary(repo_path, "src/auth.py") code_graph_ingest_git("main", blame, "contributors", source_file="src/auth.py")
Source code in src/code_context_agent/tools/graph/tools.py
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
code_graph_ingest_inheritance ¶
Add class inheritance/implementation edges from LSP hover information.
USE THIS TOOL: - After lsp_hover on a class to capture extends/implements relationships - When building class hierarchy for OOP codebases - In DEEP mode for comprehensive type analysis
DO NOT USE: - On non-class symbols (functions, variables) - Without first creating the class node via code_graph_ingest_lsp
Parses class signatures to create edges: - "inherits" edges: class Foo extends Bar → Foo --inherits→ Bar - "implements" edges: class Foo implements IBar → Foo --implements→ IBar
Works with common patterns: - TypeScript/JavaScript: extends, implements - Python: class Foo(Bar, Baz) - Java: extends, implements
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
hover_content | str | The markdown/text content from lsp_hover result. Extract the "value" field from the hover response. Example: "class UserService extends BaseService implements IUserService" | required |
class_node_id | str | The node ID of the class in the graph. Format: "file_path:ClassName" (e.g., "src/services/user.ts:UserService") Must match the ID created by code_graph_ingest_lsp. | required |
file_path | str | Path to the file containing this class. Used to resolve base class locations. | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | {"status": "success", "edges_added": N, "edge_types": ["inherits", "implements"]} |
Output Size: ~200 bytes
Workflow Example
Get class symbols¶
symbols = lsp_document_symbols(session_id, "src/user.ts") code_graph_ingest_lsp("main", symbols, "symbols", source_file="src/user.ts")
For each class, get hover info and ingest inheritance¶
hover = lsp_hover(session_id, "src/user.ts", class_line, 0) hover_content = hover["hover"]["contents"]["value"] code_graph_ingest_inheritance("main", hover_content, "src/user.ts:UserService", "src/user.ts")
Source code in src/code_context_agent/tools/graph/tools.py
code_graph_ingest_lsp ¶
Add LSP tool results to the code graph as nodes and edges.
USE THIS TOOL: - After calling lsp_document_symbols to add function/class nodes - After calling lsp_references to add "references" edges (fan-in data) - After calling lsp_definition to add "calls" edges (call relationships)
DO NOT USE: - Before calling code_graph_create (graph must exist first) - With invalid/empty LSP results (check LSP tool status first)
Converts raw LSP data into graph structure: - "symbols" → Creates nodes for functions, classes, methods, variables - "references" → Creates edges showing where a symbol is used - "definition" → Creates edges showing what a symbol calls/uses
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
lsp_result | str | The raw JSON string output from an LSP tool. Pass the exact return value from lsp_document_symbols, lsp_references, or lsp_definition. | required |
result_type | str | Type of LSP result being ingested: - "symbols": From lsp_document_symbols. Creates nodes. REQUIRES source_file parameter. - "references": From lsp_references. Creates reference edges. REQUIRES source_symbol parameter (format: "file:name"). - "definition": From lsp_definition. Creates call/import edges. | required |
source_file | str | Required for "symbols" type. The file path that was analyzed (e.g., "src/main.py"). Used to create node IDs. | '' |
source_symbol | str | Required for "references" type. The symbol ID that references point TO (format: "src/main.py:my_function"). | '' |
Returns:
| Type | Description |
|---|---|
str | JSON with ingestion results: |
str | { "status": "success", "nodes_added": 15, # New nodes created "edges_added": 8, # New edges created "total_nodes": 150, # Graph totals "total_edges": 200 |
str | } |
Output Size: ~200 bytes
Common Errors
- "Graph not found": Call code_graph_create first
- "source_file required": Must provide source_file for "symbols"
- "source_symbol required": Must provide source_symbol for "references"
- "Invalid JSON": LSP result is malformed
Workflow Examples:
Ingesting symbols (creates nodes): symbols = lsp_document_symbols(session_id, "src/api.py") code_graph_ingest_lsp("main", symbols, "symbols", source_file="src/api.py")
Ingesting references (creates edges showing fan-in): refs = lsp_references(session_id, "src/api.py", 10, 5) code_graph_ingest_lsp("main", refs, "references", source_symbol="src/api.py:handle_request")
Ingesting definitions (creates call edges): defn = lsp_definition(session_id, "src/api.py", 15, 20) code_graph_ingest_lsp("main", defn, "definition")
Source code in src/code_context_agent/tools/graph/tools.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
code_graph_ingest_rg ¶
Add ripgrep search matches to the graph as preliminary nodes.
USE THIS TOOL: - When LSP doesn't cover a language/pattern - For text-based patterns (SQL keywords, config values, comments) - As a fallback when semantic analysis isn't available
DO NOT USE: - When LSP symbols are available (prefer code_graph_ingest_lsp) - For structural patterns (prefer code_graph_ingest_astgrep)
Creates lightweight nodes from text matches. These nodes have: - file_path and line number - matched text content - No semantic type information (unlike LSP nodes)
Ripgrep nodes are useful for: - Finding TODO/FIXME comments - Locating hardcoded values - Identifying SQL queries in strings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
rg_result | str | The raw JSON string output from rg_search tool. Pass the exact return value. | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | {"status": "success", "nodes_added": N, "total_nodes": M} |
Output Size: ~150 bytes
Workflow Example
Find all SQL queries¶
sql_matches = rg_search("SELECT|INSERT|UPDATE|DELETE", repo_path) code_graph_ingest_rg("main", sql_matches)
Source code in src/code_context_agent/tools/graph/tools.py
code_graph_ingest_tests ¶
Add test-to-production file mappings as "tests" edges in the graph.
USE THIS TOOL: - After identifying test files (via rg_search for test patterns) - To enable test coverage analysis on business logic - To find untested hotspots in the codebase
DO NOT USE: - With unfiltered file lists (only include actual test files) - Before adding production file nodes to the graph
Creates "tests" edges based on naming convention matching: - test_foo.py → foo.py - foo.test.ts → foo.ts - FooTest.java → Foo.java - tests/foo.test.js → src/foo.js
These edges enable: - Finding untested business logic (nodes without incoming test edges) - Understanding test coverage per module - Prioritizing testing efforts on hotspots
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the target graph (must exist from code_graph_create) | required |
test_files | str | JSON array of test file paths as a string. Example: '["tests/test_user.py", "tests/test_auth.py"]' Obtain from rg_search or file manifest filtering. | required |
production_files | str | JSON array of production file paths as a string. Example: '["src/user.py", "src/auth.py"]' Should include all files you want to map tests to. | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | {"status": "success", "edges_added": N, "total_edges": M} |
Output Size: ~150 bytes
Workflow Example
Find test files¶
test_matches = rg_search("def test_|it(|describe(", repo_path) test_files = extract_unique_files(test_matches)
Get production files from manifest¶
prod_files = filter_non_test_files(manifest)
Create test mapping edges¶
code_graph_ingest_tests("main", json.dumps(test_files), json.dumps(prod_files))
Find untested hotspots¶
hotspots = code_graph_analyze("main", "hotspots", top_k=10)
Check which have no incoming "tests" edges¶
Source code in src/code_context_agent/tools/graph/tools.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
code_graph_load ¶
Load a previously saved code graph from disk.
USE THIS TOOL: - At the start of a session if .code-context/code_graph.json exists - To resume analysis from a previous session - To skip re-running LSP/AST-grep data collection
DO NOT USE: - If graph file doesn't exist (check with file system first) - When you need fresh analysis (create new graph instead)
Loading a saved graph restores: - All nodes with their metadata - All edges with their types - Ready for immediate analysis (code_graph_analyze, code_graph_explore)
Note: Loading replaces any existing graph with the same ID. The explorer state is reset (tracked exploration cleared).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID to assign to the loaded graph. Use: - "main": For the primary codebase graph - Descriptive names for scoped graphs | required |
file_path | str | Path to the saved graph file. Standard location: ".code-context/code_graph.json" | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | { "status": "success", "graph_id": "main", "path": ".code-context/code_graph.json", "nodes": 150, "edges": 200 |
str | } |
Output Size: ~100 bytes
Common Errors
- "Load failed": File not found or invalid JSON
Workflow Example:
Check if saved graph exists¶
If .code-context/code_graph.json exists:¶
code_graph_load("main", ".code-context/code_graph.json")
Graph is ready for analysis¶
hotspots = code_graph_analyze("main", "hotspots") overview = code_graph_explore("main", "overview")
No need to re-run lsp_* or astgrep_* tools!¶
Source code in src/code_context_agent/tools/graph/tools.py
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 | |
code_graph_save ¶
Persist the code graph to disk for reuse in future sessions.
USE THIS TOOL: - After completing graph analysis (DEEP mode) - When you want to preserve analysis results - Before ending a session with valuable graph data
DO NOT USE: - For exporting to visualization formats (use code_graph_export) - On empty graphs (waste of disk space)
Saves the complete graph structure including: - All nodes with metadata (file_path, line numbers, categories) - All edges with types (calls, references, imports, inherits) - All analysis-relevant data
Saved graphs can be reloaded with code_graph_load, avoiding the need to re-run LSP/AST-grep tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the graph to save (must exist) | required |
file_path | str | Destination file path. Recommended locations: - ".code-context/code_graph.json": Standard location for main graph - ".code-context/{name}_graph.json": For named/scoped graphs Parent directories are created automatically. | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | { "status": "success", "graph_id": "main", "path": ".code-context/code_graph.json", "nodes": 150, "edges": 200 |
str | } |
Output Size: ~100 bytes (file size varies: 10KB-1MB)
Common Errors
- "Graph not found": Graph ID doesn't exist
- "Save failed": File system error (permissions, disk full)
Workflow Example:
After comprehensive analysis in DEEP mode¶
code_graph_create("main")
... ingest LSP, AST-grep data ...¶
... run analysis ...¶
Save for future sessions¶
code_graph_save("main", ".code-context/code_graph.json")
In future session:¶
code_graph_load("main", ".code-context/code_graph.json")
Graph restored with all nodes/edges¶
Source code in src/code_context_agent/tools/graph/tools.py
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | |
code_graph_stats ¶
Get summary statistics about a code graph.
USE THIS TOOL: - To verify graph was populated correctly after ingestion - To understand graph composition before analysis - For the completion signal (graph node/edge counts)
DO NOT USE: - For detailed analysis (use code_graph_analyze) - For exploration (use code_graph_explore)
Returns counts broken down by type: - Nodes by type: function, class, method, variable, pattern_match - Edges by type: calls, references, imports, inherits, tests
This helps verify: - LSP ingestion worked (function/class nodes exist) - AST-grep ingestion worked (pattern_match nodes exist) - Reference tracking worked (references edges exist) - Test mapping worked (tests edges exist)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_id | str | ID of the graph to get stats for (must exist) | required |
Returns:
| Name | Type | Description |
|---|---|---|
JSON | str | { "status": "success", "graph_id": "main", "total_nodes": 150, "total_edges": 200, "nodes_by_type": { "function": 80, "class": 20, "method": 40, "pattern_match": 10 }, "edges_by_type": { "calls": 100, "references": 60, "imports": 30, "tests": 10 } |
str | } |
Output Size: ~300 bytes
Workflow Example:
After ingestion, verify graph state¶
stats = code_graph_stats("main")
Check ingestion worked¶
if stats["nodes_by_type"]["function"] == 0: # LSP symbols not ingested properly
if stats["edges_by_type"]["references"] == 0: # LSP references not ingested
Use in completion signal¶
Graph: {stats["total_nodes"]} nodes, {stats["total_edges"]} edges¶
Source code in src/code_context_agent/tools/graph/tools.py
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 | |