Files
HomeAgent/internal/plugins/agentcli/pty_windows.go
JianFeeeee 147d0baaf9 fix: LLM 工具循环 400、中断消息注入、ConPTY 终端支持
- agent: 工具轮请求尾部补 user 占位(zen 网关强制),tool 消息正确配对
- agent: 工具提醒/中断以 system 角色注入并带 [中断消息] 前缀,不进用户履历;系统提示词说明中断消息格式
- agentcli: 基于 ConPTY 的交互式终端(ptywin fork),terminal_create/read/write/resize/close/watch
- webui: server 输出通道适配器(保留 reasoning_content/disable_thinking)
- GUI: 沉浸式标题栏、icon 圆角重制、mascot 等打磨
2026-08-14 00:48:40 +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"
"gitcode.com/JianFeeeee/HomeAgent/internal/ptywin"
)
func defaultShell() string { return "cmd.exe" }
// windowsPty 基于 internal/ptywinConPTY的终端后端。
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
}