This commit is contained in:
Ian Gulliver
2026-10-20 22:49:11 -07:00
parent 4f7d05021a
commit 99401670ee
7 changed files with 53 additions and 40 deletions
+5 -7
View File
@@ -13,13 +13,12 @@ import (
"io"
"log/slog"
"os"
"os/exec"
"sync"
"sync/atomic"
"syscall"
"time"
"g.fc.run/ai/byre/internal/mcp"
"g.fc.run/ai/byre/internal/procgroup"
)
type HookFunc func(ctx context.Context, input json.RawMessage) (map[string]any, error)
@@ -194,7 +193,7 @@ func (e Event) Result() (Result, error) {
}
type Session struct {
cmd *exec.Cmd
cmd *procgroup.Cmd
stdin io.WriteCloser
events chan Event
done chan struct{}
@@ -255,11 +254,10 @@ func Start(ctx context.Context, opts Options) (*Session, error) {
return nil, err
}
s.cmd = exec.Command("claude", args...)
s.cmd = procgroup.Command("claude", args...)
s.cmd.Dir = opts.Cwd
s.cmd.Stderr = os.Stderr
s.cmd.Env = buildEnv(opts)
s.cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
s.stdin, err = s.cmd.StdinPipe()
if err != nil {
@@ -514,7 +512,7 @@ func (s *Session) Close() error {
select {
case <-s.done:
case <-time.After(5 * time.Second):
syscall.Kill(-s.cmd.Process.Pid, syscall.SIGKILL)
s.cmd.Kill()
<-s.done
}
@@ -522,7 +520,7 @@ func (s *Session) Close() error {
}
func (s *Session) Kill() {
syscall.Kill(-s.cmd.Process.Pid, syscall.SIGKILL)
s.cmd.Kill()
<-s.done
s.cmd.Wait()
}