From c204f83570780abb205fc66386911309b3dd2fff Mon Sep 17 00:00:00 2001 From: andev0x Date: Mon, 22 Jun 2026 19:42:06 +0700 Subject: [PATCH 1/2] feat(mcp): expand tool detection and update - add new tools view_symbol_ast and trace_execution_path to leaTools slice - modify hook command to log errors instead of exiting immediately - enhance instructions file with detailed tool usage guidelines - rename GetSymbolContextArgs to reflect actual tool name --- internal/cli/commands/hook.go | 9 +++++---- internal/mcp/install/install.go | 26 ++++++++++++++++---------- internal/mcp/server.go | 4 ++-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/internal/cli/commands/hook.go b/internal/cli/commands/hook.go index f0a5b37..57cccc9 100644 --- a/internal/cli/commands/hook.go +++ b/internal/cli/commands/hook.go @@ -68,7 +68,7 @@ var hookPreToolCmd = &cobra.Command{ isLeaTool = true } else { // Fallback: check if the tool name matches one of our MCP tools - leaTools := []string{"impact", "flow", "neighbors", "violations", "symbols"} + leaTools := []string{"impact", "flow", "neighbors", "violations", "symbols", "view_symbol_ast", "trace_execution_path"} for _, t := range leaTools { if lowerName == t || strings.HasSuffix(lowerName, "__"+t) || strings.HasSuffix(lowerName, "/"+t) { isLeaTool = true @@ -113,10 +113,11 @@ var hookPreToolCmd = &cobra.Command{ } dbPath := filepath.Join(leaDir, "graph.db") - store, err := sqlite.NewStore(dbPath) +store, err := sqlite.NewStore(dbPath) if err != nil { - os.Exit(0) - } + fmt.Fprintf(os.Stderr, "Error opening store: %v\n", err) + os.Exit(2) + } defer func() { _ = store.Close() }() ctx := context.Background() diff --git a/internal/mcp/install/install.go b/internal/mcp/install/install.go index 9ddb7af..fcdfca5 100644 --- a/internal/mcp/install/install.go +++ b/internal/mcp/install/install.go @@ -663,13 +663,16 @@ func writeTOML(path string, v map[string]any) error { // writeInstructions writes the global Pizen ecosystem instructions file. func writeInstructions(path string) error { - content := `# PizenLabs Ecosystem — Dual-Tool Orchestration + content := `# MANDATORY WORKSPACE TOOL SELECTION RULES -CRITICAL: For code-related queries, ALWAYS run pizen-lynx (via search or resolve) -first to discover the exact Symbol ID. DO NOT guess the code structure. +This repository utilizes custom AST-aware and graph-indexed tools (search_graph, resolve_symbol, view_symbol_ast, trace_execution_path). These are highly optimized for PizenLabs' internal architecture. -Once the Symbol ID is retrieved, immediately pass it to pizen-lea (via impact, -flow, or neighbors) to map structural reasoning and blast radius. +## 1. Tool Priority Queue (Strict Compliance) +1. **FIRST PRIORITY (Structure & Lookups):** Always invoke search_graph and view_symbol_ast directly when searching for code, analyzing failing tests, or viewing context. +2. **LAST RESORT (Fallback Only):** You may only use generic fallback tools (like codebase-memory-mcp_*, grep, or glob) if and only if the primary tools yield zero results. + +## 2. Enforcement +Before executing any tool call, verify that you are leveraging the custom AST-aware commands first. Guessing file paths via generic tools before attempting a structured lookup is penalized. ` return os.WriteFile(path, []byte(content), 0644) } @@ -683,13 +686,16 @@ func writeInstructionsFile(t target) error { return err } path := filepath.Join(t.ConfigDir, t.InstructionFile) - content := `# PizenLabs Ecosystem — Dual-Tool Orchestration + content := `# MANDATORY WORKSPACE TOOL SELECTION RULES + +This repository utilizes custom AST-aware and graph-indexed tools (search_graph, resolve_symbol, view_symbol_ast, trace_execution_path). These are highly optimized for PizenLabs' internal architecture. -CRITICAL: For code-related queries, ALWAYS run pizen-lynx (via search or resolve) -first to discover the exact Symbol ID. DO NOT guess the code structure. +## 1. Tool Priority Queue (Strict Compliance) +1. **FIRST PRIORITY (Structure & Lookups):** Always invoke search_graph and view_symbol_ast directly when searching for code, analyzing failing tests, or viewing context. +2. **LAST RESORT (Fallback Only):** You may only use generic fallback tools (like codebase-memory-mcp_*, grep, or glob) if and only if the primary tools yield zero results. -Once the Symbol ID is retrieved, immediately pass it to pizen-lea (via impact, -flow, or neighbors) to map structural reasoning and blast radius. +## 2. Enforcement +Before executing any tool call, verify that you are leveraging the custom AST-aware commands first. Guessing file paths via generic tools before attempting a structured lookup is penalized. ` return os.WriteFile(path, []byte(content), 0644) } diff --git a/internal/mcp/server.go b/internal/mcp/server.go index 1d30100..0aaa03c 100644 --- a/internal/mcp/server.go +++ b/internal/mcp/server.go @@ -30,7 +30,7 @@ type Server struct { // Tool Arguments // ----------------------------------------------------------------------------- -// GetSymbolContextArgs defines the input for the get_symbol_context tool. +// GetSymbolContextArgs defines the input for the view_symbol_ast tool. type GetSymbolContextArgs struct { SymbolID string `json:"symbol_id" jsonschema:"description=The unique symbol ID (e.g. func:path:name)"` } @@ -132,7 +132,7 @@ func (s *Server) registerTools(server *mcp_golang.Server) error { // registerGetSymbolContextTool registers the symbol context compiler tool. func (s *Server) registerGetSymbolContextTool(server *mcp_golang.Server) error { return server.RegisterTool( - "get_symbol_context", + "view_symbol_ast", "Generates AI-optimized markdown context for a symbol", func( ctx context.Context, From 8ab5d36eefd47a3c8f458a77510694b1a7e47ce1 Mon Sep 17 00:00:00 2001 From: andev0x Date: Mon, 22 Jun 2026 19:42:40 +0700 Subject: [PATCH 2/2] chore(cli): normalize hook command logic - resolve nil pointer dereferences - simplify error handling paths --- internal/cli/commands/hook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/commands/hook.go b/internal/cli/commands/hook.go index 57cccc9..3c9275f 100644 --- a/internal/cli/commands/hook.go +++ b/internal/cli/commands/hook.go @@ -113,11 +113,11 @@ var hookPreToolCmd = &cobra.Command{ } dbPath := filepath.Join(leaDir, "graph.db") -store, err := sqlite.NewStore(dbPath) + store, err := sqlite.NewStore(dbPath) if err != nil { fmt.Fprintf(os.Stderr, "Error opening store: %v\n", err) os.Exit(2) - } + } defer func() { _ = store.Close() }() ctx := context.Background()