yao/agent/sandbox/v2/shell.go
Max 3f390c223c feat(sandbox/v2): enhance V2 sandbox integration and testing
- Implemented V2 sandbox initialization in the assistant loading process, allowing for standalone sandbox.yao configuration.
- Added support for V2 sandbox execution paths in the Assistant's Stream method, differentiating between V1 and V2 sandboxes.
- Introduced comprehensive tests for V2 sandbox configurations, ensuring correct loading and execution behavior.
- Updated the context and types to accommodate V2 sandbox features, including system information and workspace management.

Made-with: Cursor
2026-03-10 01:13:17 +08:00

47 lines
1.2 KiB
Go

package sandboxv2
import (
"strings"
infra "github.com/yaoapp/yao/sandbox/v2"
)
// shellKind identifies which shell to use for command execution.
type shellKind int
const (
shellSh shellKind = iota // Unix: sh -c
shellPwsh // Windows: pwsh -NoProfile -Command
shellPS // Windows: powershell -NoProfile -Command
shellCmd // Windows: cmd.exe /C (last-resort fallback)
)
// shellWrap returns the Exec command slice to run a script string.
func shellWrap(kind shellKind, script string) []string {
switch kind {
case shellPwsh:
return []string{"pwsh", "-NoProfile", "-Command", script}
case shellPS:
return []string{"powershell", "-NoProfile", "-Command", script}
case shellCmd:
return []string{"cmd.exe", "/C", script}
default:
return []string{"sh", "-c", script}
}
}
// shellFromSystem resolves shellKind from ComputerInfo().System.Shell
// reported by the Tai node at registration time.
func shellFromSystem(computer infra.Computer) shellKind {
shell := strings.ToLower(computer.ComputerInfo().System.Shell)
switch shell {
case "pwsh":
return shellPwsh
case "powershell":
return shellPS
case "cmd.exe", "cmd":
return shellCmd
default:
return shellSh
}
}