diff --git a/session/session.go b/session/session.go index 25587c2..1c43ed5 100644 --- a/session/session.go +++ b/session/session.go @@ -26,6 +26,10 @@ type Session struct { envMu sync.RWMutex env map[string]string + plan []byte + prevPrompt string + peers map[string]bool // peer session IDs (bidirectional) + changeMu sync.Mutex changeCond *sync.Cond } @@ -156,3 +160,66 @@ func (s *Session) notifyChange() { s.changeCond.Broadcast() s.changeMu.Unlock() } + +// Plan returns the session plan. +func (s *Session) Plan() []byte { + s.mu.RLock() + defer s.mu.RUnlock() + return s.plan +} + +// SetPlan updates the session plan. +func (s *Session) SetPlan(p []byte) { + s.mu.Lock() + s.plan = p + s.mu.Unlock() +} + +// PrevPrompt returns the last submitted prompt. +func (s *Session) PrevPrompt() string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.prevPrompt +} + +// SetPrevPrompt stores the last submitted prompt. +func (s *Session) SetPrevPrompt(p string) { + s.mu.Lock() + s.prevPrompt = p + s.mu.Unlock() +} + +// HasPeer reports whether peerID is linked to this session. +func (s *Session) HasPeer(id string) bool { + s.mu.RLock() + defer s.mu.RUnlock() + return s.peers[id] +} + +// AddPeer adds a bidirectional peer link. +func (s *Session) AddPeer(id string) { + s.mu.Lock() + if s.peers == nil { + s.peers = make(map[string]bool) + } + s.peers[id] = true + s.mu.Unlock() +} + +// RemovePeer removes a peer link. +func (s *Session) RemovePeer(id string) { + s.mu.Lock() + delete(s.peers, id) + s.mu.Unlock() +} + +// Peers returns a copy of all peer IDs. +func (s *Session) Peers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + out := make([]string, 0, len(s.peers)) + for id := range s.peers { + out = append(out, id) + } + return out +}