Refactored orchestrator for staged file handling, added structured prompt support, adjusted Feishu file handling
This commit is contained in:
@@ -94,6 +94,9 @@ func (t *Tool) Call(ctx context.Context, input string) (string, error) {
|
||||
if runtime.GOOS == "windows" {
|
||||
// Windows 下使用 cmd /C 执行,兼容 date、dir 等内建命令。
|
||||
cmd = exec.CommandContext(runCtx, "cmd", "/C", trimmed)
|
||||
} else if requiresShellParsing(trimmed) {
|
||||
// 包含管道、重定向等语法时,必须交给 shell 解释。
|
||||
cmd = exec.CommandContext(runCtx, "sh", "-c", trimmed)
|
||||
} else {
|
||||
cmd = exec.CommandContext(runCtx, base, parts[1:]...)
|
||||
}
|
||||
@@ -126,3 +129,7 @@ func normalizeWindowsCommand(command string) string {
|
||||
return command
|
||||
}
|
||||
}
|
||||
|
||||
func requiresShellParsing(command string) bool {
|
||||
return strings.ContainsAny(command, "|&;<>()$`\\\n")
|
||||
}
|
||||
|
||||
@@ -40,3 +40,27 @@ func TestCallWindowsDateIsNonInteractive(t *testing.T) {
|
||||
t.Fatal("expected non-empty output for date command")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequiresShellParsing(t *testing.T) {
|
||||
if !requiresShellParsing("echo hi | cat") {
|
||||
t.Fatal("expected pipe command to require shell parsing")
|
||||
}
|
||||
if requiresShellParsing("echo hello") {
|
||||
t.Fatal("expected simple command to not require shell parsing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallSupportsPipeOnUnix(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("unix-only behavior test")
|
||||
}
|
||||
tool := New([]string{"echo"}, ".", 3*time.Second, 4000, nil)
|
||||
out, err := tool.Call(context.Background(), "printf hello | wc -c")
|
||||
if err != nil {
|
||||
t.Fatalf("expected pipeline command success, got err=%v output=%q", err, out)
|
||||
}
|
||||
trimmed := strings.TrimSpace(out)
|
||||
if trimmed != "5" {
|
||||
t.Fatalf("expected output 5, got %q", trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user