session

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackgroundTask

type BackgroundTask struct {
	ID       string
	Cmd      *exec.Cmd
	Stdout   *SyncBuffer
	Stderr   *SyncBuffer
	Done     chan struct{}
	ExitCode int
	// contains filtered or unexported fields
}

BackgroundTask represents a command running in the background.

func (*BackgroundTask) SetTimedOut

func (t *BackgroundTask) SetTimedOut()

SetTimedOut marks the task as killed by the safety-net timeout.

func (*BackgroundTask) TimedOut

func (t *BackgroundTask) TimedOut() bool

TimedOut reports whether the task was killed by the safety-net timeout.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session holds per-session state including the tracked working directory, a random nonce for sentinel generation, background task tracking, and viewed-file tracking for view-before-edit enforcement.

func New

func New(cwd string) *Session

New creates a Session with the given initial working directory.

func (*Session) AddTask

func (s *Session) AddTask(task *BackgroundTask) error

AddTask stores a background task. Returns an error if the session is closed or the limit is reached.

func (*Session) Close

func (s *Session) Close()

Close terminates all running background tasks and marks the session as closed. For each running task, it sends SIGTERM to the process group, waits up to 5 seconds, then sends SIGKILL if the process is still alive. Close is idempotent — subsequent calls have no effect.

func (*Session) Cwd

func (s *Session) Cwd() string

Cwd returns the current working directory.

func (*Session) GetTask

func (s *Session) GetTask(id string) (*BackgroundTask, bool)

GetTask retrieves a background task by ID.

func (*Session) HasViewed

func (s *Session) HasViewed(path string) bool

HasViewed reports whether the given resolved file path has been viewed in this session.

func (*Session) MarkViewed

func (s *Session) MarkViewed(path string)

MarkViewed records a resolved file path as having been viewed in this session.

func (*Session) Nonce

func (s *Session) Nonce() string

Nonce returns the session's random nonce.

func (*Session) RemoveTask

func (s *Session) RemoveTask(id string)

RemoveTask removes a background task by ID.

func (*Session) Sentinel

func (s *Session) Sentinel() string

Sentinel returns the cwd sentinel string for this session.

func (*Session) SetCwd

func (s *Session) SetCwd(cwd string)

SetCwd updates the current working directory.

func (*Session) TaskCount

func (s *Session) TaskCount() int

TaskCount returns the number of active background tasks.

type SessionCleanupStore

type SessionCleanupStore struct {
	Registry *SessionRegistry
}

SessionCleanupStore is a minimal mcp.EventStore implementation whose sole purpose is to receive SessionClosed notifications from the go-sdk and trigger Boris session cleanup via the SessionRegistry.

Open, Append, and After are no-ops — stream resumption is not supported.

func (*SessionCleanupStore) After

func (s *SessionCleanupStore) After(_ context.Context, _, _ string, _ int) iter.Seq2[[]byte, error]

After returns an empty iterator; stream resumption is not supported.

func (*SessionCleanupStore) Append

func (s *SessionCleanupStore) Append(_ context.Context, _, _ string, _ []byte) error

Append is a no-op; stream resumption is not supported.

func (*SessionCleanupStore) Open

func (s *SessionCleanupStore) Open(_ context.Context, _, _ string) error

Open is a no-op; stream resumption is not supported.

func (*SessionCleanupStore) SessionClosed

func (s *SessionCleanupStore) SessionClosed(_ context.Context, sessionID string) error

SessionClosed is called by the go-sdk when an HTTP session terminates (idle timeout, client DELETE, or connection drop). It closes the corresponding Boris session and removes it from the registry.

type SessionRegistry

type SessionRegistry struct {
	// contains filtered or unexported fields
}

SessionRegistry maps go-sdk session IDs to Boris sessions, enabling cleanup when the SDK signals session end (via EventStore.SessionClosed).

func NewRegistry

func NewRegistry() *SessionRegistry

NewRegistry creates an empty SessionRegistry.

func (*SessionRegistry) CloseAll

func (r *SessionRegistry) CloseAll()

CloseAll closes every session in the registry and clears the map. It is safe to call concurrently with CloseAndRemove and is idempotent.

func (*SessionRegistry) CloseAndRemove

func (r *SessionRegistry) CloseAndRemove(id string)

CloseAndRemove closes the Boris session for the given ID and removes it from the registry. If the ID is not found, this is a no-op.

func (*SessionRegistry) Register

func (r *SessionRegistry) Register(id string, sess *Session)

Register associates a go-sdk session ID with a Boris session. If the ID is already registered, the existing entry is overwritten.

type SyncBuffer

type SyncBuffer struct {
	// contains filtered or unexported fields
}

SyncBuffer is a concurrency-safe buffer that implements io.Writer. It is safe for concurrent use, e.g. as cmd.Stdout while reading accumulated output from another goroutine.

func (*SyncBuffer) String

func (sb *SyncBuffer) String() string

func (*SyncBuffer) Write

func (sb *SyncBuffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL