From db024bcd50254b7bcbdf4ce234423c4819122962 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 03:23:20 +0800 Subject: [PATCH] =?UTF-8?q?gateway:=20a=20Command=20Code=20Go=20conversati?= =?UTF-8?q?on=20moved=20onto=20its=20plugin=20keeps=20its=20reasoning=20?= =?UTF-8?q?=E2=80=94=20the=20built-in=20replayed=20each=20assistant=20turn?= =?UTF-8?q?'s=20reasoning=20to=20/alpha/generate,=20and=20the=20chat=20req?= =?UTF-8?q?uest=20built=20for=20the=20plugin=20carried=20reasoning=5Fconte?= =?UTF-8?q?nt=20only=20to=20DeepSeek,=20so=20the=20plugin,=20which=20reads?= =?UTF-8?q?=20it,=20had=20none=20to=20replay.=20Command=20Code's=20plugin?= =?UTF-8?q?=20gets=20it=20too.=20TestCommandCodePluginReasoning=20fails=20?= =?UTF-8?q?without=20the=20change.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gateway/chat.go | 8 ++++++-- internal/gateway/plugin_parity_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/internal/gateway/chat.go b/internal/gateway/chat.go index eb08166ad..852829958 100644 --- a/internal/gateway/chat.go +++ b/internal/gateway/chat.go @@ -7,6 +7,8 @@ import ( "net" "strings" "time" + + "github.com/yetone/magpie/internal/provider" ) // ---- OpenAI Chat Completions -------------------------------------------------- @@ -176,7 +178,9 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte { if r.System != "" { msgs = append(msgs, map[string]any{"role": "system", "content": r.System}) } - deepseek := strings.Contains(host, "deepseek") + // DeepSeek takes a turn's reasoning back, as Command Code's plugin does + // for a Go key, as the built-in replayed it to /alpha/generate + replay := strings.Contains(host, "deepseek") || host == provider.CommandCodePlanID // A tool message holds text only, so the images tools returned go to // the model in a user message after the tool messages, as the start of // the user's own message when one comes next: some models' chat @@ -231,7 +235,7 @@ func buildChat(r *Request, model, host string, rejectTemp bool) []byte { if len(calls) > 0 { am["tool_calls"] = calls } - if deepseek && think != "" { + if replay && think != "" { am["reasoning_content"] = think } msgs = append(msgs, am) diff --git a/internal/gateway/plugin_parity_test.go b/internal/gateway/plugin_parity_test.go index 6d7a49c14..cc52b2b50 100644 --- a/internal/gateway/plugin_parity_test.go +++ b/internal/gateway/plugin_parity_test.go @@ -118,3 +118,22 @@ func TestCursorPluginFast(t *testing.T) { } } } + +// A Command Code Go conversation moved onto its plugin keeps its +// reasoning, as the built-in replayed it to /alpha/generate: its plugin +// reads reasoning_content. DeepSeek still gets it, others don't. +func TestCommandCodePluginReasoning(t *testing.T) { + reasoning := func(host string) any { + return chatBody(t, host)["messages"].([]any)[1].(map[string]any)["reasoning_content"] + } + for _, host := range []string{provider.CommandCodePlanID, "api.deepseek.com"} { + if got := reasoning(host); got != "pondered" { + t.Errorf("%s got reasoning %v", host, got) + } + } + for _, host := range []string{"api.openai.com", "cursor", "zed"} { + if got := reasoning(host); got != nil { + t.Errorf("%s got reasoning_content %v", host, got) + } + } +}