• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valksor / go-assern / 26285265118

22 May 2026 11:31AM UTC coverage: 51.35% (+5.7%) from 45.617%
26285265118

push

github

k0d3r1s
Ignores local Claude memory files

The local memory server creates files that are not meant for version control. These rules ensure they stay out of the repository.

2909 of 5665 relevant lines covered (51.35%)

75.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.99
/internal/instance/proxy.go
1
package instance
2

3
import (
4
        "context"
5
        "io"
6
        "log/slog"
7
        "net"
8
        "os"
9
        "sync"
10
)
11

12
const (
13
        // proxyBufferSize is the buffer size for io.CopyBuffer operations.
14
        // 256KB is optimized for MCP message sizes which can be large.
15
        proxyBufferSize = 256 * 1024
16
)
17

18
// bufferPool provides reusable buffers for proxy I/O operations.
19
var bufferPool = sync.Pool{
20
        New: func() any {
×
21
                buf := make([]byte, proxyBufferSize)
×
22

×
23
                return &buf
×
24
        },
×
25
}
26

27
// Proxy connects to an existing assern instance and bridges stdio to it.
28
type Proxy struct {
29
        socketPath string
30
        logger     *slog.Logger
31
        conn       net.Conn
32
}
33

34
// NewProxy creates a new proxy to an existing instance.
35
func NewProxy(socketPath string, logger *slog.Logger) *Proxy {
11✔
36
        return &Proxy{
11✔
37
                socketPath: socketPath,
11✔
38
                logger:     logger,
11✔
39
        }
11✔
40
}
11✔
41

42
// Connect establishes connection to the primary instance.
43
func (p *Proxy) Connect(ctx context.Context) error {
9✔
44
        var dialer net.Dialer
9✔
45
        conn, err := dialer.DialContext(ctx, "unix", p.socketPath)
9✔
46
        if err != nil {
11✔
47
                return err
2✔
48
        }
2✔
49

50
        p.conn = conn
7✔
51

7✔
52
        return nil
7✔
53
}
54

55
// Close closes the connection to the primary instance.
56
func (p *Proxy) Close() error {
8✔
57
        if p.conn != nil {
15✔
58
                return p.conn.Close()
7✔
59
        }
7✔
60

61
        return nil
1✔
62
}
63

64
// ServeStdio bridges stdin/stdout to the socket connection.
65
// This makes the proxy transparent to the calling LLM.
66
func (p *Proxy) ServeStdio(ctx context.Context) error {
×
67
        if p.conn == nil {
×
68
                if err := p.Connect(ctx); err != nil {
×
69
                        return err
×
70
                }
×
71
        }
72

73
        p.logger.Info("proxy connected - forwarding stdio to primary instance")
×
74

×
75
        var wg sync.WaitGroup
×
76
        errCh := make(chan error, 2)
×
77

×
78
        // stdin -> socket
×
79
        wg.Go(func() {
×
80
                bufPtr, ok := bufferPool.Get().(*[]byte)
×
81
                if !ok {
×
82
                        errCh <- io.ErrShortBuffer
×
83

×
84
                        return
×
85
                }
×
86
                defer bufferPool.Put(bufPtr)
×
87
                _, err := io.CopyBuffer(p.conn, os.Stdin, *bufPtr)
×
88
                if err != nil && ctx.Err() == nil {
×
89
                        errCh <- err
×
90
                }
×
91
        })
92

93
        // socket -> stdout
94
        wg.Go(func() {
×
95
                bufPtr, ok := bufferPool.Get().(*[]byte)
×
96
                if !ok {
×
97
                        errCh <- io.ErrShortBuffer
×
98

×
99
                        return
×
100
                }
×
101
                defer bufferPool.Put(bufPtr)
×
102
                _, err := io.CopyBuffer(os.Stdout, p.conn, *bufPtr)
×
103
                if err != nil && ctx.Err() == nil {
×
104
                        errCh <- err
×
105
                }
×
106
        })
107

108
        // Wait for context cancellation or connection close
109
        select {
×
110
        case <-ctx.Done():
×
111
                _ = p.conn.Close()
×
112
        case err := <-errCh:
×
113
                p.logger.Debug("proxy connection closed", "error", err)
×
114
                _ = p.conn.Close()
×
115
        }
116

117
        wg.Wait()
×
118

×
119
        return nil
×
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc