@@ -806,7 +806,7 @@ M.setup = function(opts)
806
806
if cmd == " Agent" then
807
807
local buf = vim .api .nvim_get_current_buf ()
808
808
local file_name = vim .api .nvim_buf_get_name (buf )
809
- if M .is_chat (buf , file_name ) then
809
+ if M .not_chat (buf , file_name ) == nil then
810
810
return M ._chat_agents
811
811
end
812
812
return M ._command_agents
@@ -1372,28 +1372,31 @@ M.prep_md = function(buf)
1372
1372
M ._H .feedkeys (" <esc>" , " xn" )
1373
1373
end
1374
1374
1375
- M .is_chat = function (buf , file_name )
1375
+ --- @param buf number # buffer number
1376
+ --- @param file_name string # file name
1377
+ --- @return string | nil # reason for not being a chat or nil if it is a chat
1378
+ M .not_chat = function (buf , file_name )
1376
1379
if not _H .starts_with (file_name , M .config .chat_dir ) then
1377
- return false
1380
+ return " not in chat directory ( " .. M . config . chat_dir .. " ) "
1378
1381
end
1379
1382
1380
1383
local lines = vim .api .nvim_buf_get_lines (buf , 0 , - 1 , false )
1381
1384
if # lines < 4 then
1382
- return false
1385
+ return " file too short "
1383
1386
end
1384
1387
1385
1388
if not lines [1 ]:match (" ^# " ) then
1386
- return false
1389
+ return " missing topic header "
1387
1390
end
1388
1391
1389
1392
if not (lines [3 ]:match (" ^- file: " ) or lines [4 ]:match (" ^- file: " )) then
1390
- return false
1393
+ return " missing file header "
1391
1394
end
1392
- return true
1395
+ return nil
1393
1396
end
1394
1397
1395
1398
M .prep_chat = function (buf , file_name )
1396
- if not M . is_chat (buf , file_name ) then
1399
+ if M . not_chat (buf , file_name ) then
1397
1400
return
1398
1401
end
1399
1402
@@ -1834,8 +1837,9 @@ M.chat_respond = function(params)
1834
1837
1835
1838
-- check if file looks like a chat file
1836
1839
local file_name = vim .api .nvim_buf_get_name (buf )
1837
- if not M .is_chat (buf , file_name ) then
1838
- M .warning (" File " .. vim .inspect (file_name ) .. " does not look like a chat file" )
1840
+ local reason = M .not_chat (buf , file_name )
1841
+ if reason then
1842
+ M .warning (" File " .. vim .inspect (file_name ) .. " does not look like a chat file: " .. vim .inspect (reason ))
1839
1843
return
1840
1844
end
1841
1845
@@ -2374,7 +2378,7 @@ M.cmd.Agent = function(params)
2374
2378
2375
2379
local buf = vim .api .nvim_get_current_buf ()
2376
2380
local file_name = vim .api .nvim_buf_get_name (buf )
2377
- local is_chat = M .is_chat (buf , file_name )
2381
+ local is_chat = M .not_chat (buf , file_name ) == nil
2378
2382
if is_chat and M .agents [agent_name ].chat then
2379
2383
M ._state .chat_agent = agent_name
2380
2384
M .info (" Chat agent: " .. M ._state .chat_agent )
@@ -2393,7 +2397,7 @@ end
2393
2397
M .cmd .NextAgent = function ()
2394
2398
local buf = vim .api .nvim_get_current_buf ()
2395
2399
local file_name = vim .api .nvim_buf_get_name (buf )
2396
- local is_chat = M .is_chat (buf , file_name )
2400
+ local is_chat = M .not_chat (buf , file_name ) == nil
2397
2401
local current_agent , agent_list
2398
2402
2399
2403
if is_chat then
0 commit comments