diff --git a/AVANTE_INDEX.md b/AVANTE_INDEX.md deleted file mode 100644 index 218bcdf3..00000000 --- a/AVANTE_INDEX.md +++ /dev/null @@ -1,220 +0,0 @@ -# 📑 Avante Installation Index - -## Welcome! 👋 - -You've successfully installed **Avante** - a powerful AI code assistant for Neovim that integrates with your existing **Copilot Premium** subscription. - -## 📖 Documentation Map - -Read these in order: - -### 1️⃣ **START HERE**: `AVANTE_QUICK_START.md` - - 5-minute setup - - Essential keybindings - - Try it now! - - Common use cases - -### 2️⃣ **Full Setup**: `AVANTE_SETUP.md` - - Detailed configuration - - API key setup - - Project instructions - - Troubleshooting guide - -### 3️⃣ **Status Check**: `INSTALLATION_CHECKLIST.md` - - What was installed - - Configuration details - - Next steps - - Success criteria - -### 4️⃣ **Configuration**: `lua/custom/plugins/avante.lua` - - The actual plugin config - - Keybindings - - Customization options - - Inline documentation - ---- - -## ⚡ TL;DR - Get Started in 30 Seconds - -```bash -# 1. Make sure API key is set -echo $OPENAI_API_KEY - -# 2. Open Neovim -nvim - -# 3. Press these keys -at # Toggle Avante sidebar -v + select # Select some code -aa # Ask Avante a question -``` - ---- - -## 🎯 Main Keybindings - -| Shortcut | Action | -|----------|--------| -| `aa` | **A**sk about code | -| `ae` | **E**dit with Avante | -| `at` | **T**oggle sidebar | -| `ar` | **R**efactor | -| `ad` | **D**ocument | -| `af` | **F**ix issues | -| `ax` | E**X**ecute command | - ---- - -## 🚀 First-Time Setup Checklist - -- [ ] Read `AVANTE_QUICK_START.md` (5 min) -- [ ] Check API key: `echo $OPENAI_API_KEY` -- [ ] Open Neovim: `nvim` -- [ ] Press `at` to toggle sidebar -- [ ] Try `aa` on some code -- [ ] Run `:checkhealth avante` to verify -- [ ] Read `AVANTE_SETUP.md` for full guide - ---- - -## 🆚 Avante vs OpenCode - -**This is important!** You now have TWO AI tools: - -### Avante (`a*`) -- **UI**: Integrated sidebar in Neovim -- **Speed**: Instant, direct LLM access -- **Best for**: Quick edits, refactoring, questions -- **API**: OpenAI (gpt-4o) -- **Cost**: $0.15 per 1M input tokens (gpt-4o) - -### OpenCode (`o*`) -- **UI**: Terminal-based agent interface -- **Speed**: Slower, but more powerful -- **Best for**: Complex multi-step tasks, MCP tools -- **API**: Your configuration -- **Cost**: Depends on your setup - -**Tip**: Use Avante for quick tasks, OpenCode for complex workflows! - ---- - -## ⚙️ Configuration Files - -All config in: `/Users/stuartstephens/.config/nvim/` - -``` -nvim/ -├── lua/custom/plugins/ -│ ├── avante.lua ← Avante config (MAIN) -│ ├── opencode.lua ← OpenCode config (unchanged) -│ └── ... ← Other plugins -├── AVANTE_QUICK_START.md ← Quick reference -├── AVANTE_SETUP.md ← Full guide -├── INSTALLATION_CHECKLIST.md ← Status -└── AVANTE_INDEX.md ← This file! -``` - ---- - -## 🔑 API Key Setup - -Before first use, set your OpenAI API key: - -```bash -# Check if set -echo $OPENAI_API_KEY - -# Should output something like: sk-... -# If empty, add to ~/.zshrc or ~/.bash_profile - -export OPENAI_API_KEY="sk-proj-..." - -# Then restart terminal -source ~/.zshrc -``` - -**Get your key**: https://platform.openai.com/api-keys - ---- - -## 🐛 Troubleshooting - -### Sidebar won't appear? -```vim -:checkhealth avante -``` -Look for red ✗ and fix any issues listed - -### API key errors? -```bash -# Verify it's set correctly -echo $OPENAI_API_KEY -# Should show: sk-... - -# If not set, add to ~/.zshrc and restart terminal -``` - -### Want cheaper models? -Edit `lua/custom/plugins/avante.lua` and change: -```lua -model = 'gpt-4o-mini' -- Cheaper option -``` - -### More help? -Read `AVANTE_SETUP.md` → Troubleshooting section - ---- - -## 📊 Monitor Costs - -Since you're using your existing Copilot Premium: - -1. **Check usage**: https://platform.openai.com/account/billing/usage -2. **Set spending limit**: https://platform.openai.com/account/billing/limits -3. **Expected costs**: ~$0.15 per 1M input tokens - ---- - -## 🎓 Learn More - -- **Avante GitHub**: https://github.com/yetone/avante.nvim -- **OpenAI Models**: https://platform.openai.com/docs/models -- **Copilot Plans**: https://github.com/features/copilot - ---- - -## ✨ Pro Tips - -1. **Visual selection**: `v` + select + `aa` = instant context -2. **Project context**: Create `avante.md` in your project root -3. **Keyboard only**: Use `` to navigate between sidebar and code -4. **LSP integration**: Avante sees your diagnostics automatically -5. **Cost saving**: Use `gpt-4o-mini` for routine tasks - ---- - -## 📞 Quick Reference - -**Installation status**: ✅ Complete -**Plugin**: `yetone/avante.nvim` -**Version**: Latest (auto-updating) -**API**: OpenAI (Copilot Premium) -**Keybindings**: `a*` (zero conflicts) -**Documentation**: This index + 3 guides - ---- - -## 🎉 You're All Set! - -Next steps: -1. Read `AVANTE_QUICK_START.md` -2. Open Neovim: `nvim` -3. Press `at` to start -4. Have fun! 🚀 - ---- - -**Last updated**: Feb 1, 2025 -**Status**: Ready to use -**Need help?**: Check troubleshooting in `AVANTE_SETUP.md` diff --git a/AVANTE_QUICK_START.md b/AVANTE_QUICK_START.md deleted file mode 100644 index 9a97f297..00000000 --- a/AVANTE_QUICK_START.md +++ /dev/null @@ -1,161 +0,0 @@ -# 🚀 Avante Quick Start - -## ✅ You're All Set! - -Avante has been successfully installed and configured for your Neovim setup. - -## What You Get - -- **Native Neovim Integration**: No more switching to terminal -- **Copilot Premium Powered**: Uses your existing OpenAI API key -- **Instant Access**: Press `at` to toggle the sidebar -- **Full Context**: Works with your selected code, open buffers, and diagnostics - -## 🎯 Try It Now (5 seconds) - -1. Open Neovim: `nvim` -2. Open a code file -3. Press: `at` (toggle Avante sidebar) -4. Select some code with `v` key -5. Press: `aa` (ask Avante) -6. Type your question and press Enter! - -## 📋 Main Commands - -**Basic Workflow:** -``` -aa = Ask about selected code -ae = Edit/apply Avante suggestions -at = Toggle sidebar (on/off) -``` - -**Advanced Tasks:** -``` -ar = Refactor code -ad = Add documentation -af = Fix issues/bugs -ax = Use slash commands (e.g., /debug, /analyze) -``` - -## 💡 Common Use Cases - -### Quick Question -``` -1. Select function: v + select lines -2. Press aa -3. Ask: "What does this do?" -4. Read response in sidebar -``` - -### Refactor Code -``` -1. Place cursor on code -2. Press ar -3. Avante suggests improvements -4. Press 'a' to apply or review changes -``` - -### Get Documentation -``` -1. Select function -2. Press ad -3. Avante generates comments -4. Review and apply with 'a' key -``` - -### Use Your Project Context -- Create `avante.md` in your project root -- Avante will automatically use it for context -- Example: Tell it your tech stack, coding standards, etc. - -## 🔑 Important: Set Your API Key - -Before first use, make sure your OpenAI API key is set: - -```bash -# Check if it's set: -echo $OPENAI_API_KEY - -# If empty, add to ~/.zshrc or ~/.bash_profile: -export OPENAI_API_KEY="sk-..." - -# Then restart terminal or: -source ~/.zshrc -``` - -## 🎮 Sidebar Navigation - -Once `at` opens the sidebar: - -| Key | Action | -|-----|--------| -| `` | Switch between Avante and code | -| `` | Switch back | -| `a` | Apply suggestion | -| `A` | Apply all suggestions | -| Arrow keys | Navigate responses | -| `i` | Enter insert mode to edit prompt | - -## 🐛 Something Not Working? - -1. **Sidebar won't appear?** - ```vim - :checkhealth avante - ``` - Check for red X marks and fix any issues - -2. **API errors?** - - Verify key: `echo $OPENAI_API_KEY` should show `sk-...` - - Check balance: https://platform.openai.com/account/billing/overview - - Restart Neovim after setting the key - -3. **Need to change model?** - - Edit: `/Users/stuartstephens/.config/nvim/lua/custom/plugins/avante.lua` - - Find line with `model = 'gpt-4o'` - - Change to `'gpt-4o-mini'` for cheaper option - -## 🆚 Compare with OpenCode - -You now have TWO AI tools: - -**OpenCode** (`o*`): -- Agent-based orchestration -- Best for: Complex, multi-step tasks -- Terminal UI in a split -- Access to MCP tools - -**Avante** (`a*`): -- Direct LLM access -- Best for: Quick edits, refactoring -- Integrated sidebar -- Fast and focused - -Use whichever feels right for each task! - -## 📊 Monitor Your Costs - -Both tools use OpenAI API, so costs add up: -- Check usage: https://platform.openai.com/account/billing/usage -- Set spending limit: https://platform.openai.com/account/billing/limits - -## 🎓 Learn More - -- Full guide: Read `AVANTE_SETUP.md` in your nvim config directory -- Avante docs: https://github.com/yetone/avante.nvim -- OpenAI models: https://platform.openai.com/docs/models - -## ✨ Tips & Tricks - -1. **With selections**: Visual mode (`v`) + select + `aa` = instant context -2. **Multi-file**: Avante can see your whole open buffer context -3. **Diagnostics**: Avante can see LSP errors - use it to fix them -4. **Project instructions**: Create `avante.md` with your standards -5. **Keyboard only**: Everything works without mouse (vim-native) - ---- - -**You're ready to go! 🎉** - -Try it now: Open Neovim and press `at` - -Questions? Check `AVANTE_SETUP.md` for troubleshooting. diff --git a/AVANTE_SETUP.md b/AVANTE_SETUP.md deleted file mode 100644 index 5c4278ca..00000000 --- a/AVANTE_SETUP.md +++ /dev/null @@ -1,135 +0,0 @@ -# Avante Setup Guide - -## ✅ Installation Complete - -Avante has been installed and configured to use your existing **Copilot Premium** subscription (OpenAI API). - -## 🔑 Configuration - -Your Avante setup is configured to: -- **Provider**: Copilot (OpenAI - using your existing subscription) -- **Model**: gpt-4o -- **UI**: Native Neovim sidebar on the right -- **Dependencies**: Uses existing telescope, fzf-lua, snacks.nvim - -## ⌨️ Keybindings - -All Avante commands use the `a` prefix: - -| Keybinding | Action | -|------------|--------| -| `aa` | **A**sk Avante about code (selection or cursor) | -| `ae` | **E**dit with Avante | -| `at` | **T**oggle Avante sidebar | -| `ar` | **R**efactor code | -| `ax` | E**X**ecute slash command (e.g., `/code`, `/debug`) | -| `ad` | **D**ocument code | -| `af` | **F**ix code issues | - -## 🚀 First Use - -1. **Open Neovim** - Avante will be automatically loaded -2. **First time setup** - If you haven't set your OpenAI API key, Avante will prompt you -3. **Test it**: - - Select some code in visual mode: `v` + select code - - Press `aa` to ask Avante about it - - Or press `at` to toggle the sidebar - -## 🔐 API Key Setup - -Your existing `OPENAI_API_KEY` environment variable is used. If not set: - -1. Get your API key from https://platform.openai.com/api-keys -2. Add to your shell profile (`~/.zshrc` or `~/.bash_profile`): - ```bash - export OPENAI_API_KEY="your-api-key-here" - ``` -3. Restart your terminal or run: `source ~/.zshrc` - -## 📝 Project Instructions (Optional) - -Create an `avante.md` file in your project root to give Avante project-specific context: - -```markdown -# Project Instructions - -## Your Role -You are an expert developer specializing in [your tech stack]. - -## Your Mission -Help build and maintain [project description]. - -## Tech Stack -- Frontend: [your frontend tech] -- Backend: [your backend tech] -- Testing: [your testing framework] - -## Code Standards -- Use [your coding style] -- Follow [your project's patterns] -- Prioritize [performance/readability/etc] -``` - -## 🎯 Workflow Tips - -### Quick Ask About Code -``` -1. Place cursor on code -2. Press aa -3. Type your question -4. Press Enter -``` - -### Visual Selection -``` -1. Select code: v + arrow keys -2. Press aa or ar -3. Ask your question -``` - -### Toggle Sidebar -``` -Press at to toggle the sidebar on/off -Use to switch between Avante and your code -``` - -## 🔄 Comparing with OpenCode - -You now have both tools: - -| Tool | Best For | -|------|----------| -| **OpenCode** (`o*`) | Agent-orchestrated complex tasks, multi-step coding | -| **Avante** (`a*`) | Quick focused edits, refactoring, inline suggestions | - -## ❓ Troubleshooting - -### Avante not working? -- Run `:checkhealth avante` in Neovim -- Verify `OPENAI_API_KEY` is set: `echo $OPENAI_API_KEY` -- Restart Neovim - -### API errors? -- Check your API key is valid at https://platform.openai.com/api-keys -- Verify you have API credits/quota available -- Check OpenAI status: https://status.openai.com - -### Sidebar not appearing? -- Try `:lua require('avante.api').toggle()` manually -- Check dependencies are installed: `:checkhealth avante` - -## 📚 More Resources - -- **Avante Docs**: https://github.com/yetone/avante.nvim -- **Copilot Premium**: Verify you're on a paid plan at https://github.com/account/billing/overview -- **OpenAI Docs**: https://platform.openai.com/docs - -## Next Steps - -1. ✅ Plugin installed - you're here! -2. 🚀 **Try Avante** on a real coding task -3. 📊 Compare with OpenCode to find your workflow -4. 🎯 Customize keybindings if needed (edit `/lua/custom/plugins/avante.lua`) -5. 💡 Create `avante.md` for better context - -Happy coding! 🎉 diff --git a/lazy-lock.json b/lazy-lock.json index 8d226689..091391a2 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,57 +1,55 @@ { "LuaSnip": { "branch": "master", "commit": "dae4f5aaa3574bd0c2b9dd20fb9542a02c10471c" }, - "avante.nvim": { "branch": "main", "commit": "fde9a524457d17661618678f085649d4e8d3fd6f" }, "cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" }, "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "fd3e882e56956675c620898bf1ffcf4fcbe7ec84" }, "cmp-path": { "branch": "main", "commit": "c642487086dbd9a93160e1679a1327be111cbc25" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "c2526f1cde528a66e086ab1668e996d162c75f4f" }, + "conform.nvim": { "branch": "master", "commit": "086a40dc7ed8242c03be9f47fbcee68699cc2395" }, "copilot.vim": { "branch": "release", "commit": "a12fd5672110c8aa7e3c8419e28c96943ca179be" }, "dracula.nvim": { "branch": "main", "commit": "ae752c13e95fb7c5f58da4b5123cb804ea7568ee" }, "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, "fidget.nvim": { "branch": "main", "commit": "7fa433a83118a70fe24c1ce88d5f0bd3453c0970" }, "flutter-tools.nvim": { "branch": "main", "commit": "677cc07c16e8b89999108d2ebeefcfc5f539b73c" }, "friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" }, - "fzf-lua": { "branch": "main", "commit": "b4b1f05957a77f7662de834328827890c1a8c02b" }, - "git-blame.nvim": { "branch": "main", "commit": "5c536e2d4134d064aa3f41575280bc8a2a0e03d7" }, - "gitsigns.nvim": { "branch": "main", "commit": "abf82a65f185bd54adc0679f74b7d6e1ada690c9" }, + "git-blame.nvim": { "branch": "master", "commit": "39df33dad2cbf4eb9d17264bcda0c12e670ef1c2" }, + "gitsigns.nvim": { "branch": "main", "commit": "7c4faa3540d0781a28588cafbd4dd187a28ac6e3" }, "harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" }, - "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, + "indent-blankline.nvim": { "branch": "master", "commit": "d28a3f70721c79e3c5f6693057ae929f3d9c0a03" }, "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, - "lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" }, + "lazydev.nvim": { "branch": "main", "commit": "ff2cbcba459b637ec3fd165a2be59b7bbaeedf0d" }, "lua-utils.nvim": { "branch": "main", "commit": "e565749421f4bbb5d2e85e37c3cef9d56553d8bd" }, "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "c953789db7fd28eafe5eb5659846d34b5024b3cc" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "a676ab7282da8d651e175118bcf54483ca11e46d" }, "mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" }, "mason-tool-installer.nvim": { "branch": "main", "commit": "443f1ef8b5e6bf47045cb2217b6f748a223cf7dc" }, "mason.nvim": { "branch": "main", "commit": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65" }, - "mini.nvim": { "branch": "main", "commit": "9b935c218ddba02e5dc75c94f90143bce1f7c646" }, + "mini.nvim": { "branch": "main", "commit": "9990c41f10f54f29a888d13024c9f765037bde23" }, "neorg": { "branch": "main", "commit": "408fc04013a95da8f217cb0958a06b6a77c01743" }, "noice.nvim": { "branch": "main", "commit": "7bfd942445fb63089b59f97ca487d605e715f155" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-autopairs": { "branch": "master", "commit": "59bce2eef357189c3305e25bc6dd2d138c1683f5" }, "nvim-cmp": { "branch": "main", "commit": "da88697d7f45d16852c6b2769dc52387d1ddc45f" }, "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, - "nvim-dap": { "branch": "master", "commit": "e47878dcf1ccc30136b30d19ab19fe76946d61cd" }, + "nvim-dap": { "branch": "master", "commit": "a9d8cb68ee7184111dc66156c4a2ebabfbe01bc5" }, "nvim-dap-go": { "branch": "main", "commit": "b4421153ead5d726603b02743ea40cf26a51ed5f" }, "nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" }, - "nvim-lint": { "branch": "master", "commit": "bcd1a44edbea8cd473af7e7582d3f7ffc60d8e81" }, - "nvim-lspconfig": { "branch": "master", "commit": "3f58aeca0c6ece8a9fb8782ea3fcb6024f285be3" }, + "nvim-lint": { "branch": "master", "commit": "606b823a57b027502a9ae00978ebf4f5d5158098" }, + "nvim-lspconfig": { "branch": "master", "commit": "dd261ad5266ab5bbec249d21efeceda98ff3e1a6" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, - "nvim-treesitter-context": { "branch": "master", "commit": "64dd4cf3f6fd0ab17622c5ce15c91fc539c3f24a" }, - "nvim-web-devicons": { "branch": "master", "commit": "803353450c374192393f5387b6a0176d0972b848" }, - "opencode.nvim": { "branch": "main", "commit": "ed2a936b163df9e92ef210daad3a9ae89ca7e073" }, + "nvim-treesitter-context": { "branch": "master", "commit": "9a8e39993e3b895601bf8227124a48ea8268149e" }, + "nvim-web-devicons": { "branch": "master", "commit": "d7462543c9e366c0d196c7f67a945eaaf5d99414" }, + "opencode.nvim": { "branch": "main", "commit": "8804ffb81f9784dcd0e9af43a2068fb55282c4dd" }, "pathlib.nvim": { "branch": "main", "commit": "57e5598af6fe253761c1b48e0b59b7cd6699e2c1" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, - "snacks.nvim": { "branch": "main", "commit": "fe7cfe9800a182274d0f868a74b7263b8c0c020b" }, + "snacks.nvim": { "branch": "main", "commit": "a049339328e2599ad6e85a69fa034ac501e921b2" }, "telescope-file-browser.nvim": { "branch": "master", "commit": "3610dc7dc91f06aa98b11dca5cc30dfa98626b7e" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "todo-comments.nvim": { "branch": "main", "commit": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668" }, - "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }, + "vim-fugitive": { "branch": "master", "commit": "3b753cf8c6a4dcde6edee8827d464ba9b8c4a6f0" }, "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } } diff --git a/lua/custom/plugins/avante.lua b/lua/custom/plugins/avante.lua deleted file mode 100644 index 24007b66..00000000 --- a/lua/custom/plugins/avante.lua +++ /dev/null @@ -1,169 +0,0 @@ -return { - 'yetone/avante.nvim', - event = 'VeryLazy', - lazy = false, - version = false, -- set this if you want to always pull the latest change - opts = { - provider = 'copilot', - auto_suggestions_provider = nil, -- Disable auto-suggestions to save API calls - providers = { - claude = { - endpoint = 'https://api.anthropic.com', - model = 'claude-4-5-haiku', - timeout = 30000, - extra_request_body = { - temperature = 1, - max_tokens = 4096, - }, - }, - openai = { - endpoint = 'https://api.openai.com/v1', - model = 'gpt-4o', - timeout = 30000, - extra_request_body = { - temperature = 0, - max_tokens = 4096, - }, - }, - copilot = { - endpoint = 'https://api.openai.com/v1', - model = 'claude-haiku-4.5', - timeout = 30000, - extra_request_body = { - temperature = 0, - max_tokens = 4096, - }, - }, - }, - behaviour = { - auto_suggestions = false, -- Disable auto-suggestions - auto_set_highlight_group = true, - auto_set_keymaps = true, - support_paste_from_clipboard = false, - minimize_diff = true, -- Whether to only show the difference in changes - }, - mappings = { - --- When you band `change_keymap` to change `select_ai_model`, you replace the default key. - diff = { - ours = 'co', - theirs = 'ct', - all_theirs = 'ca', - both = 'cb', - cursor = 'cc', - next = ']x', - prev = '[x', - }, - suggestion = { - accept = '', - next = '', - prev = '', - dismiss = '', - }, - jump = { - next = ']]', - prev = '[[', - }, - submit = { - normal = '', - insert = '', - }, - sidebar = { - apply_all = 'A', - apply_cursor = 'a', - switch_windows = '', - reverse_switch_windows = '', - }, - }, - windows = { - ---@type "right" | "left" | "top" | "bottom" - position = 'right', -- the position of the sidebar - wrap = true, -- whether the lines in the sidebar are wrapped - width = 30, -- width of the sidebar in percentage - sidebar_header = { - enabled = true, -- whether the header is enabled - align = 'center', -- left, center, right - rounded = true, - }, - input = { - prefix = '> ', - height = 8, -- height of the input window in lines - }, - edit = { - border = 'rounded', - start_header = '--- Avante Edit ---', - end_header = '--- End Avante Edit ---', - }, - ask = { - floating = true, -- make ask window floating so it can have borders - start_header = '--- Avante Ask ---', - end_header = '--- End Avante Ask ---', - border = 'rounded', - }, - }, - highlights = { - ---@type AvanteConflictHighlights - diff = { - current = 'DiffText', - incoming = 'DiffAdd', - }, - }, - --- @class AvanteGetStatusFunction - get_status = function() - return '' - end, - }, - build = 'make', - dependencies = { - 'stevearc/dressing.nvim', - 'nvim-lua/plenary.nvim', - 'MunifTanjim/nui.nvim', - --- The below dependencies are optional, - 'nvim-telescope/telescope.nvim', -- for file selector - 'ibhagwan/fzf-lua', -- for file selector - 'folke/snacks.nvim', -- for input - }, - config = function(_, opts) - require('avante').setup(opts) - - -- Keybindings for Avante - local keymap = vim.keymap.set - local opts_desc = function(desc) - return { noremap = true, silent = true, desc = desc } - end - - -- Ask about code (with Copilot Premium) - keymap({ 'n', 'x' }, 'aa', function() - require('avante.api').ask() - end, opts_desc('[A]vante [A]sk')) - - -- Edit with Avante - keymap({ 'n', 'x' }, 'ae', function() - require('avante.api').edit() - end, opts_desc('[A]vante [E]dit')) - - -- Toggle Avante sidebar - keymap('n', 'at', function() - require('avante.api').toggle() - end, opts_desc('[A]vante [T]oggle')) - - -- Refactor code - keymap({ 'n', 'x' }, 'ar', function() - require('avante.api').ask('Refactor this code for better performance and readability.') - end, opts_desc('[A]vante [R]efactor')) - - -- Add/run slash command - keymap('n', 'ax', function() - require('avante.api').ask('/') - end, opts_desc('[A]vante e[X]ecute command')) - - -- Explain code - keymap({ 'n', 'x' }, 'ad', function() - require('avante.api').ask('Explain this code in detail.') - end, opts_desc('[A]vante [D]ocument')) - - -- Fix errors/issues - keymap({ 'n', 'x' }, 'af', function() - require('avante.api').ask('Fix any issues or errors in this code.') - end, opts_desc('[A]vante [F]ix')) - end, -} diff --git a/lua/custom/plugins/opencode.lua b/lua/custom/plugins/opencode.lua index 7fac1aa5..e31ca956 100644 --- a/lua/custom/plugins/opencode.lua +++ b/lua/custom/plugins/opencode.lua @@ -6,16 +6,99 @@ return { { 'folke/snacks.nvim', lazy = false, priority = 1000, opts = { input = {}, picker = {}, terminal = { enabled = true }, notifier = { top_down = false } } }, }, config = function() + local function pick_open_port() + local tcp = vim.uv.new_tcp() + if not tcp then + return 4096 + end + + local bind_result = tcp:bind('127.0.0.1', 0) + if bind_result ~= 0 and bind_result ~= true then + tcp:close() + return 4096 + end + + local sock = tcp:getsockname() + tcp:close() + if not sock or type(sock.port) ~= 'number' then + return 4096 + end + return sock.port + end + + local opencode_port = pick_open_port() + local opencode_cmd = string.format('NODE_TLS_REJECT_UNAUTHORIZED=0 opencode --port %d', opencode_port) + + local function run_opencode_terminal_action(action, label) + local ok, err = pcall(action) + if ok then + return + end + + local message = tostring(err) + if message:find('E444', 1, true) then + vim.cmd 'new' + local retried_ok, retried_err = pcall(action) + if retried_ok then + return + end + vim.notify(string.format('%s failed after retry: %s', label, retried_err), vim.log.levels.ERROR, { title = 'opencode.nvim' }) + return + end + + vim.notify(string.format('%s failed: %s', label, message), vim.log.levels.ERROR, { title = 'opencode.nvim' }) + end + vim.g.opencode_opts = { - terminal = { - -- Inline env var in command to bypass TLS verification on hotspot/public Wi-Fi - cmd = 'NODE_TLS_REJECT_UNAUTHORIZED=0 opencode', + server = { + port = opencode_port, + start = function() + run_opencode_terminal_action(function() + require('opencode.terminal').start(opencode_cmd) + end, 'OpenCode terminal start') + end, + stop = function() + run_opencode_terminal_action(function() + require('opencode.terminal').stop() + end, 'OpenCode terminal stop') + end, + toggle = function() + run_opencode_terminal_action(function() + require('opencode.terminal').toggle(opencode_cmd) + end, 'OpenCode terminal toggle') + end, }, } -- Required for `vim.g.opencode_opts.auto_reload` vim.opt.autoread = true + local scroll_group = vim.api.nvim_create_augroup('OpencodeTerminalScroll', { clear = true }) + vim.api.nvim_create_autocmd('TermOpen', { + group = scroll_group, + callback = function(args) + local terminal_name = vim.api.nvim_buf_get_name(args.buf) + if not terminal_name:find('opencode', 1, true) then + return + end + + local function tmap(keys, command, desc) + vim.keymap.set('t', keys, function() + require('opencode').command(command) + end, { buffer = args.buf, silent = true, desc = desc }) + end + + tmap('', 'session.half.page.up', 'Messages half page up') + tmap('', 'session.half.page.down', 'Messages half page down') + tmap('', 'session.half.page.up', 'Messages half page up') + tmap('', 'session.half.page.down', 'Messages half page down') + tmap('', 'session.half.page.up', 'Messages half page up') + tmap('', 'session.half.page.down', 'Messages half page down') + tmap('', 'session.page.up', 'Messages page up') + tmap('', 'session.page.down', 'Messages page down') + end, + }) + -- Recommended/example keymaps vim.keymap.set({ 'n', 'x' }, 'oa', function() require('opencode').ask('@this: ', { submit = true }) @@ -38,23 +121,23 @@ return { end, { desc = 'Select command' }) vim.keymap.set('n', 'on', function() - require('opencode').command 'session_new' + require('opencode').command 'session.new' end, { desc = 'New session' }) vim.keymap.set('n', 'oi', function() - require('opencode').command 'session_interrupt' + require('opencode').command 'session.interrupt' end, { desc = 'Interrupt session' }) vim.keymap.set('n', 'oA', function() - require('opencode').command 'agent_cycle' + require('opencode').command 'agent.cycle' end, { desc = 'Cycle selected agent' }) vim.keymap.set('n', '', function() - require('opencode').command 'messages_half_page_up' + require('opencode').command 'session.half.page.up' end, { desc = 'Messages half page up' }) vim.keymap.set('n', '', function() - require('opencode').command 'messages_half_page_down' + require('opencode').command 'session.half.page.down' end, { desc = 'Messages half page down' }) end, } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..b7ea3d5e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "nvim", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}