feat: allow branching from both user and assistant messages

- Relax branchSessionRecord validation to accept user or assistant roles
- Show "Branch from here" hover button on all conversation messages
- Contextual tooltip: "starting from this message" vs "continuing from this response"
- Add test for branching from assistant message
- Replace non-user rejection test with non-conversation rejection test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David Kaya
2026-03-29 21:43:58 +02:00
co-authored by Copilot
parent c0a37b0cd4
commit 4726e2acea
3 changed files with 61 additions and 9 deletions
+4 -2
View File
@@ -380,11 +380,13 @@ export function ChatPane({
{phaseLabel}
</span>
)}
{isUser && onBranchFromMessage && (
{onBranchFromMessage && (
<button
className="ml-auto flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] text-[var(--color-text-muted)] opacity-0 transition-all duration-150 hover:bg-[var(--color-surface-2)] hover:text-[var(--color-accent)] group-hover:opacity-100"
onClick={() => onBranchFromMessage(message.id)}
title="Branch from here — create a new session starting from this message"
title={isUser
? 'Branch from here — create a new session starting from this message'
: 'Branch from here — create a new session continuing from this response'}
type="button"
>
<GitBranch className="size-3" />
+2 -2
View File
@@ -237,8 +237,8 @@ export function branchSessionRecord(
throw new Error(`Message ${messageId} not found in session ${session.id}.`);
}
if (sourceMessage.role !== 'user') {
throw new Error('Only user messages can be used as a branch point.');
if (sourceMessage.role !== 'user' && sourceMessage.role !== 'assistant') {
throw new Error('Only user or assistant messages can be used as a branch point.');
}
const branchedMessages = session.messages.slice(0, sourceMessageIndex + 1).map(cloneChatMessageRecord);