Repository navigation
Conversation
Adds a session merge feature to the sidebar: select two or more sessions and combine them into a single .jsonl file beside the main session, deleting the sources. Before merging, a preview scores every pair by Dice similarity over the full session content; dissimilar pairs need an explicit confirmation (force), cross-cwd merges are rejected unless the user turns off the same-directory switch, and subagent sources are refused outright. - lib/session-merge.ts: textShingles/dice scoring, previewSessionMerge, mergeSessions (id remap + parent relink, source deletion, child reparenting), SessionMergeError with typed codes - app/api/sessions/merge/route.ts: POST endpoint with preview/force/ sameCwdOnly handling, shutdowns RPC wrappers before writing - components/SessionMergeDialog.tsx: searchable multi-select dialog with live similarity preview, force confirmation, same-directory toggle - components/SessionSidebar.tsx: row menu Merge... + top bar button, opens the merged session and closes deleted ones - i18n: en / zh-CN / zh-TW strings - tests: 9 cases covering scoring, merging, refusals, cross-cwd and subagent sources
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1163
Summary
This PR adds a session merge feature to the sidebar for the pi coding
agent web UI: pick two or more sessions, preview how similar they are, and
combine them into one session file (sources are deleted afterwards).
User story
As a pi user working across several related sessions of the same project,
I want to merge multiple sessions into a single one, so that I can keep one
coherent history instead of a fragmented list — and before anything is
deleted, I want to know how similar the sessions are, so I only merge
ones that actually belong together.
What it does
Merge…(also bound toM) and a top-bar mergebutton open a searchable multi-select dialog.
Dice coefficient over shingles of the actual
.jsonlcontent(thresholds: ≥ 0.45 suggests merging, < 0.25 warns). The UI shows the
per-pair score and an overall verdict.
(
force); the server re-validates it (409 on refusal).cwddiffersare refused unless the user turns off “only merge sessions in the same
directory”; the server enforces this (
sameCwdOnly, 400 on refusal).pi-web:subagentmetadatacannot be carried into a normal session (409).
their ids re-mapped and the parent/child tree relinked (branch
structure preserved), then are appended after the main line with a
custom_messagesource marker.re-parented to the new file. The merged session is created beside the
main session and opened in the UI.
Files
lib/session-merge.ts— scoring (textShingles,dice),previewSessionMerge,mergeSessions,SessionMergeErrorapp/api/sessions/merge/route.ts— POST endpoint (preview or execute)components/SessionMergeDialog.tsx— the dialogcomponents/SessionSidebar.tsx,components/SidebarIcons.tsx,lib/sidebar-actions.ts— entry pointsapp/sidebar.css— dialog stylinglib/session-merge.test.mjs— 9 unit tests (node:test + jiti)Test status
node --experimental-strip-types --test lib/session-merge.test.mjs— 9/9tsc --noEmit— clean