@@ -33,7 +33,8 @@ local M = {
33
33
local agent_completion = function ()
34
34
local buf = vim .api .nvim_get_current_buf ()
35
35
local file_name = vim .api .nvim_buf_get_name (buf )
36
- if M .not_chat (buf , file_name ) == nil then
36
+ local is_chat , _ = M .is_chat (buf , file_name )
37
+ if is_chat == nil then
37
38
return M ._chat_agents
38
39
end
39
40
return M ._command_agents
@@ -447,22 +448,22 @@ end
447
448
448
449
--- @param buf number # buffer number
449
450
--- @param file_name string # file name
450
- --- @return string | nil # reason for not being a chat or nil if it is a chat
451
- M .not_chat = function (buf , file_name )
451
+ --- @return ( boolean , string | nil ) # is_chat , reason for not being a chat or nil if it is a chat
452
+ M .is_chat = function (buf , file_name )
452
453
file_name = vim .fn .resolve (file_name )
453
454
local chat_dir = vim .fn .resolve (M .config .chat_dir )
454
455
455
456
if not M .helpers .starts_with (file_name , chat_dir ) then
456
- return " resolved file (" .. file_name .. " ) not in chat dir (" .. chat_dir .. " )"
457
+ return false , " resolved file (" .. file_name .. " ) not in chat dir (" .. chat_dir .. " )"
457
458
end
458
459
459
460
local lines = vim .api .nvim_buf_get_lines (buf , 0 , - 1 , false )
460
461
if # lines < 5 then
461
- return " file too short"
462
+ return false , " file too short"
462
463
end
463
464
464
465
if not lines [1 ]:match (" ^# " ) then
465
- return " missing topic header"
466
+ return false , " missing topic header"
466
467
end
467
468
468
469
local header_found = nil
@@ -473,14 +474,15 @@ M.not_chat = function(buf, file_name)
473
474
end
474
475
end
475
476
if not header_found then
476
- return " missing file header"
477
+ return false , " missing file header"
477
478
end
478
479
479
- return nil
480
+ return true
480
481
end
481
482
482
483
M .display_chat_agent = function (buf , file_name )
483
- if M .not_chat (buf , file_name ) then
484
+ local is_chat , _ = M .is_chat (buf , file_name )
485
+ if not is_chat then
484
486
return
485
487
end
486
488
504
506
505
507
M ._prepared_bufs = {}
506
508
M .prep_chat = function (buf , file_name )
507
- if M .not_chat (buf , file_name ) then
509
+ if M .is_chat (buf , file_name ) then
508
510
return
509
511
end
510
512
@@ -949,8 +951,8 @@ M.chat_respond = function(params)
949
951
950
952
-- check if file looks like a chat file
951
953
local file_name = vim .api .nvim_buf_get_name (buf )
952
- local reason = M .not_chat (buf , file_name )
953
- if reason then
954
+ local is_chat , reason = M .is_chat (buf , file_name )
955
+ if not is_chat then
954
956
M .logger .warning (" File " .. vim .inspect (file_name ) .. " does not look like a chat file: " .. vim .inspect (reason ))
955
957
return
956
958
end
@@ -1500,7 +1502,9 @@ M.cmd.Agent = function(params)
1500
1502
1501
1503
local buf = vim .api .nvim_get_current_buf ()
1502
1504
local file_name = vim .api .nvim_buf_get_name (buf )
1503
- local is_chat = M .not_chat (buf , file_name ) == nil
1505
+ local is_chat , msg = M .is_chat (buf , file_name )
1506
+ print (" is_chat ?" )
1507
+ print (is_chat , msg )
1504
1508
if is_chat and M .agents [agent_name ].chat then
1505
1509
M .refresh_state ({ chat_agent = agent_name })
1506
1510
M .logger .info (" Chat agent: " .. M ._state .chat_agent )
@@ -1509,14 +1513,15 @@ M.cmd.Agent = function(params)
1509
1513
M .logger .info (" Command agent: " .. M ._state .command_agent )
1510
1514
else
1511
1515
M .logger .warning (agent_name .. " is not a valid agent for current buffer" )
1516
+ M .logger .warning (is_chat )
1512
1517
M .refresh_state ()
1513
1518
end
1514
1519
end
1515
1520
1516
1521
M .cmd .NextAgent = function ()
1517
1522
local buf = vim .api .nvim_get_current_buf ()
1518
1523
local file_name = vim .api .nvim_buf_get_name (buf )
1519
- local is_chat = M .not_chat (buf , file_name ) == nil
1524
+ local is_chat , _ = M .is_chat (buf , file_name )
1520
1525
local current_agent , agent_list
1521
1526
1522
1527
if is_chat then
0 commit comments