Skip to content

Commit d0593a0

Browse files
committed
feat(command)!: migrate to opencode v1.0.0 commands
seem to have lost a few unfortunately - namely copy, undo, redo
1 parent 2e66ef8 commit d0593a0

File tree

5 files changed

+51
-54
lines changed

5 files changed

+51
-54
lines changed

README.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ https://github.com/user-attachments/assets/4dd19151-89e4-4272-abac-6710dbc6edc1
4242
vim.keymap.set({ "n", "x" }, "<C-a>", function() require("opencode").ask("@this: ", { submit = true }) end, { desc = "Ask opencode" })
4343
vim.keymap.set({ "n", "x" }, "<C-x>", function() require("opencode").select() end, { desc = "Execute opencode action…" })
4444
vim.keymap.set({ "n", "x" }, "ga", function() require("opencode").prompt("@this") end, { desc = "Add to opencode" })
45-
vim.keymap.set("n", "<C-.>", function() require("opencode").toggle() end, { desc = "Toggle opencode" })
46-
vim.keymap.set("n", "<S-C-u>", function() require("opencode").command("messages_half_page_up") end, { desc = "opencode half page up" })
47-
vim.keymap.set("n", "<S-C-d>", function() require("opencode").command("messages_half_page_down") end, { desc = "opencode half page down" })
45+
vim.keymap.set({ "n", "t" }, "<C-.>", function() require("opencode").toggle() end, { desc = "Toggle opencode" })
46+
vim.keymap.set("n", "<S-C-u>", function() require("opencode").command("session.half.page.up") end, { desc = "opencode half page up" })
47+
vim.keymap.set("n", "<S-C-d>", function() require("opencode").command("session.half.page.down") end, { desc = "opencode half page down" })
4848
-- You may want these if you stick with the opinionated "<C-a>" and "<C-x>" above — otherwise consider "<leader>o".
4949
vim.keymap.set('n', '+', '<C-a>', { desc = 'Increment', noremap = true })
5050
vim.keymap.set('n', '-', '<C-x>', { desc = 'Decrement', noremap = true })
@@ -165,27 +165,26 @@ Input a prompt to send to `opencode`.
165165

166166
### 🧑‍🏫 Command — `require("opencode").command()`
167167

168-
Send a [command](https://opencode.ai/docs/keybinds) to `opencode`:
169-
170-
| Command | Description |
171-
|---------------------------|----------------------------------------------------------|
172-
| `session_new` | Start a new session |
173-
| `session_share` | Share the current session |
174-
| `session_interrupt` | Interrupt the current session |
175-
| `session_compact` | Compact the current session (reduce context size) |
176-
| `messages_page_up` | Scroll messages up by one page |
177-
| `messages_page_down` | Scroll messages down by one page |
178-
| `messages_half_page_up` | Scroll messages up by half a page |
179-
| `messages_half_page_down` | Scroll messages down by half a page |
180-
| `messages_first` | Jump to the first message in the session |
181-
| `messages_last` | Jump to the last message in the session |
182-
| `messages_copy` | Copy the last message in the session |
183-
| `messages_undo` | Undo the last message in the session |
184-
| `messages_redo` | Redo the last message in the session |
185-
| `input_clear` | Clear the TUI input |
186-
| `agent_cycle` | Cycle the selected agent |
187-
188-
> Supports *all* commands — these are just the most useful ones.
168+
Send a command to `opencode`:
169+
170+
| Command | Description |
171+
|-------------------------|----------------------------------------------------------|
172+
| `session.list` | List sessions |
173+
| `session.new` | Start a new session |
174+
| `session.share` | Share the current session |
175+
| `session.interrupt` | Interrupt the current session |
176+
| `session.compact` | Compact the current session (reduce context size) |
177+
| `session.page.up` | Scroll messages up by one page |
178+
| `session.page.down` | Scroll messages down by one page |
179+
| `session.half.page.up` | Scroll messages up by half a page |
180+
| `session.half.page.down` | Scroll messages down by half a page |
181+
| `session.first` | Jump to the first message in the session |
182+
| `session.last` | Jump to the last message in the session |
183+
| `session.undo` | Undo the last action in the current session |
184+
| `session.redo` | Redo the last undone action in the current session |
185+
| `prompt.submit` | Submit the TUI input |
186+
| `prompt.clear` | Clear the TUI input |
187+
| `agent.cycle` | Cycle the selected agent |
189188

190189
### 📝 Select — `require("opencode").select()`
191190

lua/opencode/api/command.lua

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
local M = {}
22

3+
---See available commands [here](https://github.com/sst/opencode/blob/dev/packages/opencode/src/cli/cmd/tui/event.ts).
34
---@alias opencode.Command
4-
---| 'session_new'
5-
---| 'session_share'
6-
---| 'session_interrupt'
7-
---| 'session_compact'
8-
---| 'messages_page_up'
9-
---| 'messages_page_down'
10-
---| 'messages_half_page_up'
11-
---| 'messages_half_page_down'
12-
---| 'messages_first'
13-
---| 'messages_last'
14-
---| 'messages_copy'
15-
---| 'messages_undo'
16-
---| 'messages_redo'
17-
---| 'input_clear'
18-
---| 'agent_cycle'
5+
---| 'session.list'
6+
---| 'session.new'
7+
---| 'session.share'
8+
---| 'session.interrupt'
9+
---| 'session.compact'
10+
---| 'session.page.up'
11+
---| 'session.page.down'
12+
---| 'session.half.page.up'
13+
---| 'session.half.page.down'
14+
---| 'session.first'
15+
---| 'session.last'
16+
---| 'session.undo'
17+
---| 'session.redo'
18+
---| 'prompt.submit'
19+
---| 'prompt.clear'
20+
---| 'agent.cycle'
1921

20-
---Send a [command](https://opencode.ai/docs/keybinds) to `opencode`.
22+
---Send a command to `opencode`.
2123
---
22-
---@param command opencode.Command|string The command to send to `opencode`.
24+
---@param command opencode.Command|string The command to send. Can be built-in or reference your custom commands.
2325
---@param callback fun(response: table)|nil
2426
function M.command(command, callback)
2527
require("opencode.cli.server").get_port(function(ok, port)

lua/opencode/cli/client.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end
141141
---@param port number
142142
---@param callback fun(response: table)|nil
143143
function M.tui_execute_command(command, port, callback)
144-
M.call(port, "/tui/execute-command", "POST", { command = command }, callback)
144+
M.call(port, "/tui/publish", "POST", { type = "tui.command.execute", properties = { command = command } }, callback)
145145
end
146146

147147
---@param prompt string

lua/opencode/config.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ local defaults = {
9595
this = { prompt = "@this" },
9696
},
9797
commands = {
98-
session_new = "Start a new session",
99-
session_share = "Share the current session",
100-
session_interrupt = "Interrupt the current session",
101-
session_compact = "Compact the current session (reduce context size)",
102-
messages_copy = "Copy the last message in the session",
103-
messages_undo = "Undo the last message in the session",
104-
messages_redo = "Redo the last message in the session",
105-
agent_cycle = "Cycle the selected agent",
98+
["session.new"] = "Start a new session",
99+
["session.share"] = "Share the current session",
100+
["session.interrupt"] = "Interrupt the current session",
101+
["session.compact"] = "Compact the current session (reduce context size)",
102+
["session.undo"] = "Undo the last action in the current session",
103+
["session.redo"] = "Redo the last undone action in the current session",
104+
["agent.cycle"] = "Cycle the selected agent",
106105
},
107106
input = {
108107
prompt = "Ask opencode: ",
@@ -153,9 +152,6 @@ local defaults = {
153152
filetype = "opencode_terminal",
154153
},
155154
},
156-
env = {
157-
OPENCODE_THEME = "system", -- HACK: Other themes have visual bugs in embedded terminals: https://github.com/sst/opencode/issues/445
158-
},
159155
---@param self opencode.provider.Snacks
160156
toggle = function(self)
161157
require("snacks.terminal").toggle(self.cmd, self)

lua/opencode/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function M.check()
1717
found_version = vim.trim(vim.split(found_version, "\n")[1])
1818
vim.health.ok("`opencode` executable found in `$PATH` with version `" .. found_version .. "`.")
1919

20-
local latest_tested_version = "0.15.8"
20+
local latest_tested_version = "v1.0.7"
2121
if vim.version.parse(latest_tested_version)[2] ~= vim.version.parse(found_version)[2] then
2222
vim.health.warn(
2323
"`opencode` found version `"

0 commit comments

Comments
 (0)