Simplify session lifecycle and MCP cleanup
This commit is contained in:
@@ -13,10 +13,12 @@ import (
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Store is the per-project scratchpad directory.
|
||||
type Store struct {
|
||||
mu sync.Mutex
|
||||
dir string
|
||||
}
|
||||
|
||||
@@ -55,6 +57,8 @@ type Entry struct {
|
||||
func (s *Store) Dir() string { return s.dir }
|
||||
|
||||
func (s *Store) List() ([]Entry, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
entries, err := os.ReadDir(s.dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,6 +83,8 @@ func (s *Store) List() ([]Entry, error) {
|
||||
}
|
||||
|
||||
func (s *Store) Read(name string) (content string, revision string, err error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
p, err := s.safePath(name)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
@@ -106,6 +112,8 @@ func (e *RevisionMismatchError) Error() string {
|
||||
// must match the current revision or the write is rejected with a
|
||||
// *RevisionMismatchError (SPEC §14 last-write-wins-with-token).
|
||||
func (s *Store) Write(name, content, expectedRevision string) (string, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
p, err := s.safePath(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -125,6 +133,8 @@ func (s *Store) Write(name, content, expectedRevision string) (string, error) {
|
||||
}
|
||||
|
||||
func (s *Store) Append(name, content string) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
p, err := s.safePath(name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user