[PR #8598] [MERGED] feat(chats): export a selected range of messages #8696

Closed
opened 2026-11-07 17:39:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8598
Author: @SpicyMarinara
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/chat-range-export-8547


📝 Commits (8)

  • db20500 feat(chats): export a selected range of messages (#8547)
  • d0a518c fix(chats): keep Export selected to range selections
  • d0b8b0b fix(chats): harden the range export preview after review
  • fd8bb4c test(chats): tighten the range assertions; keep a newer selection
  • 0c338ad fix(chats): resolve {{input}} inside a range export
  • b42eb75 fix(chats): read a snapshot name from string extras; test echo alone
  • 8030b44 test(chats): keep the whole-chat {{input}} result pinned
  • 6aaffde fix(chats): a changed selection ends the export it was submitted for

📊 Changes

12 files changed (+566 additions, -46 deletions)

View changed files

📝 e2e/chat-insights.e2e.ts (+113 -0)
📝 packages/client/src/components/chat/ChatArea.tsx (+118 -5)
📝 packages/client/src/components/chat/ChatBranchesPanel.tsx (+21 -1)
📝 packages/client/src/components/chat/ChatCommonOverlays.tsx (+38 -13)
📝 packages/client/src/components/chat/ChatConversationSurface.tsx (+7 -1)
📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+7 -1)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+6 -1)
📝 packages/client/src/hooks/use-chats.ts (+14 -2)
📝 packages/client/src/lib/chat-floating-ui-events.ts (+7 -0)
📝 packages/client/src/localization/locales/en.json (+8 -0)
📝 packages/server/src/routes/chats.routes.ts (+72 -22)
➕ scripts/regressions/chat-range-export.regression.ts (+155 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #8547

Why this change

  • Long roleplays run to thousands of messages. To show someone a continuity or memory failure, a user had to export the whole chat: a large file that also gives away unrelated story content. They need to share only the exchange that matters.

What changed

  • Export a range: Chat Branches (Chat Settings) has a new "Export a range" button. It closes Chat Settings and puts the chat into message selection; pick the first and last message you want and press Export selected. The export covers every message from the first to the last you picked, in chat order.
  • Preview before exporting: the dialog says how many messages will be exported and quotes both boundary messages with their speakers. You then pick Text, Markdown, JSONL or Story, the same formats as the full export.
  • Export only, never delete: a selection started this way offers Export selected and Cancel, with no Delete selected. The existing delete selection is unchanged.
  • Nothing in the chat changes: the export only reads, and the export file is named <chat name> excerpt.<ext>.
  • Each message carries its selected swipe in the export, not the hidden alternate regenerations.
  • {{input}} in an exported message resolves within the range, so an excerpt never fills in a user message it leaves out. A whole-chat export is unchanged.
  • JSONL excerpts leave out chat-wide state: summaries, journal, advanced-memory records, location history and the game world snapshot all stay out of the header, since they describe the rest of the story. A whole-chat JSONL export is unchanged.
  • Server: GET /api/chats/:id/export accepts startMessageId and endMessageId. One without the other answers 400; a message that is not in the chat answers 404. Passing neither exports the whole chat as before.
  • Game chats have no "Export a range" button, because game rows cannot be selected.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Validation run locally

  • pnpm check — passed (includes localization, Prettier, lint, type checks and the production build).
  • pnpm localization:check — passed.
  • node scripts/run-regressions.mjs --filter chat-range-export — passed (new).
  • node scripts/run-regressions.mjs --filter chat-export-swipes-batch — passed.
  • node scripts/run-regressions.mjs --filter bulk-export-zips — passed.
  • node scripts/run-regressions.mjs --filter chat-story-export — passed.
  • node scripts/run-regressions.mjs --filter native-export-memory — passed on its own. It also failed once when run beside all other export regressions at once, where it measures a 128 MB heap under parallel load; it passes when run alone and in the per-file lane.
  • pnpm regression:ui e2e/chat-insights.e2e.ts --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1 — 9 passed. The new range-export test passes on all three projects. The existing "chat search, stats and story exports" test failed once on mobile Chromium in a full three-project run, then passed alone and in two further mobile Chromium runs of the whole file.
  • pnpm regression:ui e2e/core-flows.e2e.ts --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1 --grep "message deletion uses unified chroma" — 3 passed (the delete selection bar is unchanged).
  • The new regression fails without the server change (AssertionError: text range leaked "msg 0", because the route ignores the range parameters and exports the whole chat), and passes with it.

Local CodeRabbit review

Two passes were fixed and the findings addressed in commits fix(chats): harden the range export preview after review and test(chats): tighten the range assertions; keep a newer selection.

  • Accepted and fixed: a non-string personaSnapshot.name would throw while the preview was built; an export finishing after the user switched chats (or started a newer selection) cleared that newer selection; the regression's single-message case only checked the message was present, and the alternate-swipe check only rejected a line that was exactly msg 3. Both regression gaps are now covered by one check that rejects any message text left outside the exported rows.
  • Fifth pass, also fixed: any change to the selected messages now ends the run an in-flight export was submitted for, so an export that finishes after the user picks a different range leaves that newer selection open.
  • Fourth pass, also fixed: the preview now reads a user message's persona name through the file's existing parseMessageExtraRecord and getPersonaSnapshotName helpers, so a message whose extra is stored as a JSON string still shows the persona that wrote it. The {{input}} case now exports the echoing message on its own too, so the check fails if the macro reaches a user message outside the range. The new test's cleanup reports a disposal failure only when the test itself passed; throwing from a finally is dropped there.
  • Third pass, also fixed: a message in the range using {{input}} resolved to the chat's latest user message even when that message was outside the range, so the excerpt carried text it was meant to leave out (proven with a probe: echo: OUTSIDE latest user secret 2). lastInput now comes from the exported messages. The regression covers the case and fails under the old behaviour.
  • Declined: CodeRabbit reported lint/correctness/noUnsafeFinally (a Biome rule) for the test cleanup's throw cleanupFailure inside finally. This repository validates with ESLint and Prettier, has no Biome configuration, and pnpm check passes on the file. The block is copied verbatim from the finally cleanup of the test that already existed in this file (staging, e2e/chat-insights.e2e.ts:226), so it is the file's established teardown pattern rather than something this PR introduces.

Manual verification notes

  • Manually verify exporting messages 3–7 as Markdown from Chat Branches in the browser, desktop and phone width
  • Manually verify the export dialog's count and boundary quotes match the messages you picked, light and dark theme
  • Manually verify the exported JSONL re-imports through Chat Branches → Import as a chat of just those messages
  • Manually verify a game chat shows no "Export a range" button

Screenshots of the open dialog on phone width were captured locally but not uploaded; please attach before/after evidence if helpful.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

  • New copy uses the semantic keys chat.rangeExport.* in the English catalog only; other locales fall back to English.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8598 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/chat-range-export-8547` --- ### 📝 Commits (8) - [`db20500`](https://github.com/Pasta-Devs/Marinara-Engine/commit/db20500843ffcc5bac156d6742ad5d5d770aa744) feat(chats): export a selected range of messages (#8547) - [`d0a518c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d0a518c57564eb4d7c8e48989b0a365e93e27f0c) fix(chats): keep Export selected to range selections - [`d0b8b0b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d0b8b0b524894f8837d41ab85dcc44aa9dcfdefe) fix(chats): harden the range export preview after review - [`fd8bb4c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fd8bb4c2efca23a95f17cd09d82699fa2eac8112) test(chats): tighten the range assertions; keep a newer selection - [`0c338ad`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0c338ad32f6f5624d04c292866d3a26f5c9e0749) fix(chats): resolve {{input}} inside a range export - [`b42eb75`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b42eb75c7f81d01e63e0fd4139f9fc5db7c1ec1e) fix(chats): read a snapshot name from string extras; test echo alone - [`8030b44`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8030b44d24738143bfa277f6d77138d29a58af51) test(chats): keep the whole-chat {{input}} result pinned - [`6aaffde`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6aaffde68776d06c7bec2d06ab9395b54ee0029e) fix(chats): a changed selection ends the export it was submitted for ### 📊 Changes **12 files changed** (+566 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `e2e/chat-insights.e2e.ts` (+113 -0) 📝 `packages/client/src/components/chat/ChatArea.tsx` (+118 -5) 📝 `packages/client/src/components/chat/ChatBranchesPanel.tsx` (+21 -1) 📝 `packages/client/src/components/chat/ChatCommonOverlays.tsx` (+38 -13) 📝 `packages/client/src/components/chat/ChatConversationSurface.tsx` (+7 -1) 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+7 -1) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+6 -1) 📝 `packages/client/src/hooks/use-chats.ts` (+14 -2) 📝 `packages/client/src/lib/chat-floating-ui-events.ts` (+7 -0) 📝 `packages/client/src/localization/locales/en.json` (+8 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+72 -22) ➕ `scripts/regressions/chat-range-export.regression.ts` (+155 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #8547 ## Why this change - Long roleplays run to thousands of messages. To show someone a continuity or memory failure, a user had to export the whole chat: a large file that also gives away unrelated story content. They need to share only the exchange that matters. ## What changed - **Export a range:** Chat Branches (Chat Settings) has a new "Export a range" button. It closes Chat Settings and puts the chat into message selection; pick the first and last message you want and press **Export selected**. The export covers every message from the first to the last you picked, in chat order. - **Preview before exporting:** the dialog says how many messages will be exported and quotes both boundary messages with their speakers. You then pick Text, Markdown, JSONL or Story, the same formats as the full export. - **Export only, never delete:** a selection started this way offers Export selected and Cancel, with no Delete selected. The existing delete selection is unchanged. - **Nothing in the chat changes:** the export only reads, and the export file is named `<chat name> excerpt.<ext>`. - **Each message carries its selected swipe** in the export, not the hidden alternate regenerations. - **`{{input}}` in an exported message resolves within the range**, so an excerpt never fills in a user message it leaves out. A whole-chat export is unchanged. - **JSONL excerpts leave out chat-wide state:** summaries, journal, advanced-memory records, location history and the game world snapshot all stay out of the header, since they describe the rest of the story. A whole-chat JSONL export is unchanged. - **Server:** `GET /api/chats/:id/export` accepts `startMessageId` and `endMessageId`. One without the other answers 400; a message that is not in the chat answers 404. Passing neither exports the whole chat as before. - **Game chats have no "Export a range" button**, because game rows cannot be selected. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Validation run locally - `pnpm check` — passed (includes localization, Prettier, lint, type checks and the production build). - `pnpm localization:check` — passed. - `node scripts/run-regressions.mjs --filter chat-range-export` — passed (new). - `node scripts/run-regressions.mjs --filter chat-export-swipes-batch` — passed. - `node scripts/run-regressions.mjs --filter bulk-export-zips` — passed. - `node scripts/run-regressions.mjs --filter chat-story-export` — passed. - `node scripts/run-regressions.mjs --filter native-export-memory` — passed on its own. It also failed once when run beside all other export regressions at once, where it measures a 128 MB heap under parallel load; it passes when run alone and in the per-file lane. - `pnpm regression:ui e2e/chat-insights.e2e.ts --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1` — 9 passed. The new range-export test passes on all three projects. The existing "chat search, stats and story exports" test failed once on mobile Chromium in a full three-project run, then passed alone and in two further mobile Chromium runs of the whole file. - `pnpm regression:ui e2e/core-flows.e2e.ts --project=desktop-chromium --project=mobile-chromium --project=mobile-webkit --workers=1 --grep "message deletion uses unified chroma"` — 3 passed (the delete selection bar is unchanged). - The new regression fails without the server change (`AssertionError: text range leaked "msg 0"`, because the route ignores the range parameters and exports the whole chat), and passes with it. ### Local CodeRabbit review Two passes were fixed and the findings addressed in commits `fix(chats): harden the range export preview after review` and `test(chats): tighten the range assertions; keep a newer selection`. - **Accepted and fixed:** a non-string `personaSnapshot.name` would throw while the preview was built; an export finishing after the user switched chats (or started a newer selection) cleared that newer selection; the regression's single-message case only checked the message was present, and the alternate-swipe check only rejected a line that was exactly `msg 3`. Both regression gaps are now covered by one check that rejects any message text left outside the exported rows. - **Fifth pass, also fixed:** any change to the selected messages now ends the run an in-flight export was submitted for, so an export that finishes after the user picks a different range leaves that newer selection open. - **Fourth pass, also fixed:** the preview now reads a user message's persona name through the file's existing `parseMessageExtraRecord` and `getPersonaSnapshotName` helpers, so a message whose `extra` is stored as a JSON string still shows the persona that wrote it. The {{input}} case now exports the echoing message on its own too, so the check fails if the macro reaches a user message outside the range. The new test's cleanup reports a disposal failure only when the test itself passed; throwing from a `finally` is dropped there. - **Third pass, also fixed:** a message in the range using `{{input}}` resolved to the chat's latest user message even when that message was outside the range, so the excerpt carried text it was meant to leave out (proven with a probe: `echo: OUTSIDE latest user secret 2`). `lastInput` now comes from the exported messages. The regression covers the case and fails under the old behaviour. - **Declined:** CodeRabbit reported `lint/correctness/noUnsafeFinally` (a Biome rule) for the test cleanup's `throw cleanupFailure` inside `finally`. This repository validates with ESLint and Prettier, has no Biome configuration, and `pnpm check` passes on the file. The block is copied verbatim from the `finally` cleanup of the test that already existed in this file (staging, `e2e/chat-insights.e2e.ts:226`), so it is the file's established teardown pattern rather than something this PR introduces. ### Manual verification notes - [ ] Manually verify exporting messages 3–7 as Markdown from Chat Branches in the browser, desktop and phone width - [ ] Manually verify the export dialog's count and boundary quotes match the messages you picked, light and dark theme - [ ] Manually verify the exported JSONL re-imports through Chat Branches → Import as a chat of just those messages - [ ] Manually verify a game chat shows no "Export a range" button Screenshots of the open dialog on phone width were captured locally but not uploaded; please attach before/after evidence if helpful. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) - New copy uses the semantic keys `chat.rangeExport.*` in the English catalog only; other locales fall back to English. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8696
No description provided.