dotfiles bugabingas dorkfiles
owned by bugabinga
README Source History Refs Reviews Compare Notes Search Review guide feat(neovim): let pivi run commands, name files, and reach pi capabilities
0634d896386563498c8ee4250e34d872f8e70c71
Oliver Krylow <o.krylow@isp-insoft.de > · 18 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (8) neovim/lua/bugabinga/pivi/AGENTS.md Modified +9 / −1 text lines
104 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.
106 + 30. **A written prompt is not always a prompt.** `bugabinga.pivi.compose` decides: a leading bang is a shell command through pi's `bash`, which accepts `excludeFromContext` even though `rpc.md` does not document it, and `@name` is expanded client-side because pi has no server-side `@` over this channel.
107 + Expansion reuses `edit.read`, so a named file is sent as its buffer content when it is open and unsaved; anything else would contradict every other pivi read.
108 + The wire shape is pi's own: `<file name="ABSOLUTE">
110 + </file>`, images as `images[]`.
112 + 31. **A local in Lua is not visible before its declaration.** Two functions have now been used above their definition and resolved to `nil` at runtime; if a helper is called from an earlier function, define it earlier.
114 + 32. **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 +261 / −0 text lines
8 8 local comparison
= require 'bugabinga.pivi.diff' 9 9 local guide
= require 'bugabinga.pivi.guide' 10 10 local layout
= require 'bugabinga.pivi.layout' 11 + local compose
= require 'bugabinga.pivi.compose' 12 13 local INPUT_FILETYPE
= 'pivi-input' 146 + local references = function ( cwd )
147 + local found, seen
= {}, {}
149 + for _, bufnr
in ipairs ( vim.api.nvim_list_bufs() )
do 150 + if vim.api.nvim_buf_is_loaded( bufnr )
and vim.bo[bufnr].buftype
== '' then 151 + local name
= vim.api.nvim_buf_get_name( bufnr )
153 + local shown
= vim.fn.fnamemodify( name,
':.' )
154 + if not seen[shown]
then 156 + table .
insert ( found, {
path = shown,
open =
true ,
modified = vim.bo[bufnr].modified, } )
162 + local ok, listed
= pcall ( vim.fn.systemlist, {
'git' ,
'-C' , cwd,
'ls-files' , } )
163 + if ok
and vim.v.shell_error
== 0 then 164 + for _, path
in ipairs ( listed )
do 165 + if not seen[path]
then 167 + table .
insert ( found, {
path = path,
open =
false , } )
175 + local pick_reference = function ( current, on_pick )
176 + local choices
= references( current.cwd
or vim.uv.cwd() )
177 + if # choices
== 0 then 178 + notify(
'nothing to refer to' , vim.log.levels.WARN )
182 + vim.ui.select( choices, {
183 + prompt =
'refer to' ,
184 + format_item =
function ( choice )
return choice.path
end ,
185 + },
function ( choice )
186 + if choice
then on_pick( choice.path )
end 142 190 local open_prompt = function ( current )
143 191 local existing
= prompts[current.name]
144 192 if existing
and vim.api.nvim_buf_is_valid( existing )
then 174 222 end, {
buffer = bufnr,
expr =
true ,
desc =
'pivi slash command entry' , } )
226 + vim.keymap.set(
'i' ,
'@' ,
function ()
227 + local line
= vim.api.nvim_get_current_line()
228 + local column
= vim.api.nvim_win_get_cursor(
0 )[
2 ]
229 + local before
= column
> 0 and line:sub( column, column )
or '' 230 + if before
~= '' and not before:match
'%s' then return '@' end 232 + vim.schedule(
function ()
233 + pick_reference( current,
function ( path )
234 + vim.api.nvim_put( {
'@' .. path
.. ' ' , },
'c' ,
true ,
true )
235 + vim.cmd.startinsert {
bang =
true , }
239 + end , {
buffer = bufnr,
expr =
true ,
desc =
'pivi refer to a file' , } )
176 241 guide.bind( bufnr )
178 243 local send = function ()
501 + subcommands.
bang = function ( arguments )
502 + local current
= require_session()
503 + if not current
then return end 504 + if arguments
== '' then 505 + notify(
'bang needs a command' , vim.log.levels.WARN )
509 + local accepted, rejection
= current.bash( arguments,
false )
510 + if not accepted
then 511 + notify( rejection, vim.log.levels.WARN )
514 + transcript.show( current.buffer )
518 + subcommands[
'bang!' ]
= function ( arguments )
519 + local current
= require_session()
520 + if not current
then return end 521 + if arguments
== '' then 522 + notify(
'bang needs a command' , vim.log.levels.WARN )
526 + local accepted, rejection
= current.bash( arguments,
true )
527 + if not accepted
then 528 + notify( rejection, vim.log.levels.WARN )
531 + transcript.show( current.buffer )
535 + subcommands.
thinking = function ( arguments )
536 + local current
= require_session()
537 + if not current
then return end 539 + current.request( {
type =
'get_available_thinking_levels' , },
function ( response )
540 + local levels
= response.success
and response.data
and response.data.levels
or {}
541 + if # levels
== 0 then 542 + notify(
'this model offers no thinking levels' , vim.log.levels.WARN )
546 + local choose = function ( level )
547 + current.request( {
type =
'set_thinking_level' ,
level = level, },
function ( answer )
548 + if answer.success
then 549 + notify(
'thinking ' .. level )
551 + notify( answer.error
or 'pi refused the level' , vim.log.levels.ERROR )
556 + if arguments
~= '' then 557 + if vim.list_contains( levels, arguments )
then 558 + choose( arguments )
560 + notify(
'no such level: ' .. arguments, vim.log.levels.WARN )
565 + vim.ui.select( levels, {
prompt =
'thinking' , },
function ( level )
566 + if level
then choose( level )
end 572 + subcommands.
compact = function ( arguments )
573 + local current
= require_session()
574 + if not current
then return end 576 + local request
= {
type =
'compact' , }
577 + if arguments
~= '' then request.customInstructions
= arguments
end 579 + notify
'compacting' 580 + current.request( request,
function ( response )
581 + if not response.success
then 582 + notify( response.error
or 'compaction failed' , vim.log.levels.ERROR )
585 + local data
= response.data
or {}
586 + notify( (
'compacted %s to about %s tokens' ):format(
587 + tostring ( data.tokensBefore
or '?' ),
tostring ( data.estimatedTokensAfter
or '?' )
593 + subcommands.
autocompact = function ( arguments )
594 + local current
= require_session()
595 + if not current
then return end 597 + local wanted
= arguments
~= 'off' 598 + current.request( {
type =
'set_auto_compaction' ,
enabled = wanted, },
function ( response )
599 + if response.success
then 600 + notify(
'automatic compaction ' .. ( wanted
and 'on' or 'off' ) )
602 + notify( response.error
or 'pi refused' , vim.log.levels.ERROR )
608 + subcommands.
session = function ()
609 + local current
= require_session()
610 + if not current
then return end 612 + current.request( {
type =
'get_session_stats' , },
function ( response )
613 + if not response.success
or not response.data
then 614 + notify(
'pi did not report session statistics' , vim.log.levels.WARN )
618 + local data
= response.data
619 + local tokens
= data.tokens
or {}
620 + local usage
= data.contextUsage
or {}
622 + 'session ' .. tostring ( data.sessionId
or current.name ),
623 + (
'messages %s, tool calls %s' ):format(
624 + tostring ( data.totalMessages
or '?' ),
tostring ( data.toolCalls
or '?' )
626 + (
'tokens %s in, %s out, %s total' ):format(
627 + tostring ( tokens.input
or 0 ),
tostring ( tokens.output
or 0 ),
tostring ( tokens.total
or 0 )
629 + (
'cost %s' ):format(
tostring ( data.cost
or 0 ) ),
631 + if usage.percent
then 632 + table .
insert ( told, (
'context %s%% of %s' ):format(
633 + tostring ( usage.percent ),
tostring ( usage.contextWindow )
636 + notify(
table .
concat ( told,
'\n' ) )
641 + subcommands.
name = function ( arguments )
642 + local current
= require_session()
643 + if not current
then return end 644 + if arguments
== '' then 645 + notify(
'name needs a name' , vim.log.levels.WARN )
649 + current.request( {
type =
'set_session_name' ,
name = arguments, },
function ( response )
650 + if response.success
then 651 + notify(
'named ' .. arguments )
653 + notify( response.error
or 'pi refused the name' , vim.log.levels.ERROR )
660 + subcommands.
new = function ()
661 + local current
= require_session()
662 + if not current
then return end 664 + current.request( {
type =
'new_session' , },
function ( response )
665 + if not response.success
then 666 + notify( response.error
or 'pi refused a new session' , vim.log.levels.ERROR )
669 + if response.data
and response.data.cancelled
then 670 + notify(
'an extension cancelled the new session' , vim.log.levels.WARN )
673 + transcript.clear( current.buffer )
674 + notify
'new conversation' 679 + subcommands.
export = function ( arguments )
680 + local current
= require_session()
681 + if not current
then return end 683 + local request
= {
type =
'export_html' , }
684 + if arguments
~= '' then request.outputPath
= vim.fn.expand( arguments )
end 686 + current.request( request,
function ( response )
687 + if response.success
and response.data
then 688 + notify(
'exported to ' .. tostring ( response.data.path ) )
690 + notify( response.error
or 'export failed' , vim.log.levels.ERROR )
435 695 subcommands.
guide = function ()
436 696 guide.show( vim.api.nvim_get_current_buf() )
483 743 if subcommand
== 'command' then return matching( command_names( session.active() ) )
end 484 744 if subcommand
== 'stop' or subcommand
== 'sessions' then return matching( session.list() )
end 485 745 if subcommand
== 'follow' then return matching {
'window' ,
'tab' ,
'current' , }
end 746 + if subcommand
== 'autocompact' then return matching {
'on' ,
'off' , }
end 487 748 if line:match
'^%s*Pi%s+%S*$' == nil then return {}
end 488 749 return matching( names() )
neovim/lua/bugabinga/pivi/compose.lua Added new file mode 100644+124 / −0 text lines
1 + local edit
= require 'bugabinga.pivi.edit' 16 + local parse = function ( text )
17 + vim.validate(
'text' , text,
'string' )
18 + local written
= vim.trim( text )
20 + local quiet
= written:match
'^!!%s*(.*)$' 22 + return {
kind =
'bash' ,
command = vim.trim( quiet ),
exclude =
true , }
25 + local loud
= written:match
'^!%s*(.*)$' 27 + return {
kind =
'bash' ,
command = vim.trim( loud ),
exclude =
false , }
30 + return {
kind =
'prompt' ,
message = written, }
33 + local image_type = function ( path )
34 + local suffix
= path:match
'%.([%a%d]+)$' 35 + if not suffix
then return nil end 36 + return IMAGES[suffix:lower()]
39 + local absolute = function ( path, cwd )
40 + local expanded
= vim.fn.expand( path )
41 + if expanded:match
'^/' or expanded:match
'^%a:' then return vim.fs.normalize( expanded )
end 42 + return vim.fs.normalize( ( cwd
or vim.uv.cwd() )
.. '/' .. expanded )
48 + local contents = function ( path )
49 + local text
= edit.read( path )
53 + local encode_image = function ( path )
54 + local read
= io .
open ( path,
'rb' )
55 + if not read
then return nil end 56 + local bytes
= read:read
'*a' 58 + if not bytes
or bytes
== '' then return nil end 60 + local ok, encoded
= pcall ( vim.base64.encode, bytes )
61 + if not ok
then return nil end 73 + local expand = function ( text, options )
74 + vim.validate(
'text' , text,
'string' )
75 + options
= options
or {}
81 + local message
= text:gsub(
'@([%w%._%-~/\\:]+)' ,
function ( reference )
82 + local path
= absolute( reference, options.cwd )
84 + local mime
= image_type( path )
86 + local data
= encode_image( path )
88 + table .
insert ( missing, reference )
89 + return '@' .. reference
91 + table .
insert ( images, {
type =
'image' ,
data = data,
mimeType = mime, } )
92 + return (
'<file name="%s"></file>' ):format( path )
95 + local body
= contents( path )
97 + table .
insert ( missing, reference )
98 + return '@' .. reference
101 + if attached[path]
then return (
'<file name="%s"></file>' ):format( path )
end 102 + attached[path]
= true 103 + return (
'<file name="%s">\n%s\n</file>' ):format( path, body )
106 + return message, images, missing
110 + local references = function ( text )
112 + for reference
in ( text
or '' ):gmatch
'@([%w%._%-~/\\:]+)' do 113 + table .
insert ( found, reference )
119 + image_types = IMAGES,
122 + references = references,
123 + absolute = absolute,
neovim/lua/bugabinga/pivi/session.lua Modified +53 / −2 text lines
10 10 local follow
= require 'bugabinga.pivi.follow' 11 11 local edit
= require 'bugabinga.pivi.edit' 12 12 local runtime
= require 'bugabinga.pivi.runtime' 13 + local compose
= require 'bugabinga.pivi.compose' 13 14 local entry
= require 'bugabinga.pivi.entry' 14 15 local render
= require 'bugabinga.pivi.render' 15 16 local fold
= require 'bugabinga.pivi.fold' 297 + local run_bash = function ( self, command, exclude, callback )
298 + vim.validate(
'command' , command,
'string' )
299 + if command
== '' then return false ,
'nothing to run' end 301 + local id
= begin( self,
'tool' , {
302 + tool = exclude
and 'bang!' or 'bang' ,
303 + args = {
command = command, },
306 + entry.line( self.buffer, id, tool.headline( entry.meta( self.buffer, id ) ) )
308 + self.client.request(
309 + {
type =
'bash' ,
command = command,
excludeFromContext = exclude
== true , },
310 + function ( response )
311 + local data
= response.data
or {}
312 + entry.annotate( self.buffer, id, {
313 + result = {
content = { {
type =
'text' ,
text = data.output
or '' , }, }, },
314 + failed = response.success
~= true or ( data.exitCode
~= nil and data.exitCode
~= 0 ),
315 + exit = data.exitCode,
317 + entry.rewrite( self.buffer, id, tool.body( entry.meta( self.buffer, id ) ) )
319 + if callback
then callback( response )
end 314 347 return false ,
'unknown delivery "' .. tostring ( delivery )
.. '"; use steer or follow_up' 351 + if options.compose
~= false then 352 + local intent
= compose.parse( text )
353 + if intent.kind
== 'bash' then 354 + return run_bash( self, intent.command, intent.exclude )
317 358 local snapshot
= options.snapshot
318 359 if snapshot
== nil and options.capture
~= false then 319 360 snapshot
= context.snapshot( options.source )
322 - local message
= text
363 + local expanded, images, missing
= text,
nil , {}
364 + if options.compose
~= false then 365 + expanded, images, missing
= compose.expand( text, {
cwd = self.cwd, } )
366 + for _, reference
in ipairs ( missing )
do 367 + vim.notify(
'pivi: cannot read @' .. reference, vim.log.levels.WARN )
371 + local message
= expanded
324 - message
= context.render( snapshot )
.. text
373 + message
= context.render( snapshot )
.. expanded
327 376 render_submission( self, text )
335 384 command
= {
type =
'prompt' ,
message = message, }
386 + if images
and # images
> 0 then command.images
= images
end 338 388 table .
insert ( self.submissions, {
text = text,
delivery = delivery,
snapshot = snapshot, } )
410 460 self.submissions
= self.submissions
or {}
411 461 self.
submit = function ( text, options )
return submit( self, text, options )
end 412 462 self.
request = function ( command, callback )
return request( self, command, callback )
end 463 + self.
bash = function ( command, exclude, callback )
return run_bash( self, command, exclude, callback )
end 413 464 self.
abort = function ( callback )
return abort( self, callback )
end 414 465 self.
clear_queue = function ( callback )
return clear_queue( self, callback )
end 415 466 self.
refresh = function ( callback )
return refresh( self, callback )
end neovim/lua/bugabinga/pivi/skills/pivi/SKILL.md Modified +13 / −1 text lines
61 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 + `/model` and other terminal-only commands are not offered over this channel and are refused rather than said to the model; `:Pi model` and `:Pi thinking` reach the same capability natively.
65 + In a prompt, a leading `!` runs the rest as a shell command through pi and keeps the output in the conversation; `!!` runs it and keeps the output out. `@` names a file: it opens a picker when it starts a word, and stays an ordinary character inside one. A named file is sent as its buffer content when it is open and unsaved, because that is what every other pivi read answers with; an image is attached rather than inlined.
65 67 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.
80 82 | `:Pi abort` / `queue` / `clear` | run and queue control |
81 83 | `:Pi diff` | compare the change of the entry under the cursor |
82 84 | `:Pi guide` | show the guide of keys and commands |
85 + | `:Pi bang {cmd}` | run a shell command through pi, output joins the conversation |
86 + | `:Pi bang! {cmd}` | the same, kept out of the conversation |
87 + | `:Pi model [name]` | switch model |
88 + | `:Pi thinking [level]` | switch thinking level |
89 + | `:Pi compact [instructions]` | compact the conversation |
90 + | `:Pi autocompact on\|off` | automatic compaction |
91 + | `:Pi session` | tokens, cost and context so far |
92 + | `:Pi name {name}` | name the session |
93 + | `:Pi new` | fresh conversation in the running process |
94 + | `:Pi export [path]` | write the conversation out |
83 95 | `:Pi follow [window\|tab\|current]` | toggle follow mode |
85 97 `<Plug>(pivi-show)`, `<Plug>(pivi-prompt)`, `<Plug>(pivi-abort)`, and `<Plug>(pivi-follow)` exist; pivi sets no global mappings.
neovim/tests/bugabinga/pivi/compose_spec.lua Added new file mode 100644+129 / −0 text lines
2 + local compose
= require 'bugabinga.pivi.compose' 4 + local temp_file = function ( lines, suffix )
5 + local path
= vim.fs.normalize( vim.fn.tempname()
.. ( suffix
or '.lua' ) )
6 + vim.fn.writefile( lines, path )
10 + describe(
'pivi compose' ,
function ()
11 + after_each(
function ()
12 + vim.cmd
'silent! %bwipeout!' 15 + describe(
'what was written' ,
function ()
16 + it(
'reads a leading bang as a command to run' ,
function ()
17 + local intent
= compose.parse
'!just test' 19 + assert .equal(
'bash' , intent.kind )
20 + assert .equal(
'just test' , intent.command )
21 + assert .is_false( intent.exclude )
24 + it(
'reads a doubled bang as a command kept out of the conversation' ,
function ()
25 + local intent
= compose.parse
'!!git status' 27 + assert .equal(
'bash' , intent.kind )
28 + assert .equal(
'git status' , intent.command )
29 + assert .is_true( intent.exclude )
32 + it(
'tolerates space after the bang' ,
function ()
33 + assert .equal(
'ls -la' , compose.parse(
'! ls -la' ).command )
34 + assert .equal(
'ls' , compose.parse(
' !! ls ' ).command )
37 + it(
'reads anything else as something said' ,
function ()
38 + local intent
= compose.parse
'rename greet to hail' 40 + assert .equal(
'prompt' , intent.kind )
41 + assert .equal(
'rename greet to hail' , intent.message )
44 + it(
'does not mistake a bang inside a sentence for a command' ,
function ()
45 + assert .equal(
'prompt' , compose.parse(
'fix this!' ).kind )
46 + assert .equal(
'prompt' , compose.parse(
'why not use !! here' ).kind )
50 + describe(
'what was referred to' ,
function ()
51 + it(
'names every reference' ,
function ()
52 + assert .same( {
'a.lua' ,
'src/b.lua' , }, compose.references
'compare @a.lua with @src/b.lua' )
53 + assert .same( {}, compose.references
'nothing here' )
56 + it(
'replaces a reference with the file itself' ,
function ()
57 + local path
= temp_file {
'local value = 1' , }
59 + local message, images, missing
= compose.expand(
'look at @' .. path )
61 + assert .same( {}, missing )
62 + assert .same( {}, images )
63 + assert .is_true( message:find(
'<file name="' .. path
.. '">' ,
1 ,
true )
~= nil )
64 + assert .is_true( message:find(
'local value = 1' ,
1 ,
true )
~= nil )
65 + assert .is_true( message:find(
'</file>' ,
1 ,
true )
~= nil )
68 + it(
'prefers what the buffer holds over what the file holds' ,
function ()
69 + local path
= temp_file {
'on disk' , }
70 + vim.cmd(
'edit! ' .. vim.fn.fnameescape( path ) )
71 + vim.api.nvim_buf_set_lines(
0 ,
0 ,
- 1 ,
false , {
'not saved yet' , } )
73 + local message
= compose.expand(
'read @' .. path )
75 + assert .is_true( message:find(
'not saved yet' ,
1 ,
true )
~= nil )
76 + assert .is_nil( message:find(
'on disk' ,
1 ,
true ) )
79 + it(
'resolves a relative reference against the session directory' ,
function ()
80 + local path
= temp_file {
'relative' , }
81 + local directory
= vim.fs.dirname( path )
83 + local message
= compose.expand(
'@' .. vim.fs.basename( path ), {
cwd = directory, } )
85 + assert .is_true( message:find(
'relative' ,
1 ,
true )
~= nil )
88 + it(
'attaches an image rather than inlining it' ,
function ()
89 + local path
= vim.fs.normalize( vim.fn.tempname()
.. '.png' )
90 + local write
= io .
open ( path,
'wb' )
91 + write:write
'\137PNG\r\n\26\n fake but binary' 94 + local message, images
= compose.expand(
'see @' .. path )
96 + assert .equal(
1 ,
# images )
97 + assert .equal(
'image/png' , images[
1 ].mimeType )
98 + assert .equal(
'image' , images[
1 ].type )
99 + assert .is_true(
# images[
1 ].data
> 0 )
100 + assert .is_true( message:find(
'<file name="' .. path
.. '"></file>' ,
1 ,
true )
~= nil )
103 + it(
'reports a reference it cannot read and leaves it written' ,
function ()
104 + local absent
= vim.fn.tempname()
.. '-absent.lua' 106 + local message, _, missing
= compose.expand(
'read @' .. absent )
108 + assert .equal(
1 ,
# missing )
109 + assert .is_true( message:find(
'@' .. absent,
1 ,
true )
~= nil )
112 + it(
'includes a file once however often it is named' ,
function ()
113 + local path
= temp_file {
'once' , }
115 + local message
= compose.expand( (
'@%s and @%s' ):format( path, path ) )
117 + local count
= select (
2 , message:gsub(
'once' ,
'' ) )
118 + assert .equal(
1 , count )
121 + it(
'leaves text without references alone' ,
function ()
122 + local message, images, missing
= compose.expand
'just words' 124 + assert .equal(
'just words' , message )
125 + assert .same( {}, images )
126 + assert .same( {}, missing )
neovim/tests/bugabinga/pivi/keys_spec.lua Modified +51 / −5 text lines
12 12 local MODES
= {
'n' ,
'i' ,
'x' , }
17 - local ALLOWED
= { [
'/' ] =
true , }
18 + local ALLOWED
= { [
'/' ] =
true , [
'@' ] =
true , }
19 20 local claimed = function ( bufnr )
42 43 assert .same( {}, claimed( bufnr ) )
45 - it(
'claims no key of its own in a prompt, beyond slash-command entry' ,
function ()
46 + it(
'claims no key of its own in a prompt, beyond naming a command or a file' ,
function ()
46 47 local channel
= fake.new()
47 48 local current
= session.create {
48 49 spawn = channel.spawn,
58 59 assert .same( {}, claimed( bufnr ) )
62 + it(
'still types a literal @ inside a word' ,
function ()
64 + local original
= vim.ui.select
65 + vim.ui.
select = function ( _, _, on_choice ) on_choice(
nil )
end 67 + local channel
= fake.new()
68 + local current
= session.create {
69 + spawn = channel.spawn,
76 + local bufnr
= command.open_prompt( current )
77 + vim.cmd.stopinsert()
80 + for _, mapping
in ipairs ( vim.api.nvim_buf_get_keymap( bufnr,
'i' ) )
do 81 + if mapping.lhs
== '@' then at
= mapping
end 83 + assert .is_table( at )
85 + local win
= vim.fn.bufwinid( bufnr )
86 + assert .is_true( win
> 0 )
87 + vim.api.nvim_set_current_win( win )
92 + vim.api.nvim_buf_set_lines( bufnr,
0 ,
- 1 ,
false , {
'mail me' , } )
93 + vim.api.nvim_win_set_cursor( win, {
1 ,
4 , } )
94 + assert .equal(
'@' , at.callback() )
97 + vim.api.nvim_buf_set_lines( bufnr,
0 ,
- 1 ,
false , {
'look at x' , } )
98 + vim.api.nvim_win_set_cursor( win, {
1 ,
8 , } )
99 + assert .equal(
'' , at.callback() )
101 + vim.wait(
50 ,
function ()
return false end )
102 + vim.ui.select
= original
61 105 it(
'publishes every behavior a key could want' ,
function ()
62 106 local bufnr
= transcript.ensure
'published' 63 107 local published
= {}
85 129 it(
'never claims a global key' ,
function ()
86 132 for _, mode
in ipairs ( MODES )
do 87 133 for _, mapping
in ipairs ( vim.api.nvim_get_keymap( mode ) )
do 88 134 if not mapping.lhs:find(
'<Plug>' ,
1 ,
true )
then 89 - assert .is_nil( ( mapping.desc
or '' ):find(
'pivi ' ,
1 ,
true ),
135 + assert .is_nil( ( mapping.desc
or '' ):match
'^pivi ' ,
90 136 mapping.lhs
.. ' was claimed globally by pivi' )
neovim/tests/bugabinga/pivi/session_spec.lua Modified +103 / −0 text lines
591 591 assert .equal(
'write new.lua' , transcript.lines( current.buffer )[item.first] )
594 + it(
'runs a banged prompt as a command instead of saying it' ,
function ()
595 + local channel
= fake.new()
596 + local current
= create( channel )
598 + assert .is_true( current.submit(
'!just test' , {
capture =
false , } ) )
601 + for _, sent
in ipairs ( channel.commands )
do 602 + if sent.type
== 'bash' then ran
= sent
end 603 + assert .is_not.equal(
'prompt' , sent.type )
606 + assert .is_table( ran )
607 + assert .equal(
'just test' , ran.command )
608 + assert .is_false( ran.excludeFromContext )
611 + it(
'keeps a doubly banged command out of the conversation' ,
function ()
612 + local channel
= fake.new()
613 + local current
= create( channel )
615 + current.submit(
'!!git status' , {
capture =
false , } )
618 + for _, sent
in ipairs ( channel.commands )
do 619 + if sent.type
== 'bash' then ran
= sent
end 622 + assert .is_table( ran )
623 + assert .equal(
'git status' , ran.command )
624 + assert .is_true( ran.excludeFromContext )
627 + it(
'shows what a command produced inside its own entry' ,
function ()
628 + local channel
= fake.new()
629 + local current
= create( channel )
631 + current.submit(
'!echo hi' , {
capture =
false , } )
634 + for _, sent
in ipairs ( channel.commands )
do 635 + if sent.type
== 'bash' then ran
= sent
end 642 + data = {
output =
'hi' ,
exitCode =
0 , },
646 + local item
= entry.list( current.buffer )[
1 ]
647 + local lines
= transcript.lines( current.buffer )
649 + assert .equal(
'tool' , item.kind )
650 + assert .equal(
'bang' , item.meta.tool )
651 + assert .is_true( vim.list_contains( lines,
'hi' ) )
652 + assert .is_false( item.meta.failed )
655 + it(
'marks a command that exited badly' ,
function ()
656 + local channel
= fake.new()
657 + local current
= create( channel )
659 + current.submit(
'!false' , {
capture =
false , } )
662 + for _, sent
in ipairs ( channel.commands )
do 663 + if sent.type
== 'bash' then ran
= sent
end 670 + data = {
output =
'' ,
exitCode =
1 , },
674 + assert .is_true( entry.list( current.buffer )[
1 ].meta.failed )
677 + it(
'sends a referenced file with what was said' ,
function ()
678 + local path
= vim.fs.normalize( vim.fn.tempname()
.. '.lua' )
679 + vim.fn.writefile( {
'local referenced = true' , }, path )
681 + local channel
= fake.new()
682 + local current
= create( channel )
684 + current.submit(
'explain @' .. path, {
capture =
false , } )
686 + local sent
= commands_of( channel,
'prompt' )[
1 ]
687 + assert .is_table( sent )
688 + assert .is_true( sent.message:find(
'local referenced = true' ,
1 ,
true )
~= nil )
689 + assert .is_true( sent.message:find(
'<file name=' ,
1 ,
true )
~= nil )
692 + local prompt
= entry.list( current.buffer )[
1 ]
693 + local lines
= transcript.lines( current.buffer )
694 + assert .equal(
'explain @' .. path, lines[prompt.first] )
594 697 it(
'records a rejected submission as its own entry' ,
function ()
595 698 local channel
= fake.new()
596 699 local current
= create( channel )