Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/chat_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func essentialTools() []tool.Tool {
tool.ScheduleCreateTool{},
tool.ScheduleListTool{},
tool.ScheduleDeleteTool{},
tool.TerminalCreateTool{},
tool.TerminalSendTool{},
tool.TerminalReadTool{},
tool.TerminalListTool{},
tool.TerminalResizeTool{},
tool.TerminalKillTool{},
tool.AgentTool{},
tool.AskUserQuestionTool{},
tool.TodoWriteTool{},
Expand Down
1 change: 1 addition & 0 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/terminal/proc_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !windows

package terminal

import (
"os"
"syscall"
)

func killProcessGroup(proc *os.Process) error {
if proc == nil {
return nil
}
return syscall.Kill(-proc.Pid, syscall.SIGKILL)
}
14 changes: 14 additions & 0 deletions internal/terminal/proc_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build windows

package terminal

import (
"os"
)

func killProcessGroup(proc *os.Process) error {
if proc == nil {
return nil
}
return proc.Kill()
}
55 changes: 55 additions & 0 deletions internal/terminal/pty_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build !windows

package terminal

import (
"os"
"os/exec"

"github.com/creack/pty"
)

type ptyDevice struct {
file *os.File
}

func startPTY(cmd *exec.Cmd, rows, cols int) (*ptyDevice, error) {
var sz *pty.Winsize
if rows > 0 && cols > 0 {
sz = &pty.Winsize{
Rows: uint16(rows),
Cols: uint16(cols),
}
}

ptmx, err := pty.StartWithSize(cmd, sz)
if err != nil {
return nil, err
}
return &ptyDevice{file: ptmx}, nil
}

func (p *ptyDevice) Resize(rows, cols int) error {
if p == nil || p.file == nil {
return nil
}
return pty.Setsize(p.file, &pty.Winsize{
Rows: uint16(rows),
Cols: uint16(cols),
})
}

func (p *ptyDevice) Read(b []byte) (int, error) {
return p.file.Read(b)
}

func (p *ptyDevice) Write(b []byte) (int, error) {
return p.file.Write(b)
}

func (p *ptyDevice) Close() error {
if p == nil || p.file == nil {
return nil
}
return p.file.Close()
}
69 changes: 69 additions & 0 deletions internal/terminal/pty_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build windows

package terminal

import (
"errors"
"io"
"os/exec"
)

type ptyDevice struct {
stdin io.WriteCloser
stdout io.ReadCloser
}

func startPTY(cmd *exec.Cmd, rows, cols int) (*ptyDevice, error) {
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
_ = stdin.Close()
return nil, err
}
cmd.Stderr = cmd.Stdout

if err := cmd.Start(); err != nil {
_ = stdin.Close()
_ = stdout.Close()
return nil, err
}

return &ptyDevice{
stdin: stdin,
stdout: stdout,
}, nil
}

func (p *ptyDevice) Resize(rows, cols int) error {
return nil
}

func (p *ptyDevice) Read(b []byte) (int, error) {
if p == nil || p.stdout == nil {
return 0, errors.New("terminal closed")
}
return p.stdout.Read(b)
}

func (p *ptyDevice) Write(b []byte) (int, error) {
if p == nil || p.stdin == nil {
return 0, errors.New("terminal closed")
}
return p.stdin.Write(b)
}

func (p *ptyDevice) Close() error {
if p == nil {
return nil
}
if p.stdin != nil {
_ = p.stdin.Close()
}
if p.stdout != nil {
_ = p.stdout.Close()
}
return nil
}
Loading
Loading