# Buddy Companion

The buddy is an optional companion that lives in the sidebar of the TUI. It reacts to events (tool runs, message completions, idle time) with short in-character quips, powered by a local Ollama model.

## Setup

The buddy requires [Ollama](https://ollama.com) running locally. Install it, pull a model, then use `/buddy` in dreb to hatch your companion.

```bash
# Install Ollama and pull a model
ollama pull llama3.2

# In dreb, hatch your buddy
/buddy
```

After hatching, set which Ollama model the buddy should use for reactions:

```bash
/buddy model              # show current model + available models
/buddy model llama3.2     # set the buddy's model
```

The buddy won't react until a model is configured. The choice is persisted across sessions.

## Commands

| Command | Description |
|---|---|
| `/buddy` | Hatch a new buddy (or show an existing one — also brings back a buddy hidden via `/buddy off`) |
| `/buddy model` | Show current Ollama model and available models |
| `/buddy model <name>` | Set the Ollama model for buddy reactions |
| `/buddy pet` | Pet your buddy |
| `/buddy reroll` | Reroll for a new buddy (new species, name, personality) |
| `/buddy stats` | Show buddy stats panel |
| `/buddy off` | Hide the buddy (persists across sessions — it stays hidden on restart until you run `/buddy`) |

## How It Works

- **Bones** (species, rarity, stats, shiny) are deterministic from your username + hostname + a reroll counter
- **Soul** (name, personality, backstory) is generated once by your main model on first hatch and persisted
- **Reactions** are generated by the local Ollama model — short, in-character quips based on what just happened
- **Activity indicator** shows "thinking..." in the buddy panel while waiting for Ollama to respond

## Troubleshooting

### Buddy never reacts / always shows fallback message

Check that Ollama is running and has at least one model installed:

```bash
ollama list
```

If no models are listed, pull one:

```bash
ollama pull llama3.2
```

### Reasoning model shows chain-of-thought in speech bubbles

If you're using a reasoning model (e.g. `phi4-mini-reasoning`, `deepseek-r1`, `qwen3`) and the buddy's speech bubbles show the model's internal reasoning instead of just the final answer, the model's Ollama configuration likely doesn't declare thinking support properly.

**How Ollama detects thinking models:** Ollama checks the model's template for a `{{.Thinking}}` field reference, or looks for a registered parser, or checks the model family. If none of these match, Ollama treats reasoning output as regular content — meaning `<think>...</think>` tags get passed through as literal text.

**Check your model's capabilities:**

```bash
ollama show your-model-name
```

Look for `thinking` in the Capabilities section. If it's missing, the model isn't configured as a thinking model.

**Fix: Create a custom Modelfile** that adds `{{.Thinking}}` to the template. Here's an example for phi4-mini-reasoning:

```dockerfile
FROM phi4-mini-reasoning:latest
TEMPLATE """{{- if .System }}<|system|>{{ .System }}
{{- end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if ne .Role "system" }}<|{{ .Role }}|>
{{- if and (eq .Role "assistant") .Thinking }}<think>
{{ .Thinking }}</think>
{{- end }}{{ .Content }}
{{- if not $last }}<|end|>
{{- end }}
{{- if and (ne .Role "assistant") $last }}<|end|><|assistant|>{{ end }}
{{- end }}
{{- end }}"""
```

Then create the fixed model:

```bash
ollama create phi4-mini-reasoning-fixed -f Modelfile
```

Verify it now has thinking capability:

```bash
ollama show phi4-mini-reasoning-fixed
# Should show "thinking" in Capabilities
```

**Why this happens:** Many community and smaller reasoning models on Ollama ship with templates that don't include `{{.Thinking}}`. Without this, Ollama's `thinking.InferTags` heuristic can't detect the model's thinking tags, so it doesn't separate reasoning from the final answer. The model still outputs `<think>...</think>` tags, but they end up in the content field instead of a structured reasoning field.

### Reasoning model thinks but never responds

If the buddy shows the activity indicator for a while but never produces a quip, the model may be spending its entire token budget on reasoning. dreb allocates 2048 tokens for buddy responses, which should be enough for most models, but very verbose reasoners may still exhaust it. Consider using a non-reasoning model for the buddy, or a smaller/faster one.
