@@ -163,7 +163,9 @@ function M.send_message(prompt, opts)
163163 end
164164
165165 local received_message_count = vim .deepcopy (state .user_message_count )
166- received_message_count [response .info .sessionID ] = (received_message_count [response .info .sessionID ] ~= nil ) and (received_message_count [response .info .sessionID ] - 1 ) or 0
166+ received_message_count [response .info .sessionID ] = (received_message_count [response .info .sessionID ] ~= nil )
167+ and (received_message_count [response .info .sessionID ] - 1 )
168+ or 0
167169 state .user_message_count = received_message_count
168170
169171 M .after_run (prompt )
@@ -379,23 +381,25 @@ end
379381
380382function M ._on_user_message_count_change (_ , new , old )
381383 if config .hooks and config .hooks .on_done_thinking then
382- local all_sessions = session .get_all_workspace_sessions () or {}
383- local done_sessions = vim .tbl_filter (function (s )
384- local msg_count = new [s .id ] or 0
385- local old_msg_count = (old and old [s .id ]) or 0
386- return msg_count == 0 and old_msg_count > 0
387- end , all_sessions )
388-
389- for _ , done_session in ipairs (done_sessions ) do
390- pcall (config .hooks .on_done_thinking , done_session )
391- end
384+ local all_sessions = session .get_all_workspace_sessions () or {}
385+ local done_sessions = vim .tbl_filter (function (s )
386+ local msg_count = new [s .id ] or 0
387+ local old_msg_count = (old and old [s .id ]) or 0
388+ return msg_count == 0 and old_msg_count > 0
389+ end , all_sessions )
390+
391+ for _ , done_session in ipairs (done_sessions ) do
392+ pcall (config .hooks .on_done_thinking , done_session )
393+ end
392394 end
393395end
394396
395397function M ._on_current_permission_change (_ , new , old )
396398 local permission_requested = old == nil and new ~= nil
397399 if config .hooks and config .hooks .on_permission_requested and permission_requested then
398- local local_session = session .get_by_id (state .active_session .id ) or {}
400+ local local_session = (state .active_session and state .active_session .id )
401+ and session .get_by_id (state .active_session .id )
402+ or {}
399403 pcall (config .hooks .on_permission_requested , local_session )
400404 end
401405end
0 commit comments