| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // DesktopReasoningDisplayMode normalizes the desktop-only presentation mode. |
| 9 | func (c *Config) DesktopReasoningDisplayMode() string { |
| 10 | if c != nil && strings.EqualFold(strings.TrimSpace(c.Desktop.SessionExperience), string(SessionExperienceDeep)) { |
| 11 | return "expanded" |
| 12 | } |
| 13 | if c != nil && strings.EqualFold(strings.TrimSpace(c.Desktop.SessionExperience), string(SessionExperienceStandard)) { |
| 14 | return "auto" |
| 15 | } |
| 16 | raw := strings.ToLower(strings.TrimSpace(c.Desktop.ReasoningDisplayMode)) |
| 17 | switch raw { |
| 18 | case "hidden", "summary", "auto", "expanded": |
| 19 | return raw |
| 20 | } |
| 21 | // Missing and unknown values use the classic live-follow behavior. A user |
| 22 | // selection is persisted as a valid enum and therefore returns above. |
| 23 | return "auto" |
| 24 | } |
| 25 | |
| 26 | // DesktopReasoningDisplayModeExplicit reports whether a valid new enum was stored. |
| 27 | func (c *Config) DesktopReasoningDisplayModeExplicit() bool { |
| 28 | if c != nil && strings.EqualFold(strings.TrimSpace(c.Desktop.SessionExperience), string(SessionExperienceDeep)) { |
| 29 | return true |
| 30 | } |
| 31 | if c != nil && strings.EqualFold(strings.TrimSpace(c.Desktop.SessionExperience), string(SessionExperienceStandard)) { |
| 32 | return true |
| 33 | } |
| 34 | switch strings.ToLower(strings.TrimSpace(c.Desktop.ReasoningDisplayMode)) { |
| 35 | case "hidden", "summary", "auto", "expanded": |
| 36 | return true |
| 37 | default: |
| 38 | return false |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // SetDesktopReasoningDisplayMode writes the UI preference and its legacy alias. |
| 43 | func (c *Config) SetDesktopReasoningDisplayMode(mode string) error { |
| 44 | switch strings.ToLower(strings.TrimSpace(mode)) { |
| 45 | case "hidden", "summary": |
| 46 | c.Desktop.ReasoningDisplayMode = strings.ToLower(strings.TrimSpace(mode)) |
| 47 | c.Desktop.ExpandThinking = false |
| 48 | case "auto", "expanded": |
| 49 | c.Desktop.ReasoningDisplayMode = strings.ToLower(strings.TrimSpace(mode)) |
| 50 | c.Desktop.ExpandThinking = true |
| 51 | default: |
| 52 | return fmt.Errorf("reasoning display mode %q: must be hidden|summary|auto|expanded", mode) |
| 53 | } |
| 54 | return nil |
| 55 | } |
| 56 | |
| 57 | // SetExpandThinking preserves the legacy desktop edit API. |
| 58 | func (c *Config) SetExpandThinking(on bool) error { |
| 59 | if on { |
| 60 | return c.SetDesktopReasoningDisplayMode("auto") |
| 61 | } |
| 62 | return c.SetDesktopReasoningDisplayMode("summary") |
| 63 | } |
| 64 | |
| 65 | func renderDesktopReasoningDisplayMode(b *strings.Builder, c *Config) { |
| 66 | fmt.Fprintf(b, "expand_thinking = %v # desktop: legacy reasoning display alias; use reasoning_display_mode\n", c.Desktop.ExpandThinking) |
| 67 | if c.DesktopReasoningDisplayModeExplicit() { |
| 68 | fmt.Fprintf(b, "reasoning_display_mode = %q # desktop: hidden|summary|auto|expanded reasoning presentation\n", c.DesktopReasoningDisplayMode()) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | func renderDesktopSessionExperience(b *strings.Builder, c *Config) { |
| 73 | if strings.TrimSpace(c.Desktop.SessionExperience) != "" { |
| 74 | fmt.Fprintf(b, "session_experience = %q # desktop: standard|deep transcript experience\n", c.DesktopSessionExperience()) |
| 75 | } |
| 76 | } |
| 77 |