Files
HomeAgent/internal/plugins/agentcli/pty_windows.go
JianFeeeee 4e70b8d5d8 refactor(module): 核心仓 Go module 路径改为 github.com/JianFeeeee/HologramAgent
批 1,不含 SDK 仓与目录改名。

- go.mod 第 1 行 module 路径
- 366 个 .go 文件的完整前缀 github.com/JianFeeeee/HomeAgent 机械替换
  (857 处,仅完整前缀;展示名/注释里的 HomeAgent 字样留给批 5)
- 未改:third_party 目录名、SDK 自身 go.mod module、go.mod replace 目标、
  homed/waiter 可执行名、.hmap 后缀
2026-10-21 12:17:19 +08:00

80 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//go:build windows
package agentcli
import (
"fmt"
"os"
"os/exec"
"strings"
"sync"
"github.com/JianFeeeee/HologramAgent/internal/ptywin"
)
func defaultShell() string { return "cmd.exe" }
// windowsPty 基于 internal/ptywin(ConPTY)的终端后端。
type windowsPty struct {
c *ptywin.ConPty
cmd *exec.Cmd
closeOnce sync.Once
}
// newCommandPty 创建 ConPTY 并在其上运行命令(cmd.exe /c <command>)。
func newCommandPty(command string, rows, cols uint16) (ptyTerm, *exec.Cmd, error) {
cmdLine := windowsCommandLine(command)
c, err := ptywin.Start(cmdLine, ptywin.ConPtyDimensions(int(cols), int(rows)))
if err != nil {
return nil, nil, fmt.Errorf("conpty start: %v", err)
}
cmdObj := exec.Command("cmd.exe")
cmdObj.Process = &os.Process{Pid: c.Pid()}
return &windowsPty{c: c, cmd: cmdObj}, cmdObj, nil
}
func windowsCommandLine(command string) string {
return "cmd.exe /c " + command
}
func (p *windowsPty) Read(buf []byte) (int, error) {
return p.c.Read(buf)
}
func (p *windowsPty) WriteString(s string) (int, error) {
return p.c.Write([]byte(s))
}
func (p *windowsPty) Resize(rows, cols uint16) error {
return p.c.Resize(int(cols), int(rows))
}
func (p *windowsPty) Running() bool {
return p.c != nil && p.c.Running()
}
func (p *windowsPty) Kill() error {
if p.c != nil {
return p.c.Kill()
}
return nil
}
func (p *windowsPty) Close() error {
var errs []string
p.closeOnce.Do(func() {
if p.c != nil {
if err := p.c.Close(); err != nil {
errs = append(errs, err.Error())
}
p.c = nil
}
})
if len(errs) > 0 {
return fmt.Errorf("close: %s", strings.Join(errs, "; "))
}
return nil
}