feat: 加固 Agent CLI 执行边界并更新模型目录

收紧 SSH 命令护栏、权限校验与远程执行会话,并同步主流大模型供应商列表。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Logan.LiandCursor committed 2026-09-14 09:43:14 +08:00
1 parent 67660ae1d6
commit 2fd1624bec
18 files changed
+480 -49

No files matched your search

+17 -4
View File
@@ -19,6 +19,8 @@ type SSHExecuteTool struct {
timeout time.Duration // 默认命令超时
}
const maxSSHCommandTimeout = 300 * time.Second
// NewSSHExecuteTool 创建远程执行工具(内部建立 SSH 长连接) // Logan.Li
func NewSSHExecuteTool(cfg remoteexec.SSHConfig, timeout time.Duration) (*SSHExecuteTool, error) {
if timeout <= 0 {
@@ -82,12 +84,12 @@ func (t *SSHExecuteTool) Execute(ctx context.Context, args map[string]interface{
return &Result{Success: false, Error: "参数 command 不能为空"}, nil
}
timeout := t.timeout
timeout := boundedSSHTimeout(t.timeout)
if sec := IntParam(args, "timeout"); sec > 0 {
timeout = time.Duration(sec) * time.Second
timeout = boundedSSHTimeout(time.Duration(sec) * time.Second)
}
res, err := t.client.Exec(command, timeout)
res, err := t.client.ExecContext(ctx, command, timeout)
if err != nil {
return &Result{Success: false, Error: fmt.Sprintf("SSH 连接失败: %v", err)}, nil
}
@@ -103,4 +105,15 @@ func (t *SSHExecuteTool) Execute(ctx context.Context, args map[string]interface{
Output: output,
Error: res.Error,
}, nil
}
}
// boundedSSHTimeout 将模型提供的超时限制在平台允许范围内。 // Logan.Li
func boundedSSHTimeout(timeout time.Duration) time.Duration {
if timeout <= 0 {
return time.Second
}
if timeout > maxSSHCommandTimeout {
return maxSSHCommandTimeout
}
return timeout
}
@@ -0,0 +1,25 @@
package tools
import (
"testing"
"time"
)
func TestBoundedSSHTimeout(t *testing.T) {
cases := []struct {
name string
in time.Duration
want time.Duration
}{
{name: "non-positive", in: 0, want: time.Second},
{name: "normal", in: 60 * time.Second, want: 60 * time.Second},
{name: "too-large", in: 24 * time.Hour, want: 300 * time.Second},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := boundedSSHTimeout(tc.in); got != tc.want {
t.Fatalf("boundedSSHTimeout(%v)=%v, want %v", tc.in, got, tc.want)
}
})
}
}