[PR #8160] [MERGED] feat(chat): branch graph window from the Chat Branches panel #8134

Closed
opened 2026-10-24 04:10:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8160
Author: @ylli-selmani
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/chat-branches-panel-tree


📝 Commits (8)

  • 05f069b feat(chat): open a branch graph window from the Chat Branches header
  • bca4a1b feat(chats): read a group's branch graph in one request
  • 43709a5 feat(chats): draw the branch graph
  • be1e329 docs(chats): describe the branch graph
  • 4172267 fix(chats): let a tap on a graph point show its text
  • 8cae698 docs(chats): mention tapping a graph point
  • 4ba6d58 fix(client): tighten the branch graph's edge cases
  • 5333e97 fix(client): don't ring a top chat's fork twice at its tip

📊 Changes

14 files changed (+1258 additions, -1 deletions)

View changed files

📝 docs/chats/branches.md (+19 -1)
➕ packages/client/src/components/chat/ChatBranchGraphWindow.tsx (+574 -0)
📝 packages/client/src/components/chat/ChatCommonOverlays.tsx (+2 -0)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+3 -0)
📝 packages/client/src/features/chat-settings/ChatSettingsSection.tsx (+8 -0)
📝 packages/client/src/hooks/use-chats.ts (+14 -0)
➕ packages/client/src/lib/chat-branch-graph-layout.ts (+188 -0)
📝 packages/client/src/localization/locales/en.json (+21 -0)
📝 packages/server/src/routes/chats.routes.ts (+12 -0)
➕ packages/server/src/services/chat-branch-graph.ts (+81 -0)
📝 packages/server/src/services/storage/chats.storage.ts (+25 -0)
📝 packages/shared/src/types/chat.ts (+29 -0)
➕ scripts/regressions/chat-branch-graph-layout.regression.ts (+133 -0)
➕ scripts/regressions/chat-branch-graph.regression.ts (+149 -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 #8157

Why this change

  • Since #8114 the chat list shows a chat's branches as a small tree. It has no room for long histories or deep chains, and it only says which chat a branch came from, not where: the message it split off at. Community feedback asked for exactly that.
  • The Chat Branches panel is a flat list sorted by recent activity. That's right for quick switching, but it shows no shape. Turning it into a tree would cramp it and slow switching down, so the graph gets its own resizable window, opened from a tree button in the panel's header.

What changed

Slice 1: the entry point and the window ✅

  • A tree button (lucide GitGraph) in the Chat Branches header. It's in the inline section header and also in the popped-out window's title bar. ChatSettingsSection now forwards Drawer's actions and detachedHeaderControls to make that possible.
  • ChatBranchGraphWindow: a FloatingWindow (chat-branch-graph). It's movable and resizable, opens centred over the chat, and becomes a sheet on phones. Its own close button always closes it; Escape and outside presses leave a pinned window open. It's mounted from ChatCommonOverlays, so every chat mode that has the section gets it.
  • Precedent: the button follows TrackerStateEditorButton (mari-window__control in a window header). The window follows the Chat Settings and chat-control windows (marinara-chat-popover, neutral surface).

Slice 2: graph read route ✅

  • GET /chats/group/:groupId/branch-graph returns one entry per chat in a group:
    • where it forked, read from the branch's own copy of the fork message, so it survives a deleted parent;
    • its message count;
    • one role letter per message after the fork;
    • ~80-character snippets for the fork and the latest message.
  • Branches copy their history, so the client doesn't load every transcript. Storage gains two content-free reads (listMessageOutlines, getMessageContents). It's read-only, with no schema change.
  • Regression chat-branch-graph covers:
    • a nested branch;
    • a legacy branch with no lineage;
    • a deleted parent;
    • a branch of an empty chat;
    • snippet trimming;
    • an unknown group.

Slice 3: draw the graph ✅

  • One lane per chat, in the same tree order as the Chat Branches list, on one shared message axis read left to right. There's a dot per message, coloured by role: you, character, and narrator or system (a hollow ring). The colours follow ChatRowPeek.
  • Each branch joins its parent at the fork with a rounded elbow. A fork inside history the parent itself copied joins the lane that really holds that message. Older branches with no recorded fork, and branches whose parent was deleted, hang off the top chat with a dashed elbow, plus a "Fork not recorded" legend entry.
  • Runs of ten or more messages away from any fork, start or tip collapse into a ··· N ··· pill on the shared axis, so forks still line up across lanes. A pill expands on click, Enter or Space, and "Expand all" toggles every run.
  • Forks and tips get a ring. Hover, focus or a tap shows #N · speaker · "snippet". A tap on a ring doesn't switch chats, so the text is readable on touch screens.
  • Clicking a lane's name or line switches to that chat; the current lane is highlighted and has aria-current. The window opens scrolled to the current chat's latest message.
  • useChatBranchGraph is keyed under the chat group, so renames, deletions and new branches refetch it. New messages refetch it after a 1.5 s debounce.
  • Layout lives in lib/chat-branch-graph-layout.ts, kept apart from React. Regression chat-branch-graph-layout covers:
    • a 300-message chat collapsing to fewer than 40 columns;
    • expanding one run, and expanding all;
    • nested and early forks;
    • legacy and orphaned branches;
    • an adopted top chat;
    • a fresh, empty branch.

Slice 4: docs ⏳

  • docs/chats/branches.md § Chat Branches, plus a [docs-i18n] follow-up.

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

Manual verification notes

  • Manually verify in the browser that the Chat Branches header in Chat Settings shows a tree button between "?" and the pop-out control, and that it opens a "Branch graph" window.
  • Manually verify that the window moves, resizes from its corner, pins, and closes from its close button.
  • Manually verify that once the Chat Branches section is popped out, its title bar shows the same tree button and that button opens the same window.
  • Manually verify that at a phone width (375px) the graph opens as a sheet.
  • Manually verify, with a group that has a long chat and a branch of a branch, that each branch's elbow leaves its parent at the right message, that long runs show as ··· N ··· and expand on click, that hovering a ring shows #N · speaker · "snippet", and that clicking a lane switches chats.

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)

Seeded demo group: a 320-message chat with three branches, one of them a branch of a branch.

Desktop: long runs fold into ··· N ··· pills, each branch's line leaves its parent at the fork, and the current branch is highlighted. The tree button sits in the Chat Branches title bar, next to "?".

Branch graph window on desktop: four lanes, collapsed runs, elbows at each fork, current lane highlighted

Hover text on a tip: #N · speaker · "snippet", kept inside the window at its right edge.

Branch graph with the Latest message tooltip for #320 by Raven, clamped inside the window

Phone (375px): the graph opens as a sheet, scrolled to the current branch's latest message.

Branch graph as a full-height sheet at 375px wide

🤖 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/8160 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/chat-branches-panel-tree` --- ### 📝 Commits (8) - [`05f069b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/05f069ba80c1ecf279dd1c004c6e59e8d56d8128) feat(chat): open a branch graph window from the Chat Branches header - [`bca4a1b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bca4a1b22108598bd5375dc37d348cd8cbe8256d) feat(chats): read a group's branch graph in one request - [`43709a5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/43709a573b9512f74052bb32c170d2a8e07add87) feat(chats): draw the branch graph - [`be1e329`](https://github.com/Pasta-Devs/Marinara-Engine/commit/be1e3298cfa094c5a81910adb72a6fc95adf8411) docs(chats): describe the branch graph - [`4172267`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4172267dc80337843e0e6bce18e6d83529ce8830) fix(chats): let a tap on a graph point show its text - [`8cae698`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8cae6981bc74866f50b7179397cf3551d247619f) docs(chats): mention tapping a graph point - [`4ba6d58`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ba6d58ee889a11ced8eb49fd49525a71fbdfd21) fix(client): tighten the branch graph's edge cases - [`5333e97`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5333e97789f259d8a75f0132db4991431f497871) fix(client): don't ring a top chat's fork twice at its tip ### 📊 Changes **14 files changed** (+1258 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/chats/branches.md` (+19 -1) ➕ `packages/client/src/components/chat/ChatBranchGraphWindow.tsx` (+574 -0) 📝 `packages/client/src/components/chat/ChatCommonOverlays.tsx` (+2 -0) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+3 -0) 📝 `packages/client/src/features/chat-settings/ChatSettingsSection.tsx` (+8 -0) 📝 `packages/client/src/hooks/use-chats.ts` (+14 -0) ➕ `packages/client/src/lib/chat-branch-graph-layout.ts` (+188 -0) 📝 `packages/client/src/localization/locales/en.json` (+21 -0) 📝 `packages/server/src/routes/chats.routes.ts` (+12 -0) ➕ `packages/server/src/services/chat-branch-graph.ts` (+81 -0) 📝 `packages/server/src/services/storage/chats.storage.ts` (+25 -0) 📝 `packages/shared/src/types/chat.ts` (+29 -0) ➕ `scripts/regressions/chat-branch-graph-layout.regression.ts` (+133 -0) ➕ `scripts/regressions/chat-branch-graph.regression.ts` (+149 -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 #8157 ## Why this change - Since #8114 the chat list shows a chat's branches as a small tree. It has no room for long histories or deep chains, and it only says which chat a branch came from, not **where**: the message it split off at. Community feedback asked for exactly that. - The Chat Branches panel is a flat list sorted by recent activity. That's right for quick switching, but it shows no shape. Turning it into a tree would cramp it and slow switching down, so the graph gets its **own resizable window**, opened from a tree button in the panel's header. ## What changed **Slice 1: the entry point and the window** ✅ - A tree button (lucide `GitGraph`) in the Chat Branches header. It's in the inline section header and also in the popped-out window's title bar. `ChatSettingsSection` now forwards Drawer's `actions` and `detachedHeaderControls` to make that possible. - `ChatBranchGraphWindow`: a `FloatingWindow` (`chat-branch-graph`). It's movable and resizable, opens centred over the chat, and becomes a sheet on phones. Its own close button always closes it; Escape and outside presses leave a pinned window open. It's mounted from `ChatCommonOverlays`, so every chat mode that has the section gets it. - Precedent: the button follows `TrackerStateEditorButton` (`mari-window__control` in a window header). The window follows the Chat Settings and chat-control windows (`marinara-chat-popover`, neutral surface). **Slice 2: graph read route** ✅ - `GET /chats/group/:groupId/branch-graph` returns one entry per chat in a group: - where it forked, read from the branch's own copy of the fork message, so it survives a deleted parent; - its message count; - one role letter per message after the fork; - ~80-character snippets for the fork and the latest message. - Branches copy their history, so the client doesn't load every transcript. Storage gains two content-free reads (`listMessageOutlines`, `getMessageContents`). It's read-only, with no schema change. - Regression `chat-branch-graph` covers: - a nested branch; - a legacy branch with no lineage; - a deleted parent; - a branch of an empty chat; - snippet trimming; - an unknown group. **Slice 3: draw the graph** ✅ - One lane per chat, in the same tree order as the Chat Branches list, on one shared message axis read left to right. There's a dot per message, coloured by role: you, character, and narrator or system (a hollow ring). The colours follow `ChatRowPeek`. - Each branch joins its parent at the fork with a rounded elbow. A fork inside history the parent itself copied joins the lane that really holds that message. Older branches with no recorded fork, and branches whose parent was deleted, hang off the top chat with a dashed elbow, plus a "Fork not recorded" legend entry. - Runs of ten or more messages away from any fork, start or tip collapse into a `··· N ···` pill on the shared axis, so forks still line up across lanes. A pill expands on click, Enter or Space, and "Expand all" toggles every run. - Forks and tips get a ring. Hover, focus or a tap shows `#N · speaker · "snippet"`. A tap on a ring doesn't switch chats, so the text is readable on touch screens. - Clicking a lane's name or line switches to that chat; the current lane is highlighted and has `aria-current`. The window opens scrolled to the current chat's latest message. - `useChatBranchGraph` is keyed under the chat group, so renames, deletions and new branches refetch it. New messages refetch it after a 1.5 s debounce. - Layout lives in `lib/chat-branch-graph-layout.ts`, kept apart from React. Regression `chat-branch-graph-layout` covers: - a 300-message chat collapsing to fewer than 40 columns; - expanding one run, and expanding all; - nested and early forks; - legacy and orphaned branches; - an adopted top chat; - a fresh, empty branch. **Slice 4: docs** ⏳ - `docs/chats/branches.md` § Chat Branches, plus a `[docs-i18n]` follow-up. ## 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` ### Manual verification notes - Manually verify in the browser that the Chat Branches header in Chat Settings shows a tree button between "?" and the pop-out control, and that it opens a "Branch graph" window. - Manually verify that the window moves, resizes from its corner, pins, and closes from its close button. - Manually verify that once the Chat Branches section is popped out, its title bar shows the same tree button and that button opens the same window. - Manually verify that at a phone width (375px) the graph opens as a sheet. - Manually verify, with a group that has a long chat and a branch of a branch, that each branch's elbow leaves its parent at the right message, that long runs show as `··· N ···` and expand on click, that hovering a ring shows `#N · speaker · "snippet"`, and that clicking a lane switches chats. ## 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) Seeded demo group: a 320-message chat with three branches, one of them a branch of a branch. **Desktop:** long runs fold into `··· N ···` pills, each branch's line leaves its parent at the fork, and the current branch is highlighted. The tree button sits in the Chat Branches title bar, next to "?". <img src="https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/chat-branch-graph/graph-desktop.jpg" width="720" alt="Branch graph window on desktop: four lanes, collapsed runs, elbows at each fork, current lane highlighted"> **Hover text on a tip:** `#N · speaker · "snippet"`, kept inside the window at its right edge. <img src="https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/chat-branch-graph/tip-tooltip.jpg" width="720" alt="Branch graph with the Latest message tooltip for #320 by Raven, clamped inside the window"> **Phone (375px):** the graph opens as a sheet, scrolled to the current branch's latest message. <img src="https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/chat-branch-graph/graph-375.jpg" width="320" alt="Branch graph as a full-height sheet at 375px wide"> 🤖 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 changed title from [PR #8160] feat(chat): branch graph window from the Chat Branches panel to [PR #8160] [MERGED] feat(chat): branch graph window from the Chat Branches panel 2026-10-25 04:04:18 +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#8134
No description provided.