@@ -15,77 +15,58 @@ import (
1515// CodeGraphTool provides tree-sitter based code intelligence.
1616type CodeGraphTool struct {}
1717
18+ // CodeGraphInput is the typed input for CodeGraphTool.
19+ type CodeGraphInput struct {
20+ Action string `json:"action"`
21+ Query string `json:"query"`
22+ NodeID string `json:"node_id"`
23+ MaxDepth int `json:"max_depth"`
24+ MaxNodes int `json:"max_nodes"`
25+ Root string `json:"root"`
26+ From string `json:"from"`
27+ To string `json:"to"`
28+ MaxFiles int `json:"max_files"`
29+ Dir string `json:"dir"`
30+ }
31+
1832func (CodeGraphTool ) Name () string { return "CodeGraph" }
1933func (CodeGraphTool ) RiskLevel () string { return "low" }
2034func (CodeGraphTool ) Aliases () []string { return []string {"cg" , "graph" } }
2135func (CodeGraphTool ) Description () string {
2236 return "Query the code knowledge graph: search symbols, trace callers/callees, compute impact radius, build context."
2337}
2438
25- func (CodeGraphTool ) Parameters () map [string ]interface {} {
26- return map [string ]interface {}{
27- "type" : "object" ,
28- "properties" : map [string ]interface {}{
29- "action" : map [string ]interface {}{
30- "type" : "string" ,
31- "enum" : []string {"search" , "callers" , "callees" , "impact" , "context" , "index" , "sync" , "trace" , "explore" , "files" , "status" , "stats" , "pagerank" , "centrality" , "communities" , "components" , "deadcode" , "coupling" , "cross_repo" , "semantic_search" , "hybrid_search" },
32- "description" : "Action: search/find symbols, callers/who calls, callees/what it calls, impact/breakage radius, context/build task context, index/full re-index, sync/incremental update, trace/call path A→B, explore/multi-symbol source, files/list indexed, status/health check, stats/counts, pagerank/file importance, centrality/bridge files, communities/module clusters, components/isolated subsystems, deadcode/unused code, coupling/tightly coupled files, cross_repo/cross-repo dependencies, semantic_search/embedding-based search, hybrid_search/combined FTS5+semantic" ,
33- },
34- "query" : map [string ]interface {}{
35- "type" : "string" ,
36- "description" : "Search query, symbol name, or task description (for context/trace use 'from -> to')" ,
37- },
38- "node_id" : map [string ]interface {}{
39- "type" : "string" ,
40- "description" : "Node ID for callers/callees/impact" ,
41- },
42- "max_depth" : map [string ]interface {}{
43- "type" : "integer" ,
44- "description" : "Max traversal depth (default: 3)" ,
45- },
46- "max_nodes" : map [string ]interface {}{
47- "type" : "integer" ,
48- "description" : "Max nodes to return (default: 30)" ,
49- },
50- "root" : map [string ]interface {}{
51- "type" : "string" ,
52- "description" : "Project root directory (default: current dir)" ,
53- },
54- "from" : map [string ]interface {}{
55- "type" : "string" ,
56- "description" : "Source symbol for trace action" ,
57- },
58- "to" : map [string ]interface {}{
59- "type" : "string" ,
60- "description" : "Target symbol for trace action" ,
61- },
62- "max_files" : map [string ]interface {}{
63- "type" : "integer" ,
64- "description" : "Max files for explore action (default: 10)" ,
65- },
66- "dir" : map [string ]interface {}{
67- "type" : "string" ,
68- "description" : "Directory filter for files action" ,
69- },
39+ // Schema returns the typed input schema. Parameters() delegates to it so the
40+ // two cannot diverge.
41+ func (CodeGraphTool ) Schema () ToolSchema {
42+ return ToolSchema {
43+ Type : "object" ,
44+ Properties : map [string ]SchemaProperty {
45+ "action" : {Type : "string" , Enum : []interface {}{"search" , "callers" , "callees" , "impact" , "context" , "index" , "sync" , "trace" , "explore" , "files" , "status" , "stats" , "pagerank" , "centrality" , "communities" , "components" , "deadcode" , "coupling" , "cross_repo" , "semantic_search" , "hybrid_search" }, Description : "Action: search/find symbols, callers/who calls, callees/what it calls, impact/breakage radius, context/build task context, index/full re-index, sync/incremental update, trace/call path A→B, explore/multi-symbol source, files/list indexed, status/health check, stats/counts, pagerank/file importance, centrality/bridge files, communities/module clusters, components/isolated subsystems, deadcode/unused code, coupling/tightly coupled files, cross_repo/cross-repo dependencies, semantic_search/embedding-based search, hybrid_search/combined FTS5+semantic" },
46+ "query" : {Type : "string" , Description : "Search query, symbol name, or task description (for context/trace use 'from -> to')" },
47+ "node_id" : {Type : "string" , Description : "Node ID for callers/callees/impact" },
48+ "max_depth" : {Type : "integer" , Description : "Max traversal depth (default: 3)" },
49+ "max_nodes" : {Type : "integer" , Description : "Max nodes to return (default: 30)" },
50+ "root" : {Type : "string" , Description : "Project root directory (default: current dir)" },
51+ "from" : {Type : "string" , Description : "Source symbol for trace action" },
52+ "to" : {Type : "string" , Description : "Target symbol for trace action" },
53+ "max_files" : {Type : "integer" , Description : "Max files for explore action (default: 10)" },
54+ "dir" : {Type : "string" , Description : "Directory filter for files action" },
7055 },
71- "required" : []string {"action" },
56+ Required : []string {"action" },
7257 }
7358}
7459
60+ func (CodeGraphTool ) Parameters () map [string ]interface {} {
61+ return codeGraphSchema .ToJSONSchema ()
62+ }
63+
64+ // codeGraphSchema is the single source of truth for CodeGraph's input schema.
65+ var codeGraphSchema = CodeGraphTool {}.Schema ()
66+
7567func (CodeGraphTool ) Execute (ctx context.Context , input json.RawMessage ) (string , error ) {
76- var p struct {
77- Action string `json:"action"`
78- Query string `json:"query"`
79- NodeID string `json:"node_id"`
80- MaxDepth int `json:"max_depth"`
81- MaxNodes int `json:"max_nodes"`
82- Root string `json:"root"`
83- From string `json:"from"`
84- To string `json:"to"`
85- MaxFiles int `json:"max_files"`
86- Dir string `json:"dir"`
87- }
88- if err := json .Unmarshal (input , & p ); err != nil {
68+ p , err := DecodeInput [CodeGraphInput ]("CodeGraph" , input )
69+ if err != nil {
8970 return "" , err
9071 }
9172
0 commit comments