# The Conversations tab: pumping the LibreDesk conversations 2026-11-18. Two repositories: `~/aimsight-libredesk` (the pumping) and `aimsight-app` (the tab). ## Intent The client requests arrive by mail in LibreDesk (`helpdesk.sensima.ch`, v2.9.0). The user wants their conversations on the workstation, in full (the messages, the inline images, the attachments), for two uses: to help the support (a conversation read next to the station's data, the analyses and the support answers), and as training data. Nothing is ever written to LibreDesk. ## Goals, non-goals, anti-goals - **Goals**: a **Conversations** page in the app that pumps the conversations on demand and shows them; each conversation stored in `labeling/auto/conversations//`, committed in `~/aimsight-labeling` like the analyses and the support answers; the second pumping fetches only what changed. - **Non-goals (for now)**: linking a conversation to its stations (later: `acces/` of `~/aimsight-libredesk` maps a contact's e-mail to its serials); teaching the support agent to read `labeling/auto/conversations/` (`agents/agents/support.md`, a later change in `~/aimsight-agents`); turning the conversations into a training set (a later step; the raw material comes first); a scheduled pumping. - **Anti-goals**: any request to LibreDesk other than a `GET`; the API key passing through the app or read by Claude; the HTML of a client's mail rendered as HTML in the page (a mail can carry scripts or tracking pixels). ## Constraints - Read-only on LibreDesk, enforced by a guard test in `~/aimsight-libredesk`, like `tests/test_garde_fou_snippets.py` for the snippets. - The key: a dedicated LibreDesk agent "Lecture conversations" whose role has only `conversations:read_all` and `messages:read`, created by the user; its key and secret in `~/aimsight-libredesk/.env` (`LIBREDESK_API_KEY`, `LIBREDESK_API_SECRET`), never read by Claude. The `Authorization: token :` header goes only to the LibreDesk host (`add_unredirected_header`, as in `snippets/envoyer.py`). - Standard library only in `~/aimsight-libredesk` (its rule); its code and docs in French (its language); the app in English. - The app holds no domain logic: it calls the pumping of `~/aimsight-libredesk` as it calls `extraction/pumping.py` of `~/aimsight-data`. - Every conversation, by the user's decision: all the inboxes, all the statuses, no filter. - Committed in git, by the user's decision: the contacts' names and e-mails, and the attachments, go into the history of `~/aimsight-labeling`. - Every time in UTC. ## Approaches - **A. The pumping in `~/aimsight-libredesk`, called by the app** (chosen): all the LibreDesk code in one repository, the key never in the app, the guard test next to the existing one. Costs: two repositories touched, one more link in the app. - **B. Everything in the app** (`app/server/conversations.py`): shorter, one repository; but the app would carry LibreDesk's logic and the API key, which the rule of the repository forbids. - Dropped: a `claude` agent that pumps: too heavy for a download. ## The design ### `~/aimsight-libredesk/conversations/` (French) - `pomper.py`: the client restricted to three routes, all `GET`: `/api/v1/conversations/all` (`page`, `page_size` up to 500, `order_by=updated_at`, `order=desc`), `/api/v1/conversations/{uuid}/messages` (every page, private notes included), and the attachment URLs that the messages carry (`attachments[].url`, signed: `/uploads/{uuid}?…` on LibreDesk, or a bucket's host if production stores in S3), downloaded wherever they point, the `Authorization` header only to the LibreDesk host; never a URL found in a message's text. `python3 -m conversations.pomper [--depuis YYYY-MM-DD --jusqu-a YYYY-MM-DD] --sortie `. - **Incremental by default**: `/pumped.json` (`{"until": }`, committed with the conversations) holds the start time of the last pumping that **completed**; a run walks the list from the most recently updated and stops below that mark (minus an hour of margin), and writes the new mark only at its end: a run cut short is caught up by the next one. No mark: the whole history. With `--depuis/--jusqu-a`, the conversations updated in that range (`--jusqu-a` excluded), stored ones fetched again; the mark untouched. *(Builder's call.)* - A conversation is fetched in full each time it changed: `conversation.json` and `messages.json` rewritten, attachments already present not downloaded again (same name and size). - `pomper.sh`: loads `.env` (`set -a`, as `extraction/pump.sh`), one pumping at a time (`flock` on `out/conversations.lock`), output appended to `out/conversations.log`. - `pompage.py`: what the app calls, the twin of `extraction/pumping.py`: `start(depuis, jusqu_a, sortie)` → the process, `running()`, `log(lines)`. - Tests (`tests/`, `unittest`, the fake server `tests/faux_libredesk.py` extended): only `GET`, the key never sent to another host, the incremental stop, the transcript (below), an attachment re-download skipped. ### One conversation: `labeling/auto/conversations//` - `conversation.json`: the conversation as the API gives it (subject, status, contact, inbox, dates, tags), `previous_conversations` removed. - `messages.json`: the messages as the API gives them, the oldest first, attachment URLs replaced by their local path (`attachments/`; a signed URL expires). - `attachments/`: the files, under their name (a duplicate name prefixed by the attachment's uuid). - `transcript.md`: the readable thread, written from `messages.json`: per message, a heading `## — ()`, the text (`text_content`, or the HTML reduced to text: tags removed, entities decoded, paragraphs kept), the images as `![name](attachments/)`, the other attachments as links. The `activity` messages (assignments, status changes) on one line in italics. No raw HTML in it. ### The app: the **Conversations** page - A link `libredesk/` → `~/aimsight-libredesk` (ignored by git, in the README's table and install line, and in `CLAUDE.md`'s links). - `app/server/conversations.py`: imports `pompage` (as `station.py` imports `pumping`); `pump(body)` (optional From/To), `pump_state()` (`running`, `log`), `list()` (each folder of `labeling/auto/conversations/`: reference, subject, contact name, status, last message time, message and attachment counts, read from `conversation.json`/`messages.json`), `transcript(reference, dark)` (`transcript.md` HTML-escaped **before** Markdown, so a client's `