Create a new session
(
&mut self,
project_id: impl Into<String>,
directory: impl Into<String>,
)
| 829 | |
| 830 | /// Create a new session |
| 831 | pub fn create( |
| 832 | &mut self, |
| 833 | project_id: impl Into<String>, |
| 834 | directory: impl Into<String>, |
| 835 | ) -> Session { |
| 836 | let session = Session::new(project_id, directory); |
| 837 | self.sessions.insert(session.id.clone(), session.clone()); |
| 838 | self.events.push(SessionEvent::Created { |
| 839 | info: session.clone(), |
| 840 | }); |
| 841 | |
| 842 | // Publish to Bus |
| 843 | self.publish_session_event(&SESSION_CREATED_EVENT, &session); |
| 844 | |
| 845 | // Plugin hook: session.start — notify plugins of new session |
| 846 | if let Ok(handle) = tokio::runtime::Handle::try_current() { |
| 847 | let session_id = session.id.clone(); |
| 848 | handle.spawn(async move { |
| 849 | opencode_plugin::trigger( |
| 850 | HookContext::new(HookEvent::SessionStart).with_session(&session_id), |
| 851 | ) |
| 852 | .await; |
| 853 | }); |
| 854 | } |
| 855 | |
| 856 | session |
| 857 | } |
| 858 | |
| 859 | /// Create a child session |
| 860 | pub fn create_child(&mut self, parent_id: &str) -> Option<Session> { |