MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / fork

Method fork

crates/opencode-session/src/session.rs:873–899  ·  view source on GitHub ↗

Fork a session at a specific message

(&mut self, session_id: &str, message_id: Option<&str>)

Source from the content-addressed store, hash-verified

871
872 /// Fork a session at a specific message
873 pub fn fork(&mut self, session_id: &str, message_id: Option<&str>) -> Option<Session> {
874 let original = self.sessions.get(session_id)?;
875 let forked_title = original.get_forked_title();
876
877 let mut forked = Session::child(original);
878 forked.parent_id = None;
879 forked.title = forked_title;
880
881 if let Some(msg_id) = message_id {
882 for msg in &original.messages {
883 if msg.id == msg_id {
884 break;
885 }
886 forked.messages.push(msg.clone());
887 }
888 } else {
889 forked.messages = original.messages.clone();
890 }
891
892 let forked_id = forked.id.clone();
893 self.sessions.insert(forked_id, forked.clone());
894 self.events.push(SessionEvent::Created {
895 info: forked.clone(),
896 });
897 self.publish_session_event(&SESSION_CREATED_EVENT, &forked);
898 Some(forked)
899 }
900
901 /// Set share info and publish session.updated.
902 pub fn share(&mut self, session_id: &str, url: impl Into<String>) -> Option<Session> {

Callers 1

fork_sessionFunction · 0.80

Calls 4

get_forked_titleMethod · 0.80
publish_session_eventMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected