session: add plan, prevPrompt, peers to Session

Extend the core session with fields that are genuinely session
concerns currently duplicated in 9p/session:
- Plan (markdown checklist, survives compaction)
- PrevPrompt (last submitted prompt text)
- Peers (bidirectional session links)

The 9p/session layer can delegate to these in a future change.
This commit is contained in:
Levi Neely 2026-07-29 18:36:59 +02:00
parent da4d047aa1
commit e10319758b
1 changed files with 67 additions and 0 deletions

View File

@ -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
}