diff --git a/chatbot/src/engines.js b/chatbot/src/engines.js
index 63ba87453..e7dc2706a 100644
--- a/chatbot/src/engines.js
+++ b/chatbot/src/engines.js
@@ -14,12 +14,13 @@ export const EXECUTORS = [
{ id: "pi", icon: "terminal", label: "Pi", detail: "使用 Pi 与个人 API Key。" },
{ id: "dsh", icon: "terminal", label: "DeepSeek Harness", detail: "使用 DeepSeek Harness 与个人 API Key。" },
{ id: "zcode", icon: "terminal", label: "ZCode", detail: "使用 ZCode 与个人 API Key。" },
+ { id: "traecli", icon: "terminal", label: "TRAE CLI", detail: "使用 TRAE CLI 与个人 API Key。" },
];
// Bundled logo per CLI; an unknown CLI falls back to its model's brand.
const brands = {
codebuddy: "codebuddy", codex: "codex", "claude-code": "claude",
- opencode: "opencode", cursor: "cursor", agy: "antigravity", kimi: "kimi-code", pi: "pi", dsh: "deepseek", zcode: "zhipu",
+ opencode: "opencode", cursor: "cursor", agy: "antigravity", kimi: "kimi-code", pi: "pi", dsh: "deepseek", zcode: "zhipu", traecli: "trae",
};
export const engineBrand = (id) => Object.hasOwn(brands, id) ? brands[id] : "";
diff --git a/internal/domain/agent.go b/internal/domain/agent.go
index 8e6d15294..4f088f0d6 100644
--- a/internal/domain/agent.go
+++ b/internal/domain/agent.go
@@ -20,12 +20,13 @@ var ExecutorEffortLevels = map[string][]string{
"pi": {"minimal", "low", "medium", "high", "xhigh", "max"},
"dsh": {"none", "low", "high", "max"},
"zcode": {"low", "high", "max"},
+ "traecli": {"low", "medium", "high", "xhigh"},
}
// AgentCLIExecutorKinds are the agent CLIs beyond CodeBuddy / Codex / Claude
// Code. Their model and MCP configuration lives in a private HOME, so they
// only run with the responsible user's personal credentials.
-var AgentCLIExecutorKinds = []string{"opencode", "cursor", "agy", "kimi", "pi", "dsh", "zcode"}
+var AgentCLIExecutorKinds = []string{"opencode", "cursor", "agy", "kimi", "pi", "dsh", "zcode", "traecli"}
func IsAgentCLIKind(kind string) bool {
kind = strings.TrimSpace(kind)
diff --git a/internal/domain/runner.go b/internal/domain/runner.go
index 963a4b77b..b447b285e 100644
--- a/internal/domain/runner.go
+++ b/internal/domain/runner.go
@@ -314,7 +314,7 @@ func (r Runner) RuntimeAuthMode(provider string) string {
func SupportsRunnerLogin(provider string) bool {
switch strings.ToLower(strings.TrimSpace(provider)) {
- case "codex", "claude-code", "agy":
+ case "codex", "claude-code", "agy", "traecli":
return true
default:
return false
diff --git a/internal/domain/user.go b/internal/domain/user.go
index d55026290..ed8afcc28 100644
--- a/internal/domain/user.go
+++ b/internal/domain/user.go
@@ -238,6 +238,7 @@ var AgentCLIProtocolOptions = map[string][]string{
"dsh": {AgentCLIProtocolChat, AgentCLIProtocolResponses, AgentCLIProtocolMessages},
"zcode": {AgentCLIProtocolMessages, AgentCLIProtocolChat, AgentCLIProtocolResponses},
"agy": {AgentCLIProtocolGemini, AgentCLIProtocolChat},
+ "traecli": {AgentCLIProtocolResponses, AgentCLIProtocolChat},
}
// NormalizeAgentCLIProtocol returns a supported protocol choice; unknown
diff --git a/internal/httpapi/executor_models.go b/internal/httpapi/executor_models.go
index c96344a3c..2526629ea 100644
--- a/internal/httpapi/executor_models.go
+++ b/internal/httpapi/executor_models.go
@@ -174,8 +174,9 @@ func executorModelCatalogs(kimiBaseURL string) map[string]executorModelCatalog {
},
"kimi": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["kimi"])},
"pi": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["pi"])},
- "dsh": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["dsh"])},
- "zcode": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["zcode"])},
+ "dsh": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["dsh"])},
+ "zcode": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["zcode"])},
+ "traecli": {CustomModel: true, Efforts: effortOptions(domain.ExecutorEffortLevels["traecli"])},
}
for engine, catalog := range catalogs {
modelEngine := engine
diff --git a/internal/repo/catalog.go b/internal/repo/catalog.go
index 369eb6c85..b91006b4c 100644
--- a/internal/repo/catalog.go
+++ b/internal/repo/catalog.go
@@ -244,6 +244,7 @@ func BuiltInExecutors() []domain.ExecutorDefinition {
{ID: "pi", Name: "Pi", Kind: "pi", Binary: "pi", Protocol: "stream-json"},
{ID: "dsh", Name: "DeepSeek Harness", Kind: "dsh", Binary: "dsh", Protocol: "stream-json"},
{ID: "zcode", Name: "ZCode", Kind: "zcode", Binary: "zcode", Protocol: "stream-json"},
+ {ID: "traecli", Name: "TRAE CLI", Kind: "traecli", Binary: "traecli", Protocol: "stream-json"},
}
}
diff --git a/internal/runner/detect.go b/internal/runner/detect.go
index df7ab9137..4ecb5bb46 100644
--- a/internal/runner/detect.go
+++ b/internal/runner/detect.go
@@ -48,6 +48,7 @@ var defaultProviders = []providerSpec{
// The official ZCode has no npm package and its --help omits
// --output-format, so compatibility is probed with the flags we pass.
{Kind: "zcode", Binary: "zcode", VersionFlags: []string{"--output-format", "stream-json", "--mode", "yolo"}},
+ {Kind: "traecli", Binary: "traecli", Update: "update"},
}
// terminalProviderKind is the built-in remote-terminal capability: the
diff --git a/internal/runtime/agent_cli.go b/internal/runtime/agent_cli.go
index 4efb03764..647809c66 100644
--- a/internal/runtime/agent_cli.go
+++ b/internal/runtime/agent_cli.go
@@ -27,6 +27,7 @@ const (
AgentCLIPi = "pi"
AgentCLIDeepSeek = "dsh"
AgentCLIZCode = "zcode"
+ AgentCLITraeCLI = "traecli"
)
// AgentCLIKinds is the display order of the agent CLIs.
@@ -70,7 +71,7 @@ func agentCLIModelOptional(kind, baseURL string) bool {
case AgentCLICursor, AgentCLIZCode:
// ZCode resolves an unset model itself (applyZCodeCredential).
return true
- case AgentCLIAntigravity, AgentCLIDeepSeek:
+ case AgentCLIAntigravity, AgentCLIDeepSeek, AgentCLITraeCLI:
return baseURL == ""
}
return false
@@ -105,6 +106,7 @@ var agentCLIHostEnv = append([]string{
"KIMI_MODEL_NAME", "KIMI_MODEL_API_KEY", "KIMI_MODEL_BASE_URL", "KIMI_MODEL_PROVIDER_TYPE", kimiThinkingEffortEnv,
"OPENCODE_CONFIG", "OPENCODE_CONFIG_CONTENT", "OPENCODE_CONFIG_DIR", "PI_CODING_AGENT_DIR",
"ZCODE_DATA_BASE_DIR", zcodePersonalFileEnv,
+ "TRAE_HOME", "TRAECLI_PERSONAL_ACCESS_TOKEN",
}, zcodeHostEnv...)
// agentCLIConfigPaths are the HOME-relative files an agent CLI reads its MCP
@@ -117,6 +119,7 @@ var agentCLIMCPPaths = map[string]string{
AgentCLIPi: ".pi/agent/mcp.json",
AgentCLIDeepSeek: ".dsh/agentflow-mcp.json",
AgentCLIZCode: zcodeConfigPath,
+ AgentCLITraeCLI: ".trae/traecli.toml",
}
// AgentCLIMCPOptions shapes the MCP configuration of one invocation.
@@ -186,6 +189,9 @@ func WriteAgentCLIMCPConfig(kind string, home AgentCLIHome, entries map[string]a
}
}
}
+ if kind == AgentCLITraeCLI {
+ return writeAgentCLIFile(home, rel, []byte(traeCLIMCPTOML(entries, ids)))
+ }
var document any
switch kind {
case AgentCLIOpenCode:
@@ -377,7 +383,7 @@ func ApplyAgentCLICredential(kind string, cred ProviderCredential, options Agent
if key == "" {
return nil, nil, fmt.Errorf("需求责任人未配置 %s API Key,请在个人配置中配置", AgentCLILabel(kind))
}
- if kind == AgentCLIAntigravity {
+ if kind == AgentCLIAntigravity || kind == AgentCLITraeCLI {
// A crashed account-login invocation may leave a credential copy.
// API-key execution must not retain or inherit that account.
login, _ := runnerLoginSpec(kind)
@@ -512,6 +518,25 @@ func ApplyAgentCLICredential(kind string, cred ProviderCredential, options Agent
return applyDeepSeekCredential(home, homeEnv, key, baseURL, protocol, model, strings.TrimSpace(options.Effort), argv)
case AgentCLIZCode:
return applyZCodeCredential(home, homeEnv, key, baseURL, protocol, model, strings.TrimSpace(options.Effort), argv)
+ case AgentCLITraeCLI:
+ env[agentCLIKeyEnv] = key
+ env["TRAE_HOME"] = homeEnv + "/.trae"
+ endpoint := baseURL
+ if endpoint == "" {
+ endpoint = "https://api.openai.com/v1"
+ }
+ wireAPI := "responses"
+ if protocol == AgentCLIProtocolChat {
+ wireAPI = "chat"
+ }
+ argv = insertTraeCLIConfigArgs(argv,
+ "-c", `model_provider="agentflow"`,
+ "-c", `model_providers.agentflow.name="AgentFlow"`,
+ "-c", "model_providers.agentflow.base_url="+strconv.Quote(endpoint),
+ "-c", "model_providers.agentflow.env_key="+strconv.Quote(agentCLIKeyEnv),
+ "-c", "model_providers.agentflow.wire_api="+strconv.Quote(wireAPI),
+ "-c", "model_providers.agentflow.requires_openai_auth=false",
+ )
default:
return nil, nil, fmt.Errorf("unknown agent CLI %q", kind)
}
@@ -644,6 +669,8 @@ func AgentCLILabel(kind string) string {
return "DeepSeek Harness"
case AgentCLIZCode:
return "ZCode"
+ case AgentCLITraeCLI:
+ return "TRAE CLI"
}
return kind
}
@@ -671,3 +698,126 @@ func withCursorModelArg(argv []string, id string) []string {
}
return argv
}
+
+func traeCLIMCPTOML(entries map[string]any, ids []string) string {
+ var b strings.Builder
+ for _, id := range ids {
+ entry, _ := entries[id].(map[string]any)
+ if entry == nil {
+ continue
+ }
+ name := dshServerNameRe.ReplaceAllString(id, "_")
+ if name == "" {
+ continue
+ }
+ url, _ := entry["url"].(string)
+ command, _ := entry["command"].(string)
+ if url == "" && command == "" {
+ continue
+ }
+ b.WriteString("[mcp_servers.")
+ b.WriteString(name)
+ b.WriteString("]\n")
+ if url != "" {
+ b.WriteString("url = ")
+ b.WriteString(strconv.Quote(url))
+ b.WriteByte('\n')
+ if headers := tomlStringMap(entry["headers"]); len(headers) > 0 {
+ b.WriteString("http_headers = ")
+ b.WriteString(formatTOMLInlineTable(headers))
+ b.WriteByte('\n')
+ }
+ } else {
+ b.WriteString("command = ")
+ b.WriteString(strconv.Quote(command))
+ b.WriteByte('\n')
+ if cwd, _ := entry["cwd"].(string); strings.TrimSpace(cwd) != "" {
+ b.WriteString("cwd = ")
+ b.WriteString(strconv.Quote(cwd))
+ b.WriteByte('\n')
+ }
+ if args, ok := entry["args"].([]string); ok && len(args) > 0 {
+ quoted := make([]string, len(args))
+ for i, a := range args {
+ quoted[i] = strconv.Quote(a)
+ }
+ b.WriteString("args = [")
+ b.WriteString(strings.Join(quoted, ", "))
+ b.WriteString("]\n")
+ } else if args, ok := entry["args"].([]any); ok && len(args) > 0 {
+ quoted := make([]string, 0, len(args))
+ for _, a := range args {
+ if s, ok := a.(string); ok {
+ quoted = append(quoted, strconv.Quote(s))
+ }
+ }
+ if len(quoted) > 0 {
+ b.WriteString("args = [")
+ b.WriteString(strings.Join(quoted, ", "))
+ b.WriteString("]\n")
+ }
+ }
+ if env := tomlStringMap(entry["env"]); len(env) > 0 {
+ b.WriteString("env = ")
+ b.WriteString(formatTOMLInlineTable(env))
+ b.WriteByte('\n')
+ }
+ }
+ b.WriteString("default_tools_approval_mode = \"approve\"\n")
+ b.WriteString("tool_timeout_sec = 600\n\n")
+ }
+ return b.String()
+}
+
+func tomlStringMap(raw any) map[string]string {
+ switch m := raw.(type) {
+ case map[string]string:
+ if len(m) == 0 {
+ return nil
+ }
+ return m
+ case map[string]any:
+ if len(m) == 0 {
+ return nil
+ }
+ out := make(map[string]string, len(m))
+ for k, v := range m {
+ if s, ok := v.(string); ok {
+ out[k] = s
+ }
+ }
+ return out
+ default:
+ return nil
+ }
+}
+
+func formatTOMLInlineTable(m map[string]string) string {
+ keys := make([]string, 0, len(m))
+ for k := range m {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ pairs := make([]string, 0, len(keys))
+ for _, k := range keys {
+ pairs = append(pairs, strconv.Quote(k)+" = "+strconv.Quote(m[k]))
+ }
+ return "{ " + strings.Join(pairs, ", ") + " }"
+}
+
+func insertTraeCLIConfigArgs(argv []string, extra ...string) []string {
+ if len(argv) < 2 {
+ return append(append([]string{}, argv...), extra...)
+ }
+ insertAt := len(argv) - 1
+ for i := 0; i < len(argv)-1; i++ {
+ if argv[i] == "resume" {
+ insertAt = i
+ break
+ }
+ }
+ out := make([]string, 0, len(argv)+len(extra))
+ out = append(out, argv[:insertAt]...)
+ out = append(out, extra...)
+ return append(out, argv[insertAt:]...)
+}
diff --git a/internal/runtime/agent_cli_stream.go b/internal/runtime/agent_cli_stream.go
index 079798cac..3375c1d0f 100644
--- a/internal/runtime/agent_cli_stream.go
+++ b/internal/runtime/agent_cli_stream.go
@@ -176,6 +176,8 @@ func NewAgentCLITranslator(kind string) func(string) []string {
translate = (&dshStream{}).translate
case AgentCLIZCode:
translate = (&zcodeStream{}).translate
+ case AgentCLITraeCLI:
+ translate = (&traeCLIStream{}).translate
default:
return nil
}
@@ -669,3 +671,66 @@ func (d *dshStream) translate(s *ClaudeStream, raw map[string]any) []string {
}
return out
}
+
+// traeCLIStream translates `traecli exec --json` (Codex-compatible JSONL)
+// events into ClaudeStream lines.
+type traeCLIStream struct{ failure string }
+
+func (t *traeCLIStream) translate(s *ClaudeStream, raw map[string]any) []string {
+ typ := stringValue(raw["type"])
+ session := stringValue(raw["thread_id"])
+ if session == "" {
+ session = stringValue(raw["threadId"])
+ }
+ switch typ {
+ case "thread.started":
+ return s.Init(session, "")
+ case "turn.completed":
+ usage, _ := raw["usage"].(map[string]any)
+ s.AddUsage(int64Value(usage["input_tokens"]), int64Value(usage["output_tokens"]), int64Value(usage["cached_input_tokens"]), 0, int64Value(usage["reasoning_output_tokens"]))
+ return s.Result("", false)
+ case "turn.failed":
+ msg := stringValue(raw["message"])
+ if msg == "" {
+ msg = errorText(raw)
+ }
+ if msg == "" {
+ msg = "TRAE CLI turn failed"
+ }
+ t.failure = msg
+ return s.Result(msg, true)
+ case "error":
+ if msg := errorText(raw); msg != "" {
+ t.failure = msg
+ }
+ case "item.started":
+ item, _ := raw["item"].(map[string]any)
+ switch stringValue(item["type"]) {
+ case "command_execution", "mcp_tool_call", "tool_call":
+ name := stringValue(item["command"])
+ if name == "" {
+ name = stringValue(item["name"])
+ }
+ return s.ToolUse(stringValue(item["id"]), name, item)
+ }
+ case "item.completed":
+ item, _ := raw["item"].(map[string]any)
+ switch stringValue(item["type"]) {
+ case "reasoning":
+ return s.Thinking(stringValue(item["text"]))
+ case "agent_message":
+ return s.Text(stringValue(item["text"]))
+ case "command_execution", "mcp_tool_call", "tool_call":
+ failed := int64Value(item["exit_code"]) != 0 || stringValue(item["status"]) == "failed"
+ out := stringValue(item["aggregated_output"])
+ if out == "" {
+ out = stringValue(item["output"])
+ }
+ if out == "" {
+ out = stringValue(item["text"])
+ }
+ return s.ToolResult(stringValue(item["id"]), failed, out)
+ }
+ }
+ return nil
+}
diff --git a/internal/runtime/agent_cli_traecli_test.go b/internal/runtime/agent_cli_traecli_test.go
new file mode 100644
index 000000000..d51c58494
--- /dev/null
+++ b/internal/runtime/agent_cli_traecli_test.go
@@ -0,0 +1,143 @@
+package runtime
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "slices"
+ "strings"
+ "testing"
+
+ "agentflow/internal/domain"
+)
+
+func TestTraeCLICommandAndCredentials(t *testing.T) {
+ if !domain.IsAgentCLIKind(AgentCLITraeCLI) || !domain.SupportsRunnerLogin(AgentCLITraeCLI) {
+ t.Fatalf("traecli must be an AgentCLI supporting runner login")
+ }
+
+ sop := AgentCLICommand(AgentCLITraeCLI, AgentCLICommandOptions{
+ Prompt: "fix bug",
+ SystemPrompt: "SYS",
+ Model: "gpt-5",
+ Effort: "high",
+ })
+ if sop.Provider != AgentCLITraeCLI {
+ t.Fatalf("provider = %q", sop.Provider)
+ }
+ for _, want := range []string{"traecli", "exec", "--json", "--skip-git-repo-check", "--dangerously-bypass-hook-trust", `approval_policy="never"`, "--permission-mode", "bypass_permissions", "--model", "gpt-5"} {
+ if !slices.Contains(sop.Argv, want) {
+ t.Fatalf("sop argv missing %q: %q", want, sop.Argv)
+ }
+ }
+ if slices.Contains(sop.Argv, "--sandbox") {
+ t.Fatalf("sop argv must not set both --sandbox and --permission-mode: %q", sop.Argv)
+ }
+ if !slices.Contains(sop.Argv, `model_reasoning_effort="high"`) {
+ t.Fatalf("sop argv missing reasoning effort: %q", sop.Argv)
+ }
+ if last := sop.Argv[len(sop.Argv)-1]; !strings.Contains(last, "SYS") || !strings.HasSuffix(last, "fix bug") {
+ t.Fatalf("sop prompt = %q", last)
+ }
+
+ chat := AgentCLICommand(AgentCLITraeCLI, AgentCLICommandOptions{
+ Prompt: "hi",
+ Chat: true,
+ Resume: "thread-1",
+ })
+ if !slices.Contains(chat.Argv, "--sandbox") || !slices.Contains(chat.Argv, "read-only") || !slices.Contains(chat.Argv, "resume") || !slices.Contains(chat.Argv, "thread-1") || slices.Contains(chat.Argv, "--permission-mode") {
+ t.Fatalf("chat argv = %q", chat.Argv)
+ }
+
+ dir := t.TempDir()
+ home := AgentCLIHome{Base: dir, Rel: "home"}
+ if err := os.MkdirAll(filepath.Join(dir, "home"), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := WriteAgentCLIMCPConfig(AgentCLITraeCLI, home, map[string]any{
+ "agentflow-session": map[string]any{
+ "url": "http://127.0.0.1:9999/mcp",
+ "headers": map[string]string{"Authorization": "Bearer tok"},
+ },
+ "agentflow-gate": map[string]any{
+ "command": "/app/bin/agentflow-gate-mcp",
+ "cwd": "/workspace",
+ "args": []string{"--stdio"},
+ "env": map[string]string{"AGENTFLOW_GATE_RESULT_PATH": "/workspace/.agentflow/gate.json"},
+ },
+ }, AgentCLIMCPOptions{ReadOnly: true}); err != nil {
+ t.Fatalf("WriteAgentCLIMCPConfig: %v", err)
+ }
+ tomlBytes, err := os.ReadFile(filepath.Join(dir, "home", ".trae", "traecli.toml"))
+ if err != nil {
+ t.Fatalf("read traecli.toml: %v", err)
+ }
+ tomlText := string(tomlBytes)
+ for _, want := range []string{
+ "[mcp_servers.agentflow-session]",
+ `url = "http://127.0.0.1:9999/mcp"`,
+ `http_headers = { "Authorization" = "Bearer tok" }`,
+ "[mcp_servers.agentflow-gate]",
+ `command = "/app/bin/agentflow-gate-mcp"`,
+ `cwd = "/workspace"`,
+ `args = ["--stdio"]`,
+ `env = { "AGENTFLOW_GATE_RESULT_PATH" = "/workspace/.agentflow/gate.json" }`,
+ `default_tools_approval_mode = "approve"`,
+ } {
+ if !strings.Contains(tomlText, want) {
+ t.Fatalf("traecli.toml missing %q:\n%s", want, tomlText)
+ }
+ }
+
+ argv, env, err := ApplyAgentCLICredential(AgentCLITraeCLI, ProviderCredential{
+ APIKey: "sk-trae",
+ BaseURL: "https://gw.example/v1",
+ Protocol: AgentCLIProtocolChat,
+ }, AgentCLIOptions{Model: "m1"}, home, filepath.Join(dir, "home"), chat.Argv)
+ if err != nil {
+ t.Fatalf("ApplyAgentCLICredential: %v", err)
+ }
+ if env[agentCLIKeyEnv] != "sk-trae" || env["TRAE_HOME"] != filepath.ToSlash(filepath.Join(dir, "home", ".trae")) {
+ t.Fatalf("env = %+v", env)
+ }
+ resumeIdx := slices.Index(argv, "resume")
+ providerIdx := slices.Index(argv, `model_provider="agentflow"`)
+ if resumeIdx < 0 || providerIdx < 0 || providerIdx > resumeIdx {
+ t.Fatalf("provider config must precede resume: %q", argv)
+ }
+ if !slices.Contains(argv, `model_providers.agentflow.wire_api="chat"`) {
+ t.Fatalf("missing wire_api=chat: %q", argv)
+ }
+}
+
+func TestTraeCLIStreamTranslator(t *testing.T) {
+ tr := NewAgentCLITranslator(AgentCLITraeCLI)
+ if tr == nil {
+ t.Fatal("missing traecli translator")
+ }
+ lines := []string{
+ `{"type":"thread.started","thread_id":"th-1"}`,
+ `{"type":"item.completed","item":{"id":"r1","type":"reasoning","text":"think"}}`,
+ `{"type":"item.started","item":{"id":"c1","type":"command_execution","command":"ls"}}`,
+ `{"type":"item.completed","item":{"id":"c1","type":"command_execution","exit_code":0,"aggregated_output":"ok"}}`,
+ `{"type":"item.completed","item":{"id":"m1","type":"agent_message","text":"done"}}`,
+ `{"type":"turn.completed","usage":{"input_tokens":10,"output_tokens":5,"cached_input_tokens":2}}`,
+ }
+ var got []map[string]any
+ for _, line := range lines {
+ for _, out := range tr(line) {
+ var m map[string]any
+ if err := json.Unmarshal([]byte(out), &m); err != nil {
+ t.Fatalf("invalid json %q: %v", out, err)
+ }
+ got = append(got, m)
+ }
+ }
+ if len(got) == 0 {
+ t.Fatal("expected translated events")
+ }
+ last := got[len(got)-1]
+ if last["type"] != "result" || last["is_error"] != false || last["session_id"] != "th-1" {
+ t.Fatalf("unexpected terminal event: %+v", last)
+ }
+}
diff --git a/internal/runtime/conversation_approval.go b/internal/runtime/conversation_approval.go
index 9de5b7051..3f474b546 100644
--- a/internal/runtime/conversation_approval.go
+++ b/internal/runtime/conversation_approval.go
@@ -78,9 +78,9 @@ func InstallConversationApproval(root, provider string, command CommandSpec) (Co
if err := writeAgentCLIFile(home, zcodeConfigPath, data); err != nil {
return command, err
}
- case "codex":
+ case "codex", AgentCLITraeCLI:
entry := "hooks.PreToolUse=[{hooks=[{type=\"command\",command=" + strconv.Quote(launch) + ",timeout=" + strconv.Itoa(conversationApprovalHookWatchdog) + "}]}]"
- command.Argv = append(command.Argv[:len(command.Argv)-1], "-c", "features.hooks=true", "-c", entry, command.Argv[len(command.Argv)-1])
+ command.Argv = insertTraeCLIConfigArgs(command.Argv, "-c", "features.hooks=true", "-c", entry)
case AgentCLIKimi:
// Kimi blocks only on exit code 2 and allows any other exit,
// including an interpreter that is missing or crashed.
diff --git a/internal/runtime/conversation_runner_login.go b/internal/runtime/conversation_runner_login.go
index f28b44cf9..49786ba4d 100644
--- a/internal/runtime/conversation_runner_login.go
+++ b/internal/runtime/conversation_runner_login.go
@@ -28,6 +28,8 @@ func runnerLoginSpec(provider string) (conversationLoginSpec, bool) {
return conversationLoginSpec{"Claude Code", ".claude", ".credentials.json", "CLAUDE_CONFIG_DIR", BindClaudeCode}, true
case AgentCLIAntigravity:
return conversationLoginSpec{"Antigravity", ".gemini/antigravity-cli", "antigravity-oauth-token", "", BindAgentCLI}, true
+ case AgentCLITraeCLI:
+ return conversationLoginSpec{"TRAE CLI", ".trae/cli", "auth.json", "TRAE_HOME", BindAgentCLI}, true
default:
return conversationLoginSpec{}, false
}
@@ -66,7 +68,11 @@ func PrepareRunnerSandboxLogin(sandbox Sandbox, provider, runID, nodeID string)
}
env["HOME"] = homePath
if login.configEnv != "" {
- env[login.configEnv] = filepath.ToSlash(filepath.Join(homePath, login.dir))
+ val := filepath.ToSlash(filepath.Join(homePath, login.dir))
+ if login.configEnv == "TRAE_HOME" {
+ val = filepath.ToSlash(filepath.Join(homePath, ".trae"))
+ }
+ env[login.configEnv] = val
}
return env, cleanup, nil
}
@@ -129,6 +135,9 @@ func prepareRunnerLogin(home AgentCLIHome, login conversationLoginSpec, enabled
}
}
configDir := strings.TrimSpace(os.Getenv(login.configEnv))
+ if configDir != "" && login.configEnv == "TRAE_HOME" {
+ configDir = filepath.Join(configDir, "cli")
+ }
if configDir == "" {
base, _ := os.UserHomeDir()
if base != "" {
@@ -137,7 +146,7 @@ func prepareRunnerLogin(home AgentCLIHome, login conversationLoginSpec, enabled
}
var data []byte
var keepAntigravity func([]byte) error
- if login.binding == BindAgentCLI {
+ if login.binding == BindAgentCLI && login.configEnv == "" {
data, keepAntigravity, err = readAntigravityRunnerLogin()
} else {
data, err = readRunnerLoginFile(configDir, login.file)
diff --git a/internal/runtime/conversation_sandbox.go b/internal/runtime/conversation_sandbox.go
index 2b88b4be4..cbbeaae1a 100644
--- a/internal/runtime/conversation_sandbox.go
+++ b/internal/runtime/conversation_sandbox.go
@@ -270,6 +270,8 @@ func dockerCLISetup(provider, binary string) (string, error) {
// The official CLI is shipped with ZCode or built from its source;
// it has no standalone npm package. Never install a namesake.
installer = "echo 'ZCode CLI 未安装;请在工作区镜像中预装官方 ZCode CLI 并将 zcode 加入 PATH' >&2; exit 1"
+ case AgentCLITraeCLI:
+ installer = "echo 'TRAE CLI 未安装;请在工作区镜像中预装官方 TRAE CLI 并将 traecli 加入 PATH' >&2; exit 1"
case AgentCLICursor:
installer = conversationScriptInstaller(cursorInstallerURL)
case AgentCLIAntigravity:
diff --git a/internal/runtime/provider_agentcli.go b/internal/runtime/provider_agentcli.go
index 600d4a649..b3f8d1df0 100644
--- a/internal/runtime/provider_agentcli.go
+++ b/internal/runtime/provider_agentcli.go
@@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"slices"
+ "strconv"
"strings"
"agentflow/internal/domain"
@@ -228,6 +229,24 @@ func AgentCLICommand(kind string, o AgentCLICommandOptions) CommandSpec {
argv = append(argv, "--resume", resume)
}
argv = append(argv, extra...)
+ case AgentCLITraeCLI:
+ argv = []string{binary, "exec", "--json", "--skip-git-repo-check", "--dangerously-bypass-hook-trust", "-c", `approval_policy="never"`}
+ if readOnly {
+ argv = append(argv, "--sandbox", "read-only")
+ } else {
+ argv = append(argv, "--permission-mode", "bypass_permissions")
+ }
+ if model != "" {
+ argv = append(argv, "--model", model)
+ }
+ if effort != "" {
+ argv = append(argv, "-c", "model_reasoning_effort="+strconv.Quote(effort))
+ }
+ argv = append(argv, extra...)
+ if resume != "" {
+ argv = append(argv, "resume", resume)
+ }
+ argv = append(argv, prompt)
}
return CommandSpec{Argv: argv, Provider: kind, AgentCLI: options}
}
diff --git a/web/app/agents.js b/web/app/agents.js
index aa9b56d4b..4284a14f3 100644
--- a/web/app/agents.js
+++ b/web/app/agents.js
@@ -117,7 +117,7 @@ function syncAgentTabIndicators(){$$('#agentsView .agent-tabs, #agentModal .agen
if(typeof document!=='undefined'&&document.fonts?.ready)document.fonts.ready.then(()=>syncAgentTabIndicators()).catch(()=>{});
function pickerHTML(items,selected,prefix){return `${(items||[]).map(x=>``).join('')||'暂无可用资产,请先到对应的资产管理页面添加'}`}
function bindPickerFilters(root){(root||document).querySelectorAll('[data-picker-filter]').forEach(input=>input.oninput=()=>{const q=input.value.trim().toLowerCase();input.parentElement.querySelectorAll('.asset-check').forEach(row=>row.hidden=!!q&&!row.textContent.toLowerCase().includes(q))})}
-function executorOptions(selected){const allowed=new Set(['codebuddy','codex','claude','opencode','cursor','agy','kimi','pi','dsh','zcode']),items=(state.data.executors||[]).filter(x=>allowed.has(x.id)),legacy=selected&&!allowed.has(selected)?``:'';return legacy+items.map(x=>``).join('')}
+function executorOptions(selected){const allowed=new Set(['codebuddy','codex','claude','opencode','cursor','agy','kimi','pi','dsh','zcode','traecli']),items=(state.data.executors||[]).filter(x=>allowed.has(x.id)),legacy=selected&&!allowed.has(selected)?``:'';return legacy+items.map(x=>``).join('')}
const AGENT_CUSTOM_MODEL='__custom__';
let executorModelCatalogUser, executorModelCatalogRequest, agentModelRevision=0;
function executorModelCatalogs(){
diff --git a/web/app/assistant-models.js b/web/app/assistant-models.js
index ee9f6daad..6dab2abf4 100644
--- a/web/app/assistant-models.js
+++ b/web/app/assistant-models.js
@@ -29,7 +29,7 @@
const CLI_ICON = {
codebuddy:'codebuddy.svg', codex:'codex.svg', 'claude-code':'claude.svg',
opencode:'opencode.svg', cursor:'cursor.svg', agy:'antigravity.svg',
- kimi:'kimi-code.png', pi:'pi.svg', dsh:'deepseek.svg', zcode:'glm.svg'
+ kimi:'kimi-code.png', pi:'pi.svg', dsh:'deepseek.svg', zcode:'glm.svg', traecli:'trae.svg'
};
let catalog = {
default: DEFAULT_MODEL,
@@ -39,7 +39,7 @@
function familyOf(id) {
const raw = String(id || '').toLowerCase();
- const v = raw.replace(/^(?:codebuddy|codex|claude-code|opencode|cursor|agy|kimi|pi|dsh|zcode):/, '').split('/').at(-1);
+ const v = raw.replace(/^(?:codebuddy|codex|claude-code|opencode|cursor|agy|kimi|pi|dsh|zcode|traecli):/, '').split('/').at(-1);
if (/^(?:claude|anthropic|opus|sonnet|haiku|fable)(?:$|[-_.\s:\d])/.test(v)) return 'claude';
if (/^composer(?:$|[-_.\s:\d])/.test(v) || (raw.startsWith('cursor:') && /^auto(?:-smart)?$/.test(v))) return 'cursor';
if (v.startsWith('gpt') || v.includes('codex')) return 'gpt';
diff --git a/web/app/runners.js b/web/app/runners.js
index f625de4da..912b60ba7 100644
--- a/web/app/runners.js
+++ b/web/app/runners.js
@@ -56,7 +56,7 @@ function runnerStatusLabel(status,lastSeen){
const style=status==='online'?' online':status==='offline'?' offline':'';
return `${escapeHTML(label)}`;
}
-const runnerCLILabels={'claude-code':'Claude Code','codex':'Codex','codebuddy':'CodeBuddy',opencode:'OpenCode',cursor:'Cursor CLI',agy:'Antigravity',kimi:'Kimi Code',pi:'Pi',dsh:'DeepSeek Harness',zcode:'ZCode'};
+const runnerCLILabels={'claude-code':'Claude Code','codex':'Codex','codebuddy':'CodeBuddy',opencode:'OpenCode',cursor:'Cursor CLI',agy:'Antigravity',kimi:'Kimi Code',pi:'Pi',dsh:'DeepSeek Harness',zcode:'ZCode',traecli:'TRAE CLI'};
const runnerAuthLabel={local:'账号登录',personal:'API Key'};
const runnerAuthDescription={local:'Claude Code、Codex 和 Antigravity 可以使用运行 Runner 的系统账号在这台机器上的已有登录,对话与 SOP 的 native、Docker 沙箱均可复用。共享对话中,只有机器所有者发言时会使用此登录。',personal:'读取「个人配置」中保存的 API Key。对话使用当前发言人的 Key,SOP 使用运行责任人的 Key。Antigravity 的 Gemini API Key 按 API 单独计费。'};
const runnerOSLabels={darwin:'macOS',linux:'Linux',windows:'Windows'};
@@ -72,7 +72,7 @@ function runnerPersonalCredentialConfigured(provider){
return !!user.agentCliCredentials?.[provider]?.apiKeyConfigured;
}
function runnerRuntimeSupportsLogin(runtime){
- return runtime.provider==='codex'||runtime.provider==='claude-code'||runtime.provider==='agy';
+ return runtime.provider==='codex'||runtime.provider==='claude-code'||runtime.provider==='agy'||runtime.provider==='traecli';
}
function runnerRuntimeAuthMode(runtime){
return runnerRuntimeSupportsLogin(runtime)&&runtime.authMode!=='personal'?'local':'personal';
diff --git a/web/app/workbench.js b/web/app/workbench.js
index 1b210afda..de1f279b4 100644
--- a/web/app/workbench.js
+++ b/web/app/workbench.js
@@ -107,6 +107,8 @@ const CREDENTIAL_KINDS=[
note:'未填写 Base URL 时连接 DeepSeek 官方服务。',protocols:[['chat','Chat Completions'],['responses','Responses'],['messages','Messages(Anthropic)']]}),
agentCliCredentialKind('zcode',{name:'ZCode',logo:'glm',baseUrl:'https://open.bigmodel.cn/api/anthropic',
note:'未填写 Base URL 时连接智谱 BigModel 的 Anthropic 兼容服务(Messages)。',protocols:[['messages','Messages(Anthropic)'],['chat','Chat Completions'],['responses','Responses']]}),
+ agentCliCredentialKind('traecli',{name:'TRAE CLI',logo:'trae',baseUrl:'https://api.openai.com/v1',
+ note:'未填写 Base URL 时默认使用 OpenAI 兼容端点;也可在个人执行机器上选「账号登录」复用本地登录态。',protocols:[['responses','Responses'],['chat','Chat Completions']]}),
];
function agentCliCredentialKind(cli,o){
const field=`agentCli.${cli}.`,configurable=!!o.protocols;
diff --git a/web/images/credentials/trae.svg b/web/images/credentials/trae.svg
new file mode 100644
index 000000000..741f44dba
--- /dev/null
+++ b/web/images/credentials/trae.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/web/syntax_test.go b/web/syntax_test.go
index 8713f3c49..ac911193c 100644
--- a/web/syntax_test.go
+++ b/web/syntax_test.go
@@ -502,18 +502,18 @@ const count = (html, needle) => html.split(needle).length - 1;
// Groups list credentials in a fixed order.
assert.deepEqual(cred.CREDENTIAL_GROUPS.map(g => g.id), ['platform', 'model']);
assert.deepEqual(cred.CREDENTIAL_KINDS.filter(k => k.group === 'platform').map(k => k.key), ['gitToken', 'gitSshKey', 'gitHttpCredentials']);
-assert.deepEqual(cred.CREDENTIAL_KINDS.filter(k => k.group === 'model').map(k => k.key), ['codeBuddyApiKey', 'codexApiKey', 'claudeCodeApiKey', 'agentCli.opencode', 'agentCli.cursor', 'agentCli.agy', 'agentCli.kimi', 'agentCli.pi', 'agentCli.dsh', 'agentCli.zcode']);
+assert.deepEqual(cred.CREDENTIAL_KINDS.filter(k => k.group === 'model').map(k => k.key), ['codeBuddyApiKey', 'codexApiKey', 'claudeCodeApiKey', 'agentCli.opencode', 'agentCli.cursor', 'agentCli.agy', 'agentCli.kimi', 'agentCli.pi', 'agentCli.dsh', 'agentCli.zcode', 'agentCli.traecli']);
// Progress, next-step hint, filter counts and per-group counts.
const html = credentialPanelHTML(user);
-assert.ok(html.includes('2 / 13 已配置'));
+assert.ok(html.includes('2 / 14 已配置'));
assert.ok(html.includes('data-credential-setup="codeBuddyApiKey"'), 'next step follows Git → CodeBuddy');
-assert.ok(html.includes('1 / 3') && html.includes('1 / 10'));
-assert.ok(html.includes('已配置2') && html.includes('未配置11'));
-assert.equal(count(html, 'data-credential-row='), 13);
+assert.ok(html.includes('1 / 3') && html.includes('1 / 11'));
+assert.ok(html.includes('已配置2') && html.includes('未配置12'));
+assert.equal(count(html, 'data-credential-row='), 14);
assert.ok(!html.includes('credential-grid') && !html.includes('credential-savebar') && !html.includes('userCredentialForm'));
// Unconfigured rows only offer 去配置; configured rows carry an inline editor with delete.
-assert.equal(count(html, 'data-credential-act="setup"'), 11);
+assert.equal(count(html, 'data-credential-act="setup"'), 12);
assert.equal(count(html, 'credential-editor-form'), 2);
assert.equal(count(html, 'data-credential-act="delete"'), 2);
for (const key of ['codeBuddyApiKey', 'claudeCodeApiKey']) {
@@ -845,10 +845,11 @@ global.state = {data: {executors: [
{id: 'pi', name: 'Pi'},
{id: 'dsh', name: 'DeepSeek Harness'},
{id: 'zcode', name: 'ZCode'},
+ {id: 'traecli', name: 'TRAE CLI'},
{id: 'mock', name: '演示执行器'}
]}};
eval(code.slice(code.indexOf('function executorOptions('), code.indexOf('function selectAgent(')));
-for (const id of ['opencode', 'cursor', 'agy', 'kimi', 'pi', 'dsh', 'zcode']) {
+for (const id of ['opencode', 'cursor', 'agy', 'kimi', 'pi', 'dsh', 'zcode', 'traecli']) {
assert.ok(executorOptions(id).includes('value="' + id + '" selected'), id);
}
assert.ok(!executorOptions('codex').includes('value="mock"'));