dotfiles bugabingas dorkfiles
owned by bugabinga
README Source History Refs Compare Notes Search fix(neovim): stop pivi saying terminal-only commands to the model
19e84617e2bdb6afb8fc699c2556223beac27fa4
Oliver Krylow <o.krylow@isp-insoft.de > · 18 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (9) neovim/lua/bugabinga/pivi/AGENTS.md Modified 99 99 27. **A session may be a stand-in.** The drive harness passes a stub session, so code reached from a command must not assume `session.buffer` is a live buffer.
100 100 This is exactly the class of regression the drive harness exists to catch; it caught it.
102 - 28. **Contract tests guard assumptions,** not features. They skip unless `pi` is on `PATH` and opt-in is set. When Pi changes behavior, they fail before users do.
102 + 28. **Pi runs the commands it owns and says the rest.** A `/name` sent as a prompt is dispatched when Pi owns the command and becomes a user message when it does not, so a name must be checked against `get_commands` before it is sent. Terminal-only commands such as `/model` are absent from that list; offer the capability natively instead of forwarding the name.
104 + 29. **A picker filters the text it is shown.** Formatting an item as `name description` makes every description compete with the name; show the name alone.
106 + 30. **Contract tests guard assumptions,** not features. They skip unless `pi` is on `PATH` and opt-in is set. When Pi changes behavior, they fail before users do.
neovim/lua/bugabinga/pivi/command.lua Modified 15 15 vim.notify(
'pivi: ' .. message, level
or vim.log.levels.INFO )
18 + local fetch_commands = function ( current, callback )
19 + current.request( {
type =
'get_commands' , },
function ( response )
21 + if response.success
and response.data
then 22 + for _, entry
in ipairs ( response.data.commands
or {} )
do 23 + table .
insert ( commands, entry )
26 + current.commands
= commands
27 + if callback
then callback( commands )
end 20 33 local require_session = function ()
57 + fetch_commands( created )
56 - local fetch_commands = function ( current, callback )
57 - current.request( {
type =
'get_commands' , },
function ( response )
59 - if response.success
and response.data
then 60 - for _, entry
in ipairs ( response.data.commands
or {} )
do 61 - table .
insert ( commands, entry )
64 - current.commands
= commands
65 - if callback
then callback( commands )
end 71 + local command_names = function ( current )
73 + for _, entry
in ipairs ( current
and current.commands
or {} )
do 74 + table .
insert ( found, entry.name )
80 + local knows = function ( current, name )
81 + for _, entry
in ipairs ( current
and current.commands
or {} )
do 82 + if entry.name
== name
then return true end 69 90 local run_slash_command = function ( current, name, arguments )
91 + if not knows( current, name )
then 93 + (
'pi has no command "%s" here; terminal-only commands are not offered over this channel' ):format( name ),
70 99 local message
= '/' .. name
71 100 if arguments
and arguments
~= '' then message
= message
.. ' ' .. arguments
end 72 101 local accepted, rejection
= current.submit( message, {
capture =
false , } )
73 102 if not accepted
then notify( rejection, vim.log.levels.WARN )
end 76 106 local pick_slash_command = function ( current, on_pick )
79 109 notify(
'no pi commands available' , vim.log.levels.WARN )
82 115 vim.ui.select( commands, {
83 116 prompt =
'pi command' ,
84 - format_item =
function ( entry )
85 - return '/' .. entry.name
.. ( entry.description
and (
' ' .. entry.description )
or '' )
117 + format_item =
function ( entry )
return '/' .. entry.name
end ,
87 118 },
function ( choice )
88 119 if not choice
then return end 174 205 transcript.decorate( win, current.name )
175 206 vim.wo[win].winbar
= '%#Title#π ' .. current.name
.. 176 207 '%* %#Comment#' .. ( vim.g.pivi_submit_hint
or 'send' )
.. ' / commands%*' 177 - vim.cmd.startinsert()
208 + if vim.g.pivi_start_insert
~= false then vim.cmd.startinsert()
end 233 264 local name, rest
= arguments:match
'^(%S+)%s*(.*)$' 235 - run_slash_command( current, name, rest )
236 - transcript.show( current.buffer )
267 + fetch_commands( current,
function ()
268 + if run_slash_command( current, name, rest )
then transcript.show( current.buffer )
end 239 272 pick_slash_command( current,
function ( choice )
252 285 local created
= session.create {
name = arguments
~= '' and arguments
or nil , }
286 + fetch_commands( created )
253 287 publish.set_active( created.name )
254 288 transcript.show( created.buffer )
255 289 notify(
'session ' .. created.name )
386 + subcommands.
model = function ( arguments )
387 + local current
= require_session()
388 + if not current
then return end 390 + current.request( {
type =
'get_available_models' , },
function ( response )
391 + if not response.success
or not response.data
then 392 + notify(
'pi did not offer a model list' , vim.log.levels.WARN )
396 + local models
= response.data.models
or {}
397 + if # models
== 0 then 398 + notify(
'pi has no models configured' , vim.log.levels.WARN )
402 + local choose = function ( model )
404 + {
type =
'set_model' ,
provider = model.provider,
modelId = model.id, },
406 + if answer.success
then 407 + notify( model.provider
.. '/' .. model.id )
409 + notify( answer.error
or 'pi refused the model' , vim.log.levels.ERROR )
415 + if arguments
~= '' then 416 + for _, model
in ipairs ( models )
do 417 + if ( model.provider
.. '/' .. model.id )
== arguments
or model.id
== arguments
then 422 + notify(
'no model matches ' .. arguments, vim.log.levels.WARN )
426 + vim.ui.select( models, {
427 + prompt =
'pi model' ,
428 + format_item =
function ( model )
return model.provider
.. '/' .. model.id
end ,
429 + },
function ( model )
430 + if model
then choose( model )
end 349 435 subcommands.
guide = function ()
350 436 guide.show( vim.api.nvim_get_current_buf() )
386 472 desc
= 'pivi native Pi integration' ,
387 473 complete = function ( lead, line )
388 - local before
= line:match
'^%s*Pi%s+(%S*)$' 389 - if before
== nil then return {}
end 390 - return vim.tbl_filter(
function ( candidate )
391 - return candidate:sub(
1 ,
# lead )
== lead
474 + local matching = function ( candidates )
475 + return vim.tbl_filter(
function ( candidate )
476 + return candidate:sub(
1 ,
# lead )
== lead
482 + local subcommand
= line:match
'^%s*Pi%s+(%S+)%s+%S*$' 483 + if subcommand
== 'command' then return matching( command_names( session.active() ) )
end 484 + if subcommand
== 'stop' or subcommand
== 'sessions' then return matching( session.list() )
end 485 + if subcommand
== 'follow' then return matching {
'window' ,
'tab' ,
'current' , }
end 487 + if line:match
'^%s*Pi%s+%S*$' == nil then return {}
end 488 + return matching( names() )
neovim/lua/bugabinga/pivi/guide.lua Modified 84 84 table .
insert ( written,
'' )
87 + if vim.bo[bufnr].filetype
== 'pivi-input' then 88 + table .
insert ( written,
'## ' .. glyph.insert
.. ' while writing' )
89 + table .
insert ( written,
'' )
90 + table .
insert ( written,
'The prompt opens in insert mode, so keys behind a leader need `<Esc>` first.' )
91 + table .
insert ( written,
'Set `vim.g.pivi_start_insert = false` to open in normal mode instead.' )
92 + table .
insert ( written,
'' )
87 95 table .
insert ( written,
'## ' .. glyph.list
.. ' ordinary neovim' )
88 96 table .
insert ( written,
'' )
89 97 table .
insert ( written,
'- `za` `zo` `zc` collapse or expand the entry under the cursor' )
neovim/lua/bugabinga/pivi/rpc.lua Modified 37 37 local guard = function ( handler,
... )
38 38 if not handler
then return end 39 39 local ok, failure
= pcall ( handler,
... )
40 - if not ok
then table .
insert ( failures,
tostring ( failure ) )
end 41 + local reported
= tostring ( failure )
42 + table .
insert ( failures, reported )
45 + if options.on_failure
then pcall ( options.on_failure, reported )
end 43 49 local dispatch = function ( records )
neovim/lua/bugabinga/pivi/session.lua Modified 251 251 spawn
= options.spawn,
252 252 on_event = function ( event ) handle_event( self, event )
end ,
253 253 on_stderr = function ( data ) self.last_stderr
= data
end ,
254 + on_failure = function ( failure )
255 + vim.notify(
'pivi: ' .. failure, vim.log.levels.ERROR )
254 257 on_exit = function ( code )
255 258 self.status
= status.stopped( self.status, code )
256 259 publish_status( self )
neovim/lua/bugabinga/pivi/skills/pivi/SKILL.md Modified 58 58 | show this guide | `<leader>p?` |
59 59 | collapse or expand | `za` `zo` `zc` `zR` `zM`, because entries are real folds |
61 - In the prompt, `<c-y>` accepts: the completion when one is offered, the prompt otherwise. `<CR>` in normal mode sends it.
61 + In the prompt, `<c-y>` accepts: the completion when one is offered, the prompt otherwise. `<CR>` in normal mode sends it too, so both work. The prompt opens in insert mode, so keys behind a leader need `<Esc>` first; `vim.g.pivi_start_insert = false` opens it in normal mode instead.
63 + `/model` and other terminal-only commands are not offered over this channel and are refused rather than said to the model; `:Pi model` switches model natively.
63 65 pivi chooses none of these. It publishes `<Plug>(pivi-goto-location)`, `<Plug>(pivi-inspect-entry)`, `<Plug>(pivi-next-entry)`, `<Plug>(pivi-previous-entry)`, `<Plug>(pivi-next-tool)`, `<Plug>(pivi-previous-tool)`, `<Plug>(pivi-compare-change)`, `<Plug>(pivi-toggle-entry)`, `<Plug>(pivi-guide)`, `<Plug>(pivi-submit)` and `<Plug>(pivi-accept)`, and the configuration decides the keys. A key is only reused where the local behaviour is the same idea as the global one.
neovim/lua/bugabinga/pivi_keys.lua Modified 65 - vim.g.pivi_submit_hint
= '<c-y> send' 65 + vim.g.pivi_submit_hint
= '<c-y> or <cr> send' 68 68 description =
'Open the pi prompt' ,
neovim/tests/bugabinga/pivi/command_spec.lua Modified 172 172 describe(
'slash commands' ,
function ()
173 - it(
'runs a named pi command through the session' ,
function ()
174 - local channel
= fake.new()
175 - session.create {
spawn = channel.spawn,
name =
'spec' ,
extension =
false ,
skill =
false ,
env = {}, }
177 - command.subcommands.command
'compact focus on edits' 180 - for _, entry
in ipairs ( channel.commands )
do 181 - if entry.type
== 'prompt' then table .
insert ( prompts, entry )
end 183 - assert .equal(
1 ,
# prompts )
184 - assert .equal(
'/compact focus on edits' , prompts[
1 ].message )
187 - it(
'offers only the commands pi reports for this session' ,
function ()
173 + it(
'refuses a name pi does not offer, instead of saying it to the model' ,
function ()
188 174 local channel
= fake.new()
189 175 local current
= session.create {
spawn = channel.spawn,
name =
'spec' ,
extension =
false ,
skill =
false ,
env = {}, }
192 - vim.ui.
select = function ( items, _, on_choice )
194 - on_choice( items[
1 ] )
197 - command.subcommands.command
'' 177 + command.subcommands.command
'model' 200 180 for _, entry
in ipairs ( channel.commands )
do 203 183 assert .is_table( request )
188 + command =
'get_commands' ,
190 + data = {
commands = { {
name =
'compact' ,
source =
'extension' , }, }, },
192 + assert .is_true( channel.settle(
function ()
return # notices
> 0 end ) )
195 + for _, entry
in ipairs ( channel.commands )
do 196 + assert .is_not.equal(
'prompt' , entry.type )
198 + assert .equal( vim.log.levels.WARN, notices[
# notices][
2 ] )
199 + assert .is_true( notices[
# notices][
1 ]:find(
'model' ,
1 ,
true )
~= nil )
202 + it(
'runs a name pi does offer' ,
function ()
203 + local channel
= fake.new()
204 + local current
= session.create {
spawn = channel.spawn,
name =
'spec' ,
extension =
false ,
skill =
false ,
env = {}, }
206 + command.subcommands.command
'compact focus on edits' 209 + for _, entry
in ipairs ( channel.commands )
do 210 + if entry.type
== 'get_commands' then request
= entry
end 215 + command =
'get_commands' ,
217 + data = {
commands = { {
name =
'compact' ,
source =
'extension' , }, }, },
220 + assert .is_true( channel.settle(
function ()
221 + for _, entry
in ipairs ( channel.commands )
do 222 + if entry.type
== 'prompt' then return true end 228 + for _, entry
in ipairs ( channel.commands )
do 229 + if entry.type
== 'prompt' then table .
insert ( prompts, entry )
end 231 + assert .equal(
1 ,
# prompts )
232 + assert .equal(
'/compact focus on edits' , prompts[
1 ].message )
235 + it(
'filters the picker on the command name alone' ,
function ()
236 + local channel
= fake.new()
237 + local current
= session.create {
spawn = channel.spawn,
name =
'spec' ,
extension =
false ,
skill =
false ,
env = {}, }
240 + vim.ui.
select = function ( items, options, on_choice )
241 + offered
= vim.tbl_map( options.format_item, items )
245 + command.subcommands.command
'' 248 + for _, entry
in ipairs ( channel.commands )
do 249 + if entry.type
== 'get_commands' then request
= entry
end 207 253 type =
'response' ,
208 254 command =
'get_commands' ,
210 256 data = {
commands = {
211 - {
name =
'compact' ,
description =
'Compact context' ,
source =
'extension' , },
212 - {
name =
'skill:wiki' ,
description =
'Wiki skill' ,
source =
'skill' , },
257 + {
name =
'compact' ,
description =
'Compact the conversation context' ,
source =
'extension' , },
216 261 assert .is_true( channel.settle(
function ()
return offered
~= nil end ) )
217 - assert .equal(
2 ,
# offered )
218 - assert .equal(
'compact' , offered[
1 ].name )
219 - assert .equal(
2 ,
# current.commands )
262 + assert .same( {
'/compact' , }, offered )
222 265 it(
'reports when pi offers no commands' ,
function ()
288 + describe(
'completion' ,
function ()
289 + it(
'completes subcommands at the first word' ,
function ()
291 + local offered
= vim.fn.getcompletion(
'Pi ' ,
'cmdline' )
292 + assert .is_true( vim.list_contains( offered,
'command' ) )
293 + assert .is_true( vim.list_contains( offered,
'model' ) )
296 + it(
'completes the names pi actually offers after `command`' ,
function ()
298 + local channel
= fake.new()
299 + local current
= session.create {
spawn = channel.spawn,
name =
'spec' ,
extension =
false ,
skill =
false ,
env = {}, }
300 + current.commands
= {
301 + {
name =
'compact' ,
source =
'extension' , },
302 + {
name =
'skill:wiki' ,
source =
'skill' , },
305 + local offered
= vim.fn.getcompletion(
'Pi command ' ,
'cmdline' )
307 + assert .is_true( vim.list_contains( offered,
'compact' ) )
308 + assert .is_true( vim.list_contains( offered,
'skill:wiki' ) )
311 + it(
'completes follow modes' ,
function ()
313 + local offered
= vim.fn.getcompletion(
'Pi follow ' ,
'cmdline' )
315 + assert .is_true( vim.list_contains( offered,
'window' ) )
316 + assert .is_true( vim.list_contains( offered,
'tab' ) )
245 320 describe(
'follow' ,
function ()
246 321 it(
'toggles follow mode and reports it' ,
function ()
247 322 command.subcommands.follow
'' neovim/tests/bugabinga/pivi/rpc_spec.lua Modified 165 165 assert .is_true( vim.wait(
2000 ,
function ()
return exited
end ,
5 ) )
168 + it(
'reports a handler that throws instead of swallowing it' ,
function ()
169 + local channel
= fake.new()
170 + local reported
= {}
172 + on_event =
function ()
error 'handler blew up' end ,
173 + on_failure =
function ( failure )
table .
insert ( reported, failure )
end ,
176 + channel.frame {
type =
'agent_start' , }
178 + assert .is_true( channel.settle(
function ()
return # reported
== 1 end ) )
179 + assert .is_true( reported[
1 ]:find(
'handler blew up' ,
1 ,
true )
~= nil )
168 182 it(
'closes stdin first so the child can exit on its own' ,
function ()
169 183 local channel
= fake.new()
170 184 local client
= start( channel )