Skip to content

feat(chats): fork from any message on desktop - #343

Merged
sambitcreate merged 5 commits into
mainfrom
feat/chat-fork-desktop
Oct 5, 2026
Merged

sambitcreate merged 5 commits into
mainfrom
feat/chat-fork-desktop

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

Summary

Part 1 of the chat fork plan. It also contains #342's commit (sent prompts become pointer-selectable). #342 touches only renderer/ and docs, so the required Linux checks never post on it; this PR runs them, and merging it lands #342 too.

  • Fork from here. Settled assistant replies get a hover action that copies the chat up to and including that reply.
  • Edit in fork. Sent prompts get a hover action that copies everything before the prompt, opens the fork, and pre-fills its composer with the prompt's text and attachments.
    • On the first prompt, it opens an unsaved draft instead, so no empty chat is persisted.
    • The same action is in the /fork picker rows.
  • Lineage. A fork records a strictly parsed forkedFrom { chatId, messageId, position, at }.
    • The chat header shows "Forked from “X”", which links to the source, or "Forked from a deleted chat".
    • Sidebar rows get a fork glyph with a tooltip and an aria-description.
    • A corrupt lineage is dropped on read instead of hiding the chat.
  • Titles. Forks are named Title (fork), then (fork 2) and so on, numbered per workspace. Forks of forks reuse the base title.
  • Busy chats. Forking is still refused while the chat is busy. The buttons stay visible, are aria-disabled, and say why.
  • Bot chats. No hover actions, and before is rejected; the existing /fork after-reply path is unchanged.
  • IPC. chats:copyVisibleHistory now also accepts {chatId, messageId, position}. The legacy {chatId, throughMessageId} still means "fork after this reply".

Not in this PR (follow-ups in the plan):

  • Pi journal fork.
  • Fork with summary.
  • The Remote route with the CLI daemon and paired Macs.
  • iOS and Android.
  • Moving fork into ChatApplicationService (lands with the Remote route).

Tests

  • Store (chat-session-copy.test.ts): after and before cuts, the error cases, (fork N) numbering including forks of forks, lineage surviving a restart and a source deletion, and a corrupt lineage being dropped without hiding the chat.
  • chat-copy-contract.test.ts (new, registered in test:slash-commands): title numbering and code-point-safe truncation, and the strict lineage parser.
  • Parser and view: request shapes, including rejected mixes; each picker turn maps to the prompt that opened it.
  • Rendered markup: which rows get which fork action, the disabled state, and no actions without onFork.
  • Playwright (tests/e2e/chat-fork.spec.ts): the real flow against the fake LM Studio. It forks after a reply, follows the lineage link back, edits a later prompt in a fork, and edits the first prompt into an unsaved draft.
  • Local runs:
    • npm run type-check, plus eslint on the changed files;
    • test:slash-commands, test:sidebar, test:rich-links, test:tts, test:bots;
    • the new e2e plus chat-shell-interactions, draft-agent-chats and chat-message-queue, each repeated three times: 144 passed.

🤖 Generated with Claude Code

sambitcreate and others added 4 commits October 5, 2026 11:22
The app body sets user-select: none and only assistant Markdown opted
back in, so a sent user prompt could not be selected with the pointer.
The user bubble and the unrenderable-message fallback now allow text
selection. An Electron E2E drags across a sent prompt and reads the
selection back.

Adds docs/plans/chat-fork-plan.md: fork a chat from any message on
desktop, Remote, iOS and Android, informed by opencode and pi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Settled replies offer "Fork from here" and sent prompts offer "Edit in
fork", which copies everything before the prompt and pre-fills the new
chat's composer with its text and attachments. Editing the first prompt
opens an unsaved draft instead of persisting an empty chat.

Forks record a strictly parsed `forkedFrom` lineage and are titled
`Title (fork)`, `(fork 2)`, ... per workspace. The chat header links back
to the source (or notes it was deleted) and sidebar rows carry a fork
glyph. A corrupt lineage is dropped on read rather than hiding the chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Three edge cases need fixing before merging: Bot first-prompt edits bypass the intended restriction, long titles lose fork numbering, and image-only replies have no per-message fork action.

Reviewed changes Reviewed the desktop fork flow from transcript actions and /fork through IPC, persisted copies, composer prefill, and lineage display.

  • Fork boundaries. Adds explicit before-prompt and after-reply cuts, strict lineage parsing, and workspace-scoped fork-title numbering while retaining legacy Bot copying.
  • Desktop interactions. Adds transcript actions and picker edits, composer text/attachment prefill, first-prompt unsaved drafts, and source-chat links and sidebar glyphs.
  • Coverage and scope. Adds parser, store, rendered-transcript, and Electron E2E coverage; Pi journal copying, summaries, Remote/CLI routes, and native fork UI are explicitly deferred.
  • Verification. Chat/session tests (526), sidebar tests (98), rich-link/transcript tests (49), and mounted composer tests (4) passed, as did application and E2E type-checks. Direct helper and renderer reproductions confirmed the title and image-only findings; Electron E2E execution was not available on this Linux runner.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread renderer/main/chat-pane.tsx Resolved
Comment thread renderer/shared/chat-copy-contract.ts Resolved
Comment thread renderer/components/message-list.tsx Resolved
@very-hermes-bot

very-hermes-bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: a9c0029949d7f15a0294ca16d6eeb5e8b7630743
Generated: 2026-10-05T16:24:06+00:00
Reviews: 1

Summary

Adds transcript-level and composer picker controls to fork workspace chats from any message on desktop, landing Part 1 of the chat fork plan along with pointer-selectable sent prompts (#342). Completed assistant replies gain a "Fork from here" action cutting through that turn, while sent user prompts gain an "Edit in fork" action that cuts strictly before the prompt, seeds the new chat's composer with the prompt text and attachments, or opens an unsaved draft on the first prompt to avoid saving empty conversations. Provenance is tracked in a strictly validated forkedFrom lineage record (chatId, messageId, position, at) with title numbering (Title (fork), Title (fork 2)) scoped per workspace, while corrupted lineage data is dropped on read without hiding the conversation. Maintainers should double-check that future phases (Remote route and mobile consumers) adhere to the same cut semantics and strict lineage validation rules established here.

Confidence Score: 5/5

Full end-to-end verification across IPC boundary parsers, store transaction locks, title numbering, reactive query caches, draft and attachment lifecycle, accessibility attributes, and test coverage.

📁 Important Files Changed
  • main/handlers/chat-session-params.ts: Extends parseChatCopyRequest to accept { messageId, position } alongside legacy { throughMessageId }, rejecting invalid combinations or positions.
  • main/services/chat-store-core.ts: Implements forkAt boundary cuts for after (reply) and before (user prompt), generates (fork N) workspace sibling titles, persists forkedFrom lineage, and drops corrupt lineage on read.
  • renderer/shared/chat-copy-contract.ts: Defines ChatForkLineageV1, nextForkTitle calculation respecting code-point boundaries and long title truncation, and strict lineage parser.
  • renderer/main/chat-pane.tsx: Coordinates forkFromMessage for both actions, navigates and pre-fills composer text/attachments, handles the first-prompt draft path, and renders the header lineage link.
  • renderer/components/composer.tsx: Integrates "Edit in fork" buttons into the /fork picker dialog and mounts one-shot attachment seeds on navigation.
  • renderer/components/fork-message-button.tsx: Shared hover action button with aria-disabled and busy reason tooltips when the chat is generating or awaiting approvals.
  • renderer/components/chat-sidebar.tsx: Displays GitFork glyph, tooltip provenance (Forked from “X”), and aria-description on sidebar rows.
  • renderer/lib/composer-draft-store.ts: Implements in-memory one-shot attachment seeding for pre-filled composer turns without persisting raw bytes to local storage.

Findings

No findings.

Sequence Diagram

sequenceDiagram
  autonumber
  actor User
  participant Pane as ChatPane
  participant Store as ComposerDraftStore
  participant IPC as chatsApi (IPC)
  participant Main as ChatStore (main)
  participant Composer as Composer

  alt Edit prompt in fork (Prompt 2+)
    User->>Pane: Click "Edit in fork" on prompt
    Pane->>IPC: copyVisibleHistory(chatId, { messageId, position: "before" })
    IPC->>Main: copyVisibleHistory({ forkAt })
    Main->>Main: Slice messages before prompt & assign (fork N) title
    Main->>Main: Persist chat & index with forkedFrom lineage
    Main-->>IPC: Copied Chat
    IPC-->>Pane: Copied Chat
    Pane->>Store: saveComposerDraftText(newId, text)
    Pane->>Store: seedComposerAttachments(newId, attachments)
    Pane->>Pane: navigate("/chat/" + newId)
    Pane->>Composer: Mount Composer(chatId=newId)
    Composer->>Store: loadComposerDraft(newId) -> text
    Composer->>Store: takeComposerAttachmentSeed(newId) -> attachments
    Composer-->>User: Ready to edit prompt with attachments
  else Edit first prompt in fork (Prompt 1)
    User->>Pane: Click "Edit in fork" on first prompt
    Pane->>Pane: createChatDraft(workspaceId, initialText=text)
    Pane->>Store: seedComposerAttachments(draftId, attachments)
    Pane->>Pane: navigate("/chat/" + draftId)
    Pane->>Composer: Mount Composer(chatId=draftId)
    Composer->>Store: takeComposerAttachmentSeed(draftId)
    Composer-->>User: Open unsaved draft (no empty chat on disk)
  end
Loading
[]

Last reviewed commit: a9c0029949d7
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

- Bot chats no longer offer Edit in fork in the /fork picker, and the
  renderer refuses a before-prompt fork for them, including the
  first-prompt draft shortcut that never reached IPC.
- Fork titles keep numbering when a long base title was truncated to
  fit its suffix.
- Settled replies with only attachments or tool activity now show
  Fork from here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes Reviewed the fixes and CI test registration added since the prior Pullfrog review at 668dd90e.

  • Blocked Bot prompt edits. Removed Bot picker edit actions and rejected before-prompt forks before the first-prompt draft shortcut, preserving after-reply copying.
  • Preserved long-title numbering. Counted truncated sibling titles so sequential and nested forks continue numbering across wider numeric suffixes.
  • Restored no-prose actions. Added fork-only action rows for settled attachment-only and activity-only replies without duplicating Copy or prose-response actions.
  • Registered CI coverage. Assigned the fork contract test to a desktop unit lane.
  • Verified behavior. Passed test:slash-commands (529 tests), test:tts (148), test:ci:registry (10), and application type-checking; additional helper checks covered 315 sequential and 315 nested forks. Electron E2E was not rerun on this Linux runner.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@sambitcreate
sambitcreate merged commit 929f1d1 into main Oct 5, 2026
25 checks passed
@sambitcreate
sambitcreate deleted the feat/chat-fork-desktop branch October 5, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants