Add per-chat thinking levels for Codex, Claude Code and OpenCode

Codex: model/list supportedReasoningEfforts per model, turn/start effort,
thread reasoningEffort as the current level. Claude Code: initialize
supportedEffortLevels, apply_flag_settings effortLevel at the next turn
start. OpenCode v2: model variants via the session model endpoint.
chat_effort sets a level; rows and chat_models carry the levels; Codex and
Claude levels persist in operator_sessions.chat_effort and are re-applied
before every turn.
This commit is contained in:
2026-11-09 20:07:41 +00:00
parent 8ca5a1fdda
commit 06001697c8
25 changed files with 1306 additions and 23 deletions
+13
View File
@@ -259,6 +259,13 @@ type ChatModel struct {
ID string `json:"id"`
Provider string `json:"provider"`
Name string `json:"name,omitempty"`
// Efforts are the thinking levels this model accepts and DefaultEffort the
// one its harness uses when none is chosen; both empty when it has none.
Efforts []ChatEffort `json:"efforts,omitempty"`
DefaultEffort string `json:"default_effort,omitempty"`
// Resolved is the concrete model an alias names (Claude Code's "opus"),
// so a model a reply reports can be matched to its entry. Never sent.
Resolved string `json:"-"`
}
// ChatMode is one permission mode a chat harness offers.
@@ -297,6 +304,12 @@ type ChatSession struct {
// ModeName is Mode's display name. With no stored mode both name the
// harness default, so a client can show the mode without a chat_modes read.
ModeName string `json:"mode_name,omitempty"`
// Effort is the stored thinking level ("" for the harness default), and
// Efforts/DefaultEffort the levels the row's model accepts, when the
// server knows them without starting the harness. No Efforts: no control.
Effort string `json:"effort,omitempty"`
Efforts []ChatEffort `json:"efforts,omitempty"`
DefaultEffort string `json:"default_effort,omitempty"`
// InstructionStatus is the observed create-time preload outcome: applied,
// unsupported, failed, or not_requested. Ordinary list rows omit it.
InstructionStatus string `json:"instruction_status,omitempty"`
+53
View File
@@ -0,0 +1,53 @@
package protocol
import "strings"
// ChatEffortSelect sets one chat's thinking (reasoning effort) level for its
// next and later turns. The body is ChatEffortRequest naming a level of the
// chat's current model; the reply echoes the stored level with the model's
// levels. A running turn keeps the level it started with.
const ChatEffortSelect = "chat_effort"
// ChatEffort is one thinking level a chat's model accepts, as its harness
// names it (Codex reasoning efforts, Claude Code effort levels, OpenCode
// model variants).
type ChatEffort struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
}
// ChatEffortRequest is the chat_effort body, its reply, and the current level
// a chat_models reply reports. Effort "" means the harness's own default.
// Efforts and DefaultEffort are reply-only: the levels the chat's current (or
// saved next-turn) model accepts, and the level the harness uses when none
// was chosen, when it reports one. No Efforts means the model has no level
// the harness can set, so no control is offered.
type ChatEffortRequest struct {
SessionID string `json:"session_id"`
Effort string `json:"effort"`
Efforts []ChatEffort `json:"efforts,omitempty"`
DefaultEffort string `json:"default_effort,omitempty"`
}
// ChatEffortName is the display name for a level id a harness reports without
// one: the id in title case, with xhigh spelled out.
func ChatEffortName(id string) string {
switch id {
case "":
return ""
case "xhigh":
return "Extra high"
}
return strings.ToUpper(id[:1]) + id[1:]
}
// HasChatEffort reports whether id is one of efforts.
func HasChatEffort(efforts []ChatEffort, id string) bool {
for _, effort := range efforts {
if effort.ID == id {
return true
}
}
return false
}
+65
View File
@@ -0,0 +1,65 @@
package protocol
import (
"encoding/json"
"reflect"
"strings"
"testing"
)
func TestChatEffortMessagesRoundTrip(t *testing.T) {
levels := []ChatEffort{{ID: "low", Name: "Low", Description: "Fast"}, {ID: "xhigh", Name: "Extra high"}}
for _, message := range []Message{
{Type: ChatEffortSelect, ID: "set", EffortRequest: &ChatEffortRequest{SessionID: "s", Effort: "xhigh"}},
{Type: ChatEffortSelect, ID: "set", EffortRequest: &ChatEffortRequest{SessionID: "s", Effort: "", Efforts: levels, DefaultEffort: "low"}},
{Type: ChatModels, ID: "models", ChatModels: []ChatModel{{ID: "m", Provider: "p", Name: "M", Efforts: levels, DefaultEffort: "low"}}, EffortRequest: &ChatEffortRequest{SessionID: "s", Effort: "low", Efforts: levels}},
} {
raw, err := json.Marshal(message)
if err != nil {
t.Fatal(err)
}
var decoded Message
if err := json.Unmarshal(raw, &decoded); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(decoded, message) {
t.Fatalf("round trip\n got %+v\nwant %+v\njson %s", decoded, message, raw)
}
}
// The wire names the client reads.
raw, _ := json.Marshal(Message{Type: ChatEffortSelect, EffortRequest: &ChatEffortRequest{SessionID: "s", Effort: "high", Efforts: levels, DefaultEffort: "low"}})
for _, want := range []string{`"type":"chat_effort"`, `"chat_effort":{"session_id":"s","effort":"high","efforts":[{"id":"low","name":"Low","description":"Fast"}`, `"default_effort":"low"`} {
if !strings.Contains(string(raw), want) {
t.Fatalf("%s lacks %s", raw, want)
}
}
}
func TestChatSessionAndModelEffortFields(t *testing.T) {
raw, _ := json.Marshal(ChatSession{ID: "s", Effort: "max", Efforts: []ChatEffort{{ID: "max", Name: "Max"}}, DefaultEffort: "max"})
for _, want := range []string{`"effort":"max"`, `"efforts":[{"id":"max","name":"Max"}]`, `"default_effort":"max"`} {
if !strings.Contains(string(raw), want) {
t.Fatalf("%s lacks %s", raw, want)
}
}
// A row or model without levels sends none, and Resolved never leaves.
raw, _ = json.Marshal(ChatSession{ID: "s"})
if strings.Contains(string(raw), "effort") {
t.Fatalf("level-less row sends effort fields: %s", raw)
}
raw, _ = json.Marshal(ChatModel{ID: "opus", Provider: "claude", Resolved: "claude-opus-5-5"})
if strings.Contains(string(raw), "claude-opus-5-5") || strings.Contains(string(raw), "effort") {
t.Fatalf("model leaks internal fields: %s", raw)
}
}
func TestChatEffortName(t *testing.T) {
for id, want := range map[string]string{"": "", "low": "Low", "xhigh": "Extra high", "max": "Max", "minimal": "Minimal", "none": "None"} {
if got := ChatEffortName(id); got != want {
t.Errorf("ChatEffortName(%q) = %q, want %q", id, got, want)
}
}
if !HasChatEffort([]ChatEffort{{ID: "high"}}, "high") || HasChatEffort([]ChatEffort{{ID: "high"}}, "max") || HasChatEffort(nil, "") {
t.Fatal("HasChatEffort")
}
}
+3
View File
@@ -240,6 +240,9 @@ type Message struct {
ChatModes []ChatMode `json:"chat_modes,omitempty"`
// ModeRequest is the chat_mode body and echoed selection.
ModeRequest *ChatModeRequest `json:"chat_mode,omitempty"`
// EffortRequest is the chat_effort body and reply, and the chat's current
// thinking level on a chat_models reply.
EffortRequest *ChatEffortRequest `json:"chat_effort,omitempty"`
// ChatSubscribe attaches this connection to one session's shared stream; the
// body names the session like ChatQuery. A chat_prompt response sets
// ChatQueued when the prompt had to wait for an in-flight turn and was