mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-09-21 17:38:10 +00:00
- 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 等打磨
80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
//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/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
|
||
}
|