Harden Harness runtime, persistence and execution for Hand

This commit is contained in:
sausheong committed 2026-09-09 22:55:55 +08:00
1 parent 09c30fe2d5
commit 0972eed3ea
164 files changed
+15912 -506

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
package mcp
import (
"context"
"os/exec"
"sync"
sdk "github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/sausheong/harness/process"
)
type managedCommandTransport struct{ sdk.CommandTransport }
func (t *managedCommandTransport) Connect(ctx context.Context) (sdk.Connection, error) {
conn, err := t.CommandTransport.Connect(ctx)
if err != nil {
return nil, err
}
return &managedCommandConnection{Connection: conn, command: t.Command}, nil
}
type managedCommandConnection struct {
sdk.Connection
command *exec.Cmd
once sync.Once
closeErr error
}
func (c *managedCommandConnection) Close() error {
c.once.Do(func() {
// Let the SDK close stdin and join the server first, then remove any
// descendants it left behind. WaitDelay bounds inherited-pipe draining.
c.closeErr = c.Connection.Close()
if err := process.KillGroup(c.command); c.closeErr == nil {
c.closeErr = err
}
})
return c.closeErr
}