Skip to content

Commit b0284a2

Browse files
committed
refactor: compress verbose JSON format definitions in all prompts
Reduced 549 lines of repetitive format examples across 6 prompt files. Before: ~15-50 lines of verbose JSON examples per tier (4 tiers × 7 files) After: 2-line concise format declaration per tier Net savings: - code_search: 93 lines - dependency_analysis: 100 lines - call_chain: 76 lines - architecture: 92 lines - api_surface: 96 lines - context_builder: 92 lines Total: 549 lines (31% reduction) Kept: Tier-specific guidance, tool descriptions, strategic patterns Removed: Redundant JSON format examples, verbose field explanations
1 parent ea710d8 commit b0284a2

File tree

7 files changed

+85
-699
lines changed

7 files changed

+85
-699
lines changed

crates/codegraph-mcp/src/agentic_api_surface_prompts.rs

Lines changed: 12 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,9 @@ API SURFACE ANALYSIS WORKFLOW:
3838
- Count direct dependents
3939
- Report breaking change impact radius
4040
41-
RESPONSE FORMAT (strict JSON):
42-
{
43-
"reasoning": "Explain which tool to call next and why, OR provide final analysis summary",
44-
"tool_call": {
45-
"tool_name": "name_of_tool",
46-
"parameters": { "param": "value" }
47-
},
48-
"is_final": false
49-
}
50-
51-
When analysis is complete (STRUCTURED OUTPUT):
52-
{
53-
"analysis": "FINAL API SURFACE ANALYSIS:\n\n[Report structure]\n- Public API Nodes: [count and node IDs]\n- Stability Metrics: [afferent coupling and instability scores]\n- Breaking Change Impact: [dependent count for critical nodes]\n\n[Do NOT add quality judgments]",
54-
"endpoints": [
55-
{
56-
"name": "APIEndpoint",
57-
"file_path": "relative/path/to/file.rs",
58-
"line_number": 42,
59-
"api_type": "HTTP",
60-
"description": "Brief description",
61-
"dependencies": []
62-
}
63-
],
64-
"usage_patterns": [],
65-
"integration_points": []
66-
}
67-
MANDATORY: endpoints array must include file paths from tool results
41+
FORMAT:
42+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
43+
- Final: {"analysis": "...", "endpoints": [{"name": "X", "file_path": "a.rs", "line_number": 1, "api_type": "HTTP", "description": "...", "dependencies": []}], "usage_patterns": [], "integration_points": []}
6844
6945
CRITICAL RULES:
7046
- Extract node IDs from previous tool results - never invent them
@@ -121,33 +97,9 @@ API SURFACE ANALYSIS WORKFLOW:
12197
- trace_call_chain(from_node, max_depth=3) for top API nodes
12298
- Map what each public API calls transitively
12399
124-
RESPONSE FORMAT (strict JSON):
125-
{
126-
"reasoning": "Explain which tool to call next and why, OR provide final comprehensive analysis",
127-
"tool_call": {
128-
"tool_name": "name_of_tool",
129-
"parameters": { "param": "value" }
130-
},
131-
"is_final": false
132-
}
133-
134-
When analysis is complete (STRUCTURED OUTPUT):
135-
{
136-
"analysis": "FINAL API SURFACE ANALYSIS:\n\n## Public API Nodes\n[List hub nodes with their degrees]\n\n## Stability Metrics\n[For each key API node: Ca, Ce, I values]\n\n## Breaking Change Impact Assessment\n[For each API: dependent count at depth 1 and depth 2]\n\n## API Contract Issues\n[Any circular dependencies detected]\n\n## API Call Flows\n[Key call chain mappings]\n\n[Report ONLY factual metrics - NO quality judgments]",
137-
"endpoints": [
138-
{
139-
"name": "APIEndpoint",
140-
"file_path": "relative/path/to/file.rs",
141-
"line_number": 42,
142-
"api_type": "HTTP",
143-
"description": "Brief description",
144-
"dependencies": ["dep1", "dep2"]
145-
}
146-
],
147-
"usage_patterns": ["Pattern 1: Usage description"],
148-
"integration_points": ["Integration point 1"]
149-
}
150-
MANDATORY: endpoints array must include file paths from tool results
100+
FORMAT:
101+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
102+
- Final: {"analysis": "...", "endpoints": [{"name": "X", "file_path": "a.rs", "line_number": 1, "api_type": "HTTP", "description": "...", "dependencies": []}], "usage_patterns": [], "integration_points": []}
151103
152104
CRITICAL RULES:
153105
- Extract node IDs from previous tool results - never invent them
@@ -223,33 +175,9 @@ API SURFACE ANALYSIS WORKFLOW:
223175
- Count implementing types per interface
224176
- Map interface dependency chains
225177
226-
RESPONSE FORMAT (strict JSON):
227-
{
228-
"reasoning": "Explain which tool to call next and why, OR provide final comprehensive analysis with complete API characterization",
229-
"tool_call": {
230-
"tool_name": "name_of_tool",
231-
"parameters": { "param": "value" }
232-
},
233-
"is_final": false
234-
}
235-
236-
When analysis is complete (STRUCTURED OUTPUT):
237-
{
238-
"analysis": "FINAL COMPREHENSIVE API SURFACE ANALYSIS:\n\n## 1. Public API Surface Inventory\n[Complete list of hub nodes categorized by degree]\n\n## 2. API Stability Distribution\n- Highly Stable (I < 0.3): [nodes with Ca, Ce, I values]\n- Moderately Stable (0.3 ≤ I < 0.7): [nodes with metrics]\n- Unstable (I ≥ 0.7): [nodes with metrics]\n\n## 3. Breaking Change Impact Radius\n[For each API node:\n- Direct dependents (depth 1): count\n- Depth-2 dependents: count\n- Depth-3 dependents: count\n- Total impact radius: count]\n\n## 4. API Dependency Chains\n[For each major API:\n- Transitive dependencies at depth 4\n- Maximum dependency depth\n- External dependency count]\n\n## 5. API Contract Issues\n[Circular dependencies by edge type:\n- Calls cycles: [pairs]\n- Implements cycles: [pairs]\n- Extends cycles: [pairs]\n- Hub nodes involved in cycles: [list]]\n\n## 6. API Execution Flows\n[Call chains from critical APIs showing complete paths]\n\n## 7. Interface Implementation Mapping\n[Interfaces with implementer counts and dependency depth]\n\n[Report ONLY factual data - NO interpretations or recommendations]",
239-
"endpoints": [
240-
{
241-
"name": "APIEndpoint",
242-
"file_path": "relative/path/to/file.rs",
243-
"line_number": 42,
244-
"api_type": "HTTP",
245-
"description": "Brief description",
246-
"dependencies": ["dep1", "dep2"]
247-
}
248-
],
249-
"usage_patterns": ["Pattern 1: Usage description"],
250-
"integration_points": ["Integration point 1"]
251-
}
252-
MANDATORY: endpoints array must include file paths from tool results
178+
FORMAT:
179+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
180+
- Final: {"analysis": "...", "endpoints": [{"name": "X", "file_path": "a.rs", "line_number": 1, "api_type": "HTTP", "description": "...", "dependencies": []}], "usage_patterns": [], "integration_points": []}
253181
254182
CRITICAL RULES:
255183
- Extract node IDs from previous tool results - never invent them
@@ -365,33 +293,9 @@ API SURFACE ANALYSIS WORKFLOW:
365293
- Identify APIs that cross module boundaries (external-facing)
366294
- Calculate boundary crossing metrics
367295
368-
RESPONSE FORMAT (strict JSON):
369-
{
370-
"reasoning": "Explain which tool to call next and why, OR provide final exhaustive analysis with complete API ecosystem characterization",
371-
"tool_call": {
372-
"tool_name": "name_of_tool",
373-
"parameters": { "param": "value" }
374-
},
375-
"is_final": false
376-
}
377-
378-
When analysis is complete (STRUCTURED OUTPUT):
379-
{
380-
"analysis": "FINAL EXHAUSTIVE API SURFACE ANALYSIS:\n\n## 1. Complete Public API Inventory\n[Hub nodes by degree threshold:\n- min_degree ≥ 3: [count] nodes\n- min_degree ≥ 7: [count] nodes \n- min_degree ≥ 15: [count] nodes\nDegree distribution: [histogram]]\n\n## 2. Comprehensive Stability Characterization\n[For each stability band:\n- Node count in band\n- Example nodes with full Ca, Ce, I metrics\nEcosystem statistics:\n- Mean instability: [value]\n- Median instability: [value]\n- Std deviation: [value]]\n\n## 3. Maximum-Depth Breaking Change Impact Models\n[For each API node:\nNode: [id]\n- Reverse dependencies (Calls, depth 5): [d1: count, d2: count, d3: count, d4: count, d5: count, total: count]\n- Reverse dependencies (Implements, depth 5): [depth breakdown]\n- Reverse dependencies (Uses, depth 5): [depth breakdown]\n- Longest cascade chain: [depth] levels\n- Total impact radius: [count] dependent nodes]\n\n## 4. Complete API Dependency Graphs\n[For each major API:\nAPI: [id]\n- Calls dependencies (depth 6): [total count, max depth, leaf nodes]\n- Imports dependencies (depth 6): [counts]\n- Uses dependencies (depth 6): [counts]\n- External dependencies: [count]\n- Shared dependencies with other APIs: [overlap analysis]]\n\n## 5. Ecosystem-Wide Contract Integrity Report\n[Calls cycles: [count] total, [list pairs], [hub nodes involved]\nImplements cycles: [count] total, [list pairs], [hub nodes involved]\nExtends cycles: [count] total, [list pairs], [hub nodes involved]\nUses cycles: [count] total, [list pairs], [hub nodes involved]\nImports cycles: [count] total, [list pairs], [hub nodes involved]\nCycle length distribution: [histogram]\nInterconnected cycle clusters: [analysis]]\n\n## 6. Deep Execution Flow Maps\n[For top 10 APIs by Ca:\nAPI: [id] (Ca=[value])\n- Call chain (depth 8): [complete path tree]\n- Execution depth: max=[value], mean=[value]\n- Shared bottleneck nodes: [list]\n- Leaf destinations: [count]\n- Path overlap with other APIs: [percentage]]\n\n## 7. Complete Interface/Trait Ecosystem\n[For each interface:\nInterface: [id]\n- Direct implementers: [count]\n- Transitive implementers (depth 4): [count by depth]\n- Inheritance chain (Extends, depth 4): [depth, ancestors]\n- Dependency fan-out: [metric]]\n\n## 8. API Boundary Crossing Analysis\n[For each API:\n- Module containment (depth 3): [module hierarchy]\n- Crosses external boundary: [yes/no]\n- Boundary crossing count: [metric]\nExternal-facing APIs: [count and list]]\n\n[Report ONLY factual graph measurements - NO interpretations]",
381-
"endpoints": [
382-
{
383-
"name": "APIEndpoint",
384-
"file_path": "relative/path/to/file.rs",
385-
"line_number": 42,
386-
"api_type": "HTTP",
387-
"description": "Brief description",
388-
"dependencies": ["dep1", "dep2"]
389-
}
390-
],
391-
"usage_patterns": ["Pattern 1: Usage description"],
392-
"integration_points": ["Integration point 1"]
393-
}
394-
MANDATORY: endpoints array must include file paths from tool results
296+
FORMAT:
297+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
298+
- Final: {"analysis": "...", "endpoints": [{"name": "X", "file_path": "a.rs", "line_number": 1, "api_type": "HTTP", "description": "...", "dependencies": []}], "usage_patterns": [], "integration_points": []}
395299
396300
CRITICAL RULES:
397301
1. Extract ALL node IDs from previous tool results - never invent them

crates/codegraph-mcp/src/architecture_analysis_prompts.rs

Lines changed: 12 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,9 @@ ANALYSIS FOCUS (report WHAT IS, not what SHOULD BE):
2020
- Architectural Patterns: Identify hub patterns, dependency structures
2121
- Code Smells: Detect circular dependencies, god objects (nodes with extreme hub degree)
2222
23-
RESPONSE FORMAT (JSON):
24-
{
25-
"reasoning": "Your analysis plan or findings",
26-
"tool_call": {
27-
"tool_name": "name_of_tool",
28-
"parameters": { tool parameters from previous results }
29-
},
30-
"is_final": false
31-
}
32-
33-
When complete, respond with ONLY this JSON (no 'reasoning', 'tool_call', or 'is_final' fields):
34-
{
35-
"analysis": "ARCHITECTURE SUMMARY:\n- Coupling metrics: [data]\n- Circular deps: [count]\n- Hub nodes: [list with degrees]\n- Interpretation: [objective observations only]",
36-
"layers": [],
37-
"hub_nodes": [
38-
{
39-
"name": "HubNode",
40-
"file_path": "relative/path/to/file.rs",
41-
"line_number": 42
42-
}
43-
],
44-
"coupling_metrics": [],
45-
"patterns": [],
46-
"issues": []
47-
}
48-
MANDATORY: hub_nodes array must include file paths from tool results
23+
FORMAT:
24+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
25+
- Final: {"analysis": "...", "layers": [], "hub_nodes": [{"name": "X", "file_path": "a.rs", "line_number": 1}], "coupling_metrics": [], "patterns": [], "issues": []}
4926
5027
CONSTRAINTS:
5128
- MAX 5 STEPS - prioritize key architectural indicators
@@ -76,32 +53,9 @@ ANALYSIS DIMENSIONS (report WHAT IS, not what SHOULD BE):
7653
- Code Smells: Detect circular dependencies, god objects, coupling hotspots
7754
- Change Impact: Assess blast radius using reverse dependencies
7855
79-
RESPONSE FORMAT (JSON):
80-
{
81-
"reasoning": "Your analysis plan or findings with specific metrics",
82-
"tool_call": {
83-
"tool_name": "name_of_tool",
84-
"parameters": { tool parameters from previous results }
85-
},
86-
"is_final": false
87-
}
88-
89-
When complete, respond with ONLY this JSON (no 'reasoning', 'tool_call', or 'is_final' fields):
90-
{
91-
"analysis": "ARCHITECTURE ANALYSIS SUMMARY:\n\n## Coupling Metrics\n- Ca, Ce, I distributions for key nodes\n- Stability zones (stable I<0.3, unstable I>0.7)\n\n## Architectural Hotspots\n- Hub nodes with degrees and coupling metrics\n- God object candidates (high degree + high Ce)\n\n## Dependency Health\n- Circular dependencies count by edge type\n- Problematic dependency patterns\n\n## Change Impact Assessment\n- High-impact nodes (high Ca)\n- Blast radius for critical components\n\n## Interpretation\n[Objective observations only - no prescriptive judgments]",
92-
"layers": ["Layer 1: Infrastructure", "Layer 2: Core"],
93-
"hub_nodes": [
94-
{
95-
"name": "HubNode",
96-
"file_path": "relative/path/to/file.rs",
97-
"line_number": 42
98-
}
99-
],
100-
"coupling_metrics": ["Node X: Ca=15, Ce=8, I=0.35"],
101-
"patterns": ["Pattern: Layered architecture"],
102-
"issues": ["Issue: Circular dependency between X and Y"]
103-
}
104-
MANDATORY: hub_nodes array must include file paths from tool results
56+
FORMAT:
57+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
58+
- Final: {"analysis": "...", "layers": [], "hub_nodes": [{"name": "X", "file_path": "a.rs", "line_number": 1}], "coupling_metrics": [], "patterns": [], "issues": []}
10559
10660
CONSTRAINTS:
10761
- MAX 10 STEPS - cover key architectural dimensions systematically
@@ -132,32 +86,9 @@ AVAILABLE TOOLS:
13286
5. get_reverse_dependencies(node_id, edge_type, depth) - Maps dependents (depth 3-5)
13387
6. trace_call_chain(from_node, max_depth) - Maps execution paths (depth 4-6)
13488
135-
RESPONSE FORMAT (JSON):
136-
{
137-
"reasoning": "Detailed analysis of current step with specific metrics and connections to previous findings",
138-
"tool_call": {
139-
"tool_name": "name_of_tool",
140-
"parameters": { precise parameters based on prior results }
141-
},
142-
"is_final": false
143-
}
144-
145-
When complete, respond with ONLY this JSON (no 'reasoning', 'tool_call', or 'is_final' fields):
146-
{
147-
"analysis": "[Detailed architectural analysis with coupling distributions, hub analysis, dependency health, change impact, execution patterns, and objective synthesis]",
148-
"layers": ["Layer 1: Infrastructure", "Layer 2: Core", "Layer 3: Application"],
149-
"hub_nodes": [
150-
{
151-
"name": "HubNode",
152-
"file_path": "relative/path/to/file.rs",
153-
"line_number": 42
154-
}
155-
],
156-
"coupling_metrics": ["Node X: Ca=15, Ce=8, I=0.35"],
157-
"patterns": ["Pattern: Layered architecture"],
158-
"issues": ["Issue: Circular dependency between X and Y"]
159-
}
160-
MANDATORY: hub_nodes array must include file paths from tool results
89+
FORMAT:
90+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
91+
- Final: {"analysis": "...", "layers": [], "hub_nodes": [{"name": "X", "file_path": "a.rs", "line_number": 1}], "coupling_metrics": [], "patterns": [], "issues": []}
16192
16293
CONSTRAINTS:
16394
- MAX 15 STEPS - thorough multi-dimensional analysis
@@ -184,32 +115,9 @@ AVAILABLE TOOLS (use extensively):
184115
5. get_reverse_dependencies(node_id, edge_type, depth) - Complete impact (depth 5-8)
185116
6. trace_call_chain(from_node, max_depth) - Exhaustive execution (depth 7-10)
186117
187-
RESPONSE FORMAT (JSON):
188-
{
189-
"reasoning": "Comprehensive step analysis with phase, objective, rationale, connections, pattern investigation, and coverage assessment",
190-
"tool_call": {
191-
"tool_name": "name_of_tool",
192-
"parameters": { precise parameters extracted from results }
193-
},
194-
"is_final": false
195-
}
196-
197-
When complete, respond with ONLY this JSON (no 'reasoning', 'tool_call', or 'is_final' fields):
198-
{
199-
"analysis": "[Exhaustive architectural analysis with complete coupling landscape, architectural topology, dependency health, change impact, execution analysis, cross-dimensional patterns, and statistical health metrics]",
200-
"layers": ["Layer 1: Infrastructure", "Layer 2: Core", "Layer 3: Application", "Layer 4: Presentation"],
201-
"hub_nodes": [
202-
{
203-
"name": "HubNode",
204-
"file_path": "relative/path/to/file.rs",
205-
"line_number": 42
206-
}
207-
],
208-
"coupling_metrics": ["Node X: Ca=15, Ce=8, I=0.35"],
209-
"patterns": ["Pattern: Layered architecture", "Pattern: Hub-and-spoke"],
210-
"issues": ["Issue: Circular dependency between X and Y", "Issue: God object Z"]
211-
}
212-
MANDATORY: hub_nodes array must include file paths from tool results
118+
FORMAT:
119+
- Intermediate: {"reasoning": "...", "tool_call": {...}, "is_final": false}
120+
- Final: {"analysis": "...", "layers": [], "hub_nodes": [{"name": "X", "file_path": "a.rs", "line_number": 1}], "coupling_metrics": [], "patterns": [], "issues": []}
213121
214122
CRITICAL RULES:
215123
1. ZERO HEURISTICS: Every claim must be based on tool output data

0 commit comments

Comments
 (0)