@statiolake/coc-lm-chat
v2.4.0
Published
Language Model Chat agent extension for coc.nvim
Downloads
21
Maintainers
Readme
@statiolake/coc-lm-chat
Interactive AI chat interface for coc.nvim with autonomous agent capabilities and tool integration.
Features
- 🗨️ Interactive Chat Interface: Real-time chat with language models in Neovim
- 🤖 Autonomous Agent: Self-operating agent with tool execution capabilities
- 🛠️ Built-in Tools: Time, calculation, and workspace information tools
- 📝 Markdown Rendering: Syntax-highlighted chat display with virtual text
- 🔄 Streaming Responses: Real-time token streaming for immediate feedback
- 🎯 Context-Aware: Maintains conversation history and context
- 📊 Sidebar Support: Optional sidebar chat interface
Installation
Prerequisites
- coc.nvim 0.0.82+
- Node.js 16+
- @statiolake/coc-lm-api: Required dependency
- @statiolake/coc-github-copilot: Recommended for GitHub Copilot models
Install via coc.nvim
:CocInstall @statiolake/coc-lm-api @statiolake/coc-github-copilot @statiolake/coc-lm-chatInstall via npm
npm install -g @statiolake/coc-lm-api @statiolake/coc-github-copilot @statiolake/coc-lm-chatSetup
- Install all required extensions
- Authenticate with your language model provider (e.g.,
:CocCommand copilot.signInfor GitHub Copilot) - Start chatting with
:CocCommand copilot.chat
Commands
| Command | Description |
|---------|-------------|
| :CocCommand copilot.chat | Open a new chat buffer |
| :CocCommand copilot.sendMessage | Send current buffer content as message |
| :CocCommand copilot.chatSideBarToggle | Toggle sidebar chat |
| :CocCommand copilot.chatSideBarOpen | Open sidebar chat |
| :CocCommand copilot.chatSideBarClose | Close sidebar chat |
| :CocCommand copilot.chatSideBarReset | Reset sidebar chat |
Usage
Basic Chat
- Open a chat session:
:CocCommand copilot.chat - Type your message in the input area (after the "You:" line)
- Press
<Enter>in normal mode to send the message - Watch the AI response stream in real-time
Chat Interface
The chat buffer displays:
# Copilot Chat
You:
[Type your message here]
Agent:
[AI response appears here]
Tool:
🔧 **toolName** {\"param\": \"value\"}
```tool output```
You:
[Next message...]Keybindings
In chat buffers:
<Enter>(normal mode): Send the current message<C-c>(normal mode): Clear conversation history
Sidebar Chat
For a persistent chat interface:
:CocCommand copilot.chatSideBarOpenThe sidebar provides a dedicated chat area that doesn't interfere with your main editing workflow.
Built-in Tools
The extension includes several built-in tools that the AI can use:
getCurrentTime
Get the current date and time.
{
\"name\": \"getCurrentTime\",
\"description\": \"Get the current date and time\",
\"inputSchema\": { \"type\": \"object\", \"properties\": {} }
}calculate
Perform mathematical calculations.
{
\"name\": \"calculate\",
\"description\": \"Perform mathematical calculations\",
\"inputSchema\": {
\"type\": \"object\",
\"properties\": {
\"expression\": { \"type\": \"string\", \"description\": \"Mathematical expression to evaluate\" }
},
\"required\": [\"expression\"]
}
}getWorkspaceInfo
Get information about the current workspace.
{
\"name\": \"getWorkspaceInfo\",
\"description\": \"Get information about the current workspace\",
\"inputSchema\": { \"type\": \"object\", \"properties\": {} }
}Configuration
Add to your coc-settings.json:
{
\"copilot.enable\": true
}Agent Configuration
The autonomous agent supports various configuration options that can be customized by extension developers:
maxIterations: Maximum number of tool execution iterations (default: 10)maxDepth: Maximum recursion depth for tool calls (default: 3)autoExecute: Whether to automatically execute tools (default: true)timeout: Timeout for tool execution in milliseconds (default: 30000)enableLogging: Enable detailed logging (default: true)
Architecture
Agent System
The extension implements a self-operating agent that can:
- Understand Requests: Parse user messages and determine appropriate actions
- Execute Tools: Automatically invoke registered tools based on context
- Chain Operations: Use tool results to inform subsequent actions
- Provide Feedback: Stream responses and tool execution results in real-time
Tool Integration
Tools are registered with the LM API and can be invoked by the language model:
// Tools are automatically registered on startup
lmApi.registerTool('getCurrentTime', getCurrentTimeTool);
lmApi.registerTool('calculate', calculateTool);
lmApi.registerTool('getWorkspaceInfo', getWorkspaceInfoTool);Message Flow
- User types message in chat buffer
- Message sent to language model via LM API
- Model processes request and may invoke tools
- Tool results fed back to model
- Final response streamed to chat buffer
Examples
Basic Conversation
You:
What time is it?
Agent:
Let me check the current time for you.
Tool:
🔧 **getCurrentTime** {}
2025-01-13T22:45:06.406Z
Agent:
The current time is January 13th, 2025 at 10:45 PM UTC.Mathematical Calculation
You:
Calculate 15% tip on a $45 bill
Agent:
I'll calculate that for you.
Tool:
🔧 **calculate** {\"expression\": \"45 * 0.15\"}
6.75
Agent:
A 15% tip on a $45 bill would be $6.75, making the total $51.75.Workspace Information
You:
What files are in my current workspace?
Agent:
Let me check your workspace information.
Tool:
🔧 **getWorkspaceInfo** {}
Current workspace: /home/user/project
Files: src/main.ts, package.json, README.md
Agent:
Your current workspace is `/home/user/project` and contains 3 files: src/main.ts, package.json, and README.md.Troubleshooting
No Language Models Available
- Ensure LM API extension is installed:
:CocInstall @statiolake/coc-lm-api - Install a language model provider:
:CocInstall @statiolake/coc-github-copilot - Authenticate with the provider:
:CocCommand copilot.signIn - Restart coc.nvim:
:CocRestart
Agent Not Responding
- Check if the agent is initialized properly
- Verify language models are available
- Check coc.nvim logs for errors:
:CocOpenLog
Tool Execution Errors
- Ensure tools are properly registered
- Check tool input parameters
- Verify workspace permissions for file operations
Development
# Clone the repository
git clone https://github.com/statiolake/coc-github-copilot.git
cd coc-github-copilot/coc-lm-chat
# Install dependencies
npm install
# Build
npm run build
# Watch mode for development
npm run watch
# Run linting
npm run lintAdding Custom Tools
Developers can extend the tool system by registering additional tools:
import type { LmApi } from '@statiolake/coc-lm-api';
// Register a custom tool
lmApi.registerTool('customTool', {
name: 'customTool',
description: 'Description of what the tool does',
inputSchema: {
type: 'object',
properties: {
param: { type: 'string', description: 'Parameter description' }
},
required: ['param']
},
invoke: async (options) => {
const { param } = options.input;
// Tool implementation
return {
content: [new LanguageModelTextPart(`Result: ${param}`)]
};
}
});Related Extensions
- @statiolake/coc-lm-api: Required Language Model API interface
- @statiolake/coc-github-copilot: GitHub Copilot integration providing language models
License
MIT
Repository
Acknowledgments
- coc.nvim for the extension framework
- Language model providers for AI capabilities
- The Vim/Neovim community for inspiration and feedback
