683683function M .timeline ()
684684 local user_messages = {}
685685 for _ , msg in ipairs (state .messages or {}) do
686- if msg .info .role == ' user' then
686+ local parts = msg .parts or {}
687+ local is_summary = # parts == 1 and parts [1 ].synthetic == true
688+ if msg .info .role == ' user' and not is_summary then
687689 table.insert (user_messages , msg )
688690 end
689691 end
@@ -700,6 +702,39 @@ function M.timeline()
700702 end )
701703end
702704
705+ function M .fork_session (message_id )
706+ if not state .active_session then
707+ vim .notify (' No active session to fork' , vim .log .levels .WARN )
708+ return
709+ end
710+
711+ local message_to_fork = message_id or state .last_user_message and state .last_user_message .info .id
712+ if not message_to_fork then
713+ vim .notify (' No user message to fork from' , vim .log .levels .WARN )
714+ return
715+ end
716+
717+ state .api_client
718+ :fork_session (state .active_session .id , {
719+ messageID = message_to_fork ,
720+ })
721+ :and_then (function (response )
722+ vim .schedule (function ()
723+ if response and response .id then
724+ vim .notify (' Session forked successfully. New session ID: ' .. response .id , vim .log .levels .INFO )
725+ core .switch_session (response .id )
726+ else
727+ vim .notify (' Session forked but no new session ID received' , vim .log .levels .WARN )
728+ end
729+ end )
730+ end )
731+ :catch (function (err )
732+ vim .schedule (function ()
733+ vim .notify (' Failed to fork session: ' .. vim .inspect (err ), vim .log .levels .ERROR )
734+ end )
735+ end )
736+ end
737+
703738-- Returns the ID of the next user message after the current undo point
704739-- This is a port of the opencode tui logic
705740-- https://github.com/sst/opencode/blob/dev/packages/tui/internal/components/chat/messages.go#L1199
0 commit comments