Remove unused raw protocol recorders from agent sessions
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -33,7 +32,6 @@ type Options struct {
|
||||
Reminder string
|
||||
MCPServers []*mcp.Server
|
||||
StdioMCP []mcp.Stdio
|
||||
Transcript io.Writer
|
||||
OnBadLine func(line []byte, reason string)
|
||||
}
|
||||
|
||||
@@ -88,9 +86,7 @@ type Session struct {
|
||||
events chan Event
|
||||
done chan struct{}
|
||||
|
||||
writeLock chan struct{}
|
||||
recordMu sync.Mutex
|
||||
transcript io.Writer
|
||||
writeLock chan struct{}
|
||||
|
||||
nextID atomic.Int64
|
||||
pendingMu sync.Mutex
|
||||
@@ -181,15 +177,14 @@ func spawn(opts Options) (*Session, error) {
|
||||
|
||||
func newSession(opts Options, stdin *os.File, stdout io.Reader) *Session {
|
||||
s := &Session{
|
||||
stdin: stdin,
|
||||
events: make(chan Event, 256),
|
||||
writeLock: make(chan struct{}, 1),
|
||||
done: make(chan struct{}),
|
||||
transcript: opts.Transcript,
|
||||
pending: map[int64]chan rpcResult{},
|
||||
servers: map[string]*mcp.Server{},
|
||||
reminder: opts.Reminder,
|
||||
onBadLine: opts.OnBadLine,
|
||||
stdin: stdin,
|
||||
events: make(chan Event, 256),
|
||||
writeLock: make(chan struct{}, 1),
|
||||
done: make(chan struct{}),
|
||||
pending: map[int64]chan rpcResult{},
|
||||
servers: map[string]*mcp.Server{},
|
||||
reminder: opts.Reminder,
|
||||
onBadLine: opts.OnBadLine,
|
||||
}
|
||||
for _, srv := range opts.MCPServers {
|
||||
s.servers[srv.Name] = srv
|
||||
@@ -552,8 +547,6 @@ func (s *Session) write(m message, deadline time.Time) error {
|
||||
return os.ErrDeadlineExceeded
|
||||
}
|
||||
|
||||
s.record("send", b)
|
||||
|
||||
err = s.stdin.SetWriteDeadline(deadline)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -566,26 +559,6 @@ func (s *Session) write(m message, deadline time.Time) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var emailField = regexp.MustCompile(`"email":"[^"]*"`)
|
||||
|
||||
func (s *Session) record(dir string, line []byte) {
|
||||
if s.transcript == nil {
|
||||
return
|
||||
}
|
||||
|
||||
line = emailField.ReplaceAll(line, []byte(`"email":"[redacted]"`))
|
||||
|
||||
b, err := json.Marshal(map[string]any{"dir": dir, "msg": json.RawMessage(line)})
|
||||
if err != nil {
|
||||
slog.Error("record transcript", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
s.recordMu.Lock()
|
||||
defer s.recordMu.Unlock()
|
||||
s.transcript.Write(append(b, '\n'))
|
||||
}
|
||||
|
||||
func (s *Session) readLoop(stdout io.Reader) {
|
||||
defer close(s.done)
|
||||
defer close(s.events)
|
||||
@@ -620,8 +593,6 @@ func (s *Session) handleLine(line []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
s.record("recv", line)
|
||||
|
||||
if m.Method == "" {
|
||||
s.handleResponse(line, m)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user