> ## Documentation Index
> Fetch the complete documentation index at: https://joe-pro-ai.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Topic Ledger

> A running log of things to say, one list per topic, that keeps adding deeper points as the conversation moves.

When a conversation covers several subjects, the Topic Ledger keeps a list of things to say on each one and keeps adding to it. It lives in `engine/topics.py` and appears as the **Topics** panel beside the cards.

## How a point gets filed

**1. The card names its topic**

Every live card carries a `topic` label of 2 to 4 words. A claim check reuses the topic of the turn it checks.

**2. The label is normalized**

Lowercase, `&` becomes `and`, hyphens and underscores become spaces, other punctuation is stripped, and at most four words are kept.

**3. Similar topics merge**

A new label joins an existing topic when either test passes. No embeddings are used.

* **Keyword overlap.** Stopwords are dropped, simple plurals are stemmed, and a Jaccard score of 0.5 or more merges.
* **Fuzzy string match.** A `SequenceMatcher` ratio of 0.82 or more on the normalized labels merges.

So `rent control` and `rent-control policy` become one topic.

**4. The lines become points**

NEXT and each BUILD piece become talking points. The comeback, the question, and a verified fact with its citations become their own points.

**5. Duplicates are dropped**

A line whose normalized text matches an existing point at a ratio of 0.85 or more is dropped. A repeated fact only adds its new source to the existing point.

## Keeping the last thing said

The ledger can only file what reaches the transcript, so the listening controls make sure nothing said is left in the audio buffer.

| Control | What happens |
| - | - |
| **Transcribe now** (button, or `T` when you are not typing) | The audio heard so far goes to speech-to-text at once, without waiting for the 650 ms pause or the 20 second segment cap. The row is marked `transcribed now`. |
| **Stop listening** | The last partial segment is transcribed before the source closes, so a sentence cut off mid-way still becomes a ledger row and a card. The row is marked `kept at stop`. |
| **Start listening** after a stop | The same session continues. Turn numbers, the transcript, the Topic Ledger and the cards carry on, and nothing resets. A reloaded page reads the earlier turns from `GET /turns`. |

Guards:

* A second press while a flush is still running is ignored (`already transcribing`).
* A buffer under 400 ms, or one with no speech in it, makes no speech-to-text call. The corner reads `nothing new to transcribe`.
* Both engines do this. With Muse Voice Transcribe, a flush ends the realtime stream to get the open turn back. If the stream returns nothing, it falls back to one file transcription of the pending audio, then reconnects. With the local Whisper fallback, the speech gate hands over its buffer. Whisper runs on its own thread, so a slow call never stalls capture, and Stop first reads any audio the device already buffered.

> [!TIP]
>
> Live check on the Windows desk, with a recording played through the live pipeline (`POST /listen-file`) and stopped 60% into its last sentence:
>
> ```text Muse Voice Transcribe theme={"dark"}
> turn-1 [pause]       Senator Maria Delgado told the Phoenix Chamber on March 14th ... only 600 riders a day.
> turn-2 [kept at stop] And everyone knows the Great Wall of China is visible
> ```
>
> Then Start again on a second recording, with Transcribe now pressed mid-sentence and Stop near the end:
>
> ```text Muse Voice Transcribe theme={"dark"}
> turn-3 [transcribed now] Honestly, electric cars are worse for the planet than gas cars.
> turn-4 [kept at stop]    ... because battery mining wipes out every emission saving. And the purple tractor costs
> ```
>
> The flush returned in about 0.4 seconds and the stop in under 0.5 seconds. The turns continued from `turn-2` to `turn-3`, and the ledger kept its topics. The Whisper fallback gave the same rows, a few seconds slower.

> [!NOTE]
>
> A flush that lands mid-word can split that word across two rows, for example `cars.` then `rs, because`. Press Transcribe now at the end of a phrase when you can.

## Point kinds

| Kind | Comes from | Sources |
| - | - | - |
| Talking point | NEXT, BUILD, or an expansion | None |
| Comeback | The card's comeback | None |
| Open question | The card's question | None |
| Verified fact | A `verified` fact line with citations, or an expansion fact backed by a supplied note | Kept and merged |

Each point has a **Mark said** toggle, so you can see what you have not used yet. The panel shows `unused / total` for each topic.

## Heat and the hottest topic

Each mention of a topic adds heat that halves every 300 seconds. The hottest topic is the one with the most recent, most frequent mentions. Topics are listed hottest first, and automatic expansion targets the hottest one.

## Expansion

Expansion asks Muse Spark Open (`OPENROUTER_LISTEN_MODEL`, default `meta/muse-spark-open`) for 2 or 3 deeper points on one topic. The prompt includes that topic's existing points and the notes that match it, which are the only citable sources.

* **Triggers.** After `TOPIC_IDLE_SECONDS` (default 20) of quiet, on the hottest topic, or when you click **Expand deeper** on any topic. Set `TOPIC_IDLE_SECONDS=0` to turn automatic expansion off.
* **Source rule.** A fact keeps its source only when that source is one of the supplied notes. Otherwise the source is dropped and the fact becomes a talking point. At most three points are kept per expansion.
* **Caps.** One expansion per topic every `TOPIC_COOLDOWN_SECONDS` (default 120), and `TOPIC_EXPAND_CAP` per session (default 15).

> [!NOTE]
>
> The slot is counted before the model call. A failed call still spends its slot, so retries cannot run up the bill.

When a cap blocks an expansion, `POST /topics/expand` returns a clear reason instead of failing quietly:

| Code | HTTP | Meaning |
| - | - | - |
| `cooldown` | 429 | That topic was expanded recently. The body includes `retry_after_s`. |
| `cap` | 429 | The session cap is used up. |
| `busy` | 409 | An automatic expansion was asked for, but the conversation is not idle yet. |
| `off` | 409 | Automatic expansion is turned off, or `OPENROUTER_API_KEY` is not set. |
| `empty` | 404 | No topic yet, or the topic id is unknown. |

## Saving and export

Every change is written to `sessions/<date>_<time>.json` (the folder is gitignored and set by `SESSIONS_DIR`). The write goes to a temp file first and is then swapped in, so a crash cannot leave a half-written session.

**Export .md** (`GET /topics/export.md`) downloads the whole ledger as markdown, hottest topic first, with said points checked off and expanded points marked:

```markdown sluice-topics-2026-11-03_20-15-00.md theme={"dark"}
# Sluice Box topic ledger · 2026-11-03_20-15-00

Expansions used: 2 of 15

## Rent Control
4 points, 1 said. Turns: turn-3, turn-7

### Talking points
- [x] Separate the price cap from the supply question.
- [ ] Ask which city's data they mean. (expanded)

### Open questions
- [ ] What would change your mind on the supply effect?
```

The example lines above are illustrative. The structure matches `TopicLedger.to_markdown()`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.