@buger/probe-chat v0.6.0-rc12
Probe Chat
A command-line and web interface for interacting with Probe code search using AI models through the Vercel AI SDK.
Features
- Interactive CLI chat interface
- Web-based chat interface with Markdown and syntax highlighting
- Support for Anthropic Claude, OpenAI, and Google Gemini models
- Force provider option to specify which AI provider to use
- Semantic code search using Probe's search capabilities
- AST-based code querying for finding specific code structures
- Code extraction for viewing complete context
- Session-based search caching for improved performance
- Token usage tracking
- Colorized output for better readability (CLI mode)
- Diagram generation with Mermaid.js (Web mode)
Prerequisites
- Node.js 18 or higher
- Probe CLI installed and available in your PATH
- An API key for Anthropic Claude, OpenAI, or Google Gemini
Installation
- Clone the repository
- Navigate to the
examples/chatdirectory - Install dependencies:
npm install- Create a
.envfile with your API keys:
# API Keys (uncomment and add your key)
ANTHROPIC_API_KEY=your_anthropic_api_key
# OPENAI_API_KEY=your_openai_api_key
# GOOGLE_API_KEY=your_google_api_key
# Force a specific provider (optional)
# FORCE_PROVIDER=anthropic # Options: anthropic, openai, google
# Debug mode (set to true for verbose logging)
DEBUG=false
# Default model (optional)
# For Anthropic: MODEL_NAME=claude-3-7-sonnet-latest
# For OpenAI: MODEL_NAME=gpt-4o-2024-05-13
# For Google: MODEL_NAME=gemini-2.0-flash
# API URL configuration (optional)
# Generic base URL for all providers (if provider-specific URL not set)
# LLM_BASE_URL=https://your-custom-endpoint.com
# Provider-specific URLs (override LLM_BASE_URL)
# ANTHROPIC_API_URL=https://your-anthropic-endpoint.com
# OPENAI_API_URL=https://your-openai-endpoint.com
# GOOGLE_API_URL=https://your-google-endpoint.com
# Folders to search (comma-separated list of paths)
# If not specified, the current directory will be used by default
# ALLOWED_FOLDERS=/path/to/folder1,/path/to/folder2
# Web interface settings (optional)
# PORT=8080
# AUTH_ENABLED=false
# AUTH_USERNAME=admin
# AUTH_PASSWORD=passwordUsage
CLI Mode
Start the chat interface in CLI mode:
node index.jsOr with npm:
npm startWeb Mode
Start the chat interface in web mode:
node index.js --webOr with npm:
npm run webYou can specify a custom port:
node index.js --web --port 3000You can also specify a path to the codebase you want to search:
node index.js /path/to/codebaseFor example, to search in a repository located at ../../tyk:
node index.js ../../tykThis will override any ALLOWED_FOLDERS setting in your .env file.
Command-line Options
-d, --debug: Enable debug mode for verbose logging-m, --model <model>: Specify the model to use (e.g.,claude-3-7-sonnet-latest,gpt-4o-2024-05-13,gemini-2.0-flash)-f, --force-provider <provider>: Force a specific provider (options:anthropic,openai,google)-w, --web: Run in web interface mode-p, --port <port>: Port to run web server on (default: 8080)--prompt <value>: Use a custom prompt (values:architect,code-review,support, or path to a file)[path]: Path to the codebase to search (overrides ALLOWED_FOLDERS)
Special Commands
During the chat, you can use these special commands:
exitorquit: End the chat sessionusage: Display token usage statisticsclear: Clear the chat history and start a new session
How It Works
This CLI tool uses the Vercel AI SDK to interact with AI models and provides them with tools to search and analyze your codebase:
- search: Searches code using Elasticsearch-like query syntax
- query: Searches code using AST-based pattern matching
- extract: Extracts code blocks from files with context
The AI is instructed to use these tools to answer your questions about the codebase, providing relevant code snippets and explanations.
Search Caching
The tool automatically generates a unique session ID for each chat session and passes it to the Probe CLI commands using the --session parameter. This enables caching of search results within a session, which can significantly improve performance when similar searches are performed multiple times.
The session ID is managed internally and doesn't require any user intervention. When you start a new chat session (or use the "clear" command), a new session ID is generated, and a new cache is created.
Provider Options
Probe Chat supports multiple AI providers, giving you flexibility in choosing which model to use for your code search and analysis:
Supported Providers
Anthropic Claude
- Default model:
claude-3-7-sonnet-latest - Environment variable:
ANTHROPIC_API_KEY - Best for: Complex code analysis, detailed explanations, and understanding nuanced patterns
- Default model:
OpenAI GPT
- Default model:
gpt-4o-2024-05-13 - Environment variable:
OPENAI_API_KEY - Best for: General code search, pattern recognition, and concise explanations
- Default model:
Google Gemini
- Default model:
gemini-2.0-flash - Environment variable:
GOOGLE_API_KEY - Best for: Fast responses, code generation, and efficient search
- Default model:
Forcing a Specific Provider
You can force Probe Chat to use a specific provider in two ways:
Using the command line option:
node index.js --force-provider anthropic node index.js --force-provider openai node index.js --force-provider googleUsing the environment variable: Add this to your
.envfile:FORCE_PROVIDER=anthropic # or openai, google
When forcing a provider, Probe Chat will verify that you have the corresponding API key set. If the API key is missing, it will display an error message.
Customizing Models
You can specify which model to use for each provider:
Using the command line option:
node index.js --model claude-3-7-sonnet-latest node index.js --model gpt-4o-2024-05-13 node index.js --model gemini-2.0-flashUsing the environment variable: Add this to your
.envfile:MODEL_NAME=claude-3-7-sonnet-latest
Note that the model must be compatible with the selected provider. If you force a specific provider and specify a model, the model must be available for that provider.
Custom API Endpoints
You can configure custom API endpoints for each provider:
Generic endpoint for all providers:
LLM_BASE_URL=https://your-custom-endpoint.comThis will be used for all providers unless a provider-specific URL is set.
Provider-specific endpoints:
ANTHROPIC_API_URL=https://your-anthropic-endpoint.com OPENAI_API_URL=https://your-openai-endpoint.com GOOGLE_API_URL=https://your-google-endpoint.comThese override the generic LLM_BASE_URL for their respective providers. Provider-specific URLs always take precedence over the generic LLM_BASE_URL.
Custom Prompts
Probe Chat allows you to customize the system prompt used by the AI assistant. This can be useful for tailoring the assistant's behavior to specific use cases or domains.
Predefined Prompts
By default, Probe Chat uses a "Code Explorer" prompt that's optimized for answering questions about code, explaining how systems work, and providing insights into code functionality.
The --prompt option accepts several predefined prompt types to specialize the assistant for different tasks:
code-explorer (default): Focuses on explaining and navigating code. The assistant will provide clear explanations of how code works, find relevant snippets, and trace function calls and data flow.
node index.js --prompt code-explorerNote: This is the default behavior, so you don't need to specify this prompt explicitly.
architect: Focuses on software architecture and design. The assistant will analyze code from an architectural perspective, identify patterns, suggest improvements, and create high-level design documentation.
node index.js --prompt architectcode-review: Focuses on code quality and best practices. The assistant will identify issues, suggest improvements, and ensure code follows best practices.
node index.js --prompt code-reviewsupport: Focuses on troubleshooting and problem-solving. The assistant will help diagnose errors, understand unexpected behaviors, and find solutions.
node index.js --prompt support
Each predefined prompt type maintains the core functionality of Probe Chat while specializing in a particular area of focus. The standard instructions for using tools and following the XML format are automatically included with all predefined prompts.
Custom Prompt Files
You can also provide a path to a file containing your own custom prompt:
node index.js --prompt /path/to/your/prompt.txtThe file should contain the complete system prompt that you want to use. This completely replaces the default system prompt. If you're creating a custom prompt, make sure to include instructions for using the available tools and following the XML format.
Example custom prompt file:
You are ProbeChat Custom, a specialized AI assistant for [your specific use case].
You focus on [specific area of expertise] and excel at [key strengths].
Follow these instructions carefully:
1. Analyze the user's request with a focus on [your specific focus area].
2. Use <thinking></thinking> tags to analyze the situation and determine the appropriate tool for each step.
3. Use the available tools step-by-step to fulfill the request.
4. Ensure to get really deep and understand the full picture before answering.
5. You MUST respond with exactly ONE tool call per message, using the specified XML format, until the task is complete.
6. Wait for the tool execution result (provided in the next user message in a <tool_result> block) before proceeding to the next step.
7. Once the task is fully completed, and you have confirmed the success of all steps, use the '<attempt_completion>' tool to provide the final result.
8. Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.
9. [Add any additional specialized instructions here]Environment Variables
You can also set a default prompt type using the environment variable:
PROMPT_TYPE=architectOr specify a path to a custom prompt file:
CUSTOM_PROMPT=/path/to/your/prompt.txtThe command-line option takes precedence over the environment variable. Provider-specific URLs always take precedence over the generic LLM_BASE_URL.
Example Queries
- "How does the config loading work?"
- "Show me all RPC handlers"
- "What does the process_file function do?"
- "Find all implementations of the extract tool"
- "Show me the main entry point of the application"
Architecture
index.js: Main entry point for both CLI and web interfacesprobeChat.js: Core chat functionalitywebServer.js: Web server implementationauth.js: Authentication middleware for web interfaceprobeTool.js: Tool definitions for code search, query, and extractiontokenCounter.js: Utility for tracking token usageindex.html: Web interface HTML template
License
Apache-2.0
5 months ago
5 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago