Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion chatbot/src/engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] : "";

Expand Down
3 changes: 2 additions & 1 deletion internal/domain/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/domain/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/httpapi/executor_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/repo/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/runner/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
154 changes: 152 additions & 2 deletions internal/runtime/agent_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
AgentCLIPi = "pi"
AgentCLIDeepSeek = "dsh"
AgentCLIZCode = "zcode"
AgentCLITraeCLI = "traecli"
)

// AgentCLIKinds is the display order of the agent CLIs.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -644,6 +669,8 @@ func AgentCLILabel(kind string) string {
return "DeepSeek Harness"
case AgentCLIZCode:
return "ZCode"
case AgentCLITraeCLI:
return "TRAE CLI"
}
return kind
}
Expand Down Expand Up @@ -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:]...)
}
65 changes: 65 additions & 0 deletions internal/runtime/agent_cli_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Loading