Skip to content

Commit 81ac51f

Browse files
feat(provider): add kitty provider (#77)
Co-authored-by: Nick van Dyke <nickjvandyke15@gmail.com>
1 parent fda7eed commit 81ac51f

File tree

6 files changed

+321
-56
lines changed

6 files changed

+321
-56
lines changed

README.md

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# opencode.nvim
22

3-
Integrate the [opencode](https://github.com/sst/opencode) AI assistant with Neovim — streamline editor-aware research, reviews, and requests.
3+
Integrate the [opencode](https://github.com/sst/opencode) AI assistant with Neovim — streamline editor-aware research, reviews, and requests.
44

5-
https://github.com/user-attachments/assets/01e4e2fc-bbfa-427e-b9dc-c1c1badaa90e
5+
<https://github.com/user-attachments/assets/01e4e2fc-bbfa-427e-b9dc-c1c1badaa90e>
66

77
## ✨ Features
88

9-
- Auto-connects to *any* `opencode` running inside Neovim's CWD, or provides an integrated instance.
9+
- Auto-connects to _any_ `opencode` running inside Neovim's CWD, or provides an integrated instance.
1010
- Input prompts with completions, highlights, and normal-mode support.
1111
- Select prompts from a library and define your own.
1212
- Inject relevant editor context (buffer, cursor, selection, diagnostics, etc.).
@@ -74,31 +74,31 @@ programs.nixvim = {
7474

7575
`opencode.nvim` replaces placeholders in prompts with the corresponding context:
7676

77-
| Placeholder | Context |
78-
| - | - |
79-
| `@this` | Visual selection if any, else cursor position |
80-
| `@buffer` | Current buffer |
81-
| `@buffers` | Open buffers |
82-
| `@visible` | Visible text |
83-
| `@diagnostics` | Current buffer diagnostics |
84-
| `@quickfix` | Quickfix list |
85-
| `@diff` | Git diff |
86-
| `@grapple` | [grapple.nvim](https://github.com/cbochs/grapple.nvim) tags |
77+
| Placeholder | Context |
78+
| -------------- | ----------------------------------------------------------- |
79+
| `@this` | Visual selection if any, else cursor position |
80+
| `@buffer` | Current buffer |
81+
| `@buffers` | Open buffers |
82+
| `@visible` | Visible text |
83+
| `@diagnostics` | Current buffer diagnostics |
84+
| `@quickfix` | Quickfix list |
85+
| `@diff` | Git diff |
86+
| `@grapple` | [grapple.nvim](https://github.com/cbochs/grapple.nvim) tags |
8787

8888
### Prompts
8989

9090
Select or reference prompts to review, explain, and improve your code:
9191

92-
| Name | Prompt |
93-
|------------------------------------|-----------------------------------------------------------|
94-
| `diagnostics` | Explain `@diagnostics` |
95-
| `diff` | Review the following git diff for correctness and readability: `@diff` |
96-
| `document` | Add comments documenting `@this` |
97-
| `explain` | Explain `@this` and its context |
98-
| `fix` | Fix `@diagnostics` |
99-
| `optimize` | Optimize `@this` for performance and readability |
100-
| `review` | Review `@this` for correctness and readability |
101-
| `test` | Add tests for `@this` |
92+
| Name | Prompt |
93+
| ------------- | ---------------------------------------------------------------------- |
94+
| `diagnostics` | Explain `@diagnostics` |
95+
| `diff` | Review the following git diff for correctness and readability: `@diff` |
96+
| `document` | Add comments documenting `@this` |
97+
| `explain` | Explain `@this` and its context |
98+
| `fix` | Fix `@diagnostics` |
99+
| `optimize` | Optimize `@this` for performance and readability |
100+
| `review` | Review `@this` for correctness and readability |
101+
| `test` | Add tests for `@this` |
102102

103103
### Provider
104104

@@ -112,14 +112,53 @@ If `opencode.nvim` can't find an existing `opencode`, it uses the configured pro
112112
```lua
113113
vim.g.opencode_opts = {
114114
provider = {
115-
enabled = "snacks", -- Default if `snacks.terminal` is available and enabled.
115+
enabled = "snacks",
116116
snacks = {
117-
-- Customize `snacks.terminal` to your liking.
117+
-- ...
118+
}
119+
}
120+
}
121+
```
122+
123+
</details>
124+
125+
<details>
126+
<summary><a href="https://sw.kovidgoyal.net/kitty/">kitty</a></summary>
127+
128+
```lua
129+
vim.g.opencode_opts = {
130+
provider = {
131+
enabled = "kitty",
132+
kitty = {
133+
-- ...
118134
}
119135
}
120136
}
121137
```
122138

139+
The kitty provider requires [remote control via a socket](https://sw.kovidgoyal.net/kitty/remote-control/#remote-control-via-a-socket) to be enabled.
140+
141+
You can do this either by running Kitty with the following command:
142+
143+
```bash
144+
# For Linux only:
145+
kitty -o allow_remote_control=yes --single-instance --listen-on unix:@mykitty
146+
147+
# Other UNIX systems:
148+
kitty -o allow_remote_control=yes --single-instance --listen-on unix:/tmp/mykitty
149+
```
150+
151+
OR, by adding the following to your `kitty.conf`:
152+
153+
```
154+
# For Linux only:
155+
allow_remote_control yes
156+
listen_on unix:@mykitty
157+
# Other UNIX systems:
158+
allow_remote_control yes
159+
listen_on unix:/tmp/kitty
160+
```
161+
123162
</details>
124163

125164
<details>
@@ -128,9 +167,9 @@ vim.g.opencode_opts = {
128167
```lua
129168
vim.g.opencode_opts = {
130169
provider = {
131-
enabled = "tmux", -- Default if inside a `tmux` session.
170+
enabled = "tmux",
132171
tmux = {
133-
options = "-h", -- Options to pass to `tmux split-window`.
172+
-- ...
134173
}
135174
}
136175
}
@@ -200,24 +239,24 @@ Prompt `opencode`.
200239

201240
Command `opencode`:
202241

203-
| Command | Description |
204-
|-------------------------|----------------------------------------------------------|
205-
| `session.list` | List sessions |
206-
| `session.new` | Start a new session |
207-
| `session.share` | Share the current session |
208-
| `session.interrupt` | Interrupt the current session |
209-
| `session.compact` | Compact the current session (reduce context size) |
210-
| `session.page.up` | Scroll messages up by one page |
211-
| `session.page.down` | Scroll messages down by one page |
212-
| `session.half.page.up` | Scroll messages up by half a page |
213-
| `session.half.page.down` | Scroll messages down by half a page |
214-
| `session.first` | Jump to the first message in the session |
215-
| `session.last` | Jump to the last message in the session |
216-
| `session.undo` | Undo the last action in the current session |
217-
| `session.redo` | Redo the last undone action in the current session |
218-
| `prompt.submit` | Submit the TUI input |
219-
| `prompt.clear` | Clear the TUI input |
220-
| `agent.cycle` | Cycle the selected agent |
242+
| Command | Description |
243+
| ------------------------ | -------------------------------------------------- |
244+
| `session.list` | List sessions |
245+
| `session.new` | Start a new session |
246+
| `session.share` | Share the current session |
247+
| `session.interrupt` | Interrupt the current session |
248+
| `session.compact` | Compact the current session (reduce context size) |
249+
| `session.page.up` | Scroll messages up by one page |
250+
| `session.page.down` | Scroll messages down by one page |
251+
| `session.half.page.up` | Scroll messages up by half a page |
252+
| `session.half.page.down` | Scroll messages down by half a page |
253+
| `session.first` | Jump to the first message in the session |
254+
| `session.last` | Jump to the last message in the session |
255+
| `session.undo` | Undo the last action in the current session |
256+
| `session.redo` | Redo the last undone action in the current session |
257+
| `prompt.submit` | Submit the TUI input |
258+
| `prompt.clear` | Clear the TUI input |
259+
| `agent.cycle` | Cycle the selected agent |
221260

222261
## 👀 Events
223262

lua/opencode/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ local defaults = {
139139
},
140140
},
141141
},
142+
kitty = {
143+
location = "default",
144+
},
142145
tmux = {
143146
options = "-h", -- Open in a horizontal split
144147
},

lua/opencode/provider/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@
3939
---The built-in provider to use, or `false` for none.
4040
---Default order:
4141
--- - `"snacks"` if `snacks.terminal` is available and enabled
42+
--- - `"kitty"` if in a `kitty` session with remote control enabled
4243
--- - `"tmux"` if in a `tmux` session
4344
--- - `false`
44-
---@field enabled? "snacks"|"tmux"|false
45+
---@field enabled? "snacks"|"kitty"|"tmux"|false
4546
---
4647
---@field snacks? opencode.provider.snacks.Opts
48+
---@field kitty? opencode.provider.kitty.Opts
4749
---@field tmux? opencode.provider.tmux.Opts
4850

4951
local M = {}
@@ -68,6 +70,7 @@ end
6870
function M.list()
6971
return {
7072
require("opencode.provider.snacks"),
73+
require("opencode.provider.kitty"),
7174
require("opencode.provider.tmux"),
7275
}
7376
end

0 commit comments

Comments
 (0)